From f46395b9d0cfc4157e12dbb8ad2c66c942a1bc11 Mon Sep 17 00:00:00 2001 From: Rickey Date: Tue, 31 Mar 2026 21:04:47 -0700 Subject: [PATCH] Add basic common_ui background gfx functions (#415) * Add basic common_ui background gfx functions * clang format * document common_ui.h * Remove unused tonc header * Fix header guard name convention * more header cleanup * claaaaanggggg format --- Makefile | 4 ++-- include/game.h | 17 ++++++----------- include/game/common_ui.h | 30 ++++++++++++++++++++++++++++++ source/game.c | 4 ++-- source/game/common_ui.c | 22 ++++++++++++++++++++++ 5 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 include/game/common_ui.h create mode 100644 source/game/common_ui.c diff --git a/Makefile b/Makefile index 099470f..de9fadb 100644 --- a/Makefile +++ b/Makefile @@ -27,8 +27,8 @@ LIBTONC := $(DEVKITPRO)/libtonc #--------------------------------------------------------------------------------- TARGET := $(notdir $(CURDIR)) BUILD := build -SOURCES := source -INCLUDES := include +SOURCES := source source/game +INCLUDES := include include/game DATA := MUSIC := audio GRAPHICS := graphics diff --git a/include/game.h b/include/game.h index 87ae121..bbd980e 100644 --- a/include/game.h +++ b/include/game.h @@ -1,6 +1,7 @@ #ifndef GAME_H #define GAME_H +#include "game/common_ui.h" #include "game_variables.h" #include @@ -38,17 +39,6 @@ typedef struct CardObject CardObject; typedef struct Card Card; typedef struct JokerObject JokerObject; -enum BackgroundId -{ - BG_NONE, - BG_CARD_SELECTING, - BG_CARD_PLAYING, - BG_ROUND_END, - BG_SHOP, - BG_BLIND_SELECT, - BG_MAIN_MENU -}; - // Enum value names in ../include/def_state_info_table.h enum GameState { @@ -182,4 +172,9 @@ void set_game_speed(int new_game_speed); bool is_shortcut_joker_active(void); int get_straight_and_flush_size(void); +// Temporary change for Refactor. Currently this compatibility binder is to allow +// simultaneous integration of the new system in `common_ui` with the the existing +// old system incrementally and without losing functionality. +void change_background_legacy(enum BackgroundId id); + #endif // GAME_H diff --git a/include/game/common_ui.h b/include/game/common_ui.h new file mode 100644 index 0000000..0715250 --- /dev/null +++ b/include/game/common_ui.h @@ -0,0 +1,30 @@ +/** + * @file common_ui.h + * + * @brief Common functions to render UI elements. + */ +#ifndef COMMON_UI_H +#define COMMON_UI_H + +/** + * @brief Enum of possible backgrounds to render with @ref change_background + */ +enum BackgroundId +{ + BG_NONE, + BG_CARD_SELECTING, + BG_CARD_PLAYING, + BG_ROUND_END, + BG_SHOP, + BG_BLIND_SELECT, + BG_MAIN_MENU +}; + +/** + * Change the background + * + * @param id @ref BackgroundId to render to screen + */ +void change_background(enum BackgroundId id); + +#endif // COMMON_UI_H diff --git a/source/game.c b/source/game.c index e56e0b2..4a2d5f2 100644 --- a/source/game.c +++ b/source/game.c @@ -11,6 +11,7 @@ #include "blind.h" #include "button.h" #include "card.h" +#include "game/common_ui.h" #include "graphic_utils.h" #include "hand_analysis.h" #include "joker.h" @@ -235,7 +236,6 @@ static void game_round_end_display_cashout(void); static void game_round_end_dismiss_round_end_panel(void); static void sort_cards(void); -static void change_background(enum BackgroundId id); static void display_temp_score(u32 value); static void display_score(u32 value); static void check_flaming_score(void); @@ -1424,7 +1424,7 @@ static inline void reset_top_left_panel_bottom_row() main_bg_se_copy_rect(TOP_LEFT_PANEL_BOTTOM_ROW_RESET_RECT, top_left_panel_bottom_row_pos); } -static void change_background(enum BackgroundId id) +void change_background_legacy(enum BackgroundId id) { if (background == id) { diff --git a/source/game/common_ui.c b/source/game/common_ui.c new file mode 100644 index 0000000..a30775b --- /dev/null +++ b/source/game/common_ui.c @@ -0,0 +1,22 @@ +#include "game/common_ui.h" + +#include "game.h" + +typedef void (*BackgroundRenderCallback)(void); + +// Map to fill in for refactor +BackgroundRenderCallback bgCallbacks[] = +{ + [BG_NONE] = NULL, + [BG_CARD_SELECTING] = NULL, + [BG_CARD_PLAYING] = NULL, + [BG_ROUND_END] = NULL, + [BG_SHOP] = NULL, + [BG_BLIND_SELECT] = NULL, + [BG_MAIN_MENU] = NULL, +}; + +void change_background(enum BackgroundId id) +{ + change_background_legacy(id); +}