Skip to content

Commit 68917c9

Browse files
committed
Add EditorInterface method to search asset library
1 parent 97e5d8c commit 68917c9

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

editor/asset_library/asset_library_editor_plugin.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,25 @@ void EditorAssetLibrary::disable_community_support() {
16141614
support->get_popup()->set_item_checked(SUPPORT_COMMUNITY, false);
16151615
}
16161616

1617+
void EditorAssetLibrary::search(const String &p_filter_str) {
1618+
ERR_FAIL_COND(!is_visible());
1619+
1620+
// If Asset Library hasn't been opened yet, we must wait for the initial request to complete.
1621+
if (!filter->is_editable()) {
1622+
request->connect("request_completed", callable_mp(this, &EditorAssetLibrary::_on_request_completed).bind(p_filter_str), CONNECT_ONE_SHOT);
1623+
} else {
1624+
filter->set_text(p_filter_str);
1625+
filter->emit_signal("text_changed", filter->get_text());
1626+
}
1627+
}
1628+
1629+
void EditorAssetLibrary::_on_request_completed(int p_result, int p_response_code, const PackedStringArray &p_headers, const PackedByteArray &p_body, String p_filter_str) {
1630+
ERR_FAIL_COND_MSG(p_response_code != 200, vformat("Asset Library HTTPRequest returned with response code %s", p_response_code));
1631+
1632+
filter->set_text(p_filter_str);
1633+
filter->emit_signal("text_changed", filter->get_text());
1634+
}
1635+
16171636
void EditorAssetLibrary::_bind_methods() {
16181637
ADD_SIGNAL(MethodInfo("install_asset", PropertyInfo(Variant::STRING, "zip_path"), PropertyInfo(Variant::STRING, "name")));
16191638
}
@@ -1832,6 +1851,11 @@ void AssetLibraryEditorPlugin::make_visible(bool p_visible) {
18321851
}
18331852
}
18341853

