Skip to content

Commit

Permalink
menu: improve grouping in spell practice and stage select
Browse files Browse the repository at this point in the history
  • Loading branch information
Akaricchi committed Jun 14, 2024
1 parent bad453c commit 0fe4655
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/menu/spellpractice.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static void draw_spell_menu(MenuData *m) {
MenuData* create_spell_menu(void) {
char title[128];
Difficulty lastdiff = D_Any;
uint16_t lastgroup = 0;

MenuData *m = alloc_menu();

Expand All @@ -32,14 +33,17 @@ MenuData* create_spell_menu(void) {
m->transition = TransFadeBlack;

int n = stageinfo_get_num_stages();

for(int i = 0; i < n; ++i) {
StageInfo *stg = stageinfo_get_by_index(i);

if(stg->type != STAGE_SPELL) {
continue;
}

if(stg->difficulty < lastdiff || (stg->difficulty == D_Extra && lastdiff != D_Extra)) {
uint16_t group = stg->id & ~0xff;

if(i && (lastgroup != group || stg->difficulty < lastdiff)) {
add_menu_separator(m);
}

Expand All @@ -54,6 +58,7 @@ MenuData* create_spell_menu(void) {
}

lastdiff = stg->difficulty;
lastgroup = group;
}

add_menu_separator(m);
Expand Down
5 changes: 4 additions & 1 deletion src/menu/stageselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ static void draw_stage_menu(MenuData *m) {
MenuData* create_stage_menu(void) {
char title[STGMENU_MAX_TITLE_LENGTH];
Difficulty lastdiff = D_Any;
uint16_t lastgroup = 0;

MenuData *m = alloc_menu();

Expand All @@ -36,15 +37,17 @@ MenuData* create_stage_menu(void) {
for(int i = 0; i < n; ++i) {
StageInfo *stg = stageinfo_get_by_index(i);
Difficulty diff = stg->difficulty;
uint16_t group = stg->id & ~0xff;

if(diff < lastdiff || (diff == D_Extra && lastdiff != D_Extra) || (diff && !lastdiff)) {
if(i && (lastgroup != group || diff < lastdiff)) {
add_menu_separator(m);
}

snprintf(title, STGMENU_MAX_TITLE_LENGTH, "%s: %s", stg->title, stg->subtitle);
add_menu_entry(m, title, start_game, stg);

lastdiff = diff;
lastgroup = group;
}

add_menu_separator(m);
Expand Down

0 comments on commit 0fe4655

Please sign in to comment.