* Add optional exit indexes to selection grid rows & fix shop reroll button movement (#316) - Added has_exit_idx and exit_idx to SelGridRowAttributes to simulate subgrid-like behavior that was desired in shop reroll button - Add logic to use exit index if given inside selection_grid_move_selection_horz() - Add joker focus logic to shop_reroll_row_on_selection_changed() * clang-format fix * clang format fix #2 errors due to version mismatch in local fixed (i hope) * important fix: check x instead of y for next_roudn_btn_sel_x was checking y against an X value * changed commenting * selection_grid.h clang-format fix * changed commenting again trying to make docs understandable * set shop selection rows explicit Co-authored-by: Rickey <ric@rf3.xyz> * syntax fix * clang format fix onceagain * guard clause when moving down from jokers --------- Co-authored-by: Rickey <ric@rf3.xyz>
This commit is contained in:
@@ -82,6 +82,17 @@ typedef struct
|
|||||||
* @brief Whether to wrap selection when it passes the end of the row.
|
* @brief Whether to wrap selection when it passes the end of the row.
|
||||||
*/
|
*/
|
||||||
bool wrap;
|
bool wrap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Whether this row have a horizontal exit index (a row to process horizontal inputs
|
||||||
|
* from).
|
||||||
|
*/
|
||||||
|
bool has_h_exit_idx;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The index of the row to exit from when a horizontal input is received.
|
||||||
|
*/
|
||||||
|
u8 h_exit_idx;
|
||||||
} SelGridRowAttributes;
|
} SelGridRowAttributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+14
-3
@@ -488,9 +488,9 @@ Button game_playing_buttons[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SelectionGridRow shop_selection_rows[] = {
|
SelectionGridRow shop_selection_rows[] = {
|
||||||
{0, jokers_sel_row_get_size, jokers_sel_row_on_selection_changed, jokers_sel_row_on_key_transit, {.wrap = false}},
|
{0, jokers_sel_row_get_size, jokers_sel_row_on_selection_changed, jokers_sel_row_on_key_transit, {.wrap = false, .has_h_exit_idx = false, .h_exit_idx = 0}},
|
||||||
{1, shop_top_row_get_size, shop_top_row_on_selection_changed, shop_top_row_on_key_transit, {.wrap = false}},
|
{1, shop_top_row_get_size, shop_top_row_on_selection_changed, shop_top_row_on_key_transit, {.wrap = false, .has_h_exit_idx = false, .h_exit_idx = 0}},
|
||||||
{2, shop_reroll_row_get_size, shop_reroll_row_on_selection_changed, shop_reroll_row_on_key_transit, {.wrap = false}}
|
{2, shop_reroll_row_get_size, shop_reroll_row_on_selection_changed, shop_reroll_row_on_key_transit, {.wrap = false, .has_h_exit_idx = true, .h_exit_idx = 1} },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const Selection SHOP_INIT_SEL = {-1, 1};
|
static const Selection SHOP_INIT_SEL = {-1, 1};
|
||||||
@@ -4255,6 +4255,10 @@ static bool shop_top_row_on_selection_changed(
|
|||||||
const Selection* new_selection
|
const Selection* new_selection
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
// Guard if we move down while on jokers
|
||||||
|
if (new_selection->y > row_idx && prev_selection->x > 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
// The selection grid system only guarantees that the new selection is within bounds
|
// The selection grid system only guarantees that the new selection is within bounds
|
||||||
// but not the previous one...
|
// but not the previous one...
|
||||||
// This allows using INIT_SEL = {-1, 1} and move to set the initial selection in a hacky way...
|
// This allows using INIT_SEL = {-1, 1} and move to set the initial selection in a hacky way...
|
||||||
@@ -4312,6 +4316,13 @@ static bool shop_reroll_row_on_selection_changed(
|
|||||||
{
|
{
|
||||||
// Remove highlight
|
// Remove highlight
|
||||||
memcpy16(&pal_bg_mem[REROLL_BTN_SELECTED_BORDER_PID], &pal_bg_mem[REROLL_BTN_PID], 1);
|
memcpy16(&pal_bg_mem[REROLL_BTN_SELECTED_BORDER_PID], &pal_bg_mem[REROLL_BTN_PID], 1);
|
||||||
|
|
||||||
|
if (new_selection->x != NEXT_ROUND_BTN_SEL_X)
|
||||||
|
{
|
||||||
|
int idx = new_selection->x - 1;
|
||||||
|
JokerObject* joker_object = (JokerObject*)list_get_at_idx(&_shop_jokers_list, idx);
|
||||||
|
sprite_object_set_focus(joker_object->sprite_object, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (row_idx == new_selection->y)
|
else if (row_idx == new_selection->y)
|
||||||
{
|
{
|
||||||
|
|||||||
+15
-7
@@ -29,7 +29,14 @@ void selection_grid_move_selection_horz(SelectionGrid* selection_grid, int direc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Selection new_selection = selection_grid->selection;
|
SelectionGridRow current_row = selection_grid->rows[selection_grid->selection.y];
|
||||||
|
|
||||||
|
// Choose the horizontal exit index if it exists
|
||||||
|
Selection new_selection =
|
||||||
|
current_row.attributes.has_h_exit_idx
|
||||||
|
? (Selection){selection_grid->selection.x, current_row.attributes.h_exit_idx}
|
||||||
|
: selection_grid->selection;
|
||||||
|
|
||||||
new_selection.x += direction_tribool;
|
new_selection.x += direction_tribool;
|
||||||
int row_size = selection_grid->rows[new_selection.y].get_size();
|
int row_size = selection_grid->rows[new_selection.y].get_size();
|
||||||
bool wrap_enabled = selection_grid->rows[new_selection.y].attributes.wrap;
|
bool wrap_enabled = selection_grid->rows[new_selection.y].attributes.wrap;
|
||||||
@@ -41,12 +48,13 @@ void selection_grid_move_selection_horz(SelectionGrid* selection_grid, int direc
|
|||||||
|
|
||||||
if (wrap_enabled || (new_selection.x >= 0 && new_selection.x < row_size))
|
if (wrap_enabled || (new_selection.x >= 0 && new_selection.x < row_size))
|
||||||
{
|
{
|
||||||
bool proceed_selection = selection_grid->rows[new_selection.y].on_selection_changed(
|
bool proceed_selection =
|
||||||
selection_grid,
|
selection_grid->rows[selection_grid->selection.y].on_selection_changed(
|
||||||
new_selection.y,
|
selection_grid,
|
||||||
&selection_grid->selection,
|
current_row.row_idx,
|
||||||
&new_selection
|
&selection_grid->selection,
|
||||||
);
|
&new_selection
|
||||||
|
);
|
||||||
|
|
||||||
if (proceed_selection)
|
if (proceed_selection)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user