1854+
void AssetLibraryEditorPlugin::search_assset_library(const String &p_filter) {
1855+
ERR_FAIL_COND_MSG(!is_available(), "Asset Library not availabe on current platform");
1856+
addon_library->search(p_filter);
1857+
}
1858+
18351859
AssetLibraryEditorPlugin::AssetLibraryEditorPlugin() {
18361860
addon_library = memnew(EditorAssetLibrary);
18371861
addon_library->set_v_size_flags(Control::SIZE_EXPAND_FILL);

editor/asset_library/asset_library_editor_plugin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ class EditorAssetLibrary : public PanelContainer {
323323

324324
void _update_asset_items_columns();
325325

326+
void _on_request_completed(int p_result, int p_response_code, const PackedStringArray &p_headers, const PackedByteArray &p_body, String p_search_string);
327+
326328
friend class EditorAssetLibraryItemDescription;
327329
friend class EditorAssetLibraryItem;
328330

@@ -334,6 +336,8 @@ class EditorAssetLibrary : public PanelContainer {
334336
public:
335337
void disable_community_support();
336338

339+
void search(const String &p_filter);
340+
337341
EditorAssetLibrary(bool p_templates_only = false);
338342
};
339343

@@ -354,5 +358,7 @@ class AssetLibraryEditorPlugin : public EditorPlugin {
354358
//virtual Dictionary get_state() const;
355359
//virtual void set_state(const Dictionary& p_state);
356360

361+
void search_assset_library(const String &p_filter);
362+
357363
AssetLibraryEditorPlugin();
358364
};

editor/editor_interface.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
/**************************************************************************/
3030

3131
#include "editor_interface.h"
32+
#include "core/string/print_string.h"
3233
#include "editor_interface.compat.inc"
3334

3435
#include "core/config/project_settings.h"
3536
#include "core/io/resource_loader.h"
37+
#include "editor/asset_library/asset_library_editor_plugin.h"
3638
#include "editor/docks/filesystem_dock.h"
3739
#include "editor/docks/inspector_dock.h"
3840
#include "editor/editor_main_screen.h"
@@ -59,6 +61,8 @@
5961
#include "scene/3d/mesh_instance_3d.h"
6062
#include "scene/gui/box_container.h"
6163
#include "scene/gui/control.h"
64+
#include "scene/gui/line_edit.h"
65+
#include "scene/main/http_request.h"
6266
#include "scene/main/window.h"
6367
#include "scene/resources/packed_scene.h"
6468
#include "scene/resources/theme.h"
@@ -117,6 +121,14 @@ void EditorInterface::open_export_dialog() {
117121
EditorNode::get_singleton()->open_export_dialog();
118122
}
119123

124+
void EditorInterface::search_asset_library(const String &p_filter) {
125+
AssetLibraryEditorPlugin *asset_lib = EditorNode::get_singleton()->get_asset_library();
126+
ERR_FAIL_NULL_MSG(asset_lib, "Asset Library not available.");
127+
128+
set_main_screen_editor("AssetLib");
129+
asset_lib->search_assset_library(p_filter);
130+
}
131+
120132
AABB EditorInterface::_calculate_aabb_for_scene(Node *p_node, AABB &p_scene_aabb) {
121133
MeshInstance3D *mesh_node = Object::cast_to<MeshInstance3D>(p_node);
122134
if (mesh_node && mesh_node->get_mesh().is_valid()) {
@@ -844,6 +856,7 @@ void EditorInterface::_bind_methods() {
844856

845857
ClassDB::bind_method(D_METHOD("open_project_settings", "general_page", "filter"), &EditorInterface::open_project_settings);
846858
ClassDB::bind_method(D_METHOD("open_export_dialog"), &EditorInterface::open_export_dialog);
859+
ClassDB::bind_method(D_METHOD("search_asset_library", "filter"), &EditorInterface::search_asset_library);
847860

848861
ClassDB::bind_method(D_METHOD("make_mesh_previews", "meshes", "preview_size"), &EditorInterface::_make_mesh_previews);
849862

editor/editor_interface.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class EditorSettings;
4848
class EditorToaster;
4949
class EditorUndoRedoManager;
5050
class FileSystemDock;
51+
class LineEdit;
5152
class Mesh;
5253
class Node;
5354
class PropertySelector;
@@ -109,9 +110,6 @@ class EditorInterface : public Object {
109110
EditorToaster *get_editor_toaster() const;
110111
EditorUndoRedoManager *get_editor_undo_redo() const;
111112

112-
void open_project_settings(const String &p_general_page, const String &p_filter);
113-
void open_export_dialog();
114-
115113
Vector<Ref<Texture2D>> make_mesh_previews(const Vector<Ref<Mesh>> &p_meshes, Vector<Transform3D> *p_transforms, int p_preview_size);
116114
void make_scene_preview(const String &p_path, Node *p_scene, int p_preview_size);
117115

@@ -149,6 +147,10 @@ class EditorInterface : public Object {
149147
String get_current_feature_profile() const;
150148
void set_current_feature_profile(const String &p_profile_name);
151149

150+
void open_project_settings(const String &p_general_page, const String &p_filter);
151+
void open_export_dialog();
152+
void search_asset_library(const String &p_filter);
153+
152154
// Editor dialogs.
153155

154156
void popup_node_selector(const Callable &p_callback, const TypedArray<StringName> &p_valid_types = TypedArray<StringName>(), Node *p_current_value = nullptr);

editor/editor_node.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8957,7 +8957,8 @@ EditorNode::EditorNode() {
89578957
TextEditor::register_editor();
89588958

89598959
if (AssetLibraryEditorPlugin::is_available()) {
8960-
add_editor_plugin(memnew(AssetLibraryEditorPlugin));
8960+
asset_library_plugin = memnew(AssetLibraryEditorPlugin);
8961+
add_editor_plugin(asset_library_plugin);
89618962
} else {
89628963
print_verbose("Asset Library not available (due to using Web editor, or SSL support disabled).");
89638964
}

editor/editor_node.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Window;
6464

6565
class AudioStreamImportSettingsDialog;
6666
class AudioStreamPreviewGenerator;
67+
class AssetLibraryEditorPlugin;
6768
class BackgroundProgress;
6869
class DependencyErrorDialog;
6970
class DockSplitContainer;
@@ -275,6 +276,8 @@ class EditorNode : public Node {
275276
ProjectExportDialog *project_export = nullptr;
276277
ProjectSettingsEditor *project_settings_editor = nullptr;
277278

279+
AssetLibraryEditorPlugin *asset_library_plugin = nullptr;
280+
278281
FBXImporterManager *fbx_importer_manager = nullptr;
279282

280283
Vector<EditorPlugin *> editor_plugins;
@@ -795,6 +798,8 @@ class EditorNode : public Node {
795798

796799
ProjectSettingsEditor *get_project_settings() { return project_settings_editor; }
797800

801+
AssetLibraryEditorPlugin *get_asset_library() { return asset_library_plugin; }
802+
798803
void trigger_menu_option(int p_option, bool p_confirmed);
799804
bool has_previous_closed_scenes() const;
800805

0 commit comments

Comments
 (0)