Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Don't hide model scenes when quick instantiating

kobewi234697366289
diff --git a/editor/docks/scene_tree_dock.cpp b/editor/docks/scene_tree_dock.cpp
index 336a1f7afe3..3d456170093 100644
--- a/editor/docks/scene_tree_dock.cpp
+++ b/editor/docks/scene_tree_dock.cpp
@@ -722,7 +722,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
- EditorNode::get_singleton()->get_quick_open_dialog()->popup_dialog({ "PackedScene" }, callable_mp(this, &SceneTreeDock::_quick_open));
+ EditorNode::get_singleton()->get_quick_open_dialog()->popup_dialog_for_instantiating_scenes(callable_mp(this, &SceneTreeDock::_quick_open));
} break;
case TOOL_EXPAND_COLLAPSE: {
Tree *tree = scene_tree->get_scene_tree();
diff --git a/editor/gui/editor_quick_open_dialog.cpp b/editor/gui/editor_quick_open_dialog.cpp
index 253c7307fb3..66461d2646c 100644
--- a/editor/gui/editor_quick_open_dialog.cpp
+++ b/editor/gui/editor_quick_open_dialog.cpp
@@ -154,15 +154,13 @@ void EditorQuickOpenDialog::popup_dialog(const Vector<StringName> &p_base_types,
ERR_FAIL_COND(p_base_types.is_empty());
ERR_FAIL_COND(!p_item_selected_callback.is_valid());
- property_object = nullptr;
- property_path = "";
- item_selected_callback = p_item_selected_callback;
- allow_type_switching = p_allow_type_switching;
+ _popup_dialog(p_base_types, p_item_selected_callback, p_allow_type_switching);
+}
- is_cycling_items = false;
- container->init(p_base_types);
- container->set_instant_preview_toggle_visible(false);
- _finish_dialog_setup(p_base_types);
+void EditorQuickOpenDialog::popup_dialog_for_instantiating_scenes(const Callable &p_item_selected_callback) {
+ ERR_FAIL_COND(!p_item_selected_callback.is_valid());
+
+ _popup_dialog(Vector<StringName>{ "PackedScene" }, p_item_selected_callback, false, nullptr, StringName::EMPTY, true);
}
void EditorQuickOpenDialog::popup_dialog_for_property(const Vector<StringName> &p_base_types, Object *p_obj, const StringName &p_path, const Callable &p_item_selected_callback) {
@@ -170,19 +168,7 @@ void EditorQuickOpenDialog::popup_dialog_for_property(const Vector<StringName> &
ERR_FAIL_COND(p_base_types.is_empty());
ERR_FAIL_COND(!p_item_selected_callback.is_valid());
- property_object = p_obj;
- property_path = p_path;
- item_selected_callback = p_item_selected_callback;
- initial_property_value = property_object->get(property_path);
- allow_type_switching = false;
-
- // Reset this, so that the property isn't updated immediately upon opening
- // the window.
- initial_selection_performed = false;
-
- container->init(p_base_types);
- container->set_instant_preview_toggle_visible(true);
- _finish_dialog_setup(p_base_types);
+ _popup_dialog(p_base_types, p_item_selected_callback, false, p_obj, p_path);
}
void EditorQuickOpenDialog::_finish_dialog_setup(const Vector<StringName> &p_base_types) {
@@ -202,6 +188,28 @@ void EditorQuickOpenDialog::ok_pressed() {
hide();
}
+void EditorQuickOpenDialog::_popup_dialog(const Vector<StringName> &p_base_types, const Callable &p_item_selected_callback, bool p_allow_type_switching, Object *p_object, const StringName &p_property, bool p_instantiating) {
+ // The arguments are expected to be correct. The validation should be done in calling methods.
+ property_object = p_object;
+ property_path = p_property;
+ item_selected_callback = p_item_selected_callback;
+ allow_type_switching = p_allow_type_switching;
+ is_cycling_items = false;
+ container->set_instantiating_mode(p_instantiating);
+
+ if (property_object) {
+ container->set_instant_preview_toggle_visible(true);
+ initial_property_value = property_object->get(property_path);
+ // Reset this, so that the property isn't updated immediately upon opening
+ // the window.
+ initial_selection_performed = false;
+ } else {
+ container->set_instant_preview_toggle_visible(false);
+ }
+ container->init(p_base_types);
+ _finish_dialog_setup(p_base_types);
+}
+
bool EditorQuickOpenDialog::_is_instant_preview_active() const {
return property_object != nullptr && container->is_instant_preview_enabled();
}
@@ -739,8 +747,8 @@ void QuickOpenResultContainer::_add_candidate(QuickOpenResultCandidate &p_candid
String file_path = ResourceUID::get_singleton()->get_id_path(p_candidate.uid);
- // Verify that a PackedScene is actually a "real" Scene if in a Open Scene context.
- if (base_types.size() == 1 && base_types[0] == SNAME("PackedScene")) {
+ // Verify that a PackedScene is actually a "real" Scene if in a Open Scene context, unless instantiating scenes.
+ if (!instantiating_mode && base_types.size() == 1 && base_types[0] == SNAME("PackedScene")) {
static FixedVector<String, 3> valid_extensions = { "tscn", "scn", "res" };
bool is_valid_type = false;
for (const String &ext : valid_extensions) {
diff --git a/editor/gui/editor_quick_open_dialog.h b/editor/gui/editor_quick_open_dialog.h
index 3af1b57b462..b3044651add 100644
--- a/editor/gui/editor_quick_open_dialog.h
+++ b/editor/gui/editor_quick_open_dialog.h
@@ -102,6 +102,7 @@ public:
bool is_instant_preview_enabled() const;
void set_instant_preview_toggle_visible(bool p_visible);
+ void set_instantiating_mode(bool p_enabled) { instantiating_mode = p_enabled; }
void save_selected_item();
void cleanup();
@@ -127,6 +128,7 @@ private:
int selection_index = -1;
int num_visible_results = 0;
int max_total_results = 0;
+ bool instantiating_mode = false;
bool never_opened = true;
Ref<ConfigFile> history_file;
@@ -258,6 +260,7 @@ class EditorQuickOpenDialog : public AcceptDialog {
public:
void popup_dialog(const Vector<StringName> &p_base_types, const Callable &p_item_selected_callback, bool p_allow_type_switching = false);
+ void popup_dialog_for_instantiating_scenes(const Callable &p_item_selected_callback);
void popup_dialog_for_property(const Vector<StringName> &p_base_types, Object *p_obj, const StringName &p_path, const Callable &p_item_selected_callback);
EditorQuickOpenDialog();
@@ -282,6 +285,7 @@ private:
bool initial_selection_performed = false;
bool allow_type_switching = false;
bool is_cycling_items = false;
+ void _popup_dialog(const Vector<StringName> &p_base_types, const Callable &p_item_selected_callback, bool p_allow_type_switching = false, Object *p_object = nullptr, const StringName &p_property = StringName::EMPTY, bool p_instantiating = false);
bool _is_instant_preview_active() const;
void _search_box_text_changed(const String &p_query);
void _finish_dialog_setup(const Vector<StringName> &p_base_types);
diff --git a/editor/scene/canvas_item_editor_plugin.cpp b/editor/scene/canvas_item_editor_plugin.cpp
index ff23cbc69a5..fc9ba399005 100644
--- a/editor/scene/canvas_item_editor_plugin.cpp
+++ b/editor/scene/canvas_item_editor_plugin.cpp
@@ -834,7 +834,7 @@ void CanvasItemEditor::_add_node_pressed(int p_result) {
add_node_dialog->popup_create(true);
} break;
case ADD_INSTANCE: {
- EditorNode::get_singleton()->get_quick_open_dialog()->popup_dialog(Vector<StringName>{ "PackedScene" }, callable_mp(this, &CanvasItemEditor::_instantiate_scene));
+ EditorNode::get_singleton()->get_quick_open_dialog()->popup_dialog_for_instantiating_scenes(callable_mp(this, &CanvasItemEditor::_instantiate_scene));
} break;
case ADD_PASTE: {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();