From aede038ba392f8a958ea504ccd78a13b2e38484f Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 4 Jan 2025 16:18:27 +0100 Subject: [PATCH] Remember preferred file browser dimensions --- src/openrct2-ui/windows/LoadSave.cpp | 42 +++++++++++++++++++++------- src/openrct2/config/Config.cpp | 5 ++++ src/openrct2/config/Config.h | 2 ++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index c874304963..a116ab24d6 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -46,9 +46,9 @@ namespace OpenRCT2::Ui::Windows { #pragma region Widgets - static constexpr StringId WINDOW_TITLE = STR_NONE; - static constexpr int32_t WW = 350; - static constexpr int32_t WH = 400; + static constexpr ScreenSize kWindowSizeInit = { 350, 400 }; + static constexpr ScreenSize kWindowSizeMin = { kWindowSizeInit.width, kWindowSizeInit.height / 2 }; + static constexpr ScreenSize kWindowSizeMax = kWindowSizeInit * 2; static constexpr uint16_t DATE_TIME_GAP = 2; @@ -70,10 +70,13 @@ namespace OpenRCT2::Ui::Windows WIDX_BROWSE, }; + static constexpr int16_t WW = kWindowSizeInit.width; + static constexpr int16_t WH = kWindowSizeInit.height; + // clang-format off static Widget window_loadsave_widgets[] = { - WINDOW_SHIM(WINDOW_TITLE, WW, WH), + WINDOW_SHIM(STR_NONE, WW, WH), MakeWidget({ 0, WH - 1}, { WW, 1 }, WindowWidgetType::Resize, WindowColour::Secondary ), // WIDX_RESIZE MakeWidget({ 4, 36}, { 84, 14 }, WindowWidgetType::Button, WindowColour::Primary, STR_LOADSAVE_DEFAULT, STR_LOADSAVE_DEFAULT_TIP), // WIDX_DEFAULT MakeWidget({ 88, 36}, { 84, 14 }, WindowWidgetType::Button, WindowColour::Primary, STR_FILEBROWSER_ACTION_UP ), // WIDX_UP @@ -724,16 +727,18 @@ namespace OpenRCT2::Ui::Windows // Reset window dimensions InitScrollWidgets(); ComputeMaxDateWidth(); - min_width = WW; - min_height = WH / 2; - max_width = WW * 2; - max_height = WH * 2; + + min_width = kWindowSizeMin.width; + min_height = kWindowSizeMin.height; + max_width = kWindowSizeMax.width; + max_height = kWindowSizeMax.height; } void OnClose() override { _listItems.clear(); WindowCloseByClass(WindowClass::LoadsaveOverwritePrompt); + Config::Save(); // Unpause the game if not on title scene, nor in network play. if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && NetworkGetMode() == NETWORK_MODE_NONE) @@ -755,6 +760,10 @@ namespace OpenRCT2::Ui::Windows Invalidate(); height = min_height; } + + auto& config = Config::Get().general; + config.FileBrowserWidth = width; + config.FileBrowserHeight = height; } void OnUpdate() override @@ -1145,11 +1154,12 @@ namespace OpenRCT2::Ui::Windows _type = type; _defaultPath = defaultPath; + auto& config = Config::Get().general; bool isSave = (type & 0x01) == LOADSAVETYPE_SAVE; // Bypass the lot? auto hasFilePicker = OpenRCT2::GetContext()->GetUiContext()->HasFilePicker(); - if (Config::Get().general.UseNativeBrowseDialog && hasFilePicker) + if (config.UseNativeBrowseDialog && hasFilePicker) { const u8string path = OpenSystemFileBrowser(isSave); if (!path.empty()) @@ -1164,8 +1174,20 @@ namespace OpenRCT2::Ui::Windows auto* w = static_cast(WindowBringToFrontByClass(WindowClass::Loadsave)); if (w == nullptr) { + if (config.FileBrowserWidth < kWindowSizeMin.width || config.FileBrowserHeight < kWindowSizeMin.height + || config.FileBrowserWidth > kWindowSizeMax.width || config.FileBrowserHeight > kWindowSizeMax.height) + { + config.FileBrowserWidth = kWindowSizeInit.width; + config.FileBrowserHeight = kWindowSizeInit.height; + Config::Save(); + } + + auto width = config.FileBrowserWidth; + auto height = config.FileBrowserHeight; + w = WindowCreate( - WindowClass::Loadsave, WW, WH, WF_STICK_TO_FRONT | WF_RESIZABLE | WF_AUTO_POSITION | WF_CENTRE_SCREEN, type); + WindowClass::Loadsave, width, height, WF_STICK_TO_FRONT | WF_RESIZABLE | WF_AUTO_POSITION | WF_CENTRE_SCREEN, + type); } switch (type & 0x0E) diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index cbfea7d023..fad35d7172 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -252,6 +252,9 @@ namespace OpenRCT2::Config model->InvisibleSupports = reader->GetBoolean("invisible_supports", true); model->LastVersionCheckTime = reader->GetInt64("last_version_check_time", 0); + + model->FileBrowserWidth = reader->GetInt32("file_browser_width", 0); + model->FileBrowserHeight = reader->GetInt32("file_browser_height", 0); } } @@ -338,6 +341,8 @@ namespace OpenRCT2::Config writer->WriteBoolean("invisible_paths", model->InvisiblePaths); writer->WriteBoolean("invisible_supports", model->InvisibleSupports); writer->WriteInt64("last_version_check_time", model->LastVersionCheckTime); + writer->WriteInt32("file_browser_width", model->FileBrowserWidth); + writer->WriteInt32("file_browser_height", model->FileBrowserHeight); } static void ReadInterface(IIniReader* reader) diff --git a/src/openrct2/config/Config.h b/src/openrct2/config/Config.h index 5a9c87301a..82f86b4183 100644 --- a/src/openrct2/config/Config.h +++ b/src/openrct2/config/Config.h @@ -117,6 +117,8 @@ namespace OpenRCT2::Config u8string LastRunVersion; bool UseNativeBrowseDialog; int64_t LastVersionCheckTime; + int16_t FileBrowserWidth; + int16_t FileBrowserHeight; }; struct Interface