Merge pull request #17731 from hrydgard/more-ui-fixes

More achievement UI fixes
This commit is contained in:
Henrik Rydgård 2023-07-16 23:27:08 +02:00 committed by GitHub
commit 0f2a024420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 21 deletions

View File

@ -134,13 +134,25 @@ void TextDrawerWin32::MeasureString(const char *str, size_t len, float *w, float
SelectObject(ctx_->hDC, iter->second->hFont);
}
SIZE size;
std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(ReplaceAll(std::string(str, len), "\n", "\r\n"), "&&", "&"));
GetTextExtentPoint32(ctx_->hDC, wstr.c_str(), (int)wstr.size(), &size);
std::string toMeasure = ReplaceAll(std::string(str, len), "&&", "&");
std::vector<std::string> lines;
SplitString(toMeasure, '\n', lines);
int extW = 0, extH = 0;
for (auto &line : lines) {
SIZE size;
std::wstring wstr = ConvertUTF8ToWString(line);
GetTextExtentPoint32(ctx_->hDC, wstr.c_str(), (int)wstr.size(), &size);
if (size.cx > extW)
extW = size.cx;
extH += size.cy;
}
entry = new TextMeasureEntry();
entry->width = size.cx;
entry->height = size.cy;
entry->width = extW;
entry->height = extH;
sizeCache_[key] = std::unique_ptr<TextMeasureEntry>(entry);
}

View File

@ -51,6 +51,8 @@ enum class UISound {
void SetSoundEnabled(bool enabled);
void SetSoundCallback(std::function<void(UISound, float)> func);
// This is only meant for actual UI navigation sound, not achievements.
// Call directly into the player for other UI effects.
void PlayUISound(UISound sound, float volume = 0.25f);
} // namespace UI

View File

@ -546,10 +546,10 @@ void EmuScreen::sendMessage(const char *message, const char *value) {
if (g_Config.bAchievementsSoundEffects) {
// TODO: Handle this some nicer way.
if (!strcmp(value, "achievement_unlocked")) {
UI::PlayUISound(UI::UISound::ACHIEVEMENT_UNLOCKED, 0.6f);
g_BackgroundAudio.SFX().Play(UI::UISound::ACHIEVEMENT_UNLOCKED, 0.6f);
}
if (!strcmp(value, "leaderboard_submitted")) {
UI::PlayUISound(UI::UISound::LEADERBOARD_SUBMITTED, 0.6f);
g_BackgroundAudio.SFX().Play(UI::UISound::LEADERBOARD_SUBMITTED, 0.6f);
}
}
}

View File

