summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/path_editor_plugin.cpp4
-rw-r--r--editor/plugins/path_editor_plugin.h1
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp127
-rw-r--r--editor/plugins/spatial_editor_plugin.h5
4 files changed, 92 insertions, 45 deletions
diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp
index 6efa76ef80..88dc258c5f 100644
--- a/editor/plugins/path_editor_plugin.cpp
+++ b/editor/plugins/path_editor_plugin.cpp
@@ -638,6 +638,10 @@ String PathSpatialGizmoPlugin::get_name() const {
return "Path";
}
+int PathSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
PathSpatialGizmoPlugin::PathSpatialGizmoPlugin() {
Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8));
diff --git a/editor/plugins/path_editor_plugin.h b/editor/plugins/path_editor_plugin.h
index ce3d3799d4..5482d09377 100644
--- a/editor/plugins/path_editor_plugin.h
+++ b/editor/plugins/path_editor_plugin.h
@@ -62,6 +62,7 @@ protected:
public:
String get_name() const;
+ int get_priority() const;
PathSpatialGizmoPlugin();
};
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index ed11d26f25..776110b3b2 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -4117,10 +4117,10 @@ Dictionary SpatialEditor::get_state() const {
d["zfar"] = get_zfar();
Dictionary gizmos_status;
- for (int i = 0; i < gizmo_plugins.size(); i++) {
- if (!gizmo_plugins[i]->can_be_hidden()) continue;
+ for (int i = 0; i < gizmo_plugins_by_name.size(); i++) {
+ if (!gizmo_plugins_by_name[i]->can_be_hidden()) continue;
int state = gizmos_menu->get_item_state(gizmos_menu->get_item_index(i));
- String name = gizmo_plugins[i]->get_name();
+ String name = gizmo_plugins_by_name[i]->get_name();
gizmos_status[name] = state;
}
@@ -4205,32 +4205,19 @@ void SpatialEditor::set_state(const Dictionary &p_state) {
List<Variant> keys;
gizmos_status.get_key_list(&keys);
- for (int j = 0; j < gizmo_plugins.size(); ++j) {
- if (!gizmo_plugins[j]->can_be_hidden()) continue;
- int state = EditorSpatialGizmoPlugin::ON_TOP;
+ for (int j = 0; j < gizmo_plugins_by_name.size(); ++j) {
+ if (!gizmo_plugins_by_name[j]->can_be_hidden()) continue;
+ int state = EditorSpatialGizmoPlugin::VISIBLE;
for (int i = 0; i < keys.size(); i++) {
- if (gizmo_plugins.write[j]->get_name() == keys[i]) {
+ if (gizmo_plugins_by_name.write[j]->get_name() == keys[i]) {
state = gizmos_status[keys[i]];
+ break;
}
}
- const int idx = gizmos_menu->get_item_index(j);
-
- gizmos_menu->set_item_multistate(idx, state);
- gizmo_plugins.write[j]->set_state(state);
-
- switch (state) {
- case EditorSpatialGizmoPlugin::VISIBLE:
- gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_visible"));
- break;
- case EditorSpatialGizmoPlugin::ON_TOP:
- gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_xray"));
- break;
- case EditorSpatialGizmoPlugin::HIDDEN:
- gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_hidden"));
- break;
- }
+ gizmo_plugins_by_name.write[j]->set_state(state);
}
+ _update_gizmos_menu();
}
}
@@ -4344,7 +4331,7 @@ void SpatialEditor::_menu_gizmo_toggled(int p_option) {
break;
}
- gizmo_plugins.write[p_option]->set_state(state);
+ gizmo_plugins_by_name.write[p_option]->set_state(state);
update_all_gizmos();
}
@@ -4840,30 +4827,46 @@ void SpatialEditor::_init_indicators() {
_generate_selection_box();
}
-struct _GizmoPluginComparator {
-
- bool operator()(const Ref<EditorSpatialGizmoPlugin> &p_a, const Ref<EditorSpatialGizmoPlugin> &p_b) const {
- return p_a->get_name() < p_b->get_name();
- }
-};
-
void SpatialEditor::_update_gizmos_menu() {
gizmos_menu->clear();
- gizmo_plugins.sort_custom<_GizmoPluginComparator>();
- for (int i = 0; i < gizmo_plugins.size(); ++i) {
- if (!gizmo_plugins[i]->can_be_hidden()) continue;
- String plugin_name = gizmo_plugins[i]->get_name();
- gizmos_menu->add_multistate_item(TTR(plugin_name), 3, EditorSpatialGizmoPlugin::VISIBLE, i);
- gizmos_menu->set_item_icon(gizmos_menu->get_item_index(i), gizmos_menu->get_icon("visibility_visible"));
+ for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) {
+ if (!gizmo_plugins_by_name[i]->can_be_hidden()) continue;
+ String plugin_name = gizmo_plugins_by_name[i]->get_name();
+ const int plugin_state = gizmo_plugins_by_name[i]->get_state();
+ gizmos_menu->add_multistate_item(TTR(plugin_name), 3, plugin_state, i);
+ const int idx = gizmos_menu->get_item_index(i);
+ switch (plugin_state) {
+ case EditorSpatialGizmoPlugin::VISIBLE:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_visible"));
+ break;
+ case EditorSpatialGizmoPlugin::ON_TOP:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_xray"));
+ break;
+ case EditorSpatialGizmoPlugin::HIDDEN:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_hidden"));
+ break;
+ }
}
}
void SpatialEditor::_update_gizmos_menu_theme() {
- for (int i = 0; i < gizmo_plugins.size(); ++i) {
- if (!gizmo_plugins[i]->can_be_hidden()) continue;
- gizmos_menu->set_item_icon(gizmos_menu->get_item_index(i), gizmos_menu->get_icon("visibility_visible"));
+ for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) {
+ if (!gizmo_plugins_by_name[i]->can_be_hidden()) continue;
+ const int plugin_state = gizmo_plugins_by_name[i]->get_state();
+ const int idx = gizmos_menu->get_item_index(i);
+ switch (plugin_state) {
+ case EditorSpatialGizmoPlugin::VISIBLE:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_visible"));
+ break;
+ case EditorSpatialGizmoPlugin::ON_TOP:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_xray"));
+ break;
+ case EditorSpatialGizmoPlugin::HIDDEN:
+ gizmos_menu->set_item_icon(idx, gizmos_menu->get_icon("visibility_hidden"));
+ break;
+ }
}
}
@@ -5225,8 +5228,8 @@ void SpatialEditor::_request_gizmo(Object *p_obj) {
Ref<EditorSpatialGizmo> seg;
- for (int i = 0; i < gizmo_plugins.size(); ++i) {
- seg = gizmo_plugins.write[i]->get_gizmo(sp);
+ for (int i = 0; i < gizmo_plugins_by_priority.size(); ++i) {
+ seg = gizmo_plugins_by_priority.write[i]->get_gizmo(sp);
if (seg.is_valid()) {
sp->set_gizmo(seg);
@@ -5751,15 +5754,39 @@ void SpatialEditorPlugin::snap_cursor_to_plane(const Plane &p_plane) {
spatial_editor->snap_cursor_to_plane(p_plane);
}
+struct _GizmoPluginPriorityComparator {
+
+ bool operator()(const Ref<EditorSpatialGizmoPlugin> &p_a, const Ref<EditorSpatialGizmoPlugin> &p_b) const {
+ if (p_a->get_priority() == p_b->get_priority()) {
+ return p_a->get_name() < p_b->get_name();
+ }
+ return p_a->get_priority() > p_b->get_priority();
+ }
+};
+
+struct _GizmoPluginNameComparator {
+
+ bool operator()(const Ref<EditorSpatialGizmoPlugin> &p_a, const Ref<EditorSpatialGizmoPlugin> &p_b) const {
+ return p_a->get_name() < p_b->get_name();
+ }
+};
+
void SpatialEditor::add_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> p_plugin) {
ERR_FAIL_NULL(p_plugin.ptr());
- gizmo_plugins.push_back(p_plugin);
+
+ gizmo_plugins_by_priority.push_back(p_plugin);
+ gizmo_plugins_by_priority.sort_custom<_GizmoPluginPriorityComparator>();
+
+ gizmo_plugins_by_name.push_back(p_plugin);
+ gizmo_plugins_by_name.sort_custom<_GizmoPluginNameComparator>();
+
_update_gizmos_menu();
SpatialEditor::get_singleton()->update_all_gizmos();
}
void SpatialEditor::remove_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> p_plugin) {
- gizmo_plugins.erase(p_plugin);
+ gizmo_plugins_by_priority.erase(p_plugin);
+ gizmo_plugins_by_name.erase(p_plugin);
_update_gizmos_menu();
}
@@ -5912,6 +5939,13 @@ String EditorSpatialGizmoPlugin::get_name() const {
return TTR("Nameless gizmo");
}
+int EditorSpatialGizmoPlugin::get_priority() const {
+ if (get_script_instance() && get_script_instance()->has_method("get_priority")) {
+ return get_script_instance()->call("get_priority");
+ }
+ return 0;
+}
+
Ref<EditorSpatialGizmo> EditorSpatialGizmoPlugin::get_gizmo(Spatial *p_spatial) {
if (get_script_instance() && get_script_instance()->has_method("get_gizmo")) {
@@ -5944,6 +5978,7 @@ void EditorSpatialGizmoPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorSpatialGizmoPlugin::get_material); //, DEFVAL(Ref<EditorSpatialGizmo>()));
BIND_VMETHOD(MethodInfo(Variant::STRING, "get_name"));
+ BIND_VMETHOD(MethodInfo(Variant::STRING, "get_priority"));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_be_hidden"));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_selectable_when_hidden"));
@@ -6043,6 +6078,10 @@ void EditorSpatialGizmoPlugin::set_state(int p_state) {
}
}
+int EditorSpatialGizmoPlugin::get_state() const {
+ return current_state;
+}
+
void EditorSpatialGizmoPlugin::unregister_gizmo(EditorSpatialGizmo *p_gizmo) {
current_gizmos.erase(p_gizmo);
}
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 6256b8b055..4a9d34a7f7 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -639,7 +639,8 @@ private:
static SpatialEditor *singleton;
void _node_removed(Node *p_node);
- Vector<Ref<EditorSpatialGizmoPlugin> > gizmo_plugins;
+ Vector<Ref<EditorSpatialGizmoPlugin> > gizmo_plugins_by_priority;
+ Vector<Ref<EditorSpatialGizmoPlugin> > gizmo_plugins_by_name;
void _register_all_gizmos();
@@ -782,6 +783,7 @@ public:
Ref<SpatialMaterial> get_material(const String &p_name, const Ref<EditorSpatialGizmo> &p_gizmo = Ref<EditorSpatialGizmo>());
virtual String get_name() const;
+ virtual int get_priority() const;
virtual bool can_be_hidden() const;
virtual bool is_selectable_when_hidden() const;
@@ -794,6 +796,7 @@ public:
Ref<EditorSpatialGizmo> get_gizmo(Spatial *p_spatial);
void set_state(int p_state);
+ int get_state() const;
void unregister_gizmo(EditorSpatialGizmo *p_gizmo);
EditorSpatialGizmoPlugin();