RetroAchievements: Better handling of not being online when trying to log in

This commit is contained in:
Henrik Rydgård 2023-07-13 11:24:37 +02:00
parent c6d33957af
commit aa4264a192
7 changed files with 28 additions and 26 deletions

View File

@ -56,7 +56,7 @@ void OnScreenDisplay::Show(OSDType type, const std::string &text, const std::str
switch (type) {
case OSDType::MESSAGE_ERROR:
case OSDType::MESSAGE_WARNING:
duration_s = 3.0f;
duration_s = 4.0f;
break;
case OSDType::MESSAGE_FILE_LINK:
duration_s = 5.0f;

View File

@ -57,21 +57,6 @@ static inline const char *DeNull(const char *ptr) {
return ptr ? ptr : "";
}
void OSDOpenBackgroundProgressDialog(const char *str_id, std::string message, s32 min, s32 max, s32 value) {
NOTICE_LOG(ACHIEVEMENTS, "Progress dialog opened: %s %s", str_id, message.c_str());
g_OSD.SetProgressBar(str_id, std::move(message), min, max, value);
}
void OSDUpdateBackgroundProgressDialog(const char *str_id, std::string message, s32 min, s32 max, s32 value) {
NOTICE_LOG(ACHIEVEMENTS, "Progress dialog updated: %s %s %d/(%d->%d)", str_id, message.c_str(), value, min, max);
g_OSD.SetProgressBar(str_id, std::move(message), min, max, value);
}
void OSDCloseBackgroundProgressDialog(const char *str_id) {
NOTICE_LOG(ACHIEVEMENTS, "Progress dialog closed: %s", str_id);
g_OSD.RemoveProgressBar(str_id);
}
void OnAchievementsLoginStateChange() {
System_PostUIMessage("achievements_loginstatechange", "");
}
@ -233,9 +218,8 @@ static void server_call_callback(const rc_api_request_t *request,
}
}
// Write log messages to the console
static void log_message_callback(const char *message, const rc_client_t *client) {
INFO_LOG(ACHIEVEMENTS, "RetroAchievements log: %s", message);
INFO_LOG(ACHIEVEMENTS, "RetroAchievements: %s", message);
}
static void login_token_callback(int result, const char *error_message, rc_client_t *client, void *userdata) {
@ -243,10 +227,17 @@ static void login_token_callback(int result, const char *error_message, rc_clien
case RC_OK:
OnAchievementsLoginStateChange();
break;
case RC_NO_RESPONSE:
{
auto di = GetI18NCategory(I18NCat::DIALOG);
g_OSD.Show(OSDType::MESSAGE_WARNING, di->T("Failed to connect to server, check your internet connection."));
break;
}
case RC_INVALID_STATE:
case RC_API_FAILURE:
case RC_MISSING_VALUE:
case RC_INVALID_JSON:
default:
ERROR_LOG(ACHIEVEMENTS, "Failure logging in via token: %d, %s", result, error_message);
OnAchievementsLoginStateChange();
break;
@ -400,10 +391,17 @@ static void login_password_callback(int result, const char *error_message, rc_cl
g_OSD.Show(OSDType::MESSAGE_SUCCESS, di->T("Logged in!"));
break;
}
case RC_NO_RESPONSE:
{
auto di = GetI18NCategory(I18NCat::DIALOG);
g_OSD.Show(OSDType::MESSAGE_WARNING, di->T("Failed to connect to server, check your internet connection."));
break;
}
case RC_INVALID_STATE:
case RC_API_FAILURE:
case RC_MISSING_VALUE:
case RC_INVALID_JSON:
default:
{
ERROR_LOG(ACHIEVEMENTS, "Failure logging in via password: %d, %s", result, error_message);
g_OSD.Show(OSDType::MESSAGE_WARNING, di->T("Failed to log in, check your username and password."));
@ -412,14 +410,16 @@ static void login_password_callback(int result, const char *error_message, rc_cl
}
}
OSDCloseBackgroundProgressDialog("cheevos_async_login");
g_OSD.RemoveProgressBar("cheevos_async_login");
}
bool LoginAsync(const char *username, const char *password) {
auto di = GetI18NCategory(I18NCat::DIALOG);
if (IsLoggedIn() || std::strlen(username) == 0 || std::strlen(password) == 0 || IsUsingRAIntegration())
return false;
OSDOpenBackgroundProgressDialog("cheevos_async_login", "Logging in to RetroAchivements...", 0, 0, 0);
g_OSD.SetProgressBar("cheevos_async_login", di->T("Logging in..."), 0, 0, 0);
rc_client_begin_login_with_password(g_rcClient, username, password, &login_password_callback, nullptr);
return true;
}

View File

@ -853,10 +853,12 @@ void GameSettingsScreen::CreateSystemSettings(UI::ViewGroup *systemSettings) {
systemSettings->Add(new ItemHeader(sy->T("UI")));
systemSettings->Add(new Choice(sy->T("RetroAchievements")))->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
auto retro = systemSettings->Add(new Choice(sy->T("RetroAchievements")));
retro->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn {
screenManager()->push(new RetroAchievementsSettingsScreen(gamePath_));
return UI::EVENT_DONE;
});
retro->SetIcon(ImageID("I_RETROACHIEVEMENTS_LOGO"));
auto langCodeToName = [](const char *value) -> std::string {
auto &mapping = g_Config.GetLangValuesMapping();

View File

@ -38,10 +38,10 @@ static uint32_t GetNoticeBackgroundColor(NoticeLevel type) {
static ImageID GetOSDIcon(NoticeLevel level) {
switch (level) {
case NoticeLevel::INFO: return ImageID::invalid(); // return ImageID("I_INFO");
case NoticeLevel::INFO: return ImageID("I_INFO");
case NoticeLevel::ERROR: return ImageID("I_CROSS");
case NoticeLevel::WARN: return ImageID("I_WARNING");
case NoticeLevel::SUCCESS: return ImageID("I_CHECKEDBOX");
case NoticeLevel::SUCCESS: return ImageID("I_CHECKMARK");
default: return ImageID::invalid();
}
}

View File

@ -52,7 +52,6 @@ Sound Effects = Sound Effects
Statistics = Statistics
Syncing achievements data... = Syncing achievements data...
Test Mode = Test Mode
This game has no achievements = This game has no achievements
Unlocked achievements = Unlocked achievements
Unofficial achievements = Unofficial achievements
@ -361,6 +360,7 @@ Enable All = Enable all
Enabled = Enabled
Enter = Enter
Failed to log in, check your username and password. = Failed to log in, check your username and password.
Failed to connect to server, check your internet connection. = Failed to connect to server, check your internet connection.
Filter = Filter
Finish = Finish
GE Frame Dumps = GE Frame Dumps
@ -373,6 +373,7 @@ Loading = Loading\nPlease Wait...
LoadingFailed = Unable to load data.
Log in = Log in
Log out = Log out
Logging in... = Logging in...
Logged in! = Logged in!
Move = Move
Move Up = Move Up

View File

@ -25,7 +25,6 @@ Sound Effects = Ljudeffekter
Statistics = Statistik
Syncing achievements data... = Synkar achievementdata...
Test Mode = Test-läge
This game has no achievements = Detta spel har inga achievements
Unlocked achievements = Upplåsta achievements
Unofficial achievements = Inofficiella achievements

View File

@ -294,7 +294,7 @@ struct Bucket {
printf("PACKING FAIL : height=%i", (int)dest.dat.size());
exit(1);
}
dest.resize(image_width, NextPowerOf2((int)dest.dat.size()));
dest.resize(image_width, (int)dest.dat.size());
// Output the glyph data.
vector<Data> dats;