From 59f545e804c88242f4435cc3b3f94401a52a56bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 12 May 2026 10:13:00 +0200 Subject: [PATCH] Fix issue with the current tab not being saved through screen recreation --- Common/UI/TabHolder.cpp | 5 ++++- Common/UI/TabHolder.h | 2 ++ UI/TabbedDialogScreen.cpp | 15 +++++++++------ UI/TabbedDialogScreen.h | 3 +-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Common/UI/TabHolder.cpp b/Common/UI/TabHolder.cpp index 2e39b588e9..4bab2c019a 100644 --- a/Common/UI/TabHolder.cpp +++ b/Common/UI/TabHolder.cpp @@ -209,7 +209,10 @@ bool TabHolder::SetCurrentTab(int tab, bool skipTween) { tabs_[tab]->SetVisibility(V_VISIBLE); currentTab_ = tab; - + UI::EventParams e{}; + e.v = this; + e.a = currentTab_; + OnChangeTab.Trigger(e); return created; } diff --git a/Common/UI/TabHolder.h b/Common/UI/TabHolder.h index f88f2946eb..a4ca99ccbd 100644 --- a/Common/UI/TabHolder.h +++ b/Common/UI/TabHolder.h @@ -52,6 +52,8 @@ public: } bool EnsureTab(int index); // return true if it actually created a tab. + Event OnChangeTab; + private: void AddTabContents(std::string_view title, ImageID imageId, ViewGroup *tabContents); void OnTabClick(EventParams &e); diff --git a/UI/TabbedDialogScreen.cpp b/UI/TabbedDialogScreen.cpp index 03e4f93a64..c56f81caa7 100644 --- a/UI/TabbedDialogScreen.cpp +++ b/UI/TabbedDialogScreen.cpp @@ -13,6 +13,9 @@ #include "Common/UI/Context.h" #include "UI/TabbedDialogScreen.h" +UITabbedBaseDialogScreen::UITabbedBaseDialogScreen(const Path &gamePath, int *currentTabSetting, TabDialogFlags flags) + : UIBaseDialogScreen(gamePath), currentTabSetting_(currentTabSetting), flags_(flags) {} + void UITabbedBaseDialogScreen::AddTab(const char *tag, std::string_view title, ImageID imageId, std::function createCallback, TabFlags flags) { using namespace UI; @@ -106,6 +109,12 @@ void UITabbedBaseDialogScreen::CreateViews() { } tabHolder_->EnsureTab(tabHolder_->GetCurrentTab()); + tabHolder_->OnChangeTab.Add([this](UI::EventParams &e) { + if (currentTabSetting_) { + *currentTabSetting_ = e.a; + } + }); + if (System_GetPropertyBool(SYSPROP_HAS_KEYBOARD) || System_GetPropertyBool(SYSPROP_HAS_TEXT_INPUT_DIALOG)) { // Hide search if screen is too small. int deviceType = System_GetPropertyInt(SYSPROP_DEVICE_TYPE); @@ -137,12 +146,6 @@ void UITabbedBaseDialogScreen::CreateViews() { } } -UITabbedBaseDialogScreen::~UITabbedBaseDialogScreen() { - if (currentTabSetting_) { - *currentTabSetting_ = GetCurrentTab(); - } -} - void UITabbedBaseDialogScreen::sendMessage(UIMessage message, const char *value) { UIBaseDialogScreen::sendMessage(message, value); if (message == UIMessage::GAMESETTINGS_SEARCH) { diff --git a/UI/TabbedDialogScreen.h b/UI/TabbedDialogScreen.h index 423f1dfc7a..0e02f067d0 100644 --- a/UI/TabbedDialogScreen.h +++ b/UI/TabbedDialogScreen.h @@ -31,8 +31,7 @@ ENUM_CLASS_BITOPS(TabFlags); class UITabbedBaseDialogScreen : public UIBaseDialogScreen { public: // currentTabSetting can be null if you don't want to persist the current tab. - UITabbedBaseDialogScreen(const Path &gamePath, int *currentTabSetting = nullptr, TabDialogFlags flags = TabDialogFlags::Default) : UIBaseDialogScreen(gamePath), currentTabSetting_(currentTabSetting), flags_(flags) {} - ~UITabbedBaseDialogScreen() override; + UITabbedBaseDialogScreen(const Path &gamePath, int *currentTabSetting = nullptr, TabDialogFlags flags = TabDialogFlags::Default); void AddTab(const char *tag, std::string_view title, ImageID imageId, std::function createCallback, TabFlags flags = TabFlags::Default); void AddTab(const char *tag, std::string_view title, std::function createCallback, TabFlags flags = TabFlags::Default) { AddTab(tag, title, ImageID::invalid(), createCallback, flags);