Godot Engine – Multi-platform 2D and 3D game engine
Don't allow showing Game dock when it's empty
kobewi32c2b477b913
diff --git a/editor/docks/editor_dock.h b/editor/docks/editor_dock.hindex 59e80feabae..af715ca6902 100644--- a/editor/docks/editor_dock.h+++ b/editor/docks/editor_dock.h@@ -121,6 +121,7 @@ public:void make_visible();void make_floating(int p_screen = -1);void close();+ bool is_dock_open() { return is_open; }void set_title(const String &p_title);String get_title() const { return title; }diff --git a/editor/docks/editor_dock_manager.cpp b/editor/docks/editor_dock_manager.cppindex 89620a6e529..093d07e1f03 100644--- a/editor/docks/editor_dock_manager.cpp+++ b/editor/docks/editor_dock_manager.cpp@@ -351,18 +351,27 @@ void EditorDockManager::_move_dock(EditorDock *p_dock, Control *p_target, int p__close_window(p_dock->dock_window);} else {DockTabContainer *parent_tabs = Object::cast_to<DockTabContainer>(parent);+ EditorDock *previous_dock = nullptr;if (parent_tabs) {p_dock->previous_tab_index = parent_tabs->get_tab_idx_from_control(p_dock);- // Swap to previous tab when closing current tab.if (parent_tabs->get_current_tab() == p_dock->previous_tab_index && parent_tabs->get_previous_tab() != -1) {- parent_tabs->set_current_tab(parent_tabs->get_previous_tab());+ previous_dock = parent_tabs->get_dock(parent_tabs->get_previous_tab());}}parent->set_block_signals(true);parent->remove_child(p_dock);parent->set_block_signals(false);if (parent_tabs) {+ if (previous_dock) {+ // Swap to previous tab when closing current tab.+ for (int i = 0; i < parent_tabs->get_tab_count(); i++) {+ if (parent_tabs->get_dock(i) == previous_dock) {+ parent_tabs->set_current_tab(i);+ break;+ }+ }+ }parent_tabs->update_visibility();}}diff --git a/editor/run/game_view_plugin.cpp b/editor/run/game_view_plugin.cppindex ae8716ed312..6d3c00e3c58 100644--- a/editor/run/game_view_plugin.cpp+++ b/editor/run/game_view_plugin.cpp@@ -1509,6 +1509,7 @@ GameView::GameView(Ref<GameViewDebugger> p_debugger, EmbeddedProcessBase *p_embegame_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"));+ dock_singleton = game_dock;debugger = p_debugger;window_wrapper = p_wrapper;@@ -1881,27 +1882,6 @@ GameView::GameView(Ref<GameViewDebugger> p_debugger, EmbeddedProcessBase *p_embe///////-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_ENABLEDvoid GameViewPluginBase::set_window_layout(Ref<ConfigFile> p_layout) {game_view->set_window_layout(p_layout);@@ -1922,11 +1902,15 @@ void GameViewPluginBase::setup(Ref<GameViewDebugger> p_debugger, EmbeddedProcesswindow_wrapper->set_wrapped_control(game_view, nullptr);- GameView::get_dock()->add_child(window_wrapper);+ EditorDock *game_dock = GameView::get_dock();+ game_dock->add_child(window_wrapper);+ game_dock->connect(SceneStringName(visibility_changed), callable_mp(this, &GameViewPluginBase::_dock_visibility_changed).bind(game_dock));+ _create_empty_info_label(TTRC("The Game dock is embedded in a floating window and is not available here."));+ empty_dock_info->hide();EditorDockManager::get_singleton()->add_dock(GameView::get_dock());window_wrapper->set_v_size_flags(Control::SIZE_EXPAND_FILL);- window_wrapper->connect("window_visibility_changed", callable_mp(this, &GameViewPlugin::_focus_another_editor).unbind(1));+ window_wrapper->connect("window_visibility_changed", callable_mp(this, &GameViewPlugin::_window_visibility_changed));}#endif // ANDROID_ENABLED@@ -1940,34 +1924,62 @@ void GameViewPluginBase::_notification(int p_what) {} break;case NOTIFICATION_ENTER_TREE: {add_debugger_plugin(debugger);- connect("main_screen_changed", callable_mp(this, &GameViewPluginBase::_save_last_editor));} break;case NOTIFICATION_EXIT_TREE: {remove_debugger_plugin(debugger);- disconnect("main_screen_changed", callable_mp(this, &GameViewPluginBase::_save_last_editor));} break;}}-void GameViewPluginBase::_save_last_editor(const String &p_editor) {- if (p_editor != get_plugin_name()) {- last_editor = p_editor;- }+void GameViewPluginBase::_window_visibility_changed(bool p_visible) {+ empty_dock_info->set_visible(p_visible);+ _focus_another_editor();+}++void GameViewPluginBase::_create_empty_info_label(const String &p_message) {+ empty_dock_info = memnew(Label(p_message));+ empty_dock_info->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);+ empty_dock_info->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);+ empty_dock_info->set_autowrap_mode(TextServer::AUTOWRAP_WORD);+ GameView::get_dock()->add_child(empty_dock_info);}void GameViewPluginBase::_focus_another_editor() {- if (_is_window_wrapper_enabled()) {- if (last_editor.is_empty() || (last_editor == "Script" && ScriptEditor::get_singleton()->get_current_layout() == EditorDock::DOCK_LAYOUT_FLOATING)) {- CanvasItemEditor::get_singleton()->make_visible();- } else {- EditorDock *last_dock = EditorDockManager::get_singleton()->get_dock_by_name(last_editor);- if (last_dock && last_dock->get_current_layout() == EditorDock::DOCK_LAYOUT_MAIN_SCREEN) {- last_dock->make_visible();- }+ DockTabContainer *main_screen = EditorNode::get_editor_main_screen();+ EditorDock *game_dock = GameView::get_dock();++ if (main_screen->get_current_tab_control() != game_dock) {+ // Already showing different screen, so nothing to do.+ return;+ }+ EditorDock *prev_dock = main_screen->get_dock(main_screen->get_previous_tab());+ if (prev_dock && prev_dock != game_dock && prev_dock->is_dock_open()) {+ EditorDockManager::get_singleton()->force_focus_dock(prev_dock);+ return;+ }+ // The above switch can still fail when a tab is closed. Try to open the first tab that isn't Game.+ for (int i = 0; i < main_screen->get_tab_count(); i++) {+ if (main_screen->get_dock(i) != game_dock) {+ EditorDockManager::get_singleton()->force_focus_dock(main_screen->get_dock(i));+ break;}}}+void GameViewPluginBase::_dock_visibility_changed(EditorDock *p_dock) {+ if (!p_dock->is_visible_in_tree()) {+ return;+ }+ if (window_wrapper) {+ if (EditorRunBar::get_singleton()->is_playing() && window_wrapper->get_window_enabled()) {+ _focus_another_editor();+ window_wrapper->grab_window_focus();+ }+ } else {+ _focus_another_editor();+ }+}+bool GameViewPluginBase::_is_window_wrapper_enabled() const {#ifdef ANDROID_ENABLEDreturn true;@@ -2001,16 +2013,10 @@ void GameViewPluginBase::setup_android() {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"));-+ GameView::dock_singleton = game_dock;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));-}+ game_dock->connect(SceneStringName(visibility_changed), callable_mp(this, &GameViewPluginBase::_dock_visibility_changed).bind(game_dock));-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();- }+ _create_empty_info_label(TTRC("Game dock is not available on Android."));}#endifdiff --git a/editor/run/game_view_plugin.h b/editor/run/game_view_plugin.hindex cef9b2a2fd9..c4ffc17469d 100644--- a/editor/run/game_view_plugin.h+++ b/editor/run/game_view_plugin.h@@ -132,6 +132,10 @@ public:class GameView : public VBoxContainer {GDCLASS(GameView, VBoxContainer);+#ifdef ANDROID_ENABLED+ friend class GameViewPluginBase;+#endif+enum {CAMERA_RESET_2D,CAMERA_RESET_3D,@@ -172,6 +176,7 @@ class GameView : public VBoxContainer {};inline static GameView *singleton = nullptr;+ inline static EditorDock *dock_singleton = nullptr;Ref<GameViewDebugger> debugger;WindowWrapper *window_wrapper = nullptr;@@ -309,12 +314,7 @@ protected:void _notification(int p_what);public:- static EditorDock *get_dock() {- if (singleton) {- return singleton->game_dock;- }- return nullptr;- }+ static EditorDock *get_dock() { return dock_singleton; }void set_window_layout(Ref<ConfigFile> p_layout);void get_window_layout(Ref<ConfigFile> p_layout);@@ -329,22 +329,19 @@ class GameViewPluginBase : public EditorPlugin {#ifndef ANDROID_ENABLEDGameView *game_view = nullptr;- WindowWrapper *window_wrapper = nullptr;#endif // ANDROID_ENABLED+ WindowWrapper *window_wrapper = nullptr;Ref<GameViewDebugger> debugger;- String last_editor;+ Label *empty_dock_info = nullptr;-#ifndef ANDROID_ENABLEDvoid _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 _create_empty_info_label(const String &p_message);+void _focus_another_editor();bool _is_window_wrapper_enabled() const;+ void _dock_visibility_changed(EditorDock *p_dock);protected:void _notification(int p_what);@@ -361,8 +358,6 @@ public:Ref<GameViewDebugger> get_debugger() const { return debugger; }- virtual void make_visible(bool p_visible) override;-#ifndef ANDROID_ENABLEDvirtual void set_window_layout(Ref<ConfigFile> p_layout) override;virtual void get_window_layout(Ref<ConfigFile> p_layout) override;diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cppindex 9d68885e4cc..953f9685e81 100644--- a/scene/gui/tab_container.cpp+++ b/scene/gui/tab_container.cpp@@ -301,9 +301,6 @@ void TabContainer::_repaint() {}void TabContainer::_repaint_internal() {- Vector<Control *> controls = _get_tab_controls();- int current = get_current_tab();-float top_margin = theme_cache.tabbar_style->get_margin(SIDE_TOP);float bottom_margin = theme_cache.tabbar_style->get_margin(SIDE_BOTTOM);@@ -320,28 +317,30 @@ void TabContainer::_repaint_internal() {}updating_visibility = true;- for (int i = 0; i < controls.size(); i++) {- Control *c = controls[i];-- if (i == current) {- c->show();- c->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);+ Control *current_control = get_current_tab_control();+ // First hide all non-current controls, so that visibility order does not depend on tab order.+ for (Control *c : _get_tab_controls()) {+ if (c != current_control) {+ c->hide();+ }+ }+ // Then show the current control.+ if (current_control) {+ current_control->show();+ current_control->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);- if (tabs_visible && _is_tab_bar_owned()) {- if (tabs_position == POSITION_BOTTOM) {- c->set_offset(SIDE_BOTTOM, -_get_tab_height());- } else {- c->set_offset(SIDE_TOP, _get_tab_height());- }+ if (tabs_visible && _is_tab_bar_owned()) {+ if (tabs_position == POSITION_BOTTOM) {+ current_control->set_offset(SIDE_BOTTOM, -_get_tab_height());+ } else {+ current_control->set_offset(SIDE_TOP, _get_tab_height());}-- c->set_offset(SIDE_TOP, c->get_offset(SIDE_TOP) + theme_cache.panel_style->get_margin(SIDE_TOP));- c->set_offset(SIDE_LEFT, c->get_offset(SIDE_LEFT) + theme_cache.panel_style->get_margin(SIDE_LEFT));- c->set_offset(SIDE_RIGHT, c->get_offset(SIDE_RIGHT) - theme_cache.panel_style->get_margin(SIDE_RIGHT));- c->set_offset(SIDE_BOTTOM, c->get_offset(SIDE_BOTTOM) - theme_cache.panel_style->get_margin(SIDE_BOTTOM));- } else {- c->hide();}++ current_control->set_offset(SIDE_TOP, current_control->get_offset(SIDE_TOP) + theme_cache.panel_style->get_margin(SIDE_TOP));+ current_control->set_offset(SIDE_LEFT, current_control->get_offset(SIDE_LEFT) + theme_cache.panel_style->get_margin(SIDE_LEFT));+ current_control->set_offset(SIDE_RIGHT, current_control->get_offset(SIDE_RIGHT) - theme_cache.panel_style->get_margin(SIDE_RIGHT));+ current_control->set_offset(SIDE_BOTTOM, current_control->get_offset(SIDE_BOTTOM) - theme_cache.panel_style->get_margin(SIDE_BOTTOM));}updating_visibility = false;