diff options
Diffstat (limited to 'editor/plugins/theme_editor_plugin.cpp')
| -rw-r--r-- | editor/plugins/theme_editor_plugin.cpp | 114 |
1 files changed, 99 insertions, 15 deletions
diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 821d8151a4..9ba5f2faf1 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -31,12 +31,14 @@ #include "theme_editor_plugin.h" #include "core/os/keyboard.h" +#include "editor/editor_help.h" #include "editor/editor_node.h" #include "editor/editor_resource_picker.h" #include "editor/editor_scale.h" #include "editor/editor_string_names.h" #include "editor/editor_undo_redo_manager.h" #include "editor/gui/editor_file_dialog.h" +#include "editor/inspector_dock.h" #include "editor/progress_dialog.h" #include "scene/gui/check_button.h" #include "scene/gui/color_picker.h" @@ -2259,6 +2261,10 @@ ThemeTypeDialog::ThemeTypeDialog() { /////////////////////// +Control *ThemeItemLabel::make_custom_tooltip(const String &p_text) const { + return memnew(EditorHelpTooltip(p_text)); +} + VBoxContainer *ThemeTypeEditor::_create_item_list(Theme::DataType p_data_type) { VBoxContainer *items_tab = memnew(VBoxContainer); items_tab->set_custom_minimum_size(Size2(0, 160) * EDSCALE); @@ -2413,11 +2419,13 @@ HBoxContainer *ThemeTypeEditor::_create_property_control(Theme::DataType p_data_ item_name_container->set_stretch_ratio(2.0); item_control->add_child(item_name_container); - Label *item_name = memnew(Label); + Label *item_name = memnew(ThemeItemLabel); item_name->set_h_size_flags(SIZE_EXPAND_FILL); item_name->set_clip_text(true); item_name->set_text(p_item_name); - item_name->set_tooltip_text(p_item_name); + // `|` separators used in `EditorHelpTooltip` for formatting. + item_name->set_tooltip_text("theme_item|" + edited_type + "|" + p_item_name + "|"); + item_name->set_mouse_filter(Control::MOUSE_FILTER_STOP); item_name_container->add_child(item_name); if (p_editable) { @@ -2477,7 +2485,6 @@ void ThemeTypeEditor::_add_focusable(Control *p_control) { void ThemeTypeEditor::_update_type_items() { bool show_default = show_default_items_button->is_pressed(); - List<StringName> names; focusables.clear(); @@ -3528,6 +3535,16 @@ void ThemeEditor::_theme_edit_button_cbk() { theme_edit_dialog->popup_centered(Size2(850, 700) * EDSCALE); } +void ThemeEditor::_theme_close_button_cbk() { + plugin->make_visible(false); // Enables auto hide. + if (theme.is_valid() && InspectorDock::get_inspector_singleton()->get_edited_object() == theme.ptr()) { + EditorNode::get_singleton()->push_item(nullptr); + } else { + theme = Ref<Theme>(); + EditorNode::get_singleton()->hide_unused_editors(plugin); + } +} + void ThemeEditor::_add_preview_button_cbk() { preview_scene_dialog->popup_file_dialog(); } @@ -3645,6 +3662,12 @@ ThemeEditor::ThemeEditor() { theme_save_as_button->connect("pressed", callable_mp(this, &ThemeEditor::_theme_save_button_cbk).bind(true)); top_menu->add_child(theme_save_as_button); + Button *theme_close_button = memnew(Button); + theme_close_button->set_text(TTR("Close")); + theme_close_button->set_flat(true); + theme_close_button->connect("pressed", callable_mp(this, &ThemeEditor::_theme_close_button_cbk)); + top_menu->add_child(theme_close_button); + top_menu->add_child(memnew(VSeparator)); Button *theme_edit_button = memnew(Button); @@ -3711,20 +3734,12 @@ ThemeEditor::ThemeEditor() { /////////////////////// -void ThemeEditorPlugin::edit(Object *p_node) { - if (Object::cast_to<Theme>(p_node)) { - theme_editor->edit(Object::cast_to<Theme>(p_node)); - } else { - // We intentionally keep a reference to the last used theme to work around - // the the editor being hidden while base resources are edited. Uncomment - // the following line again and remove this comment once that bug has been - // fixed (scheduled for Godot 4.1 in PR 73098): - // theme_editor->edit(Ref<Theme>()); - } +void ThemeEditorPlugin::edit(Object *p_object) { + theme_editor->edit(Ref<Theme>(p_object)); } -bool ThemeEditorPlugin::handles(Object *p_node) const { - return Object::cast_to<Theme>(p_node) != nullptr; +bool ThemeEditorPlugin::handles(Object *p_object) const { + return Object::cast_to<Theme>(p_object) != nullptr; } void ThemeEditorPlugin::make_visible(bool p_visible) { @@ -3740,8 +3755,77 @@ void ThemeEditorPlugin::make_visible(bool p_visible) { } } +bool ThemeEditorPlugin::can_auto_hide() const { + Ref<Theme> edited_theme = theme_editor->theme; + if (edited_theme.is_null()) { + return true; + } + + Ref<Resource> edited_resource = Ref<Resource>(InspectorDock::get_inspector_singleton()->get_next_edited_object()); + if (edited_resource.is_null()) { + return true; + } + + // Don't hide if edited resource used by this theme. + Ref<StyleBox> sbox = edited_resource; + if (sbox.is_valid()) { + List<StringName> type_list; + edited_theme->get_stylebox_type_list(&type_list); + + for (const StringName &E : type_list) { + List<StringName> list; + edited_theme->get_stylebox_list(E, &list); + + for (const StringName &F : list) { + if (edited_theme->get_stylebox(F, E) == sbox) { + return false; + } + } + } + return true; + } + + Ref<Texture2D> tex = edited_resource; + if (tex.is_valid()) { + List<StringName> type_list; + edited_theme->get_icon_type_list(&type_list); + + for (const StringName &E : type_list) { + List<StringName> list; + edited_theme->get_icon_list(E, &list); + + for (const StringName &F : list) { + if (edited_theme->get_icon(F, E) == tex) { + return false; + } + } + } + return true; + } + + Ref<Font> fnt = edited_resource; + if (fnt.is_valid()) { + List<StringName> type_list; + edited_theme->get_font_type_list(&type_list); + + for (const StringName &E : type_list) { + List<StringName> list; + edited_theme->get_font_list(E, &list); + + for (const StringName &F : list) { + if (edited_theme->get_font(F, E) == fnt) { + return false; + } + } + } + return true; + } + return true; +} + ThemeEditorPlugin::ThemeEditorPlugin() { theme_editor = memnew(ThemeEditor); + theme_editor->plugin = this; theme_editor->set_custom_minimum_size(Size2(0, 200) * EDSCALE); button = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Theme"), theme_editor); |
