diff options
Diffstat (limited to 'editor/editor_autoload_settings.cpp')
-rw-r--r-- | editor/editor_autoload_settings.cpp | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index 200ae7045f..12ae55fbc1 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -30,8 +30,8 @@ #include "editor_autoload_settings.h" -#include "core/global_constants.h" -#include "core/project_settings.h" +#include "core/config/project_settings.h" +#include "core/core_constants.h" #include "editor_node.h" #include "editor_scale.h" #include "project_settings_editor.h" @@ -89,8 +89,8 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin } } - for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { - if (GlobalConstants::get_global_constant_name(i) == p_name) { + for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) { + if (CoreConstants::get_global_constant_name(i) == p_name) { if (r_error) { *r_error = TTR("Invalid name.") + "\n" + TTR("Must not collide with an existing global constant name."); } @@ -327,7 +327,7 @@ void EditorAutoloadSettings::_autoload_file_callback(const String &p_path) { add_autoload->set_disabled(false); } -void EditorAutoloadSettings::_autoload_text_entered(const String p_name) { +void EditorAutoloadSettings::_autoload_text_submitted(const String p_name) { if (autoload_add_path->get_text() != "" && _autoload_name_is_valid(p_name, nullptr)) { _autoload_add(); } @@ -349,14 +349,14 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) { Node *n = nullptr; if (res->is_class("PackedScene")) { Ref<PackedScene> ps = res; - n = ps->instance(); + n = ps->instantiate(); } else if (res->is_class("Script")) { Ref<Script> s = res; StringName ibt = s->get_instance_base_type(); bool valid_type = ClassDB::is_parent_class(ibt, "Node"); ERR_FAIL_COND_V_MSG(!valid_type, nullptr, "Script does not inherit a Node: " + p_path + "."); - Object *obj = ClassDB::instance(ibt); + Object *obj = ClassDB::instantiate(ibt); ERR_FAIL_COND_V_MSG(obj == nullptr, nullptr, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt) + "."); @@ -402,7 +402,7 @@ void EditorAutoloadSettings::update_autoload() { String name = pi.name.get_slice("/", 1); String path = ProjectSettings::get_singleton()->get(pi.name); - if (name.empty()) { + if (name.is_empty()) { continue; } @@ -477,6 +477,8 @@ void EditorAutoloadSettings::update_autoload() { info.node->queue_delete(); info.node = nullptr; } + + ProjectSettings::get_singleton()->remove_autoload(info.name); } // Load new/changed autoloads @@ -503,6 +505,12 @@ void EditorAutoloadSettings::update_autoload() { } } + ProjectSettings::AutoloadInfo prop_info; + prop_info.name = info->name; + prop_info.path = info->path; + prop_info.is_singleton = info->is_singleton; + ProjectSettings::get_singleton()->add_autoload(prop_info); + if (!info->in_editor && !info->is_singleton) { // No reason to keep this node memdelete(info->node); @@ -674,18 +682,18 @@ bool EditorAutoloadSettings::autoload_add(const String &p_name, const String &p_ String error; if (!_autoload_name_is_valid(name, &error)) { - EditorNode::get_singleton()->show_warning(error); + EditorNode::get_singleton()->show_warning(TTR("Can't add autoload:") + "\n" + error); return false; } const String &path = p_path; if (!FileAccess::exists(path)) { - EditorNode::get_singleton()->show_warning(TTR("Invalid path.") + "\n" + TTR("File does not exist.")); + EditorNode::get_singleton()->show_warning(TTR("Can't add autoload:") + "\n" + vformat(TTR("%s is an invalid path. File does not exist."), path)); return false; } if (!path.begins_with("res://")) { - EditorNode::get_singleton()->show_warning(TTR("Invalid path.") + "\n" + TTR("Not in resource path.")); + EditorNode::get_singleton()->show_warning(TTR("Can't add autoload:") + "\n" + vformat(TTR("%s is an invalid path. Not in resource path (res://)."), path)); return false; } @@ -741,9 +749,9 @@ void EditorAutoloadSettings::autoload_remove(const String &p_name) { void EditorAutoloadSettings::_bind_methods() { ClassDB::bind_method("_autoload_open", &EditorAutoloadSettings::_autoload_open); - ClassDB::bind_method("get_drag_data_fw", &EditorAutoloadSettings::get_drag_data_fw); - ClassDB::bind_method("can_drop_data_fw", &EditorAutoloadSettings::can_drop_data_fw); - ClassDB::bind_method("drop_data_fw", &EditorAutoloadSettings::drop_data_fw); + ClassDB::bind_method("_get_drag_data_fw", &EditorAutoloadSettings::get_drag_data_fw); + ClassDB::bind_method("_can_drop_data_fw", &EditorAutoloadSettings::can_drop_data_fw); + ClassDB::bind_method("_drop_data_fw", &EditorAutoloadSettings::drop_data_fw); ClassDB::bind_method("update_autoload", &EditorAutoloadSettings::update_autoload); ClassDB::bind_method("autoload_add", &EditorAutoloadSettings::autoload_add); @@ -766,7 +774,7 @@ EditorAutoloadSettings::EditorAutoloadSettings() { String name = pi.name.get_slice("/", 1); String path = ProjectSettings::get_singleton()->get(pi.name); - if (name.empty()) { + if (name.is_empty()) { continue; } @@ -851,7 +859,7 @@ EditorAutoloadSettings::EditorAutoloadSettings() { autoload_add_name = memnew(LineEdit); autoload_add_name->set_h_size_flags(SIZE_EXPAND_FILL); - autoload_add_name->connect("text_entered", callable_mp(this, &EditorAutoloadSettings::_autoload_text_entered)); + autoload_add_name->connect("text_submitted", callable_mp(this, &EditorAutoloadSettings::_autoload_text_submitted)); autoload_add_name->connect("text_changed", callable_mp(this, &EditorAutoloadSettings::_autoload_text_changed)); hbc->add_child(autoload_add_name); @@ -874,18 +882,17 @@ EditorAutoloadSettings::EditorAutoloadSettings() { tree->set_column_title(0, TTR("Name")); tree->set_column_expand(0, true); - tree->set_column_min_width(0, 100); + tree->set_column_expand_ratio(0, 1); tree->set_column_title(1, TTR("Path")); tree->set_column_expand(1, true); - tree->set_column_min_width(1, 100); + tree->set_column_clip_content(1, true); + tree->set_column_expand_ratio(1, 2); - tree->set_column_title(2, TTR("Singleton")); + tree->set_column_title(2, TTR("Global Variable")); tree->set_column_expand(2, false); - tree->set_column_min_width(2, 80 * EDSCALE); tree->set_column_expand(3, false); - tree->set_column_min_width(3, 120 * EDSCALE); tree->connect("cell_selected", callable_mp(this, &EditorAutoloadSettings::_autoload_selected)); tree->connect("item_edited", callable_mp(this, &EditorAutoloadSettings::_autoload_edited)); @@ -907,9 +914,9 @@ EditorAutoloadSettings::~EditorAutoloadSettings() { void EditorAutoloadSettings::_set_autoload_add_path(const String &p_text) { autoload_add_path->set_text(p_text); - autoload_add_path->emit_signal("text_entered", p_text); + autoload_add_path->emit_signal("text_submitted", p_text); } void EditorAutoloadSettings::_browse_autoload_add_path() { - file_dialog->popup_centered_ratio(); -}
\ No newline at end of file + file_dialog->popup_file_dialog(); +} |