|
@@ -39,8 +39,10 @@
|
|
#include "editor/editor_undo_redo_manager.h"
|
|
#include "editor/editor_undo_redo_manager.h"
|
|
#include "editor/filesystem_dock.h"
|
|
#include "editor/filesystem_dock.h"
|
|
#include "editor/gui/editor_run_bar.h"
|
|
#include "editor/gui/editor_run_bar.h"
|
|
|
|
+#include "editor/gui/scene_tree_editor.h"
|
|
#include "editor/inspector_dock.h"
|
|
#include "editor/inspector_dock.h"
|
|
#include "editor/plugins/node_3d_editor_plugin.h"
|
|
#include "editor/plugins/node_3d_editor_plugin.h"
|
|
|
|
+#include "editor/property_selector.h"
|
|
#include "editor/themes/editor_scale.h"
|
|
#include "editor/themes/editor_scale.h"
|
|
#include "main/main.h"
|
|
#include "main/main.h"
|
|
#include "scene/gui/box_container.h"
|
|
#include "scene/gui/box_container.h"
|
|
@@ -263,6 +265,93 @@ void EditorInterface::set_current_feature_profile(const String &p_profile_name)
|
|
EditorFeatureProfileManager::get_singleton()->set_current_profile(p_profile_name, true);
|
|
EditorFeatureProfileManager::get_singleton()->set_current_profile(p_profile_name, true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Editor dialogs.
|
|
|
|
+
|
|
|
|
+void EditorInterface::popup_node_selector(const Callable &p_callback, const TypedArray<StringName> &p_valid_types) {
|
|
|
|
+ // TODO: Should reuse dialog instance instead of creating a fresh one, but need to rework set_valid_types first.
|
|
|
|
+ if (node_selector) {
|
|
|
|
+ node_selector->disconnect(SNAME("selected"), callable_mp(this, &EditorInterface::_node_selected).bind(p_callback));
|
|
|
|
+ node_selector->disconnect(SNAME("canceled"), callable_mp(this, &EditorInterface::_node_selection_canceled).bind(p_callback));
|
|
|
|
+ get_base_control()->remove_child(node_selector);
|
|
|
|
+ node_selector->queue_free();
|
|
|
|
+ }
|
|
|
|
+ node_selector = memnew(SceneTreeDialog);
|
|
|
|
+
|
|
|
|
+ Vector<StringName> valid_types;
|
|
|
|
+ int length = p_valid_types.size();
|
|
|
|
+ valid_types.resize(length);
|
|
|
|
+ for (int i = 0; i < length; i++) {
|
|
|
|
+ valid_types.write[i] = p_valid_types[i];
|
|
|
|
+ }
|
|
|
|
+ node_selector->set_valid_types(valid_types);
|
|
|
|
+
|
|
|
|
+ get_base_control()->add_child(node_selector);
|
|
|
|
+
|
|
|
|
+ node_selector->popup_scenetree_dialog();
|
|
|
|
+
|
|
|
|
+ const Callable selected_callback = callable_mp(this, &EditorInterface::_node_selected).bind(p_callback);
|
|
|
|
+ node_selector->connect(SNAME("selected"), selected_callback, CONNECT_DEFERRED);
|
|
|
|
+
|
|
|
|
+ const Callable canceled_callback = callable_mp(this, &EditorInterface::_node_selection_canceled).bind(p_callback);
|
|
|
|
+ node_selector->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EditorInterface::popup_property_selector(Object *p_object, const Callable &p_callback, const PackedInt32Array &p_type_filter) {
|
|
|
|
+ // TODO: Should reuse dialog instance instead of creating a fresh one, but need to rework set_type_filter first.
|
|
|
|
+ if (property_selector) {
|
|
|
|
+ property_selector->disconnect(SNAME("selected"), callable_mp(this, &EditorInterface::_property_selected).bind(p_callback));
|
|
|
|
+ property_selector->disconnect(SNAME("canceled"), callable_mp(this, &EditorInterface::_property_selection_canceled).bind(p_callback));
|
|
|
|
+ get_base_control()->remove_child(property_selector);
|
|
|
|
+ property_selector->queue_free();
|
|
|
|
+ }
|
|
|
|
+ property_selector = memnew(PropertySelector);
|
|
|
|
+
|
|
|
|
+ Vector<Variant::Type> type_filter;
|
|
|
|
+ int length = p_type_filter.size();
|
|
|
|
+ type_filter.resize(length);
|
|
|
|
+ for (int i = 0; i < length; i++) {
|
|
|
|
+ type_filter.write[i] = (Variant::Type)p_type_filter[i];
|
|
|
|
+ }
|
|
|
|
+ property_selector->set_type_filter(type_filter);
|
|
|
|
+
|
|
|
|
+ get_base_control()->add_child(property_selector);
|
|
|
|
+
|
|
|
|
+ property_selector->select_property_from_instance(p_object);
|
|
|
|
+
|
|
|
|
+ const Callable selected_callback = callable_mp(this, &EditorInterface::_property_selected).bind(p_callback);
|
|
|
|
+ property_selector->connect(SNAME("selected"), selected_callback, CONNECT_DEFERRED);
|
|
|
|
+
|
|
|
|
+ const Callable canceled_callback = callable_mp(this, &EditorInterface::_property_selection_canceled).bind(p_callback);
|
|
|
|
+ property_selector->connect(SNAME("canceled"), canceled_callback, CONNECT_DEFERRED);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EditorInterface::_node_selected(const NodePath &p_node_path, const Callable &p_callback) {
|
|
|
|
+ const NodePath path = get_edited_scene_root()->get_path().rel_path_to(p_node_path);
|
|
|
|
+ _call_dialog_callback(p_callback, path, "node selected");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EditorInterface::_node_selection_canceled(const Callable &p_callback) {
|
|
|
|
+ _call_dialog_callback(p_callback, NodePath(), "node selection canceled");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EditorInterface::_property_selected(const String &p_property_name, const Callable &p_callback) {
|
|
|
|
+ _call_dialog_callback(p_callback, NodePath(p_property_name).get_as_property_path(), "property selected");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EditorInterface::_property_selection_canceled(const Callable &p_callback) {
|
|
|
|
+ _call_dialog_callback(p_callback, NodePath(), "property selection canceled");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void EditorInterface::_call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context) {
|
|
|
|
+ Callable::CallError ce;
|
|
|
|
+ Variant ret;
|
|
|
|
+ const Variant *args[1] = { &p_selected };
|
|
|
|
+ p_callback.callp(args, 1, ret, ce);
|
|
|
|
+ if (ce.error != Callable::CallError::CALL_OK) {
|
|
|
|
+ ERR_PRINT(vformat("Error calling %s callback: %s", p_context, Variant::get_callable_error_text(p_callback, args, 1, ce)));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// Editor docks.
|
|
// Editor docks.
|
|
|
|
|
|
FileSystemDock *EditorInterface::get_file_system_dock() const {
|
|
FileSystemDock *EditorInterface::get_file_system_dock() const {
|
|
@@ -458,6 +547,11 @@ void EditorInterface::_bind_methods() {
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "distraction_free_mode"), "set_distraction_free_mode", "is_distraction_free_mode_enabled");
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "distraction_free_mode"), "set_distraction_free_mode", "is_distraction_free_mode_enabled");
|
|
|
|
|
|
|
|
+ // Editor dialogs.
|
|
|
|
+
|
|
|
|
+ ClassDB::bind_method(D_METHOD("popup_node_selector", "callback", "valid_types"), &EditorInterface::popup_node_selector, DEFVAL(TypedArray<StringName>()));
|
|
|
|
+ ClassDB::bind_method(D_METHOD("popup_property_selector", "object", "callback", "type_filter"), &EditorInterface::popup_property_selector, DEFVAL(PackedInt32Array()));
|
|
|
|
+
|
|
// Editor docks.
|
|
// Editor docks.
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_file_system_dock"), &EditorInterface::get_file_system_dock);
|
|
ClassDB::bind_method(D_METHOD("get_file_system_dock"), &EditorInterface::get_file_system_dock);
|