From 314430b868be430fbd7fa3ffb0d8c0ee17d712d1 Mon Sep 17 00:00:00 2001 From: Hendrik Brucker Date: Wed, 30 Mar 2022 20:12:26 +0200 Subject: [PATCH] Cleanup EditorNode and EditorData Co-authored-by: Eric M --- editor/animation_track_editor.cpp | 6 +- editor/debugger/editor_debugger_inspector.cpp | 2 +- editor/debugger/editor_debugger_node.cpp | 2 +- editor/editor_data.cpp | 243 ++++----- editor/editor_data.h | 80 +-- editor/editor_node.cpp | 492 +++++++++--------- editor/editor_node.h | 390 +++++++------- editor/editor_path.cpp | 2 +- editor/editor_path.h | 6 +- editor/editor_properties.cpp | 4 +- editor/inspector_dock.cpp | 18 +- editor/plugins/replication_editor_plugin.cpp | 4 +- .../plugins/visual_shader_editor_plugin.cpp | 4 +- editor/scene_tree_dock.cpp | 4 +- 14 files changed, 601 insertions(+), 656 deletions(-) diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index e61a1aae9cd2..dc69a8cb08c7 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -3383,7 +3383,7 @@ Node *AnimationTrackEditor::get_root() const { void AnimationTrackEditor::update_keying() { bool keying_enabled = false; - EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history(); + EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history(); if (is_visible_in_tree() && animation.is_valid() && editor_history->get_path_size() > 0) { Object *obj = ObjectDB::get_instance(editor_history->get_path_object(0)); keying_enabled = Object::cast_to(obj) != nullptr; @@ -3776,7 +3776,7 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p return; } - EditorHistory *history = EditorNode::get_singleton()->get_editor_history(); + EditorSelectionHistory *history = EditorNode::get_singleton()->get_editor_selection_history(); for (int i = 1; i < history->get_path_size(); i++) { String prop = history->get_path_property(i); ERR_FAIL_COND(prop.is_empty()); @@ -3856,7 +3856,7 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p } void AnimationTrackEditor::insert_value_key(const String &p_property, const Variant &p_value, bool p_advance) { - EditorHistory *history = EditorNode::get_singleton()->get_editor_history(); + EditorSelectionHistory *history = EditorNode::get_singleton()->get_editor_selection_history(); ERR_FAIL_COND(!root); // Let's build a node path. diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp index c111190ca34f..936b8ca6264a 100644 --- a/editor/debugger/editor_debugger_inspector.cpp +++ b/editor/debugger/editor_debugger_inspector.cpp @@ -206,7 +206,7 @@ ObjectID EditorDebuggerInspector::add_object(const Array &p_arr) { void EditorDebuggerInspector::clear_cache() { for (const KeyValue &E : remote_objects) { EditorNode *editor = EditorNode::get_singleton(); - if (editor->get_editor_history()->get_current() == E.value->get_instance_id()) { + if (editor->get_editor_selection_history()->get_current() == E.value->get_instance_id()) { editor->push_item(nullptr); } memdelete(E.value); diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index d294858ff8ff..c0685af57220 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -181,7 +181,7 @@ void EditorDebuggerNode::_bind_methods() { } EditorDebuggerRemoteObject *EditorDebuggerNode::get_inspected_remote_object() { - return Object::cast_to(ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_history()->get_current())); + return Object::cast_to(ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_selection_history()->get_current())); } ScriptEditorDebugger *EditorDebuggerNode::get_debugger(int p_id) const { diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index c16451f3c663..a5e76ba0c06d 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -38,12 +38,13 @@ #include "editor/plugins/script_editor_plugin.h" #include "scene/resources/packed_scene.h" -void EditorHistory::cleanup_history() { +void EditorSelectionHistory::cleanup_history() { for (int i = 0; i < history.size(); i++) { bool fail = false; for (int j = 0; j < history[i].path.size(); j++) { if (!history[i].path[j].ref.is_null()) { + // Reference is not null - object still alive. continue; } @@ -51,21 +52,16 @@ void EditorHistory::cleanup_history() { if (obj) { Node *n = Object::cast_to(obj); if (n && n->is_inside_tree()) { + // Node valid and inside tree - object still alive. continue; } - if (!n) { // Possibly still alive + if (!n) { + // Node possibly still alive. continue; } - } - - if (j <= history[i].level) { - //before or equal level, complete fail - fail = true; - } else { - //after level, clip - history.write[i].path.resize(j); - } + } // Else: object not valid - not alive. + fail = true; break; } @@ -75,16 +71,16 @@ void EditorHistory::cleanup_history() { } } - if (current >= history.size()) { - current = history.size() - 1; + if (current_elem_idx >= history.size()) { + current_elem_idx = history.size() - 1; } } -void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int p_level_change, bool p_inspector_only) { +void EditorSelectionHistory::add_object(ObjectID p_object, const String &p_property, bool p_inspector_only) { Object *obj = ObjectDB::get_instance(p_object); ERR_FAIL_COND(!obj); RefCounted *r = Object::cast_to(obj); - Obj o; + _Object o; if (r) { o.ref = REF(r); } @@ -92,86 +88,64 @@ void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int o.property = p_property; o.inspector_only = p_inspector_only; - History h; - - bool has_prev = current >= 0 && current < history.size(); + bool has_prev = current_elem_idx >= 0 && current_elem_idx < history.size(); if (has_prev) { - history.resize(current + 1); //clip history to next + history.resize(current_elem_idx + 1); // Clip history to next. } + HistoryElement h; if (!p_property.is_empty() && has_prev) { - //add a sub property - History &pr = history.write[current]; - h = pr; + // Add a sub property. + HistoryElement &prev_element = history.write[current_elem_idx]; + h = prev_element; h.path.resize(h.level + 1); h.path.push_back(o); h.level++; - } else if (p_level_change != -1 && has_prev) { - //add a sub property - History &pr = history.write[current]; - h = pr; - ERR_FAIL_INDEX(p_level_change, h.path.size()); - h.level = p_level_change; + } else { - //add a new node + // Create a new history item. h.path.push_back(o); h.level = 0; } history.push_back(h); - current++; -} - -void EditorHistory::add_object_inspector_only(ObjectID p_object) { - _add_object(p_object, "", -1, true); -} - -void EditorHistory::add_object(ObjectID p_object) { - _add_object(p_object, "", -1); + current_elem_idx++; } -void EditorHistory::add_object(ObjectID p_object, const String &p_subprop) { - _add_object(p_object, p_subprop, -1); -} - -void EditorHistory::add_object(ObjectID p_object, int p_relevel) { - _add_object(p_object, "", p_relevel); -} - -int EditorHistory::get_history_len() { +int EditorSelectionHistory::get_history_len() { return history.size(); } -int EditorHistory::get_history_pos() { - return current; +int EditorSelectionHistory::get_history_pos() { + return current_elem_idx; } -bool EditorHistory::is_history_obj_inspector_only(int p_obj) const { +bool EditorSelectionHistory::is_history_obj_inspector_only(int p_obj) const { ERR_FAIL_INDEX_V(p_obj, history.size(), false); ERR_FAIL_INDEX_V(history[p_obj].level, history[p_obj].path.size(), false); return history[p_obj].path[history[p_obj].level].inspector_only; } -ObjectID EditorHistory::get_history_obj(int p_obj) const { +ObjectID EditorSelectionHistory::get_history_obj(int p_obj) const { ERR_FAIL_INDEX_V(p_obj, history.size(), ObjectID()); ERR_FAIL_INDEX_V(history[p_obj].level, history[p_obj].path.size(), ObjectID()); return history[p_obj].path[history[p_obj].level].object; } -bool EditorHistory::is_at_beginning() const { - return current <= 0; +bool EditorSelectionHistory::is_at_beginning() const { + return current_elem_idx <= 0; } -bool EditorHistory::is_at_end() const { - return ((current + 1) >= history.size()); +bool EditorSelectionHistory::is_at_end() const { + return ((current_elem_idx + 1) >= history.size()); } -bool EditorHistory::next() { +bool EditorSelectionHistory::next() { cleanup_history(); - if ((current + 1) < history.size()) { - current++; + if ((current_elem_idx + 1) < history.size()) { + current_elem_idx++; } else { return false; } @@ -179,11 +153,11 @@ bool EditorHistory::next() { return true; } -bool EditorHistory::previous() { +bool EditorSelectionHistory::previous() { cleanup_history(); - if (current > 0) { - current--; + if (current_elem_idx > 0) { + current_elem_idx--; } else { return false; } @@ -191,76 +165,63 @@ bool EditorHistory::previous() { return true; } -bool EditorHistory::is_current_inspector_only() const { - if (current < 0 || current >= history.size()) { +bool EditorSelectionHistory::is_current_inspector_only() const { + if (current_elem_idx < 0 || current_elem_idx >= history.size()) { return false; } - const History &h = history[current]; + const HistoryElement &h = history[current_elem_idx]; return h.path[h.level].inspector_only; } -ObjectID EditorHistory::get_current() { - if (current < 0 || current >= history.size()) { +ObjectID EditorSelectionHistory::get_current() { + if (current_elem_idx < 0 || current_elem_idx >= history.size()) { return ObjectID(); } - History &h = history.write[current]; - Object *obj = ObjectDB::get_instance(h.path[h.level].object); - if (!obj) { - return ObjectID(); - } - - return obj->get_instance_id(); + Object *obj = ObjectDB::get_instance(get_history_obj(current_elem_idx)); + return obj ? obj->get_instance_id() : ObjectID(); } -int EditorHistory::get_path_size() const { - if (current < 0 || current >= history.size()) { +int EditorSelectionHistory::get_path_size() const { + if (current_elem_idx < 0 || current_elem_idx >= history.size()) { return 0; } - const History &h = history[current]; - return h.path.size(); + return history[current_elem_idx].path.size(); } -ObjectID EditorHistory::get_path_object(int p_index) const { - if (current < 0 || current >= history.size()) { +ObjectID EditorSelectionHistory::get_path_object(int p_index) const { + if (current_elem_idx < 0 || current_elem_idx >= history.size()) { return ObjectID(); } - const History &h = history[current]; - - ERR_FAIL_INDEX_V(p_index, h.path.size(), ObjectID()); + ERR_FAIL_INDEX_V(p_index, history[current_elem_idx].path.size(), ObjectID()); - Object *obj = ObjectDB::get_instance(h.path[p_index].object); - if (!obj) { - return ObjectID(); - } - - return obj->get_instance_id(); + Object *obj = ObjectDB::get_instance(history[current_elem_idx].path[p_index].object); + return obj ? obj->get_instance_id() : ObjectID(); } -String EditorHistory::get_path_property(int p_index) const { - if (current < 0 || current >= history.size()) { +String EditorSelectionHistory::get_path_property(int p_index) const { + if (current_elem_idx < 0 || current_elem_idx >= history.size()) { return ""; } - const History &h = history[current]; - - ERR_FAIL_INDEX_V(p_index, h.path.size(), ""); - - return h.path[p_index].property; + ERR_FAIL_INDEX_V(p_index, history[current_elem_idx].path.size(), ""); + return history[current_elem_idx].path[p_index].property; } -void EditorHistory::clear() { +void EditorSelectionHistory::clear() { history.clear(); - current = -1; + current_elem_idx = -1; } -EditorHistory::EditorHistory() { - current = -1; +EditorSelectionHistory::EditorSelectionHistory() { + current_elem_idx = -1; } +//////////////////////////////////////////////////////////// + EditorPlugin *EditorData::get_editor(Object *p_object) { // We need to iterate backwards so that we can check user-created plugins first. // Otherwise, it would not be possible for plugins to handle CanvasItem and Spatial nodes. @@ -636,14 +597,14 @@ bool EditorData::check_and_update_scene(int p_idx) { EditorProgress ep("update_scene", TTR("Updating Scene"), 2); ep.step(TTR("Storing local changes..."), 0); - //pack first, so it stores diffs to previous version of saved scene + // Pack first, so it stores diffs to previous version of saved scene. Error err = pscene->pack(edited_scene[p_idx].root); ERR_FAIL_COND_V(err != OK, false); ep.step(TTR("Updating scene..."), 1); Node *new_scene = pscene->instantiate(PackedScene::GEN_EDIT_STATE_MAIN); ERR_FAIL_COND_V(!new_scene, false); - //transfer selection + // Transfer selection. List new_selection; for (const Node *E : edited_scene.write[p_idx].selection) { NodePath p = edited_scene[p_idx].root->get_path_to(E); @@ -675,7 +636,6 @@ int EditorData::get_edited_scene() const { void EditorData::set_edited_scene(int p_idx) { ERR_FAIL_INDEX(p_idx, edited_scene.size()); current_edited_scene = p_idx; - //swap } Node *EditorData::get_edited_scene_root(int p_idx) { @@ -850,23 +810,23 @@ NodePath EditorData::get_edited_scene_live_edit_root() { return edited_scene[current_edited_scene].live_edit_root; } -void EditorData::save_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history, const Dictionary &p_custom) { +void EditorData::save_edited_scene_state(EditorSelection *p_selection, EditorSelectionHistory *p_history, const Dictionary &p_custom) { ERR_FAIL_INDEX(current_edited_scene, edited_scene.size()); EditedScene &es = edited_scene.write[current_edited_scene]; es.selection = p_selection->get_full_selected_node_list(); - es.history_current = p_history->current; + es.history_current = p_history->current_elem_idx; es.history_stored = p_history->history; es.editor_states = get_editor_states(); es.custom_state = p_custom; } -Dictionary EditorData::restore_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history) { +Dictionary EditorData::restore_edited_scene_state(EditorSelection *p_selection, EditorSelectionHistory *p_history) { ERR_FAIL_INDEX_V(current_edited_scene, edited_scene.size(), Dictionary()); EditedScene &es = edited_scene.write[current_edited_scene]; - p_history->current = es.history_current; + p_history->current_elem_idx = es.history_current; p_history->history = es.history_stored; p_selection->clear(); @@ -1033,12 +993,11 @@ void EditorData::script_class_load_icon_paths() { EditorData::EditorData() { current_edited_scene = -1; - - //load_imported_scenes_from_globals(); script_class_load_icon_paths(); } -/////////// +/////////////////////////////////////////////////////////////////////////////// + void EditorSelection::_node_removed(Node *p_node) { if (!selection.has(p_node)) { return; @@ -1050,7 +1009,7 @@ void EditorSelection::_node_removed(Node *p_node) { } selection.erase(p_node); changed = true; - nl_changed = true; + node_list_changed = true; } void EditorSelection::add_node(Node *p_node) { @@ -1061,7 +1020,7 @@ void EditorSelection::add_node(Node *p_node) { } changed = true; - nl_changed = true; + node_list_changed = true; Object *meta = nullptr; for (Object *E : editor_plugins) { meta = E->call("_get_editor_data", p_node); @@ -1072,52 +1031,29 @@ void EditorSelection::add_node(Node *p_node) { selection[p_node] = meta; p_node->connect("tree_exiting", callable_mp(this, &EditorSelection::_node_removed), varray(p_node), CONNECT_ONESHOT); - - //emit_signal(SNAME("selection_changed")); } void EditorSelection::remove_node(Node *p_node) { ERR_FAIL_NULL(p_node); - if (!selection.has(p_node)) { return; } changed = true; - nl_changed = true; + node_list_changed = true; Object *meta = selection[p_node]; if (meta) { memdelete(meta); } selection.erase(p_node); + p_node->disconnect("tree_exiting", callable_mp(this, &EditorSelection::_node_removed)); - //emit_signal(SNAME("selection_changed")); } bool EditorSelection::is_selected(Node *p_node) const { return selection.has(p_node); } -Array EditorSelection::_get_transformable_selected_nodes() { - Array ret; - - for (const Node *E : selected_node_list) { - ret.push_back(E); - } - - return ret; -} - -TypedArray EditorSelection::get_selected_nodes() { - TypedArray ret; - - for (const KeyValue &E : selection) { - ret.push_back(E.key); - } - - return ret; -} - void EditorSelection::_bind_methods() { ClassDB::bind_method(D_METHOD("clear"), &EditorSelection::clear); ClassDB::bind_method(D_METHOD("add_node", "node"), &EditorSelection::add_node); @@ -1132,13 +1068,16 @@ void EditorSelection::add_editor_plugin(Object *p_object) { editor_plugins.push_back(p_object); } -void EditorSelection::_update_nl() { - if (!nl_changed) { +void EditorSelection::_update_node_list() { + if (!node_list_changed) { return; } selected_node_list.clear(); + // If the selection does not have the parent of the selected node, then add the node to the node list. + // However, if the parent is already selected, then adding this node is redundant as + // it is included with the parent, so skip it. for (const KeyValue &E : selection) { Node *parent = E.key; parent = parent->get_parent(); @@ -1157,11 +1096,11 @@ void EditorSelection::_update_nl() { selected_node_list.push_back(E.key); } - nl_changed = true; + node_list_changed = true; } void EditorSelection::update() { - _update_nl(); + _update_node_list(); if (!changed) { return; @@ -1178,11 +1117,31 @@ void EditorSelection::_emit_change() { emitted = false; } +Array EditorSelection::_get_transformable_selected_nodes() { + Array ret; + + for (const Node *E : selected_node_list) { + ret.push_back(E); + } + + return ret; +} + +TypedArray EditorSelection::get_selected_nodes() { + TypedArray ret; + + for (const KeyValue &E : selection) { + ret.push_back(E.key); + } + + return ret; +} + List &EditorSelection::get_selected_node_list() { if (changed) { update(); } else { - _update_nl(); + _update_node_list(); } return selected_node_list; } @@ -1202,7 +1161,7 @@ void EditorSelection::clear() { } changed = true; - nl_changed = true; + node_list_changed = true; } EditorSelection::EditorSelection() { diff --git a/editor/editor_data.h b/editor/editor_data.h index 79f8227e5c86..0a9f40b714a6 100644 --- a/editor/editor_data.h +++ b/editor/editor_data.h @@ -38,33 +38,32 @@ class ConfigFile; class EditorPlugin; -class EditorHistory { - enum { - HISTORY_MAX = 64 - }; - - struct Obj { +/** + * Stores the history of objects which have been selected for editing in the Editor & the Inspector. + * + * Used in the editor to set & access the currently edited object, as well as the history of objects which have been edited. + */ +class EditorSelectionHistory { + // Stores the object & property (if relevant). + struct _Object { REF ref; ObjectID object; String property; bool inspector_only = false; }; - struct History { - Vector path; + // Represents the selection of an object for editing. + struct HistoryElement { + // The sub-resources of the parent object (first in the path) that have been edited. + // For example, Node2D -> nested resource -> nested resource, if edited each individually in their own inspector. + Vector<_Object> path; + // The current point in the path. This is always equal to the last item in the path - it is never decremented. int level = 0; }; friend class EditorData; - Vector history; - int current; - - struct PropertyData { - String name; - Variant value; - }; - - void _add_object(ObjectID p_object, const String &p_property, int p_level_change, bool p_inspector_only = false); + Vector history; + int current_elem_idx; // The current history element being edited. public: void cleanup_history(); @@ -72,13 +71,14 @@ class EditorHistory { bool is_at_beginning() const; bool is_at_end() const; - void add_object_inspector_only(ObjectID p_object); - void add_object(ObjectID p_object); - void add_object(ObjectID p_object, const String &p_subprop); - void add_object(ObjectID p_object, int p_relevel); + // Adds an object to the selection history. A property name can be passed if the target is a subresource of the given object. + // If the object should not change the main screen plugin, it can be set as inspector only. + void add_object(ObjectID p_object, const String &p_property = String(), bool p_inspector_only = false); int get_history_len(); int get_history_pos(); + + // Gets an object from the history. The most recent object would be the object with p_obj = get_history_len() - 1. ObjectID get_history_obj(int p_obj) const; bool is_history_obj_inspector_only(int p_obj) const; @@ -87,13 +87,16 @@ class EditorHistory { ObjectID get_current(); bool is_current_inspector_only() const; + // Gets the size of the path of the current history item. int get_path_size() const; + // Gets the object of the current history item, if valid. ObjectID get_path_object(int p_index) const; + // Gets the property of the current history item. String get_path_property(int p_index) const; void clear(); - EditorHistory(); + EditorSelectionHistory(); }; class EditorSelection; @@ -112,7 +115,7 @@ class EditorData { uint64_t file_modified_time = 0; Dictionary editor_states; List selection; - Vector history_stored; + Vector history_stored; int history_current = 0; Dictionary custom_state; uint64_t version = 0; @@ -210,8 +213,8 @@ class EditorData { void set_plugin_window_layout(Ref p_layout); void get_plugin_window_layout(Ref p_layout); - void save_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history, const Dictionary &p_custom); - Dictionary restore_edited_scene_state(EditorSelection *p_selection, EditorHistory *p_history); + void save_edited_scene_state(EditorSelection *p_selection, EditorSelectionHistory *p_history, const Dictionary &p_custom); + Dictionary restore_edited_scene_state(EditorSelection *p_selection, EditorSelectionHistory *p_history); void notify_edited_scene_changed(); void notify_resource_saved(const Ref &p_resource); @@ -233,22 +236,33 @@ class EditorData { EditorData(); }; +/** + * Stores and provides access to the nodes currently selected in the editor. + * + * This provides a central location for storing "selected" nodes, as a selection can be triggered from multiple places, + * such as the SceneTreeDock or a main screen editor plugin (e.g. CanvasItemEditor). + */ class EditorSelection : public Object { GDCLASS(EditorSelection, Object); -private: + // Contains the selected nodes and corresponding metadata. + // Metadata objects come from calling _get_editor_data on the editor_plugins, passing the selected node. Map selection; + // Tracks whether the selection change signal has been emitted. + // Prevents multiple signals being called in one frame. bool emitted = false; + bool changed = false; - bool nl_changed = false; + bool node_list_changed = false; void _node_removed(Node *p_node); + // Editor plugins which are related to selection. List editor_plugins; List selected_node_list; - void _update_nl(); + void _update_node_list(); Array _get_transformable_selected_nodes(); void _emit_change(); @@ -256,10 +270,9 @@ class EditorSelection : public Object { static void _bind_methods(); public: - TypedArray get_selected_nodes(); void add_node(Node *p_node); void remove_node(Node *p_node); - bool is_selected(Node *) const; + bool is_selected(Node *p_node) const; template T *get_node_editor_data(Node *p_node) { @@ -269,13 +282,20 @@ class EditorSelection : public Object { return Object::cast_to(selection[p_node]); } + // Adds an editor plugin which can provide metadata for selected nodes. void add_editor_plugin(Object *p_object); void update(); void clear(); + // Returns all the selected nodes. + TypedArray get_selected_nodes(); + // Returns only the top level selected nodes. + // That is, if the selection includes some node and a child of that node, only the parent is returned. List &get_selected_node_list(); + // Returns all the selected nodes (list version of "get_selected_nodes"). List get_full_selected_node_list(); + // Returns the map of selected objects and their metadata. Map &get_selection() { return selection; } EditorSelection(); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index bcdd54edd48c..d386642ca3ab 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -225,17 +225,17 @@ void EditorNode::disambiguate_filenames(const Vector p_full_paths, Vecto index_sets.write[scene_name_to_set_index[scene_name]].insert(i); } - // For each index set with a size > 1, we need to disambiguate + // For each index set with a size > 1, we need to disambiguate. for (int i = 0; i < index_sets.size(); i++) { Set iset = index_sets[i]; while (iset.size() > 1) { - // Append the parent folder to each scene name + // Append the parent folder to each scene name. for (Set::Element *E = iset.front(); E; E = E->next()) { int set_idx = E->get(); String scene_name = r_filenames[set_idx]; String full_path = p_full_paths[set_idx]; - // Get rid of file extensions and res:// prefixes + // Get rid of file extensions and res:// prefixes. if (scene_name.rfind(".") >= 0) { scene_name = scene_name.substr(0, scene_name.rfind(".")); } @@ -263,7 +263,7 @@ void EditorNode::disambiguate_filenames(const Vector p_full_paths, Vecto } } - // Loop back through scene names and remove non-ambiguous names + // Loop back through scene names and remove non-ambiguous names. bool can_proceed = false; Set::Element *E = iset.front(); while (E) { @@ -648,7 +648,7 @@ void EditorNode::_notification(int p_what) { case NOTIFICATION_EXIT_TREE: { editor_data.save_editor_external_data(); FileAccess::set_file_close_fail_notify_callback(nullptr); - log->deinit(); // do not get messages anymore + log->deinit(); // Do not get messages anymore. editor_data.clear_edited_scenes(); } break; @@ -658,7 +658,7 @@ void EditorNode::_notification(int p_what) { case NOTIFICATION_READY: { { - _initializing_addons = true; + _initializing_plugins = true; Vector addons; if (ProjectSettings::get_singleton()->has_setting("editor_plugins/enabled")) { addons = ProjectSettings::get_singleton()->get("editor_plugins/enabled"); @@ -667,7 +667,7 @@ void EditorNode::_notification(int p_what) { for (int i = 0; i < addons.size(); i++) { set_addon_plugin_enabled(addons[i], true); } - _initializing_addons = false; + _initializing_plugins = false; } RenderingServer::get_singleton()->viewport_set_disable_2d(get_scene_root()->get_viewport_rid(), true); @@ -745,12 +745,12 @@ void EditorNode::_notification(int p_what) { recent_scenes->reset_size(); - // debugger area + // Update debugger area. if (EditorDebuggerNode::get_singleton()->is_visible()) { bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("BottomPanelDebuggerOverride"), SNAME("EditorStyles"))); } - // update_icons + // Update icons. for (int i = 0; i < singleton->main_editor_buttons.size(); i++) { Button *tb = singleton->main_editor_buttons[i]; EditorPlugin *p_editor = singleton->editor_table[i]; @@ -893,7 +893,7 @@ void EditorNode::_resources_changed(const Vector &p_resources) { } if (!res->get_import_path().is_empty()) { - // this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback + // This is an imported resource, will be reloaded if reimported via the _resources_reimported() callback. continue; } @@ -918,23 +918,23 @@ void EditorNode::_fs_changed() { _mark_unsaved_scenes(); - // FIXME: Move this to a cleaner location, it's hacky to do this is _fs_changed. + // FIXME: Move this to a cleaner location, it's hacky to do this in _fs_changed. String export_error; if (!export_defer.preset.is_empty() && !EditorFileSystem::get_singleton()->is_scanning()) { String preset_name = export_defer.preset; // Ensures export_project does not loop infinitely, because notifications may // come during the export. export_defer.preset = ""; - Ref preset; + Ref export_preset; for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); ++i) { - preset = EditorExport::get_singleton()->get_export_preset(i); - if (preset->get_name() == preset_name) { + export_preset = EditorExport::get_singleton()->get_export_preset(i); + if (export_preset->get_name() == preset_name) { break; } - preset.unref(); + export_preset.unref(); } - if (preset.is_null()) { + if (export_preset.is_null()) { DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (da->file_exists("res://export_presets.cfg")) { export_error = vformat( @@ -948,8 +948,8 @@ void EditorNode::_fs_changed() { export_error = "This project doesn't have an `export_presets.cfg` file at its root.\nCreate an export preset from the \"Project > Export\" dialog and try again."; } } else { - Ref platform = preset->get_platform(); - const String export_path = export_defer.path.is_empty() ? preset->get_export_path() : export_defer.path; + Ref platform = export_preset->get_platform(); + const String export_path = export_defer.path.is_empty() ? export_preset->get_export_path() : export_defer.path; if (export_path.is_empty()) { export_error = vformat("Export preset \"%s\" doesn't have a default export path, and none was specified.", preset_name); } else if (platform.is_null()) { @@ -958,18 +958,18 @@ void EditorNode::_fs_changed() { Error err = OK; if (export_defer.pack_only) { // Only export .pck or .zip data pack. if (export_path.ends_with(".zip")) { - err = platform->export_zip(preset, export_defer.debug, export_path); + err = platform->export_zip(export_preset, export_defer.debug, export_path); } else if (export_path.ends_with(".pck")) { - err = platform->export_pack(preset, export_defer.debug, export_path); + err = platform->export_pack(export_preset, export_defer.debug, export_path); } } else { // Normal project export. String config_error; bool missing_templates; - if (!platform->can_export(preset, config_error, missing_templates)) { + if (!platform->can_export(export_preset, config_error, missing_templates)) { ERR_PRINT(vformat("Cannot export project with preset \"%s\" due to configuration errors:\n%s", preset_name, config_error)); err = missing_templates ? ERR_FILE_NOT_FOUND : ERR_UNCONFIGURED; } else { - err = platform->export_project(preset, export_defer.debug, export_path); + err = platform->export_project(export_preset, export_defer.debug, export_path); } } switch (err) { @@ -998,21 +998,22 @@ void EditorNode::_fs_changed() { } void EditorNode::_resources_reimported(const Vector &p_resources) { - List scenes; // will load later + List scenes; int current_tab = scene_tabs->get_current_tab(); for (int i = 0; i < p_resources.size(); i++) { String file_type = ResourceLoader::get_resource_type(p_resources[i]); if (file_type == "PackedScene") { scenes.push_back(p_resources[i]); - // reload later if needed, first go with normal resources + // Reload later if needed, first go with normal resources. continue; } if (!ResourceCache::has(p_resources[i])) { - continue; // not loaded, no need to reload + // Not loaded, no need to reload. + continue; } - // reload normally + // Reload normally. Resource *resource = ResourceCache::get(p_resources[i]); if (resource) { resource->reload_from_file(); @@ -1184,7 +1185,6 @@ Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_d ERR_FAIL_COND_V(!res.is_valid(), ERR_CANT_OPEN); if (!p_ignore_broken_deps && dependency_errors.has(p_resource)) { - // current_option = -1; Vector errors; for (Set::Element *E = dependency_errors[p_resource].front(); E; E = E->next()) { errors.push_back(E->get()); @@ -1251,7 +1251,7 @@ void EditorNode::save_resource_as(const Ref &p_resource, const String file->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); saving_resource = p_resource; - current_option = RESOURCE_SAVE_AS; + current_menu_option = RESOURCE_SAVE_AS; List extensions; Ref sd = memnew(PackedScene); ResourceSaver::get_recognized_extensions(p_resource, &extensions); @@ -1260,18 +1260,18 @@ void EditorNode::save_resource_as(const Ref &p_resource, const String List preferred; for (const String &E : extensions) { if (p_resource->is_class("Script") && (E == "tres" || E == "res")) { - // this serves no purpose and confused people + // This serves no purpose and confused people. continue; } file->add_filter("*." + E + " ; " + E.to_upper()); preferred.push_back(E); } - // Lowest priority extension + // Lowest priority extension. List::Element *res_element = preferred.find("res"); if (res_element) { preferred.move_to_back(res_element); } - // Highest priority extension + // Highest priority extension. List::Element *tres_element = preferred.find("tres"); if (tres_element) { preferred.move_to_front(tres_element); @@ -1314,7 +1314,7 @@ void EditorNode::_menu_option(int p_option) { } void EditorNode::_menu_confirm_current() { - _menu_option_confirm(current_option, true); + _menu_option_confirm(current_menu_option, true); } void EditorNode::_dialog_display_save_error(String p_file, Error p_error) { @@ -1369,7 +1369,8 @@ void EditorNode::_get_scene_metadata(const String &p_file) { Error err = cf->load(path); if (err != OK || !cf->has_section("editor_states")) { - return; // must not exist + // Must not exist. + return; } List esl; @@ -1393,9 +1394,6 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { return; } - scene->set_meta("__editor_run_settings__", Variant()); // clear it (no point in keeping it) - scene->set_meta("__editor_plugin_states__", Variant()); - String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); Ref cf; @@ -1436,10 +1434,9 @@ bool EditorNode::_find_and_save_resource(RES p_res, Map &processed, i if (p_res->get_path().is_resource_file()) { if (changed || subchanged) { - // save ResourceSaver::save(p_res->get_path(), p_res, flags); } - processed[p_res] = false; // because it's a file + processed[p_res] = false; // Because it's a file. return false; } else { processed[p_res] = changed; @@ -1537,7 +1534,7 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { _find_node_types(editor_data.get_edited_scene_root(), c2d, c3d); save.step(TTR("Creating Thumbnail"), 1); - // current view? + // Current view? Ref img; // If neither 3D or 2D nodes are present, make a 1x1 black texture. @@ -1570,13 +1567,13 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); preview_size *= EDSCALE; - // consider a square region + // Consider a square region. int vp_size = MIN(img->get_width(), img->get_height()); int x = (img->get_width() - vp_size) / 2; int y = (img->get_height() - vp_size) / 2; if (vp_size < preview_size) { - // just square it. + // Just square it. img->crop_from_point(x, y, vp_size, vp_size); } else { int ratio = vp_size / preview_size; @@ -1590,13 +1587,12 @@ void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { } img->convert(Image::FORMAT_RGB8); - // save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5 + // Save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5. String temp_path = EditorPaths::get_singleton()->get_cache_dir(); String cache_base = ProjectSettings::get_singleton()->globalize_path(p_file).md5_text(); cache_base = temp_path.plus_file("resthumb-" + cache_base); - // does not have it, try to load a cached thumbnail - + // Does not have it, try to load a cached thumbnail. String file = cache_base + ".png"; post_process_preview(img); @@ -1643,7 +1639,7 @@ static bool _find_edited_resources(const Ref &p_resource, Setget_path().is_resource_file()) { // not a subresource, continue + if (res->get_path().is_resource_file()) { // Not a subresource, continue. continue; } if (_find_edited_resources(res, edited_resources)) { @@ -1656,7 +1652,7 @@ static bool _find_edited_resources(const Ref &p_resource, Setget("filesystem/on_save/compress_binary_resources")) { @@ -1679,8 +1675,8 @@ int EditorNode::_save_external_resources() { } } - // clear later, because user may have put the same subresource in two different resources, - // which will be shared until the next reload + // Clear later, because user may have put the same subresource in two different resources, + // which will be shared until the next reload. for (Set>::Element *E = edited_subresources.front(); E; E = E->next()) { Ref res = E->get(); @@ -1728,9 +1724,9 @@ void EditorNode::_save_scene(String p_file, int idx) { Ref sdata; if (ResourceCache::has(p_file)) { - // something may be referencing this resource and we are good with that. - // we must update it, but also let the previous scene state go, as - // old version still work for referencing changes in instantiated or inherited scenes + // Something may be referencing this resource and we are good with that. + // We must update it, but also let the previous scene state go, as + // old version still work for referencing changes in instantiated or inherited scenes. sdata = Ref(Object::cast_to(ResourceCache::get(p_file))); if (sdata.is_valid()) { @@ -1867,7 +1863,7 @@ void EditorNode::_mark_unsaved_scenes() { } void EditorNode::_dialog_action(String p_file) { - switch (current_option) { + switch (current_menu_option) { case FILE_NEW_INHERITED_SCENE: { Node *scene = editor_data.get_edited_scene_root(); // If the previous scene is rootless, just close it in favor of the new one. @@ -1883,12 +1879,12 @@ void EditorNode::_dialog_action(String p_file) { case SETTINGS_PICK_MAIN_SCENE: { ProjectSettings::get_singleton()->set("application/run/main_scene", p_file); ProjectSettings::get_singleton()->save(); - // would be nice to show the project manager opened with the highlighted field.. + // TODO: Would be nice to show the project manager opened with the highlighted field. if (pick_main_scene->has_meta("from_native") && (bool)pick_main_scene->get_meta("from_native")) { run_native->resume_run_native(); } else { - _run(false, ""); // automatically run the project + _run(false, ""); // Automatically run the project. } } break; case FILE_CLOSE: @@ -1898,7 +1894,7 @@ void EditorNode::_dialog_action(String p_file) { case SCENE_TAB_CLOSE: case FILE_SAVE_SCENE: case FILE_SAVE_AS_SCENE: { - int scene_idx = (current_option == FILE_SAVE_SCENE || current_option == FILE_SAVE_AS_SCENE) ? -1 : tab_closing; + int scene_idx = (current_menu_option == FILE_SAVE_SCENE || current_menu_option == FILE_SAVE_AS_SCENE) ? -1 : tab_closing_idx; if (file->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) { bool same_open_scene = false; @@ -1978,7 +1974,7 @@ void EditorNode::_dialog_action(String p_file) { Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err == ERR_FILE_CANT_OPEN || err == ERR_FILE_NOT_FOUND) { - config.instantiate(); // new config + config.instantiate(); } else if (err != OK) { show_warning(TTR("An error occurred while trying to save the editor layout.\nMake sure the editor's user data path is writable.")); return; @@ -2010,11 +2006,11 @@ void EditorNode::_dialog_action(String p_file) { return; } - // erase + // Erase key values. List keys; config->get_section_keys(p_file, &keys); - for (const String &E : keys) { - config->set_value(p_file, E, Variant()); + for (const String &key : keys) { + config->set_value(p_file, key, Variant()); } config->save(EditorSettings::get_singleton()->get_editor_layouts_config()); @@ -2027,8 +2023,8 @@ void EditorNode::_dialog_action(String p_file) { } } break; - default: { // save scene? - + default: { + // Save scene? if (file->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) { _save_scene_with_preview(p_file); } @@ -2115,7 +2111,7 @@ void EditorNode::push_item(Object *p_object, const String &p_property, bool p_in ObjectID id = p_object->get_instance_id(); if (id != editor_history.get_current()) { if (p_inspector_only) { - editor_history.add_object_inspector_only(id); + editor_history.add_object(id, String(), true); } else if (p_property.is_empty()) { editor_history.add_object(id); } else { @@ -2196,7 +2192,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) { bool is_resource = current_obj->is_class("Resource"); bool is_node = current_obj->is_class("Node"); - String editable_warning; // none by default + String editable_warning; // None by default. if (is_resource) { Resource *current_res = Object::cast_to(current_obj); @@ -2264,7 +2260,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) { } } if (!multi_nodes.is_empty()) { - // Pick the top-most node + // Pick the top-most node. multi_nodes.sort_custom(); selected_node = multi_nodes.front()->get(); } @@ -2289,7 +2285,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) { InspectorDock::get_inspector_singleton()->set_use_folding(!disable_folding); } - /* Take care of PLUGIN EDITOR */ + // Take care of the main editor plugin. if (!inspector_only) { EditorPlugin *main_plugin = editor_data.get_editor(current_obj); @@ -2298,7 +2294,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) { for (; plugin_index < editor_table.size(); plugin_index++) { if (editor_table[plugin_index] == main_plugin) { if (!main_editor_buttons[plugin_index]->is_visible()) { - main_plugin = nullptr; // if button is not visible, then no plugin active + main_plugin = nullptr; // If button is not visible, then no plugin is active. } break; @@ -2306,7 +2302,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) { } if (main_plugin) { - // special case if use of external editor is true + // Special case if use of external editor is true. Resource *current_res = Object::cast_to(current_obj); if (main_plugin->get_name() == "Script" && current_obj->is_class("VisualScript") && current_res && !current_res->is_built_in() && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) { if (!changing_scene) { @@ -2315,7 +2311,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) { } else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) { - // update screen main_plugin + // Update screen main_plugin. _editor_select(plugin_index); main_plugin->edit(current_obj); } else { @@ -2368,10 +2364,10 @@ void EditorNode::_run(bool p_current, const String &p_custom) { } if (scene->get_scene_file_path().is_empty()) { - current_option = -1; + current_menu_option = -1; _menu_option(FILE_SAVE_AS_SCENE); // Set the option to save and run so when the dialog is accepted, the scene runs. - current_option = FILE_SAVE_AND_RUN; + current_menu_option = FILE_SAVE_AND_RUN; file->set_title(TTR("Save scene before running...")); return; } @@ -2382,7 +2378,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) { } if (run_filename.is_empty()) { - // evidently, run the scene + // Evidently, run the scene. if (!ensure_main_scene(false)) { return; } @@ -2446,7 +2442,7 @@ void EditorNode::_run_native(const Ref &p_preset) { _menu_option_confirm(RUN_STOP, true); if (!call_build()) { - return; // build failed + return; // Build failed. } EditorDebuggerNode::get_singleton()->start(p_preset->get_platform()->get_debug_protocol()); @@ -2459,8 +2455,8 @@ void EditorNode::_android_build_source_selected(const String &p_file) { export_template_manager->install_android_template_from_file(p_file); } void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { - if (!p_confirmed) { // this may be a hack.. - current_option = (MenuOptions)p_option; + if (!p_confirmed) { // FIXME: this may be a hack. + current_menu_option = (MenuOptions)p_option; } switch (p_option) { @@ -2513,13 +2509,13 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case FILE_CLOSE_OTHERS: case FILE_CLOSE_RIGHT: case FILE_CLOSE_ALL: { - if (editor_data.get_edited_scene_count() > 1 && (current_option != FILE_CLOSE_RIGHT || editor_data.get_edited_scene() < editor_data.get_edited_scene_count() - 1)) { + if (editor_data.get_edited_scene_count() > 1 && (current_menu_option != FILE_CLOSE_RIGHT || editor_data.get_edited_scene() < editor_data.get_edited_scene_count() - 1)) { int next_tab = editor_data.get_edited_scene() + 1; next_tab %= editor_data.get_edited_scene_count(); - _scene_tab_closed(next_tab, current_option); + _scene_tab_closed(next_tab, current_menu_option); } else { - if (current_option != FILE_CLOSE_ALL) { - current_option = -1; + if (current_menu_option != FILE_CLOSE_ALL) { + current_menu_option = -1; } else { _scene_tab_closed(editor_data.get_edited_scene()); } @@ -2537,11 +2533,11 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER: case FILE_CLOSE_ALL_AND_RELOAD_CURRENT_PROJECT: { if (!p_confirmed) { - tab_closing = _next_unsaved_scene(false); - _scene_tab_changed(tab_closing); + tab_closing_idx = _next_unsaved_scene(false); + _scene_tab_changed(tab_closing_idx); if (unsaved_cache || p_option == FILE_CLOSE_ALL_AND_QUIT || p_option == FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER || p_option == FILE_CLOSE_ALL_AND_RELOAD_CURRENT_PROJECT) { - Node *scene_root = editor_data.get_edited_scene_root(tab_closing); + Node *scene_root = editor_data.get_edited_scene_root(tab_closing_idx); if (scene_root) { String scene_filename = scene_root->get_scene_file_path(); if (p_option == FILE_CLOSE_ALL_AND_RELOAD_CURRENT_PROJECT) { @@ -2556,9 +2552,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } } - if (!editor_data.get_edited_scene_root(tab_closing)) { - // empty tab - _scene_tab_closed(tab_closing); + if (!editor_data.get_edited_scene_root(tab_closing_idx)) { + // Empty tab. + _scene_tab_closed(tab_closing_idx); break; } @@ -2566,7 +2562,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } case SCENE_TAB_CLOSE: case FILE_SAVE_SCENE: { - int scene_idx = (p_option == FILE_SAVE_SCENE) ? -1 : tab_closing; + int scene_idx = (p_option == FILE_SAVE_SCENE) ? -1 : tab_closing_idx; Node *scene = editor_data.get_edited_scene_root(scene_idx); if (scene && !scene->get_scene_file_path().is_empty()) { if (DirAccess::exists(scene->get_scene_file_path().get_base_dir())) { @@ -2588,7 +2584,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { [[fallthrough]]; } case FILE_SAVE_AS_SCENE: { - int scene_idx = (p_option == FILE_SAVE_SCENE || p_option == FILE_SAVE_AS_SCENE) ? -1 : tab_closing; + int scene_idx = (p_option == FILE_SAVE_SCENE || p_option == FILE_SAVE_AS_SCENE) ? -1 : tab_closing_idx; Node *scene = editor_data.get_edited_scene_root(scene_idx); @@ -2829,7 +2825,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } break; case RUN_USER_DATA_FOLDER: { - // ensure_user_data_dir() to prevent the edge case: "Open User Data Folder" won't work after the project was renamed in ProjectSettingsEditor unless the project is saved + // Ensure_user_data_dir() to prevent the edge case: "Open User Data Folder" won't work after the project was renamed in ProjectSettingsEditor unless the project is saved. OS::get_singleton()->ensure_user_data_dir(); OS::get_singleton()->shell_open(String("file://") + OS::get_singleton()->get_user_data_dir()); } break; @@ -2967,12 +2963,6 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case HELP_SUPPORT_GODOT_DEVELOPMENT: { OS::get_singleton()->shell_open("https://godotengine.org/donate"); } break; - - // case SET_VIDEO_DRIVER_SAVE_AND_RESTART: { - // ProjectSettings::get_singleton()->set("rendering/driver/driver_name", video_driver_request); - // save_all_scenes(); - // restart_editor(); - // } break; case SET_RENDERING_DRIVER_SAVE_AND_RESTART: { ProjectSettings::get_singleton()->set("rendering/driver/driver_name", rendering_driver_request); ProjectSettings::get_singleton()->save(); @@ -3025,7 +3015,7 @@ void EditorNode::_tool_menu_option(int p_idx) { String err = Variant::get_callable_error_text(callback, nullptr, 0, ce); ERR_PRINT("Error calling function from tool menu: " + err); } - } // else it's a submenu so don't do anything. + } // Else it's a submenu so don't do anything. } break; } } @@ -3050,17 +3040,17 @@ int EditorNode::_next_unsaved_scene(bool p_valid_filename, int p_start) { void EditorNode::_exit_editor(int p_exit_code) { exiting = true; - resource_preview->stop(); // stop early to avoid crashes + resource_preview->stop(); // Stop early to avoid crashes. _save_docks(); - // Dim the editor window while it's quitting to make it clearer that it's busy + // Dim the editor window while it's quitting to make it clearer that it's busy. dim_editor(true); get_tree()->quit(p_exit_code); } void EditorNode::_discard_changes(const String &p_str) { - switch (current_option) { + switch (current_menu_option) { case FILE_CLOSE_ALL_AND_QUIT: case FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER: case FILE_CLOSE_ALL_AND_RELOAD_CURRENT_PROJECT: @@ -3069,7 +3059,7 @@ void EditorNode::_discard_changes(const String &p_str) { case FILE_CLOSE_RIGHT: case FILE_CLOSE_ALL: case SCENE_TAB_CLOSE: { - Node *scene = editor_data.get_edited_scene_root(tab_closing); + Node *scene = editor_data.get_edited_scene_root(tab_closing_idx); if (scene != nullptr) { String scene_filename = scene->get_scene_file_path(); if (!scene_filename.is_empty()) { @@ -3077,37 +3067,37 @@ void EditorNode::_discard_changes(const String &p_str) { } } - _remove_scene(tab_closing); + _remove_scene(tab_closing_idx); _update_scene_tabs(); - if (current_option == FILE_CLOSE_ALL_AND_QUIT || current_option == FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER || current_option == FILE_CLOSE_ALL_AND_RELOAD_CURRENT_PROJECT) { + if (current_menu_option == FILE_CLOSE_ALL_AND_QUIT || current_menu_option == FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER || current_menu_option == FILE_CLOSE_ALL_AND_RELOAD_CURRENT_PROJECT) { // If restore tabs is enabled, reopen the scene that has just been closed, so it's remembered properly. if (bool(EDITOR_GET("interface/scene_tabs/restore_scenes_on_load"))) { _menu_option_confirm(FILE_OPEN_PREV, true); } if (_next_unsaved_scene(false) == -1) { - if (current_option == FILE_CLOSE_ALL_AND_RELOAD_CURRENT_PROJECT) { - current_option = RELOAD_CURRENT_PROJECT; - } else if (current_option == FILE_CLOSE_ALL_AND_QUIT) { - current_option = FILE_QUIT; + if (current_menu_option == FILE_CLOSE_ALL_AND_RELOAD_CURRENT_PROJECT) { + current_menu_option = RELOAD_CURRENT_PROJECT; + } else if (current_menu_option == FILE_CLOSE_ALL_AND_QUIT) { + current_menu_option = FILE_QUIT; } else { - current_option = RUN_PROJECT_MANAGER; + current_menu_option = RUN_PROJECT_MANAGER; } _discard_changes(); } else { - _menu_option_confirm(current_option, false); + _menu_option_confirm(current_menu_option, false); } - } else if (current_option == FILE_CLOSE_OTHERS || current_option == FILE_CLOSE_RIGHT) { - if (editor_data.get_edited_scene_count() == 1 || (current_option == FILE_CLOSE_RIGHT && editor_data.get_edited_scene_count() <= editor_data.get_edited_scene() + 1)) { - current_option = -1; + } else if (current_menu_option == FILE_CLOSE_OTHERS || current_menu_option == FILE_CLOSE_RIGHT) { + if (editor_data.get_edited_scene_count() == 1 || (current_menu_option == FILE_CLOSE_RIGHT && editor_data.get_edited_scene_count() <= editor_data.get_edited_scene() + 1)) { + current_menu_option = -1; save_confirmation->hide(); } else { - _menu_option_confirm(current_option, false); + _menu_option_confirm(current_menu_option, false); } - } else if (current_option == FILE_CLOSE_ALL && editor_data.get_edited_scene_count() > 0) { - _menu_option_confirm(current_option, false); + } else if (current_menu_option == FILE_CLOSE_ALL && editor_data.get_edited_scene_count() > 0) { + _menu_option_confirm(current_menu_option, false); } else { - current_option = -1; + current_menu_option = -1; save_confirmation->hide(); } } break; @@ -3166,7 +3156,7 @@ void EditorNode::_editor_select(int p_which) { ERR_FAIL_INDEX(p_which, editor_table.size()); - if (!main_editor_buttons[p_which]->is_visible()) { // button hidden, no editor + if (!main_editor_buttons[p_which]->is_visible()) { // Button hidden, no editor. return; } @@ -3200,9 +3190,9 @@ void EditorNode::_editor_select(int p_which) { if (EditorSettings::get_singleton()->get("interface/editor/separate_distraction_mode")) { if (p_which == EDITOR_SCRIPT) { - set_distraction_free_mode(script_distraction); + set_distraction_free_mode(script_distraction_free); } else { - set_distraction_free_mode(scene_distraction); + set_distraction_free_mode(scene_distraction_free); } } } @@ -3282,13 +3272,13 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan } void EditorNode::_update_addon_config() { - if (_initializing_addons) { + if (_initializing_plugins) { return; } Vector enabled_addons; - for (const KeyValue &E : plugin_addons) { + for (const KeyValue &E : addon_name_to_plugin) { enabled_addons.push_back(E.key); } @@ -3302,14 +3292,14 @@ void EditorNode::_update_addon_config() { } void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed) { - ERR_FAIL_COND(p_enabled && plugin_addons.has(p_addon)); - ERR_FAIL_COND(!p_enabled && !plugin_addons.has(p_addon)); + ERR_FAIL_COND(p_enabled && addon_name_to_plugin.has(p_addon)); + ERR_FAIL_COND(!p_enabled && !addon_name_to_plugin.has(p_addon)); if (!p_enabled) { - EditorPlugin *addon = plugin_addons[p_addon]; + EditorPlugin *addon = addon_name_to_plugin[p_addon]; remove_editor_plugin(addon, p_config_changed); - memdelete(addon); // bye - plugin_addons.erase(p_addon); + memdelete(addon); + addon_name_to_plugin.erase(p_addon); _update_addon_config(); return; } @@ -3366,14 +3356,14 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, EditorPlugin *ep = memnew(EditorPlugin); ep->set_script(script); - plugin_addons[p_addon] = ep; + addon_name_to_plugin[p_addon] = ep; add_editor_plugin(ep, p_config_changed); _update_addon_config(); } bool EditorNode::is_addon_plugin_enabled(const String &p_addon) const { - return plugin_addons.has(p_addon); + return addon_name_to_plugin.has(p_addon); } void EditorNode::_remove_edited_scene(bool p_change_tab) { @@ -3400,10 +3390,10 @@ void EditorNode::_remove_edited_scene(bool p_change_tab) { void EditorNode::_remove_scene(int index, bool p_change_tab) { if (editor_data.get_edited_scene() == index) { - // Scene to remove is current scene + // Scene to remove is current scene. _remove_edited_scene(p_change_tab); } else { - // Scene to remove is not active scene + // Scene to remove is not active scene. editor_data.remove_scene(index); } } @@ -3417,7 +3407,7 @@ void EditorNode::set_edited_scene(Node *p_scene) { get_editor_data().set_edited_scene_root(p_scene); if (Object::cast_to(p_scene)) { - Object::cast_to(p_scene)->show(); // show popups + Object::cast_to(p_scene)->show(); } SceneTreeDock::get_singleton()->set_edited_scene(p_scene); if (get_tree()) { @@ -3453,7 +3443,7 @@ Dictionary EditorNode::_get_main_scene_state() { void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { if (get_edited_scene() != p_for_scene && p_for_scene != nullptr) { - return; // not for this scene + return; // Not for this scene. } changing_scene = false; @@ -3468,7 +3458,7 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { if (p_state.has("editor_index")) { int index = p_state["editor_index"]; - if (current < 2) { // if currently in spatial/2d, only switch to spatial/2d. if currently in script, stay there + if (current < 2) { // If currently in spatial/2d, only switch to spatial/2d. If currently in script, stay there. if (index < 2 || !get_edited_scene()) { _editor_select(index); } @@ -3477,7 +3467,7 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { if (get_edited_scene()) { if (current < 2) { - // use heuristic instead + // Use heuristic instead. int n2d = 0, n3d = 0; _find_node_types(get_edited_scene(), n2d, n3d); if (n2d > n3d) { @@ -3499,7 +3489,7 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { SceneTreeDock::get_singleton()->set_filter(p_state["node_filter"]); } - // this should only happen at the very end + // This should only happen at the very end. EditorDebuggerNode::get_singleton()->update_live_edit_root(); ScriptEditor::get_singleton()->set_scene_root_script(editor_data.get_scene_root_script(editor_data.get_edited_scene())); @@ -3548,7 +3538,7 @@ void EditorNode::set_current_scene(int p_idx) { Node *new_scene = editor_data.get_edited_scene_root(); if (Object::cast_to(new_scene)) { - Object::cast_to(new_scene)->show(); // show popups + Object::cast_to(new_scene)->show(); } SceneTreeDock::get_singleton()->set_edited_scene(new_scene); @@ -3567,7 +3557,7 @@ void EditorNode::set_current_scene(int p_idx) { _update_title(); - call_deferred(SNAME("_set_main_scene_state"), state, get_edited_scene()); // do after everything else is done setting up + call_deferred(SNAME("_set_main_scene_state"), state, get_edited_scene()); // Do after everything else is done setting up. } bool EditorNode::is_scene_open(const String &p_path) { @@ -3654,7 +3644,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b } if (!p_ignore_broken_deps && dependency_errors.has(lpath)) { - current_option = -1; + current_menu_option = -1; Vector errors; for (Set::Element *E = dependency_errors[lpath].front(); E; E = E->next()) { errors.push_back(E->get()); @@ -3669,7 +3659,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b return ERR_FILE_MISSING_DEPENDENCIES; } - dependency_errors.erase(lpath); // at least not self path + dependency_errors.erase(lpath); // At least not self path. for (KeyValue> &E : dependency_errors) { String txt = vformat(TTR("Scene '%s' has broken dependencies:"), E.key) + "\n"; @@ -3680,7 +3670,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b } if (ResourceCache::has(lpath)) { - // used from somewhere else? no problem! update state and replace sdata + // Used from somewhere else? No problem! Update state and replace sdata. Ref ps = Ref(Object::cast_to(ResourceCache::get(lpath))); if (ps.is_valid()) { ps->replace_state(sdata->get_state()); @@ -3689,7 +3679,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b } } else { - sdata->set_path(lpath, true); // take over path + sdata->set_path(lpath, true); // Take over path. } Node *new_scene = sdata->instantiate(p_set_inherited ? PackedScene::GEN_EDIT_STATE_MAIN_INHERITED : PackedScene::GEN_EDIT_STATE_MAIN); @@ -3752,7 +3742,7 @@ void EditorNode::open_request(const String &p_path) { } } - load_scene(p_path); // as it will be opened in separate tab + load_scene(p_path); // As it will be opened in separate tab. } void EditorNode::edit_foreign_resource(RES p_resource) { @@ -3769,7 +3759,7 @@ void EditorNode::request_instantiate_scenes(const Vector &p_files) { } void EditorNode::_inherit_request(String p_file) { - current_option = FILE_NEW_INHERITED_SCENE; + current_menu_option = FILE_NEW_INHERITED_SCENE; _dialog_action(p_file); } @@ -3931,9 +3921,7 @@ void EditorNode::register_editor_types() { GDREGISTER_ABSTRACT_CLASS(FileSystemDock); - // FIXME: Is this stuff obsolete, or should it be ported to new APIs? GDREGISTER_CLASS(EditorScenePostImport); - //ClassDB::register_type(); GDREGISTER_CLASS(EditorCommandPalette); GDREGISTER_CLASS(EditorDebuggerPlugin); @@ -3971,7 +3959,7 @@ Ref