diff --git a/Common/System/Request.cpp b/Common/System/Request.cpp index a7d4a4edd8..a260ed4f84 100644 --- a/Common/System/Request.cpp +++ b/Common/System/Request.cpp @@ -40,7 +40,7 @@ std::vector OnScreenDisplay::ProgressBars() { return bars_; // makes a copy. } -void OnScreenDisplay::Show(OSDType type, const std::string &text, const std::string &text2, float duration_s, const char *id) { +void OnScreenDisplay::Show(OSDType type, const std::string &text, const std::string &text2, const std::string &icon, float duration_s, const char *id) { // Automatic duration based on type. if (duration_s <= 0.0f) { switch (type) { @@ -70,6 +70,7 @@ void OnScreenDisplay::Show(OSDType type, const std::string &text, const std::str msg.text = text; msg.text2 = text2; msg.type = type; + msg.iconName = icon; // Move to top (should we? maybe not?) entries_.erase(iter); entries_.insert(entries_.begin(), msg); @@ -81,6 +82,8 @@ void OnScreenDisplay::Show(OSDType type, const std::string &text, const std::str Entry msg; msg.text = text; msg.text2 = text2; + msg.iconName = icon; + msg.startTime = now; msg.endTime = now + duration_s; msg.type = type; msg.id = id; diff --git a/Common/System/System.h b/Common/System/System.h index d493d5cb84..43d48d6c43 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -237,7 +237,10 @@ public: void Show(OSDType type, const std::string &text, float duration_s = 0.0f, const char *id = nullptr) { Show(type, text, "", duration_s, id); } - void Show(OSDType type, const std::string &text, const std::string &text2, float duration_s = 0.0f, const char *id = nullptr); + void Show(OSDType type, const std::string &text, const std::string &text2, float duration_s = 0.0f, const char *id = nullptr) { + Show(type, text, "", "", duration_s, id); + } + void Show(OSDType type, const std::string &text, const std::string &text2, const std::string &icon, float duration_s = 0.0f, const char *id = nullptr); void ShowAchievementUnlocked(int achievementID); void ShowOnOff(const std::string &message, bool on, float duration_s = 0.0f); diff --git a/Common/UI/IconCache.h b/Common/UI/IconCache.h index 82f8a2987c..0288b8de63 100644 --- a/Common/UI/IconCache.h +++ b/Common/UI/IconCache.h @@ -51,6 +51,16 @@ public: IconCacheStats GetStats(); + // for testing + std::string GetFirstIconName() const { + if (!cache_.empty()) { + return cache_.begin()->first; + } else if (!pending_.empty()) { + return *pending_.begin(); + } + return ""; + } + private: struct Entry { std::string data; diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index 70300e2705..3ae2e5c58d 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -40,7 +40,7 @@ ImageID GetOSDIcon(OSDType type) { } } -static const float iconSize = 36.0f; +static const float g_atlasIconSize = 36.0f; static const float extraTextScale = 0.7f; @@ -49,11 +49,12 @@ static void MeasureOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, if (entry.type == OSDType::ACHIEVEMENT_UNLOCKED) { const Achievements::Achievement *achievement = Achievements::GetAchievementByID(entry.numericID); MeasureAchievement(dc, *achievement, width, height); - *width = 400.0f; + *width = 550.0f; *height1 = *height; return; } + dc.SetFontStyle(dc.theme->uiFont); dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, entry.text.c_str(), width, height, align); *height1 = *height; @@ -64,18 +65,28 @@ static void MeasureOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, *height += 5.0f + height2; } - if (!GetOSDIcon(entry.type).isInvalid()) { - *width += iconSize + 5.0f; + float iconSize = 0.0f; + + if (!entry.iconName.empty()) { + // Normal entry but with a cached icon. + int iconWidth, iconHeight; + if (g_iconCache.GetDimensions(entry.iconName, &iconWidth, &iconHeight)) { + *width += 5.0f + iconWidth; + iconSize = iconWidth + 5.0f; + } + } else if (!GetOSDIcon(entry.type).isInvalid()) { + // Atlas icon. + iconSize = g_atlasIconSize + 5.0f; } - *width += 12.0f; + *width += iconSize + 12.0f; *height = std::max(*height, iconSize + 5.0f); } static void RenderOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, Bounds bounds, float height1, int align, float alpha) { if (entry.type == OSDType::ACHIEVEMENT_UNLOCKED) { const Achievements::Achievement *achievement = Achievements::GetAchievementByID(entry.numericID); - RenderAchievement(dc, *achievement, AchievementRenderStyle::UNLOCKED, bounds, alpha); + RenderAchievement(dc, *achievement, AchievementRenderStyle::UNLOCKED, bounds, alpha, entry.startTime, time_now_d()); return; } @@ -88,28 +99,40 @@ static void RenderOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, B dc.Draw()->DrawImage4Grid(dc.theme->dropShadow4Grid, shadowBounds.x, shadowBounds.y + 4.0f, shadowBounds.x2(), shadowBounds.y2(), alphaMul(0xFF000000, 0.9f * alpha), 1.0f); dc.FillRect(background, bounds); - dc.SetFontStyle(dc.theme->uiFont); ImageID iconID = GetOSDIcon(entry.type); - if (iconID.isValid()) { - dc.DrawImageVGradient(iconID, foreGround, foreGround, Bounds(bounds.x + 2.5f, bounds.y + 2.5f, iconSize, iconSize)); - - // Make room - bounds.x += iconSize + 5.0f; - bounds.w -= iconSize + 5.0f; + float iconSize = 0.0f; + if (!entry.iconName.empty()) { + dc.Flush(); + // Normal entry but with a cached icon. + Draw::Texture *texture = g_iconCache.BindIconTexture(&dc, entry.iconName); + if (texture) { + iconSize = texture->Width(); + dc.Draw()->DrawTexRect(Bounds(bounds.x + 2.5f, bounds.y + 2.5f, iconSize, iconSize), 0.0f, 0.0f, 1.0f, 1.0f, foreGround); + dc.Flush(); + dc.RebindTexture(); + } + dc.Begin(); + } else if (iconID.isValid()) { + // Atlas icon. + dc.DrawImageVGradient(iconID, foreGround, foreGround, Bounds(bounds.x + 2.5f, bounds.y + 2.5f, g_atlasIconSize, g_atlasIconSize)); } - dc.DrawTextShadowRect(entry.text.c_str(), bounds.Inset(0.0f, 1.0f, 0.0f, 0.0f), colorAlpha(0xFFFFFFFF, alpha), (align & FLAG_DYNAMIC_ASCII)); + // Make room + bounds.x += iconSize + 5.0f; + bounds.w -= iconSize + 5.0f; + + dc.DrawTextShadowRect(entry.text.c_str(), bounds.Inset(0.0f, 1.0f, 0.0f, 0.0f), foreGround, (align & FLAG_DYNAMIC_ASCII)); if (!entry.text2.empty()) { Bounds bottomTextBounds = bounds.Inset(3.0f, height1 + 5.0f, 3.0f, 3.0f); UI::Drawable backgroundDark = UI::Drawable(colorAlpha(darkenColor(GetOSDBackgroundColor(entry.type)), alpha)); dc.FillRect(backgroundDark, bottomTextBounds); dc.SetFontScale(extraTextScale, extraTextScale); - dc.DrawTextRect(entry.text2.c_str(), bottomTextBounds, colorAlpha(0xFFFFFFFF, alpha), (align & FLAG_DYNAMIC_ASCII) | ALIGN_LEFT); - dc.SetFontScale(1.0f, 1.0f); + dc.DrawTextRect(entry.text2.c_str(), bottomTextBounds, foreGround, (align & FLAG_DYNAMIC_ASCII) | ALIGN_LEFT); } + dc.SetFontScale(1.0f, 1.0f); } static void MeasureOSDProgressBar(UIContext &dc, const OnScreenDisplay::ProgressBar &bar, float *width, float *height) { @@ -153,6 +176,7 @@ static void RenderOSDProgressBar(UIContext &dc, const OnScreenDisplay::ProgressB } dc.SetFontStyle(dc.theme->uiFont); + dc.SetFontScale(1.0f, 1.0f); dc.DrawTextShadowRect(entry.message.c_str(), bounds, colorAlpha(0xFFFFFFFF, alpha), (align & FLAG_DYNAMIC_ASCII) | ALIGN_CENTER); } @@ -162,6 +186,8 @@ void OnScreenMessagesView::Draw(UIContext &dc) { return; } + dc.Flush(); + double now = time_now_d(); // Get height @@ -223,6 +249,7 @@ void OnScreenMessagesView::Draw(UIContext &dc) { } // Thin bar at the top of the screen. + // TODO: Remove and replace with "proper" progress bars. std::vector progress = g_DownloadManager.GetCurrentProgress(); if (!progress.empty()) { static const uint32_t colors[4] = { diff --git a/UI/RetroAchievementScreens.cpp b/UI/RetroAchievementScreens.cpp index 76977cd9e4..eaf78596f1 100644 --- a/UI/RetroAchievementScreens.cpp +++ b/UI/RetroAchievementScreens.cpp @@ -9,21 +9,22 @@ #include "Core/Config.h" -void RetroAchievementsListScreen::CreateViews() { +void RetroAchievementsListScreen::CreateTabs() { auto di = GetI18NCategory(I18NCat::DIALOG); auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS); using namespace UI; - root_ = new ScrollView(UI::ORIENT_VERTICAL); + LinearLayout *achievements = AddTab("Achievements", ac->T("Achievements")); - LinearLayout *listLayout = root_->Add(new LinearLayout(UI::ORIENT_VERTICAL)); - listLayout->SetSpacing(5.0f); + achievements->SetSpacing(5.0f); std::vector unlockedAchievements; std::vector lockedAchievements; - listLayout->Add(new GameAchievementSummaryView(Achievements::GetGameID())); + achievements->Add(new ItemHeader(ac->T("Achievements"))); + + achievements->Add(new GameAchievementSummaryView(Achievements::GetGameID())); Achievements::EnumerateAchievements([&](const Achievements::Achievement &achievement) { if (achievement.locked) { @@ -34,13 +35,13 @@ void RetroAchievementsListScreen::CreateViews() { return true; }); - listLayout->Add(new ItemHeader(ac->T("Unlocked achievements"))); + achievements->Add(new ItemHeader(ac->T("Unlocked achievements"))); for (auto achievement : unlockedAchievements) { - listLayout->Add(new AchievementView(achievement)); + achievements->Add(new AchievementView(achievement)); } - listLayout->Add(new ItemHeader(ac->T("Locked achievements"))); + achievements->Add(new ItemHeader(ac->T("Locked achievements"))); for (auto achievement : lockedAchievements) { - listLayout->Add(new AchievementView(achievement)); + achievements->Add(new AchievementView(achievement)); } } @@ -117,32 +118,41 @@ void RetroAchievementsSettingsScreen::CreateSettingsTab(UI::ViewGroup *viewGroup void MeasureAchievement(const UIContext &dc, const Achievements::Achievement &achievement, float *w, float *h) { *w = 0.0f; - *h = 60.0f; + *h = 72.0f; } void MeasureGameAchievementSummary(const UIContext &dc, int gameID, float *w, float *h) { *w = 0.0f; - *h = 60.0f; + *h = 72.0f; } // Graphical -void RenderAchievement(UIContext &dc, const Achievements::Achievement &achievement, AchievementRenderStyle style, const Bounds &bounds, float alpha) { +void RenderAchievement(UIContext &dc, const Achievements::Achievement &achievement, AchievementRenderStyle style, const Bounds &bounds, float alpha, float startTime, float time_s) { using namespace UI; - UI::Drawable background = achievement.locked ? dc.theme->popupStyle.background : dc.theme->itemStyle.background; - + UI::Drawable background = dc.theme->itemStyle.background; + if (achievement.locked) { + background.color = 0x706060; + } background.color = colorAlpha(background.color, alpha); + if (style == AchievementRenderStyle::UNLOCKED) { + float mixWhite = pow(Clamp((float)(1.0f - (time_s - startTime)), 0.0f, 1.0f), 3.0f); + background.color = colorBlend(0xFFE0FFFF, background.color, mixWhite); + } + float iconSpace = 64.0f; dc.Flush(); dc.Begin(); dc.FillRect(background, bounds); + dc.SetFontStyle(dc.theme->uiFont); + dc.SetFontScale(1.0f, 1.0f); - dc.DrawTextRect(achievement.title.c_str(), bounds.Inset(iconSpace + 5.0f, 5.0f, 5.0f, 5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT); + dc.DrawTextRect(achievement.title.c_str(), bounds.Inset(iconSpace + 12.0f, 2.0f, 5.0f, 5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT); dc.SetFontScale(0.66f, 0.66f); - dc.DrawTextRect(achievement.description.c_str(), bounds.Inset(iconSpace + 5.0f, 37.0f, 5.0f, 5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT); + dc.DrawTextRect(achievement.description.c_str(), bounds.Inset(iconSpace + 12.0f, 39.0f, 5.0f, 5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT); char temp[64]; snprintf(temp, sizeof(temp), "%d", achievement.points); @@ -155,7 +165,7 @@ void RenderAchievement(UIContext &dc, const Achievements::Achievement &achieveme 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.Draw()->DrawTexRect(Bounds(bounds.x + 4.0f, bounds.y + 4.0f, iconSpace, iconSpace), 0.0f, 0.0f, 1.0f, 1.0f, 0xFFFFFFFF); } dc.Flush(); @@ -174,14 +184,16 @@ void RenderGameAchievementSummary(UIContext &dc, int gameID, const Bounds &bound dc.Begin(); dc.FillRect(background, bounds); + dc.SetFontStyle(dc.theme->uiFont); + dc.SetFontScale(1.0f, 1.0f); - dc.DrawTextRect(Achievements::GetGameTitle().c_str(), bounds.Inset(iconSpace + 5.0f, 5.0f, 5.0f, 5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT); + dc.DrawTextRect(Achievements::GetGameTitle().c_str(), bounds.Inset(iconSpace + 5.0f, 2.0f, 5.0f, 5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT); std::string description = Achievements::GetGameAchievementSummary(); std::string icon = Achievements::GetGameIcon(); dc.SetFontScale(0.66f, 0.66f); - dc.DrawTextRect(description.c_str(), bounds.Inset(iconSpace + 5.0f, 30.0f, 5.0f, 5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT); + dc.DrawTextRect(description.c_str(), bounds.Inset(iconSpace + 5.0f, 38.0f, 5.0f, 5.0f), dc.theme->itemStyle.fgColor, ALIGN_TOPLEFT); dc.SetFontScale(1.0f, 1.0f); dc.Flush(); @@ -197,7 +209,7 @@ void RenderGameAchievementSummary(UIContext &dc, int gameID, const Bounds &bound void AchievementView::Draw(UIContext &dc) { - RenderAchievement(dc, achievement_, AchievementRenderStyle::LISTED, bounds_, 0.0f); + RenderAchievement(dc, achievement_, AchievementRenderStyle::LISTED, bounds_, 0.0f, 0.0f, 0.0f); } void AchievementView::GetContentDimensions(const UIContext &dc, float &w, float &h) const { diff --git a/UI/RetroAchievementScreens.h b/UI/RetroAchievementScreens.h index ddb94160e0..a8450bf378 100644 --- a/UI/RetroAchievementScreens.h +++ b/UI/RetroAchievementScreens.h @@ -8,14 +8,19 @@ #include "Common/File/Path.h" #include "UI/RetroAchievements.h" -class RetroAchievementsListScreen : public UIDialogScreenWithGameBackground { +// Lists the achievements and leaderboards for one game. +class RetroAchievementsListScreen : public TabbedUIDialogScreenWithGameBackground { public: - RetroAchievementsListScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) {} + RetroAchievementsListScreen(const Path &gamePath) : TabbedUIDialogScreenWithGameBackground(gamePath) {} const char *tag() const override { return "RetroAchievementsListScreen"; } - void CreateViews() override; + void CreateTabs() override; + +protected: + bool ShowSearchControls() const override { return false; } }; +// Lets you manage your account, and shows some achievement stats and stuff. class RetroAchievementsSettingsScreen : public TabbedUIDialogScreenWithGameBackground { public: RetroAchievementsSettingsScreen(const Path &gamePath) : TabbedUIDialogScreenWithGameBackground(gamePath) {} @@ -40,7 +45,7 @@ enum class AchievementRenderStyle { }; void MeasureAchievement(const UIContext &dc, const Achievements::Achievement &achievement, float *w, float *h); -void RenderAchievement(UIContext &dc, const Achievements::Achievement &achievement, AchievementRenderStyle style, const Bounds &bounds, float alpha); +void RenderAchievement(UIContext &dc, const Achievements::Achievement &achievement, AchievementRenderStyle style, const Bounds &bounds, float alpha, float startTime, float time_s); void MeasureGameAchievementSummary(const UIContext &dc, int gameID, float *w, float *h); void RenderGameAchievementSummary(UIContext &dc, int gameID, const Bounds &bounds, float alpha); diff --git a/UI/RetroAchievements.cpp b/UI/RetroAchievements.cpp index 74a3342c3d..9a93b98e0c 100644 --- a/UI/RetroAchievements.cpp +++ b/UI/RetroAchievements.cpp @@ -110,7 +110,7 @@ void OSDAddToast(float duration_s, const std::string &text) { } void OSDAddNotification(float duration_s, const std::string &title, const std::string &summary, const std::string &iconImageData) { - g_OSD.Show(OSDType::MESSAGE_INFO, title); + g_OSD.Show(OSDType::MESSAGE_INFO, title, summary, iconImageData, 5.0f); } void OSDAddAchievementUnlockedNotification(unsigned int achievementId) {