FullscreenUI: Use RetroAchievements game icon as fallback game image

This commit is contained in:
Stenzek 2025-03-11 22:38:40 +10:00
parent 492a55ee8b
commit d6ab840e4b
No known key found for this signature in database
4 changed files with 30 additions and 12 deletions

View File

@ -603,6 +603,11 @@ const std::string& Achievements::GetGameTitle()
return s_state.game_title;
}
const std::string& Achievements::GetGamePath()
{
return s_state.game_path;
}
const std::string& Achievements::GetGameIconPath()
{
return s_state.game_icon;

View File

@ -155,10 +155,16 @@ const std::string& GetRichPresenceString();
/// Returns the URL for the current icon of the game
const std::string& GetGameIconURL();
/// Returns the path for the current icon of the game
const std::string& GetGameIconPath();
/// Returns the RetroAchievements title for the current game.
/// Should be called with the lock held.
const std::string& GetGameTitle();
/// Returns the path for the game that is current hashed/running.
const std::string& GetGamePath();
/// Returns the logged-in user name.
const char* GetLoggedInUserName();

View File

@ -13,7 +13,6 @@ namespace Achievements {
rc_client_t* GetClient();
const rc_client_user_game_summary_t& GetGameSummary();
const std::string& GetGameIconPath();
std::string GetAchievementBadgePath(const rc_client_achievement_t* achievement, int state,
bool download_if_missing = true);

View File

@ -448,7 +448,8 @@ static void DrawGameListSettingsWindow();
static void SwitchToGameList();
static void PopulateGameListEntryList();
static GPUTexture* GetTextureForGameListEntryType(GameList::EntryType type);
static GPUTexture* GetGameListCover(const GameList::Entry* entry, bool fallback_to_icon);
static GPUTexture* GetGameListCover(const GameList::Entry* entry, bool fallback_to_achievements_icon,
bool fallback_to_icon);
static GPUTexture* GetGameListCoverTrophy(const GameList::Entry* entry, const ImVec2& image_size);
static GPUTexture* GetCoverForCurrentGame();
@ -7527,7 +7528,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)
if (!visible)
continue;
GPUTexture* cover_texture = GetGameListCover(entry, true);
GPUTexture* cover_texture = GetGameListCover(entry, false, true);
if (entry->serial.empty())
{
@ -7589,7 +7590,7 @@ void FullscreenUI::DrawGameList(const ImVec2& heading_size)
{
static constexpr float info_top_margin = 20.0f;
static constexpr float cover_size = 320.0f;
GPUTexture* cover_texture = selected_entry ? GetGameListCover(selected_entry, false) :
GPUTexture* cover_texture = selected_entry ? GetGameListCover(selected_entry, false, false) :
GetTextureForGameListEntryType(GameList::EntryType::Count);
if (cover_texture)
{
@ -7803,7 +7804,7 @@ void FullscreenUI::DrawGameGrid(const ImVec2& heading_size)
bb.Min += style.FramePadding;
bb.Max -= style.FramePadding;
GPUTexture* const cover_texture = GetGameListCover(entry, false);
GPUTexture* const cover_texture = GetGameListCover(entry, false, false);
const ImRect image_rect(
CenterImage(ImRect(bb.Min, bb.Min + image_size), ImVec2(static_cast<float>(cover_texture->GetWidth()),
static_cast<float>(cover_texture->GetHeight()))));
@ -8202,7 +8203,8 @@ void FullscreenUI::SwitchToGameList()
QueueResetFocus(FocusResetType::ViewChanged);
}
GPUTexture* FullscreenUI::GetGameListCover(const GameList::Entry* entry, bool fallback_to_icon)
GPUTexture* FullscreenUI::GetGameListCover(const GameList::Entry* entry, bool fallback_to_achievements_icon,
bool fallback_to_icon)
{
// lookup and grab cover image
auto cover_it = s_state.cover_image_map.find(entry->path);
@ -8210,12 +8212,18 @@ GPUTexture* FullscreenUI::GetGameListCover(const GameList::Entry* entry, bool fa
{
std::string cover_path = GameList::GetCoverImagePathForEntry(entry);
cover_it = s_state.cover_image_map.emplace(entry->path, std::move(cover_path)).first;
// try achievements image before memcard icon
if (fallback_to_achievements_icon && cover_it->second.empty() && Achievements::IsActive())
{
const auto lock = Achievements::GetLock();
if (Achievements::GetGamePath() == entry->path)
cover_it->second = Achievements::GetGameIconPath();
}
// because memcard icons are crap res
if (fallback_to_icon && cover_it->second.empty())
{
std::string icon_path = GameList::GetGameIconPath(entry->serial, entry->path);
cover_it = s_state.icon_image_map.emplace(entry->path, std::move(icon_path)).first;
cover_it->second = GameList::GetGameIconPath(entry->serial, entry->path);
}
GPUTexture* tex = (!cover_it->second.empty()) ? GetCachedTextureAsync(cover_it->second.c_str()) : nullptr;
@ -8265,7 +8273,7 @@ GPUTexture* FullscreenUI::GetCoverForCurrentGame()
if (!entry)
return s_state.fallback_disc_texture.get();
return GetGameListCover(entry, true);
return GetGameListCover(entry, true, true);
}
//////////////////////////////////////////////////////////////////////////