diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index a9869f06f5..c8a29879b7 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -143,8 +143,10 @@ using ImGuiFullscreen::ToggleButton; using ImGuiFullscreen::WantsToCloseMenu; #ifndef __ANDROID__ + namespace FullscreenUI { -enum class MainWindowType + +enum class MainWindowType : u8 { None, Landing, @@ -158,14 +160,14 @@ enum class MainWindowType Leaderboards, }; -enum class PauseSubMenu +enum class PauseSubMenu : u8 { None, Exit, Achievements, }; -enum class SettingsPage +enum class SettingsPage : u8 { Summary, Interface, @@ -185,7 +187,7 @@ enum class SettingsPage Count }; -enum class GameListView +enum class GameListView : u8 { Grid, List, @@ -217,28 +219,12 @@ static void OpenAboutWindow(); static void FixStateIfPaused(); static void GetStandardSelectionFooterText(SmallStringBase& dest, bool back_instead_of_cancel); -static MainWindowType s_current_main_window = MainWindowType::None; -static PauseSubMenu s_current_pause_submenu = PauseSubMenu::None; -static std::string s_current_game_subtitle; -static bool s_initialized = false; -static bool s_tried_to_initialize = false; -static bool s_pause_menu_was_open = false; -static bool s_was_paused_on_quick_menu_open = false; -static bool s_about_window_open = false; -static bool s_achievements_login_window_open = false; - ////////////////////////////////////////////////////////////////////////// // Resources ////////////////////////////////////////////////////////////////////////// static bool LoadResources(); static void DestroyResources(); -static std::shared_ptr s_app_icon_texture; -static std::shared_ptr s_fallback_disc_texture; -static std::shared_ptr s_fallback_exe_texture; -static std::shared_ptr s_fallback_psf_texture; -static std::shared_ptr s_fallback_playlist_texture; - ////////////////////////////////////////////////////////////////////////// // Landing ////////////////////////////////////////////////////////////////////////// @@ -384,31 +370,6 @@ static void DrawInputBindingButton(SettingsInterface* bsi, InputBindingInfo::Typ static void ClearInputBindingVariables(); static void StartAutomaticBinding(u32 port); -static SettingsPage s_settings_page = SettingsPage::Interface; -static std::unique_ptr s_game_settings_interface; -static std::unique_ptr s_game_settings_entry; -static std::vector> s_game_list_directories_cache; -static GPUDevice::AdapterInfoList s_graphics_adapter_list_cache; -static std::vector s_fullscreen_mode_list_cache; -static Cheats::CodeInfoList s_game_patch_list; -static std::vector s_enabled_game_patch_cache; -static Cheats::CodeInfoList s_game_cheats_list; -static std::vector s_enabled_game_cheat_cache; -static std::vector s_game_cheat_groups; -static std::vector s_postprocessing_stages; -static std::vector s_hotkey_list_cache; -static std::atomic_bool s_settings_changed{false}; -static std::atomic_bool s_game_settings_changed{false}; -static InputBindingInfo::Type s_input_binding_type = InputBindingInfo::Type::Unknown; -static std::string s_input_binding_section; -static std::string s_input_binding_key; -static std::string s_input_binding_display_name; -static std::vector s_input_binding_new_bindings; -static std::vector>> s_input_binding_value_ranges; -static Timer s_input_binding_timer; -static bool s_controller_macro_expanded[NUM_CONTROLLER_AND_CARD_PORTS][InputManager::NUM_MACRO_BUTTONS_PER_CONTROLLER] = - {}; - ////////////////////////////////////////////////////////////////////////// // Save State List ////////////////////////////////////////////////////////////////////////// @@ -439,13 +400,6 @@ static void DrawResumeStateSelector(); static void DoLoadState(std::string path); static void DoSaveState(s32 slot, bool global); -static std::vector s_save_state_selector_slots; -static std::string s_save_state_selector_game_path; -static s32 s_save_state_selector_submenu_index = -1; -static bool s_save_state_selector_open = false; -static bool s_save_state_selector_loading = true; -static bool s_save_state_selector_resuming = false; - ////////////////////////////////////////////////////////////////////////// // Game List ////////////////////////////////////////////////////////////////////////// @@ -462,10 +416,71 @@ static GPUTexture* GetTextureForGameListEntryType(GameList::EntryType type); static GPUTexture* GetGameListCover(const GameList::Entry* entry); static GPUTexture* GetCoverForCurrentGame(); -// Lazily populated cover images. -static std::unordered_map s_cover_image_map; -static std::vector s_game_list_sorted_entries; -static GameListView s_game_list_view = GameListView::Grid; +namespace { + +struct ALIGN_TO_CACHE_LINE UIState +{ + // Main + MainWindowType current_main_window = MainWindowType::None; + PauseSubMenu current_pause_submenu = PauseSubMenu::None; + bool initialized = false; + bool tried_to_initialize = false; + bool pause_menu_was_open = false; + bool was_paused_on_quick_menu_open = false; + bool about_window_open = false; + bool achievements_login_window_open = false; + std::string current_game_subtitle; + + // Resources + std::shared_ptr app_icon_texture; + std::shared_ptr fallback_disc_texture; + std::shared_ptr fallback_exe_texture; + std::shared_ptr fallback_psf_texture; + std::shared_ptr fallback_playlist_texture; + + // Settings + SettingsPage settings_page = SettingsPage::Interface; + std::unique_ptr game_settings_interface; + std::unique_ptr game_settings_entry; + std::vector> game_list_directories_cache; + GPUDevice::AdapterInfoList graphics_adapter_list_cache; + std::vector fullscreen_mode_list_cache; + Cheats::CodeInfoList game_patch_list; + std::vector enabled_game_patch_cache; + Cheats::CodeInfoList game_cheats_list; + std::vector enabled_game_cheat_cache; + std::vector game_cheat_groups; + std::vector postprocessing_stages; + std::vector hotkey_list_cache; + std::atomic_bool settings_changed{false}; + std::atomic_bool game_settings_changed{false}; + InputBindingInfo::Type input_binding_type = InputBindingInfo::Type::Unknown; + std::string input_binding_section; + std::string input_binding_key; + std::string input_binding_display_name; + std::vector input_binding_new_bindings; + std::vector>> input_binding_value_ranges; + Timer input_binding_timer; + bool controller_macro_expanded[NUM_CONTROLLER_AND_CARD_PORTS][InputManager::NUM_MACRO_BUTTONS_PER_CONTROLLER] = {}; + + // Save State List + std::vector save_state_selector_slots; + std::string save_state_selector_game_path; + s32 save_state_selector_submenu_index = -1; + bool save_state_selector_open = false; + bool save_state_selector_loading = true; + bool save_state_selector_resuming = false; + + // Lazily populated cover images. + std::unordered_map cover_image_map; + std::vector game_list_sorted_entries; + GameListView game_list_view = GameListView::Grid; +}; + +} // namespace + +static UIState s_state; + } // namespace FullscreenUI ////////////////////////////////////////////////////////////////////////// @@ -559,10 +574,10 @@ void ImGuiFullscreen::GetInputDialogHelpText(SmallStringBase& dest) bool FullscreenUI::Initialize() { - if (s_initialized) + if (s_state.initialized) return true; - if (s_tried_to_initialize) + if (s_state.tried_to_initialize) return false; ImGuiFullscreen::SetTheme(Host::GetBaseBoolSettingValue("Main", "UseLightFullscreenUITheme", false)); @@ -574,17 +589,17 @@ bool FullscreenUI::Initialize() { DestroyResources(); ImGuiFullscreen::Shutdown(); - s_tried_to_initialize = true; + s_state.tried_to_initialize = true; return false; } - s_initialized = true; - s_current_main_window = MainWindowType::None; - s_current_pause_submenu = PauseSubMenu::None; - s_pause_menu_was_open = false; - s_was_paused_on_quick_menu_open = false; - s_about_window_open = false; - s_hotkey_list_cache = InputManager::GetHotkeyList(); + s_state.initialized = true; + s_state.current_main_window = MainWindowType::None; + s_state.current_pause_submenu = PauseSubMenu::None; + s_state.pause_menu_was_open = false; + s_state.was_paused_on_quick_menu_open = false; + s_state.about_window_open = false; + s_state.hotkey_list_cache = InputManager::GetHotkeyList(); if (!System::IsValid()) SwitchToLanding(); @@ -598,18 +613,18 @@ bool FullscreenUI::Initialize() bool FullscreenUI::IsInitialized() { - return s_initialized; + return s_state.initialized; } bool FullscreenUI::HasActiveWindow() { - return s_initialized && (s_current_main_window != MainWindowType::None || AreAnyDialogsOpen()); + return s_state.initialized && (s_state.current_main_window != MainWindowType::None || AreAnyDialogsOpen()); } bool FullscreenUI::AreAnyDialogsOpen() { - return (s_save_state_selector_open || s_about_window_open || - s_input_binding_type != InputBindingInfo::Type::Unknown || ImGuiFullscreen::IsChoiceDialogOpen() || + return (s_state.save_state_selector_open || s_state.about_window_open || + s_state.input_binding_type != InputBindingInfo::Type::Unknown || ImGuiFullscreen::IsChoiceDialogOpen() || ImGuiFullscreen::IsFileSelectorOpen()); } @@ -622,7 +637,8 @@ void FullscreenUI::CheckForConfigChanges(const Settings& old_settings) // That means we're going to be reading achievement state. if (old_settings.achievements_enabled && !g_settings.achievements_enabled) { - if (s_current_main_window == MainWindowType::Achievements || s_current_main_window == MainWindowType::Leaderboards) + if (s_state.current_main_window == MainWindowType::Achievements || + s_state.current_main_window == MainWindowType::Leaderboards) ReturnToPreviousWindow(); } } @@ -632,7 +648,7 @@ void FullscreenUI::OnSystemStarted() if (!IsInitialized()) return; - s_current_main_window = MainWindowType::None; + s_state.current_main_window = MainWindowType::None; QueueResetFocus(FocusResetType::ViewChanged); } @@ -644,7 +660,7 @@ void FullscreenUI::OnSystemPaused() void FullscreenUI::OnSystemResumed() { // get rid of pause menu if we unpaused another way - if (s_current_main_window == MainWindowType::PauseMenu) + if (s_state.current_main_window == MainWindowType::PauseMenu) ClosePauseMenu(); } @@ -653,9 +669,9 @@ void FullscreenUI::OnSystemDestroyed() if (!IsInitialized()) return; - s_pause_menu_was_open = false; - s_was_paused_on_quick_menu_open = false; - s_current_pause_submenu = PauseSubMenu::None; + s_state.pause_menu_was_open = false; + s_state.was_paused_on_quick_menu_open = false; + s_state.current_pause_submenu = PauseSubMenu::None; SwitchToLanding(); } @@ -667,18 +683,18 @@ void FullscreenUI::OnRunningGameChanged() const std::string& path = System::GetDiscPath(); const std::string& serial = System::GetGameSerial(); if (!serial.empty()) - s_current_game_subtitle = fmt::format("{0} - {1}", serial, Path::GetFileName(path)); + s_state.current_game_subtitle = fmt::format("{0} - {1}", serial, Path::GetFileName(path)); else - s_current_game_subtitle = {}; + s_state.current_game_subtitle = {}; } void FullscreenUI::PauseForMenuOpen(bool set_pause_menu_open) { - s_was_paused_on_quick_menu_open = (System::GetState() == System::State::Paused); - if (!s_was_paused_on_quick_menu_open) + s_state.was_paused_on_quick_menu_open = (System::GetState() == System::State::Paused); + if (!s_state.was_paused_on_quick_menu_open) Host::RunOnCPUThread([]() { System::PauseSystem(true); }); - s_pause_menu_was_open |= set_pause_menu_open; + s_state.pause_menu_was_open |= set_pause_menu_open; } void FullscreenUI::OpenPauseMenu() @@ -686,12 +702,12 @@ void FullscreenUI::OpenPauseMenu() if (!System::IsValid()) return; - if (!Initialize() || s_current_main_window != MainWindowType::None) + if (!Initialize() || s_state.current_main_window != MainWindowType::None) return; PauseForMenuOpen(true); - s_current_main_window = MainWindowType::PauseMenu; - s_current_pause_submenu = PauseSubMenu::None; + s_state.current_main_window = MainWindowType::PauseMenu; + s_state.current_pause_submenu = PauseSubMenu::None; QueueResetFocus(FocusResetType::ViewChanged); ForceKeyNavEnabled(); FixStateIfPaused(); @@ -702,10 +718,10 @@ void FullscreenUI::OpenCheatsMenu() if (!System::IsValid()) return; - if (!Initialize() || s_current_main_window != MainWindowType::None || !SwitchToGameSettings()) + if (!Initialize() || s_state.current_main_window != MainWindowType::None || !SwitchToGameSettings()) return; - s_settings_page = SettingsPage::Cheats; + s_state.settings_page = SettingsPage::Cheats; PauseForMenuOpen(true); ForceKeyNavEnabled(); FixStateIfPaused(); @@ -735,20 +751,20 @@ void FullscreenUI::ClosePauseMenu() if (!IsInitialized() || !System::IsValid()) return; - if (System::GetState() == System::State::Paused && !s_was_paused_on_quick_menu_open) + if (System::GetState() == System::State::Paused && !s_state.was_paused_on_quick_menu_open) Host::RunOnCPUThread([]() { System::PauseSystem(false); }); - s_current_main_window = MainWindowType::None; - s_current_pause_submenu = PauseSubMenu::None; - s_pause_menu_was_open = false; + s_state.current_main_window = MainWindowType::None; + s_state.current_pause_submenu = PauseSubMenu::None; + s_state.pause_menu_was_open = false; QueueResetFocus(FocusResetType::ViewChanged); FixStateIfPaused(); } void FullscreenUI::OpenPauseSubMenu(PauseSubMenu submenu) { - s_current_main_window = MainWindowType::PauseMenu; - s_current_pause_submenu = submenu; + s_state.current_main_window = MainWindowType::PauseMenu; + s_state.current_pause_submenu = submenu; QueueResetFocus(FocusResetType::ViewChanged); } @@ -757,29 +773,29 @@ void FullscreenUI::Shutdown() Achievements::ClearUIState(); ClearInputBindingVariables(); CloseSaveStateSelector(); - s_cover_image_map.clear(); - std::memset(s_controller_macro_expanded, 0, sizeof(s_controller_macro_expanded)); - s_game_list_sorted_entries = {}; - s_game_list_directories_cache = {}; - s_game_patch_list = {}; - s_enabled_game_patch_cache = {}; - s_game_cheats_list = {}; - s_enabled_game_cheat_cache = {}; - s_game_cheat_groups = {}; - s_postprocessing_stages = {}; - s_fullscreen_mode_list_cache = {}; - s_graphics_adapter_list_cache = {}; - s_hotkey_list_cache = {}; - s_current_game_subtitle = {}; + s_state.cover_image_map.clear(); + std::memset(s_state.controller_macro_expanded, 0, sizeof(s_state.controller_macro_expanded)); + s_state.game_list_sorted_entries = {}; + s_state.game_list_directories_cache = {}; + s_state.game_patch_list = {}; + s_state.enabled_game_patch_cache = {}; + s_state.game_cheats_list = {}; + s_state.enabled_game_cheat_cache = {}; + s_state.game_cheat_groups = {}; + s_state.postprocessing_stages = {}; + s_state.fullscreen_mode_list_cache = {}; + s_state.graphics_adapter_list_cache = {}; + s_state.hotkey_list_cache = {}; + s_state.current_game_subtitle = {}; DestroyResources(); ImGuiFullscreen::Shutdown(); - s_initialized = false; - s_tried_to_initialize = false; + s_state.initialized = false; + s_state.tried_to_initialize = false; } void FullscreenUI::Render() { - if (!s_initialized) + if (!s_state.initialized) return; ImGuiFullscreen::UploadAsyncTextures(); @@ -787,10 +803,10 @@ void FullscreenUI::Render() ImGuiFullscreen::BeginLayout(); // Primed achievements must come first, because we don't want the pause screen to be behind them. - if (s_current_main_window == MainWindowType::None) + if (s_state.current_main_window == MainWindowType::None) Achievements::DrawGameOverlays(); - switch (s_current_main_window) + switch (s_state.current_main_window) { case MainWindowType::Landing: DrawLandingWindow(); @@ -823,39 +839,39 @@ void FullscreenUI::Render() break; } - if (s_save_state_selector_open) + if (s_state.save_state_selector_open) { - if (s_save_state_selector_resuming) + if (s_state.save_state_selector_resuming) DrawResumeStateSelector(); else - DrawSaveStateSelector(s_save_state_selector_loading); + DrawSaveStateSelector(s_state.save_state_selector_loading); } - if (s_about_window_open) + if (s_state.about_window_open) DrawAboutWindow(); - if (s_input_binding_type != InputBindingInfo::Type::Unknown) + if (s_state.input_binding_type != InputBindingInfo::Type::Unknown) DrawInputBindingWindow(); ImGuiFullscreen::EndLayout(); - if (s_settings_changed.load(std::memory_order_relaxed)) + if (s_state.settings_changed.load(std::memory_order_relaxed)) { Host::CommitBaseSettingChanges(); Host::RunOnCPUThread([]() { System::ApplySettings(false); }); - s_settings_changed.store(false, std::memory_order_release); + s_state.settings_changed.store(false, std::memory_order_release); } - if (s_game_settings_changed.load(std::memory_order_relaxed)) + if (s_state.game_settings_changed.load(std::memory_order_relaxed)) { - if (s_game_settings_interface) + if (s_state.game_settings_interface) { Error error; - s_game_settings_interface->RemoveEmptySections(); + s_state.game_settings_interface->RemoveEmptySections(); - if (s_game_settings_interface->IsEmpty()) + if (s_state.game_settings_interface->IsEmpty()) { - if (FileSystem::FileExists(s_game_settings_interface->GetFileName().c_str()) && - !FileSystem::DeleteFile(s_game_settings_interface->GetFileName().c_str(), &error)) + if (FileSystem::FileExists(s_state.game_settings_interface->GetFileName().c_str()) && + !FileSystem::DeleteFile(s_state.game_settings_interface->GetFileName().c_str(), &error)) { ImGuiFullscreen::OpenInfoMessageDialog( FSUI_STR("Error"), fmt::format(FSUI_FSTR("An error occurred while deleting empty game settings:\n{}"), @@ -864,7 +880,7 @@ void FullscreenUI::Render() } else { - if (!s_game_settings_interface->Save(&error)) + if (!s_state.game_settings_interface->Save(&error)) { ImGuiFullscreen::OpenInfoMessageDialog( FSUI_STR("Error"), @@ -875,7 +891,7 @@ void FullscreenUI::Render() if (System::IsValid()) Host::RunOnCPUThread([]() { System::ReloadGameSettings(false); }); } - s_game_settings_changed.store(false, std::memory_order_release); + s_state.game_settings_changed.store(false, std::memory_order_release); } ImGuiFullscreen::ResetCloseMenuIfNeeded(); @@ -886,14 +902,14 @@ void FullscreenUI::InvalidateCoverCache() if (!IsInitialized()) return; - Host::RunOnCPUThread([]() { s_cover_image_map.clear(); }); + Host::RunOnCPUThread([]() { s_state.cover_image_map.clear(); }); } void FullscreenUI::ReturnToPreviousWindow() { - if (System::IsValid() && s_pause_menu_was_open) + if (System::IsValid() && s_state.pause_menu_was_open) { - s_current_main_window = MainWindowType::PauseMenu; + s_state.current_main_window = MainWindowType::PauseMenu; QueueResetFocus(FocusResetType::ViewChanged); } else @@ -905,28 +921,28 @@ void FullscreenUI::ReturnToPreviousWindow() void FullscreenUI::ReturnToMainWindow() { ClosePauseMenu(); - s_current_main_window = System::IsValid() ? MainWindowType::None : MainWindowType::Landing; + s_state.current_main_window = System::IsValid() ? MainWindowType::None : MainWindowType::Landing; FixStateIfPaused(); } bool FullscreenUI::LoadResources() { - s_app_icon_texture = LoadTexture("images/duck.png"); + s_state.app_icon_texture = LoadTexture("images/duck.png"); - s_fallback_disc_texture = LoadTexture("fullscreenui/media-cdrom.png"); - s_fallback_exe_texture = LoadTexture("fullscreenui/applications-system.png"); - s_fallback_psf_texture = LoadTexture("fullscreenui/multimedia-player.png"); - s_fallback_playlist_texture = LoadTexture("fullscreenui/address-book-new.png"); + s_state.fallback_disc_texture = LoadTexture("fullscreenui/media-cdrom.png"); + s_state.fallback_exe_texture = LoadTexture("fullscreenui/applications-system.png"); + s_state.fallback_psf_texture = LoadTexture("fullscreenui/multimedia-player.png"); + s_state.fallback_playlist_texture = LoadTexture("fullscreenui/address-book-new.png"); return true; } void FullscreenUI::DestroyResources() { - s_app_icon_texture.reset(); - s_fallback_playlist_texture.reset(); - s_fallback_psf_texture.reset(); - s_fallback_exe_texture.reset(); - s_fallback_disc_texture.reset(); + s_state.app_icon_texture.reset(); + s_state.fallback_playlist_texture.reset(); + s_state.fallback_psf_texture.reset(); + s_state.fallback_exe_texture.reset(); + s_state.fallback_disc_texture.reset(); } ////////////////////////////////////////////////////////////////////////// @@ -975,11 +991,11 @@ void FullscreenUI::DoResume() return; CloseSaveStateSelector(); - s_save_state_selector_slots.push_back(std::move(slentry)); - s_save_state_selector_game_path = {}; - s_save_state_selector_loading = true; - s_save_state_selector_open = true; - s_save_state_selector_resuming = true; + s_state.save_state_selector_slots.push_back(std::move(slentry)); + s_state.save_state_selector_game_path = {}; + s_state.save_state_selector_loading = true; + s_state.save_state_selector_open = true; + s_state.save_state_selector_resuming = true; } void FullscreenUI::DoStartFile() @@ -1263,7 +1279,7 @@ void FullscreenUI::DoToggleFullscreen() void FullscreenUI::SwitchToLanding() { - s_current_main_window = MainWindowType::Landing; + s_state.current_main_window = MainWindowType::Landing; QueueResetFocus(FocusResetType::ViewChanged); } @@ -1289,7 +1305,7 @@ void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size) { const ImVec2 logo_pos = LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING, LAYOUT_MENU_BUTTON_Y_PADDING); const ImVec2 logo_size = LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); - dl->AddImage(s_app_icon_texture.get(), logo_pos, logo_pos + logo_size); + dl->AddImage(s_state.app_icon_texture.get(), logo_pos, logo_pos + logo_size); dl->AddText(heading_font, heading_font->FontSize, ImVec2(logo_pos.x + logo_size.x + LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING), logo_pos.y), ImGui::GetColorU32(ImGuiCol_Text), "DuckStation"); @@ -1360,7 +1376,7 @@ void FullscreenUI::DrawLandingWindow() GetCachedTexture("fullscreenui/media-cdrom.png"), FSUI_CSTR("Start Game"), FSUI_CSTR("Launch a game from a file, disc, or starts the console without any disc inserted."))) { - s_current_main_window = MainWindowType::StartGame; + s_state.current_main_window = MainWindowType::StartGame; QueueResetFocus(FocusResetType::ViewChanged); } @@ -1374,7 +1390,7 @@ void FullscreenUI::DrawLandingWindow() FSUI_CSTR("Return to desktop mode, or exit the application.")) || (!AreAnyDialogsOpen() && WantsToCloseMenu())) { - s_current_main_window = MainWindowType::Exit; + s_state.current_main_window = MainWindowType::Exit; QueueResetFocus(FocusResetType::ViewChanged); } } @@ -1445,7 +1461,7 @@ void FullscreenUI::DrawStartGameWindow() FSUI_CSTR("Return to the previous menu.")) || (!AreAnyDialogsOpen() && WantsToCloseMenu())) { - s_current_main_window = MainWindowType::Landing; + s_state.current_main_window = MainWindowType::Landing; QueueResetFocus(FocusResetType::ViewChanged); } } @@ -1491,7 +1507,7 @@ void FullscreenUI::DrawExitWindow() FSUI_CSTR("Return to the previous menu.")) || WantsToCloseMenu()) { - s_current_main_window = MainWindowType::Landing; + s_state.current_main_window = MainWindowType::Landing; QueueResetFocus(FocusResetType::ViewChanged); } @@ -1521,26 +1537,27 @@ bool FullscreenUI::ShouldShowAdvancedSettings() bool FullscreenUI::IsEditingGameSettings(SettingsInterface* bsi) { - return (bsi == s_game_settings_interface.get()); + return (bsi == s_state.game_settings_interface.get()); } SettingsInterface* FullscreenUI::GetEditingSettingsInterface() { - return s_game_settings_interface ? s_game_settings_interface.get() : Host::Internal::GetBaseSettingsLayer(); + return s_state.game_settings_interface ? s_state.game_settings_interface.get() : + Host::Internal::GetBaseSettingsLayer(); } SettingsInterface* FullscreenUI::GetEditingSettingsInterface(bool game_settings) { - return (game_settings && s_game_settings_interface) ? s_game_settings_interface.get() : - Host::Internal::GetBaseSettingsLayer(); + return (game_settings && s_state.game_settings_interface) ? s_state.game_settings_interface.get() : + Host::Internal::GetBaseSettingsLayer(); } void FullscreenUI::SetSettingsChanged(SettingsInterface* bsi) { - if (bsi && bsi == s_game_settings_interface.get()) - s_game_settings_changed.store(true, std::memory_order_release); + if (bsi && bsi == s_state.game_settings_interface.get()) + s_state.game_settings_changed.store(true, std::memory_order_release); else - s_settings_changed.store(true, std::memory_order_release); + s_state.settings_changed.store(true, std::memory_order_release); } bool FullscreenUI::GetEffectiveBoolSetting(SettingsInterface* bsi, const char* section, const char* key, @@ -1715,36 +1732,36 @@ void FullscreenUI::DrawInputBindingButton(SettingsInterface* bsi, InputBindingIn void FullscreenUI::ClearInputBindingVariables() { - s_input_binding_type = InputBindingInfo::Type::Unknown; - s_input_binding_section = {}; - s_input_binding_key = {}; - s_input_binding_display_name = {}; - s_input_binding_new_bindings = {}; - s_input_binding_value_ranges = {}; + s_state.input_binding_type = InputBindingInfo::Type::Unknown; + s_state.input_binding_section = {}; + s_state.input_binding_key = {}; + s_state.input_binding_display_name = {}; + s_state.input_binding_new_bindings = {}; + s_state.input_binding_value_ranges = {}; } void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::Type type, std::string_view section, std::string_view key, std::string_view display_name) { - if (s_input_binding_type != InputBindingInfo::Type::Unknown) + if (s_state.input_binding_type != InputBindingInfo::Type::Unknown) { InputManager::RemoveHook(); ClearInputBindingVariables(); } - s_input_binding_type = type; - s_input_binding_section = section; - s_input_binding_key = key; - s_input_binding_display_name = display_name; - s_input_binding_new_bindings = {}; - s_input_binding_value_ranges = {}; - s_input_binding_timer.Reset(); + s_state.input_binding_type = type; + s_state.input_binding_section = section; + s_state.input_binding_key = key; + s_state.input_binding_display_name = display_name; + s_state.input_binding_new_bindings = {}; + s_state.input_binding_value_ranges = {}; + s_state.input_binding_timer.Reset(); const bool game_settings = IsEditingGameSettings(bsi); InputManager::SetHook([game_settings](InputBindingKey key, float value) -> InputInterceptHook::CallbackResult { // shouldn't happen, just in case - if (s_input_binding_type == InputBindingInfo::Type::Unknown) + if (s_state.input_binding_type == InputBindingInfo::Type::Unknown) return InputInterceptHook::CallbackResult::RemoveHookAndContinueProcessingEvent; // holding the settings lock here will protect the input binding list @@ -1753,17 +1770,17 @@ void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::T float initial_value = value; float min_value = value; InputInterceptHook::CallbackResult default_action = InputInterceptHook::CallbackResult::StopProcessingEvent; - const auto it = std::find_if(s_input_binding_value_ranges.begin(), s_input_binding_value_ranges.end(), + const auto it = std::find_if(s_state.input_binding_value_ranges.begin(), s_state.input_binding_value_ranges.end(), [key](const auto& it) { return it.first.bits == key.bits; }); - if (it != s_input_binding_value_ranges.end()) + if (it != s_state.input_binding_value_ranges.end()) { initial_value = it->second.first; min_value = it->second.second = std::min(it->second.second, value); } else { - s_input_binding_value_ranges.emplace_back(key, std::make_pair(initial_value, min_value)); + s_state.input_binding_value_ranges.emplace_back(key, std::make_pair(initial_value, min_value)); // forward the event to imgui if it's a new key and a release, because this is what triggered the binding to start // if we don't do this, imgui thinks the activate button is held down @@ -1774,7 +1791,7 @@ void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::T const float abs_value = std::abs(value); const bool reverse_threshold = (key.source_subtype == InputSubclass::ControllerAxis && initial_value > 0.5f); - for (InputBindingKey& other_key : s_input_binding_new_bindings) + for (InputBindingKey& other_key : s_state.input_binding_new_bindings) { // if this key is in our new binding list, it's a "release", and we're done if (other_key.MaskDirection() == key.MaskDirection()) @@ -1788,8 +1805,10 @@ void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::T SettingsInterface* bsi = GetEditingSettingsInterface(game_settings); const std::string new_binding(InputManager::ConvertInputBindingKeysToString( - s_input_binding_type, s_input_binding_new_bindings.data(), s_input_binding_new_bindings.size())); - bsi->SetStringValue(s_input_binding_section.c_str(), s_input_binding_key.c_str(), new_binding.c_str()); + s_state.input_binding_type, s_state.input_binding_new_bindings.data(), + s_state.input_binding_new_bindings.size())); + bsi->SetStringValue(s_state.input_binding_section.c_str(), s_state.input_binding_key.c_str(), + new_binding.c_str()); SetSettingsChanged(bsi); ClearInputBindingVariables(); QueueResetFocus(FocusResetType::PopupClosed); @@ -1807,7 +1826,7 @@ void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::T InputBindingKey key_to_add = key; key_to_add.modifier = (value < 0.0f && !reverse_threshold) ? InputModifier::Negate : InputModifier::None; key_to_add.invert = reverse_threshold; - s_input_binding_new_bindings.push_back(key_to_add); + s_state.input_binding_new_bindings.push_back(key_to_add); } return default_action; @@ -1816,9 +1835,9 @@ void FullscreenUI::BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::T void FullscreenUI::DrawInputBindingWindow() { - DebugAssert(s_input_binding_type != InputBindingInfo::Type::Unknown); + DebugAssert(s_state.input_binding_type != InputBindingInfo::Type::Unknown); - const double time_remaining = INPUT_BINDING_TIMEOUT_SECONDS - s_input_binding_timer.GetTimeSeconds(); + const double time_remaining = INPUT_BINDING_TIMEOUT_SECONDS - s_state.input_binding_timer.GetTimeSeconds(); if (time_remaining <= 0.0) { InputManager::RemoveHook(); @@ -1843,8 +1862,8 @@ void FullscreenUI::DrawInputBindingWindow() ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoCollapse)) { - ImGui::TextWrapped("%s", SmallString::from_format(FSUI_FSTR("Setting {} binding {}."), s_input_binding_section, - s_input_binding_display_name) + ImGui::TextWrapped("%s", SmallString::from_format(FSUI_FSTR("Setting {} binding {}."), + s_state.input_binding_section, s_state.input_binding_display_name) .c_str()); ImGui::TextUnformatted(FSUI_CSTR("Push a controller button or axis now.")); ImGui::NewLine(); @@ -2663,7 +2682,7 @@ void FullscreenUI::DrawFolderSetting(SettingsInterface* bsi, const char* title, SetSettingsChanged(bsi); Host::RunOnCPUThread(&EmuFolders::Update); - s_cover_image_map.clear(); + s_state.cover_image_map.clear(); CloseFileSelector(); }); @@ -2709,29 +2728,29 @@ void FullscreenUI::StartAutomaticBinding(u32 port) void FullscreenUI::SwitchToSettings() { - s_game_settings_entry.reset(); - s_game_settings_interface.reset(); - s_game_patch_list = {}; - s_enabled_game_patch_cache = {}; - s_game_cheats_list = {}; - s_enabled_game_cheat_cache = {}; - s_game_cheat_groups = {}; + s_state.game_settings_entry.reset(); + s_state.game_settings_interface.reset(); + s_state.game_patch_list = {}; + s_state.enabled_game_patch_cache = {}; + s_state.game_cheats_list = {}; + s_state.enabled_game_cheat_cache = {}; + s_state.game_cheat_groups = {}; PopulateGraphicsAdapterList(); PopulatePostProcessingChain(GetEditingSettingsInterface(), PostProcessing::Config::DISPLAY_CHAIN_SECTION); - s_current_main_window = MainWindowType::Settings; - s_settings_page = SettingsPage::Interface; + s_state.current_main_window = MainWindowType::Settings; + s_state.settings_page = SettingsPage::Interface; } void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial) { - s_game_settings_entry.reset(); - s_game_settings_interface = std::make_unique(System::GetGameSettingsPath(serial)); - s_game_settings_interface->Load(); + s_state.game_settings_entry.reset(); + s_state.game_settings_interface = std::make_unique(System::GetGameSettingsPath(serial)); + s_state.game_settings_interface->Load(); PopulatePatchesAndCheatsList(serial); - s_current_main_window = MainWindowType::Settings; - s_settings_page = SettingsPage::Summary; + s_state.current_main_window = MainWindowType::Settings; + s_state.settings_page = SettingsPage::Summary; QueueResetFocus(FocusResetType::ViewChanged); } @@ -2768,7 +2787,7 @@ bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path) void FullscreenUI::SwitchToGameSettings(const GameList::Entry* entry) { SwitchToGameSettingsForSerial(entry->serial); - s_game_settings_entry = std::make_unique(*entry); + s_state.game_settings_entry = std::make_unique(*entry); } void FullscreenUI::PopulateGraphicsAdapterList() @@ -2779,58 +2798,58 @@ void FullscreenUI::PopulateGraphicsAdapterList() .c_str()) .value_or(Settings::DEFAULT_GPU_RENDERER); - s_graphics_adapter_list_cache = GPUDevice::GetAdapterListForAPI(Settings::GetRenderAPIForRenderer(renderer)); + s_state.graphics_adapter_list_cache = GPUDevice::GetAdapterListForAPI(Settings::GetRenderAPIForRenderer(renderer)); } void FullscreenUI::PopulateGameListDirectoryCache(SettingsInterface* si) { - s_game_list_directories_cache.clear(); + s_state.game_list_directories_cache.clear(); for (std::string& dir : si->GetStringList("GameList", "Paths")) - s_game_list_directories_cache.emplace_back(std::move(dir), false); + s_state.game_list_directories_cache.emplace_back(std::move(dir), false); for (std::string& dir : si->GetStringList("GameList", "RecursivePaths")) - s_game_list_directories_cache.emplace_back(std::move(dir), true); + s_state.game_list_directories_cache.emplace_back(std::move(dir), true); } void FullscreenUI::PopulatePatchesAndCheatsList(const std::string_view serial) { - s_game_patch_list = Cheats::GetCodeInfoList(serial, std::nullopt, false, true, true); - s_game_cheats_list = - Cheats::GetCodeInfoList(serial, std::nullopt, true, - s_game_settings_interface->GetBoolValue("Cheats", "LoadCheatsFromDatabase", true), true); - s_game_cheat_groups = Cheats::GetCodeListUniquePrefixes(s_game_cheats_list, true); - s_enabled_game_patch_cache = - s_game_settings_interface->GetStringList(Cheats::PATCHES_CONFIG_SECTION, Cheats::PATCH_ENABLE_CONFIG_KEY); - s_enabled_game_cheat_cache = - s_game_settings_interface->GetStringList(Cheats::CHEATS_CONFIG_SECTION, Cheats::PATCH_ENABLE_CONFIG_KEY); + s_state.game_patch_list = Cheats::GetCodeInfoList(serial, std::nullopt, false, true, true); + s_state.game_cheats_list = Cheats::GetCodeInfoList( + serial, std::nullopt, true, s_state.game_settings_interface->GetBoolValue("Cheats", "LoadCheatsFromDatabase", true), + true); + s_state.game_cheat_groups = Cheats::GetCodeListUniquePrefixes(s_state.game_cheats_list, true); + s_state.enabled_game_patch_cache = + s_state.game_settings_interface->GetStringList(Cheats::PATCHES_CONFIG_SECTION, Cheats::PATCH_ENABLE_CONFIG_KEY); + s_state.enabled_game_cheat_cache = + s_state.game_settings_interface->GetStringList(Cheats::CHEATS_CONFIG_SECTION, Cheats::PATCH_ENABLE_CONFIG_KEY); } void FullscreenUI::DoCopyGameSettings() { - if (!s_game_settings_interface) + if (!s_state.game_settings_interface) return; Settings temp_settings; temp_settings.Load(*GetEditingSettingsInterface(false), *GetEditingSettingsInterface(false)); - temp_settings.Save(*s_game_settings_interface, true); - SetSettingsChanged(s_game_settings_interface.get()); + temp_settings.Save(*s_state.game_settings_interface, true); + SetSettingsChanged(s_state.game_settings_interface.get()); ShowToast("Game Settings Copied", fmt::format(FSUI_FSTR("Game settings initialized with global settings for '{}'."), - Path::GetFileTitle(s_game_settings_interface->GetFileName()))); + Path::GetFileTitle(s_state.game_settings_interface->GetFileName()))); } void FullscreenUI::DoClearGameSettings() { - if (!s_game_settings_interface) + if (!s_state.game_settings_interface) return; - s_game_settings_interface->Clear(); - if (!s_game_settings_interface->GetFileName().empty()) - FileSystem::DeleteFile(s_game_settings_interface->GetFileName().c_str()); + s_state.game_settings_interface->Clear(); + if (!s_state.game_settings_interface->GetFileName().empty()) + FileSystem::DeleteFile(s_state.game_settings_interface->GetFileName().c_str()); - SetSettingsChanged(s_game_settings_interface.get()); + SetSettingsChanged(s_state.game_settings_interface.get()); ShowToast("Game Settings Cleared", fmt::format(FSUI_FSTR("Game settings have been cleared for '{}'."), - Path::GetFileTitle(s_game_settings_interface->GetFileName()))); + Path::GetFileTitle(s_state.game_settings_interface->GetFileName()))); } void FullscreenUI::DrawSettingsWindow() @@ -2840,7 +2859,8 @@ void FullscreenUI::DrawSettingsWindow() ImVec2(io.DisplaySize.x, LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY) + (LayoutScale(LAYOUT_MENU_BUTTON_Y_PADDING) * 2.0f) + LayoutScale(2.0f)); - const float bg_alpha = System::IsValid() ? (s_settings_page == SettingsPage::PostProcessing ? 0.50f : 0.90f) : 1.0f; + const float bg_alpha = + System::IsValid() ? (s_state.settings_page == SettingsPage::PostProcessing ? 0.50f : 0.90f) : 1.0f; if (BeginFullscreenWindow(ImVec2(0.0f, 0.0f), heading_size, "settings_category", ImVec4(UIStyle.PrimaryColor.x, UIStyle.PrimaryColor.y, UIStyle.PrimaryColor.z, bg_alpha))) @@ -2880,7 +2900,7 @@ void FullscreenUI::DrawSettingsWindow() u32 index = 0; for (u32 i = 0; i < count; i++) { - if (pages[i] == s_settings_page) + if (pages[i] == s_state.settings_page) { index = i; break; @@ -2895,7 +2915,7 @@ void FullscreenUI::DrawSettingsWindow() ImGui::IsKeyPressed(ImGuiKey_NavGamepadTweakSlow, true) || ImGui::IsKeyPressed(ImGuiKey_LeftArrow, true)) { index = (index == 0) ? (count - 1) : (index - 1); - s_settings_page = pages[index]; + s_state.settings_page = pages[index]; QueueResetFocus(FocusResetType::Other); } else if (ImGui::IsKeyPressed(ImGuiKey_GamepadDpadRight, true) || @@ -2903,7 +2923,7 @@ void FullscreenUI::DrawSettingsWindow() ImGui::IsKeyPressed(ImGuiKey_RightArrow, true)) { index = (index + 1) % count; - s_settings_page = pages[index]; + s_state.settings_page = pages[index]; QueueResetFocus(FocusResetType::Other); } } @@ -2911,8 +2931,8 @@ void FullscreenUI::DrawSettingsWindow() if (NavButton(ICON_FA_BACKWARD, true, true)) ReturnToPreviousWindow(); - if (s_game_settings_entry) - NavTitle(s_game_settings_entry->title.c_str()); + if (s_state.game_settings_entry) + NavTitle(s_state.game_settings_entry->title.c_str()); else NavTitle(Host::TranslateToCString(TR_CONTEXT, titles[static_cast(pages[index])].first)); @@ -2923,7 +2943,7 @@ void FullscreenUI::DrawSettingsWindow() if (NavButton(titles[static_cast(pages[i])].second, i == index, true, ITEM_WIDTH, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY)) { - s_settings_page = pages[i]; + s_state.settings_page = pages[i]; QueueResetFocus(FocusResetType::Other); } } @@ -2941,7 +2961,7 @@ void FullscreenUI::DrawSettingsWindow() if (BeginFullscreenWindow( ImVec2(0.0f, heading_size.y), ImVec2(io.DisplaySize.x, io.DisplaySize.y - heading_size.y - LayoutScale(LAYOUT_FOOTER_HEIGHT)), - TinyString::from_format("settings_page_{}", static_cast(s_settings_page)).c_str(), + TinyString::from_format("settings_page_{}", static_cast(s_state.settings_page)).c_str(), ImVec4(UIStyle.BackgroundColor.x, UIStyle.BackgroundColor.y, UIStyle.BackgroundColor.z, bg_alpha), 0.0f, ImVec2(ImGuiFullscreen::LAYOUT_MENU_WINDOW_X_PADDING, 0.0f))) { @@ -2952,7 +2972,7 @@ void FullscreenUI::DrawSettingsWindow() auto lock = Host::GetSettingsLock(); - switch (s_settings_page) + switch (s_state.settings_page) { case SettingsPage::Summary: DrawSummarySettingsPage(); @@ -3043,38 +3063,38 @@ void FullscreenUI::DrawSummarySettingsPage() MenuHeading(FSUI_CSTR("Details")); - if (s_game_settings_entry) + if (s_state.game_settings_entry) { - if (MenuButton(FSUI_ICONSTR(ICON_FA_WINDOW_MAXIMIZE, "Title"), s_game_settings_entry->title.c_str(), true)) - CopyTextToClipboard(FSUI_STR("Game title copied to clipboard."), s_game_settings_entry->title); - if (MenuButton(FSUI_ICONSTR(ICON_FA_PAGER, "Serial"), s_game_settings_entry->serial.c_str(), true)) - CopyTextToClipboard(FSUI_STR("Game serial copied to clipboard."), s_game_settings_entry->serial); + if (MenuButton(FSUI_ICONSTR(ICON_FA_WINDOW_MAXIMIZE, "Title"), s_state.game_settings_entry->title.c_str(), true)) + CopyTextToClipboard(FSUI_STR("Game title copied to clipboard."), s_state.game_settings_entry->title); + if (MenuButton(FSUI_ICONSTR(ICON_FA_PAGER, "Serial"), s_state.game_settings_entry->serial.c_str(), true)) + CopyTextToClipboard(FSUI_STR("Game serial copied to clipboard."), s_state.game_settings_entry->serial); if (MenuButton(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Type"), - GameList::GetEntryTypeDisplayName(s_game_settings_entry->type), true)) + GameList::GetEntryTypeDisplayName(s_state.game_settings_entry->type), true)) { CopyTextToClipboard(FSUI_STR("Game type copied to clipboard."), - GameList::GetEntryTypeDisplayName(s_game_settings_entry->type)); + GameList::GetEntryTypeDisplayName(s_state.game_settings_entry->type)); } if (MenuButton(FSUI_ICONSTR(ICON_FA_BOX, "Region"), - Settings::GetDiscRegionDisplayName(s_game_settings_entry->region), true)) + Settings::GetDiscRegionDisplayName(s_state.game_settings_entry->region), true)) { CopyTextToClipboard(FSUI_STR("Game region copied to clipboard."), - Settings::GetDiscRegionDisplayName(s_game_settings_entry->region)); + Settings::GetDiscRegionDisplayName(s_state.game_settings_entry->region)); } if (MenuButton(FSUI_ICONSTR(ICON_FA_STAR, "Compatibility Rating"), - GameDatabase::GetCompatibilityRatingDisplayName(s_game_settings_entry->dbentry ? - s_game_settings_entry->dbentry->compatibility : - GameDatabase::CompatibilityRating::Unknown), + GameDatabase::GetCompatibilityRatingDisplayName( + s_state.game_settings_entry->dbentry ? s_state.game_settings_entry->dbentry->compatibility : + GameDatabase::CompatibilityRating::Unknown), true)) { CopyTextToClipboard(FSUI_STR("Game compatibility rating copied to clipboard."), GameDatabase::GetCompatibilityRatingDisplayName( - s_game_settings_entry->dbentry ? s_game_settings_entry->dbentry->compatibility : - GameDatabase::CompatibilityRating::Unknown)); + s_state.game_settings_entry->dbentry ? s_state.game_settings_entry->dbentry->compatibility : + GameDatabase::CompatibilityRating::Unknown)); } - if (MenuButton(FSUI_ICONSTR(ICON_FA_FOLDER_OPEN, "Path"), s_game_settings_entry->path.c_str(), true)) + if (MenuButton(FSUI_ICONSTR(ICON_FA_FOLDER_OPEN, "Path"), s_state.game_settings_entry->path.c_str(), true)) { - CopyTextToClipboard(FSUI_STR("Game path copied to clipboard."), s_game_settings_entry->path); + CopyTextToClipboard(FSUI_STR("Game path copied to clipboard."), s_state.game_settings_entry->path); } } else @@ -3845,10 +3865,10 @@ void FullscreenUI::DrawControllerSettingsPage() for (u32 macro_index = 0; macro_index < InputManager::NUM_MACRO_BUTTONS_PER_CONTROLLER; macro_index++) { - bool& expanded = s_controller_macro_expanded[global_slot][macro_index]; + bool& expanded = s_state.controller_macro_expanded[global_slot][macro_index]; expanded ^= MenuHeadingButton( SmallString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_PF_EMPTY_KEYCAP, "Macro Button {}")), macro_index + 1), - s_controller_macro_expanded[global_slot][macro_index] ? ICON_FA_CHEVRON_UP : ICON_FA_CHEVRON_DOWN); + s_state.controller_macro_expanded[global_slot][macro_index] ? ICON_FA_CHEVRON_UP : ICON_FA_CHEVRON_DOWN); if (!expanded) continue; @@ -4047,7 +4067,7 @@ void FullscreenUI::DrawHotkeySettingsPage() BeginMenuButtons(); const HotkeyInfo* last_category = nullptr; - for (const HotkeyInfo* hotkey : s_hotkey_list_cache) + for (const HotkeyInfo* hotkey : s_state.hotkey_list_cache) { if (!last_category || std::strcmp(hotkey->category, last_category->category) != 0) { @@ -4215,11 +4235,11 @@ void FullscreenUI::DrawGraphicsSettingsPage() FSUI_CSTR("Use Global Setting"))) { ImGuiFullscreen::ChoiceDialogOptions options; - options.reserve(s_graphics_adapter_list_cache.size() + 2); + options.reserve(s_state.graphics_adapter_list_cache.size() + 2); if (game_settings) options.emplace_back(FSUI_STR("Use Global Setting"), !current_adapter.has_value()); options.emplace_back(FSUI_STR("Default"), current_adapter.has_value() && current_adapter->empty()); - for (const GPUDevice::AdapterInfo& adapter : s_graphics_adapter_list_cache) + for (const GPUDevice::AdapterInfo& adapter : s_state.graphics_adapter_list_cache) { const bool checked = (current_adapter.has_value() && current_adapter.value() == adapter.name); options.emplace_back(adapter.name, checked); @@ -4371,7 +4391,7 @@ void FullscreenUI::DrawGraphicsSettingsPage() const GPUDevice::AdapterInfo* selected_adapter = nullptr; if (current_adapter.has_value()) { - for (const GPUDevice::AdapterInfo& ai : s_graphics_adapter_list_cache) + for (const GPUDevice::AdapterInfo& ai : s_state.graphics_adapter_list_cache) { if (ai.name == current_adapter->view()) { @@ -4382,8 +4402,8 @@ void FullscreenUI::DrawGraphicsSettingsPage() } else { - if (!s_graphics_adapter_list_cache.empty()) - selected_adapter = &s_graphics_adapter_list_cache.front(); + if (!s_state.graphics_adapter_list_cache.empty()) + selected_adapter = &s_state.graphics_adapter_list_cache.front(); } ImGuiFullscreen::ChoiceDialogOptions options; @@ -4613,14 +4633,14 @@ void FullscreenUI::DrawGraphicsSettingsPage() void FullscreenUI::PopulatePostProcessingChain(SettingsInterface* si, const char* section) { const u32 stages = PostProcessing::Config::GetStageCount(*si, section); - s_postprocessing_stages.clear(); - s_postprocessing_stages.reserve(stages); + s_state.postprocessing_stages.clear(); + s_state.postprocessing_stages.reserve(stages); for (u32 i = 0; i < stages; i++) { PostProcessingStageInfo psi; psi.name = PostProcessing::Config::GetStageShaderName(*si, section, i); psi.options = PostProcessing::Config::GetStageOptions(*si, section, i); - s_postprocessing_stages.push_back(std::move(psi)); + s_state.postprocessing_stages.push_back(std::move(psi)); } } @@ -4711,9 +4731,9 @@ void FullscreenUI::DrawPostProcessingSettingsPage() SmallString str; SmallString tstr; - for (u32 stage_index = 0; stage_index < static_cast(s_postprocessing_stages.size()); stage_index++) + for (u32 stage_index = 0; stage_index < static_cast(s_state.postprocessing_stages.size()); stage_index++) { - PostProcessingStageInfo& si = s_postprocessing_stages[stage_index]; + PostProcessingStageInfo& si = s_state.postprocessing_stages[stage_index]; ImGui::PushID(stage_index); str.format(FSUI_FSTR("Stage {}: {}"), stage_index + 1, si.name); @@ -4734,7 +4754,7 @@ void FullscreenUI::DrawPostProcessingSettingsPage() if (MenuButton(FSUI_ICONSTR(ICON_FA_ARROW_DOWN, "Move Down"), FSUI_CSTR("Moves this shader lower in the chain, applying it later."), - (stage_index != (s_postprocessing_stages.size() - 1)))) + (stage_index != (s_state.postprocessing_stages.size() - 1)))) { postprocessing_action = POSTPROCESSING_ACTION_MOVE_DOWN; postprocessing_action_index = stage_index; @@ -4972,7 +4992,7 @@ void FullscreenUI::DrawPostProcessingSettingsPage() { case POSTPROCESSING_ACTION_REMOVE: { - const PostProcessingStageInfo& si = s_postprocessing_stages[postprocessing_action_index]; + const PostProcessingStageInfo& si = s_state.postprocessing_stages[postprocessing_action_index]; ShowToast(std::string(), fmt::format(FSUI_FSTR("Removed stage {} ({})."), postprocessing_action_index + 1, si.name)); PostProcessing::Config::RemoveStage(*bsi, section, postprocessing_action_index); @@ -5148,11 +5168,11 @@ void FullscreenUI::DrawAchievementsSettingsPage() if (MenuButton(FSUI_ICONSTR(ICON_FA_KEY, "Login"), FSUI_CSTR("Logs in to RetroAchievements."))) { - s_achievements_login_window_open = true; + s_state.achievements_login_window_open = true; QueueResetFocus(FocusResetType::PopupOpened); } - if (s_achievements_login_window_open) + if (s_state.achievements_login_window_open) DrawAchievementsLoginWindow(); } @@ -5200,7 +5220,7 @@ void FullscreenUI::DrawAchievementsLoginWindow() static constexpr auto actually_close_popup = []() { std::memset(username, 0, sizeof(username)); std::memset(password, 0, sizeof(password)); - s_achievements_login_window_open = false; + s_state.achievements_login_window_open = false; QueueResetFocus(FocusResetType::PopupClosed); }; @@ -5259,13 +5279,13 @@ void FullscreenUI::DrawAchievementsLoginWindow() // keep popup open on failure // because of the whole popup stack thing, we need to hide the dialog while this popup is visible - s_achievements_login_window_open = false; + s_state.achievements_login_window_open = false; ImGuiFullscreen::OpenInfoMessageDialog( FSUI_STR("Login Error"), fmt::format(FSUI_FSTR("Login Failed.\nError: {}\nPlease check your username and password, and try again."), error.GetDescription()), []() { - s_achievements_login_window_open = true; + s_state.achievements_login_window_open = true; QueueResetFocus(FocusResetType::PopupOpened); }, FSUI_ICONSTR(ICON_FA_TIMES, "Close")); @@ -5370,8 +5390,8 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) { SettingsInterface* bsi = GetEditingSettingsInterface(); - const Cheats::CodeInfoList& code_list = cheats ? s_game_cheats_list : s_game_patch_list; - std::vector& enable_list = cheats ? s_enabled_game_cheat_cache : s_enabled_game_patch_cache; + const Cheats::CodeInfoList& code_list = cheats ? s_state.game_cheats_list : s_state.game_patch_list; + std::vector& enable_list = cheats ? s_state.enabled_game_cheat_cache : s_state.enabled_game_patch_cache; const char* section = cheats ? Cheats::CHEATS_CONFIG_SECTION : Cheats::PATCHES_CONFIG_SECTION; BeginMenuButtons(); @@ -5412,13 +5432,13 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) [cheat_name = ci.name, cheats, section](s32 index, const std::string& title, bool checked) { if (index >= 0) { - const Cheats::CodeInfo* ci = - Cheats::FindCodeInInfoList(cheats ? s_game_cheats_list : s_game_patch_list, cheat_name); + const Cheats::CodeInfo* ci = Cheats::FindCodeInInfoList( + cheats ? s_state.game_cheats_list : s_state.game_patch_list, cheat_name); if (ci) { SettingsInterface* bsi = GetEditingSettingsInterface(); std::vector& enable_list = - cheats ? s_enabled_game_cheat_cache : s_enabled_game_patch_cache; + cheats ? s_state.enabled_game_cheat_cache : s_state.enabled_game_patch_cache; const auto it = std::find(enable_list.begin(), enable_list.end(), ci->name); if (index == 0) { @@ -5603,8 +5623,8 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) else bsi->SetBoolValue("Cheats", "LoadCheatsFromDatabase", false); SetSettingsChanged(bsi); - if (s_game_settings_entry) - PopulatePatchesAndCheatsList(s_game_settings_entry->serial); + if (s_state.game_settings_entry) + PopulatePatchesAndCheatsList(s_state.game_settings_entry->serial); } if (code_list.empty()) @@ -5614,7 +5634,7 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) } else { - for (const std::string_view& group : s_game_cheat_groups) + for (const std::string_view& group : s_state.game_cheat_groups) { if (group.empty()) MenuHeading(FSUI_CSTR("Ungrouped")); @@ -5770,11 +5790,11 @@ void FullscreenUI::DrawPauseMenu() }; ResetFocusHere(); - BeginMenuButtons(submenu_item_count[static_cast(s_current_pause_submenu)], 1.0f, + BeginMenuButtons(submenu_item_count[static_cast(s_state.current_pause_submenu)], 1.0f, ImGuiFullscreen::LAYOUT_MENU_BUTTON_X_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_Y_PADDING, ImGuiFullscreen::LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); - switch (s_current_pause_submenu) + switch (s_state.current_pause_submenu) { case PauseSubMenu::None: { @@ -5793,13 +5813,13 @@ void FullscreenUI::DrawPauseMenu() if (ActiveButton(FSUI_ICONSTR(ICON_FA_UNDO, "Load State"), false, has_game)) { if (OpenSaveStateSelector(true)) - s_current_main_window = MainWindowType::None; + s_state.current_main_window = MainWindowType::None; } if (ActiveButton(FSUI_ICONSTR(ICON_FA_DOWNLOAD, "Save State"), false, has_game)) { if (OpenSaveStateSelector(false)) - s_current_main_window = MainWindowType::None; + s_state.current_main_window = MainWindowType::None; } if (ActiveButton(FSUI_ICONSTR(ICON_FA_GAMEPAD, "Toggle Analog"), false)) @@ -5831,7 +5851,7 @@ void FullscreenUI::DrawPauseMenu() if (ActiveButton(FSUI_ICONSTR(ICON_FA_COMPACT_DISC, "Change Disc"), false)) { - s_current_main_window = MainWindowType::None; + s_state.current_main_window = MainWindowType::None; DoChangeDisc(); } @@ -5960,19 +5980,19 @@ bool FullscreenUI::InitializeSaveStateListEntryFromPath(SaveStateListEntry* li, void FullscreenUI::ClearSaveStateEntryList() { - for (SaveStateListEntry& entry : s_save_state_selector_slots) + for (SaveStateListEntry& entry : s_state.save_state_selector_slots) { if (entry.preview_texture) g_gpu_device->RecycleTexture(std::move(entry.preview_texture)); } - s_save_state_selector_slots.clear(); + s_state.save_state_selector_slots.clear(); } u32 FullscreenUI::PopulateSaveStateListEntries(const std::string& title, const std::string& serial) { ClearSaveStateEntryList(); - if (s_save_state_selector_loading) + if (s_state.save_state_selector_loading) { std::optional ssi = System::GetUndoSaveStateInfo(); if (ssi) @@ -5982,7 +6002,7 @@ u32 FullscreenUI::PopulateSaveStateListEntries(const std::string& title, const s li.summary = FSUI_STR("Restores the state of the system prior to the last state loaded."); if (ssi->screenshot.IsValid()) li.preview_texture = g_gpu_device->FetchAndUploadTextureImage(ssi->screenshot); - s_save_state_selector_slots.push_back(std::move(li)); + s_state.save_state_selector_slots.push_back(std::move(li)); } } @@ -5991,19 +6011,19 @@ u32 FullscreenUI::PopulateSaveStateListEntries(const std::string& title, const s for (s32 i = 1; i <= System::PER_GAME_SAVE_STATE_SLOTS; i++) { SaveStateListEntry li; - if (InitializeSaveStateListEntryFromSerial(&li, serial, i, false) || !s_save_state_selector_loading) - s_save_state_selector_slots.push_back(std::move(li)); + if (InitializeSaveStateListEntryFromSerial(&li, serial, i, false) || !s_state.save_state_selector_loading) + s_state.save_state_selector_slots.push_back(std::move(li)); } } for (s32 i = 1; i <= System::GLOBAL_SAVE_STATE_SLOTS; i++) { SaveStateListEntry li; - if (InitializeSaveStateListEntryFromSerial(&li, serial, i, true) || !s_save_state_selector_loading) - s_save_state_selector_slots.push_back(std::move(li)); + if (InitializeSaveStateListEntryFromSerial(&li, serial, i, true) || !s_state.save_state_selector_loading) + s_state.save_state_selector_slots.push_back(std::move(li)); } - return static_cast(s_save_state_selector_slots.size()); + return static_cast(s_state.save_state_selector_slots.size()); } bool FullscreenUI::OpenLoadStateSelectorForGame(const std::string& game_path) @@ -6012,12 +6032,12 @@ bool FullscreenUI::OpenLoadStateSelectorForGame(const std::string& game_path) const GameList::Entry* entry = GameList::GetEntryForPath(game_path); if (entry) { - s_save_state_selector_loading = true; + s_state.save_state_selector_loading = true; if (PopulateSaveStateListEntries(entry->title, entry->serial) > 0) { - s_save_state_selector_open = true; - s_save_state_selector_resuming = false; - s_save_state_selector_game_path = game_path; + s_state.save_state_selector_open = true; + s_state.save_state_selector_resuming = false; + s_state.save_state_selector_game_path = game_path; return true; } } @@ -6028,12 +6048,12 @@ bool FullscreenUI::OpenLoadStateSelectorForGame(const std::string& game_path) bool FullscreenUI::OpenSaveStateSelector(bool is_loading) { - s_save_state_selector_game_path = {}; - s_save_state_selector_loading = is_loading; - s_save_state_selector_resuming = false; + s_state.save_state_selector_game_path = {}; + s_state.save_state_selector_loading = is_loading; + s_state.save_state_selector_resuming = false; if (PopulateSaveStateListEntries(System::GetGameTitle(), System::GetGameSerial()) > 0) { - s_save_state_selector_open = true; + s_state.save_state_selector_open = true; QueueResetFocus(FocusResetType::PopupOpened); return true; } @@ -6044,14 +6064,14 @@ bool FullscreenUI::OpenSaveStateSelector(bool is_loading) void FullscreenUI::CloseSaveStateSelector() { - if (s_save_state_selector_open) + if (s_state.save_state_selector_open) QueueResetFocus(FocusResetType::PopupClosed); ClearSaveStateEntryList(); - s_save_state_selector_open = false; - s_save_state_selector_loading = false; - s_save_state_selector_resuming = false; - s_save_state_selector_game_path = {}; + s_state.save_state_selector_open = false; + s_state.save_state_selector_loading = false; + s_state.save_state_selector_resuming = false; + s_state.save_state_selector_game_path = {}; } void FullscreenUI::DrawSaveStateSelector(bool is_loading) @@ -6143,10 +6163,10 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading) u32 grid_x = 0; ImGui::SetCursorPos(ImVec2(start_x, 0.0f)); - for (u32 i = 0; i < s_save_state_selector_slots.size();) + for (u32 i = 0; i < s_state.save_state_selector_slots.size();) { - SaveStateListEntry& entry = s_save_state_selector_slots[i]; - if (static_cast(i) == s_save_state_selector_submenu_index) + SaveStateListEntry& entry = s_state.save_state_selector_slots[i]; + if (static_cast(i) == s_state.save_state_selector_submenu_index) { // can't use a choice dialog here, because we're already in a modal... ImGuiFullscreen::PushResetLayout(); @@ -6202,10 +6222,10 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading) else if (FileSystem::DeleteFile(entry.path.c_str())) { ShowToast({}, fmt::format(FSUI_FSTR("{} deleted."), ImGuiFullscreen::RemoveHash(entry.title))); - s_save_state_selector_slots.erase(s_save_state_selector_slots.begin() + i); + s_state.save_state_selector_slots.erase(s_state.save_state_selector_slots.begin() + i); removed = true; - if (s_save_state_selector_slots.empty()) + if (s_state.save_state_selector_slots.empty()) { closed = true; was_close_not_back = true; @@ -6237,7 +6257,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading) } if (!is_open) - s_save_state_selector_submenu_index = -1; + s_state.save_state_selector_submenu_index = -1; ImGui::PopStyleColor(3); ImGui::PopStyleVar(3); @@ -6319,7 +6339,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading) (ImGui::IsItemClicked(ImGuiMouseButton_Right) || ImGui::IsKeyPressed(ImGuiKey_NavGamepadInput, false) || ImGui::IsKeyPressed(ImGuiKey_F1, false))) { - s_save_state_selector_submenu_index = static_cast(i); + s_state.save_state_selector_submenu_index = static_cast(i); } } @@ -6370,7 +6390,7 @@ void FullscreenUI::DrawSaveStateSelector(bool is_loading) CloseSaveStateSelector(); if (was_close_not_back) ReturnToMainWindow(); - else if (s_current_main_window != MainWindowType::GameList) + else if (s_state.current_main_window != MainWindowType::GameList) ReturnToPreviousWindow(); } } @@ -6382,11 +6402,11 @@ bool FullscreenUI::OpenLoadStateSelectorForGameResume(const GameList::Entry* ent return false; CloseSaveStateSelector(); - s_save_state_selector_slots.push_back(std::move(slentry)); - s_save_state_selector_game_path = entry->path; - s_save_state_selector_loading = true; - s_save_state_selector_open = true; - s_save_state_selector_resuming = true; + s_state.save_state_selector_slots.push_back(std::move(slentry)); + s_state.save_state_selector_game_path = entry->path; + s_state.save_state_selector_loading = true; + s_state.save_state_selector_open = true; + s_state.save_state_selector_resuming = true; QueueResetFocus(FocusResetType::PopupOpened); return true; } @@ -6405,7 +6425,7 @@ void FullscreenUI::DrawResumeStateSelector() if (ImGui::BeginPopupModal(FSUI_CSTR("Load Resume State"), &is_open, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize)) { - SaveStateListEntry& entry = s_save_state_selector_slots.front(); + SaveStateListEntry& entry = s_state.save_state_selector_slots.front(); SmallString time; TimeToPrintableString(&time, entry.timestamp); ImGui::TextWrapped( @@ -6429,13 +6449,13 @@ void FullscreenUI::DrawResumeStateSelector() if (ActiveButton(FSUI_ICONSTR(ICON_FA_PLAY, "Load State"), false)) { - DoStartPath(s_save_state_selector_game_path, std::move(entry.path)); + DoStartPath(s_state.save_state_selector_game_path, std::move(entry.path)); is_open = false; } if (ActiveButton(FSUI_ICONSTR(ICON_FA_LIGHTBULB, "Clean Boot"), false)) { - DoStartPath(s_save_state_selector_game_path); + DoStartPath(s_state.save_state_selector_game_path); is_open = false; } @@ -6443,7 +6463,7 @@ void FullscreenUI::DrawResumeStateSelector() { if (FileSystem::DeleteFile(entry.path.c_str())) { - DoStartPath(s_save_state_selector_game_path); + DoStartPath(s_state.save_state_selector_game_path); is_open = false; } else @@ -6468,10 +6488,10 @@ void FullscreenUI::DrawResumeStateSelector() if (!is_open) { ClearSaveStateEntryList(); - s_save_state_selector_open = false; - s_save_state_selector_loading = false; - s_save_state_selector_resuming = false; - s_save_state_selector_game_path = {}; + s_state.save_state_selector_open = false; + s_state.save_state_selector_loading = false; + s_state.save_state_selector_resuming = false; + s_state.save_state_selector_game_path = {}; } else { @@ -6481,7 +6501,7 @@ void FullscreenUI::DrawResumeStateSelector() void FullscreenUI::DoLoadState(std::string path) { - Host::RunOnCPUThread([boot_path = s_save_state_selector_game_path, path = std::move(path)]() { + Host::RunOnCPUThread([boot_path = s_state.save_state_selector_game_path, path = std::move(path)]() { CloseSaveStateSelector(); if (System::IsValid()) @@ -6533,8 +6553,8 @@ void FullscreenUI::PopulateGameListEntryList() const bool merge_disc_sets = Host::GetBaseBoolSettingValue("Main", "FullscreenUIMergeDiscSets", true); const u32 count = GameList::GetEntryCount(); - s_game_list_sorted_entries.clear(); - s_game_list_sorted_entries.reserve(count); + s_state.game_list_sorted_entries.clear(); + s_state.game_list_sorted_entries.reserve(count); for (u32 i = 0; i < count; i++) { const GameList::Entry* entry = GameList::GetEntryByIndex(i); @@ -6549,10 +6569,10 @@ void FullscreenUI::PopulateGameListEntryList() continue; } - s_game_list_sorted_entries.push_back(entry); + s_state.game_list_sorted_entries.push_back(entry); } - std::sort(s_game_list_sorted_entries.begin(), s_game_list_sorted_entries.end(), + std::sort(s_state.game_list_sorted_entries.begin(), s_state.game_list_sorted_entries.end(), [sort, reverse](const GameList::Entry* lhs, const GameList::Entry* rhs) { switch (sort) { @@ -6657,15 +6677,15 @@ void FullscreenUI::DrawGameListWindow() if (NavButton(ICON_FA_BACKWARD, true, true)) ReturnToPreviousWindow(); - NavTitle(Host::TranslateToCString(TR_CONTEXT, titles[static_cast(s_game_list_view)])); + NavTitle(Host::TranslateToCString(TR_CONTEXT, titles[static_cast(s_state.game_list_view)])); RightAlignNavButtons(count, ITEM_WIDTH, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY); for (u32 i = 0; i < count; i++) { - if (NavButton(icons[i], static_cast(i) == s_game_list_view, true, ITEM_WIDTH, + if (NavButton(icons[i], static_cast(i) == s_state.game_list_view, true, ITEM_WIDTH, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY)) { - s_game_list_view = static_cast(i); + s_state.game_list_view = static_cast(i); } } @@ -6676,15 +6696,15 @@ void FullscreenUI::DrawGameListWindow() if (ImGui::IsKeyPressed(ImGuiKey_NavGamepadMenu, false) || ImGui::IsKeyPressed(ImGuiKey_F1, false)) { - s_game_list_view = (s_game_list_view == GameListView::Grid) ? GameListView::List : GameListView::Grid; + s_state.game_list_view = (s_state.game_list_view == GameListView::Grid) ? GameListView::List : GameListView::Grid; } else if (ImGui::IsKeyPressed(ImGuiKey_GamepadStart, false) || ImGui::IsKeyPressed(ImGuiKey_F2)) { - s_current_main_window = MainWindowType::GameListSettings; + s_state.current_main_window = MainWindowType::GameListSettings; QueueResetFocus(FocusResetType::ViewChanged); } - switch (s_game_list_view) + switch (s_state.game_list_view) { case GameListView::Grid: DrawGameGrid(heading_size); @@ -6744,7 +6764,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size) SmallString summary; - for (const GameList::Entry* entry : s_game_list_sorted_entries) + for (const GameList::Entry* entry : s_state.game_list_sorted_entries) { ImRect bb; bool visible, hovered; @@ -6977,7 +6997,7 @@ void FullscreenUI::DrawGameGrid(const ImVec2& heading_size) u32 grid_x = 0; ImGui::SetCursorPos(ImVec2(start_x, 0.0f)); - for (const GameList::Entry* entry : s_game_list_sorted_entries) + for (const GameList::Entry* entry : s_state.game_list_sorted_entries) { ImGuiWindow* window = ImGui::GetCurrentWindow(); if (window->SkipItems) @@ -7201,7 +7221,7 @@ void FullscreenUI::DrawGameListSettingsWindow() if (NavButton(ICON_FA_BACKWARD, true, true)) { - s_current_main_window = MainWindowType::GameList; + s_state.current_main_window = MainWindowType::GameList; QueueResetFocus(FocusResetType::Other); } @@ -7222,7 +7242,7 @@ void FullscreenUI::DrawGameListSettingsWindow() if (ImGui::IsWindowFocused() && WantsToCloseMenu()) { - s_current_main_window = MainWindowType::GameList; + s_state.current_main_window = MainWindowType::GameList; QueueResetFocus(FocusResetType::ViewChanged); } @@ -7252,7 +7272,7 @@ void FullscreenUI::DrawGameListSettingsWindow() }); } - for (const auto& it : s_game_list_directories_cache) + for (const auto& it : s_state.game_list_directories_cache) { if (MenuButton(SmallString::from_format(ICON_FA_FOLDER " {}", it.first), it.second ? FSUI_CSTR("Scanning Subdirectories") : FSUI_CSTR("Not Scanning Subdirectories"))) @@ -7371,8 +7391,9 @@ void FullscreenUI::DrawGameListSettingsWindow() void FullscreenUI::SwitchToGameList() { - s_current_main_window = MainWindowType::GameList; - s_game_list_view = static_cast(Host::GetBaseIntSettingValue("Main", "DefaultFullscreenUIGameView", 0)); + s_state.current_main_window = MainWindowType::GameList; + s_state.game_list_view = + static_cast(Host::GetBaseIntSettingValue("Main", "DefaultFullscreenUIGameView", 0)); { auto lock = Host::GetSettingsLock(); PopulateGameListDirectoryCache(Host::Internal::GetBaseSettingsLayer()); @@ -7383,11 +7404,11 @@ void FullscreenUI::SwitchToGameList() GPUTexture* FullscreenUI::GetGameListCover(const GameList::Entry* entry) { // lookup and grab cover image - auto cover_it = s_cover_image_map.find(entry->path); - if (cover_it == s_cover_image_map.end()) + auto cover_it = s_state.cover_image_map.find(entry->path); + if (cover_it == s_state.cover_image_map.end()) { std::string cover_path(GameList::GetCoverImagePathForEntry(entry)); - cover_it = s_cover_image_map.emplace(entry->path, std::move(cover_path)).first; + cover_it = s_state.cover_image_map.emplace(entry->path, std::move(cover_path)).first; } GPUTexture* tex = (!cover_it->second.empty()) ? GetCachedTextureAsync(cover_it->second.c_str()) : nullptr; @@ -7399,17 +7420,17 @@ GPUTexture* FullscreenUI::GetTextureForGameListEntryType(GameList::EntryType typ switch (type) { case GameList::EntryType::PSExe: - return s_fallback_exe_texture.get(); + return s_state.fallback_exe_texture.get(); case GameList::EntryType::Playlist: - return s_fallback_playlist_texture.get(); + return s_state.fallback_playlist_texture.get(); case GameList::EntryType::PSF: - return s_fallback_psf_texture.get(); + return s_state.fallback_psf_texture.get(); case GameList::EntryType::Disc: default: - return s_fallback_disc_texture.get(); + return s_state.fallback_disc_texture.get(); } } @@ -7419,7 +7440,7 @@ GPUTexture* FullscreenUI::GetCoverForCurrentGame() const GameList::Entry* entry = GameList::GetEntryForPath(System::GetDiscPath()); if (!entry) - return s_fallback_disc_texture.get(); + return s_state.fallback_disc_texture.get(); return GetGameListCover(entry); } @@ -7430,7 +7451,7 @@ GPUTexture* FullscreenUI::GetCoverForCurrentGame() void FullscreenUI::OpenAboutWindow() { - s_about_window_open = true; + s_state.about_window_open = true; } void FullscreenUI::ExitFullscreenAndOpenURL(std::string_view url) @@ -7461,7 +7482,7 @@ void FullscreenUI::DrawAboutWindow() ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, LayoutScale(10.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, LayoutScale(30.0f, 30.0f)); - if (ImGui::BeginPopupModal(FSUI_CSTR("About DuckStation"), &s_about_window_open, + if (ImGui::BeginPopupModal(FSUI_CSTR("About DuckStation"), &s_state.about_window_open, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize)) { ImGui::TextWrapped("%s", FSUI_CSTR("DuckStation is a free simulator/emulator of the Sony PlayStation(TM) " @@ -7489,7 +7510,7 @@ void FullscreenUI::DrawAboutWindow() if (ActiveButton(FSUI_ICONSTR(ICON_FA_WINDOW_CLOSE, "Close"), false) || WantsToCloseMenu()) { ImGui::CloseCurrentPopup(); - s_about_window_open = false; + s_state.about_window_open = false; } else { @@ -7523,20 +7544,20 @@ void FullscreenUI::OpenAchievementsWindow() return; } - if (s_current_main_window != MainWindowType::PauseMenu) + if (s_state.current_main_window != MainWindowType::PauseMenu) { PauseForMenuOpen(false); ForceKeyNavEnabled(); } - s_current_main_window = MainWindowType::Achievements; + s_state.current_main_window = MainWindowType::Achievements; QueueResetFocus(FocusResetType::ViewChanged); FixStateIfPaused(); } bool FullscreenUI::IsAchievementsWindowOpen() { - return (s_current_main_window == MainWindowType::Achievements); + return (s_state.current_main_window == MainWindowType::Achievements); } void FullscreenUI::OpenLeaderboardsWindow() @@ -7557,20 +7578,20 @@ void FullscreenUI::OpenLeaderboardsWindow() return; } - if (s_current_main_window != MainWindowType::PauseMenu) + if (s_state.current_main_window != MainWindowType::PauseMenu) { PauseForMenuOpen(false); ForceKeyNavEnabled(); } - s_current_main_window = MainWindowType::Leaderboards; + s_state.current_main_window = MainWindowType::Leaderboards; QueueResetFocus(FocusResetType::ViewChanged); FixStateIfPaused(); } bool FullscreenUI::IsLeaderboardsWindowOpen() { - return (s_current_main_window == MainWindowType::Leaderboards); + return (s_state.current_main_window == MainWindowType::Leaderboards); } #endif // __ANDROID__