Update hardcore toggle to use rc_client

The client can take care of itself and handle its own hardcore status when it toggles, so I can tell the settings widget to contact the manager directly to set it.
Also, gradually reorganizing the settings dialog over the next handful of commits.
This commit is contained in:
LillyJadeKatrin 2024-04-03 15:55:00 -04:00
parent 9a40ec06b5
commit 0883aa114e
4 changed files with 22 additions and 15 deletions

@ -45,7 +45,7 @@ void AchievementManager::Init()
[](const char* message, const rc_client_t* client) { [](const char* message, const rc_client_t* client) {
INFO_LOG_FMT(ACHIEVEMENTS, "{}", message); INFO_LOG_FMT(ACHIEVEMENTS, "{}", message);
}); });
rc_client_set_hardcore_enabled(m_client, 0); rc_client_set_hardcore_enabled(m_client, Config::Get(Config::RA_HARDCORE_ENABLED));
rc_client_set_unofficial_enabled(m_client, 1); rc_client_set_unofficial_enabled(m_client, 1);
m_queue.Reset("AchievementManagerQueue", [](const std::function<void()>& func) { func(); }); m_queue.Reset("AchievementManagerQueue", [](const std::function<void()>& func) { func(); });
m_image_queue.Reset("AchievementManagerImageQueue", m_image_queue.Reset("AchievementManagerImageQueue",
@ -240,16 +240,19 @@ std::recursive_mutex& AchievementManager::GetLock()
return m_lock; return m_lock;
} }
void AchievementManager::SetHardcoreMode()
{
rc_client_set_hardcore_enabled(m_client, Config::Get(Config::RA_HARDCORE_ENABLED));
}
bool AchievementManager::IsHardcoreModeActive() const bool AchievementManager::IsHardcoreModeActive() const
{ {
std::lock_guard lg{m_lock}; std::lock_guard lg{m_lock};
if (!Config::Get(Config::RA_HARDCORE_ENABLED)) if (!rc_client_get_hardcore_enabled(m_client))
return false; return false;
if (!Core::IsRunning()) if (!rc_client_get_game_info(m_client))
return true; return true;
if (!IsGameLoaded()) return rc_client_is_processing_required(m_client);
return false;
return (m_runtime.trigger_count + m_runtime.lboard_count > 0);
} }
std::string_view AchievementManager::GetPlayerDisplayName() const std::string_view AchievementManager::GetPlayerDisplayName() const

@ -103,6 +103,7 @@ public:
void DoFrame(); void DoFrame();
std::recursive_mutex& GetLock(); std::recursive_mutex& GetLock();
void SetHardcoreMode();
bool IsHardcoreModeActive() const; bool IsHardcoreModeActive() const;
std::string_view GetPlayerDisplayName() const; std::string_view GetPlayerDisplayName() const;
u32 GetPlayerScore() const; u32 GetPlayerScore() const;