@ -148,7 +148,7 @@ static void RenderOSDEntry(UIContext &dc, const OnScreenDisplay::Entry &entry, B
if (entry.type == OSDType::ACHIEVEMENT_UNLOCKED) {
const rc_client_achievement_t * achievement = rc_client_get_achievement_info(Achievements::GetClient(), entry.numericID);
if (achievement) {
RenderAchievement(dc, achievement, AchievementRenderStyle::UNLOCKED, bounds, alpha, entry.startTime, time_now_d());
RenderAchievement(dc, achievement, AchievementRenderStyle::UNLOCKED, bounds, alpha, entry.startTime, time_now_d(), false);
}
return;
} else {
@ -278,7 +278,7 @@ void OnScreenMessagesView::Draw(UIContext &dc) {
case OSDType::ACHIEVEMENT_PROGRESS:
case OSDType::ACHIEVEMENT_CHALLENGE_INDICATOR:
{
RenderAchievement(dc, achievement, style, b, alpha * sidebarAlpha, entry.startTime, now);
RenderAchievement(dc, achievement, style, b, alpha * sidebarAlpha, entry.startTime, now, false);
break;
}
case OSDType::LEADERBOARD_TRACKER:

View File

@ -116,6 +116,10 @@ void RetroAchievementsListScreen::CreateAchievementsTab(UI::ViewGroup *achieveme
achievements->Add(new GameAchievementSummaryView());
if (Achievements::EncoreModeActive()) {
achievements->Add(new NoticeView(NoticeLevel::WARN, ac->T("In Encore mode - unlock state may not be accurate"), ""));
}
CollapsibleSection *unlocked = new CollapsibleSection(StringFromFormat("%s (%d)", ac->T("Unlocked achievements"), (int)unlockedAchievements.size()));
unlocked->SetSpacing(2.0f);
for (auto &achievement : unlockedAchievements) {
@ -386,7 +390,7 @@ void MeasureGameAchievementSummary(const UIContext &dc, float *w, float *h) {
dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, "Wg", &tw, &th);
dc.MeasureText(dc.theme->uiFont, 0.66f, 0.66f, description.c_str(), w, h);
*h += 12.0f + th;
*h += 8.0f + th;
*w += 8.0f;
}
@ -401,16 +405,20 @@ void MeasureLeaderboardEntry(const UIContext &dc, const rc_client_leaderboard_en
}
// Graphical
void RenderAchievement(UIContext &dc, const rc_client_achievement_t *achievement, AchievementRenderStyle style, const Bounds &bounds, float alpha, float startTime, float time_s) {
void RenderAchievement(UIContext &dc, const rc_client_achievement_t *achievement, AchievementRenderStyle style, const Bounds &bounds, float alpha, float startTime, float time_s, bool hasFocus) {
using namespace UI;
UI::Drawable background = UI::Drawable(dc.theme->backgroundColor);
if (hasFocus) {
background = dc.theme->itemFocusedStyle.background;
}
// Set some alpha, if displayed in list.
if (style == AchievementRenderStyle::LISTED) {
background.color = colorAlpha(background.color, 0.6f);
}
if (!achievement->unlocked) {
if (!achievement->unlocked && !hasFocus) {
// Make the background color gray.
// TODO: Different colors in challenge mode, or even in the "re-take achievements" mode when we add that?
background.color = (background.color & 0xFF000000) | 0x706060;
@ -544,11 +552,15 @@ void RenderGameAchievementSummary(UIContext &dc, const Bounds &bounds, float alp
dc.RebindTexture();
}
void RenderLeaderboardSummary(UIContext &dc, const rc_client_leaderboard_t *leaderboard, AchievementRenderStyle style, const Bounds &bounds, float alpha, float startTime, float time_s) {
void RenderLeaderboardSummary(UIContext &dc, const rc_client_leaderboard_t *leaderboard, AchievementRenderStyle style, const Bounds &bounds, float alpha, float startTime, float time_s, bool hasFocus) {
using namespace UI;
UI::Drawable background = UI::Drawable(dc.theme->backgroundColor);
background.color = colorAlpha(background.color, alpha);
uint32_t fgColor = colorAlpha(dc.theme->itemStyle.fgColor, alpha);
UI::Drawable background = dc.theme->itemStyle.background;
if (hasFocus) {
background = dc.theme->itemFocusedStyle.background;
}
background.color = alphaMul(background.color, alpha);
uint32_t fgColor = alphaMul(dc.theme->itemStyle.fgColor, alpha);
if (style == AchievementRenderStyle::UNLOCKED) {
float mixWhite = pow(Clamp((float)(1.0f - (time_s - startTime)), 0.0f, 1.0f), 3.0f);
@ -583,9 +595,12 @@ void RenderLeaderboardSummary(UIContext &dc, const rc_client_leaderboard_t *lead
dc.RebindTexture();
}
void RenderLeaderboardEntry(UIContext &dc, const rc_client_leaderboard_entry_t *entry, const Bounds &bounds, float alpha) {
void RenderLeaderboardEntry(UIContext &dc, const rc_client_leaderboard_entry_t *entry, const Bounds &bounds, float alpha, bool hasFocus) {
using namespace UI;
UI::Drawable background = dc.theme->itemStyle.background;
if (hasFocus) {
background = dc.theme->itemFocusedStyle.background;
}
background.color = alphaMul(background.color, alpha);
uint32_t fgColor = alphaMul(dc.theme->itemStyle.fgColor, alpha);
@ -635,7 +650,7 @@ void RenderLeaderboardEntry(UIContext &dc, const rc_client_leaderboard_entry_t *
}
void AchievementView::Draw(UIContext &dc) {
RenderAchievement(dc, achievement_, AchievementRenderStyle::LISTED, bounds_, 1.0f, 0.0f, 0.0f);
RenderAchievement(dc, achievement_, AchievementRenderStyle::LISTED, bounds_, 1.0f, 0.0f, 0.0f, HasFocus());
}
void AchievementView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
@ -668,7 +683,7 @@ void GameAchievementSummaryView::GetContentDimensions(const UIContext &dc, float
}
void LeaderboardSummaryView::Draw(UIContext &dc) {
RenderLeaderboardSummary(dc, leaderboard_, AchievementRenderStyle::LISTED, bounds_, 1.0f, 0.0f, 0.0f);
RenderLeaderboardSummary(dc, leaderboard_, AchievementRenderStyle::LISTED, bounds_, 1.0f, 0.0f, 0.0f, HasFocus());
}
void LeaderboardSummaryView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
@ -676,7 +691,7 @@ void LeaderboardSummaryView::GetContentDimensions(const UIContext &dc, float &w,
}
void LeaderboardEntryView::Draw(UIContext &dc) {
RenderLeaderboardEntry(dc, entry_, bounds_, 1.0f);
RenderLeaderboardEntry(dc, entry_, bounds_, 1.0f, HasFocus());
}
void LeaderboardEntryView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {

View File

@ -86,7 +86,7 @@ enum class AchievementRenderStyle {
};
void MeasureAchievement(const UIContext &dc, const rc_client_achievement_t *achievement, AchievementRenderStyle style, float *w, float *h);
void RenderAchievement(UIContext &dc, const rc_client_achievement_t *achievement, AchievementRenderStyle style, const Bounds &bounds, float alpha, float startTime, float time_s);
void RenderAchievement(UIContext &dc, const rc_client_achievement_t *achievement, AchievementRenderStyle style, const Bounds &bounds, float alpha, float startTime, float time_s, bool hasFocus);
void MeasureGameAchievementSummary(const UIContext &dc, float *w, float *h);
void RenderGameAchievementSummary(UIContext &dc, const Bounds &bounds, float alpha);

View File

@ -36,6 +36,7 @@ Customize = Customize
Earned = You have earned %d of %d achievements, and %d of %d points
Encore Mode = Encore Mode
How to use RetroAchievements = How to use RetroAchievements
In Encore mode - listings may be wrong below = In Encore mode - listings may be wrong below
Leaderboard score submission = Leaderboard score submission
Leaderboard submission is enabled = Leaderboard submission is enabled
Leaderboards = Leaderboards

View File

@ -12,6 +12,7 @@ Customize = Inställningar
Earned = Du har tjänat %d av %d achievements, och %d of %d poäng
Encore Mode = Encore-läge (kan ta achievements igen)
How to use RetroAchievements = Hur man använder RetroAchievements
In Encore mode - listings may be wrong below = I Encore-läge - saker kan visas fel nedan
Leaderboard score submission = Leaderboard score submission
Leaderboard submission is enabled = Skickar in poäng till ledartabeller
Leaderboards = Topplistor