GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
joker_row.c
1#include "game/joker_row.h"
2
3#include "game.h"
4#include "game_variables.h"
5#include "joker.h"
6#include "layout.h"
7#include "list.h"
8#include "sprite.h"
9#include "util.h"
10
12{
13 return list_get_len(get_jokers_list());
14}
15
17 SelectionGrid* selection_grid,
18 int row_idx,
19 const Selection* prev_selection,
20 const Selection* new_selection
21)
22{
23 List* owned_jokers_list = get_jokers_list();
24
25 // swap Jokers if the A button is held down and all Jokers are on the same row
26 bool swapping =
27 key_is_down(SELECT_CARD) && new_selection->y == row_idx && prev_selection->y == row_idx;
28
29 if (prev_selection->y == row_idx)
30 {
31 JokerObject* joker_object =
32 (JokerObject*)list_get_at_idx(owned_jokers_list, prev_selection->x);
33 // Don't change focus from current Joker if swapping
34 if (joker_object != NULL && !swapping)
35 {
37 sprite_object_set_focus((SpriteObject*)joker_object, false);
38 }
39 }
40
41 if (new_selection->y == row_idx)
42 {
43 JokerObject* joker_object =
44 (JokerObject*)list_get_at_idx(owned_jokers_list, new_selection->x);
45 if (joker_object != NULL)
46 {
47 if (!swapping)
48 {
49 sprite_object_set_focus((SpriteObject*)joker_object, true);
50 }
51 // If we land on this row while the A button is being held, we are in swapping mode
52 // This means that we need to hide the price, whether we were already
53 // on this row or if we come from another
54 if (!key_is_down(SELECT_CARD))
55 {
57 (SpriteObject*)joker_object,
58 joker_object_get_sell_price((Item*)joker_object)
59 );
60 }
61 }
62 }
63
64 if (swapping)
65 {
67 owned_jokers_list,
68 (unsigned int)prev_selection->x,
69 (unsigned int)new_selection->x
70 );
71 }
72
73 return true;
74}
75
76static inline void sell_joker(int joker_idx)
77{
78 List* owned_jokers_list = get_jokers_list();
79
80 if (joker_idx < 0 || joker_idx >= list_get_len(owned_jokers_list))
81 {
82 MGBA_FUNC_ERROR("Invalid joker_idx == %d", joker_idx);
83 return;
84 }
85
86 Item* joker_object = (Item*)list_get_at_idx(owned_jokers_list, joker_idx);
87 item_sell(joker_object);
88
89 remove_owned_joker(joker_idx);
90}
91
92void jokers_sel_row_on_key_transit(SelectionGrid* selection_grid, Selection* selection)
93{
94 JokerObject* joker_object = (JokerObject*)list_get_at_idx(get_jokers_list(), selection->x);
95 if (joker_object != NULL)
96 {
97 if (key_hit(SELECT_CARD))
98 {
100 }
101 else if (key_released(SELECT_CARD))
102 {
104 (SpriteObject*)joker_object,
105 joker_object_get_sell_price((Item*)joker_object)
106 );
107 }
108 }
109
110 if (key_hit(SELL_KEY))
111 {
112 int sold_joker_idx = selection->x;
113
114 // Move the selection away from the jokers so it doesn't point to an invalid place
115 // Do this before selling the joker so valid row sizes are used
116 selection_grid_move_selection_vert(selection_grid, SCREEN_DOWN);
117
118 sell_joker(sold_joker_idx);
119 }
120}
Game global game variables struct definition.
void item_sell(Item *item)
Performs the item sell transaction, gaining its sell value and discarding it.
Definition item.c:185
Functions relative to the handling of Jokers.
int joker_object_get_sell_price(Item *joker_object)
Returns the sell price of the joker object.
Definition joker.c:329
All the functions used specifically to interact with Jokers. This includes browsing,...
bool jokers_sel_row_on_selection_changed(SelectionGrid *selection_grid, int row_idx, const Selection *prev_selection, const Selection *new_selection)
Handle directional inputs on the Jokers' row at the top of the game screen.
Definition joker_row.c:16
void jokers_sel_row_on_key_transit(SelectionGrid *selection_grid, Selection *selection)
Handle button inputs on the Jokers' row at the top of the game screen.
Definition joker_row.c:92
int jokers_sel_row_get_size(void)
Returns the size of the Jokers' row at the top of the game screen. Is equal to the number of Jokers o...
Definition joker_row.c:11
Header of shared rects and points needed for ui.
A doubly-linked list.
bool list_swap(List *list, unsigned int idx_a, unsigned int idx_b)
Definition list.c:148
void * list_get_at_idx(List *list, unsigned int idx)
Definition list.c:219
int list_get_len(const List *list)
Definition list.c:214
void selection_grid_move_selection_vert(SelectionGrid *selection_grid, int direction_tribool)
Moves the selection vertically within the selection grid.
Sprite system for Gbalatro.
void sprite_object_set_focus(SpriteObject *sprite_object, bool focus)
Set the focus for SpriteObject Raises the object by SPRITE_FOCUS_RAISE_PX.
Definition sprite.c:446
void sprite_object_print_price_under(SpriteObject *sprite_object, int price)
Print the price string directly beneath a SpriteObject. More specialized version of sprite_object_pri...
Definition sprite.c:523
void sprite_object_erase_text_under(SpriteObject *sprite_object)
Erase the text within the Rect directly beneath a SpriteObject. This is used only for Cards for now.
Definition sprite.c:533
A generic interface for all items that can appear in the shop or be in the inventory....
Definition item.h:83
A doubly-linked list.
Definition list.h:61
The core selection grid struct, represents the grid itself and its state.
A sprite object is a sprite that is focusable and movable in animation.
Definition sprite.h:86
Utilities relating around number string representation and protected arithmatic helper functions.