@ -16,7 +16,7 @@ const Info<std::string> RA_HOST_URL{{System::Achievements, "Achievements", "Host
const Info<std::string> RA_USERNAME{{System::Achievements, "Achievements", "Username"}, ""}; const Info<std::string> RA_USERNAME{{System::Achievements, "Achievements", "Username"}, ""};
const Info<std::string> RA_API_TOKEN{{System::Achievements, "Achievements", "ApiToken"}, ""}; const Info<std::string> RA_API_TOKEN{{System::Achievements, "Achievements", "ApiToken"}, ""};
const Info<bool> RA_HARDCORE_ENABLED{{System::Achievements, "Achievements", "HardcoreEnabled"}, const Info<bool> RA_HARDCORE_ENABLED{{System::Achievements, "Achievements", "HardcoreEnabled"},
false}; true};
const Info<bool> RA_PROGRESS_ENABLED{{System::Achievements, "Achievements", "ProgressEnabled"}, const Info<bool> RA_PROGRESS_ENABLED{{System::Achievements, "Achievements", "ProgressEnabled"},
false}; false};
const Info<bool> RA_BADGES_ENABLED{{System::Achievements, "Achievements", "BadgesEnabled"}, false}; const Info<bool> RA_BADGES_ENABLED{{System::Achievements, "Achievements", "BadgesEnabled"}, false};

@ -61,12 +61,6 @@ void AchievementSettingsWidget::CreateLayout()
m_common_login_failed = new QLabel(tr("Login Failed")); m_common_login_failed = new QLabel(tr("Login Failed"));
m_common_login_failed->setStyleSheet(QStringLiteral("QLabel { color : red; }")); m_common_login_failed->setStyleSheet(QStringLiteral("QLabel { color : red; }"));
m_common_login_failed->setVisible(false); m_common_login_failed->setVisible(false);
m_common_unofficial_enabled_input = new ToolTipCheckBox(tr("Enable Unofficial Achievements"));
m_common_unofficial_enabled_input->SetDescription(
tr("Enable unlocking unofficial achievements as well as official "
"achievements.<br><br>Unofficial achievements may be optional or unfinished achievements "
"that have not been deemed official by RetroAchievements and may be useful for testing or "
"simply for fun."));
m_common_hardcore_enabled_input = new ToolTipCheckBox(tr("Enable Hardcore Mode")); m_common_hardcore_enabled_input = new ToolTipCheckBox(tr("Enable Hardcore Mode"));
m_common_hardcore_enabled_input->SetDescription( m_common_hardcore_enabled_input->SetDescription(
tr("Enable Hardcore Mode on RetroAchievements.<br><br>Hardcore Mode is intended to provide " tr("Enable Hardcore Mode on RetroAchievements.<br><br>Hardcore Mode is intended to provide "
@ -81,6 +75,12 @@ void AchievementSettingsWidget::CreateLayout()
"playing.</dolphin_emphasis><br>Close your current game before enabling.<br>Be aware that " "playing.</dolphin_emphasis><br>Close your current game before enabling.<br>Be aware that "
"turning Hardcore Mode off while a game is running requires the game to be closed before " "turning Hardcore Mode off while a game is running requires the game to be closed before "
"re-enabling.")); "re-enabling."));
m_common_unofficial_enabled_input = new ToolTipCheckBox(tr("Enable Unofficial Achievements"));
m_common_unofficial_enabled_input->SetDescription(
tr("Enable unlocking unofficial achievements as well as official "
"achievements.<br><br>Unofficial achievements may be optional or unfinished achievements "
"that have not been deemed official by RetroAchievements and may be useful for testing or "
"simply for fun."));
m_common_progress_enabled_input = new ToolTipCheckBox(tr("Enable Progress Notifications")); m_common_progress_enabled_input = new ToolTipCheckBox(tr("Enable Progress Notifications"));
m_common_progress_enabled_input->SetDescription( m_common_progress_enabled_input->SetDescription(
tr("Enable progress notifications on achievements.<br><br>Displays a brief popup message " tr("Enable progress notifications on achievements.<br><br>Displays a brief popup message "
@ -105,11 +105,13 @@ void AchievementSettingsWidget::CreateLayout()
m_common_layout->addWidget(m_common_login_button); m_common_layout->addWidget(m_common_login_button);
m_common_layout->addWidget(m_common_logout_button); m_common_layout->addWidget(m_common_logout_button);
m_common_layout->addWidget(m_common_login_failed); m_common_layout->addWidget(m_common_login_failed);
m_common_layout->addWidget(new QLabel(tr("Function Settings")));
m_common_layout->addWidget(m_common_hardcore_enabled_input); m_common_layout->addWidget(m_common_hardcore_enabled_input);
m_common_layout->addWidget(m_common_progress_enabled_input);
m_common_layout->addWidget(m_common_badges_enabled_input);
m_common_layout->addWidget(m_common_unofficial_enabled_input); m_common_layout->addWidget(m_common_unofficial_enabled_input);
m_common_layout->addWidget(m_common_encore_enabled_input); m_common_layout->addWidget(m_common_encore_enabled_input);
m_common_layout->addWidget(new QLabel(tr("Display Settings")));
m_common_layout->addWidget(m_common_progress_enabled_input);
m_common_layout->addWidget(m_common_badges_enabled_input);
m_common_layout->setAlignment(Qt::AlignTop); m_common_layout->setAlignment(Qt::AlignTop);
setLayout(m_common_layout); setLayout(m_common_layout);
@ -229,6 +231,7 @@ void AchievementSettingsWidget::Logout()
void AchievementSettingsWidget::ToggleHardcore() void AchievementSettingsWidget::ToggleHardcore()
{ {
SaveSettings(); SaveSettings();
AchievementManager::GetInstance().SetHardcoreMode();
if (Config::Get(Config::RA_HARDCORE_ENABLED)) if (Config::Get(Config::RA_HARDCORE_ENABLED))
{ {
if (Config::Get(Config::MAIN_EMULATION_SPEED) < 1.0f) if (Config::Get(Config::MAIN_EMULATION_SPEED) < 1.0f)