Skip to content

Commit fb476d0

Browse files
committed
Cleanup EditorPluginList
- Removes unused / unnecessary methods. - Removes the `Object` parent. No `Object` features are used by this class. - Makes the actual list a `LocalVector` instead of a `Vector`. It's not shared. - Moves the class into a separate file. `editor_node.{h,cpp}` are bloated. - Simplify some call sites of `EditorPluginList` methods.
1 parent 3bf0f77 commit fb476d0

File tree

7 files changed

+181
-158
lines changed

7 files changed

+181
-158
lines changed

editor/editor_node.cpp

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "core/version.h"
4848
#include "editor/editor_string_names.h"
4949
#include "editor/inspector/editor_context_menu_plugin.h"
50+
#include "editor/plugins/editor_plugin_list.h"
5051
#include "main/main.h"
5152
#include "scene/2d/node_2d.h"
5253
#include "scene/3d/bone_attachment_3d.h"
@@ -8899,92 +8900,3 @@ EditorNode::~EditorNode() {
88998900

89008901
singleton = nullptr;
89018902
}
8902-
8903-
/*
8904-
* EDITOR PLUGIN LIST
8905-
*/
8906-
8907-
void EditorPluginList::make_visible(bool p_visible) {
8908-
for (int i = 0; i < plugins_list.size(); i++) {
8909-
plugins_list[i]->make_visible(p_visible);
8910-
}
8911-
}
8912-
8913-
void EditorPluginList::edit(Object *p_object) {
8914-
for (int i = 0; i < plugins_list.size(); i++) {
8915-
plugins_list[i]->edit(p_object);
8916-
}
8917-
}
8918-
8919-
bool EditorPluginList::forward_gui_input(const Ref<InputEvent> &p_event) {
8920-
bool discard = false;
8921-
8922-
for (int i = 0; i < plugins_list.size(); i++) {
8923-
if (plugins_list[i]->forward_canvas_gui_input(p_event)) {
8924-
discard = true;
8925-
}
8926-
}
8927-
8928-
return discard;
8929-
}
8930-
8931-
EditorPlugin::AfterGUIInput EditorPluginList::forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled) {
8932-
EditorPlugin::AfterGUIInput after = EditorPlugin::AFTER_GUI_INPUT_PASS;
8933-
8934-
for (int i = 0; i < plugins_list.size(); i++) {
8935-
if ((!serve_when_force_input_enabled) && plugins_list[i]->is_input_event_forwarding_always_enabled()) {
8936-
continue;
8937-
}
8938-
8939-
EditorPlugin::AfterGUIInput current_after = plugins_list[i]->forward_3d_gui_input(p_camera, p_event);
8940-
if (current_after == EditorPlugin::AFTER_GUI_INPUT_STOP) {
8941-
after = EditorPlugin::AFTER_GUI_INPUT_STOP;
8942-
}
8943-
if (after != EditorPlugin::AFTER_GUI_INPUT_STOP && current_after == EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
8944-
after = EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
8945-
}
8946-
}
8947-
8948-
return after;
8949-
}
8950-
8951-
void EditorPluginList::forward_canvas_draw_over_viewport(Control *p_overlay) {
8952-
for (int i = 0; i < plugins_list.size(); i++) {
8953-
plugins_list[i]->forward_canvas_draw_over_viewport(p_overlay);
8954-
}
8955-
}
8956-
8957-
void EditorPluginList::forward_canvas_force_draw_over_viewport(Control *p_overlay) {
8958-
for (int i = 0; i < plugins_list.size(); i++) {
8959-
plugins_list[i]->forward_canvas_force_draw_over_viewport(p_overlay);
8960-
}
8961-
}
8962-
8963-
void EditorPluginList::forward_3d_draw_over_viewport(Control *p_overlay) {
8964-
for (int i = 0; i < plugins_list.size(); i++) {
8965-
plugins_list[i]->forward_3d_draw_over_viewport(p_overlay);
8966-
}
8967-
}
8968-
8969-
void EditorPluginList::forward_3d_force_draw_over_viewport(Control *p_overlay) {
8970-
for (int i = 0; i < plugins_list.size(); i++) {
8971-
plugins_list[i]->forward_3d_force_draw_over_viewport(p_overlay);
8972-
}
8973-
}
8974-
8975-
void EditorPluginList::add_plugin(EditorPlugin *p_plugin) {
8976-
ERR_FAIL_COND(plugins_list.has(p_plugin));
8977-
plugins_list.push_back(p_plugin);
8978-
}
8979-
8980-
void EditorPluginList::remove_plugin(EditorPlugin *p_plugin) {
8981-
plugins_list.erase(p_plugin);
8982-
}
8983-
8984-
bool EditorPluginList::is_empty() {
8985-
return plugins_list.is_empty();
8986-
}
8987-
8988-
void EditorPluginList::clear() {
8989-
plugins_list.clear();
8990-
}

