Skip to content

armgit / godot

Public Imported from GitHub
0

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

Change main screen plugins into docks

kobewi0ceb0a515d9d
diff --git a/doc/classes/EditorDock.xml b/doc/classes/EditorDock.xml
index cffb3b3bb5e..888109d34a7 100644
--- a/doc/classes/EditorDock.xml
+++ b/doc/classes/EditorDock.xml
@@ -155,8 +155,11 @@
<constant name="DOCK_LAYOUT_FLOATING" value="4" enum="DockLayout" is_bitfield="true">
Allows making the dock floating (opened as a separate window).
</constant>
+ <constant name="DOCK_LAYOUT_MAIN_SCREEN" value="8" enum="DockLayout" is_bitfield="true">
+ Allows using the dock as main screen.
+ </constant>
<constant name="DOCK_LAYOUT_ALL" value="7" enum="DockLayout" is_bitfield="true">
- Allows placing the dock in all available slots.
+ Allows placing the dock in all available slots, except in main screen.
</constant>
<constant name="DOCK_SLOT_NONE" value="-1" enum="DockSlot">
The dock is closed.
@@ -194,7 +197,10 @@
<constant name="DOCK_SLOT_BOTTOM_R" value="10" enum="DockSlot">
Dock slot at the bottom, below bottom panel, on the right side.
</constant>
- <constant name="DOCK_SLOT_MAX" value="11" enum="DockSlot">
+ <constant name="DOCK_SLOT_MAIN_SCREEN" value="11" enum="DockSlot">
+ The editor's main screen.
+ </constant>
+ <constant name="DOCK_SLOT_MAX" value="12" enum="DockSlot">
Represents the size of the [enum DockSlot] enum.
</constant>
</constants>
diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml
index 656f81b80c8..3d81ef076af 100644
--- a/doc/classes/EditorInterface.xml
+++ b/doc/classes/EditorInterface.xml
@@ -90,6 +90,13 @@
Returns the current path being viewed in the [FileSystemDock].
</description>
</method>
+ <method name="get_dock_by_name">
+ <return type="EditorDock" />
+ <param index="0" name="name" type="String" />
+ <description>
+ Returns an [EditorDock] with the specified [param name]. [param name] must match the original (untranslated) title of the tab in question exactly (e.g., [code]2D[/code], [code]Scene[/code], [code]Audio[/code]). Returns [code]null[/code] if the dock was not found.
+ </description>
+ </method>
<method name="get_edited_scene_root" qualifiers="const">
<return type="Node" />
<description>
@@ -102,12 +109,10 @@
Returns the language currently used for the editor interface.
</description>
</method>
- <method name="get_editor_main_screen" qualifiers="const">
+ <method name="get_editor_main_screen" qualifiers="const" deprecated="This method no longer returns the main screen. Only used for legacy main screen plugins.">
<return type="VBoxContainer" />
<description>
- Returns the editor control responsible for main screen plugins and tools. Use it with plugins that implement [method EditorPlugin._has_main_screen].
- [b]Note:[/b] This node is a [VBoxContainer], which means that if you add a [Control] child to it, you need to set the child's [member Control.size_flags_vertical] to [constant Control.SIZE_EXPAND_FILL] to make it use the full available space.
- [b]Warning:[/b] Removing and freeing this node will render a part of the editor useless and may cause a crash.
+ Returns the editor control responsible for legacy main screen plugins and tools.
</description>
</method>
<method name="get_editor_paths" qualifiers="const">
@@ -509,7 +514,7 @@
[b]Note:[/b] The feature profile that gets activated must be located in the [code]feature_profiles[/code] directory, as a file with the [code].profile[/code] extension. If a profile could not be found, an error occurs. The editor configuration folder can be found by using [method EditorPaths.get_config_dir].
</description>
</method>
- <method name="set_main_screen_editor">
+ <method name="set_main_screen_editor" deprecated="Use [method get_dock_by_name] with [method EditorDock.make_visible] instead.">
<return type="void" />
<param index="0" name="name" type="String" />
<description>
diff --git a/doc/classes/EditorPlugin.xml b/doc/classes/EditorPlugin.xml
index 54f9bc48baf..6ca1aabd767 100644
--- a/doc/classes/EditorPlugin.xml
+++ b/doc/classes/EditorPlugin.xml
@@ -230,7 +230,7 @@
This is for editors that edit script-based objects. You can return a list of breakpoints in the format ([code]script:line[/code]), for example: [code]res://path_to_script.gd:25[/code].
</description>
</method>
- <method name="_get_plugin_icon" qualifiers="virtual const">
+ <method name="_get_plugin_icon" qualifiers="virtual const" deprecated="Use [member EditorDock.dock_icon] of a main screen dock.">
<return type="Texture2D" />
<description>
Override this method in your plugin to return a [Texture2D] in order to give it an icon.
@@ -261,6 +261,7 @@
<description>
Override this method in your plugin to provide the name of the plugin when displayed in the Godot editor.
For main screen plugins, this appears at the top of the screen, to the right of the "2D", "3D", "Script", "Game", and "Asset Store" buttons.
+ [b]Note:[/b] Main screen plugins should instead use [member EditorDock.title] of a main screen dock.
</description>
</method>
<method name="_get_state" qualifiers="virtual const">
@@ -326,32 +327,11 @@
[b]Note:[/b] Each plugin should handle only one type of objects at a time. If a plugin handles more types of objects and they are edited at the same time, it will result in errors.
</description>
</method>
- <method name="_has_main_screen" qualifiers="virtual const">
+ <method name="_has_main_screen" qualifiers="virtual const" deprecated="Use [method add_dock] instead, with [member EditorDock.default_slot] set to [constant EditorDock.DOCK_SLOT_MAIN_SCREEN].">
<return type="bool" />
<description>
- Returns [code]true[/code] if this is a main screen editor plugin (it goes in the workspace selector together with [b]2D[/b], [b]3D[/b], [b]Script[/b], [b]Game[/b], and [b]Asset Store[/b]).
- When the plugin's workspace is selected, other main screen plugins will be hidden, but your plugin will not appear automatically. It needs to be added as a child of [method EditorInterface.get_editor_main_screen] and made visible inside [method _make_visible].
- Use [method _get_plugin_name] and [method _get_plugin_icon] to customize the plugin button's appearance.
- [codeblock]
- var plugin_control
-
- func _enter_tree():
- plugin_control = preload("my_plugin_control.tscn").instantiate()
- EditorInterface.get_editor_main_screen().add_child(plugin_control)
- plugin_control.hide()
-
- func _has_main_screen():
- return true
-
- func _make_visible(visible):
- plugin_control.visible = visible
-
- func _get_plugin_name():
- return "My Super Cool Plugin 3000"
-
- func _get_plugin_icon():
- return EditorInterface.get_editor_theme().get_icon("Node", "EditorIcons")
- [/codeblock]
+ Return [code]true[/code] if this is a main screen editor plugin (it goes in the workspace selector together with [b]2D[/b], [b]3D[/b], [b]Script[/b], [b]Game[/b], and [b]Asset Store[/b]).
+ You can add a main screen dock by using [EditorDock] with [constant EditorDock.DOCK_LAYOUT_MAIN_SCREEN] as available layout.
</description>
</method>
<method name="_make_visible" qualifiers="virtual">
@@ -424,7 +404,7 @@
[b]Note:[/b] A plugin instance can belong only to a single context menu slot.
</description>
</method>
- <method name="add_control_to_bottom_panel" deprecated="Use [method add_dock] instead, with [member EditorDock.default_slot] set to [constant DOCK_SLOT_BOTTOM].">
+ <method name="add_control_to_bottom_panel" deprecated="Use [method add_dock] instead, with [member EditorDock.default_slot] set to [constant EditorDock.DOCK_SLOT_BOTTOM].">
<return type="Button" />
<param index="0" name="control" type="Control" />
<param index="1" name="title" type="String" />
diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml
index 19882493a95..bf238a46093 100644
--- a/doc/classes/EditorSettings.xml
+++ b/doc/classes/EditorSettings.xml
@@ -1055,6 +1055,9 @@
<member name="interface/editor/docks/dock_tab_style" type="int" setter="" getter="">
Tab style of editor docks, except bottom docks.
</member>
+ <member name="interface/editor/docks/main_screen_dock_tab_style" type="int" setter="" getter="">
+ Tab style of editor docks located at the editor's main screen.
+ </member>
<member name="interface/editor/fonts/code_font" type="String" setter="" getter="">
The font to use for the script editor. Must be a resource of a [Font] type such as a [code].ttf[/code] or [code].otf[/code] font file.
</member>
diff --git a/doc/classes/ScriptEditor.xml b/doc/classes/ScriptEditor.xml
index 4f26f1cf500..056c2916bac 100644
--- a/doc/classes/ScriptEditor.xml
+++ b/doc/classes/ScriptEditor.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="ScriptEditor" inherits="PanelContainer" api_type="editor" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
+<class name="ScriptEditor" inherits="EditorDock" api_type="editor" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Godot editor's script editor.
</brief_description>
diff --git a/editor/asset_library/asset_library_editor_plugin.cpp b/editor/asset_library/asset_library_editor_plugin.cpp
index 806eb6668f7..46a6607f9e0 100644
--- a/editor/asset_library/asset_library_editor_plugin.cpp
+++ b/editor/asset_library/asset_library_editor_plugin.cpp
@@ -39,6 +39,7 @@
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/version.h"
+#include "editor/docks/editor_dock_manager.h"
#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
@@ -1047,6 +1048,12 @@ void EditorAssetLibrary::_notification(int p_what) {
case NOTIFICATION_READY: {
add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("bg"), SNAME("AssetLib")));
error_label->move_to_front();
+
+ if (EditorNode::get_singleton()) {
+ EditorNode::get_singleton()->get_gui_base()->connect(SceneStringName(theme_changed), callable_mp(this, &EditorAssetLibrary::_update_margins));
+ } else if (ProjectManager::get_singleton()) {
+ ProjectManager::get_singleton()->connect(SceneStringName(theme_changed), callable_mp(this, &EditorAssetLibrary::_update_margins));
+ }
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
@@ -1069,7 +1076,7 @@ void EditorAssetLibrary::_notification(int p_what) {
// Focus the search box automatically when switching to the Templates tab (in the Project Manager)
// or switching to the AssetLib tab (in the editor).
// The Project Manager's project filter box is automatically focused in the project manager code.
- filter->grab_focus();
+ callable_mp((Control *)filter, &Control::grab_focus).call_deferred(false);
#endif
if (initial_loading) {
@@ -1167,6 +1174,10 @@ void EditorAssetLibrary::_update_repository_options() {
}
}
+void EditorAssetLibrary::_update_margins() {
+ update_layout(get_current_layout(), get_current_slot());
+}
+
void EditorAssetLibrary::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
@@ -1181,6 +1192,21 @@ void EditorAssetLibrary::shortcut_input(const Ref<InputEvent> &p_event) {
}
}
+void EditorAssetLibrary::update_layout(EditorDock::DockLayout p_layout, int p_slot) {
+ begin_bulk_theme_override();
+ if (p_layout == DOCK_LAYOUT_FLOATING) {
+ remove_theme_constant_override("margin_left");
+ remove_theme_constant_override("margin_right");
+ remove_theme_constant_override("margin_bottom");
+ } else {
+ int margin = EditorNode::get_singleton()->get_editor_theme()->get_constant("base_margin", EditorStringName(Editor));
+ add_theme_constant_override("margin_left", margin);
+ add_theme_constant_override("margin_right", margin);
+ add_theme_constant_override("margin_bottom", margin);
+ }
+ end_bulk_theme_override();
+}
+
void EditorAssetLibrary::_install_asset(const String &p_asset_id, const String &p_version, const String &p_download_url, const String &p_sha256) {
ERR_FAIL_NULL(description);
@@ -2136,6 +2162,13 @@ void EditorAssetLibrary::_bind_methods() {
}
EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) {
+ set_name(TTRC("Asset Store"));
+ set_icon_name("AssetStore");
+ set_available_layouts(EditorDock::DOCK_LAYOUT_MAIN_SCREEN | EditorDock::DOCK_LAYOUT_FLOATING);
+ set_default_slot(EditorDock::DOCK_SLOT_MAIN_SCREEN);
+ if (!Engine::get_singleton()->is_project_manager_hint()) {
+ set_dock_shortcut(ED_GET_SHORTCUT("editor/editor_asset_store"));
+ }
templates_only = p_templates_only;
loading_blocked = ((int)EDITOR_GET("network/connection/network_mode") == EditorSettings::NETWORK_OFFLINE);
@@ -2342,10 +2375,6 @@ bool AssetLibraryEditorPlugin::is_available() {
#endif
}
-const Ref<Texture2D> AssetLibraryEditorPlugin::get_plugin_icon() const {
- return EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("AssetStore"), EditorStringName(EditorIcons));
-}
-
void AssetLibraryEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
addon_library->show();
@@ -2357,7 +2386,7 @@ void AssetLibraryEditorPlugin::make_visible(bool p_visible) {
AssetLibraryEditorPlugin::AssetLibraryEditorPlugin() {
addon_library = memnew(EditorAssetLibrary);
addon_library->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- EditorNode::get_singleton()->get_editor_main_screen()->get_control()->add_child(addon_library);
+ EditorDockManager::get_singleton()->add_dock(addon_library);
addon_library->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
addon_library->hide();
}
diff --git a/editor/asset_library/asset_library_editor_plugin.h b/editor/asset_library/asset_library_editor_plugin.h
index a7cd71289b2..53f05fd257d 100644
--- a/editor/asset_library/asset_library_editor_plugin.h
+++ b/editor/asset_library/asset_library_editor_plugin.h
@@ -31,6 +31,7 @@
#pragma once
#include "editor/asset_library/editor_asset_installer.h"
+#include "editor/docks/editor_dock.h"
#include "editor/plugins/editor_plugin.h"
#include "scene/gui/box_container.h"
#include "scene/gui/grid_container.h"
@@ -249,8 +250,8 @@ public:
EditorAssetLibraryItemDownload();
};
-class EditorAssetLibrary : public PanelContainer {
- GDCLASS(EditorAssetLibrary, PanelContainer);
+class EditorAssetLibrary : public EditorDock {
+ GDCLASS(EditorAssetLibrary, EditorDock);
String host;
@@ -260,6 +261,7 @@ class EditorAssetLibrary : public PanelContainer {
void _asset_open();
void _asset_file_selected(const String &p_file);
void _update_repository_options();
+ void _update_margins();
MarginContainer *library_mc = nullptr;
ScrollContainer *library_scroll = nullptr;
@@ -400,6 +402,7 @@ protected:
static void _bind_methods();
void _notification(int p_what);
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
+ virtual void update_layout(EditorDock::DockLayout p_layout, int p_slot) override;
public:
EditorAssetLibrary(bool p_templates_only = false);
@@ -408,14 +411,13 @@ public:
class AssetLibraryEditorPlugin : public EditorPlugin {
GDCLASS(AssetLibraryEditorPlugin, EditorPlugin);
- EditorAssetLibrary *addon_library = nullptr;
+ static inline EditorAssetLibrary *addon_library = nullptr;
public:
static bool is_available();
+ static EditorAssetLibrary *get_library() { return addon_library; }
- virtual String get_plugin_name() const override { return TTRC("Asset Store"); }
- virtual const Ref<Texture2D> get_plugin_icon() const override;
- bool has_main_screen() const override { return true; }
+ virtual String get_plugin_name() const override { return "Asset Store"; }
virtual void edit(Object *p_object) override {}
virtual bool handles(Object *p_object) const override { return false; }
virtual void make_visible(bool p_visible) override;
diff --git a/editor/doc/editor_help.cpp b/editor/doc/editor_help.cpp
index cf0f2d26736..763fc753621 100644
--- a/editor/doc/editor_help.cpp
+++ b/editor/doc/editor_help.cpp
@@ -48,7 +48,6 @@
#include "core/version.h"
#include "editor/doc/doc_data_compressed.gen.h"
#include "editor/docks/filesystem_dock.h"
-#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/file_system/editor_file_system.h"
@@ -2355,7 +2354,7 @@ void EditorHelp::_update_doc() {
void EditorHelp::_request_help(const String &p_string) {
Error err = _goto_desc(p_string, false);
if (err == OK) {
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor();
}
}
@@ -4360,7 +4359,7 @@ void EditorHelpBit::_go_to_url(const String &p_what) {
void EditorHelpBit::_go_to_help(const String &p_what) {
if (ScriptEditor::get_singleton()) {
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor();
ScriptEditor::get_singleton()->goto_help(p_what);
} else {
_go_to_url(p_what);
diff --git a/editor/doc/editor_help_search.cpp b/editor/doc/editor_help_search.cpp
index fe30b336f21..70bfdf1ae53 100644
--- a/editor/doc/editor_help_search.cpp
+++ b/editor/doc/editor_help_search.cpp
@@ -33,10 +33,10 @@
#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
#include "core/os/os.h"
-#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/gui/filter_line_edit.h"
+#include "editor/script/script_editor_plugin.h"
#include "editor/settings/editor_feature_profile.h"
#include "editor/settings/editor_settings.h"
#include "editor/themes/editor_scale.h"
@@ -189,7 +189,7 @@ void EditorHelpSearch::_confirmed() {
}
// Activate the script editor and emit the signal with the documentation link to display.
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor();
emit_signal(SNAME("go_to_help"), item->get_metadata(0));
diff --git a/editor/docks/dock_tab_container.cpp b/editor/docks/dock_tab_container.cpp
index 0d8c6314d7d..e5f49f5bdbf 100644
--- a/editor/docks/dock_tab_container.cpp
+++ b/editor/docks/dock_tab_container.cpp
@@ -46,7 +46,7 @@ bool EditorDockDragHint::can_drop_data(const Point2 &p_point, const Variant &p_d
void EditorDockDragHint::drop_data(const Point2 &p_point, const Variant &p_data) {
// Drop dock into last spot if not over tabbar.
if (mouse_inside_tabbar) {
- drop_tabbar->_handle_drop_data("tab_container_tab", p_point, p_data, callable_mp(this, &EditorDockDragHint::_drag_move_tab), callable_mp(this, &EditorDockDragHint::_drag_move_tab_from));
+ drop_tabbar->_handle_drop_data("tab_container_tab", p_point - (drop_tabbar->get_global_position() - get_global_position()), p_data, callable_mp(this, &EditorDockDragHint::_drag_move_tab), callable_mp(this, &EditorDockDragHint::_drag_move_tab_from));
} else {
EditorDockManager *dock_manager = EditorDockManager::get_singleton();
if (mouse_margin_index == -1) {
@@ -77,7 +77,7 @@ void EditorDockDragHint::gui_input(const Ref<InputEvent> &p_event) {
queue_redraw();
}
const Point2 pos = mm->get_position();
- mouse_inside_tabbar = drop_tabbar_parent->get_rect().has_point(pos);
+ mouse_inside_tabbar = drop_tabbar_parent->get_global_rect().has_point(mm->get_global_position());
if (mouse_inside_tabbar) {
mouse_margin_index = -1;
@@ -194,7 +194,7 @@ void EditorDockDragHint::_notification(int p_what) {
// Only display tabbar hint if the mouse is over the tabbar.
if (mouse_inside_tabbar) {
- draw_set_transform(drop_tabbar_parent->get_position()); // The TabBar isn't always on top.
+ draw_set_transform(Vector2(drop_tabbar->get_global_position().x - get_global_position().x, drop_tabbar_parent->get_position().y)); // The TabBar isn't always on top.
drop_tabbar->_draw_tab_drop(get_canvas_item());
}
} break;
@@ -317,11 +317,22 @@ EditorDock *DockTabContainer::get_dock(int p_idx) const {
return Object::cast_to<EditorDock>(get_tab_control(p_idx));
}
+EditorDock *DockTabContainer::get_dock_by_name(const String &p_name) const {
+ for (int i = 0; i < get_tab_count(); i++) {
+ EditorDock *dock = get_dock(i);
+ ERR_CONTINUE(!dock);
+ if (dock->get_display_title() == p_name) {
+ return dock;
+ }
+ }
+ return nullptr;
+}
+
void DockTabContainer::show_drag_hint() {
if (!is_visible_in_tree()) {
return;
}
- drag_hint->set_rect(get_global_rect());
+ drag_hint->set_rect(get_drag_hint_rect());
drag_hint->show();
}
diff --git a/editor/docks/dock_tab_container.h b/editor/docks/dock_tab_container.h
index 67e5084d378..d8b116938d1 100644
--- a/editor/docks/dock_tab_container.h
+++ b/editor/docks/dock_tab_container.h
@@ -107,6 +107,7 @@ public:
virtual TabStyle get_tab_style() const;
virtual bool can_switch_dock() const;
virtual Rect2 get_floating_dock_rect(EditorDock *p_dock) { return DockTabContainer::get_default_floating_dock_rect(p_dock); }
+ virtual Rect2 get_drag_hint_rect() const { return get_global_rect(); }
void add_margin_valid_drop(int p_margin, int p_target_dock_slot);
int get_margin_drop_slot(int p_margin) const;
@@ -120,6 +121,7 @@ public:
void set_dock_context_popup(DockContextPopup *p_popup);
EditorDock *get_dock(int p_idx) const;
+ EditorDock *get_dock_by_name(const String &p_name) const;
void show_drag_hint();
EditorDockDragHint *get_drag_hint() const { return drag_hint; }
diff --git a/editor/docks/editor_dock.cpp b/editor/docks/editor_dock.cpp
index 9a9a1198500..de81d71896f 100644
--- a/editor/docks/editor_dock.cpp
+++ b/editor/docks/editor_dock.cpp
@@ -114,11 +114,11 @@ void EditorDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_default_slot", "slot"), &EditorDock::_set_default_slot_bind);
ClassDB::bind_method(D_METHOD("get_default_slot"), &EditorDock::_get_default_slot_bind);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "default_slot", PROPERTY_HINT_ENUM, "None:-1,Left Side Upper-Left,Left Side Bottom-Left,Left Side Upper-Right,Left Side Bottom-Right,Right Side Upper-Left,Right Side Bottom-Left,Right Side Upper-Right,Right Side Bottom-Right,Bottom"), "set_default_slot", "get_default_slot");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "default_slot", PROPERTY_HINT_ENUM, "None:-1,Left Side Upper-Left,Left Side Bottom-Left,Left Side Upper-Right,Left Side Bottom-Right,Right Side Upper-Left,Right Side Bottom-Left,Right Side Upper-Right,Right Side Bottom-Right,Bottom,Bottom Left,Bottom Right,Main Screen"), "set_default_slot", "get_default_slot");
ClassDB::bind_method(D_METHOD("set_available_layouts", "layouts"), &EditorDock::set_available_layouts);
ClassDB::bind_method(D_METHOD("get_available_layouts"), &EditorDock::get_available_layouts);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "available_layouts", PROPERTY_HINT_FLAGS, "Vertical:1,Horizontal:2,Floating:4"), "set_available_layouts", "get_available_layouts");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "available_layouts", PROPERTY_HINT_FLAGS, "Vertical:1,Horizontal:2,Floating:4,Main Screen:8"), "set_available_layouts", "get_available_layouts");
ADD_SIGNAL(MethodInfo("opened"));
ADD_SIGNAL(MethodInfo("closed"));
@@ -127,6 +127,7 @@ void EditorDock::_bind_methods() {
BIND_BITFIELD_FLAG(DOCK_LAYOUT_VERTICAL);
BIND_BITFIELD_FLAG(DOCK_LAYOUT_HORIZONTAL);
BIND_BITFIELD_FLAG(DOCK_LAYOUT_FLOATING);
+ BIND_BITFIELD_FLAG(DOCK_LAYOUT_MAIN_SCREEN);
BIND_BITFIELD_FLAG(DOCK_LAYOUT_ALL);
BIND_ENUM_CONSTANT(DOCK_SLOT_NONE);
@@ -141,6 +142,7 @@ void EditorDock::_bind_methods() {
BIND_ENUM_CONSTANT(DOCK_SLOT_BOTTOM);
BIND_ENUM_CONSTANT(DOCK_SLOT_BOTTOM_L);
BIND_ENUM_CONSTANT(DOCK_SLOT_BOTTOM_R);
+ BIND_ENUM_CONSTANT(DOCK_SLOT_MAIN_SCREEN);
BIND_ENUM_CONSTANT(DOCK_SLOT_MAX);
GDVIRTUAL_BIND(_update_layout_and_slot, "layout", "slot");
diff --git a/editor/docks/editor_dock.h b/editor/docks/editor_dock.h
index f37104d1e12..b9195abca50 100644
--- a/editor/docks/editor_dock.h
+++ b/editor/docks/editor_dock.h
@@ -45,6 +45,7 @@ public:
DOCK_LAYOUT_VERTICAL = 1,
DOCK_LAYOUT_HORIZONTAL = 2,
DOCK_LAYOUT_FLOATING = 4,
+ DOCK_LAYOUT_MAIN_SCREEN = 8,
DOCK_LAYOUT_ALL = DOCK_LAYOUT_VERTICAL | DOCK_LAYOUT_HORIZONTAL | DOCK_LAYOUT_FLOATING,
};
@@ -61,6 +62,7 @@ public:
DOCK_SLOT_BOTTOM,
DOCK_SLOT_BOTTOM_L,
DOCK_SLOT_BOTTOM_R,
+ DOCK_SLOT_MAIN_SCREEN,
DOCK_SLOT_MAX
};
diff --git a/editor/docks/editor_dock_manager.cpp b/editor/docks/editor_dock_manager.cpp
index 62e75ce7e82..6adffeb6472 100644
--- a/editor/docks/editor_dock_manager.cpp
+++ b/editor/docks/editor_dock_manager.cpp
@@ -33,6 +33,7 @@
#include "core/object/callable_mp.h"
#include "editor/docks/dock_tab_container.h"
#include "editor/docks/editor_dock.h"
+#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/gui/window_wrapper.h"
@@ -152,14 +153,7 @@ EditorDock *EditorDockManager::_get_dock_tab_dragged() {
const String tab_type = dock_drop_data.get("tab_type", "");
if (tab_type == "tab_container_tab") {
Node *source_tab_bar = EditorNode::get_singleton()->get_node(dock_drop_data["from_path"]);
- if (!source_tab_bar) {
- return nullptr;
- }
- HBoxContainer *parent = Object::cast_to<HBoxContainer>(source_tab_bar->get_parent()); // The internal container.
- if (!parent) {
- return nullptr;
- }
- DockTabContainer *source_tab_container = Object::cast_to<DockTabContainer>(parent->get_parent());
+ DockTabContainer *source_tab_container = Object::cast_to<DockTabContainer>(TabContainer::get_tab_bar_container(Object::cast_to<TabBar>(source_tab_bar)));
if (!source_tab_container) {
return nullptr;
}
@@ -200,6 +194,15 @@ DockTabContainer *EditorDockManager::get_dock_container(int p_slot) const {
return dock_slots[p_slot];
}
+EditorDock *EditorDockManager::get_dock_by_name(const String &p_name) const {
+ for (EditorDock *dock : all_docks) {
+ if (dock->get_display_title() == p_name) {
+ return dock;
+ }
+ }
+ return nullptr;
+}
+
void EditorDockManager::update_docks_menu() {
docks_menu->clear();
docks_menu->reset_size();
@@ -1046,17 +1049,6 @@ void DockSlotGrid::_update_rect_cache() {
rect.size = rect.size * CELL_SIZE * EDSCALE + (rect.size - Vector2i(1, 1)) * MARGINS * EDSCALE;
rect_cache[i] = rect;
}
-
- // Temporarily hard-coded, until main screen is registered as a slot.
- {
- Rect2 rect = Rect2i(2, 0, 4, 4);
- if (is_layout_rtl()) {
- rect.position.x = GRID_SIZE.x - rect.position.x - rect.size.x;
- }
- rect.position = rect.position * CELL_SIZE * EDSCALE + (rect.position + Vector2i(0, 1)) * MARGINS * EDSCALE;
- rect.size = rect.size * CELL_SIZE * EDSCALE + (rect.size - Vector2i(1, 1)) * MARGINS * EDSCALE;
- main_screen_rect = rect;
- }
}
void DockSlotGrid::_bind_methods() {
@@ -1129,7 +1121,6 @@ void DockSlotGrid::_notification(int p_what) {
}
}
}
- draw_rect(main_screen_rect, unusable_dock_color);
} break;
case NOTIFICATION_MOUSE_EXIT: {
diff --git a/editor/docks/editor_dock_manager.h b/editor/docks/editor_dock_manager.h
index 5c30536924f..4eb76abfcab 100644
--- a/editor/docks/editor_dock_manager.h
+++ b/editor/docks/editor_dock_manager.h
@@ -132,6 +132,7 @@ public:
static EditorDockManager *get_singleton() { return singleton; }
DockTabContainer *get_dock_container(int p_slot) const;
+ EditorDock *get_dock_by_name(const String &p_name) const;
void update_docks_menu();
void update_tab_styles();
@@ -177,7 +178,6 @@ class DockSlotGrid : public Control {
int hovered_slot = -1;
Rect2 rect_cache[EditorDock::DOCK_SLOT_MAX];
- Rect2 main_screen_rect;
bool rect_cache_dirty = true;
void _update_rect_cache();
diff --git a/editor/docks/inspector_dock.cpp b/editor/docks/inspector_dock.cpp
index 2bc104101d0..3a66f506468 100644
--- a/editor/docks/inspector_dock.cpp
+++ b/editor/docks/inspector_dock.cpp
@@ -111,7 +111,7 @@ void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) {
case OBJECT_REQUEST_HELP: {
if (current) {
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor();
emit_signal(SNAME("request_help"), current->get_class());
}
} break;
diff --git a/editor/docks/scene_tree_dock.cpp b/editor/docks/scene_tree_dock.cpp
index da29213f027..c223a672796 100644
--- a/editor/docks/scene_tree_dock.cpp
+++ b/editor/docks/scene_tree_dock.cpp
@@ -1323,7 +1323,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
ScriptEditor::get_singleton()->goto_help("class_name:" + class_name);
}
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor();
} break;
case TOOL_AUTO_EXPAND: {
scene_tree->set_auto_expand_selected(!EDITOR_GET("docks/scene_tree/auto_expand_to_selected"), true);
diff --git a/editor/editor_interface.cpp b/editor/editor_interface.cpp
index 3013152c70b..ac90d389c16 100644
--- a/editor/editor_interface.cpp
+++ b/editor/editor_interface.cpp
@@ -36,6 +36,7 @@
#include "core/io/resource_loader.h"
#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
+#include "editor/docks/editor_dock_manager.h"
#include "editor/docks/filesystem_dock.h"
#include "editor/docks/inspector_dock.h"
#include "editor/editor_main_screen.h"
@@ -421,9 +422,11 @@ Control *EditorInterface::get_base_control() const {
return EditorNode::get_singleton()->get_gui_base();
}
+#ifndef DISABLE_DEPRECATED
VBoxContainer *EditorInterface::get_editor_main_screen() const {
return EditorNode::get_singleton()->get_editor_main_screen()->get_control();
}
+#endif
ScriptEditor *EditorInterface::get_script_editor() const {
return ScriptEditor::get_singleton();
@@ -438,8 +441,16 @@ SubViewport *EditorInterface::get_editor_viewport_3d(int p_idx) const {
return Node3DEditor::get_singleton()->get_editor_viewport(p_idx)->get_viewport_node();
}
+#ifndef DISABLE_DEPRECATED
void EditorInterface::set_main_screen_editor(const String &p_name) {
- EditorNode::get_singleton()->get_editor_main_screen()->select_by_name(p_name);
+ EditorDock *dock = EditorNode::get_singleton()->get_editor_main_screen()->get_dock_by_name(p_name);
+ ERR_FAIL_NULL_MSG(dock, "The editor name '" + p_name + "' was not found.");
+ EditorDockManager::get_singleton()->focus_dock(dock);
+}
+#endif
+
+EditorDock *EditorInterface::get_dock_by_name(const String &p_name) {
+ return EditorDockManager::get_singleton()->get_dock_by_name(p_name);
}
void EditorInterface::set_distraction_free_mode(bool p_enter) {
@@ -836,11 +847,14 @@ bool EditorInterface::is_movie_maker_enabled() const {
void EditorInterface::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
const String pf = p_function;
if (p_idx == 0) {
+#ifndef DISABLE_DEPRECATED
if (pf == "set_main_screen_editor") {
- for (String E : { "\"2D\"", "\"3D\"", "\"Script\"", "\"Game\"", "\"AssetLib\"" }) {
+ for (String E : { "\"2D\"", "\"3D\"", "\"Script\"", "\"Game\"", "\"Asset Store\"" }) {
r_options->push_back(E);
}
- } else if (pf == "get_editor_viewport_3d") {
+ }
+#endif
+ if (pf == "get_editor_viewport_3d") {
for (uint32_t i = 0; i < Node3DEditor::VIEWPORTS_COUNT; i++) {
r_options->push_back(String::num_int64(i));
}
@@ -876,12 +890,15 @@ void EditorInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_editor_theme"), &EditorInterface::get_editor_theme);
ClassDB::bind_method(D_METHOD("get_base_control"), &EditorInterface::get_base_control);
- ClassDB::bind_method(D_METHOD("get_editor_main_screen"), &EditorInterface::get_editor_main_screen);
ClassDB::bind_method(D_METHOD("get_script_editor"), &EditorInterface::get_script_editor);
ClassDB::bind_method(D_METHOD("get_editor_viewport_2d"), &EditorInterface::get_editor_viewport_2d);
ClassDB::bind_method(D_METHOD("get_editor_viewport_3d", "idx"), &EditorInterface::get_editor_viewport_3d, DEFVAL(0));
+#ifndef DISABLE_DEPRECATED
+ ClassDB::bind_method(D_METHOD("get_editor_main_screen"), &EditorInterface::get_editor_main_screen);
ClassDB::bind_method(D_METHOD("set_main_screen_editor", "name"), &EditorInterface::set_main_screen_editor);
+#endif
+ ClassDB::bind_method(D_METHOD("get_dock_by_name", "name"), &EditorInterface::get_dock_by_name);
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);
ClassDB::bind_method(D_METHOD("is_multi_window_enabled"), &EditorInterface::is_multi_window_enabled);
diff --git a/editor/editor_interface.h b/editor/editor_interface.h
index 64b808cc0c5..49d729e0729 100644
--- a/editor/editor_interface.h
+++ b/editor/editor_interface.h
@@ -37,6 +37,7 @@
class Control;
class CreateDialog;
class EditorCommandPalette;
+class EditorDock;
class EditorFileSystem;
class EditorInspector;
class EditorPaths;
@@ -122,12 +123,17 @@ public:
Ref<Theme> get_editor_theme() const;
Control *get_base_control() const;
+#ifndef DISABLE_DEPRECATED
VBoxContainer *get_editor_main_screen() const;
+#endif
ScriptEditor *get_script_editor() const;
SubViewport *get_editor_viewport_2d() const;
SubViewport *get_editor_viewport_3d(int p_idx = 0) const;
+#ifndef DISABLE_DEPRECATED
void set_main_screen_editor(const String &p_name);
+#endif
+ EditorDock *get_dock_by_name(const String &p_name);
void set_distraction_free_mode(bool p_enter);
bool is_distraction_free_mode_enabled() const;
bool is_multi_window_enabled() const;
diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp
index f9decd6b649..51c3cb2ff19 100644
--- a/editor/editor_log.cpp
+++ b/editor/editor_log.cpp
@@ -222,6 +222,7 @@ void EditorLog::_meta_clicked(const String &p_meta) {
// Avoid re-editing the current script without the clicked line number.
editor_node->push_item(res.ptr(), "", true);
}
+ ScriptEditor::get_singleton()->focus_script_editor(res);
}
} else if (path.has_extension("cpp") || path.has_extension("h") || path.has_extension("mm") || path.has_extension("hpp")) {
// Godot source file. Try to open it in external editor.
diff --git a/editor/editor_main_screen.cpp b/editor/editor_main_screen.cpp
index aad79076e65..a311761a16f 100644
--- a/editor/editor_main_screen.cpp
+++ b/editor/editor_main_screen.cpp
@@ -30,296 +30,207 @@
#include "editor_main_screen.h"
-#include "core/io/config_file.h"
#include "core/object/callable_mp.h"
+#include "editor/docks/editor_dock.h"
+#include "editor/docks/editor_dock_manager.h"
#include "editor/editor_node.h"
-#include "editor/editor_string_names.h"
#include "editor/plugins/editor_plugin.h"
+#include "editor/scene/3d/node_3d_editor_plugin.h"
+#include "editor/script/script_editor_plugin.h"
#include "editor/settings/editor_settings.h"
-#include "scene/gui/box_container.h"
-#include "scene/gui/button.h"
+#include "editor/themes/editor_scale.h"
-void EditorMainScreen::_notification(int p_what) {
- switch (p_what) {
- case NOTIFICATION_READY: {
- set_accessibility_region(true);
- if (EDITOR_3D < buttons.size() && buttons[EDITOR_3D]->is_visible()) {
- // If the 3D editor is enabled, use this as the default.
- select(EDITOR_3D);
- return;
- }
-
- // Switch to the first main screen plugin that is enabled. Usually this is
- // 2D, but may be subsequent ones if 2D is disabled in the feature profile.
- for (int i = 0; i < buttons.size(); i++) {
- Button *editor_button = buttons[i];
- if (editor_button->is_visible()) {
- select(i);
- return;
- }
- }
-
- select(-1);
- } break;
- case NOTIFICATION_THEME_CHANGED: {
- for (int i = 0; i < buttons.size(); i++) {
- Button *tb = buttons[i];
- EditorPlugin *p_editor = editor_table[i];
- Ref<Texture2D> icon = p_editor->get_plugin_icon();
-
- if (icon.is_valid()) {
- tb->set_button_icon(icon);
- } else if (has_theme_icon(p_editor->get_plugin_name(), EditorStringName(EditorIcons))) {
- tb->set_button_icon(get_theme_icon(p_editor->get_plugin_name(), EditorStringName(EditorIcons)));
- }
- }
- } break;
+#ifndef DISABLE_DEPRECATED
+void LegacyMainScreenContainer::_force_dock_visible(EditorDock *p_dock, CanvasItem *p_child) {
+ if (p_dock->is_visible_in_tree()) {
+ p_child->show();
}
}
-void EditorMainScreen::set_button_container(HBoxContainer *p_button_hb) {
- button_hb = p_button_hb;
-}
-
-void EditorMainScreen::save_layout_to_config(Ref<ConfigFile> p_config_file, const String &p_section) const {
- int selected_main_editor_idx = -1;
- for (int i = 0; i < buttons.size(); i++) {
- if (buttons[i]->is_pressed()) {
- selected_main_editor_idx = i;
- break;
- }
- }
- if (selected_main_editor_idx != -1) {
- p_config_file->set_value(p_section, "selected_main_editor_idx", selected_main_editor_idx);
- } else {
- p_config_file->set_value(p_section, "selected_main_editor_idx", Variant());
- }
-}
-
-void EditorMainScreen::load_layout_from_config(Ref<ConfigFile> p_config_file, const String &p_section) {
- int selected_main_editor_idx = p_config_file->get_value(p_section, "selected_main_editor_idx", -1);
- if (selected_main_editor_idx >= 0 && selected_main_editor_idx < buttons.size()) {
- callable_mp(this, &EditorMainScreen::select).call_deferred(selected_main_editor_idx);
+void LegacyMainScreenContainer::add_child_notify(Node *p_child) {
+ EditorMainScreen *ms = EditorNode::get_editor_main_screen();
+ if (!ms->adding_plugin || !ms->adding_plugin->has_main_screen()) {
+ return;
}
-}
-void EditorMainScreen::set_button_enabled(int p_index, bool p_enabled) {
- ERR_FAIL_INDEX(p_index, buttons.size());
- buttons[p_index]->set_visible(p_enabled);
- if (!p_enabled && buttons[p_index]->is_pressed()) {
- select(EDITOR_2D);
- }
-}
+ EditorDock *dock = memnew(EditorDock);
+ dock->set_default_slot(EditorDock::DOCK_SLOT_MAIN_SCREEN);
+ dock->set_available_layouts(EditorDock::DOCK_LAYOUT_MAIN_SCREEN);
+ dock->set_title(ms->adding_plugin->get_plugin_name());
+ dock->set_dock_icon(ms->adding_plugin->get_plugin_icon());
+ dock->set_icon_name(ms->adding_plugin->get_plugin_name());
+ EditorDockManager::get_singleton()->add_dock(dock);
-bool EditorMainScreen::is_button_enabled(int p_index) const {
- ERR_FAIL_INDEX_V(p_index, buttons.size(), false);
- return buttons[p_index]->is_visible();
-}
+ ms->adding_plugin->set_meta("_dock", dock);
-int EditorMainScreen::_get_current_main_editor() const {
- for (int i = 0; i < editor_table.size(); i++) {
- if (editor_table[i] == selected_plugin) {
- return i;
- }
+ CanvasItem *ci_child = Object::cast_to<CanvasItem>(p_child);
+ if (ci_child) {
+ ci_child->show();
+ dock->connect(SceneStringName(visibility_changed), callable_mp(this, &LegacyMainScreenContainer::_force_dock_visible).bind(dock, ci_child));
}
- return 0;
+ callable_mp(p_child, &Node::reparent).call_deferred(dock, false);
}
+#endif
-void EditorMainScreen::select_next() {
- int editor = _get_current_main_editor();
+void EditorMainScreen::_on_tab_changed(int p_tab) {
+ EditorNode::get_singleton()->update_distraction_free_mode();
- do {
- if (editor == editor_table.size() - 1) {
- editor = 0;
- } else {
- editor++;
- }
- } while (!buttons[editor]->is_visible());
+ EditorDock *dock = get_dock(p_tab);
+ if (!dock) {
+ return;
+ }
+ const String new_main_screen = dock->get_display_title();
- select(editor);
+ EditorData &editor_data = EditorNode::get_editor_data();
+ int plugin_count = editor_data.get_editor_plugin_count();
+ for (int i = 0; i < plugin_count; i++) {
+ editor_data.get_editor_plugin(i)->notify_main_screen_changed(new_main_screen);
+ }
}
-void EditorMainScreen::select_prev() {
- int editor = _get_current_main_editor();
-
- do {
- if (editor == 0) {
- editor = editor_table.size() - 1;
- } else {
- editor--;
- }
- } while (!buttons[editor]->is_visible());
-
- select(editor);
-}
+void EditorMainScreen::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_POSTINITIALIZE: {
+ set_tab_alignment(TabBar::ALIGNMENT_CENTER);
+ get_internal_container()->set_alignment(BoxContainer::ALIGNMENT_CENTER);
+ connect("tab_changed", callable_mp(this, &EditorMainScreen::_on_tab_changed));
+ } break;
-void EditorMainScreen::select_by_name(const String &p_name) {
- ERR_FAIL_COND(p_name.is_empty());
+ case NOTIFICATION_READY: {
+ set_popup(nullptr);
- for (int i = 0; i < buttons.size(); i++) {
- if (buttons[i]->get_text() == p_name) {
- select(i);
- return;
- }
+ for (int i = 0; i < get_tab_count(); i++) {
+ EditorDock *dock = get_dock(i);
+ if (dock == Node3DEditor::get_singleton()) {
+ dock->make_visible();
+ break;
+ }
+ }
+ } break;
}
-
- ERR_FAIL_MSG("The editor name '" + p_name + "' was not found.");
}
-void EditorMainScreen::select(int p_index) {
- if (EditorNode::get_singleton()->is_changing_scene()) {
- return;
- }
+DockTabContainer::TabStyle EditorMainScreen::get_tab_style() const {
+ return (TabStyle)EDITOR_GET("interface/editor/docks/main_screen_dock_tab_style").operator int();
+}
- ERR_FAIL_INDEX(p_index, editor_table.size());
+Rect2 EditorMainScreen::get_drag_hint_rect() const {
+ const Rect2 tab_rect = get_internal_container()->get_global_rect();
+ const Rect2 content_rect = get_global_rect();
+ Rect2 final_rect = tab_rect.merge(content_rect);
+ float tab_x = get_tab_bar()->get_global_transform().xform(get_tab_bar()->get_tab_rect(0).position).x;
+ final_rect.position.x = MIN(tab_x, content_rect.position.x);
+ tab_x = get_tab_bar()->get_global_transform().xform(get_tab_bar()->get_tab_rect(-1).get_end()).x;
+ final_rect.set_end(Vector2(MAX(tab_x, content_rect.get_end().x), final_rect.get_end().y));
+ return final_rect;
+}
- if (!buttons[p_index]->is_visible()) { // Button hidden, no editor.
- return;
+void EditorMainScreen::edit(Object *p_object) {
+ EditorPlugin *handling_plugin = EditorNode::get_editor_data().get_handling_main_editor(p_object);
+ if (selected_plugin) {
+ if (handling_plugin == selected_plugin) {
+ selected_plugin->edit(p_object);
+ } else {
+ selected_plugin->edit(nullptr);
+ if (handling_plugin) {
+ selected_plugin->make_visible(false);
+ }
+ }
}
-
- for (int i = 0; i < buttons.size(); i++) {
- buttons[i]->set_pressed_no_signal(i == p_index);
+ selected_plugin = handling_plugin;
+ if (selected_plugin) {
+ selected_plugin->edit(p_object);
+ selected_plugin->make_visible(true);
}
+}
- EditorPlugin *new_editor = editor_table[p_index];
- ERR_FAIL_NULL(new_editor);
-
- if (selected_plugin == new_editor) {
+void EditorMainScreen::select_next() {
+ if (get_tab_count() == 0) {
return;
}
-
- if (selected_plugin) {
- selected_plugin->make_visible(false);
- }
-
- selected_plugin = new_editor;
- selected_plugin->make_visible(true);
- selected_plugin->selected_notify();
- set_accessibility_name(selected_plugin->get_plugin_name());
-
- EditorData &editor_data = EditorNode::get_editor_data();
- int plugin_count = editor_data.get_editor_plugin_count();
- for (int i = 0; i < plugin_count; i++) {
- editor_data.get_editor_plugin(i)->notify_main_screen_changed(selected_plugin->get_plugin_name());
+ if (get_current_tab() < get_tab_count() - 1) {
+ set_current_tab(get_current_tab() + 1);
+ } else {
+ set_current_tab(0);
}
-
- EditorNode::get_singleton()->update_distraction_free_mode();
}
-int EditorMainScreen::get_selected_index() const {
- for (int i = 0; i < editor_table.size(); i++) {
- if (selected_plugin == editor_table[i]) {
- return i;
- }
+void EditorMainScreen::select_prev() {
+ if (get_tab_count() == 0) {
+ return;
}
- return -1;
-}
-
-int EditorMainScreen::get_plugin_index(EditorPlugin *p_editor) const {
- int screen = -1;
- for (int i = 0; i < editor_table.size(); i++) {
- if (p_editor == editor_table[i]) {
- screen = i;
- break;
- }
+ if (get_current_tab() > 0) {
+ set_current_tab(get_current_tab() - 1);
+ } else {
+ set_current_tab(get_tab_count() - 1);
}
- return screen;
}
EditorPlugin *EditorMainScreen::get_selected_plugin() const {
return selected_plugin;
}
-EditorPlugin *EditorMainScreen::get_plugin_by_name(const String &p_plugin_name) const {
- ERR_FAIL_COND_V(!main_editor_plugins.has(p_plugin_name), nullptr);
- return main_editor_plugins[p_plugin_name];
-}
-
bool EditorMainScreen::can_auto_switch_screens() const {
if (selected_plugin == nullptr) {
return true;
}
- // Only allow auto-switching if the selected button is to the left of the Script button.
- for (int i = 0; i < button_hb->get_child_count(); i++) {
- Button *button = Object::cast_to<Button>(button_hb->get_child(i));
- if (button->get_text() == "Script") {
- // Selected button is at or after the Script button.
- return false;
+ // Only allow auto-switching if the selected tab is to the left of the Script tab, or is not in the TabBar.
+ bool was_script_tab = false;
+ for (int i = 0; i < get_tab_count(); i++) {
+ EditorDock *dock = get_dock(i);
+ if (dock == ScriptEditor::get_singleton()) {
+ was_script_tab = true;
}
- if (button->get_text() == selected_plugin->get_plugin_name()) {
- // Selected button is before the Script button.
- return true;
+ if (dock->get_display_title() == selected_plugin->get_plugin_name()) {
+ return !was_script_tab;
}
}
- return false;
+ return true;
}
+#ifndef DISABLE_DEPRECATED
VBoxContainer *EditorMainScreen::get_control() const {
return main_screen_vbox;
}
void EditorMainScreen::add_main_plugin(EditorPlugin *p_editor) {
- Button *tb = memnew(Button);
- tb->set_toggle_mode(true);
- tb->set_theme_type_variation("MainScreenButton");
- tb->set_name(p_editor->get_plugin_name());
- tb->set_text(p_editor->get_plugin_name());
-
- Ref<Shortcut> shortcut = EditorSettings::get_singleton()->get_shortcut("editor/editor_" + p_editor->get_plugin_name().to_lower().replace_char(' ', '_'));
- if (shortcut.is_valid()) {
- tb->set_shortcut(shortcut);
- }
-
- Ref<Texture2D> icon = p_editor->get_plugin_icon();
- if (icon.is_null() && has_theme_icon(p_editor->get_plugin_name(), EditorStringName(EditorIcons))) {
- icon = get_editor_theme_icon(p_editor->get_plugin_name());
- }
- if (icon.is_valid()) {
- tb->set_button_icon(icon);
- // Make sure the control is updated if the icon is reimported.
- icon->connect_changed(callable_mp((Control *)tb, &Control::update_minimum_size));
- }
-
- tb->connect(SceneStringName(pressed), callable_mp(this, &EditorMainScreen::select).bind(buttons.size()));
-
- buttons.push_back(tb);
- button_hb->add_child(tb);
editor_table.push_back(p_editor);
- main_editor_plugins.insert(p_editor->get_plugin_name(), p_editor);
}
void EditorMainScreen::remove_main_plugin(EditorPlugin *p_editor) {
- // Remove the main editor button and update the bindings of
- // all buttons behind it to point to the correct main window.
- for (int i = buttons.size() - 1; i >= 0; i--) {
- if (p_editor->get_plugin_name() == buttons[i]->get_text()) {
- if (buttons[i]->is_pressed()) {
- select(EDITOR_SCRIPT);
- }
-
- memdelete(buttons[i]);
- buttons.remove_at(i);
-
- break;
- } else {
- buttons[i]->disconnect(SceneStringName(pressed), callable_mp(this, &EditorMainScreen::select));
- buttons[i]->connect(SceneStringName(pressed), callable_mp(this, &EditorMainScreen::select).bind(i - 1));
- }
- }
-
if (selected_plugin == p_editor) {
selected_plugin = nullptr;
}
+ if (p_editor->has_meta("_dock")) {
+ EditorDock *dock = Object::cast_to<EditorDock>(p_editor->get_meta("_dock").get_validated_object());
+ if (dock) {
+ EditorDockManager::get_singleton()->remove_dock(dock);
+ }
+ }
editor_table.erase(p_editor);
- main_editor_plugins.erase(p_editor->get_plugin_name());
}
+#endif
+
+EditorMainScreen::EditorMainScreen() :
+ DockTabContainer(EditorDock::DOCK_SLOT_MAIN_SCREEN) {
+ layout = EditorDock::DOCK_LAYOUT_MAIN_SCREEN;
+ grid_rect = Rect2i(2, 0, 4, 4);
+
+ set_theme_type_variation("MainScreenContainer");
+ set_custom_minimum_size(Size2(0, 80) * EDSCALE);
+ set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ set_draw_behind_parent(true);
+ get_tab_bar()->set_mouse_filter(Control::MOUSE_FILTER_PASS);
+
+#ifndef DISABLE_DEPRECATED
+ main_screen_vbox = memnew(LegacyMainScreenContainer);
+ main_screen_vbox->hide();
+ EditorNode::get_singleton()->get_gui_base()->add_child(main_screen_vbox);
+#endif
-EditorMainScreen::EditorMainScreen() {
- main_screen_vbox = memnew(VBoxContainer);
- main_screen_vbox->set_name("MainScreen");
- main_screen_vbox->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- main_screen_vbox->add_theme_constant_override("separation", 0);
- add_child(main_screen_vbox);
+ Ref<StyleBoxEmpty> sb;
+ sb.instantiate();
+ add_theme_style_override(SceneStringName(panel), sb);
}
diff --git a/editor/editor_main_screen.h b/editor/editor_main_screen.h
index 78ec4992feb..0f3d344c52b 100644
--- a/editor/editor_main_screen.h
+++ b/editor/editor_main_screen.h
@@ -30,63 +30,58 @@
#pragma once
-#include "scene/gui/panel_container.h"
+#include "editor/docks/dock_tab_container.h"
+#include "scene/gui/box_container.h"
-class Button;
class ConfigFile;
+class EditorDock;
class EditorPlugin;
-class HBoxContainer;
-class VBoxContainer;
-class EditorMainScreen : public PanelContainer {
- GDCLASS(EditorMainScreen, PanelContainer);
+#ifndef DISABLE_DEPRECATED
+class LegacyMainScreenContainer : public VBoxContainer {
+ GDCLASS(LegacyMainScreenContainer, VBoxContainer);
-public:
- enum EditorTable {
- EDITOR_2D = 0,
- EDITOR_3D,
- EDITOR_SCRIPT,
- EDITOR_GAME,
- EDITOR_ASSETLIB,
- };
+ void _force_dock_visible(EditorDock *p_dock, CanvasItem *p_child);
+
+protected:
+ virtual void add_child_notify(Node *p_child) override;
+ virtual void remove_child_notify(Node *p_child) override {} // Disable parent method.
+};
+#endif
+
+class EditorMainScreen : public DockTabContainer {
+ GDCLASS(EditorMainScreen, DockTabContainer);
private:
+#ifndef DISABLE_DEPRECATED
VBoxContainer *main_screen_vbox = nullptr;
- EditorPlugin *selected_plugin = nullptr;
-
- HBoxContainer *button_hb = nullptr;
- Vector<Button *> buttons;
Vector<EditorPlugin *> editor_table;
- HashMap<String, EditorPlugin *> main_editor_plugins;
+#endif
+ EditorPlugin *selected_plugin = nullptr;
- int _get_current_main_editor() const;
+ void _on_tab_changed(int p_tab);
protected:
void _notification(int p_what);
-public:
- void set_button_container(HBoxContainer *p_button_hb);
+ virtual void update_visibility() override { show(); } // Never hide main screen.
+ virtual TabStyle get_tab_style() const override;
+ virtual Rect2 get_drag_hint_rect() const override;
- void save_layout_to_config(Ref<ConfigFile> p_config_file, const String &p_section) const;
- void load_layout_from_config(Ref<ConfigFile> p_config_file, const String &p_section);
+public:
+#ifndef DISABLE_DEPRECATED
+ EditorPlugin *adding_plugin = nullptr;
+ VBoxContainer *get_control() const;
+ void add_main_plugin(EditorPlugin *p_editor);
+ void remove_main_plugin(EditorPlugin *p_editor);
+#endif
- void set_button_enabled(int p_index, bool p_enabled);
- bool is_button_enabled(int p_index) const;
+ void edit(Object *p_object);
void select_next();
void select_prev();
- void select_by_name(const String &p_name);
- void select(int p_index);
- int get_selected_index() const;
- int get_plugin_index(EditorPlugin *p_editor) const;
EditorPlugin *get_selected_plugin() const;
- EditorPlugin *get_plugin_by_name(const String &p_plugin_name) const;
bool can_auto_switch_screens() const;
- VBoxContainer *get_control() const;
-
- void add_main_plugin(EditorPlugin *p_editor);
- void remove_main_plugin(EditorPlugin *p_editor);
-
EditorMainScreen();
};
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index b932c76a08d..28454a64fe2 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -421,18 +421,8 @@ void EditorNode::shortcut_input(const Ref<InputEvent> &p_event) {
bool is_handled = true;
if (ED_IS_SHORTCUT("editor/filter_files", p_event)) {
FileSystemDock::get_singleton()->focus_on_filter();
- } else if (ED_IS_SHORTCUT("editor/editor_2d", p_event)) {
- editor_main_screen->select(EditorMainScreen::EDITOR_2D);
- } else if (ED_IS_SHORTCUT("editor/editor_3d", p_event)) {
- editor_main_screen->select(EditorMainScreen::EDITOR_3D);
- } else if (ED_IS_SHORTCUT("editor/editor_script", p_event)) {
- editor_main_screen->select(EditorMainScreen::EDITOR_SCRIPT);
- } else if (ED_IS_SHORTCUT("editor/editor_game", p_event)) {
- editor_main_screen->select(EditorMainScreen::EDITOR_GAME);
} else if (ED_IS_SHORTCUT("editor/editor_help", p_event)) {
emit_signal(SNAME("request_help_search"), "");
- } else if (ED_IS_SHORTCUT("editor/editor_asset_store", p_event) && AssetLibraryEditorPlugin::is_available()) {
- editor_main_screen->select(EditorMainScreen::EDITOR_ASSETLIB);
} else if (ED_IS_SHORTCUT("editor/editor_next", p_event)) {
editor_main_screen->select_next();
} else if (ED_IS_SHORTCUT("editor/editor_prev", p_event)) {
@@ -3249,7 +3239,7 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
SceneTreeDock::get_singleton()->set_selection({ current_node });
InspectorDock::get_singleton()->update(current_node);
if (!inspector_only && !skip_main_plugin) {
- if (!ScriptEditor::get_singleton()->is_editor_floating() && ScriptEditor::get_singleton()->is_visible_in_tree()) {
+ if ((ScriptEditor::get_singleton()->get_current_layout() != EditorDock::DOCK_LAYOUT_FLOATING) && ScriptEditor::get_singleton()->is_visible_in_tree()) {
skip_main_plugin = stay_in_script_editor_on_node_selected;
} else {
skip_main_plugin = !editor_main_screen->can_auto_switch_screens();
@@ -3323,43 +3313,9 @@ void EditorNode::_edit_current(bool p_skip_foreign, bool p_skip_inspector_update
// Take care of the main editor plugin.
if (!inspector_only) {
- EditorPlugin *main_plugin = editor_data.get_handling_main_editor(current_obj);
-
- int plugin_index = editor_main_screen->get_plugin_index(main_plugin);
- if (main_plugin && plugin_index >= 0 && !editor_main_screen->is_button_enabled(plugin_index)) {
- main_plugin = nullptr;
- }
- EditorPlugin *editor_plugin_screen = editor_main_screen->get_selected_plugin();
-
- ObjectID editor_owner_id = editor_owner->get_instance_id();
- if (main_plugin && !skip_main_plugin) {
- // Special case if current_obj is a script.
- Script *current_script = Object::cast_to<Script>(current_obj);
- if (current_script) {
- if (!changing_scene) {
- // Only update main editor screen if using in-engine editor.
- if (current_script->is_built_in() || (!bool(EDITOR_GET("text_editor/external/use_external_editor")) && !current_script->get_language()->overrides_external_editor())) {
- editor_main_screen->select(plugin_index);
- }
-
- main_plugin->edit(current_script);
- }
- } else if (main_plugin != editor_plugin_screen) {
- // Unedit previous plugin.
- editor_plugin_screen->edit(nullptr);
- active_plugins[editor_owner_id].erase(editor_plugin_screen);
- // Update screen main_plugin.
- editor_main_screen->select(plugin_index);
- main_plugin->edit(current_obj);
- } else {
- editor_plugin_screen->edit(current_obj);
- }
- is_main_screen_editing = true;
- } else if (!main_plugin && editor_plugin_screen && is_main_screen_editing) {
- editor_plugin_screen->edit(nullptr);
- is_main_screen_editing = false;
+ if (!skip_main_plugin) {
+ editor_main_screen->edit(current_obj);
}
-
edit_item(current_obj, editor_owner);
}
@@ -4094,10 +4050,8 @@ void EditorNode::_screenshot(bool p_use_utc) {
}
void EditorNode::_save_screenshot_with_embedded_process(int64_t p_w, int64_t p_h, const String &p_emb_path, const Rect2i &p_rect, const String &p_path) {
- Control *main_screen_control = editor_main_screen->get_control();
- ERR_FAIL_NULL_MSG(main_screen_control, "Cannot get the editor main screen control.");
- Viewport *viewport = main_screen_control->get_viewport();
- ERR_FAIL_NULL_MSG(viewport, "Cannot get a viewport from the editor main screen.");
+ Viewport *viewport = get_viewport();
+ ERR_FAIL_NULL_MSG(viewport, "Cannot get a viewport from the EditorNode.");
Ref<ViewportTexture> texture = viewport->get_texture();
ERR_FAIL_COND_MSG(texture.is_null(), "Cannot get a viewport texture from the editor main screen.");
Ref<Image> img = texture->get_image();
@@ -4125,10 +4079,8 @@ void EditorNode::_save_screenshot_with_embedded_process(int64_t p_w, int64_t p_h
}
void EditorNode::_save_screenshot(const String &p_path) {
- Control *main_screen_control = editor_main_screen->get_control();
- ERR_FAIL_NULL_MSG(main_screen_control, "Cannot get the editor main screen control.");
- Viewport *viewport = main_screen_control->get_viewport();
- ERR_FAIL_NULL_MSG(viewport, "Cannot get a viewport from the editor main screen.");
+ Viewport *viewport = get_viewport();
+ ERR_FAIL_NULL_MSG(viewport, "Cannot get a viewport from the EditorNode.");
Ref<ViewportTexture> texture = viewport->get_texture();
ERR_FAIL_COND_MSG(texture.is_null(), "Cannot get a viewport texture from the editor main screen.");
Ref<Image> img = texture->get_image();
@@ -4774,16 +4726,13 @@ Dictionary EditorNode::_get_main_scene_state() {
void EditorNode::_set_main_scene_state(const Dictionary &p_state) {
if (get_edited_scene()) {
- if (editor_main_screen->can_auto_switch_screens()) {
+ if (!restoring_scenes && editor_main_screen->can_auto_switch_screens()) {
// Switch between 2D and 3D if currently in 2D or 3D.
Node *selected_node = SceneTreeDock::get_singleton()->get_tree_editor()->get_selected();
if (!selected_node) {
selected_node = get_edited_scene();
}
- const int plugin_index = editor_main_screen->get_plugin_index(editor_data.get_handling_main_editor(selected_node));
- if (plugin_index >= 0) {
- editor_main_screen->select(plugin_index);
- }
+ editor_main_screen->edit(selected_node);
}
}
@@ -6476,10 +6425,6 @@ void EditorNode::_save_central_editor_layout_to_config(Ref<ConfigFile> p_config_
int selected_default_debugger_tab_idx = EditorDebuggerNode::get_singleton()->get_default_debugger()->get_current_debugger_tab();
p_config_file->set_value(EDITOR_NODE_CONFIG_SECTION, "selected_default_debugger_tab_idx", selected_default_debugger_tab_idx);
-
- // Main editor (plugin).
-
- editor_main_screen->save_layout_to_config(p_config_file, EDITOR_NODE_CONFIG_SECTION);
}
void EditorNode::_load_central_editor_layout_from_config(Ref<ConfigFile> p_config_file) {
@@ -6493,10 +6438,6 @@ void EditorNode::_load_central_editor_layout_from_config(Ref<ConfigFile> p_confi
int selected_default_debugger_tab_idx = p_config_file->get_value(EDITOR_NODE_CONFIG_SECTION, "selected_default_debugger_tab_idx");
EditorDebuggerNode::get_singleton()->get_default_debugger()->switch_to_debugger(selected_default_debugger_tab_idx);
}
-
- // Main editor (plugin).
-
- editor_main_screen->load_layout_from_config(p_config_file, EDITOR_NODE_CONFIG_SECTION);
}
void EditorNode::_save_window_settings_to_config(Ref<ConfigFile> p_layout, const String &p_section) {
@@ -6963,9 +6904,8 @@ void EditorNode::_prepare_save_confirmation_popup() {
void EditorNode::_toggle_distraction_free_mode() {
if (EDITOR_GET("interface/editor/behavior/separate_distraction_mode")) {
- int screen = editor_main_screen->get_selected_index();
-
- if (screen == EditorMainScreen::EDITOR_SCRIPT) {
+ Control *screen = editor_main_screen->get_current_tab_control();
+ if (screen == ScriptEditor::get_singleton()) {
script_distraction_free = !script_distraction_free;
set_distraction_free_mode(script_distraction_free);
} else {
@@ -6981,8 +6921,8 @@ void EditorNode::update_distraction_free_mode() {
if (!EDITOR_GET("interface/editor/behavior/separate_distraction_mode")) {
return;
}
- int screen = editor_main_screen->get_selected_index();
- if (screen == EditorMainScreen::EDITOR_SCRIPT) {
+ Control *screen = editor_main_screen->get_current_tab_control();
+ if (screen == ScriptEditor::get_singleton()) {
set_distraction_free_mode(script_distraction_free);
} else {
set_distraction_free_mode(scene_distraction_free);
@@ -7972,13 +7912,13 @@ void EditorNode::_feature_profile_changed() {
editor_dock_manager->set_dock_enabled(ImportDock::get_singleton(), !fs_dock_disabled && !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_IMPORT_DOCK));
editor_dock_manager->set_dock_enabled(history_dock, !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_HISTORY_DOCK));
- editor_main_screen->set_button_enabled(EditorMainScreen::EDITOR_3D, !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D));
- editor_main_screen->set_button_enabled(EditorMainScreen::EDITOR_SCRIPT, !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT));
+ editor_dock_manager->set_dock_enabled(Node3DEditor::get_singleton(), !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D));
+ editor_dock_manager->set_dock_enabled(ScriptEditor::get_singleton(), !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT));
if (!Engine::get_singleton()->is_recovery_mode_hint()) {
- editor_main_screen->set_button_enabled(EditorMainScreen::EDITOR_GAME, !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_GAME));
+ editor_dock_manager->set_dock_enabled(GameView::get_dock(), !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_GAME));
}
if (AssetLibraryEditorPlugin::is_available()) {
- editor_main_screen->set_button_enabled(EditorMainScreen::EDITOR_ASSETLIB, !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB));
+ editor_dock_manager->set_dock_enabled(AssetLibraryEditorPlugin::get_library(), !profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB));
}
} else {
editor_dock_manager->set_dock_enabled(ImportDock::get_singleton(), true);
@@ -7986,13 +7926,13 @@ void EditorNode::_feature_profile_changed() {
editor_dock_manager->set_dock_enabled(GroupsDock::get_singleton(), true);
editor_dock_manager->set_dock_enabled(FileSystemDock::get_singleton(), true);
editor_dock_manager->set_dock_enabled(history_dock, true);
- editor_main_screen->set_button_enabled(EditorMainScreen::EDITOR_3D, true);
- editor_main_screen->set_button_enabled(EditorMainScreen::EDITOR_SCRIPT, true);
- if (!Engine::get_singleton()->is_recovery_mode_hint()) {
- editor_main_screen->set_button_enabled(EditorMainScreen::EDITOR_GAME, true);
+ editor_dock_manager->set_dock_enabled(Node3DEditor::get_singleton(), true);
+ editor_dock_manager->set_dock_enabled(ScriptEditor::get_singleton(), true);
+ if (!Engine::get_singleton()->is_recovery_mode_hint() && GameView::get_dock()) {
+ editor_dock_manager->set_dock_enabled(GameView::get_dock(), true);
}
if (AssetLibraryEditorPlugin::is_available()) {
- editor_main_screen->set_button_enabled(EditorMainScreen::EDITOR_ASSETLIB, true);
+ editor_dock_manager->set_dock_enabled(AssetLibraryEditorPlugin::get_library(), true);
}
}
@@ -9012,10 +8952,10 @@ EditorNode::EditorNode() {
distraction_free->connect(SceneStringName(pressed), callable_mp(this, &EditorNode::_toggle_distraction_free_mode));
editor_main_screen = memnew(EditorMainScreen);
- editor_main_screen->set_custom_minimum_size(Size2(0, 80) * EDSCALE);
- editor_main_screen->set_draw_behind_parent(true);
srt->add_child(editor_main_screen);
- editor_main_screen->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ title_bar->set_center_control(editor_main_screen->get_internal_container());
+
+ editor_dock_manager->register_dock_slot(editor_main_screen);
scene_root = memnew(SubViewport);
scene_root->set_auto_translate_mode(AUTO_TRANSLATE_MODE_ALWAYS);
@@ -9186,7 +9126,7 @@ EditorNode::EditorNode() {
if (can_expand) {
// Add spacer to avoid other controls under window minimize/maximize/close buttons (left side).
left_menu_spacer = memnew(Control);
- left_menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
+ left_menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
title_bar->add_child(left_menu_spacer);
}
@@ -9215,7 +9155,7 @@ EditorNode::EditorNode() {
// Spacer to center 2D / 3D / Script buttons.
left_spacer = memnew(HBoxContainer);
- left_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
+ left_spacer->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
left_spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL);
title_bar->add_child(left_spacer);
@@ -9225,20 +9165,13 @@ EditorNode::EditorNode() {
project_title->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
project_title->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
project_title->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- project_title->set_mouse_filter(Control::MOUSE_FILTER_PASS);
+ project_title->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
project_title->set_visible(can_expand && menu_type == MENU_TYPE_GLOBAL);
left_spacer->add_child(project_title);
- HBoxContainer *main_editor_button_hb = memnew(HBoxContainer);
- main_editor_button_hb->set_mouse_filter(Control::MOUSE_FILTER_STOP);
- main_editor_button_hb->set_name("EditorMainScreenButtons");
- editor_main_screen->set_button_container(main_editor_button_hb);
- title_bar->add_child(main_editor_button_hb);
- title_bar->set_center_control(main_editor_button_hb);
-
// Spacer to center 2D / 3D / Script buttons.
right_spacer = memnew(Control);
- right_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
+ right_spacer->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
right_spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL);
title_bar->add_child(right_spacer);
@@ -9252,6 +9185,13 @@ EditorNode::EditorNode() {
right_menu_hb->set_mouse_filter(Control::MOUSE_FILTER_STOP);
title_bar->add_child(right_menu_hb);
+ // FIXME: There has to be a simpler way to determine correct index.
+#ifdef ANDROID_ENABLED
+ title_bar->move_child(editor_main_screen->get_internal_container(), title_bar->get_child_count() / 2);
+#else
+ title_bar->move_child(editor_main_screen->get_internal_container(), left_menu_spacer ? 3 : 2);
+#endif
+
renderer = memnew(OptionButton);
renderer->set_flat(true);
renderer->set_theme_type_variation("TopBarOptionButton");
@@ -9267,7 +9207,7 @@ EditorNode::EditorNode() {
if (can_expand) {
// Add spacer to avoid other controls under the window minimize/maximize/close buttons (right side).
right_menu_spacer = memnew(Control);
- right_menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_PASS);
+ right_menu_spacer->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
title_bar->add_child(right_menu_spacer);
}
@@ -9353,49 +9293,6 @@ EditorNode::EditorNode() {
const int dock_hsize_scaled = dock_hsize * EDSCALE;
main_hsplit->set_split_offsets({ dock_hsize_scaled, -dock_hsize_scaled });
- // Define corresponding default layout.
-
- const String docks_section = "docks";
- default_layout.instantiate();
- // Dock numbers are based on DockSlot enum value + 1.
- {
- const String scene_key = SceneTreeDock::get_singleton()->get_effective_layout_key();
- const String import_key = ImportDock::get_singleton()->get_effective_layout_key();
- default_layout->set_value(docks_section, "dock_3", vformat("%s,%s", scene_key, import_key));
- default_layout->set_value(docks_section, "dock_3_selected_tab_idx", 0);
- }
- {
- const String filesystem_key = filesystem_dock->get_effective_layout_key();
- const String history_key = history_dock->get_effective_layout_key();
- default_layout->set_value(docks_section, "dock_4", vformat("%s,%s", filesystem_key, history_key));
- default_layout->set_value(docks_section, "dock_4_selected_tab_idx", 0);
- }
- {
- const String inspector_key = InspectorDock::get_singleton()->get_effective_layout_key();
- const String signals_key = SignalsDock::get_singleton()->get_effective_layout_key();
- const String groups_key = GroupsDock::get_singleton()->get_effective_layout_key();
- default_layout->set_value(docks_section, "dock_5", vformat("%s,%s,%s", inspector_key, signals_key, groups_key));
- default_layout->set_value(docks_section, "dock_5_selected_tab_idx", 0);
- }
-
- int hsplits[] = { 0, dock_hsize, -dock_hsize, 0 };
- for (int i = 0; i < (int)std_size(hsplits); i++) {
- default_layout->set_value(docks_section, "dock_hsplit_" + itos(i + 1), hsplits[i]);
- }
- for (int i = 0; i < editor_dock_manager->get_vsplit_count(); i++) {
- default_layout->set_value(docks_section, "dock_split_" + itos(i + 1), 0);
- }
-
- {
- Dictionary offsets;
- offsets["Audio"] = -450;
- offsets["Output"] = -270;
- offsets["Shader Editor"] = -348;
- default_layout->set_value(EDITOR_NODE_CONFIG_SECTION, "bottom_panel_offsets", offsets);
- }
-
- _update_layouts_menu();
-
// Bottom panels.
bottom_panel = memnew(EditorBottomPanel);
@@ -9791,6 +9688,66 @@ EditorNode::EditorNode() {
follow_system_theme = EDITOR_GET("interface/theme/follow_system_theme");
use_system_accent_color = EDITOR_GET("interface/theme/use_system_accent_color");
+
+ // Define the default layout after everything is initialized.
+
+ default_layout.instantiate();
+ const String docks_section = "docks";
+ {
+ const String scene_key = SceneTreeDock::get_singleton()->get_effective_layout_key();
+ const String import_key = ImportDock::get_singleton()->get_effective_layout_key();
+ default_layout->set_value(docks_section, DockTabContainer::get_config_key(EditorDock::DOCK_SLOT_LEFT_UR), vformat("%s,%s", scene_key, import_key));
+ default_layout->set_value(docks_section, DockTabContainer::get_config_key(EditorDock::DOCK_SLOT_LEFT_UR) + "_selected_tab_idx", 0);
+ }
+ {
+ const String filesystem_key = filesystem_dock->get_effective_layout_key();
+ const String history_key = history_dock->get_effective_layout_key();
+ default_layout->set_value(docks_section, DockTabContainer::get_config_key(EditorDock::DOCK_SLOT_LEFT_BR), vformat("%s,%s", filesystem_key, history_key));
+ default_layout->set_value(docks_section, DockTabContainer::get_config_key(EditorDock::DOCK_SLOT_LEFT_BR) + "_selected_tab_idx", 0);
+ }
+ {
+ const String inspector_key = InspectorDock::get_singleton()->get_effective_layout_key();
+ const String signals_key = SignalsDock::get_singleton()->get_effective_layout_key();
+ const String groups_key = GroupsDock::get_singleton()->get_effective_layout_key();
+ default_layout->set_value(docks_section, DockTabContainer::get_config_key(EditorDock::DOCK_SLOT_RIGHT_UL), vformat("%s,%s,%s", inspector_key, signals_key, groups_key));
+ default_layout->set_value(docks_section, DockTabContainer::get_config_key(EditorDock::DOCK_SLOT_RIGHT_UL) + "_selected_tab_idx", 0);
+ }
+ {
+ const String _2d_key = CanvasItemEditor::get_singleton()->get_effective_layout_key();
+ const String _3d_key = Node3DEditor::get_singleton()->get_effective_layout_key();
+ const String script_key = ScriptEditor::get_singleton()->get_effective_layout_key();
+ String game_key;
+ if (GameView::get_dock()) {
+ game_key = GameView::get_dock()->get_effective_layout_key();
+ }
+ String asset_lib_key;
+ if (AssetLibraryEditorPlugin::get_library()) {
+ asset_lib_key = AssetLibraryEditorPlugin::get_library()->get_effective_layout_key();
+ }
+ default_layout->set_value(docks_section, DockTabContainer::get_config_key(EditorDock::DOCK_SLOT_MAIN_SCREEN), vformat("%s,%s,%s,%s,%s", _2d_key, _3d_key, script_key, game_key, asset_lib_key));
+ }
+
+ int hsplits[] = { 0, dock_hsize, -dock_hsize, 0 };
+ for (int i = 0; i < (int)std_size(hsplits); i++) {
+ default_layout->set_value(docks_section, "dock_hsplit_" + itos(i + 1), hsplits[i]);
+ }
+ for (int i = 0; i < editor_dock_manager->get_vsplit_count(); i++) {
+ default_layout->set_value(docks_section, "dock_split_" + itos(i + 1), 0);
+ }
+
+ {
+ const String output_key = log->get_effective_layout_key();
+ const String audio_key = audio_bus_editor->get_effective_layout_key();
+ const String shader_key = ScriptEditor::get_bottom_script_editor()->get_effective_layout_key();
+
+ Dictionary offsets;
+ offsets[output_key] = -270;
+ offsets[audio_key] = -450;
+ offsets[shader_key] = -348;
+ default_layout->set_value(EDITOR_NODE_CONFIG_SECTION, "bottom_panel_offsets", offsets);
+ }
+
+ _update_layouts_menu();
}
EditorNode::~EditorNode() {
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 7ad2b3cab5b..6a75701615a 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -289,7 +289,6 @@ private:
HashMap<String, EditorPlugin *> addon_name_to_plugin;
LocalVector<String> pending_addons;
HashMap<ObjectID, HashSet<EditorPlugin *>> active_plugins;
- bool is_main_screen_editing = false;
Control *gui_base = nullptr;
VBoxContainer *main_vbox = nullptr;
diff --git a/editor/gui/editor_title_bar.cpp b/editor/gui/editor_title_bar.cpp
index 6e15c9abe59..a9c54b46e42 100644
--- a/editor/gui/editor_title_bar.cpp
+++ b/editor/gui/editor_title_bar.cpp
@@ -87,6 +87,10 @@ void EditorTitleBar::gui_input(const Ref<InputEvent> &p_event) {
void EditorTitleBar::set_center_control(Control *p_center_control) {
center_control = p_center_control;
+
+ if (center_control->get_parent() != this) {
+ center_control->reparent(this);
+ }
}
Control *EditorTitleBar::get_center_control() const {
@@ -155,8 +159,11 @@ void EditorTitleBar::_notification(int p_what) {
offset = CLAMP(offset, min_offset, max_offset);
fit_child_in_rect(prev, Rect2i(prev->get_position().x, 0, offset - prev->get_position().x, title_size.height));
- fit_child_in_rect(base, Rect2i(offset, 0, c_size.width, title_size.height));
fit_child_in_rect(next, Rect2i(offset + c_size.width, 0, next->get_position().x + next->get_size().x - (offset + c_size.width), title_size.height));
+
+ int center = title_size.x / 2;
+ int width = MIN(center - prev->get_position().x, next->get_end().x - center) * 1.9;
+ fit_child_in_rect(base, Rect2i(center - width / 2, 0, width, title_size.height));
}
} break;
}
diff --git a/editor/inspector/editor_inspector.cpp b/editor/inspector/editor_inspector.cpp
index ba3a7fad6c4..78d65132fa9 100644
--- a/editor/inspector/editor_inspector.cpp
+++ b/editor/inspector/editor_inspector.cpp
@@ -41,7 +41,6 @@
#include "editor/doc/doc_tools.h"
#include "editor/docks/inspector_dock.h"
#include "editor/editor_interface.h"
-#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
@@ -1629,7 +1628,7 @@ void EditorProperty::menu_option(int p_option) {
} break;
case MENU_OPEN_DOCUMENTATION: {
ScriptEditor::get_singleton()->goto_help(doc_path);
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor();
} break;
default: {
if (p_option >= EditorContextMenuPlugin::BASE_ID) {
@@ -2101,7 +2100,7 @@ void EditorInspectorCategory::_handle_menu_option(int p_option) {
case MENU_OPEN_DOCS: {
ScriptEditor::get_singleton()->goto_help("class:" + doc_class_name);
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor();
} break;
case MENU_UNFAVORITE_ALL: {
@@ -2980,7 +2979,7 @@ void EditorInspectorSection::menu_option(int p_option) {
case MENU_OPEN_DOCUMENTATION: {
ScriptEditor::get_singleton()->goto_help(doc_path);
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor();
} break;
}
}
diff --git a/editor/plugins/editor_plugin.cpp b/editor/plugins/editor_plugin.cpp
index 0a0753e8331..26e2276fc17 100644
--- a/editor/plugins/editor_plugin.cpp
+++ b/editor/plugins/editor_plugin.cpp
@@ -41,6 +41,7 @@
#include "editor/docks/inspector_dock.h"
#include "editor/docks/scene_tree_dock.h"
#include "editor/editor_interface.h"
+#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/export/editor_export.h"
@@ -617,6 +618,12 @@ void EditorPlugin::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorPlugin::_editor_project_settings_changed));
+ // When the plugin registers a main screen (which usually should happen when entering tree), this allows to recognize it as the owner.
+ EditorNode::get_editor_main_screen()->adding_plugin = this;
+ } break;
+
+ case NOTIFICATION_POST_ENTER_TREE: {
+ EditorNode::get_editor_main_screen()->adding_plugin = nullptr;
} break;
case NOTIFICATION_EXIT_TREE: {
diff --git a/editor/plugins/editor_plugin.h b/editor/plugins/editor_plugin.h
index bd8178fa4ed..5a3993b6735 100644
--- a/editor/plugins/editor_plugin.h
+++ b/editor/plugins/editor_plugin.h
@@ -200,7 +200,6 @@ public:
virtual bool has_main_screen() const;
virtual void make_visible(bool p_visible);
virtual void set_current() {}
- virtual void selected_notify() {} //notify that it was raised by the user, not the editor
virtual void edit(Object *p_object);
virtual bool handles(Object *p_object) const;
virtual bool can_auto_hide() const;
diff --git a/editor/run/game_view_plugin.cpp b/editor/run/game_view_plugin.cpp
index 79938b15067..37fe65d4ed6 100644
--- a/editor/run/game_view_plugin.cpp
+++ b/editor/run/game_view_plugin.cpp
@@ -37,6 +37,8 @@
#include "core/string/translation_server.h"
#include "editor/debugger/editor_debugger_node.h"
#include "editor/debugger/script_editor_debugger.h"
+#include "editor/docks/editor_dock.h"
+#include "editor/docks/editor_dock_manager.h"
#include "editor/editor_interface.h"
#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
@@ -46,6 +48,7 @@
#include "editor/run/editor_run_bar.h"
#include "editor/run/embedded_process.h"
#include "editor/run/run_instances_dialog.h"
+#include "editor/scene/canvas_item_editor_plugin.h"
#include "editor/script/script_editor_plugin.h"
#include "editor/settings/editor_feature_profile.h"
#include "editor/settings/editor_settings.h"
@@ -558,7 +561,7 @@ void GameView::_play_pressed() {
}
if (!window_wrapper->get_window_enabled()) {
- screen_index_before_start = EditorNode::get_singleton()->get_editor_main_screen()->get_selected_index();
+ screen_index_before_start = EditorNode::get_singleton()->get_editor_main_screen()->get_current_tab();
}
if (embed_on_play && _get_embed_available() == EMBED_AVAILABLE) {
@@ -568,7 +571,7 @@ void GameView::_play_pressed() {
EditorNode::get_singleton()->set_unfocused_low_processor_usage_mode_enabled(false);
_update_embed_window_size();
if (!window_wrapper->get_window_enabled()) {
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_GAME);
+ game_dock->make_visible();
// Reset the normal size of the bottom panel when fully expanded.
EditorNode::get_singleton()->get_bottom_panel()->set_expanded(false);
@@ -597,9 +600,9 @@ void GameView::_stop_pressed() {
window_wrapper->set_window_enabled(false);
}
- if (screen_index_before_start >= 0 && EditorNode::get_singleton()->get_editor_main_screen()->get_selected_index() == EditorMainScreen::EDITOR_GAME) {
+ if (screen_index_before_start >= 0 && EditorNode::get_singleton()->get_editor_main_screen()->get_current_tab_control() == game_dock) {
// We go back to the screen where the user was before starting the game.
- EditorNode::get_singleton()->get_editor_main_screen()->select(screen_index_before_start);
+ EditorNode::get_singleton()->get_editor_main_screen()->set_current_tab(screen_index_before_start);
}
screen_index_before_start = -1;
@@ -621,7 +624,7 @@ void GameView::_embedding_failed() {
void GameView::_embedded_process_focused() {
if (embed_on_play && !window_wrapper->get_window_enabled()) {
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_GAME);
+ game_dock->make_visible();
}
}
@@ -1307,8 +1310,8 @@ void GameView::_detach_script_debugger() {
embedded_process->set_script_debugger(nullptr);
}
-void GameView::_remote_window_title_changed(String title) {
- window_wrapper->set_window_title(title);
+void GameView::_remote_window_title_changed(const String &p_title) {
+ window_wrapper->set_window_title(p_title);
}
void GameView::_update_arguments_for_instance(int p_idx, List<String> &r_arguments) {
@@ -1391,7 +1394,7 @@ void GameView::_update_arguments_for_instance(int p_idx, List<String> &r_argumen
Size2 old_min_size = embedded_process->get_custom_minimum_size();
embedded_process->set_custom_minimum_size(Size2i());
- Control *container = EditorNode::get_singleton()->get_editor_main_screen()->get_control();
+ Control *container = game_dock;
rect = container->get_global_rect();
Size2 wrapped_min_size = window_wrapper->get_minimum_size();
@@ -1476,6 +1479,13 @@ void GameView::_feature_profile_changed() {
GameView::GameView(Ref<GameViewDebugger> p_debugger, EmbeddedProcessBase *p_embedded_process, WindowWrapper *p_wrapper) {
singleton = this;
+ game_dock = memnew(EditorDock);
+ game_dock->set_name(TTRC("Game"));
+ game_dock->set_icon_name("Game");
+ game_dock->set_available_layouts(EditorDock::DOCK_LAYOUT_MAIN_SCREEN);
+ game_dock->set_default_slot(EditorDock::DOCK_SLOT_MAIN_SCREEN);
+ game_dock->set_dock_shortcut(ED_GET_SHORTCUT("editor/editor_game"));
+
debugger = p_debugger;
window_wrapper = p_wrapper;
embedded_process = p_embedded_process;
@@ -1763,26 +1773,28 @@ GameView::GameView(Ref<GameViewDebugger> p_debugger, EmbeddedProcessBase *p_embe
///////
-void GameViewPluginBase::selected_notify() {
- if (_is_window_wrapper_enabled()) {
-#ifdef ANDROID_ENABLED
- notify_main_screen_changed(get_plugin_name());
-#else
- window_wrapper->grab_window_focus();
-#endif // ANDROID_ENABLED
- _focus_another_editor();
- }
-}
-
-#ifndef ANDROID_ENABLED
void GameViewPluginBase::make_visible(bool p_visible) {
if (p_visible) {
+#ifndef ANDROID_ENABLED
window_wrapper->show();
+#endif // ANDROID_ENABLED
+
+ if (_is_window_wrapper_enabled()) {
+#ifdef ANDROID_ENABLED
+ notify_main_screen_changed(get_plugin_name());
+#else
+ window_wrapper->grab_window_focus();
+#endif // ANDROID_ENABLED
+ _focus_another_editor();
+ }
} else {
+#ifndef ANDROID_ENABLED
window_wrapper->hide();
+#endif // ANDROID_ENABLED
}
}
+#ifndef ANDROID_ENABLED
void GameViewPluginBase::set_window_layout(Ref<ConfigFile> p_layout) {
game_view->set_window_layout(p_layout);
}
@@ -1802,9 +1814,10 @@ void GameViewPluginBase::setup(Ref<GameViewDebugger> p_debugger, EmbeddedProcess
window_wrapper->set_wrapped_control(game_view, nullptr);
- EditorNode::get_singleton()->get_editor_main_screen()->get_control()->add_child(window_wrapper);
+ GameView::get_dock()->add_child(window_wrapper);
+
+ EditorDockManager::get_singleton()->add_dock(GameView::get_dock());
window_wrapper->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- window_wrapper->hide();
window_wrapper->connect("window_visibility_changed", callable_mp(this, &GameViewPlugin::_focus_another_editor).unbind(1));
}
@@ -1836,8 +1849,8 @@ void GameViewPluginBase::_save_last_editor(const String &p_editor) {
void GameViewPluginBase::_focus_another_editor() {
if (_is_window_wrapper_enabled()) {
- if (last_editor.is_empty() || (last_editor == "Script" && ScriptEditor::get_singleton()->is_editor_floating())) {
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_2D);
+ if (last_editor.is_empty() || (last_editor == "Script" && ScriptEditor::get_singleton()->get_current_layout() == EditorDock::DOCK_LAYOUT_FLOATING)) {
+ CanvasItemEditor::get_singleton()->make_visible();
} else {
EditorInterface::get_singleton()->set_main_screen_editor(last_editor);
}
@@ -1864,5 +1877,29 @@ GameViewPlugin::GameViewPlugin() {
game_view_debugger.instantiate();
EmbeddedProcess *embedded_process = memnew(EmbeddedProcess);
setup(game_view_debugger, embedded_process);
+#else
+ setup_android();
#endif
}
+
+#ifdef ANDROID_ENABLED
+void GameViewPluginBase::setup_android() {
+ EditorDock *game_dock = memnew(EditorDock);
+ game_dock->set_name(TTRC("Game"));
+ game_dock->set_icon_name("Game");
+ game_dock->set_available_layouts(EditorDock::DOCK_LAYOUT_MAIN_SCREEN);
+ game_dock->set_default_slot(EditorDock::DOCK_SLOT_MAIN_SCREEN);
+ game_dock->set_dock_shortcut(ED_GET_SHORTCUT("editor/editor_game"));
+
+ EditorDockManager::get_singleton()->add_dock(game_dock);
+ game_dock->get_parent_container()->connect("tab_changed", callable_mp(this, &GameViewPluginBase::_main_screen_tab_changed).bind(game_dock).unbind(1));
+}
+
+void GameViewPluginBase::_main_screen_tab_changed(EditorDock *game_dock) {
+ if (game_dock->is_visible_in_tree()) {
+ EditorNode::get_editor_main_screen()->set_current_tab(previous_tab);
+ } else {
+ previous_tab = EditorNode::get_editor_main_screen()->get_current_tab();
+ }
+}
+#endif
diff --git a/editor/run/game_view_plugin.h b/editor/run/game_view_plugin.h
index 183c70c42d7..c2a3fa4e4d8 100644
--- a/editor/run/game_view_plugin.h
+++ b/editor/run/game_view_plugin.h
@@ -41,6 +41,7 @@ class EmbeddedProcessBase;
class VSeparator;
class WindowWrapper;
class ScriptEditorDebugger;
+class EditorDock;
class GameViewDebugger : public EditorDebuggerPlugin {
GDCLASS(GameViewDebugger, EditorDebuggerPlugin);
@@ -163,6 +164,7 @@ class GameView : public VBoxContainer {
Ref<GameViewDebugger> debugger;
WindowWrapper *window_wrapper = nullptr;
+ EditorDock *game_dock = nullptr;
bool is_feature_enabled = true;
int active_sessions = 0;
@@ -274,7 +276,7 @@ class GameView : public VBoxContainer {
void _update_floating_window_settings();
void _attach_script_debugger();
void _detach_script_debugger();
- void _remote_window_title_changed(String title);
+ void _remote_window_title_changed(const String &p_title);
void _debugger_breaked(bool p_breaked, bool p_can_debug);
@@ -284,8 +286,12 @@ protected:
void _notification(int p_what);
public:
- void set_state(const Dictionary &p_state);
- Dictionary get_state() const;
+ static EditorDock *get_dock() {
+ if (singleton) {
+ return singleton->game_dock;
+ }
+ return nullptr;
+ }
void set_window_layout(Ref<ConfigFile> p_layout);
void get_window_layout(Ref<ConfigFile> p_layout);
@@ -307,6 +313,9 @@ class GameViewPluginBase : public EditorPlugin {
#ifndef ANDROID_ENABLED
void _window_visibility_changed(bool p_visible);
+#else
+ int previous_tab = 0;
+ void _main_screen_tab_changed(EditorDock *game_dock);
#endif // ANDROID_ENABLED
void _save_last_editor(const String &p_editor);
void _focus_another_editor();
@@ -316,20 +325,20 @@ protected:
void _notification(int p_what);
#ifndef ANDROID_ENABLED
void setup(Ref<GameViewDebugger> p_debugger, EmbeddedProcessBase *p_embedded_process);
+#else
+ void setup_android();
#endif
public:
- virtual String get_plugin_name() const override { return TTRC("Game"); }
- bool has_main_screen() const override { return true; }
+ virtual String get_plugin_name() const override { return "Game"; }
virtual void edit(Object *p_object) override {}
virtual bool handles(Object *p_object) const override { return false; }
- virtual void selected_notify() override;
Ref<GameViewDebugger> get_debugger() const { return debugger; }
-#ifndef ANDROID_ENABLED
virtual void make_visible(bool p_visible) override;
+#ifndef ANDROID_ENABLED
virtual void set_window_layout(Ref<ConfigFile> p_layout) override;
virtual void get_window_layout(Ref<ConfigFile> p_layout) override;
#endif // ANDROID_ENABLED
diff --git a/editor/scene/3d/node_3d_editor_plugin.cpp b/editor/scene/3d/node_3d_editor_plugin.cpp
index a3e23fc2141..3a45c53c2cc 100644
--- a/editor/scene/3d/node_3d_editor_plugin.cpp
+++ b/editor/scene/3d/node_3d_editor_plugin.cpp
@@ -40,6 +40,7 @@
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "editor/debugger/editor_debugger_node.h"
+#include "editor/docks/editor_dock_manager.h"
#include "editor/docks/scene_tree_dock.h"
#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
@@ -97,6 +98,7 @@
#include "scene/gui/color_picker.h"
#include "scene/gui/flow_container.h"
#include "scene/gui/menu_button.h"
+#include "scene/gui/panel_container.h"
#include "scene/gui/rich_text_label.h"
#include "scene/gui/separator.h"
#include "scene/gui/spin_box.h"
@@ -2449,13 +2451,11 @@ void Node3DEditor::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_theme();
- _register_all_gizmos();
- _init_indicators();
- update_all_gizmos();
- } break;
-
- case NOTIFICATION_EXIT_TREE: {
- _finish_indicators();
+ if (move_gizmo[0].is_null()) {
+ _register_all_gizmos();
+ _init_indicators();
+ update_all_gizmos();
+ }
} break;
case NOTIFICATION_PROCESS: {
@@ -3228,12 +3228,19 @@ void Node3DEditor::PreviewSunEnvPopup::shortcut_input(const Ref<InputEvent> &p_e
}
Node3DEditor::Node3DEditor() {
+ set_name(TTRC("3D"));
+ set_icon_name("3D");
+ set_available_layouts(EditorDock::DOCK_LAYOUT_MAIN_SCREEN | EditorDock::DOCK_LAYOUT_FLOATING);
+ set_default_slot(EditorDock::DOCK_SLOT_MAIN_SCREEN);
+ set_dock_shortcut(ED_GET_SHORTCUT("editor/editor_3d"));
+
gizmo.visible = true;
gizmo.scale = 1.0;
gizmo_view_rotation_scale = GIZMO_CIRCLE_SIZE * (float)EDITOR_GET("editors/3d/view_plane_rotation_gizmo_scale");
viewport_environment.instantiate();
- VBoxContainer *vbc = this;
+ VBoxContainer *vbc = memnew(VBoxContainer);
+ add_child(vbc);
ERR_FAIL_COND_MSG(singleton != nullptr, "A Node3DEditor singleton already exists.");
singleton = this;
@@ -3925,6 +3932,7 @@ void fragment() {
}
Node3DEditor::~Node3DEditor() {
singleton = nullptr;
+ _finish_indicators();
memdelete(preview_node);
if (preview_sun_dangling && preview_sun) {
memdelete(preview_sun);
@@ -3945,7 +3953,7 @@ void Node3DEditorPlugin::edited_scene_changed() {
void Node3DEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
- spatial_editor->show();
+ spatial_editor->make_visible();
spatial_editor->set_process(true);
spatial_editor->set_physics_process(true);
spatial_editor->refresh_dirty_gizmos();
@@ -3961,7 +3969,7 @@ void Node3DEditorPlugin::edit(Object *p_object) {
}
bool Node3DEditorPlugin::handles(Object *p_object) const {
- return p_object->is_class("Node3D");
+ return Object::cast_to<Node3D>(p_object);
}
Dictionary Node3DEditorPlugin::get_state() const {
@@ -4136,7 +4144,7 @@ Vector<Node3D *> Node3DEditor::gizmo_bvh_frustum_query(const Vector<Plane> &p_fr
Node3DEditorPlugin::Node3DEditorPlugin() {
spatial_editor = memnew(Node3DEditor);
spatial_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- EditorNode::get_singleton()->get_editor_main_screen()->get_control()->add_child(spatial_editor);
+ EditorDockManager::get_singleton()->add_dock(spatial_editor);
spatial_editor->hide();
}
diff --git a/editor/scene/3d/node_3d_editor_plugin.h b/editor/scene/3d/node_3d_editor_plugin.h
index 7e0bbe6fd92..a5d5b6cedec 100644
--- a/editor/scene/3d/node_3d_editor_plugin.h
+++ b/editor/scene/3d/node_3d_editor_plugin.h
@@ -31,6 +31,7 @@
#pragma once
#include "core/math/dynamic_bvh.h"
+#include "editor/docks/editor_dock.h"
#include "editor/plugins/editor_plugin.h"
#include "editor/scene/3d/node_3d_editor_gizmos.h"
#include "scene/debugger/view_3d_controller.h"
@@ -57,8 +58,8 @@ class VSeparator;
class VSplitContainer;
class WorldEnvironment;
-class Node3DEditor : public VBoxContainer {
- GDCLASS(Node3DEditor, VBoxContainer);
+class Node3DEditor : public EditorDock {
+ GDCLASS(Node3DEditor, EditorDock);
public:
static const unsigned int VIEWPORTS_COUNT = 4;
@@ -519,7 +520,7 @@ class Node3DEditorPlugin : public EditorPlugin {
public:
Node3DEditor *get_spatial_editor() { return spatial_editor; }
- virtual String get_plugin_name() const override { return TTRC("3D"); }
+ virtual String get_plugin_name() const override { return "3D"; }
bool has_main_screen() const override { return true; }
virtual void make_visible(bool p_visible) override;
virtual void edit(Object *p_object) override;
diff --git a/editor/scene/3d/node_3d_editor_viewport.cpp b/editor/scene/3d/node_3d_editor_viewport.cpp
index ba8e3c2a2f8..1f2426d9770 100644
--- a/editor/scene/3d/node_3d_editor_viewport.cpp
+++ b/editor/scene/3d/node_3d_editor_viewport.cpp
@@ -68,6 +68,7 @@
#include "scene/gui/rich_text_label.h"
#include "scene/gui/split_container.h"
#include "scene/gui/subviewport_container.h"
+#include "scene/main/node.h"
#include "scene/main/scene_tree.h"
#include "scene/resources/gradient.h"
#include "scene/resources/immediate_mesh.h"
@@ -3185,12 +3186,13 @@ void Node3DEditorViewport::_project_settings_changed() {
}
static void override_label_colors(Control *p_control) {
+ const Ref<Theme> &editor_theme = EditorNode::get_singleton()->get_editor_theme();
p_control->begin_bulk_theme_override();
- p_control->add_theme_color_override(SceneStringName(font_color), p_control->get_theme_color(SNAME("font_dark_background_color"), EditorStringName(Editor)));
- p_control->add_theme_color_override("font_hover_color", p_control->get_theme_color(SNAME("font_dark_background_hover_color"), EditorStringName(Editor)));
- p_control->add_theme_color_override("font_focus_color", p_control->get_theme_color(SNAME("font_dark_background_focus_color"), EditorStringName(Editor)));
- p_control->add_theme_color_override("font_pressed_color", p_control->get_theme_color(SNAME("font_dark_background_pressed_color"), EditorStringName(Editor)));
- p_control->add_theme_color_override("font_hover_pressed_color", p_control->get_theme_color(SNAME("font_dark_background_hover_pressed_color"), EditorStringName(Editor)));
+ p_control->add_theme_color_override(SceneStringName(font_color), editor_theme->get_color(SNAME("font_dark_background_color"), EditorStringName(Editor)));
+ p_control->add_theme_color_override("font_hover_color", editor_theme->get_color(SNAME("font_dark_background_hover_color"), EditorStringName(Editor)));
+ p_control->add_theme_color_override("font_focus_color", editor_theme->get_color(SNAME("font_dark_background_focus_color"), EditorStringName(Editor)));
+ p_control->add_theme_color_override("font_pressed_color", editor_theme->get_color(SNAME("font_dark_background_pressed_color"), EditorStringName(Editor)));
+ p_control->add_theme_color_override("font_hover_pressed_color", editor_theme->get_color(SNAME("font_dark_background_hover_pressed_color"), EditorStringName(Editor)));
p_control->end_bulk_theme_override();
}
@@ -3259,6 +3261,7 @@ void Node3DEditorViewport::_notification(int p_what) {
case NOTIFICATION_READY: {
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &Node3DEditorViewport::_project_settings_changed));
_update_navigation_controls_visibility();
+ _init_gizmo_instance(index);
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
@@ -3869,21 +3872,6 @@ void Node3DEditorViewport::_notification(int p_what) {
}
} break;
- case NOTIFICATION_ENTER_TREE: {
- surface->connect(SceneStringName(draw), callable_mp(this, &Node3DEditorViewport::_draw));
- surface->connect(SceneStringName(gui_input), callable_mp(this, &Node3DEditorViewport::_sinput));
- surface->connect(SceneStringName(mouse_entered), callable_mp(this, &Node3DEditorViewport::_surface_mouse_enter));
- surface->connect(SceneStringName(mouse_exited), callable_mp(this, &Node3DEditorViewport::_surface_mouse_exit));
- surface->connect(SceneStringName(focus_entered), callable_mp(this, &Node3DEditorViewport::_surface_focus_enter));
- surface->connect(SceneStringName(focus_exited), callable_mp(this, &Node3DEditorViewport::_surface_focus_exit));
-
- _init_gizmo_instance(index);
- } break;
-
- case NOTIFICATION_EXIT_TREE: {
- _finish_gizmo_instances();
- } break;
-
case NOTIFICATION_THEME_CHANGED: {
_update_centered_labels();
@@ -6787,7 +6775,6 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
c->add_child(viewport);
surface = memnew(Control);
SET_DRAG_FORWARDING_CD(surface, Node3DEditorViewport);
- add_child(surface);
surface->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
surface->set_clip_contents(true);
camera = memnew(Camera3D);
@@ -6796,6 +6783,14 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
viewport->add_child(camera);
camera->make_current();
surface->set_focus_mode(FOCUS_ALL);
+ add_child(surface);
+
+ surface->connect(SceneStringName(draw), callable_mp(this, &Node3DEditorViewport::_draw));
+ surface->connect(SceneStringName(gui_input), callable_mp(this, &Node3DEditorViewport::_sinput));
+ surface->connect(SceneStringName(mouse_entered), callable_mp(this, &Node3DEditorViewport::_surface_mouse_enter));
+ surface->connect(SceneStringName(mouse_exited), callable_mp(this, &Node3DEditorViewport::_surface_mouse_exit));
+ surface->connect(SceneStringName(focus_entered), callable_mp(this, &Node3DEditorViewport::_surface_focus_enter));
+ surface->connect(SceneStringName(focus_exited), callable_mp(this, &Node3DEditorViewport::_surface_focus_exit));
VBoxContainer *vbox = memnew(VBoxContainer);
surface->add_child(vbox);
@@ -7221,6 +7216,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
}
Node3DEditorViewport::~Node3DEditorViewport() {
+ _finish_gizmo_instances();
memdelete(ruler);
}
diff --git a/editor/scene/canvas_item_editor_plugin.cpp b/editor/scene/canvas_item_editor_plugin.cpp
index 2432fe0e0f4..9b66207a073 100644
--- a/editor/scene/canvas_item_editor_plugin.cpp
+++ b/editor/scene/canvas_item_editor_plugin.cpp
@@ -40,6 +40,7 @@
#include "core/string/translation_server.h"
#include "editor/animation/animation_player_editor_plugin.h"
#include "editor/debugger/editor_debugger_node.h"
+#include "editor/docks/editor_dock_manager.h"
#include "editor/docks/scene_tree_dock.h"
#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
@@ -4518,6 +4519,18 @@ void CanvasItemEditor::_notification(int p_what) {
} break;
case NOTIFICATION_READY: {
+ select_sb->set_texture(get_editor_theme_icon(SNAME("EditorRect2D")));
+ select_sb->set_texture_margin_all(4);
+ select_sb->set_content_margin_all(4);
+
+ AnimationPlayerEditor::get_singleton()->get_track_editor()->connect("keying_changed", callable_mp(this, &CanvasItemEditor::_keying_changed));
+ AnimationPlayerEditor::get_singleton()->connect("animation_selected", callable_mp(this, &CanvasItemEditor::_keying_changed).unbind(1));
+ _keying_changed();
+ _update_editor_settings();
+
+ connect("item_lock_status_changed", callable_mp(this, &CanvasItemEditor::_update_lock_and_group_button));
+ connect("item_group_status_changed", callable_mp(this, &CanvasItemEditor::_update_lock_and_group_button));
+
_update_lock_and_group_button();
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &CanvasItemEditor::_project_settings_changed));
@@ -4597,20 +4610,6 @@ void CanvasItemEditor::_notification(int p_what) {
}
} break;
- case NOTIFICATION_ENTER_TREE: {
- select_sb->set_texture(get_editor_theme_icon(SNAME("EditorRect2D")));
- select_sb->set_texture_margin_all(4);
- select_sb->set_content_margin_all(4);
-
- AnimationPlayerEditor::get_singleton()->get_track_editor()->connect("keying_changed", callable_mp(this, &CanvasItemEditor::_keying_changed));
- AnimationPlayerEditor::get_singleton()->connect("animation_selected", callable_mp(this, &CanvasItemEditor::_keying_changed).unbind(1));
- _keying_changed();
- _update_editor_settings();
-
- connect("item_lock_status_changed", callable_mp(this, &CanvasItemEditor::_update_lock_and_group_button));
- connect("item_group_status_changed", callable_mp(this, &CanvasItemEditor::_update_lock_and_group_button));
- } break;
-
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
if (EditorThemeManager::is_generated_theme_outdated() ||
EditorSettings::get_singleton()->check_changed_settings_in_group("editors/panning") ||
@@ -4627,6 +4626,18 @@ void CanvasItemEditor::_notification(int p_what) {
_commit_drag();
}
} break;
+
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ if (is_visible_in_tree()) {
+ set_process(true);
+ RenderingServer::get_singleton()->viewport_set_disable_2d(EditorNode::get_singleton()->get_scene_root()->get_viewport_rid(), false);
+ RenderingServer::get_singleton()->viewport_set_environment_mode(EditorNode::get_singleton()->get_scene_root()->get_viewport_rid(), RSE::VIEWPORT_ENVIRONMENT_ENABLED);
+ } else {
+ set_process(false);
+ RenderingServer::get_singleton()->viewport_set_disable_2d(EditorNode::get_singleton()->get_scene_root()->get_viewport_rid(), true);
+ RenderingServer::get_singleton()->viewport_set_environment_mode(EditorNode::get_singleton()->get_scene_root()->get_viewport_rid(), RSE::VIEWPORT_ENVIRONMENT_DISABLED);
+ }
+ } break;
}
}
@@ -5736,6 +5747,12 @@ void CanvasItemEditor::center_at(const Point2 &p_pos) {
}
CanvasItemEditor::CanvasItemEditor() {
+ set_name(TTRC("2D"));
+ set_icon_name("2D");
+ set_available_layouts(EditorDock::DOCK_LAYOUT_MAIN_SCREEN | EditorDock::DOCK_LAYOUT_FLOATING);
+ set_default_slot(EditorDock::DOCK_SLOT_MAIN_SCREEN);
+ set_dock_shortcut(ED_GET_SHORTCUT("editor/editor_2d"));
+
snap_target[0] = SNAP_TARGET_NONE;
snap_target[1] = SNAP_TARGET_NONE;
@@ -5744,9 +5761,12 @@ CanvasItemEditor::CanvasItemEditor() {
editor_selection->connect("selection_changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
editor_selection->connect("selection_changed", callable_mp(this, &CanvasItemEditor::_selection_changed));
+ VBoxContainer *main_vb = memnew(VBoxContainer);
+ add_child(main_vb);
+
MarginContainer *toolbar_margin = memnew(MarginContainer);
toolbar_margin->set_theme_type_variation("MainToolBarMargin");
- add_child(toolbar_margin);
+ main_vb->add_child(toolbar_margin);
// A fluid container for all toolbars.
HFlowContainer *main_flow = memnew(HFlowContainer);
@@ -5760,7 +5780,7 @@ CanvasItemEditor::CanvasItemEditor() {
main_flow->add_child(tool_button_hbox);
bottom_split = memnew(VSplitContainer);
- add_child(bottom_split);
+ main_vb->add_child(bottom_split);
bottom_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
left_panel_split = memnew(HSplitContainer);
@@ -6278,21 +6298,12 @@ void CanvasItemEditorPlugin::edit(Object *p_object) {
}
bool CanvasItemEditorPlugin::handles(Object *p_object) const {
- return p_object->is_class("CanvasItem");
+ return Object::cast_to<CanvasItem>(p_object);
}
void CanvasItemEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
- canvas_item_editor->show();
- canvas_item_editor->set_process(true);
- RenderingServer::get_singleton()->viewport_set_disable_2d(EditorNode::get_singleton()->get_scene_root()->get_viewport_rid(), false);
- RenderingServer::get_singleton()->viewport_set_environment_mode(EditorNode::get_singleton()->get_scene_root()->get_viewport_rid(), RSE::VIEWPORT_ENVIRONMENT_ENABLED);
-
- } else {
- canvas_item_editor->hide();
- canvas_item_editor->set_process(false);
- RenderingServer::get_singleton()->viewport_set_disable_2d(EditorNode::get_singleton()->get_scene_root()->get_viewport_rid(), true);
- RenderingServer::get_singleton()->viewport_set_environment_mode(EditorNode::get_singleton()->get_scene_root()->get_viewport_rid(), RSE::VIEWPORT_ENVIRONMENT_DISABLED);
+ canvas_item_editor->make_visible();
}
}
@@ -6319,10 +6330,7 @@ void CanvasItemEditorPlugin::_notification(int p_what) {
CanvasItemEditorPlugin::CanvasItemEditorPlugin() {
canvas_item_editor = memnew(CanvasItemEditor);
- canvas_item_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- EditorNode::get_singleton()->get_editor_main_screen()->get_control()->add_child(canvas_item_editor);
- canvas_item_editor->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
- canvas_item_editor->hide();
+ EditorDockManager::get_singleton()->add_dock(canvas_item_editor);
}
void CanvasItemEditorViewport::_on_mouse_exit() {
diff --git a/editor/scene/canvas_item_editor_plugin.h b/editor/scene/canvas_item_editor_plugin.h
index acee9ac57cb..2ffcfc810f3 100644
--- a/editor/scene/canvas_item_editor_plugin.h
+++ b/editor/scene/canvas_item_editor_plugin.h
@@ -30,6 +30,7 @@
#pragma once
+#include "editor/docks/editor_dock.h"
#include "editor/plugins/editor_plugin.h"
#include "scene/gui/box_container.h"
@@ -73,8 +74,8 @@ public:
Dictionary undo_state;
};
-class CanvasItemEditor : public VBoxContainer {
- GDCLASS(CanvasItemEditor, VBoxContainer);
+class CanvasItemEditor : public EditorDock {
+ GDCLASS(CanvasItemEditor, EditorDock);
public:
enum Tool {
@@ -649,7 +650,7 @@ protected:
void _notification(int p_what);
public:
- virtual String get_plugin_name() const override { return TTRC("2D"); }
+ virtual String get_plugin_name() const override { return "2D"; }
bool has_main_screen() const override { return true; }
virtual void edit(Object *p_object) override;
virtual bool handles(Object *p_object) const override;
diff --git a/editor/scene/connections_dialog.cpp b/editor/scene/connections_dialog.cpp
index 6c73dcb069c..2d1be127ace 100644
--- a/editor/scene/connections_dialog.cpp
+++ b/editor/scene/connections_dialog.cpp
@@ -38,7 +38,6 @@
#include "editor/doc/editor_help.h"
#include "editor/docks/scene_tree_dock.h"
#include "editor/docks/signals_dock.h"
-#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/editor_undo_redo_manager.h"
@@ -1293,7 +1292,7 @@ void ConnectionsDock::_go_to_method(TreeItem &p_item) {
}
if (scr.is_valid() && ScriptEditor::get_singleton()->script_goto_method(scr, cd.method)) {
- EditorNode::get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_script_editor(scr); // TODO: Move this to goto_method().
}
}
@@ -1301,7 +1300,7 @@ void ConnectionsDock::_handle_class_menu_option(int p_option) {
switch (p_option) {
case CLASS_MENU_OPEN_DOCS:
ScriptEditor::get_singleton()->goto_help("class:" + class_menu_doc_class_name);
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor(); // TODO: Move this to goto_help().
break;
}
}
@@ -1331,7 +1330,7 @@ void ConnectionsDock::_handle_signal_menu_option(int p_option) {
} break;
case SIGNAL_MENU_OPEN_DOCS: {
ScriptEditor::get_singleton()->goto_help("class_signal:" + String(meta["class"]) + ":" + String(meta["name"]));
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor();
} break;
}
}
diff --git a/editor/scene/editor_scene_tabs.cpp b/editor/scene/editor_scene_tabs.cpp
index 6f08e9ec1bf..556069d53b8 100644
--- a/editor/scene/editor_scene_tabs.cpp
+++ b/editor/scene/editor_scene_tabs.cpp
@@ -42,6 +42,7 @@
#include "editor/inspector/editor_context_menu_plugin.h"
#include "editor/inspector/editor_resource_preview.h"
#include "editor/run/editor_run_bar.h"
+#include "editor/run/game_view_plugin.h"
#include "editor/settings/editor_settings.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/box_container.h"
@@ -108,7 +109,7 @@ void EditorSceneTabs::_scene_tab_hovered(int p_tab) {
// Currently the tab previews are displayed under the running game process when embed.
// Right now, the easiest technique to fix that is to prevent displaying the tab preview
// when the user is in the Game View.
- if (EditorNode::get_singleton()->get_editor_main_screen()->get_selected_index() == EditorMainScreen::EDITOR_GAME && EditorRunBar::get_singleton()->is_playing()) {
+ if (EditorNode::get_singleton()->get_editor_main_screen()->get_current_tab_control() == GameView::get_dock() && EditorRunBar::get_singleton()->is_playing()) {
return;
}
diff --git a/editor/scene/scene_tree_editor.cpp b/editor/scene/scene_tree_editor.cpp
index 3a487edbdf4..334bc5f48ec 100644
--- a/editor/scene/scene_tree_editor.cpp
+++ b/editor/scene/scene_tree_editor.cpp
@@ -108,7 +108,7 @@ void SceneTreeEditor::_gui_input(const Ref<InputEvent> &p_event) {
TreeItem *tree_item = tree->get_item_at_position(tree_mouse_pos);
ERR_FAIL_NULL(tree_item);
NodePath node_path = tree_item->get_metadata(0);
- Node *node = get_node_or_null(node_path);
+ Node *node = get_scene_node()->get_node_or_null(node_path);
if (node != nullptr) {
visibility_drag_value = !node->call("is_visible");
visibility_drag_start_pos = tree_mouse_pos;
@@ -158,7 +158,7 @@ void SceneTreeEditor::_gui_input(const Ref<InputEvent> &p_event) {
TreeItem *tree_item = tree->get_item_at_position(tree_mouse_pos);
ERR_FAIL_NULL(tree_item);
NodePath node_path = tree_item->get_metadata(0);
- Node *node = get_node_or_null(node_path);
+ Node *node = get_scene_node()->get_node_or_null(node_path);
if (node != nullptr && (bool)node->call("is_visible") != visibility_drag_value) {
node->call("set_visible", visibility_drag_value);
visibility_drag_nodes.push_back(node->get_instance_id());
@@ -191,7 +191,7 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
NodePath np = item->get_metadata(0);
- Node *n = get_node(np);
+ Node *n = _get_node(np);
ERR_FAIL_NULL(n);
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
@@ -364,7 +364,7 @@ void SceneTreeEditor::_update_node_path(Node *p_node, bool p_recursive) {
return;
}
- I->value.item->set_metadata(0, p_node->get_path());
+ I->value.item->set_metadata(0, _get_node_path(p_node));
if (!p_recursive) {
return;
@@ -516,7 +516,7 @@ void SceneTreeEditor::_update_node(Node *p_node, TreeItem *p_item, bool p_part_o
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(p_node);
p_item->set_icon(0, icon);
- p_item->set_metadata(0, p_node->get_path());
+ p_item->set_metadata(0, _get_node_path(p_node));
if (!p_node->is_connected("child_order_changed", callable_mp(this, &SceneTreeEditor::_node_child_order_changed))) {
p_node->connect("child_order_changed", callable_mp(this, &SceneTreeEditor::_node_child_order_changed).bind(p_node));
@@ -818,10 +818,10 @@ void SceneTreeEditor::_node_visibility_changed(Node *p_node) {
}
TreeItem *item;
- if (I->value.item && I->value.item->get_metadata(0) == p_node->get_path()) {
+ if (I->value.item && I->value.item->get_metadata(0) == _get_node_path(p_node)) {
item = I->value.item;
} else {
- item = _find(tree->get_root(), p_node->get_path());
+ item = _find(tree->get_root(), _get_node_path(p_node));
}
if (!item) {
@@ -1123,7 +1123,7 @@ bool SceneTreeEditor::_update_filter_helper(TreeItem *p_parent, bool p_scroll_to
bool is_root = p_parent == tree->get_root();
if (keep) {
- Node *n = get_node(p_parent->get_metadata(0));
+ Node *n = _get_node(p_parent->get_metadata(0));
if (!p_parent->is_visible() || (is_root && tree->is_root_hidden())) {
// Place back moved out children from when this item has hidden.
HashMap<Node *, CachedNode>::Iterator I = node_cache.get(n, false);
@@ -1209,7 +1209,7 @@ bool SceneTreeEditor::_update_filter_helper(TreeItem *p_parent, bool p_scroll_to
ti->select(0);
}
- HashMap<Node *, CachedNode>::Iterator I = node_cache.get(get_node(p_parent->get_metadata(0)), false);
+ HashMap<Node *, CachedNode>::Iterator I = node_cache.get(_get_node(p_parent->get_metadata(0)), false);
if (I) {
I->value.has_moved_children = true;
}
@@ -1230,7 +1230,7 @@ bool SceneTreeEditor::_update_filter_helper(TreeItem *p_parent, bool p_scroll_to
}
if (editor_selection) {
- Node *n = get_node(p_parent->get_metadata(0));
+ Node *n = _get_node(p_parent->get_metadata(0));
if (selectable) {
if (n && editor_selection->is_selected(n)) {
if (p_scroll_to_selected) {
@@ -1288,13 +1288,13 @@ bool SceneTreeEditor::_item_matches_all_terms(TreeItem *p_item, const PackedStri
if (parameter == "type" || parameter == "t") {
// Filter by Type.
- Node *item_node = get_node(p_item->get_metadata(0));
+ Node *item_node = _get_node(p_item->get_metadata(0));
if (!_node_matches_class_term(item_node, argument)) {
return false;
}
} else if (parameter == "group" || parameter == "g") {
// Filter by Group.
- Node *node = get_node(p_item->get_metadata(0));
+ Node *node = _get_node(p_item->get_metadata(0));
if (argument.is_empty()) {
// When argument is empty, match all Nodes belonging to any exposed group.
@@ -1401,7 +1401,7 @@ void SceneTreeEditor::_selected_changed() {
ERR_FAIL_NULL(s);
NodePath np = s->get_metadata(0);
- Node *n = get_node(np);
+ Node *n = _get_node(np);
if (n == selected) {
return;
@@ -1432,7 +1432,7 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_
NodePath np = item->get_metadata(0);
- Node *n = get_node(np);
+ Node *n = _get_node(np);
if (!n) {
return;
@@ -1518,12 +1518,12 @@ void SceneTreeEditor::_notification(int p_what) {
TreeItem *item = nullptr;
if (selected) {
// Scroll to selected node.
- item = _find(tree->get_root(), selected->get_path());
+ item = _find(tree->get_root(), _get_node_path(selected));
} else if (marked.size() == 1) {
// Scroll to a single marked node.
Node *marked_node = *marked.begin();
if (marked_node) {
- item = _find(tree->get_root(), marked_node->get_path());
+ item = _find(tree->get_root(), _get_node_path(marked_node));
}
}
@@ -1585,7 +1585,7 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
}
selected = p_node;
- TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : nullptr;
+ TreeItem *item = p_node ? _find(tree->get_root(), _get_node_path((p_node))) : nullptr;
if (item) {
if (auto_expand_selected) {
// Make visible when it's collapsed.
@@ -1625,7 +1625,7 @@ void SceneTreeEditor::rename_node(Node *p_node, const String &p_name, TreeItem *
if (p_item) {
item = p_item; // During batch rename the paths may change, so using _find() is unreliable.
} else {
- item = _find(tree->get_root(), p_node->get_path());
+ item = _find(tree->get_root(), _get_node_path(p_node));
}
ERR_FAIL_NULL(item);
bool check_for_unique_name_token = !p_name.is_empty() && p_name[0] == '%';
@@ -1744,7 +1744,7 @@ void SceneTreeEditor::rename_node(Node *p_node, const String &p_name, TreeItem *
if (check_for_unique_name_token) {
p_node->set_unique_name_in_owner(true);
}
- item->set_metadata(0, p_node->get_path());
+ item->set_metadata(0, _get_node_path(p_node));
emit_signal(SNAME("node_renamed"));
} else {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
@@ -1757,11 +1757,11 @@ void SceneTreeEditor::rename_node(Node *p_node, const String &p_name, TreeItem *
emit_signal(SNAME("node_prerename"), p_node, new_name);
undo_redo->add_undo_method(p_node, "set_name", p_node->get_name());
- undo_redo->add_undo_method(item, "set_metadata", 0, p_node->get_path());
+ undo_redo->add_undo_method(item, "set_metadata", 0, _get_node_path(p_node));
undo_redo->add_undo_method(item, "set_text", 0, p_node->get_name());
undo_redo->add_do_method(p_node, "set_name", new_name);
- undo_redo->add_do_method(item, "set_metadata", 0, p_node->get_path());
+ undo_redo->add_do_method(item, "set_metadata", 0, _get_node_path(p_node));
undo_redo->add_do_method(item, "set_text", 0, new_name);
if (check_for_unique_name_token) {
@@ -1781,7 +1781,7 @@ void SceneTreeEditor::_edited() {
if (is_scene_tree_dock && tree->get_next_selected(which)) {
List<Node *> nodes_to_rename;
for (TreeItem *item = which; item; item = tree->get_next_selected(item)) {
- Node *n = get_node(item->get_metadata(0));
+ Node *n = _get_node(item->get_metadata(0));
ERR_FAIL_NULL(n);
nodes_to_rename.push_back(n);
}
@@ -1799,7 +1799,7 @@ void SceneTreeEditor::_edited() {
undo_redo->commit_action();
} else {
- Node *n = get_node(which->get_metadata(0));
+ Node *n = _get_node(which->get_metadata(0));
ERR_FAIL_NULL(n);
rename_node(n, which->get_text(0));
}
@@ -1890,11 +1890,11 @@ void SceneTreeEditor::_update_selection(TreeItem *item) {
NodePath np = item->get_metadata(0);
- if (!has_node(np)) {
+ if (!get_scene_node()->has_node(np)) {
return;
}
- Node *n = get_node(np);
+ Node *n = _get_node(np);
if (!n) {
return;
@@ -1952,7 +1952,7 @@ void SceneTreeEditor::_cell_collapsed(Object *p_obj) {
NodePath np = ti->get_metadata(0);
- Node *n = get_node(np);
+ Node *n = _get_node(np);
ERR_FAIL_NULL(n);
n->set_display_folded(collapsed);
@@ -1973,7 +1973,7 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from
while (next) {
NodePath np = next->get_metadata(0);
- Node *n = get_node(np);
+ Node *n = _get_node(np);
if (n) {
selected_nodes.push_back(n);
icons.push_back(next->get_icon(0));
@@ -2027,6 +2027,14 @@ bool SceneTreeEditor::_is_script_type(const StringName &p_type) const {
return (script_types->has(p_type));
}
+NodePath SceneTreeEditor::_get_node_path(Node *p_node) const {
+ return get_scene_node()->get_path_to(p_node);
+}
+
+Node *SceneTreeEditor::_get_node(const NodePath &p_path) const {
+ return get_scene_node()->get_node(p_path);
+}
+
bool SceneTreeEditor::_has_drop_selection(TreeItem *p_item, const Point2 &p_point) const {
int section = (p_point == Vector2(Math::INF, Math::INF)) ? tree->get_drop_section_at_position(tree->get_item_rect(p_item).position) : tree->get_drop_section_at_position(p_point);
return !(section < -1 || (section == -1 && !p_item->get_parent()));
@@ -2140,7 +2148,7 @@ void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data,
}
NodePath np = item->get_metadata(0);
- Node *n = get_node(np);
+ Node *n = _get_node(np);
if (!n) {
return;
}
diff --git a/editor/scene/scene_tree_editor.h b/editor/scene/scene_tree_editor.h
index b199079e2c4..92991a5b358 100644
--- a/editor/scene/scene_tree_editor.h
+++ b/editor/scene/scene_tree_editor.h
@@ -229,6 +229,8 @@ class SceneTreeEditor : public Control {
LocalVector<StringName> *script_types;
bool _has_drop_selection(TreeItem *p_item, const Point2 &p_point) const;
bool _is_script_type(const StringName &p_type) const;
+ NodePath _get_node_path(Node *p_node) const;
+ Node *_get_node(const NodePath &p_path) const;
Vector<StringName> valid_types;
diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp
index e9eaa63f34e..80ee9163a61 100644
--- a/editor/script/script_editor_plugin.cpp
+++ b/editor/script/script_editor_plugin.cpp
@@ -47,6 +47,7 @@
#include "editor/debugger/script_editor_debugger.h"
#include "editor/doc/editor_help.h"
#include "editor/doc/editor_help_search.h"
+#include "editor/docks/editor_dock_manager.h"
#include "editor/docks/filesystem_dock.h"
#include "editor/docks/inspector_dock.h"
#include "editor/editor_interface.h"
@@ -144,6 +145,24 @@ void ScriptEditorQuickOpen::_bind_methods() {
ADD_SIGNAL(MethodInfo("goto_line", PropertyInfo(Variant::INT, "line")));
}
+void ScriptEditor::update_layout(EditorDock::DockLayout p_layout, int p_slot) {
+ if (this == bottom_script_editor) {
+ return;
+ }
+ begin_bulk_theme_override();
+ if (p_layout == DOCK_LAYOUT_FLOATING) {
+ remove_theme_constant_override("margin_left");
+ remove_theme_constant_override("margin_right");
+ remove_theme_constant_override("margin_bottom");
+ } else {
+ int margin = EditorNode::get_singleton()->get_editor_theme()->get_constant("base_margin", EditorStringName(Editor));
+ add_theme_constant_override("margin_left", margin);
+ add_theme_constant_override("margin_right", margin);
+ add_theme_constant_override("margin_bottom", margin);
+ }
+ end_bulk_theme_override();
+}
+
ScriptEditorQuickOpen::ScriptEditorQuickOpen() {
set_ok_button_text(TTRC("Open"));
get_ok_button()->set_disabled(true);
@@ -883,6 +902,12 @@ void ScriptEditor::_resource_created(Ref<Resource> p_res) {
EditorNode::get_singleton()->push_item(p_res.ptr());
}
+bool ScriptEditor::_should_use_external_editor(const Ref<Script> &p_for_script) {
+ bool use_external_editor = external_editor_active ||
+ (p_for_script.is_valid() && p_for_script->get_language()->overrides_external_editor());
+ return use_external_editor && !(p_for_script.is_valid() && p_for_script->is_built_in()); // Ignore external editor for built-in scripts.
+}
+
void ScriptEditor::_goto_script_line2(int p_line) {
if (TextEditorBase *current = Object::cast_to<TextEditorBase>(_get_current_editor())) {
ScriptEditorNavigationMarker::get_singleton()->locate_begin();
@@ -1671,10 +1696,7 @@ void ScriptEditor::_file_dialog_action(const String &p_file) {
[[fallthrough]];
}
case FILE_MENU_OPEN: {
- if (!is_visible_in_tree()) {
- // When created from outside the editor.
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
- }
+ make_visible();
open_file(p_file);
} break;
case FILE_MENU_SAVE_AS: {
@@ -2107,17 +2129,12 @@ void ScriptEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_apply_editor_settings();
- _floating_state_changed(get_window() != EditorNode::get_singleton()->get_window());
[[fallthrough]];
}
case NOTIFICATION_TRANSLATION_CHANGED: {
_update_filenames();
_update_online_doc();
- if (!make_floating->is_disabled()) {
- // Override default ScreenSelect tooltip if multi-window support is available.
- make_floating->set_tooltip_text(TTR("Make the editor floating.") + "\n" + TTR("Right-click to open the screen selector."));
- }
[[fallthrough]];
}
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
@@ -2152,9 +2169,6 @@ void ScriptEditor::_notification(int p_what) {
} break;
case NOTIFICATION_READY: {
- // Can't set own styles in NOTIFICATION_THEME_CHANGED, so for now this will do.
- add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("ScriptEditorPanel"), EditorStringName(EditorStyles)));
-
if (this == script_editor) {
InspectorDock::get_singleton()->connect("request_help", callable_mp(this, &ScriptEditor::_help_class_open));
EditorNode::get_singleton()->connect("request_help_search", callable_mp(this, &ScriptEditor::_help_search));
@@ -2328,8 +2342,21 @@ void ScriptEditor::ensure_select_current() {
_update_document_name_button();
}
-bool ScriptEditor::is_editor_floating() {
- return is_floating;
+void ScriptEditor::focus_editor() {
+ EditorDockManager::get_singleton()->focus_dock(this);
+ ScriptEditorBase *seb = Object::cast_to<ScriptEditorBase>(get_active_editor());
+ EditorHelp *eh = Object::cast_to<EditorHelp>(get_active_editor());
+ if (seb) {
+ seb->get_base_editor()->grab_focus();
+ } else if (eh) {
+ eh->set_focused();
+ }
+}
+
+void ScriptEditor::focus_script_editor(const Ref<Resource> &p_for_resource) {
+ if (!_should_use_external_editor(p_for_resource)) {
+ focus_editor();
+ }
}
void ScriptEditor::_connect_to_scene() {
@@ -2478,10 +2505,7 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col,
Ref<Script> scr = p_resource;
// Don't open dominant script if using an external editor.
- bool use_external_editor =
- external_editor_active ||
- (scr.is_valid() && scr->get_language()->overrides_external_editor());
- use_external_editor = use_external_editor && !(scr.is_valid() && scr->is_built_in()); // Ignore external editor for built-in scripts.
+ bool use_external_editor = _should_use_external_editor(p_resource);
const bool open_dominant = EDITOR_GET("text_editor/behavior/files/open_dominant_script_on_scene_change");
const bool should_open = (open_dominant && !use_external_editor) || !EditorNode::get_singleton()->is_changing_scene();
@@ -3229,6 +3253,10 @@ void ScriptEditor::_update_find_replace_bar() {
}
}
+void ScriptEditor::_update_margins() {
+ update_layout(get_current_layout(), get_current_slot());
+}
+
void ScriptEditor::_autosave_scripts() {
save_all_scripts();
}
@@ -3995,7 +4023,7 @@ void ScriptEditor::_on_find_in_files_result_selected(const String &fpath, int li
ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor());
if (ste) {
- callable_mp(EditorInterface::get_singleton(), &EditorInterface::set_main_screen_editor).call_deferred("Script");
+ callable_mp(this, &ScriptEditor::focus_editor).call_deferred();
if (line_number == 0) {
const int source_len = strlen(source_header);
ste->goto_line_selection(line_number, begin - source_len, end - source_len);
@@ -4016,7 +4044,7 @@ void ScriptEditor::_on_find_in_files_result_selected(const String &fpath, int li
ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor());
if (ste) {
- EditorInterface::get_singleton()->set_main_screen_editor("Script");
+ focus_script_editor(res);
ste->goto_line_selection(line_number - 1, begin, end);
}
ScriptEditorNavigationMarker::get_singleton()->locate_end();
@@ -4058,11 +4086,6 @@ void ScriptEditor::_update_code_editor_zoom_factor(CodeTextEditor *p_code_text_e
}
}
-void ScriptEditor::_floating_state_changed(bool p_floating) {
- make_floating->set_visible(!p_floating && !make_floating->is_disabled());
- is_floating = p_floating;
-}
-
void ScriptEditor::_bind_methods() {
ClassDB::bind_method("get_current_editor", &ScriptEditor::_get_current_editor);
ClassDB::bind_method("get_open_script_editors", &ScriptEditor::_get_open_script_editors);
@@ -4090,25 +4113,16 @@ void ScriptEditor::_bind_methods() {
ADD_SIGNAL(MethodInfo("script_close", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, Script::get_class_static())));
}
-ScriptEditor::ScriptEditor(const String &p_config_section, const String &p_cache_path, WindowWrapper *p_wrapper, EditorDock *p_dock) {
+ScriptEditor::ScriptEditor(const String &p_config_section, const String &p_cache_path) {
config_section = p_config_section;
cache_path = p_cache_path;
- // The main editor uses WindowWrapper while the shader editor uses EditorDock.
- if (p_wrapper) {
+
+ if (p_config_section == "ScriptEditor") {
script_editor = this;
} else {
bottom_script_editor = this;
}
- make_floating = memnew(ScreenSelect);
- make_floating->set_tooltip_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
-
- if (p_wrapper) {
- make_floating->connect("request_open_in_screen", callable_mp(p_wrapper, &WindowWrapper::enable_window_on_screen).bind(true));
- } else if (p_dock) {
- make_floating->connect("request_open_in_screen", callable_mp(p_dock, &EditorDock::make_floating));
- }
-
script_editor_cache.instantiate();
script_editor_cache->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join(cache_path));
@@ -4332,9 +4346,6 @@ ScriptEditor::ScriptEditor(const String &p_config_section, const String &p_cache
menu_hb->add_child(script_forward);
script_forward->connect(SceneStringName(pressed), callable_mp(this, &ScriptEditor::_history_forward));
- menu_hb->add_child(memnew(VSeparator));
- menu_hb->add_child(make_floating);
-
tab_container->connect("tab_changed", callable_mp(this, &ScriptEditor::ensure_select_current).unbind(1));
erase_tab_confirm = memnew(ConfirmationDialog);
@@ -4433,45 +4444,23 @@ ScriptEditor::ScriptEditor(const String &p_config_section, const String &p_cache
Ref<GDShaderSyntaxHighlighter> gdshader_syntax_highlighter;
gdshader_syntax_highlighter.instantiate();
register_syntax_highlighter(gdshader_syntax_highlighter);
-}
-ScriptEditor::~ScriptEditor() {
- ScriptEditorNavigationMarker::release_singleton();
-}
-
-void ScriptEditorPlugin::_focus_another_editor() {
- if (window_wrapper->get_window_enabled()) {
- ERR_FAIL_COND(last_editor.is_empty());
- EditorInterface::get_singleton()->set_main_screen_editor(last_editor);
+ if (this == script_editor) {
+ EditorNode::get_singleton()->get_gui_base()->connect(SceneStringName(theme_changed), callable_mp(this, &ScriptEditor::_update_margins));
}
}
-void ScriptEditorPlugin::_save_last_editor(const String &p_editor) {
- if (p_editor != get_plugin_name()) {
- last_editor = p_editor;
- }
+ScriptEditor::~ScriptEditor() {
+ ScriptEditorNavigationMarker::release_singleton();
}
-void ScriptEditorPlugin::_window_visibility_changed(bool p_visible) {
- _focus_another_editor();
- if (p_visible) {
- script_editor->add_theme_style_override(SceneStringName(panel), script_editor->get_theme_stylebox("ScriptEditorPanelFloating", EditorStringName(EditorStyles)));
- } else {
- script_editor->add_theme_style_override(SceneStringName(panel), script_editor->get_theme_stylebox("ScriptEditorPanel", EditorStringName(EditorStyles)));
+void ScriptEditorPlugin::shortcut_input(const Ref<InputEvent> &p_event) {
+ if (p_event.is_null() || !p_event->is_pressed() || p_event->is_echo()) {
+ return;
}
-}
-void ScriptEditorPlugin::_notification(int p_what) {
- switch (p_what) {
- case NOTIFICATION_TRANSLATION_CHANGED: {
- window_wrapper->set_window_title(vformat(TTR("%s - Godot Engine"), TTR("Script Editor")));
- } break;
- case NOTIFICATION_ENTER_TREE: {
- connect("main_screen_changed", callable_mp(this, &ScriptEditorPlugin::_save_last_editor));
- } break;
- case NOTIFICATION_EXIT_TREE: {
- disconnect("main_screen_changed", callable_mp(this, &ScriptEditorPlugin::_save_last_editor));
- } break;
+ if (make_floating_shortcut.is_valid() && make_floating_shortcut->matches_event(p_event)) {
+ script_editor->make_floating();
}
}
@@ -4541,7 +4530,10 @@ void ScriptEditorPlugin::edit(Object *p_object) {
Script *p_script = Object::cast_to<Script>(p_object);
String res_path = p_script->get_path().get_slice("::", 0);
- if (p_script->is_built_in() && !res_path.is_empty()) {
+ // Only update main editor screen if using in-engine editor.
+ if (!p_script->is_built_in() && (bool(EDITOR_GET("text_editor/external/use_external_editor")) || p_script->get_language()->overrides_external_editor())) {
+ skip_visible = true;
+ } else if (p_script->is_built_in() && !res_path.is_empty()) {
EditorNode::get_singleton()->load_scene_or_resource(res_path, false, false);
}
script_editor->edit(p_script);
@@ -4568,18 +4560,15 @@ bool ScriptEditorPlugin::handles(Object *p_object) const {
void ScriptEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
- window_wrapper->show();
+ if (skip_visible) {
+ skip_visible = false;
+ return;
+ }
+ script_editor->focus_editor();
script_editor->ensure_select_current();
- } else {
- window_wrapper->hide();
}
}
-void ScriptEditorPlugin::selected_notify() {
- script_editor->ensure_select_current();
- _focus_another_editor();
-}
-
String ScriptEditorPlugin::get_unsaved_status(const String &p_for_scene) const {
const PackedStringArray unsaved_scripts = script_editor->get_unsaved_scripts();
if (unsaved_scripts.is_empty()) {
@@ -4621,15 +4610,6 @@ void ScriptEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
if (bool(EDITOR_GET("text_editor/behavior/files/restore_scripts_on_load"))) {
script_editor->set_window_layout(p_layout);
}
-
- if (EDITOR_GET("interface/multi_window/restore_windows_on_load") && window_wrapper->is_window_available() && p_layout->has_section_key("ScriptEditor", "window_rect")) {
- window_wrapper->restore_window_from_saved_position(
- p_layout->get_value("ScriptEditor", "window_rect", Rect2i()),
- p_layout->get_value("ScriptEditor", "window_screen", -1),
- p_layout->get_value("ScriptEditor", "window_screen_rect", Rect2i()));
- } else {
- window_wrapper->set_window_enabled(false);
- }
}
void ScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
@@ -4640,27 +4620,19 @@ void ScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
es->set_project_metadata("recent_files", "scripts", Variant());
es->save_project_metadata();
}
+
+ if (p_layout->has_section_key("ScriptEditor", "window_rect")) {
+ p_layout->erase_section_key("ScriptEditor", "window_rect");
+ }
+ if (p_layout->has_section_key("ScriptEditor", "window_screen")) {
+ p_layout->erase_section_key("ScriptEditor", "window_screen");
+ }
+ if (p_layout->has_section_key("ScriptEditor", "window_screen_rect")) {
+ p_layout->erase_section_key("ScriptEditor", "window_screen_rect");
+ }
#endif
script_editor->get_window_layout(p_layout);
-
- if (window_wrapper->get_window_enabled()) {
- p_layout->set_value("ScriptEditor", "window_rect", window_wrapper->get_window_rect());
- int screen = window_wrapper->get_window_screen();
- p_layout->set_value("ScriptEditor", "window_screen", screen);
- p_layout->set_value("ScriptEditor", "window_screen_rect", DisplayServer::get_singleton()->screen_get_usable_rect(screen));
-
- } else {
- if (p_layout->has_section_key("ScriptEditor", "window_rect")) {
- p_layout->erase_section_key("ScriptEditor", "window_rect");
- }
- if (p_layout->has_section_key("ScriptEditor", "window_screen")) {
- p_layout->erase_section_key("ScriptEditor", "window_screen");
- }
- if (p_layout->has_section_key("ScriptEditor", "window_screen_rect")) {
- p_layout->erase_section_key("ScriptEditor", "window_screen_rect");
- }
- }
}
ScriptEditorPlugin::ScriptEditorPlugin() {
@@ -4673,19 +4645,20 @@ ScriptEditorPlugin::ScriptEditorPlugin() {
ED_SHORTCUT("script_text_editor/convert_to_lowercase", TTRC("Lowercase"), KeyModifierMask::SHIFT | Key::F5);
ED_SHORTCUT("script_text_editor/capitalize", TTRC("Capitalize"), KeyModifierMask::SHIFT | Key::F6);
- window_wrapper = memnew(WindowWrapper);
- window_wrapper->set_margins_enabled(true);
+ make_floating_shortcut = ED_SHORTCUT_AND_COMMAND("script_editor/make_floating", TTRC("Make Floating"));
+ set_process_shortcut_input(true);
memnew(FindInFiles);
- script_editor = memnew(ScriptEditor("ScriptEditor", "script_editor_cache.cfg", window_wrapper));
+ script_editor = memnew(ScriptEditor("ScriptEditor", "script_editor_cache.cfg"));
script_editor->set_handled_resource_types({ "GDScript", "Script", "JSON" });
- Ref<Shortcut> make_floating_shortcut = ED_SHORTCUT_AND_COMMAND("script_editor/make_floating", TTRC("Make Floating"));
- window_wrapper->set_wrapped_control(script_editor, make_floating_shortcut);
- EditorNode::get_singleton()->get_editor_main_screen()->get_control()->add_child(window_wrapper);
- window_wrapper->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- window_wrapper->hide();
- window_wrapper->connect("window_visibility_changed", callable_mp(this, &ScriptEditorPlugin::_window_visibility_changed));
+ script_editor->set_name(TTRC("Script"));
+ script_editor->set_icon_name("Script");
+ script_editor->set_available_layouts(EditorDock::DOCK_LAYOUT_MAIN_SCREEN | EditorDock::DOCK_LAYOUT_FLOATING);
+ script_editor->set_default_slot(EditorDock::DOCK_SLOT_MAIN_SCREEN);
+ script_editor->set_dock_shortcut(ED_GET_SHORTCUT("editor/editor_script"));
+
+ EditorDockManager::get_singleton()->add_dock(script_editor);
ScriptServer::set_reload_scripts_on_save(EDITOR_GET("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save"));
}
diff --git a/editor/script/script_editor_plugin.h b/editor/script/script_editor_plugin.h
index aabf62a7923..d81483250d1 100644
--- a/editor/script/script_editor_plugin.h
+++ b/editor/script/script_editor_plugin.h
@@ -32,9 +32,9 @@
#include "core/error/error_list.h"
#include "core/object/script_language.h"
+#include "editor/docks/editor_dock.h"
#include "editor/plugins/editor_plugin.h"
#include "editor/script/script_editor_base.h"
-#include "scene/gui/panel_container.h"
#include "scene/resources/text_file.h"
class CodeTextEditor;
@@ -150,8 +150,8 @@ class FindInFiles;
class TextFile;
class ShaderCreateDialog;
-class ScriptEditor : public PanelContainer {
- GDCLASS(ScriptEditor, PanelContainer);
+class ScriptEditor : public EditorDock {
+ GDCLASS(ScriptEditor, EditorDock);
enum MenuOptions {
// File.
@@ -238,8 +238,6 @@ class ScriptEditor : public PanelContainer {
Button *help_search = nullptr;
Button *site_search = nullptr;
- Button *make_floating = nullptr;
- bool is_floating = false;
EditorHelpSearch *help_search_dialog = nullptr;
friend class DocumentList;
@@ -274,8 +272,6 @@ class ScriptEditor : public PanelContainer {
Button *script_back = nullptr;
Button *script_forward = nullptr;
- WindowWrapper *window_wrapper = nullptr;
-
#ifdef ANDROID_ENABLED
Control *virtual_keyboard_spacer = nullptr;
int last_kb_height = -1;
@@ -327,6 +323,7 @@ class ScriptEditor : public PanelContainer {
void _close_tab(int p_idx, bool p_save = true);
void _update_find_replace_bar();
+ void _update_margins();
void _close_current_tab(bool p_save = true);
void _close_discard_current_tab(const String &p_str);
@@ -357,6 +354,7 @@ class ScriptEditor : public PanelContainer {
bool trim_final_newlines_on_save;
bool convert_indent_on_save;
bool external_editor_active;
+ bool _should_use_external_editor(const Ref<Script> &p_for_script);
void _goto_script_line2(int p_line);
void _goto_script_line(Ref<RefCounted> p_script, int p_line);
@@ -453,6 +451,8 @@ protected:
void _notification(int p_what);
static void _bind_methods();
+ virtual void update_layout(EditorDock::DockLayout p_layout, int p_slot) override;
+
public:
static ScriptEditor *get_singleton() { return script_editor; }
static ScriptEditor *get_bottom_script_editor() { return bottom_script_editor; }
@@ -470,8 +470,8 @@ public:
Error close_file(const String &p_file);
void ensure_select_current();
-
- bool is_editor_floating();
+ void focus_editor();
+ void focus_script_editor(const Ref<Resource> &p_for_resource);
void set_handled_resource_types(HashSet<String> p_file_types) { handled_resource_types = p_file_types; }
@@ -523,7 +523,7 @@ public:
static void register_create_script_editor_function(CreateScriptEditorFunc p_func);
- ScriptEditor(const String &p_config_section, const String &p_cache_path, WindowWrapper *p_wrapper = nullptr, EditorDock *p_dock = nullptr);
+ ScriptEditor(const String &p_config_section, const String &p_cache_path);
~ScriptEditor();
};
@@ -531,31 +531,26 @@ class ScriptEditorPlugin : public EditorPlugin {
GDCLASS(ScriptEditorPlugin, EditorPlugin);
ScriptEditor *script_editor = nullptr;
- WindowWrapper *window_wrapper = nullptr;
-
- String last_editor;
- void _focus_another_editor();
-
- void _save_last_editor(const String &p_editor);
- void _window_visibility_changed(bool p_visible);
+ Ref<Shortcut> make_floating_shortcut;
static inline ScriptEditorPlugin *script_editor_plugin = nullptr;
+ bool skip_visible = false;
+
protected:
- void _notification(int p_what);
+ virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
public:
static ScriptEditorPlugin *get_singleton() { return script_editor_plugin; }
static bool open_in_external_editor(const String &p_path, int p_line, int p_col, bool p_ignore_project = false);
- virtual String get_plugin_name() const override { return TTRC("Script"); }
+ virtual String get_plugin_name() const override { return "Script"; }
virtual bool has_main_screen() const override { return true; }
virtual void edit(Object *p_object) override;
virtual bool handles(Object *p_object) const override;
virtual void make_visible(bool p_visible) override;
- virtual void selected_notify() override;
virtual String get_unsaved_status(const String &p_for_scene) const override;
virtual void save_external_data() override;
diff --git a/editor/settings/editor_settings.cpp b/editor/settings/editor_settings.cpp
index b4294d5f454..ad43bbafbc9 100644
--- a/editor/settings/editor_settings.cpp
+++ b/editor/settings/editor_settings.cpp
@@ -474,8 +474,10 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
// Editor
EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/localization/localize_settings", true, "")
- EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/docks/dock_tab_style", 0, "Text Only,Icon Only,Text and Icon")
- EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/docks/bottom_dock_tab_style", 0, "Text Only,Icon Only,Text and Icon")
+ const String dock_tab_style_hint = "Text Only,Icon Only,Text and Icon";
+ EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/docks/dock_tab_style", 0, dock_tab_style_hint)
+ EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/docks/bottom_dock_tab_style", 0, dock_tab_style_hint)
+ EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/docks/main_screen_dock_tab_style", 2, dock_tab_style_hint)
EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/localization/ui_layout_direction", 0, "Based on Application Locale,Left-to-Right,Right-to-Left,Based on System Locale", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
// Display what the Auto display scale setting effectively corresponds to.
diff --git a/editor/shader/shader_editor_plugin.cpp b/editor/shader/shader_editor_plugin.cpp
index 52046c84542..b596f433e3e 100644
--- a/editor/shader/shader_editor_plugin.cpp
+++ b/editor/shader/shader_editor_plugin.cpp
@@ -48,18 +48,18 @@ void ShaderEditorPlugin::shortcut_input(const Ref<InputEvent> &p_event) {
}
if (make_floating_shortcut.is_valid() && make_floating_shortcut->matches_event(p_event)) {
- shader_dock->make_floating();
+ script_editor->make_floating();
}
}
void ShaderEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
- shader_dock->open();
+ script_editor->open();
}
}
void ShaderEditorPlugin::set_current() {
- shader_dock->make_visible();
+ script_editor->make_visible();
TextEditorBase *text_shader_editor = Object::cast_to<TextEditorBase>(script_editor->get_current_editor());
if (text_shader_editor) {
text_shader_editor->ensure_focus();
@@ -150,21 +150,19 @@ ShaderEditorPlugin::ShaderEditorPlugin() {
text_shader_lang.instantiate();
EditorShaderLanguagePlugin::register_shader_language(text_shader_lang);
- shader_dock = memnew(EditorDock);
- shader_dock->set_name(TTRC("Shader Editor"));
- shader_dock->set_icon_name("ShaderDock");
- shader_dock->set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_shader_editor_bottom_panel", TTRC("Toggle Shader Editor Dock"), KeyModifierMask::ALT | Key::S));
- shader_dock->set_default_slot(EditorDock::DOCK_SLOT_BOTTOM);
- shader_dock->set_available_layouts(EditorDock::DOCK_LAYOUT_HORIZONTAL | EditorDock::DOCK_LAYOUT_FLOATING);
- EditorDockManager::get_singleton()->add_dock(shader_dock);
-
set_process_shortcut_input(true);
make_floating_shortcut = ED_SHORTCUT_AND_COMMAND("shader_editor/make_floating", TTRC("Make Floating"));
- script_editor = memnew(ScriptEditor(config_section, "shader_editor_cache.cfg", nullptr, shader_dock));
+ script_editor = memnew(ScriptEditor(config_section, "shader_editor_cache.cfg"));
script_editor->set_handled_resource_types({ "Shader", "VisualShader", "ShaderInclude" });
- shader_dock->add_child(script_editor);
+
+ script_editor->set_name(TTRC("Shader Editor"));
+ script_editor->set_icon_name("ShaderDock");
+ script_editor->set_dock_shortcut(ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_shader_editor_bottom_panel", TTRC("Toggle Shader Editor Dock"), KeyModifierMask::ALT | Key::S));
+ script_editor->set_default_slot(EditorDock::DOCK_SLOT_BOTTOM);
+ script_editor->set_available_layouts(EditorDock::DOCK_LAYOUT_HORIZONTAL | EditorDock::DOCK_LAYOUT_FLOATING);
+ EditorDockManager::get_singleton()->add_dock(script_editor);
}
ShaderEditorPlugin::~ShaderEditorPlugin() {
diff --git a/editor/shader/shader_editor_plugin.h b/editor/shader/shader_editor_plugin.h
index f1946c8325d..942aa8d1bf5 100644
--- a/editor/shader/shader_editor_plugin.h
+++ b/editor/shader/shader_editor_plugin.h
@@ -36,8 +36,6 @@ class ShaderEditorPlugin : public EditorPlugin {
GDCLASS(ShaderEditorPlugin, EditorPlugin);
ScriptEditor *script_editor = nullptr;
-
- EditorDock *shader_dock = nullptr;
Ref<Shortcut> make_floating_shortcut;
const String config_section = "ShaderEditor";
diff --git a/editor/themes/editor_fonts.cpp b/editor/themes/editor_fonts.cpp
index 1f68c6cc114..ba10d3878ac 100644
--- a/editor/themes/editor_fonts.cpp
+++ b/editor/themes/editor_fonts.cpp
@@ -503,9 +503,9 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {
p_theme->set_font("title", EditorStringName(EditorFonts), bold_fc);
p_theme->set_font_size("title_size", EditorStringName(EditorFonts), default_font_size + 1 * EDSCALE);
- p_theme->set_type_variation("MainScreenButton", "Button");
- p_theme->set_font(SceneStringName(font), "MainScreenButton", bold_fc);
- p_theme->set_font_size(SceneStringName(font_size), "MainScreenButton", default_font_size + 2 * EDSCALE);
+ p_theme->set_type_variation("MainScreenContainer", "TabContainer");
+ p_theme->set_font(SceneStringName(font), "MainScreenContainer", bold_fc);
+ p_theme->set_font_size(SceneStringName(font_size), "MainScreenContainer", default_font_size + 2 * EDSCALE);
// Labels.
diff --git a/editor/themes/theme_classic.cpp b/editor/themes/theme_classic.cpp
index 7a1af9ce1c2..e44c850a1ee 100644
--- a/editor/themes/theme_classic.cpp
+++ b/editor/themes/theme_classic.cpp
@@ -1685,8 +1685,6 @@ void ThemeClassic::populate_editor_styles(const Ref<EditorTheme> &p_theme, Edito
p_theme->set_stylebox("ContextualToolbar", EditorStringName(EditorStyles), toolbar_stylebox);
// Script editor.
- p_theme->set_stylebox("ScriptEditorPanel", EditorStringName(EditorStyles), EditorThemeManager::make_empty_stylebox(p_config.base_margin, 0, p_config.base_margin, p_config.base_margin));
- p_theme->set_stylebox("ScriptEditorPanelFloating", EditorStringName(EditorStyles), EditorThemeManager::make_empty_stylebox(0, 0, 0, 0));
p_theme->set_stylebox("ScriptEditor", EditorStringName(EditorStyles), EditorThemeManager::make_empty_stylebox(0, 0, 0, 0));
// Game view.
@@ -1704,14 +1702,12 @@ void ThemeClassic::populate_editor_styles(const Ref<EditorTheme> &p_theme, Edito
menu_transparent_style->set_content_margin((Side)i, p_config.button_style->get_content_margin((Side)i));
main_screen_button_hover->set_content_margin((Side)i, p_config.button_style_hover->get_content_margin((Side)i));
}
- p_theme->set_stylebox(CoreStringName(normal), "MainScreenButton", menu_transparent_style);
- p_theme->set_stylebox("normal_mirrored", "MainScreenButton", menu_transparent_style);
- p_theme->set_stylebox(SceneStringName(pressed), "MainScreenButton", menu_transparent_style);
- p_theme->set_stylebox("pressed_mirrored", "MainScreenButton", menu_transparent_style);
- p_theme->set_stylebox(SceneStringName(hover), "MainScreenButton", main_screen_button_hover);
- p_theme->set_stylebox("hover_mirrored", "MainScreenButton", main_screen_button_hover);
- p_theme->set_stylebox("hover_pressed", "MainScreenButton", main_screen_button_hover);
- p_theme->set_stylebox("hover_pressed_mirrored", "MainScreenButton", main_screen_button_hover);
+ p_theme->set_color("font_selected_color", "MainScreenContainer", p_config.accent_color);
+ p_theme->set_color("icon_selected_color", "MainScreenContainer", p_config.accent_color);
+ p_theme->set_stylebox("tab_unselected", "MainScreenContainer", menu_transparent_style);
+ p_theme->set_stylebox("tab_selected", "MainScreenContainer", menu_transparent_style);
+ p_theme->set_stylebox("tab_hovered", "MainScreenContainer", main_screen_button_hover);
+ p_theme->set_constant("tab_separation", "MainScreenContainer", 8 * EDSCALE);
p_theme->set_type_variation("MainMenuBar", "FlatMenuButton");
p_theme->set_stylebox(CoreStringName(normal), "MainMenuBar", menu_transparent_style);
diff --git a/editor/themes/theme_modern.cpp b/editor/themes/theme_modern.cpp
index 03e710fa795..45e46cc567e 100644
--- a/editor/themes/theme_modern.cpp
+++ b/editor/themes/theme_modern.cpp
@@ -1723,8 +1723,6 @@ void ThemeModern::populate_editor_styles(const Ref<EditorTheme> &p_theme, Editor
p_theme->set_stylebox("ContextualToolbar", EditorStringName(EditorStyles), toolbar_stylebox);
// Script editor.
- p_theme->set_stylebox("ScriptEditorPanel", EditorStringName(EditorStyles), EditorThemeManager::make_empty_stylebox(p_config.base_margin, 0, p_config.base_margin, p_config.base_margin));
- p_theme->set_stylebox("ScriptEditorPanelFloating", EditorStringName(EditorStyles), EditorThemeManager::make_empty_stylebox(0, 0, 0, 0));
p_theme->set_stylebox("ScriptEditor", EditorStringName(EditorStyles), EditorThemeManager::make_empty_stylebox(0, 0, 0, 0));
// Game view.
@@ -1734,14 +1732,12 @@ void ThemeModern::populate_editor_styles(const Ref<EditorTheme> &p_theme, Editor
p_theme->set_stylebox(SceneStringName(panel), "GamePanel", game_panel);
// Main menu.
- p_theme->set_stylebox(CoreStringName(normal), "MainScreenButton", p_config.base_empty_wide_style);
- p_theme->set_stylebox("normal_mirrored", "MainScreenButton", p_config.base_empty_wide_style);
- p_theme->set_stylebox(SceneStringName(pressed), "MainScreenButton", p_config.base_empty_wide_style);
- p_theme->set_stylebox("pressed_mirrored", "MainScreenButton", p_config.base_empty_wide_style);
- p_theme->set_stylebox(SceneStringName(hover), "MainScreenButton", p_config.base_empty_wide_style);
- p_theme->set_stylebox("hover_mirrored", "MainScreenButton", p_config.base_empty_wide_style);
- p_theme->set_stylebox("hover_pressed", "MainScreenButton", p_config.base_empty_wide_style);
- p_theme->set_stylebox("hover_pressed_mirrored", "MainScreenButton", p_config.base_empty_wide_style);
+ p_theme->set_color("font_selected_color", "MainScreenContainer", p_config.accent_color);
+ p_theme->set_color("icon_selected_color", "MainScreenContainer", p_config.accent_color);
+ p_theme->set_stylebox("tab_unselected", "MainScreenContainer", p_config.base_empty_wide_style);
+ p_theme->set_stylebox("tab_selected", "MainScreenContainer", p_config.base_empty_wide_style);
+ p_theme->set_stylebox("tab_hovered", "MainScreenContainer", p_config.base_empty_wide_style);
+ p_theme->set_constant("tab_separation", "MainScreenContainer", 8 * EDSCALE);
// Main screen buttons.
const Color mb_font_color = p_config.font_color * Color(1, 1, 1, 0.95);
diff --git a/modules/mono/editor/editor_internal_calls.cpp b/modules/mono/editor/editor_internal_calls.cpp
index 5a06f97b089..b7430560eb9 100644
--- a/modules/mono/editor/editor_internal_calls.cpp
+++ b/modules/mono/editor/editor_internal_calls.cpp
@@ -47,7 +47,6 @@
#include "core/os/os.h"
#include "core/version.h"
#include "editor/debugger/editor_debugger_node.h"
-#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
#include "editor/export/lipo.h"
#include "editor/file_system/editor_paths.h"
@@ -168,7 +167,7 @@ bool godot_icall_Internal_ScriptEditorEdit(Resource *p_resource, int32_t p_line,
}
void godot_icall_Internal_EditorNodeShowScriptScreen() {
- EditorNode::get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
+ ScriptEditor::get_singleton()->focus_editor();
}
void godot_icall_Internal_EditorRunPlay() {
diff --git a/platform/android/editor/game_menu_utils_jni.cpp b/platform/android/editor/game_menu_utils_jni.cpp
index 5599a39c430..31b514ca26e 100644
--- a/platform/android/editor/game_menu_utils_jni.cpp
+++ b/platform/android/editor/game_menu_utils_jni.cpp
@@ -38,7 +38,7 @@
_FORCE_INLINE_ static GameViewPlugin *_get_game_view_plugin() {
ERR_FAIL_NULL_V(EditorNode::get_singleton(), nullptr);
ERR_FAIL_NULL_V(EditorNode::get_singleton()->get_editor_main_screen(), nullptr);
- return Object::cast_to<GameViewPlugin>(EditorNode::get_singleton()->get_editor_main_screen()->get_plugin_by_name("Game"));
+ return Object::cast_to<GameViewPlugin>(EditorNode::get_editor_data().get_editor_by_name("Game"));
}
#endif
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp
index f0a4648f5dd..315a6cf35b1 100644
--- a/platform/android/os_android.cpp
+++ b/platform/android/os_android.cpp
@@ -87,7 +87,7 @@ String _remove_symlink(const String &dir) {
_FORCE_INLINE_ static GameViewPlugin *_get_game_view_plugin() {
ERR_FAIL_NULL_V(EditorNode::get_singleton(), nullptr);
ERR_FAIL_NULL_V(EditorNode::get_singleton()->get_editor_main_screen(), nullptr);
- return Object::cast_to<GameViewPlugin>(EditorNode::get_singleton()->get_editor_main_screen()->get_plugin_by_name("Game"));
+ return Object::cast_to<GameViewPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor_by_name("Game"));
}
#endif
diff --git a/platform/macos/editor/embedded_process_macos.mm b/platform/macos/editor/embedded_process_macos.mm
index d83fd847864..da6cc2e9c82 100644
--- a/platform/macos/editor/embedded_process_macos.mm
+++ b/platform/macos/editor/embedded_process_macos.mm
@@ -39,6 +39,7 @@
#include "editor/debugger/script_editor_debugger.h"
#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
+#include "editor/run/game_view_plugin.h"
#include "editor/settings/editor_settings.h"
#include "scene/gui/control.h"
#include "scene/main/window.h"
@@ -195,7 +196,7 @@ void EmbeddedProcessMacOS::mouse_set_mode(DisplayServerEnums::MouseMode p_mode)
mouse_mode = p_mode;
// If the mouse is anything other than visible, we must ensure the Game view is active and the layer focused.
if (mouse_mode != DisplayServerEnums::MOUSE_MODE_VISIBLE) {
- EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_GAME);
+ GameView::get_dock()->make_visible();
layer_host->grab_focus();
}
DisplayServer::get_singleton()->mouse_set_mode(p_mode);
diff --git a/scene/debugger/view_3d_controller.cpp b/scene/debugger/view_3d_controller.cpp
index ce5878f51e1..486600ac72c 100644
--- a/scene/debugger/view_3d_controller.cpp
+++ b/scene/debugger/view_3d_controller.cpp
@@ -36,7 +36,6 @@
#include "core/input/input.h"
#include "core/input/shortcut.h"
#include "scene/main/scene_tree.h"
-#include "scene/main/window.h"
using namespace View3DControllerConsts;
@@ -753,7 +752,7 @@ void View3DController::set_freelook_enabled(const bool p_enabled) {
freelook_speed = freelook_base_speed * cursor.distance;
}
- previous_mouse_position = SceneTree::get_singleton()->get_root()->get_mouse_position();
+ previous_mouse_position = Input::get_singleton()->get_mouse_position();
// Hide mouse like in an FPS (warping doesn't work).
if (Engine::get_singleton()->is_editor_hint()) {
diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp
index cfa3eda8fab..81dad49a3f0 100644
--- a/scene/gui/tab_bar.cpp
+++ b/scene/gui/tab_bar.cpp
@@ -220,6 +220,10 @@ void TabBar::gui_input(const Ref<InputEvent> &p_event) {
}
}
+ if (hover != -1 && mb->get_button_index() == MouseButton::LEFT) {
+ accept_event();
+ }
+
if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
if (rb_hover != -1) {
emit_signal(SNAME("tab_button_pressed"), rb_hover);
@@ -2138,6 +2142,9 @@ void TabBar::ensure_tab_visible(int p_idx) {
}
Rect2 TabBar::get_tab_rect(int p_tab) const {
+ if (p_tab < 0) {
+ p_tab += tabs.size();
+ }
ERR_FAIL_INDEX_V(p_tab, tabs.size(), Rect2());
if (is_layout_rtl()) {
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 918f680e026..6dd5ac7d81b 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -38,6 +38,10 @@
#include "scene/theme/theme_db.h"
#include "servers/display/accessibility_server.h"
+bool TabContainer::_is_tab_bar_owned() const {
+ return internal_container->get_parent() == this;
+}
+
TabContainer::CachedTab *TabContainer::get_pending_tab(int p_idx) const {
if (p_idx >= pending_tabs.size()) {
ERR_FAIL_COND_V(pending_tabs.resize(p_idx + 1) != OK, nullptr);
@@ -159,7 +163,7 @@ void TabContainer::_notification(int p_what) {
Size2 size = get_size();
// Draw only the tab area if the header is hidden.
- if (!tabs_visible) {
+ if (!tabs_visible || !_is_tab_bar_owned()) {
theme_cache.panel_style->draw(canvas, Rect2(0, 0, size.width, size.height));
return;
}
@@ -280,12 +284,14 @@ void TabContainer::_repaint_internal() {
// Move the TabBar to the top or bottom.
// Don't change the left and right offsets since the TabBar will resize and may change tab offset.
- if (tabs_position == POSITION_BOTTOM) {
- internal_container->set_anchor_and_offset(SIDE_BOTTOM, 1.0, -bottom_margin);
- internal_container->set_anchor_and_offset(SIDE_TOP, 1.0, top_margin - _get_tab_height());
- } else {
- internal_container->set_anchor_and_offset(SIDE_TOP, 0.0, top_margin);
- internal_container->set_anchor_and_offset(SIDE_BOTTOM, 0.0, _get_tab_height() - bottom_margin);
+ if (_is_tab_bar_owned()) {
+ if (tabs_position == POSITION_BOTTOM) {
+ internal_container->set_anchor_and_offset(SIDE_BOTTOM, 1.0, -bottom_margin);
+ internal_container->set_anchor_and_offset(SIDE_TOP, 1.0, top_margin - _get_tab_height());
+ } else {
+ internal_container->set_anchor_and_offset(SIDE_TOP, 0.0, top_margin);
+ internal_container->set_anchor_and_offset(SIDE_BOTTOM, 0.0, _get_tab_height() - bottom_margin);
+ }
}
updating_visibility = true;
@@ -296,7 +302,7 @@ void TabContainer::_repaint_internal() {
c->show();
c->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
- if (tabs_visible) {
+ if (tabs_visible && _is_tab_bar_owned()) {
if (tabs_position == POSITION_BOTTOM) {
c->set_offset(SIDE_BOTTOM, -_get_tab_height());
} else {
@@ -319,6 +325,9 @@ void TabContainer::_repaint_internal() {
}
void TabContainer::_update_margins() {
+ if (!_is_tab_bar_owned()) {
+ return;
+ }
// Directly check for validity, to avoid errors when quitting.
bool has_popup = popup_obj_id.is_valid();
@@ -414,11 +423,7 @@ void TabContainer::_drag_move_tab(int p_from_index, int p_to_index) {
}
void TabContainer::_drag_move_tab_from(TabBar *p_from_tabbar, int p_from_index, int p_to_index) {
- HBoxContainer *parent = Object::cast_to<HBoxContainer>(p_from_tabbar->get_parent()); // The internal container.
- if (!parent) {
- return;
- }
- TabContainer *from_tab_container = Object::cast_to<TabContainer>(parent->get_parent());
+ TabContainer *from_tab_container = TabContainer::get_tab_bar_container(p_from_tabbar);
if (!from_tab_container) {
return;
}
@@ -1016,7 +1021,7 @@ Ref<Texture2D> TabContainer::get_tab_button_icon(int p_tab) const {
Size2 TabContainer::_get_minimum_size(bool p_use_desired_sizes) const {
Size2 ms;
- if (tabs_visible) {
+ if (tabs_visible && _is_tab_bar_owned()) {
ms = p_use_desired_sizes ? tab_bar->get_bound_desired_size() : tab_bar->get_minimum_size();
ms.width += theme_cache.tabbar_style->get_margin(SIDE_LEFT) + theme_cache.tabbar_style->get_margin(SIDE_RIGHT);
ms.height += theme_cache.tabbar_style->get_margin(SIDE_TOP) + theme_cache.tabbar_style->get_margin(SIDE_BOTTOM);
@@ -1347,7 +1352,21 @@ void TabContainer::_bind_methods() {
PropertyListHelper::register_base_helper(get_class_static(), &base_property_helper);
}
+TabContainer *TabContainer::get_tab_bar_container(TabBar *p_tab_bar) {
+ if (!p_tab_bar) {
+ return nullptr;
+ }
+ HBoxContainer *parent = Object::cast_to<HBoxContainer>(p_tab_bar->get_parent()); // The internal container.
+ if (!parent || !parent->has_meta(TAB_CONTAINER_META)) {
+ return nullptr;
+ }
+ return Object::cast_to<TabContainer>(parent->get_meta(TAB_CONTAINER_META).get_validated_object());
+}
+
TabContainer::TabContainer() {
+ if (TAB_CONTAINER_META.is_empty()) {
+ TAB_CONTAINER_META = StringName("_tab_container", true);
+ }
connect(SceneStringName(maximum_size_changed), callable_mp(this, &TabContainer::_maximum_size_changed));
internal_container = memnew(HBoxContainer);
@@ -1355,6 +1374,7 @@ TabContainer::TabContainer() {
internal_container->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE);
internal_container->set_use_parent_material(true);
add_child(internal_container, false, INTERNAL_MODE_FRONT);
+ internal_container->set_meta(TAB_CONTAINER_META, this);
tab_bar = memnew(TabBar);
SET_DRAG_FORWARDING_GCDU(tab_bar, TabContainer);
diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h
index 7bff097dcd5..34e341902ba 100644
--- a/scene/gui/tab_container.h
+++ b/scene/gui/tab_container.h
@@ -49,6 +49,8 @@ public:
};
private:
+ inline static StringName TAB_CONTAINER_META;
+
HBoxContainer *internal_container = nullptr;
TabBar *tab_bar = nullptr;
Button *popup_button = nullptr;
@@ -122,6 +124,7 @@ private:
HashMap<Node *, RID> tab_panels;
+ bool _is_tab_bar_owned() const;
int _get_tab_height() const;
Control *_as_tab_control(Node *p_child) const;
Vector<Control *> _get_tab_controls() const;
@@ -167,9 +170,11 @@ protected:
static void _bind_methods();
public:
+ static TabContainer *get_tab_bar_container(TabBar *p_tab_bar);
+
virtual bool accessibility_override_tree_hierarchy() const override { return true; }
- HBoxContainer *get_internal_container() { return internal_container; }
+ HBoxContainer *get_internal_container() const { return internal_container; }
TabBar *get_tab_bar() const;
int get_tab_idx_at_point(const Point2 &p_point) const;