Discord fixes

This commit is contained in:
Megamouse 2018-06-16 22:56:21 +02:00 committed by Ivan
parent 0c4cdaa7d3
commit 27a94308a7
8 changed files with 96 additions and 55 deletions

View File

@ -985,6 +985,7 @@
<ClCompile Include="rpcs3qt\breakpoint_handler.cpp" />
<ClCompile Include="rpcs3qt\breakpoint_list.cpp" />
<ClCompile Include="rpcs3qt\debugger_list.cpp" />
<ClCompile Include="rpcs3qt\_discord_utils.cpp" />
<ClCompile Include="rpcs3qt\find_dialog.cpp" />
<ClCompile Include="rpcs3qt\gamepads_settings_dialog.cpp" />
<ClCompile Include="rpcs3qt\game_compatibility.cpp" />
@ -1424,6 +1425,7 @@
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug - LLVM|x64'">.\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug - LLVM|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DQT_OPENGL_LIB -DQT_WIDGETS_LIB -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_WINEXTRAS_LIB -DLLVM_AVAILABLE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE "-I$(VULKAN_SDK)\Include" "-I.\.." "-I.\..\3rdparty\minidx12\Include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtOpenGL" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtQuick" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtQml" "-I$(QTDIR)\include\QtNetwork" "-I$(QTDIR)\include\QtCore" "-I.\debug" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)\." "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras"</Command>
</CustomBuild>
<ClInclude Include="rpcs3qt\_discord_utils.h" />
<ClInclude Include="rpcs3qt\find_dialog.h" />
<ClInclude Include="rpcs3qt\custom_table_widget_item.h" />
<ClInclude Include="rpcs3qt\gamepads_settings_dialog.h" />

View File

@ -638,6 +638,9 @@
<ClCompile Include="QTGeneratedFiles\qrc_windows.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="rpcs3qt\_discord_utils.cpp">
<Filter>Gui\utils</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="\rpcs3qt\*.h">
@ -721,6 +724,9 @@
<ClInclude Include="rpcs3qt\custom_dock_widget.h">
<Filter>Gui</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\_discord_utils.h">
<Filter>Gui\utils</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">

View File

@ -5,8 +5,7 @@
#include "rpcs3qt/welcome_dialog.h"
#ifdef WITH_DISCORD_RPC
#include "discord_rpc.h"
#include "discord_register.h"
#include "rpcs3qt/_discord_utils.h"
#endif
#include "Emu/System.h"
@ -98,8 +97,7 @@ void rpcs3_app::Init()
// Discord Rich Presence Integration
if (guiSettings->GetValue(gui::m_richPresence).toBool())
{
DiscordEventHandlers handlers = {};
Discord_Initialize("424004941485572097", &handlers, 1, NULL);
discord::initialize();
}
#endif

View File

@ -0,0 +1,33 @@
#include "_discord_utils.h"
#include "discord_rpc.h"
#include "discord_register.h"
namespace discord
{
void initialize(const std::string& application_id)
{
DiscordEventHandlers handlers = {};
Discord_Initialize(application_id.c_str(), &handlers, 1, NULL);
}
void shutdown()
{
Discord_Shutdown();
}
void update_presence(const std::string& state, const std::string& details, bool reset_timer)
{
DiscordRichPresence discordPresence = {};
discordPresence.details = details.c_str();
discordPresence.state = state.c_str();
discordPresence.largeImageKey = "rpcs3_logo";
discordPresence.largeImageText = "RPCS3 is the world's first PlayStation 3 emulator.";
if (reset_timer)
{
discordPresence.startTimestamp = time(0);
}
Discord_UpdatePresence(&discordPresence);
}
}

View File

@ -0,0 +1,15 @@
#pragma once
#include "stdafx.h"
namespace discord
{
// Convenience function for initialization
void initialize(const std::string& application_id = "424004941485572097");
// Convenience function for shutdown
void shutdown();
// Convenience function for status updates. The default is set to idle.
void update_presence(const std::string& state = "", const std::string& details = "Idle", bool reset_timer = true);
}

View File

