Skip to content

Commit

Permalink
Login: Support desktop platforms other than Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jun 21, 2023
1 parent 0cedaca commit 60f2cea
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions Common/System/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ enum SystemProperty {
SYSPROP_HAS_BACK_BUTTON,
SYSPROP_HAS_KEYBOARD,
SYSPROP_HAS_OPEN_DIRECTORY,
SYSPROP_HAS_LOGIN_DIALOG,

SYSPROP_CAN_CREATE_SHORTCUT,

Expand Down
8 changes: 7 additions & 1 deletion Common/UI/PopupScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,13 @@ void AbstractChoiceWithValueDisplay::Draw(UIContext &dc) {
int paddingX = 12;
dc.SetFontStyle(dc.theme->uiFont);

const std::string valueText = ValueText();
std::string valueText = ValueText();

if (password_) {
for (size_t i = 0; i < valueText.size(); i++) {
valueText[i] = '*';
}
}

// If there is a label, assume we want at least 20% of the size for it, at a minimum.

Expand Down
6 changes: 6 additions & 0 deletions Common/UI/PopupScreens.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,16 @@ class AbstractChoiceWithValueDisplay : public UI::Choice {
void Draw(UIContext &dc) override;
void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override;

void SetPasswordDisplay() {
password_ = true;
}

protected:
virtual std::string ValueText() const = 0;

float CalculateValueScale(const UIContext &dc, const std::string &valueText, float availWidth) const;

bool password_ = false;
};

// Reads and writes value to determine the current selection.
Expand Down
6 changes: 3 additions & 3 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,13 @@ void GameSettingsScreen::CreateSystemSettings(UI::ViewGroup *systemSettings) {
auto vr = GetI18NCategory(I18NCat::VR);
auto th = GetI18NCategory(I18NCat::THEMES);

systemSettings->Add(new Choice(sy->T("Achievements")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
systemSettings->Add(new ItemHeader(sy->T("UI")));

systemSettings->Add(new Choice(sy->T("RetroAchievements")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
screenManager()->push(new RetroAchievementsSettingsScreen(gamePath_));
return UI::EVENT_DONE;
});

systemSettings->Add(new ItemHeader(sy->T("UI")));

auto langCodeToName = [](const char *value) -> std::string {
auto &mapping = g_Config.GetLangValuesMapping();
auto iter = mapping.find(value);
Expand Down
37 changes: 28 additions & 9 deletions UI/RetroAchievementScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void RetroAchievementsSettingsScreen::sendMessage(const char *message, const cha

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

using namespace UI;

Expand All @@ -78,25 +79,43 @@ void RetroAchievementsSettingsScreen::CreateAccountTab(UI::ViewGroup *viewGroup)
});
} else {
// TODO: Add UI for platforms that don't support System_AskUsernamePassword.
viewGroup->Add(new Choice(ac->T("Log in to RetroAchievements")))->OnClick.Add([=](UI::EventParams &) -> UI::EventReturn {
System_AskUsernamePassword(ac->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()) {
Achievements::LoginAsync(parts[0].c_str(), parts[1].c_str());
if (System_GetPropertyBool(SYSPROP_HAS_LOGIN_DIALOG)) {
viewGroup->Add(new Choice(ac->T("Log in to RetroAchievements")))->OnClick.Add([=](UI::EventParams &) -> UI::EventReturn {
System_AskUsernamePassword(ac->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()) {
Achievements::LoginAsync(parts[0].c_str(), parts[1].c_str());
}
});
return UI::EVENT_DONE;
});
} else {
// Hack up a temporary quick login-form-ish-thing
viewGroup->Add(new PopupTextInputChoice(&username_, "Username", "", 128, screenManager()));
viewGroup->Add(new PopupTextInputChoice(&password_, "Password", "", 128, screenManager()));
viewGroup->Add(new Choice(ac->T("Log in")))->OnClick.Add([=](UI::EventParams &) -> UI::EventReturn {
if (!username_.empty() && !password_.empty()) {
Achievements::LoginAsync(username_.c_str(), password_.c_str());
}
return UI::EVENT_DONE;
});
return UI::EVENT_DONE;
});
}
viewGroup->Add(new Choice(ac->T("Register on www.retroachievements.org")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://retroachievements.org/createaccount.php");
return UI::EVENT_DONE;
});
}
viewGroup->Add(new Choice(ac->T("About RetroAchievements")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {

viewGroup->Add(new ItemHeader(di->T("Links")));
viewGroup->Add(new Choice(ac->T("RetroAchievements website")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.retroachievements.org/");
return UI::EVENT_DONE;
});
viewGroup->Add(new Choice(ac->T("How to use RetroAchievements")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.ppsspp.org/docs/reference/retro-achievements");
return UI::EVENT_DONE;
});
}

void RetroAchievementsSettingsScreen::CreateSettingsTab(UI::ViewGroup *viewGroup) {
Expand Down
3 changes: 3 additions & 0 deletions UI/RetroAchievementScreens.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class RetroAchievementsSettingsScreen : public TabbedUIDialogScreenWithGameBackg
private:
void CreateAccountTab(UI::ViewGroup *viewGroup);
void CreateSettingsTab(UI::ViewGroup *viewGroup);

std::string username_;
std::string password_;
};

class UIContext;
Expand Down
2 changes: 2 additions & 0 deletions Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
return true;
case SYSPROP_HAS_BACK_BUTTON:
return true;
case SYSPROP_HAS_LOGIN_DIALOG:
return true;
case SYSPROP_APP_GOLD:
#ifdef GOLD
return true;
Expand Down

0 comments on commit 60f2cea

Please sign in to comment.