Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Add EditorIconManager

kobewid1a4c89c7614
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 9160fe43185..38c5b6a2dff 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -84,6 +84,7 @@
#include "editor/gui/editor_about.h"
#include "editor/gui/editor_bottom_panel.h"
#include "editor/gui/editor_file_dialog.h"
+#include "editor/gui/editor_icon_manager.h"
#include "editor/gui/editor_quick_open_dialog.h"
#include "editor/gui/editor_title_bar.h"
#include "editor/gui/editor_toaster.h"
@@ -8703,6 +8704,9 @@ EditorNode::EditorNode() {
gui_base = memnew(Panel);
add_child(gui_base);
+ icon_manager = memnew(EditorIconManager);
+ gui_base->add_child(icon_manager);
+
// Take up all screen.
gui_base->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
gui_base->set_anchor(SIDE_RIGHT, Control::ANCHOR_END);
diff --git a/editor/editor_node.h b/editor/editor_node.h
index f34bdd7ecd0..d63a416a551 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -79,6 +79,7 @@ class EditorExport;
class EditorExportPreset;
class EditorFeatureProfileManager;
class EditorFileDialog;
+class EditorIconManager;
class EditorFolding;
class EditorLayoutsDialog;
class EditorLog;
@@ -359,6 +360,7 @@ private:
AcceptDialog *execute_output_dialog = nullptr;
Ref<Theme> theme;
+ EditorIconManager *icon_manager = nullptr;
bool follow_system_theme = false;
bool use_system_accent_color = false;
diff --git a/editor/gui/editor_icon_manager.cpp b/editor/gui/editor_icon_manager.cpp
new file mode 100644
index 00000000000..692bfc0ae82
--- /dev/null
+++ b/editor/gui/editor_icon_manager.cpp
@@ -0,0 +1,58 @@
+/**************************************************************************/
+/* editor_icon_manager.cpp */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#include "editor_icon_manager.h"
+
+#include "editor/editor_node.h"
+#include "scene/resources/atlas_texture.h"
+
+void EditorIconManager::_notification(int p_what) {
+ if (p_what == NOTIFICATION_THEME_CHANGED) {
+ for (KeyValue<StringName, Ref<AtlasTexture>> &icon : icons) {
+ icon.value->set_atlas(get_editor_theme_icon(icon.key));
+ }
+ }
+}
+
+EditorIconManager::EditorIconManager() {
+ singleton = this;
+}
+
+Ref<Texture2D> EditorIconManager::get_icon(const StringName &p_icon_name) {
+ Ref<AtlasTexture> *existing = singleton->icons.getptr(p_icon_name);
+ if (existing) {
+ return *existing;
+ }
+ Ref<AtlasTexture> icon;
+ icon.instantiate();
+ icon->set_atlas(singleton->get_editor_theme_icon(p_icon_name));
+ singleton->icons[p_icon_name] = icon;
+ return icon;
+}
diff --git a/editor/gui/editor_icon_manager.h b/editor/gui/editor_icon_manager.h
new file mode 100644
index 00000000000..1ab800daba2
--- /dev/null
+++ b/editor/gui/editor_icon_manager.h
@@ -0,0 +1,52 @@
+/**************************************************************************/
+/* editor_icon_manager.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#pragma once
+
+#include "scene/gui/control.h"
+
+class AtlasTexture;
+class Texture2D;
+
+class EditorIconManager : public Control {
+ GDCLASS(EditorIconManager, Control);
+
+ HashMap<StringName, Ref<AtlasTexture>> icons;
+
+ inline static EditorIconManager *singleton = nullptr;
+
+protected:
+ void _notification(int p_what);
+
+public:
+ EditorIconManager();
+
+ static Ref<Texture2D> get_icon(const StringName &p_icon_name);
+};
diff --git a/editor/inspector/editor_properties_array_dict.cpp b/editor/inspector/editor_properties_array_dict.cpp
index 04d0e0e97b8..577f0b69f7a 100644
--- a/editor/inspector/editor_properties_array_dict.cpp
+++ b/editor/inspector/editor_properties_array_dict.cpp
@@ -39,6 +39,7 @@
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/file_system/editor_file_system.h"
+#include "editor/gui/editor_icon_manager.h"
#include "editor/gui/editor_spin_slider.h"
#include "editor/gui/editor_variant_type_selectors.h"
#include "editor/inspector/editor_properties.h"
@@ -333,7 +334,7 @@ void EditorPropertyArray::_create_new_property_slot() {
Button *reorder_button = memnew(Button);
reorder_button->set_accessibility_name(TTRC("Reorder"));
- reorder_button->set_button_icon(get_editor_theme_icon(SNAME("TripleBar")));
+ reorder_button->set_button_icon(EditorIconManager::get_icon(SNAME("TripleBar")));
reorder_button->set_default_cursor_shape(Control::CURSOR_MOVE);
reorder_button->set_disabled(is_read_only());
reorder_button->set_theme_type_variation(SNAME("EditorInspectorFlatButton"));
@@ -350,14 +351,14 @@ void EditorPropertyArray::_create_new_property_slot() {
if (is_untyped_array) {
edit_btn = memnew(Button);
edit_btn->set_accessibility_name(TTRC("Edit"));
- edit_btn->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
+ edit_btn->set_button_icon(EditorIconManager::get_icon(SNAME("Edit")));
edit_btn->set_disabled(is_read_only());
edit_btn->set_theme_type_variation(SNAME("EditorInspectorFlatButton"));
edit_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_change_type).bind(edit_btn, idx));
} else {
remove_btn = memnew(Button);
remove_btn->set_accessibility_name(TTRC("Remove"));
- remove_btn->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
+ remove_btn->set_button_icon(EditorIconManager::get_icon(SNAME("Remove")));
remove_btn->set_disabled(is_read_only());
remove_btn->set_theme_type_variation(SNAME("EditorInspectorFlatButton"));
remove_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_remove_pressed).bind(idx));
@@ -402,7 +403,7 @@ void EditorPropertyArray::update_property() {
if (!array.is_array()) {
if (preview_value) {
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
- edit->set_button_icon(get_editor_theme_icon(SNAME("Nil")));
+ edit->set_button_icon(EditorIconManager::get_icon(SNAME("Nil")));
edit->set_text(array_type_name);
} else {
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_CENTER);
@@ -439,7 +440,7 @@ void EditorPropertyArray::update_property() {
edit->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
- edit->set_button_icon(get_editor_theme_icon(array_type_name));
+ edit->set_button_icon(EditorIconManager::get_icon(array_type_name));
edit->set_text(vformat("%s%s", array_sub_type_name, ctr_str));
edit->set_tooltip_text(vformat(TTR("%s%s (size %d)"), array_type_name, array_sub_type_name, size));
} else {
@@ -798,17 +799,6 @@ Node *EditorPropertyArray::get_base_node() {
void EditorPropertyArray::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
- for (Slot &slot : slots) {
- if (slot.edit_button) {
- slot.edit_button->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
- }
- if (slot.reorder_button) {
- slot.reorder_button->set_button_icon(get_editor_theme_icon(SNAME("TripleBar")));
- }
- if (slot.remove_button) {
- slot.remove_button->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
- }
- }
_update_slots_size();
} break;
case NOTIFICATION_DRAG_BEGIN: {
@@ -1127,14 +1117,14 @@ void EditorPropertyDictionary::_create_new_property_slot(int p_idx) {
if (is_untyped_dict) {
edit_btn = memnew(Button);
edit_btn->set_accessibility_name(TTRC("Edit"));
- edit_btn->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
+ edit_btn->set_button_icon(EditorIconManager::get_icon(SNAME("Edit")));
edit_btn->set_disabled(is_read_only());
edit_btn->set_theme_type_variation(SNAME("EditorInspectorFlatButton"));
edit_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyDictionary::_change_type).bind(edit_btn, slots.size()));
} else if (p_idx >= 0) {
remove_btn = memnew(Button);
remove_btn->set_accessibility_name(TTRC("Remove"));
- remove_btn->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
+ remove_btn->set_button_icon(EditorIconManager::get_icon(SNAME("Remove")));
remove_btn->set_disabled(is_read_only());
remove_btn->set_theme_type_variation(SNAME("EditorInspectorFlatButton"));
remove_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyDictionary::_remove_pressed).bind(slots.size()));
@@ -1285,7 +1275,7 @@ void EditorPropertyDictionary::update_property() {
if (updated_val.get_type() != Variant::DICTIONARY) {
if (preview_value) {
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
- edit->set_button_icon(get_editor_theme_icon(SNAME("Nil")));
+ edit->set_button_icon(EditorIconManager::get_icon(SNAME("Nil")));
edit->set_text(dict_type_name);
} else {
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_CENTER);
@@ -1318,7 +1308,7 @@ void EditorPropertyDictionary::update_property() {
edit->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
edit->set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT);
- edit->set_button_icon(get_editor_theme_icon(dict_type_name));
+ edit->set_button_icon(EditorIconManager::get_icon(dict_type_name));
edit->set_text(vformat("%s%s", dict_sub_type_name, ctr_str));
edit->set_tooltip_text(vformat(TTR("%s%s (size %d)"), dict_type_name, dict_sub_type_name, dict.size()));
} else {
@@ -1539,15 +1529,6 @@ void EditorPropertyDictionary::_resource_selected(const String &p_path, Ref<Reso
void EditorPropertyDictionary::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
- for (Slot &slot : slots) {
- if (slot.edit_button) {
- slot.edit_button->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
- }
- if (slot.remove_button) {
- slot.remove_button->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
- }
- }
-
if (button_add_item) {
add_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("DictionaryAddItem")));
}
@@ -1750,7 +1731,7 @@ void EditorPropertyLocalizableString::update_property() {
prop->set_h_size_flags(SIZE_EXPAND_FILL);
Button *edit_btn = memnew(Button);
edit_btn->set_accessibility_name(TTRC("Remove Translation"));
- edit_btn->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
+ edit_btn->set_button_icon(EditorIconManager::get_icon(SNAME("Remove")));
hbox->add_child(edit_btn);
edit_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyLocalizableString::_remove_item).bind(edit_btn, remove_index));