Use new config system for Discord Rich Presence option

This doesn't feel like a mirror change to me.
This commit is contained in:
Sleepy Flower Girl 2018-06-06 00:16:42 -04:00
parent f25d833dbd
commit 57bd13a0ce
9 changed files with 42 additions and 47 deletions

View File

@ -9,6 +9,7 @@
#include "Common/Config/Config.h" #include "Common/Config/Config.h"
#include "Core/Config/GraphicsSettings.h" #include "Core/Config/GraphicsSettings.h"
#include "UICommon/DiscordPresence.h"
namespace ConfigLoaders namespace ConfigLoaders
{ {
@ -115,6 +116,10 @@ bool IsSettingSaveable(const Config::ConfigLocation& config_location)
Config::GFX_PERF_QUERIES_ENABLE.location, Config::GFX_PERF_QUERIES_ENABLE.location,
// Main.General
MAIN_USE_DISCORD_PRESENCE.location,
}; };
return std::find(s_setting_saveable.begin(), s_setting_saveable.end(), config_location) != return std::find(s_setting_saveable.begin(), s_setting_saveable.end(), config_location) !=

View File

@ -131,10 +131,6 @@ void SConfig::SaveGeneralSettings(IniFile& ini)
#endif #endif
general->Set("GDBPort", iGDBPort); general->Set("GDBPort", iGDBPort);
#endif #endif
#ifdef USE_DISCORD_PRESENCE
general->Set("UseDiscordPresence", bUseDiscordPresence);
#endif
} }
void SConfig::SaveInterfaceSettings(IniFile& ini) void SConfig::SaveInterfaceSettings(IniFile& ini)
@ -420,9 +416,6 @@ void SConfig::LoadGeneralSettings(IniFile& ini)
general->Get("RecursiveISOPaths", &m_RecursiveISOFolder, false); general->Get("RecursiveISOPaths", &m_RecursiveISOFolder, false);
general->Get("WirelessMac", &m_WirelessMac); general->Get("WirelessMac", &m_WirelessMac);
#ifdef USE_DISCORD_PRESENCE
general->Get("UseDiscordPresence", &bUseDiscordPresence, true);
#endif
} }
void SConfig::LoadInterfaceSettings(IniFile& ini) void SConfig::LoadInterfaceSettings(IniFile& ini)

View File

@ -71,9 +71,6 @@ struct SConfig
#ifndef _WIN32 #ifndef _WIN32
std::string gdb_socket; std::string gdb_socket;
#endif #endif
#endif
#ifdef USE_DISCORD_PRESENCE
bool bUseDiscordPresence;
#endif #endif
bool bAutomaticStart = false; bool bAutomaticStart = false;
bool bBootToPause = false; bool bBootToPause = false;

View File

@ -480,19 +480,3 @@ void Settings::SetBatchModeEnabled(bool batch)
{ {
m_batch = batch; m_batch = batch;
} }
#ifdef USE_DISCORD_PRESENCE
void Settings::SetDiscordPresenceEnabled(bool enabled)
{
if (SConfig::GetInstance().bUseDiscordPresence == enabled)
return;
if (SConfig::GetInstance().bUseDiscordPresence)
Discord::Shutdown();
SConfig::GetInstance().bUseDiscordPresence = enabled;
if (SConfig::GetInstance().bUseDiscordPresence)
Discord::Init();
}
#endif

View File

@ -127,9 +127,6 @@ public:
// Other // Other
GameListModel* GetGameListModel() const; GameListModel* GetGameListModel() const;
#ifdef USE_DISCORD_PRESENCE
void SetDiscordPresenceEnabled(bool enabled);
#endif
signals: signals:
void ConfigChanged(); void ConfigChanged();
void EmulationStateChanged(Core::State new_state); void EmulationStateChanged(Core::State new_state);

View File

