mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Achievements: Show achievement icons in list
This commit is contained in:
parent
603dc7493a
commit
1d0badae56
4 changed files with 30 additions and 16 deletions
|
@ -76,6 +76,13 @@ struct Bounds {
|
|||
return Bounds(x + left, y + top, w - left - right, h - bottom - top);
|
||||
}
|
||||
|
||||
Bounds Inset(float xAmount, float yAmount) const {
|
||||
return Bounds(x + xAmount, y + yAmount, w - xAmount * 2, h - yAmount * 2);
|
||||
}
|
||||
Bounds Inset(float left, float top, float right, float bottom) const {
|
||||
return Bounds(x + left, y + top, w - left - right, h - top - bottom);
|
||||
}
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float w;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "Common/UI/ViewGroup.h"
|
||||
#include "Common/UI/Context.h"
|
||||
#include "Common/Data/Text/I18n.h"
|
||||
#include "Common/UI/IconCache.h"
|
||||
|
||||
void RetroAchievementsListScreen::CreateViews() {
|
||||
auto di = GetI18NCategory(I18NCat::DIALOG);
|
||||
|
@ -82,14 +83,16 @@ void RenderAchievement(UIContext &dc, const Achievements::Achievement &achieveme
|
|||
|
||||
background.color = colorAlpha(background.color, opacity);
|
||||
|
||||
float iconSpace = 64.0f;
|
||||
|
||||
dc.Begin();
|
||||
dc.FillRect(background, bounds);
|
||||
|
||||
dc.SetFontScale(0.7f, 0.7f);
|
||||
dc.DrawTextRect(achievement.title.c_str(), bounds.Expand(-5.0f, -5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT);
|
||||
dc.DrawTextRect(achievement.title.c_str(), bounds.Inset(iconSpace + 5.0f, 5.0f, 5.0f, 5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT);
|
||||
|
||||
dc.SetFontScale(0.5f, 0.5f);
|
||||
dc.DrawTextRect(achievement.description.c_str(), bounds.Expand(-5.0f, -5.0f).Offset(0.0f, 30.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT);
|
||||
dc.DrawTextRect(achievement.description.c_str(), bounds.Inset(iconSpace + 5.0f, 30.0f, 5.0f, 5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT);
|
||||
|
||||
char temp[64];
|
||||
snprintf(temp, sizeof(temp), "%d", achievement.points);
|
||||
|
@ -98,6 +101,15 @@ void RenderAchievement(UIContext &dc, const Achievements::Achievement &achieveme
|
|||
dc.DrawTextRect(temp, bounds.Expand(-5.0f, -5.0f), dc.theme->itemStyle.fgColor, ALIGN_RIGHT | ALIGN_VCENTER);
|
||||
|
||||
dc.SetFontScale(1.0f, 1.0f);
|
||||
dc.Flush();
|
||||
|
||||
std::string name = Achievements::GetAchievementBadgePath(achievement);
|
||||
if (g_iconCache.BindIconTexture(&dc, name)) {
|
||||
dc.Draw()->DrawTexRect(Bounds(bounds.x, bounds.y, iconSpace, iconSpace), 0.0f, 0.0f, 1.0f, 1.0f, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
dc.Flush();
|
||||
dc.RebindTexture();
|
||||
|
||||
dc.Flush();
|
||||
}
|
||||
|
|
|
@ -319,7 +319,6 @@ public:
|
|||
|
||||
_dbg_assert_msg_(!api_request.post_data, "Download request does not have POST data");
|
||||
|
||||
INFO_LOG(ACHIEVEMENTS, "Downloading image: %s (%s)", api_request.url, cache_filename.c_str());
|
||||
Achievements::DownloadImage(api_request.url, std::move(cache_filename));
|
||||
return true;
|
||||
}
|
||||
|
@ -1086,9 +1085,13 @@ void Achievements::DownloadImage(std::string url, std::string cache_filename)
|
|||
g_iconCache.InsertIcon(cache_filename, IconFormat::PNG, std::move(data));
|
||||
};
|
||||
|
||||
s_http_downloader->CreateRequest(std::move(url), std::move(callback));
|
||||
if (g_iconCache.MarkPending(cache_filename)) {
|
||||
INFO_LOG(ACHIEVEMENTS, "Downloading image: %s (%s)", url.c_str(), cache_filename.c_str());
|
||||
s_http_downloader->CreateRequest(std::move(url), std::move(callback));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Achievements::DisplayAchievementSummary()
|
||||
{
|
||||
auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS);
|
||||
|
@ -1209,7 +1212,7 @@ void Achievements::GetPatchesCallback(s32 status_code, std::string content_type,
|
|||
// try for a icon. not that we really need one, PSP games have their own icons...
|
||||
if (response.image_name && std::strlen(response.image_name) > 0)
|
||||
{
|
||||
s_game_icon = g_gameIconCachePrefix + StringFromFormat("%d", s_game_id));
|
||||
s_game_icon = g_gameIconCachePrefix + StringFromFormat("%d", s_game_id);
|
||||
if (!g_iconCache.Contains(s_game_icon))
|
||||
{
|
||||
RAPIRequest<rc_api_fetch_image_request_t, rc_api_init_fetch_image_request> request;
|
||||
|
@ -1988,15 +1991,11 @@ std::string Achievements::GetAchievementProgressText(const Achievement &achievem
|
|||
}
|
||||
|
||||
// Note that this returns an g_iconCache key, rather than an actual filename. So look up your image there.
|
||||
const std::string &Achievements::GetAchievementBadgePath(const Achievement &achievement, bool download_if_missing, bool force_unlocked_icon)
|
||||
std::string Achievements::GetAchievementBadgePath(const Achievement &achievement, bool download_if_missing, bool force_unlocked_icon)
|
||||
{
|
||||
const bool use_locked = (achievement.locked && !force_unlocked_icon);
|
||||
std::string &badge_path = use_locked ? achievement.locked_badge_path : achievement.unlocked_badge_path;
|
||||
if (!badge_path.empty() || achievement.badge_name.empty())
|
||||
return badge_path;
|
||||
|
||||
std::string badge_path = g_iconCachePrefix + achievement.badge_name + (use_locked ? "_lock" : "");
|
||||
|
||||
std::string badge_path = g_iconCachePrefix + achievement.badge_name + std::string(use_locked ? "_lock" : "");
|
||||
if (g_iconCache.Contains(badge_path)) {
|
||||
return badge_path;
|
||||
}
|
||||
|
|
|
@ -38,10 +38,6 @@ struct Achievement
|
|||
std::string memaddr;
|
||||
std::string badge_name;
|
||||
|
||||
// badge paths are mutable because they're resolved when they're needed.
|
||||
mutable std::string locked_badge_path;
|
||||
mutable std::string unlocked_badge_path;
|
||||
|
||||
u32 points;
|
||||
AchievementCategory category;
|
||||
bool locked;
|
||||
|
@ -160,7 +156,7 @@ u32 GetPrimedAchievementCount();
|
|||
const Achievement *GetAchievementByID(u32 id);
|
||||
std::pair<u32, u32> GetAchievementProgress(const Achievement &achievement);
|
||||
std::string GetAchievementProgressText(const Achievement &achievement);
|
||||
const std::string &GetAchievementBadgePath(const Achievement &achievement, bool download_if_missing = true,
|
||||
std::string GetAchievementBadgePath(const Achievement &achievement, bool download_if_missing = true,
|
||||
bool force_unlocked_icon = false);
|
||||
std::string GetAchievementBadgeURL(const Achievement &achievement);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue