diff options
-rw-r--r-- | editor/editor_node.cpp | 42 | ||||
-rw-r--r-- | editor/editor_node.h | 2 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 30 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.h | 16 |
4 files changed, 85 insertions, 5 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 6f14a4568a..2d867ed8c2 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -482,6 +482,10 @@ void EditorNode::_update_theme(bool p_skip_creation) { } } + if (CanvasItemEditor::get_singleton()->get_theme_preview() == CanvasItemEditor::THEME_PREVIEW_EDITOR) { + update_preview_themes(CanvasItemEditor::THEME_PREVIEW_EDITOR); + } + gui_base->add_theme_style_override("panel", theme->get_stylebox(SNAME("Background"), EditorStringName(EditorStyles))); main_vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, theme->get_constant(SNAME("window_border_margin"), EditorStringName(Editor))); main_vbox->add_theme_constant_override("separation", theme->get_constant(SNAME("top_bar_separation"), EditorStringName(Editor))); @@ -534,6 +538,36 @@ void EditorNode::_update_theme(bool p_skip_creation) { } } +void EditorNode::update_preview_themes(int p_mode) { + if (!scene_root->is_inside_tree()) { + return; // Too early. + } + + List<Ref<Theme>> preview_themes; + + switch (p_mode) { + case CanvasItemEditor::THEME_PREVIEW_PROJECT: + preview_themes.push_back(ThemeDB::get_singleton()->get_project_theme()); + break; + + case CanvasItemEditor::THEME_PREVIEW_EDITOR: + preview_themes.push_back(get_editor_theme()); + break; + + default: + break; + } + + preview_themes.push_back(ThemeDB::get_singleton()->get_default_theme()); + + ThemeContext *preview_context = ThemeDB::get_singleton()->get_theme_context(scene_root); + if (preview_context) { + preview_context->set_themes(preview_themes); + } else { + ThemeDB::get_singleton()->create_theme_context(scene_root, preview_themes); + } +} + void EditorNode::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PROCESS: { @@ -668,11 +702,9 @@ void EditorNode::_notification(int p_what) { _titlebar_resized(); - // Set up a theme context for the 2D preview viewport using the project theme. - List<Ref<Theme>> preview_themes; - preview_themes.push_back(ThemeDB::get_singleton()->get_project_theme()); - preview_themes.push_back(ThemeDB::get_singleton()->get_default_theme()); - ThemeDB::get_singleton()->create_theme_context(scene_root, preview_themes); + // Set up a theme context for the 2D preview viewport using the stored preview theme. + CanvasItemEditor::ThemePreviewMode theme_preview_mode = (CanvasItemEditor::ThemePreviewMode)(int)EditorSettings::get_singleton()->get_project_metadata("2d_editor", "theme_preview", CanvasItemEditor::THEME_PREVIEW_PROJECT); + update_preview_themes(theme_preview_mode); /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */ } break; diff --git a/editor/editor_node.h b/editor/editor_node.h index 1119f6b896..a83570b2ea 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -851,6 +851,8 @@ public: void stop_child_process(OS::ProcessID p_pid); Ref<Theme> get_editor_theme() const { return theme; } + void update_preview_themes(int p_mode); + Ref<Script> get_object_custom_type_base(const Object *p_object) const; StringName get_object_custom_type_name(const Object *p_object) const; Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "Object"); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index b2f4e43018..703cd7ef81 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1034,6 +1034,22 @@ void CanvasItemEditor::_on_grid_menu_id_pressed(int p_id) { viewport->queue_redraw(); } +void CanvasItemEditor::_switch_theme_preview(int p_mode) { + view_menu->get_popup()->hide(); + + if (theme_preview == p_mode) { + return; + } + theme_preview = (ThemePreviewMode)p_mode; + EditorSettings::get_singleton()->set_project_metadata("2d_editor", "theme_preview", theme_preview); + + for (int i = 0; i < THEME_PREVIEW_MAX; i++) { + theme_menu->set_item_checked(i, i == theme_preview); + } + + EditorNode::get_singleton()->update_preview_themes(theme_preview); +} + bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_event) { EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); Ref<InputEventMouseButton> b = p_event; @@ -5322,6 +5338,20 @@ CanvasItemEditor::CanvasItemEditor() { p->add_separator(); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale")), PREVIEW_CANVAS_SCALE); + theme_menu = memnew(PopupMenu); + theme_menu->connect("id_pressed", callable_mp(this, &CanvasItemEditor::_switch_theme_preview)); + theme_menu->set_name("ThemeMenu"); + theme_menu->add_radio_check_item(TTR("Project theme"), THEME_PREVIEW_PROJECT); + theme_menu->add_radio_check_item(TTR("Editor theme"), THEME_PREVIEW_EDITOR); + theme_menu->add_radio_check_item(TTR("Default theme"), THEME_PREVIEW_DEFAULT); + p->add_child(theme_menu); + p->add_submenu_item(TTR("Preview Theme"), "ThemeMenu"); + + theme_preview = (ThemePreviewMode)(int)EditorSettings::get_singleton()->get_project_metadata("2d_editor", "theme_preview", THEME_PREVIEW_PROJECT); + for (int i = 0; i < THEME_PREVIEW_MAX; i++) { + theme_menu->set_item_checked(i, i == theme_preview); + } + main_menu_hbox->add_child(memnew(VSeparator)); // Contextual toolbars. diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 74f150fd65..674f38c8c0 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -325,6 +325,7 @@ private: Button *override_camera_button = nullptr; MenuButton *view_menu = nullptr; PopupMenu *grid_menu = nullptr; + PopupMenu *theme_menu = nullptr; HBoxContainer *animation_hb = nullptr; MenuButton *animation_menu = nullptr; @@ -404,6 +405,19 @@ private: void _prepare_grid_menu(); void _on_grid_menu_id_pressed(int p_id); +public: + enum ThemePreviewMode { + THEME_PREVIEW_PROJECT, + THEME_PREVIEW_EDITOR, + THEME_PREVIEW_DEFAULT, + + THEME_PREVIEW_MAX // The number of options for enumerating. + }; + +private: + ThemePreviewMode theme_preview = THEME_PREVIEW_PROJECT; + void _switch_theme_preview(int p_mode); + List<CanvasItem *> _get_edited_canvas_items(bool retrieve_locked = false, bool remove_canvas_item_if_parent_in_selection = true) const; Rect2 _get_encompassing_rect_from_list(List<CanvasItem *> p_list); void _expand_encompassing_rect_using_children(Rect2 &r_rect, const Node *p_node, bool &r_first, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D(), bool include_locked_nodes = true); @@ -558,6 +572,8 @@ public: virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override; + ThemePreviewMode get_theme_preview() const { return theme_preview; } + EditorSelection *editor_selection = nullptr; CanvasItemEditor(); |