mirror of https://github.com/PCSX2/pcsx2.git
DiscordRPC: Add game icon support.
This commit is contained in:
parent
31b5672870
commit
ffe8d16df4
|
@ -199,6 +199,7 @@ namespace Achievements
|
||||||
static std::string s_game_hash;
|
static std::string s_game_hash;
|
||||||
static std::string s_game_title;
|
static std::string s_game_title;
|
||||||
static std::string s_game_icon;
|
static std::string s_game_icon;
|
||||||
|
static std::string s_game_icon_url;
|
||||||
static u32 s_game_crc;
|
static u32 s_game_crc;
|
||||||
static rc_client_user_game_summary_t s_game_summary;
|
static rc_client_user_game_summary_t s_game_summary;
|
||||||
static u32 s_game_id = 0;
|
static u32 s_game_id = 0;
|
||||||
|
@ -401,6 +402,10 @@ const std::string& Achievements::GetRichPresenceString()
|
||||||
return s_rich_presence_string;
|
return s_rich_presence_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& Achievements::GetGameIconURL()
|
||||||
|
{
|
||||||
|
return s_game_icon_url;
|
||||||
|
}
|
||||||
|
|
||||||
bool Achievements::Initialize()
|
bool Achievements::Initialize()
|
||||||
{
|
{
|
||||||
|
@ -945,6 +950,7 @@ void Achievements::ClientLoadGameCallback(int result, const char* error_message,
|
||||||
s_has_leaderboards = has_leaderboards;
|
s_has_leaderboards = has_leaderboards;
|
||||||
s_has_rich_presence = rc_client_has_rich_presence(client);
|
s_has_rich_presence = rc_client_has_rich_presence(client);
|
||||||
s_game_icon = {};
|
s_game_icon = {};
|
||||||
|
s_game_icon_url = {};
|
||||||
|
|
||||||
// ensure fullscreen UI is ready for notifications
|
// ensure fullscreen UI is ready for notifications
|
||||||
MTGS::RunOnGSThread(&ImGuiManager::InitializeFullscreenUI);
|
MTGS::RunOnGSThread(&ImGuiManager::InitializeFullscreenUI);
|
||||||
|
@ -966,6 +972,16 @@ void Achievements::ClientLoadGameCallback(int result, const char* error_message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char icon_url[64];
|
||||||
|
if (int err = rc_client_game_get_image_url(info, icon_url, std::size(icon_url)); err == RC_OK)
|
||||||
|
{
|
||||||
|
s_game_icon_url = icon_url;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReportRCError(err, "rc_client_game_get_image_url() failed: ");
|
||||||
|
}
|
||||||
|
|
||||||
UpdateGameSummary();
|
UpdateGameSummary();
|
||||||
DisplayAchievementSummary();
|
DisplayAchievementSummary();
|
||||||
|
|
||||||
|
@ -990,6 +1006,7 @@ void Achievements::ClearGameInfo()
|
||||||
s_game_id = 0;
|
s_game_id = 0;
|
||||||
s_game_title = {};
|
s_game_title = {};
|
||||||
s_game_icon = {};
|
s_game_icon = {};
|
||||||
|
s_game_icon_url = {};
|
||||||
s_has_achievements = false;
|
s_has_achievements = false;
|
||||||
s_has_leaderboards = false;
|
s_has_leaderboards = false;
|
||||||
s_has_rich_presence = false;
|
s_has_rich_presence = false;
|
||||||
|
|
|
@ -108,6 +108,10 @@ namespace Achievements
|
||||||
/// Should be called with the lock held.
|
/// Should be called with the lock held.
|
||||||
const std::string& GetRichPresenceString();
|
const std::string& GetRichPresenceString();
|
||||||
|
|
||||||
|
/// Returns the current game icon url.
|
||||||
|
/// Should be called with the lock held.
|
||||||
|
const std::string& GetGameIconURL();
|
||||||
|
|
||||||
/// Returns the RetroAchievements title for the current game.
|
/// Returns the RetroAchievements title for the current game.
|
||||||
/// Should be called with the lock held.
|
/// Should be called with the lock held.
|
||||||
const std::string& GetGameTitle();
|
const std::string& GetGameTitle();
|
||||||
|
|
|
@ -3608,15 +3608,21 @@ void VMManager::UpdateDiscordPresence(bool update_session_time)
|
||||||
// https://discord.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields
|
// https://discord.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload-fields
|
||||||
DiscordRichPresence rp = {};
|
DiscordRichPresence rp = {};
|
||||||
rp.largeImageKey = "4k-pcsx2";
|
rp.largeImageKey = "4k-pcsx2";
|
||||||
rp.largeImageText = "PCSX2 Emulator";
|
rp.largeImageText = "PCSX2 PS2 Emulator";
|
||||||
rp.startTimestamp = s_discord_presence_time_epoch;
|
rp.startTimestamp = s_discord_presence_time_epoch;
|
||||||
rp.details = s_title.empty() ? TRANSLATE("VMManager","No Game Running") : s_title.c_str();
|
rp.details = s_title.empty() ? TRANSLATE("VMManager","No Game Running") : s_title.c_str();
|
||||||
|
|
||||||
std::string state_string;
|
std::string state_string;
|
||||||
|
|
||||||
if (Achievements::HasRichPresence())
|
if (Achievements::HasRichPresence())
|
||||||
{
|
{
|
||||||
|
auto lock = Achievements::GetLock();
|
||||||
|
|
||||||
state_string = StringUtil::Ellipsise(Achievements::GetRichPresenceString(), 128);
|
state_string = StringUtil::Ellipsise(Achievements::GetRichPresenceString(), 128);
|
||||||
rp.state = state_string.c_str();
|
rp.state = state_string.c_str();
|
||||||
|
|
||||||
|
rp.largeImageKey = Achievements::GetGameIconURL().c_str();
|
||||||
|
rp.largeImageText = s_title.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
Discord_UpdatePresence(&rp);
|
Discord_UpdatePresence(&rp);
|
||||||
|
|
Loading…
Reference in New Issue