Fixed shop initial selection to be visible + extracted shop outro

This commit is contained in:
MeirGavish
2025-08-16 06:41:33 +03:00
parent 168e34375d
commit ae019be190
2 changed files with 62 additions and 52 deletions
+51 -44
View File
@@ -2251,7 +2251,6 @@ static void game_shop_reroll(int *reroll_cost)
// Shop input // Shop input
static int shop_top_row_get_size() static int shop_top_row_get_size()
{ {
// TODO: Make dynamic to not allow selecting sold items
return list_get_size(shop_jokers) + 1; // + 1 to account for next round button return list_get_size(shop_jokers) + 1; // + 1 to account for next round button
} }
@@ -2317,7 +2316,8 @@ static void shop_top_row_on_selection_changed(SelectionGrid* selection_grid, int
const Selection* prev_selection, const Selection* prev_selection,
const Selection* new_selection) const Selection* new_selection)
{ {
if (prev_selection->y == row_idx) // The selection grid system only guarantees that the new selection is within bounds
if (prev_selection->y == row_idx && prev_selection->x >= 0 && prev_selection->x < shop_top_row_get_size())
{ {
if (prev_selection->x == NEXT_ROUND_BTN_SEL_X) if (prev_selection->x == NEXT_ROUND_BTN_SEL_X)
{ {
@@ -2380,15 +2380,19 @@ SelectionGridRow shop_selection_rows[] =
{1, shop_bottom_row_get_size, shop_bottom_row_on_selection_changed, shop_bottom_row_on_key_hit} {1, shop_bottom_row_get_size, shop_bottom_row_on_selection_changed, shop_bottom_row_on_key_hit}
}; };
// TODO: Initialize selection better static const Selection SHOP_INIT_SEL = {-1, 0};
SelectionGrid shop_selection_grid = {shop_selection_rows, NUM_ELEM_IN_ARR(shop_selection_rows), {0, 0}};
SelectionGrid shop_selection_grid = {shop_selection_rows, NUM_ELEM_IN_ARR(shop_selection_rows), SHOP_INIT_SEL};
// Shop menu input and selection // Shop menu input and selection
static void game_shop_process_user_input() static void game_shop_process_user_input()
{ {
if (timer == 1) if (timer == 1)
{ {
// The selection grid is initialized outside of bounds and moved
// to trigger the selection change so the initial selection is visible
shop_selection_grid.selection = SHOP_INIT_SEL;
selection_grid_move_selection_horz(&shop_selection_grid, 1);
tte_printf("#{P:%d,%d; cx:0xF000}$%d", SHOP_REROLL_RECT.left, SHOP_REROLL_RECT.top, reroll_cost); tte_printf("#{P:%d,%d; cx:0xF000}$%d", SHOP_REROLL_RECT.left, SHOP_REROLL_RECT.top, reroll_cost);
} }
@@ -2421,42 +2425,9 @@ static void game_shop_lights_anim_frame()
memcpy16(&pal_bg_mem[8], &shifted_palette[3], 1); memcpy16(&pal_bg_mem[8], &shifted_palette[3], 1);
} }
void game_shop() // Outro sequence (menu and shop icon going out of frame)
static void game_shop_outro()
{ {
change_background(BG_ID_SHOP);
if (shop_jokers != NULL)
{
for (int i = 0; i < list_get_size(shop_jokers); i++)
{
JokerObject *joker_object = list_get(shop_jokers, i);
if (joker_object != NULL)
{
joker_object_update(joker_object);
}
}
}
if (timer % 20 == 0)
{
game_shop_lights_anim_frame();
}
switch (state) // I'm only using magic numbers here for the sake of simplicity since it's just sequential, but you can replace them with named constants or enums if it makes it clearer
{
case 0:
{
game_shop_intro();
break;
}
case 1:
{
game_shop_process_user_input();
break;
}
case 2: // Outro sequence (menu and shop icon going out of frame)
{
// Shift the shop panel // Shift the shop panel
main_bg_se_move_rect_1_tile_vert(POP_MENU_ANIM_RECT, SE_DOWN); main_bg_se_move_rect_1_tile_vert(POP_MENU_ANIM_RECT, SE_DOWN);
@@ -2496,22 +2467,56 @@ void game_shop()
state = 3; // Go to the next state state = 3; // Go to the next state
timer = 0; // Reset the timer timer = 0; // Reset the timer
} }
}
void game_shop()
{
change_background(BG_ID_SHOP);
if (shop_jokers != NULL)
{
for (int i = 0; i < list_get_size(shop_jokers); i++)
{
JokerObject *joker_object = list_get(shop_jokers, i);
if (joker_object != NULL)
{
joker_object_update(joker_object);
}
}
}
if (timer % 20 == 0)
{
game_shop_lights_anim_frame();
}
switch (state) // I'm only using magic numbers here for the sake of simplicity since it's just sequential, but you can replace them with named constants or enums if it makes it clearer
{
case 0:
{
game_shop_intro();
break;
}
case 1:
{
game_shop_process_user_input();
break;
}
case 2:
{
game_shop_outro();
break; break;
} }
default: default:
state = 0; // Reset the state state = 0; // Reset the state
selection_x = 0; // Reset the selection
selection_y = 0; // Reset the selection
for (int i = 0; i < list_get_size(shop_jokers); i++) for (int i = 0; i < list_get_size(shop_jokers); i++)
{ {
JokerObject* joker_object = list_get(shop_jokers, i); JokerObject* joker_object = list_get(shop_jokers, i);
if (joker_object != NULL) if (joker_object != NULL)
{ {
// Make the joker available back to shop // Make the joker available back to shop
int_list_append(jokers_available_to_shop, (intptr_t)joker_object->joker->id); int_list_append(jokers_available_to_shop, (intptr_t)joker_object->joker->id);
} }
joker_object_destroy(&joker_object); // Destroy the joker objects joker_object_destroy(&joker_object); // Destroy the joker objects
@@ -2526,6 +2531,8 @@ void game_shop()
} }
} }
void game_blind_select() void game_blind_select()
{ {
switch (state) // I'm only using magic numbers here for the sake of simplicity since it's just sequential, but you can replace them with named constants or enums if it makes it clearer switch (state) // I'm only using magic numbers here for the sake of simplicity since it's just sequential, but you can replace them with named constants or enums if it makes it clearer
+3
View File
@@ -55,7 +55,10 @@ void selection_grid_move_selection_vert(SelectionGrid *selection_grid, int direc
// Clip selection to row size // Clip selection to row size
new_selection.x = new_row_size - 1; new_selection.x = new_row_size - 1;
} }
if (selection.y >= 0 && selection.y < selection_grid->num_rows)
{
selection_grid->rows[selection.y].on_selection_changed(selection_grid, selection.y, &selection, &new_selection); selection_grid->rows[selection.y].on_selection_changed(selection_grid, selection.y, &selection, &new_selection);
}
selection_grid->rows[new_selection.y].on_selection_changed(selection_grid, new_selection.y, &selection, &new_selection); selection_grid->rows[new_selection.y].on_selection_changed(selection_grid, new_selection.y, &selection, &new_selection);
selection_grid->selection = new_selection; selection_grid->selection = new_selection;
} }