From 98acdf8270bb40a2da095bbbea4aa81766834689 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 20 Aug 2022 17:20:34 +0200 Subject: [PATCH] Now full screen editor plugins have the ability to hide their tab button in the top bar. --- doc/classes/EditorInterface.xml | 10 +++++- editor/editor_node.cpp | 38 ++++++++++++++------- editor/editor_node.h | 1 + editor/editor_plugin.cpp | 59 ++++++++++++++++++--------------- editor/editor_plugin.h | 11 +++--- 5 files changed, 74 insertions(+), 45 deletions(-) diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml index ea2798205..b30e197b9 100644 --- a/doc/classes/EditorInterface.xml +++ b/doc/classes/EditorInterface.xml @@ -219,7 +219,15 @@ - Sets the editor's current main screen to the one specified in [code]name[/code]. [code]name[/code] must match the text of the tab in question exactly ([code]2D[/code], [code]3D[/code], [code]Script[/code], [code]AssetLib[/code]). + Sets the editor's current main screen to the one specified in [code]name[/code]. It will also make the editor's tab button at the top to be visible if it weren't. [code]name[/code] must match the text of the tab in question exactly like: [code]2D[/code], [code]3D[/code], [code]Script[/code]. + + + + + + + + Sets whether the specified main screen's button is visible or not. Will not change the main screen. [code]name[/code] must match the text of the tab in question exactly like: [code]2D[/code], [code]3D[/code], [code]Script[/code], [code]AssetLib[/code]. diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 902302b0b..6ce446308 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -32,34 +32,35 @@ #include -#include "core/variant/array.h" -#include "core/object/class_db.h" -#include "core/math/color.h" #include "core/config/engine.h" +#include "core/config/project_settings.h" +#include "core/containers/pool_vector.h" #include "core/error/error_macros.h" -#include "core/io/image.h" +#include "core/input/input.h" +#include "core/input/input_event.h" +#include "core/input/shortcut.h" #include "core/io/config_file.h" +#include "core/io/image.h" #include "core/io/image_loader.h" #include "core/io/resource_importer.h" #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" +#include "core/math/color.h" #include "core/math/math_defs.h" #include "core/math/vector2.h" +#include "core/object/class_db.h" #include "core/object/object_id.h" +#include "core/object/script_language.h" +#include "core/object/undo_redo.h" #include "core/os/dir_access.h" #include "core/os/file_access.h" -#include "core/input/input.h" -#include "core/input/input_event.h" #include "core/os/keyboard.h" #include "core/os/main_loop.h" #include "core/os/memory.h" #include "core/os/os.h" -#include "core/containers/pool_vector.h" #include "core/string/print_string.h" -#include "core/config/project_settings.h" -#include "core/object/script_language.h" #include "core/string/translation.h" -#include "core/object/undo_redo.h" +#include "core/variant/array.h" #include "core/version.h" #include "core/version_generated.gen.h" #include "editor/animation_track_editor.h" @@ -177,7 +178,6 @@ #include "scene/gui/popup_menu.h" #include "scene/gui/rich_text_label.h" #include "scene/gui/scroll_bar.h" -#include "core/input/shortcut.h" #include "scene/gui/split_container.h" #include "scene/gui/tab_container.h" #include "scene/gui/tabs.h" @@ -3071,6 +3071,7 @@ void EditorNode::select_editor_by_name(const String &p_name) { for (int i = 0; i < main_editor_buttons.size(); i++) { if (main_editor_buttons[i]->get_text() == p_name) { + main_editor_buttons[i]->set_visible(true); _editor_select(i); return; } @@ -3079,6 +3080,19 @@ void EditorNode::select_editor_by_name(const String &p_name) { ERR_FAIL_MSG("The editor name '" + p_name + "' was not found."); } +void EditorNode::editor_set_visible_by_name(const String &p_name, const bool p_visible) { + ERR_FAIL_COND(p_name == ""); + + for (int i = 0; i < main_editor_buttons.size(); i++) { + if (main_editor_buttons[i]->get_text() == p_name) { + main_editor_buttons[i]->set_visible(p_visible); + return; + } + } + + ERR_FAIL_MSG("The editor name '" + p_name + "' was not found."); +} + void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed) { if (p_editor->has_main_screen()) { ToolButton *tb = memnew(ToolButton); @@ -7036,7 +7050,7 @@ EditorPlugin::AfterGUIInput EditorPluginList::forward_spatial_gui_input(Camera * if (current_after == EditorPlugin::AFTER_GUI_INPUT_STOP) { after = EditorPlugin::AFTER_GUI_INPUT_STOP; } - + if (after != EditorPlugin::AFTER_GUI_INPUT_STOP && current_after == EditorPlugin::AFTER_GUI_INPUT_NO_DESELECT) { after = EditorPlugin::AFTER_GUI_INPUT_NO_DESELECT; } diff --git a/editor/editor_node.h b/editor/editor_node.h index e3e5a3225..3bf5f6f60 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -230,6 +230,7 @@ public: void hide_top_editors(); void select_editor_by_name(const String &p_name); + void editor_set_visible_by_name(const String &p_name, const bool p_visible); void open_request(const String &p_path); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index b89fb5a2d..5d9bb7e87 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -30,50 +30,50 @@ #include "editor_plugin.h" +#include "core/containers/pool_vector.h" +#include "core/containers/rid.h" +#include "core/containers/rid_handle.h" +#include "core/input/input_event.h" +#include "core/io/image.h" +#include "core/io/resource_importer.h" +#include "core/math/aabb.h" +#include "core/math/basis.h" +#include "core/math/color.h" +#include "core/math/math_defs.h" +#include "core/math/transform.h" +#include "core/math/vector3.h" +#include "core/object/class_db.h" +#include "core/object/resource.h" +#include "core/object/script_language.h" +#include "core/typedefs.h" +#include "editor/editor_autoload_settings.h" +#include "editor/editor_data.h" #include "editor/editor_export.h" +#include "editor/editor_file_system.h" +#include "editor/editor_inspector.h" #include "editor/editor_node.h" +#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/filesystem_dock.h" +#include "editor/import/editor_import_plugin.h" +#include "editor/import/resource_importer_scene.h" +#include "editor/plugins/script_editor_plugin.h" #include "editor/project_settings_editor.h" +#include "editor/script_create_dialog.h" #include "editor_resource_preview.h" #include "main/main.h" #include "plugins/canvas_item_editor_plugin.h" #include "plugins/spatial_editor_plugin.h" #include "scene/3d/camera.h" -#include "scene/gui/popup_menu.h" -#include "servers/rendering_server.h" -#include "core/object/class_db.h" -#include "core/math/color.h" -#include "core/io/image.h" -#include "core/io/resource_importer.h" -#include "core/math/aabb.h" -#include "core/math/basis.h" -#include "core/math/math_defs.h" -#include "core/math/transform.h" -#include "core/math/vector3.h" -#include "core/input/input_event.h" -#include "core/containers/pool_vector.h" -#include "core/object/resource.h" -#include "core/containers/rid.h" -#include "core/containers/rid_handle.h" -#include "core/object/script_language.h" -#include "core/typedefs.h" -#include "editor/editor_autoload_settings.h" -#include "editor/editor_data.h" -#include "editor/editor_file_system.h" -#include "editor/editor_inspector.h" -#include "editor/editor_scale.h" -#include "editor/import/editor_import_plugin.h" -#include "editor/import/resource_importer_scene.h" -#include "editor/plugins/script_editor_plugin.h" #include "scene/gui/box_container.h" #include "scene/gui/container.h" #include "scene/gui/control.h" +#include "scene/gui/popup_menu.h" #include "scene/gui/split_container.h" #include "scene/gui/tab_container.h" #include "scene/resources/mesh.h" #include "scene/resources/texture.h" -#include "editor/script_create_dialog.h" +#include "servers/rendering_server.h" class ConfigFile; class ScriptCreateDialog; @@ -189,6 +189,10 @@ void EditorInterface::set_main_screen_editor(const String &p_name) { EditorNode::get_singleton()->select_editor_by_name(p_name); } +void EditorInterface::set_main_screen_editor_tab_button_visible(const String &p_name, const bool p_visible) { + EditorNode::get_singleton()->editor_set_visible_by_name(p_name, p_visible); +} + Control *EditorInterface::get_editor_viewport() { return EditorNode::get_singleton()->get_viewport(); } @@ -387,6 +391,7 @@ void EditorInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("save_scene_as", "path", "with_preview"), &EditorInterface::save_scene_as, DEFVAL(true)); ClassDB::bind_method(D_METHOD("set_main_screen_editor", "name"), &EditorInterface::set_main_screen_editor); + ClassDB::bind_method(D_METHOD("set_main_screen_editor_tab_button_visible", "name", "visible"), &EditorInterface::set_main_screen_editor_tab_button_visible); ClassDB::bind_method(D_METHOD("set_distraction_free_mode", "enter"), &EditorInterface::set_distraction_free_mode); ClassDB::bind_method(D_METHOD("is_distraction_free_mode_enabled"), &EditorInterface::is_distraction_free_mode_enabled); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 210fdcaf1..5e5c29ca6 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -36,20 +36,20 @@ #include "scene/resources/texture.h" -#include "core/variant/array.h" -#include "core/variant/dictionary.h" +#include "core/containers/list.h" +#include "core/containers/vector.h" #include "core/error/error_list.h" #include "core/error/error_macros.h" #include "core/io/config_file.h" -#include "core/containers/list.h" #include "core/object/method_bind.h" #include "core/object/object.h" -#include "core/os/memory.h" #include "core/object/reference.h" #include "core/object/undo_redo.h" +#include "core/os/memory.h" #include "core/string/ustring.h" +#include "core/variant/array.h" +#include "core/variant/dictionary.h" #include "core/variant/variant.h" -#include "core/containers/vector.h" class EditorNode; class Spatial; @@ -138,6 +138,7 @@ public: Vector> make_mesh_previews(const Vector> &p_meshes, Vector *p_transforms, int p_preview_size); void set_main_screen_editor(const String &p_name); + void set_main_screen_editor_tab_button_visible(const String &p_name, const bool p_visible); void set_distraction_free_mode(bool p_enter); bool is_distraction_free_mode_enabled() const;