ui/stats: fix assault course dialog

This commit is contained in:
Marcin Kurczewski 2025-04-20 17:14:27 +02:00
parent f29e30ffe2
commit 747f0af086
2 changed files with 32 additions and 27 deletions

View file

@ -1,9 +1,19 @@
#include "game/ui/dialogs/stats.h" #include "game/ui/dialogs/stats.h"
#include "game/gym.h"
void UI_StatsDialog_Init( void UI_StatsDialog_Init(
UI_STATS_DIALOG_STATE *const s, const UI_STATS_DIALOG_ARGS args) UI_STATS_DIALOG_STATE *const s, const UI_STATS_DIALOG_ARGS args)
{ {
UI_Requester_Init(&s->assault_req, 7, 10, false); const ASSAULT_STATS stats = Gym_GetAssaultStats();
int32_t max_assault_times = 0;
for (int i = 0; i < MAX_ASSAULT_TIMES; i++) {
if (stats.best_time[i] != 0) {
max_assault_times++;
}
}
UI_Requester_Init(&s->assault_req, 7, max_assault_times, false);
s->assault_req.reserve_space = true;
s->args = args; s->args = args;
} }

View file

@ -13,6 +13,7 @@
#include <libtrx/game/ui/elements/modal.h> #include <libtrx/game/ui/elements/modal.h>
#include <libtrx/game/ui/elements/pad.h> #include <libtrx/game/ui/elements/pad.h>
#include <libtrx/game/ui/elements/requester.h> #include <libtrx/game/ui/elements/requester.h>
#include <libtrx/game/ui/elements/resize.h>
#include <libtrx/game/ui/elements/spacer.h> #include <libtrx/game/ui/elements/spacer.h>
#include <libtrx/game/ui/elements/stack.h> #include <libtrx/game/ui/elements/stack.h>
#include <libtrx/game/ui/elements/window.h> #include <libtrx/game/ui/elements/window.h>
@ -196,28 +197,23 @@ static void M_FinalStatsRows(const UI_STATS_DIALOG_STATE *const s)
static void M_AssaultCourseStatsRows(UI_STATS_DIALOG_STATE *const s) static void M_AssaultCourseStatsRows(UI_STATS_DIALOG_STATE *const s)
{ {
const ASSAULT_STATS stats = Gym_GetAssaultStats(); const ASSAULT_STATS stats = Gym_GetAssaultStats();
UI_BeginRequester(&s->assault_req, M_GetDialogTitle(s));
int32_t present = 0; // ensure minimum dialog width
for (int i = 0; i < MAX_ASSAULT_TIMES; i++) { UI_Spacer(290.0f, 0.0f);
if (stats.best_time[i] != 0) {
present++;
}
}
UI_Requester_SetMaxRows(&s->assault_req, present);
int32_t visible = 0;
if (stats.best_time[0] == 0) { if (stats.best_time[0] == 0) {
UI_BeginAnchor(0.5f, 0.5f); UI_BeginAnchor(0.5f, 0.5f);
UI_Label(GS(STATS_ASSAULT_NO_TIMES_SET)); UI_Label(GS(STATS_ASSAULT_NO_TIMES_SET));
UI_EndAnchor(); UI_EndAnchor();
visible = 1;
} else { } else {
int32_t first = UI_Requester_GetFirstRow(&s->assault_req); const int32_t first = UI_Requester_GetFirstRow(&s->assault_req);
int32_t last = UI_Requester_GetLastRow(&s->assault_req); const int32_t last = UI_Requester_GetLastRow(&s->assault_req);
for (int32_t i = first; i < last; i++) { for (int32_t i = first; i < last; i++) {
char left_buf[32] = ""; if (stats.best_time[i] == 0) {
char right_buf[32] = ""; break;
ASSERT(stats.best_time[i] != 0); }
char left_buf[32] = " ";
char right_buf[32] = " ";
sprintf( sprintf(
left_buf, "%2d: %s %d", i + 1, GS(STATS_ASSAULT_FINISH), left_buf, "%2d: %s %d", i + 1, GS(STATS_ASSAULT_FINISH),
stats.best_finish[i]); stats.best_finish[i]);
@ -229,12 +225,9 @@ static void M_AssaultCourseStatsRows(UI_STATS_DIALOG_STATE *const s)
/ (FRAMES_PER_SECOND / 10)); / (FRAMES_PER_SECOND / 10));
M_Row(s, left_buf, right_buf); M_Row(s, left_buf, right_buf);
visible++;
} }
} }
UI_EndRequester(&s->assault_req);
UI_Spacer(
0.0f, TEXT_HEIGHT_FIXED * MAX(0, s->assault_req.vis_rows - visible));
} }
static const char *M_GetDialogTitle(const UI_STATS_DIALOG_STATE *const s) static const char *M_GetDialogTitle(const UI_STATS_DIALOG_STATE *const s)
@ -259,8 +252,6 @@ static const char *M_GetDialogTitle(const UI_STATS_DIALOG_STATE *const s)
static void M_BeginDialog(const UI_STATS_DIALOG_STATE *const s) static void M_BeginDialog(const UI_STATS_DIALOG_STATE *const s)
{ {
const char *const title = M_GetDialogTitle(s); const char *const title = M_GetDialogTitle(s);
UI_BeginModal(0.5f, 1.0f);
UI_BeginPad(40.f, 40.0f);
if (s->args.style == UI_STATS_DIALOG_STYLE_BARE) { if (s->args.style == UI_STATS_DIALOG_STYLE_BARE) {
UI_BeginStackEx((UI_STACK_SETTINGS) { UI_BeginStackEx((UI_STACK_SETTINGS) {
.orientation = UI_STACK_VERTICAL, .orientation = UI_STACK_VERTICAL,
@ -295,8 +286,6 @@ static void M_EndDialog(const UI_STATS_DIALOG_STATE *const s)
UI_EndWindowBody(); UI_EndWindowBody();
UI_EndWindow(); UI_EndWindow();
} }
UI_EndPad();
UI_EndModal();
} }
void UI_StatsDialog(UI_STATS_DIALOG_STATE *const s) void UI_StatsDialog(UI_STATS_DIALOG_STATE *const s)
@ -305,19 +294,25 @@ void UI_StatsDialog(UI_STATS_DIALOG_STATE *const s)
// implementations. // implementations.
ASSERT(s->args.style == UI_STATS_DIALOG_STYLE_BORDERED); ASSERT(s->args.style == UI_STATS_DIALOG_STYLE_BORDERED);
M_BeginDialog(s); UI_BeginModal(0.5f, 1.0f);
UI_BeginPad(40.f, 40.0f);
switch (s->args.mode) { switch (s->args.mode) {
case UI_STATS_DIALOG_MODE_LEVEL: case UI_STATS_DIALOG_MODE_LEVEL:
M_BeginDialog(s);
M_LevelStatsRows(s); M_LevelStatsRows(s);
M_EndDialog(s);
break; break;
case UI_STATS_DIALOG_MODE_FINAL: case UI_STATS_DIALOG_MODE_FINAL:
M_BeginDialog(s);
M_FinalStatsRows(s); M_FinalStatsRows(s);
M_EndDialog(s);
break; break;
case UI_STATS_DIALOG_MODE_ASSAULT_COURSE: case UI_STATS_DIALOG_MODE_ASSAULT_COURSE:
M_AssaultCourseStatsRows(s); M_AssaultCourseStatsRows(s);
break; break;
} }
M_EndDialog(s); UI_EndPad();
UI_EndModal();
} }