From 42768c31015c6e9e39e25741069ee9af3c1a68ed Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 8 Oct 2022 20:59:18 +1000 Subject: [PATCH] Achievements: Fix a few minor issues --- src/core/achievements.h | 7 +++++-- src/core/system.cpp | 25 ++++++++++++------------ src/frontend-common/achievements.cpp | 24 +++++++++++------------ src/frontend-common/achievements.h | 2 +- src/frontend-common/fullscreen_ui.cpp | 5 ++++- src/frontend-common/imgui_fullscreen.cpp | 2 +- 6 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/core/achievements.h b/src/core/achievements.h index 7df438460..d8c0df51f 100644 --- a/src/core/achievements.h +++ b/src/core/achievements.h @@ -15,7 +15,7 @@ extern bool DoState(StateWrapper& sw); extern void GameChanged(const std::string& path, CDImage* image); /// Re-enables hardcode mode if it is enabled in the settings. -extern void ResetChallengeMode(); +extern bool ResetChallengeMode(); /// Forces hardcore mode off until next reset. extern void DisableChallengeMode(); @@ -43,7 +43,10 @@ static constexpr inline bool ChallengeModeActive() return false; } -static inline void ResetChallengeMode() {} +static inline bool ResetChallengeMode() +{ + return false; +} static inline void DisableChallengeMode() {} diff --git a/src/core/system.cpp b/src/core/system.cpp index 61c071f7a..75401c807 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -908,6 +908,9 @@ void System::ResetSystem() #ifdef WITH_CHEEVOS if (!Achievements::ConfirmSystemReset()) return; + + if (Achievements::ResetChallengeMode()) + ApplySettings(false); #endif InternalReset(); @@ -915,10 +918,6 @@ void System::ResetSystem() ResetThrottler(); Host::AddOSDMessage(Host::TranslateStdString("OSDMessage", "System reset.")); -#ifdef WITH_CHEEVOS - Achievements::ResetChallengeMode(); -#endif - // need to clear this here, because of eject disc -> reset. s_running_bios = !s_running_game_path.empty(); } @@ -2925,21 +2924,21 @@ void System::UpdateRunningGame(const char* path, CDImage* image, bool booting) g_texture_replacements.SetGameID(s_running_game_serial); - s_cheat_list.reset(); - if (g_settings.auto_load_cheats && !Achievements::ChallengeModeActive()) - LoadCheatListFromGameTitle(); - - UpdateGameSettingsLayer(); - ApplySettings(true); - - Host::OnGameChanged(s_running_game_path, s_running_game_serial, s_running_game_title); - #ifdef WITH_CHEEVOS if (booting) Achievements::ResetChallengeMode(); Achievements::GameChanged(s_running_game_path, image); #endif + + UpdateGameSettingsLayer(); + ApplySettings(true); + + s_cheat_list.reset(); + if (g_settings.auto_load_cheats && !Achievements::ChallengeModeActive()) + LoadCheatListFromGameTitle(); + + Host::OnGameChanged(s_running_game_path, s_running_game_serial, s_running_game_title); } bool System::CheckForSBIFile(CDImage* image) diff --git a/src/frontend-common/achievements.cpp b/src/frontend-common/achievements.cpp index d2e7bcb90..d568dee69 100644 --- a/src/frontend-common/achievements.cpp +++ b/src/frontend-common/achievements.cpp @@ -498,9 +498,9 @@ void Achievements::UpdateSettings(const Settings& old_config) } else if (!s_challenge_mode && g_settings.achievements_challenge_mode) { - Host::AddKeyedOSDMessage( - "challenge_mode_reset", - Host::TranslateStdString("Achievements", "Hardcore mode will be enabled on system reset."), 10.0f); + ImGuiFullscreen::ShowToast( + std::string(), Host::TranslateStdString("Achievements", "Hardcore mode will be enabled on system reset."), + 10.0f); } } @@ -560,13 +560,13 @@ void Achievements::DisableChallengeMode() SetChallengeMode(false); } -void Achievements::ResetChallengeMode() +bool Achievements::ResetChallengeMode() { - if (!s_active) - return; + if (!s_active || s_challenge_mode == g_settings.achievements_challenge_mode) + return false; - if (s_challenge_mode != g_settings.achievements_challenge_mode) - SetChallengeMode(g_settings.achievements_challenge_mode); + SetChallengeMode(g_settings.achievements_challenge_mode); + return true; } void Achievements::SetChallengeMode(bool enabled) @@ -579,10 +579,10 @@ void Achievements::SetChallengeMode(bool enabled) if (HasActiveGame()) { - Host::AddKeyedOSDMessage("achievements_set_challenge_mode", - enabled ? Host::TranslateStdString("Achievements", "Hardcore mode is now enabled.") : - Host::TranslateStdString("Achievements", "Hardcore mode is now disabled."), - 10.0f); + ImGuiFullscreen::ShowToast(std::string(), + enabled ? Host::TranslateStdString("Achievements", "Hardcore mode is now enabled.") : + Host::TranslateStdString("Achievements", "Hardcore mode is now disabled."), + 10.0f); } if (HasActiveGame() && !IsTestModeActive()) diff --git a/src/frontend-common/achievements.h b/src/frontend-common/achievements.h index 1aeab25cb..ca64b89c4 100644 --- a/src/frontend-common/achievements.h +++ b/src/frontend-common/achievements.h @@ -119,7 +119,7 @@ void Logout(); void GameChanged(const std::string& path, CDImage* image); /// Re-enables hardcode mode if it is enabled in the settings. -void ResetChallengeMode(); +bool ResetChallengeMode(); /// Forces hardcore mode off until next reset. void DisableChallengeMode(); diff --git a/src/frontend-common/fullscreen_ui.cpp b/src/frontend-common/fullscreen_ui.cpp index 08007f594..c33002d22 100644 --- a/src/frontend-common/fullscreen_ui.cpp +++ b/src/frontend-common/fullscreen_ui.cpp @@ -585,7 +585,10 @@ void FullscreenUI::CheckForConfigChanges(const Settings& old_settings) // If achievements got disabled, we might have the menu open... // That means we're going to be reading achievement state. if (old_settings.achievements_enabled && !g_settings.achievements_enabled) - ReturnToMainWindow(); + { + if (s_current_main_window == MainWindowType::Achievements || s_current_main_window == MainWindowType::Leaderboards) + ReturnToMainWindow(); + } #endif } diff --git a/src/frontend-common/imgui_fullscreen.cpp b/src/frontend-common/imgui_fullscreen.cpp index 2cc9e5c5e..809868415 100644 --- a/src/frontend-common/imgui_fullscreen.cpp +++ b/src/frontend-common/imgui_fullscreen.cpp @@ -2144,7 +2144,7 @@ void ImGuiFullscreen::DrawMessageDialog() } } -static float s_notification_vertical_position = 0.3f; +static float s_notification_vertical_position = 0.15f; static float s_notification_vertical_direction = 1.0f; float ImGuiFullscreen::GetNotificationVerticalPosition()