@ -24,6 +24,9 @@
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "DolphinQt2/Settings.h" #include "DolphinQt2/Settings.h"
#include "UICommon/AutoUpdate.h" #include "UICommon/AutoUpdate.h"
#ifdef USE_DISCORD_PRESENCE
#include "UICommon/DiscordPresence.h"
#endif
constexpr int AUTO_UPDATE_DISABLE_INDEX = 0; constexpr int AUTO_UPDATE_DISABLE_INDEX = 0;
constexpr int AUTO_UPDATE_STABLE_INDEX = 1; constexpr int AUTO_UPDATE_STABLE_INDEX = 1;
@ -127,7 +130,7 @@ void GeneralPane::CreateBasic()
basic_group_layout->addWidget(m_checkbox_cheats); basic_group_layout->addWidget(m_checkbox_cheats);
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
m_checkbox_discord_presence = new QCheckBox(tr("Show Activity in Your Discord Status")); m_checkbox_discord_presence = new QCheckBox(tr("Show Current Game on Discord"));
basic_group_layout->addWidget(m_checkbox_discord_presence); basic_group_layout->addWidget(m_checkbox_discord_presence);
#endif #endif
@ -224,7 +227,7 @@ void GeneralPane::LoadConfig()
m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread); m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread);
m_checkbox_cheats->setChecked(Settings::Instance().GetCheatsEnabled()); m_checkbox_cheats->setChecked(Settings::Instance().GetCheatsEnabled());
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
m_checkbox_discord_presence->setChecked(SConfig::GetInstance().bUseDiscordPresence); m_checkbox_discord_presence->setChecked(Config::Get(MAIN_USE_DISCORD_PRESENCE));
#endif #endif
int selection = qRound(SConfig::GetInstance().m_EmulationSpeed * 10); int selection = qRound(SConfig::GetInstance().m_EmulationSpeed * 10);
if (selection < m_combobox_speedlimit->count()) if (selection < m_combobox_speedlimit->count())
@ -272,7 +275,7 @@ void GeneralPane::OnSaveConfig()
} }
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
Settings::Instance().SetDiscordPresenceEnabled(m_checkbox_discord_presence->isChecked()); Discord::SetDiscordPresenceEnabled(m_checkbox_discord_presence->isChecked());
#endif #endif
#if defined(USE_ANALYTICS) && USE_ANALYTICS #if defined(USE_ANALYTICS) && USE_ANALYTICS

View File

