Add RAIntegration event handler

Some refactoring done to hardcore toggling so that it's more readily available for the toggle hardcore event.
This commit is contained in:
LillyJadeKatrin 2024-07-22 02:17:00 -04:00
parent 9caa02493d
commit 90a4be4b36
8 changed files with 43 additions and 21 deletions

View file

@ -1438,6 +1438,7 @@ void AchievementManager::LoadIntegrationCallback(int result, const char* error_m
case RC_OK:
INFO_LOG_FMT(ACHIEVEMENTS, "RAIntegration.dll found.");
instance.m_dll_found = true;
rc_client_raintegration_set_event_handler(instance.m_client, RAIntegrationEventHandler);
instance.m_dev_menu_callback();
// TODO: hook up menu and dll event handlers
break;
@ -1456,6 +1457,31 @@ void AchievementManager::LoadIntegrationCallback(int result, const char* error_m
instance.Login("");
INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager Initialized");
}
void AchievementManager::RAIntegrationEventHandler(const rc_client_raintegration_event_t* event,
rc_client_t* client)
{
auto& instance = AchievementManager::GetInstance();
switch (event->type)
{
case RC_CLIENT_RAINTEGRATION_EVENT_MENU_CHANGED:
case RC_CLIENT_RAINTEGRATION_EVENT_MENUITEM_CHECKED_CHANGED:
instance.m_dev_menu_callback();
break;
case RC_CLIENT_RAINTEGRATION_EVENT_PAUSE:
{
Core::QueueHostJob([](Core::System& system) { Core::SetState(system, Core::State::Paused); });
break;
}
case RC_CLIENT_RAINTEGRATION_EVENT_HARDCORE_CHANGED:
Config::SetBaseOrCurrent(Config::RA_HARDCORE_ENABLED,
!Config::Get(Config::RA_HARDCORE_ENABLED));
break;
default:
WARN_LOG_FMT(ACHIEVEMENTS, "Unsupported raintegration event. {}", event->type);
break;
}
}
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
#endif // USE_RETRO_ACHIEVEMENTS

View file

@ -251,6 +251,8 @@ private:
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
static void LoadIntegrationCallback(int result, const char* error_message, rc_client_t* client,
void* userdata);
static void RAIntegrationEventHandler(const rc_client_raintegration_event_t* event,
rc_client_t* client);
#endif // RC_CLIENT_SUPPORTS_RAINTEGRATION
rc_runtime_t m_runtime{};

View file

@ -34,10 +34,6 @@ AchievementSettingsWidget::AchievementSettingsWidget(QWidget* parent) : QWidget(
connect(&Settings::Instance(), &Settings::ConfigChanged, this,
&AchievementSettingsWidget::LoadSettings);
// If hardcore is enabled when the emulator starts, make sure it turns off what it needs to
if (Config::Get(Config::RA_HARDCORE_ENABLED))
UpdateHardcoreMode();
}
void AchievementSettingsWidget::UpdateData(int login_failed_code)
@ -259,7 +255,6 @@ void AchievementSettingsWidget::ToggleRAIntegration()
instance.Init(reinterpret_cast<void*>(winId()));
else
instance.Shutdown();
UpdateHardcoreMode();
}
void AchievementSettingsWidget::Login()
@ -297,7 +292,6 @@ void AchievementSettingsWidget::ToggleHardcore()
}
}
SaveSettings();
UpdateHardcoreMode();
}
void AchievementSettingsWidget::ToggleUnofficial()
@ -327,14 +321,4 @@ void AchievementSettingsWidget::ToggleProgress()
SaveSettings();
}
void AchievementSettingsWidget::UpdateHardcoreMode()
{
if (Config::Get(Config::RA_HARDCORE_ENABLED))
{
Settings::Instance().SetDebugModeEnabled(false);
}
emit Settings::Instance().EmulationStateChanged(Core::GetState(Core::System::GetInstance()));
emit Settings::Instance().HardcoreStateChanged();
}
#endif // USE_RETRO_ACHIEVEMENTS

View file

@ -39,8 +39,6 @@ private:
void ToggleDiscordPresence();
void ToggleProgress();
void UpdateHardcoreMode();
QGroupBox* m_common_box;
QVBoxLayout* m_common_layout;
ToolTipCheckBox* m_common_integration_enabled_input;

View file

@ -39,8 +39,6 @@ AchievementsWindow::AchievementsWindow(QWidget* parent) : QDialog(parent)
});
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[this] { m_settings_widget->UpdateData(RC_OK); });
connect(&Settings::Instance(), &Settings::HardcoreStateChanged, this,
[this] { AchievementsWindow::UpdateData({.all = true}); });
}
void AchievementsWindow::showEvent(QShowEvent* event)

View file

@ -43,6 +43,7 @@
#include "Core/BootManager.h"
#include "Core/CommonTitles.h"
#include "Core/Config/AchievementSettings.h"
#include "Core/Config/FreeLookSettings.h"
#include "Core/Config/MainSettings.h"
#include "Core/Config/NetplaySettings.h"
#include "Core/Config/UISettings.h"
@ -275,6 +276,12 @@ MainWindow::MainWindow(Core::System& system, std::unique_ptr<BootParameters> boo
AchievementManager::GetInstance().Init(reinterpret_cast<void*>(winId()));
if (AchievementManager::GetInstance().IsHardcoreModeActive())
Settings::Instance().SetDebugModeEnabled(false);
// This needs to trigger on both RA_HARDCORE_ENABLED and RA_ENABLED
Config::AddConfigChangedCallback(
[this]() { QueueOnObject(this, [this] { this->OnHardcoreChanged(); }); });
// If hardcore is enabled when the emulator starts, make sure it turns off what it needs to
if (Config::Get(Config::RA_HARDCORE_ENABLED))
OnHardcoreChanged();
#endif // USE_RETRO_ACHIEVEMENTS
#if defined(__unix__) || defined(__unix) || defined(__APPLE__)
@ -1992,6 +1999,13 @@ void MainWindow::ShowAchievementSettings()
ShowAchievementsWindow();
m_achievements_window->ForceSettingsTab();
}
void MainWindow::OnHardcoreChanged()
{
if (Config::Get(Config::RA_HARDCORE_ENABLED))
Settings::Instance().SetDebugModeEnabled(false);
emit Settings::Instance().EmulationStateChanged(Core::GetState(Core::System::GetInstance()));
}
#endif // USE_RETRO_ACHIEVEMENTS
void MainWindow::ShowMemcardManager()

View file

@ -181,6 +181,7 @@ private:
#ifdef USE_RETRO_ACHIEVEMENTS
void ShowAchievementsWindow();
void ShowAchievementSettings();
void OnHardcoreChanged();
#endif // USE_RETRO_ACHIEVEMENTS
void NetPlayInit();

View file

@ -222,7 +222,6 @@ signals:
void SDCardInsertionChanged(bool inserted);
void USBKeyboardConnectionChanged(bool connected);
void EnableGfxModsChanged(bool enabled);
void HardcoreStateChanged();
private:
Settings();