This commit is contained in:
Spartan322
2024-12-15 09:24:31 -05:00
1031 changed files with 128643 additions and 5393 deletions

View File

@@ -34,6 +34,7 @@
#include "editor_interface.compat.inc"
#include "core/config/project_settings.h"
#include "editor/create_dialog.h"
#include "editor/editor_command_palette.h"
#include "editor/editor_feature_profile.h"
#include "editor/editor_main_screen.h"
@@ -514,6 +515,45 @@ void EditorInterface::popup_quick_open(const Callable &p_callback, const TypedAr
quick_open->popup_dialog(base_types, callable_mp(this, &EditorInterface::_quick_open).bind(p_callback));
}
void EditorInterface::popup_create_dialog(const Callable &p_callback, const StringName &p_base_type, const String &p_current_type, const String &p_dialog_title, const TypedArray<StringName> &p_custom_type_blocklist, const Dictionary &p_custom_suffix) {
if (!create_dialog) {
create_dialog = memnew(CreateDialog);
get_base_control()->add_child(create_dialog);
}
HashSet<StringName> blocklist;
for (const Variant &E : p_custom_type_blocklist) {
blocklist.insert(E);
}
create_dialog->set_type_blocklist(blocklist);
HashMap<StringName, String> suffix_map;
List<Variant> keys;
p_custom_suffix.get_key_list(&keys);
for (Variant &k : keys) {
const StringName key = k;
if (key.is_empty()) {
continue;
}
suffix_map.insert(key, p_custom_suffix[key]);
}
create_dialog->set_type_suffixes(suffix_map);
String safe_base_type = p_base_type;
if (p_base_type.is_empty() || (!ClassDB::class_exists(p_base_type) && !ScriptServer::is_global_class(p_base_type))) {
ERR_PRINT(vformat("Invalid base type '%s'. The base type has fallen back to 'Object'.", p_base_type));
safe_base_type = "Object";
}
create_dialog->set_base_type(safe_base_type);
create_dialog->popup_create(false, true, p_current_type, "");
create_dialog->set_title(p_dialog_title.is_empty() ? vformat(TTR("Create New %s"), p_base_type) : p_dialog_title);
const Callable callback = callable_mp(this, &EditorInterface::_create_dialog_item_selected);
create_dialog->connect(SNAME("create"), callback.bind(false, p_callback), CONNECT_DEFERRED);
create_dialog->connect(SNAME("canceled"), callback.bind(true, p_callback), CONNECT_DEFERRED);
}
void EditorInterface::_node_selected(const NodePath &p_node_path, const Callable &p_callback) {
const Callable callback = callable_mp(this, &EditorInterface::_node_selected);
node_selector->disconnect(SNAME("selected"), callback);
@@ -557,6 +597,13 @@ void EditorInterface::_quick_open(const String &p_file_path, const Callable &p_c
_call_dialog_callback(p_callback, p_file_path, "quick open");
}
void EditorInterface::_create_dialog_item_selected(bool p_is_canceled, const Callable &p_callback) {
const Callable callback = callable_mp(this, &EditorInterface::_create_dialog_item_selected);
create_dialog->disconnect(SNAME("create"), callback);
create_dialog->disconnect(SNAME("canceled"), callback);
_call_dialog_callback(p_callback, p_is_canceled ? "" : create_dialog->get_selected_type(), "create dialog");
}
void EditorInterface::_call_dialog_callback(const Callable &p_callback, const Variant &p_selected, const String &p_context) {
Callable::CallError ce;
Variant ret;
@@ -611,12 +658,12 @@ void EditorInterface::edit_script(const Ref<Script> &p_script, int p_line, int p
ScriptEditor::get_singleton()->edit(p_script, p_line - 1, p_col - 1, p_grab_focus);
}
void EditorInterface::open_scene_from_path(const String &scene_path) {
void EditorInterface::open_scene_from_path(const String &scene_path, bool p_set_inherited) {
if (EditorNode::get_singleton()->is_changing_scene()) {
return;
}
EditorNode::get_singleton()->open_request(scene_path);
EditorNode::get_singleton()->open_request(scene_path, p_set_inherited);
}
void EditorInterface::reload_scene_from_path(const String &scene_path) {
@@ -775,6 +822,7 @@ void EditorInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("popup_property_selector", "object", "callback", "type_filter", "current_value"), &EditorInterface::popup_property_selector, DEFVAL(PackedInt32Array()), DEFVAL(String()));
ClassDB::bind_method(D_METHOD("popup_method_selector", "object", "callback", "current_value"), &EditorInterface::popup_method_selector, DEFVAL(String()));
ClassDB::bind_method(D_METHOD("popup_quick_open", "callback", "base_types"), &EditorInterface::popup_quick_open, DEFVAL(TypedArray<StringName>()));
ClassDB::bind_method(D_METHOD("popup_create_dialog", "callback", "base_type", "current_type", "dialog_title", "type_blocklist", "type_suffixes"), &EditorInterface::popup_create_dialog, DEFVAL(""), DEFVAL(""), DEFVAL(""), DEFVAL(TypedArray<StringName>()), DEFVAL(Dictionary()));
// Editor docks.
@@ -793,7 +841,7 @@ void EditorInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("edit_resource", "resource"), &EditorInterface::edit_resource);
ClassDB::bind_method(D_METHOD("edit_node", "node"), &EditorInterface::edit_node);
ClassDB::bind_method(D_METHOD("edit_script", "script", "line", "column", "grab_focus"), &EditorInterface::edit_script, DEFVAL(-1), DEFVAL(0), DEFVAL(true));
ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath"), &EditorInterface::open_scene_from_path);
ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath", "set_inherited"), &EditorInterface::open_scene_from_path, DEFVAL(false));
ClassDB::bind_method(D_METHOD("reload_scene_from_path", "scene_filepath"), &EditorInterface::reload_scene_from_path);
ClassDB::bind_method(D_METHOD("get_open_scenes"), &EditorInterface::get_open_scenes);