Skip to content

Commit 65beea6

Browse files
committed
Merge pull request godotengine#108987 from timothyqiu/plugins-list-cleanup
Clean up `EditorPluginList`
2 parents 9a9e64a + fb476d0 commit 65beea6

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"
@@ -9154,92 +9155,3 @@ EditorNode::~EditorNode() {
91549155

91559156
singleton = nullptr;
91569157
}
9157-
9158-
/*
9159-
* EDITOR PLUGIN LIST
9160-
*/
9161-
9162-
void EditorPluginList::make_visible(bool p_visible) {
9163-
for (int i = 0; i < plugins_list.size(); i++) {
9164-
plugins_list[i]->make_visible(p_visible);
9165-
}
9166-
}
9167-
9168-
void EditorPluginList::edit(Object *p_object) {
9169-
for (int i = 0; i < plugins_list.size(); i++) {
9170-
plugins_list[i]->edit(p_object);
9171-
}
9172-
}
9173-
9174-
bool EditorPluginList::forward_gui_input(const Ref<InputEvent> &p_event) {
9175-
bool discard = false;
9176-
9177-
for (int i = 0; i < plugins_list.size(); i++) {
9178-
if (plugins_list[i]->forward_canvas_gui_input(p_event)) {
9179-
discard = true;
9180-
}
9181-
}
9182-
9183-
return discard;
9184-
}
9185-
9186-
EditorPlugin::AfterGUIInput EditorPluginList::forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled) {
9187-
EditorPlugin::AfterGUIInput after = EditorPlugin::AFTER_GUI_INPUT_PASS;
9188-
9189-
for (int i = 0; i < plugins_list.size(); i++) {
9190-
if ((!serve_when_force_input_enabled) && plugins_list[i]->is_input_event_forwarding_always_enabled()) {
9191-
continue;
9192-
}
9193-
9194-
EditorPlugin::AfterGUIInput current_after = plugins_list[i]->forward_3d_gui_input(p_camera, p_event);
9195-
if (current_after == EditorPlugin::AFTER_GUI_INPUT_STOP) {
9196-
after = EditorPlugin::AFTER_GUI_INPUT_STOP;
9197-
}
9198-
if (after != EditorPlugin::AFTER_GUI_INPUT_STOP && current_after == EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
9199-
after = EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
9200-
}
9201-
}
9202-
9203-
return after;
9204-
}
9205-
9206-
void EditorPluginList::forward_canvas_draw_over_viewport(Control *p_overlay) {
9207-
for (int i = 0; i < plugins_list.size(); i++) {
9208-
plugins_list[i]->forward_canvas_draw_over_viewport(p_overlay);
9209-
}
9210-
}
9211-
9212-
void EditorPluginList::forward_canvas_force_draw_over_viewport(Control *p_overlay) {
9213-
for (int i = 0; i < plugins_list.size(); i++) {
9214-
plugins_list[i]->forward_canvas_force_draw_over_viewport(p_overlay);
9215-
}
9216-
}
9217-
9218-
void EditorPluginList::forward_3d_draw_over_viewport(Control *p_overlay) {
9219-
for (int i = 0; i < plugins_list.size(); i++) {
9220-
plugins_list[i]->forward_3d_draw_over_viewport(p_overlay);
9221-
}
9222-
}
9223-
9224-
void EditorPluginList::forward_3d_force_draw_over_viewport(Control *p_overlay) {
9225-
for (int i = 0; i < plugins_list.size(); i++) {
9226-
plugins_list[i]->forward_3d_force_draw_over_viewport(p_overlay);
9227-
}
9228-
}
9229-
9230-
void EditorPluginList::add_plugin(EditorPlugin *p_plugin) {
9231-
ERR_FAIL_COND(plugins_list.has(p_plugin));
9232-
plugins_list.push_back(p_plugin);
9233-
}
9234-
9235-
void EditorPluginList::remove_plugin(EditorPlugin *p_plugin) {
9236-
plugins_list.erase(p_plugin);
9237-
}
9238-
9239-
bool EditorPluginList::is_empty() {
9240-
return plugins_list.is_empty();
9241-
}
9242-
9243-
void EditorPluginList::clear() {
9244-
plugins_list.clear();
9245-
}

editor/editor_node.h

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

