diff options
Diffstat (limited to 'editor')
195 files changed, 5838 insertions, 3709 deletions
diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp index 04c1c9951b..9126e0512e 100644 --- a/editor/action_map_editor.cpp +++ b/editor/action_map_editor.cpp @@ -581,7 +581,7 @@ void InputEventConfigurationDialog::set_allowed_input_types(int p_type_masks) { InputEventConfigurationDialog::InputEventConfigurationDialog() { allowed_input_types = INPUT_KEY | INPUT_MOUSE_BUTTON | INPUT_JOY_BUTTON | INPUT_JOY_MOTION; - set_title("Event Configuration"); + set_title(TTR("Event Configuration")); set_min_size(Size2i(550 * EDSCALE, 0)); // Min width VBoxContainer *main_vbox = memnew(VBoxContainer); @@ -595,7 +595,7 @@ InputEventConfigurationDialog::InputEventConfigurationDialog() { main_vbox->add_child(tab_container); CenterContainer *cc = memnew(CenterContainer); - cc->set_name("Listen for Input"); + cc->set_name(TTR("Listen for Input")); event_as_text = memnew(Label); event_as_text->set_align(Label::ALIGN_CENTER); cc->add_child(event_as_text); @@ -604,7 +604,7 @@ InputEventConfigurationDialog::InputEventConfigurationDialog() { // List of all input options to manually select from. VBoxContainer *manual_vbox = memnew(VBoxContainer); - manual_vbox->set_name("Manual Selection"); + manual_vbox->set_name(TTR("Manual Selection")); manual_vbox->set_v_size_flags(Control::SIZE_EXPAND_FILL); tab_container->add_child(manual_vbox); @@ -632,7 +632,7 @@ InputEventConfigurationDialog::InputEventConfigurationDialog() { Label *opts_label = memnew(Label); opts_label->set_theme_type_variation("HeaderSmall"); - opts_label->set_text("Additional Options"); + opts_label->set_text(TTR("Additional Options")); additional_options_container->add_child(opts_label); // Device Selection @@ -641,7 +641,7 @@ InputEventConfigurationDialog::InputEventConfigurationDialog() { Label *device_label = memnew(Label); device_label->set_theme_type_variation("HeaderSmall"); - device_label->set_text("Device:"); + device_label->set_text(TTR("Device:")); device_container->add_child(device_label); device_id_option = memnew(OptionButton); @@ -1039,7 +1039,7 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info // Third column - buttons action_item->add_button(2, action_tree->get_theme_icon(SNAME("Add"), SNAME("EditorIcons")), BUTTON_ADD_EVENT, false, TTR("Add Event")); - action_item->add_button(2, action_tree->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_ACTION, !action_info.editable, action_info.editable ? "Remove Action" : "Cannot Remove Action"); + action_item->add_button(2, action_tree->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_ACTION, !action_info.editable, action_info.editable ? TTR("Remove Action") : TTR("Cannot Remove Action")); action_item->set_custom_bg_color(0, action_tree->get_theme_color(SNAME("prop_subsection"), SNAME("Editor"))); action_item->set_custom_bg_color(1, action_tree->get_theme_color(SNAME("prop_subsection"), SNAME("Editor"))); diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 05db9045bd..1e3140e202 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -898,8 +898,7 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { } // 6-(undo) reinsert overlapped keys - for (List<AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) { - AnimMoveRestore &amr = E->get(); + for (const AnimMoveRestore &amr : to_restore) { undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, 1); } @@ -1091,9 +1090,9 @@ void AnimationBezierTrackEdit::duplicate_selection() { //reselect duplicated selection.clear(); - for (List<Pair<int, float>>::Element *E = new_selection_values.front(); E; E = E->next()) { - int track = E->get().first; - float time = E->get().second; + for (const Pair<int, float> &E : new_selection_values) { + int track = E.first; + float time = E.second; int existing_idx = animation->track_find_key(track, time, true); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 174f19280a..91835c1866 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -598,12 +598,12 @@ public: if (ap) { List<StringName> anims; ap->get_animation_list(&anims); - for (List<StringName>::Element *E = anims.front(); E; E = E->next()) { + for (const StringName &E : anims) { if (animations != String()) { animations += ","; } - animations += String(E->get()); + animations += String(E); } } } @@ -702,8 +702,8 @@ public: for (Map<int, List<float>>::Element *E = key_ofs_map.front(); E; E = E->next()) { int key = 0; - for (List<float>::Element *F = E->value().front(); F; F = F->next()) { - float key_ofs = F->get(); + for (float &F : E->value()) { + float key_ofs = F; if (from != key_ofs) { key++; continue; @@ -728,8 +728,8 @@ public: bool change_notify_deserved = false; for (Map<int, List<float>>::Element *E = key_ofs_map.front(); E; E = E->next()) { int track = E->key(); - for (List<float>::Element *F = E->value().front(); F; F = F->next()) { - float key_ofs = F->get(); + for (float &F : E->value()) { + float key_ofs = F; int key = animation->track_find_key(track, key_ofs, true); ERR_FAIL_COND_V(key == -1, false); @@ -986,8 +986,8 @@ public: bool _get(const StringName &p_name, Variant &r_ret) const { for (Map<int, List<float>>::Element *E = key_ofs_map.front(); E; E = E->next()) { int track = E->key(); - for (List<float>::Element *F = E->value().front(); F; F = F->next()) { - float key_ofs = F->get(); + for (float &F : E->value()) { + float key_ofs = F; int key = animation->track_find_key(track, key_ofs, true); ERR_CONTINUE(key == -1); @@ -1137,8 +1137,8 @@ public: same_key_type = false; } - for (List<float>::Element *F = E->value().front(); F; F = F->next()) { - int key = animation->track_find_key(track, F->get(), true); + for (float &F : E->value()) { + int key = animation->track_find_key(track, F, true); ERR_FAIL_COND(key == -1); if (first_key < 0) { first_key = key; @@ -3356,9 +3356,9 @@ void AnimationTrackEditor::_query_insert(const InsertData &p_id) { } insert_frame = Engine::get_singleton()->get_frames_drawn(); - for (List<InsertData>::Element *E = insert_data.front(); E; E = E->next()) { + for (const InsertData &E : insert_data) { //prevent insertion of multiple tracks - if (E->get().path == p_id.path) { + if (E.path == p_id.path) { return; //already inserted a track for this on this frame } } @@ -3843,9 +3843,9 @@ PropertyInfo AnimationTrackEditor::_find_hint_for_track(int p_idx, NodePath &r_b List<PropertyInfo> pinfo; property_info_base.get_property_list(&pinfo); - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().name == leftover_path[leftover_path.size() - 1]) { - return E->get(); + for (const PropertyInfo &E : pinfo) { + if (E.name == leftover_path[leftover_path.size() - 1]) { + return E; } } @@ -4675,21 +4675,21 @@ void AnimationTrackEditor::_add_method_key(const String &p_method) { List<MethodInfo> minfo; base->get_method_list(&minfo); - for (List<MethodInfo>::Element *E = minfo.front(); E; E = E->next()) { - if (E->get().name == p_method) { + for (const MethodInfo &E : minfo) { + if (E.name == p_method) { Dictionary d; d["method"] = p_method; Array params; - int first_defarg = E->get().arguments.size() - E->get().default_arguments.size(); + int first_defarg = E.arguments.size() - E.default_arguments.size(); - for (int i = 0; i < E->get().arguments.size(); i++) { + for (int i = 0; i < E.arguments.size(); i++) { if (i >= first_defarg) { - Variant arg = E->get().default_arguments[i - first_defarg]; + Variant arg = E.default_arguments[i - first_defarg]; params.push_back(arg); } else { Callable::CallError ce; Variant arg; - Variant::construct(E->get().arguments[i].type, arg, nullptr, 0, ce); + Variant::construct(E.arguments[i].type, arg, nullptr, 0, ce); params.push_back(arg); } } @@ -4936,8 +4936,7 @@ void AnimationTrackEditor::_move_selection_commit() { } // 6 - (undo) reinsert overlapped keys - for (List<_AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) { - _AnimMoveRestore &amr = E->get(); + for (_AnimMoveRestore &amr : to_restore) { undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, amr.transition); } @@ -5151,9 +5150,9 @@ void AnimationTrackEditor::_anim_duplicate_keys(bool transpose) { //reselect duplicated Map<SelectedKey, KeyInfo> new_selection; - for (List<Pair<int, float>>::Element *E = new_selection_values.front(); E; E = E->next()) { - int track = E->get().first; - float time = E->get().second; + for (const Pair<int, float> &E : new_selection_values) { + int track = E.first; + float time = E.second; int existing_idx = animation->track_find_key(track, time, true); @@ -5462,8 +5461,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { } // 6-(undo) reinsert overlapped keys - for (List<_AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) { - _AnimMoveRestore &amr = E->get(); + for (_AnimMoveRestore &amr : to_restore) { undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, amr.transition); } @@ -5543,8 +5541,8 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { if (cleanup_all->is_pressed()) { List<StringName> names; AnimationPlayerEditor::singleton->get_player()->get_animation_list(&names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - _cleanup_animation(AnimationPlayerEditor::singleton->get_player()->get_animation(E->get())); + for (const StringName &E : names) { + _cleanup_animation(AnimationPlayerEditor::singleton->get_player()->get_animation(E)); } } else { _cleanup_animation(animation); diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index b0ec346afe..285084a72b 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -31,6 +31,7 @@ #include "code_editor.h" #include "core/input/input.h" +#include "core/object/message_queue.h" #include "core/os/keyboard.h" #include "core/string/string_builder.h" #include "editor/editor_scale.h" @@ -854,9 +855,7 @@ void CodeTextEditor::_complete_request() { return; } - for (List<ScriptCodeCompletionOption>::Element *E = entries.front(); E; E = E->next()) { - ScriptCodeCompletionOption &e = E->get(); - + for (const ScriptCodeCompletionOption &e : entries) { Color font_color = completion_font_color; if (e.insert_text.begins_with("\"") || e.insert_text.begins_with("\'")) { font_color = completion_string_color; @@ -1569,6 +1568,17 @@ void CodeTextEditor::_update_font() { } void CodeTextEditor::_on_settings_change() { + if (settings_changed) { + return; + } + + settings_changed = true; + MessageQueue::get_singleton()->push_callable(callable_mp(this, &CodeTextEditor::_apply_settings_change)); +} + +void CodeTextEditor::_apply_settings_change() { + settings_changed = false; + _update_text_editor_theme(); _update_font(); diff --git a/editor/code_editor.h b/editor/code_editor.h index 0e5a84b3d5..4cd4880df0 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -162,7 +162,10 @@ class CodeTextEditor : public VBoxContainer { int error_line; int error_column; + bool settings_changed = false; + void _on_settings_change(); + void _apply_settings_change(); void _update_text_editor_theme(); void _update_font(); diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index c439d6a1d4..c773f51342 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -944,9 +944,7 @@ void ConnectionsDock::update_tree() { node_signals2.sort(); } - for (List<MethodInfo>::Element *E = node_signals2.front(); E; E = E->next()) { - MethodInfo &mi = E->get(); - + for (MethodInfo &mi : node_signals2) { StringName signal_name = mi.name; String signaldesc = "("; PackedStringArray argnames; @@ -1025,8 +1023,8 @@ void ConnectionsDock::update_tree() { List<Object::Connection> connections; selectedNode->get_signal_connection_list(signal_name, &connections); - for (List<Object::Connection>::Element *F = connections.front(); F; F = F->next()) { - Connection cn = F->get(); + for (const Object::Connection &F : connections) { + Connection cn = F; if (!(cn.flags & CONNECT_PERSIST)) { continue; } diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 3b002961f9..3389b53317 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -195,7 +195,8 @@ void CreateDialog::_update_search() { select_type(_top_result(candidates, search_text)); } else { favorite->set_disabled(true); - help_bit->set_text(""); + help_bit->set_text(vformat(TTR("No results for \"%s\"."), search_text)); + help_bit->get_rich_text()->set_self_modulate(Color(1, 1, 1, 0.5)); get_ok_button()->set_disabled(true); search_options->deselect_all(); } @@ -393,8 +394,15 @@ void CreateDialog::select_type(const String &p_type) { to_select->select(0); search_options->scroll_to_item(to_select); - if (EditorHelp::get_doc_data()->class_list.has(p_type)) { - help_bit->set_text(DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description)); + if (EditorHelp::get_doc_data()->class_list.has(p_type) && !DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description).is_empty()) { + // Display both class name and description, since the help bit may be displayed + // far away from the location (especially if the dialog was resized to be taller). + help_bit->set_text(vformat("[b]%s[/b]: %s", p_type, DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description))); + help_bit->get_rich_text()->set_self_modulate(Color(1, 1, 1, 1)); + } else { + // Use nested `vformat()` as translators shouldn't interfere with BBCode tags. + help_bit->set_text(vformat(TTR("No description available for %s."), vformat("[b]%s[/b]", p_type))); + help_bit->get_rich_text()->set_self_modulate(Color(1, 1, 1, 0.5)); } favorite->set_disabled(false); @@ -439,8 +447,7 @@ Variant CreateDialog::instance_selected() { List<PropertyInfo> pinfo; ((Object *)obj)->get_property_list(&pinfo); - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - PropertyInfo pi = E->get(); + for (const PropertyInfo &pi : pinfo) { if (pi.type == Variant::OBJECT && pi.usage & PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT) { Object *prop = ClassDB::instantiate(pi.class_name); ((Object *)obj)->set(pi.name, prop); diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp index a629bf6159..a1eb71235c 100644 --- a/editor/debugger/editor_debugger_inspector.cpp +++ b/editor/debugger/editor_debugger_inspector.cpp @@ -56,8 +56,8 @@ bool EditorDebuggerRemoteObject::_get(const StringName &p_name, Variant &r_ret) void EditorDebuggerRemoteObject::_get_property_list(List<PropertyInfo> *p_list) const { p_list->clear(); //sorry, no want category - for (const List<PropertyInfo>::Element *E = prop_list.front(); E; E = E->next()) { - p_list->push_back(E->get()); + for (const PropertyInfo &E : prop_list) { + p_list->push_back(E); } } diff --git a/editor/debugger/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp index 6b015e1fda..fa9c9f61f5 100644 --- a/editor/debugger/editor_profiler.cpp +++ b/editor/debugger/editor_profiler.cpp @@ -588,8 +588,8 @@ EditorProfiler::EditorProfiler() { hb->add_child(memnew(Label(TTR("Measure:")))); display_mode = memnew(OptionButton); - display_mode->add_item(TTR("Frame Time (sec)")); - display_mode->add_item(TTR("Average Time (sec)")); + display_mode->add_item(TTR("Frame Time (ms)")); + display_mode->add_item(TTR("Average Time (ms)")); display_mode->add_item(TTR("Frame %")); display_mode->add_item(TTR("Physics Frame %")); display_mode->connect("item_selected", callable_mp(this, &EditorProfiler::_combo_changed)); @@ -601,6 +601,7 @@ EditorProfiler::EditorProfiler() { display_time = memnew(OptionButton); display_time->add_item(TTR("Inclusive")); display_time->add_item(TTR("Self")); + display_time->set_tooltip(TTR("Inclusive: Includes time from other functions called by this function.\nUse this to spot bottlenecks.\n\nSelf: Only count the time spent in the function itself, not in other functions called by that function.\nUse this to find individual functions to optimize.")); display_time->connect("item_selected", callable_mp(this, &EditorProfiler::_combo_changed)); hb->add_child(display_time); diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index a61e9bd73e..f17ad0d36c 100644 --- a/editor/debugger/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -365,13 +365,13 @@ void EditorVisualProfiler::_update_frame(bool p_focus_selected) { } TreeItem *category = variables->create_item(parent); - for (List<TreeItem *>::Element *E = stack.front(); E; E = E->next()) { - float total_cpu = E->get()->get_metadata(1); - float total_gpu = E->get()->get_metadata(2); + for (TreeItem *E : stack) { + float total_cpu = E->get_metadata(1); + float total_gpu = E->get_metadata(2); total_cpu += cpu_time; total_gpu += gpu_time; - E->get()->set_metadata(1, cpu_time); - E->get()->set_metadata(2, gpu_time); + E->set_metadata(1, cpu_time); + E->set_metadata(2, gpu_time); } category->set_icon(0, track_icon); @@ -392,11 +392,11 @@ void EditorVisualProfiler::_update_frame(bool p_focus_selected) { } } - for (List<TreeItem *>::Element *E = categories.front(); E; E = E->next()) { - float total_cpu = E->get()->get_metadata(1); - float total_gpu = E->get()->get_metadata(2); - E->get()->set_text(1, _get_time_as_text(total_cpu)); - E->get()->set_text(2, _get_time_as_text(total_gpu)); + for (TreeItem *E : categories) { + float total_cpu = E->get_metadata(1); + float total_gpu = E->get_metadata(2); + E->set_text(1, _get_time_as_text(total_cpu)); + E->set_text(2, _get_time_as_text(total_gpu)); } if (ensure_selected) { diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index e704609639..9856fbec74 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -347,13 +347,13 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da uint64_t total = 0; - for (List<DebuggerMarshalls::ResourceInfo>::Element *E = usage.infos.front(); E; E = E->next()) { + for (const DebuggerMarshalls::ResourceInfo &E : usage.infos) { TreeItem *it = vmem_tree->create_item(root); - String type = E->get().type; - int bytes = E->get().vram; - it->set_text(0, E->get().path); + String type = E.type; + int bytes = E.vram; + it->set_text(0, E.path); it->set_text(1, type); - it->set_text(2, E->get().format); + it->set_text(2, E.format); it->set_text(3, String::humanize_size(bytes)); total += bytes; @@ -793,7 +793,7 @@ void ScriptEditorDebugger::_notification(int p_what) { } else if (camera_override >= CameraOverride::OVERRIDE_3D_1) { int viewport_idx = camera_override - CameraOverride::OVERRIDE_3D_1; Node3DEditorViewport *viewport = Node3DEditor::get_singleton()->get_editor_viewport(viewport_idx); - Camera3D *const cam = viewport->get_camera(); + Camera3D *const cam = viewport->get_camera_3d(); Array msg; msg.push_back(cam->get_camera_transform()); diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index c18b8743cd..069ae2c7f2 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -55,8 +55,8 @@ void DependencyEditor::_load_pressed(Object *p_item, int p_cell, int p_button) { search->clear_filters(); List<String> ext; ResourceLoader::get_recognized_extensions_for_type(ti->get_metadata(0), &ext); - for (List<String>::Element *E = ext.front(); E; E = E->next()) { - search->add_filter("*" + E->get()); + for (const String &E : ext) { + search->add_filter("*" + E); } search->popup_file_dialog(); } @@ -120,13 +120,13 @@ void DependencyEditor::_fix_all() { Map<String, Map<String, String>> candidates; - for (List<String>::Element *E = missing.front(); E; E = E->next()) { - String base = E->get().get_file(); + for (const String &E : missing) { + String base = E.get_file(); if (!candidates.has(base)) { candidates[base] = Map<String, String>(); } - candidates[base][E->get()] = ""; + candidates[base][E] = ""; } _fix_and_find(EditorFileSystem::get_singleton()->get_filesystem(), candidates); @@ -166,10 +166,8 @@ void DependencyEditor::_update_list() { bool broken = false; - for (List<String>::Element *E = deps.front(); E; E = E->next()) { + for (const String &n : deps) { TreeItem *item = tree->create_item(root); - - String n = E->get(); String path; String type; @@ -180,6 +178,15 @@ void DependencyEditor::_update_list() { path = n; type = "Resource"; } + + ResourceUID::ID uid = ResourceUID::get_singleton()->text_to_id(path); + if (uid != ResourceUID::INVALID_ID) { + // dependency is in uid format, obtain proper path + ERR_CONTINUE(!ResourceUID::get_singleton()->has_id(uid)); + + path = ResourceUID::get_singleton()->get_id_path(uid); + } + String name = path.get_file(); Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(type); @@ -741,9 +748,9 @@ void OrphanResourcesDialog::_find_to_delete(TreeItem *p_item, List<String> &path void OrphanResourcesDialog::_delete_confirm() { DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); - for (List<String>::Element *E = paths.front(); E; E = E->next()) { - da->remove(E->get()); - EditorFileSystem::get_singleton()->update_file(E->get()); + for (const String &E : paths) { + da->remove(E); + EditorFileSystem::get_singleton()->update_file(E); } memdelete(da); refresh(); diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index befafec6cb..c752d0d4fd 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -266,20 +266,20 @@ void DocTools::generate(bool p_basic_types) { } List<PropertyInfo>::Element *EO = own_properties.front(); - for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { + for (const PropertyInfo &E : properties) { bool inherited = EO == nullptr; - if (EO && EO->get() == E->get()) { + if (EO && EO->get() == E) { inherited = false; EO = EO->next(); } - if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL) { + if (E.usage & PROPERTY_USAGE_GROUP || E.usage & PROPERTY_USAGE_SUBGROUP || E.usage & PROPERTY_USAGE_CATEGORY || E.usage & PROPERTY_USAGE_INTERNAL) { continue; } DocData::PropertyDoc prop; - prop.name = E->get().name; + prop.name = E.name; prop.overridden = inherited; @@ -288,20 +288,20 @@ void DocTools::generate(bool p_basic_types) { if (name == "ProjectSettings") { // Special case for project settings, so that settings are not taken from the current project's settings - if (E->get().name == "script" || !ProjectSettings::get_singleton()->is_builtin_setting(E->get().name)) { + if (E.name == "script" || !ProjectSettings::get_singleton()->is_builtin_setting(E.name)) { continue; } - if (E->get().usage & PROPERTY_USAGE_EDITOR) { - if (!ProjectSettings::get_singleton()->get_ignore_value_in_docs(E->get().name)) { - default_value = ProjectSettings::get_singleton()->property_get_revert(E->get().name); + if (E.usage & PROPERTY_USAGE_EDITOR) { + if (!ProjectSettings::get_singleton()->get_ignore_value_in_docs(E.name)) { + default_value = ProjectSettings::get_singleton()->property_get_revert(E.name); default_value_valid = true; } } } else { - default_value = get_documentation_default_value(name, E->get().name, default_value_valid); + default_value = get_documentation_default_value(name, E.name, default_value_valid); if (inherited) { bool base_default_value_valid = false; - Variant base_default_value = get_documentation_default_value(ClassDB::get_parent_class(name), E->get().name, base_default_value_valid); + Variant base_default_value = get_documentation_default_value(ClassDB::get_parent_class(name), E.name, base_default_value_valid); if (!default_value_valid || !base_default_value_valid || default_value == base_default_value) { continue; } @@ -309,13 +309,13 @@ void DocTools::generate(bool p_basic_types) { } //used to track uninitialized values using valgrind - //print_line("getting default value for " + String(name) + "." + String(E->get().name)); + //print_line("getting default value for " + String(name) + "." + String(E.name)); if (default_value_valid && default_value.get_type() != Variant::OBJECT) { prop.default_value = default_value.get_construct_string().replace("\n", ""); } - StringName setter = ClassDB::get_property_setter(name, E->get().name); - StringName getter = ClassDB::get_property_getter(name, E->get().name); + StringName setter = ClassDB::get_property_setter(name, E.name); + StringName getter = ClassDB::get_property_getter(name, E.name); prop.setter = setter; prop.getter = getter; @@ -353,10 +353,10 @@ void DocTools::generate(bool p_basic_types) { } if (!found_type) { - if (E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE) { - prop.type = E->get().hint_string; + if (E.type == Variant::OBJECT && E.hint == PROPERTY_HINT_RESOURCE_TYPE) { + prop.type = E.hint_string; } else { - prop.type = Variant::get_type_name(E->get().type); + prop.type = Variant::get_type_name(E.type); } } @@ -367,62 +367,62 @@ void DocTools::generate(bool p_basic_types) { ClassDB::get_method_list(name, &method_list, true); method_list.sort(); - for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) { - if (E->get().name == "" || (E->get().name[0] == '_' && !(E->get().flags & METHOD_FLAG_VIRTUAL))) { + for (const MethodInfo &E : method_list) { + if (E.name == "" || (E.name[0] == '_' && !(E.flags & METHOD_FLAG_VIRTUAL))) { continue; //hidden, don't count } - if (skip_setter_getter_methods && setters_getters.has(E->get().name)) { + if (skip_setter_getter_methods && setters_getters.has(E.name)) { // Don't skip parametric setters and getters, i.e. method which require // one or more parameters to define what property should be set or retrieved. // E.g. CPUParticles3D::set_param(Parameter param, float value). - if (E->get().arguments.size() == 0 /* getter */ || (E->get().arguments.size() == 1 && E->get().return_val.type == Variant::NIL /* setter */)) { + if (E.arguments.size() == 0 /* getter */ || (E.arguments.size() == 1 && E.return_val.type == Variant::NIL /* setter */)) { continue; } } DocData::MethodDoc method; - method.name = E->get().name; + method.name = E.name; - if (E->get().flags & METHOD_FLAG_VIRTUAL) { + if (E.flags & METHOD_FLAG_VIRTUAL) { method.qualifiers = "virtual"; } - if (E->get().flags & METHOD_FLAG_CONST) { + if (E.flags & METHOD_FLAG_CONST) { if (method.qualifiers != "") { method.qualifiers += " "; } method.qualifiers += "const"; } - if (E->get().flags & METHOD_FLAG_VARARG) { + if (E.flags & METHOD_FLAG_VARARG) { if (method.qualifiers != "") { method.qualifiers += " "; } method.qualifiers += "vararg"; } - if (E->get().flags & METHOD_FLAG_STATIC) { + if (E.flags & METHOD_FLAG_STATIC) { if (method.qualifiers != "") { method.qualifiers += " "; } method.qualifiers += "static"; } - for (int i = -1; i < E->get().arguments.size(); i++) { + for (int i = -1; i < E.arguments.size(); i++) { if (i == -1) { #ifdef DEBUG_METHODS_ENABLED - DocData::return_doc_from_retinfo(method, E->get().return_val); + DocData::return_doc_from_retinfo(method, E.return_val); #endif } else { - const PropertyInfo &arginfo = E->get().arguments[i]; + const PropertyInfo &arginfo = E.arguments[i]; DocData::ArgumentDoc argument; DocData::argument_doc_from_arginfo(argument, arginfo); - int darg_idx = i - (E->get().arguments.size() - E->get().default_arguments.size()); + int darg_idx = i - (E.arguments.size() - E.default_arguments.size()); if (darg_idx >= 0) { - Variant default_arg = E->get().default_arguments[darg_idx]; + Variant default_arg = E.default_arguments[darg_idx]; argument.default_value = default_arg.get_construct_string(); } @@ -455,12 +455,12 @@ void DocTools::generate(bool p_basic_types) { List<String> constant_list; ClassDB::get_integer_constant_list(name, &constant_list, true); - for (List<String>::Element *E = constant_list.front(); E; E = E->next()) { + for (const String &E : constant_list) { DocData::ConstantDoc constant; - constant.name = E->get(); - constant.value = itos(ClassDB::get_integer_constant(name, E->get())); + constant.name = E; + constant.value = itos(ClassDB::get_integer_constant(name, E)); constant.is_value_valid = true; - constant.enumeration = ClassDB::get_integer_constant_enum(name, E->get()); + constant.enumeration = ClassDB::get_integer_constant_enum(name, E); c.constants.push_back(constant); } @@ -469,53 +469,53 @@ void DocTools::generate(bool p_basic_types) { { List<StringName> l; Theme::get_default()->get_constant_list(cname, &l); - for (List<StringName>::Element *E = l.front(); E; E = E->next()) { + for (const StringName &E : l) { DocData::PropertyDoc pd; - pd.name = E->get(); + pd.name = E; pd.type = "int"; - pd.default_value = itos(Theme::get_default()->get_constant(E->get(), cname)); + pd.default_value = itos(Theme::get_default()->get_constant(E, cname)); c.theme_properties.push_back(pd); } l.clear(); Theme::get_default()->get_color_list(cname, &l); - for (List<StringName>::Element *E = l.front(); E; E = E->next()) { + for (const StringName &E : l) { DocData::PropertyDoc pd; - pd.name = E->get(); + pd.name = E; pd.type = "Color"; - pd.default_value = Variant(Theme::get_default()->get_color(E->get(), cname)).get_construct_string(); + pd.default_value = Variant(Theme::get_default()->get_color(E, cname)).get_construct_string(); c.theme_properties.push_back(pd); } l.clear(); Theme::get_default()->get_icon_list(cname, &l); - for (List<StringName>::Element *E = l.front(); E; E = E->next()) { + for (const StringName &E : l) { DocData::PropertyDoc pd; - pd.name = E->get(); + pd.name = E; pd.type = "Texture2D"; c.theme_properties.push_back(pd); } l.clear(); Theme::get_default()->get_font_list(cname, &l); - for (List<StringName>::Element *E = l.front(); E; E = E->next()) { + for (const StringName &E : l) { DocData::PropertyDoc pd; - pd.name = E->get(); + pd.name = E; pd.type = "Font"; c.theme_properties.push_back(pd); } l.clear(); Theme::get_default()->get_font_size_list(cname, &l); - for (List<StringName>::Element *E = l.front(); E; E = E->next()) { + for (const StringName &E : l) { DocData::PropertyDoc pd; - pd.name = E->get(); + pd.name = E; pd.type = "int"; c.theme_properties.push_back(pd); } l.clear(); Theme::get_default()->get_stylebox_list(cname, &l); - for (List<StringName>::Element *E = l.front(); E; E = E->next()) { + for (const StringName &E : l) { DocData::PropertyDoc pd; - pd.name = E->get(); + pd.name = E; pd.type = "StyleBox"; c.theme_properties.push_back(pd); } @@ -621,8 +621,7 @@ void DocTools::generate(bool p_basic_types) { method_list.push_back(mi); } - for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) { - MethodInfo &mi = E->get(); + for (const MethodInfo &mi : method_list) { DocData::MethodDoc method; method.name = mi.name; @@ -675,8 +674,7 @@ void DocTools::generate(bool p_basic_types) { List<PropertyInfo> properties; v.get_property_list(&properties); - for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { - PropertyInfo pi = E->get(); + for (const PropertyInfo &pi : properties) { DocData::PropertyDoc property; property.name = pi.name; property.type = Variant::get_type_name(pi.type); @@ -688,10 +686,10 @@ void DocTools::generate(bool p_basic_types) { List<StringName> constants; Variant::get_constants_for_type(Variant::Type(i), &constants); - for (List<StringName>::Element *E = constants.front(); E; E = E->next()) { + for (const StringName &E : constants) { DocData::ConstantDoc constant; - constant.name = E->get(); - Variant value = Variant::get_constant_value(Variant::Type(i), E->get()); + constant.name = E; + Variant value = Variant::get_constant_value(Variant::Type(i), E); constant.value = value.get_type() == Variant::INT ? itos(value) : value.get_construct_string(); constant.is_value_valid = true; c.constants.push_back(constant); @@ -723,9 +721,8 @@ void DocTools::generate(bool p_basic_types) { Engine::get_singleton()->get_singletons(&singletons); //servers (this is kind of hackish) - for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) { + for (const Engine::Singleton &s : singletons) { DocData::PropertyDoc pd; - Engine::Singleton &s = E->get(); if (!s.ptr) { continue; } @@ -743,13 +740,13 @@ void DocTools::generate(bool p_basic_types) { List<StringName> utility_functions; Variant::get_utility_function_list(&utility_functions); utility_functions.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = utility_functions.front(); E; E = E->next()) { + for (const StringName &E : utility_functions) { DocData::MethodDoc md; - md.name = E->get(); + md.name = E; //return - if (Variant::has_utility_function_return_value(E->get())) { + if (Variant::has_utility_function_return_value(E)) { PropertyInfo pi; - pi.type = Variant::get_utility_function_return_type(E->get()); + pi.type = Variant::get_utility_function_return_type(E); if (pi.type == Variant::NIL) { pi.usage = PROPERTY_USAGE_NIL_IS_VARIANT; } @@ -758,13 +755,13 @@ void DocTools::generate(bool p_basic_types) { md.return_type = ad.type; } - if (Variant::is_utility_function_vararg(E->get())) { + if (Variant::is_utility_function_vararg(E)) { md.qualifiers = "vararg"; } else { - for (int i = 0; i < Variant::get_utility_function_argument_count(E->get()); i++) { + for (int i = 0; i < Variant::get_utility_function_argument_count(E); i++) { PropertyInfo pi; - pi.type = Variant::get_utility_function_argument_type(E->get(), i); - pi.name = Variant::get_utility_function_argument_name(E->get(), i); + pi.type = Variant::get_utility_function_argument_type(E, i); + pi.name = Variant::get_utility_function_argument_name(E, i); if (pi.type == Variant::NIL) { pi.usage = PROPERTY_USAGE_NIL_IS_VARIANT; } @@ -793,8 +790,7 @@ void DocTools::generate(bool p_basic_types) { List<MethodInfo> minfo; lang->get_public_functions(&minfo); - for (List<MethodInfo>::Element *E = minfo.front(); E; E = E->next()) { - MethodInfo &mi = E->get(); + for (const MethodInfo &mi : minfo) { DocData::MethodDoc md; md.name = mi.name; @@ -813,7 +809,7 @@ void DocTools::generate(bool p_basic_types) { int darg_idx = j - (mi.arguments.size() - mi.default_arguments.size()); if (darg_idx >= 0) { - Variant default_arg = E->get().default_arguments[darg_idx]; + Variant default_arg = mi.default_arguments[darg_idx]; ad.default_value = default_arg.get_construct_string(); } @@ -827,10 +823,10 @@ void DocTools::generate(bool p_basic_types) { List<Pair<String, Variant>> cinfo; lang->get_public_constants(&cinfo); - for (List<Pair<String, Variant>>::Element *E = cinfo.front(); E; E = E->next()) { + for (const Pair<String, Variant> &E : cinfo) { DocData::ConstantDoc cd; - cd.name = E->get().first; - cd.value = E->get().second; + cd.name = E.first; + cd.value = E.second; cd.is_value_valid = true; c.constants.push_back(cd); } @@ -1212,8 +1208,7 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str if (m.return_enum != String()) { enum_text = " enum=\"" + m.return_enum + "\""; } - _write_string(f, 3, "<return type=\"" + m.return_type + "\"" + enum_text + ">"); - _write_string(f, 3, "</return>"); + _write_string(f, 3, "<return type=\"" + m.return_type + "\"" + enum_text + " />"); } for (int j = 0; j < m.arguments.size(); j++) { @@ -1225,12 +1220,10 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str } if (a.default_value != "") { - _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " default=\"" + a.default_value.xml_escape(true) + "\">"); + _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " default=\"" + a.default_value.xml_escape(true) + "\" />"); } else { - _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + ">"); + _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " />"); } - - _write_string(f, 3, "</argument>"); } _write_string(f, 3, "<description>"); @@ -1278,8 +1271,7 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str _write_string(f, 2, "<signal name=\"" + m.name + "\">"); for (int j = 0; j < m.arguments.size(); j++) { const DocData::ArgumentDoc &a = m.arguments[j]; - _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\">"); - _write_string(f, 3, "</argument>"); + _write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\" />"); } _write_string(f, 3, "<description>"); diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index d94ac21837..4a19f007d4 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -920,15 +920,15 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) { List<StringName> effects; ClassDB::get_inheriters_from_class("AudioEffect", &effects); effects.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = effects.front(); E; E = E->next()) { - if (!ClassDB::can_instantiate(E->get())) { + for (const StringName &E : effects) { + if (!ClassDB::can_instantiate(E)) { continue; } - Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(E->get()); - String name = E->get().operator String().replace("AudioEffect", ""); + Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(E); + String name = E.operator String().replace("AudioEffect", ""); effect_options->add_item(name); - effect_options->set_item_metadata(effect_options->get_item_count() - 1, E->get()); + effect_options->set_item_metadata(effect_options->get_item_count() - 1, E); effect_options->set_item_icon(effect_options->get_item_count() - 1, icon); } @@ -1331,8 +1331,8 @@ EditorAudioBuses::EditorAudioBuses() { file_dialog = memnew(EditorFileDialog); List<String> ext; ResourceLoader::get_recognized_extensions_for_type("AudioBusLayout", &ext); - for (List<String>::Element *E = ext.front(); E; E = E->next()) { - file_dialog->add_filter("*." + E->get() + "; Audio Bus Layout"); + for (const String &E : ext) { + file_dialog->add_filter("*." + E + "; Audio Bus Layout"); } add_child(file_dialog); file_dialog->connect("file_selected", callable_mp(this, &EditorAudioBuses::_file_dialog_callback)); diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index c6d52107cd..fad76682b5 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -46,12 +46,11 @@ void EditorAutoloadSettings::_notification(int p_what) { ResourceLoader::get_recognized_extensions_for_type("Script", &afn); ResourceLoader::get_recognized_extensions_for_type("PackedScene", &afn); - for (List<String>::Element *E = afn.front(); E; E = E->next()) { - file_dialog->add_filter("*." + E->get()); + for (const String &E : afn) { + file_dialog->add_filter("*." + E); } - for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) { - AutoLoadInfo &info = E->get(); + for (const AutoLoadInfo &info : autoload_cache) { if (info.node && info.in_editor) { get_tree()->get_root()->call_deferred(SNAME("add_child"), info.node); } @@ -102,8 +101,8 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin for (int i = 0; i < ScriptServer::get_language_count(); i++) { List<String> keywords; ScriptServer::get_language(i)->get_reserved_words(&keywords); - for (List<String>::Element *E = keywords.front(); E; E = E->next()) { - if (E->get() == p_name) { + for (const String &E : keywords) { + if (E == p_name) { if (r_error) { *r_error = TTR("Invalid name.") + "\n" + TTR("Keyword cannot be used as an autoload name."); } @@ -379,8 +378,7 @@ void EditorAutoloadSettings::update_autoload() { Map<String, AutoLoadInfo> to_remove; List<AutoLoadInfo *> to_add; - for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) { - AutoLoadInfo &info = E->get(); + for (const AutoLoadInfo &info : autoload_cache) { to_remove.insert(info.name, info); } @@ -392,9 +390,7 @@ void EditorAutoloadSettings::update_autoload() { List<PropertyInfo> props; ProjectSettings::get_singleton()->get_property_list(&props); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - const PropertyInfo &pi = E->get(); - + for (const PropertyInfo &pi : props) { if (!pi.name.begins_with("autoload/")) { continue; } @@ -483,9 +479,7 @@ void EditorAutoloadSettings::update_autoload() { // Load new/changed autoloads List<Node *> nodes_to_add; - for (List<AutoLoadInfo *>::Element *E = to_add.front(); E; E = E->next()) { - AutoLoadInfo *info = E->get(); - + for (AutoLoadInfo *info : to_add) { info->node = _create_autoload(info->path); ERR_CONTINUE(!info->node); @@ -518,8 +512,8 @@ void EditorAutoloadSettings::update_autoload() { } } - for (List<Node *>::Element *E = nodes_to_add.front(); E; E = E->next()) { - get_tree()->get_root()->add_child(E->get()); + for (Node *E : nodes_to_add) { + get_tree()->get_root()->add_child(E); } updating_autoload = false; @@ -649,8 +643,8 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant & int i = 0; - for (List<AutoLoadInfo>::Element *F = autoload_cache.front(); F; F = F->next()) { - orders.write[i++] = F->get().order; + for (const AutoLoadInfo &F : autoload_cache) { + orders.write[i++] = F.order; } orders.sort(); @@ -661,9 +655,9 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant & i = 0; - for (List<AutoLoadInfo>::Element *F = autoload_cache.front(); F; F = F->next()) { - undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F->get().name, orders[i++]); - undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F->get().name, F->get().order); + for (const AutoLoadInfo &F : autoload_cache) { + undo_redo->add_do_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F.name, orders[i++]); + undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set_order", "autoload/" + F.name, F.order); } orders.clear(); @@ -764,9 +758,7 @@ EditorAutoloadSettings::EditorAutoloadSettings() { // Make first cache List<PropertyInfo> props; ProjectSettings::get_singleton()->get_property_list(&props); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - const PropertyInfo &pi = E->get(); - + for (const PropertyInfo &pi : props) { if (!pi.name.begins_with("autoload/")) { continue; } @@ -799,9 +791,7 @@ EditorAutoloadSettings::EditorAutoloadSettings() { autoload_cache.push_back(info); } - for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) { - AutoLoadInfo &info = E->get(); - + for (AutoLoadInfo &info : autoload_cache) { info.node = _create_autoload(info.path); if (info.node) { @@ -904,8 +894,7 @@ EditorAutoloadSettings::EditorAutoloadSettings() { } EditorAutoloadSettings::~EditorAutoloadSettings() { - for (List<AutoLoadInfo>::Element *E = autoload_cache.front(); E; E = E->next()) { - AutoLoadInfo &info = E->get(); + for (const AutoLoadInfo &info : autoload_cache) { if (info.node && !info.in_editor) { memdelete(info.node); } diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 3529a4fbdc..c62e5b75b2 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -299,13 +299,13 @@ void EditorData::copy_object_params(Object *p_object) { List<PropertyInfo> pinfo; p_object->get_property_list(&pinfo); - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_EDITOR) || E->get().name == "script" || E->get().name == "scripts") { + for (const PropertyInfo &E : pinfo) { + if (!(E.usage & PROPERTY_USAGE_EDITOR) || E.name == "script" || E.name == "scripts") { continue; } PropertyData pd; - pd.name = E->get().name; + pd.name = E.name; pd.value = p_object->get(pd.name); clipboard.push_back(pd); } @@ -404,9 +404,9 @@ void EditorData::restore_editor_global_states() { void EditorData::paste_object_params(Object *p_object) { ERR_FAIL_NULL(p_object); undo_redo.create_action(TTR("Paste Params")); - for (List<PropertyData>::Element *E = clipboard.front(); E; E = E->next()) { - String name = E->get().name; - undo_redo.add_do_property(p_object, name, E->get().value); + for (const PropertyData &E : clipboard) { + String name = E.name; + undo_redo.add_do_property(p_object, name, E.value); undo_redo.add_undo_property(p_object, name, p_object->get(name)); } undo_redo.commit_action(); @@ -616,8 +616,8 @@ bool EditorData::check_and_update_scene(int p_idx) { //transfer selection List<Node *> new_selection; - for (List<Node *>::Element *E = edited_scene.write[p_idx].selection.front(); E; E = E->next()) { - NodePath p = edited_scene[p_idx].root->get_path_to(E->get()); + for (const Node *E : edited_scene.write[p_idx].selection) { + NodePath p = edited_scene[p_idx].root->get_path_to(E); Node *new_node = new_scene->get_node(p); if (new_node) { new_selection.push_back(new_node); @@ -841,8 +841,8 @@ Dictionary EditorData::restore_edited_scene_state(EditorSelection *p_selection, p_history->history = es.history_stored; p_selection->clear(); - for (List<Node *>::Element *E = es.selection.front(); E; E = E->next()) { - p_selection->add_node(E->get()); + for (Node *E : es.selection) { + p_selection->add_node(E); } set_editor_states(es.editor_states); @@ -964,9 +964,9 @@ void EditorData::script_class_save_icon_paths() { _script_class_icon_paths.get_key_list(&keys); Dictionary d; - for (List<StringName>::Element *E = keys.front(); E; E = E->next()) { - if (ScriptServer::is_global_class(E->get())) { - d[E->get()] = _script_class_icon_paths[E->get()]; + for (const StringName &E : keys) { + if (ScriptServer::is_global_class(E)) { + d[E] = _script_class_icon_paths[E]; } } @@ -996,8 +996,8 @@ void EditorData::script_class_load_icon_paths() { List<Variant> keys; d.get_key_list(&keys); - for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - String name = E->get().operator String(); + for (const Variant &E : keys) { + String name = E.operator String(); _script_class_icon_paths[name] = d[name]; String path = ScriptServer::get_global_class_path(name); @@ -1038,8 +1038,8 @@ void EditorSelection::add_node(Node *p_node) { changed = true; nl_changed = true; Object *meta = nullptr; - for (List<Object *>::Element *E = editor_plugins.front(); E; E = E->next()) { - meta = E->get()->call("_get_editor_data", p_node); + for (Object *E : editor_plugins) { + meta = E->call("_get_editor_data", p_node); if (meta) { break; } @@ -1076,8 +1076,8 @@ bool EditorSelection::is_selected(Node *p_node) const { Array EditorSelection::_get_transformable_selected_nodes() { Array ret; - for (List<Node *>::Element *E = selected_node_list.front(); E; E = E->next()) { - ret.push_back(E->get()); + for (const Node *E : selected_node_list) { + ret.push_back(E); } return ret; diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index fc483b46b7..b374f56f6d 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -80,9 +80,9 @@ bool EditorExportPreset::_get(const StringName &p_name, Variant &r_ret) const { } void EditorExportPreset::_get_property_list(List<PropertyInfo> *p_list) const { - for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { - if (platform->get_option_visibility(E->get().name, values)) { - p_list->push_back(E->get()); + for (const PropertyInfo &E : properties) { + if (platform->get_option_visibility(E.name, values)) { + p_list->push_back(E); } } } @@ -436,9 +436,9 @@ Ref<EditorExportPreset> EditorExportPlatform::create_preset() { List<ExportOption> options; get_export_options(&options); - for (List<ExportOption>::Element *E = options.front(); E; E = E->next()) { - preset->properties.push_back(E->get().option); - preset->values[E->get().option.name] = E->get().default_value; + for (const ExportOption &E : options) { + preset->properties.push_back(E.option); + preset->values[E.option.name] = E.default_value; } return preset; @@ -679,9 +679,9 @@ EditorExportPlatform::FeatureContainers EditorExportPlatform::get_feature_contai platform->get_preset_features(p_preset, &feature_list); FeatureContainers result; - for (List<String>::Element *E = feature_list.front(); E; E = E->next()) { - result.features.insert(E->get()); - result.features_pv.push_back(E->get()); + for (const String &E : feature_list) { + result.features.insert(E); + result.features_pv.push_back(E); } if (p_preset->get_custom_features() != String()) { @@ -752,9 +752,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & List<PropertyInfo> props; ProjectSettings::get_singleton()->get_property_list(&props); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - const PropertyInfo &pi = E->get(); - + for (const PropertyInfo &pi : props) { if (!pi.name.begins_with("autoload/")) { continue; } @@ -899,8 +897,8 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & Set<String> remap_features; - for (List<String>::Element *F = remaps.front(); F; F = F->next()) { - String remap = F->get(); + for (const String &F : remaps) { + String remap = F; String feature = remap.get_slice(".", 1); if (features.has(feature)) { remap_features.insert(feature); @@ -913,8 +911,8 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & err = OK; - for (List<String>::Element *F = remaps.front(); F; F = F->next()) { - String remap = F->get(); + for (const String &F : remaps) { + String remap = F; if (remap == "path") { String remapped_path = config->get_value("remap", remap); Vector<uint8_t> array = FileAccess::get_file_as_array(remapped_path); @@ -1050,6 +1048,13 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & return err; } } + if (FileAccess::exists(ResourceUID::CACHE_FILE)) { + Vector<uint8_t> array = FileAccess::get_file_as_array(ResourceUID::CACHE_FILE); + err = p_func(p_udata, ResourceUID::CACHE_FILE, array, idx, total, enc_in_filters, enc_ex_filters, key); + if (err != OK) { + return err; + } + } // Store text server data if it is supported. if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) { @@ -1362,7 +1367,7 @@ void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags if (breakpoints.size()) { r_flags.push_back("--breakpoints"); String bpoints; - for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) { + for (List<String>::Element *E = breakpoints.front(); E; E = E->next()) { bpoints += E->get().replace(" ", "%20"); if (E->next()) { bpoints += ","; @@ -1436,8 +1441,8 @@ void EditorExport::_save() { String option_section = "preset." + itos(i) + ".options"; - for (const List<PropertyInfo>::Element *E = preset->get_properties().front(); E; E = E->next()) { - config->set_value(option_section, E->get().name, preset->get(E->get().name)); + for (const PropertyInfo &E : preset->get_properties()) { + config->set_value(option_section, E.name, preset->get(E.name)); } } @@ -1642,10 +1647,10 @@ void EditorExport::load_config() { config->get_section_keys(option_section, &options); - for (List<String>::Element *E = options.front(); E; E = E->next()) { - Variant value = config->get_value(option_section, E->get()); + for (const String &E : options) { + Variant value = config->get_value(option_section, E); - preset->set(E->get(), value); + preset->set(E, value); } add_export_preset(preset); @@ -1684,11 +1689,11 @@ void EditorExport::update_export_presets() { preset->properties.clear(); preset->values.clear(); - for (List<EditorExportPlatform::ExportOption>::Element *E = options.front(); E; E = E->next()) { - preset->properties.push_back(E->get().option); + for (const EditorExportPlatform::ExportOption &E : options) { + preset->properties.push_back(E.option); - StringName option_name = E->get().option.name; - preset->values[option_name] = previous_values.has(option_name) ? previous_values[option_name] : E->get().default_value; + StringName option_name = E.option.name; + preset->values[option_name] = previous_values.has(option_name) ? previous_values[option_name] : E.default_value; } } } diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index e36cc7bc2e..72a0c353e8 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -527,9 +527,8 @@ void EditorFeatureProfileManager::_fill_classes_from(TreeItem *p_parent, const S ClassDB::get_direct_inheriters_from_class(p_class, &child_classes); child_classes.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = child_classes.front(); E; E = E->next()) { - String name = E->get(); - if (name.begins_with("Editor") || ClassDB::get_api_type(name) != ClassDB::API_CORE) { + for (const StringName &name : child_classes) { + if (String(name).begins_with("Editor") || ClassDB::get_api_type(name) != ClassDB::API_CORE) { continue; } _fill_classes_from(class_item, name, p_selected); @@ -597,9 +596,9 @@ void EditorFeatureProfileManager::_class_list_item_selected() { TreeItem *properties = property_list->create_item(root); properties->set_text(0, TTR("Class Properties:")); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - String name = E->get().name; - if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) { + for (const PropertyInfo &E : props) { + String name = E.name; + if (!(E.usage & PROPERTY_USAGE_EDITOR)) { continue; } TreeItem *property = property_list->create_item(properties); @@ -609,7 +608,7 @@ void EditorFeatureProfileManager::_class_list_item_selected() { property->set_checked(0, !edited->is_class_property_disabled(class_name, name)); property->set_text(0, name.capitalize()); property->set_metadata(0, name); - String icon_type = Variant::get_type_name(E->get().type); + String icon_type = Variant::get_type_name(E.type); property->set_icon(0, EditorNode::get_singleton()->get_class_icon(icon_type)); } } @@ -741,7 +740,7 @@ void EditorFeatureProfileManager::_update_selected_profile() { TreeItem *features = class_list->create_item(root); TreeItem *last_feature; - features->set_text(0, TTR("Main Features") + ":"); + features->set_text(0, TTR("Main Features:")); for (int i = 0; i < EditorFeatureProfile::FEATURE_MAX; i++) { TreeItem *feature; if (i == EditorFeatureProfile::FEATURE_IMPORT_DOCK) { @@ -765,7 +764,7 @@ void EditorFeatureProfileManager::_update_selected_profile() { } TreeItem *classes = class_list->create_item(root); - classes->set_text(0, TTR("Nodes and Classes") + ":"); + classes->set_text(0, TTR("Nodes and Classes:")); _fill_classes_from(classes, "Node", class_selected); _fill_classes_from(classes, "Resource", class_selected); @@ -918,7 +917,7 @@ EditorFeatureProfileManager::EditorFeatureProfileManager() { class_list_vbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); class_list = memnew(Tree); - class_list_vbc->add_margin_child(TTR("Configure Selected Profile") + ":", class_list, true); + class_list_vbc->add_margin_child(TTR("Configure Selected Profile:"), class_list, true); class_list->set_hide_root(true); class_list->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true); class_list->connect("cell_selected", callable_mp(this, &EditorFeatureProfileManager::_class_list_item_selected)); @@ -932,11 +931,11 @@ EditorFeatureProfileManager::EditorFeatureProfileManager() { property_list_vbc->set_h_size_flags(Control::SIZE_EXPAND_FILL); description_bit = memnew(EditorHelpBit); - property_list_vbc->add_margin_child(TTR("Description") + ":", description_bit, false); + property_list_vbc->add_margin_child(TTR("Description:"), description_bit, false); description_bit->set_custom_minimum_size(Size2(0, 80) * EDSCALE); property_list = memnew(Tree); - property_list_vbc->add_margin_child(TTR("Extra Options") + ":", property_list, true); + property_list_vbc->add_margin_child(TTR("Extra Options:"), property_list, true); property_list->set_hide_root(true); property_list->set_hide_folding(true); property_list->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true); @@ -958,7 +957,7 @@ EditorFeatureProfileManager::EditorFeatureProfileManager() { VBoxContainer *new_profile_vb = memnew(VBoxContainer); new_profile_dialog->add_child(new_profile_vb); Label *new_profile_label = memnew(Label); - new_profile_label->set_text(TTR("New profile name") + ":"); + new_profile_label->set_text(TTR("New profile name:")); new_profile_vb->add_child(new_profile_label); new_profile_name = memnew(LineEdit); new_profile_vb->add_child(new_profile_name); diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index ed2edb5a5d..5ccbed1b49 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -830,8 +830,8 @@ void EditorFileDialog::update_file_list() { while (!files.is_empty()) { bool match = patterns.is_empty(); - for (List<String>::Element *E = patterns.front(); E; E = E->next()) { - if (files.front()->get().matchn(E->get())) { + for (const String &E : patterns) { + if (files.front()->get().matchn(E)) { match = true; break; } diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 82a71c0e0c..78861eff9d 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -43,7 +43,7 @@ EditorFileSystem *EditorFileSystem::singleton = nullptr; //the name is the version, to keep compatibility with different versions of Godot -#define CACHE_FILE_NAME "filesystem_cache6" +#define CACHE_FILE_NAME "filesystem_cache7" void EditorFileSystemDirectory::sort_files() { files.sort_custom<FileInfoSort>(); @@ -116,7 +116,26 @@ String EditorFileSystemDirectory::get_file_path(int p_idx) const { Vector<String> EditorFileSystemDirectory::get_file_deps(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, files.size(), Vector<String>()); - return files[p_idx]->deps; + Vector<String> deps; + + for (int i = 0; i < files[p_idx]->deps.size(); i++) { + String dep = files[p_idx]->deps[i]; + int sep_idx = dep.find("::"); //may contain type information, unwanted + if (sep_idx != -1) { + dep = dep.substr(0, sep_idx); + } + ResourceUID::ID uid = ResourceUID::get_singleton()->text_to_id(dep); + if (uid != ResourceUID::INVALID_ID) { + //return proper dependency resource from uid + if (ResourceUID::get_singleton()->has_id(uid)) { + dep = ResourceUID::get_singleton()->get_id_path(uid); + } else { + continue; + } + } + deps.push_back(dep); + } + return deps; } bool EditorFileSystemDirectory::get_file_import_is_valid(int p_idx) const { @@ -234,7 +253,7 @@ void EditorFileSystem::_scan_filesystem() { } else { Vector<String> split = l.split("::"); - ERR_CONTINUE(split.size() != 8); + ERR_CONTINUE(split.size() != 9); String name = split[0]; String file; @@ -243,15 +262,16 @@ void EditorFileSystem::_scan_filesystem() { FileCache fc; fc.type = split[1]; - fc.modification_time = split[2].to_int(); - fc.import_modification_time = split[3].to_int(); - fc.import_valid = split[4].to_int() != 0; - fc.import_group_file = split[5].strip_edges(); - fc.script_class_name = split[6].get_slice("<>", 0); - fc.script_class_extends = split[6].get_slice("<>", 1); - fc.script_class_icon_path = split[6].get_slice("<>", 2); - - String deps = split[7].strip_edges(); + fc.uid = split[2].to_int(); + fc.modification_time = split[3].to_int(); + fc.import_modification_time = split[4].to_int(); + fc.import_valid = split[5].to_int() != 0; + fc.import_group_file = split[6].strip_edges(); + fc.script_class_name = split[7].get_slice("<>", 0); + fc.script_class_extends = split[7].get_slice("<>", 1); + fc.script_class_icon_path = split[7].get_slice("<>", 2); + + String deps = split[8].strip_edges(); if (deps.length()) { Vector<String> dp = deps.split("<>"); for (int i = 0; i < dp.size(); i++) { @@ -368,6 +388,7 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo Vector<String> dest_files; String dest_md5 = ""; int version = 0; + bool found_uid = false; while (true) { assign = Variant(); @@ -395,6 +416,8 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo version = value; } else if (assign == "importer") { importer_name = value; + } else if (assign == "uid") { + found_uid = true; } else if (!p_only_imported_files) { if (assign == "source_file") { source_file = value; @@ -414,6 +437,10 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo return false; //keep mode, do not reimport } + if (!found_uid) { + return true; //UUID not found, old format, reimport. + } + Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name); if (importer->get_format_version() > version) { @@ -457,8 +484,8 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo memdelete(md5s); //imported files are gone, reimport - for (List<String>::Element *E = to_check.front(); E; E = E->next()) { - if (!FileAccess::exists(E->get())) { + for (const String &E : to_check) { + if (!FileAccess::exists(E)) { return true; } } @@ -497,9 +524,7 @@ bool EditorFileSystem::_update_scan_actions() { Vector<String> reimports; Vector<String> reloads; - for (List<ItemAction>::Element *E = scan_actions.front(); E; E = E->next()) { - ItemAction &ia = E->get(); - + for (const ItemAction &ia : scan_actions) { switch (ia.action) { case ItemAction::ACTION_NONE: { } break; @@ -582,6 +607,9 @@ bool EditorFileSystem::_update_scan_actions() { if (reimports.size()) { reimport_files(reimports); + } else { + //reimport files will update the uid cache file so if nothing was reimported, update it manually + ResourceUID::get_singleton()->update_cache(); } if (first_scan) { @@ -756,6 +784,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess if (fc && fc->modification_time == mt && fc->import_modification_time == import_mt && !_test_for_reimport(path, true)) { fi->type = fc->type; + fi->uid = fc->uid; fi->deps = fc->deps; fi->modified_time = fc->modification_time; fi->import_modified_time = fc->import_modification_time; @@ -781,8 +810,14 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess //note: I think this should not happen any longer.. } + if (fc->uid == ResourceUID::INVALID_ID) { + // imported files should always have a UUID, so attempt to fetch it. + fi->uid = ResourceLoader::get_resource_uid(path); + } + } else { fi->type = ResourceFormatImporter::get_singleton()->get_resource_type(path); + fi->uid = ResourceFormatImporter::get_singleton()->get_resource_uid(path); fi->import_group_file = ResourceFormatImporter::get_singleton()->get_import_group_file(path); fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path); fi->modified_time = 0; @@ -799,6 +834,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess if (fc && fc->modification_time == mt) { //not imported, so just update type if changed fi->type = fc->type; + fi->uid = fc->uid; fi->modified_time = fc->modification_time; fi->deps = fc->deps; fi->import_modified_time = 0; @@ -809,6 +845,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess } else { //new or modified time fi->type = ResourceLoader::get_resource_type(path); + fi->uid = ResourceLoader::get_resource_uid(path); fi->script_class_name = _get_global_script_class(fi->type, path, &fi->script_class_extends, &fi->script_class_icon_path); fi->deps = _get_dependencies(path); fi->modified_time = mt; @@ -817,6 +854,14 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess } } + if (fi->uid != ResourceUID::INVALID_ID) { + if (ResourceUID::get_singleton()->has_id(fi->uid)) { + ResourceUID::get_singleton()->set_id(fi->uid, path); + } else { + ResourceUID::get_singleton()->add_id(fi->uid, path); + } + } + for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptLanguage *lang = ScriptServer::get_language(i); if (lang->supports_documentation() && fi->type == lang->get_type()) { @@ -1027,8 +1072,8 @@ void EditorFileSystem::_delete_internal_files(String p_file) { List<String> paths; ResourceFormatImporter::get_singleton()->get_internal_resource_path_list(p_file, &paths); DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); - for (List<String>::Element *E = paths.front(); E; E = E->next()) { - da->remove(E->get()); + for (const String &E : paths) { + da->remove(E); } da->remove(p_file + ".import"); memdelete(da); @@ -1181,7 +1226,7 @@ void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir, if (p_dir->files[i]->import_group_file != String()) { group_file_cache.insert(p_dir->files[i]->import_group_file); } - String s = p_dir->files[i]->file + "::" + p_dir->files[i]->type + "::" + itos(p_dir->files[i]->modified_time) + "::" + itos(p_dir->files[i]->import_modified_time) + "::" + itos(p_dir->files[i]->import_valid) + "::" + p_dir->files[i]->import_group_file + "::" + p_dir->files[i]->script_class_name + "<>" + p_dir->files[i]->script_class_extends + "<>" + p_dir->files[i]->script_class_icon_path; + String s = p_dir->files[i]->file + "::" + p_dir->files[i]->type + "::" + itos(p_dir->files[i]->uid) + "::" + itos(p_dir->files[i]->modified_time) + "::" + itos(p_dir->files[i]->import_modified_time) + "::" + itos(p_dir->files[i]->import_valid) + "::" + p_dir->files[i]->import_group_file + "::" + p_dir->files[i]->script_class_name + "<>" + p_dir->files[i]->script_class_extends + "<>" + p_dir->files[i]->script_class_icon_path; s += "::"; for (int j = 0; j < p_dir->files[i]->deps.size(); j++) { if (j > 0) { @@ -1368,8 +1413,8 @@ Vector<String> EditorFileSystem::_get_dependencies(const String &p_path) { ResourceLoader::get_dependencies(p_path, &deps); Vector<String> ret; - for (List<String>::Element *E = deps.front(); E; E = E->next()) { - ret.push_back(E->get()); + for (const String &E : deps) { + ret.push_back(E); } return ret; @@ -1462,6 +1507,11 @@ void EditorFileSystem::update_file(const String &p_file) { //was removed _delete_internal_files(p_file); if (cpos != -1) { // Might've never been part of the editor file system (*.* files deleted in Open dialog). + if (fs->files[cpos]->uid != ResourceUID::INVALID_ID) { + if (ResourceUID::get_singleton()->has_id(fs->files[cpos]->uid)) { + ResourceUID::get_singleton()->remove_id(fs->files[cpos]->uid); + } + } memdelete(fs->files[cpos]); fs->files.remove(cpos); } @@ -1472,6 +1522,7 @@ void EditorFileSystem::update_file(const String &p_file) { } String type = ResourceLoader::get_resource_type(p_file); + ResourceUID::ID uid = ResourceLoader::get_resource_uid(p_file); if (cpos == -1) { // The file did not exist, it was added. @@ -1504,12 +1555,22 @@ void EditorFileSystem::update_file(const String &p_file) { } fs->files[cpos]->type = type; + fs->files[cpos]->uid = uid; fs->files[cpos]->script_class_name = _get_global_script_class(type, p_file, &fs->files[cpos]->script_class_extends, &fs->files[cpos]->script_class_icon_path); fs->files[cpos]->import_group_file = ResourceLoader::get_import_group_file(p_file); fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file); fs->files[cpos]->deps = _get_dependencies(p_file); fs->files[cpos]->import_valid = ResourceLoader::is_import_valid(p_file); + if (uid != ResourceUID::INVALID_ID) { + if (ResourceUID::get_singleton()->has_id(uid)) { + ResourceUID::get_singleton()->set_id(uid, p_file); + } else { + ResourceUID::get_singleton()->add_id(uid, p_file); + } + + ResourceUID::get_singleton()->update_cache(); + } // Update preview EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); @@ -1532,7 +1593,6 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector ERR_CONTINUE(file_importer_name == String()); if (importer_name != String() && importer_name != file_importer_name) { - print_line("one importer '" + importer_name + "' the other '" + file_importer_name + "'."); EditorNode::get_singleton()->show_warning(vformat(TTR("There are multiple importers for different types pointing to file %s, import aborted"), p_group_file)); ERR_FAIL_V(ERR_FILE_CORRUPT); } @@ -1549,15 +1609,14 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector List<ResourceImporter::ImportOption> options; importer->get_import_options(&options); //set default values - for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { - source_file_options[p_files[i]][E->get().option.name] = E->get().default_value; + for (const ResourceImporter::ImportOption &E : options) { + source_file_options[p_files[i]][E.option.name] = E.default_value; } if (config->has_section("params")) { List<String> sk; config->get_section_keys("params", &sk); - for (List<String>::Element *E = sk.front(); E; E = E->next()) { - String param = E->get(); + for (const String ¶m : sk) { Variant value = config->get_value("params", param); //override with whathever is in file source_file_options[p_files[i]][param] = value; @@ -1631,9 +1690,9 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector List<ResourceImporter::ImportOption> options; importer->get_import_options(&options); //set default values - for (List<ResourceImporter::ImportOption>::Element *F = options.front(); F; F = F->next()) { - String base = F->get().option.name; - Variant v = F->get().default_value; + for (const ResourceImporter::ImportOption &F : options) { + String base = F.option.name; + Variant v = F.default_value; if (source_file_options[file].has(base)) { v = source_file_options[file][base]; } @@ -1702,6 +1761,8 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName params = *p_custom_options; } + ResourceUID::ID uid = ResourceUID::INVALID_ID; + if (FileAccess::exists(p_file + ".import")) { //use existing if (p_custom_options == nullptr) { @@ -1712,12 +1773,20 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName if (cf->has_section("params")) { List<String> sk; cf->get_section_keys("params", &sk); - for (List<String>::Element *E = sk.front(); E; E = E->next()) { - params[E->get()] = cf->get_value("params", E->get()); + for (const String &E : sk) { + params[E] = cf->get_value("params", E); } } - if (p_custom_importer == String() && cf->has_section("remap")) { - importer_name = cf->get_value("remap", "importer"); + + if (cf->has_section("remap")) { + if (p_custom_importer == String()) { + importer_name = cf->get_value("remap", "importer"); + } + + if (cf->has_section_key("remap", "uid")) { + String uidt = cf->get_value("remap", "uid"); + uid = ResourceUID::get_singleton()->text_to_id(uidt); + } } } } @@ -1754,9 +1823,9 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName List<ResourceImporter::ImportOption> opts; importer->get_import_options(&opts); - for (List<ResourceImporter::ImportOption>::Element *E = opts.front(); E; E = E->next()) { - if (!params.has(E->get().option.name)) { //this one is not present - params[E->get().option.name] = E->get().default_value; + for (const ResourceImporter::ImportOption &E : opts) { + if (!params.has(E.option.name)) { //this one is not present + params[E.option.name] = E.default_value; } } @@ -1766,8 +1835,8 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName List<Variant> v; d.get_key_list(&v); - for (List<Variant>::Element *E = v.front(); E; E = E->next()) { - params[E->get()] = d[E->get()]; + for (const Variant &E : v) { + params[E] = d[E]; } } @@ -1800,6 +1869,12 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName f->store_line("type=\"" + importer->get_resource_type() + "\""); } + if (uid == ResourceUID::INVALID_ID) { + uid = ResourceUID::get_singleton()->create_id(); + } + + f->store_line("uid=\"" + ResourceUID::get_singleton()->id_to_text(uid) + "\""); //store in readable format + Vector<String> dest_paths; if (err == OK) { @@ -1807,10 +1882,10 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName //no path } else if (import_variants.size()) { //import with variants - for (List<String>::Element *E = import_variants.front(); E; E = E->next()) { - String path = base_path.c_escape() + "." + E->get() + "." + importer->get_save_extension(); + for (const String &E : import_variants) { + String path = base_path.c_escape() + "." + E + "." + importer->get_save_extension(); - f->store_line("path." + E->get() + "=\"" + path + "\""); + f->store_line("path." + E + "=\"" + path + "\""); dest_paths.push_back(path); } } else { @@ -1833,9 +1908,9 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName if (gen_files.size()) { Array genf; - for (List<String>::Element *E = gen_files.front(); E; E = E->next()) { - genf.push_back(E->get()); - dest_paths.push_back(E->get()); + for (const String &E : gen_files) { + genf.push_back(E); + dest_paths.push_back(E); } String value; @@ -1859,8 +1934,8 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName //store options in provided order, to avoid file changing. Order is also important because first match is accepted first. - for (List<ResourceImporter::ImportOption>::Element *E = opts.front(); E; E = E->next()) { - String base = E->get().option.name; + for (const ResourceImporter::ImportOption &E : opts) { + String base = E.option.name; String value; VariantWriter::write_to_string(params[base], value); f->store_line(base + "=" + value); @@ -1885,8 +1960,15 @@ void EditorFileSystem::_reimport_file(const String &p_file, const Map<StringName fs->files[cpos]->import_modified_time = FileAccess::get_modified_time(p_file + ".import"); fs->files[cpos]->deps = _get_dependencies(p_file); fs->files[cpos]->type = importer->get_resource_type(); + fs->files[cpos]->uid = uid; fs->files[cpos]->import_valid = ResourceLoader::is_import_valid(p_file); + if (ResourceUID::get_singleton()->has_id(uid)) { + ResourceUID::get_singleton()->set_id(uid, p_file); + } else { + ResourceUID::get_singleton()->add_id(uid, p_file); + } + //if file is currently up, maybe the source it was loaded from changed, so import math must be updated for it //to reload properly if (ResourceCache::has(p_file)) { @@ -1937,11 +2019,18 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) { Set<String> groups_to_reimport; for (int i = 0; i < p_files.size(); i++) { - String group_file = ResourceFormatImporter::get_singleton()->get_import_group_file(p_files[i]); + String file = p_files[i]; + + ResourceUID::ID uid = ResourceUID::get_singleton()->text_to_id(file); + if (uid != ResourceUID::INVALID_ID && ResourceUID::get_singleton()->has_id(uid)) { + file = ResourceUID::get_singleton()->get_id_path(uid); + } + + String group_file = ResourceFormatImporter::get_singleton()->get_import_group_file(file); - if (group_file_cache.has(p_files[i])) { + if (group_file_cache.has(file)) { //maybe the file itself is a group! - groups_to_reimport.insert(p_files[i]); + groups_to_reimport.insert(file); //groups do not belong to grups group_file = String(); } else if (group_file != String()) { @@ -1950,15 +2039,15 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) { } else { //it's a regular file ImportFile ifile; - ifile.path = p_files[i]; - ResourceFormatImporter::get_singleton()->get_import_order_threads_and_importer(p_files[i], ifile.order, ifile.threaded, ifile.importer); + ifile.path = file; + ResourceFormatImporter::get_singleton()->get_import_order_threads_and_importer(file, ifile.order, ifile.threaded, ifile.importer); reimport_files.push_back(ifile); } //group may have changed, so also update group reference EditorFileSystemDirectory *fs = nullptr; int cpos = -1; - if (_find_file(p_files[i], &fs, cpos)) { + if (_find_file(file, &fs, cpos)) { fs->files.write[cpos]->import_group_file = group_file; } } @@ -2023,6 +2112,8 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) { } } + ResourceUID::get_singleton()->update_cache(); //after reimporting, update the cache + _save_filesystem_cache(); importing = false; if (!is_scanning()) { @@ -2080,9 +2171,8 @@ void EditorFileSystem::_move_group_files(EditorFileSystemDirectory *efd, const S List<String> sk; config->get_section_keys("params", &sk); - for (List<String>::Element *E = sk.front(); E; E = E->next()) { + for (const String ¶m : sk) { //not very clean, but should work - String param = E->get(); String value = config->get_value("params", param); if (value == p_group_file) { config->set_value("params", param, p_new_location); @@ -2108,6 +2198,30 @@ void EditorFileSystem::move_group_file(const String &p_path, const String &p_new } } +ResourceUID::ID EditorFileSystem::_resource_saver_get_resource_id_for_path(const String &p_path, bool p_generate) { + if (!p_path.is_resource_file() || p_path.begins_with("res://.godot")) { + //saved externally (configuration file) or internal file, do not assign an ID. + return ResourceUID::INVALID_ID; + } + + EditorFileSystemDirectory *fs = nullptr; + int cpos = -1; + + if (!singleton->_find_file(p_path, &fs, cpos)) { + if (p_generate) { + return ResourceUID::get_singleton()->create_id(); //just create a new one, we will be notified of save anyway and fetch the right UUID at that time, to keep things simple. + } else { + return ResourceUID::INVALID_ID; + } + } else if (fs->files[cpos]->uid != ResourceUID::INVALID_ID) { + return fs->files[cpos]->uid; + } else if (p_generate) { + return ResourceUID::get_singleton()->create_id(); //just create a new one, we will be notified of save anyway and fetch the right UUID at that time, to keep things simple. + } else { + return ResourceUID::INVALID_ID; + } +} + void EditorFileSystem::_bind_methods() { ClassDB::bind_method(D_METHOD("get_filesystem"), &EditorFileSystem::get_filesystem); ClassDB::bind_method(D_METHOD("is_scanning"), &EditorFileSystem::is_scanning); @@ -2131,14 +2245,14 @@ void EditorFileSystem::_update_extensions() { List<String> extensionsl; ResourceLoader::get_recognized_extensions_for_type("", &extensionsl); - for (List<String>::Element *E = extensionsl.front(); E; E = E->next()) { - valid_extensions.insert(E->get()); + for (const String &E : extensionsl) { + valid_extensions.insert(E); } extensionsl.clear(); ResourceFormatImporter::get_singleton()->get_recognized_extensions(&extensionsl); - for (List<String>::Element *E = extensionsl.front(); E; E = E->next()) { - import_extensions.insert(E->get()); + for (const String &E : extensionsl) { + import_extensions.insert(E); } } @@ -2169,8 +2283,11 @@ EditorFileSystem::EditorFileSystem() { scan_changes_pending = false; revalidate_import_files = false; import_threads.init(); + ResourceUID::get_singleton()->clear(); //will be updated on scan + ResourceSaver::set_get_resource_id_for_path(_resource_saver_get_resource_id_for_path); } EditorFileSystem::~EditorFileSystem() { import_threads.finish(); + ResourceSaver::set_get_resource_id_for_path(nullptr); } diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h index 37eee13c16..9dce29d09c 100644 --- a/editor/editor_file_system.h +++ b/editor/editor_file_system.h @@ -55,6 +55,7 @@ class EditorFileSystemDirectory : public Object { struct FileInfo { String file; StringName type; + ResourceUID::ID uid = ResourceUID::INVALID_ID; uint64_t modified_time = 0; uint64_t import_modified_time = 0; bool import_valid = false; @@ -159,6 +160,7 @@ class EditorFileSystem : public Node { /* Used for reading the filesystem cache file */ struct FileCache { String type; + ResourceUID::ID uid = ResourceUID::INVALID_ID; uint64_t modification_time = 0; uint64_t import_modification_time = 0; Vector<String> deps; @@ -251,6 +253,8 @@ class EditorFileSystem : public Node { void _reimport_thread(uint32_t p_index, ImportThreadData *p_import_data); + static ResourceUID::ID _resource_saver_get_resource_id_for_path(const String &p_path, bool p_generate); + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp index 5d6c415d39..29e3236ac2 100644 --- a/editor/editor_folding.cpp +++ b/editor/editor_folding.cpp @@ -109,10 +109,10 @@ void EditorFolding::_fill_folds(const Node *p_root, const Node *p_node, Array &p List<PropertyInfo> plist; p_node->get_property_list(&plist); - for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_EDITOR) { - if (E->get().type == Variant::OBJECT) { - RES res = p_node->get(E->get().name); + for (const PropertyInfo &E : plist) { + if (E.usage & PROPERTY_USAGE_EDITOR) { + if (E.type == Variant::OBJECT) { + RES res = p_node->get(E.name); if (res.is_valid() && !resources.has(res) && res->get_path() != String() && !res->get_path().is_resource_file()) { Vector<String> res_unfolds = _get_unfolds(res.ptr()); resource_folds.push_back(res->get_path()); @@ -228,41 +228,41 @@ void EditorFolding::_do_object_unfolds(Object *p_object, Set<RES> &resources) { Set<String> unfold_group; - for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_CATEGORY) { + for (const PropertyInfo &E : plist) { + if (E.usage & PROPERTY_USAGE_CATEGORY) { group = ""; group_base = ""; } - if (E->get().usage & PROPERTY_USAGE_GROUP) { - group = E->get().name; - group_base = E->get().hint_string; + if (E.usage & PROPERTY_USAGE_GROUP) { + group = E.name; + group_base = E.hint_string; if (group_base.ends_with("_")) { group_base = group_base.substr(0, group_base.length() - 1); } } //can unfold - if (E->get().usage & PROPERTY_USAGE_EDITOR) { + if (E.usage & PROPERTY_USAGE_EDITOR) { if (group != "") { //group - if (group_base == String() || E->get().name.begins_with(group_base)) { - bool can_revert = EditorPropertyRevert::can_property_revert(p_object, E->get().name); + if (group_base == String() || E.name.begins_with(group_base)) { + bool can_revert = EditorPropertyRevert::can_property_revert(p_object, E.name); if (can_revert) { unfold_group.insert(group); } } } else { //path - int last = E->get().name.rfind("/"); + int last = E.name.rfind("/"); if (last != -1) { - bool can_revert = EditorPropertyRevert::can_property_revert(p_object, E->get().name); + bool can_revert = EditorPropertyRevert::can_property_revert(p_object, E.name); if (can_revert) { - unfold_group.insert(E->get().name.substr(0, last)); + unfold_group.insert(E.name.substr(0, last)); } } } - if (E->get().type == Variant::OBJECT) { - RES res = p_object->get(E->get().name); - print_line("res: " + String(E->get().name) + " valid " + itos(res.is_valid())); + if (E.type == Variant::OBJECT) { + RES res = p_object->get(E.name); + print_line("res: " + String(E.name) + " valid " + itos(res.is_valid())); if (res.is_valid()) { print_line("path " + res->get_path()); } diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index 8968e562c1..1e3db1a7b0 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -37,19 +37,34 @@ #include "scene/resources/default_theme/default_theme.h" #include "scene/resources/font.h" -#define MAKE_FALLBACKS(m_name) \ - m_name->add_data(FontArabic); \ - m_name->add_data(FontBengali); \ - m_name->add_data(FontGeorgian); \ - m_name->add_data(FontMalayalam); \ - m_name->add_data(FontOriya); \ - m_name->add_data(FontSinhala); \ - m_name->add_data(FontTamil); \ - m_name->add_data(FontTelugu); \ - m_name->add_data(FontHebrew); \ - m_name->add_data(FontThai); \ - m_name->add_data(FontHindi); \ - m_name->add_data(FontJapanese); \ +#define MAKE_FALLBACKS(m_name) \ + m_name->add_data(FontArabic); \ + m_name->add_data(FontBengali); \ + m_name->add_data(FontDevanagari); \ + m_name->add_data(FontGeorgian); \ + m_name->add_data(FontHebrew); \ + m_name->add_data(FontMalayalam); \ + m_name->add_data(FontOriya); \ + m_name->add_data(FontSinhala); \ + m_name->add_data(FontTamil); \ + m_name->add_data(FontTelugu); \ + m_name->add_data(FontThai); \ + m_name->add_data(FontJapanese); \ + m_name->add_data(FontFallback); + +#define MAKE_FALLBACKS_BOLD(m_name) \ + m_name->add_data(FontArabicBold); \ + m_name->add_data(FontBengaliBold); \ + m_name->add_data(FontDevanagariBold); \ + m_name->add_data(FontGeorgianBold); \ + m_name->add_data(FontHebrewBold); \ + m_name->add_data(FontMalayalamBold); \ + m_name->add_data(FontOriyaBold); \ + m_name->add_data(FontSinhalaBold); \ + m_name->add_data(FontTamilBold); \ + m_name->add_data(FontTeluguBold); \ + m_name->add_data(FontThaiBold); \ + m_name->add_data(FontJapanese); \ m_name->add_data(FontFallback); // the custom spacings might only work with Noto Sans @@ -77,7 +92,7 @@ } \ m_name->set_spacing(Font::SPACING_TOP, -EDSCALE); \ m_name->set_spacing(Font::SPACING_BOTTOM, -EDSCALE); \ - MAKE_FALLBACKS(m_name); + MAKE_FALLBACKS_BOLD(m_name); #define MAKE_SOURCE_FONT(m_name) \ Ref<Font> m_name; \ @@ -175,36 +190,22 @@ void editor_register_fonts(Ref<Theme> p_theme) { memdelete(dir); - /* Droid Sans */ + /* Noto Sans UI */ Ref<FontData> DefaultFont; DefaultFont.instantiate(); - DefaultFont->load_memory(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size, "ttf", default_font_size); + DefaultFont->load_memory(_font_NotoSans_Regular, _font_NotoSans_Regular_size, "ttf", default_font_size); DefaultFont->set_antialiased(font_antialiased); DefaultFont->set_hinting(font_hinting); DefaultFont->set_force_autohinter(true); //just looks better..i think? Ref<FontData> DefaultFontBold; DefaultFontBold.instantiate(); - DefaultFontBold->load_memory(_font_NotoSansUI_Bold, _font_NotoSansUI_Bold_size, "ttf", default_font_size); + DefaultFontBold->load_memory(_font_NotoSans_Bold, _font_NotoSans_Bold_size, "ttf", default_font_size); DefaultFontBold->set_antialiased(font_antialiased); DefaultFontBold->set_hinting(font_hinting); DefaultFontBold->set_force_autohinter(true); // just looks better..i think? - Ref<FontData> FontFallback; - FontFallback.instantiate(); - FontFallback->load_memory(_font_DroidSansFallback, _font_DroidSansFallback_size, "ttf", default_font_size); - FontFallback->set_antialiased(font_antialiased); - FontFallback->set_hinting(font_hinting); - FontFallback->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontJapanese; - FontJapanese.instantiate(); - FontJapanese->load_memory(_font_DroidSansJapanese, _font_DroidSansJapanese_size, "ttf", default_font_size); - FontJapanese->set_antialiased(font_antialiased); - FontJapanese->set_hinting(font_hinting); - FontJapanese->set_force_autohinter(true); //just looks better..i think? - Ref<FontData> FontArabic; FontArabic.instantiate(); FontArabic->load_memory(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size, "ttf", default_font_size); @@ -212,13 +213,41 @@ void editor_register_fonts(Ref<Theme> p_theme) { FontArabic->set_hinting(font_hinting); FontArabic->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontArabicBold; + FontArabicBold.instantiate(); + FontArabicBold->load_memory(_font_NotoNaskhArabicUI_Bold, _font_NotoNaskhArabicUI_Bold_size, "ttf", default_font_size); + FontArabicBold->set_antialiased(font_antialiased); + FontArabicBold->set_hinting(font_hinting); + FontArabicBold->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontBengali; FontBengali.instantiate(); - FontBengali->load_memory(_font_NotoSansBengali_Regular, _font_NotoSansBengali_Regular_size, "ttf", default_font_size); + FontBengali->load_memory(_font_NotoSansBengaliUI_Regular, _font_NotoSansBengaliUI_Regular_size, "ttf", default_font_size); FontBengali->set_antialiased(font_antialiased); FontBengali->set_hinting(font_hinting); FontBengali->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontBengaliBold; + FontBengaliBold.instantiate(); + FontBengaliBold->load_memory(_font_NotoSansBengaliUI_Bold, _font_NotoSansBengaliUI_Bold_size, "ttf", default_font_size); + FontBengaliBold->set_antialiased(font_antialiased); + FontBengaliBold->set_hinting(font_hinting); + FontBengaliBold->set_force_autohinter(true); //just looks better..i think? + + Ref<FontData> FontDevanagari; + FontDevanagari.instantiate(); + FontDevanagari->load_memory(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size, "ttf", default_font_size); + FontDevanagari->set_antialiased(font_antialiased); + FontDevanagari->set_hinting(font_hinting); + FontDevanagari->set_force_autohinter(true); //just looks better..i think? + + Ref<FontData> FontDevanagariBold; + FontDevanagariBold.instantiate(); + FontDevanagariBold->load_memory(_font_NotoSansDevanagariUI_Bold, _font_NotoSansDevanagariUI_Bold_size, "ttf", default_font_size); + FontDevanagariBold->set_antialiased(font_antialiased); + FontDevanagariBold->set_hinting(font_hinting); + FontDevanagariBold->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontGeorgian; FontGeorgian.instantiate(); FontGeorgian->load_memory(_font_NotoSansGeorgian_Regular, _font_NotoSansGeorgian_Regular_size, "ttf", default_font_size); @@ -226,6 +255,13 @@ void editor_register_fonts(Ref<Theme> p_theme) { FontGeorgian->set_hinting(font_hinting); FontGeorgian->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontGeorgianBold; + FontGeorgianBold.instantiate(); + FontGeorgianBold->load_memory(_font_NotoSansGeorgian_Bold, _font_NotoSansGeorgian_Bold_size, "ttf", default_font_size); + FontGeorgianBold->set_antialiased(font_antialiased); + FontGeorgianBold->set_hinting(font_hinting); + FontGeorgianBold->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontHebrew; FontHebrew.instantiate(); FontHebrew->load_memory(_font_NotoSansHebrew_Regular, _font_NotoSansHebrew_Regular_size, "ttf", default_font_size); @@ -233,6 +269,13 @@ void editor_register_fonts(Ref<Theme> p_theme) { FontHebrew->set_hinting(font_hinting); FontHebrew->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontHebrewBold; + FontHebrewBold.instantiate(); + FontHebrewBold->load_memory(_font_NotoSansHebrew_Bold, _font_NotoSansHebrew_Bold_size, "ttf", default_font_size); + FontHebrewBold->set_antialiased(font_antialiased); + FontHebrewBold->set_hinting(font_hinting); + FontHebrewBold->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontMalayalam; FontMalayalam.instantiate(); FontMalayalam->load_memory(_font_NotoSansMalayalamUI_Regular, _font_NotoSansMalayalamUI_Regular_size, "ttf", default_font_size); @@ -240,6 +283,13 @@ void editor_register_fonts(Ref<Theme> p_theme) { FontMalayalam->set_hinting(font_hinting); FontMalayalam->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontMalayalamBold; + FontMalayalamBold.instantiate(); + FontMalayalamBold->load_memory(_font_NotoSansMalayalamUI_Bold, _font_NotoSansMalayalamUI_Bold_size, "ttf", default_font_size); + FontMalayalamBold->set_antialiased(font_antialiased); + FontMalayalamBold->set_hinting(font_hinting); + FontMalayalamBold->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontOriya; FontOriya.instantiate(); FontOriya->load_memory(_font_NotoSansOriyaUI_Regular, _font_NotoSansOriyaUI_Regular_size, "ttf", default_font_size); @@ -247,6 +297,13 @@ void editor_register_fonts(Ref<Theme> p_theme) { FontOriya->set_hinting(font_hinting); FontOriya->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontOriyaBold; + FontOriyaBold.instantiate(); + FontOriyaBold->load_memory(_font_NotoSansOriyaUI_Bold, _font_NotoSansOriyaUI_Bold_size, "ttf", default_font_size); + FontOriyaBold->set_antialiased(font_antialiased); + FontOriyaBold->set_hinting(font_hinting); + FontOriyaBold->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontSinhala; FontSinhala.instantiate(); FontSinhala->load_memory(_font_NotoSansSinhalaUI_Regular, _font_NotoSansSinhalaUI_Regular_size, "ttf", default_font_size); @@ -254,6 +311,13 @@ void editor_register_fonts(Ref<Theme> p_theme) { FontSinhala->set_hinting(font_hinting); FontSinhala->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontSinhalaBold; + FontSinhalaBold.instantiate(); + FontSinhalaBold->load_memory(_font_NotoSansSinhalaUI_Bold, _font_NotoSansSinhalaUI_Bold_size, "ttf", default_font_size); + FontSinhalaBold->set_antialiased(font_antialiased); + FontSinhalaBold->set_hinting(font_hinting); + FontSinhalaBold->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontTamil; FontTamil.instantiate(); FontTamil->load_memory(_font_NotoSansTamilUI_Regular, _font_NotoSansTamilUI_Regular_size, "ttf", default_font_size); @@ -261,6 +325,13 @@ void editor_register_fonts(Ref<Theme> p_theme) { FontTamil->set_hinting(font_hinting); FontTamil->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontTamilBold; + FontTamilBold.instantiate(); + FontTamilBold->load_memory(_font_NotoSansTamilUI_Bold, _font_NotoSansTamilUI_Bold_size, "ttf", default_font_size); + FontTamilBold->set_antialiased(font_antialiased); + FontTamilBold->set_hinting(font_hinting); + FontTamilBold->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontTelugu; FontTelugu.instantiate(); FontTelugu->load_memory(_font_NotoSansTeluguUI_Regular, _font_NotoSansTeluguUI_Regular_size, "ttf", default_font_size); @@ -268,6 +339,13 @@ void editor_register_fonts(Ref<Theme> p_theme) { FontTelugu->set_hinting(font_hinting); FontTelugu->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontTeluguBold; + FontTeluguBold.instantiate(); + FontTeluguBold->load_memory(_font_NotoSansTeluguUI_Bold, _font_NotoSansTeluguUI_Bold_size, "ttf", default_font_size); + FontTeluguBold->set_antialiased(font_antialiased); + FontTeluguBold->set_hinting(font_hinting); + FontTeluguBold->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontThai; FontThai.instantiate(); FontThai->load_memory(_font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size, "ttf", default_font_size); @@ -275,12 +353,30 @@ void editor_register_fonts(Ref<Theme> p_theme) { FontThai->set_hinting(font_hinting); FontThai->set_force_autohinter(true); //just looks better..i think? - Ref<FontData> FontHindi; - FontHindi.instantiate(); - FontHindi->load_memory(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size, "ttf", default_font_size); - FontHindi->set_antialiased(font_antialiased); - FontHindi->set_hinting(font_hinting); - FontHindi->set_force_autohinter(true); //just looks better..i think? + Ref<FontData> FontThaiBold; + FontThaiBold.instantiate(); + FontThaiBold->load_memory(_font_NotoSansThaiUI_Bold, _font_NotoSansThaiUI_Bold_size, "ttf", default_font_size); + FontThaiBold->set_antialiased(font_antialiased); + FontThaiBold->set_hinting(font_hinting); + FontThaiBold->set_force_autohinter(true); //just looks better..i think? + + /* Droid Sans Fallback */ + + Ref<FontData> FontFallback; + FontFallback.instantiate(); + FontFallback->load_memory(_font_DroidSansFallback, _font_DroidSansFallback_size, "ttf", default_font_size); + FontFallback->set_antialiased(font_antialiased); + FontFallback->set_hinting(font_hinting); + FontFallback->set_force_autohinter(true); //just looks better..i think? + + /* Droid Sans Japanese */ + + Ref<FontData> FontJapanese; + FontJapanese.instantiate(); + FontJapanese->load_memory(_font_DroidSansJapanese, _font_DroidSansJapanese_size, "ttf", default_font_size); + FontJapanese->set_antialiased(font_antialiased); + FontJapanese->set_hinting(font_hinting); + FontJapanese->set_force_autohinter(true); //just looks better..i think? /* Hack */ diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index b9245fba80..4a3413d9ef 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -493,6 +493,7 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian if (ss.is_valid()) { found_state = true; + break; } if (node == edited_scene) { //just in case @@ -506,59 +507,71 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian } } - if (p_current.get_type() == Variant::FLOAT && p_orig.get_type() == Variant::FLOAT) { - float a = p_current; - float b = p_orig; + return is_property_value_different(p_current, p_orig); +} - return !Math::is_equal_approx(a, b); //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error +bool EditorPropertyRevert::is_property_value_different(const Variant &p_a, const Variant &p_b) { + if (p_a.get_type() == Variant::FLOAT && p_b.get_type() == Variant::FLOAT) { + //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error + return !Math::is_equal_approx((float)p_a, (float)p_b); + } else { + return p_a != p_b; } - - return bool(Variant::evaluate(Variant::OP_NOT_EQUAL, p_current, p_orig)); } -bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) { - bool has_revert = false; +Variant EditorPropertyRevert::get_property_revert_value(Object *p_object, const StringName &p_property) { + // If the object implements property_can_revert, rely on that completely + // (i.e. don't then try to revert to default value - the property_get_revert implementation + // can do that if so desired) + if (p_object->has_method("property_can_revert") && p_object->call("property_can_revert", p_property)) { + return p_object->call("property_get_revert", p_property); + } + Ref<Script> scr = p_object->get_script(); Node *node = Object::cast_to<Node>(p_object); - if (node && EditorPropertyRevert::may_node_be_in_instance(node)) { - //check for difference including instantiation - Variant vorig; - if (EditorPropertyRevert::get_instantiated_node_original_property(node, p_property, vorig)) { - Variant v = p_object->get(p_property); - - if (EditorPropertyRevert::is_node_property_different(node, v, vorig)) { - has_revert = true; + //if this node is an instance or inherits, but it has a script attached which is unrelated + //to the one set for the parent and also has a default value for the property, consider that + //has precedence over the value from the parent, because that is an explicit source of defaults + //closer in the tree to the current node + bool ignore_parent = false; + if (scr.is_valid()) { + Variant sorig; + if (EditorPropertyRevert::get_instantiated_node_original_property(node, "script", sorig) && !scr->inherits_script(sorig)) { + Variant dummy; + if (scr->get_property_default_value(p_property, dummy)) { + ignore_parent = true; + } } } - } else { - //check for difference against default class value instead - Variant default_value = ClassDB::class_get_default_property_value(p_object->get_class_name(), p_property); - if (default_value != Variant() && default_value != p_object->get(p_property)) { - has_revert = true; + + if (!ignore_parent) { + //check for difference including instantiation + Variant vorig; + if (EditorPropertyRevert::get_instantiated_node_original_property(node, p_property, vorig)) { + return vorig; + } } } - // If the object implements property_can_revert, rely on that completely - // (i.e. don't then try to revert to default value - the property_get_revert implementation - // can do that if so desired) - if (p_object->has_method("property_can_revert")) { - has_revert = p_object->call("property_can_revert", p_property).operator bool(); - } else { - if (!has_revert && !p_object->get_script().is_null()) { - Ref<Script> scr = p_object->get_script(); - if (scr.is_valid()) { - Variant orig_value; - if (scr->get_property_default_value(p_property, orig_value)) { - if (orig_value != p_object->get(p_property)) { - has_revert = true; - } - } - } + if (scr.is_valid()) { + Variant orig_value; + if (scr->get_property_default_value(p_property, orig_value)) { + return orig_value; } } - return has_revert; + //report default class value instead + return ClassDB::class_get_default_property_value(p_object->get_class_name(), p_property); +} + +bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) { + Variant revert_value = EditorPropertyRevert::get_property_revert_value(p_object, p_property); + if (revert_value.get_type() == Variant::NIL) { + return false; + } + Variant current_value = p_object->get(p_property); + return EditorPropertyRevert::is_property_value_different(current_value, revert_value); } void EditorProperty::update_reload_status() { @@ -761,41 +774,11 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { } if (revert_rect.has_point(mpos)) { - Variant vorig; - - Node *node = Object::cast_to<Node>(object); - if (node && EditorPropertyRevert::may_node_be_in_instance(node) && EditorPropertyRevert::get_instantiated_node_original_property(node, property, vorig)) { - emit_changed(property, vorig.duplicate(true)); - update_property(); - return; - } - - if (object->call("property_can_revert", property).operator bool()) { - Variant rev = object->call("property_get_revert", property); - emit_changed(property, rev); - update_property(); - return; - } - - if (!object->get_script().is_null()) { - Ref<Script> scr = object->get_script(); - if (scr.is_valid()) { - Variant orig_value; - if (scr->get_property_default_value(property, orig_value)) { - emit_changed(property, orig_value); - update_property(); - return; - } - } - } - - Variant default_value = ClassDB::class_get_default_property_value(object->get_class_name(), property); - if (default_value != Variant()) { - emit_changed(property, default_value); - update_property(); - return; - } + Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, property); + emit_changed(property, revert_value); + update_property(); } + if (check_rect.has_point(mpos)) { checked = !checked; update(); @@ -1508,9 +1491,9 @@ String EditorInspector::get_selected_path() const { } void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<EditorInspectorPlugin> ped) { - for (List<EditorInspectorPlugin::AddedEditor>::Element *F = ped->added_editors.front(); F; F = F->next()) { - EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor); - current_vbox->add_child(F->get().property_editor); + for (const EditorInspectorPlugin::AddedEditor &F : ped->added_editors) { + EditorProperty *ep = Object::cast_to<EditorProperty>(F.property_editor); + current_vbox->add_child(F.property_editor); if (ep) { ep->object = object; @@ -1524,19 +1507,19 @@ void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<Edit ep->connect("resource_selected", callable_mp(this, &EditorInspector::_resource_selected), varray(), CONNECT_DEFERRED); ep->connect("object_id_selected", callable_mp(this, &EditorInspector::_object_id_selected), varray(), CONNECT_DEFERRED); - if (F->get().properties.size()) { - if (F->get().properties.size() == 1) { + if (F.properties.size()) { + if (F.properties.size() == 1) { //since it's one, associate: - ep->property = F->get().properties[0]; + ep->property = F.properties[0]; ep->property_usage = 0; } - if (F->get().label != String()) { - ep->set_label(F->get().label); + if (F.label != String()) { + ep->set_label(F.label); } - for (int i = 0; i < F->get().properties.size(); i++) { - String prop = F->get().properties[i]; + for (int i = 0; i < F.properties.size(); i++) { + String prop = F.properties[i]; if (!editor_property_map.has(prop)) { editor_property_map[prop] = List<EditorProperty *>(); @@ -1648,8 +1631,7 @@ void EditorInspector::update_tree() { Color sscolor = get_theme_color(SNAME("prop_subsection"), SNAME("Editor")); - for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) { - Ref<EditorInspectorPlugin> ped = E->get(); + for (Ref<EditorInspectorPlugin> &ped : valid_plugins) { ped->parse_begin(object); _parse_added_editors(main_vbox, ped); } @@ -1746,8 +1728,7 @@ void EditorInspector::update_tree() { category->set_tooltip(p.name + "::" + (class_descr_cache[type2] == "" ? "" : class_descr_cache[type2])); } - for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) { - Ref<EditorInspectorPlugin> ped = E->get(); + for (Ref<EditorInspectorPlugin> &ped : valid_plugins) { ped->parse_category(object, p.name); _parse_added_editors(main_vbox, ped); } @@ -1948,36 +1929,35 @@ void EditorInspector::update_tree() { doc_hint = descr; } - for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) { - Ref<EditorInspectorPlugin> ped = E->get(); + for (Ref<EditorInspectorPlugin> &ped : valid_plugins) { bool exclusive = ped->parse_property(object, p.type, p.name, p.hint, p.hint_string, p.usage, wide_editors); List<EditorInspectorPlugin::AddedEditor> editors = ped->added_editors; //make a copy, since plugins may be used again in a sub-inspector ped->added_editors.clear(); - for (List<EditorInspectorPlugin::AddedEditor>::Element *F = editors.front(); F; F = F->next()) { - EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor); + for (const EditorInspectorPlugin::AddedEditor &F : editors) { + EditorProperty *ep = Object::cast_to<EditorProperty>(F.property_editor); if (ep) { //set all this before the control gets the ENTER_TREE notification ep->object = object; - if (F->get().properties.size()) { - if (F->get().properties.size() == 1) { + if (F.properties.size()) { + if (F.properties.size() == 1) { //since it's one, associate: - ep->property = F->get().properties[0]; + ep->property = F.properties[0]; ep->property_usage = p.usage; //and set label? } - if (F->get().label != String()) { - ep->set_label(F->get().label); + if (F.label != String()) { + ep->set_label(F.label); } else { - //use existin one + // Use the existing one. ep->set_label(name); } - for (int i = 0; i < F->get().properties.size(); i++) { - String prop = F->get().properties[i]; + for (int i = 0; i < F.properties.size(); i++) { + String prop = F.properties[i]; if (!editor_property_map.has(prop)) { editor_property_map[prop] = List<EditorProperty *>(); @@ -1995,7 +1975,7 @@ void EditorInspector::update_tree() { ep->set_deletable(deletable_properties); } - current_vbox->add_child(F->get().property_editor); + current_vbox->add_child(F.property_editor); if (ep) { ep->connect("property_changed", callable_mp(this, &EditorInspector::_property_changed)); @@ -2031,8 +2011,7 @@ void EditorInspector::update_tree() { } } - for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) { - Ref<EditorInspectorPlugin> ped = E->get(); + for (Ref<EditorInspectorPlugin> &ped : valid_plugins) { ped->parse_end(); _parse_added_editors(main_vbox, ped); } @@ -2045,10 +2024,10 @@ void EditorInspector::update_property(const String &p_prop) { return; } - for (List<EditorProperty *>::Element *E = editor_property_map[p_prop].front(); E; E = E->next()) { - E->get()->update_property(); - E->get()->update_reload_status(); - E->get()->update_cache(); + for (EditorProperty *E : editor_property_map[p_prop]) { + E->update_property(); + E->update_reload_status(); + E->update_cache(); } } @@ -2157,24 +2136,24 @@ bool EditorInspector::is_using_folding() { } void EditorInspector::collapse_all_folding() { - for (List<EditorInspectorSection *>::Element *E = sections.front(); E; E = E->next()) { - E->get()->fold(); + for (EditorInspectorSection *E : sections) { + E->fold(); } for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) { - for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) { - E->get()->collapse_all_folding(); + for (EditorProperty *E : F->get()) { + E->collapse_all_folding(); } } } void EditorInspector::expand_all_folding() { - for (List<EditorInspectorSection *>::Element *E = sections.front(); E; E = E->next()) { - E->get()->unfold(); + for (EditorInspectorSection *E : sections) { + E->unfold(); } for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) { - for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) { - E->get()->expand_all_folding(); + for (EditorProperty *E : F->get()) { + E->expand_all_folding(); } } } @@ -2239,9 +2218,9 @@ void EditorInspector::_edit_request_change(Object *p_object, const String &p_pro void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field) { if (autoclear && editor_property_map.has(p_name)) { - for (List<EditorProperty *>::Element *E = editor_property_map[p_name].front(); E; E = E->next()) { - if (E->get()->is_checkable()) { - E->get()->set_checked(true); + for (EditorProperty *E : editor_property_map[p_name]) { + if (E->is_checkable()) { + E->set_checked(true); } } } @@ -2308,8 +2287,8 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo } if (editor_property_map.has(p_name)) { - for (List<EditorProperty *>::Element *E = editor_property_map[p_name].front(); E; E = E->next()) { - E->get()->update_reload_status(); + for (EditorProperty *E : editor_property_map[p_name]) { + E->update_reload_status(); } } } @@ -2367,7 +2346,6 @@ void EditorInspector::_property_keyed(const String &p_path, bool p_advance) { } void EditorInspector::_property_deleted(const String &p_path) { - print_line("deleted pressed?"); if (!object) { return; } @@ -2396,10 +2374,10 @@ void EditorInspector::_property_checked(const String &p_path, bool p_checked) { Variant to_create; List<PropertyInfo> pinfo; object->get_property_list(&pinfo); - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().name == p_path) { + for (const PropertyInfo &E : pinfo) { + if (E.name == p_path) { Callable::CallError ce; - Variant::construct(E->get().type, to_create, nullptr, 0, ce); + Variant::construct(E.type, to_create, nullptr, 0, ce); break; } } @@ -2407,10 +2385,10 @@ void EditorInspector::_property_checked(const String &p_path, bool p_checked) { } if (editor_property_map.has(p_path)) { - for (List<EditorProperty *>::Element *E = editor_property_map[p_path].front(); E; E = E->next()) { - E->get()->update_property(); - E->get()->update_reload_status(); - E->get()->update_cache(); + for (EditorProperty *E : editor_property_map[p_path]) { + E->update_property(); + E->update_reload_status(); + E->update_cache(); } } @@ -2427,9 +2405,9 @@ void EditorInspector::_property_selected(const String &p_path, int p_focusable) if (F->key() == property_selected) { continue; } - for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) { - if (E->get()->is_selected()) { - E->get()->deselect(); + for (EditorProperty *E : F->get()) { + if (E->is_selected()) { + E->deselect(); } } } @@ -2486,11 +2464,11 @@ void EditorInspector::_notification(int p_what) { refresh_countdown -= get_process_delta_time(); if (refresh_countdown <= 0) { for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) { - for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) { - if (!E->get()->is_cache_valid()) { - E->get()->update_property(); - E->get()->update_reload_status(); - E->get()->update_cache(); + for (EditorProperty *E : F->get()) { + if (!E->is_cache_valid()) { + E->update_property(); + E->update_reload_status(); + E->update_cache(); } } } @@ -2509,10 +2487,10 @@ void EditorInspector::_notification(int p_what) { while (pending.size()) { StringName prop = pending.front()->get(); if (editor_property_map.has(prop)) { - for (List<EditorProperty *>::Element *E = editor_property_map[prop].front(); E; E = E->next()) { - E->get()->update_property(); - E->get()->update_reload_status(); - E->get()->update_cache(); + for (EditorProperty *E : editor_property_map[prop]) { + E->update_property(); + E->update_reload_status(); + E->update_cache(); } } pending.erase(pending.front()); @@ -2600,8 +2578,7 @@ void EditorInspector::_update_script_class_properties(const Object &p_object, Li } Set<StringName> added; - for (List<Ref<Script>>::Element *E = classes.front(); E; E = E->next()) { - Ref<Script> s = E->get(); + for (const Ref<Script> &s : classes) { String path = s->get_path(); String name = EditorNode::get_editor_data().script_class_get_name(path); if (name.is_empty()) { diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index ee70bd4397..2bb856dc81 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -42,6 +42,8 @@ public: static bool may_node_be_in_instance(Node *p_node); static bool get_instantiated_node_original_property(Node *p_node, const StringName &p_prop, Variant &value); static bool is_node_property_different(Node *p_node, const Variant &p_current, const Variant &p_orig); + static bool is_property_value_different(const Variant &p_a, const Variant &p_b); + static Variant get_property_revert_value(Object *p_object, const StringName &p_property); static bool can_property_revert(Object *p_object, const StringName &p_property); }; diff --git a/editor/editor_layouts_dialog.cpp b/editor/editor_layouts_dialog.cpp index 16538a2376..0c8660c216 100644 --- a/editor/editor_layouts_dialog.cpp +++ b/editor/editor_layouts_dialog.cpp @@ -92,8 +92,8 @@ void EditorLayoutsDialog::_post_popup() { List<String> layouts; config.ptr()->get_sections(&layouts); - for (List<String>::Element *E = layouts.front(); E; E = E->next()) { - layout_names->add_item(**E); + for (const String &E : layouts) { + layout_names->add_item(E); } } diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index b64cc3f31c..2cb73664f5 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -57,35 +57,43 @@ void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_f } } +void EditorLog::_update_theme() { + Ref<Font> normal_font = get_theme_font(SNAME("output_source"), SNAME("EditorFonts")); + if (normal_font.is_valid()) { + log->add_theme_font_override("normal_font", normal_font); + } + + log->add_theme_font_size_override("normal_font_size", get_theme_font_size(SNAME("output_source_size"), SNAME("EditorFonts"))); + log->add_theme_color_override("selection_color", get_theme_color(SNAME("accent_color"), SNAME("Editor")) * Color(1, 1, 1, 0.4)); + + Ref<Font> bold_font = get_theme_font(SNAME("bold"), SNAME("EditorFonts")); + if (bold_font.is_valid()) { + log->add_theme_font_override("bold_font", bold_font); + } + + type_filter_map[MSG_TYPE_STD]->toggle_button->set_icon(get_theme_icon(SNAME("Popup"), SNAME("EditorIcons"))); + type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons"))); + type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_icon(get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons"))); + type_filter_map[MSG_TYPE_EDITOR]->toggle_button->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"))); + + clear_button->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons"))); + copy_button->set_icon(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons"))); + collapse_button->set_icon(get_theme_icon(SNAME("CombineLines"), SNAME("EditorIcons"))); + show_search_button->set_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); +} + void EditorLog::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - //button->set_icon(get_icon("Console","EditorIcons")); - log->add_theme_font_override("normal_font", get_theme_font(SNAME("output_source"), SNAME("EditorFonts"))); - log->add_theme_font_size_override("normal_font_size", get_theme_font_size(SNAME("output_source_size"), SNAME("EditorFonts"))); - log->add_theme_color_override("selection_color", get_theme_color(SNAME("accent_color"), SNAME("Editor")) * Color(1, 1, 1, 0.4)); - log->add_theme_font_override("bold_font", get_theme_font(SNAME("bold"), SNAME("EditorFonts"))); - - type_filter_map[MSG_TYPE_STD]->toggle_button->set_icon(get_theme_icon(SNAME("Popup"), SNAME("EditorIcons"))); - type_filter_map[MSG_TYPE_ERROR]->toggle_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons"))); - type_filter_map[MSG_TYPE_WARNING]->toggle_button->set_icon(get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons"))); - type_filter_map[MSG_TYPE_EDITOR]->toggle_button->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"))); - - clear_button->set_icon(get_theme_icon(SNAME("Clear"), SNAME("EditorIcons"))); - copy_button->set_icon(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons"))); - collapse_button->set_icon(get_theme_icon(SNAME("CombineLines"), SNAME("EditorIcons"))); - show_search_button->set_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); - - _load_state(); - - } else if (p_what == NOTIFICATION_THEME_CHANGED) { - Ref<Font> df_output_code = get_theme_font(SNAME("output_source"), SNAME("EditorFonts")); - if (df_output_code.is_valid()) { - if (log != nullptr) { - log->add_theme_font_override("normal_font", get_theme_font(SNAME("output_source"), SNAME("EditorFonts"))); - log->add_theme_font_size_override("normal_font_size", get_theme_font_size(SNAME("output_source_size"), SNAME("EditorFonts"))); - log->add_theme_color_override("selection_color", get_theme_color(SNAME("accent_color"), SNAME("Editor")) * Color(1, 1, 1, 0.4)); - } - } + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + _update_theme(); + _load_state(); + } break; + case NOTIFICATION_THEME_CHANGED: { + _update_theme(); + _rebuild_log(); + } break; + default: + break; } } @@ -398,22 +406,22 @@ EditorLog::EditorLog() { vb_right->add_child(memnew(HSeparator)); LogFilter *std_filter = memnew(LogFilter(MSG_TYPE_STD)); - std_filter->initialize_button("Toggle visibility of standard output messages.", callable_mp(this, &EditorLog::_set_filter_active)); + std_filter->initialize_button(TTR("Toggle visibility of standard output messages."), callable_mp(this, &EditorLog::_set_filter_active)); vb_right->add_child(std_filter->toggle_button); type_filter_map.insert(MSG_TYPE_STD, std_filter); LogFilter *error_filter = memnew(LogFilter(MSG_TYPE_ERROR)); - error_filter->initialize_button("Toggle visibility of errors.", callable_mp(this, &EditorLog::_set_filter_active)); + error_filter->initialize_button(TTR("Toggle visibility of errors."), callable_mp(this, &EditorLog::_set_filter_active)); vb_right->add_child(error_filter->toggle_button); type_filter_map.insert(MSG_TYPE_ERROR, error_filter); LogFilter *warning_filter = memnew(LogFilter(MSG_TYPE_WARNING)); - warning_filter->initialize_button("Toggle visibility of warnings.", callable_mp(this, &EditorLog::_set_filter_active)); + warning_filter->initialize_button(TTR("Toggle visibility of warnings."), callable_mp(this, &EditorLog::_set_filter_active)); vb_right->add_child(warning_filter->toggle_button); type_filter_map.insert(MSG_TYPE_WARNING, warning_filter); LogFilter *editor_filter = memnew(LogFilter(MSG_TYPE_EDITOR)); - editor_filter->initialize_button("Toggle visibility of editor messages.", callable_mp(this, &EditorLog::_set_filter_active)); + editor_filter->initialize_button(TTR("Toggle visibility of editor messages."), callable_mp(this, &EditorLog::_set_filter_active)); vb_right->add_child(editor_filter->toggle_button); type_filter_map.insert(MSG_TYPE_EDITOR, editor_filter); diff --git a/editor/editor_log.h b/editor/editor_log.h index 3b6476634a..6cbf4bedee 100644 --- a/editor/editor_log.h +++ b/editor/editor_log.h @@ -163,6 +163,8 @@ private: void _save_state(); void _load_state(); + void _update_theme(); + protected: static void _bind_methods(); void _notification(int p_what); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index e18535a28c..2dfad8f05a 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -508,6 +508,9 @@ void EditorNode::_update_from_settings() { float lod_threshold = GLOBAL_GET("rendering/mesh_lod/lod_change/threshold_pixels"); scene_root->set_lod_threshold(lod_threshold); + + RS::get_singleton()->decals_set_filter(RS::DecalFilter(int(GLOBAL_GET("rendering/textures/decals/filter")))); + RS::get_singleton()->light_projectors_set_filter(RS::LightProjectorFilter(int(GLOBAL_GET("rendering/textures/light_projectors/filter")))); } void EditorNode::_notification(int p_what) { @@ -794,8 +797,8 @@ void EditorNode::_resources_changed(const Vector<String> &p_resources) { } if (changed.size()) { - for (List<Ref<Resource>>::Element *E = changed.front(); E; E = E->next()) { - E->get()->reload_from_file(); + for (Ref<Resource> &res : changed) { + res->reload_from_file(); } } } @@ -911,8 +914,8 @@ void EditorNode::_resources_reimported(const Vector<String> &p_resources) { } } - for (List<String>::Element *E = scenes.front(); E; E = E->next()) { - reload_scene(E->get()); + for (const String &E : scenes) { + reload_scene(E); } scene_tabs->set_current_tab(current_tab); @@ -923,7 +926,7 @@ void EditorNode::_sources_changed(bool p_exist) { waiting_for_first_scan = false; // Reload the global shader variables, but this time - // loading texures, as they are now properly imported. + // loading textures, as they are now properly imported. RenderingServer::get_singleton()->global_variables_load_settings(true); // Start preview thread now that it's safe. @@ -1140,13 +1143,13 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String file->clear_filters(); List<String> preferred; - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (p_resource->is_class("Script") && (E->get() == "tres" || E->get() == "res")) { + for (const String &E : extensions) { + if (p_resource->is_class("Script") && (E == "tres" || E == "res")) { //this serves no purpose and confused people continue; } - file->add_filter("*." + E->get() + " ; " + E->get().to_upper()); - preferred.push_back(E->get()); + file->add_filter("*." + E + " ; " + E.to_upper()); + preferred.push_back(E); } // Lowest priority extension List<String>::Element *res_element = preferred.find("res"); @@ -1165,7 +1168,8 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String file->set_current_file(p_resource->get_path().get_file()); } else { if (extensions.size()) { - file->set_current_file("new_" + p_resource->get_class().to_lower() + "." + preferred.front()->get().to_lower()); + String resource_name_snake_case = p_resource->get_class().camelcase_to_underscore(); + file->set_current_file("new_" + resource_name_snake_case + "." + preferred.front()->get().to_lower()); } else { file->set_current_file(String()); } @@ -1181,7 +1185,8 @@ void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String } else if (preferred.size()) { String existing; if (extensions.size()) { - existing = "new_" + p_resource->get_class().to_lower() + "." + preferred.front()->get().to_lower(); + String resource_name_snake_case = p_resource->get_class().camelcase_to_underscore(); + existing = "new_" + resource_name_snake_case + "." + preferred.front()->get().to_lower(); } file->set_current_path(existing); } @@ -1256,10 +1261,10 @@ void EditorNode::_get_scene_metadata(const String &p_file) { cf->get_section_keys("editor_states", &esl); Dictionary md; - for (List<String>::Element *E = esl.front(); E; E = E->next()) { - Variant st = cf->get_value("editor_states", E->get()); + for (const String &E : esl) { + Variant st = cf->get_value("editor_states", E); if (st.get_type() != Variant::NIL) { - md[E->get()] = st; + md[E] = st; } } @@ -1292,8 +1297,8 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { List<Variant> keys; md.get_key_list(&keys); - for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - cf->set_value("editor_states", E->get(), md[E->get()]); + for (const Variant &E : keys) { + cf->set_value("editor_states", E, md[E]); } Error err = cf->save(path); @@ -1331,14 +1336,14 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> bool ret_changed = false; List<PropertyInfo> pi; obj->get_property_list(&pi); - for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + for (const PropertyInfo &E : pi) { + if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } - switch (E->get().type) { + switch (E.type) { case Variant::OBJECT: { - RES res = obj->get(E->get().name); + RES res = obj->get(E.name); if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; @@ -1346,7 +1351,7 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> } break; case Variant::ARRAY: { - Array varray = obj->get(E->get().name); + Array varray = obj->get(E.name); int len = varray.size(); for (int i = 0; i < len; i++) { const Variant &v = varray.get(i); @@ -1358,11 +1363,11 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool> } break; case Variant::DICTIONARY: { - Dictionary d = obj->get(E->get().name); + Dictionary d = obj->get(E.name); List<Variant> keys; d.get_key_list(&keys); - for (List<Variant>::Element *F = keys.front(); F; F = F->next()) { - Variant v = d[F->get()]; + for (const Variant &F : keys) { + Variant v = d[F]; RES res = v; if (_find_and_save_resource(res, processed, flags)) { ret_changed = true; @@ -1517,9 +1522,9 @@ static bool _find_edited_resources(const Ref<Resource> &p_resource, Set<Ref<Reso p_resource->get_property_list(&plist); - for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (E->get().type == Variant::OBJECT && E->get().usage & PROPERTY_USAGE_STORAGE && !(E->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT)) { - RES res = p_resource->get(E->get().name); + for (const PropertyInfo &E : plist) { + if (E.type == Variant::OBJECT && E.usage & PROPERTY_USAGE_STORAGE && !(E.usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT)) { + RES res = p_resource->get(E.name); if (res.is_null()) { continue; } @@ -1548,12 +1553,11 @@ int EditorNode::_save_external_resources() { int saved = 0; List<Ref<Resource>> cached; ResourceCache::get_cached_resources(&cached); - for (List<Ref<Resource>>::Element *E = cached.front(); E; E = E->next()) { - Ref<Resource> res = E->get(); + for (const Ref<Resource> &res : cached) { if (!res->get_path().is_resource_file()) { continue; } - //not only check if this resourec is edited, check contained subresources too + //not only check if this resource is edited, check contained subresources too if (_find_edited_resources(res, edited_subresources)) { ResourceSaver::save(res->get_path(), res, flg); saved++; @@ -1639,8 +1643,8 @@ void EditorNode::_save_scene(String p_file, int idx) { editor_data.save_editor_external_data(); - for (List<Ref<AnimatedValuesBackup>>::Element *E = anim_backups.front(); E; E = E->next()) { - E->get()->restore(); + for (Ref<AnimatedValuesBackup> &E : anim_backups) { + E->restore(); } if (err == OK) { @@ -1881,8 +1885,8 @@ void EditorNode::_dialog_action(String p_file) { // erase List<String> keys; config->get_section_keys(p_file, &keys); - for (List<String>::Element *E = keys.front(); E; E = E->next()) { - config->set_value(p_file, E->get(), Variant()); + for (const String &E : keys) { + config->set_value(p_file, E, Variant()); } config->save(EditorSettings::get_singleton()->get_editor_layouts_config()); @@ -2530,8 +2534,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { Ref<MeshLibrary> ml(memnew(MeshLibrary)); ResourceSaver::get_recognized_extensions(ml, &extensions); file_export_lib->clear_filters(); - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - file_export_lib->add_filter("*." + E->get()); + for (const String &E : extensions) { + file_export_lib->add_filter("*." + E); } file_export_lib->popup_file_dialog(); @@ -4052,11 +4056,11 @@ void EditorNode::_build_icon_type_cache() { List<StringName> tl; StringName ei = "EditorIcons"; theme_base->get_theme()->get_icon_list(ei, &tl); - for (List<StringName>::Element *E = tl.front(); E; E = E->next()) { - if (!ClassDB::class_exists(E->get())) { + for (const StringName &E : tl) { + if (!ClassDB::class_exists(E)) { continue; } - icon_type_cache[E->get()] = theme_base->get_theme()->get_icon(E->get(), ei); + icon_type_cache[E] = theme_base->get_theme()->get_icon(E, ei); } } @@ -4781,9 +4785,7 @@ void EditorNode::_update_layouts_menu() { List<String> layouts; config.ptr()->get_sections(&layouts); - for (List<String>::Element *E = layouts.front(); E; E = E->next()) { - String layout = E->get(); - + for (const String &layout : layouts) { if (layout == TTR("Default")) { editor_layouts->remove_item(editor_layouts->get_item_index(SETTINGS_LAYOUT_DEFAULT)); overridden_default_layout = editor_layouts->get_item_count(); @@ -5333,27 +5335,6 @@ void EditorNode::_file_access_close_error_notify(const String &p_str) { } void EditorNode::reload_scene(const String &p_path) { - /* - * No longer necessary since scenes now reset and reload their internal resource if needed. - //first of all, reload internal textures, materials, meshes, etc. as they might have changed on disk - - List<Ref<Resource>> cached; - ResourceCache::get_cached_resources(&cached); - List<Ref<Resource>> to_clear; //clear internal resources from previous scene from being used - for (List<Ref<Resource>>::Element *E = cached.front(); E; E = E->next()) { - if (E->get()->get_path().begins_with(p_path + "::")) { //subresources of existing scene - to_clear.push_back(E->get()); - } - } - - //so reload reloads everything, clear subresources of previous scene - while (to_clear.front()) { - to_clear.front()->get()->set_path(""); - to_clear.pop_front(); - } - - */ - int scene_idx = -1; for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { if (editor_data.get_scene_path(i) == p_path) { @@ -6738,8 +6719,8 @@ EditorNode::EditorNode() { file_script->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); List<String> sexts; ResourceLoader::get_recognized_extensions_for_type("Script", &sexts); - for (List<String>::Element *E = sexts.front(); E; E = E->next()) { - file_script->add_filter("*." + E->get()); + for (const String &E : sexts) { + file_script->add_filter("*." + E); } gui_base->add_child(file_script); file_script->connect("file_selected", callable_mp(this, &EditorNode::_dialog_action)); diff --git a/editor/editor_path.cpp b/editor/editor_path.cpp index a31b9fd0c7..f3b3eedccc 100644 --- a/editor/editor_path.cpp +++ b/editor/editor_path.cpp @@ -40,15 +40,15 @@ void EditorPath::_add_children_to_popup(Object *p_obj, int p_depth) { List<PropertyInfo> pinfo; p_obj->get_property_list(&pinfo); - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) { + for (const PropertyInfo &E : pinfo) { + if (!(E.usage & PROPERTY_USAGE_EDITOR)) { continue; } - if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) { + if (E.hint != PROPERTY_HINT_RESOURCE_TYPE) { continue; } - Variant value = p_obj->get(E->get().name); + Variant value = p_obj->get(E.name); if (value.get_type() != Variant::OBJECT) { continue; } @@ -60,7 +60,7 @@ void EditorPath::_add_children_to_popup(Object *p_obj, int p_depth) { Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj); String proper_name = ""; - Vector<String> name_parts = E->get().name.split("/"); + Vector<String> name_parts = E.name.split("/"); for (int i = 0; i < name_parts.size(); i++) { if (i > 0) { diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp index a8b08dc9ed..aa313f0c50 100644 --- a/editor/editor_plugin_settings.cpp +++ b/editor/editor_plugin_settings.cpp @@ -208,11 +208,11 @@ EditorPluginSettings::EditorPluginSettings() { plugin_list->set_v_size_flags(SIZE_EXPAND_FILL); plugin_list->set_columns(5); plugin_list->set_column_titles_visible(true); - plugin_list->set_column_title(0, TTR("Name:")); - plugin_list->set_column_title(1, TTR("Version:")); - plugin_list->set_column_title(2, TTR("Author:")); - plugin_list->set_column_title(3, TTR("Status:")); - plugin_list->set_column_title(4, TTR("Edit:")); + plugin_list->set_column_title(0, TTR("Name")); + plugin_list->set_column_title(1, TTR("Version")); + plugin_list->set_column_title(2, TTR("Author")); + plugin_list->set_column_title(3, TTR("Status")); + plugin_list->set_column_title(4, TTR("Edit")); plugin_list->set_column_expand(0, true); plugin_list->set_column_clip_content(0, true); plugin_list->set_column_expand(1, false); diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 8bb6c590dc..7d809ea656 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -221,8 +221,8 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { } Set<String> valid_extensions; - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - valid_extensions.insert(E->get()); + for (const String &E : extensions) { + valid_extensions.insert(E); } if (!file_dialog) { @@ -260,9 +260,8 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { List<PropertyInfo> property_list; edited_resource->get_property_list(&property_list); List<Pair<String, Variant>> propvalues; - for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) { + for (const PropertyInfo &pi : property_list) { Pair<String, Variant> p; - PropertyInfo &pi = E->get(); if (pi.usage & PROPERTY_USAGE_STORAGE) { p.first = pi.name; p.second = edited_resource->get(pi.name); @@ -276,8 +275,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { Ref<Resource> unique_resource = Ref<Resource>(Object::cast_to<Resource>(inst)); ERR_FAIL_COND(unique_resource.is_null()); - for (List<Pair<String, Variant>>::Element *E = propvalues.front(); E; E = E->next()) { - Pair<String, Variant> &p = E->get(); + for (const Pair<String, Variant> &p : propvalues) { unique_resource->set(p.first, p.second); } @@ -467,13 +465,13 @@ void EditorResourcePicker::_get_allowed_types(bool p_with_convert, Set<String> * List<StringName> inheriters; ClassDB::get_inheriters_from_class(base, &inheriters); - for (List<StringName>::Element *E = inheriters.front(); E; E = E->next()) { - p_vector->insert(E->get()); + for (const StringName &E : inheriters) { + p_vector->insert(E); } - for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) { - if (EditorNode::get_editor_data().script_class_is_parent(E->get(), base)) { - p_vector->insert(E->get()); + for (const StringName &E : global_classes) { + if (EditorNode::get_editor_data().script_class_is_parent(E, base)) { + p_vector->insert(E); } } diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index 5e6d2ab69c..8a7ec9aa82 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -228,8 +228,8 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L } printf("Running: %s", exec.utf8().get_data()); - for (List<String>::Element *E = args.front(); E; E = E->next()) { - printf(" %s", E->get().utf8().get_data()); + for (const String &E : args) { + printf(" %s", E.utf8().get_data()); }; printf("\n"); @@ -250,8 +250,8 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L } bool EditorRun::has_child_process(OS::ProcessID p_pid) const { - for (const List<OS::ProcessID>::Element *E = pids.front(); E; E = E->next()) { - if (E->get() == p_pid) { + for (const OS::ProcessID &E : pids) { + if (E == p_pid) { return true; } } @@ -267,9 +267,10 @@ void EditorRun::stop_child_process(OS::ProcessID p_pid) { void EditorRun::stop() { if (status != STATUS_STOP && pids.size() > 0) { - for (List<OS::ProcessID>::Element *E = pids.front(); E; E = E->next()) { - OS::get_singleton()->kill(E->get()); + for (const OS::ProcessID &E : pids) { + OS::get_singleton()->kill(E); } + pids.clear(); } status = STATUS_STOP; diff --git a/editor/editor_sectioned_inspector.cpp b/editor/editor_sectioned_inspector.cpp index 1209df50ed..751cc7a574 100644 --- a/editor/editor_sectioned_inspector.cpp +++ b/editor/editor_sectioned_inspector.cpp @@ -76,8 +76,7 @@ class SectionedInspectorFilter : public Object { List<PropertyInfo> pinfo; edited->get_property_list(&pinfo); - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - PropertyInfo pi = E->get(); + for (PropertyInfo &pi : pinfo) { int sp = pi.name.find("/"); if (pi.name == "resource_path" || pi.name == "resource_name" || pi.name == "resource_local_to_scene" || pi.name.begins_with("script/") || pi.name.begins_with("_global_script")) { //skip resource stuff @@ -221,9 +220,7 @@ void SectionedInspector::update_category_list() { filter = search_box->get_text(); } - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - PropertyInfo pi = E->get(); - + for (PropertyInfo &pi : pinfo) { if (pi.usage & PROPERTY_USAGE_CATEGORY) { continue; } else if (!(pi.usage & PROPERTY_USAGE_EDITOR) || (restrict_to_basic && !(pi.usage & PROPERTY_USAGE_EDITOR_BASIC_SETTING))) { diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 0667d7116f..df4469b6fe 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -759,8 +759,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { List<String> keys; p_extra_config->get_section_keys("presets", &keys); - for (List<String>::Element *E = keys.front(); E; E = E->next()) { - String key = E->get(); + for (const String &key : keys) { Variant val = p_extra_config->get_value("presets", key); set(key, val); } @@ -815,8 +814,7 @@ bool EditorSettings::_save_text_editor_theme(String p_file) { props.get_key_list(&keys); keys.sort(); - for (const List<String>::Element *E = keys.front(); E; E = E->next()) { - const String &key = E->get(); + for (const String &key : keys) { if (key.begins_with("text_editor/highlighting/") && key.find("color") >= 0) { cf->set_value(theme_section, key.replace("text_editor/highlighting/", ""), ((Color)props[key].variant).to_html()); } @@ -1015,15 +1013,13 @@ void EditorSettings::setup_network() { String selected = "127.0.0.1"; // Check that current remote_host is a valid interface address and populate hints. - for (List<IPAddress>::Element *E = local_ip.front(); E; E = E->next()) { - String ip = E->get(); - + for (const IPAddress &ip : local_ip) { // link-local IPv6 addresses don't work, skipping them - if (ip.begins_with("fe80:0:0:0:")) { // fe80::/64 + if (String(ip).begins_with("fe80:0:0:0:")) { // fe80::/64 continue; } // Same goes for IPv4 link-local (APIPA) addresses. - if (ip.begins_with("169.254.")) { // 169.254.0.0/16 + if (String(ip).begins_with("169.254.")) { // 169.254.0.0/16 continue; } // Select current IP (found) @@ -1303,8 +1299,8 @@ void EditorSettings::list_text_editor_themes() { memdelete(d); custom_themes.sort(); - for (List<String>::Element *E = custom_themes.front(); E; E = E->next()) { - themes += "," + E->get(); + for (const String &E : custom_themes) { + themes += "," + E; } } add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes)); @@ -1332,8 +1328,7 @@ void EditorSettings::load_text_editor_theme() { List<String> keys; cf->get_section_keys("color_theme", &keys); - for (List<String>::Element *E = keys.front(); E; E = E->next()) { - String key = E->get(); + for (const String &key : keys) { String val = cf->get_value("color_theme", key); // don't load if it's not already there! @@ -1434,7 +1429,7 @@ float EditorSettings::get_auto_display_scale() const { return DisplayServer::get_singleton()->screen_get_max_scale(); #else const int screen = DisplayServer::get_singleton()->window_get_current_screen(); - // Use the smallest dimension to use a correct display scale on portait displays. + // Use the smallest dimension to use a correct display scale on portrait displays. const int smallest_dimension = MIN(DisplayServer::get_singleton()->screen_get_size(screen).x, DisplayServer::get_singleton()->screen_get_size(screen).y); if (DisplayServer::get_singleton()->screen_get_dpi(screen) >= 192 && smallest_dimension >= 1400) { // hiDPI display. @@ -1585,8 +1580,8 @@ void EditorSettings::set_builtin_action_override(const String &p_name, const Arr int event_idx = 0; // Check equality of each event. - for (List<Ref<InputEvent>>::Element *E = builtin_events.front(); E; E = E->next()) { - if (!E->get()->is_match(p_events[event_idx])) { + for (const Ref<InputEvent> &E : builtin_events) { + if (!E->is_match(p_events[event_idx])) { same_as_builtin = false; break; } @@ -1615,8 +1610,8 @@ const Array EditorSettings::get_builtin_action_overrides(const String &p_name) c Array event_array; List<Ref<InputEvent>> events_list = AO->get(); - for (List<Ref<InputEvent>>::Element *E = events_list.front(); E; E = E->next()) { - event_array.push_back(E->get()); + for (const Ref<InputEvent> &E : events_list) { + event_array.push_back(E); } return event_array; } diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index cea8081a5f..c230bdcb73 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -582,6 +582,10 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // Focus theme->set_stylebox("Focus", "EditorStyles", style_widget_focus); + // Use a less opaque color to be less distracting for the 2D and 3D editor viewports. + Ref<StyleBoxFlat> style_widget_focus_viewport = style_widget_focus->duplicate(); + style_widget_focus_viewport->set_border_color(accent_color * Color(1, 1, 1, 0.5)); + theme->set_stylebox("FocusViewport", "EditorStyles", style_widget_focus_viewport); // Menu Ref<StyleBoxFlat> style_menu = style_widget->duplicate(); @@ -1024,6 +1028,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_stylebox("read_only", "LineEdit", style_line_edit_disabled); theme->set_icon("clear", "LineEdit", theme->get_icon("GuiClose", "EditorIcons")); theme->set_color("read_only", "LineEdit", font_disabled_color); + theme->set_color("font_uneditable_color", "LineEdit", font_disabled_color); theme->set_color("font_color", "LineEdit", font_color); theme->set_color("font_selected_color", "LineEdit", mono_color); theme->set_color("caret_color", "LineEdit", font_color); @@ -1085,17 +1090,16 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { style_window_title->set_corner_radius(CORNER_TOP_RIGHT, 0); // Prevent visible line between window title and body. style_window_title->set_expand_margin_size(SIDE_BOTTOM, 2 * EDSCALE); - theme->set_stylebox("panel", "Window", style_window_title); Ref<StyleBoxFlat> style_window = style_popup->duplicate(); style_window->set_border_color(base_color); style_window->set_border_width(SIDE_TOP, 24 * EDSCALE); style_window->set_expand_margin_size(SIDE_TOP, 24 * EDSCALE); - theme->set_stylebox("panel_window", "Window", style_window); + theme->set_stylebox("embedded_border", "Window", style_window); theme->set_color("title_color", "Window", font_color); theme->set_icon("close", "Window", theme->get_icon("GuiClose", "EditorIcons")); - theme->set_icon("close_highlight", "Window", theme->get_icon("GuiClose", "EditorIcons")); + theme->set_icon("close_pressed", "Window", theme->get_icon("GuiClose", "EditorIcons")); theme->set_constant("close_h_ofs", "Window", 22 * EDSCALE); theme->set_constant("close_v_ofs", "Window", 20 * EDSCALE); theme->set_constant("title_height", "Window", 24 * EDSCALE); @@ -1111,6 +1115,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_stylebox("panel", "ProjectSettingsEditor", style_complex_window); theme->set_stylebox("panel", "EditorAbout", style_complex_window); + // AcceptDialog + theme->set_stylebox("panel", "AcceptDialog", style_window_title); + // HScrollBar Ref<Texture2D> empty_icon = memnew(ImageTexture); @@ -1189,7 +1196,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { style_tooltip->set_default_margin(SIDE_TOP, default_margin_size * EDSCALE * 0.5); style_tooltip->set_default_margin(SIDE_RIGHT, default_margin_size * EDSCALE); style_tooltip->set_default_margin(SIDE_BOTTOM, default_margin_size * EDSCALE * 0.5); - style_tooltip->set_bg_color(mono_color.inverted() * Color(1, 1, 1, 0.8)); + style_tooltip->set_bg_color(mono_color.inverted()); style_tooltip->set_border_width_all(0); theme->set_color("font_color", "TooltipLabel", font_hover_color); theme->set_color("font_color_shadow", "TooltipLabel", Color(0, 0, 0, 0)); diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 49c2a84e18..daee61c2dd 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -135,9 +135,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory _sort_file_info_list(file_list); // Build the tree. - for (List<FileInfo>::Element *E = file_list.front(); E; E = E->next()) { - FileInfo fi = E->get(); - + for (const FileInfo &fi : file_list) { TreeItem *file_item = tree->create_item(subdirectory_item); file_item->set_text(0, fi.name); file_item->set_structured_text_bidi_override(0, STRUCTURED_TEXT_FILE); @@ -869,8 +867,8 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { // Fills the ItemList control node from the FileInfos. String main_scene = ProjectSettings::get_singleton()->get("application/run/main_scene"); String oi = "Object"; - for (List<FileInfo>::Element *E = file_list.front(); E; E = E->next()) { - FileInfo *finfo = &(E->get()); + for (FileInfo &E : file_list) { + FileInfo *finfo = &(E); String fname = finfo->name; String fpath = finfo->path; String ftype = finfo->type; @@ -966,8 +964,8 @@ void FileSystemDock::_select_file(const String &p_path, bool p_select_in_favorit List<String> importer_exts; ResourceImporterScene::get_singleton()->get_recognized_extensions(&importer_exts); String extension = fpath.get_extension(); - for (List<String>::Element *E = importer_exts.front(); E; E = E->next()) { - if (extension.nocasecmp_to(E->get()) == 0) { + for (const String &E : importer_exts) { + if (extension.nocasecmp_to(E) == 0) { is_imported = true; break; } @@ -1239,9 +1237,7 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> List<Ref<Resource>> cached; ResourceCache::get_cached_resources(&cached); - for (List<Ref<Resource>>::Element *E = cached.front(); E; E = E->next()) { - Ref<Resource> r = E->get(); - + for (Ref<Resource> &r : cached) { String base_path = r->get_path(); String extra_path; int sep_pos = r->get_path().find("::"); @@ -1317,16 +1313,16 @@ void FileSystemDock::_update_project_settings_after_move(const Map<String, Strin // Also search for the file in autoload, as they are stored differently from normal files. List<PropertyInfo> property_list; ProjectSettings::get_singleton()->get_property_list(&property_list); - for (const List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) { - if (E->get().name.begins_with("autoload/")) { + for (const PropertyInfo &E : property_list) { + if (E.name.begins_with("autoload/")) { // If the autoload resource paths has a leading "*", it indicates that it is a Singleton, // so we have to handle both cases when updating. - String autoload = GLOBAL_GET(E->get().name); + String autoload = GLOBAL_GET(E.name); String autoload_singleton = autoload.substr(1, autoload.length()); if (p_renames.has(autoload)) { - ProjectSettings::get_singleton()->set_setting(E->get().name, p_renames[autoload]); + ProjectSettings::get_singleton()->set_setting(E.name, p_renames[autoload]); } else if (autoload.begins_with("*") && p_renames.has(autoload_singleton)) { - ProjectSettings::get_singleton()->set_setting(E->get().name, "*" + p_renames[autoload_singleton]); + ProjectSettings::get_singleton()->set_setting(E.name, "*" + p_renames[autoload_singleton]); } } } @@ -1417,8 +1413,8 @@ void FileSystemDock::_make_scene_confirm() { ResourceSaver::get_recognized_extensions(sd, &extensions); bool extension_correct = false; - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get() == extension) { + for (const String &E : extensions) { + if (E == extension) { extension_correct = true; break; } diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index 87277e79f3..9444706fd2 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -228,6 +228,11 @@ void FindInFiles::_scan_dir(String path, PackedStringArray &out_folders) { break; } + // If there is a .gdignore file in the directory, don't bother searching it + if (file == ".gdignore") { + break; + } + // Ignore special dirs (such as .git and .import) if (file == "." || file == ".." || file.begins_with(".")) { continue; diff --git a/editor/groups_editor.cpp b/editor/groups_editor.cpp index 0a39768b9a..113306fc8a 100644 --- a/editor/groups_editor.cpp +++ b/editor/groups_editor.cpp @@ -240,8 +240,7 @@ void GroupDialog::_group_renamed() { List<Node *> nodes; scene_tree->get_nodes_in_group(selected_group, &nodes); bool removed_all = true; - for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { - Node *node = E->get(); + for (Node *node : nodes) { if (_can_edit(node, selected_group)) { undo_redo->add_do_method(node, "remove_from_group", selected_group); undo_redo->add_undo_method(node, "remove_from_group", name); @@ -286,11 +285,11 @@ void GroupDialog::_load_groups(Node *p_current) { List<Node::GroupInfo> gi; p_current->get_groups(&gi); - for (List<Node::GroupInfo>::Element *E = gi.front(); E; E = E->next()) { - if (!E->get().persistent) { + for (const Node::GroupInfo &E : gi) { + if (!E.persistent) { continue; } - _add_group(E->get().name); + _add_group(E.name); } for (int i = 0; i < p_current->get_child_count(); i++) { @@ -311,10 +310,10 @@ void GroupDialog::_delete_group_pressed(Object *p_item, int p_column, int p_id) List<Node *> nodes; scene_tree->get_nodes_in_group(name, &nodes); bool removed_all = true; - for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { - if (_can_edit(E->get(), name)) { - undo_redo->add_do_method(E->get(), "remove_from_group", name); - undo_redo->add_undo_method(E->get(), "add_to_group", name, true); + for (Node *E : nodes) { + if (_can_edit(E, name)) { + undo_redo->add_do_method(E, "remove_from_group", name); + undo_redo->add_undo_method(E, "add_to_group", name, true); } else { removed_all = false; } @@ -628,8 +627,7 @@ void GroupsEditor::update_tree() { TreeItem *root = tree->create_item(); - for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next()) { - Node::GroupInfo gi = E->get(); + for (const GroupInfo &gi : groups) { if (!gi.persistent) { continue; } diff --git a/editor/icons/ImmediateGeometry3D.svg b/editor/icons/ImmediateGeometry3D.svg deleted file mode 100644 index ec5a392a68..0000000000 --- a/editor/icons/ImmediateGeometry3D.svg +++ /dev/null @@ -1 +0,0 @@ -<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m2.9208 1046.4c-.26373.3-.4204.7296-.4204 1.2383 0 1.6277-3.1381-.1781-.33757 2.6703.88382.899 2.6544.6701 3.5382-.2288.88384-.899.88382-2.3565 0-3.2554-1.1002-1.1191-2.2001-1.0845-2.7803-.4244zm2.3802-1.6103 2.4005 2.4416 6.8014-6.9177c.66286-.6742.66286-1.7673 0-2.4415-.66288-.6741-1.7376-.6741-2.4005 0z" fill="#fc7f7f" transform="translate(0 -1036.4)"/></svg> diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index ddf89f077b..b615c73422 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -894,8 +894,8 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<EditorSceneImpor surftool->add_vertex(vertex_array[k].vertex); } - for (List<int>::Element *E = indices_list.front(); E; E = E->next()) { - surftool->add_index(E->get()); + for (int &E : indices_list) { + surftool->add_index(E); } if (!normal_src) { diff --git a/editor/import/editor_importer_bake_reset.cpp b/editor/import/editor_importer_bake_reset.cpp new file mode 100644 index 0000000000..939c47faa4 --- /dev/null +++ b/editor/import/editor_importer_bake_reset.cpp @@ -0,0 +1,223 @@ +/*************************************************************************/ +/* editor_importer_bake_reset.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* 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 */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "editor/import/editor_importer_bake_reset.h" + +#include "core/error/error_macros.h" +#include "core/math/transform_3d.h" +#include "editor/import/scene_importer_mesh_node_3d.h" +#include "resource_importer_scene.h" +#include "scene/3d/mesh_instance_3d.h" +#include "scene/3d/node_3d.h" +#include "scene/3d/skeleton_3d.h" +#include "scene/animation/animation_player.h" + +// Given that an engineering team has made a reference character, one wants ten animators to create animations. +// Currently, a tech artist needs to combine the ten files into one exported gltf2 to import into Godot Engine. +// We bake the RESET animation and then set it to identity, +// so that rigs with corresponding RESET animation can have their animations transferred with ease. +// +// The original algorithm for the code was used to change skeleton bone rolls to be parent to child. +// +// Reference https://github.com/godotengine/godot-proposals/issues/2961 +void BakeReset::_bake_animation_pose(Node *scene, const String &p_bake_anim) { + Map<StringName, BakeResetRestBone> r_rest_bones; + Vector<Node3D *> r_meshes; + List<Node *> queue; + queue.push_back(scene); + while (!queue.is_empty()) { + List<Node *>::Element *E = queue.front(); + Node *node = E->get(); + AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(node); + // Step 1: import scene with animations into the rest bones data structure. + _fetch_reset_animation(ap, r_rest_bones, p_bake_anim); + + int child_count = node->get_child_count(); + for (int i = 0; i < child_count; i++) { + queue.push_back(node->get_child(i)); + } + queue.pop_front(); + } + + queue.push_back(scene); + while (!queue.is_empty()) { + List<Node *>::Element *E = queue.front(); + Node *node = E->get(); + EditorSceneImporterMeshNode3D *editor_mesh_3d = scene->cast_to<EditorSceneImporterMeshNode3D>(node); + MeshInstance3D *mesh_3d = scene->cast_to<MeshInstance3D>(node); + if (scene->cast_to<Skeleton3D>(node)) { + Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(node); + + // Step 2: Bake the RESET animation from the RestBone to the skeleton. + _fix_skeleton(skeleton, r_rest_bones); + } + if (editor_mesh_3d) { + NodePath path = editor_mesh_3d->get_skeleton_path(); + if (!path.is_empty() && editor_mesh_3d->get_node_or_null(path) && Object::cast_to<Skeleton3D>(editor_mesh_3d->get_node_or_null(path))) { + r_meshes.push_back(editor_mesh_3d); + } + } else if (mesh_3d) { + NodePath path = mesh_3d->get_skeleton_path(); + if (!path.is_empty() && mesh_3d->get_node_or_null(path) && Object::cast_to<Skeleton3D>(mesh_3d->get_node_or_null(path))) { + r_meshes.push_back(mesh_3d); + } + } + int child_count = node->get_child_count(); + for (int i = 0; i < child_count; i++) { + queue.push_back(node->get_child(i)); + } + queue.pop_front(); + } + + queue.push_back(scene); + while (!queue.is_empty()) { + List<Node *>::Element *E = queue.front(); + Node *node = E->get(); + AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(node); + if (ap) { + // Step 3: Key all RESET animation frames to identity. + _align_animations(ap, r_rest_bones); + } + + int child_count = node->get_child_count(); + for (int i = 0; i < child_count; i++) { + queue.push_back(node->get_child(i)); + } + queue.pop_front(); + } +} + +void BakeReset::_align_animations(AnimationPlayer *p_ap, const Map<StringName, BakeResetRestBone> &r_rest_bones) { + ERR_FAIL_NULL(p_ap); + List<StringName> anim_names; + p_ap->get_animation_list(&anim_names); + for (List<StringName>::Element *anim_i = anim_names.front(); anim_i; anim_i = anim_i->next()) { + Ref<Animation> a = p_ap->get_animation(anim_i->get()); + ERR_CONTINUE(a.is_null()); + for (Map<StringName, BakeResetRestBone>::Element *rest_bone_i = r_rest_bones.front(); rest_bone_i; rest_bone_i = rest_bone_i->next()) { + int track = a->find_track(NodePath(rest_bone_i->key())); + if (track == -1) { + continue; + } + int new_track = a->add_track(Animation::TYPE_TRANSFORM3D); + NodePath new_path = NodePath(rest_bone_i->key()); + BakeResetRestBone rest_bone = rest_bone_i->get(); + a->track_set_path(new_track, new_path); + for (int key_i = 0; key_i < a->track_get_key_count(track); key_i++) { + Vector3 loc; + Quaternion rot; + Vector3 scale; + Error err = a->transform_track_get_key(track, key_i, &loc, &rot, &scale); + ERR_CONTINUE(err); + real_t time = a->track_get_key_time(track, key_i); + rot.normalize(); + loc = loc - rest_bone.loc; + rot = rest_bone.rest_delta.get_rotation_quaternion().inverse() * rot; + rot.normalize(); + scale = Vector3(1, 1, 1) - (rest_bone.rest_delta.get_scale() - scale); + // Apply the reverse of the rest changes to make the key be close to identity transform. + a->transform_track_insert_key(new_track, time, loc, rot, scale); + } + a->remove_track(track); + } + } +} + +void BakeReset::_fetch_reset_animation(AnimationPlayer *p_ap, Map<StringName, BakeResetRestBone> &r_rest_bones, const String &p_bake_anim) { + ERR_FAIL_NULL(p_ap); + List<StringName> anim_names; + p_ap->get_animation_list(&anim_names); + Node *root = p_ap->get_owner(); + ERR_FAIL_NULL(root); + Ref<Animation> a = p_ap->get_animation(p_bake_anim); + ERR_FAIL_NULL(a); + for (int32_t track = 0; track < a->get_track_count(); track++) { + NodePath path = a->track_get_path(track); + String string_path = path; + Skeleton3D *skeleton = root->cast_to<Skeleton3D>(root->get_node(string_path.get_slice(":", 0))); + if (!skeleton) { + continue; + } + String bone_name = string_path.get_slice(":", 1); + for (int key_i = 0; key_i < a->track_get_key_count(track); key_i++) { + Vector3 loc; + Quaternion rot; + Vector3 scale; + Error err = a->transform_track_get_key(track, key_i, &loc, &rot, &scale); + ERR_CONTINUE(err); + rot.normalize(); + Basis rot_basis = Basis(rot, scale); + BakeResetRestBone rest_bone; + rest_bone.rest_delta = rot_basis; + rest_bone.loc = loc; + // Store the animation into the RestBone. + r_rest_bones[StringName(String(skeleton->get_owner()->get_path_to(skeleton)) + ":" + bone_name)] = rest_bone; + break; + } + } +} + +void BakeReset::_fix_skeleton(Skeleton3D *p_skeleton, Map<StringName, BakeReset::BakeResetRestBone> &r_rest_bones) { + int bone_count = p_skeleton->get_bone_count(); + + // First iterate through all the bones and update the RestBone. + for (int j = 0; j < bone_count; j++) { + StringName final_path = String(p_skeleton->get_owner()->get_path_to(p_skeleton)) + String(":") + p_skeleton->get_bone_name(j); + BakeResetRestBone &rest_bone = r_rest_bones[final_path]; + rest_bone.rest_local = p_skeleton->get_bone_rest(j); + } + for (int i = 0; i < bone_count; i++) { + int parent_bone = p_skeleton->get_bone_parent(i); + String path = p_skeleton->get_owner()->get_path_to(p_skeleton); + StringName final_path = String(path) + String(":") + p_skeleton->get_bone_name(parent_bone); + if (parent_bone >= 0) { + r_rest_bones[path].children.push_back(i); + } + } + + // When we apply transform to a bone, we also have to move all of its children in the opposite direction. + for (int i = 0; i < bone_count; i++) { + StringName final_path = String(p_skeleton->get_owner()->get_path_to(p_skeleton)) + String(":") + p_skeleton->get_bone_name(i); + r_rest_bones[final_path].rest_local = r_rest_bones[final_path].rest_local * Transform3D(r_rest_bones[final_path].rest_delta, r_rest_bones[final_path].loc); + // Iterate through the children and move in the opposite direction. + for (int j = 0; j < r_rest_bones[final_path].children.size(); j++) { + int child_index = r_rest_bones[final_path].children[j]; + StringName children_path = String(p_skeleton->get_name()) + String(":") + p_skeleton->get_bone_name(child_index); + r_rest_bones[children_path].rest_local = Transform3D(r_rest_bones[final_path].rest_delta, r_rest_bones[final_path].loc).affine_inverse() * r_rest_bones[children_path].rest_local; + } + } + + for (int i = 0; i < bone_count; i++) { + StringName final_path = String(p_skeleton->get_owner()->get_path_to(p_skeleton)) + String(":") + p_skeleton->get_bone_name(i); + ERR_CONTINUE(!r_rest_bones.has(final_path)); + Transform3D rest_transform = r_rest_bones[final_path].rest_local; + p_skeleton->set_bone_rest(i, rest_transform); + } +} diff --git a/editor/import/editor_importer_bake_reset.h b/editor/import/editor_importer_bake_reset.h new file mode 100644 index 0000000000..e36ae86181 --- /dev/null +++ b/editor/import/editor_importer_bake_reset.h @@ -0,0 +1,54 @@ +/*************************************************************************/ +/* editor_importer_bake_reset.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* 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 */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef RESOURCE_IMPORTER_BAKE_RESET_H +#define RESOURCE_IMPORTER_BAKE_RESET_H + +#include "scene/main/node.h" + +class Skeleton3D; +class AnimationPlayer; +class BakeReset { + struct BakeResetRestBone { + Transform3D rest_local; + Basis rest_delta; + Vector3 loc; + Vector<int> children; + }; + +public: + void _bake_animation_pose(Node *scene, const String &p_bake_anim); + +private: + void _fix_skeleton(Skeleton3D *p_skeleton, Map<StringName, BakeReset::BakeResetRestBone> &r_rest_bones); + void _align_animations(AnimationPlayer *p_ap, const Map<StringName, BakeResetRestBone> &r_rest_bones); + void _fetch_reset_animation(AnimationPlayer *p_ap, Map<StringName, BakeResetRestBone> &r_rest_bones, const String &p_bake_anim); +}; +#endif diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 01603c0a6a..34bc0a7d8d 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -438,17 +438,16 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in Node3D *scene = memnew(Node3D); - for (List<Ref<Mesh>>::Element *E = meshes.front(); E; E = E->next()) { + for (const Ref<Mesh> &m : meshes) { Ref<EditorSceneImporterMesh> mesh; mesh.instantiate(); - Ref<Mesh> m = E->get(); for (int i = 0; i < m->get_surface_count(); i++) { mesh->add_surface(m->surface_get_primitive_type(i), m->surface_get_arrays(i), Array(), Dictionary(), m->surface_get_material(i)); } EditorSceneImporterMeshNode3D *mi = memnew(EditorSceneImporterMeshNode3D); mi->set_mesh(mesh); - mi->set_name(E->get()->get_name()); + mi->set_name(m->get_name()); scene->add_child(mi); mi->set_owner(scene); } diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index c14b948dae..1e642462dc 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -32,6 +32,7 @@ #include "core/io/resource_saver.h" #include "editor/editor_node.h" +#include "editor/import/editor_importer_bake_reset.h" #include "editor/import/scene_import_settings.h" #include "editor/import/scene_importer_mesh_node_3d.h" #include "scene/3d/area_3d.h" @@ -312,8 +313,8 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E List<StringName> anims; ap->get_animation_list(&anims); - for (List<StringName>::Element *E = anims.front(); E; E = E->next()) { - Ref<Animation> anim = ap->get_animation(E->get()); + for (const StringName &E : anims) { + Ref<Animation> anim = ap->get_animation(E); ERR_CONTINUE(anim.is_null()); for (int i = 0; i < anim->get_track_count(); i++) { NodePath path = anim->track_get_path(i); @@ -328,14 +329,14 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E } } - String animname = E->get(); + String animname = E; const int loop_string_count = 3; static const char *loop_strings[loop_string_count] = { "loops", "loop", "cycle" }; for (int i = 0; i < loop_string_count; i++) { if (_teststr(animname, loop_strings[i])) { anim->set_loop(true); animname = _fixstr(animname, loop_strings[i]); - ap->rename_animation(E->get(), animname); + ap->rename_animation(E, animname); } } } @@ -659,9 +660,9 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref< } int idx = 0; - for (List<Ref<Shape3D>>::Element *E = shapes.front(); E; E = E->next()) { + for (const Ref<Shape3D> &E : shapes) { CollisionShape3D *cshape = memnew(CollisionShape3D); - cshape->set_shape(E->get()); + cshape->set_shape(E); base->add_child(cshape); cshape->set_owner(base->get_owner()); @@ -712,9 +713,9 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref< //fill node settings for this node with default values List<ImportOption> iopts; get_internal_import_options(INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE, &iopts); - for (List<ImportOption>::Element *E = iopts.front(); E; E = E->next()) { - if (!node_settings.has(E->get().option.name)) { - node_settings[E->get().option.name] = E->get().default_value; + for (const ImportOption &E : iopts) { + if (!node_settings.has(E.option.name)) { + node_settings[E.option.name] = E.default_value; } } } @@ -756,8 +757,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref< } else { List<StringName> anims; ap->get_animation_list(&anims); - for (List<StringName>::Element *E = anims.front(); E; E = E->next()) { - String name = E->get(); + for (const StringName &name : anims) { Ref<Animation> anim = ap->get_animation(name); if (p_animation_data.has(name)) { Dictionary anim_settings = p_animation_data[name]; @@ -765,9 +765,9 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref< //fill with default values List<ImportOption> iopts; get_internal_import_options(INTERNAL_IMPORT_CATEGORY_ANIMATION, &iopts); - for (List<ImportOption>::Element *F = iopts.front(); F; F = F->next()) { - if (!anim_settings.has(F->get().option.name)) { - anim_settings[F->get().option.name] = F->get().default_value; + for (const ImportOption &F : iopts) { + if (!anim_settings.has(F.option.name)) { + anim_settings[F.option.name] = F.default_value; } } } @@ -936,8 +936,8 @@ void ResourceImporterScene::_create_clips(AnimationPlayer *anim, const Array &p_ void ResourceImporterScene::_optimize_animations(AnimationPlayer *anim, float p_max_lin_error, float p_max_ang_error, float p_max_angle) { List<StringName> anim_names; anim->get_animation_list(&anim_names); - for (List<StringName>::Element *E = anim_names.front(); E; E = E->next()) { - Ref<Animation> a = anim->get_animation(E->get()); + for (const StringName &E : anim_names) { + Ref<Animation> a = anim->get_animation(E); a->optimize(p_max_lin_error, p_max_ang_error, Math::deg2rad(p_max_angle)); } } @@ -1046,11 +1046,11 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in String script_ext_hint; - for (List<String>::Element *E = script_extentions.front(); E; E = E->next()) { + for (const String &E : script_extentions) { if (script_ext_hint != "") { script_ext_hint += ","; } - script_ext_hint += "*." + E->get(); + script_ext_hint += "*." + E; } r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "nodes/root_scale", PROPERTY_HINT_RANGE, "0.001,1000,0.001"), 1.0)); @@ -1061,6 +1061,7 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "meshes/lightmap_texel_size", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 0.1)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "skins/use_named_skins"), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/import"), true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/bake_reset_animation"), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "animation/fps", PROPERTY_HINT_RANGE, "1,120,1"), 15)); r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "import_script/path", PROPERTY_HINT_FILE, script_ext_hint), "")); @@ -1089,9 +1090,9 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporte List<String> extensions; E->get()->get_extensions(&extensions); - for (List<String>::Element *F = extensions.front(); F; F = F->next()) { - if (F->get().to_lower() == ext) { - importer = E->get(); + for (const String &F : extensions) { + if (F.to_lower() == ext) { + importer = E; break; } } @@ -1119,9 +1120,9 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito List<String> extensions; E->get()->get_extensions(&extensions); - for (List<String>::Element *F = extensions.front(); F; F = F->next()) { - if (F->get().to_lower() == ext) { - importer = E->get(); + for (const String &F : extensions) { + if (F.to_lower() == ext) { + importer = E; break; } } @@ -1291,9 +1292,9 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m } void ResourceImporterScene::_add_shapes(Node *p_node, const List<Ref<Shape3D>> &p_shapes) { - for (const List<Ref<Shape3D>>::Element *E = p_shapes.front(); E; E = E->next()) { + for (const Ref<Shape3D> &E : p_shapes) { CollisionShape3D *cshape = memnew(CollisionShape3D); - cshape->set_shape(E->get()); + cshape->set_shape(E); p_node->add_child(cshape); cshape->set_owner(p_node->get_owner()); @@ -1311,8 +1312,8 @@ Node *ResourceImporterScene::pre_import(const String &p_source_file) { List<String> extensions; E->get()->get_extensions(&extensions); - for (List<String>::Element *F = extensions.front(); F; F = F->next()) { - if (F->get().to_lower() == ext) { + for (const String &F : extensions) { + if (F.to_lower() == ext) { importer = E->get(); break; } @@ -1351,8 +1352,8 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p List<String> extensions; E->get()->get_extensions(&extensions); - for (List<String>::Element *F = extensions.front(); F; F = F->next()) { - if (F->get().to_lower() == ext) { + for (const String &F : extensions) { + if (F.to_lower() == ext) { importer = E->get(); break; } @@ -1411,6 +1412,11 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p _pre_fix_node(scene, scene, collision_map); _post_fix_node(scene, scene, collision_map, scanned_meshes, node_data, material_data, animation_data, fps); + bool use_bake_reset_animation = p_options["animation/bake_reset_animation"]; + if (use_bake_reset_animation) { + BakeReset bake_reset; + bake_reset._bake_animation_pose(scene, "RESET"); + } String root_type = p_options["nodes/root_type"]; root_type = root_type.split(" ")[0]; // full root_type is "ClassName (filename.gd)" for a script global class. diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index c6e5836a23..781beff689 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -155,7 +155,8 @@ public: virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const override; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override; - virtual int get_import_order() const override { return 100; } //after everything + // Import scenes *after* everything else (such as textures). + virtual int get_import_order() const override { return ResourceImporter::IMPORT_ORDER_SCENE; } Node *_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<EditorSceneImporterMesh>, List<Ref<Shape3D>>> &collision_map); Node *_post_fix_node(Node *p_node, Node *p_root, Map<Ref<EditorSceneImporterMesh>, List<Ref<Shape3D>>> &collision_map, Set<Ref<EditorSceneImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps); diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp index 5dc494d6df..19a8f209bb 100644 --- a/editor/import/scene_import_settings.cpp +++ b/editor/import/scene_import_settings.cpp @@ -71,9 +71,9 @@ class SceneImportSettingsData : public Object { return false; } void _get_property_list(List<PropertyInfo> *p_list) const { - for (const List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { - if (ResourceImporterScene::get_singleton()->get_internal_option_visibility(category, E->get().option.name, current)) { - p_list->push_back(E->get().option); + for (const ResourceImporter::ImportOption &E : options) { + if (ResourceImporterScene::get_singleton()->get_internal_option_visibility(category, E.option.name, current)) { + p_list->push_back(E.option); } } } @@ -305,8 +305,8 @@ void SceneImportSettings::_fill_scene(Node *p_node, TreeItem *p_parent_item) { if (anim_node) { List<StringName> animations; anim_node->get_animation_list(&animations); - for (List<StringName>::Element *E = animations.front(); E; E = E->next()) { - _fill_animation(scene_tree, anim_node->get_animation(E->get()), E->get(), item); + for (const StringName &E : animations) { + _fill_animation(scene_tree, anim_node->get_animation(E), E, item); } } @@ -394,8 +394,8 @@ void SceneImportSettings::_load_default_subresource_settings(Map<StringName, Var d = d[p_import_id]; List<ResourceImporterScene::ImportOption> options; ResourceImporterScene::get_singleton()->get_internal_import_options(p_category, &options); - for (List<ResourceImporterScene::ImportOption>::Element *E = options.front(); E; E = E->next()) { - String key = E->get().option.name; + for (const ResourceImporterScene::ImportOption &E : options) { + String key = E.option.name; if (d.has(key)) { settings[key] = d[key]; } @@ -440,12 +440,12 @@ void SceneImportSettings::open_settings(const String &p_path) { if (err == OK) { List<String> keys; config->get_section_keys("params", &keys); - for (List<String>::Element *E = keys.front(); E; E = E->next()) { - Variant value = config->get_value("params", E->get()); - if (E->get() == "_subresources") { + for (const String &E : keys) { + Variant value = config->get_value("params", E); + if (E == "_subresources") { base_subresource_settings = value; } else { - defaults[E->get()] = value; + defaults[E] = value; } } } @@ -605,13 +605,13 @@ void SceneImportSettings::_select(Tree *p_from, String p_type, String p_id) { scene_import_settings_data->defaults.clear(); scene_import_settings_data->current.clear(); - for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { - scene_import_settings_data->defaults[E->get().option.name] = E->get().default_value; + for (const ResourceImporter::ImportOption &E : options) { + scene_import_settings_data->defaults[E.option.name] = E.default_value; //needed for visibility toggling (fails if something is missing) - if (scene_import_settings_data->settings->has(E->get().option.name)) { - scene_import_settings_data->current[E->get().option.name] = (*scene_import_settings_data->settings)[E->get().option.name]; + if (scene_import_settings_data->settings->has(E.option.name)) { + scene_import_settings_data->current[E.option.name] = (*scene_import_settings_data->settings)[E.option.name]; } else { - scene_import_settings_data->current[E->get().option.name] = E->get().default_value; + scene_import_settings_data->current[E.option.name] = E.default_value; } } scene_import_settings_data->options = options; diff --git a/editor/import/scene_importer_mesh.cpp b/editor/import/scene_importer_mesh.cpp index f8e93df382..0d14347225 100644 --- a/editor/import/scene_importer_mesh.cpp +++ b/editor/import/scene_importer_mesh.cpp @@ -79,11 +79,11 @@ void EditorSceneImporterMesh::add_surface(Mesh::PrimitiveType p_primitive, const List<Variant> lods; p_lods.get_key_list(&lods); - for (List<Variant>::Element *E = lods.front(); E; E = E->next()) { - ERR_CONTINUE(!E->get().is_num()); + for (const Variant &E : lods) { + ERR_CONTINUE(!E.is_num()); Surface::LOD lod; - lod.distance = E->get(); - lod.indices = p_lods[E->get()]; + lod.distance = E; + lod.indices = p_lods[E]; ERR_CONTINUE(lod.indices.size() == 0); s.lods.push_back(lod); } diff --git a/editor/import_defaults_editor.cpp b/editor/import_defaults_editor.cpp index 8c506e938d..25bca1d4f4 100644 --- a/editor/import_defaults_editor.cpp +++ b/editor/import_defaults_editor.cpp @@ -61,9 +61,9 @@ protected: if (importer.is_null()) { return; } - for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { - if (importer->get_option_visibility(E->get().name, values)) { - p_list->push_back(E->get()); + for (const PropertyInfo &E : properties) { + if (importer->get_option_visibility(E.name, values)) { + p_list->push_back(E); } } } @@ -106,9 +106,9 @@ void ImportDefaultsEditor::_update_importer() { List<Ref<ResourceImporter>> importer_list; ResourceFormatImporter::get_singleton()->get_importers(&importer_list); Ref<ResourceImporter> importer; - for (List<Ref<ResourceImporter>>::Element *E = importer_list.front(); E; E = E->next()) { - if (E->get()->get_visible_name() == importers->get_item_text(importers->get_selected())) { - importer = E->get(); + for (const Ref<ResourceImporter> &E : importer_list) { + if (E->get_visible_name() == importers->get_item_text(importers->get_selected())) { + importer = E; break; } } @@ -125,14 +125,14 @@ void ImportDefaultsEditor::_update_importer() { d = ProjectSettings::get_singleton()->get("importer_defaults/" + importer->get_importer_name()); } - for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { - settings->properties.push_back(E->get().option); - if (d.has(E->get().option.name)) { - settings->values[E->get().option.name] = d[E->get().option.name]; + for (const ResourceImporter::ImportOption &E : options) { + settings->properties.push_back(E.option); + if (d.has(E.option.name)) { + settings->values[E.option.name] = d[E.option.name]; } else { - settings->values[E->get().option.name] = E->get().default_value; + settings->values[E.option.name] = E.default_value; } - settings->default_values[E->get().option.name] = E->get().default_value; + settings->default_values[E.option.name] = E.default_value; } save_defaults->set_disabled(false); @@ -166,8 +166,8 @@ void ImportDefaultsEditor::clear() { List<Ref<ResourceImporter>> importer_list; ResourceFormatImporter::get_singleton()->get_importers(&importer_list); Vector<String> names; - for (List<Ref<ResourceImporter>>::Element *E = importer_list.front(); E; E = E->next()) { - String vn = E->get()->get_visible_name(); + for (const Ref<ResourceImporter> &E : importer_list) { + String vn = E->get_visible_name(); names.push_back(vn); } names.sort(); diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index 4110912ff3..648e60a554 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -65,14 +65,14 @@ public: return false; } void _get_property_list(List<PropertyInfo> *p_list) const { - for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { - if (!importer->get_option_visibility(E->get().name, values)) { + for (const PropertyInfo &E : properties) { + if (!importer->get_option_visibility(E.name, values)) { continue; } - PropertyInfo pi = E->get(); + PropertyInfo pi = E; if (checking) { pi.usage |= PROPERTY_USAGE_CHECKABLE; - if (checked.has(E->get().name)) { + if (checked.has(E.name)) { pi.usage |= PROPERTY_USAGE_CHECKED; } } @@ -111,18 +111,18 @@ void ImportDock::set_edit_path(const String &p_path) { ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_path.get_extension(), &importers); List<Pair<String, String>> importer_names; - for (List<Ref<ResourceImporter>>::Element *E = importers.front(); E; E = E->next()) { - importer_names.push_back(Pair<String, String>(E->get()->get_visible_name(), E->get()->get_importer_name())); + for (const Ref<ResourceImporter> &E : importers) { + importer_names.push_back(Pair<String, String>(E->get_visible_name(), E->get_importer_name())); } importer_names.sort_custom<PairSort<String, String>>(); import_as->clear(); - for (List<Pair<String, String>>::Element *E = importer_names.front(); E; E = E->next()) { - import_as->add_item(E->get().first); - import_as->set_item_metadata(import_as->get_item_count() - 1, E->get().second); - if (E->get().second == importer_name) { + for (const Pair<String, String> &E : importer_names) { + import_as->add_item(E.first); + import_as->set_item_metadata(import_as->get_item_count() - 1, E.second); + if (E.second == importer_name) { import_as->select(import_as->get_item_count() - 1); } } @@ -153,12 +153,12 @@ void ImportDock::_update_options(const Ref<ConfigFile> &p_config) { params->checking = params->paths.size() > 1; params->checked.clear(); - for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { - params->properties.push_back(E->get().option); - if (p_config.is_valid() && p_config->has_section_key("params", E->get().option.name)) { - params->values[E->get().option.name] = p_config->get_value("params", E->get().option.name); + for (const ResourceImporter::ImportOption &E : options) { + params->properties.push_back(E.option); + if (p_config.is_valid() && p_config->has_section_key("params", E.option.name)) { + params->values[E.option.name] = p_config->get_value("params", E.option.name); } else { - params->values[E->get().option.name] = E->get().default_value; + params->values[E.option.name] = E.default_value; } } @@ -201,17 +201,17 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { List<String> keys; config->get_section_keys("params", &keys); - for (List<String>::Element *E = keys.front(); E; E = E->next()) { - if (!value_frequency.has(E->get())) { - value_frequency[E->get()] = Dictionary(); + for (const String &E : keys) { + if (!value_frequency.has(E)) { + value_frequency[E] = Dictionary(); } - Variant value = config->get_value("params", E->get()); + Variant value = config->get_value("params", E); - if (value_frequency[E->get()].has(value)) { - value_frequency[E->get()][value] = int(value_frequency[E->get()][value]) + 1; + if (value_frequency[E].has(value)) { + value_frequency[E][value] = int(value_frequency[E][value]) + 1; } else { - value_frequency[E->get()][value] = 1; + value_frequency[E][value] = 1; } } } @@ -226,25 +226,25 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { params->checking = true; params->checked.clear(); - for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { - params->properties.push_back(E->get().option); + for (const ResourceImporter::ImportOption &E : options) { + params->properties.push_back(E.option); - if (value_frequency.has(E->get().option.name)) { - Dictionary d = value_frequency[E->get().option.name]; + if (value_frequency.has(E.option.name)) { + Dictionary d = value_frequency[E.option.name]; int freq = 0; List<Variant> v; d.get_key_list(&v); Variant value; - for (List<Variant>::Element *F = v.front(); F; F = F->next()) { - int f = d[F->get()]; + for (const Variant &F : v) { + int f = d[F]; if (f > freq) { - value = F->get(); + value = F; } } - params->values[E->get().option.name] = value; + params->values[E.option.name] = value; } else { - params->values[E->get().option.name] = E->get().default_value; + params->values[E.option.name] = E.default_value; } } @@ -254,18 +254,18 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_paths[0].get_extension(), &importers); List<Pair<String, String>> importer_names; - for (List<Ref<ResourceImporter>>::Element *E = importers.front(); E; E = E->next()) { - importer_names.push_back(Pair<String, String>(E->get()->get_visible_name(), E->get()->get_importer_name())); + for (const Ref<ResourceImporter> &E : importers) { + importer_names.push_back(Pair<String, String>(E->get_visible_name(), E->get_importer_name())); } importer_names.sort_custom<PairSort<String, String>>(); import_as->clear(); - for (List<Pair<String, String>>::Element *E = importer_names.front(); E; E = E->next()) { - import_as->add_item(E->get().first); - import_as->set_item_metadata(import_as->get_item_count() - 1, E->get().second); - if (E->get().second == params->importer->get_importer_name()) { + for (const Pair<String, String> &E : importer_names) { + import_as->add_item(E.first); + import_as->set_item_metadata(import_as->get_item_count() - 1, E.second); + if (E.second == params->importer->get_importer_name()) { import_as->select(import_as->get_item_count() - 1); } } @@ -345,8 +345,8 @@ void ImportDock::_preset_selected(int p_idx) { case ITEM_SET_AS_DEFAULT: { Dictionary d; - for (const List<PropertyInfo>::Element *E = params->properties.front(); E; E = E->next()) { - d[E->get().name] = params->values[E->get().name]; + for (const PropertyInfo &E : params->properties) { + d[E.name] = params->values[E.name]; } ProjectSettings::get_singleton()->set("importer_defaults/" + params->importer->get_importer_name(), d); @@ -363,10 +363,10 @@ void ImportDock::_preset_selected(int p_idx) { if (params->checking) { params->checked.clear(); } - for (List<Variant>::Element *E = v.front(); E; E = E->next()) { - params->values[E->get()] = d[E->get()]; + for (const Variant &E : v) { + params->values[E] = d[E]; if (params->checking) { - params->checked.insert(E->get()); + params->checked.insert(E); } } params->update(); @@ -384,10 +384,10 @@ void ImportDock::_preset_selected(int p_idx) { if (params->checking) { params->checked.clear(); } - for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { - params->values[E->get().option.name] = E->get().default_value; + for (const ResourceImporter::ImportOption &E : options) { + params->values[E.option.name] = E.default_value; if (params->checking) { - params->checked.insert(E->get().option.name); + params->checked.insert(E.option.name); } } params->update(); @@ -486,9 +486,9 @@ void ImportDock::_reimport() { if (params->checking && config->get_value("remap", "importer") == params->importer->get_importer_name()) { //update only what is edited (checkboxes) if the importer is the same - for (List<PropertyInfo>::Element *E = params->properties.front(); E; E = E->next()) { - if (params->checked.has(E->get().name)) { - config->set_value("params", E->get().name, params->values[E->get().name]); + for (const PropertyInfo &E : params->properties) { + if (params->checked.has(E.name)) { + config->set_value("params", E.name, params->values[E.name]); } } } else { @@ -498,8 +498,8 @@ void ImportDock::_reimport() { config->erase_section("params"); } - for (List<PropertyInfo>::Element *E = params->properties.front(); E; E = E->next()) { - config->set_value("params", E->get().name, params->values[E->get().name]); + for (const PropertyInfo &E : params->properties) { + config->set_value("params", E.name, params->values[E.name]); } } diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index ab307500e7..a566afb597 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -87,12 +87,12 @@ void InspectorDock::_menu_option(int p_option) { List<PropertyInfo> props; current->get_property_list(&props); Map<RES, RES> duplicates; - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + for (const PropertyInfo &E : props) { + if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } - Variant v = current->get(E->get().name); + Variant v = current->get(E.name); if (v.is_ref()) { REF ref = v; if (ref.is_valid()) { @@ -103,8 +103,8 @@ void InspectorDock::_menu_option(int p_option) { } res = duplicates[res]; - current->set(E->get().name, res); - editor->get_inspector()->update_property(E->get().name); + current->set(E.name, res); + editor->get_inspector()->update_property(E.name); } } } @@ -409,6 +409,7 @@ void InspectorDock::update(Object *p_object) { current = p_object; if (!p_object) { + open_docs_button->set_disabled(true); object_menu->set_disabled(true); warning->hide(); search->set_editable(false); @@ -424,7 +425,7 @@ void InspectorDock::update(Object *p_object) { editor_path->enable_path(); resource_save_button->set_disabled(!is_resource); - open_docs_button->set_visible(is_resource || is_node); + open_docs_button->set_disabled(!is_resource && !is_node); PopupMenu *resource_extra_popup = resource_extra_button->get_popup(); resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_COPY), !is_resource); @@ -575,7 +576,7 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { open_docs_button = memnew(Button); open_docs_button->set_flat(true); - open_docs_button->set_visible(false); + open_docs_button->set_disabled(true); open_docs_button->set_tooltip(TTR("Open documentation for this object.")); open_docs_button->set_icon(get_theme_icon(SNAME("HelpSearch"), SNAME("EditorIcons"))); open_docs_button->set_shortcut(ED_SHORTCUT("property_editor/open_help", TTR("Open Documentation"))); diff --git a/editor/localization_editor.cpp b/editor/localization_editor.cpp index f51decd9dc..b32ea67d4d 100644 --- a/editor/localization_editor.cpp +++ b/editor/localization_editor.cpp @@ -43,15 +43,15 @@ void LocalizationEditor::_notification(int p_what) { List<String> tfn; ResourceLoader::get_recognized_extensions_for_type("Translation", &tfn); - for (List<String>::Element *E = tfn.front(); E; E = E->next()) { - translation_file_open->add_filter("*." + E->get()); + for (const String &E : tfn) { + translation_file_open->add_filter("*." + E); } List<String> rfn; ResourceLoader::get_recognized_extensions_for_type("Resource", &rfn); - for (List<String>::Element *E = rfn.front(); E; E = E->next()) { - translation_res_file_open_dialog->add_filter("*." + E->get()); - translation_res_option_file_open_dialog->add_filter("*." + E->get()); + for (const String &E : rfn) { + translation_res_file_open_dialog->add_filter("*." + E); + translation_res_option_file_open_dialog->add_filter("*." + E); } _update_pot_file_extensions(); @@ -430,8 +430,8 @@ void LocalizationEditor::_update_pot_file_extensions() { pot_file_open_dialog->clear_filters(); List<String> translation_parse_file_extensions; EditorTranslationParser::get_singleton()->get_recognized_extensions(&translation_parse_file_extensions); - for (List<String>::Element *E = translation_parse_file_extensions.front(); E; E = E->next()) { - pot_file_open_dialog->add_filter("*." + E->get()); + for (const String &E : translation_parse_file_extensions) { + pot_file_open_dialog->add_filter("*." + E); } } @@ -560,8 +560,8 @@ void LocalizationEditor::update_translations() { List<Variant> rk; remaps.get_key_list(&rk); Vector<String> keys; - for (List<Variant>::Element *E = rk.front(); E; E = E->next()) { - keys.push_back(E->get()); + for (const Variant &E : rk) { + keys.push_back(E); } keys.sort(); diff --git a/editor/multi_node_edit.cpp b/editor/multi_node_edit.cpp index b714109af7..fd4a4334fc 100644 --- a/editor/multi_node_edit.cpp +++ b/editor/multi_node_edit.cpp @@ -52,12 +52,12 @@ bool MultiNodeEdit::_set_impl(const StringName &p_name, const Variant &p_value, UndoRedo *ur = EditorNode::get_undo_redo(); ur->create_action(TTR("MultiNode Set") + " " + String(name), UndoRedo::MERGE_ENDS); - for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) { - if (!es->has_node(E->get())) { + for (const NodePath &E : nodes) { + if (!es->has_node(E)) { continue; } - Node *n = es->get_node(E->get()); + Node *n = es->get_node(E); if (!n) { continue; } @@ -98,12 +98,12 @@ bool MultiNodeEdit::_get(const StringName &p_name, Variant &r_ret) const { name = "script"; } - for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) { - if (!es->has_node(E->get())) { + for (const NodePath &E : nodes) { + if (!es->has_node(E)) { continue; } - const Node *n = es->get_node(E->get()); + const Node *n = es->get_node(E); if (!n) { continue; } @@ -130,12 +130,12 @@ void MultiNodeEdit::_get_property_list(List<PropertyInfo> *p_list) const { List<PLData *> data_list; - for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) { - if (!es->has_node(E->get())) { + for (const NodePath &E : nodes) { + if (!es->has_node(E)) { continue; } - Node *n = es->get_node(E->get()); + Node *n = es->get_node(E); if (!n) { continue; } @@ -143,30 +143,30 @@ void MultiNodeEdit::_get_property_list(List<PropertyInfo> *p_list) const { List<PropertyInfo> plist; n->get_property_list(&plist, true); - for (List<PropertyInfo>::Element *F = plist.front(); F; F = F->next()) { - if (F->get().name == "script") { + for (const PropertyInfo &F : plist) { + if (F.name == "script") { continue; //added later manually, since this is intercepted before being set (check Variant Object::get() ) } - if (!usage.has(F->get().name)) { + if (!usage.has(F.name)) { PLData pld; pld.uses = 0; - pld.info = F->get(); - usage[F->get().name] = pld; - data_list.push_back(usage.getptr(F->get().name)); + pld.info = F; + usage[F.name] = pld; + data_list.push_back(usage.getptr(F.name)); } // Make sure only properties with the same exact PropertyInfo data will appear - if (usage[F->get().name].info == F->get()) { - usage[F->get().name].uses++; + if (usage[F.name].info == F) { + usage[F.name].uses++; } } nc++; } - for (List<PLData *>::Element *E = data_list.front(); E; E = E->next()) { - if (nc == E->get()->uses) { - p_list->push_back(E->get()->info); + for (const PLData *E : data_list) { + if (nc == E->uses) { + p_list->push_back(E->info); } } diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp index 35b27b25aa..5fe466140b 100644 --- a/editor/plugin_config_dialog.cpp +++ b/editor/plugin_config_dialog.cpp @@ -150,7 +150,7 @@ void PluginConfigDialog::_on_required_text_changed(const String &) { if (script_edit->get_text().get_extension() != ext) { is_valid = false; script_validation->set_texture(invalid_icon); - script_validation->set_tooltip(vformat(TTR("Script extension must match chosen langauge extension (.%s)."), ext)); + script_validation->set_tooltip(vformat(TTR("Script extension must match chosen language extension (.%s)."), ext)); } if (script_edit->get_text().get_basename().is_empty()) { is_valid = false; diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index 9e58332e41..ad2d9866fa 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -72,22 +72,22 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven List<StringName> names; ap->get_animation_list(&names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - animations_menu->add_icon_item(get_theme_icon(SNAME("Animation"), SNAME("EditorIcons")), E->get()); - animations_to_add.push_back(E->get()); + for (const StringName &E : names) { + animations_menu->add_icon_item(get_theme_icon(SNAME("Animation"), SNAME("EditorIcons")), E); + animations_to_add.push_back(E); } } } - for (List<StringName>::Element *E = classes.front(); E; E = E->next()) { - String name = String(E->get()).replace_first("AnimationNode", ""); + for (const StringName &E : classes) { + String name = String(E).replace_first("AnimationNode", ""); if (name == "Animation") { continue; } int idx = menu->get_item_count(); menu->add_item(vformat("Add %s", name), idx); - menu->set_item_metadata(idx, E->get()); + menu->set_item_metadata(idx, E); } Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard(); @@ -373,8 +373,8 @@ void AnimationNodeBlendSpace1DEditor::_add_menu_type(int p_index) { open_file->clear_filters(); List<String> filters; ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters); - for (List<String>::Element *E = filters.front(); E; E = E->next()) { - open_file->add_filter("*." + E->get()); + for (const String &E : filters) { + open_file->add_filter("*." + E); } open_file->popup_file_dialog(); return; diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index bbf88bbd8f..49fcac512b 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -96,21 +96,21 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven if (ap) { List<StringName> names; ap->get_animation_list(&names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - animations_menu->add_icon_item(get_theme_icon(SNAME("Animation"), SNAME("EditorIcons")), E->get()); - animations_to_add.push_back(E->get()); + for (const StringName &E : names) { + animations_menu->add_icon_item(get_theme_icon(SNAME("Animation"), SNAME("EditorIcons")), E); + animations_to_add.push_back(E); } } } - for (List<StringName>::Element *E = classes.front(); E; E = E->next()) { - String name = String(E->get()).replace_first("AnimationNode", ""); + for (const StringName &E : classes) { + String name = String(E).replace_first("AnimationNode", ""); if (name == "Animation") { continue; // nope } int idx = menu->get_item_count(); menu->add_item(vformat("Add %s", name), idx); - menu->set_item_metadata(idx, E->get()); + menu->set_item_metadata(idx, E); } Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard(); @@ -295,8 +295,8 @@ void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) { open_file->clear_filters(); List<String> filters; ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters); - for (List<String>::Element *E = filters.front(); E; E = E->next()) { - open_file->add_filter("*." + E->get()); + for (const String &E : filters) { + open_file->add_filter("*." + E); } open_file->popup_file_dialog(); return; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 7930bc1e1c..69206daea8 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -89,7 +89,7 @@ Size2 AnimationNodeBlendTreeEditor::get_minimum_size() const { void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) { AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_tree(); updating = true; - undo_redo->create_action(TTR("Parameter Changed") + ": " + String(p_property), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Parameter Changed:") + " " + String(p_property), UndoRedo::MERGE_ENDS); undo_redo->add_do_property(tree, p_property, p_value); undo_redo->add_undo_property(tree, p_property, tree->get(p_property)); undo_redo->add_do_method(this, "_update_graph"); @@ -121,21 +121,21 @@ void AnimationNodeBlendTreeEditor::_update_graph() { List<StringName> nodes; blend_tree->get_node_list(&nodes); - for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) { + for (const StringName &E : nodes) { GraphNode *node = memnew(GraphNode); graph->add_child(node); - Ref<AnimationNode> agnode = blend_tree->get_node(E->get()); + Ref<AnimationNode> agnode = blend_tree->get_node(E); - node->set_position_offset(blend_tree->get_node_position(E->get()) * EDSCALE); + node->set_position_offset(blend_tree->get_node_position(E) * EDSCALE); node->set_title(agnode->get_caption()); - node->set_name(E->get()); + node->set_name(E); int base = 0; - if (String(E->get()) != "output") { + if (String(E) != "output") { LineEdit *name = memnew(LineEdit); - name->set_text(E->get()); + name->set_text(E); name->set_expand_to_text_length_enabled(true); node->add_child(name); node->set_slot(0, false, 0, Color(), true, 0, get_theme_color(SNAME("font_color"), SNAME("Label"))); @@ -143,7 +143,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { name->connect("focus_exited", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed_focus_out), varray(name, agnode), CONNECT_DEFERRED); base = 1; node->set_show_close_button(true); - node->connect("close_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_request), varray(E->get()), CONNECT_DEFERRED); + node->connect("close_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_request), varray(E), CONNECT_DEFERRED); } for (int i = 0; i < agnode->get_input_count(); i++) { @@ -155,12 +155,12 @@ void AnimationNodeBlendTreeEditor::_update_graph() { List<PropertyInfo> pinfo; agnode->get_parameter_list(&pinfo); - for (List<PropertyInfo>::Element *F = pinfo.front(); F; F = F->next()) { - if (!(F->get().usage & PROPERTY_USAGE_EDITOR)) { + for (const PropertyInfo &F : pinfo) { + if (!(F.usage & PROPERTY_USAGE_EDITOR)) { continue; } - String base_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E->get()) + "/" + F->get().name; - EditorProperty *prop = EditorInspector::instantiate_property_editor(AnimationTreeEditor::get_singleton()->get_tree(), F->get().type, base_path, F->get().hint, F->get().hint_string, F->get().usage); + String base_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E) + "/" + F.name; + EditorProperty *prop = EditorInspector::instantiate_property_editor(AnimationTreeEditor::get_singleton()->get_tree(), F.type, base_path, F.hint, F.hint_string, F.usage); if (prop) { prop->set_object_and_property(AnimationTreeEditor::get_singleton()->get_tree(), base_path); prop->update_property(); @@ -171,7 +171,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { } } - node->connect("dragged", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_dragged), varray(E->get())); + node->connect("dragged", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_dragged), varray(E)); if (AnimationTreeEditor::get_singleton()->can_edit(agnode)) { node->add_child(memnew(HSeparator)); @@ -179,7 +179,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { open_in_editor->set_text(TTR("Open Editor")); open_in_editor->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons"))); node->add_child(open_in_editor); - open_in_editor->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_open_in_editor), varray(E->get()), CONNECT_DEFERRED); + open_in_editor->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_open_in_editor), varray(E), CONNECT_DEFERRED); open_in_editor->set_h_size_flags(SIZE_SHRINK_CENTER); } @@ -189,7 +189,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { edit_filters->set_text(TTR("Edit Filters")); edit_filters->set_icon(get_theme_icon(SNAME("AnimationFilter"), SNAME("EditorIcons"))); node->add_child(edit_filters); - edit_filters->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_edit_filters), varray(E->get()), CONNECT_DEFERRED); + edit_filters->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_edit_filters), varray(E), CONNECT_DEFERRED); edit_filters->set_h_size_flags(SIZE_SHRINK_CENTER); } @@ -212,9 +212,9 @@ void AnimationNodeBlendTreeEditor::_update_graph() { List<StringName> anims; ap->get_animation_list(&anims); - for (List<StringName>::Element *F = anims.front(); F; F = F->next()) { - mb->get_popup()->add_item(F->get()); - options.push_back(F->get()); + for (const StringName &F : anims) { + mb->get_popup()->add_item(F); + options.push_back(F); } if (ap->has_animation(anim->get_animation())) { @@ -225,10 +225,10 @@ void AnimationNodeBlendTreeEditor::_update_graph() { pb->set_percent_visible(false); pb->set_custom_minimum_size(Vector2(0, 14) * EDSCALE); - animations[E->get()] = pb; + animations[E] = pb; node->add_child(pb); - mb->get_popup()->connect("index_pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_anim_selected), varray(options, E->get()), CONNECT_DEFERRED); + mb->get_popup()->connect("index_pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_anim_selected), varray(options, E), CONNECT_DEFERRED); } Ref<StyleBoxFlat> sb = node->get_theme_stylebox(SNAME("frame"), SNAME("GraphNode")); @@ -246,10 +246,10 @@ void AnimationNodeBlendTreeEditor::_update_graph() { List<AnimationNodeBlendTree::NodeConnection> connections; blend_tree->get_node_connections(&connections); - for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = connections.front(); E; E = E->next()) { - StringName from = E->get().output_node; - StringName to = E->get().input_node; - int to_idx = E->get().input_index; + for (const AnimationNodeBlendTree::NodeConnection &E : connections) { + StringName from = E.output_node; + StringName to = E.input_node; + int to_idx = E.input_index; graph->connect_node(from, 0, to, to_idx); } @@ -274,8 +274,8 @@ void AnimationNodeBlendTreeEditor::_add_node(int p_idx) { open_file->clear_filters(); List<String> filters; ResourceLoader::get_recognized_extensions_for_type("AnimationNode", &filters); - for (List<String>::Element *E = filters.front(); E; E = E->next()) { - open_file->add_filter("*." + E->get()); + for (const String &E : filters) { + open_file->add_filter("*." + E); } open_file->popup_file_dialog(); return; @@ -394,9 +394,9 @@ void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) { List<AnimationNodeBlendTree::NodeConnection> conns; blend_tree->get_node_connections(&conns); - for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = conns.front(); E; E = E->next()) { - if (E->get().output_node == p_which || E->get().input_node == p_which) { - undo_redo->add_undo_method(blend_tree.ptr(), "connect_node", E->get().input_node, E->get().input_index, E->get().output_node); + for (const AnimationNodeBlendTree::NodeConnection &E : conns) { + if (E.output_node == p_which || E.input_node == p_which) { + undo_redo->add_undo_method(blend_tree.ptr(), "connect_node", E.input_node, E.input_index, E.output_node); } } @@ -423,8 +423,8 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request() { undo_redo->create_action(TTR("Delete Node(s)")); - for (List<StringName>::Element *F = to_erase.front(); F; F = F->next()) { - _delete_request(F->get()); + for (const StringName &F : to_erase) { + _delete_request(F); } undo_redo->commit_action(); @@ -517,8 +517,8 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano List<StringName> animations; player->get_animation_list(&animations); - for (List<StringName>::Element *E = animations.front(); E; E = E->next()) { - Ref<Animation> anim = player->get_animation(E->get()); + for (const StringName &E : animations) { + Ref<Animation> anim = player->get_animation(E); for (int i = 0; i < anim->get_track_count(); i++) { String track_path = anim->track_get_path(i); paths.insert(track_path); @@ -718,13 +718,13 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { List<AnimationNodeBlendTree::NodeConnection> conns; blend_tree->get_node_connections(&conns); - for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = conns.front(); E; E = E->next()) { + for (const AnimationNodeBlendTree::NodeConnection &E : conns) { float activity = 0; - StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E->get().input_node; + StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node; if (AnimationTreeEditor::get_singleton()->get_tree() && !AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) { - activity = AnimationTreeEditor::get_singleton()->get_tree()->get_connection_activity(path, E->get().input_index); + activity = AnimationTreeEditor::get_singleton()->get_tree()->get_connection_activity(path, E.input_index); } - graph->set_connection_activity(E->get().output_node, 0, E->get().input_node, E->get().input_index, activity); + graph->set_connection_activity(E.output_node, 0, E.input_node, E.input_index, activity); } AnimationTree *graph_player = AnimationTreeEditor::get_singleton()->get_tree(); @@ -741,7 +741,7 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) { Ref<Animation> anim = player->get_animation(an->get_animation()); if (anim.is_valid()) { E->get()->set_max(anim->get_length()); - //StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E->get().input_node; + //StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node; StringName time_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E->key()) + "/time"; E->get()->set_value(AnimationTreeEditor::get_singleton()->get_tree()->get(time_path)); } @@ -828,10 +828,10 @@ void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<Anima List<AnimationNodeBlendTree::NodeConnection> connections; blend_tree->get_node_connections(&connections); - for (List<AnimationNodeBlendTree::NodeConnection>::Element *E = connections.front(); E; E = E->next()) { - StringName from = E->get().output_node; - StringName to = E->get().input_node; - int to_idx = E->get().input_index; + for (const AnimationNodeBlendTree::NodeConnection &E : connections) { + StringName from = E.output_node; + StringName to = E.input_node; + int to_idx = E.input_index; graph->connect_node(from, 0, to, to_idx); } diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index acfa873f62..681c3e7195 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -350,8 +350,8 @@ void AnimationPlayerEditor::_animation_load() { List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("Animation", &extensions); - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - file->add_filter("*." + E->get() + " ; " + E->get().to_upper()); + for (const String &E : extensions) { + file->add_filter("*." + E + " ; " + E.to_upper()); } file->popup_file_dialog(); @@ -408,7 +408,8 @@ void AnimationPlayerEditor::_animation_save_as(const Ref<Resource> &p_resource) if (p_resource->get_name() != "") { path = p_resource->get_name() + "." + extensions.front()->get().to_lower(); } else { - path = "new_" + p_resource->get_class().to_lower() + "." + extensions.front()->get().to_lower(); + String resource_name_snake_case = p_resource->get_class().camelcase_to_underscore(); + path = "new_" + resource_name_snake_case + "." + extensions.front()->get().to_lower(); } } } @@ -584,8 +585,7 @@ void AnimationPlayerEditor::_animation_blend() { blend_editor.next->clear(); blend_editor.next->add_item("", i); - for (List<StringName>::Element *E = anims.front(); E; E = E->next()) { - String to = E->get(); + for (const StringName &to : anims) { TreeItem *blend = blend_editor.tree->create_item(root); blend->set_editable(0, false); blend->set_editable(1, true); @@ -830,20 +830,20 @@ void AnimationPlayerEditor::_update_player() { } int active_idx = -1; - for (List<StringName>::Element *E = animlist.front(); E; E = E->next()) { + for (const StringName &E : animlist) { Ref<Texture2D> icon; - if (E->get() == player->get_autoplay()) { - if (E->get() == "RESET") { + if (E == player->get_autoplay()) { + if (E == "RESET") { icon = autoplay_reset_icon; } else { icon = autoplay_icon; } - } else if (E->get() == "RESET") { + } else if (E == "RESET") { icon = reset_icon; } - animation->add_icon_item(icon, E->get()); + animation->add_icon_item(icon, E); - if (player->get_assigned_animation() == E->get()) { + if (player->get_assigned_animation() == E) { active_idx = animation->get_item_count() - 1; } } @@ -966,9 +966,9 @@ void AnimationPlayerEditor::_animation_duplicate() { Ref<Animation> new_anim = memnew(Animation); List<PropertyInfo> plist; anim->get_property_list(&plist); - for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_STORAGE) { - new_anim->set(E->get().name, anim->get(E->get().name)); + for (const PropertyInfo &E : plist) { + if (E.usage & PROPERTY_USAGE_STORAGE) { + new_anim->set(E.name, anim->get(E.name)); } } new_anim->set_path(""); @@ -1733,27 +1733,27 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay onion.capture.material = Ref<ShaderMaterial>(memnew(ShaderMaterial)); onion.capture.shader = Ref<Shader>(memnew(Shader)); - onion.capture.shader->set_code(" \ - shader_type canvas_item; \ - \ - uniform vec4 bkg_color; \ - uniform vec4 dir_color; \ - uniform bool differences_only; \ - uniform sampler2D present; \ - \ - float zero_if_equal(vec4 a, vec4 b) { \ - return smoothstep(0.0, 0.005, length(a.rgb - b.rgb) / sqrt(3.0)); \ - } \ - \ - void fragment() { \ - vec4 capture_samp = texture(TEXTURE, UV); \ - vec4 present_samp = texture(present, UV); \ - float bkg_mask = zero_if_equal(capture_samp, bkg_color); \ - float diff_mask = 1.0 - zero_if_equal(present_samp, bkg_color); \ - diff_mask = min(1.0, diff_mask + float(!differences_only)); \ - COLOR = vec4(capture_samp.rgb * dir_color.rgb, bkg_mask * diff_mask); \ - } \ - "); + onion.capture.shader->set_code(R"( +shader_type canvas_item; + +uniform vec4 bkg_color; +uniform vec4 dir_color; +uniform bool differences_only; +uniform sampler2D present; + +float zero_if_equal(vec4 a, vec4 b) { + return smoothstep(0.0, 0.005, length(a.rgb - b.rgb) / sqrt(3.0)); +} + +void fragment() { + vec4 capture_samp = texture(TEXTURE, UV); + vec4 present_samp = texture(present, UV); + float bkg_mask = zero_if_equal(capture_samp, bkg_color); + float diff_mask = 1.0 - zero_if_equal(present_samp, bkg_color); + diff_mask = min(1.0, diff_mask + float(!differences_only)); + COLOR = vec4(capture_samp.rgb * dir_color.rgb, bkg_mask * diff_mask); +} +)"); RS::get_singleton()->material_set_shader(onion.capture.material->get_rid(), onion.capture.shader->get_rid()); } diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index 8abe20c3c9..a1f96f21bf 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -93,21 +93,21 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv if (ap) { List<StringName> names; ap->get_animation_list(&names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - animations_menu->add_icon_item(get_theme_icon(SNAME("Animation"), SNAME("EditorIcons")), E->get()); - animations_to_add.push_back(E->get()); + for (const StringName &E : names) { + animations_menu->add_icon_item(get_theme_icon(SNAME("Animation"), SNAME("EditorIcons")), E); + animations_to_add.push_back(E); } } } - for (List<StringName>::Element *E = classes.front(); E; E = E->next()) { - String name = String(E->get()).replace_first("AnimationNode", ""); + for (const StringName &E : classes) { + String name = String(E).replace_first("AnimationNode", ""); if (name == "Animation") { continue; // nope } int idx = menu->get_item_count(); menu->add_item(vformat("Add %s", name), idx); - menu->set_item_metadata(idx, E->get()); + menu->set_item_metadata(idx, E); } Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard(); @@ -318,24 +318,24 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv float best_d_x = 1e20; float best_d_y = 1e20; - for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) { - if (E->get() == selected_node) { + for (const StringName &E : nodes) { + if (E == selected_node) { continue; } - Vector2 npos = state_machine->get_node_position(E->get()); + Vector2 npos = state_machine->get_node_position(E); float d_x = ABS(npos.x - cpos.x); if (d_x < MIN(5, best_d_x)) { drag_ofs.x -= cpos.x - npos.x; best_d_x = d_x; - snap_x = E->get(); + snap_x = E; } float d_y = ABS(npos.y - cpos.y); if (d_y < MIN(5, best_d_y)) { drag_ofs.y -= cpos.y - npos.y; best_d_y = d_y; - snap_y = E->get(); + snap_y = E; } } } @@ -409,8 +409,8 @@ void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) { open_file->clear_filters(); List<String> filters; ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters); - for (List<String>::Element *E = filters.front(); E; E = E->next()) { - open_file->add_filter("*." + E->get()); + for (const String &E : filters) { + open_file->add_filter("*." + E); } open_file->popup_file_dialog(); return; @@ -606,11 +606,11 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { } //pre pass nodes so we know the rectangles - for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) { - Ref<AnimationNode> anode = state_machine->get_node(E->get()); - String name = E->get(); + for (const StringName &E : nodes) { + Ref<AnimationNode> anode = state_machine->get_node(E); + String name = E; bool needs_editor = EditorNode::get_singleton()->item_has_editor(anode.ptr()); - Ref<StyleBox> sb = E->get() == selected_node ? style_selected : style; + Ref<StyleBox> sb = E == selected_node ? style_selected : style; Size2 s = sb->get_minimum_size(); int strsize = font->get_string_size(name, font_size).width; @@ -622,8 +622,8 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { } Vector2 offset; - offset += state_machine->get_node_position(E->get()) * EDSCALE; - if (selected_node == E->get() && dragging_selected) { + offset += state_machine->get_node_position(E) * EDSCALE; + if (selected_node == E && dragging_selected) { offset += drag_ofs; } offset -= s / 2; @@ -633,7 +633,7 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() { NodeRect nr; nr.node = Rect2(offset, s); - nr.node_name = E->get(); + nr.node_name = E; scroll_range = scroll_range.merge(nr.node); //merge with range diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index e90665f84d..cd84be0c25 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -79,7 +79,7 @@ void AnimationTreeEditor::_update_path() { group.instantiate(); Button *b = memnew(Button); - b->set_text("Root"); + b->set_text(TTR("Root")); b->set_toggle_mode(true); b->set_button_group(group); b->set_pressed(true); @@ -215,8 +215,8 @@ Vector<String> AnimationTreeEditor::get_animation_list() { List<StringName> anims; ap->get_animation_list(&anims); Vector<String> ret; - for (List<StringName>::Element *E = anims.front(); E; E = E->next()) { - ret.push_back(E->get()); + for (const StringName &E : anims) { + ret.push_back(E); } return ret; diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index bbc8107cf6..785bab42cf 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -603,12 +603,11 @@ void EditorAssetLibrary::_notification(int p_what) { void EditorAssetLibrary::_update_repository_options() { Dictionary default_urls; - default_urls["godotengine.org"] = "https://godotengine.org/asset-library/api"; - default_urls["localhost"] = "http://127.0.0.1/asset-library/api"; + default_urls["godotengine.org (Official)"] = "https://godotengine.org/asset-library/api"; Dictionary available_urls = _EDITOR_DEF("asset_library/available_urls", default_urls, true); repository->clear(); Array keys = available_urls.keys(); - for (int i = 0; i < available_urls.size(); i++) { + for (int i = 0; i < keys.size(); i++) { String key = keys[i]; repository->add_item(key); repository->set_item_metadata(i, available_urls[key]); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index aedcf16fa5..cd16353d6a 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -301,8 +301,8 @@ void CanvasItemEditor::_snap_other_nodes( // Check if the element is in the exception bool exception = false; - for (List<const CanvasItem *>::Element *E = p_exceptions.front(); E; E = E->next()) { - if (E->get() == p_current) { + for (const CanvasItem *&E : p_exceptions) { + if (E == p_current) { exception = true; break; } @@ -399,8 +399,8 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsig if ((is_snap_active && snap_other_nodes && (p_modes & SNAP_OTHER_NODES)) || (p_forced_modes & SNAP_OTHER_NODES)) { Transform2D to_snap_transform = Transform2D(); List<const CanvasItem *> exceptions = List<const CanvasItem *>(); - for (List<CanvasItem *>::Element *E = p_other_nodes_exceptions.front(); E; E = E->next()) { - exceptions.push_back(E->get()); + for (const CanvasItem *E : p_other_nodes_exceptions) { + exceptions.push_back(E); } if (p_self_canvas_item) { exceptions.push_back(p_self_canvas_item); @@ -527,8 +527,7 @@ Rect2 CanvasItemEditor::_get_encompassing_rect_from_list(List<CanvasItem *> p_li Rect2 rect = Rect2(canvas_item->get_global_transform_with_canvas().xform(canvas_item->_edit_get_rect().position + canvas_item->_edit_get_rect().size / 2), Size2()); // Expand with the other ones - for (List<CanvasItem *>::Element *E = p_list.front(); E; E = E->next()) { - CanvasItem *canvas_item2 = E->get(); + for (CanvasItem *canvas_item2 : p_list) { Transform2D xform = canvas_item2->get_global_transform_with_canvas(); Rect2 current_rect = canvas_item2->_edit_get_rect(); @@ -760,9 +759,9 @@ List<CanvasItem *> CanvasItemEditor::_get_edited_canvas_items(bool retreive_lock if (remove_canvas_item_if_parent_in_selection) { List<CanvasItem *> filtered_selection; - for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) { - if (!selection.find(E->get()->get_parent())) { - filtered_selection.push_back(E->get()); + for (CanvasItem *E : selection) { + if (!selection.find(E->get_parent())) { + filtered_selection.push_back(E); } } return filtered_selection; @@ -800,8 +799,7 @@ Vector2 CanvasItemEditor::_position_to_anchor(const Control *p_control, Vector2 } void CanvasItemEditor::_save_canvas_item_state(List<CanvasItem *> p_canvas_items, bool save_bones) { - for (List<CanvasItem *>::Element *E = p_canvas_items.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : p_canvas_items) { CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); if (se) { se->undo_state = canvas_item->_edit_get_state(); @@ -816,8 +814,7 @@ void CanvasItemEditor::_save_canvas_item_state(List<CanvasItem *> p_canvas_items } void CanvasItemEditor::_restore_canvas_item_state(List<CanvasItem *> p_canvas_items, bool restore_bones) { - for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : drag_selection) { CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); canvas_item->_edit_set_state(se->undo_state); } @@ -825,8 +822,7 @@ void CanvasItemEditor::_restore_canvas_item_state(List<CanvasItem *> p_canvas_it void CanvasItemEditor::_commit_canvas_item_state(List<CanvasItem *> p_canvas_items, String action_name, bool commit_bones) { List<CanvasItem *> modified_canvas_items; - for (List<CanvasItem *>::Element *E = p_canvas_items.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : p_canvas_items) { Dictionary old_state = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item)->undo_state; Dictionary new_state = canvas_item->_edit_get_state(); @@ -840,17 +836,16 @@ void CanvasItemEditor::_commit_canvas_item_state(List<CanvasItem *> p_canvas_ite } undo_redo->create_action(action_name); - for (List<CanvasItem *>::Element *E = modified_canvas_items.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : modified_canvas_items) { CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); if (se) { undo_redo->add_do_method(canvas_item, "_edit_set_state", canvas_item->_edit_get_state()); undo_redo->add_undo_method(canvas_item, "_edit_set_state", se->undo_state); if (commit_bones) { - for (List<Dictionary>::Element *F = se->pre_drag_bones_undo_state.front(); F; F = F->next()) { + for (const Dictionary &F : se->pre_drag_bones_undo_state) { canvas_item = Object::cast_to<CanvasItem>(canvas_item->get_parent()); undo_redo->add_do_method(canvas_item, "_edit_set_state", canvas_item->_edit_get_state()); - undo_redo->add_undo_method(canvas_item, "_edit_set_state", F->get()); + undo_redo->add_undo_method(canvas_item, "_edit_set_state", F); } } } @@ -1197,7 +1192,17 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bo Ref<InputEventKey> k = p_event; if (k.is_valid()) { if (k->is_pressed()) { - if (ED_GET_SHORTCUT("canvas_item_editor/zoom_100_percent")->is_shortcut(p_event)) { + if (ED_GET_SHORTCUT("canvas_item_editor/zoom_3.125_percent")->is_shortcut(p_event)) { + _update_zoom((1.0 / 32.0) * MAX(1, EDSCALE)); + } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_6.25_percent")->is_shortcut(p_event)) { + _update_zoom((1.0 / 16.0) * MAX(1, EDSCALE)); + } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_12.5_percent")->is_shortcut(p_event)) { + _update_zoom((1.0 / 8.0) * MAX(1, EDSCALE)); + } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_25_percent")->is_shortcut(p_event)) { + _update_zoom((1.0 / 4.0) * MAX(1, EDSCALE)); + } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_50_percent")->is_shortcut(p_event)) { + _update_zoom((1.0 / 2.0) * MAX(1, EDSCALE)); + } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_100_percent")->is_shortcut(p_event)) { _update_zoom(1.0 * MAX(1, EDSCALE)); } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_200_percent")->is_shortcut(p_event)) { _update_zoom(2.0 * MAX(1, EDSCALE)); @@ -1294,8 +1299,7 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) { // Filters the selection with nodes that allow setting the pivot drag_selection = List<CanvasItem *>(); - for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : selection) { if (canvas_item->_edit_use_pivot()) { drag_selection.push_back(canvas_item); } @@ -1311,8 +1315,7 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) { } else { new_pos = snap_point(drag_from, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, nullptr, drag_selection); } - for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : drag_selection) { canvas_item->_edit_set_pivot(canvas_item->get_global_transform_with_canvas().affine_inverse().xform(new_pos)); } @@ -1333,8 +1336,7 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) { } else { new_pos = snap_point(drag_to, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL); } - for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : drag_selection) { canvas_item->_edit_set_pivot(canvas_item->get_global_transform_with_canvas().affine_inverse().xform(new_pos)); } return true; @@ -1377,8 +1379,8 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) { List<CanvasItem *> selection = _get_edited_canvas_items(); // Remove not movable nodes - for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) { - if (!_is_node_movable(E->get(), true)) { + for (CanvasItem *E : selection) { + if (!_is_node_movable(E, true)) { selection.erase(E); } } @@ -1404,8 +1406,7 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) { // Rotate the node if (m.is_valid()) { _restore_canvas_item_state(drag_selection); - for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : drag_selection) { drag_to = transform.affine_inverse().xform(m->get_position()); //Rotate the opposite way if the canvas item's compounded scale has an uneven number of negative elements bool opposite = (canvas_item->get_global_transform().get_scale().sign().dot(canvas_item->get_transform().get_scale().sign()) == 0); @@ -2036,8 +2037,7 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { } int index = 0; - for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : drag_selection) { Transform2D xform = canvas_item->get_global_transform_with_canvas().affine_inverse() * canvas_item->get_transform(); canvas_item->_edit_set_position(canvas_item->_edit_get_position() + xform.xform(new_pos) - xform.xform(previous_pos)); @@ -2152,8 +2152,7 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { } int index = 0; - for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : drag_selection) { Transform2D xform = canvas_item->get_global_transform_with_canvas().affine_inverse() * canvas_item->get_transform(); canvas_item->_edit_set_position(canvas_item->_edit_get_position() + xform.xform(new_pos) - xform.xform(previous_pos)); @@ -2365,8 +2364,8 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { if (selitems.size() == 1 && editor_selection->get_selected_node_list().is_empty()) { editor->push_item(selitems[0]); } - for (List<CanvasItem *>::Element *E = selitems.front(); E; E = E->next()) { - editor_selection->add_node(E->get()); + for (CanvasItem *E : selitems) { + editor_selection->add_node(E); } } @@ -2656,7 +2655,7 @@ void CanvasItemEditor::_draw_percentage_at_position(float p_value, Point2 p_posi void CanvasItemEditor::_draw_focus() { // Draw the focus around the base viewport if (viewport->has_focus()) { - get_theme_stylebox(SNAME("Focus"), SNAME("EditorStyles"))->draw(viewport->get_canvas_item(), Rect2(Point2(), viewport->get_size())); + get_theme_stylebox(SNAME("FocusViewport"), SNAME("EditorStyles"))->draw(viewport->get_canvas_item(), Rect2(Point2(), viewport->get_size())); } } @@ -2922,7 +2921,7 @@ void CanvasItemEditor::_draw_ruler_tool() { Point2 text_pos = (begin + end) / 2 - Vector2(text_width / 2, text_height / 2); text_pos.x = CLAMP(text_pos.x, text_width / 2, viewport->get_rect().size.x - text_width * 1.5); text_pos.y = CLAMP(text_pos.y, text_height * 1.5, viewport->get_rect().size.y - text_height * 1.5); - viewport->draw_string(font, text_pos, TS->format_number(vformat("%.2f " + TTR("px"), length_vector.length())), HALIGN_LEFT, -1, font_size, font_color, outline_size, outline_color); + viewport->draw_string(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length())), HALIGN_LEFT, -1, font_size, font_color, outline_size, outline_color); if (draw_secondary_lines) { const float horizontal_angle_rad = atan2(length_vector.y, length_vector.x); @@ -2932,16 +2931,16 @@ void CanvasItemEditor::_draw_ruler_tool() { Point2 text_pos2 = text_pos; text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2); - viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.2f " + TTR("px"), length_vector.y)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.y)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color); Point2 v_angle_text_pos = Point2(); v_angle_text_pos.x = CLAMP(begin.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width); v_angle_text_pos.y = begin.y < end.y ? MIN(text_pos2.y - 2 * text_height, begin.y - text_height * 0.5) : MAX(text_pos2.y + text_height * 3, begin.y + text_height * 1.5); - viewport->draw_string(font, v_angle_text_pos, TS->format_number(vformat("%d " + TTR("deg"), vertical_angle)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color); + viewport->draw_string(font, v_angle_text_pos, TS->format_number(vformat(String::utf8("%d°"), vertical_angle)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color); text_pos2 = text_pos; text_pos2.y = end.y < text_pos.y ? MIN(text_pos.y - text_height * 2, end.y - text_height / 2) : MAX(text_pos.y + text_height * 2, end.y - text_height / 2); - viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.2f " + TTR("px"), length_vector.x)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color); + viewport->draw_string(font, text_pos2, TS->format_number(vformat("%.1f px", length_vector.x)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color); Point2 h_angle_text_pos = Point2(); h_angle_text_pos.x = CLAMP(end.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width); @@ -2958,7 +2957,7 @@ void CanvasItemEditor::_draw_ruler_tool() { h_angle_text_pos.y = MIN(text_pos.y - height_multiplier * text_height, MIN(end.y - text_height * 0.5, text_pos2.y - height_multiplier * text_height)); } } - viewport->draw_string(font, h_angle_text_pos, TS->format_number(vformat("%d " + TTR("deg"), horizontal_angle)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color); + viewport->draw_string(font, h_angle_text_pos, TS->format_number(vformat(String::utf8("%d°"), horizontal_angle)), HALIGN_LEFT, -1, font_size, font_secondary_color, outline_size, outline_color); // Angle arcs int arc_point_count = 8; @@ -3238,8 +3237,8 @@ void CanvasItemEditor::_draw_selection() { List<CanvasItem *> selection = _get_edited_canvas_items(true, false); bool single = selection.size() == 1; - for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get()); + for (CanvasItem *E : selection) { + CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E); CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); bool item_locked = canvas_item->has_meta("_edit_lock_"); @@ -3556,9 +3555,9 @@ void CanvasItemEditor::_draw_hover() { Point2 pos = transform.xform(hovering_results[i].position) - Point2(0, item_size.y) + (Point2(node_icon->get_size().x, -node_icon->get_size().y) / 4); // Rectify the position to avoid overlapping items - for (List<Rect2>::Element *E = previous_rects.front(); E; E = E->next()) { - if (E->get().intersects(Rect2(pos, item_size))) { - pos.y = E->get().get_position().y - item_size.y; + for (const Rect2 &E : previous_rects) { + if (E.intersects(Rect2(pos, item_size))) { + pos.y = E.get_position().y - item_size.y; } } @@ -3632,14 +3631,14 @@ void CanvasItemEditor::_draw_viewport() { all_locked = false; all_group = false; } else { - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - if (Object::cast_to<CanvasItem>(E->get()) && !Object::cast_to<CanvasItem>(E->get())->has_meta("_edit_lock_")) { + for (Node *E : selection) { + if (Object::cast_to<CanvasItem>(E) && !Object::cast_to<CanvasItem>(E)->has_meta("_edit_lock_")) { all_locked = false; break; } } - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - if (Object::cast_to<CanvasItem>(E->get()) && !Object::cast_to<CanvasItem>(E->get())->has_meta("_edit_group_")) { + for (Node *E : selection) { + if (Object::cast_to<CanvasItem>(E) && !Object::cast_to<CanvasItem>(E)->has_meta("_edit_group_")) { all_group = false; break; } @@ -3706,8 +3705,7 @@ void CanvasItemEditor::_notification(int p_what) { // Update the viewport if the canvas_item changes List<CanvasItem *> selection = _get_edited_canvas_items(true); - for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = E->get(); + for (CanvasItem *canvas_item : selection) { CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); Rect2 rect; @@ -3855,7 +3853,10 @@ void CanvasItemEditor::_notification(int p_what) { key_auto_insert_button->add_theme_color_override("icon_pressed_color", key_auto_color.lerp(Color(1, 0, 0), 0.55)); animation_menu->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); + _update_context_menu_stylebox(); + presets_menu->set_icon(get_theme_icon(SNAME("ControlLayout"), SNAME("EditorIcons"))); + PopupMenu *p = presets_menu->get_popup(); p->clear(); @@ -3922,8 +3923,8 @@ void CanvasItemEditor::_selection_changed() { int nbValidControls = 0; int nbAnchorsMode = 0; List<Node *> selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Control *control = Object::cast_to<Control>(E->get()); + for (Node *E : selection) { + Control *control = Object::cast_to<Control>(E); if (!control) { continue; } @@ -3956,6 +3957,18 @@ void CanvasItemEditor::edit(CanvasItem *p_canvas_item) { } } +void CanvasItemEditor::_update_context_menu_stylebox() { + // This must be called when the theme changes to follow the new accent color. + Ref<StyleBoxFlat> context_menu_stylebox = memnew(StyleBoxFlat); + const Color accent_color = EditorNode::get_singleton()->get_gui_base()->get_theme_color("accent_color", "Editor"); + context_menu_stylebox->set_bg_color(accent_color * Color(1, 1, 1, 0.1)); + // Add an underline to the StyleBox, but prevent its minimum vertical size from changing. + context_menu_stylebox->set_border_color(accent_color); + context_menu_stylebox->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE)); + context_menu_stylebox->set_default_margin(SIDE_BOTTOM, 0); + context_menu_container->add_theme_style_override("panel", context_menu_stylebox); +} + void CanvasItemEditor::_update_scrollbars() { updating_scroll = true; @@ -4091,8 +4104,8 @@ void CanvasItemEditor::_set_anchors_and_offsets_preset(Control::LayoutPreset p_p undo_redo->create_action(TTR("Change Anchors and Offsets")); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Control *control = Object::cast_to<Control>(E->get()); + for (Node *E : selection) { + Control *control = Object::cast_to<Control>(E); if (control) { undo_redo->add_do_method(control, "set_anchors_preset", p_preset); switch (p_preset) { @@ -4132,8 +4145,8 @@ void CanvasItemEditor::_set_anchors_and_offsets_to_keep_ratio() { undo_redo->create_action(TTR("Change Anchors and Offsets")); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Control *control = Object::cast_to<Control>(E->get()); + for (Node *E : selection) { + Control *control = Object::cast_to<Control>(E); if (control) { Point2 top_left_anchor = _position_to_anchor(control, Point2()); Point2 bottom_right_anchor = _position_to_anchor(control, control->get_size()); @@ -4159,8 +4172,8 @@ void CanvasItemEditor::_set_anchors_preset(Control::LayoutPreset p_preset) { List<Node *> selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Change Anchors")); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Control *control = Object::cast_to<Control>(E->get()); + for (Node *E : selection) { + Control *control = Object::cast_to<Control>(E); if (control) { undo_redo->add_do_method(control, "set_anchors_preset", p_preset); undo_redo->add_undo_method(control, "_edit_set_state", control->_edit_get_state()); @@ -4285,15 +4298,15 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, } if (has_chain && ik_chain.size()) { - for (List<Node2D *>::Element *F = ik_chain.front(); F; F = F->next()) { + for (Node2D *&F : ik_chain) { if (key_pos) { - AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "position", F->get()->get_position(), p_on_existing); + AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F, "position", F->get_position(), p_on_existing); } if (key_rot) { - AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "rotation", F->get()->get_rotation(), p_on_existing); + AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F, "rotation", F->get_rotation(), p_on_existing); } if (key_scale) { - AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "scale", F->get()->get_scale(), p_on_existing); + AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F, "scale", F->get_scale(), p_on_existing); } } } @@ -4317,8 +4330,8 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, void CanvasItemEditor::_button_toggle_anchor_mode(bool p_status) { List<CanvasItem *> selection = _get_edited_canvas_items(false, false); - for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) { - Control *control = Object::cast_to<Control>(E->get()); + for (CanvasItem *E : selection) { + Control *control = Object::cast_to<Control>(E); if (!control || Object::cast_to<Container>(control->get_parent())) { continue; } @@ -4431,13 +4444,13 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case SKELETON_SHOW_BONES: { List<Node *> selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { + for (Node *E : selection) { // Add children nodes so they are processed - for (int child = 0; child < E->get()->get_child_count(); child++) { - selection.push_back(E->get()->get_child(child)); + for (int child = 0; child < E->get_child_count(); child++) { + selection.push_back(E->get_child(child)); } - Bone2D *bone_2d = Object::cast_to<Bone2D>(E->get()); + Bone2D *bone_2d = Object::cast_to<Bone2D>(E); if (!bone_2d || !bone_2d->is_inside_tree()) { continue; } @@ -4467,8 +4480,8 @@ void CanvasItemEditor::_popup_callback(int p_op) { undo_redo->create_action(TTR("Lock Selected")); List<Node *> selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get()); + for (Node *E : selection) { + CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E); if (!canvas_item || !canvas_item->is_inside_tree()) { continue; } @@ -4489,8 +4502,8 @@ void CanvasItemEditor::_popup_callback(int p_op) { undo_redo->create_action(TTR("Unlock Selected")); List<Node *> selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get()); + for (Node *E : selection) { + CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E); if (!canvas_item || !canvas_item->is_inside_tree()) { continue; } @@ -4511,8 +4524,8 @@ void CanvasItemEditor::_popup_callback(int p_op) { undo_redo->create_action(TTR("Group Selected")); List<Node *> selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get()); + for (Node *E : selection) { + CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E); if (!canvas_item || !canvas_item->is_inside_tree()) { continue; } @@ -4533,8 +4546,8 @@ void CanvasItemEditor::_popup_callback(int p_op) { undo_redo->create_action(TTR("Ungroup Selected")); List<Node *> selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get()); + for (Node *E : selection) { + CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E); if (!canvas_item || !canvas_item->is_inside_tree()) { continue; } @@ -4701,14 +4714,14 @@ void CanvasItemEditor::_popup_callback(int p_op) { } undo_redo->create_action(TTR("Paste Pose")); - for (List<PoseClipboard>::Element *E = pose_clipboard.front(); E; E = E->next()) { - Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E->get().id)); + for (const PoseClipboard &E : pose_clipboard) { + Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E.id)); if (!n2d) { continue; } - undo_redo->add_do_method(n2d, "set_position", E->get().pos); - undo_redo->add_do_method(n2d, "set_rotation", E->get().rot); - undo_redo->add_do_method(n2d, "set_scale", E->get().scale); + undo_redo->add_do_method(n2d, "set_position", E.pos); + undo_redo->add_do_method(n2d, "set_rotation", E.rot); + undo_redo->add_do_method(n2d, "set_scale", E.scale); undo_redo->add_undo_method(n2d, "set_position", n2d->get_position()); undo_redo->add_undo_method(n2d, "set_rotation", n2d->get_rotation()); undo_redo->add_undo_method(n2d, "set_scale", n2d->get_scale()); @@ -5129,11 +5142,11 @@ void CanvasItemEditor::remove_control_from_info_overlay(Control *p_control) { void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) { ERR_FAIL_COND(!p_control); - hb->add_child(p_control); + hbc_context_menu->add_child(p_control); } void CanvasItemEditor::remove_control_from_menu_panel(Control *p_control) { - hb->remove_child(p_control); + hbc_context_menu->remove_child(p_control); } HSplitContainer *CanvasItemEditor::get_palette_split() { @@ -5315,7 +5328,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { select_button->set_pressed(true); select_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/select_mode", TTR("Select Mode"), KEY_Q)); select_button->set_shortcut_context(this); - select_button->set_tooltip(keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate") + "\n" + TTR("Alt+Drag: Move") + "\n" + TTR("Press 'v' to Change Pivot, 'Shift+v' to Drag Pivot (while moving).") + "\n" + TTR("Alt+RMB: Show list of all nodes at position clicked, including locked.")); + select_button->set_tooltip(keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate selected node around pivot.") + "\n" + TTR("Alt+Drag: Move selected node.") + "\n" + TTR("V: Set selected node's pivot position.") + "\n" + TTR("Alt+RMB: Show list of all nodes at position clicked, including locked.") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("RMB: Add node at position clicked.")); hb->add_child(memnew(VSeparator)); @@ -5518,10 +5531,21 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_separator(); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_P), PREVIEW_CANVAS_SCALE); + hb->add_child(memnew(VSeparator)); + + context_menu_container = memnew(PanelContainer); + hbc_context_menu = memnew(HBoxContainer); + context_menu_container->add_child(hbc_context_menu); + // Use a custom stylebox to make contextual menu items stand out from the rest. + // This helps with editor usability as contextual menu items change when selecting nodes, + // even though it may not be immediately obvious at first. + hb->add_child(context_menu_container); + _update_context_menu_stylebox(); + presets_menu = memnew(MenuButton); presets_menu->set_shortcut_context(this); presets_menu->set_text(TTR("Layout")); - hb->add_child(presets_menu); + hbc_context_menu->add_child(presets_menu); presets_menu->hide(); presets_menu->set_switch_on_hover(true); @@ -5535,17 +5559,18 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { anchor_mode_button = memnew(Button); anchor_mode_button->set_flat(true); - hb->add_child(anchor_mode_button); + hbc_context_menu->add_child(anchor_mode_button); anchor_mode_button->set_toggle_mode(true); anchor_mode_button->hide(); anchor_mode_button->connect("toggled", callable_mp(this, &CanvasItemEditor::_button_toggle_anchor_mode)); animation_hb = memnew(HBoxContainer); - hb->add_child(animation_hb); + hbc_context_menu->add_child(animation_hb); animation_hb->add_child(memnew(VSeparator)); animation_hb->hide(); key_loc_button = memnew(Button); + key_loc_button->set_flat(true); key_loc_button->set_toggle_mode(true); key_loc_button->set_pressed(true); key_loc_button->set_focus_mode(FOCUS_NONE); @@ -5554,6 +5579,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { animation_hb->add_child(key_loc_button); key_rot_button = memnew(Button); + key_rot_button->set_flat(true); key_rot_button->set_toggle_mode(true); key_rot_button->set_pressed(true); key_rot_button->set_focus_mode(FOCUS_NONE); @@ -5562,6 +5588,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { animation_hb->add_child(key_rot_button); key_scale_button = memnew(Button); + key_scale_button->set_flat(true); key_scale_button->set_toggle_mode(true); key_scale_button->set_focus_mode(FOCUS_NONE); key_scale_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback), varray(ANIM_INSERT_SCALE)); @@ -5569,6 +5596,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { animation_hb->add_child(key_scale_button); key_insert_button = memnew(Button); + key_insert_button->set_flat(true); key_insert_button->set_focus_mode(FOCUS_NONE); key_insert_button->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback), varray(ANIM_INSERT_KEY)); key_insert_button->set_tooltip(TTR("Insert keys (based on mask).")); @@ -5630,6 +5658,11 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { // those shortcuts one by one. // Resetting zoom to 100% is a duplicate shortcut of `canvas_item_editor/reset_zoom`, // but it ensures both 1 and Ctrl + 0 can be used to reset zoom. + ED_SHORTCUT("canvas_item_editor/zoom_3.125_percent", TTR("Zoom to 3.125%"), KEY_MASK_SHIFT | KEY_5); + ED_SHORTCUT("canvas_item_editor/zoom_6.25_percent", TTR("Zoom to 6.25%"), KEY_MASK_SHIFT | KEY_4); + ED_SHORTCUT("canvas_item_editor/zoom_12.5_percent", TTR("Zoom to 12.5%"), KEY_MASK_SHIFT | KEY_3); + ED_SHORTCUT("canvas_item_editor/zoom_25_percent", TTR("Zoom to 25%"), KEY_MASK_SHIFT | KEY_2); + ED_SHORTCUT("canvas_item_editor/zoom_50_percent", TTR("Zoom to 50%"), KEY_MASK_SHIFT | KEY_1); ED_SHORTCUT("canvas_item_editor/zoom_100_percent", TTR("Zoom to 100%"), KEY_1); ED_SHORTCUT("canvas_item_editor/zoom_200_percent", TTR("Zoom to 200%"), KEY_2); ED_SHORTCUT("canvas_item_editor/zoom_400_percent", TTR("Zoom to 400%"), KEY_3); @@ -5730,11 +5763,14 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons preview_node->add_child(sprite); label->show(); label_desc->show(); + label_desc->set_text(TTR("Drag and drop to add as child of current scene's root node.\nHold Ctrl when dropping to add as child of selected node.\nHold Shift when dropping to add as sibling of selected node.\nHold Alt when dropping to add as a different node type.")); } else { if (scene.is_valid()) { Node *instance = scene->instantiate(); if (instance) { preview_node->add_child(instance); + label_desc->show(); + label_desc->set_text(TTR("Drag and drop to add as child of current scene's root node.\nHold Ctrl when dropping to add as child of selected node.\nHold Shift when dropping to add as sibling of selected node.")); } } } @@ -5804,14 +5840,14 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String & String property = "texture"; List<PropertyInfo> props; child->get_property_list(&props); - for (const List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (E->get().name == "config/texture") { // Particles2D + for (const PropertyInfo &E : props) { + if (E.name == "config/texture") { // Particles2D property = "config/texture"; break; - } else if (E->get().name == "texture/texture") { // Polygon2D + } else if (E.name == "texture/texture") { // Polygon2D property = "texture/texture"; break; - } else if (E->get().name == "normal") { // TouchScreenButton + } else if (E.name == "normal") { // TouchScreenButton property = "normal"; break; } @@ -6033,6 +6069,7 @@ bool CanvasItemEditorViewport::_only_packed_scenes_selected() const { void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p_data) { bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT); + bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CTRL); bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT); selected_files.clear(); @@ -6044,24 +6081,25 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p return; } - List<Node *> list = editor->get_editor_selection()->get_selected_node_list(); - if (list.size() == 0) { - Node *root_node = editor->get_edited_scene(); + List<Node *> selected_nodes = editor->get_editor_selection()->get_selected_node_list(); + Node *root_node = editor->get_edited_scene(); + if (selected_nodes.size() > 0) { + Node *selected_node = selected_nodes[0]; + target_node = root_node; + if (is_ctrl) { + target_node = selected_node; + } else if (is_shift && selected_node != root_node) { + target_node = selected_node->get_parent(); + } + } else { if (root_node) { - list.push_back(root_node); + target_node = root_node; } else { drop_pos = p_point; target_node = nullptr; } } - if (list.size() > 0) { - target_node = list[0]; - if (is_shift && target_node != editor->get_edited_scene()) { - target_node = target_node->get_parent(); - } - } - drop_pos = p_point; if (is_alt && !_only_packed_scenes_selected()) { @@ -6142,7 +6180,6 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte canvas_item_editor->get_controls_container()->add_child(label); label_desc = memnew(Label); - label_desc->set_text(TTR("Drag & drop + Shift : Add node as sibling\nDrag & drop + Alt : Change node type")); label_desc->add_theme_color_override("font_color", Color(0.6f, 0.6f, 0.6f, 1)); label_desc->add_theme_color_override("font_shadow_color", Color(0.2f, 0.2f, 0.2f, 1)); label_desc->add_theme_constant_override("shadow_as_outline", 1 * EDSCALE); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 7b64d0cb5d..d466032588 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -230,6 +230,10 @@ private: HScrollBar *h_scroll; VScrollBar *v_scroll; HBoxContainer *hb; + // Used for secondary menu items which are displayed depending on the currently selected node + // (such as MeshInstance's "Mesh" menu). + PanelContainer *context_menu_container; + HBoxContainer *hbc_context_menu; Map<Control *, Timer *> popup_temporarily_timers; @@ -535,6 +539,7 @@ private: HSplitContainer *palette_split; VSplitContainer *bottom_split; + void _update_context_menu_stylebox(); void _popup_warning_temporarily(Control *p_control, const float p_duration); void _popup_warning_depop(Control *p_control); diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index 45adbe29de..2c2adc2672 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -31,6 +31,7 @@ #include "collision_shape_2d_editor_plugin.h" #include "canvas_item_editor_plugin.h" +#include "core/os/keyboard.h" #include "scene/resources/capsule_shape_2d.h" #include "scene/resources/circle_shape_2d.h" #include "scene/resources/concave_polygon_shape_2d.h" @@ -97,7 +98,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { case RECTANGLE_SHAPE: { Ref<RectangleShape2D> rect = node->get_shape(); - if (idx < 3) { + if (idx < 8) { return rect->get_size().abs(); } @@ -176,16 +177,26 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { } break; case RECTANGLE_SHAPE: { - if (idx < 3) { + if (idx < 8) { Ref<RectangleShape2D> rect = node->get_shape(); + Vector2 size = (Point2)original; - Vector2 size = rect->get_size(); - if (idx == 2) { - size = p_point * 2; + if (RECT_HANDLES[idx].x != 0) { + size.x = p_point.x * RECT_HANDLES[idx].x * 2; + } + if (RECT_HANDLES[idx].y != 0) { + size.y = p_point.y * RECT_HANDLES[idx].y * 2; + } + + if (Input::get_singleton()->is_key_pressed(KEY_ALT)) { + rect->set_size(size.abs()); + node->set_global_position(original_transform.get_origin()); } else { - size[idx] = p_point[idx] * 2; + rect->set_size(((Point2)original + (size - (Point2)original) * 0.5).abs()); + Point2 pos = original_transform.affine_inverse().xform(original_transform.get_origin()); + pos += (size - (Point2)original) * 0.5 * RECT_HANDLES[idx] * 0.5; + node->set_global_position(original_transform.xform(pos)); } - rect->set_size(size.abs()); canvas_item_editor->update_viewport(); } @@ -280,8 +291,10 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { Ref<RectangleShape2D> rect = node->get_shape(); undo_redo->add_do_method(rect.ptr(), "set_size", rect->get_size()); + undo_redo->add_do_method(node, "set_global_transform", node->get_global_transform()); undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(rect.ptr(), "set_size", p_org); + undo_redo->add_undo_method(node, "set_global_transform", original_transform); undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } break; @@ -342,6 +355,8 @@ bool CollisionShape2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_e } original = get_handle_value(edit_handle); + original_transform = node->get_global_transform(); + last_point = original; pressed = true; return true; @@ -369,13 +384,26 @@ bool CollisionShape2DEditor::forward_canvas_gui_input(const Ref<InputEvent> &p_e } Vector2 cpoint = canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mm->get_position())); - cpoint = node->get_global_transform().affine_inverse().xform(cpoint); + cpoint = original_transform.affine_inverse().xform(cpoint); + last_point = cpoint; set_handle(edit_handle, cpoint); return true; } + Ref<InputEventKey> k = p_event; + + if (k.is_valid()) { + if (edit_handle == -1 || !pressed || k->is_echo()) { + return false; + } + + if (shape_type == RECTANGLE_SHAPE && k->get_keycode() == KEY_ALT) { + set_handle(edit_handle, last_point); // Update handle when Alt key is toggled. + } + } + return false; } @@ -492,15 +520,12 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla case RECTANGLE_SHAPE: { Ref<RectangleShape2D> shape = node->get_shape(); - handles.resize(3); + handles.resize(8); Vector2 ext = shape->get_size() / 2; - handles.write[0] = Point2(ext.x, 0); - handles.write[1] = Point2(0, ext.y); - handles.write[2] = Point2(ext.x, ext.y); - - p_overlay->draw_texture(h, gt.xform(handles[0]) - size); - p_overlay->draw_texture(h, gt.xform(handles[1]) - size); - p_overlay->draw_texture(h, gt.xform(handles[2]) - size); + for (int i = 0; i < handles.size(); i++) { + handles.write[i] = RECT_HANDLES[i] * ext; + p_overlay->draw_texture(h, gt.xform(handles[i]) - size); + } } break; diff --git a/editor/plugins/collision_shape_2d_editor_plugin.h b/editor/plugins/collision_shape_2d_editor_plugin.h index 054db1a61b..7db6bd22aa 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.h +++ b/editor/plugins/collision_shape_2d_editor_plugin.h @@ -52,6 +52,17 @@ class CollisionShape2DEditor : public Control { SEGMENT_SHAPE }; + const Point2 RECT_HANDLES[8] = { + Point2(1, 0), + Point2(1, 1), + Point2(0, 1), + Point2(-1, 1), + Point2(-1, 0), + Point2(-1, -1), + Point2(0, -1), + Point2(1, -1), + }; + EditorNode *editor; UndoRedo *undo_redo; CanvasItemEditor *canvas_item_editor; @@ -63,6 +74,8 @@ class CollisionShape2DEditor : public Control { int edit_handle; bool pressed; Variant original; + Transform2D original_transform; + Point2 last_point; Variant get_handle_value(int idx) const; void set_handle(int idx, Point2 &p_point); diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp index c4deb296fb..6f246c1661 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp @@ -253,8 +253,8 @@ CPUParticles2DEditorPlugin::CPUParticles2DEditorPlugin(EditorNode *p_node) { file = memnew(EditorFileDialog); List<String> ext; ImageLoader::get_recognized_extensions(&ext); - for (List<String>::Element *E = ext.front(); E; E = E->next()) { - file->add_filter("*." + E->get() + "; " + E->get().to_upper()); + for (const String &E : ext) { + file->add_filter("*." + E + "; " + E.to_upper()); } file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); toolbar->add_child(file); diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 7d07e99c2f..07ff0eb346 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -393,7 +393,8 @@ int CurveEditor::get_point_at(Vector2 pos) const { } const Curve &curve = **_curve_ref; - const float r = _hover_radius * _hover_radius; + const float true_hover_radius = Math::round(_hover_radius * EDSCALE); + const float r = true_hover_radius * true_hover_radius; for (int i = 0; i < curve.get_point_count(); ++i) { Vector2 p = get_view_pos(curve.get_point_position(i)); @@ -558,7 +559,7 @@ Vector2 CurveEditor::get_tangent_view_pos(int i, TangentIndex tangent) const { Vector2 point_pos = get_view_pos(_curve_ref->get_point_position(i)); Vector2 control_pos = get_view_pos(_curve_ref->get_point_position(i) + dir); - return point_pos + _tangents_length * (control_pos - point_pos).normalized(); + return point_pos + Math::round(_tangents_length * EDSCALE) * (control_pos - point_pos).normalized(); } Vector2 CurveEditor::get_view_pos(Vector2 world_pos) const { @@ -703,13 +704,13 @@ void CurveEditor::_draw() { if (i != 0) { Vector2 control_pos = get_tangent_view_pos(i, TANGENT_LEFT); draw_line(get_view_pos(pos), control_pos, tangent_color, Math::round(EDSCALE)); - draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(2), tangent_color); + draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(Math::round(2 * EDSCALE)), tangent_color); } if (i != curve.get_point_count() - 1) { Vector2 control_pos = get_tangent_view_pos(i, TANGENT_RIGHT); draw_line(get_view_pos(pos), control_pos, tangent_color, Math::round(EDSCALE)); - draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(2), tangent_color); + draw_rect(Rect2(control_pos, Vector2(1, 1)).grow(Math::round(2 * EDSCALE)), tangent_color); } } @@ -732,7 +733,7 @@ void CurveEditor::_draw() { for (int i = 0; i < curve.get_point_count(); ++i) { Vector2 pos = curve.get_point_position(i); - draw_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(3), i == _selected_point ? selected_point_color : point_color); + draw_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(Math::round(3 * EDSCALE)), i == _selected_point ? selected_point_color : point_color); // TODO Circles are prettier. Needs a fix! Or a texture //draw_circle(pos, 2, point_color); } @@ -742,7 +743,7 @@ void CurveEditor::_draw() { if (_hover_point != -1) { const Color hover_color = line_color; Vector2 pos = curve.get_point_position(_hover_point); - draw_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(_hover_radius), hover_color, false, Math::round(EDSCALE)); + draw_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(Math::round(_hover_radius * EDSCALE)), hover_color, false, Math::round(EDSCALE)); } // Help text diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index a233d66d82..81c340e9a4 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -490,11 +490,11 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size Set<String> control_flow_keywords; Set<String> keywords; - for (List<String>::Element *E = kwors.front(); E; E = E->next()) { - if (scr->get_language()->is_control_flow_keyword(E->get())) { - control_flow_keywords.insert(E->get()); + for (const String &E : kwors) { + if (scr->get_language()->is_control_flow_keyword(E)) { + control_flow_keywords.insert(E); } else { - keywords.insert(E->get()); + keywords.insert(E); } } diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.cpp b/editor/plugins/gpu_particles_2d_editor_plugin.cpp index cc5793a1f9..5184e837ce 100644 --- a/editor/plugins/gpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_2d_editor_plugin.cpp @@ -361,8 +361,8 @@ GPUParticles2DEditorPlugin::GPUParticles2DEditorPlugin(EditorNode *p_node) { file = memnew(EditorFileDialog); List<String> ext; ImageLoader::get_recognized_extensions(&ext); - for (List<String>::Element *E = ext.front(); E; E = E->next()) { - file->add_filter("*." + E->get() + "; " + E->get().to_upper()); + for (const String &E : ext) { + file->add_filter("*." + E + "; " + E.to_upper()); } file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); toolbar->add_child(file); diff --git a/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp index 71598b904b..a4436525fb 100644 --- a/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_collision_sdf_editor_plugin.cpp @@ -131,7 +131,7 @@ void GPUParticlesCollisionSDFEditorPlugin::_sdf_save_path_and_bake(const String if (col_sdf) { Ref<Image> bake_img = col_sdf->bake(); if (bake_img.is_null()) { - EditorNode::get_singleton()->show_warning("Bake Error."); + EditorNode::get_singleton()->show_warning(TTR("Bake Error.")); return; } diff --git a/editor/plugins/input_event_editor_plugin.cpp b/editor/plugins/input_event_editor_plugin.cpp index f1aa10844b..d3d2de92f5 100644 --- a/editor/plugins/input_event_editor_plugin.cpp +++ b/editor/plugins/input_event_editor_plugin.cpp @@ -86,7 +86,7 @@ InputEventConfigContainer::InputEventConfigContainer() { mc->add_child(hb); open_config_button = memnew(Button); - open_config_button->set_text("Configure"); + open_config_button->set_text(TTR("Configure")); open_config_button->connect("pressed", callable_mp(this, &InputEventConfigContainer::_configure_pressed)); hb->add_child(open_config_button); diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index 7105d351b0..94966d4fe6 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -265,15 +265,15 @@ Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p List<PropertyInfo> params; RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms); - for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { + for (const PropertyInfo &E : params) { // Texture parameter has to be treated specially since StandardMaterial3D saved it // as RID but ShaderMaterial needs Texture itself - Ref<Texture2D> texture = mat->get_texture_by_name(E->get().name); + Ref<Texture2D> texture = mat->get_texture_by_name(E.name); if (texture.is_valid()) { - smat->set_shader_param(E->get().name, texture); + smat->set_shader_param(E.name, texture); } else { - Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E->get().name); - smat->set_shader_param(E->get().name, value); + Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name); + smat->set_shader_param(E.name, value); } } @@ -309,9 +309,9 @@ Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_ List<PropertyInfo> params; RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms); - for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { - Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E->get().name); - smat->set_shader_param(E->get().name, value); + for (const PropertyInfo &E : params) { + Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name); + smat->set_shader_param(E.name, value); } smat->set_render_priority(mat->get_render_priority()); @@ -346,9 +346,9 @@ Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p List<PropertyInfo> params; RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms); - for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { - Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E->get().name); - smat->set_shader_param(E->get().name, value); + for (const PropertyInfo &E : params) { + Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name); + smat->set_shader_param(E.name, value); } smat->set_render_priority(mat->get_render_priority()); @@ -383,9 +383,9 @@ Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> List<PropertyInfo> params; RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms); - for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { - Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E->get().name); - smat->set_shader_param(E->get().name, value); + for (const PropertyInfo &E : params) { + Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name); + smat->set_shader_param(E.name, value); } smat->set_render_priority(mat->get_render_priority()); @@ -420,9 +420,9 @@ Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> & List<PropertyInfo> params; RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms); - for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { - Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E->get().name); - smat->set_shader_param(E->get().name, value); + for (const PropertyInfo &E : params) { + Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name); + smat->set_shader_param(E.name, value); } smat->set_render_priority(mat->get_render_priority()); @@ -457,9 +457,9 @@ Ref<Resource> PhysicalSkyMaterialConversionPlugin::convert(const Ref<Resource> & List<PropertyInfo> params; RS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms); - for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { - Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E->get().name); - smat->set_shader_param(E->get().name, value); + for (const PropertyInfo &E : params) { + Variant value = RS::get_singleton()->material_get_param(mat->get_rid(), E.name); + smat->set_shader_param(E.name, value); } smat->set_render_priority(mat->get_render_priority()); diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp index 91415f4883..9a2b222f21 100644 --- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp +++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp @@ -90,8 +90,8 @@ void MeshInstance3DEditor::_menu_option(int p_option) { ur->create_action(TTR("Create Static Trimesh Body")); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - MeshInstance3D *instance = Object::cast_to<MeshInstance3D>(E->get()); + for (Node *E : selection) { + MeshInstance3D *instance = Object::cast_to<MeshInstance3D>(E); if (!instance) { continue; } @@ -332,7 +332,7 @@ void MeshInstance3DEditor::_create_uv_lines(int p_layer) { Vector<Vector2> uv = a[p_layer == 0 ? Mesh::ARRAY_TEX_UV : Mesh::ARRAY_TEX_UV2]; if (uv.size() == 0) { - err_dialog->set_text(TTR("Model has no UV in this layer")); + err_dialog->set_text(vformat(TTR("Mesh has no UV in layer %d."), p_layer + 1)); err_dialog->popup_centered(); return; } @@ -382,9 +382,10 @@ void MeshInstance3DEditor::_debug_uv_draw() { } debug_uv->set_clip_contents(true); - debug_uv->draw_rect(Rect2(Vector2(), debug_uv->get_size()), Color(0.2, 0.2, 0.0)); + debug_uv->draw_rect(Rect2(Vector2(), debug_uv->get_size()), get_theme_color(SNAME("dark_color_3"), SNAME("Editor"))); debug_uv->draw_set_transform(Vector2(), 0, debug_uv->get_size()); - debug_uv->draw_multiline(uv_lines, Color(1.0, 0.8, 0.7)); + // Use a translucent color to allow overlapping triangles to be visible. + debug_uv->draw_multiline(uv_lines, get_theme_color(SNAME("mono_color"), SNAME("Editor")) * Color(1, 1, 1, 0.5), Math::round(EDSCALE)); } void MeshInstance3DEditor::_create_outline_mesh() { diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp index 15b6a0f3a0..b3f92c9d95 100644 --- a/editor/plugins/mesh_library_editor_plugin.cpp +++ b/editor/plugins/mesh_library_editor_plugin.cpp @@ -122,23 +122,23 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, List<uint32_t> shapes; sb->get_shape_owners(&shapes); - for (List<uint32_t>::Element *E = shapes.front(); E; E = E->next()) { - if (sb->is_shape_owner_disabled(E->get())) { + for (uint32_t &E : shapes) { + if (sb->is_shape_owner_disabled(E)) { continue; } - //Transform3D shape_transform = sb->shape_owner_get_transform(E->get()); + //Transform3D shape_transform = sb->shape_owner_get_transform(E); //shape_transform.set_origin(shape_transform.get_origin() - phys_offset); - for (int k = 0; k < sb->shape_owner_get_shape_count(E->get()); k++) { - Ref<Shape3D> collision = sb->shape_owner_get_shape(E->get(), k); + for (int k = 0; k < sb->shape_owner_get_shape_count(E); k++) { + Ref<Shape3D> collision = sb->shape_owner_get_shape(E, k); if (!collision.is_valid()) { continue; } MeshLibrary::ShapeData shape_data; shape_data.shape = collision; - shape_data.local_transform = sb->get_transform() * sb->shape_owner_get_transform(E->get()); + shape_data.local_transform = sb->get_transform() * sb->shape_owner_get_transform(E); collisions.push_back(shape_data); } } diff --git a/editor/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index 2e85e19732..2138f943da 100644 --- a/editor/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -33,7 +33,9 @@ #include "core/math/convex_hull.h" #include "core/math/geometry_2d.h" #include "core/math/geometry_3d.h" +#include "editor/plugins/node_3d_editor_plugin.h" #include "scene/3d/audio_stream_player_3d.h" +#include "scene/3d/camera_3d.h" #include "scene/3d/collision_polygon_3d.h" #include "scene/3d/collision_shape_3d.h" #include "scene/3d/cpu_particles_3d.h" @@ -106,58 +108,122 @@ void EditorNode3DGizmo::clear() { void EditorNode3DGizmo::redraw() { if (get_script_instance() && get_script_instance()->has_method("_redraw")) { get_script_instance()->call("_redraw"); - return; + } else { + ERR_FAIL_COND(!gizmo_plugin); + gizmo_plugin->redraw(this); } - ERR_FAIL_COND(!gizmo_plugin); - gizmo_plugin->redraw(this); + if (Node3DEditor::get_singleton()->is_current_selected_gizmo(this)) { + Node3DEditor::get_singleton()->update_transform_gizmo(); + } } -String EditorNode3DGizmo::get_handle_name(int p_idx) const { +String EditorNode3DGizmo::get_handle_name(int p_id) const { if (get_script_instance() && get_script_instance()->has_method("_get_handle_name")) { - return get_script_instance()->call("_get_handle_name", p_idx); + return get_script_instance()->call("_get_handle_name", p_id); } ERR_FAIL_COND_V(!gizmo_plugin, ""); - return gizmo_plugin->get_handle_name(this, p_idx); + return gizmo_plugin->get_handle_name(this, p_id); } -bool EditorNode3DGizmo::is_handle_highlighted(int p_idx) const { +bool EditorNode3DGizmo::is_handle_highlighted(int p_id) const { if (get_script_instance() && get_script_instance()->has_method("_is_handle_highlighted")) { - return get_script_instance()->call("_is_handle_highlighted", p_idx); + return get_script_instance()->call("_is_handle_highlighted", p_id); } ERR_FAIL_COND_V(!gizmo_plugin, false); - return gizmo_plugin->is_handle_highlighted(this, p_idx); + return gizmo_plugin->is_handle_highlighted(this, p_id); } -Variant EditorNode3DGizmo::get_handle_value(int p_idx) { +Variant EditorNode3DGizmo::get_handle_value(int p_id) const { if (get_script_instance() && get_script_instance()->has_method("_get_handle_value")) { - return get_script_instance()->call("_get_handle_value", p_idx); + return get_script_instance()->call("_get_handle_value", p_id); } ERR_FAIL_COND_V(!gizmo_plugin, Variant()); - return gizmo_plugin->get_handle_value(this, p_idx); + return gizmo_plugin->get_handle_value(this, p_id); } -void EditorNode3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void EditorNode3DGizmo::set_handle(int p_id, Camera3D *p_camera, const Point2 &p_point) const { if (get_script_instance() && get_script_instance()->has_method("_set_handle")) { - get_script_instance()->call("_set_handle", p_idx, p_camera, p_point); + get_script_instance()->call("_set_handle", p_id, p_camera, p_point); return; } ERR_FAIL_COND(!gizmo_plugin); - gizmo_plugin->set_handle(this, p_idx, p_camera, p_point); + gizmo_plugin->set_handle(this, p_id, p_camera, p_point); } -void EditorNode3DGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) { +void EditorNode3DGizmo::commit_handle(int p_id, const Variant &p_restore, bool p_cancel) const { if (get_script_instance() && get_script_instance()->has_method("_commit_handle")) { - get_script_instance()->call("_commit_handle", p_idx, p_restore, p_cancel); + get_script_instance()->call("_commit_handle", p_id, p_restore, p_cancel); + return; + } + + ERR_FAIL_COND(!gizmo_plugin); + gizmo_plugin->commit_handle(this, p_id, p_restore, p_cancel); +} + +int EditorNode3DGizmo::subgizmos_intersect_ray(Camera3D *p_camera, const Vector2 &p_point) const { + if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_ray")) { + return get_script_instance()->call("_subgizmos_intersect_ray", p_camera, p_point); + } + + ERR_FAIL_COND_V(!gizmo_plugin, -1); + return gizmo_plugin->subgizmos_intersect_ray(this, p_camera, p_point); +} + +Vector<int> EditorNode3DGizmo::subgizmos_intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum) const { + if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_frustum")) { + Array frustum; + for (int i = 0; i < p_frustum.size(); i++) { + frustum[i] = p_frustum[i]; + } + return get_script_instance()->call("_subgizmos_intersect_frustum", p_camera, frustum); + } + + ERR_FAIL_COND_V(!gizmo_plugin, Vector<int>()); + return gizmo_plugin->subgizmos_intersect_frustum(this, p_camera, p_frustum); +} + +Transform3D EditorNode3DGizmo::get_subgizmo_transform(int p_id) const { + if (get_script_instance() && get_script_instance()->has_method("_get_subgizmo_transform")) { + return get_script_instance()->call("_get_subgizmo_transform", p_id); + } + + ERR_FAIL_COND_V(!gizmo_plugin, Transform3D()); + return gizmo_plugin->get_subgizmo_transform(this, p_id); +} + +void EditorNode3DGizmo::set_subgizmo_transform(int p_id, Transform3D p_transform) const { + if (get_script_instance() && get_script_instance()->has_method("_set_subgizmo_transform")) { + get_script_instance()->call("_set_subgizmo_transform", p_id, p_transform); return; } ERR_FAIL_COND(!gizmo_plugin); - gizmo_plugin->commit_handle(this, p_idx, p_restore, p_cancel); + gizmo_plugin->set_subgizmo_transform(this, p_id, p_transform); +} + +void EditorNode3DGizmo::commit_subgizmos(const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel) const { + if (get_script_instance() && get_script_instance()->has_method("_commit_subgizmos")) { + Array ids; + for (int i = 0; i < p_ids.size(); i++) { + ids[i] = p_ids[i]; + } + + Array restore; + for (int i = 0; i < p_restore.size(); i++) { + restore[i] = p_restore[i]; + } + + get_script_instance()->call("_commit_subgizmos", ids, restore, p_cancel); + return; + } + + ERR_FAIL_COND(!gizmo_plugin); + gizmo_plugin->commit_subgizmos(this, p_ids, p_restore, p_cancel); } void EditorNode3DGizmo::set_spatial_node(Node3D *p_node) { @@ -180,17 +246,17 @@ void EditorNode3DGizmo::Instance::create_instance(Node3D *p_base, bool p_hidden) RS::get_singleton()->instance_geometry_set_flag(instance, RS::INSTANCE_FLAG_IGNORE_OCCLUSION_CULLING, true); } -void EditorNode3DGizmo::add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard, const Ref<SkinReference> &p_skin_reference, const Ref<Material> &p_material) { +void EditorNode3DGizmo::add_mesh(const Ref<ArrayMesh> &p_mesh, const Ref<Material> &p_material, const Transform3D &p_xform, const Ref<SkinReference> &p_skin_reference) { ERR_FAIL_COND(!spatial_node); Instance ins; - ins.billboard = p_billboard; ins.mesh = p_mesh; ins.skin_reference = p_skin_reference; ins.material = p_material; + ins.xform = p_xform; if (valid) { ins.create_instance(spatial_node, hidden); - RS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform()); + RS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform() * ins.xform); if (ins.material.is_valid()) { RS::get_singleton()->instance_geometry_set_material_override(ins.instance, p_material->get_rid()); } @@ -245,7 +311,6 @@ void EditorNode3DGizmo::add_vertices(const Vector<Vector3> &p_vertices, const Re } } - ins.billboard = p_billboard; ins.mesh = mesh; if (valid) { ins.create_instance(spatial_node, hidden); @@ -307,8 +372,6 @@ void EditorNode3DGizmo::add_unscaled_billboard(const Ref<Material> &p_material, mesh->set_custom_aabb(AABB(Vector3(-selectable_icon_size, -selectable_icon_size, -selectable_icon_size) * 100.0f, Vector3(selectable_icon_size, selectable_icon_size, selectable_icon_size) * 200.0f)); ins.mesh = mesh; - ins.unscaled = true; - ins.billboard = true; if (valid) { ins.create_instance(spatial_node, hidden); RS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform()); @@ -331,7 +394,7 @@ void EditorNode3DGizmo::add_collision_segments(const Vector<Vector3> &p_lines) { } } -void EditorNode3DGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, bool p_billboard, bool p_secondary) { +void EditorNode3DGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, const Vector<int> &p_ids, bool p_billboard, bool p_secondary) { billboard_handle = p_billboard; if (!is_selected() || !is_editable()) { @@ -340,8 +403,16 @@ void EditorNode3DGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref< ERR_FAIL_COND(!spatial_node); - Instance ins; + if (p_ids.is_empty()) { + ERR_FAIL_COND_MSG((!handles.is_empty() && !handle_ids.is_empty()) || (!secondary_handles.is_empty() && !secondary_handle_ids.is_empty()), "Fail"); + } else { + ERR_FAIL_COND_MSG(handles.size() != handle_ids.size() || secondary_handles.size() != secondary_handle_ids.size(), "Fail"); + } + bool is_current_hover_gizmo = Node3DEditor::get_singleton()->get_current_hover_gizmo() == this; + int current_hover_handle = Node3DEditor::get_singleton()->get_current_hover_gizmo_handle(); + + Instance ins; Ref<ArrayMesh> mesh = memnew(ArrayMesh); Array a; @@ -357,7 +428,8 @@ void EditorNode3DGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref< col = Color(0, 0, 1, 0.9); } - if (Node3DEditor::get_singleton()->get_over_gizmo_handle() != i) { + int id = p_ids.is_empty() ? i : p_ids[i]; + if (!is_current_hover_gizmo || current_hover_handle != id) { col.a = 0.8; } @@ -379,29 +451,31 @@ void EditorNode3DGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref< } ins.mesh = mesh; - ins.billboard = p_billboard; ins.extra_margin = true; if (valid) { ins.create_instance(spatial_node, hidden); RS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform()); } instances.push_back(ins); - if (!p_secondary) { - int chs = handles.size(); - handles.resize(chs + p_handles.size()); - for (int i = 0; i < p_handles.size(); i++) { - handles.write[i + chs] = p_handles[i]; - } - } else { - int chs = secondary_handles.size(); - secondary_handles.resize(chs + p_handles.size()); - for (int i = 0; i < p_handles.size(); i++) { - secondary_handles.write[i + chs] = p_handles[i]; + + Vector<Vector3> &h = p_secondary ? secondary_handles : handles; + int current_size = h.size(); + h.resize(current_size + p_handles.size()); + for (int i = 0; i < p_handles.size(); i++) { + h.write[current_size + i] = p_handles[i]; + } + + if (!p_ids.is_empty()) { + Vector<int> &ids = p_secondary ? secondary_handle_ids : handle_ids; + current_size = ids.size(); + ids.resize(current_size + p_ids.size()); + for (int i = 0; i < p_ids.size(); i++) { + ids.write[current_size + i] = p_ids[i]; } } } -void EditorNode3DGizmo::add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position) { +void EditorNode3DGizmo::add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position, const Transform3D &p_xform) { ERR_FAIL_COND(!spatial_node); BoxMesh box_mesh; @@ -419,8 +493,7 @@ void EditorNode3DGizmo::add_solid_box(Ref<Material> &p_material, Vector3 p_size, Ref<ArrayMesh> m = memnew(ArrayMesh); m->add_surface_from_arrays(box_mesh.surface_get_primitive_type(0), arrays); - m->surface_set_material(0, p_material); - add_mesh(m); + add_mesh(m, p_material, p_xform); } bool EditorNode3DGizmo::intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum) { @@ -485,13 +558,15 @@ bool EditorNode3DGizmo::intersect_frustum(const Camera3D *p_camera, const Vector Transform3D it = t.affine_inverse(); Vector<Plane> transformed_frustum; + int plane_count = p_frustum.size(); + transformed_frustum.resize(plane_count); - for (int i = 0; i < p_frustum.size(); i++) { - transformed_frustum.push_back(it.xform(p_frustum[i])); + for (int i = 0; i < plane_count; i++) { + transformed_frustum.write[i] = it.xform(p_frustum[i]); } - Vector<Vector3> convex_points = Geometry3D::compute_convex_mesh_points(p_frustum.ptr(), p_frustum.size()); - if (collision_mesh->inside_convex_shape(transformed_frustum.ptr(), transformed_frustum.size(), convex_points.ptr(), convex_points.size(), mesh_scale)) { + Vector<Vector3> convex_points = Geometry3D::compute_convex_mesh_points(transformed_frustum.ptr(), plane_count); + if (collision_mesh->inside_convex_shape(transformed_frustum.ptr(), plane_count, convex_points.ptr(), convex_points.size(), mesh_scale)) { return true; } } @@ -499,70 +574,77 @@ bool EditorNode3DGizmo::intersect_frustum(const Camera3D *p_camera, const Vector return false; } -bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle, bool p_sec_first) { - ERR_FAIL_COND_V(!spatial_node, false); - ERR_FAIL_COND_V(!valid, false); +void EditorNode3DGizmo::handles_intersect_ray(Camera3D *p_camera, const Vector2 &p_point, bool p_shift_pressed, int &r_id) { + r_id = -1; - if (hidden && !gizmo_plugin->is_selectable_when_hidden()) { - return false; + ERR_FAIL_COND(!spatial_node); + ERR_FAIL_COND(!valid); + + if (hidden) { + return; } - if (r_gizmo_handle && !hidden) { - Transform3D t = spatial_node->get_global_transform(); - if (billboard_handle) { - t.set_look_at(t.origin, t.origin - p_camera->get_transform().basis.get_axis(2), p_camera->get_transform().basis.get_axis(1)); - } + Transform3D camera_xform = p_camera->get_global_transform(); + Transform3D t = spatial_node->get_global_transform(); + if (billboard_handle) { + t.set_look_at(t.origin, t.origin - camera_xform.basis.get_axis(2), camera_xform.basis.get_axis(1)); + } - float min_d = 1e20; - int idx = -1; + float min_d = 1e20; - for (int i = 0; i < secondary_handles.size(); i++) { - Vector3 hpos = t.xform(secondary_handles[i]); - Vector2 p = p_camera->unproject_position(hpos); + for (int i = 0; i < secondary_handles.size(); i++) { + Vector3 hpos = t.xform(secondary_handles[i]); + Vector2 p = p_camera->unproject_position(hpos); - if (p.distance_to(p_point) < HANDLE_HALF_SIZE) { - real_t dp = p_camera->get_transform().origin.distance_to(hpos); - if (dp < min_d) { - r_pos = t.xform(hpos); - r_normal = p_camera->get_transform().basis.get_axis(2); - min_d = dp; - idx = i + handles.size(); + if (p.distance_to(p_point) < HANDLE_HALF_SIZE) { + real_t dp = p_camera->get_transform().origin.distance_to(hpos); + if (dp < min_d) { + min_d = dp; + if (secondary_handle_ids.is_empty()) { + r_id = i; + } else { + r_id = secondary_handle_ids[i]; } } } + } - if (p_sec_first && idx != -1) { - *r_gizmo_handle = idx; - return true; - } + if (r_id != -1 && p_shift_pressed) { + return; + } - min_d = 1e20; + min_d = 1e20; - for (int i = 0; i < handles.size(); i++) { - Vector3 hpos = t.xform(handles[i]); - Vector2 p = p_camera->unproject_position(hpos); + for (int i = 0; i < handles.size(); i++) { + Vector3 hpos = t.xform(handles[i]); + Vector2 p = p_camera->unproject_position(hpos); - if (p.distance_to(p_point) < HANDLE_HALF_SIZE) { - real_t dp = p_camera->get_transform().origin.distance_to(hpos); - if (dp < min_d) { - r_pos = t.xform(hpos); - r_normal = p_camera->get_transform().basis.get_axis(2); - min_d = dp; - idx = i; + if (p.distance_to(p_point) < HANDLE_HALF_SIZE) { + real_t dp = p_camera->get_transform().origin.distance_to(hpos); + if (dp < min_d) { + min_d = dp; + if (handle_ids.is_empty()) { + r_id = i; + } else { + r_id = handle_ids[i]; } } } + } +} - if (idx >= 0) { - *r_gizmo_handle = idx; - return true; - } +bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal) { + ERR_FAIL_COND_V(!spatial_node, false); + ERR_FAIL_COND_V(!valid, false); + + if (hidden && !gizmo_plugin->is_selectable_when_hidden()) { + return false; } if (selectable_icon_size > 0.0f) { Transform3D t = spatial_node->get_global_transform(); Vector3 camera_position = p_camera->get_camera_transform().origin; - if (camera_position.distance_squared_to(t.origin) > 0.01) { + if (!camera_position.is_equal_approx(t.origin)) { t.set_look_at(t.origin, camera_position); } @@ -578,7 +660,7 @@ bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point, Transform3D orig_camera_transform = p_camera->get_camera_transform(); - if (orig_camera_transform.origin.distance_squared_to(t.origin) > 0.01 && + if (!orig_camera_transform.origin.is_equal_approx(t.origin) && ABS(orig_camera_transform.basis.get_axis(Vector3::AXIS_Z).dot(Vector3(0, 1, 0))) < 0.99) { p_camera->look_at(t.origin); } @@ -674,6 +756,25 @@ bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point, return false; } +bool EditorNode3DGizmo::is_subgizmo_selected(int p_id) const { + Node3DEditor *ed = Node3DEditor::get_singleton(); + ERR_FAIL_COND_V(!ed, false); + return ed->is_current_selected_gizmo(this) && ed->is_subgizmo_selected(p_id); +} + +Vector<int> EditorNode3DGizmo::get_subgizmo_selection() const { + Vector<int> ret; + + Node3DEditor *ed = Node3DEditor::get_singleton(); + ERR_FAIL_COND_V(!ed, ret); + + if (ed->is_current_selected_gizmo(this)) { + ret = ed->get_subgizmo_selection(); + } + + return ret; +} + void EditorNode3DGizmo::create() { ERR_FAIL_COND(!spatial_node); ERR_FAIL_COND(valid); @@ -690,7 +791,7 @@ void EditorNode3DGizmo::transform() { ERR_FAIL_COND(!spatial_node); ERR_FAIL_COND(!valid); for (int i = 0; i < instances.size(); i++) { - RS::get_singleton()->instance_set_transform(instances[i].instance, spatial_node->get_global_transform()); + RS::get_singleton()->instance_set_transform(instances[i].instance, spatial_node->get_global_transform() * instances[i].xform); } } @@ -724,38 +825,46 @@ void EditorNode3DGizmo::set_plugin(EditorNode3DGizmoPlugin *p_plugin) { void EditorNode3DGizmo::_bind_methods() { ClassDB::bind_method(D_METHOD("add_lines", "lines", "material", "billboard", "modulate"), &EditorNode3DGizmo::add_lines, DEFVAL(false), DEFVAL(Color(1, 1, 1))); - ClassDB::bind_method(D_METHOD("add_mesh", "mesh", "billboard", "skeleton", "material"), &EditorNode3DGizmo::add_mesh, DEFVAL(false), DEFVAL(Ref<SkinReference>()), DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("add_mesh", "mesh", "material", "transform", "skeleton"), &EditorNode3DGizmo::add_mesh, DEFVAL(Variant()), DEFVAL(Transform3D()), DEFVAL(Ref<SkinReference>())); ClassDB::bind_method(D_METHOD("add_collision_segments", "segments"), &EditorNode3DGizmo::add_collision_segments); ClassDB::bind_method(D_METHOD("add_collision_triangles", "triangles"), &EditorNode3DGizmo::add_collision_triangles); ClassDB::bind_method(D_METHOD("add_unscaled_billboard", "material", "default_scale", "modulate"), &EditorNode3DGizmo::add_unscaled_billboard, DEFVAL(1), DEFVAL(Color(1, 1, 1))); - ClassDB::bind_method(D_METHOD("add_handles", "handles", "material", "billboard", "secondary"), &EditorNode3DGizmo::add_handles, DEFVAL(false), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("add_handles", "handles", "material", "ids", "billboard", "secondary"), &EditorNode3DGizmo::add_handles, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("set_spatial_node", "node"), &EditorNode3DGizmo::_set_spatial_node); ClassDB::bind_method(D_METHOD("get_spatial_node"), &EditorNode3DGizmo::get_spatial_node); ClassDB::bind_method(D_METHOD("get_plugin"), &EditorNode3DGizmo::get_plugin); ClassDB::bind_method(D_METHOD("clear"), &EditorNode3DGizmo::clear); ClassDB::bind_method(D_METHOD("set_hidden", "hidden"), &EditorNode3DGizmo::set_hidden); + ClassDB::bind_method(D_METHOD("is_subgizmo_selected"), &EditorNode3DGizmo::is_subgizmo_selected); + ClassDB::bind_method(D_METHOD("get_subgizmo_selection"), &EditorNode3DGizmo::get_subgizmo_selection); BIND_VMETHOD(MethodInfo("_redraw")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_handle_name", PropertyInfo(Variant::INT, "index"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_handle_highlighted", PropertyInfo(Variant::INT, "index"))); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_handle_name", PropertyInfo(Variant::INT, "id"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_handle_highlighted", PropertyInfo(Variant::INT, "id"))); - MethodInfo hvget(Variant::NIL, "_get_handle_value", PropertyInfo(Variant::INT, "index")); + MethodInfo hvget(Variant::NIL, "_get_handle_value", PropertyInfo(Variant::INT, "id")); hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; BIND_VMETHOD(hvget); - BIND_VMETHOD(MethodInfo("_set_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - MethodInfo cm = MethodInfo("_commit_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); + BIND_VMETHOD(MethodInfo("_set_handle", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); + MethodInfo cm = MethodInfo("_commit_handle", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); cm.default_arguments.push_back(false); BIND_VMETHOD(cm); + + BIND_VMETHOD(MethodInfo(Variant::INT, "_subgizmos_intersect_ray", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); + BIND_VMETHOD(MethodInfo(Variant::PACKED_INT32_ARRAY, "_subgizmos_intersect_frustum", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::ARRAY, "frustum"))); + BIND_VMETHOD(MethodInfo(Variant::TRANSFORM3D, "_get_subgizmo_transform", PropertyInfo(Variant::INT, "id"))); + BIND_VMETHOD(MethodInfo("_set_subgizmo_transform", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::TRANSFORM3D, "transform"))); + MethodInfo cs = MethodInfo("_commit_subgizmos", PropertyInfo(Variant::PACKED_INT32_ARRAY, "ids"), PropertyInfo(Variant::ARRAY, "restore"), PropertyInfo(Variant::BOOL, "cancel")); + cs.default_arguments.push_back(false); + BIND_VMETHOD(cs); } EditorNode3DGizmo::EditorNode3DGizmo() { valid = false; billboard_handle = false; hidden = false; - base = nullptr; selected = false; - instantiated = false; spatial_node = nullptr; gizmo_plugin = nullptr; selectable_icon_size = -1.0f; @@ -768,10 +877,362 @@ EditorNode3DGizmo::~EditorNode3DGizmo() { clear(); } -Vector3 EditorNode3DGizmo::get_handle_pos(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, handles.size(), Vector3()); +///// + +void EditorNode3DGizmoPlugin::create_material(const String &p_name, const Color &p_color, bool p_billboard, bool p_on_top, bool p_use_vertex_color) { + Color instantiated_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6)); + + Vector<Ref<StandardMaterial3D>> mats; + + for (int i = 0; i < 4; i++) { + bool selected = i % 2 == 1; + bool instantiated = i < 2; + + Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); - return handles[p_idx]; + Color color = instantiated ? instantiated_color : p_color; + + if (!selected) { + color.a *= 0.3; + } + + material->set_albedo(color); + material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 1); + material->set_cull_mode(StandardMaterial3D::CULL_DISABLED); + + if (p_use_vertex_color) { + material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); + } + + if (p_billboard) { + material->set_billboard_mode(StandardMaterial3D::BILLBOARD_ENABLED); + } + + if (p_on_top && selected) { + material->set_on_top_of_alpha(); + } + + mats.push_back(material); + } + + materials[p_name] = mats; +} + +void EditorNode3DGizmoPlugin::create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top, const Color &p_albedo) { + Color instantiated_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6)); + + Vector<Ref<StandardMaterial3D>> icons; + + for (int i = 0; i < 4; i++) { + bool selected = i % 2 == 1; + bool instantiated = i < 2; + + Ref<StandardMaterial3D> icon = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); + + Color color = instantiated ? instantiated_color : p_albedo; + + if (!selected) { + color.a *= 0.85; + } + + icon->set_albedo(color); + + icon->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + icon->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + icon->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); + icon->set_cull_mode(StandardMaterial3D::CULL_DISABLED); + icon->set_depth_draw_mode(StandardMaterial3D::DEPTH_DRAW_DISABLED); + icon->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + icon->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, p_texture); + icon->set_flag(StandardMaterial3D::FLAG_FIXED_SIZE, true); + icon->set_billboard_mode(StandardMaterial3D::BILLBOARD_ENABLED); + icon->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN); + + if (p_on_top && selected) { + icon->set_on_top_of_alpha(); + } + + icons.push_back(icon); + } + + materials[p_name] = icons; +} + +void EditorNode3DGizmoPlugin::create_handle_material(const String &p_name, bool p_billboard, const Ref<Texture2D> &p_icon) { + Ref<StandardMaterial3D> handle_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); + + handle_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + handle_material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true); + Ref<Texture2D> handle_t = p_icon != nullptr ? p_icon : Node3DEditor::get_singleton()->get_theme_icon(SNAME("Editor3DHandle"), SNAME("EditorIcons")); + handle_material->set_point_size(handle_t->get_width()); + handle_material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, handle_t); + handle_material->set_albedo(Color(1, 1, 1)); + handle_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + handle_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); + handle_material->set_on_top_of_alpha(); + if (p_billboard) { + handle_material->set_billboard_mode(StandardMaterial3D::BILLBOARD_ENABLED); + handle_material->set_on_top_of_alpha(); + } + handle_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + + materials[p_name] = Vector<Ref<StandardMaterial3D>>(); + materials[p_name].push_back(handle_material); +} + +void EditorNode3DGizmoPlugin::add_material(const String &p_name, Ref<StandardMaterial3D> p_material) { + materials[p_name] = Vector<Ref<StandardMaterial3D>>(); + materials[p_name].push_back(p_material); +} + +Ref<StandardMaterial3D> EditorNode3DGizmoPlugin::get_material(const String &p_name, const Ref<EditorNode3DGizmo> &p_gizmo) { + ERR_FAIL_COND_V(!materials.has(p_name), Ref<StandardMaterial3D>()); + ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<StandardMaterial3D>()); + + if (p_gizmo.is_null() || materials[p_name].size() == 1) { + return materials[p_name][0]; + } + + int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0); + + Ref<StandardMaterial3D> mat = materials[p_name][index]; + + if (current_state == ON_TOP && p_gizmo->is_selected()) { + mat->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true); + } else { + mat->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, false); + } + + return mat; +} + +String EditorNode3DGizmoPlugin::get_gizmo_name() const { + if (get_script_instance() && get_script_instance()->has_method("_get_gizmo_name")) { + return get_script_instance()->call("_get_gizmo_name"); + } + return TTR("Nameless gizmo"); +} + +int EditorNode3DGizmoPlugin::get_priority() const { + if (get_script_instance() && get_script_instance()->has_method("_get_priority")) { + return get_script_instance()->call("_get_priority"); + } + return 0; +} + +Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) { + if (get_script_instance() && get_script_instance()->has_method("_get_gizmo")) { + return get_script_instance()->call("_get_gizmo", p_spatial); + } + + Ref<EditorNode3DGizmo> ref = create_gizmo(p_spatial); + + if (ref.is_null()) { + return ref; + } + + ref->set_plugin(this); + ref->set_spatial_node(p_spatial); + ref->set_hidden(current_state == HIDDEN); + + current_gizmos.push_back(ref.ptr()); + return ref; +} + +void EditorNode3DGizmoPlugin::_bind_methods() { +#define GIZMO_REF PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "EditorNode3DGizmo") + + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); + BIND_VMETHOD(MethodInfo(GIZMO_REF, "_create_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); + + ClassDB::bind_method(D_METHOD("create_material", "name", "color", "billboard", "on_top", "use_vertex_color"), &EditorNode3DGizmoPlugin::create_material, DEFVAL(false), DEFVAL(false), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("create_icon_material", "name", "texture", "on_top", "color"), &EditorNode3DGizmoPlugin::create_icon_material, DEFVAL(false), DEFVAL(Color(1, 1, 1, 1))); + ClassDB::bind_method(D_METHOD("create_handle_material", "name", "billboard", "texture"), &EditorNode3DGizmoPlugin::create_handle_material, DEFVAL(false), DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("add_material", "name", "material"), &EditorNode3DGizmoPlugin::add_material); + + ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorNode3DGizmoPlugin::get_material, DEFVAL(Ref<EditorNode3DGizmo>())); + + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_gizmo_name")); + BIND_VMETHOD(MethodInfo(Variant::INT, "_get_priority")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_be_hidden")); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_selectable_when_hidden")); + + BIND_VMETHOD(MethodInfo("_redraw", GIZMO_REF)); + BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_handle_name", GIZMO_REF, PropertyInfo(Variant::INT, "id"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_handle_highlighted", GIZMO_REF, PropertyInfo(Variant::INT, "id"))); + + MethodInfo hvget(Variant::NIL, "_get_handle_value", GIZMO_REF, PropertyInfo(Variant::INT, "id")); + hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + BIND_VMETHOD(hvget); + + BIND_VMETHOD(MethodInfo("_set_handle", GIZMO_REF, PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); + MethodInfo cm = MethodInfo("_commit_handle", GIZMO_REF, PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); + cm.default_arguments.push_back(false); + BIND_VMETHOD(cm); + + BIND_VMETHOD(MethodInfo(Variant::INT, "_subgizmos_intersect_ray", GIZMO_REF, PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); + BIND_VMETHOD(MethodInfo(Variant::PACKED_INT32_ARRAY, "_subgizmos_intersect_frustum", GIZMO_REF, PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::ARRAY, "frustum"))); + BIND_VMETHOD(MethodInfo(Variant::TRANSFORM3D, "_get_subgizmo_transform", GIZMO_REF, PropertyInfo(Variant::INT, "id"))); + BIND_VMETHOD(MethodInfo("_set_subgizmo_transform", GIZMO_REF, PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::TRANSFORM3D, "transform"))); + MethodInfo cs = MethodInfo("_commit_subgizmos", GIZMO_REF, PropertyInfo(Variant::PACKED_INT32_ARRAY, "ids"), PropertyInfo(Variant::ARRAY, "restore"), PropertyInfo(Variant::BOOL, "cancel")); + cs.default_arguments.push_back(false); + BIND_VMETHOD(cs); + +#undef GIZMO_REF +} + +bool EditorNode3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { + if (get_script_instance() && get_script_instance()->has_method("_has_gizmo")) { + return get_script_instance()->call("_has_gizmo", p_spatial); + } + return false; +} + +Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) { + if (get_script_instance() && get_script_instance()->has_method("_create_gizmo")) { + return get_script_instance()->call("_create_gizmo", p_spatial); + } + + Ref<EditorNode3DGizmo> ref; + if (has_gizmo(p_spatial)) { + ref.instantiate(); + } + return ref; +} + +bool EditorNode3DGizmoPlugin::can_be_hidden() const { + if (get_script_instance() && get_script_instance()->has_method("_can_be_hidden")) { + return get_script_instance()->call("_can_be_hidden"); + } + return true; +} + +bool EditorNode3DGizmoPlugin::is_selectable_when_hidden() const { + if (get_script_instance() && get_script_instance()->has_method("_is_selectable_when_hidden")) { + return get_script_instance()->call("_is_selectable_when_hidden"); + } + return false; +} + +void EditorNode3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { + if (get_script_instance() && get_script_instance()->has_method("_redraw")) { + Ref<EditorNode3DGizmo> ref(p_gizmo); + get_script_instance()->call("_redraw", ref); + } +} + +bool EditorNode3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id) const { + if (get_script_instance() && get_script_instance()->has_method("_is_handle_highlighted")) { + return get_script_instance()->call("_is_handle_highlighted", p_gizmo, p_id); + } + return false; +} + +String EditorNode3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { + if (get_script_instance() && get_script_instance()->has_method("_get_handle_name")) { + return get_script_instance()->call("_get_handle_name", p_gizmo, p_id); + } + return ""; +} + +Variant EditorNode3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { + if (get_script_instance() && get_script_instance()->has_method("_get_handle_value")) { + return get_script_instance()->call("_get_handle_value", p_gizmo, p_id); + } + return Variant(); +} + +void EditorNode3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { + if (get_script_instance() && get_script_instance()->has_method("_set_handle")) { + get_script_instance()->call("_set_handle", p_gizmo, p_id, p_camera, p_point); + } +} + +void EditorNode3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { + if (get_script_instance() && get_script_instance()->has_method("_commit_handle")) { + get_script_instance()->call("_commit_handle", p_gizmo, p_id, p_restore, p_cancel); + } +} + +int EditorNode3DGizmoPlugin::subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const { + if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_ray")) { + return get_script_instance()->call("_subgizmos_intersect_ray", p_camera, p_point); + } + return -1; +} + +Vector<int> EditorNode3DGizmoPlugin::subgizmos_intersect_frustum(const EditorNode3DGizmo *p_gizmo, const Camera3D *p_camera, const Vector<Plane> &p_frustum) const { + if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_frustum")) { + Array frustum; + for (int i = 0; i < p_frustum.size(); i++) { + frustum[i] = p_frustum[i]; + } + return get_script_instance()->call("_subgizmos_intersect_frustum", p_camera, frustum); + } + + return Vector<int>(); +} + +Transform3D EditorNode3DGizmoPlugin::get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const { + if (get_script_instance() && get_script_instance()->has_method("_get_subgizmo_transform")) { + return get_script_instance()->call("_get_subgizmo_transform", p_id); + } + + return Transform3D(); +} + +void EditorNode3DGizmoPlugin::set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform) const { + if (get_script_instance() && get_script_instance()->has_method("_set_subgizmo_transform")) { + get_script_instance()->call("_set_subgizmo_transform", p_id, p_transform); + } +} + +void EditorNode3DGizmoPlugin::commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel) const { + if (get_script_instance() && get_script_instance()->has_method("_commit_subgizmos")) { + Array ids; + for (int i = 0; i < p_ids.size(); i++) { + ids[i] = p_ids[i]; + } + + Array restore; + for (int i = 0; i < p_restore.size(); i++) { + restore[i] = p_restore[i]; + } + + get_script_instance()->call("_commit_subgizmos", ids, restore, p_cancel); + } +} + +void EditorNode3DGizmoPlugin::set_state(int p_state) { + current_state = p_state; + for (int i = 0; i < current_gizmos.size(); ++i) { + current_gizmos[i]->set_hidden(current_state == HIDDEN); + } +} + +int EditorNode3DGizmoPlugin::get_state() const { + return current_state; +} + +void EditorNode3DGizmoPlugin::unregister_gizmo(EditorNode3DGizmo *p_gizmo) { + current_gizmos.erase(p_gizmo); +} + +EditorNode3DGizmoPlugin::EditorNode3DGizmoPlugin() { + current_state = VISIBLE; +} + +EditorNode3DGizmoPlugin::~EditorNode3DGizmoPlugin() { + for (int i = 0; i < current_gizmos.size(); ++i) { + current_gizmos[i]->set_plugin(nullptr); + current_gizmos[i]->get_spatial_node()->remove_gizmo(current_gizmos[i]); + } + if (Node3DEditor::get_singleton()) { + Node3DEditor::get_singleton()->update_all_gizmos(); + } } //// light gizmo @@ -802,20 +1263,20 @@ int Light3DGizmoPlugin::get_priority() const { return -1; } -String Light3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - if (p_idx == 0) { +String Light3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { + if (p_id == 0) { return "Radius"; } else { return "Aperture"; } } -Variant Light3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant Light3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { Light3D *light = Object::cast_to<Light3D>(p_gizmo->get_spatial_node()); - if (p_idx == 0) { + if (p_id == 0) { return light->get_param(Light3D::PARAM_RANGE); } - if (p_idx == 1) { + if (p_id == 1) { return light->get_param(Light3D::PARAM_SPOT_ANGLE); } @@ -849,7 +1310,7 @@ static float _find_closest_angle_to_half_pi_arc(const Vector3 &p_from, const Vec return Math::rad2deg(a); } -void Light3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void Light3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { Light3D *light = Object::cast_to<Light3D>(p_gizmo->get_spatial_node()); Transform3D gt = light->get_global_transform(); Transform3D gi = gt.affine_inverse(); @@ -858,7 +1319,7 @@ void Light3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camer Vector3 ray_dir = p_camera->project_ray_normal(p_point); Vector3 s[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) }; - if (p_idx == 0) { + if (p_id == 0) { if (Object::cast_to<SpotLight3D>(light)) { Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(Vector3(), Vector3(0, 0, -4096), s[0], s[1], ra, rb); @@ -887,24 +1348,24 @@ void Light3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camer } } - } else if (p_idx == 1) { + } else if (p_id == 1) { float a = _find_closest_angle_to_half_pi_arc(s[0], s[1], light->get_param(Light3D::PARAM_RANGE), gt); light->set_param(Light3D::PARAM_SPOT_ANGLE, CLAMP(a, 0.01, 89.99)); } } -void Light3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void Light3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { Light3D *light = Object::cast_to<Light3D>(p_gizmo->get_spatial_node()); if (p_cancel) { - light->set_param(p_idx == 0 ? Light3D::PARAM_RANGE : Light3D::PARAM_SPOT_ANGLE, p_restore); + light->set_param(p_id == 0 ? Light3D::PARAM_RANGE : Light3D::PARAM_SPOT_ANGLE, p_restore); - } else if (p_idx == 0) { + } else if (p_id == 0) { UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); ur->create_action(TTR("Change Light Radius")); ur->add_do_method(light, "set_param", Light3D::PARAM_RANGE, light->get_param(Light3D::PARAM_RANGE)); ur->add_undo_method(light, "set_param", Light3D::PARAM_RANGE, p_restore); ur->commit_action(); - } else if (p_idx == 1) { + } else if (p_id == 1) { UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); ur->create_action(TTR("Change Light Radius")); ur->add_do_method(light, "set_param", Light3D::PARAM_SPOT_ANGLE, light->get_param(Light3D::PARAM_SPOT_ANGLE)); @@ -996,7 +1457,7 @@ void Light3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Vector<Vector3> handles; handles.push_back(Vector3(r, 0, 0)); - p_gizmo->add_handles(handles, get_material("handles_billboard"), true); + p_gizmo->add_handles(handles, get_material("handles_billboard"), Vector<int>(), true); } if (Object::cast_to<SpotLight3D>(light)) { @@ -1068,16 +1529,16 @@ int AudioStreamPlayer3DGizmoPlugin::get_priority() const { return -1; } -String AudioStreamPlayer3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { +String AudioStreamPlayer3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { return "Emission Radius"; } -Variant AudioStreamPlayer3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant AudioStreamPlayer3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { AudioStreamPlayer3D *player = Object::cast_to<AudioStreamPlayer3D>(p_gizmo->get_spatial_node()); return player->get_emission_angle(); } -void AudioStreamPlayer3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void AudioStreamPlayer3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { AudioStreamPlayer3D *player = Object::cast_to<AudioStreamPlayer3D>(p_gizmo->get_spatial_node()); Transform3D gt = player->get_global_transform(); @@ -1114,7 +1575,7 @@ void AudioStreamPlayer3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int } } -void AudioStreamPlayer3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void AudioStreamPlayer3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { AudioStreamPlayer3D *player = Object::cast_to<AudioStreamPlayer3D>(p_gizmo->get_spatial_node()); if (p_cancel) { @@ -1203,7 +1664,7 @@ int Camera3DGizmoPlugin::get_priority() const { return -1; } -String Camera3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { +String Camera3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { Camera3D *camera = Object::cast_to<Camera3D>(p_gizmo->get_spatial_node()); if (camera->get_projection() == Camera3D::PROJECTION_PERSPECTIVE) { @@ -1213,7 +1674,7 @@ String Camera3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, in } } -Variant Camera3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant Camera3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { Camera3D *camera = Object::cast_to<Camera3D>(p_gizmo->get_spatial_node()); if (camera->get_projection() == Camera3D::PROJECTION_PERSPECTIVE) { @@ -1223,7 +1684,7 @@ Variant Camera3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_ } } -void Camera3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void Camera3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { Camera3D *camera = Object::cast_to<Camera3D>(p_gizmo->get_spatial_node()); Transform3D gt = camera->get_global_transform(); @@ -1252,7 +1713,7 @@ void Camera3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Came } } -void Camera3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void Camera3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { Camera3D *camera = Object::cast_to<Camera3D>(p_gizmo->get_spatial_node()); if (camera->get_projection() == Camera3D::PROJECTION_PERSPECTIVE) { @@ -1761,7 +2222,7 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { } Ref<ArrayMesh> m = surface_tool->commit(); - p_gizmo->add_mesh(m, false, skel->register_skin(Ref<Skin>())); + p_gizmo->add_mesh(m, Ref<Material>(), Transform3D(), skel->register_skin(Ref<Skin>())); } //// @@ -2102,23 +2563,23 @@ void SoftBody3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->add_collision_triangles(tm); } -String SoftBody3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { +String SoftBody3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { return "SoftBody3D pin point"; } -Variant SoftBody3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant SoftBody3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { SoftBody3D *soft_body = Object::cast_to<SoftBody3D>(p_gizmo->get_spatial_node()); - return Variant(soft_body->is_point_pinned(p_idx)); + return Variant(soft_body->is_point_pinned(p_id)); } -void SoftBody3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void SoftBody3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { SoftBody3D *soft_body = Object::cast_to<SoftBody3D>(p_gizmo->get_spatial_node()); - soft_body->pin_point_toggle(p_idx); + soft_body->pin_point_toggle(p_id); } -bool SoftBody3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int idx) const { +bool SoftBody3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id) const { SoftBody3D *soft_body = Object::cast_to<SoftBody3D>(p_gizmo->get_spatial_node()); - return soft_body->is_point_pinned(idx); + return soft_body->is_point_pinned(p_id); } /////////// @@ -2143,8 +2604,8 @@ int VisibleOnScreenNotifier3DGizmoPlugin::get_priority() const { return -1; } -String VisibleOnScreenNotifier3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - switch (p_idx) { +String VisibleOnScreenNotifier3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { + switch (p_id) { case 0: return "Size X"; case 1: @@ -2162,20 +2623,20 @@ String VisibleOnScreenNotifier3DGizmoPlugin::get_handle_name(const EditorNode3DG return ""; } -Variant VisibleOnScreenNotifier3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant VisibleOnScreenNotifier3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { VisibleOnScreenNotifier3D *notifier = Object::cast_to<VisibleOnScreenNotifier3D>(p_gizmo->get_spatial_node()); return notifier->get_aabb(); } -void VisibleOnScreenNotifier3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void VisibleOnScreenNotifier3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { VisibleOnScreenNotifier3D *notifier = Object::cast_to<VisibleOnScreenNotifier3D>(p_gizmo->get_spatial_node()); Transform3D gt = notifier->get_global_transform(); Transform3D gi = gt.affine_inverse(); - bool move = p_idx >= 3; - p_idx = p_idx % 3; + bool move = p_id >= 3; + p_id = p_id % 3; AABB aabb = notifier->get_aabb(); Vector3 ray_from = p_camera->project_ray_origin(p_point); @@ -2186,25 +2647,25 @@ void VisibleOnScreenNotifier3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 axis; - axis[p_idx] = 1.0; + axis[p_id] = 1.0; if (move) { Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(ofs - axis * 4096, ofs + axis * 4096, sg[0], sg[1], ra, rb); - float d = ra[p_idx]; + float d = ra[p_id]; if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); } - aabb.position[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5; + aabb.position[p_id] = d - 1.0 - aabb.size[p_id] * 0.5; notifier->set_aabb(aabb); } else { Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(ofs, ofs + axis * 4096, sg[0], sg[1], ra, rb); - float d = ra[p_idx] - ofs[p_idx]; + float d = ra[p_id] - ofs[p_id]; if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); } @@ -2213,13 +2674,13 @@ void VisibleOnScreenNotifier3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo d = 0.001; } //resize - aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d; - aabb.size[p_idx] = d * 2; + aabb.position[p_id] = (aabb.position[p_id] + aabb.size[p_id] * 0.5) - d; + aabb.size[p_id] = d * 2; notifier->set_aabb(aabb); } } -void VisibleOnScreenNotifier3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void VisibleOnScreenNotifier3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { VisibleOnScreenNotifier3D *notifier = Object::cast_to<VisibleOnScreenNotifier3D>(p_gizmo->get_spatial_node()); if (p_cancel) { @@ -2335,8 +2796,8 @@ bool GPUParticles3DGizmoPlugin::is_selectable_when_hidden() const { return true; } -String GPUParticles3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - switch (p_idx) { +String GPUParticles3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { + switch (p_id) { case 0: return "Size X"; case 1: @@ -2354,19 +2815,19 @@ String GPUParticles3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_giz return ""; } -Variant GPUParticles3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant GPUParticles3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_spatial_node()); return particles->get_visibility_aabb(); } -void GPUParticles3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void GPUParticles3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_spatial_node()); Transform3D gt = particles->get_global_transform(); Transform3D gi = gt.affine_inverse(); - bool move = p_idx >= 3; - p_idx = p_idx % 3; + bool move = p_id >= 3; + p_id = p_id % 3; AABB aabb = particles->get_visibility_aabb(); Vector3 ray_from = p_camera->project_ray_origin(p_point); @@ -2377,25 +2838,25 @@ void GPUParticles3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 axis; - axis[p_idx] = 1.0; + axis[p_id] = 1.0; if (move) { Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(ofs - axis * 4096, ofs + axis * 4096, sg[0], sg[1], ra, rb); - float d = ra[p_idx]; + float d = ra[p_id]; if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); } - aabb.position[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5; + aabb.position[p_id] = d - 1.0 - aabb.size[p_id] * 0.5; particles->set_visibility_aabb(aabb); } else { Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(ofs, ofs + axis * 4096, sg[0], sg[1], ra, rb); - float d = ra[p_idx] - ofs[p_idx]; + float d = ra[p_id] - ofs[p_id]; if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); } @@ -2404,13 +2865,13 @@ void GPUParticles3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx d = 0.001; } //resize - aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d; - aabb.size[p_idx] = d * 2; + aabb.position[p_id] = (aabb.position[p_id] + aabb.size[p_id] * 0.5) - d; + aabb.size[p_id] = d * 2; particles->set_visibility_aabb(aabb); } } -void GPUParticles3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void GPUParticles3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_spatial_node()); if (p_cancel) { @@ -2475,8 +2936,6 @@ void GPUParticles3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { //// -//// - GPUParticlesCollision3DGizmoPlugin::GPUParticlesCollision3DGizmoPlugin() { Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particle_collision", Color(0.5, 0.7, 1)); create_material("shape_material", gizmo_color); @@ -2498,7 +2957,7 @@ int GPUParticlesCollision3DGizmoPlugin::get_priority() const { return -1; } -String GPUParticlesCollision3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { +String GPUParticlesCollision3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { const Node3D *cs = p_gizmo->get_spatial_node(); if (Object::cast_to<GPUParticlesCollisionSphere>(cs) || Object::cast_to<GPUParticlesAttractorSphere>(cs)) { @@ -2512,7 +2971,7 @@ String GPUParticlesCollision3DGizmoPlugin::get_handle_name(const EditorNode3DGiz return ""; } -Variant GPUParticlesCollision3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant GPUParticlesCollision3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { const Node3D *cs = p_gizmo->get_spatial_node(); if (Object::cast_to<GPUParticlesCollisionSphere>(cs) || Object::cast_to<GPUParticlesAttractorSphere>(cs)) { @@ -2526,7 +2985,7 @@ Variant GPUParticlesCollision3DGizmoPlugin::get_handle_value(EditorNode3DGizmo * return Variant(); } -void GPUParticlesCollision3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void GPUParticlesCollision3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { Node3D *sn = p_gizmo->get_spatial_node(); Transform3D gt = sn->get_global_transform(); @@ -2554,10 +3013,10 @@ void GPUParticlesCollision3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, if (Object::cast_to<GPUParticlesCollisionBox>(sn) || Object::cast_to<GPUParticlesAttractorBox>(sn) || Object::cast_to<GPUParticlesAttractorVectorField>(sn) || Object::cast_to<GPUParticlesCollisionSDF>(sn) || Object::cast_to<GPUParticlesCollisionHeightField>(sn)) { Vector3 axis; - axis[p_idx] = 1.0; + axis[p_id] = 1.0; Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb); - float d = ra[p_idx]; + float d = ra[p_id]; if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); } @@ -2567,12 +3026,12 @@ void GPUParticlesCollision3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, } Vector3 he = sn->call("get_extents"); - he[p_idx] = d; + he[p_id] = d; sn->call("set_extents", he); } } -void GPUParticlesCollision3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void GPUParticlesCollision3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { Node3D *sn = p_gizmo->get_spatial_node(); if (Object::cast_to<GPUParticlesCollisionSphere>(sn) || Object::cast_to<GPUParticlesAttractorSphere>(sn)) { @@ -2762,8 +3221,8 @@ int ReflectionProbeGizmoPlugin::get_priority() const { return -1; } -String ReflectionProbeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - switch (p_idx) { +String ReflectionProbeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { + switch (p_id) { case 0: return "Extents X"; case 1: @@ -2781,18 +3240,18 @@ String ReflectionProbeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gi return ""; } -Variant ReflectionProbeGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant ReflectionProbeGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { ReflectionProbe *probe = Object::cast_to<ReflectionProbe>(p_gizmo->get_spatial_node()); return AABB(probe->get_extents(), probe->get_origin_offset()); } -void ReflectionProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void ReflectionProbeGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { ReflectionProbe *probe = Object::cast_to<ReflectionProbe>(p_gizmo->get_spatial_node()); Transform3D gt = probe->get_global_transform(); Transform3D gi = gt.affine_inverse(); - if (p_idx < 3) { + if (p_id < 3) { Vector3 extents = probe->get_extents(); Vector3 ray_from = p_camera->project_ray_origin(p_point); @@ -2801,11 +3260,11 @@ void ReflectionProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_id Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) }; Vector3 axis; - axis[p_idx] = 1.0; + axis[p_id] = 1.0; Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb); - float d = ra[p_idx]; + float d = ra[p_id]; if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); } @@ -2814,13 +3273,13 @@ void ReflectionProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_id d = 0.001; } - extents[p_idx] = d; + extents[p_id] = d; probe->set_extents(extents); } else { - p_idx -= 3; + p_id -= 3; Vector3 origin = probe->get_origin_offset(); - origin[p_idx] = 0; + origin[p_id] = 0; Vector3 ray_from = p_camera->project_ray_origin(p_point); Vector3 ray_dir = p_camera->project_ray_normal(p_point); @@ -2828,22 +3287,22 @@ void ReflectionProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_id Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) }; Vector3 axis; - axis[p_idx] = 1.0; + axis[p_id] = 1.0; Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(origin - axis * 16384, origin + axis * 16384, sg[0], sg[1], ra, rb); // Adjust the actual position to account for the gizmo handle position - float d = ra[p_idx] + 0.25; + float d = ra[p_id] + 0.25; if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); } - origin[p_idx] = d; + origin[p_id] = d; probe->set_origin_offset(origin); } } -void ReflectionProbeGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void ReflectionProbeGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { ReflectionProbe *probe = Object::cast_to<ReflectionProbe>(p_gizmo->get_spatial_node()); AABB restore = p_restore; @@ -2947,8 +3406,8 @@ int DecalGizmoPlugin::get_priority() const { return -1; } -String DecalGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - switch (p_idx) { +String DecalGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { + switch (p_id) { case 0: return "Extents X"; case 1: @@ -2960,12 +3419,12 @@ String DecalGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p return ""; } -Variant DecalGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant DecalGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { Decal *decal = Object::cast_to<Decal>(p_gizmo->get_spatial_node()); return decal->get_extents(); } -void DecalGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void DecalGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { Decal *decal = Object::cast_to<Decal>(p_gizmo->get_spatial_node()); Transform3D gt = decal->get_global_transform(); @@ -2979,11 +3438,11 @@ void DecalGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3 Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) }; Vector3 axis; - axis[p_idx] = 1.0; + axis[p_id] = 1.0; Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb); - float d = ra[p_idx]; + float d = ra[p_id]; if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); } @@ -2992,11 +3451,11 @@ void DecalGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3 d = 0.001; } - extents[p_idx] = d; + extents[p_id] = d; decal->set_extents(extents); } -void DecalGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void DecalGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { Decal *decal = Object::cast_to<Decal>(p_gizmo->get_spatial_node()); Vector3 restore = p_restore; @@ -3055,7 +3514,6 @@ void DecalGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Ref<Material> material = get_material("decal_material", p_gizmo); p_gizmo->add_lines(lines, material); - p_gizmo->add_handles(handles, get_material("handles")); } @@ -3088,8 +3546,8 @@ int VoxelGIGizmoPlugin::get_priority() const { return -1; } -String VoxelGIGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - switch (p_idx) { +String VoxelGIGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { + switch (p_id) { case 0: return "Extents X"; case 1: @@ -3101,12 +3559,12 @@ String VoxelGIGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int return ""; } -Variant VoxelGIGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant VoxelGIGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { VoxelGI *probe = Object::cast_to<VoxelGI>(p_gizmo->get_spatial_node()); return probe->get_extents(); } -void VoxelGIGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void VoxelGIGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { VoxelGI *probe = Object::cast_to<VoxelGI>(p_gizmo->get_spatial_node()); Transform3D gt = probe->get_global_transform(); @@ -3120,11 +3578,11 @@ void VoxelGIGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camer Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) }; Vector3 axis; - axis[p_idx] = 1.0; + axis[p_id] = 1.0; Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb); - float d = ra[p_idx]; + float d = ra[p_id]; if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); } @@ -3133,11 +3591,11 @@ void VoxelGIGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camer d = 0.001; } - extents[p_idx] = d; + extents[p_id] = d; probe->set_extents(extents); } -void VoxelGIGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void VoxelGIGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { VoxelGI *probe = Object::cast_to<VoxelGI>(p_gizmo->get_spatial_node()); Vector3 restore = p_restore; @@ -3257,18 +3715,18 @@ LightmapGIGizmoPlugin::LightmapGIGizmoPlugin() { create_icon_material("baked_indirect_light_icon", Node3DEditor::get_singleton()->get_theme_icon(SNAME("GizmoLightmapGI"), SNAME("EditorIcons"))); } -String LightmapGIGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { +String LightmapGIGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { return ""; } -Variant LightmapGIGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant LightmapGIGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { return Variant(); } -void LightmapGIGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void LightmapGIGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { } -void LightmapGIGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void LightmapGIGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { } bool LightmapGIGizmoPlugin::has_gizmo(Node3D *p_spatial) { @@ -3439,18 +3897,18 @@ LightmapProbeGizmoPlugin::LightmapProbeGizmoPlugin() { create_material("lightprobe_lines", gizmo_color); } -String LightmapProbeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { +String LightmapProbeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { return ""; } -Variant LightmapProbeGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant LightmapProbeGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { return Variant(); } -void LightmapProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void LightmapProbeGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { } -void LightmapProbeGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void LightmapProbeGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { } bool LightmapProbeGizmoPlugin::has_gizmo(Node3D *p_spatial) { @@ -3555,8 +4013,7 @@ void CollisionObject3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { List<uint32_t> owners; co->get_shape_owners(&owners); - for (List<uint32_t>::Element *E = owners.front(); E; E = E->next()) { - uint32_t owner_id = E->get(); + for (uint32_t &owner_id : owners) { Transform3D xform = co->shape_owner_get_transform(owner_id); Object *owner = co->shape_owner_get_owner(owner_id); // Exclude CollisionShape3D and CollisionPolygon3D as they have their gizmo. @@ -3570,7 +4027,7 @@ void CollisionObject3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { SurfaceTool st; st.append_from(s->get_debug_mesh(), 0, xform); - p_gizmo->add_mesh(st.commit(), false, Ref<SkinReference>(), material); + p_gizmo->add_mesh(st.commit(), material); p_gizmo->add_collision_segments(s->get_debug_mesh_lines()); } } @@ -3600,7 +4057,7 @@ int CollisionShape3DGizmoPlugin::get_priority() const { return -1; } -String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { +String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { const CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node()); Ref<Shape3D> s = cs->get_shape(); @@ -3617,11 +4074,11 @@ String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_g } if (Object::cast_to<CapsuleShape3D>(*s)) { - return p_idx == 0 ? "Radius" : "Height"; + return p_id == 0 ? "Radius" : "Height"; } if (Object::cast_to<CylinderShape3D>(*s)) { - return p_idx == 0 ? "Radius" : "Height"; + return p_id == 0 ? "Radius" : "Height"; } if (Object::cast_to<RayShape3D>(*s)) { @@ -3631,7 +4088,7 @@ String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_g return ""; } -Variant CollisionShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { +Variant CollisionShape3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node()); Ref<Shape3D> s = cs->get_shape(); @@ -3651,12 +4108,12 @@ Variant CollisionShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo if (Object::cast_to<CapsuleShape3D>(*s)) { Ref<CapsuleShape3D> cs2 = s; - return p_idx == 0 ? cs2->get_radius() : cs2->get_height(); + return p_id == 0 ? cs2->get_radius() : cs2->get_height(); } if (Object::cast_to<CylinderShape3D>(*s)) { Ref<CylinderShape3D> cs2 = s; - return p_idx == 0 ? cs2->get_radius() : cs2->get_height(); + return p_id == 0 ? cs2->get_radius() : cs2->get_height(); } if (Object::cast_to<RayShape3D>(*s)) { @@ -3667,7 +4124,7 @@ Variant CollisionShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo return Variant(); } -void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void CollisionShape3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const { CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node()); Ref<Shape3D> s = cs->get_shape(); @@ -3717,11 +4174,11 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i if (Object::cast_to<BoxShape3D>(*s)) { Vector3 axis; - axis[p_idx] = 1.0; + axis[p_id] = 1.0; Ref<BoxShape3D> bs = s; Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb); - float d = ra[p_idx]; + float d = ra[p_id]; if (Node3DEditor::get_singleton()->is_snap_enabled()) { d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); } @@ -3731,18 +4188,18 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i } Vector3 he = bs->get_size(); - he[p_idx] = d * 2; + he[p_id] = d * 2; bs->set_size(he); } if (Object::cast_to<CapsuleShape3D>(*s)) { Vector3 axis; - axis[p_idx == 0 ? 0 : 2] = 1.0; + axis[p_id == 0 ? 0 : 2] = 1.0; Ref<CapsuleShape3D> cs2 = s; Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb); float d = axis.dot(ra); - if (p_idx == 1) { + if (p_id == 1) { d -= cs2->get_radius(); } @@ -3754,16 +4211,16 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i d = 0.001; } - if (p_idx == 0) { + if (p_id == 0) { cs2->set_radius(d); - } else if (p_idx == 1) { + } else if (p_id == 1) { cs2->set_height(d * 2.0); } } if (Object::cast_to<CylinderShape3D>(*s)) { Vector3 axis; - axis[p_idx == 0 ? 0 : 1] = 1.0; + axis[p_id == 0 ? 0 : 1] = 1.0; Ref<CylinderShape3D> cs2 = s; Vector3 ra, rb; Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb); @@ -3776,15 +4233,15 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i d = 0.001; } - if (p_idx == 0) { + if (p_id == 0) { cs2->set_radius(d); - } else if (p_idx == 1) { + } else if (p_id == 1) { cs2->set_height(d * 2.0); } } } -void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { +void CollisionShape3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) const { CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node()); Ref<Shape3D> s = cs->get_shape(); @@ -3823,7 +4280,7 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int if (Object::cast_to<CapsuleShape3D>(*s)) { Ref<CapsuleShape3D> ss = s; if (p_cancel) { - if (p_idx == 0) { + if (p_id == 0) { ss->set_radius(p_restore); } else { ss->set_height(p_restore); @@ -3832,7 +4289,7 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int } UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); - if (p_idx == 0) { + if (p_id == 0) { ur->create_action(TTR("Change Capsule Shape Radius")); ur->add_do_method(ss.ptr(), "set_radius", ss->get_radius()); ur->add_undo_method(ss.ptr(), "set_radius", p_restore); @@ -3848,7 +4305,7 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int if (Object::cast_to<CylinderShape3D>(*s)) { Ref<CylinderShape3D> ss = s; if (p_cancel) { - if (p_idx == 0) { + if (p_id == 0) { ss->set_radius(p_restore); } else { ss->set_height(p_restore); @@ -3857,7 +4314,7 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int } UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); - if (p_idx == 0) { + if (p_id == 0) { ur->create_action(TTR("Change Cylinder Shape Radius")); ur->add_do_method(ss.ptr(), "set_radius", ss->get_radius()); ur->add_undo_method(ss.ptr(), "set_radius", p_restore); @@ -4153,7 +4610,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { if (Object::cast_to<ConcavePolygonShape3D>(*s)) { Ref<ConcavePolygonShape3D> cs2 = s; Ref<ArrayMesh> mesh = cs2->get_debug_mesh(); - p_gizmo->add_mesh(mesh, false, Ref<SkinReference>(), material); + p_gizmo->add_mesh(mesh, material); p_gizmo->add_collision_segments(cs2->get_debug_mesh_lines()); } @@ -4174,7 +4631,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Ref<HeightMapShape3D> hms = s; Ref<ArrayMesh> mesh = hms->get_debug_mesh(); - p_gizmo->add_mesh(mesh, false, Ref<SkinReference>(), material); + p_gizmo->add_mesh(mesh, material); } } @@ -4289,9 +4746,7 @@ void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Vector3 *tw = tmeshfaces.ptrw(); int tidx = 0; - for (List<Face3>::Element *E = faces.front(); E; E = E->next()) { - const Face3 &f = E->get(); - + for (const Face3 &f : faces) { for (int j = 0; j < 3; j++) { tw[tidx++] = f.vertex[j]; _EdgeKey ek; diff --git a/editor/node_3d_editor_gizmos.h b/editor/plugins/node_3d_editor_gizmos.h index 6f071859ec..61ee3a95a9 100644 --- a/editor/node_3d_editor_gizmos.h +++ b/editor/plugins/node_3d_editor_gizmos.h @@ -28,13 +28,156 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SPATIAL_EDITOR_GIZMOS_H -#define SPATIAL_EDITOR_GIZMOS_H +#ifndef NODE_3D_EDITOR_GIZMOS_H +#define NODE_3D_EDITOR_GIZMOS_H -#include "editor/plugins/node_3d_editor_plugin.h" -#include "scene/3d/camera_3d.h" +#include "core/templates/ordered_hash_map.h" +#include "scene/3d/node_3d.h" +#include "scene/3d/skeleton_3d.h" class Camera3D; +class Timer; +class EditorNode3DGizmoPlugin; + +class EditorNode3DGizmo : public Node3DGizmo { + GDCLASS(EditorNode3DGizmo, Node3DGizmo); + + struct Instance { + RID instance; + Ref<ArrayMesh> mesh; + Ref<Material> material; + Ref<SkinReference> skin_reference; + bool extra_margin = false; + Transform3D xform; + + void create_instance(Node3D *p_base, bool p_hidden = false); + }; + + bool selected; + + Vector<Vector3> collision_segments; + Ref<TriangleMesh> collision_mesh; + + Vector<Vector3> handles; + Vector<int> handle_ids; + Vector<Vector3> secondary_handles; + Vector<int> secondary_handle_ids; + + float selectable_icon_size; + bool billboard_handle; + + bool valid; + bool hidden; + Vector<Instance> instances; + Node3D *spatial_node; + + void _set_spatial_node(Node *p_node) { set_spatial_node(Object::cast_to<Node3D>(p_node)); } + +protected: + static void _bind_methods(); + + EditorNode3DGizmoPlugin *gizmo_plugin; + +public: + void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); + void add_vertices(const Vector<Vector3> &p_vertices, const Ref<Material> &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); + void add_mesh(const Ref<ArrayMesh> &p_mesh, const Ref<Material> &p_material = Ref<Material>(), const Transform3D &p_xform = Transform3D(), const Ref<SkinReference> &p_skin_reference = Ref<SkinReference>()); + void add_collision_segments(const Vector<Vector3> &p_lines); + void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh); + void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1, const Color &p_modulate = Color(1, 1, 1)); + void add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, const Vector<int> &p_ids = Vector<int>(), bool p_billboard = false, bool p_secondary = false); + void add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position = Vector3(), const Transform3D &p_xform = Transform3D()); + + virtual bool is_handle_highlighted(int p_id) const; + virtual String get_handle_name(int p_id) const; + virtual Variant get_handle_value(int p_id) const; + virtual void set_handle(int p_id, Camera3D *p_camera, const Point2 &p_point) const; + virtual void commit_handle(int p_id, const Variant &p_restore, bool p_cancel = false) const; + + virtual int subgizmos_intersect_ray(Camera3D *p_camera, const Vector2 &p_point) const; + virtual Vector<int> subgizmos_intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum) const; + virtual Transform3D get_subgizmo_transform(int p_id) const; + virtual void set_subgizmo_transform(int p_id, Transform3D p_transform) const; + virtual void commit_subgizmos(const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel = false) const; + + void set_selected(bool p_selected) { selected = p_selected; } + bool is_selected() const { return selected; } + + void set_spatial_node(Node3D *p_node); + Node3D *get_spatial_node() const { return spatial_node; } + Ref<EditorNode3DGizmoPlugin> get_plugin() const { return gizmo_plugin; } + bool intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum); + void handles_intersect_ray(Camera3D *p_camera, const Vector2 &p_point, bool p_shift_pressed, int &r_id); + bool intersect_ray(Camera3D *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal); + bool is_subgizmo_selected(int p_id) const; + Vector<int> get_subgizmo_selection() const; + + virtual void clear() override; + virtual void create() override; + virtual void transform() override; + virtual void redraw() override; + virtual void free() override; + + virtual bool is_editable() const; + + void set_hidden(bool p_hidden); + void set_plugin(EditorNode3DGizmoPlugin *p_plugin); + + EditorNode3DGizmo(); + ~EditorNode3DGizmo(); +}; + +class EditorNode3DGizmoPlugin : public Resource { + GDCLASS(EditorNode3DGizmoPlugin, Resource); + +public: + static const int VISIBLE = 0; + static const int HIDDEN = 1; + static const int ON_TOP = 2; + +protected: + int current_state; + List<EditorNode3DGizmo *> current_gizmos; + HashMap<String, Vector<Ref<StandardMaterial3D>>> materials; + + static void _bind_methods(); + virtual bool has_gizmo(Node3D *p_spatial); + virtual Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial); + +public: + void create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false); + void create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1)); + void create_handle_material(const String &p_name, bool p_billboard = false, const Ref<Texture2D> &p_texture = nullptr); + void add_material(const String &p_name, Ref<StandardMaterial3D> p_material); + + Ref<StandardMaterial3D> get_material(const String &p_name, const Ref<EditorNode3DGizmo> &p_gizmo = Ref<EditorNode3DGizmo>()); + + virtual String get_gizmo_name() const; + virtual int get_priority() const; + virtual bool can_be_hidden() const; + virtual bool is_selectable_when_hidden() const; + + virtual void redraw(EditorNode3DGizmo *p_gizmo); + virtual bool is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id) const; + virtual String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const; + virtual Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const; + virtual void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const; + virtual void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const; + + virtual int subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const; + virtual Vector<int> subgizmos_intersect_frustum(const EditorNode3DGizmo *p_gizmo, const Camera3D *p_camera, const Vector<Plane> &p_frustum) const; + virtual Transform3D get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const; + virtual void set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform) const; + virtual void commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel = false) const; + + Ref<EditorNode3DGizmo> get_gizmo(Node3D *p_spatial); + void set_state(int p_state); + int get_state() const; + void unregister_gizmo(EditorNode3DGizmo *p_gizmo); + + EditorNode3DGizmoPlugin(); + virtual ~EditorNode3DGizmoPlugin(); +}; class Light3DGizmoPlugin : public EditorNode3DGizmoPlugin { GDCLASS(Light3DGizmoPlugin, EditorNode3DGizmoPlugin); @@ -44,10 +187,10 @@ public: String get_gizmo_name() const override; int get_priority() const override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; void redraw(EditorNode3DGizmo *p_gizmo) override; Light3DGizmoPlugin(); @@ -61,10 +204,10 @@ public: String get_gizmo_name() const override; int get_priority() const override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; void redraw(EditorNode3DGizmo *p_gizmo) override; AudioStreamPlayer3DGizmoPlugin(); @@ -78,10 +221,10 @@ public: String get_gizmo_name() const override; int get_priority() const override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; void redraw(EditorNode3DGizmo *p_gizmo) override; Camera3DGizmoPlugin(); @@ -210,10 +353,10 @@ public: bool is_selectable_when_hidden() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) override; - bool is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int idx) const override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; + bool is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id) const override; SoftBody3DGizmoPlugin(); }; @@ -227,10 +370,10 @@ public: int get_priority() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; VisibleOnScreenNotifier3DGizmoPlugin(); }; @@ -257,10 +400,10 @@ public: bool is_selectable_when_hidden() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; GPUParticles3DGizmoPlugin(); }; @@ -274,10 +417,10 @@ public: int get_priority() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; GPUParticlesCollision3DGizmoPlugin(); }; @@ -291,10 +434,10 @@ public: int get_priority() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; ReflectionProbeGizmoPlugin(); }; @@ -308,10 +451,10 @@ public: int get_priority() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; DecalGizmoPlugin(); }; @@ -325,10 +468,10 @@ public: int get_priority() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; VoxelGIGizmoPlugin(); }; @@ -342,10 +485,10 @@ public: int get_priority() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; LightmapGIGizmoPlugin(); }; @@ -359,10 +502,10 @@ public: int get_priority() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; LightmapProbeGizmoPlugin(); }; @@ -388,10 +531,10 @@ public: int get_priority() const override; void redraw(EditorNode3DGizmo *p_gizmo) override; - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + Variant get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const override; + void set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) const override; CollisionShape3DGizmoPlugin(); }; @@ -489,4 +632,4 @@ public: Joint3DGizmoPlugin(); }; -#endif // SPATIAL_EDITOR_GIZMOS_H +#endif // NODE_3D_EDITOR_GIZMOS_H diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index c341783d54..af04c9566a 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -35,20 +35,20 @@ #include "core/math/camera_matrix.h" #include "core/math/math_funcs.h" #include "core/os/keyboard.h" -#include "core/string/print_string.h" #include "core/templates/sort_array.h" #include "editor/debugger/editor_debugger_node.h" #include "editor/editor_node.h" -#include "editor/editor_scale.h" #include "editor/editor_settings.h" -#include "editor/node_3d_editor_gizmos.h" #include "editor/plugins/animation_player_editor_plugin.h" +#include "editor/plugins/node_3d_editor_gizmos.h" #include "editor/plugins/script_editor_plugin.h" #include "scene/3d/camera_3d.h" #include "scene/3d/collision_shape_3d.h" +#include "scene/3d/light_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/physics_body_3d.h" #include "scene/3d/visual_instance_3d.h" +#include "scene/3d/world_environment.h" #include "scene/gui/center_container.h" #include "scene/gui/subviewport_container.h" #include "scene/resources/packed_scene.h" @@ -58,7 +58,6 @@ #define GIZMO_ARROW_SIZE 0.35 #define GIZMO_RING_HALF_WIDTH 0.1 -#define GIZMO_SCALE_DEFAULT 0.15 #define GIZMO_PLANE_SIZE 0.2 #define GIZMO_PLANE_DST 0.3 #define GIZMO_CIRCLE_SIZE 1.1 @@ -436,16 +435,29 @@ Vector3 Node3DEditorViewport::_get_ray(const Vector2 &p_pos) const { } void Node3DEditorViewport::_clear_selected() { - editor_selection->clear(); -} - -void Node3DEditorViewport::_select_clicked(bool p_append, bool p_single, bool p_allow_locked) { - if (clicked.is_null()) { - return; + _edit.gizmo = Ref<EditorNode3DGizmo>(); + _edit.gizmo_handle = -1; + _edit.gizmo_initial_value = Variant(); + + Node3D *selected = spatial_editor->get_single_selected_node(); + Node3DEditorSelectedItem *se = selected ? editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected) : nullptr; + + if (se && se->gizmo.is_valid()) { + se->subgizmos.clear(); + se->gizmo->redraw(); + se->gizmo.unref(); + spatial_editor->update_transform_gizmo(); + } else { + editor_selection->clear(); + Node3DEditor::get_singleton()->edit(nullptr); } +} - Node *node = Object::cast_to<Node>(ObjectDB::get_instance(clicked)); +void Node3DEditorViewport::_select_clicked(bool p_allow_locked) { + Node *node = Object::cast_to<Node3D>(ObjectDB::get_instance(clicked)); Node3D *selected = Object::cast_to<Node3D>(node); + clicked = ObjectID(); + if (!selected) { return; } @@ -462,43 +474,27 @@ void Node3DEditorViewport::_select_clicked(bool p_append, bool p_single, bool p_ } if (p_allow_locked || !_is_node_locked(selected)) { - _select(selected, clicked_wants_append, true); - } -} - -void Node3DEditorViewport::_select(Node *p_node, bool p_append, bool p_single) { - // Add or remove a single node from the selection - if (p_append && p_single) { - if (editor_selection->is_selected(p_node)) { - // Already in the selection, remove it from the selected nodes - editor_selection->remove_node(p_node); + if (clicked_wants_append) { + if (editor_selection->is_selected(selected)) { + editor_selection->remove_node(selected); + } else { + editor_selection->add_node(selected); + } } else { - // Add the item to the selection - editor_selection->add_node(p_node); - } - } else if (p_append && !p_single) { - // Add the item to the selection - editor_selection->add_node(p_node); - } else { - // No append; single select - editor_selection->clear(); - editor_selection->add_node(p_node); - // Reselect - if (Engine::get_singleton()->is_editor_hint()) { - editor->call("edit_node", p_node); + if (!editor_selection->is_selected(selected)) { + editor_selection->clear(); + editor_selection->add_node(selected); + editor->edit_node(selected); + } } - } - if (editor_selection->get_selected_node_list().size() == 1) { - editor->push_item(editor_selection->get_selected_node_list()[0]); + if (editor_selection->get_selected_node_list().size() == 1) { + editor->edit_node(editor_selection->get_selected_node_list()[0]); + } } } -ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle, bool p_alt_select) { - if (r_gizmo_handle) { - *r_gizmo_handle = -1; - } - +ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos) { Vector3 ray = _get_ray(p_pos); Vector3 pos = _get_ray_pos(p_pos); Vector2 shrinked_pos = p_pos / subviewport_container->get_stretch_shrink(); @@ -514,7 +510,6 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b ObjectID closest; Node *item = nullptr; float closest_dist = 1e20; - int selected_handle = -1; for (int i = 0; i < instances.size(); i++) { Node3D *spat = Object::cast_to<Node3D>(ObjectDB::get_instance(instances[i])); @@ -523,38 +518,40 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b continue; } - Ref<EditorNode3DGizmo> seg = spat->get_gizmo(); + Vector<Ref<Node3DGizmo>> gizmos = spat->get_gizmos(); - if ((!seg.is_valid()) || found_gizmos.has(seg)) { - continue; - } + for (int j = 0; j < gizmos.size(); j++) { + Ref<EditorNode3DGizmo> seg = gizmos[j]; - found_gizmos.insert(seg); - Vector3 point; - Vector3 normal; + if ((!seg.is_valid()) || found_gizmos.has(seg)) { + continue; + } - int handle = -1; - bool inters = seg->intersect_ray(camera, shrinked_pos, point, normal, &handle, p_alt_select); + found_gizmos.insert(seg); + Vector3 point; + Vector3 normal; - if (!inters) { - continue; - } + bool inters = seg->intersect_ray(camera, shrinked_pos, point, normal); - float dist = pos.distance_to(point); + if (!inters) { + continue; + } - if (dist < 0) { - continue; - } + float dist = pos.distance_to(point); - if (dist < closest_dist) { - item = Object::cast_to<Node>(spat); - if (item != edited_scene) { - item = edited_scene->get_deepest_editable_node(item); + if (dist < 0) { + continue; } - closest = item->get_instance_id(); - closest_dist = dist; - selected_handle = handle; + if (dist < closest_dist) { + item = Object::cast_to<Node>(spat); + if (item != edited_scene) { + item = edited_scene->get_deepest_editable_node(item); + } + + closest = item->get_instance_id(); + closest_dist = dist; + } } } @@ -562,23 +559,15 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b return ObjectID(); } - if (!editor_selection->is_selected(item) || (r_gizmo_handle && selected_handle >= 0)) { - if (r_gizmo_handle) { - *r_gizmo_handle = selected_handle; - } - } - return closest; } -void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select, bool p_include_locked_nodes) { +void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, Vector<_RayResult> &r_results, bool p_include_locked_nodes) { Vector3 ray = _get_ray(p_pos); Vector3 pos = _get_ray_pos(p_pos); Vector<ObjectID> instances = RenderingServer::get_singleton()->instances_cull_ray(pos, ray, get_tree()->get_root()->get_world_3d()->get_scenario()); - Set<Ref<EditorNode3DGizmo>> found_gizmos; - - r_includes_current = false; + Set<Node3D *> found_nodes; for (int i = 0; i < instances.size(); i++) { Node3D *spat = Object::cast_to<Node3D>(ObjectDB::get_instance(instances[i])); @@ -587,53 +576,48 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu continue; } - Ref<EditorNode3DGizmo> seg = spat->get_gizmo(); - - if (!seg.is_valid()) { + if (found_nodes.has(spat)) { continue; } - if (found_gizmos.has(seg)) { + if (!p_include_locked_nodes && _is_node_locked(spat)) { continue; } - found_gizmos.insert(seg); - Vector3 point; - Vector3 normal; + Vector<Ref<Node3DGizmo>> gizmos = spat->get_gizmos(); + for (int j = 0; j < gizmos.size(); j++) { + Ref<EditorNode3DGizmo> seg = gizmos[j]; - int handle = -1; - bool inters = seg->intersect_ray(camera, p_pos, point, normal, nullptr, p_alt_select); + if (!seg.is_valid()) { + continue; + } - if (!inters) { - continue; - } + Vector3 point; + Vector3 normal; - float dist = pos.distance_to(point); + bool inters = seg->intersect_ray(camera, p_pos, point, normal); - if (dist < 0) { - continue; - } + if (!inters) { + continue; + } - if (!p_include_locked_nodes && _is_node_locked(spat)) { - continue; - } + float dist = pos.distance_to(point); - if (editor_selection->is_selected(spat)) { - r_includes_current = true; - } + if (dist < 0) { + continue; + } - _RayResult res; - res.item = spat; - res.depth = dist; - res.handle = handle; - results.push_back(res); - } + found_nodes.insert(spat); - if (results.is_empty()) { - return; + _RayResult res; + res.item = spat; + res.depth = dist; + r_results.push_back(res); + break; + } } - results.sort(); + r_results.sort(); } Vector3 Node3DEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) { @@ -656,6 +640,9 @@ Vector3 Node3DEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) { void Node3DEditorViewport::_select_region() { if (cursor.region_begin == cursor.region_end) { + if (!clicked_wants_append) { + _clear_selected(); + } return; //nothing really } @@ -702,7 +689,66 @@ void Node3DEditorViewport::_select_region() { far.d += get_zfar(); frustum.push_back(far); + if (spatial_editor->get_single_selected_node()) { + Node3D *single_selected = spatial_editor->get_single_selected_node(); + Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(single_selected); + + Ref<EditorNode3DGizmo> old_gizmo; + if (!clicked_wants_append) { + se->subgizmos.clear(); + old_gizmo = se->gizmo; + se->gizmo.unref(); + } + + bool found_subgizmos = false; + Vector<Ref<Node3DGizmo>> gizmos = single_selected->get_gizmos(); + for (int j = 0; j < gizmos.size(); j++) { + Ref<EditorNode3DGizmo> seg = gizmos[j]; + if (!seg.is_valid()) { + continue; + } + + if (se->gizmo.is_valid() && se->gizmo != seg) { + continue; + } + + Vector<int> subgizmos = seg->subgizmos_intersect_frustum(camera, frustum); + if (!subgizmos.is_empty()) { + se->gizmo = seg; + for (int i = 0; i < subgizmos.size(); i++) { + int subgizmo_id = subgizmos[i]; + if (!se->subgizmos.has(subgizmo_id)) { + se->subgizmos.insert(subgizmo_id, se->gizmo->get_subgizmo_transform(subgizmo_id)); + } + } + found_subgizmos = true; + break; + } + } + + if (!clicked_wants_append || found_subgizmos) { + if (se->gizmo.is_valid()) { + se->gizmo->redraw(); + } + + if (old_gizmo != se->gizmo && old_gizmo.is_valid()) { + old_gizmo->redraw(); + } + + spatial_editor->update_transform_gizmo(); + } + + if (found_subgizmos) { + return; + } + } + + if (!clicked_wants_append) { + _clear_selected(); + } + Vector<ObjectID> instances = RenderingServer::get_singleton()->instances_cull_convex(frustum, get_tree()->get_root()->get_world_3d()->get_scenario()); + Set<Node3D *> found_nodes; Vector<Node *> selected; Node *edited_scene = get_tree()->get_edited_scene_root(); @@ -713,6 +759,12 @@ void Node3DEditorViewport::_select_region() { continue; } + if (found_nodes.has(sp)) { + continue; + } + + found_nodes.insert(sp); + Node *item = Object::cast_to<Node>(sp); if (item != edited_scene) { item = edited_scene->get_deepest_editable_node(item); @@ -731,28 +783,31 @@ void Node3DEditorViewport::_select_region() { item = sel; } - if (selected.find(item) != -1) { - continue; - } - if (_is_node_locked(item)) { continue; } - Ref<EditorNode3DGizmo> seg = sp->get_gizmo(); + Vector<Ref<Node3DGizmo>> gizmos = sp->get_gizmos(); + for (int j = 0; j < gizmos.size(); j++) { + Ref<EditorNode3DGizmo> seg = gizmos[j]; + if (!seg.is_valid()) { + continue; + } - if (!seg.is_valid()) { - continue; + if (seg->intersect_frustum(camera, frustum)) { + selected.push_back(item); + } } + } - if (seg->intersect_frustum(camera, frustum)) { - selected.push_back(item); + for (int i = 0; i < selected.size(); i++) { + if (!editor_selection->is_selected(selected[i])) { + editor_selection->add_node(selected[i]); } } - bool single = selected.size() == 1; - for (int i = 0; i < selected.size(); i++) { - _select(selected[i], true, single); + if (editor_selection->get_selected_node_list().size() == 1) { + editor->edit_node(editor_selection->get_selected_node_list()[0]); } } @@ -779,21 +834,34 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) { spatial_editor->update_transform_gizmo(); _edit.center = spatial_editor->get_gizmo_transform().origin; - List<Node *> &selection = editor_selection->get_selected_node_list(); + Node3D *selected = spatial_editor->get_single_selected_node(); + Node3DEditorSelectedItem *se = selected ? editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected) : nullptr; - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) { - continue; + if (se && se->gizmo.is_valid()) { + for (Map<int, Transform3D>::Element *E = se->subgizmos.front(); E; E = E->next()) { + int subgizmo_id = E->key(); + se->subgizmos[subgizmo_id] = se->gizmo->get_subgizmo_transform(subgizmo_id); } + se->original_local = selected->get_transform(); + se->original = selected->get_global_transform(); + } else { + List<Node *> &selection = editor_selection->get_selected_node_list(); - Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) { - continue; - } + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { + Node3D *sp = Object::cast_to<Node3D>(E->get()); + if (!sp) { + continue; + } + + Node3DEditorSelectedItem *sel_item = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); + + if (!sel_item) { + continue; + } - se->original = se->sp->get_global_gizmo_transform(); - se->original_local = se->sp->get_local_gizmo_transform(); + sel_item->original_local = sel_item->sp->get_local_gizmo_transform(); + sel_item->original = sel_item->sp->get_global_gizmo_transform(); + } } } @@ -829,7 +897,7 @@ static int _get_key_modifier(Ref<InputEventWithModifiers> e) { return 0; } -bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only) { +bool Node3DEditorViewport::_transform_gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only) { if (!spatial_editor->is_gizmo_visible()) { return false; } @@ -874,14 +942,18 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized(); Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized(); - Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST); + // Allow some tolerance to make the plane easier to click, + // even if the click is actually slightly outside the plane. + const Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST * 0.6667); Vector3 r; Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); if (plane.intersects_ray(ray_pos, ray, &r)) { float dist = r.distance_to(grabber_pos); - if (dist < (gs * GIZMO_PLANE_SIZE)) { + // Allow some tolerance to make the plane easier to click, + // even if the click is actually slightly outside the plane. + if (dist < (gs * GIZMO_PLANE_SIZE * 1.5)) { float d = ray_pos.distance_to(r); if (d < col_d) { col_d = d; @@ -974,14 +1046,18 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized(); Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized(); - Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST); + // Allow some tolerance to make the plane easier to click, + // even if the click is actually slightly outside the plane. + Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST * 0.6667); Vector3 r; Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); if (plane.intersects_ray(ray_pos, ray, &r)) { float dist = r.distance_to(grabber_pos); - if (dist < (gs * GIZMO_PLANE_SIZE)) { + // Allow some tolerance to make the plane easier to click, + // even if the click is actually slightly outside the plane. + if (dist < (gs * GIZMO_PLANE_SIZE * 1.5)) { float d = ray_pos.distance_to(r); if (d < col_d) { col_d = d; @@ -1015,6 +1091,88 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high return false; } +void Node3DEditorViewport::_transform_gizmo_apply(Node3D *p_node, const Transform3D &p_transform, bool p_local) { + if (p_transform.basis.determinant() == 0) { + return; + } + + if (p_local) { + p_node->set_transform(p_transform); + } else { + p_node->set_global_transform(p_transform); + } +} + +Transform3D Node3DEditorViewport::_compute_transform(TransformMode p_mode, const Transform3D &p_original, const Transform3D &p_original_local, Vector3 p_motion, double p_extra, bool p_local) { + switch (p_mode) { + case TRANSFORM_SCALE: { + if (p_local) { + Basis g = p_original.basis.orthonormalized(); + Vector3 local_motion = g.inverse().xform(p_motion); + + if (_edit.snap || spatial_editor->is_snap_enabled()) { + local_motion.snap(Vector3(p_extra, p_extra, p_extra)); + } + + Vector3 local_scale = p_original_local.basis.get_scale() * (local_motion + Vector3(1, 1, 1)); + Transform3D local_t = p_original_local; + local_t.basis.set_euler_scale(p_original_local.basis.get_rotation_euler(), local_scale); + return local_t; + } else { + Transform3D base = Transform3D(Basis(), _edit.center); + if (_edit.snap || spatial_editor->is_snap_enabled()) { + p_motion.snap(Vector3(p_extra, p_extra, p_extra)); + } + + Transform3D r; + r.basis.scale(p_motion + Vector3(1, 1, 1)); + return base * (r * (base.inverse() * p_original)); + } + } + case TRANSFORM_TRANSLATE: { + if (p_local) { + if (_edit.snap || spatial_editor->is_snap_enabled()) { + Basis g = p_original.basis.orthonormalized(); + Vector3 local_motion = g.inverse().xform(p_motion); + local_motion.snap(Vector3(p_extra, p_extra, p_extra)); + + p_motion = g.xform(local_motion); + } + + } else { + if (_edit.snap || spatial_editor->is_snap_enabled()) { + p_motion.snap(Vector3(p_extra, p_extra, p_extra)); + } + } + + // Apply translation + Transform3D t = p_original; + t.origin += p_motion; + return t; + } + case TRANSFORM_ROTATE: { + if (p_local) { + Basis rot = Basis(p_motion, p_extra); + + Vector3 scale = p_original_local.basis.get_scale(); + Vector3 euler = (p_original_local.get_basis().orthonormalized() * rot).get_euler(); + Transform3D t; + t.basis.set_euler_scale(euler, scale); + t.origin = p_original_local.origin; + return t; + } else { + Transform3D r; + r.basis.rotate(p_motion, p_extra); + Transform3D base = Transform3D(Basis(), _edit.center); + return base * r * base.inverse() * p_original; + } + } + default: { + ERR_FAIL_V_MSG(Transform3D(), "Invalid mode in '_compute_transform'"); + } + } +} + void Node3DEditorViewport::_surface_mouse_enter() { if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) { surface->grab_focus(); @@ -1038,7 +1196,7 @@ bool Node3DEditorViewport ::_is_node_locked(const Node *p_node) { } void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) { - _find_items_at_pos(b->get_position(), clicked_includes_current, selection_results, b->is_shift_pressed(), spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT); + _find_items_at_pos(b->get_position(), selection_results, spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT); Node *scene = editor->get_edited_scene(); @@ -1058,10 +1216,8 @@ void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) { selection_results.clear(); if (clicked.is_valid()) { - _select_clicked(clicked_wants_append, true, spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT); - clicked = ObjectID(); + _select_clicked(spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT); } - } else if (!selection_results.is_empty()) { NodePath root_path = get_tree()->get_edited_scene_root()->get_path(); StringName root_name = root_path.get_name(root_path.get_name_count() - 1); @@ -1179,8 +1335,8 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { List<Node *> &selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E); if (!sp) { continue; } @@ -1190,7 +1346,20 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { continue; } - sp->set_global_transform(se->original); + if (se->gizmo.is_valid()) { + Vector<int> ids; + Vector<Transform3D> restore; + + for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) { + ids.push_back(GE->key()); + restore.push_back(GE->value()); + } + + se->gizmo->commit_subgizmos(ids, restore, true); + spatial_editor->update_transform_gizmo(); + } else { + sp->set_global_transform(se->original); + } } surface->update(); set_message(TTR("Transform Aborted."), 3); @@ -1262,37 +1431,92 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { _edit.snap = spatial_editor->is_snap_enabled(); _edit.mode = TRANSFORM_NONE; - //gizmo has priority over everything - - bool can_select_gizmos = true; + bool can_select_gizmos = spatial_editor->get_single_selected_node(); { int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); - can_select_gizmos = view_menu->get_popup()->is_item_checked(idx); + can_select_gizmos = can_select_gizmos && view_menu->get_popup()->is_item_checked(idx); } - if (can_select_gizmos && spatial_editor->get_selected()) { - Ref<EditorNode3DGizmo> seg = spatial_editor->get_selected()->get_gizmo(); - if (seg.is_valid()) { - int handle = -1; - Vector3 point; - Vector3 normal; - bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, b->is_shift_pressed()); - if (inters && handle != -1) { + // Gizmo handles + if (can_select_gizmos) { + Vector<Ref<Node3DGizmo>> gizmos = spatial_editor->get_single_selected_node()->get_gizmos(); + + bool intersected_handle = false; + for (int i = 0; i < gizmos.size(); i++) { + Ref<EditorNode3DGizmo> seg = gizmos[i]; + + if ((!seg.is_valid())) { + continue; + } + + int gizmo_handle = -1; + seg->handles_intersect_ray(camera, _edit.mouse_pos, b->is_shift_pressed(), gizmo_handle); + if (gizmo_handle != -1) { _edit.gizmo = seg; - _edit.gizmo_handle = handle; - _edit.gizmo_initial_value = seg->get_handle_value(handle); + _edit.gizmo_handle = gizmo_handle; + _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle); + intersected_handle = true; break; } } + + if (intersected_handle) { + break; + } } - if (_gizmo_select(_edit.mouse_pos)) { + // Transform gizmo + if (_transform_gizmo_select(_edit.mouse_pos)) { break; } + // Subgizmos + if (can_select_gizmos) { + Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(spatial_editor->get_single_selected_node()); + Vector<Ref<Node3DGizmo>> gizmos = spatial_editor->get_single_selected_node()->get_gizmos(); + + bool intersected_subgizmo = false; + for (int i = 0; i < gizmos.size(); i++) { + Ref<EditorNode3DGizmo> seg = gizmos[i]; + + if ((!seg.is_valid())) { + continue; + } + + int subgizmo_id = seg->subgizmos_intersect_ray(camera, _edit.mouse_pos); + if (subgizmo_id != -1) { + ERR_CONTINUE(!se); + if (b->is_shift_pressed()) { + if (se->subgizmos.has(subgizmo_id)) { + se->subgizmos.erase(subgizmo_id); + } else { + se->subgizmos.insert(subgizmo_id, seg->get_subgizmo_transform(subgizmo_id)); + } + } else { + se->subgizmos.clear(); + se->subgizmos.insert(subgizmo_id, seg->get_subgizmo_transform(subgizmo_id)); + } + + if (se->subgizmos.is_empty()) { + se->gizmo = Ref<EditorNode3DGizmo>(); + } else { + se->gizmo = seg; + } + + seg->redraw(); + spatial_editor->update_transform_gizmo(); + intersected_subgizmo = true; + break; + } + } + + if (intersected_subgizmo) { + break; + } + } + clicked = ObjectID(); - clicked_includes_current = false; if ((spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT && b->is_command_pressed()) || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_ROTATE) { /* HANDLE ROTATION */ @@ -1325,40 +1549,19 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; } - // todo scale - - int gizmo_handle = -1; - - clicked = _select_ray(b->get_position(), b->is_shift_pressed(), clicked_includes_current, &gizmo_handle, b->is_shift_pressed()); + clicked = _select_ray(b->get_position()); //clicking is always deferred to either move or release clicked_wants_append = b->is_shift_pressed(); if (clicked.is_null()) { - if (!clicked_wants_append) { - _clear_selected(); - } - //default to regionselect cursor.region_select = true; cursor.region_begin = b->get_position(); cursor.region_end = b->get_position(); } - if (clicked.is_valid() && gizmo_handle >= 0) { - Node3D *spa = Object::cast_to<Node3D>(ObjectDB::get_instance(clicked)); - if (spa) { - Ref<EditorNode3DGizmo> seg = spa->get_gizmo(); - if (seg.is_valid()) { - _edit.gizmo = seg; - _edit.gizmo_handle = gizmo_handle; - _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle); - break; - } - } - } - surface->update(); } else { if (_edit.gizmo.is_valid()) { @@ -1366,47 +1569,63 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { _edit.gizmo = Ref<EditorNode3DGizmo>(); break; } + if (clicked.is_valid()) { - _select_clicked(clicked_wants_append, true); - // Processing was deferred. - clicked = ObjectID(); + _select_clicked(false); } if (cursor.region_select) { - if (!clicked_wants_append) { - _clear_selected(); - } - _select_region(); cursor.region_select = false; surface->update(); } if (_edit.mode != TRANSFORM_NONE) { - static const char *_transform_name[4] = { "None", "Rotate", "Translate", "Scale" }; - undo_redo->create_action(_transform_name[_edit.mode]); + Node3D *selected = spatial_editor->get_single_selected_node(); + Node3DEditorSelectedItem *se = selected ? editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected) : nullptr; - List<Node *> &selection = editor_selection->get_selected_node_list(); + if (se && se->gizmo.is_valid()) { + Vector<int> ids; + Vector<Transform3D> restore; - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) { - continue; + for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) { + ids.push_back(GE->key()); + restore.push_back(GE->value()); } - Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) { - continue; - } + se->gizmo->commit_subgizmos(ids, restore, false); + spatial_editor->update_transform_gizmo(); + } else { + static const char *_transform_name[4] = { + TTRC("None"), + TTRC("Rotate"), + // TRANSLATORS: This refers to the movement that changes the position of an object. + TTRC("Translate"), + TTRC("Scale"), + }; + undo_redo->create_action(TTRGET(_transform_name[_edit.mode])); + + List<Node *> &selection = editor_selection->get_selected_node_list(); + + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { + Node3D *sp = Object::cast_to<Node3D>(E->get()); + if (!sp) { + continue; + } - undo_redo->add_do_method(sp, "set_global_transform", sp->get_global_gizmo_transform()); - undo_redo->add_undo_method(sp, "set_global_transform", se->original); + Node3DEditorSelectedItem *sel_item = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); + if (!sel_item) { + continue; + } + + undo_redo->add_do_method(sp, "set_global_transform", sp->get_global_gizmo_transform()); + undo_redo->add_undo_method(sp, "set_global_transform", sel_item->original); + } + undo_redo->commit_action(); } - undo_redo->commit_action(); _edit.mode = TRANSFORM_NONE; set_message(""); } - surface->update(); } @@ -1421,31 +1640,39 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (m.is_valid()) { _edit.mouse_pos = m->get_position(); - if (spatial_editor->get_selected()) { - Ref<EditorNode3DGizmo> seg = spatial_editor->get_selected()->get_gizmo(); - if (seg.is_valid()) { - int selected_handle = -1; - - int handle = -1; - Vector3 point; - Vector3 normal; - bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, false); - if (inters && handle != -1) { - selected_handle = handle; + if (spatial_editor->get_single_selected_node()) { + Vector<Ref<Node3DGizmo>> gizmos = spatial_editor->get_single_selected_node()->get_gizmos(); + + Ref<EditorNode3DGizmo> found_gizmo; + int found_handle = -1; + + for (int i = 0; i < gizmos.size(); i++) { + Ref<EditorNode3DGizmo> seg = gizmos[i]; + if (!seg.is_valid()) { + continue; } - if (selected_handle != spatial_editor->get_over_gizmo_handle()) { - spatial_editor->set_over_gizmo_handle(selected_handle); - spatial_editor->get_selected()->update_gizmo(); - if (selected_handle != -1) { - spatial_editor->select_gizmo_highlight_axis(-1); - } + seg->handles_intersect_ray(camera, _edit.mouse_pos, false, found_handle); + + if (found_handle != -1) { + found_gizmo = seg; + break; } } + + if (found_gizmo.is_valid()) { + spatial_editor->select_gizmo_highlight_axis(-1); + } + + if (found_gizmo != spatial_editor->get_current_hover_gizmo() || found_handle != spatial_editor->get_current_hover_gizmo_handle()) { + spatial_editor->set_current_hover_gizmo(found_gizmo); + spatial_editor->set_current_hover_gizmo_handle(found_handle); + spatial_editor->get_single_selected_node()->update_gizmos(); + } } - if (spatial_editor->get_over_gizmo_handle() == -1 && !(m->get_button_mask() & 1) && !_edit.gizmo.is_valid()) { - _gizmo_select(_edit.mouse_pos, true); + if (spatial_editor->get_current_hover_gizmo().is_null() && !(m->get_button_mask() & 1) && !_edit.gizmo.is_valid()) { + _transform_gizmo_select(_edit.mouse_pos, true); } NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int(); @@ -1469,11 +1696,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } else { const bool movement_threshold_passed = _edit.original_mouse_pos.distance_to(_edit.mouse_pos) > 8 * EDSCALE; if (clicked.is_valid() && movement_threshold_passed) { - if (!clicked_includes_current) { - _select_clicked(clicked_wants_append, true); - // Processing was deferred. - } - _compute_edit(_edit.mouse_pos); clicked = ObjectID(); @@ -1568,8 +1790,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { motion = Vector3(scale, scale, scale); } - List<Node *> &selection = editor_selection->get_selected_node_list(); - // Disable local transformation for TRANSFORM_VIEW bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); @@ -1582,8 +1802,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { set_message(TTR("Scaling: ") + "(" + String::num(motion_snapped.x, snap_step_decimals) + ", " + String::num(motion_snapped.y, snap_step_decimals) + ", " + String::num(motion_snapped.z, snap_step_decimals) + ")"); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); + List<Node *> &selection = editor_selection->get_selected_node_list(); + for (Node *E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E); if (!sp) { continue; } @@ -1597,44 +1818,22 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { continue; } - Transform3D original = se->original; - Transform3D original_local = se->original_local; - Transform3D base = Transform3D(Basis(), _edit.center); - Transform3D t; - Vector3 local_scale; - - if (local_coords) { - Basis g = original.basis.orthonormalized(); - Vector3 local_motion = g.inverse().xform(motion); - - if (_edit.snap || spatial_editor->is_snap_enabled()) { - local_motion.snap(Vector3(snap, snap, snap)); + if (se->gizmo.is_valid()) { + for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) { + Transform3D xform = GE->get(); + Transform3D new_xform = _compute_transform(TRANSFORM_SCALE, se->original * xform, xform, motion, snap, local_coords); + if (!local_coords) { + new_xform = se->original.affine_inverse() * new_xform; + } + se->gizmo->set_subgizmo_transform(GE->key(), new_xform); } - - local_scale = original_local.basis.get_scale() * (local_motion + Vector3(1, 1, 1)); - - // Prevent scaling to 0 it would break the gizmo - Basis check = original_local.basis; - check.scale(local_scale); - if (check.determinant() != 0) { - // Apply scale - sp->set_scale(local_scale); - } - } else { - if (_edit.snap || spatial_editor->is_snap_enabled()) { - motion.snap(Vector3(snap, snap, snap)); - } - - Transform3D r; - r.basis.scale(motion + Vector3(1, 1, 1)); - t = base * (r * (base.inverse() * original)); - - // Apply scale - sp->set_global_transform(t); + Transform3D new_xform = _compute_transform(TRANSFORM_SCALE, se->original, se->original_local, motion, snap, local_coords); + _transform_gizmo_apply(se->sp, new_xform, local_coords); } } + spatial_editor->update_transform_gizmo(); surface->update(); } break; @@ -1691,8 +1890,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { } } - List<Node *> &selection = editor_selection->get_selected_node_list(); - // Disable local transformation for TRANSFORM_VIEW bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); @@ -1704,8 +1901,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { set_message(TTR("Translating: ") + "(" + String::num(motion_snapped.x, snap_step_decimals) + ", " + String::num(motion_snapped.y, snap_step_decimals) + ", " + String::num(motion_snapped.z, snap_step_decimals) + ")"); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); + List<Node *> &selection = editor_selection->get_selected_node_list(); + for (Node *E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E); if (!sp) { continue; } @@ -1719,30 +1917,20 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { continue; } - Transform3D original = se->original; - Transform3D t; - - if (local_coords) { - if (_edit.snap || spatial_editor->is_snap_enabled()) { - Basis g = original.basis.orthonormalized(); - Vector3 local_motion = g.inverse().xform(motion); - local_motion.snap(Vector3(snap, snap, snap)); - - motion = g.xform(local_motion); + if (se->gizmo.is_valid()) { + for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) { + Transform3D xform = GE->get(); + Transform3D new_xform = _compute_transform(TRANSFORM_TRANSLATE, se->original * xform, xform, motion, snap, local_coords); + new_xform = se->original.affine_inverse() * new_xform; + se->gizmo->set_subgizmo_transform(GE->key(), new_xform); } - } else { - if (_edit.snap || spatial_editor->is_snap_enabled()) { - motion.snap(Vector3(snap, snap, snap)); - } + Transform3D new_xform = _compute_transform(TRANSFORM_TRANSLATE, se->original, se->original_local, motion, snap, local_coords); + _transform_gizmo_apply(se->sp, new_xform, false); } - - // Apply translation - t = original; - t.origin += motion; - sp->set_global_transform(t); } + spatial_editor->update_transform_gizmo(); surface->update(); } break; @@ -1796,12 +1984,11 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { set_message(vformat(TTR("Rotating %s degrees."), String::num(angle, snap_step_decimals))); angle = Math::deg2rad(angle); - List<Node *> &selection = editor_selection->get_selected_node_list(); - bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); + List<Node *> &selection = editor_selection->get_selected_node_list(); + for (Node *E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E); if (!sp) { continue; } @@ -1815,32 +2002,24 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { continue; } - Transform3D t; - - if (local_coords) { - Transform3D original_local = se->original_local; - Basis rot = Basis(axis, angle); - - t.basis = original_local.get_basis().orthonormalized() * rot; - t.origin = original_local.origin; - - // Apply rotation - sp->set_transform(t); - sp->set_scale(original_local.basis.get_scale()); // re-apply original scale + Vector3 compute_axis = local_coords ? axis : plane.normal; + if (se->gizmo.is_valid()) { + for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) { + Transform3D xform = GE->get(); + Transform3D new_xform = _compute_transform(TRANSFORM_ROTATE, se->original * xform, xform, compute_axis, angle, local_coords); + if (!local_coords) { + new_xform = se->original.affine_inverse() * new_xform; + } + se->gizmo->set_subgizmo_transform(GE->key(), new_xform); + } } else { - Transform3D original = se->original; - Transform3D r; - Transform3D base = Transform3D(Basis(), _edit.center); - - r.basis.rotate(plane.normal, angle); - t = base * r * base.inverse() * original; - - // Apply rotation - sp->set_global_transform(t); + Transform3D new_xform = _compute_transform(TRANSFORM_ROTATE, se->original, se->original_local, compute_axis, angle, local_coords); + _transform_gizmo_apply(se->sp, new_xform, local_coords); } } + spatial_editor->update_transform_gizmo(); surface->update(); } break; @@ -2039,8 +2218,8 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { List<Node *> &selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E); if (!sp) { continue; } @@ -2438,7 +2617,7 @@ void Node3DEditorViewport::_notification(int p_what) { Node *scene_root = editor->get_scene_tree_dock()->get_editor_data()->get_edited_scene_root(); if (previewing_cinema && scene_root != nullptr) { - Camera3D *cam = scene_root->get_viewport()->get_camera(); + Camera3D *cam = scene_root->get_viewport()->get_camera_3d(); if (cam != nullptr && cam != previewing) { //then switch the viewport's camera to the scene's viewport camera if (previewing != nullptr) { @@ -2698,7 +2877,7 @@ void Node3DEditorViewport::_draw() { if (surface->has_focus()) { Size2 size = surface->get_size(); Rect2 r = Rect2(Point2(), size); - get_theme_stylebox(SNAME("Focus"), SNAME("EditorStyles"))->draw(surface->get_canvas_item(), r); + get_theme_stylebox(SNAME("FocusViewport"), SNAME("EditorStyles"))->draw(surface->get_canvas_item(), r); } if (cursor.region_select) { @@ -2744,9 +2923,7 @@ void Node3DEditorViewport::_draw() { handle_color = get_theme_color(SNAME("accent_color"), SNAME("Editor")); break; } - handle_color.a = 1.0; - const float brightness = 1.3; - handle_color *= Color(brightness, brightness, brightness); + handle_color = handle_color.from_hsv(handle_color.get_h(), 0.25, 1.0, 1); RenderingServer::get_singleton()->canvas_item_add_line( ci, @@ -2905,8 +3082,8 @@ void Node3DEditorViewport::_menu_option(int p_option) { undo_redo->create_action(TTR("Align Transform with View")); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E); if (!sp) { continue; } @@ -2941,8 +3118,8 @@ void Node3DEditorViewport::_menu_option(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); undo_redo->create_action(TTR("Align Rotation with View")); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E); if (!sp) { continue; } @@ -3310,8 +3487,7 @@ void Node3DEditorViewport::_selection_result_pressed(int p_result) { clicked = selection_results[p_result].item->get_instance_id(); if (clicked.is_valid()) { - _select_clicked(clicked_wants_append, true, spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT); - clicked = ObjectID(); + _select_clicked(spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT); } } @@ -3338,7 +3514,7 @@ void Node3DEditorViewport::update_transform_gizmo_view() { Transform3D camera_xform = camera->get_transform(); - if (xform.origin.distance_squared_to(camera_xform.origin) < 0.01) { + if (xform.origin.is_equal_approx(camera_xform.origin)) { for (int i = 0; i < 3; i++) { RenderingServer::get_singleton()->instance_set_visible(move_gizmo_instance[i], false); RenderingServer::get_singleton()->instance_set_visible(move_plane_gizmo_instance[i], false); @@ -3595,8 +3771,8 @@ void Node3DEditorViewport::focus_selection() { List<Node *> &selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E); if (!sp) { continue; } @@ -3606,6 +3782,13 @@ void Node3DEditorViewport::focus_selection() { continue; } + if (se->gizmo.is_valid()) { + for (Map<int, Transform3D>::Element *GE = se->subgizmos.front(); GE; GE = GE->next()) { + center += se->gizmo->get_subgizmo_transform(GE->key()).origin; + count++; + } + } + center += sp->get_global_gizmo_transform().origin; count++; } @@ -3629,58 +3812,16 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const Vector3 world_ray = _get_ray(p_pos); Vector3 world_pos = _get_ray_pos(p_pos); - Vector<ObjectID> instances = RenderingServer::get_singleton()->instances_cull_ray(world_pos, world_ray, get_tree()->get_root()->get_world_3d()->get_scenario()); - Set<Ref<EditorNode3DGizmo>> found_gizmos; - - float closest_dist = MAX_DISTANCE; - Vector3 point = world_pos + world_ray * MAX_DISTANCE; - Vector3 normal = Vector3(0.0, 0.0, 0.0); - for (int i = 0; i < instances.size(); i++) { - MeshInstance3D *mesh_instance = Object::cast_to<MeshInstance3D>(ObjectDB::get_instance(instances[i])); - - if (!mesh_instance) { - continue; - } - - Ref<EditorNode3DGizmo> seg = mesh_instance->get_gizmo(); - - if ((!seg.is_valid()) || found_gizmos.has(seg)) { - continue; - } - - found_gizmos.insert(seg); - - Vector3 hit_point; - Vector3 hit_normal; - bool inters = seg->intersect_ray(camera, p_pos, hit_point, hit_normal, nullptr, false); - - if (!inters) { - continue; - } - - float dist = world_pos.distance_to(hit_point); - - if (dist < 0) { - continue; - } + PhysicsDirectSpaceState3D *ss = get_tree()->get_root()->get_world_3d()->get_direct_space_state(); + PhysicsDirectSpaceState3D::RayResult result; - if (dist < closest_dist) { - closest_dist = dist; - point = hit_point; - normal = hit_normal; - } - } - Vector3 offset = Vector3(); - for (int i = 0; i < 3; i++) { - if (normal[i] > 0.0) { - offset[i] = (preview_bounds->get_size()[i] - (preview_bounds->get_size()[i] + preview_bounds->get_position()[i])); - } else if (normal[i] < 0.0) { - offset[i] = -(preview_bounds->get_size()[i] + preview_bounds->get_position()[i]); - } + if (ss->intersect_ray(world_pos, world_pos + world_ray * MAX_DISTANCE, result)) { + point = result.position; } - return point + offset; + + return point; } AABB Node3DEditorViewport::_calculate_spatial_bounds(const Node3D *p_parent, bool p_exclude_top_level_transform) { @@ -3931,6 +4072,7 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_ } bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT); + bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CTRL); selected_files.clear(); Dictionary d = p_data; @@ -3938,29 +4080,32 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_ selected_files = d["files"]; } - List<Node *> list = editor->get_editor_selection()->get_selected_node_list(); - if (list.size() == 0) { - Node *root_node = editor->get_edited_scene(); + List<Node *> selected_nodes = editor->get_editor_selection()->get_selected_node_list(); + Node *root_node = editor->get_edited_scene(); + if (selected_nodes.size() == 1) { + Node *selected_node = selected_nodes[0]; + target_node = root_node; + if (is_ctrl) { + target_node = selected_node; + } else if (is_shift && selected_node != root_node) { + target_node = selected_node->get_parent(); + } + } else if (selected_nodes.size() == 0) { if (root_node) { - list.push_back(root_node); + target_node = root_node; } else { - accept->set_text(TTR("No parent to instance a child at.")); + accept->set_text(TTR("Cannot drag and drop into scene with no root node.")); accept->popup_centered(); _remove_preview(); return; } - } - if (list.size() != 1) { - accept->set_text(TTR("This operation requires a single selected node.")); + } else { + accept->set_text(TTR("Cannot drag and drop into multiple selected nodes.")); accept->popup_centered(); _remove_preview(); return; } - target_node = list[0]; - if (is_shift && target_node != editor->get_edited_scene()) { - target_node = target_node->get_parent(); - } drop_pos = p_point; _perform_drop_data(); @@ -3972,9 +4117,8 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito _edit.mode = TRANSFORM_NONE; _edit.plane = TRANSFORM_VIEW; - _edit.edited_gizmo = 0; _edit.snap = true; - _edit.gizmo_handle = 0; + _edit.gizmo_handle = -1; index = p_index; editor = p_editor; @@ -3982,7 +4126,6 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito editor_selection = editor->get_editor_selection(); undo_redo = editor->get_undo_redo(); - clicked_includes_current = false; orthogonal = false; auto_orthogonal = false; lock_rotation = false; @@ -4005,7 +4148,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito surface->set_anchors_and_offsets_preset(Control::PRESET_WIDE); surface->set_clip_contents(true); camera = memnew(Camera3D); - camera->set_disable_gizmo(true); + camera->set_disable_gizmos(true); camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + p_index)) | (1 << GIZMO_EDIT_LAYER) | (1 << GIZMO_GRID_LAYER) | (1 << MISC_TOOL_LAYER)); viewport->add_child(camera); camera->make_current(); @@ -4134,6 +4277,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito preview_camera = memnew(CheckBox); preview_camera->set_text(TTR("Preview")); + preview_camera->set_shortcut(ED_SHORTCUT("spatial_editor/toggle_camera_preview", TTR("Toggle Camera Preview"), KEY_MASK_CMD | KEY_P)); vbox->add_child(preview_camera); preview_camera->set_h_size_flags(0); preview_camera->hide(); @@ -4574,43 +4718,54 @@ void Node3DEditor::select_gizmo_highlight_axis(int p_axis) { } void Node3DEditor::update_transform_gizmo() { - List<Node *> &selection = editor_selection->get_selected_node_list(); - AABB center; - bool first = true; + int count = 0; + bool local_gizmo_coords = are_local_coords_enabled(); + Vector3 gizmo_center; Basis gizmo_basis; - bool local_gizmo_coords = are_local_coords_enabled(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); - if (!sp) { - continue; - } + Node3DEditorSelectedItem *se = selected ? editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected) : nullptr; - Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); - if (!se) { - continue; + if (se && se->gizmo.is_valid()) { + for (Map<int, Transform3D>::Element *E = se->subgizmos.front(); E; E = E->next()) { + Transform3D xf = se->sp->get_global_transform() * se->gizmo->get_subgizmo_transform(E->key()); + gizmo_center += xf.origin; + if (count == 0 && local_gizmo_coords) { + gizmo_basis = xf.basis; + gizmo_basis.orthonormalize(); + } + count++; } + } else { + List<Node *> &selection = editor_selection->get_selected_node_list(); + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { + Node3D *sp = Object::cast_to<Node3D>(E->get()); + if (!sp) { + continue; + } - Transform3D xf = se->sp->get_global_gizmo_transform(); + if (sp->has_meta("_edit_lock_")) { + continue; + } - if (first) { - center.position = xf.origin; - first = false; - if (local_gizmo_coords) { + Node3DEditorSelectedItem *sel_item = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); + if (!sel_item) { + continue; + } + + Transform3D xf = sel_item->sp->get_global_transform(); + gizmo_center += xf.origin; + if (count == 0 && local_gizmo_coords) { gizmo_basis = xf.basis; gizmo_basis.orthonormalize(); } - } else { - center.expand_to(xf.origin); - gizmo_basis = Basis(); + count++; } } - Vector3 pcenter = center.position + center.size * 0.5; - gizmo.visible = !first; - gizmo.transform.origin = pcenter; - gizmo.transform.basis = gizmo_basis; + gizmo.visible = count > 0; + gizmo.transform.origin = (count > 0) ? gizmo_center / count : Vector3(); + gizmo.transform.basis = (count == 1) ? gizmo_basis : Basis(); for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) { viewports[i]->update_transform_gizmo_view(); @@ -4621,7 +4776,7 @@ void _update_all_gizmos(Node *p_node) { for (int i = p_node->get_child_count() - 1; 0 <= i; --i) { Node3D *spatial_node = Object::cast_to<Node3D>(p_node->get_child(i)); if (spatial_node) { - spatial_node->update_gizmo(); + spatial_node->update_gizmos(); } _update_all_gizmos(p_node->get_child(i)); @@ -4655,7 +4810,9 @@ Object *Node3DEditor::_get_editor_data(Object *p_what) { RS::get_singleton()->instance_geometry_set_cast_shadows_setting( si->sbox_instance, RS::SHADOW_CASTING_SETTING_OFF); - RS::get_singleton()->instance_set_layer_mask(si->sbox_instance, 1 << Node3DEditorViewport::MISC_TOOL_LAYER); + // Use the Edit layer to hide the selection box when View Gizmos is disabled, since it is a bit distracting. + // It's still possible to approximately guess what is selected by looking at the manipulation gizmo position. + RS::get_singleton()->instance_set_layer_mask(si->sbox_instance, 1 << Node3DEditorViewport::GIZMO_EDIT_LAYER); RS::get_singleton()->instance_geometry_set_flag(si->sbox_instance, RS::INSTANCE_FLAG_IGNORE_OCCLUSION_CULLING, true); si->sbox_instance_xray = RenderingServer::get_singleton()->instance_create2( selection_box_xray->get_rid(), @@ -4663,7 +4820,9 @@ Object *Node3DEditor::_get_editor_data(Object *p_what) { RS::get_singleton()->instance_geometry_set_cast_shadows_setting( si->sbox_instance_xray, RS::SHADOW_CASTING_SETTING_OFF); - RS::get_singleton()->instance_set_layer_mask(si->sbox_instance_xray, 1 << Node3DEditorViewport::MISC_TOOL_LAYER); + // Use the Edit layer to hide the selection box when View Gizmos is disabled, since it is a bit distracting. + // It's still possible to approximately guess what is selected by looking at the manipulation gizmo position. + RS::get_singleton()->instance_set_layer_mask(si->sbox_instance_xray, 1 << Node3DEditorViewport::GIZMO_EDIT_LAYER); RS::get_singleton()->instance_geometry_set_flag(si->sbox_instance, RS::INSTANCE_FLAG_IGNORE_OCCLUSION_CULLING, true); return si; @@ -4940,22 +5099,38 @@ void Node3DEditor::set_state(const Dictionary &p_state) { void Node3DEditor::edit(Node3D *p_spatial) { if (p_spatial != selected) { if (selected) { - Ref<EditorNode3DGizmo> seg = selected->get_gizmo(); - if (seg.is_valid()) { + Vector<Ref<Node3DGizmo>> gizmos = selected->get_gizmos(); + for (int i = 0; i < gizmos.size(); i++) { + Ref<EditorNode3DGizmo> seg = gizmos[i]; + if (!seg.is_valid()) { + continue; + } seg->set_selected(false); - selected->update_gizmo(); } + + Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected); + if (se) { + se->gizmo.unref(); + se->subgizmos.clear(); + } + + selected->update_gizmos(); } selected = p_spatial; - over_gizmo_handle = -1; + current_hover_gizmo = Ref<EditorNode3DGizmo>(); + current_hover_gizmo_handle = -1; if (selected) { - Ref<EditorNode3DGizmo> seg = selected->get_gizmo(); - if (seg.is_valid()) { + Vector<Ref<Node3DGizmo>> gizmos = selected->get_gizmos(); + for (int i = 0; i < gizmos.size(); i++) { + Ref<EditorNode3DGizmo> seg = gizmos[i]; + if (!seg.is_valid()) { + continue; + } seg->set_selected(true); - selected->update_gizmo(); } + selected->update_gizmos(); } } } @@ -4993,8 +5168,8 @@ void Node3DEditor::_xform_dialog_action() { List<Node *> &selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E); if (!sp) { continue; } @@ -5230,8 +5405,8 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *spatial = Object::cast_to<Node3D>(E); if (!spatial || !spatial->is_inside_tree()) { continue; } @@ -5255,8 +5430,8 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *spatial = Object::cast_to<Node3D>(E); if (!spatial || !spatial->is_inside_tree()) { continue; } @@ -5280,8 +5455,8 @@ void Node3DEditor::_menu_item_pressed(int p_option) { List<Node *> &selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *spatial = Object::cast_to<Node3D>(E); if (!spatial || !spatial->is_inside_tree()) { continue; } @@ -5304,8 +5479,8 @@ void Node3DEditor::_menu_item_pressed(int p_option) { undo_redo->create_action(TTR("Ungroup Selected")); List<Node *> &selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *spatial = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *spatial = Object::cast_to<Node3D>(E); if (!spatial || !spatial->is_inside_tree()) { continue; } @@ -5381,35 +5556,37 @@ void Node3DEditor::_init_indicators() { } Ref<Shader> grid_shader = memnew(Shader); - grid_shader->set_code( - "\n" - "shader_type spatial; \n" - "render_mode unshaded; \n" - "uniform bool orthogonal; \n" - "uniform float grid_size; \n" - "\n" - "void vertex() { \n" - " // From FLAG_SRGB_VERTEX_COLOR \n" - " if (!OUTPUT_IS_SRGB) { \n" - " COLOR.rgb = mix(pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb * (1.0 / 12.92), lessThan(COLOR.rgb, vec3(0.04045))); \n" - " } \n" - "} \n" - "\n" - "void fragment() { \n" - " ALBEDO = COLOR.rgb; \n" - " vec3 dir = orthogonal ? -vec3(0, 0, 1) : VIEW; \n" - " float angle_fade = abs(dot(dir, NORMAL)); \n" - " angle_fade = smoothstep(0.05, 0.2, angle_fade); \n" - " \n" - " vec3 world_pos = (CAMERA_MATRIX * vec4(VERTEX, 1.0)).xyz; \n" - " vec3 world_normal = (CAMERA_MATRIX * vec4(NORMAL, 0.0)).xyz; \n" - " vec3 camera_world_pos = CAMERA_MATRIX[3].xyz; \n" - " vec3 camera_world_pos_on_plane = camera_world_pos * (1.0 - world_normal); \n" - " float dist_fade = 1.0 - (distance(world_pos, camera_world_pos_on_plane) / grid_size); \n" - " dist_fade = smoothstep(0.02, 0.3, dist_fade); \n" - " \n" - " ALPHA = COLOR.a * dist_fade * angle_fade; \n" - "}"); + grid_shader->set_code(R"( +shader_type spatial; + +render_mode unshaded; + +uniform bool orthogonal; +uniform float grid_size; + +void vertex() { + // From FLAG_SRGB_VERTEX_COLOR. + if (!OUTPUT_IS_SRGB) { + COLOR.rgb = mix(pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb * (1.0 / 12.92), lessThan(COLOR.rgb, vec3(0.04045))); + } +} + +void fragment() { + ALBEDO = COLOR.rgb; + vec3 dir = orthogonal ? -vec3(0, 0, 1) : VIEW; + float angle_fade = abs(dot(dir, NORMAL)); + angle_fade = smoothstep(0.05, 0.2, angle_fade); + + vec3 world_pos = (CAMERA_MATRIX * vec4(VERTEX, 1.0)).xyz; + vec3 world_normal = (CAMERA_MATRIX * vec4(NORMAL, 0.0)).xyz; + vec3 camera_world_pos = CAMERA_MATRIX[3].xyz; + vec3 camera_world_pos_on_plane = camera_world_pos * (1.0 - world_normal); + float dist_fade = 1.0 - (distance(world_pos, camera_world_pos_on_plane) / grid_size); + dist_fade = smoothstep(0.02, 0.3, dist_fade); + + ALPHA = COLOR.a * dist_fade * angle_fade; +} +)"); for (int i = 0; i < 3; i++) { grid_mat[i].instantiate(); @@ -5477,8 +5654,7 @@ void Node3DEditor::_init_indicators() { gizmo_color[i] = mat; Ref<StandardMaterial3D> mat_hl = mat->duplicate(); - const float brightness = 1.3; - const Color albedo = Color(col.r * brightness, col.g * brightness, col.b * brightness); + const Color albedo = col.from_hsv(col.get_h(), 0.25, 1.0, 1); mat_hl->set_albedo(albedo); gizmo_color_hl[i] = mat_hl; @@ -5585,7 +5761,7 @@ void Node3DEditor::_init_indicators() { surftool->begin(Mesh::PRIMITIVE_TRIANGLES); int n = 128; // number of circle segments - int m = 6; // number of thickness segments + int m = 3; // number of thickness segments real_t step = Math_TAU / n; for (int j = 0; j < n; ++j) { @@ -5621,33 +5797,35 @@ void Node3DEditor::_init_indicators() { Ref<Shader> rotate_shader = memnew(Shader); - rotate_shader->set_code( - "\n" - "shader_type spatial; \n" - "render_mode unshaded, depth_test_disabled; \n" - "uniform vec4 albedo; \n" - "\n" - "mat3 orthonormalize(mat3 m) { \n" - " vec3 x = normalize(m[0]); \n" - " vec3 y = normalize(m[1] - x * dot(x, m[1])); \n" - " vec3 z = m[2] - x * dot(x, m[2]); \n" - " z = normalize(z - y * (dot(y,m[2]))); \n" - " return mat3(x,y,z); \n" - "} \n" - "\n" - "void vertex() { \n" - " mat3 mv = orthonormalize(mat3(MODELVIEW_MATRIX)); \n" - " vec3 n = mv * VERTEX; \n" - " float orientation = dot(vec3(0,0,-1),n); \n" - " if (orientation <= 0.005) { \n" - " VERTEX += NORMAL*0.02; \n" - " } \n" - "} \n" - "\n" - "void fragment() { \n" - " ALBEDO = albedo.rgb; \n" - " ALPHA = albedo.a; \n" - "}"); + rotate_shader->set_code(R"( +shader_type spatial; + +render_mode unshaded, depth_test_disabled; + +uniform vec4 albedo; + +mat3 orthonormalize(mat3 m) { + vec3 x = normalize(m[0]); + vec3 y = normalize(m[1] - x * dot(x, m[1])); + vec3 z = m[2] - x * dot(x, m[2]); + z = normalize(z - y * (dot(y,m[2]))); + return mat3(x,y,z); +} + +void vertex() { + mat3 mv = orthonormalize(mat3(MODELVIEW_MATRIX)); + vec3 n = mv * VERTEX; + float orientation = dot(vec3(0, 0, -1), n); + if (orientation <= 0.005) { + VERTEX += NORMAL * 0.02; + } +} + +void fragment() { + ALBEDO = albedo.rgb; + ALPHA = albedo.a; +} +)"); Ref<ShaderMaterial> rotate_mat = memnew(ShaderMaterial); rotate_mat->set_render_priority(Material::RENDER_PRIORITY_MAX); @@ -5667,34 +5845,36 @@ void Node3DEditor::_init_indicators() { Ref<ShaderMaterial> border_mat = rotate_mat->duplicate(); Ref<Shader> border_shader = memnew(Shader); - border_shader->set_code( - "\n" - "shader_type spatial; \n" - "render_mode unshaded, depth_test_disabled; \n" - "uniform vec4 albedo; \n" - "\n" - "mat3 orthonormalize(mat3 m) { \n" - " vec3 x = normalize(m[0]); \n" - " vec3 y = normalize(m[1] - x * dot(x, m[1])); \n" - " vec3 z = m[2] - x * dot(x, m[2]); \n" - " z = normalize(z - y * (dot(y,m[2]))); \n" - " return mat3(x,y,z); \n" - "} \n" - "\n" - "void vertex() { \n" - " mat3 mv = orthonormalize(mat3(MODELVIEW_MATRIX)); \n" - " mv = inverse(mv); \n" - " VERTEX += NORMAL*0.008; \n" - " vec3 camera_dir_local = mv * vec3(0,0,1); \n" - " vec3 camera_up_local = mv * vec3(0,1,0); \n" - " mat3 rotation_matrix = mat3(cross(camera_dir_local, camera_up_local), camera_up_local, camera_dir_local); \n" - " VERTEX = rotation_matrix * VERTEX; \n" - "} \n" - "\n" - "void fragment() { \n" - " ALBEDO = albedo.rgb; \n" - " ALPHA = albedo.a; \n" - "}"); + border_shader->set_code(R"( +shader_type spatial; + +render_mode unshaded, depth_test_disabled; + +uniform vec4 albedo; + +mat3 orthonormalize(mat3 m) { + vec3 x = normalize(m[0]); + vec3 y = normalize(m[1] - x * dot(x, m[1])); + vec3 z = m[2] - x * dot(x, m[2]); + z = normalize(z - y * (dot(y,m[2]))); + return mat3(x,y,z); +} + +void vertex() { + mat3 mv = orthonormalize(mat3(MODELVIEW_MATRIX)); + mv = inverse(mv); + VERTEX += NORMAL*0.008; + vec3 camera_dir_local = mv * vec3(0,0,1); + vec3 camera_up_local = mv * vec3(0,1,0); + mat3 rotation_matrix = mat3(cross(camera_dir_local, camera_up_local), camera_up_local, camera_dir_local); + VERTEX = rotation_matrix * VERTEX; +} + +void fragment() { + ALBEDO = albedo.rgb; + ALPHA = albedo.a; +} +)"); border_mat->set_shader(border_shader); border_mat->set_shader_param("albedo", Color(0.75, 0.75, 0.75, col.a / 3.0)); @@ -5789,7 +5969,7 @@ void Node3DEditor::_init_indicators() { surftool->commit(scale_plane_gizmo[i]); Ref<StandardMaterial3D> plane_mat_hl = plane_mat->duplicate(); - plane_mat_hl->set_albedo(Color(col.r * 1.3, col.g * 1.3, col.b * 1.3)); + plane_mat_hl->set_albedo(col.from_hsv(col.get_h(), 0.25, 1.0, 1)); plane_gizmo_color_hl[i] = plane_mat_hl; // needed, so we can draw planes from both sides } } @@ -5798,6 +5978,18 @@ void Node3DEditor::_init_indicators() { _generate_selection_boxes(); } +void Node3DEditor::_update_context_menu_stylebox() { + // This must be called when the theme changes to follow the new accent color. + Ref<StyleBoxFlat> context_menu_stylebox = memnew(StyleBoxFlat); + const Color accent_color = EditorNode::get_singleton()->get_gui_base()->get_theme_color("accent_color", "Editor"); + context_menu_stylebox->set_bg_color(accent_color * Color(1, 1, 1, 0.1)); + // Add an underline to the StyleBox, but prevent its minimum vertical size from changing. + context_menu_stylebox->set_border_color(accent_color); + context_menu_stylebox->set_border_width(SIDE_BOTTOM, Math::round(2 * EDSCALE)); + context_menu_stylebox->set_default_margin(SIDE_BOTTOM, 0); + context_menu_container->add_theme_style_override("panel", context_menu_stylebox); +} + void Node3DEditor::_update_gizmos_menu() { gizmos_menu->clear(); @@ -6021,13 +6213,27 @@ void Node3DEditor::update_grid() { _init_grid(); } -bool Node3DEditor::is_any_freelook_active() const { - for (unsigned int i = 0; i < VIEWPORTS_COUNT; ++i) { - if (viewports[i]->is_freelook_active()) { - return true; +void Node3DEditor::_selection_changed() { + _refresh_menu_icons(); + if (selected && editor_selection->get_selected_node_list().size() != 1) { + Vector<Ref<Node3DGizmo>> gizmos = selected->get_gizmos(); + for (int i = 0; i < gizmos.size(); i++) { + Ref<EditorNode3DGizmo> seg = gizmos[i]; + if (!seg.is_valid()) { + continue; + } + seg->set_selected(false); + } + + Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected); + if (se) { + se->gizmo.unref(); + se->subgizmos.clear(); } + selected->update_gizmos(); + selected = nullptr; } - return false; + update_transform_gizmo(); } void Node3DEditor::_refresh_menu_icons() { @@ -6040,14 +6246,14 @@ void Node3DEditor::_refresh_menu_icons() { all_locked = false; all_grouped = false; } else { - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - if (Object::cast_to<Node3D>(E->get()) && !Object::cast_to<Node3D>(E->get())->has_meta("_edit_lock_")) { + for (Node *E : selection) { + if (Object::cast_to<Node3D>(E) && !Object::cast_to<Node3D>(E)->has_meta("_edit_lock_")) { all_locked = false; break; } } - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - if (Object::cast_to<Node3D>(E->get()) && !Object::cast_to<Node3D>(E->get())->has_meta("_edit_group_")) { + for (Node *E : selection) { + if (Object::cast_to<Node3D>(E) && !Object::cast_to<Node3D>(E)->has_meta("_edit_group_")) { all_grouped = false; break; } @@ -6100,8 +6306,8 @@ void Node3DEditor::snap_selected_nodes_to_floor() { List<Node *> &selection = editor_selection->get_selected_node_list(); Dictionary snap_data; - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node3D *sp = Object::cast_to<Node3D>(E->get()); + for (Node *E : selection) { + Node3D *sp = Object::cast_to<Node3D>(E); if (sp) { Vector3 from = Vector3(); Vector3 position_offset = Vector3(); @@ -6248,7 +6454,7 @@ void Node3DEditor::_add_sun_to_scene(bool p_already_added_environment) { ERR_FAIL_COND(!base); Node *new_sun = preview_sun->duplicate(); - undo_redo->create_action("Add Preview Sun to Scene"); + undo_redo->create_action(TTR("Add Preview Sun to Scene")); undo_redo->add_do_method(base, "add_child", new_sun); // Move to the beginning of the scene tree since more "global" nodes // generally look better when placed at the top. @@ -6278,7 +6484,7 @@ void Node3DEditor::_add_environment_to_scene(bool p_already_added_sun) { WorldEnvironment *new_env = memnew(WorldEnvironment); new_env->set_environment(preview_environment->get_environment()->duplicate(true)); - undo_redo->create_action("Add Preview Environment to Scene"); + undo_redo->create_action(TTR("Add Preview Environment to Scene")); undo_redo->add_do_method(base, "add_child", new_env); // Move to the beginning of the scene tree since more "global" nodes // generally look better when placed at the top. @@ -6289,101 +6495,122 @@ void Node3DEditor::_add_environment_to_scene(bool p_already_added_sun) { undo_redo->commit_action(); } +void Node3DEditor::_update_theme() { + tool_button[Node3DEditor::TOOL_MODE_SELECT]->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); + tool_button[Node3DEditor::TOOL_MODE_MOVE]->set_icon(get_theme_icon(SNAME("ToolMove"), SNAME("EditorIcons"))); + tool_button[Node3DEditor::TOOL_MODE_ROTATE]->set_icon(get_theme_icon(SNAME("ToolRotate"), SNAME("EditorIcons"))); + tool_button[Node3DEditor::TOOL_MODE_SCALE]->set_icon(get_theme_icon(SNAME("ToolScale"), SNAME("EditorIcons"))); + tool_button[Node3DEditor::TOOL_MODE_LIST_SELECT]->set_icon(get_theme_icon(SNAME("ListSelect"), SNAME("EditorIcons"))); + tool_button[Node3DEditor::TOOL_LOCK_SELECTED]->set_icon(get_theme_icon(SNAME("Lock"), SNAME("EditorIcons"))); + tool_button[Node3DEditor::TOOL_UNLOCK_SELECTED]->set_icon(get_theme_icon(SNAME("Unlock"), SNAME("EditorIcons"))); + tool_button[Node3DEditor::TOOL_GROUP_SELECTED]->set_icon(get_theme_icon(SNAME("Group"), SNAME("EditorIcons"))); + tool_button[Node3DEditor::TOOL_UNGROUP_SELECTED]->set_icon(get_theme_icon(SNAME("Ungroup"), SNAME("EditorIcons"))); + + tool_option_button[Node3DEditor::TOOL_OPT_LOCAL_COORDS]->set_icon(get_theme_icon(SNAME("Object"), SNAME("EditorIcons"))); + tool_option_button[Node3DEditor::TOOL_OPT_USE_SNAP]->set_icon(get_theme_icon(SNAME("Snap"), SNAME("EditorIcons"))); + tool_option_button[Node3DEditor::TOOL_OPT_OVERRIDE_CAMERA]->set_icon(get_theme_icon(SNAME("Camera3D"), SNAME("EditorIcons"))); + + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), get_theme_icon(SNAME("Panels1"), SNAME("EditorIcons"))); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), get_theme_icon(SNAME("Panels2"), SNAME("EditorIcons"))); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), get_theme_icon(SNAME("Panels2Alt"), SNAME("EditorIcons"))); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), get_theme_icon(SNAME("Panels3"), SNAME("EditorIcons"))); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), get_theme_icon(SNAME("Panels3Alt"), SNAME("EditorIcons"))); + view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), get_theme_icon(SNAME("Panels4"), SNAME("EditorIcons"))); + + sun_button->set_icon(get_theme_icon(SNAME("DirectionalLight3D"), SNAME("EditorIcons"))); + environ_button->set_icon(get_theme_icon(SNAME("WorldEnvironment"), SNAME("EditorIcons"))); + sun_environ_settings->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); + + sun_title->add_theme_font_override("font", get_theme_font(SNAME("title_font"), SNAME("Window"))); + environ_title->add_theme_font_override("font", get_theme_font(SNAME("title_font"), SNAME("Window"))); +} + void Node3DEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - tool_button[Node3DEditor::TOOL_MODE_SELECT]->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_MODE_MOVE]->set_icon(get_theme_icon(SNAME("ToolMove"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_MODE_ROTATE]->set_icon(get_theme_icon(SNAME("ToolRotate"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_MODE_SCALE]->set_icon(get_theme_icon(SNAME("ToolScale"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_MODE_LIST_SELECT]->set_icon(get_theme_icon(SNAME("ListSelect"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_LOCK_SELECTED]->set_icon(get_theme_icon(SNAME("Lock"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_UNLOCK_SELECTED]->set_icon(get_theme_icon(SNAME("Unlock"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_GROUP_SELECTED]->set_icon(get_theme_icon(SNAME("Group"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_UNGROUP_SELECTED]->set_icon(get_theme_icon(SNAME("Ungroup"), SNAME("EditorIcons"))); - - tool_option_button[Node3DEditor::TOOL_OPT_LOCAL_COORDS]->set_icon(get_theme_icon(SNAME("Object"), SNAME("EditorIcons"))); - tool_option_button[Node3DEditor::TOOL_OPT_USE_SNAP]->set_icon(get_theme_icon(SNAME("Snap"), SNAME("EditorIcons"))); - tool_option_button[Node3DEditor::TOOL_OPT_OVERRIDE_CAMERA]->set_icon(get_theme_icon(SNAME("Camera3D"), SNAME("EditorIcons"))); - - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), get_theme_icon(SNAME("Panels1"), SNAME("EditorIcons"))); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), get_theme_icon(SNAME("Panels2"), SNAME("EditorIcons"))); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), get_theme_icon(SNAME("Panels2Alt"), SNAME("EditorIcons"))); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), get_theme_icon(SNAME("Panels3"), SNAME("EditorIcons"))); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), get_theme_icon(SNAME("Panels3Alt"), SNAME("EditorIcons"))); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), get_theme_icon(SNAME("Panels4"), SNAME("EditorIcons"))); - - _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - - _refresh_menu_icons(); - - get_tree()->connect("node_removed", callable_mp(this, &Node3DEditor::_node_removed)); - get_tree()->connect("node_added", callable_mp(this, &Node3DEditor::_node_added)); - EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor()->connect("node_changed", callable_mp(this, &Node3DEditor::_refresh_menu_icons)); - editor_selection->connect("selection_changed", callable_mp(this, &Node3DEditor::_refresh_menu_icons)); - - editor->connect("stop_pressed", callable_mp(this, &Node3DEditor::_update_camera_override_button), make_binds(false)); - editor->connect("play_pressed", callable_mp(this, &Node3DEditor::_update_camera_override_button), make_binds(true)); - - sun_button->set_icon(get_theme_icon(SNAME("DirectionalLight3D"), SNAME("EditorIcons"))); - environ_button->set_icon(get_theme_icon(SNAME("WorldEnvironment"), SNAME("EditorIcons"))); - sun_environ_settings->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); + switch (p_what) { + case NOTIFICATION_READY: { + _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - _update_preview_environment(); - sun_title->add_theme_font_override("font", get_theme_font(SNAME("title_font"), SNAME("Window"))); - environ_title->add_theme_font_override("font", get_theme_font(SNAME("title_font"), SNAME("Window"))); + _refresh_menu_icons(); - sun_state->set_custom_minimum_size(sun_vb->get_combined_minimum_size()); - environ_state->set_custom_minimum_size(environ_vb->get_combined_minimum_size()); - } else if (p_what == NOTIFICATION_ENTER_TREE) { - _register_all_gizmos(); - _update_gizmos_menu(); - _init_indicators(); - } else if (p_what == NOTIFICATION_THEME_CHANGED) { - _update_gizmos_menu_theme(); - sun_title->add_theme_font_override("font", get_theme_font(SNAME("title_font"), SNAME("Window"))); - environ_title->add_theme_font_override("font", get_theme_font(SNAME("title_font"), SNAME("Window"))); - } else if (p_what == NOTIFICATION_EXIT_TREE) { - _finish_indicators(); - } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - tool_button[Node3DEditor::TOOL_MODE_SELECT]->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_MODE_MOVE]->set_icon(get_theme_icon(SNAME("ToolMove"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_MODE_ROTATE]->set_icon(get_theme_icon(SNAME("ToolRotate"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_MODE_SCALE]->set_icon(get_theme_icon(SNAME("ToolScale"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_MODE_LIST_SELECT]->set_icon(get_theme_icon(SNAME("ListSelect"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_LOCK_SELECTED]->set_icon(get_theme_icon(SNAME("Lock"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_UNLOCK_SELECTED]->set_icon(get_theme_icon(SNAME("Unlock"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_GROUP_SELECTED]->set_icon(get_theme_icon(SNAME("Group"), SNAME("EditorIcons"))); - tool_button[Node3DEditor::TOOL_UNGROUP_SELECTED]->set_icon(get_theme_icon(SNAME("Ungroup"), SNAME("EditorIcons"))); - - tool_option_button[Node3DEditor::TOOL_OPT_LOCAL_COORDS]->set_icon(get_theme_icon(SNAME("Object"), SNAME("EditorIcons"))); - tool_option_button[Node3DEditor::TOOL_OPT_USE_SNAP]->set_icon(get_theme_icon(SNAME("Snap"), SNAME("EditorIcons"))); - - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), get_theme_icon(SNAME("Panels1"), SNAME("EditorIcons"))); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), get_theme_icon(SNAME("Panels2"), SNAME("EditorIcons"))); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), get_theme_icon(SNAME("Panels2Alt"), SNAME("EditorIcons"))); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), get_theme_icon(SNAME("Panels3"), SNAME("EditorIcons"))); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), get_theme_icon(SNAME("Panels3Alt"), SNAME("EditorIcons"))); - view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), get_theme_icon(SNAME("Panels4"), SNAME("EditorIcons"))); - - // Update grid color by rebuilding grid. - _finish_grid(); - _init_grid(); - } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - if (!is_visible() && tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->is_pressed()) { - EditorDebuggerNode *debugger = EditorDebuggerNode::get_singleton(); + get_tree()->connect("node_removed", callable_mp(this, &Node3DEditor::_node_removed)); + get_tree()->connect("node_added", callable_mp(this, &Node3DEditor::_node_added)); + EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor()->connect("node_changed", callable_mp(this, &Node3DEditor::_refresh_menu_icons)); + editor_selection->connect("selection_changed", callable_mp(this, &Node3DEditor::_selection_changed)); + + editor->connect("stop_pressed", callable_mp(this, &Node3DEditor::_update_camera_override_button), make_binds(false)); + editor->connect("play_pressed", callable_mp(this, &Node3DEditor::_update_camera_override_button), make_binds(true)); + + _update_preview_environment(); + + sun_state->set_custom_minimum_size(sun_vb->get_combined_minimum_size()); + environ_state->set_custom_minimum_size(environ_vb->get_combined_minimum_size()); + } break; + case NOTIFICATION_ENTER_TREE: { + _update_theme(); + _register_all_gizmos(); + _update_gizmos_menu(); + _init_indicators(); + } break; + case NOTIFICATION_EXIT_TREE: { + _finish_indicators(); + } break; + case NOTIFICATION_THEME_CHANGED: { + _update_theme(); + _update_gizmos_menu_theme(); + _update_context_menu_stylebox(); + sun_title->add_theme_font_override("font", get_theme_font(SNAME("title_font"), SNAME("Window"))); + environ_title->add_theme_font_override("font", get_theme_font(SNAME("title_font"), SNAME("Window"))); + } break; + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { + // Update grid color by rebuilding grid. + _finish_grid(); + _init_grid(); + } break; + case NOTIFICATION_VISIBILITY_CHANGED: { + if (!is_visible() && tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->is_pressed()) { + EditorDebuggerNode *debugger = EditorDebuggerNode::get_singleton(); + + debugger->set_camera_override(EditorDebuggerNode::OVERRIDE_NONE); + tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->set_pressed(false); + } + } break; + } +} + +bool Node3DEditor::is_subgizmo_selected(int p_id) { + Node3DEditorSelectedItem *se = selected ? editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected) : nullptr; + if (se) { + return se->subgizmos.has(p_id); + } + return false; +} + +bool Node3DEditor::is_current_selected_gizmo(const EditorNode3DGizmo *p_gizmo) { + Node3DEditorSelectedItem *se = selected ? editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected) : nullptr; + if (se) { + return se->gizmo == p_gizmo; + } + return false; +} - debugger->set_camera_override(EditorDebuggerNode::OVERRIDE_NONE); - tool_option_button[TOOL_OPT_OVERRIDE_CAMERA]->set_pressed(false); +Vector<int> Node3DEditor::get_subgizmo_selection() { + Node3DEditorSelectedItem *se = selected ? editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected) : nullptr; + + Vector<int> ret; + if (se) { + for (Map<int, Transform3D>::Element *E = se->subgizmos.front(); E; E = E->next()) { + ret.push_back(E->key()); } } + return ret; } void Node3DEditor::add_control_to_menu_panel(Control *p_control) { - hbc_menu->add_child(p_control); + hbc_context_menu->add_child(p_control); } void Node3DEditor::remove_control_from_menu_panel(Control *p_control) { - hbc_menu->remove_child(p_control); + hbc_context_menu->remove_child(p_control); } void Node3DEditor::set_can_preview(Camera3D *p_preview) { @@ -6405,23 +6632,43 @@ void Node3DEditor::_request_gizmo(Object *p_obj) { if (!sp) { return; } - if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_ancestor_of(sp)))) { - Ref<EditorNode3DGizmo> seg; + bool is_selected = (sp == selected); + + if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_ancestor_of(sp)))) { for (int i = 0; i < gizmo_plugins_by_priority.size(); ++i) { - seg = gizmo_plugins_by_priority.write[i]->get_gizmo(sp); + Ref<EditorNode3DGizmo> seg = gizmo_plugins_by_priority.write[i]->get_gizmo(sp); if (seg.is_valid()) { - sp->set_gizmo(seg); + sp->add_gizmo(seg); - if (sp == selected) { - seg->set_selected(true); - selected->update_gizmo(); + if (is_selected != seg->is_selected()) { + seg->set_selected(is_selected); } - - break; } } + sp->update_gizmos(); + } +} + +void Node3DEditor::_clear_subgizmo_selection(Object *p_obj) { + Node3D *sp = nullptr; + if (p_obj) { + sp = Object::cast_to<Node3D>(p_obj); + } else { + sp = selected; + } + + if (!sp) { + return; + } + + Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp); + if (se) { + se->subgizmos.clear(); + se->gizmo.unref(); + sp->update_gizmos(); + update_transform_gizmo(); } } @@ -6510,7 +6757,13 @@ void Node3DEditor::_node_removed(Node *p_node) { } if (p_node == selected) { + Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(selected); + if (se) { + se->gizmo.unref(); + se->subgizmos.clear(); + } selected = nullptr; + update_transform_gizmo(); } } @@ -6548,6 +6801,7 @@ void Node3DEditor::_bind_methods() { ClassDB::bind_method("_unhandled_key_input", &Node3DEditor::_unhandled_key_input); ClassDB::bind_method("_get_editor_data", &Node3DEditor::_get_editor_data); ClassDB::bind_method("_request_gizmo", &Node3DEditor::_request_gizmo); + ClassDB::bind_method("_clear_subgizmo_selection", &Node3DEditor::_clear_subgizmo_selection); ClassDB::bind_method("_refresh_menu_icons", &Node3DEditor::_refresh_menu_icons); ADD_SIGNAL(MethodInfo("transform_key_request")); @@ -6763,8 +7017,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_SELECT]->connect("pressed", callable_mp(this, &Node3DEditor::_menu_item_pressed), button_binds); tool_button[TOOL_MODE_SELECT]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_select", TTR("Select Mode"), KEY_Q)); tool_button[TOOL_MODE_SELECT]->set_shortcut_context(this); - tool_button[TOOL_MODE_SELECT]->set_tooltip(keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Show list of all nodes at position clicked, including locked.")); - + tool_button[TOOL_MODE_SELECT]->set_tooltip(keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate selected node around pivot.") + "\n" + TTR("Alt+RMB: Show list of all nodes at position clicked, including locked.")); hbc_menu->add_child(memnew(VSeparator)); tool_button[TOOL_MODE_MOVE] = memnew(Button); @@ -6940,6 +7193,17 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { view_menu->set_shortcut_context(this); hbc_menu->add_child(view_menu); + hbc_menu->add_child(memnew(VSeparator)); + + context_menu_container = memnew(PanelContainer); + hbc_context_menu = memnew(HBoxContainer); + context_menu_container->add_child(hbc_context_menu); + // Use a custom stylebox to make contextual menu items stand out from the rest. + // This helps with editor usability as contextual menu items change when selecting nodes, + // even though it may not be immediately obvious at first. + hbc_menu->add_child(context_menu_container); + _update_context_menu_stylebox(); + p = view_menu->get_popup(); accept = memnew(AcceptDialog); @@ -7124,7 +7388,7 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::FLOAT, "editors/3d/manipulator_gizmo_opacity", PROPERTY_HINT_RANGE, "0,1,0.01")); EDITOR_DEF("editors/3d/navigation/show_viewport_rotation_gizmo", true); - over_gizmo_handle = -1; + current_hover_gizmo_handle = -1; { //sun popup @@ -7155,9 +7419,21 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { sun_direction->connect("draw", callable_mp(this, &Node3DEditor::_sun_direction_draw)); sun_direction->set_default_cursor_shape(CURSOR_MOVE); - String sun_dir_shader_code = "shader_type canvas_item; uniform vec3 sun_direction; uniform vec3 sun_color; void fragment() { vec3 n; n.xy = UV * 2.0 - 1.0; n.z = sqrt(max(0.0, 1.0 - dot(n.xy, n.xy))); COLOR.rgb = dot(n,sun_direction) * sun_color; COLOR.a = 1.0 - smoothstep(0.99,1.0,length(n.xy)); }"; sun_direction_shader.instantiate(); - sun_direction_shader->set_code(sun_dir_shader_code); + sun_direction_shader->set_code(R"( +shader_type canvas_item; + +uniform vec3 sun_direction; +uniform vec3 sun_color; + +void fragment() { + vec3 n; + n.xy = UV * 2.0 - 1.0; + n.z = sqrt(max(0.0, 1.0 - dot(n.xy, n.xy))); + COLOR.rgb = dot(n, sun_direction) * sun_color; + COLOR.a = 1.0 - smoothstep(0.99, 1.0, length(n.xy)); +} +)"); sun_direction_material.instantiate(); sun_direction_material->set_shader(sun_direction_shader); sun_direction_material->set_shader_param("sun_direction", Vector3(0, 0, 1)); @@ -7426,303 +7702,3 @@ Node3DEditorPlugin::Node3DEditorPlugin(EditorNode *p_node) { Node3DEditorPlugin::~Node3DEditorPlugin() { } - -void EditorNode3DGizmoPlugin::create_material(const String &p_name, const Color &p_color, bool p_billboard, bool p_on_top, bool p_use_vertex_color) { - Color instantiated_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6)); - - Vector<Ref<StandardMaterial3D>> mats; - - for (int i = 0; i < 4; i++) { - bool selected = i % 2 == 1; - bool instantiated = i < 2; - - Ref<StandardMaterial3D> material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); - - Color color = instantiated ? instantiated_color : p_color; - - if (!selected) { - color.a *= 0.3; - } - - material->set_albedo(color); - material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); - material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); - material->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN + 1); - material->set_cull_mode(StandardMaterial3D::CULL_DISABLED); - - if (p_use_vertex_color) { - material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); - } - - if (p_billboard) { - material->set_billboard_mode(StandardMaterial3D::BILLBOARD_ENABLED); - } - - if (p_on_top && selected) { - material->set_on_top_of_alpha(); - } - - mats.push_back(material); - } - - materials[p_name] = mats; -} - -void EditorNode3DGizmoPlugin::create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top, const Color &p_albedo) { - Color instantiated_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/instantiated", Color(0.7, 0.7, 0.7, 0.6)); - - Vector<Ref<StandardMaterial3D>> icons; - - for (int i = 0; i < 4; i++) { - bool selected = i % 2 == 1; - bool instantiated = i < 2; - - Ref<StandardMaterial3D> icon = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); - - Color color = instantiated ? instantiated_color : p_albedo; - - if (!selected) { - color.a *= 0.85; - } - - icon->set_albedo(color); - - icon->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); - icon->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - icon->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); - icon->set_cull_mode(StandardMaterial3D::CULL_DISABLED); - icon->set_depth_draw_mode(StandardMaterial3D::DEPTH_DRAW_DISABLED); - icon->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); - icon->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, p_texture); - icon->set_flag(StandardMaterial3D::FLAG_FIXED_SIZE, true); - icon->set_billboard_mode(StandardMaterial3D::BILLBOARD_ENABLED); - icon->set_render_priority(StandardMaterial3D::RENDER_PRIORITY_MIN); - - if (p_on_top && selected) { - icon->set_on_top_of_alpha(); - } - - icons.push_back(icon); - } - - materials[p_name] = icons; -} - -void EditorNode3DGizmoPlugin::create_handle_material(const String &p_name, bool p_billboard, const Ref<Texture2D> &p_icon) { - Ref<StandardMaterial3D> handle_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); - - handle_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); - handle_material->set_flag(StandardMaterial3D::FLAG_USE_POINT_SIZE, true); - Ref<Texture2D> handle_t = p_icon != nullptr ? p_icon : Node3DEditor::get_singleton()->get_theme_icon(SNAME("Editor3DHandle"), SNAME("EditorIcons")); - handle_material->set_point_size(handle_t->get_width()); - handle_material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, handle_t); - handle_material->set_albedo(Color(1, 1, 1)); - handle_material->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); - handle_material->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); - handle_material->set_on_top_of_alpha(); - if (p_billboard) { - handle_material->set_billboard_mode(StandardMaterial3D::BILLBOARD_ENABLED); - handle_material->set_on_top_of_alpha(); - } - handle_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); - - materials[p_name] = Vector<Ref<StandardMaterial3D>>(); - materials[p_name].push_back(handle_material); -} - -void EditorNode3DGizmoPlugin::add_material(const String &p_name, Ref<StandardMaterial3D> p_material) { - materials[p_name] = Vector<Ref<StandardMaterial3D>>(); - materials[p_name].push_back(p_material); -} - -Ref<StandardMaterial3D> EditorNode3DGizmoPlugin::get_material(const String &p_name, const Ref<EditorNode3DGizmo> &p_gizmo) { - ERR_FAIL_COND_V(!materials.has(p_name), Ref<StandardMaterial3D>()); - ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<StandardMaterial3D>()); - - if (p_gizmo.is_null() || materials[p_name].size() == 1) { - return materials[p_name][0]; - } - - int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0); - - Ref<StandardMaterial3D> mat = materials[p_name][index]; - - if (current_state == ON_TOP && p_gizmo->is_selected()) { - mat->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, true); - } else { - mat->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, false); - } - - return mat; -} - -String EditorNode3DGizmoPlugin::get_gizmo_name() const { - if (get_script_instance() && get_script_instance()->has_method("_get_gizmo_name")) { - return get_script_instance()->call("_get_gizmo_name"); - } - return TTR("Nameless gizmo"); -} - -int EditorNode3DGizmoPlugin::get_priority() const { - if (get_script_instance() && get_script_instance()->has_method("_get_priority")) { - return get_script_instance()->call("_get_priority"); - } - return 0; -} - -Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("get_gizmo")) { - return get_script_instance()->call("get_gizmo", p_spatial); - } - - Ref<EditorNode3DGizmo> ref = create_gizmo(p_spatial); - - if (ref.is_null()) { - return ref; - } - - ref->set_plugin(this); - ref->set_spatial_node(p_spatial); - ref->set_hidden(current_state == HIDDEN); - - current_gizmos.push_back(ref.ptr()); - return ref; -} - -void EditorNode3DGizmoPlugin::_bind_methods() { -#define GIZMO_REF PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "EditorNode3DGizmo") - - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); - BIND_VMETHOD(MethodInfo(GIZMO_REF, "_create_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); - - ClassDB::bind_method(D_METHOD("create_material", "name", "color", "billboard", "on_top", "use_vertex_color"), &EditorNode3DGizmoPlugin::create_material, DEFVAL(false), DEFVAL(false), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("create_icon_material", "name", "texture", "on_top", "color"), &EditorNode3DGizmoPlugin::create_icon_material, DEFVAL(false), DEFVAL(Color(1, 1, 1, 1))); - ClassDB::bind_method(D_METHOD("create_handle_material", "name", "billboard", "texture"), &EditorNode3DGizmoPlugin::create_handle_material, DEFVAL(false), DEFVAL(Variant())); - ClassDB::bind_method(D_METHOD("add_material", "name", "material"), &EditorNode3DGizmoPlugin::add_material); - - ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorNode3DGizmoPlugin::get_material, DEFVAL(Ref<EditorNode3DGizmo>())); - - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_gizmo_name")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_priority")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_be_hidden")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_selectable_when_hidden")); - - BIND_VMETHOD(MethodInfo("_redraw", GIZMO_REF)); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_handle_name", GIZMO_REF, PropertyInfo(Variant::INT, "index"))); - - MethodInfo hvget(Variant::NIL, "_get_handle_value", GIZMO_REF, PropertyInfo(Variant::INT, "index")); - hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(hvget); - - BIND_VMETHOD(MethodInfo("_set_handle", GIZMO_REF, PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - MethodInfo cm = MethodInfo("_commit_handle", GIZMO_REF, PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); - cm.default_arguments.push_back(false); - BIND_VMETHOD(cm); - - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_handle_highlighted", GIZMO_REF, PropertyInfo(Variant::INT, "index"))); - -#undef GIZMO_REF -} - -bool EditorNode3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("_has_gizmo")) { - return get_script_instance()->call("_has_gizmo", p_spatial); - } - return false; -} - -Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("_create_gizmo")) { - return get_script_instance()->call("_create_gizmo", p_spatial); - } - - Ref<EditorNode3DGizmo> ref; - if (has_gizmo(p_spatial)) { - ref.instantiate(); - } - return ref; -} - -bool EditorNode3DGizmoPlugin::can_be_hidden() const { - if (get_script_instance() && get_script_instance()->has_method("_can_be_hidden")) { - return get_script_instance()->call("_can_be_hidden"); - } - return true; -} - -bool EditorNode3DGizmoPlugin::is_selectable_when_hidden() const { - if (get_script_instance() && get_script_instance()->has_method("_is_selectable_when_hidden")) { - return get_script_instance()->call("_is_selectable_when_hidden"); - } - return false; -} - -void EditorNode3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { - if (get_script_instance() && get_script_instance()->has_method("_redraw")) { - Ref<EditorNode3DGizmo> ref(p_gizmo); - get_script_instance()->call("_redraw", ref); - } -} - -String EditorNode3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - if (get_script_instance() && get_script_instance()->has_method("_get_handle_name")) { - return get_script_instance()->call("_get_handle_name", p_gizmo, p_idx); - } - return ""; -} - -Variant EditorNode3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { - if (get_script_instance() && get_script_instance()->has_method("_get_handle_value")) { - return get_script_instance()->call("_get_handle_value", p_gizmo, p_idx); - } - return Variant(); -} - -void EditorNode3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { - if (get_script_instance() && get_script_instance()->has_method("_set_handle")) { - get_script_instance()->call("_set_handle", p_gizmo, p_idx, p_camera, p_point); - } -} - -void EditorNode3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("_commit_handle")) { - get_script_instance()->call("_commit_handle", p_gizmo, p_idx, p_restore, p_cancel); - } -} - -bool EditorNode3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - if (get_script_instance() && get_script_instance()->has_method("_is_handle_highlighted")) { - return get_script_instance()->call("_is_handle_highlighted", p_gizmo, p_idx); - } - return false; -} - -void EditorNode3DGizmoPlugin::set_state(int p_state) { - current_state = p_state; - for (int i = 0; i < current_gizmos.size(); ++i) { - current_gizmos[i]->set_hidden(current_state == HIDDEN); - } -} - -int EditorNode3DGizmoPlugin::get_state() const { - return current_state; -} - -void EditorNode3DGizmoPlugin::unregister_gizmo(EditorNode3DGizmo *p_gizmo) { - current_gizmos.erase(p_gizmo); -} - -EditorNode3DGizmoPlugin::EditorNode3DGizmoPlugin() { - current_state = VISIBLE; -} - -EditorNode3DGizmoPlugin::~EditorNode3DGizmoPlugin() { - for (int i = 0; i < current_gizmos.size(); ++i) { - current_gizmos[i]->set_plugin(nullptr); - current_gizmos[i]->get_spatial_node()->set_gizmo(nullptr); - } - if (Node3DEditor::get_singleton()) { - Node3DEditor::get_singleton()->update_all_gizmos(); - } -} diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index fa0f4e950f..6ac3345daf 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -34,6 +34,7 @@ #include "editor/editor_node.h" #include "editor/editor_plugin.h" #include "editor/editor_scale.h" +#include "editor/plugins/node_3d_editor_gizmos.h" #include "scene/3d/light_3d.h" #include "scene/3d/visual_instance_3d.h" #include "scene/3d/world_environment.h" @@ -43,96 +44,10 @@ class Camera3D; class Node3DEditor; -class EditorNode3DGizmoPlugin; class Node3DEditorViewport; class SubViewportContainer; - -class EditorNode3DGizmo : public Node3DGizmo { - GDCLASS(EditorNode3DGizmo, Node3DGizmo); - - bool selected; - bool instantiated; - -public: - void set_selected(bool p_selected) { selected = p_selected; } - bool is_selected() const { return selected; } - - struct Instance { - RID instance; - Ref<ArrayMesh> mesh; - Ref<Material> material; - Ref<SkinReference> skin_reference; - RID skeleton; - bool billboard = false; - bool unscaled = false; - bool can_intersect = false; - bool extra_margin = false; - - void create_instance(Node3D *p_base, bool p_hidden = false); - }; - - Vector<Vector3> collision_segments; - Ref<TriangleMesh> collision_mesh; - - struct Handle { - Vector3 pos; - bool billboard = false; - }; - - Vector<Vector3> handles; - Vector<Vector3> secondary_handles; - float selectable_icon_size; - bool billboard_handle; - - bool valid; - bool hidden; - Node3D *base; - Vector<Instance> instances; - Node3D *spatial_node; - EditorNode3DGizmoPlugin *gizmo_plugin; - - void _set_spatial_node(Node *p_node) { set_spatial_node(Object::cast_to<Node3D>(p_node)); } - -protected: - static void _bind_methods(); - -public: - void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); - void add_vertices(const Vector<Vector3> &p_vertices, const Ref<Material> &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); - void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const Ref<SkinReference> &p_skin_reference = Ref<SkinReference>(), const Ref<Material> &p_material = Ref<Material>()); - void add_collision_segments(const Vector<Vector3> &p_lines); - void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh); - void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1, const Color &p_modulate = Color(1, 1, 1)); - void add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, bool p_billboard = false, bool p_secondary = false); - void add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position = Vector3()); - - virtual bool is_handle_highlighted(int p_idx) const; - virtual String get_handle_name(int p_idx) const; - virtual Variant get_handle_value(int p_idx); - virtual void set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_point); - virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false); - - void set_spatial_node(Node3D *p_node); - Node3D *get_spatial_node() const { return spatial_node; } - Ref<EditorNode3DGizmoPlugin> get_plugin() const { return gizmo_plugin; } - Vector3 get_handle_pos(int p_idx) const; - bool intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum); - bool intersect_ray(Camera3D *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle = nullptr, bool p_sec_first = false); - - virtual void clear() override; - virtual void create() override; - virtual void transform() override; - virtual void redraw() override; - virtual void free() override; - - virtual bool is_editable() const; - - void set_hidden(bool p_hidden); - void set_plugin(EditorNode3DGizmoPlugin *p_plugin); - - EditorNode3DGizmo(); - ~EditorNode3DGizmo(); -}; +class DirectionalLight3D; +class WorldEnvironment; class ViewportRotationControl : public Control { GDCLASS(ViewportRotationControl, Control); @@ -307,17 +222,15 @@ private: struct _RayResult { Node3D *item = nullptr; float depth = 0; - int handle = 0; _FORCE_INLINE_ bool operator<(const _RayResult &p_rr) const { return depth < p_rr.depth; } }; void _update_name(); void _compute_edit(const Point2 &p_point); void _clear_selected(); - void _select_clicked(bool p_append, bool p_single, bool p_allow_locked = false); - void _select(Node *p_node, bool p_append, bool p_single); - ObjectID _select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle = nullptr, bool p_alt_select = false); - void _find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select = false, bool p_include_locked_nodes = false); + void _select_clicked(bool p_allow_locked); + ObjectID _select_ray(const Point2 &p_pos); + void _find_items_at_pos(const Point2 &p_pos, Vector<_RayResult> &r_results, bool p_include_locked); Vector3 _get_ray_pos(const Vector2 &p_pos) const; Vector3 _get_ray(const Vector2 &p_pos) const; Point2 _point_to_screen(const Vector3 &p_point); @@ -329,7 +242,8 @@ private: Vector3 _get_screen_to_space(const Vector3 &p_vector3); void _select_region(); - bool _gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only = false); + bool _transform_gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only = false); + void _transform_gizmo_apply(Node3D *p_node, const Transform3D &p_transform, bool p_local); void _nav_pan(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative); void _nav_zoom(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative); @@ -342,7 +256,6 @@ private: ObjectID clicked; Vector<_RayResult> selection_results; - bool clicked_includes_current; bool clicked_wants_append; PopupMenu *selection_menu; @@ -383,15 +296,12 @@ private: Vector3 click_ray; Vector3 click_ray_pos; Vector3 center; - Vector3 orig_gizmo_pos; - int edited_gizmo = 0; Point2 mouse_pos; Point2 original_mouse_pos; bool snap = false; Ref<EditorNode3DGizmo> gizmo; int gizmo_handle = 0; Variant gizmo_initial_value; - Vector3 gizmo_initial_pos; } _edit; struct Cursor { @@ -472,6 +382,8 @@ private: void _project_settings_changed(); + Transform3D _compute_transform(TransformMode p_mode, const Transform3D &p_original, const Transform3D &p_original_local, Vector3 p_motion, double p_extra, bool p_local); + protected: void _notification(int p_what); static void _bind_methods(); @@ -494,7 +406,7 @@ public: AcceptDialog *p_accept); SubViewport *get_viewport_node() { return viewport; } - Camera3D *get_camera() { return camera; } // return the default camera object. + Camera3D *get_camera_3d() { return camera; } // return the default camera object. Node3DEditorViewport(Node3DEditor *p_spatial_editor, EditorNode *p_editor, int p_index); ~Node3DEditorViewport(); @@ -512,6 +424,8 @@ public: Node3D *sp; RID sbox_instance; RID sbox_instance_xray; + Ref<EditorNode3DGizmo> gizmo; + Map<int, Transform3D> subgizmos; // map ID -> initial transform Node3DEditorSelectedItem() { sp = nullptr; @@ -617,7 +531,9 @@ private: Ref<StandardMaterial3D> plane_gizmo_color_hl[3]; Ref<ShaderMaterial> rotate_gizmo_color_hl[3]; - int over_gizmo_handle; + Ref<Node3DGizmo> current_hover_gizmo; + int current_hover_gizmo_handle; + float snap_translate_value; float snap_rotate_value; float snap_scale_value; @@ -688,7 +604,6 @@ private: LineEdit *snap_translate; LineEdit *snap_rotate; LineEdit *snap_scale; - PanelContainer *menu_panel; LineEdit *xform_translate[3]; LineEdit *xform_rotate[3]; @@ -710,6 +625,10 @@ private: void _update_camera_override_viewport(Object *p_viewport); HBoxContainer *hbc_menu; + // Used for secondary menu items which are displayed depending on the currently selected node + // (such as MeshInstance's "Mesh" menu). + PanelContainer *context_menu_container; + HBoxContainer *hbc_context_menu; void _generate_selection_boxes(); UndoRedo *undo_redo; @@ -717,6 +636,7 @@ private: int camera_override_viewport_id; void _init_indicators(); + void _update_context_menu_stylebox(); void _update_gizmos_menu(); void _update_gizmos_menu_theme(); void _init_grid(); @@ -734,6 +654,7 @@ private: Node3D *selected; void _request_gizmo(Object *p_obj); + void _clear_subgizmo_selection(Object *p_obj = nullptr); static Node3DEditor *singleton; @@ -746,8 +667,7 @@ private: Node3DEditor(); - bool is_any_freelook_active() const; - + void _selection_changed(); void _refresh_menu_icons(); // Preview Sun and Environment @@ -808,6 +728,8 @@ private: void _add_sun_to_scene(bool p_already_added_environment = false); void _add_environment_to_scene(bool p_already_added_sun = false); + void _update_theme(); + protected: void _notification(int p_what); //void _gui_input(InputEvent p_event); @@ -861,10 +783,16 @@ public: VSplitContainer *get_shader_split(); HSplitContainer *get_palette_split(); - Node3D *get_selected() { return selected; } + Node3D *get_single_selected_node() { return selected; } + bool is_current_selected_gizmo(const EditorNode3DGizmo *p_gizmo); + bool is_subgizmo_selected(int p_id); + Vector<int> get_subgizmo_selection(); + + Ref<EditorNode3DGizmo> get_current_hover_gizmo() const { return current_hover_gizmo; } + void set_current_hover_gizmo(Ref<EditorNode3DGizmo> p_gizmo) { current_hover_gizmo = p_gizmo; } - int get_over_gizmo_handle() const { return over_gizmo_handle; } - void set_over_gizmo_handle(int idx) { over_gizmo_handle = idx; } + void set_current_hover_gizmo_handle(int p_id) { current_hover_gizmo_handle = p_id; } + int get_current_hover_gizmo_handle() const { return current_hover_gizmo_handle; } void set_can_preview(Camera3D *p_preview); @@ -907,50 +835,4 @@ public: ~Node3DEditorPlugin(); }; -class EditorNode3DGizmoPlugin : public Resource { - GDCLASS(EditorNode3DGizmoPlugin, Resource); - -public: - static const int VISIBLE = 0; - static const int HIDDEN = 1; - static const int ON_TOP = 2; - -protected: - int current_state; - List<EditorNode3DGizmo *> current_gizmos; - HashMap<String, Vector<Ref<StandardMaterial3D>>> materials; - - static void _bind_methods(); - virtual bool has_gizmo(Node3D *p_spatial); - virtual Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial); - -public: - void create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false); - void create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1)); - void create_handle_material(const String &p_name, bool p_billboard = false, const Ref<Texture2D> &p_texture = nullptr); - void add_material(const String &p_name, Ref<StandardMaterial3D> p_material); - - Ref<StandardMaterial3D> get_material(const String &p_name, const Ref<EditorNode3DGizmo> &p_gizmo = Ref<EditorNode3DGizmo>()); - - virtual String get_gizmo_name() const; - virtual int get_priority() const; - virtual bool can_be_hidden() const; - virtual bool is_selectable_when_hidden() const; - - virtual void redraw(EditorNode3DGizmo *p_gizmo); - virtual String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const; - virtual Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const; - virtual void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point); - virtual void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false); - virtual bool is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_idx) const; - - Ref<EditorNode3DGizmo> get_gizmo(Node3D *p_spatial); - void set_state(int p_state); - int get_state() const; - void unregister_gizmo(EditorNode3DGizmo *p_gizmo); - - EditorNode3DGizmoPlugin(); - virtual ~EditorNode3DGizmoPlugin(); -}; - #endif // NODE_3D_EDITOR_PLUGIN_H diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 8861fee7a6..8866e8c53e 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -481,7 +481,7 @@ void Path2DEditor::_mode_selected(int p_mode) { Vector2 begin = node->get_curve()->get_point_position(0); Vector2 end = node->get_curve()->get_point_position(node->get_curve()->get_point_count() - 1); - if (begin.distance_to(end) < CMP_EPSILON) { + if (begin.is_equal_approx(end)) { return; } diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp index 0a95986fe2..63b89aea35 100644 --- a/editor/plugins/path_3d_editor_plugin.cpp +++ b/editor/plugins/path_3d_editor_plugin.cpp @@ -36,20 +36,20 @@ #include "node_3d_editor_plugin.h" #include "scene/resources/curve.h" -String Path3DGizmo::get_handle_name(int p_idx) const { +String Path3DGizmo::get_handle_name(int p_id) const { Ref<Curve3D> c = path->get_curve(); if (c.is_null()) { return ""; } - if (p_idx < c->get_point_count()) { - return TTR("Curve Point #") + itos(p_idx); + if (p_id < c->get_point_count()) { + return TTR("Curve Point #") + itos(p_id); } - p_idx = p_idx - c->get_point_count() + 1; + p_id = p_id - c->get_point_count() + 1; - int idx = p_idx / 2; - int t = p_idx % 2; + int idx = p_id / 2; + int t = p_id % 2; String n = TTR("Curve Point #") + itos(idx); if (t == 0) { n += " In"; @@ -60,21 +60,21 @@ String Path3DGizmo::get_handle_name(int p_idx) const { return n; } -Variant Path3DGizmo::get_handle_value(int p_idx) { +Variant Path3DGizmo::get_handle_value(int p_id) const { Ref<Curve3D> c = path->get_curve(); if (c.is_null()) { return Variant(); } - if (p_idx < c->get_point_count()) { - original = c->get_point_position(p_idx); + if (p_id < c->get_point_count()) { + original = c->get_point_position(p_id); return original; } - p_idx = p_idx - c->get_point_count() + 1; + p_id = p_id - c->get_point_count() + 1; - int idx = p_idx / 2; - int t = p_idx % 2; + int idx = p_id / 2; + int t = p_id % 2; Vector3 ofs; if (t == 0) { @@ -88,7 +88,7 @@ Variant Path3DGizmo::get_handle_value(int p_idx) { return ofs; } -void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_point) { +void Path3DGizmo::set_handle(int p_id, Camera3D *p_camera, const Point2 &p_point) const { Ref<Curve3D> c = path->get_curve(); if (c.is_null()) { return; @@ -100,7 +100,7 @@ void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_poin Vector3 ray_dir = p_camera->project_ray_normal(p_point); // Setting curve point positions - if (p_idx < c->get_point_count()) { + if (p_id < c->get_point_count()) { Plane p(gt.xform(original), p_camera->get_transform().basis.get_axis(2)); Vector3 inters; @@ -112,16 +112,16 @@ void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_poin } Vector3 local = gi.xform(inters); - c->set_point_position(p_idx, local); + c->set_point_position(p_id, local); } return; } - p_idx = p_idx - c->get_point_count() + 1; + p_id = p_id - c->get_point_count() + 1; - int idx = p_idx / 2; - int t = p_idx % 2; + int idx = p_id / 2; + int t = p_id % 2; Vector3 base = c->get_point_position(idx); @@ -157,7 +157,7 @@ void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_poin } } -void Path3DGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) { +void Path3DGizmo::commit_handle(int p_id, const Variant &p_restore, bool p_cancel) const { Ref<Curve3D> c = path->get_curve(); if (c.is_null()) { return; @@ -165,27 +165,27 @@ void Path3DGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_canc UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); - if (p_idx < c->get_point_count()) { + if (p_id < c->get_point_count()) { if (p_cancel) { - c->set_point_position(p_idx, p_restore); + c->set_point_position(p_id, p_restore); return; } ur->create_action(TTR("Set Curve Point Position")); - ur->add_do_method(c.ptr(), "set_point_position", p_idx, c->get_point_position(p_idx)); - ur->add_undo_method(c.ptr(), "set_point_position", p_idx, p_restore); + ur->add_do_method(c.ptr(), "set_point_position", p_id, c->get_point_position(p_id)); + ur->add_undo_method(c.ptr(), "set_point_position", p_id, p_restore); ur->commit_action(); return; } - p_idx = p_idx - c->get_point_count() + 1; + p_id = p_id - c->get_point_count() + 1; - int idx = p_idx / 2; - int t = p_idx % 2; + int idx = p_id / 2; + int t = p_id % 2; if (t == 0) { if (p_cancel) { - c->set_point_in(p_idx, p_restore); + c->set_point_in(p_id, p_restore); return; } @@ -282,7 +282,7 @@ void Path3DGizmo::redraw() { add_handles(handles, handles_material); } if (sec_handles.size()) { - add_handles(sec_handles, sec_handles_material, false, true); + add_handles(sec_handles, sec_handles_material, Vector<int>(), false, true); } } } diff --git a/editor/plugins/path_3d_editor_plugin.h b/editor/plugins/path_3d_editor_plugin.h index 13870d7591..5902500526 100644 --- a/editor/plugins/path_3d_editor_plugin.h +++ b/editor/plugins/path_3d_editor_plugin.h @@ -31,7 +31,9 @@ #ifndef PATH_EDITOR_PLUGIN_H #define PATH_EDITOR_PLUGIN_H -#include "editor/node_3d_editor_gizmos.h" +#include "editor/editor_plugin.h" +#include "editor/plugins/node_3d_editor_gizmos.h" +#include "scene/3d/camera_3d.h" #include "scene/3d/path_3d.h" class Path3DGizmo : public EditorNode3DGizmo { @@ -44,9 +46,9 @@ class Path3DGizmo : public EditorNode3DGizmo { public: virtual String get_handle_name(int p_idx) const override; - virtual Variant get_handle_value(int p_idx) override; - virtual void set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_point) override; - virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false) override; + virtual Variant get_handle_value(int p_id) const override; + virtual void set_handle(int p_id, Camera3D *p_camera, const Point2 &p_point) const override; + virtual void commit_handle(int p_id, const Variant &p_restore, bool p_cancel = false) const override; virtual void redraw() override; Path3DGizmo(Path3D *p_path = nullptr); diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index e099c8b5fd..cbea2405b8 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -181,21 +181,21 @@ void ResourcePreloaderEditor::_update_library() { preloader->get_resource_list(&rnames); List<String> names; - for (List<StringName>::Element *E = rnames.front(); E; E = E->next()) { - names.push_back(E->get()); + for (const StringName &E : rnames) { + names.push_back(E); } names.sort(); - for (List<String>::Element *E = names.front(); E; E = E->next()) { + for (const String &E : names) { TreeItem *ti = tree->create_item(root); ti->set_cell_mode(0, TreeItem::CELL_MODE_STRING); ti->set_editable(0, true); ti->set_selectable(0, true); - ti->set_text(0, E->get()); - ti->set_metadata(0, E->get()); + ti->set_text(0, E); + ti->set_metadata(0, E); - RES r = preloader->get_resource(E->get()); + RES r = preloader->get_resource(E); ERR_CONTINUE(r.is_null()); diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp index cea76f5233..ed91f174d1 100644 --- a/editor/plugins/root_motion_editor_plugin.cpp +++ b/editor/plugins/root_motion_editor_plugin.cpp @@ -70,8 +70,8 @@ void EditorPropertyRootMotion::_node_assign() { List<StringName> animations; player->get_animation_list(&animations); - for (List<StringName>::Element *E = animations.front(); E; E = E->next()) { - Ref<Animation> anim = player->get_animation(E->get()); + for (const StringName &E : animations) { + Ref<Animation> anim = player->get_animation(E); for (int i = 0; i < anim->get_track_count(); i++) { paths.insert(anim->track_get_path(i)); } diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 1851ffdc34..668a15da37 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -103,8 +103,8 @@ void EditorStandardSyntaxHighlighter::_update_cache() { const Color type_color = EDITOR_GET("text_editor/highlighting/engine_type_color"); List<StringName> types; ClassDB::get_class_list(&types); - for (List<StringName>::Element *E = types.front(); E; E = E->next()) { - String n = E->get(); + for (const StringName &E : types) { + String n = E; if (n.begins_with("_")) { n = n.substr(1, n.length()); } @@ -115,8 +115,8 @@ void EditorStandardSyntaxHighlighter::_update_cache() { const Color usertype_color = EDITOR_GET("text_editor/highlighting/user_type_color"); List<StringName> global_classes; ScriptServer::get_global_class_list(&global_classes); - for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) { - highlighter->add_keyword_color(E->get(), usertype_color); + for (const StringName &E : global_classes) { + highlighter->add_keyword_color(E, usertype_color); } /* Autoloads. */ @@ -134,8 +134,8 @@ void EditorStandardSyntaxHighlighter::_update_cache() { const Color basetype_color = EDITOR_GET("text_editor/highlighting/base_type_color"); List<String> core_types; script->get_language()->get_core_type_words(&core_types); - for (List<String>::Element *E = core_types.front(); E; E = E->next()) { - highlighter->add_keyword_color(E->get(), basetype_color); + for (const String &E : core_types) { + highlighter->add_keyword_color(E, basetype_color); } /* Reserved words. */ @@ -143,11 +143,11 @@ void EditorStandardSyntaxHighlighter::_update_cache() { const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color"); List<String> keywords; script->get_language()->get_reserved_words(&keywords); - for (List<String>::Element *E = keywords.front(); E; E = E->next()) { - if (script->get_language()->is_control_flow_keyword(E->get())) { - highlighter->add_keyword_color(E->get(), control_flow_keyword_color); + for (const String &E : keywords) { + if (script->get_language()->is_control_flow_keyword(E)) { + highlighter->add_keyword_color(E, control_flow_keyword_color); } else { - highlighter->add_keyword_color(E->get(), keyword_color); + highlighter->add_keyword_color(E, keyword_color); } } @@ -157,9 +157,9 @@ void EditorStandardSyntaxHighlighter::_update_cache() { if (instance_base != StringName()) { List<PropertyInfo> plist; ClassDB::get_property_list(instance_base, &plist); - for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - String name = E->get().name; - if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP) { + for (const PropertyInfo &E : plist) { + String name = E.name; + if (E.usage & PROPERTY_USAGE_CATEGORY || E.usage & PROPERTY_USAGE_GROUP || E.usage & PROPERTY_USAGE_SUBGROUP) { continue; } if (name.find("/") != -1) { @@ -170,8 +170,8 @@ void EditorStandardSyntaxHighlighter::_update_cache() { List<String> clist; ClassDB::get_integer_constant_list(instance_base, &clist); - for (List<String>::Element *E = clist.front(); E; E = E->next()) { - highlighter->add_member_keyword_color(E->get(), member_variable_color); + for (const String &E : clist) { + highlighter->add_member_keyword_color(E, member_variable_color); } } @@ -179,8 +179,7 @@ void EditorStandardSyntaxHighlighter::_update_cache() { const Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); List<String> comments; script->get_language()->get_comment_delimiters(&comments); - for (List<String>::Element *E = comments.front(); E; E = E->next()) { - String comment = E->get(); + for (const String &comment : comments) { String beg = comment.get_slice(" ", 0); String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String(); highlighter->add_color_region(beg, end, comment_color, end == ""); @@ -190,8 +189,7 @@ void EditorStandardSyntaxHighlighter::_update_cache() { const Color string_color = EDITOR_GET("text_editor/highlighting/string_color"); List<String> strings; script->get_language()->get_string_delimiters(&strings); - for (List<String>::Element *E = strings.front(); E; E = E->next()) { - String string = E->get(); + for (const String &string : strings) { String beg = string.get_slice(" ", 0); String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String(); highlighter->add_color_region(beg, end, string_color, end == ""); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 1a6dfa273e..65459d159d 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -50,9 +50,7 @@ void ConnectionInfoDialog::popup_connections(String p_method, Vector<Node *> p_n List<Connection> all_connections; p_nodes[i]->get_signals_connected_to_this(&all_connections); - for (List<Connection>::Element *E = all_connections.front(); E; E = E->next()) { - Connection connection = E->get(); - + for (const Connection &connection : all_connections) { if (connection.callable.get_method() != p_method) { continue; } @@ -116,8 +114,8 @@ Vector<String> ScriptTextEditor::get_functions() { if (script->get_language()->validate(text, script->get_path(), &fnc)) { //if valid rewrite functions to latest functions.clear(); - for (List<String>::Element *E = fnc.front(); E; E = E->next()) { - functions.push_back(E->get()); + for (const String &E : fnc) { + functions.push_back(E); } } @@ -203,8 +201,7 @@ void ScriptTextEditor::_set_theme_for_script() { List<String> strings; script->get_language()->get_string_delimiters(&strings); text_edit->clear_string_delimiters(); - for (List<String>::Element *E = strings.front(); E; E = E->next()) { - String string = E->get(); + for (const String &string : strings) { String beg = string.get_slice(" ", 0); String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String(); text_edit->add_string_delimiter(beg, end, end == ""); @@ -213,8 +210,7 @@ void ScriptTextEditor::_set_theme_for_script() { List<String> comments; script->get_language()->get_comment_delimiters(&comments); text_edit->clear_comment_delimiters(); - for (List<String>::Element *E = comments.front(); E; E = E->next()) { - String comment = E->get(); + for (const String &comment : comments) { String beg = comment.get_slice(" ", 0); String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String(); text_edit->add_comment_delimiter(beg, end, end == ""); @@ -417,8 +413,8 @@ void ScriptTextEditor::_validate_script() { } functions.clear(); - for (List<String>::Element *E = fnc.front(); E; E = E->next()) { - functions.push_back(E->get()); + for (const String &E : fnc) { + functions.push_back(E); } script_is_valid = true; } @@ -432,9 +428,7 @@ void ScriptTextEditor::_validate_script() { Node *base = get_tree()->get_edited_scene_root(); if (base && missing_connections.size() > 0) { warnings_panel->push_table(1); - for (List<Connection>::Element *E = missing_connections.front(); E; E = E->next()) { - Connection connection = E->get(); - + for (const Connection &connection : missing_connections) { String base_path = base->get_name(); String source_path = base == connection.signal.get_object() ? base_path : base_path + "/" + base->get_path_to(Object::cast_to<Node>(connection.signal.get_object())); String target_path = base == connection.callable.get_object() ? base_path : base_path + "/" + base->get_path_to(Object::cast_to<Node>(connection.callable.get_object())); @@ -456,9 +450,7 @@ void ScriptTextEditor::_validate_script() { // Add script warnings. warnings_panel->push_table(3); - for (List<ScriptLanguage::Warning>::Element *E = warnings.front(); E; E = E->next()) { - ScriptLanguage::Warning w = E->get(); - + for (const ScriptLanguage::Warning &w : warnings) { Dictionary ignore_meta; ignore_meta["line"] = w.start_line; ignore_meta["code"] = w.string_code.to_lower(); @@ -488,9 +480,7 @@ void ScriptTextEditor::_validate_script() { errors_panel->clear(); errors_panel->push_table(2); - for (List<ScriptLanguage::ScriptError>::Element *E = errors.front(); E; E = E->next()) { - ScriptLanguage::ScriptError err = E->get(); - + for (const ScriptLanguage::ScriptError &err : errors) { errors_panel->push_cell(); errors_panel->push_meta(err.line - 1); errors_panel->push_color(warnings_panel->get_theme_color(SNAME("error_color"), SNAME("Editor"))); @@ -511,8 +501,8 @@ void ScriptTextEditor::_validate_script() { if (errors.is_empty()) { te->set_line_background_color(i, Color(0, 0, 0, 0)); } else { - for (List<ScriptLanguage::ScriptError>::Element *E = errors.front(); E; E = E->next()) { - bool error_line = i == E->get().line - 1; + for (const ScriptLanguage::ScriptError &E : errors) { + bool error_line = i == E.line - 1; te->set_line_background_color(i, error_line ? marked_line_color : Color(0, 0, 0, 0)); if (error_line) { break; @@ -910,8 +900,7 @@ void ScriptTextEditor::_update_connected_methods() { List<Connection> connections; nodes[i]->get_signals_connected_to_this(&connections); - for (List<Connection>::Element *E = connections.front(); E; E = E->next()) { - Connection connection = E->get(); + for (const Connection &connection : connections) { if (!(connection.flags & CONNECT_PERSIST)) { continue; } @@ -1286,8 +1275,7 @@ void ScriptTextEditor::_edit_option_toggle_inline_comment() { List<String> comment_delimiters; script->get_language()->get_comment_delimiters(&comment_delimiters); - for (List<String>::Element *E = comment_delimiters.front(); E; E = E->next()) { - String script_delimiter = E->get(); + for (const String &script_delimiter : comment_delimiters) { if (script_delimiter.find(" ") == -1) { delimiter = script_delimiter; break; diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 0d65dec87b..2c45b96106 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -118,11 +118,11 @@ void ShaderTextEditor::_load_theme_settings() { const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color"); const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color"); - for (List<String>::Element *E = keywords.front(); E; E = E->next()) { - if (ShaderLanguage::is_control_flow_keyword(E->get())) { - syntax_highlighter->add_keyword_color(E->get(), control_flow_keyword_color); + for (const String &E : keywords) { + if (ShaderLanguage::is_control_flow_keyword(E)) { + syntax_highlighter->add_keyword_color(E, control_flow_keyword_color); } else { - syntax_highlighter->add_keyword_color(E->get(), keyword_color); + syntax_highlighter->add_keyword_color(E, keyword_color); } } @@ -144,8 +144,8 @@ void ShaderTextEditor::_load_theme_settings() { const Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color"); - for (List<String>::Element *E = built_ins.front(); E; E = E->next()) { - syntax_highlighter->add_keyword_color(E->get(), member_variable_color); + for (const String &E : built_ins) { + syntax_highlighter->add_keyword_color(E, member_variable_color); } // Colorize comments. @@ -770,7 +770,7 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { disk_changed->add_child(vbc); Label *dl = memnew(Label); - dl->set_text(TTR("This shader has been modified on on disk.\nWhat action should be taken?")); + dl->set_text(TTR("This shader has been modified on disk.\nWhat action should be taken?")); vbc->add_child(dl); disk_changed->connect("confirmed", callable_mp(this, &ShaderEditor::_reload_shader_from_disk)); diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp index 66d2b36be1..1e62261244 100644 --- a/editor/plugins/shader_file_editor_plugin.cpp +++ b/editor/plugins/shader_file_editor_plugin.cpp @@ -55,7 +55,7 @@ void ShaderFileEditor::_version_selected(int p_option) { RD::ShaderStage stage = RD::SHADER_STAGE_MAX; int first_found = -1; - Ref<RDShaderBytecode> bytecode = shader_file->get_bytecode(version_txt); + Ref<RDShaderSPIRV> bytecode = shader_file->get_spirv(version_txt); ERR_FAIL_COND(bytecode.is_null()); for (int i = 0; i < RD::SHADER_STAGE_MAX; i++) { @@ -142,7 +142,7 @@ void ShaderFileEditor::_update_options() { Ref<Texture2D> icon; - Ref<RDShaderBytecode> bytecode = shader_file->get_bytecode(version_list[i]); + Ref<RDShaderSPIRV> bytecode = shader_file->get_spirv(version_list[i]); ERR_FAIL_COND(bytecode.is_null()); bool failed = false; @@ -175,7 +175,7 @@ void ShaderFileEditor::_update_options() { return; } - Ref<RDShaderBytecode> bytecode = shader_file->get_bytecode(current_version); + Ref<RDShaderSPIRV> bytecode = shader_file->get_spirv(current_version); ERR_FAIL_COND(bytecode.is_null()); int first_valid = -1; int current = -1; diff --git a/editor/plugins/sprite_2d_editor_plugin.cpp b/editor/plugins/sprite_2d_editor_plugin.cpp index 9a62b22d63..0f889ce33d 100644 --- a/editor/plugins/sprite_2d_editor_plugin.cpp +++ b/editor/plugins/sprite_2d_editor_plugin.cpp @@ -521,7 +521,7 @@ Sprite2DEditor::Sprite2DEditor() { debug_uv_dialog = memnew(ConfirmationDialog); debug_uv_dialog->get_ok_button()->set_text(TTR("Create Mesh2D")); - debug_uv_dialog->set_title("Mesh 2D Preview"); + debug_uv_dialog->set_title(TTR("Mesh 2D Preview")); VBoxContainer *vb = memnew(VBoxContainer); debug_uv_dialog->add_child(vb); ScrollContainer *scroll = memnew(ScrollContainer); diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index cd06fdc757..42f7d23da2 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -65,13 +65,11 @@ void SpriteFramesEditor::_sheet_preview_draw() { int x = i * width; split_sheet_preview->draw_line(Point2(x, 0), Point2(x, size.height), Color(1, 1, 1, a)); split_sheet_preview->draw_line(Point2(x + 1, 0), Point2(x + 1, size.height), Color(0, 0, 0, a)); - - for (int j = 1; j < v; j++) { - int y = j * height; - - split_sheet_preview->draw_line(Point2(0, y), Point2(size.width, y), Color(1, 1, 1, a)); - split_sheet_preview->draw_line(Point2(0, y + 1), Point2(size.width, y + 1), Color(0, 0, 0, a)); - } + } + for (int i = 1; i < v; i++) { + int y = i * height; + split_sheet_preview->draw_line(Point2(0, y), Point2(size.width, y), Color(1, 1, 1, a)); + split_sheet_preview->draw_line(Point2(0, y + 1), Point2(size.width, y + 1), Color(0, 0, 0, a)); } if (frames_selected.size() == 0) { @@ -367,8 +365,8 @@ void SpriteFramesEditor::_file_load_request(const Vector<String> &p_path, int p_ int count = 0; - for (List<Ref<Texture2D>>::Element *E = resources.front(); E; E = E->next()) { - undo_redo->add_do_method(frames, "add_frame", edited_anim, E->get(), p_at_pos == -1 ? -1 : p_at_pos + count); + for (const Ref<Texture2D> &E : resources) { + undo_redo->add_do_method(frames, "add_frame", edited_anim, E, p_at_pos == -1 ? -1 : p_at_pos + count); undo_redo->add_undo_method(frames, "remove_frame", edited_anim, p_at_pos == -1 ? fc : p_at_pos); count++; } @@ -626,10 +624,10 @@ void SpriteFramesEditor::_animation_name_edited() { undo_redo->add_do_method(frames, "rename_animation", edited_anim, name); undo_redo->add_undo_method(frames, "rename_animation", name, edited_anim); - for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { - String current = E->get()->call("get_animation"); - undo_redo->add_do_method(E->get(), "set_animation", name); - undo_redo->add_undo_method(E->get(), "set_animation", edited_anim); + for (Node *E : nodes) { + String current = E->call("get_animation"); + undo_redo->add_do_method(E, "set_animation", name); + undo_redo->add_undo_method(E, "set_animation", edited_anim); } undo_redo->add_do_method(this, "_update_library"); @@ -657,10 +655,10 @@ void SpriteFramesEditor::_animation_add() { undo_redo->add_do_method(this, "_update_library"); undo_redo->add_undo_method(this, "_update_library"); - for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { - String current = E->get()->call("get_animation"); - undo_redo->add_do_method(E->get(), "set_animation", name); - undo_redo->add_undo_method(E->get(), "set_animation", current); + for (Node *E : nodes) { + String current = E->call("get_animation"); + undo_redo->add_do_method(E, "set_animation", name); + undo_redo->add_undo_method(E, "set_animation", current); } edited_anim = name; @@ -790,8 +788,8 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { anim_names.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = anim_names.front(); E; E = E->next()) { - String name = E->get(); + for (const StringName &E : anim_names) { + String name = E; TreeItem *it = animations->create_item(anim_root); @@ -800,7 +798,7 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { it->set_text(0, name); it->set_editable(0, true); - if (E->get() == edited_anim) { + if (E == edited_anim) { it->select(0); } } diff --git a/editor/plugins/sub_viewport_preview_editor_plugin.cpp b/editor/plugins/sub_viewport_preview_editor_plugin.cpp index 5fd173cae3..75c47bda2e 100644 --- a/editor/plugins/sub_viewport_preview_editor_plugin.cpp +++ b/editor/plugins/sub_viewport_preview_editor_plugin.cpp @@ -38,6 +38,7 @@ void EditorInspectorPluginSubViewportPreview::parse_begin(Object *p_object) { SubViewport *sub_viewport = Object::cast_to<SubViewport>(p_object); TexturePreview *sub_viewport_preview = memnew(TexturePreview(sub_viewport->get_texture(), false)); + // Otherwise `sub_viewport_preview`'s `texture_display` doesn't update properly when `sub_viewport`'s size changes. sub_viewport->connect("size_changed", callable_mp((CanvasItem *)sub_viewport_preview->get_texture_display(), &CanvasItem::update)); add_custom_control(sub_viewport_preview); } diff --git a/editor/plugins/texture_3d_editor_plugin.cpp b/editor/plugins/texture_3d_editor_plugin.cpp index 096062fc8b..3987cdd6a0 100644 --- a/editor/plugins/texture_3d_editor_plugin.cpp +++ b/editor/plugins/texture_3d_editor_plugin.cpp @@ -77,16 +77,17 @@ void Texture3DEditor::_update_material() { } void Texture3DEditor::_make_shaders() { - String shader_3d = "" - "shader_type canvas_item;\n" - "uniform sampler3D tex;\n" - "uniform float layer;\n" - "void fragment() {\n" - " COLOR = textureLod(tex,vec3(UV,layer),0.0);\n" - "}"; - shader.instantiate(); - shader->set_code(shader_3d); + shader->set_code(R"( +shader_type canvas_item; + +uniform sampler3D tex; +uniform float layer; + +void fragment() { + COLOR = textureLod(tex, vec3(UV, layer), 0.0); +} +)"); material.instantiate(); material->set_shader(shader); } diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index 6ee652098d..44db06bcfd 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -36,11 +36,30 @@ TextureRect *TexturePreview::get_texture_display() { return texture_display; } -TexturePreview::TexturePreview(Ref<Texture2D> p_texture, bool p_show_metadata) { - Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme(); +void TexturePreview::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + if (!is_inside_tree()) { + // TODO: This is a workaround because `NOTIFICATION_THEME_CHANGED` + // is getting called for some reason when the `TexturePreview` is + // getting destroyed, which causes `get_theme_font()` to return `nullptr`. + // See https://github.com/godotengine/godot/issues/50743. + break; + } + + if (metadata_label) { + Ref<Font> metadata_label_font = get_theme_font(SNAME("expression"), SNAME("EditorFonts")); + metadata_label->add_theme_font_override("font", metadata_label_font); + } + + checkerboard->set_texture(get_theme_icon(SNAME("Checkerboard"), SNAME("EditorIcons"))); + } break; + } +} - TextureRect *checkerboard = memnew(TextureRect); - checkerboard->set_texture(theme->get_icon("Checkerboard", "EditorIcons")); +TexturePreview::TexturePreview(Ref<Texture2D> p_texture, bool p_show_metadata) { + checkerboard = memnew(TextureRect); checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE); checkerboard->set_texture_repeat(CanvasItem::TEXTURE_REPEAT_ENABLED); checkerboard->set_custom_minimum_size(Size2(0.0, 256.0) * EDSCALE); @@ -54,7 +73,7 @@ TexturePreview::TexturePreview(Ref<Texture2D> p_texture, bool p_show_metadata) { add_child(texture_display); if (p_show_metadata) { - Label *metadata_label = memnew(Label); + metadata_label = memnew(Label); String format; if (Object::cast_to<ImageTexture>(*p_texture)) { @@ -67,15 +86,13 @@ TexturePreview::TexturePreview(Ref<Texture2D> p_texture, bool p_show_metadata) { metadata_label->set_text(itos(p_texture->get_width()) + "x" + itos(p_texture->get_height()) + " " + format); + // It's okay that these colors are static since the grid color is static too. + metadata_label->add_theme_color_override("font_color", Color::named("white")); + metadata_label->add_theme_color_override("font_color_shadow", Color::named("black")); + metadata_label->add_theme_font_size_override("font_size", 16 * EDSCALE); metadata_label->add_theme_color_override("font_outline_color", Color::named("black")); metadata_label->add_theme_constant_override("outline_size", 2 * EDSCALE); - Ref<Font> metadata_label_font = theme->get_font("expression", "EditorFonts"); - metadata_label->add_theme_font_override("font", metadata_label_font); - - // it's okay that these colors are static since the grid color is static too - metadata_label->add_theme_color_override("font_color", Color::named("white")); - metadata_label->add_theme_color_override("font_color_shadow", Color::named("black")); metadata_label->add_theme_constant_override("shadow_as_outline", 1); metadata_label->set_h_size_flags(Control::SIZE_SHRINK_END); diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h index 165090be93..36a5513ea6 100644 --- a/editor/plugins/texture_editor_plugin.h +++ b/editor/plugins/texture_editor_plugin.h @@ -39,7 +39,13 @@ class TexturePreview : public MarginContainer { GDCLASS(TexturePreview, MarginContainer); private: - TextureRect *texture_display; + TextureRect *texture_display = nullptr; + + TextureRect *checkerboard = nullptr; + Label *metadata_label = nullptr; + +protected: + void _notification(int p_what); public: TextureRect *get_texture_display(); diff --git a/editor/plugins/texture_layered_editor_plugin.cpp b/editor/plugins/texture_layered_editor_plugin.cpp index fb50e1c4a6..80359452ac 100644 --- a/editor/plugins/texture_layered_editor_plugin.cpp +++ b/editor/plugins/texture_layered_editor_plugin.cpp @@ -104,43 +104,46 @@ void TextureLayeredEditor::_update_material() { } void TextureLayeredEditor::_make_shaders() { - String shader_2d_array = "" - "shader_type canvas_item;\n" - "uniform sampler2DArray tex;\n" - "uniform float layer;\n" - "void fragment() {\n" - " COLOR = textureLod(tex,vec3(UV,layer),0.0);\n" - "}"; - shaders[0].instantiate(); - shaders[0]->set_code(shader_2d_array); - - String shader_cube = "" - "shader_type canvas_item;\n" - "uniform samplerCube tex;\n" - "uniform vec3 normal;\n" - "uniform mat3 rot;\n" - "void fragment() {\n" - " vec3 n = rot * normalize(vec3(normal.xy*(UV * 2.0 - 1.0),normal.z));\n" - " COLOR = textureLod(tex,n,0.0);\n" - "}"; + shaders[0]->set_code(R"( +shader_type canvas_item; + +uniform sampler2DArray tex; +uniform float layer; + +void fragment() { + COLOR = textureLod(tex, vec3(UV, layer), 0.0); +} +)"); shaders[1].instantiate(); - shaders[1]->set_code(shader_cube); - - String shader_cube_array = "" - "shader_type canvas_item;\n" - "uniform samplerCubeArray tex;\n" - "uniform vec3 normal;\n" - "uniform mat3 rot;\n" - "uniform float layer;\n" - "void fragment() {\n" - " vec3 n = rot * normalize(vec3(normal.xy*(UV * 2.0 - 1.0),normal.z));\n" - " COLOR = textureLod(tex,vec4(n,layer),0.0);\n" - "}"; + shaders[1]->set_code(R"( +shader_type canvas_item; + +uniform samplerCube tex; +uniform vec3 normal; +uniform mat3 rot; + +void fragment() { + vec3 n = rot * normalize(vec3(normal.xy * (UV * 2.0 - 1.0), normal.z)); + COLOR = textureLod(tex, n, 0.0); +} +)"); shaders[2].instantiate(); - shaders[2]->set_code(shader_cube_array); + shaders[2]->set_code(R"( +shader_type canvas_item; + +uniform samplerCubeArray tex; +uniform vec3 normal; +uniform mat3 rot; +uniform float layer; + +void fragment() { + vec3 n = rot * normalize(vec3(normal.xy * (UV * 2.0 - 1.0), normal.z)); + COLOR = textureLod(tex, vec4(n, layer), 0.0); +} +)"); for (int i = 0; i < 3; i++) { materials[i].instantiate(); diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index e323f1571d..b277f2ab42 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -144,8 +144,7 @@ void TextureRegionEditor::_region_draw() { } } } else if (snap_mode == SNAP_AUTOSLICE) { - for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { - Rect2 r = E->get(); + for (const Rect2 &r : autoslice_cache) { Vector2 endpoints[4] = { mtx.basis_xform(r.position), mtx.basis_xform(r.position + Vector2(r.size.x, 0)), @@ -328,9 +327,9 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) { } if (edited_margin < 0 && snap_mode == SNAP_AUTOSLICE) { Vector2 point = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y)); - for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { - if (E->get().has_point(point)) { - rect = E->get(); + for (const Rect2 &E : autoslice_cache) { + if (E.has_point(point)) { + rect = E; if (Input::get_singleton()->is_key_pressed(KEY_CTRL) && !(Input::get_singleton()->is_key_pressed(KEY_SHIFT | KEY_ALT))) { Rect2 r; if (node_sprite) { @@ -749,12 +748,12 @@ void TextureRegionEditor::_update_autoslice() { for (int x = 0; x < texture->get_width(); x++) { if (texture->is_pixel_opaque(x, y)) { bool found = false; - for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) { - Rect2 grown = E->get().grow(1.5); + for (Rect2 &E : autoslice_cache) { + Rect2 grown = E.grow(1.5); if (grown.has_point(Point2(x, y))) { - E->get().expand_to(Point2(x, y)); - E->get().expand_to(Point2(x + 1, y + 1)); - x = E->get().position.x + E->get().size.x - 1; + E.expand_to(Point2(x, y)); + E.expand_to(Point2(x + 1, y + 1)); + x = E.position.x + E.size.x - 1; bool merged = true; while (merged) { merged = false; @@ -764,12 +763,12 @@ void TextureRegionEditor::_update_autoslice() { autoslice_cache.erase(F->prev()); queue_erase = false; } - if (F == E) { + if (F->get() == E) { continue; } - if (E->get().grow(1).intersects(F->get())) { - E->get().expand_to(F->get().position); - E->get().expand_to(F->get().position + F->get().size); + if (E.grow(1).intersects(F->get())) { + E.expand_to(F->get().position); + E.expand_to(F->get().position + F->get().size); if (F->prev()) { F = F->prev(); autoslice_cache.erase(F->next()); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 4a4816e3b8..0929a629f8 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -65,8 +65,8 @@ void ThemeItemImportTree::_update_items_tree() { tree_icon_items.clear(); tree_stylebox_items.clear(); - for (List<StringName>::Element *E = types.front(); E; E = E->next()) { - String type_name = (String)E->get(); + for (const StringName &E : types) { + String type_name = (String)E; TreeItem *type_node = import_items_tree->create_item(root); type_node->set_meta("_can_be_imported", false); @@ -89,12 +89,12 @@ void ThemeItemImportTree::_update_items_tree() { names.clear(); filtered_names.clear(); - base_theme->get_theme_item_list(dt, E->get(), &names); + base_theme->get_theme_item_list(dt, E, &names); bool data_type_has_filtered_items = false; - for (List<StringName>::Element *F = names.front(); F; F = F->next()) { - String item_name = (String)F->get(); + for (const StringName &F : names) { + String item_name = (String)F; bool is_item_matching_filter = (item_name.findn(filter_text) > -1); if (!filter_text.is_empty() && !is_matching_filter && !is_item_matching_filter) { continue; @@ -105,7 +105,7 @@ void ThemeItemImportTree::_update_items_tree() { has_filtered_items = true; data_type_has_filtered_items = true; } - filtered_names.push_back(F->get()); + filtered_names.push_back(F); } if (filtered_names.size() == 0) { @@ -182,10 +182,10 @@ void ThemeItemImportTree::_update_items_tree() { bool data_type_any_checked_with_data = false; filtered_names.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *F = filtered_names.front(); F; F = F->next()) { + for (const StringName &F : filtered_names) { TreeItem *item_node = import_items_tree->create_item(data_type_node); item_node->set_meta("_can_be_imported", true); - item_node->set_text(0, F->get()); + item_node->set_text(0, F); item_node->set_cell_mode(IMPORT_ITEM, TreeItem::CELL_MODE_CHECK); item_node->set_checked(IMPORT_ITEM, false); item_node->set_editable(IMPORT_ITEM, true); @@ -754,7 +754,7 @@ void ThemeItemImportTree::_import_selected() { return; } - // Prevent changes from immediatelly being reported while the operation is still ongoing. + // Prevent changes from immediately being reported while the operation is still ongoing. edited_theme->_freeze_change_propagation(); ProgressDialog::get_singleton()->add_task("import_theme_items", TTR("Importing Theme Items"), selected_items.size() + 2); @@ -1236,16 +1236,16 @@ void ThemeItemEditorDialog::_update_edit_types() { bool item_reselected = false; edit_type_list->clear(); int e_idx = 0; - for (List<StringName>::Element *E = theme_types.front(); E; E = E->next()) { + for (const StringName &E : theme_types) { Ref<Texture2D> item_icon; - if (E->get() == "") { + if (E == "") { item_icon = get_theme_icon(SNAME("NodeDisabled"), SNAME("EditorIcons")); } else { - item_icon = EditorNode::get_singleton()->get_class_icon(E->get(), "NodeDisabled"); + item_icon = EditorNode::get_singleton()->get_class_icon(E, "NodeDisabled"); } - edit_type_list->add_item(E->get(), item_icon); + edit_type_list->add_item(E, item_icon); - if (E->get() == edited_item_type) { + if (E == edited_item_type) { edit_type_list->select(e_idx); item_reselected = true; } @@ -1318,9 +1318,9 @@ void ThemeItemEditorDialog::_update_edit_item_tree(String p_item_type) { color_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All Color Items")); names.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + for (const StringName &E : names) { TreeItem *item = edit_items_tree->create_item(color_root); - item->set_text(0, E->get()); + item->set_text(0, E); item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item")); item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item")); } @@ -1339,9 +1339,9 @@ void ThemeItemEditorDialog::_update_edit_item_tree(String p_item_type) { constant_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All Constant Items")); names.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + for (const StringName &E : names) { TreeItem *item = edit_items_tree->create_item(constant_root); - item->set_text(0, E->get()); + item->set_text(0, E); item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item")); item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item")); } @@ -1360,9 +1360,9 @@ void ThemeItemEditorDialog::_update_edit_item_tree(String p_item_type) { font_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All Font Items")); names.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + for (const StringName &E : names) { TreeItem *item = edit_items_tree->create_item(font_root); - item->set_text(0, E->get()); + item->set_text(0, E); item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item")); item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item")); } @@ -1381,9 +1381,9 @@ void ThemeItemEditorDialog::_update_edit_item_tree(String p_item_type) { font_size_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All Font Size Items")); names.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + for (const StringName &E : names) { TreeItem *item = edit_items_tree->create_item(font_size_root); - item->set_text(0, E->get()); + item->set_text(0, E); item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item")); item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item")); } @@ -1402,9 +1402,9 @@ void ThemeItemEditorDialog::_update_edit_item_tree(String p_item_type) { icon_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All Icon Items")); names.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + for (const StringName &E : names) { TreeItem *item = edit_items_tree->create_item(icon_root); - item->set_text(0, E->get()); + item->set_text(0, E); item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item")); item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item")); } @@ -1423,9 +1423,9 @@ void ThemeItemEditorDialog::_update_edit_item_tree(String p_item_type) { stylebox_root->add_button(0, get_theme_icon(SNAME("Clear"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_DATA_TYPE, false, TTR("Remove All StyleBox Items")); names.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + for (const StringName &E : names) { TreeItem *item = edit_items_tree->create_item(stylebox_root); - item->set_text(0, E->get()); + item->set_text(0, E); item->add_button(0, get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), ITEMS_TREE_RENAME_ITEM, false, TTR("Rename Item")); item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), ITEMS_TREE_REMOVE_ITEM, false, TTR("Remove Item")); } @@ -1459,13 +1459,16 @@ void ThemeItemEditorDialog::_item_tree_button_pressed(Object *p_item, int p_colu _update_edit_item_tree(edited_item_type); } -void ThemeItemEditorDialog::_add_theme_type() { - edited_theme->add_icon_type(edit_add_type_value->get_text()); - edited_theme->add_stylebox_type(edit_add_type_value->get_text()); - edited_theme->add_font_type(edit_add_type_value->get_text()); - edited_theme->add_font_size_type(edit_add_type_value->get_text()); - edited_theme->add_color_type(edit_add_type_value->get_text()); - edited_theme->add_constant_type(edit_add_type_value->get_text()); +void ThemeItemEditorDialog::_add_theme_type(const String &p_new_text) { + const String new_type = edit_add_type_value->get_text().strip_edges(); + edit_add_type_value->clear(); + + edited_theme->add_icon_type(new_type); + edited_theme->add_stylebox_type(new_type); + edited_theme->add_font_type(new_type); + edited_theme->add_font_size_type(new_type); + edited_theme->add_color_type(new_type); + edited_theme->add_constant_type(new_type); _update_edit_types(); // Force emit a change so that other parts of the editor can update. @@ -1500,12 +1503,12 @@ void ThemeItemEditorDialog::_add_theme_item(Theme::DataType p_data_type, String void ThemeItemEditorDialog::_remove_data_type_items(Theme::DataType p_data_type, String p_item_type) { List<StringName> names; - // Prevent changes from immediatelly being reported while the operation is still ongoing. + // Prevent changes from immediately being reported while the operation is still ongoing. edited_theme->_freeze_change_propagation(); edited_theme->get_theme_item_list(p_data_type, p_item_type, &names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - edited_theme->clear_theme_item(p_data_type, E->get(), p_item_type); + for (const StringName &E : names) { + edited_theme->clear_theme_item(p_data_type, E, p_item_type); } // Allow changes to be reported now that the operation is finished. @@ -1515,7 +1518,7 @@ void ThemeItemEditorDialog::_remove_data_type_items(Theme::DataType p_data_type, void ThemeItemEditorDialog::_remove_class_items() { List<StringName> names; - // Prevent changes from immediatelly being reported while the operation is still ongoing. + // Prevent changes from immediately being reported while the operation is still ongoing. edited_theme->_freeze_change_propagation(); for (int dt = 0; dt < Theme::DATA_TYPE_MAX; dt++) { @@ -1523,9 +1526,9 @@ void ThemeItemEditorDialog::_remove_class_items() { names.clear(); Theme::get_default()->get_theme_item_list(data_type, edited_item_type, &names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - if (edited_theme->has_theme_item_nocheck(data_type, E->get(), edited_item_type)) { - edited_theme->clear_theme_item(data_type, E->get(), edited_item_type); + for (const StringName &E : names) { + if (edited_theme->has_theme_item_nocheck(data_type, E, edited_item_type)) { + edited_theme->clear_theme_item(data_type, E, edited_item_type); } } } @@ -1539,7 +1542,7 @@ void ThemeItemEditorDialog::_remove_class_items() { void ThemeItemEditorDialog::_remove_custom_items() { List<StringName> names; - // Prevent changes from immediatelly being reported while the operation is still ongoing. + // Prevent changes from immediately being reported while the operation is still ongoing. edited_theme->_freeze_change_propagation(); for (int dt = 0; dt < Theme::DATA_TYPE_MAX; dt++) { @@ -1547,9 +1550,9 @@ void ThemeItemEditorDialog::_remove_custom_items() { names.clear(); edited_theme->get_theme_item_list(data_type, edited_item_type, &names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - if (!Theme::get_default()->has_theme_item_nocheck(data_type, E->get(), edited_item_type)) { - edited_theme->clear_theme_item(data_type, E->get(), edited_item_type); + for (const StringName &E : names) { + if (!Theme::get_default()->has_theme_item_nocheck(data_type, E, edited_item_type)) { + edited_theme->clear_theme_item(data_type, E, edited_item_type); } } } @@ -1563,7 +1566,7 @@ void ThemeItemEditorDialog::_remove_custom_items() { void ThemeItemEditorDialog::_remove_all_items() { List<StringName> names; - // Prevent changes from immediatelly being reported while the operation is still ongoing. + // Prevent changes from immediately being reported while the operation is still ongoing. edited_theme->_freeze_change_propagation(); for (int dt = 0; dt < Theme::DATA_TYPE_MAX; dt++) { @@ -1571,8 +1574,8 @@ void ThemeItemEditorDialog::_remove_all_items() { names.clear(); edited_theme->get_theme_item_list(data_type, edited_item_type, &names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - edited_theme->clear_theme_item(data_type, E->get(), edited_item_type); + for (const StringName &E : names) { + edited_theme->clear_theme_item(data_type, E, edited_item_type); } } @@ -1776,11 +1779,12 @@ ThemeItemEditorDialog::ThemeItemEditorDialog() { edit_dialog_side_vb->add_child(edit_add_type_hb); edit_add_type_value = memnew(LineEdit); edit_add_type_value->set_h_size_flags(Control::SIZE_EXPAND_FILL); + edit_add_type_value->connect("text_submitted", callable_mp(this, &ThemeItemEditorDialog::_add_theme_type)); edit_add_type_hb->add_child(edit_add_type_value); Button *edit_add_type_button = memnew(Button); edit_add_type_button->set_text(TTR("Add")); edit_add_type_hb->add_child(edit_add_type_button); - edit_add_type_button->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_add_theme_type)); + edit_add_type_button->connect("pressed", callable_mp(this, &ThemeItemEditorDialog::_add_theme_type), varray("")); VBoxContainer *edit_items_vb = memnew(VBoxContainer); edit_items_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); @@ -1923,8 +1927,8 @@ ThemeItemEditorDialog::ThemeItemEditorDialog() { import_another_theme_dialog->set_title(TTR("Select Another Theme Resource:")); List<String> ext; ResourceLoader::get_recognized_extensions_for_type("Theme", &ext); - for (List<String>::Element *E = ext.front(); E; E = E->next()) { - import_another_theme_dialog->add_filter("*." + E->get() + "; Theme Resource"); + for (const String &E : ext) { + import_another_theme_dialog->add_filter("*." + E + "; Theme Resource"); } import_another_file_hb->add_child(import_another_theme_dialog); import_another_theme_dialog->connect("file_selected", callable_mp(this, &ThemeItemEditorDialog::_select_another_theme_cbk)); @@ -1965,26 +1969,26 @@ void ThemeTypeDialog::_update_add_type_options(const String &p_filter) { names.sort_custom<StringName::AlphCompare>(); Vector<StringName> unique_names; - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { + for (const StringName &E : names) { // Filter out undesired values. - if (!p_filter.is_subsequence_ofi(String(E->get()))) { + if (!p_filter.is_subsequence_ofi(String(E))) { continue; } // Skip duplicate values. - if (unique_names.has(E->get())) { + if (unique_names.has(E)) { continue; } - unique_names.append(E->get()); + unique_names.append(E); Ref<Texture2D> item_icon; - if (E->get() == "") { + if (E == "") { item_icon = get_theme_icon(SNAME("NodeDisabled"), SNAME("EditorIcons")); } else { - item_icon = EditorNode::get_singleton()->get_class_icon(E->get(), "NodeDisabled"); + item_icon = EditorNode::get_singleton()->get_class_icon(E, "NodeDisabled"); } - add_type_options->add_item(E->get(), item_icon); + add_type_options->add_item(E, item_icon); } } @@ -2128,16 +2132,16 @@ void ThemeTypeEditor::_update_type_list() { bool item_reselected = false; int e_idx = 0; - for (List<StringName>::Element *E = theme_types.front(); E; E = E->next()) { + for (const StringName &E : theme_types) { Ref<Texture2D> item_icon; - if (E->get() == "") { + if (E == "") { item_icon = get_theme_icon(SNAME("NodeDisabled"), SNAME("EditorIcons")); } else { - item_icon = EditorNode::get_singleton()->get_class_icon(E->get(), "NodeDisabled"); + item_icon = EditorNode::get_singleton()->get_class_icon(E, "NodeDisabled"); } - theme_type_list->add_icon_item(item_icon, E->get()); + theme_type_list->add_icon_item(item_icon, E); - if (E->get() == edited_type) { + if (E == edited_type) { theme_type_list->select(e_idx); item_reselected = true; } @@ -2178,8 +2182,8 @@ OrderedHashMap<StringName, bool> ThemeTypeEditor::_get_type_items(String p_type_ (Theme::get_default().operator->()->*get_list_func)(default_type, &names); names.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - items[E->get()] = false; + for (const StringName &E : names) { + items[E] = false; } } @@ -2187,8 +2191,8 @@ OrderedHashMap<StringName, bool> ThemeTypeEditor::_get_type_items(String p_type_ names.clear(); (edited_theme.operator->()->*get_list_func)(p_type_name, &names); names.sort_custom<StringName::AlphCompare>(); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - items[E->get()] = true; + for (const StringName &E : names) { + items[E] = true; } } @@ -2199,8 +2203,8 @@ OrderedHashMap<StringName, bool> ThemeTypeEditor::_get_type_items(String p_type_ keys.sort_custom<StringName::AlphCompare>(); OrderedHashMap<StringName, bool> ordered_items; - for (List<StringName>::Element *E = keys.front(); E; E = E->next()) { - ordered_items[E->get()] = items[E->get()]; + for (const StringName &E : keys) { + ordered_items[E] = items[E]; } return ordered_items; @@ -2570,60 +2574,60 @@ void ThemeTypeEditor::_add_default_type_items() { } updating = true; - // Prevent changes from immediatelly being reported while the operation is still ongoing. + // Prevent changes from immediately being reported while the operation is still ongoing. edited_theme->_freeze_change_propagation(); { names.clear(); Theme::get_default()->get_icon_list(default_type, &names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - if (!edited_theme->has_icon(E->get(), edited_type)) { - edited_theme->set_icon(E->get(), edited_type, Ref<Texture2D>()); + for (const StringName &E : names) { + if (!edited_theme->has_icon(E, edited_type)) { + edited_theme->set_icon(E, edited_type, Ref<Texture2D>()); } } } { names.clear(); Theme::get_default()->get_stylebox_list(default_type, &names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - if (!edited_theme->has_stylebox(E->get(), edited_type)) { - edited_theme->set_stylebox(E->get(), edited_type, Ref<StyleBox>()); + for (const StringName &E : names) { + if (!edited_theme->has_stylebox(E, edited_type)) { + edited_theme->set_stylebox(E, edited_type, Ref<StyleBox>()); } } } { names.clear(); Theme::get_default()->get_font_list(default_type, &names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - if (!edited_theme->has_font(E->get(), edited_type)) { - edited_theme->set_font(E->get(), edited_type, Ref<Font>()); + for (const StringName &E : names) { + if (!edited_theme->has_font(E, edited_type)) { + edited_theme->set_font(E, edited_type, Ref<Font>()); } } } { names.clear(); Theme::get_default()->get_font_size_list(default_type, &names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - if (!edited_theme->has_font_size(E->get(), edited_type)) { - edited_theme->set_font_size(E->get(), edited_type, Theme::get_default()->get_font_size(E->get(), default_type)); + for (const StringName &E : names) { + if (!edited_theme->has_font_size(E, edited_type)) { + edited_theme->set_font_size(E, edited_type, Theme::get_default()->get_font_size(E, default_type)); } } } { names.clear(); Theme::get_default()->get_color_list(default_type, &names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - if (!edited_theme->has_color(E->get(), edited_type)) { - edited_theme->set_color(E->get(), edited_type, Theme::get_default()->get_color(E->get(), default_type)); + for (const StringName &E : names) { + if (!edited_theme->has_color(E, edited_type)) { + edited_theme->set_color(E, edited_type, Theme::get_default()->get_color(E, default_type)); } } } { names.clear(); Theme::get_default()->get_constant_list(default_type, &names); - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - if (!edited_theme->has_constant(E->get(), edited_type)) { - edited_theme->set_constant(E->get(), edited_type, Theme::get_default()->get_constant(E->get(), default_type)); + for (const StringName &E : names) { + if (!edited_theme->has_constant(E, edited_type)) { + edited_theme->set_constant(E, edited_type, Theme::get_default()->get_constant(E, default_type)); } } } @@ -2872,18 +2876,18 @@ void ThemeTypeEditor::_update_stylebox_from_leading() { return; } - // Prevent changes from immediatelly being reported while the operation is still ongoing. + // Prevent changes from immediately being reported while the operation is still ongoing. edited_theme->_freeze_change_propagation(); List<StringName> names; edited_theme->get_stylebox_list(edited_type, &names); List<Ref<StyleBox>> styleboxes; - for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - if (E->get() == leading_stylebox.item_name) { + for (const StringName &E : names) { + if (E == leading_stylebox.item_name) { continue; } - Ref<StyleBox> sb = edited_theme->get_stylebox(E->get(), edited_type); + Ref<StyleBox> sb = edited_theme->get_stylebox(E, edited_type); if (sb->get_class() == leading_stylebox.stylebox->get_class()) { styleboxes.push_back(sb); } @@ -2891,20 +2895,20 @@ void ThemeTypeEditor::_update_stylebox_from_leading() { List<PropertyInfo> props; leading_stylebox.stylebox->get_property_list(&props); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + for (const PropertyInfo &E : props) { + if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } - Variant value = leading_stylebox.stylebox->get(E->get().name); - Variant ref_value = leading_stylebox.ref_stylebox->get(E->get().name); + Variant value = leading_stylebox.stylebox->get(E.name); + Variant ref_value = leading_stylebox.ref_stylebox->get(E.name); if (value == ref_value) { continue; } - for (List<Ref<StyleBox>>::Element *F = styleboxes.front(); F; F = F->next()) { - Ref<StyleBox> sb = F->get(); - sb->set(E->get().name, value); + for (const Ref<StyleBox> &F : styleboxes) { + Ref<StyleBox> sb = F; + sb->set(E.name, value); } } @@ -3108,7 +3112,7 @@ void ThemeEditor::edit(const Ref<Theme> &p_theme) { preview_tab->set_preview_theme(p_theme); } - theme_name->set_text(TTR("Theme") + ": " + theme->get_path().get_file()); + theme_name->set_text(TTR("Theme:") + " " + theme->get_path().get_file()); } Ref<Theme> ThemeEditor::get_edited_theme() { @@ -3226,7 +3230,7 @@ ThemeEditor::ThemeEditor() { add_child(top_menu); theme_name = memnew(Label); - theme_name->set_text(TTR("Theme") + ": "); + theme_name->set_text(TTR("Theme:")); theme_name->set_theme_type_variation("HeaderSmall"); top_menu->add_child(theme_name); @@ -3297,8 +3301,8 @@ ThemeEditor::ThemeEditor() { preview_scene_dialog->set_title(TTR("Select UI Scene:")); List<String> ext; ResourceLoader::get_recognized_extensions_for_type("PackedScene", &ext); - for (List<String>::Element *E = ext.front(); E; E = E->next()) { - preview_scene_dialog->add_filter("*." + E->get() + "; Scene"); + for (const String &E : ext) { + preview_scene_dialog->add_filter("*." + E + "; Scene"); } main_hs->add_child(preview_scene_dialog); preview_scene_dialog->connect("file_selected", callable_mp(this, &ThemeEditor::_preview_scene_dialog_cbk)); @@ -3339,12 +3343,12 @@ bool ThemeEditorPlugin::handles(Object *p_node) const { List<StringName> names; edited_theme->get_font_type_list(&types); - for (List<StringName>::Element *E = types.front(); E; E = E->next()) { + for (const StringName &E : types) { names.clear(); - edited_theme->get_font_list(E->get(), &names); + edited_theme->get_font_list(E, &names); - for (List<StringName>::Element *F = names.front(); F; F = F->next()) { - if (font_item == edited_theme->get_font(F->get(), E->get())) { + for (const StringName &F : names) { + if (font_item == edited_theme->get_font(F, E)) { belongs_to_theme = true; break; } @@ -3356,12 +3360,12 @@ bool ThemeEditorPlugin::handles(Object *p_node) const { List<StringName> names; edited_theme->get_stylebox_type_list(&types); - for (List<StringName>::Element *E = types.front(); E; E = E->next()) { + for (const StringName &E : types) { names.clear(); - edited_theme->get_stylebox_list(E->get(), &names); + edited_theme->get_stylebox_list(E, &names); - for (List<StringName>::Element *F = names.front(); F; F = F->next()) { - if (stylebox_item == edited_theme->get_stylebox(F->get(), E->get())) { + for (const StringName &F : names) { + if (stylebox_item == edited_theme->get_stylebox(F, E)) { belongs_to_theme = true; break; } @@ -3373,12 +3377,12 @@ bool ThemeEditorPlugin::handles(Object *p_node) const { List<StringName> names; edited_theme->get_icon_type_list(&types); - for (List<StringName>::Element *E = types.front(); E; E = E->next()) { + for (const StringName &E : types) { names.clear(); - edited_theme->get_icon_list(E->get(), &names); + edited_theme->get_icon_list(E, &names); - for (List<StringName>::Element *F = names.front(); F; F = F->next()) { - if (icon_item == edited_theme->get_icon(F->get(), E->get())) { + for (const StringName &F : names) { + if (icon_item == edited_theme->get_icon(F, E)) { belongs_to_theme = true; break; } diff --git a/editor/plugins/theme_editor_plugin.h b/editor/plugins/theme_editor_plugin.h index 3c114a375a..e78b244a42 100644 --- a/editor/plugins/theme_editor_plugin.h +++ b/editor/plugins/theme_editor_plugin.h @@ -239,7 +239,7 @@ class ThemeItemEditorDialog : public AcceptDialog { void _update_edit_item_tree(String p_item_type); void _item_tree_button_pressed(Object *p_item, int p_column, int p_id); - void _add_theme_type(); + void _add_theme_type(const String &p_new_text); void _add_theme_item(Theme::DataType p_data_type, String p_item_name, String p_item_type); void _remove_data_type_items(Theme::DataType p_data_type, String p_item_type); void _remove_class_items(); diff --git a/editor/plugins/tiles/atlas_merging_dialog.cpp b/editor/plugins/tiles/atlas_merging_dialog.cpp new file mode 100644 index 0000000000..d54906c98c --- /dev/null +++ b/editor/plugins/tiles/atlas_merging_dialog.cpp @@ -0,0 +1,320 @@ +/*************************************************************************/ +/* atlas_merging_dialog.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* 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 */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "atlas_merging_dialog.h" + +#include "editor/editor_scale.h" + +#include "scene/gui/control.h" +#include "scene/gui/split_container.h" + +void AtlasMergingDialog::_property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) { + _set(p_property, p_value); +} + +void AtlasMergingDialog::_generate_merged(Vector<Ref<TileSetAtlasSource>> p_atlas_sources, int p_max_columns) { + merged.instantiate(); + merged_mapping.clear(); + + if (p_atlas_sources.size() >= 2) { + Ref<Image> output_image; + output_image.instantiate(); + output_image->create(1, 1, false, Image::FORMAT_RGBA8); + + // Compute the new texture region size. + Vector2i new_texture_region_size; + for (int source_index = 0; source_index < p_atlas_sources.size(); source_index++) { + Ref<TileSetAtlasSource> atlas_source = p_atlas_sources[source_index]; + new_texture_region_size = new_texture_region_size.max(atlas_source->get_texture_region_size()); + } + + // Generate the merged TileSetAtlasSource. + Vector2i atlas_offset; + int line_height = 0; + for (int source_index = 0; source_index < p_atlas_sources.size(); source_index++) { + Ref<TileSetAtlasSource> atlas_source = p_atlas_sources[source_index]; + merged_mapping.push_back(Map<Vector2i, Vector2i>()); + + // Layout the tiles. + Vector2i atlas_size; + + for (int tile_index = 0; tile_index < atlas_source->get_tiles_count(); tile_index++) { + Vector2i tile_id = atlas_source->get_tile_id(tile_index); + atlas_size = atlas_size.max(tile_id + atlas_source->get_tile_size_in_atlas(tile_id)); + + Rect2i new_tile_rect_in_altas = Rect2i(atlas_offset + tile_id, atlas_source->get_tile_size_in_atlas(tile_id)); + + // Create tiles and alternatives, then copy their properties. + for (int alternative_index = 0; alternative_index < atlas_source->get_alternative_tiles_count(tile_id); alternative_index++) { + int alternative_id = atlas_source->get_alternative_tile_id(tile_id, alternative_index); + if (alternative_id == 0) { + merged->create_tile(new_tile_rect_in_altas.position, new_tile_rect_in_altas.size); + } else { + merged->create_alternative_tile(new_tile_rect_in_altas.position, alternative_index); + } + + // Copy the properties. + TileData *original_tile_data = Object::cast_to<TileData>(atlas_source->get_tile_data(tile_id, alternative_id)); + List<PropertyInfo> properties; + original_tile_data->get_property_list(&properties); + for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { + const StringName &property_name = E->get().name; + merged->set(property_name, original_tile_data->get(property_name)); + } + + // Add to the mapping. + merged_mapping[source_index][tile_id] = new_tile_rect_in_altas.position; + } + + // Copy the texture. + Rect2i src_rect = atlas_source->get_tile_texture_region(tile_id); + Rect2 dst_rect_wide = Rect2i(new_tile_rect_in_altas.position * new_texture_region_size, new_tile_rect_in_altas.size * new_texture_region_size); + if (dst_rect_wide.get_end().x > output_image->get_width() || dst_rect_wide.get_end().y > output_image->get_height()) { + output_image->crop(MAX(dst_rect_wide.get_end().x, output_image->get_width()), MAX(dst_rect_wide.get_end().y, output_image->get_height())); + } + output_image->blit_rect(atlas_source->get_texture()->get_image(), src_rect, (dst_rect_wide.get_position() + dst_rect_wide.get_end()) / 2 - src_rect.size / 2); + } + + // Compute the atlas offset. + line_height = MAX(atlas_size.y, line_height); + atlas_offset.x += atlas_size.x; + if (atlas_offset.x >= p_max_columns) { + atlas_offset.x = 0; + atlas_offset.y += line_height; + line_height = 0; + } + } + + Ref<ImageTexture> output_image_texture; + output_image_texture.instantiate(); + output_image_texture->create_from_image(output_image); + + merged->set_texture(output_image_texture); + merged->set_texture_region_size(new_texture_region_size); + } +} + +void AtlasMergingDialog::_update_texture() { + Vector<int> selected = atlas_merging_atlases_list->get_selected_items(); + if (selected.size() >= 2) { + Vector<Ref<TileSetAtlasSource>> to_merge; + for (int i = 0; i < selected.size(); i++) { + int source_id = atlas_merging_atlases_list->get_item_metadata(selected[i]); + to_merge.push_back(tile_set->get_source(source_id)); + } + _generate_merged(to_merge, next_line_after_column); + preview->set_texture(merged->get_texture()); + preview->show(); + select_2_atlases_label->hide(); + get_ok_button()->set_disabled(false); + merge_button->set_disabled(false); + } else { + _generate_merged(Vector<Ref<TileSetAtlasSource>>(), next_line_after_column); + preview->set_texture(Ref<Texture2D>()); + preview->hide(); + select_2_atlases_label->show(); + get_ok_button()->set_disabled(true); + merge_button->set_disabled(true); + } +} + +void AtlasMergingDialog::_merge_confirmed(String p_path) { + ERR_FAIL_COND(!merged.is_valid()); + + Ref<ImageTexture> output_image_texture = merged->get_texture(); + output_image_texture->get_image()->save_png(p_path); + + Ref<Texture2D> new_texture_resource = ResourceLoader::load(p_path, "Texture2D"); + merged->set_texture(new_texture_resource); + + undo_redo->create_action(TTR("Merge TileSetAtlasSource")); + int next_id = tile_set->get_next_source_id(); + undo_redo->add_do_method(*tile_set, "add_source", merged, next_id); + undo_redo->add_undo_method(*tile_set, "remove_source", next_id); + + if (delete_original_atlases) { + // Delete originals if needed. + Vector<int> selected = atlas_merging_atlases_list->get_selected_items(); + for (int i = 0; i < selected.size(); i++) { + int source_id = atlas_merging_atlases_list->get_item_metadata(selected[i]); + Ref<TileSetAtlasSource> tas = tile_set->get_source(source_id); + undo_redo->add_do_method(*tile_set, "remove_source", source_id); + undo_redo->add_undo_method(*tile_set, "add_source", tas, source_id); + + // Add the tile proxies. + for (int tile_index = 0; tile_index < tas->get_tiles_count(); tile_index++) { + Vector2i tile_id = tas->get_tile_id(tile_index); + undo_redo->add_do_method(*tile_set, "set_coords_level_tile_proxy", source_id, tile_id, next_id, merged_mapping[i][tile_id]); + if (tile_set->has_coords_level_tile_proxy(source_id, tile_id)) { + Array a = tile_set->get_coords_level_tile_proxy(source_id, tile_id); + undo_redo->add_undo_method(*tile_set, "set_coords_level_tile_proxy", a[0], a[1]); + } else { + undo_redo->add_undo_method(*tile_set, "remove_coords_level_tile_proxy", source_id, tile_id); + } + } + } + } + undo_redo->commit_action(); + commited_actions_count++; + + hide(); +} + +void AtlasMergingDialog::ok_pressed() { + delete_original_atlases = false; + editor_file_dialog->popup_file_dialog(); +} + +void AtlasMergingDialog::cancel_pressed() { + for (int i = 0; i < commited_actions_count; i++) { + undo_redo->undo(); + } + commited_actions_count = 0; +} + +void AtlasMergingDialog::custom_action(const String &p_action) { + if (p_action == "merge") { + delete_original_atlases = true; + editor_file_dialog->popup_file_dialog(); + } +} + +bool AtlasMergingDialog::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "next_line_after_column" && p_value.get_type() == Variant::INT) { + next_line_after_column = p_value; + _update_texture(); + return true; + } + return false; +} + +bool AtlasMergingDialog::_get(const StringName &p_name, Variant &r_ret) const { + if (p_name == "next_line_after_column") { + r_ret = next_line_after_column; + return true; + } + return false; +} + +void AtlasMergingDialog::update_tile_set(Ref<TileSet> p_tile_set) { + ERR_FAIL_COND(!p_tile_set.is_valid()); + tile_set = p_tile_set; + + atlas_merging_atlases_list->clear(); + for (int i = 0; i < p_tile_set->get_source_count(); i++) { + int source_id = p_tile_set->get_source_id(i); + Ref<TileSetAtlasSource> atlas_source = p_tile_set->get_source(source_id); + if (atlas_source.is_valid()) { + Ref<Texture2D> texture = atlas_source->get_texture(); + if (texture.is_valid()) { + String item_text = vformat("%s (id:%d)", texture->get_path().get_file(), source_id); + atlas_merging_atlases_list->add_item(item_text, texture); + atlas_merging_atlases_list->set_item_metadata(atlas_merging_atlases_list->get_item_count() - 1, source_id); + } + } + } + + get_ok_button()->set_disabled(true); + merge_button->set_disabled(true); + + commited_actions_count = 0; +} + +AtlasMergingDialog::AtlasMergingDialog() { + // Atlas merging window. + set_title(TTR("Atlas Merging")); + set_hide_on_ok(false); + + // Ok buttons + get_ok_button()->set_text(TTR("Merge (Keep original Atlases)")); + get_ok_button()->set_disabled(true); + merge_button = add_button(TTR("Merge"), true, "merge"); + merge_button->set_disabled(true); + + HSplitContainer *atlas_merging_h_split_container = memnew(HSplitContainer); + atlas_merging_h_split_container->set_h_size_flags(Control::SIZE_EXPAND_FILL); + atlas_merging_h_split_container->set_v_size_flags(Control::SIZE_EXPAND_FILL); + add_child(atlas_merging_h_split_container); + + // Atlas sources item list. + atlas_merging_atlases_list = memnew(ItemList); + atlas_merging_atlases_list->set_fixed_icon_size(Size2i(60, 60) * EDSCALE); + atlas_merging_atlases_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); + atlas_merging_atlases_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); + atlas_merging_atlases_list->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST); + atlas_merging_atlases_list->set_custom_minimum_size(Size2(100, 200)); + atlas_merging_atlases_list->set_select_mode(ItemList::SELECT_MULTI); + atlas_merging_atlases_list->connect("multi_selected", callable_mp(this, &AtlasMergingDialog::_update_texture).unbind(2)); + atlas_merging_h_split_container->add_child(atlas_merging_atlases_list); + + VBoxContainer *atlas_merging_right_panel = memnew(VBoxContainer); + atlas_merging_right_panel->set_h_size_flags(Control::SIZE_EXPAND_FILL); + atlas_merging_h_split_container->add_child(atlas_merging_right_panel); + + // Settings. + Label *settings_label = memnew(Label); + settings_label->set_text(TTR("Settings:")); + atlas_merging_right_panel->add_child(settings_label); + + columns_editor_property = memnew(EditorPropertyInteger); + columns_editor_property->set_label(TTR("Next Line After Column")); + columns_editor_property->set_object_and_property(this, "next_line_after_column"); + columns_editor_property->update_property(); + columns_editor_property->connect("property_changed", callable_mp(this, &AtlasMergingDialog::_property_changed)); + atlas_merging_right_panel->add_child(columns_editor_property); + + // Preview. + Label *preview_label = memnew(Label); + preview_label->set_text(TTR("Preview:")); + atlas_merging_right_panel->add_child(preview_label); + + preview = memnew(TextureRect); + preview->set_h_size_flags(Control::SIZE_EXPAND_FILL); + preview->set_v_size_flags(Control::SIZE_EXPAND_FILL); + preview->set_expand(true); + preview->hide(); + preview->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); + atlas_merging_right_panel->add_child(preview); + + select_2_atlases_label = memnew(Label); + select_2_atlases_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + select_2_atlases_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); + select_2_atlases_label->set_align(Label::ALIGN_CENTER); + select_2_atlases_label->set_valign(Label::VALIGN_CENTER); + select_2_atlases_label->set_text(TTR("Please select two atlases or more.")); + atlas_merging_right_panel->add_child(select_2_atlases_label); + + // The file dialog to choose the texture path. + editor_file_dialog = memnew(EditorFileDialog); + editor_file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); + editor_file_dialog->add_filter("*.png"); + editor_file_dialog->connect("file_selected", callable_mp(this, &AtlasMergingDialog::_merge_confirmed)); + add_child(editor_file_dialog); +} diff --git a/editor/plugins/tiles/atlas_merging_dialog.h b/editor/plugins/tiles/atlas_merging_dialog.h new file mode 100644 index 0000000000..7cb54bc17e --- /dev/null +++ b/editor/plugins/tiles/atlas_merging_dialog.h @@ -0,0 +1,86 @@ +/*************************************************************************/ +/* atlas_merging_dialog.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* 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 */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef ATLAS_MERGING_DIALOG_H +#define ATLAS_MERGING_DIALOG_H + +#include "editor/editor_node.h" +#include "editor/editor_properties.h" + +#include "scene/gui/dialogs.h" +#include "scene/gui/item_list.h" +#include "scene/gui/texture_rect.h" +#include "scene/resources/tile_set.h" + +class AtlasMergingDialog : public ConfirmationDialog { + GDCLASS(AtlasMergingDialog, ConfirmationDialog); + +private: + int commited_actions_count = 0; + bool delete_original_atlases = true; + Ref<TileSetAtlasSource> merged; + LocalVector<Map<Vector2i, Vector2i>> merged_mapping; + Ref<TileSet> tile_set; + + UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); + + // Settings. + int next_line_after_column = 30; + + // GUI. + ItemList *atlas_merging_atlases_list; + EditorPropertyVector2i *texture_region_size_editor_property; + EditorPropertyInteger *columns_editor_property; + TextureRect *preview; + Label *select_2_atlases_label; + EditorFileDialog *editor_file_dialog; + Button *merge_button; + + void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing); + + void _generate_merged(Vector<Ref<TileSetAtlasSource>> p_atlas_sources, int p_max_columns); + void _update_texture(); + void _merge_confirmed(String p_path); + +protected: + virtual void ok_pressed() override; + virtual void cancel_pressed() override; + virtual void custom_action(const String &) override; + + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + +public: + void update_tile_set(Ref<TileSet> p_tile_set); + + AtlasMergingDialog(); +}; + +#endif // ATLAS_MERGING_DIALOG_H diff --git a/editor/plugins/tiles/tile_atlas_view.cpp b/editor/plugins/tiles/tile_atlas_view.cpp index 502e30836b..84e40e2ffa 100644 --- a/editor/plugins/tiles/tile_atlas_view.cpp +++ b/editor/plugins/tiles/tile_atlas_view.cpp @@ -41,25 +41,31 @@ #include "editor/editor_settings.h" void TileAtlasView::_gui_input(const Ref<InputEvent> &p_event) { - bool ctrl = Input::get_singleton()->is_key_pressed(KEY_CTRL); - Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { drag_type = DRAG_TYPE_NONE; - if (ctrl && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) { - // Zoom out - zoom_widget->set_zoom_by_increments(-2); - emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); - _update_zoom_and_panning(true); - accept_event(); - } - if (ctrl && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) { - // Zoom in - zoom_widget->set_zoom_by_increments(2); - emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); - _update_zoom_and_panning(true); - accept_event(); + Vector2i scroll_vec = Vector2((mb->get_button_index() == MOUSE_BUTTON_WHEEL_LEFT) - (mb->get_button_index() == MOUSE_BUTTON_WHEEL_RIGHT), (mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) - (mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN)); + if (scroll_vec != Vector2()) { + if (mb->is_ctrl_pressed()) { + if (mb->is_shift_pressed()) { + panning.x += 32 * mb->get_factor() * scroll_vec.y; + panning.y += 32 * mb->get_factor() * scroll_vec.x; + } else { + panning.y += 32 * mb->get_factor() * scroll_vec.y; + panning.x += 32 * mb->get_factor() * scroll_vec.x; + } + + emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); + _update_zoom_and_panning(true); + accept_event(); + + } else if (!mb->is_shift_pressed()) { + zoom_widget->set_zoom_by_increments(scroll_vec.y * 2); + emit_signal(SNAME("transform_changed"), zoom_widget->get_zoom(), panning); + _update_zoom_and_panning(true); + accept_event(); + } } if (mb->get_button_index() == MOUSE_BUTTON_MIDDLE || mb->get_button_index() == MOUSE_BUTTON_RIGHT) { @@ -569,6 +575,7 @@ TileAtlasView::TileAtlasView() { button_center_view->connect("pressed", callable_mp(this, &TileAtlasView::_center_view)); button_center_view->set_flat(true); button_center_view->set_disabled(true); + button_center_view->set_tooltip(TTR("Center View")); add_child(button_center_view); center_container = memnew(CenterContainer); diff --git a/editor/plugins/tiles/tile_atlas_view.h b/editor/plugins/tiles/tile_atlas_view.h index bafc2b3985..b2046f4322 100644 --- a/editor/plugins/tiles/tile_atlas_view.h +++ b/editor/plugins/tiles/tile_atlas_view.h @@ -47,7 +47,7 @@ class TileAtlasView : public Control { private: TileSet *tile_set; TileSetAtlasSource *tile_set_atlas_source; - int source_id = -1; + int source_id = TileSet::INVALID_SOURCE; enum DragType { DRAG_TYPE_NONE, diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index 8cfc4990ea..bab55df65a 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -1050,7 +1050,7 @@ void TileDataDefaultEditor::_notification(int p_what) { TileDataDefaultEditor::TileDataDefaultEditor() { label = memnew(Label); - label->set_text("Painting:"); + label->set_text(TTR("Painting:")); add_child(label); toolbar->add_child(memnew(VSeparator)); @@ -1244,7 +1244,7 @@ void TileDataCollisionEditor::_polygons_changed() { } } - // Remove uneeded properties and their editors. + // Remove unneeded properties and their editors. for (int i = polygon_editor->get_polygon_count(); dummy_object->has_dummy_property(vformat("polygon_%d_one_way", i)); i++) { dummy_object->remove_dummy_property(vformat("polygon_%d_one_way", i)); } diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp index cf6ce1ff8b..e70aed8ed6 100644 --- a/editor/plugins/tiles/tile_map_editor.cpp +++ b/editor/plugins/tiles/tile_map_editor.cpp @@ -56,18 +56,11 @@ void TileMapEditorTilesPlugin::_notification(int p_what) { picker_button->set_icon(get_theme_icon(SNAME("ColorPick"), SNAME("EditorIcons"))); erase_button->set_icon(get_theme_icon(SNAME("Eraser"), SNAME("EditorIcons"))); - toggle_grid_button->set_icon(get_theme_icon(SNAME("Grid"), SNAME("EditorIcons"))); - missing_atlas_texture_icon = get_theme_icon(SNAME("TileSet"), SNAME("EditorIcons")); - - toggle_grid_button->set_pressed(EditorSettings::get_singleton()->get("editors/tiles_editor/display_grid")); break; case NOTIFICATION_VISIBILITY_CHANGED: _stop_dragging(); break; - case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: - toggle_grid_button->set_pressed(EditorSettings::get_singleton()->get("editors/tiles_editor/display_grid")); - break; } } @@ -85,10 +78,6 @@ void TileMapEditorTilesPlugin::_on_scattering_spinbox_changed(double p_value) { scattering = p_value; } -void TileMapEditorTilesPlugin::_on_grid_toggled(bool p_pressed) { - EditorSettings::get_singleton()->set("editors/tiles_editor/display_grid", p_pressed); -} - void TileMapEditorTilesPlugin::_update_toolbar() { // Stop draggig if needed. _stop_dragging(); @@ -168,9 +157,9 @@ void TileMapEditorTilesPlugin::_update_tile_set_sources_list() { if (atlas_source) { texture = atlas_source->get_texture(); if (texture.is_valid()) { - item_text = vformat("%s (id:%d)", texture->get_path().get_file(), source_id); + item_text = vformat("%s (ID: %d)", texture->get_path().get_file(), source_id); } else { - item_text = vformat("No Texture Atlas Source (id:%d)", source_id); + item_text = vformat("No Texture Atlas Source (ID: %d)", source_id); } } @@ -178,12 +167,12 @@ void TileMapEditorTilesPlugin::_update_tile_set_sources_list() { TileSetScenesCollectionSource *scene_collection_source = Object::cast_to<TileSetScenesCollectionSource>(source); if (scene_collection_source) { texture = get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons")); - item_text = vformat(TTR("Scene Collection Source (id:%d)"), source_id); + item_text = vformat(TTR("Scene Collection Source (ID: %d)"), source_id); } // Use default if not valid. if (item_text.is_empty()) { - item_text = vformat(TTR("Unknown Type Source (id:%d)"), source_id); + item_text = vformat(TTR("Unknown Type Source (ID: %d)"), source_id); } if (!texture.is_valid()) { texture = missing_atlas_texture_icon; @@ -204,7 +193,7 @@ void TileMapEditorTilesPlugin::_update_tile_set_sources_list() { } // Synchronize - TilesEditor::get_singleton()->set_atlas_sources_lists_current(sources_list->get_current()); + TilesEditor::get_singleton()->set_sources_lists_current(sources_list->get_current()); } void TileMapEditorTilesPlugin::_update_bottom_panel() { @@ -302,7 +291,7 @@ void TileMapEditorTilesPlugin::_update_scenes_collection_view() { int item_index = 0; if (scene.is_valid()) { - item_index = scene_tiles_list->add_item(vformat("%s (path:%s id:%d)", scene->get_path().get_file().get_basename(), scene->get_path(), scene_id)); + item_index = scene_tiles_list->add_item(vformat("%s (Path: %s, ID: %d)", scene->get_path().get_file().get_basename(), scene->get_path(), scene_id)); Variant udata = i; EditorResourcePreview::get_singleton()->queue_edited_resource_preview(scene, this, "_scene_thumbnail_done", udata); } else { @@ -410,7 +399,7 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p if (!tile_map_selection.is_empty()) { undo_redo->create_action(TTR("Delete tiles")); for (Set<Vector2i>::Element *E = tile_map_selection.front(); E; E = E->next()) { - undo_redo->add_do_method(tile_map, "set_cell", E->get(), -1, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); + undo_redo->add_do_method(tile_map, "set_cell", E->get(), TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); undo_redo->add_undo_method(tile_map, "set_cell", E->get(), tile_map->get_cell_source_id(E->get()), tile_map->get_cell_atlas_coords(E->get()), tile_map->get_cell_alternative_tile(E->get())); } undo_redo->add_undo_method(this, "_set_tile_map_selection", _get_tile_map_selection()); @@ -441,7 +430,7 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p if (!tile_map_selection.is_empty()) { undo_redo->create_action(TTR("Delete tiles")); for (Set<Vector2i>::Element *E = tile_map_selection.front(); E; E = E->next()) { - undo_redo->add_do_method(tile_map, "set_cell", E->get(), -1, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); + undo_redo->add_do_method(tile_map, "set_cell", E->get(), TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); undo_redo->add_undo_method(tile_map, "set_cell", E->get(), tile_map->get_cell_source_id(E->get()), tile_map->get_cell_atlas_coords(E->get()), tile_map->get_cell_alternative_tile(E->get())); } undo_redo->add_undo_method(this, "_set_tile_map_selection", _get_tile_map_selection()); @@ -462,12 +451,12 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p case DRAG_TYPE_PAINT: { Map<Vector2i, TileMapCell> to_draw = _draw_line(drag_start_mouse_pos, drag_last_mouse_pos, mpos); for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) { - if (!erase_button->is_pressed() && E->get().source_id == -1) { + if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) { continue; } Vector2i coords = E->key(); if (!drag_modified.has(coords)) { - drag_modified.insert(coords, TileMapCell(tile_map->get_cell_source_id(coords), tile_map->get_cell_atlas_coords(coords), tile_map->get_cell_alternative_tile(coords))); + drag_modified.insert(coords, tile_map->get_cell(coords)); } tile_map->set_cell(coords, E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile); } @@ -478,12 +467,12 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p if (!drag_modified.has(line[i])) { Map<Vector2i, TileMapCell> to_draw = _draw_bucket_fill(line[i], bucket_continuous_checkbox->is_pressed()); for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) { - if (!erase_button->is_pressed() && E->get().source_id == -1) { + if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) { continue; } Vector2i coords = E->key(); if (!drag_modified.has(coords)) { - drag_modified.insert(coords, TileMapCell(tile_map->get_cell_source_id(coords), tile_map->get_cell_atlas_coords(coords), tile_map->get_cell_alternative_tile(coords))); + drag_modified.insert(coords, tile_map->get_cell(coords)); } tile_map->set_cell(coords, E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile); } @@ -516,8 +505,8 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p drag_modified.clear(); for (Set<Vector2i>::Element *E = tile_map_selection.front(); E; E = E->next()) { Vector2i coords = E->get(); - drag_modified.insert(coords, TileMapCell(tile_map->get_cell_source_id(coords), tile_map->get_cell_atlas_coords(coords), tile_map->get_cell_alternative_tile(coords))); - tile_map->set_cell(coords, -1, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); + drag_modified.insert(coords, tile_map->get_cell(coords)); + tile_map->set_cell(coords, TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); } } else { // Select tiles @@ -536,12 +525,12 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p drag_modified.clear(); Map<Vector2i, TileMapCell> to_draw = _draw_line(drag_start_mouse_pos, mpos, mpos); for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) { - if (!erase_button->is_pressed() && E->get().source_id == -1) { + if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) { continue; } Vector2i coords = E->key(); if (!drag_modified.has(coords)) { - drag_modified.insert(coords, TileMapCell(tile_map->get_cell_source_id(coords), tile_map->get_cell_atlas_coords(coords), tile_map->get_cell_alternative_tile(coords))); + drag_modified.insert(coords, tile_map->get_cell(coords)); } tile_map->set_cell(coords, E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile); } @@ -562,12 +551,12 @@ bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p if (!drag_modified.has(line[i])) { Map<Vector2i, TileMapCell> to_draw = _draw_bucket_fill(line[i], bucket_continuous_checkbox->is_pressed()); for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) { - if (!erase_button->is_pressed() && E->get().source_id == -1) { + if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) { continue; } Vector2i coords = E->key(); if (!drag_modified.has(coords)) { - drag_modified.insert(coords, TileMapCell(tile_map->get_cell_source_id(coords), tile_map->get_cell_atlas_coords(coords), tile_map->get_cell_alternative_tile(coords))); + drag_modified.insert(coords, tile_map->get_cell(coords)); } tile_map->set_cell(coords, E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile); } @@ -634,7 +623,7 @@ void TileMapEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p_over for (int x = rect.position.x; x < rect.get_end().x; x++) { for (int y = rect.position.y; y < rect.get_end().y; y++) { Vector2i coords = Vector2i(x, y); - if (tile_map->get_cell_source_id(coords) != -1) { + if (tile_map->get_cell_source_id(coords) != TileSet::INVALID_SOURCE) { Rect2 cell_region = xform.xform(Rect2(tile_map->map_to_world(coords) - tile_shape_size / 2, tile_shape_size)); tile_set->draw_tile_shape(p_overlay, cell_region, Color(1.0, 1.0, 1.0), false); } @@ -648,7 +637,7 @@ void TileMapEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p_over for (int x = rect.position.x; x < rect.get_end().x; x++) { for (int y = rect.position.y; y < rect.get_end().y; y++) { Vector2i coords = Vector2i(x, y); - if (tile_map->get_cell_source_id(coords) != -1) { + if (tile_map->get_cell_source_id(coords) != TileSet::INVALID_SOURCE) { to_draw.insert(coords); } } @@ -871,7 +860,7 @@ Map<Vector2i, TileMapCell> TileMapEditorTilesPlugin::_draw_line(Vector2 p_start_ // Get or create the pattern. TileMapPattern erase_pattern; - erase_pattern.set_cell(Vector2i(0, 0), -1, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); + erase_pattern.set_cell(Vector2i(0, 0), TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); TileMapPattern *pattern = erase_button->is_pressed() ? &erase_pattern : selection_pattern; Map<Vector2i, TileMapCell> output; @@ -923,7 +912,7 @@ Map<Vector2i, TileMapCell> TileMapEditorTilesPlugin::_draw_rect(Vector2i p_start // Get or create the pattern. TileMapPattern erase_pattern; - erase_pattern.set_cell(Vector2i(0, 0), -1, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); + erase_pattern.set_cell(Vector2i(0, 0), TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); TileMapPattern *pattern = erase_button->is_pressed() ? &erase_pattern : selection_pattern; // Compute the offset to align things to the bottom or right. @@ -974,7 +963,7 @@ Map<Vector2i, TileMapCell> TileMapEditorTilesPlugin::_draw_bucket_fill(Vector2i // Get or create the pattern. TileMapPattern erase_pattern; - erase_pattern.set_cell(Vector2i(0, 0), -1, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); + erase_pattern.set_cell(Vector2i(0, 0), TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); TileMapPattern *pattern = erase_button->is_pressed() ? &erase_pattern : selection_pattern; Map<Vector2i, TileMapCell> output; @@ -983,7 +972,7 @@ Map<Vector2i, TileMapCell> TileMapEditorTilesPlugin::_draw_bucket_fill(Vector2i // If we are filling empty tiles, compute the tilemap boundaries. Rect2i boundaries; - if (source.source_id == -1) { + if (source.source_id == TileSet::INVALID_SOURCE) { boundaries = tile_map->get_used_rect(); } @@ -999,7 +988,7 @@ Map<Vector2i, TileMapCell> TileMapEditorTilesPlugin::_draw_bucket_fill(Vector2i if (source.source_id == tile_map->get_cell_source_id(coords) && source.get_atlas_coords() == tile_map->get_cell_atlas_coords(coords) && source.alternative_tile == tile_map->get_cell_alternative_tile(coords) && - (source.source_id != -1 || boundaries.has_point(coords))) { + (source.source_id != TileSet::INVALID_SOURCE || boundaries.has_point(coords))) { if (!erase_button->is_pressed() && random_tile_checkbox->is_pressed()) { // Paint a random tile. output.insert(coords, _pick_random_tile(pattern)); @@ -1027,7 +1016,7 @@ Map<Vector2i, TileMapCell> TileMapEditorTilesPlugin::_draw_bucket_fill(Vector2i } else { // Replace all tiles like the source. TypedArray<Vector2i> to_check; - if (source.source_id == -1) { + if (source.source_id == TileSet::INVALID_SOURCE) { Rect2i rect = tile_map->get_used_rect(); if (rect.size.x <= 0 || rect.size.y <= 0) { rect = Rect2i(p_coords, Vector2i(1, 1)); @@ -1045,7 +1034,7 @@ Map<Vector2i, TileMapCell> TileMapEditorTilesPlugin::_draw_bucket_fill(Vector2i if (source.source_id == tile_map->get_cell_source_id(coords) && source.get_atlas_coords() == tile_map->get_cell_atlas_coords(coords) && source.alternative_tile == tile_map->get_cell_alternative_tile(coords) && - (source.source_id != -1 || boundaries.has_point(coords))) { + (source.source_id != TileSet::INVALID_SOURCE || boundaries.has_point(coords))) { if (!erase_button->is_pressed() && random_tile_checkbox->is_pressed()) { // Paint a random tile. output.insert(coords, _pick_random_tile(pattern)); @@ -1102,7 +1091,7 @@ void TileMapEditorTilesPlugin::_stop_dragging() { tile_map_selection.erase(coords); } } else { - if (tile_map->get_cell_source_id(coords) != -1) { + if (tile_map->get_cell_source_id(coords) != TileSet::INVALID_SOURCE) { tile_map_selection.insert(coords); } } @@ -1173,7 +1162,7 @@ void TileMapEditorTilesPlugin::_stop_dragging() { for (int x = rect.position.x; x < rect.get_end().x; x++) { for (int y = rect.position.y; y < rect.get_end().y; y++) { Vector2i coords = Vector2i(x, y); - if (tile_map->get_cell_source_id(coords) != -1) { + if (tile_map->get_cell_source_id(coords) != TileSet::INVALID_SOURCE) { coords_array.push_back(coords); } } @@ -1198,7 +1187,7 @@ void TileMapEditorTilesPlugin::_stop_dragging() { Map<Vector2i, TileMapCell> to_draw = _draw_line(drag_start_mouse_pos, drag_start_mouse_pos, mpos); undo_redo->create_action(TTR("Paint tiles")); for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) { - if (!erase_button->is_pressed() && E->get().source_id == -1) { + if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) { continue; } undo_redo->add_do_method(tile_map, "set_cell", E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile); @@ -1210,7 +1199,7 @@ void TileMapEditorTilesPlugin::_stop_dragging() { Map<Vector2i, TileMapCell> to_draw = _draw_rect(tile_map->world_to_map(drag_start_mouse_pos), tile_map->world_to_map(mpos)); undo_redo->create_action(TTR("Paint tiles")); for (Map<Vector2i, TileMapCell>::Element *E = to_draw.front(); E; E = E->next()) { - if (!erase_button->is_pressed() && E->get().source_id == -1) { + if (!erase_button->is_pressed() && E->get().source_id == TileSet::INVALID_SOURCE) { continue; } undo_redo->add_do_method(tile_map, "set_cell", E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile); @@ -1221,9 +1210,6 @@ void TileMapEditorTilesPlugin::_stop_dragging() { case DRAG_TYPE_BUCKET: { undo_redo->create_action(TTR("Paint tiles")); for (Map<Vector2i, TileMapCell>::Element *E = drag_modified.front(); E; E = E->next()) { - if (!erase_button->is_pressed() && E->get().source_id == -1) { - continue; - } undo_redo->add_do_method(tile_map, "set_cell", E->key(), tile_map->get_cell_source_id(E->key()), tile_map->get_cell_atlas_coords(E->key()), tile_map->get_cell_alternative_tile(E->key())); undo_redo->add_undo_method(tile_map, "set_cell", E->key(), E->get().source_id, E->get().get_atlas_coords(), E->get().alternative_tile); } @@ -1249,7 +1235,7 @@ void TileMapEditorTilesPlugin::_stop_dragging() { void TileMapEditorTilesPlugin::_update_fix_selected_and_hovered() { TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id)); if (!tile_map) { - hovered_tile.source_id = -1; + hovered_tile.source_id = TileSet::INVALID_SOURCE; hovered_tile.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS); hovered_tile.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; tile_set_selection.clear(); @@ -1260,7 +1246,7 @@ void TileMapEditorTilesPlugin::_update_fix_selected_and_hovered() { Ref<TileSet> tile_set = tile_map->get_tileset(); if (!tile_set.is_valid()) { - hovered_tile.source_id = -1; + hovered_tile.source_id = TileSet::INVALID_SOURCE; hovered_tile.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS); hovered_tile.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; tile_set_selection.clear(); @@ -1271,7 +1257,7 @@ void TileMapEditorTilesPlugin::_update_fix_selected_and_hovered() { int source_index = sources_list->get_current(); if (source_index < 0 || source_index >= sources_list->get_item_count()) { - hovered_tile.source_id = -1; + hovered_tile.source_id = TileSet::INVALID_SOURCE; hovered_tile.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS); hovered_tile.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; tile_set_selection.clear(); @@ -1287,7 +1273,7 @@ void TileMapEditorTilesPlugin::_update_fix_selected_and_hovered() { !tile_set->has_source(hovered_tile.source_id) || !tile_set->get_source(hovered_tile.source_id)->has_tile(hovered_tile.get_atlas_coords()) || !tile_set->get_source(hovered_tile.source_id)->has_alternative_tile(hovered_tile.get_atlas_coords(), hovered_tile.alternative_tile)) { - hovered_tile.source_id = -1; + hovered_tile.source_id = TileSet::INVALID_SOURCE; hovered_tile.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS); hovered_tile.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; } @@ -1403,7 +1389,7 @@ void TileMapEditorTilesPlugin::_update_tileset_selection_from_selection_pattern( TypedArray<Vector2i> used_cells = selection_pattern->get_used_cells(); for (int i = 0; i < used_cells.size(); i++) { Vector2i coords = used_cells[i]; - if (selection_pattern->get_cell_source_id(coords) != -1) { + if (selection_pattern->get_cell_source_id(coords) != TileSet::INVALID_SOURCE) { tile_set_selection.insert(TileMapCell(selection_pattern->get_cell_source_id(coords), selection_pattern->get_cell_atlas_coords(coords), selection_pattern->get_cell_alternative_tile(coords))); } } @@ -1475,7 +1461,7 @@ void TileMapEditorTilesPlugin::_tile_atlas_control_draw() { } void TileMapEditorTilesPlugin::_tile_atlas_control_mouse_exited() { - hovered_tile.source_id = -1; + hovered_tile.source_id = TileSet::INVALID_SOURCE; hovered_tile.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS); hovered_tile.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; tile_set_dragging_selection = false; @@ -1634,7 +1620,7 @@ void TileMapEditorTilesPlugin::_tile_alternatives_control_draw() { } void TileMapEditorTilesPlugin::_tile_alternatives_control_mouse_exited() { - hovered_tile.source_id = -1; + hovered_tile.source_id = TileSet::INVALID_SOURCE; hovered_tile.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS); hovered_tile.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; tile_set_dragging_selection = false; @@ -1770,7 +1756,7 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() { paint_tool_button->set_flat(true); paint_tool_button->set_toggle_mode(true); paint_tool_button->set_button_group(tool_buttons_group); - paint_tool_button->set_shortcut(ED_SHORTCUT("tiles_editor/paint_tool", "Paint", KEY_E)); + paint_tool_button->set_shortcut(ED_SHORTCUT("tiles_editor/paint_tool", "Paint", KEY_D)); paint_tool_button->connect("pressed", callable_mp(this, &TileMapEditorTilesPlugin::_update_toolbar)); tilemap_tiles_tools_buttons->add_child(paint_tool_button); @@ -1856,18 +1842,6 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() { _on_random_tile_checkbox_toggled(false); - // Wide empty separation control. - Control *h_empty_space = memnew(Control); - h_empty_space->set_h_size_flags(SIZE_EXPAND_FILL); - toolbar->add_child(h_empty_space); - - // Grid toggle. - toggle_grid_button = memnew(Button); - toggle_grid_button->set_flat(true); - toggle_grid_button->set_toggle_mode(true); - toggle_grid_button->connect("toggled", callable_mp(this, &TileMapEditorTilesPlugin::_on_grid_toggled)); - toolbar->add_child(toggle_grid_button); - // Default tool. paint_tool_button->set_pressed(true); _update_toolbar(); @@ -1897,8 +1871,8 @@ TileMapEditorTilesPlugin::TileMapEditorTilesPlugin() { sources_list->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST); sources_list->connect("item_selected", callable_mp(this, &TileMapEditorTilesPlugin::_update_fix_selected_and_hovered).unbind(1)); sources_list->connect("item_selected", callable_mp(this, &TileMapEditorTilesPlugin::_update_bottom_panel).unbind(1)); - sources_list->connect("item_selected", callable_mp(TilesEditor::get_singleton(), &TilesEditor::set_atlas_sources_lists_current)); - sources_list->connect("visibility_changed", callable_mp(TilesEditor::get_singleton(), &TilesEditor::synchronize_atlas_sources_list), varray(sources_list)); + sources_list->connect("item_selected", callable_mp(TilesEditor::get_singleton(), &TilesEditor::set_sources_lists_current)); + sources_list->connect("visibility_changed", callable_mp(TilesEditor::get_singleton(), &TilesEditor::synchronize_sources_list), varray(sources_list)); atlas_sources_split_container->add_child(sources_list); // Tile atlas source. @@ -2967,7 +2941,7 @@ void TileMapEditorTerrainsPlugin::_update_terrains_cache() { } TileMapCell empty_cell; - empty_cell.source_id = -1; + empty_cell.source_id = TileSet::INVALID_SOURCE; empty_cell.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS); empty_cell.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; per_terrain_terrains_tile_patterns_tiles[i][empty_pattern].insert(empty_cell); @@ -3189,6 +3163,9 @@ void TileMapEditor::_notification(int p_what) { case NOTIFICATION_THEME_CHANGED: missing_tile_texture = get_theme_icon(SNAME("StatusWarning"), SNAME("EditorIcons")); warning_pattern_texture = get_theme_icon(SNAME("WarningPattern"), SNAME("EditorIcons")); + advanced_menu_button->set_icon(get_theme_icon(SNAME("Tools"), SNAME("EditorIcons"))); + toggle_grid_button->set_icon(get_theme_icon(SNAME("Grid"), SNAME("EditorIcons"))); + toggle_grid_button->set_pressed(EditorSettings::get_singleton()->get("editors/tiles_editor/display_grid")); break; case NOTIFICATION_INTERNAL_PROCESS: if (is_visible_in_tree() && tileset_changed_needs_update) { @@ -3198,6 +3175,44 @@ void TileMapEditor::_notification(int p_what) { tileset_changed_needs_update = false; } break; + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: + toggle_grid_button->set_pressed(EditorSettings::get_singleton()->get("editors/tiles_editor/display_grid")); + break; + } +} + +void TileMapEditor::_on_grid_toggled(bool p_pressed) { + EditorSettings::get_singleton()->set("editors/tiles_editor/display_grid", p_pressed); +} + +void TileMapEditor::_advanced_menu_button_id_pressed(int p_id) { + TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id)); + if (!tile_map) { + return; + } + + Ref<TileSet> tile_set = tile_map->get_tileset(); + if (!tile_set.is_valid()) { + return; + } + + if (p_id == 0) { // Replace Tile Proxies + undo_redo->create_action(TTR("Replace Tiles with Proxies")); + TypedArray<Vector2i> used_cells = tile_map->get_used_cells(); + for (int i = 0; i < used_cells.size(); i++) { + Vector2i cell_coords = used_cells[i]; + TileMapCell from = tile_map->get_cell(cell_coords); + Array to_array = tile_set->map_tile_proxy(from.source_id, from.get_atlas_coords(), from.alternative_tile); + TileMapCell to; + to.source_id = to_array[0]; + to.set_atlas_coords(to_array[1]); + to.alternative_tile = to_array[2]; + if (from != to) { + undo_redo->add_do_method(tile_map, "set_cell", cell_coords, to.source_id, to.get_atlas_coords(), to.alternative_tile); + undo_redo->add_undo_method(tile_map, "set_cell", cell_coords, from.source_id, from.get_atlas_coords(), from.alternative_tile); + } + } + undo_redo->commit_action(); } } @@ -3348,7 +3363,6 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { Vector2i tile_shape_size = tile_set->get_tile_size(); // Draw tiles with invalid IDs in the grid. - float icon_ratio = MIN(missing_tile_texture->get_size().x / tile_set->get_tile_size().x, missing_tile_texture->get_size().y / tile_set->get_tile_size().y) / 3; TypedArray<Vector2i> used_cells = tile_map->get_used_cells(); for (int i = 0; i < used_cells.size(); i++) { Vector2i coords = used_cells[i]; @@ -3364,25 +3378,33 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { if (!source || !source->has_tile(tile_atlas_coords) || !source->has_alternative_tile(tile_atlas_coords, tile_alternative_tile)) { // Generate a random color from the hashed values of the tiles. - Array to_hash; - to_hash.push_back(tile_source_id); - to_hash.push_back(tile_atlas_coords); - to_hash.push_back(tile_alternative_tile); - uint32_t hash = RandomPCG(to_hash.hash()).rand(); - - Color color; - color = color.from_hsv( - (float)((hash >> 24) & 0xFF) / 256.0, - Math::lerp(0.5, 1.0, (float)((hash >> 16) & 0xFF) / 256.0), - Math::lerp(0.5, 1.0, (float)((hash >> 8) & 0xFF) / 256.0), - 0.8); - - // Draw the scaled tile. - Rect2 cell_region = xform.xform(Rect2(tile_map->map_to_world(coords) - Vector2(tile_shape_size) / 2, Vector2(tile_shape_size))); - tile_set->draw_tile_shape(p_overlay, cell_region, color, true, warning_pattern_texture); + Array a = tile_set->map_tile_proxy(tile_source_id, tile_atlas_coords, tile_alternative_tile); + if (int(a[0]) == tile_source_id && Vector2i(a[1]) == tile_atlas_coords && int(a[2]) == tile_alternative_tile) { + // Only display the pattern if we have no proxy tile. + Array to_hash; + to_hash.push_back(tile_source_id); + to_hash.push_back(tile_atlas_coords); + to_hash.push_back(tile_alternative_tile); + uint32_t hash = RandomPCG(to_hash.hash()).rand(); + + Color color; + color = color.from_hsv( + (float)((hash >> 24) & 0xFF) / 256.0, + Math::lerp(0.5, 1.0, (float)((hash >> 16) & 0xFF) / 256.0), + Math::lerp(0.5, 1.0, (float)((hash >> 8) & 0xFF) / 256.0), + 0.8); + + // Draw the scaled tile. + Rect2 cell_region = xform.xform(Rect2(tile_map->map_to_world(coords) - Vector2(tile_shape_size) / 2, Vector2(tile_shape_size))); + tile_set->draw_tile_shape(p_overlay, cell_region, color, true, warning_pattern_texture); + } // Draw the warning icon. - Rect2 rect = Rect2(xform.xform(tile_map->map_to_world(coords)) - (icon_ratio * missing_tile_texture->get_size() * xform.get_scale() / 2), icon_ratio * missing_tile_texture->get_size() * xform.get_scale()); + int min_axis = missing_tile_texture->get_size().min_axis(); + Vector2 icon_size; + icon_size[min_axis] = tile_set->get_tile_size()[min_axis] / 3; + icon_size[(min_axis + 1) % 2] = (icon_size[min_axis] * missing_tile_texture->get_size()[(min_axis + 1) % 2] / missing_tile_texture->get_size()[min_axis]); + Rect2 rect = Rect2(xform.xform(tile_map->map_to_world(coords)) - (icon_size * xform.get_scale() / 2), icon_size * xform.get_scale()); p_overlay->draw_texture_rect(missing_tile_texture, rect); } } @@ -3502,6 +3524,26 @@ TileMapEditor::TileMapEditor() { tilemap_toolbar->add_child(tile_map_editor_plugins[i]->get_toolbar()); } + // Wide empty separation control. + Control *h_empty_space = memnew(Control); + h_empty_space->set_h_size_flags(SIZE_EXPAND_FILL); + tilemap_toolbar->add_child(h_empty_space); + + // Grid toggle. + toggle_grid_button = memnew(Button); + toggle_grid_button->set_flat(true); + toggle_grid_button->set_toggle_mode(true); + toggle_grid_button->set_tooltip(TTR("Toggle grid visibility.")); + toggle_grid_button->connect("toggled", callable_mp(this, &TileMapEditor::_on_grid_toggled)); + tilemap_toolbar->add_child(toggle_grid_button); + + // Advanced settings menu button. + advanced_menu_button = memnew(MenuButton); + advanced_menu_button->set_flat(true); + advanced_menu_button->get_popup()->add_item(TTR("Automatically Replace Tiles with Proxies")); + advanced_menu_button->get_popup()->connect("id_pressed", callable_mp(this, &TileMapEditor::_advanced_menu_button_id_pressed)); + tilemap_toolbar->add_child(advanced_menu_button); + missing_tileset_label = memnew(Label); missing_tileset_label->set_text(TTR("The edited TileMap node has no TileSet resource.")); missing_tileset_label->set_h_size_flags(SIZE_EXPAND_FILL); diff --git a/editor/plugins/tiles/tile_map_editor.h b/editor/plugins/tiles/tile_map_editor.h index a6f4ec3021..236774a06b 100644 --- a/editor/plugins/tiles/tile_map_editor.h +++ b/editor/plugins/tiles/tile_map_editor.h @@ -82,9 +82,6 @@ private: void _on_random_tile_checkbox_toggled(bool p_pressed); void _on_scattering_spinbox_changed(double p_value); - Button *toggle_grid_button; - void _on_grid_toggled(bool p_pressed); - void _update_toolbar(); ///// Tilemap editing. ///// @@ -300,6 +297,7 @@ class TileMapEditor : public VBoxContainer { GDCLASS(TileMapEditor, VBoxContainer); private: + UndoRedo *undo_redo = EditorNode::get_undo_redo(); bool tileset_changed_needs_update = false; ObjectID tile_map_id; @@ -309,6 +307,12 @@ private: // Toolbar. HBoxContainer *tilemap_toolbar; + Button *toggle_grid_button; + void _on_grid_toggled(bool p_pressed); + + MenuButton *advanced_menu_button; + void _advanced_menu_button_id_pressed(int p_id); + // Bottom panel Label *missing_tileset_label; Tabs *tabs; diff --git a/editor/plugins/tiles/tile_proxies_manager_dialog.cpp b/editor/plugins/tiles/tile_proxies_manager_dialog.cpp new file mode 100644 index 0000000000..9e47a44b34 --- /dev/null +++ b/editor/plugins/tiles/tile_proxies_manager_dialog.cpp @@ -0,0 +1,476 @@ +/*************************************************************************/ +/* tile_proxies_manager_dialog.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* 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 */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "tile_proxies_manager_dialog.h" + +#include "editor/editor_scale.h" + +void TileProxiesManagerDialog::_right_clicked(int p_item, Vector2 p_local_mouse_pos, Object *p_item_list) { + ItemList *item_list = Object::cast_to<ItemList>(p_item_list); + popup_menu->set_size(Vector2(1, 1)); + popup_menu->set_position(get_position() + item_list->get_global_mouse_position()); + popup_menu->popup(); +} + +void TileProxiesManagerDialog::_menu_id_pressed(int p_id) { + if (p_id == 0) { + // Delete. + _delete_selected_bindings(); + } +} + +void TileProxiesManagerDialog::_delete_selected_bindings() { + undo_redo->create_action(TTR("Remove Tile Proxies")); + + Vector<int> source_level_selected = source_level_list->get_selected_items(); + for (int i = 0; i < source_level_selected.size(); i++) { + int key = source_level_list->get_item_metadata(source_level_selected[i]); + int val = tile_set->get_source_level_tile_proxy(key); + undo_redo->add_do_method(*tile_set, "remove_source_level_tile_proxy", key); + undo_redo->add_undo_method(*tile_set, "set_source_level_tile_proxy", key, val); + } + + Vector<int> coords_level_selected = coords_level_list->get_selected_items(); + for (int i = 0; i < coords_level_selected.size(); i++) { + Array key = coords_level_list->get_item_metadata(coords_level_selected[i]); + Array val = tile_set->get_coords_level_tile_proxy(key[0], key[1]); + undo_redo->add_do_method(*tile_set, "remove_coords_level_tile_proxy", key[0], key[1]); + undo_redo->add_undo_method(*tile_set, "set_coords_level_tile_proxy", key[0], key[1], val[0], val[1]); + } + + Vector<int> alternative_level_selected = alternative_level_list->get_selected_items(); + for (int i = 0; i < alternative_level_selected.size(); i++) { + Array key = alternative_level_list->get_item_metadata(alternative_level_selected[i]); + Array val = tile_set->get_coords_level_tile_proxy(key[0], key[1]); + undo_redo->add_do_method(*tile_set, "remove_alternative_level_tile_proxy", key[0], key[1], key[2]); + undo_redo->add_undo_method(*tile_set, "set_alternative_level_tile_proxy", key[0], key[1], key[2], val[0], val[1], val[2]); + } + undo_redo->add_do_method(this, "_update_lists"); + undo_redo->add_undo_method(this, "_update_lists"); + undo_redo->commit_action(); + + commited_actions_count += 1; +} + +void TileProxiesManagerDialog::_update_lists() { + source_level_list->clear(); + coords_level_list->clear(); + alternative_level_list->clear(); + + Array proxies = tile_set->get_source_level_tile_proxies(); + for (int i = 0; i < proxies.size(); i++) { + Array proxy = proxies[i]; + String text = vformat("%s", proxy[0]).rpad(5) + "-> " + vformat("%s", proxy[1]); + int id = source_level_list->add_item(text); + source_level_list->set_item_metadata(id, proxy[0]); + } + + proxies = tile_set->get_coords_level_tile_proxies(); + for (int i = 0; i < proxies.size(); i++) { + Array proxy = proxies[i]; + String text = vformat("%s, %s", proxy[0], proxy[1]).rpad(17) + "-> " + vformat("%s, %s", proxy[2], proxy[3]); + int id = coords_level_list->add_item(text); + coords_level_list->set_item_metadata(id, proxy.slice(0, 2)); + } + + proxies = tile_set->get_alternative_level_tile_proxies(); + for (int i = 0; i < proxies.size(); i++) { + Array proxy = proxies[i]; + String text = vformat("%s, %s, %s", proxy[0], proxy[1], proxy[2]).rpad(24) + "-> " + vformat("%s, %s, %s", proxy[3], proxy[4], proxy[5]); + int id = alternative_level_list->add_item(text); + alternative_level_list->set_item_metadata(id, proxy.slice(0, 3)); + } +} + +void TileProxiesManagerDialog::_update_enabled_property_editors() { + if (from.source_id == TileSet::INVALID_SOURCE) { + from.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS); + to.set_atlas_coords(TileSetSource::INVALID_ATLAS_COORDS); + from.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; + to.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; + coords_from_property_editor->hide(); + coords_to_property_editor->hide(); + alternative_from_property_editor->hide(); + alternative_to_property_editor->hide(); + } else if (from.get_atlas_coords().x == -1 || from.get_atlas_coords().y == -1) { + from.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; + to.alternative_tile = TileSetSource::INVALID_TILE_ALTERNATIVE; + coords_from_property_editor->show(); + coords_to_property_editor->show(); + alternative_from_property_editor->hide(); + alternative_to_property_editor->hide(); + } else { + coords_from_property_editor->show(); + coords_to_property_editor->show(); + alternative_from_property_editor->show(); + alternative_to_property_editor->show(); + } + + source_from_property_editor->update_property(); + source_to_property_editor->update_property(); + coords_from_property_editor->update_property(); + coords_to_property_editor->update_property(); + alternative_from_property_editor->update_property(); + alternative_to_property_editor->update_property(); +} + +void TileProxiesManagerDialog::_property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool p_changing) { + _set(p_path, p_value); +} + +void TileProxiesManagerDialog::_add_button_pressed() { + if (from.source_id != TileSet::INVALID_SOURCE && to.source_id != TileSet::INVALID_SOURCE) { + Vector2i from_coords = from.get_atlas_coords(); + Vector2i to_coords = to.get_atlas_coords(); + if (from_coords.x >= 0 && from_coords.y >= 0 && to_coords.x >= 0 && to_coords.y >= 0) { + if (from.alternative_tile != TileSetSource::INVALID_TILE_ALTERNATIVE && to.alternative_tile != TileSetSource::INVALID_TILE_ALTERNATIVE) { + undo_redo->create_action(TTR("Create Alternative-level Tile Proxy")); + undo_redo->add_do_method(*tile_set, "set_alternative_level_tile_proxy", from.source_id, from.get_atlas_coords(), from.alternative_tile, to.source_id, to.get_atlas_coords(), to.alternative_tile); + if (tile_set->has_alternative_level_tile_proxy(from.source_id, from.get_atlas_coords(), from.alternative_tile)) { + Array a = tile_set->get_alternative_level_tile_proxy(from.source_id, from.get_atlas_coords(), from.alternative_tile); + undo_redo->add_undo_method(*tile_set, "set_alternative_level_tile_proxy", to.source_id, to.get_atlas_coords(), to.alternative_tile, a[0], a[1], a[2]); + } else { + undo_redo->add_undo_method(*tile_set, "remove_alternative_level_tile_proxy", from.source_id, from.get_atlas_coords(), from.alternative_tile); + } + } else { + undo_redo->create_action(TTR("Create Coords-level Tile Proxy")); + undo_redo->add_do_method(*tile_set, "set_coords_level_tile_proxy", from.source_id, from.get_atlas_coords(), to.source_id, to.get_atlas_coords()); + if (tile_set->has_coords_level_tile_proxy(from.source_id, from.get_atlas_coords())) { + Array a = tile_set->get_coords_level_tile_proxy(from.source_id, from.get_atlas_coords()); + undo_redo->add_undo_method(*tile_set, "set_coords_level_tile_proxy", to.source_id, to.get_atlas_coords(), a[0], a[1]); + } else { + undo_redo->add_undo_method(*tile_set, "remove_coords_level_tile_proxy", from.source_id, from.get_atlas_coords()); + } + } + } else { + undo_redo->create_action(TTR("Create source-level Tile Proxy")); + undo_redo->add_do_method(*tile_set, "set_source_level_tile_proxy", from.source_id, to.source_id); + if (tile_set->has_source_level_tile_proxy(from.source_id)) { + undo_redo->add_undo_method(*tile_set, "set_source_level_tile_proxy", to.source_id, tile_set->get_source_level_tile_proxy(from.source_id)); + } else { + undo_redo->add_undo_method(*tile_set, "remove_source_level_tile_proxy", from.source_id); + } + } + undo_redo->add_do_method(this, "_update_lists"); + undo_redo->add_undo_method(this, "_update_lists"); + undo_redo->commit_action(); + commited_actions_count++; + } +} + +void TileProxiesManagerDialog::_clear_invalid_button_pressed() { + undo_redo->create_action(TTR("Delete All Invalid Tile Proxies")); + + undo_redo->add_do_method(*tile_set, "cleanup_invalid_tile_proxies"); + + Array proxies = tile_set->get_source_level_tile_proxies(); + for (int i = 0; i < proxies.size(); i++) { + Array proxy = proxies[i]; + undo_redo->add_undo_method(*tile_set, "set_source_level_tile_proxy", proxy[0], proxy[1]); + } + + proxies = tile_set->get_coords_level_tile_proxies(); + for (int i = 0; i < proxies.size(); i++) { + Array proxy = proxies[i]; + undo_redo->add_undo_method(*tile_set, "set_coords_level_tile_proxy", proxy[0], proxy[1], proxy[2], proxy[3]); + } + + proxies = tile_set->get_alternative_level_tile_proxies(); + for (int i = 0; i < proxies.size(); i++) { + Array proxy = proxies[i]; + undo_redo->add_undo_method(*tile_set, "set_alternative_level_tile_proxy", proxy[0], proxy[1], proxy[2], proxy[3], proxy[4], proxy[5]); + } + undo_redo->add_do_method(this, "_update_lists"); + undo_redo->add_undo_method(this, "_update_lists"); + undo_redo->commit_action(); +} + +void TileProxiesManagerDialog::_clear_all_button_pressed() { + undo_redo->create_action(TTR("Delete All Tile Proxies")); + + undo_redo->add_do_method(*tile_set, "clear_tile_proxies"); + + Array proxies = tile_set->get_source_level_tile_proxies(); + for (int i = 0; i < proxies.size(); i++) { + Array proxy = proxies[i]; + undo_redo->add_undo_method(*tile_set, "set_source_level_tile_proxy", proxy[0], proxy[1]); + } + + proxies = tile_set->get_coords_level_tile_proxies(); + for (int i = 0; i < proxies.size(); i++) { + Array proxy = proxies[i]; + undo_redo->add_undo_method(*tile_set, "set_coords_level_tile_proxy", proxy[0], proxy[1], proxy[2], proxy[3]); + } + + proxies = tile_set->get_alternative_level_tile_proxies(); + for (int i = 0; i < proxies.size(); i++) { + Array proxy = proxies[i]; + undo_redo->add_undo_method(*tile_set, "set_alternative_level_tile_proxy", proxy[0], proxy[1], proxy[2], proxy[3], proxy[4], proxy[5]); + } + undo_redo->add_do_method(this, "_update_lists"); + undo_redo->add_undo_method(this, "_update_lists"); + undo_redo->commit_action(); +} + +bool TileProxiesManagerDialog::_set(const StringName &p_name, const Variant &p_value) { + if (p_name == "from_source") { + from.source_id = MAX(int(p_value), -1); + } else if (p_name == "from_coords") { + from.set_atlas_coords(Vector2i(p_value).max(Vector2i(-1, -1))); + } else if (p_name == "from_alternative") { + from.alternative_tile = MAX(int(p_value), -1); + } else if (p_name == "to_source") { + to.source_id = MAX(int(p_value), 0); + } else if (p_name == "to_coords") { + to.set_atlas_coords(Vector2i(p_value).max(Vector2i(0, 0))); + } else if (p_name == "to_alternative") { + to.alternative_tile = MAX(int(p_value), 0); + } else { + return false; + } + _update_enabled_property_editors(); + return true; +} + +bool TileProxiesManagerDialog::_get(const StringName &p_name, Variant &r_ret) const { + if (p_name == "from_source") { + r_ret = from.source_id; + } else if (p_name == "from_coords") { + r_ret = from.get_atlas_coords(); + } else if (p_name == "from_alternative") { + r_ret = from.alternative_tile; + } else if (p_name == "to_source") { + r_ret = to.source_id; + } else if (p_name == "to_coords") { + r_ret = to.get_atlas_coords(); + } else if (p_name == "to_alternative") { + r_ret = to.alternative_tile; + } else { + return false; + } + return true; +} + +void TileProxiesManagerDialog::_unhandled_key_input(Ref<InputEvent> p_event) { + ERR_FAIL_COND(p_event.is_null()); + + if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event))) { + if (!is_inside_tree() || !is_visible()) { + return; + } + + if (popup_menu->activate_item_by_event(p_event, false)) { + set_input_as_handled(); + } + } +} + +void TileProxiesManagerDialog::cancel_pressed() { + for (int i = 0; i < commited_actions_count; i++) { + undo_redo->undo(); + } + commited_actions_count = 0; +} + +void TileProxiesManagerDialog::_bind_methods() { + ClassDB::bind_method(D_METHOD("_update_lists"), &TileProxiesManagerDialog::_update_lists); + ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &TileProxiesManagerDialog::_unhandled_key_input); +} + +void TileProxiesManagerDialog::update_tile_set(Ref<TileSet> p_tile_set) { + ERR_FAIL_COND(!p_tile_set.is_valid()); + tile_set = p_tile_set; + commited_actions_count = 0; + _update_lists(); +} + +TileProxiesManagerDialog::TileProxiesManagerDialog() { + // Tile proxy management window. + set_title(TTR("Tile Proxies Management")); + set_process_unhandled_key_input(true); + + to.source_id = 0; + to.set_atlas_coords(Vector2i()); + to.alternative_tile = 0; + + VBoxContainer *vbox_container = memnew(VBoxContainer); + vbox_container->set_h_size_flags(Control::SIZE_EXPAND_FILL); + vbox_container->set_v_size_flags(Control::SIZE_EXPAND_FILL); + add_child(vbox_container); + + Label *source_level_label = memnew(Label); + source_level_label->set_text(TTR("Source-level proxies")); + vbox_container->add_child(source_level_label); + + source_level_list = memnew(ItemList); + source_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); + source_level_list->set_select_mode(ItemList::SELECT_MULTI); + source_level_list->set_allow_rmb_select(true); + source_level_list->connect("item_rmb_selected", callable_mp(this, &TileProxiesManagerDialog::_right_clicked), varray(source_level_list)); + vbox_container->add_child(source_level_list); + + Label *coords_level_label = memnew(Label); + coords_level_label->set_text(TTR("Coords-level proxies")); + vbox_container->add_child(coords_level_label); + + coords_level_list = memnew(ItemList); + coords_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); + coords_level_list->set_select_mode(ItemList::SELECT_MULTI); + coords_level_list->set_allow_rmb_select(true); + coords_level_list->connect("item_rmb_selected", callable_mp(this, &TileProxiesManagerDialog::_right_clicked), varray(coords_level_list)); + vbox_container->add_child(coords_level_list); + + Label *alternative_level_label = memnew(Label); + alternative_level_label->set_text(TTR("Alternative-level proxies")); + vbox_container->add_child(alternative_level_label); + + alternative_level_list = memnew(ItemList); + alternative_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); + alternative_level_list->set_select_mode(ItemList::SELECT_MULTI); + alternative_level_list->set_allow_rmb_select(true); + alternative_level_list->connect("item_rmb_selected", callable_mp(this, &TileProxiesManagerDialog::_right_clicked), varray(alternative_level_list)); + vbox_container->add_child(alternative_level_list); + + popup_menu = memnew(PopupMenu); + popup_menu->add_shortcut(ED_GET_SHORTCUT("ui_text_delete")); + popup_menu->connect("id_pressed", callable_mp(this, &TileProxiesManagerDialog::_menu_id_pressed)); + add_child(popup_menu); + + // Add proxy panel. + HSeparator *h_separator = memnew(HSeparator); + vbox_container->add_child(h_separator); + + Label *add_label = memnew(Label); + add_label->set_text(TTR("Add a new tile proxy:")); + vbox_container->add_child(add_label); + + HBoxContainer *hboxcontainer = memnew(HBoxContainer); + vbox_container->add_child(hboxcontainer); + + // From + VBoxContainer *vboxcontainer_from = memnew(VBoxContainer); + vboxcontainer_from->set_h_size_flags(Control::SIZE_EXPAND_FILL); + hboxcontainer->add_child(vboxcontainer_from); + + source_from_property_editor = memnew(EditorPropertyInteger); + source_from_property_editor->set_label(TTR("From Source")); + source_from_property_editor->set_object_and_property(this, "from_source"); + source_from_property_editor->connect("property_changed", callable_mp(this, &TileProxiesManagerDialog::_property_changed)); + source_from_property_editor->set_selectable(false); + source_from_property_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); + source_from_property_editor->setup(-1, 99999, 1, true, false); + vboxcontainer_from->add_child(source_from_property_editor); + + coords_from_property_editor = memnew(EditorPropertyVector2i); + coords_from_property_editor->set_label(TTR("From Coords")); + coords_from_property_editor->set_object_and_property(this, "from_coords"); + coords_from_property_editor->connect("property_changed", callable_mp(this, &TileProxiesManagerDialog::_property_changed)); + coords_from_property_editor->set_selectable(false); + coords_from_property_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); + coords_from_property_editor->setup(-1, 99999, true); + coords_from_property_editor->hide(); + vboxcontainer_from->add_child(coords_from_property_editor); + + alternative_from_property_editor = memnew(EditorPropertyInteger); + alternative_from_property_editor->set_label(TTR("From Alternative")); + alternative_from_property_editor->set_object_and_property(this, "from_alternative"); + alternative_from_property_editor->connect("property_changed", callable_mp(this, &TileProxiesManagerDialog::_property_changed)); + alternative_from_property_editor->set_selectable(false); + alternative_from_property_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); + alternative_from_property_editor->setup(-1, 99999, 1, true, false); + alternative_from_property_editor->hide(); + vboxcontainer_from->add_child(alternative_from_property_editor); + + // To + VBoxContainer *vboxcontainer_to = memnew(VBoxContainer); + vboxcontainer_to->set_h_size_flags(Control::SIZE_EXPAND_FILL); + hboxcontainer->add_child(vboxcontainer_to); + + source_to_property_editor = memnew(EditorPropertyInteger); + source_to_property_editor->set_label(TTR("To Source")); + source_to_property_editor->set_object_and_property(this, "to_source"); + source_to_property_editor->connect("property_changed", callable_mp(this, &TileProxiesManagerDialog::_property_changed)); + source_to_property_editor->set_selectable(false); + source_to_property_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); + source_to_property_editor->setup(-1, 99999, 1, true, false); + vboxcontainer_to->add_child(source_to_property_editor); + + coords_to_property_editor = memnew(EditorPropertyVector2i); + coords_to_property_editor->set_label(TTR("To Coords")); + coords_to_property_editor->set_object_and_property(this, "to_coords"); + coords_to_property_editor->connect("property_changed", callable_mp(this, &TileProxiesManagerDialog::_property_changed)); + coords_to_property_editor->set_selectable(false); + coords_to_property_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); + coords_to_property_editor->setup(-1, 99999, true); + coords_to_property_editor->hide(); + vboxcontainer_to->add_child(coords_to_property_editor); + + alternative_to_property_editor = memnew(EditorPropertyInteger); + alternative_to_property_editor->set_label(TTR("To Alternative")); + alternative_to_property_editor->set_object_and_property(this, "to_alternative"); + alternative_to_property_editor->connect("property_changed", callable_mp(this, &TileProxiesManagerDialog::_property_changed)); + alternative_to_property_editor->set_selectable(false); + alternative_to_property_editor->set_h_size_flags(Control::SIZE_EXPAND_FILL); + alternative_to_property_editor->setup(-1, 99999, 1, true, false); + alternative_to_property_editor->hide(); + vboxcontainer_to->add_child(alternative_to_property_editor); + + Button *add_button = memnew(Button); + add_button->set_text(TTR("Add")); + add_button->set_h_size_flags(Control::SIZE_SHRINK_CENTER); + add_button->connect("pressed", callable_mp(this, &TileProxiesManagerDialog::_add_button_pressed)); + vbox_container->add_child(add_button); + + h_separator = memnew(HSeparator); + vbox_container->add_child(h_separator); + + // Generic actions. + Label *generic_actions_label = memnew(Label); + generic_actions_label->set_text(TTR("Global actions:")); + vbox_container->add_child(generic_actions_label); + + hboxcontainer = memnew(HBoxContainer); + vbox_container->add_child(hboxcontainer); + + Button *clear_invalid_button = memnew(Button); + clear_invalid_button->set_text(TTR("Clear Invalid")); + clear_invalid_button->set_h_size_flags(Control::SIZE_SHRINK_CENTER); + clear_invalid_button->connect("pressed", callable_mp(this, &TileProxiesManagerDialog::_clear_invalid_button_pressed)); + hboxcontainer->add_child(clear_invalid_button); + + Button *clear_all_button = memnew(Button); + clear_all_button->set_text(TTR("Clear All")); + clear_all_button->set_h_size_flags(Control::SIZE_SHRINK_CENTER); + clear_all_button->connect("pressed", callable_mp(this, &TileProxiesManagerDialog::_clear_all_button_pressed)); + hboxcontainer->add_child(clear_all_button); + + h_separator = memnew(HSeparator); + vbox_container->add_child(h_separator); +} diff --git a/editor/plugins/tiles/tile_proxies_manager_dialog.h b/editor/plugins/tiles/tile_proxies_manager_dialog.h new file mode 100644 index 0000000000..f6898e960b --- /dev/null +++ b/editor/plugins/tiles/tile_proxies_manager_dialog.h @@ -0,0 +1,90 @@ +/*************************************************************************/ +/* tile_proxies_manager_dialog.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* 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 */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef TILE_PROXIES_MANAGER_DIALOG_H +#define TILE_PROXIES_MANAGER_DIALOG_H + +#include "editor/editor_node.h" +#include "editor/editor_properties.h" + +#include "scene/gui/dialogs.h" +#include "scene/gui/item_list.h" +#include "scene/resources/tile_set.h" + +class TileProxiesManagerDialog : public ConfirmationDialog { + GDCLASS(TileProxiesManagerDialog, ConfirmationDialog); + +private: + int commited_actions_count = 0; + Ref<TileSet> tile_set; + + UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); + + TileMapCell from; + TileMapCell to; + + // GUI + ItemList *source_level_list; + ItemList *coords_level_list; + ItemList *alternative_level_list; + + EditorPropertyInteger *source_from_property_editor; + EditorPropertyVector2i *coords_from_property_editor; + EditorPropertyInteger *alternative_from_property_editor; + EditorPropertyInteger *source_to_property_editor; + EditorPropertyVector2i *coords_to_property_editor; + EditorPropertyInteger *alternative_to_property_editor; + + PopupMenu *popup_menu; + void _right_clicked(int p_item, Vector2 p_local_mouse_pos, Object *p_item_list); + void _menu_id_pressed(int p_id); + void _delete_selected_bindings(); + void _update_lists(); + void _update_enabled_property_editors(); + void _property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool p_changing); + void _add_button_pressed(); + + void _clear_invalid_button_pressed(); + void _clear_all_button_pressed(); + +protected: + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _unhandled_key_input(Ref<InputEvent> p_event); + virtual void cancel_pressed() override; + static void _bind_methods(); + +public: + void update_tile_set(Ref<TileSet> p_tile_set); + + TileProxiesManagerDialog(); +}; + +#endif // TILE_PROXIES_MANAGER_DIALOG_H diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index c2542aa7c0..432f48fa85 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -303,9 +303,9 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::_get_property_list(List<Pro } // Add only properties that are common to all tiles. - for (List<PLData *>::Element *E = data_list.front(); E; E = E->next()) { - if (E->get()->uses == tiles.size()) { - p_list->push_back(E->get()->property_info); + for (const PLData *E : data_list) { + if (E->uses == tiles.size()) { + p_list->push_back(E->property_info); } } } @@ -745,7 +745,7 @@ void TileSetAtlasSourceEditor::_update_atlas_view() { button->add_theme_style_override("hover", memnew(StyleBoxEmpty)); button->add_theme_style_override("focus", memnew(StyleBoxEmpty)); button->add_theme_style_override("pressed", memnew(StyleBoxEmpty)); - button->connect("pressed", callable_mp(tile_set_atlas_source, &TileSetAtlasSource::create_alternative_tile), varray(tile_id, -1)); + button->connect("pressed", callable_mp(tile_set_atlas_source, &TileSetAtlasSource::create_alternative_tile), varray(tile_id, TileSetSource::INVALID_TILE_ALTERNATIVE)); button->set_rect(Rect2(Vector2(pos.x, pos.y + (y_increment - texture_region_base_size.y) / 2.0), Vector2(texture_region_base_size_min, texture_region_base_size_min))); button->set_expand_icon(true); @@ -2055,7 +2055,7 @@ void TileSetAtlasSourceEditor::_notification(int p_what) { tools_settings_erase_button->set_icon(get_theme_icon(SNAME("Eraser"), SNAME("EditorIcons"))); - tool_advanced_menu_buttom->set_icon(get_theme_icon(SNAME("GuiTabMenu"), SNAME("EditorIcons"))); + tool_advanced_menu_buttom->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); resize_handle = get_theme_icon(SNAME("EditorHandle"), SNAME("EditorIcons")); resize_handle_disabled = get_theme_icon(SNAME("EditorHandleDisabled"), SNAME("EditorIcons")); @@ -2176,7 +2176,7 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() { // -- Dialogs -- confirm_auto_create_tiles = memnew(AcceptDialog); - confirm_auto_create_tiles->set_title(TTR("Create tiles automatically in non-transparent texture regions?")); + confirm_auto_create_tiles->set_title(TTR("Auto Create Tiles in Non-Transparent Texture Regions?")); confirm_auto_create_tiles->set_text(TTR("The atlas's texture was modified.\nWould you like to automatically create tiles in the atlas?")); confirm_auto_create_tiles->get_ok_button()->set_text(TTR("Yes")); confirm_auto_create_tiles->add_cancel_button()->set_text(TTR("No")); @@ -2202,7 +2202,7 @@ TileSetAtlasSourceEditor::TileSetAtlasSourceEditor() { tool_setup_atlas_source_button->set_toggle_mode(true); tool_setup_atlas_source_button->set_pressed(true); tool_setup_atlas_source_button->set_button_group(tools_button_group); - tool_setup_atlas_source_button->set_tooltip(TTR("Atlas Setup. Add/Remove tiles tool (use the shift key to create big tiles, control for rectangle editing).")); + tool_setup_atlas_source_button->set_tooltip(TTR("Atlas setup. Add/Remove tiles tool (use the shift key to create big tiles, control for rectangle editing).")); toolbox->add_child(tool_setup_atlas_source_button); tool_select_button = memnew(Button); diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.h b/editor/plugins/tiles/tile_set_atlas_source_editor.h index dbb0756a16..501416c340 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.h +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.h @@ -65,7 +65,7 @@ private: private: Ref<TileSet> tile_set; TileSetAtlasSource *tile_set_atlas_source = nullptr; - int source_id = -1; + int source_id = TileSet::INVALID_SOURCE; protected: bool _set(const StringName &p_name, const Variant &p_value); @@ -108,7 +108,7 @@ private: Ref<TileSet> tile_set; TileSetAtlasSource *tile_set_atlas_source = nullptr; - int tile_set_atlas_source_id = -1; + int tile_set_atlas_source_id = TileSet::INVALID_SOURCE; UndoRedo *undo_redo = EditorNode::get_undo_redo(); diff --git a/editor/plugins/tiles/tile_set_editor.cpp b/editor/plugins/tiles/tile_set_editor.cpp index 76ce6f0065..ba98a7d6b3 100644 --- a/editor/plugins/tiles/tile_set_editor.cpp +++ b/editor/plugins/tiles/tile_set_editor.cpp @@ -50,7 +50,7 @@ void TileSetEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, C if (p_from == sources_list) { // Handle dropping a texture in the list of atlas resources. - int source_id = -1; + int source_id = TileSet::INVALID_SOURCE; int added = 0; Dictionary d = p_data; Vector<String> files = d["files"]; @@ -77,7 +77,7 @@ void TileSetEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, C } // Update the selected source (thus triggering an update). - _update_atlas_sources_list(source_id); + _update_sources_list(source_id); } } @@ -114,11 +114,11 @@ bool TileSetEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_dat return false; } -void TileSetEditor::_update_atlas_sources_list(int force_selected_id) { +void TileSetEditor::_update_sources_list(int force_selected_id) { ERR_FAIL_COND(!tile_set.is_valid()); // Get the previously selected id. - int old_selected = -1; + int old_selected = TileSet::INVALID_SOURCE; if (sources_list->get_current() >= 0) { int source_id = sources_list->get_item_metadata(sources_list->get_current()); if (tile_set->has_source(source_id)) { @@ -126,7 +126,7 @@ void TileSetEditor::_update_atlas_sources_list(int force_selected_id) { } } - int to_select = -1; + int to_select = TileSet::INVALID_SOURCE; if (force_selected_id >= 0) { to_select = force_selected_id; } else if (old_selected >= 0) { @@ -200,7 +200,7 @@ void TileSetEditor::_update_atlas_sources_list(int force_selected_id) { _source_selected(sources_list->get_current()); // Synchronize the lists. - TilesEditor::get_singleton()->set_atlas_sources_lists_current(sources_list->get_current()); + TilesEditor::get_singleton()->set_sources_lists_current(sources_list->get_current()); } void TileSetEditor::_source_selected(int p_source_index) { @@ -235,6 +235,23 @@ void TileSetEditor::_source_selected(int p_source_index) { } } +void TileSetEditor::_source_delete_pressed() { + ERR_FAIL_COND(!tile_set.is_valid()); + + // Update the selected source. + int to_delete = sources_list->get_item_metadata(sources_list->get_current()); + + Ref<TileSetSource> source = tile_set->get_source(to_delete); + + // Remove the source. + undo_redo->create_action(TTR("Remove source")); + undo_redo->add_do_method(*tile_set, "remove_source", to_delete); + undo_redo->add_undo_method(*tile_set, "add_source", source, to_delete); + undo_redo->commit_action(); + + _update_sources_list(); +} + void TileSetEditor::_source_add_id_pressed(int p_id_pressed) { ERR_FAIL_COND(!tile_set.is_valid()); @@ -251,7 +268,7 @@ void TileSetEditor::_source_add_id_pressed(int p_id_pressed) { undo_redo->add_undo_method(*tile_set, "remove_source", source_id); undo_redo->commit_action(); - _update_atlas_sources_list(source_id); + _update_sources_list(source_id); } break; case 1: { int source_id = tile_set->get_next_source_id(); @@ -264,28 +281,26 @@ void TileSetEditor::_source_add_id_pressed(int p_id_pressed) { undo_redo->add_undo_method(*tile_set, "remove_source", source_id); undo_redo->commit_action(); - _update_atlas_sources_list(source_id); + _update_sources_list(source_id); } break; default: ERR_FAIL(); } } -void TileSetEditor::_source_delete_pressed() { +void TileSetEditor::_sources_advanced_menu_id_pressed(int p_id_pressed) { ERR_FAIL_COND(!tile_set.is_valid()); - // Update the selected source. - int to_delete = sources_list->get_item_metadata(sources_list->get_current()); - - Ref<TileSetSource> source = tile_set->get_source(to_delete); - - // Remove the source. - undo_redo->create_action(TTR("Remove source")); - undo_redo->add_do_method(*tile_set, "remove_source", to_delete); - undo_redo->add_undo_method(*tile_set, "add_source", source, to_delete); - undo_redo->commit_action(); - - _update_atlas_sources_list(); + switch (p_id_pressed) { + case 0: { + atlas_merging_dialog->update_tile_set(tile_set); + atlas_merging_dialog->popup_centered_ratio(0.5); + } break; + case 1: { + tile_proxies_manager_dialog->update_tile_set(tile_set); + tile_proxies_manager_dialog->popup_centered_ratio(0.5); + } break; + } } void TileSetEditor::_notification(int p_what) { @@ -294,6 +309,7 @@ void TileSetEditor::_notification(int p_what) { case NOTIFICATION_THEME_CHANGED: sources_delete_button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); sources_add_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + sources_advanced_menu_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); missing_texture_texture = get_theme_icon(SNAME("TileSet"), SNAME("EditorIcons")); break; case NOTIFICATION_INTERNAL_PROCESS: @@ -301,7 +317,7 @@ void TileSetEditor::_notification(int p_what) { if (tile_set.is_valid()) { tile_set->set_edited(true); } - _update_atlas_sources_list(); + _update_sources_list(); tile_set_changed_needs_update = false; } break; @@ -414,7 +430,7 @@ void TileSetEditor::edit(Ref<TileSet> p_tile_set) { // Add the listener again. if (tile_set.is_valid()) { tile_set->connect("changed", callable_mp(this, &TileSetEditor::_tile_set_changed)); - _update_atlas_sources_list(); + _update_sources_list(); } tile_set_atlas_source_editor->hide(); @@ -447,8 +463,8 @@ TileSetEditor::TileSetEditor() { sources_list->set_h_size_flags(SIZE_EXPAND_FILL); sources_list->set_v_size_flags(SIZE_EXPAND_FILL); sources_list->connect("item_selected", callable_mp(this, &TileSetEditor::_source_selected)); - sources_list->connect("item_selected", callable_mp(TilesEditor::get_singleton(), &TilesEditor::set_atlas_sources_lists_current)); - sources_list->connect("visibility_changed", callable_mp(TilesEditor::get_singleton(), &TilesEditor::synchronize_atlas_sources_list), varray(sources_list)); + sources_list->connect("item_selected", callable_mp(TilesEditor::get_singleton(), &TilesEditor::set_sources_lists_current)); + sources_list->connect("visibility_changed", callable_mp(TilesEditor::get_singleton(), &TilesEditor::synchronize_sources_list), varray(sources_list)); sources_list->set_texture_filter(CanvasItem::TEXTURE_FILTER_NEAREST); sources_list->set_drag_forwarding(this); split_container_left_side->add_child(sources_list); @@ -470,6 +486,19 @@ TileSetEditor::TileSetEditor() { sources_add_button->get_popup()->connect("id_pressed", callable_mp(this, &TileSetEditor::_source_add_id_pressed)); sources_bottom_actions->add_child(sources_add_button); + sources_advanced_menu_button = memnew(MenuButton); + sources_advanced_menu_button->set_flat(true); + sources_advanced_menu_button->get_popup()->add_item(TTR("Open Atlas Merging Tool")); + sources_advanced_menu_button->get_popup()->add_item(TTR("Manage Tile Proxies")); + sources_advanced_menu_button->get_popup()->connect("id_pressed", callable_mp(this, &TileSetEditor::_sources_advanced_menu_id_pressed)); + sources_bottom_actions->add_child(sources_advanced_menu_button); + + atlas_merging_dialog = memnew(AtlasMergingDialog); + add_child(atlas_merging_dialog); + + tile_proxies_manager_dialog = memnew(TileProxiesManagerDialog); + add_child(tile_proxies_manager_dialog); + // Right side container. VBoxContainer *split_container_right_side = memnew(VBoxContainer); split_container_right_side->set_h_size_flags(SIZE_EXPAND_FILL); @@ -489,7 +518,7 @@ TileSetEditor::TileSetEditor() { tile_set_atlas_source_editor = memnew(TileSetAtlasSourceEditor); tile_set_atlas_source_editor->set_h_size_flags(SIZE_EXPAND_FILL); tile_set_atlas_source_editor->set_v_size_flags(SIZE_EXPAND_FILL); - tile_set_atlas_source_editor->connect("source_id_changed", callable_mp(this, &TileSetEditor::_update_atlas_sources_list)); + tile_set_atlas_source_editor->connect("source_id_changed", callable_mp(this, &TileSetEditor::_update_sources_list)); split_container_right_side->add_child(tile_set_atlas_source_editor); tile_set_atlas_source_editor->hide(); @@ -497,7 +526,7 @@ TileSetEditor::TileSetEditor() { tile_set_scenes_collection_source_editor = memnew(TileSetScenesCollectionSourceEditor); tile_set_scenes_collection_source_editor->set_h_size_flags(SIZE_EXPAND_FILL); tile_set_scenes_collection_source_editor->set_v_size_flags(SIZE_EXPAND_FILL); - tile_set_scenes_collection_source_editor->connect("source_id_changed", callable_mp(this, &TileSetEditor::_update_atlas_sources_list)); + tile_set_scenes_collection_source_editor->connect("source_id_changed", callable_mp(this, &TileSetEditor::_update_sources_list)); split_container_right_side->add_child(tile_set_scenes_collection_source_editor); tile_set_scenes_collection_source_editor->hide(); diff --git a/editor/plugins/tiles/tile_set_editor.h b/editor/plugins/tiles/tile_set_editor.h index 9e50aca62f..970e3fabb6 100644 --- a/editor/plugins/tiles/tile_set_editor.h +++ b/editor/plugins/tiles/tile_set_editor.h @@ -31,8 +31,10 @@ #ifndef TILE_SET_EDITOR_H #define TILE_SET_EDITOR_H +#include "atlas_merging_dialog.h" #include "scene/gui/box_container.h" #include "scene/resources/tile_set.h" +#include "tile_proxies_manager_dialog.h" #include "tile_set_atlas_source_editor.h" #include "tile_set_scenes_collection_source_editor.h" @@ -51,16 +53,21 @@ private: UndoRedo *undo_redo = EditorNode::get_undo_redo(); - void _update_atlas_sources_list(int force_selected_id = -1); + void _update_sources_list(int force_selected_id = -1); - // -- Sources management -- + // Sources management. Button *sources_delete_button; MenuButton *sources_add_button; + MenuButton *sources_advanced_menu_button; ItemList *sources_list; Ref<Texture2D> missing_texture_texture; void _source_selected(int p_source_index); - void _source_add_id_pressed(int p_id_pressed); void _source_delete_pressed(); + void _source_add_id_pressed(int p_id_pressed); + void _sources_advanced_menu_id_pressed(int p_id_pressed); + + AtlasMergingDialog *atlas_merging_dialog; + TileProxiesManagerDialog *tile_proxies_manager_dialog; void _tile_set_changed(); diff --git a/editor/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp index 339efc7b99..79b869b511 100644 --- a/editor/plugins/tiles/tiles_editor_plugin.cpp +++ b/editor/plugins/tiles/tiles_editor_plugin.cpp @@ -118,11 +118,11 @@ void TilesEditor::_update_editors() { CanvasItemEditor::get_singleton()->update_viewport(); } -void TilesEditor::set_atlas_sources_lists_current(int p_current) { +void TilesEditor::set_sources_lists_current(int p_current) { atlas_sources_lists_current = p_current; } -void TilesEditor::synchronize_atlas_sources_list(Object *p_current) { +void TilesEditor::synchronize_sources_list(Object *p_current) { ItemList *item_list = Object::cast_to<ItemList>(p_current); ERR_FAIL_COND(!item_list); diff --git a/editor/plugins/tiles/tiles_editor_plugin.h b/editor/plugins/tiles/tiles_editor_plugin.h index 6cc6f51598..f976d68938 100644 --- a/editor/plugins/tiles/tiles_editor_plugin.h +++ b/editor/plugins/tiles/tiles_editor_plugin.h @@ -76,8 +76,8 @@ public: void forward_canvas_draw_over_viewport(Control *p_overlay) { tilemap_editor->forward_canvas_draw_over_viewport(p_overlay); } // To synchronize the atlas sources lists. - void set_atlas_sources_lists_current(int p_current); - void synchronize_atlas_sources_list(Object *p_current); + void set_sources_lists_current(int p_current); + void synchronize_sources_list(Object *p_current); void set_atlas_view_transform(float p_zoom, Vector2 p_scroll); void synchronize_atlas_view(Object *p_current); diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp index 25b08a1509..5804f54649 100644 --- a/editor/plugins/version_control_editor_plugin.cpp +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -164,7 +164,7 @@ void VersionControlEditorPlugin::_refresh_stage_area() { _refresh_file_diff(); } } - commit_status->set_text("New changes detected"); + commit_status->set_text(TTR("New changes detected")); } } else { WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu."); @@ -270,9 +270,9 @@ void VersionControlEditorPlugin::_clear_file_diff() { void VersionControlEditorPlugin::_update_stage_status() { String status; if (staged_files_count == 1) { - status = "Stage contains 1 file"; + status = TTR("Stage contains 1 file"); } else { - status = "Stage contains " + String::num_int64(staged_files_count) + " files"; + status = vformat(TTR("Stage contains %d files"), staged_files_count); } commit_status->set_text(status); } @@ -280,9 +280,9 @@ void VersionControlEditorPlugin::_update_stage_status() { void VersionControlEditorPlugin::_update_commit_status() { String status; if (staged_files_count == 1) { - status = "Committed 1 file"; + status = TTR("Committed 1 file"); } else { - status = "Committed " + String::num_int64(staged_files_count) + " files "; + status = vformat(TTR("Committed %d files"), staged_files_count); } commit_status->set_text(status); staged_files_count = 0; diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index f49279aa33..add75d47fd 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -666,8 +666,8 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { if (valid_left) { name_left = vsnode->get_input_port_name(i); port_left = vsnode->get_input_port_type(i); - for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) { - if (E->get().to_node == p_id && E->get().to_port == j) { + for (const VisualShader::Connection &E : connections) { + if (E.to_node == p_id && E.to_port == j) { port_left_used = true; } } @@ -899,11 +899,11 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { expression_box->set_syntax_highlighter(expression_syntax_highlighter); expression_box->add_theme_color_override("background_color", background_color); - for (List<String>::Element *E = VisualShaderEditor::get_singleton()->keyword_list.front(); E; E = E->next()) { - if (ShaderLanguage::is_control_flow_keyword(E->get())) { - expression_syntax_highlighter->add_keyword_color(E->get(), control_flow_keyword_color); + for (const String &E : VisualShaderEditor::get_singleton()->keyword_list) { + if (ShaderLanguage::is_control_flow_keyword(E)) { + expression_syntax_highlighter->add_keyword_color(E, control_flow_keyword_color); } else { - expression_syntax_highlighter->add_keyword_color(E->get(), keyword_color); + expression_syntax_highlighter->add_keyword_color(E, keyword_color); } } @@ -961,7 +961,7 @@ void VisualShaderGraphPlugin::connect_nodes(VisualShader::Type p_type, int p_fro void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { if (visual_shader->get_shader_type() == p_type) { VisualShaderEditor::get_singleton()->graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port); - for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) { + for (const List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) { if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { connections.erase(E); break; @@ -1470,11 +1470,11 @@ void VisualShaderEditor::_update_graph() { graph_plugin->make_dirty(false); - for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) { - int from = E->get().from_node; - int from_idx = E->get().from_port; - int to = E->get().to_node; - int to_idx = E->get().to_port; + for (const VisualShader::Connection &E : connections) { + int from = E.from_node; + int from_idx = E.from_port; + int to = E.to_node; + int to_idx = E.to_port; graph->connect_node(itos(from), from_idx, itos(to), to_idx); } @@ -1634,11 +1634,11 @@ void VisualShaderEditor::_expand_output_port(int p_node, int p_port, bool p_expa List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); - for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - int from_node = E->get().from_node; - int from_port = E->get().from_port; - int to_node = E->get().to_node; - int to_port = E->get().to_port; + for (const VisualShader::Connection &E : conns) { + int from_node = E.from_node; + int from_port = E.from_port; + int to_node = E.to_node; + int to_port = E.to_port; if (from_node == p_node) { if (p_expand) { @@ -1708,11 +1708,11 @@ void VisualShaderEditor::_remove_input_port(int p_node, int p_port) { List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); - for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - int from_node = E->get().from_node; - int from_port = E->get().from_port; - int to_node = E->get().to_node; - int to_port = E->get().to_port; + for (const VisualShader::Connection &E : conns) { + int from_node = E.from_node; + int from_port = E.from_port; + int to_node = E.to_node; + int to_port = E.to_port; if (to_node == p_node) { if (to_port == p_port) { @@ -1757,11 +1757,11 @@ void VisualShaderEditor::_remove_output_port(int p_node, int p_port) { List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); - for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - int from_node = E->get().from_node; - int from_port = E->get().from_port; - int to_node = E->get().to_node; - int to_port = E->get().to_port; + for (const VisualShader::Connection &E : conns) { + int from_node = E.from_node; + int from_port = E.from_port; + int to_node = E.to_node; + int to_port = E.to_port; if (from_node == p_node) { if (from_port == p_port) { @@ -2518,11 +2518,11 @@ void VisualShaderEditor::_nodes_dragged() { undo_redo->create_action(TTR("Node(s) Moved")); - for (List<DragOp>::Element *E = drag_buffer.front(); E; E = E->next()) { - undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", E->get().type, E->get().node, E->get().to); - undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", E->get().type, E->get().node, E->get().from); - undo_redo->add_do_method(graph_plugin.ptr(), "set_node_position", E->get().type, E->get().node, E->get().to); - undo_redo->add_undo_method(graph_plugin.ptr(), "set_node_position", E->get().type, E->get().node, E->get().from); + for (const DragOp &E : drag_buffer) { + undo_redo->add_do_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.to); + undo_redo->add_undo_method(visual_shader.ptr(), "set_node_position", E.type, E.node, E.from); + undo_redo->add_do_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.to); + undo_redo->add_undo_method(graph_plugin.ptr(), "set_node_position", E.type, E.node, E.from); } drag_buffer.clear(); @@ -2544,12 +2544,12 @@ void VisualShaderEditor::_connection_request(const String &p_from, int p_from_in List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); - for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - if (E->get().to_node == to && E->get().to_port == p_to_index) { - undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); + for (const VisualShader::Connection &E : conns) { + if (E.to_node == to && E.to_port == p_to_index) { + undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); } } @@ -2597,22 +2597,22 @@ void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) { List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); - for (const List<int>::Element *F = p_nodes.front(); F; F = F->next()) { - for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - if (E->get().from_node == F->get() || E->get().to_node == F->get()) { - undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); + for (const int &F : p_nodes) { + for (const VisualShader::Connection &E : conns) { + if (E.from_node == F || E.to_node == F) { + undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); } } } Set<String> uniform_names; - for (const List<int>::Element *F = p_nodes.front(); F; F = F->next()) { - Ref<VisualShaderNode> node = visual_shader->get_node(type, F->get()); + for (const int &F : p_nodes) { + Ref<VisualShaderNode> node = visual_shader->get_node(type, F); - undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F->get()); - undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F->get()), F->get()); - undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F->get()); + undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F); + undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F), F); + undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F); undo_redo->add_do_method(this, "_clear_buffer"); undo_redo->add_undo_method(this, "_clear_buffer"); @@ -2638,28 +2638,28 @@ void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) { } List<VisualShader::Connection> used_conns; - for (const List<int>::Element *F = p_nodes.front(); F; F = F->next()) { - for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - if (E->get().from_node == F->get() || E->get().to_node == F->get()) { + for (const int &F : p_nodes) { + for (const VisualShader::Connection &E : conns) { + if (E.from_node == F || E.to_node == F) { bool cancel = false; for (List<VisualShader::Connection>::Element *R = used_conns.front(); R; R = R->next()) { - if (R->get().from_node == E->get().from_node && R->get().from_port == E->get().from_port && R->get().to_node == E->get().to_node && R->get().to_port == E->get().to_port) { + if (R->get().from_node == E.from_node && R->get().from_port == E.from_port && R->get().to_node == E.to_node && R->get().to_port == E.to_port) { cancel = true; // to avoid ERR_ALREADY_EXISTS warning break; } } if (!cancel) { - undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - used_conns.push_back(E->get()); + undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + used_conns.push_back(E); } } } } // delete nodes from the graph - for (const List<int>::Element *F = p_nodes.front(); F; F = F->next()) { - undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, F->get()); + for (const int &F : p_nodes) { + undo_redo->add_do_method(graph_plugin.ptr(), "remove_node", type, F); } // update uniform refs if any uniform has been deleted @@ -3094,11 +3094,11 @@ void VisualShaderEditor::_notification(int p_what) { preview_text->add_theme_color_override("background_color", background_color); - for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) { - if (ShaderLanguage::is_control_flow_keyword(E->get())) { - syntax_highlighter->add_keyword_color(E->get(), control_flow_keyword_color); + for (const String &E : keyword_list) { + if (ShaderLanguage::is_control_flow_keyword(E)) { + syntax_highlighter->add_keyword_color(E, control_flow_keyword_color); } else { - syntax_highlighter->add_keyword_color(E->get(), keyword_color); + syntax_highlighter->add_keyword_color(E, keyword_color); } } @@ -3206,9 +3206,9 @@ void VisualShaderEditor::_dup_paste_nodes(int p_type, int p_pasted_type, List<in Map<int, int> connection_remap; Set<int> unsupported_set; - for (List<int>::Element *E = r_nodes.front(); E; E = E->next()) { - connection_remap[E->get()] = id_from; - Ref<VisualShaderNode> node = visual_shader->get_node(pasted_type, E->get()); + for (int &E : r_nodes) { + connection_remap[E] = id_from; + Ref<VisualShaderNode> node = visual_shader->get_node(pasted_type, E); bool unsupported = false; for (int i = 0; i < add_options.size(); i++) { @@ -3220,13 +3220,13 @@ void VisualShaderEditor::_dup_paste_nodes(int p_type, int p_pasted_type, List<in } } if (unsupported) { - unsupported_set.insert(E->get()); + unsupported_set.insert(E); continue; } Ref<VisualShaderNode> dupli = node->duplicate(); - undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, dupli, visual_shader->get_node_position(pasted_type, E->get()) + p_offset, id_from); + undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, dupli, visual_shader->get_node_position(pasted_type, E) + p_offset, id_from); undo_redo->add_do_method(graph_plugin.ptr(), "add_node", type, id_from); // duplicate size, inputs and outputs if node is group @@ -3249,19 +3249,19 @@ void VisualShaderEditor::_dup_paste_nodes(int p_type, int p_pasted_type, List<in List<VisualShader::Connection> conns; visual_shader->get_node_connections(pasted_type, &conns); - for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - if (unsupported_set.has(E->get().from_node) || unsupported_set.has(E->get().to_node)) { + for (const VisualShader::Connection &E : conns) { + if (unsupported_set.has(E.from_node) || unsupported_set.has(E.to_node)) { continue; } - if (connection_remap.has(E->get().from_node) && connection_remap.has(E->get().to_node)) { - undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, connection_remap[E->get().from_node], E->get().from_port, connection_remap[E->get().to_node], E->get().to_port); - undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, connection_remap[E->get().from_node], E->get().from_port, connection_remap[E->get().to_node], E->get().to_port); - undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, connection_remap[E->get().from_node], E->get().from_port, connection_remap[E->get().to_node], E->get().to_port); + if (connection_remap.has(E.from_node) && connection_remap.has(E.to_node)) { + undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, connection_remap[E.from_node], E.from_port, connection_remap[E.to_node], E.to_port); + undo_redo->add_do_method(graph_plugin.ptr(), "connect_nodes", type, connection_remap[E.from_node], E.from_port, connection_remap[E.to_node], E.to_port); + undo_redo->add_undo_method(graph_plugin.ptr(), "disconnect_nodes", type, connection_remap[E.from_node], E.from_port, connection_remap[E.to_node], E.to_port); } } id_from = base_id; - for (List<int>::Element *E = r_nodes.front(); E; E = E->next()) { + for (int i = 0; i < r_nodes.size(); i++) { undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_from); undo_redo->add_undo_method(graph_plugin.ptr(), "remove_node", type, id_from); id_from++; @@ -3399,17 +3399,17 @@ void VisualShaderEditor::_input_select_item(Ref<VisualShaderNodeInput> p_input, if (type_changed) { List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); - for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - if (E->get().from_node == id) { - if (visual_shader->is_port_types_compatible(p_input->get_input_type_by_name(p_name), visual_shader->get_node(type, E->get().to_node)->get_input_port_type(E->get().to_port))) { - undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); + for (const VisualShader::Connection &E : conns) { + if (E.from_node == id) { + if (visual_shader->is_port_types_compatible(p_input->get_input_type_by_name(p_name), visual_shader->get_node(type, E.to_node)->get_input_port_type(E.to_port))) { + undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); continue; } - undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); + undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); } } } @@ -3445,15 +3445,15 @@ void VisualShaderEditor::_uniform_select_item(Ref<VisualShaderNodeUniformRef> p_ if (type_changed) { List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); - for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - if (E->get().from_node == id) { - if (visual_shader->is_port_types_compatible(p_uniform_ref->get_uniform_type_by_name(p_name), visual_shader->get_node(type, E->get().to_node)->get_input_port_type(E->get().to_port))) { + for (const VisualShader::Connection &E : conns) { + if (E.from_node == id) { + if (visual_shader->is_port_types_compatible(p_uniform_ref->get_uniform_type_by_name(p_name), visual_shader->get_node(type, E.to_node)->get_input_port_type(E.to_port))) { continue; } - undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); - undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); + undo_redo->add_do_method(visual_shader.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_do_method(graph_plugin.ptr(), "disconnect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); + undo_redo->add_undo_method(graph_plugin.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); } } } @@ -4697,7 +4697,7 @@ public: UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); updating = true; - undo_redo->create_action(TTR("Edit Visual Property") + ": " + p_property, UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Edit Visual Property:") + " " + p_property, UndoRedo::MERGE_ENDS); undo_redo->add_do_property(node.ptr(), p_property, p_value); undo_redo->add_undo_property(node.ptr(), p_property, node->get(p_property)); @@ -4825,10 +4825,10 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par Vector<PropertyInfo> pinfo; - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { + for (const PropertyInfo &E : props) { for (int i = 0; i < properties.size(); i++) { - if (E->get().name == String(properties[i])) { - pinfo.push_back(E->get()); + if (E.name == String(properties[i])) { + pinfo.push_back(E); } } } @@ -4894,9 +4894,9 @@ void EditorPropertyShaderMode::_option_selected(int p_which) { VisualShader::Type type = VisualShader::Type(i); List<VisualShader::Connection> conns; visual_shader->get_node_connections(type, &conns); - for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { - if (E->get().to_node == VisualShader::NODE_ID_OUTPUT) { - undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); + for (const VisualShader::Connection &E : conns) { + if (E.to_node == VisualShader::NODE_ID_OUTPUT) { + undo_redo->add_undo_method(visual_shader.ptr(), "connect_nodes", type, E.from_node, E.from_port, E.to_node, E.to_port); } } } @@ -4918,9 +4918,9 @@ void EditorPropertyShaderMode::_option_selected(int p_which) { List<PropertyInfo> props; visual_shader->get_property_list(&props); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (E->get().name.begins_with("flags/") || E->get().name.begins_with("modes/")) { - undo_redo->add_undo_property(visual_shader.ptr(), E->get().name, visual_shader->get(E->get().name)); + for (const PropertyInfo &E : props) { + if (E.name.begins_with("flags/") || E.name.begins_with("modes/")) { + undo_redo->add_undo_property(visual_shader.ptr(), E.name, visual_shader->get(E.name)); } } @@ -5024,8 +5024,8 @@ void VisualShaderNodePortPreview::_shader_changed() { if (src_mat && src_mat->get_shader().is_valid()) { List<PropertyInfo> params; src_mat->get_shader()->get_param_list(¶ms); - for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { - material->set(E->get().name, src_mat->get(E->get().name)); + for (const PropertyInfo &E : params) { + material->set(E.name, src_mat->get(E.name)); } } } diff --git a/editor/project_export.cpp b/editor/project_export.cpp index b8e1613fca..14158b02c8 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -340,8 +340,8 @@ void ProjectExportDialog::_update_feature_list() { } } - for (List<String>::Element *E = features.front(); E; E = E->next()) { - fset.insert(E->get()); + for (const String &E : features) { + fset.insert(E); } custom_feature_display->clear(); @@ -567,8 +567,8 @@ void ProjectExportDialog::_duplicate_preset() { preset->set_exclude_filter(current->get_exclude_filter()); preset->set_custom_features(current->get_custom_features()); - for (const List<PropertyInfo>::Element *E = current->get_properties().front(); E; E = E->next()) { - preset->set(E->get().name, current->get(E->get().name)); + for (const PropertyInfo &E : current->get_properties()) { + preset->set(E.name, current->get(E.name)); } EditorExport::get_singleton()->add_export_preset(preset); @@ -1153,7 +1153,7 @@ ProjectExportDialog::ProjectExportDialog() { enc_directory = memnew(CheckButton); enc_directory->connect("toggled", callable_mp(this, &ProjectExportDialog::_enc_directory_changed)); - enc_directory->set_text("Encrypt Index (File Names and Info)"); + enc_directory->set_text(TTR("Encrypt Index (File Names and Info)")); sec_vb->add_child(enc_directory); enc_in_filters = memnew(LineEdit); @@ -1171,7 +1171,7 @@ ProjectExportDialog::ProjectExportDialog() { script_key = memnew(LineEdit); script_key->connect("text_changed", callable_mp(this, &ProjectExportDialog::_script_encryption_key_changed)); script_key_error = memnew(Label); - script_key_error->set_text("- " + TTR("Invalid Encryption Key (must be 64 hexadecimal characters long)")); + script_key_error->set_text(String::utf8("• ") + TTR("Invalid Encryption Key (must be 64 hexadecimal characters long)")); script_key_error->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("error_color"), SNAME("Editor"))); sec_vb->add_margin_child(TTR("Encryption Key (256-bits as hexadecimal):"), script_key); sec_vb->add_child(script_key_error); @@ -1219,7 +1219,7 @@ ProjectExportDialog::ProjectExportDialog() { export_all_dialog = memnew(ConfirmationDialog); add_child(export_all_dialog); - export_all_dialog->set_title("Export All"); + export_all_dialog->set_title(TTR("Export All")); export_all_dialog->set_text(TTR("Choose an export mode:")); export_all_dialog->get_ok_button()->hide(); export_all_dialog->add_button(TTR("Debug"), true, "debug"); @@ -1250,10 +1250,10 @@ ProjectExportDialog::ProjectExportDialog() { Label *export_error2 = memnew(Label); export_templates_error->add_child(export_error2); export_error2->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("error_color"), SNAME("Editor"))); - export_error2->set_text(" - " + TTR("Export templates for this platform are missing:") + " "); + export_error2->set_text(String::utf8("• ") + TTR("Export templates for this platform are missing:") + " "); error_dialog = memnew(AcceptDialog); - error_dialog->set_title("Error"); + error_dialog->set_title(TTR("Error")); error_dialog->set_text(TTR("Export templates for this platform are missing/corrupted:") + " "); main_vb->add_child(error_dialog); error_dialog->hide(); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 46a1253ca0..8d425a1e51 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -474,13 +474,7 @@ private: return; } ProjectSettings::CustomMap initial_settings; - if (rasterizer_button_group->get_pressed_button()->get_meta("driver_name") == "Vulkan") { - initial_settings["rendering/driver/driver_name"] = "Vulkan"; - } else { - initial_settings["rendering/driver/driver_name"] = "GLES2"; - initial_settings["rendering/textures/vram_compression/import_etc2"] = false; - initial_settings["rendering/textures/vram_compression/import_etc"] = true; - } + initial_settings["rendering/vulkan/rendering/back_end"] = rasterizer_button_group->get_pressed_button()->get_meta(SNAME("driver_name")); initial_settings["application/config/name"] = project_name->get_text().strip_edges(); initial_settings["application/config/icon"] = "res://icon.png"; initial_settings["rendering/environment/defaults/default_environment"] = "res://default_env.tres"; @@ -494,13 +488,13 @@ private: if (!f) { set_message(TTR("Couldn't create project.godot in project path."), MESSAGE_ERROR); } else { - f->store_line("[gd_resource type=\"Environment\" load_steps=2 format=2]"); + f->store_line("[gd_resource type=\"Environment\" load_steps=2 format=3]"); f->store_line(""); - f->store_line("[sub_resource type=\"Sky\" id=1]"); + f->store_line("[sub_resource type=\"Sky\" id=\"1\"]"); f->store_line(""); f->store_line("[resource]"); f->store_line("background_mode = 2"); - f->store_line("sky = SubResource( 1 )"); + f->store_line("sky = SubResource( \"1\" )"); memdelete(f); } } @@ -869,37 +863,36 @@ public: rshb->add_child(rvb); Button *rs_button = memnew(CheckBox); rs_button->set_button_group(rasterizer_button_group); - rs_button->set_text(TTR("Vulkan")); - rs_button->set_meta("driver_name", "Vulkan"); + rs_button->set_text(TTR("Vulkan Clustered")); + rs_button->set_meta(SNAME("driver_name"), 0); // Vulkan backend "Forward Clustered" rs_button->set_pressed(true); rvb->add_child(rs_button); l = memnew(Label); - l->set_text(TTR("- Higher visual quality\n- More accurate API, which produces very fast code\n- Some features not implemented yet - work in progress\n- Incompatible with older hardware\n- Not recommended for web and mobile games")); + l->set_text( + String::utf8("• ") + TTR("Supports desktop platforms only.") + + String::utf8("\n• ") + TTR("Advanced 3D graphics available.") + + String::utf8("\n• ") + TTR("Can scale to large complex scenes.") + + String::utf8("\n• ") + TTR("Slower rendering of simple scenes.")); l->set_modulate(Color(1, 1, 1, 0.7)); rvb->add_child(l); rshb->add_child(memnew(VSeparator)); - const String gles2_unsupported_tooltip = - TTR("The GLES2 renderer is currently unavailable, as it needs to be reworked for Godot 4.0.\nUse Godot 3.2 if you need GLES2 support."); - rvb = memnew(VBoxContainer); rvb->set_h_size_flags(Control::SIZE_EXPAND_FILL); rshb->add_child(rvb); rs_button = memnew(CheckBox); rs_button->set_button_group(rasterizer_button_group); - rs_button->set_text(TTR("OpenGL ES 2.0 (currently unavailable)")); - rs_button->set_meta("driver_name", "GLES2"); - rs_button->set_disabled(true); - rs_button->set_tooltip(gles2_unsupported_tooltip); + rs_button->set_text(TTR("Vulkan Mobile")); + rs_button->set_meta(SNAME("driver_name"), 1); // Vulkan backend "Forward Mobile" rvb->add_child(rs_button); l = memnew(Label); - l->set_text(TTR("- Lower visual quality\n- Some features not available\n- Works on most hardware\n- Recommended for web and mobile games")); + l->set_text( + String::utf8("• ") + TTR("Supports desktop + mobile platforms.") + + String::utf8("\n• ") + TTR("Less advanced 3D graphics.") + + String::utf8("\n• ") + TTR("Less scalable for complex scenes.") + + String::utf8("\n• ") + TTR("Faster rendering of simple scenes.")); l->set_modulate(Color(1, 1, 1, 0.7)); - // Also set the tooltip on the label so it appears when hovering either the checkbox or label. - l->set_tooltip(gles2_unsupported_tooltip); - // Required for the tooltip to show. - l->set_mouse_filter(Control::MOUSE_FILTER_STOP); rvb->add_child(l); l = memnew(Label); @@ -1238,16 +1231,16 @@ void ProjectList::load_projects() { Set<String> favorites; // Find favourites... - for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { - String property_key = E->get().name; + for (const PropertyInfo &E : properties) { + String property_key = E.name; if (property_key.begins_with("favorite_projects/")) { favorites.insert(property_key); } } - for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { + for (const PropertyInfo &E : properties) { // This is actually something like "projects/C:::Documents::Godot::Projects::MyGame" - String property_key = E->get().name; + String property_key = E.name; if (!property_key.begins_with("projects/")) { continue; } @@ -1582,8 +1575,8 @@ int ProjectList::refresh_project(const String &dir_path) { String favorite_property_key = "favorite_projects/" + project_key; bool found = false; - for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { - String prop = E->get().name; + for (const PropertyInfo &E : properties) { + String prop = E.name; if (!found && prop == property_key) { found = true; } else if (!is_favourite && prop == favorite_property_key) { @@ -2188,9 +2181,9 @@ void ProjectManager::_scan_begin(const String &p_base) { _scan_dir(p_base, &projects); print_line("Found " + itos(projects.size()) + " projects."); - for (List<String>::Element *E = projects.front(); E; E = E->next()) { - String proj = get_project_key_from_path(E->get()); - EditorSettings::get_singleton()->set("projects/" + proj, E->get()); + for (const String &E : projects) { + String proj = get_project_key_from_path(E); + EditorSettings::get_singleton()->set("projects/" + proj, E); } EditorSettings::get_singleton()->save(); _load_recent_projects(); @@ -2625,8 +2618,7 @@ ProjectManager::ProjectManager() { Vector<String> editor_languages; List<PropertyInfo> editor_settings_properties; EditorSettings::get_singleton()->get_property_list(&editor_settings_properties); - for (List<PropertyInfo>::Element *E = editor_settings_properties.front(); E; E = E->next()) { - PropertyInfo &pi = E->get(); + for (const PropertyInfo &pi : editor_settings_properties) { if (pi.name == "interface/editor/editor_language") { editor_languages = pi.hint_string.split(","); break; diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 2c4b28e13d..b8ccab78dd 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -229,16 +229,16 @@ void ProjectSettingsEditor::_add_feature_overrides() { for (int i = 0; i < ee->get_export_platform_count(); i++) { List<String> p; ee->get_export_platform(i)->get_platform_features(&p); - for (List<String>::Element *E = p.front(); E; E = E->next()) { - presets.insert(E->get()); + for (const String &E : p) { + presets.insert(E); } } for (int i = 0; i < ee->get_export_preset_count(); i++) { List<String> p; ee->get_export_preset(i)->get_platform()->get_preset_features(ee->get_export_preset(i), &p); - for (List<String>::Element *E = p.front(); E; E = E->next()) { - presets.insert(E->get()); + for (const String &E : p) { + presets.insert(E); } String custom = ee->get_export_preset(i)->get_custom_features(); @@ -391,8 +391,7 @@ void ProjectSettingsEditor::_action_reordered(const String &p_action_name, const undo_redo->create_action(TTR("Update Input Action Order")); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - PropertyInfo prop = E->get(); + for (const PropertyInfo &prop : props) { // Skip builtins and non-inputs if (ProjectSettings::get_singleton()->is_builtin_setting(prop.name) || !prop.name.begins_with("input/")) { continue; @@ -445,8 +444,8 @@ void ProjectSettingsEditor::_update_action_map_editor() { ProjectSettings::get_singleton()->get_property_list(&props); const Ref<Texture2D> builtin_icon = get_theme_icon(SNAME("PinPressed"), SNAME("EditorIcons")); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - const String property_name = E->get().name; + for (const PropertyInfo &E : props) { + const String property_name = E.name; if (!property_name.begins_with("input/")) { continue; diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index db8334b485..7338588d56 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -143,8 +143,8 @@ void CustomPropertyEditor::_menu_option(int p_which) { } Set<String> valid_extensions; - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - valid_extensions.insert(E->get()); + for (const String &E : extensions) { + valid_extensions.insert(E); } file->clear_filters(); @@ -179,9 +179,8 @@ void CustomPropertyEditor::_menu_option(int p_which) { res_orig->get_property_list(&property_list); List<Pair<String, Variant>> propvalues; - for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) { + for (const PropertyInfo &pi : property_list) { Pair<String, Variant> p; - PropertyInfo &pi = E->get(); if (pi.usage & PROPERTY_USAGE_STORAGE) { p.first = pi.name; p.second = res_orig->get(pi.name); @@ -198,8 +197,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { ERR_FAIL_COND(res.is_null()); - for (List<Pair<String, Variant>>::Element *E = propvalues.front(); E; E = E->next()) { - Pair<String, Variant> &p = E->get(); + for (const Pair<String, Variant> &p : propvalues) { res->set(p.first, p.second); } @@ -1293,8 +1291,8 @@ void CustomPropertyEditor::_action_pressed(int p_which) { ResourceLoader::get_recognized_extensions_for_type(type, &extensions); file->clear_filters(); - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - file->add_filter("*." + E->get() + " ; " + E->get().to_upper()); + for (const String &E : extensions) { + file->add_filter("*." + E + " ; " + E.to_upper()); } file->popup_file_dialog(); @@ -1321,9 +1319,8 @@ void CustomPropertyEditor::_action_pressed(int p_which) { res_orig->get_property_list(&property_list); List<Pair<String, Variant>> propvalues; - for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) { + for (const PropertyInfo &pi : property_list) { Pair<String, Variant> p; - PropertyInfo &pi = E->get(); if (pi.usage & PROPERTY_USAGE_STORAGE) { p.first = pi.name; p.second = res_orig->get(pi.name); @@ -1336,8 +1333,7 @@ void CustomPropertyEditor::_action_pressed(int p_which) { ERR_FAIL_COND(res.is_null()); - for (List<Pair<String, Variant>>::Element *E = propvalues.front(); E; E = E->next()) { - Pair<String, Variant> &p = E->get(); + for (const Pair<String, Variant> &p : propvalues) { res->set(p.first, p.second); } diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp index e4e372a19c..a1deae92a4 100644 --- a/editor/property_selector.cpp +++ b/editor/property_selector.cpp @@ -137,6 +137,7 @@ void PropertySelector::_update_search() { search_options->get_theme_icon(SNAME("Basis"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("Color"), SNAME("EditorIcons")), + search_options->get_theme_icon(SNAME("StringName"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("NodePath"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("RID"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("MiniObject"), SNAME("EditorIcons")), @@ -146,50 +147,52 @@ void PropertySelector::_update_search() { search_options->get_theme_icon(SNAME("Array"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("PackedByteArray"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("PackedInt32Array"), SNAME("EditorIcons")), + search_options->get_theme_icon(SNAME("PackedInt64Array"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("PackedFloat32Array"), SNAME("EditorIcons")), + search_options->get_theme_icon(SNAME("PackedFloat64Array"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("PackedStringArray"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("PackedVector2Array"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("PackedVector3Array"), SNAME("EditorIcons")), search_options->get_theme_icon(SNAME("PackedColorArray"), SNAME("EditorIcons")) }; - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (E->get().usage == PROPERTY_USAGE_CATEGORY) { + for (const PropertyInfo &E : props) { + if (E.usage == PROPERTY_USAGE_CATEGORY) { if (category && category->get_first_child() == nullptr) { memdelete(category); //old category was unused } category = search_options->create_item(root); - category->set_text(0, E->get().name); + category->set_text(0, E.name); category->set_selectable(0, false); Ref<Texture2D> icon; - if (E->get().name == "Script Variables") { + if (E.name == "Script Variables") { icon = search_options->get_theme_icon(SNAME("Script"), SNAME("EditorIcons")); } else { - icon = EditorNode::get_singleton()->get_class_icon(E->get().name); + icon = EditorNode::get_singleton()->get_class_icon(E.name); } category->set_icon(0, icon); continue; } - if (!(E->get().usage & PROPERTY_USAGE_EDITOR) && !(E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) { + if (!(E.usage & PROPERTY_USAGE_EDITOR) && !(E.usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) { continue; } - if (search_box->get_text() != String() && E->get().name.findn(search_text) == -1) { + if (search_box->get_text() != String() && E.name.findn(search_text) == -1) { continue; } - if (type_filter.size() && type_filter.find(E->get().type) == -1) { + if (type_filter.size() && type_filter.find(E.type) == -1) { continue; } TreeItem *item = search_options->create_item(category ? category : root); - item->set_text(0, E->get().name); - item->set_metadata(0, E->get().name); - item->set_icon(0, type_icons[E->get().type]); + item->set_text(0, E.name); + item->set_metadata(0, E.name); + item->set_icon(0, type_icons[E.type]); - if (!found && search_box->get_text() != String() && E->get().name.findn(search_text) != -1) { + if (!found && search_box->get_text() != String() && E.name.findn(search_text) != -1) { item->select(0); found = true; } @@ -228,19 +231,19 @@ void PropertySelector::_update_search() { bool found = false; bool script_methods = false; - for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { - if (E->get().name.begins_with("*")) { + for (MethodInfo &mi : methods) { + if (mi.name.begins_with("*")) { if (category && category->get_first_child() == nullptr) { memdelete(category); //old category was unused } category = search_options->create_item(root); - category->set_text(0, E->get().name.replace_first("*", "")); + category->set_text(0, mi.name.replace_first("*", "")); category->set_selectable(0, false); Ref<Texture2D> icon; script_methods = false; - String rep = E->get().name.replace("*", ""); - if (E->get().name == "*Script Methods") { + String rep = mi.name.replace("*", ""); + if (mi.name == "*Script Methods") { icon = search_options->get_theme_icon(SNAME("Script"), SNAME("EditorIcons")); script_methods = true; } else { @@ -251,16 +254,16 @@ void PropertySelector::_update_search() { continue; } - String name = E->get().name.get_slice(":", 0); - if (!script_methods && name.begins_with("_") && !(E->get().flags & METHOD_FLAG_VIRTUAL)) { + String name = mi.name.get_slice(":", 0); + if (!script_methods && name.begins_with("_") && !(mi.flags & METHOD_FLAG_VIRTUAL)) { continue; } - if (virtuals_only && !(E->get().flags & METHOD_FLAG_VIRTUAL)) { + if (virtuals_only && !(mi.flags & METHOD_FLAG_VIRTUAL)) { continue; } - if (!virtuals_only && (E->get().flags & METHOD_FLAG_VIRTUAL)) { + if (!virtuals_only && (mi.flags & METHOD_FLAG_VIRTUAL)) { continue; } @@ -270,8 +273,6 @@ void PropertySelector::_update_search() { TreeItem *item = search_options->create_item(category ? category : root); - MethodInfo mi = E->get(); - String desc; if (mi.name.find(":") != -1) { desc = mi.name.get_slice(":", 1) + " "; @@ -303,11 +304,11 @@ void PropertySelector::_update_search() { desc += ")"; - if (E->get().flags & METHOD_FLAG_CONST) { + if (mi.flags & METHOD_FLAG_CONST) { desc += " const"; } - if (E->get().flags & METHOD_FLAG_VIRTUAL) { + if (mi.flags & METHOD_FLAG_VIRTUAL) { desc += " virtual"; } diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index dad708612e..c4d47c7594 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -263,8 +263,8 @@ void SceneTreeDock::_replace_with_branch_scene(const String &p_file, Node *base) List<Node *> owned; base->get_owned_by(base->get_owner(), &owned); Array owners; - for (List<Node *>::Element *F = owned.front(); F; F = F->next()) { - owners.push_back(F->get()); + for (Node *F : owned) { + owners.push_back(F); } undo_redo->add_do_method(instantiated_scene, "set_owner", edited_scene); undo_redo->add_undo_method(this, "_set_owners", edited_scene, owners); @@ -441,8 +441,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { selection.sort_custom<Node::Comparator>(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node *node = E->get(); + for (Node *node : selection) { Map<const Node *, Node *> duplimap; Node *dup = node->duplicate_from_editor(duplimap); @@ -462,8 +461,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { bool has_cycle = false; if (edited_scene->get_filename() != String()) { - for (List<Node *>::Element *E = node_clipboard.front(); E; E = E->next()) { - if (edited_scene->get_filename() == E->get()->get_filename()) { + for (Node *E : node_clipboard) { + if (edited_scene->get_filename() == E->get_filename()) { has_cycle = true; break; } @@ -496,16 +495,15 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (target_scene != clipboard_source_scene) { if (!clipboard_resource_remap.has(target_scene)) { Map<RES, RES> remap; - for (List<Node *>::Element *E = node_clipboard.front(); E; E = E->next()) { - _create_remap_for_node(E->get(), remap); + for (Node *E : node_clipboard) { + _create_remap_for_node(E, remap); } clipboard_resource_remap[target_scene] = remap; } resource_remap = clipboard_resource_remap[target_scene]; } - for (List<Node *>::Element *E = node_clipboard.front(); E; E = E->next()) { - Node *node = E->get(); + for (Node *node : node_clipboard) { Map<const Node *, Node *> duplimap; Node *dup = node->duplicate_from_editor(duplimap, resource_remap); @@ -544,6 +542,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } + if (reset_create_dialog) { + create_dialog->set_base_type("Node"); + reset_create_dialog = false; + } + Node *selected = scene_tree->get_selected(); if (!selected && !editor_selection->get_selected_node_list().is_empty()) { selected = editor_selection->get_selected_node_list().front()->get(); @@ -622,8 +625,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { int lowest_id = common_parent->get_child_count() - 1; int highest_id = 0; - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - int index = E->get()->get_index(); + for (Node *E : selection) { + int index = E->get_index(); if (index > highest_id) { highest_id = index; @@ -632,7 +635,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { lowest_id = index; } - if (E->get()->get_parent() != common_parent) { + if (E->get_parent() != common_parent) { common_parent = nullptr; } } @@ -699,8 +702,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *add_below_node = selection.back()->get(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node *node = E->get(); + for (Node *node : selection) { Node *parent = node->get_parent(); List<Node *> owned; @@ -719,11 +721,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { editor_data->get_undo_redo().add_do_method(add_below_node, "add_sibling", dup); - for (List<Node *>::Element *F = owned.front(); F; F = F->next()) { - if (!duplimap.has(F->get())) { + for (Node *F : owned) { + if (!duplimap.has(F)) { continue; } - Node *d = duplimap[F->get()]; + Node *d = duplimap[F]; editor_data->get_undo_redo().add_do_method(d, "set_owner", node->get_owner()); } editor_data->get_undo_redo().add_do_method(editor_selection, "add_node", dup); @@ -766,8 +768,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { List<Node *> nodes = editor_selection->get_selected_node_list(); Set<Node *> nodeset; - for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) { - nodeset.insert(E->get()); + for (Node *E : nodes) { + nodeset.insert(E); } reparent_dialog->set_current(nodeset); reparent_dialog->popup_centered_clamped(Size2(350, 700) * EDSCALE); @@ -1379,30 +1381,25 @@ void SceneTreeDock::_set_owners(Node *p_owner, const Array &p_nodes) { } } -void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, List<Pair<NodePath, NodePath>> *p_renames) { +void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, Map<Node *, NodePath> *p_renames) { base_path.push_back(p_node->get_name()); if (new_base_path.size()) { new_base_path.push_back(p_node->get_name()); } - NodePath from(base_path, true); - NodePath to; + NodePath new_path; if (new_base_path.size()) { - to = NodePath(new_base_path, true); + new_path = NodePath(new_base_path, true); } - Pair<NodePath, NodePath> npp; - npp.first = from; - npp.second = to; - - p_renames->push_back(npp); + p_renames->insert(p_node, new_path); for (int i = 0; i < p_node->get_child_count(); i++) { _fill_path_renames(base_path, new_base_path, p_node->get_child(i), p_renames); } } -void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pair<NodePath, NodePath>> *p_renames) { +void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, Map<Node *, NodePath> *p_renames) { Vector<StringName> base_path; Node *n = p_node->get_parent(); while (n) { @@ -1425,50 +1422,41 @@ void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pai _fill_path_renames(base_path, new_base_path, p_node, p_renames); } -bool SceneTreeDock::_update_node_path(const NodePath &p_root_path, NodePath &r_node_path, List<Pair<NodePath, NodePath>> *p_renames) { - NodePath root_path_new = p_root_path; - for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { - if (p_root_path == F->get().first) { - root_path_new = F->get().second; - break; - } - } - - // Goes through all paths to check if it's matching. - for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { - NodePath rel_path_old = p_root_path.rel_path_to(F->get().first); +bool SceneTreeDock::_update_node_path(Node *p_root_node, NodePath &r_node_path, Map<Node *, NodePath> *p_renames) const { + Node *target_node = p_root_node->get_node_or_null(r_node_path); + ERR_FAIL_NULL_V_MSG(target_node, false, "Found invalid node path '" + String(r_node_path) + "' on node '" + String(scene_root->get_path_to(p_root_node)) + "'"); - // If old path detected, then it needs to be replaced with the new one. - if (r_node_path == rel_path_old) { - NodePath rel_path_new = F->get().second; + // Try to find the target node in modified node paths. + Map<Node *, NodePath>::Element *found_node_path = p_renames->find(target_node); + if (found_node_path) { + Map<Node *, NodePath>::Element *found_root_path = p_renames->find(p_root_node); + NodePath root_path_new = found_root_path ? found_root_path->get() : p_root_node->get_path(); + r_node_path = root_path_new.rel_path_to(found_node_path->get()); - // If not empty, get new relative path. - if (!rel_path_new.is_empty()) { - rel_path_new = root_path_new.rel_path_to(rel_path_new); - } + return true; + } - r_node_path = rel_path_new; - return true; + // Update the path if the base node has changed and has not been deleted. + Map<Node *, NodePath>::Element *found_root_path = p_renames->find(p_root_node); + if (found_root_path) { + NodePath root_path_new = found_root_path->get(); + if (!root_path_new.is_empty()) { + NodePath old_abs_path = NodePath(String(p_root_node->get_path()).plus_file(r_node_path)); + old_abs_path.simplify(); + r_node_path = root_path_new.rel_path_to(old_abs_path); } - // Update the node itself if it has a valid node path and has not been deleted. - if (p_root_path == F->get().first && r_node_path != NodePath() && F->get().second != NodePath()) { - NodePath abs_path = NodePath(String(root_path_new).plus_file(r_node_path)).simplified(); - NodePath rel_path_new = F->get().second.rel_path_to(abs_path); - - r_node_path = rel_path_new; - return true; - } + return true; } return false; } -bool SceneTreeDock::_check_node_path_recursive(const NodePath &p_root_path, Variant &r_variant, List<Pair<NodePath, NodePath>> *p_renames) { +bool SceneTreeDock::_check_node_path_recursive(Node *p_root_node, Variant &r_variant, Map<Node *, NodePath> *p_renames) const { switch (r_variant.get_type()) { case Variant::NODE_PATH: { NodePath node_path = r_variant; - if (_update_node_path(p_root_path, node_path, p_renames)) { + if (!node_path.is_empty() && _update_node_path(p_root_node, node_path, p_renames)) { r_variant = node_path; return true; } @@ -1479,7 +1467,7 @@ bool SceneTreeDock::_check_node_path_recursive(const NodePath &p_root_path, Vari bool updated = false; for (int i = 0; i < a.size(); i++) { Variant value = a[i]; - if (_check_node_path_recursive(p_root_path, value, p_renames)) { + if (_check_node_path_recursive(p_root_node, value, p_renames)) { if (!updated) { a = a.duplicate(); // Need to duplicate for undo-redo to work. updated = true; @@ -1498,7 +1486,7 @@ bool SceneTreeDock::_check_node_path_recursive(const NodePath &p_root_path, Vari bool updated = false; for (int i = 0; i < d.size(); i++) { Variant value = d.get_value_at_index(i); - if (_check_node_path_recursive(p_root_path, value, p_renames)) { + if (_check_node_path_recursive(p_root_node, value, p_renames)) { if (!updated) { d = d.duplicate(); // Need to duplicate for undo-redo to work. updated = true; @@ -1519,7 +1507,7 @@ bool SceneTreeDock::_check_node_path_recursive(const NodePath &p_root_path, Vari return false; } -void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodePath>> *p_renames, Map<Ref<Animation>, Set<int>> *r_rem_anims) { +void SceneTreeDock::perform_node_renames(Node *p_base, Map<Node *, NodePath> *p_renames, Map<Ref<Animation>, Set<int>> *r_rem_anims) { Map<Ref<Animation>, Set<int>> rem_anims; if (!r_rem_anims) { r_rem_anims = &rem_anims; @@ -1533,19 +1521,24 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP return; } + // No renaming if base node is deleted. + Map<Node *, NodePath>::Element *found_base_path = p_renames->find(p_base); + if (found_base_path && found_base_path->get().is_empty()) { + return; + } + // Renaming node paths used in node properties. List<PropertyInfo> properties; p_base->get_property_list(&properties); - NodePath base_root_path = p_base->get_path(); - for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) { - if (!(E->get().usage & (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR))) { + for (const PropertyInfo &E : properties) { + if (!(E.usage & (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR))) { continue; } - String propertyname = E->get().name; + String propertyname = E.name; Variant old_variant = p_base->get(propertyname); Variant updated_variant = old_variant; - if (_check_node_path_recursive(base_root_path, updated_variant, p_renames)) { + if (_check_node_path_recursive(p_base, updated_variant, p_renames)) { editor_data->get_undo_redo().add_do_property(p_base, propertyname, updated_variant); editor_data->get_undo_redo().add_undo_property(p_base, propertyname, old_variant); p_base->set(propertyname, updated_variant); @@ -1561,21 +1554,11 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP Node *root = ap->get_node(ap->get_root()); if (root) { - NodePath root_path = root->get_path(); - NodePath new_root_path = root_path; - - for (List<Pair<NodePath, NodePath>>::Element *E = p_renames->front(); E; E = E->next()) { - if (E->get().first == root_path) { - new_root_path = E->get().second; - break; - } - } - - if (new_root_path != NodePath()) { - //will not be erased - - for (List<StringName>::Element *E = anims.front(); E; E = E->next()) { - Ref<Animation> anim = ap->get_animation(E->get()); + Map<Node *, NodePath>::Element *found_root_path = p_renames->find(root); + NodePath new_root_path = found_root_path ? found_root_path->get() : root->get_path(); + if (!new_root_path.is_empty()) { // No renaming if root node is deleted. + for (const StringName &E : anims) { + Ref<Animation> anim = ap->get_animation(E); if (!r_rem_anims->has(anim)) { r_rem_anims->insert(anim, Set<int>()); Set<int> &ran = r_rem_anims->find(anim)->get(); @@ -1597,47 +1580,44 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP continue; } - NodePath old_np = n->get_path(); - if (!ran.has(i)) { continue; //channel was removed } - for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) { - if (F->get().first == old_np) { - if (F->get().second == NodePath()) { - //will be erased - - int idx = 0; - Set<int>::Element *EI = ran.front(); - ERR_FAIL_COND(!EI); //bug - while (EI->get() != i) { - idx++; - EI = EI->next(); - ERR_FAIL_COND(!EI); //another bug - } - - editor_data->get_undo_redo().add_do_method(anim.ptr(), "remove_track", idx); - editor_data->get_undo_redo().add_undo_method(anim.ptr(), "add_track", anim->track_get_type(i), idx); - editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_path", idx, track_np); - editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_interpolation_type", idx, anim->track_get_interpolation_type(i)); - for (int j = 0; j < anim->track_get_key_count(i); j++) { - editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_insert_key", idx, anim->track_get_key_time(i, j), anim->track_get_key_value(i, j), anim->track_get_key_transition(i, j)); - } - - ran.erase(i); //byebye channel - - } else { - //will be renamed - NodePath rel_path = new_root_path.rel_path_to(F->get().second); - - NodePath new_path = NodePath(rel_path.get_names(), track_np.get_subnames(), false); - if (new_path == track_np) { - continue; //bleh - } - editor_data->get_undo_redo().add_do_method(anim.ptr(), "track_set_path", i, new_path); - editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_path", i, track_np); + Map<Node *, NodePath>::Element *found_path = p_renames->find(n); + if (found_path) { + if (found_path->get() == NodePath()) { + //will be erased + + int idx = 0; + Set<int>::Element *EI = ran.front(); + ERR_FAIL_COND(!EI); //bug + while (EI->get() != i) { + idx++; + EI = EI->next(); + ERR_FAIL_COND(!EI); //another bug + } + + editor_data->get_undo_redo().add_do_method(anim.ptr(), "remove_track", idx); + editor_data->get_undo_redo().add_undo_method(anim.ptr(), "add_track", anim->track_get_type(i), idx); + editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_path", idx, track_np); + editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_interpolation_type", idx, anim->track_get_interpolation_type(i)); + for (int j = 0; j < anim->track_get_key_count(i); j++) { + editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_insert_key", idx, anim->track_get_key_time(i, j), anim->track_get_key_value(i, j), anim->track_get_key_transition(i, j)); + } + + ran.erase(i); //byebye channel + + } else { + //will be renamed + NodePath rel_path = new_root_path.rel_path_to(found_path->get()); + + NodePath new_path = NodePath(rel_path.get_names(), track_np.get_subnames(), false); + if (new_path == track_np) { + continue; //bleh } + editor_data->get_undo_redo().add_do_method(anim.ptr(), "track_set_path", i, new_path); + editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_path", i, track_np); } } } @@ -1652,7 +1632,7 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP } void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) { - List<Pair<NodePath, NodePath>> path_renames; + Map<Node *, NodePath> path_renames; Vector<StringName> base_path; Node *n = p_node->get_parent(); @@ -1667,10 +1647,8 @@ void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) { new_base_path.push_back(p_new_name); - Pair<NodePath, NodePath> npp; - npp.first = NodePath(base_path, true); - npp.second = NodePath(new_base_path, true); - path_renames.push_back(npp); + NodePath new_path(new_base_path, true); + path_renames[p_node] = new_path; for (int i = 0; i < p_node->get_child_count(); i++) { _fill_path_renames(base_path, new_base_path, p_node->get_child(i), &path_renames); @@ -1682,8 +1660,8 @@ void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) { bool SceneTreeDock::_validate_no_foreign() { List<Node *> selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - if (E->get() != edited_scene && E->get()->get_owner() != edited_scene) { + for (Node *E : selection) { + if (E != edited_scene && E->get_owner() != edited_scene) { accept->set_text(TTR("Can't operate on nodes from a foreign scene!")); accept->popup_centered(); return false; @@ -1692,11 +1670,11 @@ bool SceneTreeDock::_validate_no_foreign() { // When edited_scene inherits from another one the root Node will be the parent Scene, // we don't want to consider that Node a foreign one otherwise we would not be able to // delete it. - if (edited_scene->get_scene_inherited_state().is_valid() && edited_scene == E->get()) { + if (edited_scene->get_scene_inherited_state().is_valid() && edited_scene == E) { continue; } - if (edited_scene->get_scene_inherited_state().is_valid() && edited_scene->get_scene_inherited_state()->find_node_by_path(edited_scene->get_path_to(E->get())) >= 0) { + if (edited_scene->get_scene_inherited_state().is_valid() && edited_scene->get_scene_inherited_state()->find_node_by_path(edited_scene->get_path_to(E)) >= 0) { accept->set_text(TTR("Can't operate on nodes the current scene inherits from!")); accept->popup_centered(); return false; @@ -1709,8 +1687,8 @@ bool SceneTreeDock::_validate_no_foreign() { bool SceneTreeDock::_validate_no_instance() { List<Node *> selection = editor_selection->get_selected_node_list(); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - if (E->get() != edited_scene && E->get()->get_filename() != "") { + for (Node *E : selection) { + if (E != edited_scene && E->get_filename() != "") { accept->set_text(TTR("This operation can't be done on instantiated scenes.")); accept->popup_centered(); return false; @@ -1732,8 +1710,8 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) { Vector<Node *> nodes; - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - nodes.push_back(E->get()); + for (Node *E : selection) { + nodes.push_back(E); } _do_reparent(new_parent, -1, nodes, p_keep_global_xform); @@ -1775,7 +1753,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V editor_data->get_undo_redo().create_action(TTR("Reparent Node")); - List<Pair<NodePath, NodePath>> path_renames; + Map<Node *, NodePath> path_renames; Vector<StringName> former_names; int inc = 0; @@ -1790,8 +1768,8 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V List<Node *> owned; node->get_owned_by(node->get_owner(), &owned); Array owners; - for (List<Node *>::Element *E = owned.front(); E; E = E->next()) { - owners.push_back(E->get()); + for (Node *E : owned) { + owners.push_back(E); } if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni) { @@ -1812,21 +1790,24 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V // Name was modified, fix the path renames. if (old_name.casecmp_to(new_name) != 0) { // Fix the to name to have the new name. - NodePath old_new_name = path_renames[ni].second; - NodePath new_path; + Map<Node *, NodePath>::Element *found_path = path_renames.find(node); + if (found_path) { + NodePath old_new_name = found_path->get(); - Vector<StringName> unfixed_new_names = old_new_name.get_names(); - Vector<StringName> fixed_new_names; + Vector<StringName> unfixed_new_names = old_new_name.get_names(); + Vector<StringName> fixed_new_names; - // Get last name and replace with fixed new name. - for (int a = 0; a < (unfixed_new_names.size() - 1); a++) { - fixed_new_names.push_back(unfixed_new_names[a]); - } - fixed_new_names.push_back(new_name); - - NodePath fixed_node_path = NodePath(fixed_new_names, true); + // Get last name and replace with fixed new name. + for (int a = 0; a < (unfixed_new_names.size() - 1); a++) { + fixed_new_names.push_back(unfixed_new_names[a]); + } + fixed_new_names.push_back(new_name); - path_renames[ni].second = fixed_node_path; + NodePath fixed_node_path = NodePath(fixed_new_names, true); + path_renames[node] = fixed_node_path; + } else { + ERR_PRINT("Internal error. Can't find renamed path for node '" + node->get_path() + "'"); + } } editor_data->get_undo_redo().add_do_method(ed, "live_debug_reparent_node", edited_scene->get_path_to(node), edited_scene->get_path_to(new_parent), new_name, p_position_in_parent + inc); @@ -1863,8 +1844,8 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V List<Node *> owned; node->get_owned_by(node->get_owner(), &owned); Array owners; - for (List<Node *>::Element *E = owned.front(); E; E = E->next()) { - owners.push_back(E->get()); + for (Node *E : owned) { + owners.push_back(E); } int child_pos = node->get_index(); @@ -1944,10 +1925,10 @@ void SceneTreeDock::_script_created(Ref<Script> p_script) { } editor_data->get_undo_redo().create_action(TTR("Attach Script")); - for (List<Node *>::Element *E = selected.front(); E; E = E->next()) { - Ref<Script> existing = E->get()->get_script(); - editor_data->get_undo_redo().add_do_method(E->get(), "set_script", p_script); - editor_data->get_undo_redo().add_undo_method(E->get(), "set_script", existing); + for (Node *E : selected) { + Ref<Script> existing = E->get_script(); + editor_data->get_undo_redo().add_do_method(E, "set_script", p_script); + editor_data->get_undo_redo().add_undo_method(E, "set_script", existing); editor_data->get_undo_redo().add_do_method(this, "_update_script_button"); editor_data->get_undo_redo().add_undo_method(this, "_update_script_button"); } @@ -2022,8 +2003,8 @@ void SceneTreeDock::_delete_confirm(bool p_cut) { bool entire_scene = false; - for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) { - if (E->get() == edited_scene) { + for (Node *E : remove_list) { + if (E == edited_scene) { entire_scene = true; } } @@ -2037,11 +2018,10 @@ void SceneTreeDock::_delete_confirm(bool p_cut) { } else { remove_list.sort_custom<Node::Comparator>(); //sort nodes to keep positions - List<Pair<NodePath, NodePath>> path_renames; + Map<Node *, NodePath> path_renames; //delete from animation - for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) { - Node *n = E->get(); + for (Node *n : remove_list) { if (!n->is_inside_tree() || !n->get_parent()) { continue; } @@ -2051,8 +2031,7 @@ void SceneTreeDock::_delete_confirm(bool p_cut) { perform_node_renames(nullptr, &path_renames); //delete for read - for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) { - Node *n = E->get(); + for (Node *n : remove_list) { if (!n->is_inside_tree() || !n->get_parent()) { continue; } @@ -2060,8 +2039,8 @@ void SceneTreeDock::_delete_confirm(bool p_cut) { List<Node *> owned; n->get_owned_by(n->get_owner(), &owned); Array owners; - for (List<Node *>::Element *F = owned.front(); F; F = F->next()) { - owners.push_back(F->get()); + for (Node *F : owned) { + owners.push_back(F); } editor_data->get_undo_redo().add_do_method(n->get_parent(), "remove_child", n); @@ -2214,8 +2193,7 @@ void SceneTreeDock::_create() { UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); ur->create_action(TTR("Change type of node(s)")); - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node *n = E->get(); + for (Node *n : selection) { ERR_FAIL_COND(!n); Variant c = create_dialog->instance_selected(); @@ -2272,8 +2250,8 @@ void SceneTreeDock::_create() { _do_create(parent); Vector<Node *> nodes; - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - nodes.push_back(E->get()); + for (Node *E : selection) { + nodes.push_back(E); } // This works because editor_selection was cleared and populated with last created node in _do_create() @@ -2293,13 +2271,13 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop List<PropertyInfo> pinfo; n->get_property_list(&pinfo); - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + for (const PropertyInfo &E : pinfo) { + if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } - if (E->get().name == "__meta__") { - Dictionary metadata = n->get(E->get().name); + if (E.name == "__meta__") { + Dictionary metadata = n->get(E.name); if (metadata.has("_editor_description_")) { newnode->set_meta("_editor_description_", metadata["_editor_description_"]); } @@ -2316,8 +2294,8 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop continue; } - if (default_oldnode->get(E->get().name) != n->get(E->get().name)) { - newnode->set(E->get().name, n->get(E->get().name)); + if (default_oldnode->get(E.name) != n->get(E.name)) { + newnode->set(E.name, n->get(E.name)); } } @@ -2330,12 +2308,11 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop List<MethodInfo> sl; n->get_signal_list(&sl); - for (List<MethodInfo>::Element *E = sl.front(); E; E = E->next()) { + for (const MethodInfo &E : sl) { List<Object::Connection> cl; - n->get_signal_connection_list(E->get().name, &cl); + n->get_signal_connection_list(E.name, &cl); - for (List<Object::Connection>::Element *F = cl.front(); F; F = F->next()) { - Object::Connection &c = F->get(); + for (const Object::Connection &c : cl) { if (!(c.flags & Object::CONNECT_PERSIST)) { continue; } @@ -2541,13 +2518,13 @@ void SceneTreeDock::_files_dropped(Vector<String> p_files, NodePath p_to, int p_ List<PropertyInfo> pinfo; node->get_property_list(&pinfo); - for (PropertyInfo &p : pinfo) { + for (const PropertyInfo &p : pinfo) { if (!(p.usage & PROPERTY_USAGE_EDITOR) || !(p.usage & PROPERTY_USAGE_STORAGE) || p.hint != PROPERTY_HINT_RESOURCE_TYPE) { continue; } Vector<String> valid_types = p.hint_string.split(","); - for (String &prop_type : valid_types) { + for (const String &prop_type : valid_types) { if (res_type == prop_type || ClassDB::is_parent_class(res_type, prop_type) || EditorNode::get_editor_data().script_class_is_parent(res_type, prop_type)) { valid_properties.push_back(p.name); break; @@ -2561,7 +2538,7 @@ void SceneTreeDock::_files_dropped(Vector<String> p_files, NodePath p_to, int p_ bool capitalize = bool(EDITOR_GET("interface/inspector/capitalize_properties")); menu_properties->clear(); - for (String &p : valid_properties) { + for (const String &p : valid_properties) { menu_properties->add_item(capitalize ? p.capitalize() : p); menu_properties->set_item_metadata(menu_properties->get_item_count() - 1, p); } @@ -2602,8 +2579,8 @@ void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) { } Vector<Node *> nodes; - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - nodes.push_back(E->get()); + for (Node *E : selection) { + nodes.push_back(E); } int to_pos = -1; @@ -2619,15 +2596,15 @@ void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) { List<PropertyInfo> pinfo; p_obj->get_property_list(&pinfo); - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) { + for (const PropertyInfo &E : pinfo) { + if (!(E.usage & PROPERTY_USAGE_EDITOR)) { continue; } - if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) { + if (E.hint != PROPERTY_HINT_RESOURCE_TYPE) { continue; } - Variant value = p_obj->get(E->get().name); + Variant value = p_obj->get(E.name); if (value.get_type() != Variant::OBJECT) { continue; } @@ -2642,7 +2619,7 @@ void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) { menu->add_submenu_item(TTR("Sub-Resources"), "Sub-Resources"); } int index = menu_subresources->get_item_count(); - menu_subresources->add_icon_item(icon, E->get().name.capitalize(), EDIT_SUBRESOURCE_BASE + subresources.size()); + menu_subresources->add_icon_item(icon, E.name.capitalize(), EDIT_SUBRESOURCE_BASE + subresources.size()); menu_subresources->set_item_h_offset(index, p_depth * 10 * EDSCALE); subresources.push_back(obj->get_instance_id()); @@ -2724,8 +2701,8 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->add_icon_shortcut(get_theme_icon(SNAME("ScriptRemove"), SNAME("EditorIcons")), ED_GET_SHORTCUT("scene_tree/detach_script"), TOOL_DETACH_SCRIPT); } else if (full_selection.size() > 1) { bool script_exists = false; - for (List<Node *>::Element *E = full_selection.front(); E; E = E->next()) { - if (!E->get()->get_script().is_null()) { + for (Node *E : full_selection) { + if (!E->get_script().is_null()) { script_exists = true; break; } @@ -2748,8 +2725,8 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { } bool can_replace = true; - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - if (E->get() != edited_scene && (E->get()->get_owner() != edited_scene || E->get()->get_filename() != "")) { + for (Node *E : selection) { + if (E != edited_scene && (E->get_owner() != edited_scene || E->get_filename() != "")) { can_replace = false; break; } @@ -3062,8 +3039,8 @@ void SceneTreeDock::_feature_profile_changed() { } void SceneTreeDock::_clear_clipboard() { - for (List<Node *>::Element *E = node_clipboard.front(); E; E = E->next()) { - memdelete(E->get()); + for (Node *E : node_clipboard) { + memdelete(E); } node_clipboard.clear(); clipboard_resource_remap.clear(); @@ -3074,18 +3051,18 @@ void SceneTreeDock::_create_remap_for_node(Node *p_node, Map<RES, RES> &r_remap) p_node->get_property_list(&props); bool is_instantiated = EditorPropertyRevert::may_node_be_in_instance(p_node); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + for (const PropertyInfo &E : props) { + if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } - Variant v = p_node->get(E->get().name); + Variant v = p_node->get(E.name); if (v.is_ref()) { RES res = v; if (res.is_valid()) { if (is_instantiated) { Variant orig; - if (EditorPropertyRevert::get_instantiated_node_original_property(p_node, E->get().name, orig)) { + if (EditorPropertyRevert::get_instantiated_node_original_property(p_node, E.name, orig)) { if (!EditorPropertyRevert::is_node_property_different(p_node, v, orig)) { continue; } @@ -3110,12 +3087,12 @@ void SceneTreeDock::_create_remap_for_resource(RES p_resource, Map<RES, RES> &r_ List<PropertyInfo> props; p_resource->get_property_list(&props); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + for (const PropertyInfo &E : props) { + if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } - Variant v = p_resource->get(E->get().name); + Variant v = p_resource->get(E.name); if (v.is_ref()) { RES res = v; if (res.is_valid()) { diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index fd9299fb2b..4952122cb7 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -217,7 +217,7 @@ class SceneTreeDock : public VBoxContainer { void _selection_changed(); void _update_script_button(); - void _fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, List<Pair<NodePath, NodePath>> *p_renames); + void _fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, Map<Node *, NodePath> *p_renames); void _normalize_drop(Node *&to_node, int &to_pos, int p_type); @@ -253,8 +253,8 @@ class SceneTreeDock : public VBoxContainer { static SceneTreeDock *singleton; static void _update_configuration_warning(); - static bool _update_node_path(const NodePath &p_root_path, NodePath &r_node_path, List<Pair<NodePath, NodePath>> *p_renames); - static bool _check_node_path_recursive(const NodePath &p_root_path, Variant &r_variant, List<Pair<NodePath, NodePath>> *p_renames); + bool _update_node_path(Node *p_root_node, NodePath &r_node_path, Map<Node *, NodePath> *p_renames) const; + bool _check_node_path_recursive(Node *p_root_node, Variant &r_variant, Map<Node *, NodePath> *p_renames) const; protected: void _notification(int p_what); @@ -272,8 +272,8 @@ public: void instantiate(const String &p_file); void instantiate_scenes(const Vector<String> &p_files, Node *p_parent = nullptr); void set_selected(Node *p_node, bool p_emit_selected = false); - void fill_path_renames(Node *p_node, Node *p_new_parent, List<Pair<NodePath, NodePath>> *p_renames); - void perform_node_renames(Node *p_base, List<Pair<NodePath, NodePath>> *p_renames, Map<Ref<Animation>, Set<int>> *r_rem_anims = nullptr); + void fill_path_renames(Node *p_node, Node *p_new_parent, Map<Node *, NodePath> *p_renames); + void perform_node_renames(Node *p_base, Map<Node *, NodePath> *p_renames, Map<Ref<Animation>, Set<int>> *r_rem_anims = nullptr); SceneTreeEditor *get_tree_editor() { return scene_tree; } EditorData *get_editor_data() { return editor_data; } diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index c6f2c9253e..83b0203f32 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -79,8 +79,7 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i _toggle_visible(n); List<Node *> selection = editor_selection->get_selected_node_list(); if (selection.size() > 1 && selection.find(n) != nullptr) { - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - Node *nv = E->get(); + for (Node *nv : selection) { ERR_FAIL_COND(!nv); if (nv == n) { continue; @@ -521,7 +520,7 @@ void SceneTreeEditor::_node_removed(Node *p_node) { if (p_node == selected) { selected = nullptr; - _emit_node_selected(); + emit_signal("node_selected"); } } @@ -615,6 +614,24 @@ void SceneTreeEditor::_tree_changed() { pending_test_update = true; } +void SceneTreeEditor::_selected_changed() { + TreeItem *s = tree->get_selected(); + ERR_FAIL_COND(!s); + NodePath np = s->get_metadata(0); + + Node *n = get_node(np); + + if (n == selected) { + return; + } + + selected = get_node(np); + + blocked++; + emit_signal("node_selected"); + blocked--; +} + void SceneTreeEditor::_deselect_items() { // Clear currently selected items in scene tree dock. if (editor_selection) { @@ -623,12 +640,6 @@ void SceneTreeEditor::_deselect_items() { } } -void SceneTreeEditor::_emit_node_selected() { - blocked++; - emit_signal(SNAME("node_selected")); - blocked--; -} - void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_selected) { TreeItem *item = Object::cast_to<TreeItem>(p_object); ERR_FAIL_COND(!item); @@ -652,11 +663,8 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_ editor_selection->remove_node(n); } - // Selection changed to be single node, so emit "selected" (for single node) rather than "changed" (for multiple nodes) - if (editor_selection->get_selected_nodes().size() == 1) { - selected = editor_selection->get_selected_node_list()[0]; - _emit_node_selected(); - } else { + // Emitted "selected" in _selected_changed() when select single node, so select multiple node emit "changed" + if (editor_selection->get_selected_nodes().size() > 1) { emit_signal(SNAME("node_changed")); } } @@ -747,7 +755,7 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) { } if (p_emit_selected) { - _emit_node_selected(); + emit_signal("node_selected"); } } @@ -1197,6 +1205,7 @@ SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_ope tree->connect("empty_tree_rmb_selected", callable_mp(this, &SceneTreeEditor::_rmb_select)); } + tree->connect("cell_selected", callable_mp(this, &SceneTreeEditor::_selected_changed)); tree->connect("item_edited", callable_mp(this, &SceneTreeEditor::_renamed), varray(), CONNECT_DEFERRED); tree->connect("multi_selected", callable_mp(this, &SceneTreeEditor::_cell_multi_selected)); tree->connect("button_pressed", callable_mp(this, &SceneTreeEditor::_cell_button_pressed)); diff --git a/editor/scene_tree_editor.h b/editor/scene_tree_editor.h index e833bf93e0..acd49e8d92 100644 --- a/editor/scene_tree_editor.h +++ b/editor/scene_tree_editor.h @@ -81,6 +81,7 @@ class SceneTreeEditor : public Control { TreeItem *_find(TreeItem *p_node, const NodePath &p_path); void _notification(int p_what); + void _selected_changed(); void _deselect_items(); void _rename_node(ObjectID p_node, const String &p_name); @@ -132,8 +133,6 @@ class SceneTreeEditor : public Control { Vector<StringName> valid_types; - void _emit_node_selected(); - public: void set_filter(const String &p_filter); String get_filter() const; diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 2601382009..4cbc859e0c 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -205,12 +205,12 @@ String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must bool found = false; bool match = false; int index = 0; - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(extension) == 0) { + for (const String &E : extensions) { + if (E.nocasecmp_to(extension) == 0) { //FIXME (?) - changing language this way doesn't update controls, needs rework //language_menu->select(index); // change Language option by extension found = true; - if (E->get() == ScriptServer::get_language(language_menu->get_selected())->get_extension()) { + if (E == ScriptServer::get_language(language_menu->get_selected())->get_extension()) { match = true; } break; @@ -373,8 +373,8 @@ void ScriptCreateDialog::_lang_changed(int l) { ScriptServer::get_language(m)->get_recognized_extensions(&extensions); } - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - if (E->get().nocasecmp_to(extension) == 0) { + for (const String &E : extensions) { + if (E.nocasecmp_to(extension) == 0) { path = path.get_basename() + selected_ext; _path_changed(path); break; @@ -534,8 +534,8 @@ void ScriptCreateDialog::_browse_path(bool browse_parent, bool p_save) { int lang = language_menu->get_selected(); ScriptServer::get_language(lang)->get_recognized_extensions(&extensions); - for (List<String>::Element *E = extensions.front(); E; E = E->next()) { - file_browse->add_filter("*." + E->get()); + for (const String &E : extensions) { + file_browse->add_filter("*." + E); } file_browse->set_current_path(file_path->get_text()); @@ -604,7 +604,7 @@ void ScriptCreateDialog::_path_submitted(const String &p_path) { } void ScriptCreateDialog::_msg_script_valid(bool valid, const String &p_msg) { - error_label->set_text("- " + p_msg); + error_label->set_text(String::utf8("• ") + p_msg); if (valid) { error_label->add_theme_color_override("font_color", get_theme_color(SNAME("success_color"), SNAME("Editor"))); } else { @@ -613,7 +613,7 @@ void ScriptCreateDialog::_msg_script_valid(bool valid, const String &p_msg) { } void ScriptCreateDialog::_msg_path_valid(bool valid, const String &p_msg) { - path_error_label->set_text("- " + p_msg); + path_error_label->set_text(String::utf8("• ") + p_msg); if (valid) { path_error_label->add_theme_color_override("font_color", get_theme_color(SNAME("success_color"), SNAME("Editor"))); } else { diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp index 0524b91634..b3ec0c96c4 100644 --- a/editor/settings_config_dialog.cpp +++ b/editor/settings_config_dialog.cpp @@ -324,15 +324,15 @@ void EditorSettingsDialog::_update_shortcuts() { List<String> slist; EditorSettings::get_singleton()->get_shortcut_list(&slist); - for (List<String>::Element *E = slist.front(); E; E = E->next()) { - Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E->get()); + for (const String &E : slist) { + Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(E); if (!sc->has_meta("original")) { continue; } Ref<InputEvent> original = sc->get_meta("original"); - String section_name = E->get().get_slice("/", 0); + String section_name = E.get_slice("/", 0); TreeItem *section; @@ -372,8 +372,8 @@ void EditorSettingsDialog::_update_shortcuts() { item->add_button(1, shortcuts->get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")), 0); item->add_button(1, shortcuts->get_theme_icon(SNAME("Close"), SNAME("EditorIcons")), 1); - item->set_tooltip(0, E->get()); - item->set_metadata(0, E->get()); + item->set_tooltip(0, E); + item->set_metadata(0, E); } } @@ -403,10 +403,9 @@ void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column List<Ref<InputEvent>> defaults = InputMap::get_singleton()->get_builtins()[current_action]; // Convert the list to an array, and only keep key events as this is for the editor. - for (List<Ref<InputEvent>>::Element *E = defaults.front(); E; E = E->next()) { - Ref<InputEventKey> k = E->get(); + for (const Ref<InputEvent> &k : defaults) { if (k.is_valid()) { - events.append(E->get()); + events.append(k); } } diff --git a/editor/shader_globals_editor.cpp b/editor/shader_globals_editor.cpp index eba96e5967..d504d3b137 100644 --- a/editor/shader_globals_editor.cpp +++ b/editor/shader_globals_editor.cpp @@ -84,7 +84,7 @@ protected: UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); - undo_redo->create_action("Set Shader Global Variable"); + undo_redo->create_action(TTR("Set Shader Global Variable")); undo_redo->add_do_method(RS::get_singleton(), "global_variable_set", p_name, p_value); undo_redo->add_undo_method(RS::get_singleton(), "global_variable_set", p_name, existing); RS::GlobalVariableType type = RS::get_singleton()->global_variable_get_type(p_name); @@ -110,7 +110,6 @@ protected: undo_redo->commit_action(); block_update = false; - print_line("all good?"); return true; } @@ -395,7 +394,7 @@ void ShaderGlobalsEditor::_variable_added() { Variant value = create_var(RS::GlobalVariableType(variable_type->get_selected())); - undo_redo->create_action("Add Shader Global Variable"); + undo_redo->create_action(TTR("Add Shader Global Variable")); undo_redo->add_do_method(RS::get_singleton(), "global_variable_add", var, RS::GlobalVariableType(variable_type->get_selected()), value); undo_redo->add_undo_method(RS::get_singleton(), "global_variable_remove", var); Dictionary gv; @@ -410,10 +409,9 @@ void ShaderGlobalsEditor::_variable_added() { } void ShaderGlobalsEditor::_variable_deleted(const String &p_variable) { - print_line("deleted " + p_variable); UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo(); - undo_redo->create_action("Add Shader Global Variable"); + undo_redo->create_action(TTR("Add Shader Global Variable")); undo_redo->add_do_method(RS::get_singleton(), "global_variable_remove", p_variable); undo_redo->add_undo_method(RS::get_singleton(), "global_variable_add", p_variable, RS::get_singleton()->global_variable_get_type(p_variable), RS::get_singleton()->global_variable_get(p_variable)); @@ -439,7 +437,6 @@ void ShaderGlobalsEditor::_bind_methods() { void ShaderGlobalsEditor::_notification(int p_what) { if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { if (is_visible_in_tree()) { - print_line("OK load settings in globalseditor"); inspector->edit(interface); } } diff --git a/editor/translations/af.po b/editor/translations/af.po index bb7e7ca553..6a74789da2 100644 --- a/editor/translations/af.po +++ b/editor/translations/af.po @@ -5251,8 +5251,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/ar.po b/editor/translations/ar.po index 6d8db6f47b..b851db361f 100644 --- a/editor/translations/ar.po +++ b/editor/translations/ar.po @@ -52,12 +52,13 @@ # ILG - Game <moegypt277@gmail.com>, 2021. # Hatim Jamal <hatimjamal8@gmail.com>, 2021. # HASSAN GAMER - حسن جيمر <gamerhassan55@gmail.com>, 2021. +# abubakrAlsaab <madeinsudan19@gmail.com>, 2021. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-07-09 14:32+0000\n" -"Last-Translator: HASSAN GAMER - حسن جيمر <gamerhassan55@gmail.com>\n" +"PO-Revision-Date: 2021-07-16 05:47+0000\n" +"Last-Translator: abubakrAlsaab <madeinsudan19@gmail.com>\n" "Language-Team: Arabic <https://hosted.weblate.org/projects/godot-engine/" "godot/ar/>\n" "Language: ar\n" @@ -66,7 +67,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 " "&& n%100<=10 ? 3 : n%100>=11 ? 4 : 5;\n" -"X-Generator: Weblate 4.8-dev\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -3021,7 +3022,7 @@ msgstr "حول" #: editor/editor_node.cpp msgid "Support Godot Development" -msgstr "" +msgstr "إدعم تطوير محرك غو-دوت" #: editor/editor_node.cpp msgid "Play the project." @@ -5215,9 +5216,10 @@ msgstr "" "الضوء المعدة مسبقا." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "لايوجد ميش لكي يتم تجهيزة. تاكد من انه يحتوي على منفذ UV2 و ان زر الضوء " "'المعد' مفعل." @@ -5342,7 +5344,7 @@ msgstr "تعديل حجم العقدة \"Node2D \"%s إلى (s, %s%)" #: editor/plugins/canvas_item_editor_plugin.cpp msgid "Resize Control \"%s\" to (%d, %d)" -msgstr "" +msgstr "تغيير حجم عنصر التحكم \"٪ s\" إلى (٪ d،٪ d)" #: editor/plugins/canvas_item_editor_plugin.cpp #, fuzzy @@ -7566,6 +7568,7 @@ msgstr "تدوير الرؤية مقفول" msgid "" "To zoom further, change the camera's clipping planes (View -> Settings...)" msgstr "" +"للتكبير بشكل أكبر ، قم بتغيير مستويات اقتصاص الكاميرا (عرض -> الإعدادات ...)" #: editor/plugins/spatial_editor_plugin.cpp msgid "" @@ -9536,7 +9539,7 @@ msgstr "" #: editor/plugins/visual_shader_editor_plugin.cpp msgid "A reference to an existing uniform." -msgstr "" +msgstr "إشارة إلى زي موحد موجود." #: editor/plugins/visual_shader_editor_plugin.cpp msgid "(Fragment/Light mode only) Scalar derivative function." @@ -9903,7 +9906,7 @@ msgstr "OpenGL ES 3.0" #: editor/project_manager.cpp msgid "Not supported by your GPU drivers." -msgstr "" +msgstr "غير مدعوم من قبل برامج تشغيل GPU(اجهزة اارسوم) الخاصة بك." #: editor/project_manager.cpp msgid "" @@ -10959,6 +10962,9 @@ msgid "" "every time it updates.\n" "Switch back to the Local scene tree dock to improve performance." msgstr "" +"إذا تم تحديده ، فسيؤدي شجرة المشهد إلى توقف المشروع في كل مرة يتم فيها " +"تحديثه.\n" +"قم بالتبديل مرة أخرى إلى رصيف شجرة المشهد المحلي لتحسين الأداء." #: editor/scene_tree_dock.cpp msgid "Local" @@ -11657,11 +11663,11 @@ msgstr "" #: modules/lightmapper_cpu/lightmapper_cpu.cpp msgid "Begin Bake" -msgstr "" +msgstr "ابدأ الخبز (دمج تاثير الضوء في الصورة )" #: modules/lightmapper_cpu/lightmapper_cpu.cpp msgid "Preparing data structures" -msgstr "" +msgstr "تحضير هياكل البيانات" #: modules/lightmapper_cpu/lightmapper_cpu.cpp #, fuzzy @@ -12192,7 +12198,7 @@ msgstr "اختر جهازاً من القائمة" #: platform/android/export/export.cpp msgid "Unable to find the 'apksigner' tool." -msgstr "" +msgstr "تعذر العثور على أداة توقيع تطبيق اندرويد\"apksigner\"." #: platform/android/export/export.cpp msgid "" diff --git a/editor/translations/az.po b/editor/translations/az.po index 054bc9263d..be05c12c5c 100644 --- a/editor/translations/az.po +++ b/editor/translations/az.po @@ -5056,8 +5056,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/bg.po b/editor/translations/bg.po index 7bf3d40805..9759e3d1e5 100644 --- a/editor/translations/bg.po +++ b/editor/translations/bg.po @@ -5042,9 +5042,10 @@ msgstr "" "Запазете сцената и опитайте отново." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Няма полигонни мрежи за изпичане. Уверете се, че те съдържат канал UV2 и че " "флагът „Изпичане на светлината“ е включен." diff --git a/editor/translations/bn.po b/editor/translations/bn.po index 70a66820fb..f4a10f7dea 100644 --- a/editor/translations/bn.po +++ b/editor/translations/bn.po @@ -5526,8 +5526,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/br.po b/editor/translations/br.po index 9d1e52e009..0fe39331f9 100644 --- a/editor/translations/br.po +++ b/editor/translations/br.po @@ -5000,8 +5000,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/ca.po b/editor/translations/ca.po index 1032b7cdeb..40429cc0e0 100644 --- a/editor/translations/ca.po +++ b/editor/translations/ca.po @@ -5277,9 +5277,10 @@ msgstr "" "camí des de les propietats de BakedLightmap." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Cap Malla per precalcular. Comproveu que disposin d'un canal d'UV2 i que " "l'indicador 'Bake Light' és activat." diff --git a/editor/translations/cs.po b/editor/translations/cs.po index 3aaf91d758..281bc500f2 100644 --- a/editor/translations/cs.po +++ b/editor/translations/cs.po @@ -30,8 +30,8 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-06-25 02:57+0000\n" -"Last-Translator: Vojtěch Šamla <auzkok@seznam.cz>\n" +"PO-Revision-Date: 2021-07-26 14:18+0000\n" +"Last-Translator: Zbyněk <zbynek.fiala@gmail.com>\n" "Language-Team: Czech <https://hosted.weblate.org/projects/godot-engine/godot/" "cs/>\n" "Language: cs\n" @@ -39,7 +39,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" -"X-Generator: Weblate 4.7.1-dev\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -5139,7 +5139,7 @@ msgstr "Poslední" #: editor/plugins/asset_library_editor_plugin.cpp msgid "All" -msgstr "Všechny" +msgstr "všichni" #: editor/plugins/asset_library_editor_plugin.cpp msgid "No results for \"%s\"." @@ -5194,9 +5194,10 @@ msgstr "" "Uložte scénu a zkuste to znovu." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Žádné sítě k zapečení. Ujistěte se, že obsahují kanál UV2 a že je nastaven " "příznak \"Zapéct světlo\"." @@ -10546,7 +10547,7 @@ msgstr "Hodnota, o kterou se počítadlo zvýší za každý uzel" #: editor/rename_dialog.cpp msgid "Padding" -msgstr "Odsazení" +msgstr "Zarovnávání" #: editor/rename_dialog.cpp msgid "" diff --git a/editor/translations/da.po b/editor/translations/da.po index 9e09250fbc..c86ec25b4b 100644 --- a/editor/translations/da.po +++ b/editor/translations/da.po @@ -5390,8 +5390,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/de.po b/editor/translations/de.po index bbf72f815b..954f8426f8 100644 --- a/editor/translations/de.po +++ b/editor/translations/de.po @@ -5289,9 +5289,10 @@ msgstr "" "Ein Speichern der Szene sollte dieses Problem beheben." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Keine Meshes zum vorrendern vorhanden. Meshes, die vorgerendert werden " "sollen, müssen einen UV2-Kanal beinhalten und die ‚Bake Light‘-Option " diff --git a/editor/translations/editor.pot b/editor/translations/editor.pot index a0f4654639..ae7b6b37dc 100644 --- a/editor/translations/editor.pot +++ b/editor/translations/editor.pot @@ -4980,8 +4980,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp @@ -6979,7 +6979,7 @@ msgstr "" #: editor/plugins/shader_editor_plugin.cpp msgid "" -"This shader has been modified on on disk.\n" +"This shader has been modified on disk.\n" "What action should be taken?" msgstr "" diff --git a/editor/translations/el.po b/editor/translations/el.po index 035a82f99f..40d8ab46cc 100644 --- a/editor/translations/el.po +++ b/editor/translations/el.po @@ -5239,9 +5239,10 @@ msgstr "" "Αποθηκεύστε τη σκηνή σας και δοκιμάστε ξανα." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Δεν υπάρχουν πλέγματα για προετοιμασία. Σιγουρευτείτε ότι εμπεριέχουν κανάλι " "UV2 και πως η σημαία 'Bake Light' είναι ενεργοποιημένη." diff --git a/editor/translations/eo.po b/editor/translations/eo.po index 0523742303..38c72380da 100644 --- a/editor/translations/eo.po +++ b/editor/translations/eo.po @@ -5204,8 +5204,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/es.po b/editor/translations/es.po index 5953536c60..e09d1df8c7 100644 --- a/editor/translations/es.po +++ b/editor/translations/es.po @@ -72,7 +72,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-07-05 21:41+0000\n" +"PO-Revision-Date: 2021-07-16 05:47+0000\n" "Last-Translator: Erick Figueroa <querecuto@hotmail.com>\n" "Language-Team: Spanish <https://hosted.weblate.org/projects/godot-engine/" "godot/es/>\n" @@ -81,7 +81,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.8-dev\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1205,7 +1205,7 @@ msgstr "Desarrollador Principal" #. you do not have to keep it in your translation. #: editor/editor_about.cpp msgid "Project Manager " -msgstr "Gestor del Proyecto " +msgstr "Administrador de Proyectos " #: editor/editor_about.cpp msgid "Developers" @@ -3078,7 +3078,7 @@ msgstr "Apoyar el desarrollo de Godot" #: editor/editor_node.cpp msgid "Play the project." -msgstr "Reproducir el proyecto." +msgstr "Ejecutar el proyecto." #: editor/editor_node.cpp msgid "Play" @@ -5293,9 +5293,10 @@ msgstr "" "Guarda tu escena e inténtalo de nuevo." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "No hay mallas para hacer bake. Asegúrate que contengan un canal UV2 y que la " "opción de 'Bake Light' está activada." @@ -10154,8 +10155,8 @@ msgid "" "The interface will update after restarting the editor or project manager." msgstr "" "Idioma cambiado.\n" -"La interfaz se actualizará después de reiniciar el editor o el gestor de " -"proyectos." +"La interfaz se actualizará después de reiniciar el editor o el administrador " +"de proyectos." #: editor/project_manager.cpp msgid "" @@ -11737,7 +11738,7 @@ msgstr "Eliminar Rotación del Cursor" #: modules/gridmap/grid_map_editor_plugin.cpp msgid "Paste Selects" -msgstr "Pegar Selecciona" +msgstr "Pegar Seleccionados" #: modules/gridmap/grid_map_editor_plugin.cpp msgid "Clear Selection" diff --git a/editor/translations/es_AR.po b/editor/translations/es_AR.po index d1fe06a565..33c29d9c6e 100644 --- a/editor/translations/es_AR.po +++ b/editor/translations/es_AR.po @@ -5237,9 +5237,10 @@ msgstr "" "Guardá tu escena e inténtalo de nuevo." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "No hay meshes para hacer bake. Asegúrate que contienen un canal UV2 y que el " "flag 'Bake Light' esta activado." diff --git a/editor/translations/et.po b/editor/translations/et.po index 05a414f5a9..fd534943b1 100644 --- a/editor/translations/et.po +++ b/editor/translations/et.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" -"PO-Revision-Date: 2021-05-10 15:32+0000\n" +"PO-Revision-Date: 2021-07-16 05:47+0000\n" "Last-Translator: Kritzmensch <streef.gtx@gmail.com>\n" "Language-Team: Estonian <https://hosted.weblate.org/projects/godot-engine/" "godot/et/>\n" @@ -18,7 +18,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8-bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1090,7 +1090,7 @@ msgstr "Suur tänu Godot kogukonnalt!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Klõpsa, et kopeerida." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -5039,8 +5039,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp @@ -7244,7 +7244,7 @@ msgstr "Kuva tavaliselt" #: editor/plugins/spatial_editor_plugin.cpp msgid "Display Wireframe" -msgstr "Kuva traadiraamina" +msgstr "Kuva traatraamina" #: editor/plugins/spatial_editor_plugin.cpp msgid "Display Overdraw" diff --git a/editor/translations/eu.po b/editor/translations/eu.po index 87c91de10e..f9f2d97348 100644 --- a/editor/translations/eu.po +++ b/editor/translations/eu.po @@ -5012,8 +5012,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/fa.po b/editor/translations/fa.po index ddccfeaebe..ab4157565e 100644 --- a/editor/translations/fa.po +++ b/editor/translations/fa.po @@ -5191,8 +5191,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/fi.po b/editor/translations/fi.po index 834d1894e3..1007ee660b 100644 --- a/editor/translations/fi.po +++ b/editor/translations/fi.po @@ -5195,9 +5195,10 @@ msgstr "" "Tallenna skenesi ja yritä uudelleen." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Ei meshejä kehitettävänä. Varmista, että ne sisältävät UV2-kanavan, ja että " "'Bake Light' asetus on päällä." diff --git a/editor/translations/fil.po b/editor/translations/fil.po index 892968821b..b23a43088c 100644 --- a/editor/translations/fil.po +++ b/editor/translations/fil.po @@ -4998,8 +4998,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/fr.po b/editor/translations/fr.po index 6fad70a7c2..d4ded02294 100644 --- a/editor/translations/fr.po +++ b/editor/translations/fr.po @@ -85,8 +85,8 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-07-01 14:33+0000\n" -"Last-Translator: Clément Topy <topy72.mine@gmail.com>\n" +"PO-Revision-Date: 2021-07-16 05:47+0000\n" +"Last-Translator: Pierre Caye <pierrecaye@laposte.net>\n" "Language-Team: French <https://hosted.weblate.org/projects/godot-engine/" "godot/fr/>\n" "Language: fr\n" @@ -94,7 +94,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n > 1;\n" -"X-Generator: Weblate 4.8-dev\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -5258,7 +5258,7 @@ msgstr "Dernier" #: editor/plugins/asset_library_editor_plugin.cpp msgid "All" -msgstr "Tout" +msgstr "All" #: editor/plugins/asset_library_editor_plugin.cpp msgid "No results for \"%s\"." @@ -5314,11 +5314,12 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" -"Aucun maillage à transférer. Assurez-vous qu'ils contiennent un canal UV2 et " -"que l'indicateur « Bake Light » est activé." +"Aucun maillage à précalculer. Assurez-vous qu'ils contiennent un canal UV2 " +"et que les propriétés « Use In Bake Light » et « Generate Lightmap » soient " +"activées." #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "Failed creating lightmap images, make sure path is writable." diff --git a/editor/translations/ga.po b/editor/translations/ga.po index 8168c1a440..9db93e38f8 100644 --- a/editor/translations/ga.po +++ b/editor/translations/ga.po @@ -4995,8 +4995,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/gl.po b/editor/translations/gl.po index 016a3ab589..68e7b47599 100644 --- a/editor/translations/gl.po +++ b/editor/translations/gl.po @@ -5162,8 +5162,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/he.po b/editor/translations/he.po index 5dc30a6cc2..a989a8aad0 100644 --- a/editor/translations/he.po +++ b/editor/translations/he.po @@ -5214,9 +5214,10 @@ msgstr "" "ממאפייני BakedLightmap." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "אין רשתות לאפייה. ודא/י שהם מכילים ערוץ UV2 והדגל 'Bake Light' מאופשר." #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/hi.po b/editor/translations/hi.po index db1dcd67e6..70187feed0 100644 --- a/editor/translations/hi.po +++ b/editor/translations/hi.po @@ -5137,8 +5137,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/hr.po b/editor/translations/hr.po index d737bb04b7..c62d3f3eb5 100644 --- a/editor/translations/hr.po +++ b/editor/translations/hr.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" -"PO-Revision-Date: 2021-04-11 22:02+0000\n" +"PO-Revision-Date: 2021-07-16 05:47+0000\n" "Last-Translator: LeoClose <leoclose575@gmail.com>\n" "Language-Team: Croatian <https://hosted.weblate.org/projects/godot-engine/" "godot/hr/>\n" @@ -18,7 +18,7 @@ msgstr "" "Content-Transfer-Encoding: 8-bit\n" "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" -"X-Generator: Weblate 4.6-dev\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -41,7 +41,7 @@ msgstr "Neispravan unos %i (nije uspio) u izrazu" #: core/math/expression.cpp msgid "self can't be used because instance is null (not passed)" -msgstr "self nije moguće koristiti jer je jedinka null (nije uspio)" +msgstr "self se ne može koristiti jer instanca je null (nije prosljeđena)" #: core/math/expression.cpp msgid "Invalid operands to operator %s, %s and %s." @@ -1716,7 +1716,7 @@ msgstr "Novo" #: editor/editor_feature_profile.cpp editor/editor_node.cpp #: editor/project_manager.cpp msgid "Import" -msgstr "Uvoz" +msgstr "Uvezi" #: editor/editor_feature_profile.cpp editor/project_export.cpp msgid "Export" @@ -2861,7 +2861,7 @@ msgstr "Zajednica" #: editor/editor_node.cpp msgid "About" -msgstr "" +msgstr "U vezi s" #: editor/editor_node.cpp msgid "Support Godot Development" @@ -5009,8 +5009,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/hu.po b/editor/translations/hu.po index 85933dc05d..7a2e35e37b 100644 --- a/editor/translations/hu.po +++ b/editor/translations/hu.po @@ -5180,9 +5180,10 @@ msgstr "" "tulajdonságaiból." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Nincs mesh, amibe adatokat süthetne. Bizonyosodjon meg arról, hogy " "tartalmaznak egy UV2 csatornát, és hogy a 'Fény Besütése' opció be van " diff --git a/editor/translations/id.po b/editor/translations/id.po index e1029fc231..4dce64fd92 100644 --- a/editor/translations/id.po +++ b/editor/translations/id.po @@ -5210,9 +5210,10 @@ msgstr "" "Simpan skena Anda dan coba lagi." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Tidak ada mesh-mesh untuk di bake. Pastikan mereka punya kanal UV2 dan 'Bake " "Cahaya' menyala." diff --git a/editor/translations/is.po b/editor/translations/is.po index fc1423d841..c7d7023690 100644 --- a/editor/translations/is.po +++ b/editor/translations/is.po @@ -5051,8 +5051,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/it.po b/editor/translations/it.po index 60c362c63a..f1de95dac6 100644 --- a/editor/translations/it.po +++ b/editor/translations/it.po @@ -59,12 +59,13 @@ # Alessandro Mandelli <mandelli.alessandro@ngi.it>, 2021. # Jusef Azzolina <rosarioazzolina33@gmail.com>, 2021. # Daniele Basso <tiziodcaio@gmail.com>, 2021. +# Riteo Siuga <riteo@posteo.net>, 2021. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-06-15 19:34+0000\n" -"Last-Translator: Riteo Siuga <lorenzocerqua@tutanota.com>\n" +"PO-Revision-Date: 2021-07-26 14:18+0000\n" +"Last-Translator: Riteo Siuga <riteo@posteo.net>\n" "Language-Team: Italian <https://hosted.weblate.org/projects/godot-engine/" "godot/it/>\n" "Language: it\n" @@ -72,7 +73,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -876,6 +877,7 @@ msgid "Deferred" msgstr "Differita" #: editor/connections_dialog.cpp +#, fuzzy msgid "" "Defers the signal, storing it in a queue and only firing it at idle time." msgstr "" @@ -1172,7 +1174,7 @@ msgstr "Grazie dalla comunità di Godot!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Clicca per copiare." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -2348,7 +2350,7 @@ msgid "" msgstr "" "Questa scena non può essere salvata perché contiene un'istanziazione " "ciclica.\n" -"Riprovare ad eseguire il salvataggio dopo aver risolto il problema." +"Riprovare a eseguire il salvataggio dopo aver risolto il problema." #: editor/editor_node.cpp msgid "" @@ -2962,7 +2964,7 @@ msgstr "" #: editor/editor_node.cpp msgid "Synchronize Scene Changes" -msgstr "Sincronizza i cambi della scena" +msgstr "Sincronizza i cambiamenti delle scene" #: editor/editor_node.cpp msgid "" @@ -2978,9 +2980,10 @@ msgstr "" #: editor/editor_node.cpp msgid "Synchronize Script Changes" -msgstr "Sincronizza Modifiche Script" +msgstr "Sincronizza le modifiche degli script" #: editor/editor_node.cpp +#, fuzzy msgid "" "When this option is enabled, any script that is saved will be reloaded in " "the running project.\n" @@ -2989,7 +2992,7 @@ msgid "" msgstr "" "Quando questa opzione è abilitata, qualsiasi script salvato verrà ricaricato " "nel progetto in esecuzione.\n" -"Quando usato in remoto su un dispositivo, essa risulta più efficate " +"Quando usato in remoto su un dispositivo, essa risulta più efficace " "abilitando l'opzione \"network filesystem\"." #: editor/editor_node.cpp editor/script_create_dialog.cpp @@ -3062,6 +3065,7 @@ msgid "Report a Bug" msgstr "Segnala un problema" #: editor/editor_node.cpp +#, fuzzy msgid "Send Docs Feedback" msgstr "Valuta la documentazione" @@ -3078,6 +3082,7 @@ msgid "Support Godot Development" msgstr "Supporta lo sviluppo di Godot" #: editor/editor_node.cpp +#, fuzzy msgid "Play the project." msgstr "Esegui il progetto." @@ -3091,7 +3096,7 @@ msgstr "Metti in pausa l'esecuzione della scena per eseguire il debug." #: editor/editor_node.cpp msgid "Pause Scene" -msgstr "Pausa scena" +msgstr "Pausa la scena" #: editor/editor_node.cpp msgid "Stop the scene." @@ -3115,7 +3120,7 @@ msgstr "Avvia una scena personalizzata" #: editor/editor_node.cpp msgid "Changing the video driver requires restarting the editor." -msgstr "Il cambiamento dei driver video necessita il riavvio dell'editor." +msgstr "Il cambiamento dei driver video necessita di un riavvio dell'editor." #: editor/editor_node.cpp editor/project_settings_editor.cpp #: editor/settings_config_dialog.cpp @@ -3131,6 +3136,7 @@ msgid "Update Continuously" msgstr "Aggiorna continuamente" #: editor/editor_node.cpp +#, fuzzy msgid "Update When Changed" msgstr "Aggiorna quando modificata" @@ -3209,16 +3215,17 @@ msgid "Template Package" msgstr "Pacchetto di modelli" #: editor/editor_node.cpp +#, fuzzy msgid "Export Library" msgstr "Esporta Libreria" #: editor/editor_node.cpp msgid "Merge With Existing" -msgstr "Unisci Con Esistente" +msgstr "Unisci con una esistente" #: editor/editor_node.cpp msgid "Open & Run a Script" -msgstr "Apri ed Esegui uno Script" +msgstr "Apri ed esegui uno script" #: editor/editor_node.cpp msgid "" @@ -3244,7 +3251,7 @@ msgstr "Nuova ereditata" #: editor/editor_node.cpp msgid "Load Errors" -msgstr "Carica errori" +msgstr "Errori di caricamento" #: editor/editor_node.cpp editor/plugins/tile_map_editor_plugin.cpp msgid "Select" @@ -3252,27 +3259,28 @@ msgstr "Seleziona" #: editor/editor_node.cpp msgid "Open 2D Editor" -msgstr "Apri Editor 2D" +msgstr "Apri l'editor 2D" #: editor/editor_node.cpp msgid "Open 3D Editor" -msgstr "Apri Editor 3D" +msgstr "Apri l'editor 3D" #: editor/editor_node.cpp msgid "Open Script Editor" -msgstr "Apri Editor degli script" +msgstr "Apri l'editor degli script" #: editor/editor_node.cpp editor/project_manager.cpp +#, fuzzy msgid "Open Asset Library" -msgstr "Apri Libreria degli Asset" +msgstr "Apri la libreria degli Asset" #: editor/editor_node.cpp msgid "Open the next Editor" -msgstr "Apri l'Editor successivo" +msgstr "Apri l'editor successivo" #: editor/editor_node.cpp msgid "Open the previous Editor" -msgstr "Apri l'Editor precedente" +msgstr "Apri l'editor precedente" #: editor/editor_node.h msgid "Warning!" @@ -3284,7 +3292,7 @@ msgstr "Nessuna sottorisorsa trovata." #: editor/editor_plugin.cpp msgid "Creating Mesh Previews" -msgstr "Creazione Anteprime Mesh" +msgstr "Creando le anteprime delle mesh" #: editor/editor_plugin.cpp msgid "Thumbnail..." @@ -3292,11 +3300,11 @@ msgstr "Miniatura..." #: editor/editor_plugin_settings.cpp msgid "Main Script:" -msgstr "Script Principale:" +msgstr "Script principale:" #: editor/editor_plugin_settings.cpp msgid "Edit Plugin" -msgstr "Modifica estensione" +msgstr "Modifica l'estensione" #: editor/editor_plugin_settings.cpp msgid "Installed Plugins:" @@ -3328,32 +3336,37 @@ msgid "Measure:" msgstr "Misura:" #: editor/editor_profiler.cpp +#, fuzzy msgid "Frame Time (sec)" -msgstr "Tempo Frame (sec)" +msgstr "Tempo fotogramma (sec)" #: editor/editor_profiler.cpp +#, fuzzy msgid "Average Time (sec)" -msgstr "Tempo Medio (sec)" +msgstr "Tempo medio (sec)" #: editor/editor_profiler.cpp +#, fuzzy msgid "Frame %" -msgstr "Frame %" +msgstr "% fotogramma" #: editor/editor_profiler.cpp +#, fuzzy msgid "Physics Frame %" -msgstr "Fotogramma della Fisica %" +msgstr "% fotogramma fisico" #: editor/editor_profiler.cpp msgid "Inclusive" msgstr "Inclusivo" #: editor/editor_profiler.cpp +#, fuzzy msgid "Self" msgstr "Se stesso" #: editor/editor_profiler.cpp msgid "Frame #:" -msgstr "Frame #:" +msgstr "Fotogramma #:" #: editor/editor_profiler.cpp msgid "Time" @@ -3365,7 +3378,7 @@ msgstr "Chiamate" #: editor/editor_properties.cpp msgid "Edit Text:" -msgstr "Modifica Testo:" +msgstr "Modifica il testo:" #: editor/editor_properties.cpp editor/script_create_dialog.cpp msgid "On" @@ -3389,55 +3402,57 @@ msgstr "Assegna..." #: editor/editor_properties.cpp msgid "Invalid RID" -msgstr "RID Invalido" +msgstr "RID non valido" #: editor/editor_properties.cpp msgid "" "The selected resource (%s) does not match any type expected for this " "property (%s)." msgstr "" -"La risorsa selezionata (%s) non corrisponde ad alcun tipo atteso per questa " -"proprietà (%s)." +"La risorsa selezionata (%s) non corrisponde ad alcun tipo previsto per " +"questa proprietà (%s)." #: editor/editor_properties.cpp msgid "" "Can't create a ViewportTexture on resources saved as a file.\n" "Resource needs to belong to a scene." msgstr "" -"Impossibile creare ViewportTexture da risorse salvate come file.\n" -"La risorsa deve appartenere ad una scena." +"Impossibile creare un ViewportTexture su delle risorse salvate come file.\n" +"Esse devono appartenere a una scena." #: editor/editor_properties.cpp +#, fuzzy msgid "" "Can't create a ViewportTexture on this resource because it's not set as " "local to scene.\n" "Please switch on the 'local to scene' property on it (and all resources " "containing it up to a node)." msgstr "" -"Impossibile creare ViewportTexture da questa risorsa perché non è definita " -"localmente in una scena.\n" -"Per favore attivare la proprietà \"local to scene\" sulla risorsa (e su " -"tutte le risorse che la contengono, fino al nodo che le utilizza)." +"Impossibile creare un VieportTexture su questa risorsa perché non è stata " +"impostata come locale alla scena.\n" +"Per favore attivare la properietà \"local to scene\" su di essa (e su tutte " +"quelle che la contengono fino ad arrivare a un nodo)." #: editor/editor_properties.cpp editor/property_editor.cpp msgid "Pick a Viewport" -msgstr "Scegli una Vista" +msgstr "Selezionare una vista" #: editor/editor_properties.cpp editor/property_editor.cpp msgid "New Script" -msgstr "Nuovo Script" +msgstr "Nuovo script" #: editor/editor_properties.cpp editor/scene_tree_dock.cpp msgid "Extend Script" -msgstr "Estendi Script" +msgstr "Estendi script" #: editor/editor_properties.cpp editor/property_editor.cpp msgid "New %s" msgstr "Nuovo %s" #: editor/editor_properties.cpp editor/property_editor.cpp +#, fuzzy msgid "Make Unique" -msgstr "Rendi Unico" +msgstr "Rendi unico" #: editor/editor_properties.cpp #: editor/plugins/animation_blend_space_1d_editor.cpp @@ -3455,11 +3470,12 @@ msgstr "Incolla" #: editor/editor_properties.cpp editor/property_editor.cpp msgid "Convert To %s" -msgstr "Converti In %s" +msgstr "Converti in %s" #: editor/editor_properties.cpp editor/property_editor.cpp +#, fuzzy msgid "Selected node is not a Viewport!" -msgstr "Il nodo selezionato non è una Viewport!" +msgstr "Il nodo selezionato non è un Viewport!" #: editor/editor_properties_array_dict.cpp msgid "Size: " @@ -3472,19 +3488,19 @@ msgstr "Pagina: " #: editor/editor_properties_array_dict.cpp #: editor/plugins/theme_editor_plugin.cpp msgid "Remove Item" -msgstr "Rimuovi Elemento" +msgstr "Rimuovi l'elemento" #: editor/editor_properties_array_dict.cpp msgid "New Key:" -msgstr "Nuova Chiave:" +msgstr "Nuova chiave:" #: editor/editor_properties_array_dict.cpp msgid "New Value:" -msgstr "Nuovo Valore:" +msgstr "Nuovo valore:" #: editor/editor_properties_array_dict.cpp msgid "Add Key/Value Pair" -msgstr "Aggiungi Coppia Chiave/Valore" +msgstr "Aggiungi una coppia chiave/valore" #: editor/editor_run_native.cpp msgid "" @@ -3492,13 +3508,15 @@ msgid "" "Please add a runnable preset in the Export menu or define an existing preset " "as runnable." msgstr "" -"Nessuna esportazione eseguibile trovata per questa piattaforma.\n" -"Per favore, aggiungi un preset eseguibile nel menù Export oppure definisci " -"un preset già esistente come \"eseguibile\"." +"Nessuna preimpostazione di esportazione eseguibile trovata per questa " +"piattaforma.\n" +"Per favore, aggiungerne una nel menù di esportazione o impostarne una già " +"esistente come eseguibile." #: editor/editor_run_script.cpp +#, fuzzy msgid "Write your logic in the _run() method." -msgstr "Scrivi la logica nel metodo _run()." +msgstr "Inserire la logica dello script nel metodo _run()." #: editor/editor_run_script.cpp msgid "There is an edited scene already." @@ -4499,7 +4517,7 @@ msgstr "Rimuovi Triangolo BlendSpace2D" #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "BlendSpace2D does not belong to an AnimationTree node." -msgstr "BlendSpace2D non appartiene ad un nodo AnimationTree." +msgstr "BlendSpace2D non appartiene a un nodo AnimationTree." #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "No triangles exist, so no blending can take place." @@ -5292,9 +5310,10 @@ msgstr "" "Salva la scena e riprova." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Nessuna mesh da preprocessare. Assicurarsi che contengano un canale UV2 e " "che la spunta \"Bake Light\" sia abilitata." @@ -6658,7 +6677,7 @@ msgstr "Spostare il giunto" #: editor/plugins/polygon_2d_editor_plugin.cpp msgid "" "The skeleton property of the Polygon2D does not point to a Skeleton2D node" -msgstr "La proprietà scheletro del Polygon2D non punta ad un nodo Skeleton2D" +msgstr "La proprietà scheletro del Polygon2D non punta a un nodo Skeleton2D" #: editor/plugins/polygon_2d_editor_plugin.cpp msgid "Sync Bones" @@ -6914,7 +6933,7 @@ msgstr "Preloader Risorsa" #: editor/plugins/root_motion_editor_plugin.cpp msgid "AnimationTree has no path set to an AnimationPlayer" -msgstr "AnimationTree non ha nessun percorso impostato ad un AnimationPlayer" +msgstr "AnimationTree non ha nessun percorso impostato a un AnimationPlayer" #: editor/plugins/root_motion_editor_plugin.cpp msgid "Path to AnimationPlayer is invalid" @@ -6982,10 +7001,11 @@ msgid "Script is not in tool mode, will not be able to run." msgstr "Lo script non è in modalità tool, non sarà possibile eseguirlo." #: editor/plugins/script_editor_plugin.cpp +#, fuzzy msgid "" "To run this script, it must inherit EditorScript and be set to tool mode." msgstr "" -"Per eseguire questo script, esso deve ereditare EditorScript ed essere " +"Per eseguire questo script, esso deve ereditare da EditorScript ed essere " "impostato in modalità tool." #: editor/plugins/script_editor_plugin.cpp @@ -9322,8 +9342,9 @@ msgid "Finds the nearest even integer to the parameter." msgstr "Trova il numero intero pari più vicino al parametro." #: editor/plugins/visual_shader_editor_plugin.cpp +#, fuzzy msgid "Clamps the value between 0.0 and 1.0." -msgstr "Blocca il valore tra 0.0 ed 1.0." +msgstr "Blocca il valore tra 0.0 e 1.0." #: editor/plugins/visual_shader_editor_plugin.cpp msgid "Extracts the sign of the parameter." @@ -9342,6 +9363,7 @@ msgid "Returns the square root of the parameter." msgstr "Restituisce la radice quadrata del parametro." #: editor/plugins/visual_shader_editor_plugin.cpp +#, fuzzy msgid "" "SmoothStep function( scalar(edge0), scalar(edge1), scalar(x) ).\n" "\n" @@ -9353,7 +9375,7 @@ msgstr "" "\n" "Restituisce 0.0 se \"x\" è più piccolo di \"edge0\", o 1.0 se \"x\" è più " "grande di \"edge1\". Altrimenti, il valore di ritorno è interpolato tra 0.0 " -"ed 1.0 usando i polinomi di Hermite." +"e 1.0 usando i polinomi di Hermite." #: editor/plugins/visual_shader_editor_plugin.cpp msgid "" @@ -9430,6 +9452,7 @@ msgid "Transform function." msgstr "Funzione di trasformazione." #: editor/plugins/visual_shader_editor_plugin.cpp +#, fuzzy msgid "" "Calculate the outer product of a pair of vectors.\n" "\n" @@ -9513,6 +9536,7 @@ msgid "Calculates the dot product of two vectors." msgstr "Calcola il prodotto scalare di due vettori." #: editor/plugins/visual_shader_editor_plugin.cpp +#, fuzzy msgid "" "Returns the vector that points in the same direction as a reference vector. " "The function has three vector parameters : N, the vector to orient, I, the " @@ -9562,6 +9586,7 @@ msgid "Returns the vector that points in the direction of refraction." msgstr "Restituisce un vettore che punta nella direzione della refrazione." #: editor/plugins/visual_shader_editor_plugin.cpp +#, fuzzy msgid "" "SmoothStep function( vector(edge0), vector(edge1), vector(x) ).\n" "\n" @@ -9571,11 +9596,12 @@ msgid "" msgstr "" "SmoothStep function( vector(edge0), vector(edge1), vector(x) ).\n" "\n" -"Restituisce 0.0 se \"x\" è minore di \"edge0\", ed 1.0 se \"x\" è più grande " -"di \"edge1\". Altrimenti, il valore di ritorno è interpolato tra 0.0 ed 1.0 " +"Restituisce 0.0 se \"x\" è minore di \"edge0\", e 1.0 se \"x\" è più grande " +"di \"edge1\". Altrimenti, il valore di ritorno è interpolato tra 0.0 e 1.0 " "usando i polinomiali di Hermite." #: editor/plugins/visual_shader_editor_plugin.cpp +#, fuzzy msgid "" "SmoothStep function( scalar(edge0), scalar(edge1), vector(x) ).\n" "\n" @@ -9585,8 +9611,8 @@ msgid "" msgstr "" "SmoothStep function( scalar(edge0), scalar(edge1), vector(x) ).\n" "\n" -"Restituisce 0.0 se \"x\" è minore di \"edge0\", ed 1.0 se \"x\" è più grande " -"di \"edge1\". Altrimenti, il valore di ritorno è interpolato tra 0.0 ed 1.0 " +"Restituisce 0.0 se \"x\" è minore di \"edge0\", e 1.0 se \"x\" è più grande " +"di \"edge1\". Altrimenti, il valore di ritorno è interpolato tra 0.0 e 1.0 " "usando i polinomiali di Hermite." #: editor/plugins/visual_shader_editor_plugin.cpp @@ -9638,13 +9664,14 @@ msgid "Vector uniform." msgstr "Uniforme vettore." #: editor/plugins/visual_shader_editor_plugin.cpp +#, fuzzy msgid "" "Custom Godot Shader Language expression, with custom amount of input and " "output ports. This is a direct injection of code into the vertex/fragment/" "light function, do not use it to write the function declarations inside." msgstr "" "Una espressione del Custom Godot Shader Language, con quantità " -"personalizzabile di porte input ed output. Questa è una iniezione diretta di " +"personalizzabile di porte input e output. Questa è una iniezione diretta di " "codice nella funzione vertex/fragment/light. Non usarla per scrivere le " "dichiarazione della funzione all'interno." @@ -9654,7 +9681,7 @@ msgid "" "direction of camera (pass associated inputs to it)." msgstr "" "Restituisce il decadimento in base al prodotto scalare della normale della " -"superfice e direzione della telecamera (passa gli input associati ad essa)." +"superfice e direzione della telecamera (passa gli input associati a essa)." #: editor/plugins/visual_shader_editor_plugin.cpp msgid "" @@ -9669,8 +9696,9 @@ msgstr "" "dichiarare varianti, uniformi e costanti." #: editor/plugins/visual_shader_editor_plugin.cpp +#, fuzzy msgid "A reference to an existing uniform." -msgstr "Un riferimento ad una uniform esistente." +msgstr "Un riferimento a una uniform esistente." #: editor/plugins/visual_shader_editor_plugin.cpp msgid "(Fragment/Light mode only) Scalar derivative function." @@ -9713,20 +9741,22 @@ msgstr "" "differenziazione locale." #: editor/plugins/visual_shader_editor_plugin.cpp +#, fuzzy msgid "" "(Fragment/Light mode only) (Vector) Sum of absolute derivative in 'x' and " "'y'." msgstr "" "(Soltanto modalità Fragment/Light) (Vettore) Somma delle derivate assolute " -"in \"x\" ed \"y\"." +"in \"x\" e \"y\"." #: editor/plugins/visual_shader_editor_plugin.cpp +#, fuzzy msgid "" "(Fragment/Light mode only) (Scalar) Sum of absolute derivative in 'x' and " "'y'." msgstr "" "(Soltanto modalità Fragment/Light) (Scalare) Somma delle derivate assolute " -"in \"x\" ed \"y\"." +"in \"x\" e \"y\"." #: editor/plugins/visual_shader_editor_plugin.cpp msgid "VisualShader" @@ -9757,13 +9787,14 @@ msgstr "" "I template di esportazione sembrano essere mancanti o non validi." #: editor/project_export.cpp +#, fuzzy msgid "" "Failed to export the project for platform '%s'.\n" "This might be due to a configuration issue in the export preset or your " "export settings." msgstr "" "Impossibile esportare il progetto per la piattaforma \"%s\".\n" -"Questo potrebbe essere dovuto ad un problema di configurazione nel preset di " +"Questo potrebbe essere dovuto a un problema di configurazione nel preset di " "esportazione o nelle impostazioni di esportazione." #: editor/project_export.cpp @@ -12264,7 +12295,7 @@ msgstr "L'oggetto base non è un Nodo!" #: modules/visual_script/visual_script_func_nodes.cpp msgid "Path does not lead Node!" -msgstr "Il percorso non conduce ad un Nodo!" +msgstr "Il percorso non conduce a un Nodo!" #: modules/visual_script/visual_script_func_nodes.cpp msgid "Invalid index property name '%s' in node %s." @@ -12676,7 +12707,7 @@ msgid "" "CollisionObject2D derived node. Please only use it as a child of Area2D, " "StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape." msgstr "" -"CollisionPolygon2D serve a fornire una forma di collisione ad un nodo " +"CollisionPolygon2D serve a fornire una forma di collisione a un nodo " "derivato di CollisionObject2D. Si prega di utilizzarlo solamente come figlio " "di Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. in modo da " "dargli una forma." @@ -12698,13 +12729,14 @@ msgstr "" "costruzione \"Segmenti\"." #: scene/2d/collision_shape_2d.cpp +#, fuzzy msgid "" "CollisionShape2D only serves to provide a collision shape to a " "CollisionObject2D derived node. Please only use it as a child of Area2D, " "StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape." msgstr "" -"CollisionShape2D serve a fornire una forma di collisione ad un nodo derivato " -"di CollisionObject2D. Si prega di utilizzarlo solamente come figlio di " +"CollisionShape2D serve a fornire una forma di collisione a un nodo derivato " +"da CollisionObject2D. Si prega di utilizzarlo solamente come figlio di " "Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. in modo da dargli " "una forma." @@ -12840,9 +12872,9 @@ msgstr "" "Modifica invece la dimensione nelle forme di collisione figlie." #: scene/2d/remote_transform_2d.cpp +#, fuzzy msgid "Path property must point to a valid Node2D node to work." -msgstr "" -"La proprietà path deve puntare ad un nodo Node2D valido per funzionare." +msgstr "La proprietà path deve puntare a un nodo Node2D valido per funzionare." #: scene/2d/skeleton_2d.cpp msgid "This Bone2D chain should end at a Skeleton2D node." @@ -12888,11 +12920,12 @@ msgid "ARVRController must have an ARVROrigin node as its parent." msgstr "ARVRController deve avere un nodo ARVROrigin come genitore." #: scene/3d/arvr_nodes.cpp +#, fuzzy msgid "" "The controller ID must not be 0 or this controller won't be bound to an " "actual controller." msgstr "" -"L'id del controller non deve essere 0 o non verrà associato ad un controller " +"L'id del controller non deve essere 0 o non verrà associato a un controller " "attuale." #: scene/3d/arvr_nodes.cpp @@ -12900,11 +12933,12 @@ msgid "ARVRAnchor must have an ARVROrigin node as its parent." msgstr "ARVRAnchor deve avere un nodo ARVROrigin come genitore." #: scene/3d/arvr_nodes.cpp +#, fuzzy msgid "" "The anchor ID must not be 0 or this anchor won't be bound to an actual " "anchor." msgstr "" -"L'ID dell'ancora non deve essere 0 oppure non verrà associato ad un'ancora " +"L'ID dell'ancora non deve essere 0 oppure non verrà associato a un'ancora " "attuale." #: scene/3d/arvr_nodes.cpp @@ -12947,28 +12981,29 @@ msgstr "" "definire la sua forma." #: scene/3d/collision_polygon.cpp +#, fuzzy msgid "" "CollisionPolygon only serves to provide a collision shape to a " "CollisionObject derived node. Please only use it as a child of Area, " "StaticBody, RigidBody, KinematicBody, etc. to give them a shape." msgstr "" -"CollisionPolygon serve solamente a fornire una forma di collisione ad un " -"nodo derivato di CollisionObject. Si prega di usarlo solamente come figlio " -"di Area, StaticBody, RigidBody, KinematicBody, etc. in modo da dargli una " -"forma." +"CollisionPolygon serve solamente a fornire una forma di collisione a un nodo " +"derivato da CollisionObject. Si prega di usarlo solamente come figlio di " +"Area, StaticBody, RigidBody, KinematicBody, etc. in modo da dargli una forma." #: scene/3d/collision_polygon.cpp msgid "An empty CollisionPolygon has no effect on collision." msgstr "Un CollisionPolygon vuoto non ha effetti in collisione." #: scene/3d/collision_shape.cpp +#, fuzzy msgid "" "CollisionShape only serves to provide a collision shape to a CollisionObject " "derived node. Please only use it as a child of Area, StaticBody, RigidBody, " "KinematicBody, etc. to give them a shape." msgstr "" -"CollisionShape serve a fornire una forma di collisione ad un nodo derivato " -"di CollisionObject. Si prega di utilizzarlo solamente come figlio di Area, " +"CollisionShape serve a fornire una forma di collisione a un nodo derivato da " +"CollisionObject. Si prega di utilizzarlo solamente come figlio di Area, " "StaticBody, RigidBody, KinematicBody, etc. in modo da dargli una forma." #: scene/3d/collision_shape.cpp @@ -13288,13 +13323,14 @@ msgid "If \"Exp Edit\" is enabled, \"Min Value\" must be greater than 0." msgstr "Se \"Exp Edit\" è abilitato, \"Min Value\" deve essere maggiore di 0." #: scene/gui/scroll_container.cpp +#, fuzzy msgid "" "ScrollContainer is intended to work with a single child control.\n" "Use a container as child (VBox, HBox, etc.), or a Control and set the custom " "minimum size manually." msgstr "" "ScrollContainer è inteso per funzionare con un singolo figlio di controllo.\n" -"Usa un container come figlio (VBox, HBox, ect.), oppure un nodo Control ed " +"Usa un container come figlio (VBox, HBox, ect.), oppure un nodo Control e " "imposta la dimensione minima personalizzata manualmente." #: scene/gui/tree.cpp diff --git a/editor/translations/ja.po b/editor/translations/ja.po index 1fd770fe13..45977a890f 100644 --- a/editor/translations/ja.po +++ b/editor/translations/ja.po @@ -5214,9 +5214,10 @@ msgstr "" "シーンを保存してから再度行ってください。" #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "ベイクするメッシュがありません。メッシュに UV2チャンネルが含まれてお" "り、'Bake Light' フラグがオンになっていることを確認してください。" diff --git a/editor/translations/ka.po b/editor/translations/ka.po index 587624651a..7a108d6f95 100644 --- a/editor/translations/ka.po +++ b/editor/translations/ka.po @@ -5176,8 +5176,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/km.po b/editor/translations/km.po index fe396cf590..33e9b00daf 100644 --- a/editor/translations/km.po +++ b/editor/translations/km.po @@ -4986,8 +4986,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/ko.po b/editor/translations/ko.po index ec9fed24ca..877f572f48 100644 --- a/editor/translations/ko.po +++ b/editor/translations/ko.po @@ -27,7 +27,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-06-20 13:35+0000\n" +"PO-Revision-Date: 2021-07-16 05:47+0000\n" "Last-Translator: Myeongjin Lee <aranet100@gmail.com>\n" "Language-Team: Korean <https://hosted.weblate.org/projects/godot-engine/" "godot/ko/>\n" @@ -36,7 +36,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 4.7\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -5182,9 +5182,10 @@ msgstr "" "당신의 씬을 저장하고 다시 시도하세요." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "라이트맵을 구울 메시가 없습니다. 메시가 UV2 채널을 갖고 있고 'Bake Light' 플" "래그가 켜져 있는지 확인해주세요." diff --git a/editor/translations/lt.po b/editor/translations/lt.po index 6df1f44cfb..f4043f1de2 100644 --- a/editor/translations/lt.po +++ b/editor/translations/lt.po @@ -5145,8 +5145,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/lv.po b/editor/translations/lv.po index 8c8a0011c7..a4c8d10715 100644 --- a/editor/translations/lv.po +++ b/editor/translations/lv.po @@ -5038,8 +5038,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/mi.po b/editor/translations/mi.po index 36a93be0ee..5a847e6594 100644 --- a/editor/translations/mi.po +++ b/editor/translations/mi.po @@ -4978,8 +4978,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/mk.po b/editor/translations/mk.po index 7e5aa06f3c..001542b888 100644 --- a/editor/translations/mk.po +++ b/editor/translations/mk.po @@ -4985,8 +4985,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/ml.po b/editor/translations/ml.po index 3919011ade..f7bc8349bc 100644 --- a/editor/translations/ml.po +++ b/editor/translations/ml.po @@ -4993,8 +4993,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/mr.po b/editor/translations/mr.po index 4d81595cb1..66157f77d1 100644 --- a/editor/translations/mr.po +++ b/editor/translations/mr.po @@ -4985,8 +4985,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/ms.po b/editor/translations/ms.po index 6226d644a3..d8714d6196 100644 --- a/editor/translations/ms.po +++ b/editor/translations/ms.po @@ -14,7 +14,7 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-05-29 13:49+0000\n" +"PO-Revision-Date: 2021-07-23 12:59+0000\n" "Last-Translator: Keviindran Ramachandran <keviinx@yahoo.com>\n" "Language-Team: Malay <https://hosted.weblate.org/projects/godot-engine/godot/" "ms/>\n" @@ -23,7 +23,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -459,7 +459,7 @@ msgstr "Kunci Gerak Anim" #: editor/animation_track_editor.cpp #: modules/visual_script/visual_script_editor.cpp msgid "Clipboard is empty!" -msgstr "" +msgstr "Papan klip kosong!" #: editor/animation_track_editor.cpp msgid "Paste Tracks" @@ -1122,7 +1122,7 @@ msgstr "Terima kasih dari komuniti Godot!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Klik untuk salin." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -1624,16 +1624,15 @@ msgstr "" "GLES3. Aktifkan 'Import Etc 2' atau 'Import Pvrtc' dalam Tetapan Projek." #: editor/editor_export.cpp -#, fuzzy msgid "" "Target platform requires 'PVRTC' texture compression for the driver fallback " "to GLES2.\n" "Enable 'Import Pvrtc' in Project Settings, or disable 'Driver Fallback " "Enabled'." msgstr "" -"Platform sasaran memerlukan pemampatan tekstur 'ETC' untuk sandaran pemandu " +"Platform sasaran memerlukan pemampatan tekstur 'PVRTC' untuk sandaran driver " "ke GLES2.\n" -"Aktifkan 'Import Etc' dalam Tetapan Projek, atau nyahaktifkan 'Driver " +"Aktifkan 'Import Pvrtc' dalam Tetapan Projek, atau nyahaktifkan 'Driver " "Fallback Enabled'." #: editor/editor_export.cpp platform/android/export/export.cpp @@ -2335,9 +2334,8 @@ msgid "Layout name not found!" msgstr "Nama susun atur tidak dijumpai!" #: editor/editor_node.cpp -#, fuzzy msgid "Restored the Default layout to its base settings." -msgstr "Tata letak lalai telah dipulihkan ke tetapan asas." +msgstr "Susun atur lalai telah dipulihkan ke tetapan asas." #: editor/editor_node.cpp msgid "" @@ -4501,34 +4499,34 @@ msgstr "Tetapkan kedudukan pengadunan dalam ruang" #: editor/plugins/animation_blend_space_1d_editor.cpp #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Select and move points, create points with RMB." -msgstr "" +msgstr "Pilih dan pindahkan titik-titik, cipta titik-titik dengan RMB." #: editor/plugins/animation_blend_space_1d_editor.cpp #: editor/plugins/animation_blend_space_2d_editor.cpp scene/gui/graph_edit.cpp msgid "Enable snap and show grid." -msgstr "" +msgstr "Aktifkan snap dan tunjukkan grid." #: editor/plugins/animation_blend_space_1d_editor.cpp #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Point" -msgstr "" +msgstr "Titik" #: editor/plugins/animation_blend_space_1d_editor.cpp #: editor/plugins/animation_blend_space_2d_editor.cpp #: editor/plugins/animation_blend_tree_editor_plugin.cpp msgid "Open Editor" -msgstr "" +msgstr "Buka Editor" #: editor/plugins/animation_blend_space_1d_editor.cpp #: editor/plugins/animation_blend_space_2d_editor.cpp #: editor/plugins/animation_blend_tree_editor_plugin.cpp #: editor/plugins/animation_state_machine_editor.cpp msgid "Open Animation Node" -msgstr "" +msgstr "Buka Nod Animasi" #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Triangle already exists." -msgstr "" +msgstr "Segi tiga sudah wujud." #: editor/plugins/animation_blend_space_2d_editor.cpp #, fuzzy @@ -4537,39 +4535,40 @@ msgstr "Anim Tambah Trek" #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Change BlendSpace2D Limits" -msgstr "" +msgstr "Tukar Had-had BlendSpace2D" #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Change BlendSpace2D Labels" -msgstr "" +msgstr "Tukar Label-label BlendSpace2D" #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Remove BlendSpace2D Point" -msgstr "" +msgstr "Keluarkan Titik BlendSpace2D" #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Remove BlendSpace2D Triangle" -msgstr "" +msgstr "Keluarkan Segi tiga BlendSpace2D" #: editor/plugins/animation_blend_space_2d_editor.cpp +#, fuzzy msgid "BlendSpace2D does not belong to an AnimationTree node." -msgstr "" +msgstr "BlendSpace2D bukan milik nod AnimationTree." #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "No triangles exist, so no blending can take place." -msgstr "" +msgstr "Tiada segi tiga-segi tiga wujud, jadi tiada pengadunan boleh berlaku." #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Toggle Auto Triangles" -msgstr "" +msgstr "Togol Segi Tiga Auto" #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Create triangles by connecting points." -msgstr "" +msgstr "Cipta segi tiga dengan menhubungkan titik-titik." #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Erase points and triangles." -msgstr "" +msgstr "Padamkan titik-titik dan segi tiga-segi tiga." #: editor/plugins/animation_blend_space_2d_editor.cpp msgid "Generate blend triangles automatically (instead of manually)" @@ -5334,8 +5333,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/nb.po b/editor/translations/nb.po index 042ee8d26f..c36274abba 100644 --- a/editor/translations/nb.po +++ b/editor/translations/nb.po @@ -5427,8 +5427,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/nl.po b/editor/translations/nl.po index 2410cd5ad0..296291e435 100644 --- a/editor/translations/nl.po +++ b/editor/translations/nl.po @@ -46,12 +46,13 @@ # T-rex08 <ipadtriceratops@gmail.com>, 2021. # Dwarffish <hoogvlietjohan@gmail.com>, 2021. # Arthur de Roos <arthur.de.roos@gmail.com>, 2021. +# Vancha March <tjipkevdh@gmail.com>, 2021. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-06-05 08:32+0000\n" -"Last-Translator: Stijn Hinlopen <f.a.hinlopen@gmail.com>\n" +"PO-Revision-Date: 2021-07-26 14:18+0000\n" +"Last-Translator: Vancha March <tjipkevdh@gmail.com>\n" "Language-Team: Dutch <https://hosted.weblate.org/projects/godot-engine/godot/" "nl/>\n" "Language: nl\n" @@ -59,7 +60,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.7-dev\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -1162,7 +1163,7 @@ msgstr "Bedankt van de Godot gemeenschap!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." -msgstr "" +msgstr "Klik om te kopiëren." #: editor/editor_about.cpp msgid "Godot Engine contributors" @@ -5243,9 +5244,10 @@ msgstr "" "Sla uw scène op en probeer opnieuw." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Geen meshes om te bakken. Zorg ervoor dat ze een UV2 kanaal bevatten en dat " "'Bake Light' vlag aan staat." diff --git a/editor/translations/or.po b/editor/translations/or.po index 87528cdac5..c1d191a4a5 100644 --- a/editor/translations/or.po +++ b/editor/translations/or.po @@ -4984,8 +4984,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/pl.po b/editor/translations/pl.po index 3c51593e02..d933e8f92b 100644 --- a/editor/translations/pl.po +++ b/editor/translations/pl.po @@ -52,8 +52,8 @@ msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-07-05 14:32+0000\n" -"Last-Translator: Rafal Brozio <rafal.brozio@gmail.com>\n" +"PO-Revision-Date: 2021-07-16 05:47+0000\n" +"Last-Translator: Tomek <kobewi4e@gmail.com>\n" "Language-Team: Polish <https://hosted.weblate.org/projects/godot-engine/" "godot/pl/>\n" "Language: pl\n" @@ -62,7 +62,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " "|| n%100>=20) ? 1 : 2;\n" -"X-Generator: Weblate 4.8-dev\n" +"X-Generator: Weblate 4.7.2-dev\n" #: core/math/expression.cpp modules/gdscript/gdscript_functions.cpp #: modules/visual_script/visual_script_builtin_funcs.cpp @@ -5229,9 +5229,10 @@ msgstr "" "Zapisz scenę i spróbuj ponownie." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Brak siatek do cieniowania. Upewnij się, że zawierają kanał UV2 i że flaga " "\"Bake Light\" jest ustawiona." @@ -5760,7 +5761,7 @@ msgstr "Powiększ do zaznaczenia" #: editor/plugins/canvas_item_editor_plugin.cpp msgid "Preview Canvas Scale" -msgstr "Skala płótna podglądu" +msgstr "Podejrzyj skalę płótna" #: editor/plugins/canvas_item_editor_plugin.cpp msgid "Translation mask for inserting keys." diff --git a/editor/translations/pr.po b/editor/translations/pr.po index 675c9cf506..9b586ad756 100644 --- a/editor/translations/pr.po +++ b/editor/translations/pr.po @@ -5153,8 +5153,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/pt.po b/editor/translations/pt.po index 17b1861821..6eb24001a5 100644 --- a/editor/translations/pt.po +++ b/editor/translations/pt.po @@ -5209,9 +5209,10 @@ msgstr "" "Guarde a sua cena e tente novamente." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Não há malhas para consolidar. Assegure-se que contêm um canal UV2 e que a " "referência 'Bake Light' flag está on." diff --git a/editor/translations/pt_BR.po b/editor/translations/pt_BR.po index e79dd0fa19..01f6220bbd 100644 --- a/editor/translations/pt_BR.po +++ b/editor/translations/pt_BR.po @@ -5320,9 +5320,10 @@ msgstr "" "Salve sua cena e tente novamente." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Não há malhas para preparar. Certifique-se de que elas possuem um canal UV2 " "e que a propriedade \"Preparar Luz\" está habilitada." diff --git a/editor/translations/ro.po b/editor/translations/ro.po index 7ac06fc1b1..3b5af5fe1a 100644 --- a/editor/translations/ro.po +++ b/editor/translations/ro.po @@ -5218,9 +5218,10 @@ msgstr "" "cale de salvare din proprietățile BakedLightmap." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Nicio structură pentru procesare. Asigură-te că acestea conțin un canal UV2 " "și că opțiunea 'Procesează Lumina' este pornită." diff --git a/editor/translations/ru.po b/editor/translations/ru.po index 4b56d21383..e02b70b16d 100644 --- a/editor/translations/ru.po +++ b/editor/translations/ru.po @@ -97,12 +97,13 @@ # Bualma Show <appleaidar6@gmail.com>, 2021. # enderlorde <madel.laboratories@gmail.com>, 2021. # Олег Довгер <oleg.a.dovger@gmail.com>, 2021. +# Anna Malinovskaia <tacitcoast@gmail.com>, 2021. msgid "" msgstr "" "Project-Id-Version: Godot Engine editor\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2021-07-13 06:13+0000\n" -"Last-Translator: Danil Alexeev <danil@alexeev.xyz>\n" +"PO-Revision-Date: 2021-07-19 09:34+0000\n" +"Last-Translator: Anna Malinovskaia <tacitcoast@gmail.com>\n" "Language-Team: Russian <https://hosted.weblate.org/projects/godot-engine/" "godot/ru/>\n" "Language: ru\n" @@ -5286,9 +5287,10 @@ msgstr "" "Сохраните сцену и попробуйте ещё раз." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Нет полисеток для запекания. Убедитесь, что они содержат канал UV2 и что " "флаг «Запекание света» включён." diff --git a/editor/translations/si.po b/editor/translations/si.po index a5586af274..36abdd4774 100644 --- a/editor/translations/si.po +++ b/editor/translations/si.po @@ -5024,8 +5024,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/sk.po b/editor/translations/sk.po index d97e1321ef..cb56bb037e 100644 --- a/editor/translations/sk.po +++ b/editor/translations/sk.po @@ -5183,9 +5183,10 @@ msgstr "" "na uloženie so BakedLightmap vlastností." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Žiadne mesh-e na bake. Uistite sa že obsahujú UV2 channel a je na ňom 'Bake " "Light' vlajka." diff --git a/editor/translations/sl.po b/editor/translations/sl.po index 07bd33c389..42f0bfc2cb 100644 --- a/editor/translations/sl.po +++ b/editor/translations/sl.po @@ -5419,9 +5419,10 @@ msgstr "" "shranitev iz lastnosti Zapečene Svetlobne karte." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Brez modelov za peko. Poskrbi, da vsebujejo kanal UV2 in da je vključena " "oznaka 'Zapeči Svetlobo'." diff --git a/editor/translations/sq.po b/editor/translations/sq.po index 49a42b5553..f054de99bd 100644 --- a/editor/translations/sq.po +++ b/editor/translations/sq.po @@ -5273,8 +5273,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/sr_Cyrl.po b/editor/translations/sr_Cyrl.po index 53fb04b3e4..5d4f6cab1b 100644 --- a/editor/translations/sr_Cyrl.po +++ b/editor/translations/sr_Cyrl.po @@ -5682,8 +5682,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp #, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Нема мрежа за печење. Провери да ли садрже UV2 канал и да је опција 'Изпеци " "Светла' укључена." diff --git a/editor/translations/sr_Latn.po b/editor/translations/sr_Latn.po index 0a90379b41..49f7cd7f3e 100644 --- a/editor/translations/sr_Latn.po +++ b/editor/translations/sr_Latn.po @@ -5048,8 +5048,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/sv.po b/editor/translations/sv.po index 0c5db25a9a..79c1c4a1b9 100644 --- a/editor/translations/sv.po +++ b/editor/translations/sv.po @@ -5277,8 +5277,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/ta.po b/editor/translations/ta.po index 0c9022b097..45eef9a8f6 100644 --- a/editor/translations/ta.po +++ b/editor/translations/ta.po @@ -5033,8 +5033,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/te.po b/editor/translations/te.po index 8274d5520f..47338f3f28 100644 --- a/editor/translations/te.po +++ b/editor/translations/te.po @@ -4987,8 +4987,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/th.po b/editor/translations/th.po index e9c2a80a49..fc38c35df9 100644 --- a/editor/translations/th.po +++ b/editor/translations/th.po @@ -5125,9 +5125,10 @@ msgstr "" "ลองบันทึกฉากของคุณแล้วลองอีกครั้ง" #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "ไม่มีพื้นผิวให้สร้าง lightmap กรุณาตรวจสอบว่าพื้นผิวมี UV2 และได้เปิดใช้งาน 'Bake Light'" diff --git a/editor/translations/tr.po b/editor/translations/tr.po index 578d7b48d0..4f3eb3ff60 100644 --- a/editor/translations/tr.po +++ b/editor/translations/tr.po @@ -5250,9 +5250,10 @@ msgstr "" "Sahneyi kaydedip tekrar deneyin." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Pişirilecek örüntüler yok. Örüntülerin UV2 kanalı içerdiğinden ve 'Bake " "Light' bayrağınının açık olduğundan emin olun." diff --git a/editor/translations/tt.po b/editor/translations/tt.po index 3e63f2369d..d5d41b7879 100644 --- a/editor/translations/tt.po +++ b/editor/translations/tt.po @@ -4987,8 +4987,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/tzm.po b/editor/translations/tzm.po index 0b0ce7d01e..fdb092c6a4 100644 --- a/editor/translations/tzm.po +++ b/editor/translations/tzm.po @@ -4985,8 +4985,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/uk.po b/editor/translations/uk.po index 50508c5df3..66c69938f6 100644 --- a/editor/translations/uk.po +++ b/editor/translations/uk.po @@ -5222,9 +5222,10 @@ msgstr "" "Збережіть вашу сцену і повторіть спробу." #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "Немає полісеток для запікання. Переконайтеся, що вони містять канал UV2 і що " "прапор 'Запікання світла' включений." diff --git a/editor/translations/ur_PK.po b/editor/translations/ur_PK.po index 0a213a2bdf..5476915ea5 100644 --- a/editor/translations/ur_PK.po +++ b/editor/translations/ur_PK.po @@ -5091,8 +5091,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/vi.po b/editor/translations/vi.po index 0104d05502..4267f19def 100644 --- a/editor/translations/vi.po +++ b/editor/translations/vi.po @@ -5156,8 +5156,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/zh_CN.po b/editor/translations/zh_CN.po index 4393cb4e08..c5b0c34c74 100644 --- a/editor/translations/zh_CN.po +++ b/editor/translations/zh_CN.po @@ -83,7 +83,7 @@ msgid "" msgstr "" "Project-Id-Version: Chinese (Simplified) (Godot Engine)\n" "POT-Creation-Date: 2018-01-20 12:15+0200\n" -"PO-Revision-Date: 2021-07-13 06:13+0000\n" +"PO-Revision-Date: 2021-07-23 12:59+0000\n" "Last-Translator: Haoyu Qiu <timothyqiu32@gmail.com>\n" "Language-Team: Chinese (Simplified) <https://hosted.weblate.org/projects/" "godot-engine/godot/zh_Hans/>\n" @@ -1172,7 +1172,7 @@ msgstr "改变字典值" #: editor/editor_about.cpp msgid "Thanks from the Godot community!" -msgstr "Godot 社区感谢你!" +msgstr "Godot 社区感谢大家!" #: editor/editor_about.cpp editor/editor_node.cpp editor/project_manager.cpp msgid "Click to copy." @@ -5171,9 +5171,10 @@ msgstr "" "BakedLightmap 属性。" #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "没有可烘焙的网格。请确保网格包含 UV2 通道并且勾选 “Bake Light” 选项。" #: editor/plugins/baked_lightmap_editor_plugin.cpp @@ -7338,7 +7339,7 @@ msgstr "顶视图。" #: editor/plugins/spatial_editor_plugin.cpp msgid "Bottom View." -msgstr "仰视图。" +msgstr "底视图。" #: editor/plugins/spatial_editor_plugin.cpp msgid "Bottom" @@ -7547,11 +7548,11 @@ msgstr "使用吸附" #: editor/plugins/spatial_editor_plugin.cpp msgid "Bottom View" -msgstr "仰视图" +msgstr "底视图" #: editor/plugins/spatial_editor_plugin.cpp msgid "Top View" -msgstr "俯视图" +msgstr "顶视图" #: editor/plugins/spatial_editor_plugin.cpp msgid "Rear View" @@ -7559,7 +7560,7 @@ msgstr "后视图" #: editor/plugins/spatial_editor_plugin.cpp msgid "Front View" -msgstr "正视图" +msgstr "前视图" #: editor/plugins/spatial_editor_plugin.cpp msgid "Left View" @@ -8240,7 +8241,7 @@ msgstr "新建自动图块" #: editor/plugins/tile_set_editor_plugin.cpp msgid "New Atlas" -msgstr "新建合集" +msgstr "新建图集" #: editor/plugins/tile_set_editor_plugin.cpp msgid "Next Coordinate" diff --git a/editor/translations/zh_HK.po b/editor/translations/zh_HK.po index 28a69ee289..69a8998437 100644 --- a/editor/translations/zh_HK.po +++ b/editor/translations/zh_HK.po @@ -5380,8 +5380,8 @@ msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" #: editor/plugins/baked_lightmap_editor_plugin.cpp diff --git a/editor/translations/zh_TW.po b/editor/translations/zh_TW.po index f65d628d63..2d04a07157 100644 --- a/editor/translations/zh_TW.po +++ b/editor/translations/zh_TW.po @@ -5118,9 +5118,10 @@ msgstr "" "請保存場景並重試。" #: editor/plugins/baked_lightmap_editor_plugin.cpp +#, fuzzy msgid "" -"No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake " -"Light' flag is on." +"No meshes to bake. Make sure they contain an UV2 channel and that the 'Use " +"In Baked Light' and 'Generate Lightmap' flags are on." msgstr "" "無可烘焙之網格。請確保這些網格包含 UV2 通道並已開啟「Bake Light」旗標。" |