Skip to content

Commit

Permalink
make loading widget unique
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras committed Apr 3, 2024
1 parent 6f00cf4 commit 794ef1e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
10 changes: 3 additions & 7 deletions cheevos/cheevos.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ static rcheevos_locals_t rcheevos_locals =
#endif
#ifdef HAVE_RC_CLIENT
true, /* hardcore_allowed */
false,/* is_disconnected */
#else
#ifdef HAVE_GFX_WIDGETS
0, /* active_lboard_trackers */
Expand Down Expand Up @@ -618,7 +617,6 @@ static void rcheevos_server_error(const char* api_name, const char* message)
static void rcheevos_server_disconnected(void)
{
CHEEVOS_LOG(RCHEEVOS_TAG "Unable to communicate with RetroAchievements server\n");
rcheevos_locals.is_disconnected = true;

/* always show message - even with widget. it helps the user understand what the widget is for */
{
Expand All @@ -636,7 +634,6 @@ static void rcheevos_server_disconnected(void)
static void rcheevos_server_reconnected(void)
{
CHEEVOS_LOG(RCHEEVOS_TAG "All pending requests synced to RetroAchievements server\n");
rcheevos_locals.is_disconnected = false;

{
const char* message = msg_hash_to_str(MENU_ENUM_LABEL_CHEEVOS_SERVER_RECONNECTED);
Expand Down Expand Up @@ -1224,6 +1221,7 @@ bool rcheevos_unload(void)

#ifdef HAVE_GFX_WIDGETS
rcheevos_hide_widgets(gfx_widgets_ready());
gfx_widget_set_cheevos_set_loading(false);
#endif

#ifdef HAVE_RC_CLIENT
Expand Down Expand Up @@ -2445,9 +2443,7 @@ static void rcheevos_client_load_game_callback(int result,
char msg[256];

#if defined(HAVE_GFX_WIDGETS)
/* hide the loading widget if not in a disconnected state */
if (!rcheevos_locals.is_disconnected)
gfx_widget_set_cheevos_disconnect(false);
gfx_widget_set_cheevos_set_loading(false);
#endif

if (result != RC_OK || !game)
Expand Down Expand Up @@ -3267,7 +3263,7 @@ bool rcheevos_load(const void *data)
rc_hash_reset_cdreader_hooks();

#if defined(HAVE_GFX_WIDGETS)
gfx_widget_set_cheevos_disconnect(true);
gfx_widget_set_cheevos_set_loading(true);
#endif

rc_client_begin_identify_and_load_game(rcheevos_locals.client, RC_CONSOLE_UNKNOWN,
Expand Down
1 change: 1 addition & 0 deletions gfx/gfx_widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ void gfx_widgets_set_challenge_display(unsigned id, const char* badge);
void gfx_widgets_clear_challenge_displays(void);
void gfx_widget_set_achievement_progress(const char* badge, const char* progress);
void gfx_widget_set_cheevos_disconnect(bool visible);
void gfx_widget_set_cheevos_set_loading(bool visible);
#endif

/* TODO/FIXME/WARNING: Not thread safe! */
Expand Down
20 changes: 18 additions & 2 deletions gfx/widgets/gfx_widget_leaderboard_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct gfx_widget_leaderboard_display_state
unsigned challenge_count;
uint16_t char_width[CHEEVO_LBOARD_LAST_FIXED_CHAR - CHEEVO_LBOARD_FIRST_FIXED_CHAR + 1];
uint16_t fixed_char_width;
uint16_t loading;
bool disconnected;
};

Expand Down Expand Up @@ -115,6 +116,7 @@ static void gfx_widget_leaderboard_display_frame(void* data, void* userdata)
if (state->tracker_count == 0 &&
state->challenge_count == 0 &&
state->progress_tracker.show_until == 0 &&
!state->loading &&
!state->disconnected)
return;

Expand Down Expand Up @@ -342,9 +344,10 @@ static void gfx_widget_leaderboard_display_frame(void* data, void* userdata)
}
}

if (state->disconnected)
if (state->disconnected || state->loading)
{
const char* disconnected_text = "! RA !";
char loading_buffer[8] = "RA ...";
const char* disconnected_text = state->disconnected ? "! RA !" : loading_buffer;
const unsigned disconnect_widget_width = font_driver_get_message_width(
state->dispwidget_ptr->gfx_widget_fonts.msg_queue.font,
disconnected_text, 0, 1) + CHEEVO_LBOARD_DISPLAY_PADDING * 2;
Expand All @@ -353,6 +356,13 @@ static void gfx_widget_leaderboard_display_frame(void* data, void* userdata)
x = video_width - disconnect_widget_width - spacing;
y -= disconnect_widget_height + spacing;

if (state->loading) {
const uint16_t loading_shift = 5;
loading_buffer[((state->loading - 1) >> loading_shift) + 3] = '\0';
state->loading &= (1 << (loading_shift + 2)) - 1;
++state->loading;
}

/* Backdrop */
gfx_display_draw_quad(
p_disp,
Expand Down Expand Up @@ -586,6 +596,12 @@ void gfx_widget_set_cheevos_disconnect(bool value)
state->disconnected = value;
}

void gfx_widget_set_cheevos_set_loading(bool value)
{
gfx_widget_leaderboard_display_state_t* state = &p_w_leaderboard_display_st;
state->loading = value ? 1 : 0;
}


const gfx_widget_t gfx_widget_leaderboard_display = {
&gfx_widget_leaderboard_display_init,
Expand Down

0 comments on commit 794ef1e

Please sign in to comment.