Skip to content

Commit

Permalink
Merge pull request #17827 from hrydgard/more-achievement-ui-work
Browse files Browse the repository at this point in the history
More achievement UI work - allow choosing screen positions for notifications
  • Loading branch information
hrydgard committed Aug 1, 2023
2 parents f4b345b + 9f11784 commit ff72d13
Show file tree
Hide file tree
Showing 58 changed files with 903 additions and 171 deletions.
11 changes: 11 additions & 0 deletions Common/System/OSD.cpp
Expand Up @@ -199,6 +199,15 @@ void OnScreenDisplay::ShowLeaderboardTracker(int leaderboardTrackerID, const cha
entries_.insert(entries_.begin(), entry);
}

void OnScreenDisplay::ShowLeaderboardStartEnd(const std::string &title, const std::string &description, bool started) {
g_OSD.Show(OSDType::LEADERBOARD_STARTED_FAILED, title, description, 3.0f);

}

void OnScreenDisplay::ShowLeaderboardSubmitted(const std::string &title, const std::string &value) {
g_OSD.Show(OSDType::MESSAGE_SUCCESS, title, value, 3.0f);
}

void OnScreenDisplay::ShowOnOff(const std::string &message, bool on, float duration_s) {
// TODO: translate "on" and "off"? Or just get rid of this whole thing?
Show(OSDType::MESSAGE_INFO, message + ": " + (on ? "on" : "off"), duration_s);
Expand Down Expand Up @@ -266,6 +275,8 @@ void OnScreenDisplay::ClearAchievementStuff() {
case OSDType::ACHIEVEMENT_UNLOCKED:
case OSDType::ACHIEVEMENT_PROGRESS:
case OSDType::LEADERBOARD_TRACKER:
case OSDType::LEADERBOARD_STARTED_FAILED:
case OSDType::LEADERBOARD_SUBMITTED:
iter.endTime = now;
break;
default:
Expand Down
4 changes: 4 additions & 0 deletions Common/System/OSD.h
Expand Up @@ -21,6 +21,8 @@ enum class OSDType {
ACHIEVEMENT_CHALLENGE_INDICATOR, // Achievement icon ONLY, no auto-hide

LEADERBOARD_TRACKER,
LEADERBOARD_STARTED_FAILED,
LEADERBOARD_SUBMITTED,

PROGRESS_BAR,

Expand Down Expand Up @@ -51,6 +53,8 @@ class OnScreenDisplay {
void ShowAchievementProgress(int achievementID, bool show); // call with show=false to hide. There can only be one of these. When hiding it's ok to not pass a valid achievementID.
void ShowChallengeIndicator(int achievementID, bool show); // call with show=false to hide.
void ShowLeaderboardTracker(int leaderboardTrackerID, const char *trackerText, bool show); // show=true is used both for create and update.
void ShowLeaderboardStartEnd(const std::string &title, const std::string &description, bool started); // started = true for started, false for ended.
void ShowLeaderboardSubmitted(const std::string &title, const std::string &value);

// Progress bar controls
// Set is both create and update. If you set maxValue <= minValue, you'll create an "indeterminate" progress
Expand Down
5 changes: 5 additions & 0 deletions Core/Config.cpp
Expand Up @@ -285,6 +285,11 @@ static const ConfigSetting achievementSettings[] = {
ConfigSetting("AchievementsLeaderboardSubmitAudioFile", &g_Config.sAchievementsLeaderboardSubmitAudioFile, "", CfgFlag::DEFAULT),

ConfigSetting("AchievementsLeaderboardTrackerPos", &g_Config.iAchievementsLeaderboardTrackerPos, (int)ScreenEdgePosition::TOP_LEFT, CfgFlag::DEFAULT),
ConfigSetting("AchievementsLeaderboardStartedOrFailedPos", &g_Config.iAchievementsLeaderboardStartedOrFailedPos, (int)ScreenEdgePosition::TOP_LEFT, CfgFlag::DEFAULT),
ConfigSetting("AchievementsLeaderboardSubmittedPos", &g_Config.iAchievementsLeaderboardSubmittedPos, (int)ScreenEdgePosition::TOP_LEFT, CfgFlag::DEFAULT),
ConfigSetting("AchievementsProgressPos", &g_Config.iAchievementsProgressPos, (int)ScreenEdgePosition::TOP_LEFT, CfgFlag::DEFAULT),
ConfigSetting("AchievementsChallengePos", &g_Config.iAchievementsChallengePos, (int)ScreenEdgePosition::TOP_LEFT, CfgFlag::DEFAULT),
ConfigSetting("AchievementsUnlockedPos", &g_Config.iAchievementsUnlockedPos, (int)ScreenEdgePosition::TOP_CENTER, CfgFlag::DEFAULT),
};

static const ConfigSetting cpuSettings[] = {
Expand Down
5 changes: 5 additions & 0 deletions Core/Config.h
Expand Up @@ -488,6 +488,11 @@ struct Config {

// Positioning of the various notifications
int iAchievementsLeaderboardTrackerPos;
int iAchievementsLeaderboardStartedOrFailedPos;
int iAchievementsLeaderboardSubmittedPos;
int iAchievementsProgressPos;
int iAchievementsChallengePos;
int iAchievementsUnlockedPos;

// Customizations
std::string sAchievementsUnlockAudioFile;
Expand Down
4 changes: 2 additions & 2 deletions Core/KeyMap.cpp
Expand Up @@ -400,8 +400,8 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_REWIND, "Rewind"},
{VIRTKEY_SAVE_STATE, "Save State"},
{VIRTKEY_LOAD_STATE, "Load State"},
{VIRTKEY_PREVIOUS_SLOT, "Previous Slot"},
{VIRTKEY_NEXT_SLOT, "Next Slot"},
{VIRTKEY_PREVIOUS_SLOT, "Previous Slot"},
{VIRTKEY_NEXT_SLOT, "Next Slot"},
#if !defined(MOBILE_DEVICE)
{VIRTKEY_TOGGLE_FULLSCREEN, "Toggle Fullscreen"},
#endif
Expand Down
35 changes: 25 additions & 10 deletions Core/RetroAchievements.cpp
Expand Up @@ -244,22 +244,37 @@ static void event_handler_callback(const rc_client_event_t *event, rc_client_t *
break;
}
case RC_CLIENT_EVENT_LEADERBOARD_STARTED:
// A leaderboard attempt has started. The handler may show a message with the leaderboard title and /or description indicating the attempt started.
INFO_LOG(ACHIEVEMENTS, "Leaderboard attempt started: %s", event->leaderboard->title);
g_OSD.Show(OSDType::MESSAGE_INFO, ApplySafeSubstitutions(ac->T("%1: Leaderboard attempt started"), event->leaderboard->title), DeNull(event->leaderboard->description), 3.0f);
break;
case RC_CLIENT_EVENT_LEADERBOARD_FAILED:
INFO_LOG(ACHIEVEMENTS, "Leaderboard attempt failed: %s", event->leaderboard->title);
g_OSD.Show(OSDType::MESSAGE_INFO, ApplySafeSubstitutions(ac->T("%1: Leaderboard attempt failed"), event->leaderboard->title), 3.0f);
// A leaderboard attempt has failed.
{
bool started = event->type == RC_CLIENT_EVENT_LEADERBOARD_STARTED;
// A leaderboard attempt has started. The handler may show a message with the leaderboard title and /or description indicating the attempt started.
const char *title = "";
const char *description = "";
// Hack around some problematic events in Burnout Legends. Hopefully this can be fixed in the backend.
if (strlen(event->leaderboard->title) > 0) {
title = event->leaderboard->title;
description = event->leaderboard->description;
} else {
title = event->leaderboard->description;
}
INFO_LOG(ACHIEVEMENTS, "Attempt %s: %s", started ? "started" : "failed", title);
g_OSD.ShowLeaderboardStartEnd(ApplySafeSubstitutions(ac->T(started ? "%1: Attempt started" : "%1: Attempt failed"), title), description, started);
break;
}
case RC_CLIENT_EVENT_LEADERBOARD_SUBMITTED:
{
INFO_LOG(ACHIEVEMENTS, "Leaderboard result submitted: %s", event->leaderboard->title);
g_OSD.Show(OSDType::MESSAGE_SUCCESS,
ApplySafeSubstitutions(ac->T("Submitted %1 for %2"), DeNull(event->leaderboard->tracker_value), DeNull(event->leaderboard->title)),
DeNull(event->leaderboard->description), 3.0f);
const char *title = "";
// Hack around some problematic events in Burnout Legends. Hopefully this can be fixed in the backend.
if (strlen(event->leaderboard->title) > 0) {
title = event->leaderboard->title;
} else {
title = event->leaderboard->description;
}
g_OSD.ShowLeaderboardSubmitted(ApplySafeSubstitutions(ac->T("Submitted %1 for %2"), DeNull(event->leaderboard->tracker_value), title), "");
System_PostUIMessage("play_sound", "leaderboard_submitted");
break;
}
case RC_CLIENT_EVENT_ACHIEVEMENT_CHALLENGE_INDICATOR_SHOW:
INFO_LOG(ACHIEVEMENTS, "Challenge indicator show: %s", event->achievement->title);
g_OSD.ShowChallengeIndicator(event->achievement->id, true);
Expand Down
21 changes: 16 additions & 5 deletions Tools/langtool/src/main.rs
Expand Up @@ -17,7 +17,10 @@ struct Opt {

#[derive(StructOpt, Debug)]
enum Command {
CopyMissingLines {},
CopyMissingLines {
#[structopt(short, long)]
dont_comment_missing: bool,
},
CommentUnknownLines {},
RemoveUnknownLines {},
AddNewKey {
Expand All @@ -43,7 +46,11 @@ enum Command {
},
}

fn copy_missing_lines(reference_ini: &IniFile, target_ini: &mut IniFile) -> io::Result<()> {
fn copy_missing_lines(
reference_ini: &IniFile,
target_ini: &mut IniFile,
comment_missing: bool,
) -> io::Result<()> {
for reference_section in &reference_ini.sections {
// Insert any missing full sections.
if !target_ini.insert_section_if_missing(reference_section) {
Expand All @@ -53,7 +60,9 @@ fn copy_missing_lines(reference_ini: &IniFile, target_ini: &mut IniFile) -> io::
}

//target_section.remove_lines_if_not_in(reference_section);
target_section.comment_out_lines_if_not_in(reference_section);
if comment_missing {
target_section.comment_out_lines_if_not_in(reference_section);
}
}
} else {
// Note: insert_section_if_missing will copy the entire section,
Expand Down Expand Up @@ -177,8 +186,10 @@ fn main() {
let mut target_ini = IniFile::parse(&target_ini_filename).unwrap();

match opt.cmd {
Command::CopyMissingLines {} => {
copy_missing_lines(reference_ini, &mut target_ini).unwrap();
Command::CopyMissingLines {
dont_comment_missing,
} => {
copy_missing_lines(reference_ini, &mut target_ini, !dont_comment_missing).unwrap();
}
Command::CommentUnknownLines {} => {
deal_with_unknown_lines(reference_ini, &mut target_ini, false).unwrap();
Expand Down
10 changes: 6 additions & 4 deletions UI/OnScreenDisplay.cpp
Expand Up @@ -268,10 +268,12 @@ void OnScreenMessagesView::Draw(UIContext &dc) {
typeEdges[i] = ScreenEdgePosition::TOP_CENTER;
}

// TODO: Add ability to override these with g_Config settings.
typeEdges[(size_t)OSDType::ACHIEVEMENT_CHALLENGE_INDICATOR] = ScreenEdgePosition::TOP_LEFT;
typeEdges[(size_t)OSDType::ACHIEVEMENT_PROGRESS] = ScreenEdgePosition::TOP_LEFT;
typeEdges[(size_t)OSDType::ACHIEVEMENT_CHALLENGE_INDICATOR] = (ScreenEdgePosition)g_Config.iAchievementsChallengePos;
typeEdges[(size_t)OSDType::ACHIEVEMENT_PROGRESS] = (ScreenEdgePosition)g_Config.iAchievementsProgressPos;
typeEdges[(size_t)OSDType::LEADERBOARD_TRACKER] = (ScreenEdgePosition)g_Config.iAchievementsLeaderboardTrackerPos;
typeEdges[(size_t)OSDType::LEADERBOARD_STARTED_FAILED] = (ScreenEdgePosition)g_Config.iAchievementsLeaderboardStartedOrFailedPos;
typeEdges[(size_t)OSDType::LEADERBOARD_SUBMITTED] = (ScreenEdgePosition)g_Config.iAchievementsLeaderboardSubmittedPos;
typeEdges[(size_t)OSDType::ACHIEVEMENT_UNLOCKED] = (ScreenEdgePosition)g_Config.iAchievementsUnlockedPos;

dc.SetFontScale(1.0f, 1.0f);

Expand All @@ -281,7 +283,7 @@ void OnScreenMessagesView::Draw(UIContext &dc) {
auto &measuredEntry = measuredEntries[i];

ScreenEdgePosition pos = typeEdges[(size_t)entry.type];
if (pos == ScreenEdgePosition::VALUE_COUNT) {
if (pos == ScreenEdgePosition::VALUE_COUNT || pos == (ScreenEdgePosition)-1) {
// NONE.
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion UI/PauseScreen.cpp
Expand Up @@ -380,7 +380,7 @@ void GamePauseScreen::CreateViews() {
});
}
if (g_Config.bAchievementsEnable && Achievements::HasAchievementsOrLeaderboards()) {
rightColumnItems->Add(new Choice(pa->T("Achievements")))->OnClick.Add([&](UI::EventParams &e) {
rightColumnItems->Add(new Choice(ac->T("Achievements")))->OnClick.Add([&](UI::EventParams &e) {
screenManager()->push(new RetroAchievementsListScreen(gamePath_));
return UI::EVENT_DONE;
});
Expand Down
16 changes: 11 additions & 5 deletions UI/RetroAchievementScreens.cpp
Expand Up @@ -283,7 +283,7 @@ void RetroAchievementsSettingsScreen::CreateAccountTab(UI::ViewGroup *viewGroup)
if (strcmp(info->display_name, info->username) != 0) {
viewGroup->Add(new InfoItem(ac->T("Name"), info->display_name));
}
viewGroup->Add(new InfoItem(ac->T("Username"), info->username));
viewGroup->Add(new InfoItem(di->T("Username"), info->username));
// viewGroup->Add(new InfoItem(ac->T("Unread messages"), info.numUnreadMessages));
viewGroup->Add(new Choice(di->T("Log out")))->OnClick.Add([=](UI::EventParams &) -> UI::EventReturn {
Achievements::Logout();
Expand All @@ -304,8 +304,8 @@ void RetroAchievementsSettingsScreen::CreateAccountTab(UI::ViewGroup *viewGroup)
return UI::EVENT_DONE;
});
} else if (System_GetPropertyBool(SYSPROP_HAS_LOGIN_DIALOG)) {
viewGroup->Add(new Choice(ac->T("Log in")))->OnClick.Add([=](UI::EventParams &) -> UI::EventReturn {
System_AskUsernamePassword(ac->T("Log in"), [](const std::string &value, int) {
viewGroup->Add(new Choice(di->T("Log in")))->OnClick.Add([=](UI::EventParams &) -> UI::EventReturn {
System_AskUsernamePassword(di->T("Log in"), [](const std::string &value, int) {
std::vector<std::string> parts;
SplitString(value, '\n', parts);
if (parts.size() == 2 && !parts[0].empty() && !parts[1].empty()) {
Expand Down Expand Up @@ -363,21 +363,27 @@ void RetroAchievementsSettingsScreen::CreateCustomizeTab(UI::ViewGroup *viewGrou
auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS);

using namespace UI;
viewGroup->Add(new ItemHeader(ac->T("Sound effects")));
viewGroup->Add(new ItemHeader(ac->T("Sound Effects")));
viewGroup->Add(new AudioFileChooser(&g_Config.sAchievementsUnlockAudioFile, ac->T("Achievement unlocked"), UISound::ACHIEVEMENT_UNLOCKED));
viewGroup->Add(new AudioFileChooser(&g_Config.sAchievementsLeaderboardSubmitAudioFile, ac->T("Leaderboard score submission"), UISound::LEADERBOARD_SUBMITTED));

static const char *positions[] = { "Bottom Left", "Bottom Center", "Bottom Right", "Top Left", "Top Center", "Top Right", "Center Left", "Center Right", "None" };

viewGroup->Add(new ItemHeader(ac->T("Notifications")));
viewGroup->Add(new PopupMultiChoice(&g_Config.iAchievementsLeaderboardStartedOrFailedPos, ac->T("Leaderboard attempt started or failed"), positions, 0, ARRAY_SIZE(positions), I18NCat::DIALOG, screenManager()))->SetEnabledPtr(&g_Config.bAchievementsEnable);
viewGroup->Add(new PopupMultiChoice(&g_Config.iAchievementsLeaderboardSubmittedPos, ac->T("Leaderboard result submitted"), positions, 0, ARRAY_SIZE(positions), I18NCat::DIALOG, screenManager()))->SetEnabledPtr(&g_Config.bAchievementsEnable);
viewGroup->Add(new PopupMultiChoice(&g_Config.iAchievementsLeaderboardTrackerPos, ac->T("Leaderboard tracker"), positions, 0, ARRAY_SIZE(positions), I18NCat::DIALOG, screenManager()))->SetEnabledPtr(&g_Config.bAchievementsEnable);
viewGroup->Add(new PopupMultiChoice(&g_Config.iAchievementsUnlockedPos, ac->T("Achievement unlocked"), positions, 0, ARRAY_SIZE(positions), I18NCat::DIALOG, screenManager()))->SetEnabledPtr(&g_Config.bAchievementsEnable);
viewGroup->Add(new PopupMultiChoice(&g_Config.iAchievementsChallengePos, ac->T("Challenge indicator"), positions, 0, ARRAY_SIZE(positions), I18NCat::DIALOG, screenManager()))->SetEnabledPtr(&g_Config.bAchievementsEnable);
viewGroup->Add(new PopupMultiChoice(&g_Config.iAchievementsProgressPos, ac->T("Achievement progress"), positions, 0, ARRAY_SIZE(positions), I18NCat::DIALOG, screenManager()))->SetEnabledPtr(&g_Config.bAchievementsEnable);
}

void RetroAchievementsSettingsScreen::CreateDeveloperToolsTab(UI::ViewGroup *viewGroup) {
auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS);
auto di = GetI18NCategory(I18NCat::DIALOG);

using namespace UI;
viewGroup->Add(new ItemHeader(ac->T("Settings")));
viewGroup->Add(new ItemHeader(di->T("Settings")));
viewGroup->Add(new CheckBox(&g_Config.bAchievementsUnofficial, ac->T("Unofficial achievements")))->SetEnabledPtr(&g_Config.bAchievementsEnable);
viewGroup->Add(new CheckBox(&g_Config.bAchievementsLogBadMemReads, ac->T("Log bad memory accesses")))->SetEnabledPtr(&g_Config.bAchievementsEnable);
}
Expand Down
4 changes: 2 additions & 2 deletions UWP/UWP.vcxproj
Expand Up @@ -847,7 +847,7 @@
<None Include="Content\shaders\defaultshaders.ini">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="Content\shaders\fakereclections.fsh">
<None Include="Content\shaders\fakereflections.fsh">
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="Content\shaders\fxaa.fsh">
Expand Down Expand Up @@ -968,4 +968,4 @@
<Import Project="$(VSINSTALLDIR)\Common7\IDE\Extensions\Microsoft\VsGraphics\MeshContentTask.targets" />
<Import Project="$(VSINSTALLDIR)\Common7\IDE\Extensions\Microsoft\VsGraphics\ShaderGraphContentTask.targets" />
</ImportGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions UWP/UWP.vcxproj.filters
Expand Up @@ -313,7 +313,7 @@
<None Include="Content\shaders\defaultshaders.ini">
<Filter>Content\shaders</Filter>
</None>
<None Include="Content\shaders\fakereclections.fsh">
<None Include="Content\shaders\fakereflections.fsh">
<Filter>Content\shaders</Filter>
</None>
<None Include="Content\shaders\fxaa.fsh">
Expand Down Expand Up @@ -563,4 +563,4 @@
<Filter>Content</Filter>
</Font>
</ItemGroup>
</Project>
</Project>

0 comments on commit ff72d13

Please sign in to comment.