@ -9,8 +9,7 @@
#include <QMimeData>
#ifdef WITH_DISCORD_RPC
#include "discord_rpc.h"
#include "discord_register.h"
#include "_discord_utils.h"
#endif
#include "qt_utils.h"
@ -65,7 +64,7 @@ main_window::~main_window()
{
delete ui;
#ifdef WITH_DISCORD_RPC
Discord_Shutdown();
discord::shutdown();
#endif
}
@ -277,19 +276,6 @@ void main_window::Boot(const std::string& path, bool direct, bool add_only)
LOG_SUCCESS(LOADER, "Boot successful.");
const std::string serial = Emu.GetTitleID().empty() ? "" : "[" + Emu.GetTitleID() + "] ";
AddRecentAction(gui::Recent_Game(qstr(Emu.GetBoot()), qstr(serial + Emu.GetTitle())));
#ifdef WITH_DISCORD_RPC
// Discord Rich Presence Integration
if (guiSettings->GetValue(gui::m_richPresence).toBool())
{
DiscordRichPresence discordPresence = {};
discordPresence.state = Emu.GetTitleID().c_str();
discordPresence.details = Emu.GetTitle().c_str();
discordPresence.largeImageKey = "rpcs3_logo";
discordPresence.largeImageText = "RPCS3 is the world's first PlayStation 3 emulator.";
discordPresence.startTimestamp = time(0);
Discord_UpdatePresence(&discordPresence);
}
#endif
}
else
{
@ -775,6 +761,14 @@ void main_window::OnEmuRun()
ui->toolbar_start->setIcon(m_icon_pause);
ui->toolbar_start->setToolTip(tr("Pause emulation"));
EnableMenus(true);
#ifdef WITH_DISCORD_RPC
// Discord Rich Presence Integration
if (guiSettings->GetValue(gui::m_richPresence).toBool())
{
discord::update_presence(Emu.GetTitleID(), Emu.GetTitle());
}
#endif
}
void main_window::OnEmuResume()
@ -832,14 +826,7 @@ void main_window::OnEmuStop()
// Discord Rich Presence Integration
if (guiSettings->GetValue(gui::m_richPresence).toBool())
{
QString discord_state = guiSettings->GetValue(gui::m_discordState).toString();
DiscordRichPresence discordPresence = {};
discordPresence.details = "Idle";
discordPresence.state = sstr(discord_state).c_str();
discordPresence.largeImageKey = "rpcs3_logo";
discordPresence.largeImageText = "RPCS3 is the world's first PlayStation 3 emulator.";
discordPresence.startTimestamp = time(0);
Discord_UpdatePresence(&discordPresence);
discord::update_presence(sstr(guiSettings->GetValue(gui::m_discordState).toString()));
}
#endif
}

View File

@ -26,8 +26,7 @@
#include <thread>
#ifdef WITH_DISCORD_RPC
#include "discord_rpc.h"
#include "discord_register.h"
#include "_discord_utils.h"
#endif
inline std::string sstr(const QString& _in) { return _in.toStdString(); }
@ -109,11 +108,11 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> guiSettings, std:
}
// Discord variables
bool use_discord = xgui_settings->GetValue(gui::m_richPresence).toBool();
QString discord_state = xgui_settings->GetValue(gui::m_discordState).toString();
m_use_discord = xgui_settings->GetValue(gui::m_richPresence).toBool();
m_discord_state = xgui_settings->GetValue(gui::m_discordState).toString();
// Various connects
connect(ui->okButton, &QAbstractButton::clicked, [=]
connect(ui->okButton, &QAbstractButton::clicked, [=, use_discord_old = m_use_discord, discord_state_old = m_discord_state]
{
std::set<std::string> selectedlle;
for (int i = 0; i<ui->lleList->count(); ++i)
@ -129,30 +128,27 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> guiSettings, std:
xemu_settings->SaveSettings();
accept();
// Discord Settings can be saved regardless of WITH_DISCORD_RPC
xgui_settings->SetValue(gui::m_richPresence, m_use_discord);
xgui_settings->SetValue(gui::m_discordState, m_discord_state);
#ifdef WITH_DISCORD_RPC
bool use_discord_new = xgui_settings->GetValue(gui::m_richPresence).toBool();
QString discord_state_new = xgui_settings->GetValue(gui::m_discordState).toString();
if (use_discord != use_discord_new || discord_state != discord_state_new)
if (m_use_discord != use_discord_old)
{
if (use_discord_new)
if (m_use_discord)
{
DiscordEventHandlers handlers = {};
Discord_Initialize("424004941485572097", &handlers, 1, NULL);
DiscordRichPresence discordPresence = {};
discordPresence.details = "Idle";
discordPresence.state = sstr(discord_state_new).c_str();
discordPresence.largeImageKey = "rpcs3_logo";
discordPresence.largeImageText = "RPCS3 is the world's first PlayStation 3 emulator.";
discordPresence.startTimestamp = time(0);
Discord_UpdatePresence(&discordPresence);
discord::initialize();
discord::update_presence(sstr(m_discord_state));
}
else
{
Discord_ClearPresence();
discord::shutdown();
}
}
else if (m_discord_state != discord_state_old && Emu.IsStopped())
{
discord::update_presence(sstr(m_discord_state), "Idle", false);
}
#endif
});
@ -868,21 +864,21 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> guiSettings, std:
if (!game)
{
// Discord:
ui->useRichPresence->setChecked(use_discord);
ui->label_discordState->setEnabled(use_discord);
ui->discordState->setEnabled(use_discord);
ui->discordState->setText(discord_state);
ui->useRichPresence->setChecked(m_use_discord);
ui->label_discordState->setEnabled(m_use_discord);
ui->discordState->setEnabled(m_use_discord);
ui->discordState->setText(m_discord_state);
connect(ui->useRichPresence, &QCheckBox::clicked, [this](bool checked)
{
ui->discordState->setEnabled(checked);
ui->label_discordState->setEnabled(checked);
xgui_settings->SetValue(gui::m_richPresence, checked);
m_use_discord = checked;
});
connect(ui->discordState, &QLineEdit::editingFinished, [this]()
{
xgui_settings->SetValue(gui::m_discordState, ui->discordState->text());
m_discord_state = ui->discordState->text();
});
// colorize preview icons

View File

@ -47,6 +47,10 @@ private:
std::shared_ptr<gui_settings> xgui_settings;
std::shared_ptr<emu_settings> xemu_settings;
// Discord
bool m_use_discord;
QString m_discord_state;
// descriptions
QList<QPair<QLabel*, QString>> m_description_labels;
QHash<QObject*, QString> m_descriptions;