1037-
class EditorPluginList : public Object {
1038-
GDSOFTCLASS(EditorPluginList, Object);
1039-
1040-
private:
1041-
Vector<EditorPlugin *> plugins_list;
1042-
1043-
public:
1044-
void set_plugins_list(Vector<EditorPlugin *> p_plugins_list) {
1045-
plugins_list = p_plugins_list;
1046-
}
1047-
1048-
Vector<EditorPlugin *> &get_plugins_list() {
1049-
return plugins_list;
1050-
}
1051-
1052-
void make_visible(bool p_visible);
1053-
void edit(Object *p_object);
1054-
bool forward_gui_input(const Ref<InputEvent> &p_event);
1055-
void forward_canvas_draw_over_viewport(Control *p_overlay);
1056-
void forward_canvas_force_draw_over_viewport(Control *p_overlay);
1057-
EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
1058-
void forward_3d_draw_over_viewport(Control *p_overlay);
1059-
void forward_3d_force_draw_over_viewport(Control *p_overlay);
1060-
void add_plugin(EditorPlugin *p_plugin);
1061-
void remove_plugin(EditorPlugin *p_plugin);
1062-
void clear();
1063-
bool is_empty();
1064-
};
1065-
10661037
struct EditorProgressBG {
10671038
String task;
10681039
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
@@ -48,6 +48,7 @@
4848
#include "editor/import/3d/resource_importer_scene.h"
4949
#include "editor/import/editor_import_plugin.h"
5050
#include "editor/inspector/editor_inspector.h"
51+
#include "editor/plugins/editor_plugin_list.h"
5152
#include "editor/plugins/editor_resource_conversion_plugin.h"
5253
#include "editor/scene/3d/node_3d_editor_plugin.h"
5354
#include "editor/scene/canvas_item_editor_plugin.h"
@@ -248,14 +249,12 @@ PopupMenu *EditorPlugin::get_export_as_menu() {
248249

249250
void EditorPlugin::set_input_event_forwarding_always_enabled() {
250251
input_event_forwarding_always_enabled = true;
251-
EditorPluginList *always_input_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding();
252-
always_input_forwarding_list->add_plugin(this);
252+
EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding()->add_plugin(this);
253253
}
254254

255255
void EditorPlugin::set_force_draw_over_forwarding_enabled() {
256256
force_draw_over_forwarding_enabled = true;
257-
EditorPluginList *always_draw_over_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_over();
258-
always_draw_over_forwarding_list->add_plugin(this);
257+
EditorNode::get_singleton()->get_editor_plugins_force_over()->add_plugin(this);
259258
}
260259

261260
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
@@ -45,6 +45,7 @@
4545
#include "editor/editor_string_names.h"
4646
#include "editor/editor_undo_redo_manager.h"
4747
#include "editor/gui/editor_spin_slider.h"
48+
#include "editor/plugins/editor_plugin_list.h"
4849
#include "editor/run/editor_run_bar.h"
4950
#include "editor/scene/3d/gizmos/audio_listener_3d_gizmo_plugin.h"
5051
#include "editor/scene/3d/gizmos/audio_stream_player_3d_gizmo_plugin.h"
@@ -1767,28 +1768,33 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
17671768
EditorPlugin::AfterGUIInput after = EditorPlugin::AFTER_GUI_INPUT_PASS;
17681769
{
17691770
EditorNode *en = EditorNode::get_singleton();
1770-
EditorPluginList *force_input_forwarding_list = en->get_editor_plugins_force_input_forwarding();
1771-
if (!force_input_forwarding_list->is_empty()) {
1772-
EditorPlugin::AfterGUIInput discard = force_input_forwarding_list->forward_3d_gui_input(camera, p_event, true);
1773-
if (discard == EditorPlugin::AFTER_GUI_INPUT_STOP) {
1774-
return;
1775-
}
1776-
if (discard == EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
1771+
1772+
switch (en->get_editor_plugins_force_input_forwarding()->forward_3d_gui_input(camera, p_event, true)) {
1773+
case EditorPlugin::AFTER_GUI_INPUT_PASS: {
1774+
// Continue processing.
1775+
} break;
1776+
1777+
case EditorPlugin::AFTER_GUI_INPUT_STOP: {
1778+
return; // Stop processing.
1779+
} break;
1780+
1781+
case EditorPlugin::AFTER_GUI_INPUT_CUSTOM: {
17771782
after = EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
1778-
}
1783+
} break;
17791784
}
1780-
}
1781-
{
1782-
EditorNode *en = EditorNode::get_singleton();
1783-
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
1784-
if (!over_plugin_list->is_empty()) {
1785-
EditorPlugin::AfterGUIInput discard = over_plugin_list->forward_3d_gui_input(camera, p_event, false);
1786-
if (discard == EditorPlugin::AFTER_GUI_INPUT_STOP) {
1787-
return;
1788-
}
1789-
if (discard == EditorPlugin::AFTER_GUI_INPUT_CUSTOM) {
1785+
1786+
switch (en->get_editor_plugins_over()->forward_3d_gui_input(camera, p_event, false)) {
1787+
case EditorPlugin::AFTER_GUI_INPUT_PASS: {
1788+
// Continue processing.
1789+
} break;
1790+
1791+
case EditorPlugin::AFTER_GUI_INPUT_STOP: {
1792+
return; // Stop processing.
1793+
} break;
1794+
1795+
case EditorPlugin::AFTER_GUI_INPUT_CUSTOM: {
17901796
after = EditorPlugin::AFTER_GUI_INPUT_CUSTOM;
1791-
}
1797+
} break;
17921798
}
17931799
}
17941800

@@ -3613,15 +3619,8 @@ static void draw_indicator_bar(Control &p_surface, real_t p_fill, const Ref<Text
36133619
}
36143620

36153621
void Node3DEditorViewport::_draw() {
3616-
EditorPluginList *over_plugin_list = EditorNode::get_singleton()->get_editor_plugins_over();
3617-
if (!over_plugin_list->is_empty()) {
3618-
over_plugin_list->forward_3d_draw_over_viewport(surface);
3619-
}
3620-
3621-
EditorPluginList *force_over_plugin_list = EditorNode::get_singleton()->get_editor_plugins_force_over();
3622-
if (!force_over_plugin_list->is_empty()) {
3623-
force_over_plugin_list->forward_3d_force_draw_over_viewport(surface);
3624-
}
3622+
EditorNode::get_singleton()->get_editor_plugins_over()->forward_3d_draw_over_viewport(surface);
3623+
EditorNode::get_singleton()->get_editor_plugins_force_over()->forward_3d_force_draw_over_viewport(surface);
36253624

36263625
if (surface->has_focus() || rotation_control->has_focus()) {
36273626
Size2 size = surface->get_size();

0 commit comments

Comments
 (0)