@ -59,8 +59,7 @@ void GeneralConfigPane::InitializeGUI()
m_dual_core_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Dual Core (speedup)")); m_dual_core_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Dual Core (speedup)"));
m_cheats_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Cheats")); m_cheats_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Cheats"));
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
m_discord_presence_checkbox = m_discord_presence_checkbox = new wxCheckBox(this, wxID_ANY, _("Show Current Game on Discord"));
new wxCheckBox(this, wxID_ANY, _("Show Activity in Your Discord Status"));
#endif #endif
#if defined(USE_ANALYTICS) && USE_ANALYTICS #if defined(USE_ANALYTICS) && USE_ANALYTICS
m_analytics_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Usage Statistics Reporting")); m_analytics_checkbox = new wxCheckBox(this, wxID_ANY, _("Enable Usage Statistics Reporting"));
@ -83,8 +82,8 @@ void GeneralConfigPane::InitializeGUI()
m_cheats_checkbox->SetToolTip(_("Enables the use of Action Replay and Gecko cheats.")); m_cheats_checkbox->SetToolTip(_("Enables the use of Action Replay and Gecko cheats."));
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
m_discord_presence_checkbox->SetToolTip( m_discord_presence_checkbox->SetToolTip(
_("Allow other people on Discord to see your current activity in Dolphin. Activities such as " _("Allow other people on Discord to see the current activity in Dolphin. Activities such as "
"games you are playing, and how long you've been doing something in Dolphin")); "the game being played, and for how long"));
#endif #endif
#if defined(USE_ANALYTICS) && USE_ANALYTICS #if defined(USE_ANALYTICS) && USE_ANALYTICS
m_analytics_checkbox->SetToolTip( m_analytics_checkbox->SetToolTip(
@ -162,7 +161,7 @@ void GeneralConfigPane::LoadGUIValues()
m_cheats_checkbox->SetValue(startup_params.bEnableCheats); m_cheats_checkbox->SetValue(startup_params.bEnableCheats);
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
m_discord_presence_checkbox->SetValue(startup_params.bUseDiscordPresence); m_discord_presence_checkbox->SetValue(Config::Get(MAIN_USE_DISCORD_PRESENCE));
#endif #endif
#if defined(USE_ANALYTICS) && USE_ANALYTICS #if defined(USE_ANALYTICS) && USE_ANALYTICS
@ -222,13 +221,7 @@ void GeneralConfigPane::OnCheatCheckBoxChanged(wxCommandEvent& event)
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
void GeneralConfigPane::OnDiscordPresenceCheckBoxChanged(wxCommandEvent& event) void GeneralConfigPane::OnDiscordPresenceCheckBoxChanged(wxCommandEvent& event)
{ {
if (SConfig::GetInstance().bUseDiscordPresence) Discord::SetDiscordPresenceEnabled(m_discord_presence_checkbox->IsChecked());
Discord::Shutdown();
SConfig::GetInstance().bUseDiscordPresence = m_discord_presence_checkbox->IsChecked();
if (SConfig::GetInstance().bUseDiscordPresence)
Discord::Init();
} }
#endif #endif

View File

@ -13,12 +13,15 @@
#endif #endif
const Config::ConfigInfo<bool> MAIN_USE_DISCORD_PRESENCE{
{Config::System::Main, "General", "UseDiscordPresence"}, true};
namespace Discord namespace Discord
{ {
void Init() void Init()
{ {
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
if (!SConfig::GetInstance().bUseDiscordPresence) if (!Config::Get(MAIN_USE_DISCORD_PRESENCE))
return; return;
DiscordEventHandlers handlers = {}; DiscordEventHandlers handlers = {};
@ -31,7 +34,7 @@ void Init()
void UpdateDiscordPresence() void UpdateDiscordPresence()
{ {
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
if (!SConfig::GetInstance().bUseDiscordPresence) if (!Config::Get(MAIN_USE_DISCORD_PRESENCE))
return; return;
const std::string& title = SConfig::GetInstance().GetTitleDescription(); const std::string& title = SConfig::GetInstance().GetTitleDescription();
@ -48,11 +51,26 @@ void UpdateDiscordPresence()
void Shutdown() void Shutdown()
{ {
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
if (!SConfig::GetInstance().bUseDiscordPresence) if (!Config::Get(MAIN_USE_DISCORD_PRESENCE))
return; return;
Discord_ClearPresence(); Discord_ClearPresence();
Discord_Shutdown(); Discord_Shutdown();
#endif #endif
} }
void SetDiscordPresenceEnabled(bool enabled)
{
if (Config::Get(MAIN_USE_DISCORD_PRESENCE) == enabled)
return;
if (Config::Get(MAIN_USE_DISCORD_PRESENCE))
Discord::Shutdown();
Config::SetBase(MAIN_USE_DISCORD_PRESENCE, enabled);
if (Config::Get(MAIN_USE_DISCORD_PRESENCE))
Discord::Init();
}
} // namespace Discord } // namespace Discord

View File

@ -4,9 +4,14 @@
#pragma once #pragma once
#include "Common/Config/Config.h"
namespace Discord namespace Discord
{ {
void Init(); void Init();
void UpdateDiscordPresence(); void UpdateDiscordPresence();
void Shutdown(); void Shutdown();
void SetDiscordPresenceEnabled(bool enabled);
} // namespace Discord } // namespace Discord
extern const Config::ConfigInfo<bool> MAIN_USE_DISCORD_PRESENCE;