GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
common_ui.c
1#include "game/common_ui.h"
2
3#include "blind_select.h"
4#include "game.h"
5#include "game/main_menu.h"
6#include "game/options_menu.h"
7#include "game/round.h"
8#include "game/round_end.h"
9#include "game/run_setup.h"
10#include "game/shop.h"
11#include "layout.h"
12
13typedef void (*BackgroundRenderCallback)(void);
14
15static enum BackgroundId s_background = BG_NONE;
16
17// Map to fill in for refactor
18static const BackgroundRenderCallback bgCallbacks[] = {
19 [BG_NONE] = NULL,
20 [BG_CARD_SELECTING] = game_round_change_background_selecting,
21 [BG_CARD_PLAYING] = game_round_change_background_playing,
22 [BG_ROUND_END] = game_round_end_change_background,
24 [BG_BLIND_SELECT] = game_blind_select_change_background,
25 [BG_RUN_SETUP] = game_run_setup_change_background,
26 [BG_OPTIONS_MENU] = game_options_menu_change_background,
27 [BG_MAIN_MENU] = game_main_menu_change_background,
28};
29
30enum BackgroundId get_current_background(void)
31{
32 return s_background;
33}
34
35void change_background(enum BackgroundId id, bool force_redraw)
36{
37 if (force_redraw)
38 {
39 s_background = BG_NONE;
40 }
41 if (id != s_background && bgCallbacks[id] != NULL)
42 {
43 bgCallbacks[id]();
44 }
45 s_background = id;
46}
47
49{
50 BG_POINT top_left_panel_bottom_row_pos = TOP_LEFT_PANEL_POINT;
51 // Use the source rect height to offset to the bottom row point
52 top_left_panel_bottom_row_pos.y += rect_height(&TOP_LEFT_ITEM_SRC_RECT) - 1;
53 main_bg_se_copy_rect(TOP_LEFT_PANEL_BOTTOM_ROW_RESET_RECT, top_left_panel_bottom_row_pos);
54}
Blind select state functions.
void game_blind_select_change_background(void)
Change to the blind select background.
Common functions to render UI elements.
void change_background(enum BackgroundId id, bool force_redraw)
Definition common_ui.c:35
BackgroundId
Enum of possible backgrounds to render with change_background.
Definition common_ui.h:15
void reset_top_left_panel_bottom_row(void)
Restores the bottom row of the top-left panel from the background map.
Definition common_ui.c:48
INLINE int rect_height(const Rect *rect)
Get the height of a rectangle.
void main_bg_se_copy_rect(Rect se_rect, BG_POINT dest_pos)
Copies a rect in the main background from se_rect to the position (x, y).
Header of shared rects and points needed for ui.
Main menu state functions.
void game_main_menu_change_background(void)
Change the main menu background.
Definition main_menu.c:86
Options menu state functions.
void game_options_menu_change_background(void)
Change the options menu background.
API relative to the Rounds we play.
void game_round_change_background_playing(void)
Change to the round card playing background.
Definition round.c:400
void game_round_change_background_selecting(void)
Change to the round card selection background.
Definition round.c:338
Round end game state functions.
void game_round_end_change_background(void)
Change to the round end background.
Definition round_end.c:440
Setup Run menu state functions.
void game_run_setup_change_background(void)
Change to the Run Setup menu background.
Definition run_setup.c:568
Shop state functions.
void game_shop_change_background(void)
Change to the shop background.
Definition shop.c:194