editor/editor_node.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,35 +1013,6 @@ class EditorNode : public Node {
10131013
void run_editor_script(const Ref<Script> &p_script);
10141014
};
10151015

1016-
class EditorPluginList : public Object {
1017-
GDSOFTCLASS(EditorPluginList, Object);
1018-
1019-
private:
1020-
Vector<EditorPlugin *> plugins_list;
1021-
1022-
public:
1023-
void set_plugins_list(Vector<EditorPlugin *> p_plugins_list) {
1024-
plugins_list = p_plugins_list;
1025-
}
1026-
1027-
Vector<EditorPlugin *> &get_plugins_list() {
1028-
return plugins_list;
1029-
}
1030-
1031-
void make_visible(bool p_visible);
1032-
void edit(Object *p_object);
1033-
bool forward_gui_input(const Ref<InputEvent> &p_event);
1034-
void forward_canvas_draw_over_viewport(Control *p_overlay);
1035-
void forward_canvas_force_draw_over_viewport(Control *p_overlay);
1036-
EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
1037-
void forward_3d_draw_over_viewport(Control *p_overlay);
1038-
void forward_3d_force_draw_over_viewport(Control *p_overlay);
1039-
void add_plugin(EditorPlugin *p_plugin);
1040-
void remove_plugin(EditorPlugin *p_plugin);
1041-
void clear();
1042-
bool is_empty();
1043-
};
1044-
10451016
struct EditorProgressBG {
10461017
String task;
10471018
void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }

editor/plugins/editor_plugin.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "editor/import/3d/resource_importer_scene.h"
4848
#include "editor/import/editor_import_plugin.h"
4949
#include "editor/inspector/editor_inspector.h"
50+
#include "editor/plugins/editor_plugin_list.h"
5051
#include "editor/plugins/editor_resource_conversion_plugin.h"
5152
#include "editor/scene/3d/node_3d_editor_plugin.h"
5253
#include "editor/scene/canvas_item_editor_plugin.h"
@@ -223,14 +224,12 @@ PopupMenu *EditorPlugin::get_export_as_menu() {
223224

224225
void EditorPlugin::set_input_event_forwarding_always_enabled() {
225226
input_event_forwarding_always_enabled = true;
226-
EditorPluginList *always_input_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding();
227-
always_input_forwarding_list->add_plugin(this);
227+
EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding()->add_plugin(this);
228228
}
229229

230230
void EditorPlugin::set_force_draw_over_forwarding_enabled() {
231231
force_draw_over_forwarding_enabled = true;
232-
EditorPluginList *always_draw_over_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_over();
233-
always_draw_over_forwarding_list->add_plugin(this);
232+
EditorNode::get_singleton()->get_editor_plugins_force_over()->add_plugin(this);
234233
}
235234

236235
void EditorPlugin::notify_scene_changed(const Node *scn_root) {
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**************************************************************************/
2+
/* editor_plugin_list.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include "editor_plugin_list.h"
32+
33+
bool EditorPluginList::forward_gui_input(const Ref<InputEvent> &p_event) const {
34+
bool discard = false;
35+
36+
for (EditorPlugin *plugin : plugins_list) {
37+
if (plugin->forward_canvas_gui_input(p_event)) {
38+
discard = true;
39+
}
40+
}
41+
42+
return discard;
43+
}
44+
45+
EditorPlugin::AfterGUIInput EditorPluginList::forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool p_serve_when_force_input_enabled) const {
46+
EditorPlugin::AfterGUIInput after = EditorPlugin::AFTER_GUI_INPUT_PASS;
47+
48+
for (EditorPlugin *plugin : plugins_list) {
49+
if (!p_serve_when_force_input_enabled && plugin->is_input_event_forwarding_always_enabled()) {
50+
continue;
51+
}
52+
53+
EditorPlugin::AfterGUIInput current_after = plugin->forward_3d_gui_input(p_camera, p_event);
54+
if (current_after == EditorPlugin::AFTER_GUI_INPUT_STOP) {
55+
after = EditorPlugin::AFTER_GUI_INPUT_STOP;
56+
}
57+
if (after != EditorPlugin::AFTER_GUI_INPUT_STOP && current_after == EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
58+
after = EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
59+
}
60+
}
61+
62+
return after;
63+
}
64+
65+
void EditorPluginList::forward_canvas_draw_over_viewport(Control *p_overlay) const {
66+
for (EditorPlugin *plugin : plugins_list) {
67+
plugin->forward_canvas_draw_over_viewport(p_overlay);
68+
}
69+
}
70+
71+
void EditorPluginList::forward_canvas_force_draw_over_viewport(Control *p_overlay) const {
72+
for (EditorPlugin *plugin : plugins_list) {
73+
plugin->forward_canvas_force_draw_over_viewport(p_overlay);
74+
}
75+
}
76+
77+
void EditorPluginList::forward_3d_draw_over_viewport(Control *p_overlay) const {
78+
for (EditorPlugin *plugin : plugins_list) {
79+
plugin->forward_3d_draw_over_viewport(p_overlay);
80+
}
81+
}
82+
83+
void EditorPluginList::forward_3d_force_draw_over_viewport(Control *p_overlay) const {
84+
for (EditorPlugin *plugin : plugins_list) {
85+
plugin->forward_3d_force_draw_over_viewport(p_overlay);
86+
}
87+
}
88+
89+
void EditorPluginList::add_plugin(EditorPlugin *p_plugin) {
90+
ERR_FAIL_COND(plugins_list.has(p_plugin));
91+
plugins_list.push_back(p_plugin);
92+
}
93+
94+
void EditorPluginList::remove_plugin(EditorPlugin *p_plugin) {
95+
plugins_list.erase(p_plugin);
96+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**************************************************************************/
2+
/* editor_plugin_list.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#pragma once
32+
33+
#include "editor/plugins/editor_plugin.h"
34+
35+
class Control;
36+
class InputEvent;
37+
38+
class EditorPluginList {
39+
LocalVector<EditorPlugin *> plugins_list;
40+
41+
public:
42+
bool forward_gui_input(const Ref<InputEvent> &p_event) const;
43+
void forward_canvas_draw_over_viewport(Control *p_overlay) const;
44+
void forward_canvas_force_draw_over_viewport(Control *p_overlay) const;
45+
EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool p_serve_when_force_input_enabled) const;
46+
void forward_3d_draw_over_viewport(Control *p_overlay) const;
47+
void forward_3d_force_draw_over_viewport(Control *p_overlay) const;
48+
49+
void add_plugin(EditorPlugin *p_plugin);
50+
void remove_plugin(EditorPlugin *p_plugin);
51+
};

editor/scene/3d/node_3d_editor_plugin.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "editor/editor_string_names.h"
4545
#include "editor/editor_undo_redo_manager.h"
4646
#include "editor/gui/editor_spin_slider.h"
47+
#include "editor/plugins/editor_plugin_list.h"
4748
#include "editor/run/editor_run_bar.h"
4849
#include "editor/scene/3d/gizmos/audio_listener_3d_gizmo_plugin.h"
4950
#include "editor/scene/3d/gizmos/audio_stream_player_3d_gizmo_plugin.h"
@@ -1726,28 +1727,33 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
17261727
EditorPlugin::AfterGUIInput after = EditorPlugin::AFTER_GUI_INPUT_PASS;
17271728
{
17281729
EditorNode *en = EditorNode::get_singleton();
1729-
EditorPluginList *force_input_forwarding_list = en->get_editor_plugins_force_input_forwarding();
1730-
if (!force_input_forwarding_list->is_empty()) {
1731-
EditorPlugin::AfterGUIInput discard = force_input_forwarding_list->forward_3d_gui_input(camera, p_event, true);
1732-
if (discard == EditorPlugin::AFTER_GUI_INPUT_STOP) {
1733-
return;
1734-
}
1735-
if (discard == EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
1730+
1731+
switch (en->get_editor_plugins_force_input_forwarding()->forward_3d_gui_input(camera, p_event, true)) {
1732+
case EditorPlugin::AFTER_GUI_INPUT_PASS: {
1733+
// Continue processing.
1734+
} break;
1735+
1736+
case EditorPlugin::AFTER_GUI_INPUT_STOP: {
1737+
return; // Stop processing.
1738+
} break;
1739+
1740+
case EditorPlugin::AFTER_GUI_INPUT_CUSTOM: {
17361741
after = EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
1737-
}
1742+
} break;
17381743
}
1739-
}
1740-
{
1741-
EditorNode *en = EditorNode::get_singleton();
1742-
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
1743-
if (!over_plugin_list->is_empty()) {
1744-
EditorPlugin::AfterGUIInput discard = over_plugin_list->forward_3d_gui_input(camera, p_event, false);
1745-
if (discard == EditorPlugin::AFTER_GUI_INPUT_STOP) {
1746-
return;
1747-
}
1748-
if (discard == EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
1744+
1745+
switch (en->get_editor_plugins_over()->forward_3d_gui_input(camera, p_event, false)) {
1746+
case EditorPlugin::AFTER_GUI_INPUT_PASS: {
1747+
// Continue processing.
1748+
} break;
1749+
1750+
case EditorPlugin::AFTER_GUI_INPUT_STOP: {
1751+
return; // Stop processing.
1752+
} break;
1753+
1754+
case EditorPlugin::AFTER_GUI_INPUT_CUSTOM: {
17491755
after = EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
1750-
}
1756+
} break;
17511757
}
17521758
}
17531759

@@ -3494,15 +3500,8 @@ static void draw_indicator_bar(Control &p_surface, real_t p_fill, const Ref<Text
34943500
}
34953501

34963502
void Node3DEditorViewport::_draw() {
3497-
EditorPluginList *over_plugin_list = EditorNode::get_singleton()->get_editor_plugins_over();
3498-
if (!over_plugin_list->is_empty()) {
3499-
over_plugin_list->forward_3d_draw_over_viewport(surface);
3500-
}
3501-
3502-
EditorPluginList *force_over_plugin_list = EditorNode::get_singleton()->get_editor_plugins_force_over();
3503-
if (!force_over_plugin_list->is_empty()) {
3504-
force_over_plugin_list->forward_3d_force_draw_over_viewport(surface);
3505-
}
3503+
EditorNode::get_singleton()->get_editor_plugins_over()->forward_3d_draw_over_viewport(surface);
3504+
EditorNode::get_singleton()->get_editor_plugins_force_over()->forward_3d_force_draw_over_viewport(surface);
35063505

35073506
if (surface->has_focus() || rotation_control->has_focus()) {
35083507
Size2 size = surface->get_size();

0 commit comments

Comments
 (0)