* Turned SpriteObject into a member of JokerObject and CardObject and expiremented with casting * Extracted shop code to use generic `SpriteObject` * Extracted shop joker generation to a function * Renamed object -> item * Added setters and getters for `SpriteObject` members and updated all accesses to use them with casting (AI used for tedious work and reviewed - model Raptor mini) * Added sprite_object_set_vx() because sprite_object_set_vy() exists and reordered the function order to have x,y parameters first, then targets * Added Item object to act as a purchasable interface for the shop - AI used (model Raptor mini) * Added -fms-extensions and switched to anonymous inheritance * Fixed anonymous inheritance for joker and added direct access for that too * fix build error from previous commit + clang-format * Fixed build errors + clang-format for real this time (I hope...) * clang-format one last time, I don't understand it anymore * clang-format is annoying * Added uses of CHECK_NULL_ARG macros * Merged item_defs.h into item.h and fixed build error from previous commit * clang-format...? * Changed sprite_object_new() into sprite_object_init() and made it accept a parameter instead of returning one to make it less awkward * Updated sprite_object_init() documentation * Updated sprite_object_destroy documentation * More clang-format * Renamed add_to_inventory to acquire and updated documentation * Added function documentations * Update documentation + swap order of consumable and playing card types * Added documentation for new files (+ small addition to button.h) * clang-format * Used typedef * A bit more documentation * Changed sho pcode to use generic Item instead of SpriteObject * clang-format + fixed NULL-check error * Revert weird clang-format...? * clang-format for real * Fixed errors from rebase on log_function_name * Fixed build errors from rebase on main * Added some more documentation about first member struct inheritance * typo fix * typo fix for real * Removed SpriteObject field getters/setters (AI used - model Raptor mini) * Renamed item_acquire -> item_on_acquired * Added item_can_acquire() * clang-format * Fixed some sprite issues but not all... * Fixed some more issues * Cleanup JokerObject some more JokerObjects in the shop * Added `item_destroy()` * Added item_set_available_to_shop, CHECK_ITEM_TYPE macros + small documentation updates * Another small JokerObject->Item replacement * Removed item_set_available_to_shop and replaced with item_roll_new() and item_dispose(), also changed "available_to_shop" semantics to "rollable" * Re-applied changes from game.c to round.c after rebase on main * Added partial implementations of item functions for playing cards * Line endings fix... * Macro renames, function documentations * Updated documentations * Apply fixes from Copilot review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix card_object_get_buy_price type checking Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Avoid double pointer cast on dispose Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Apply suggestions from @ricfehr3's code review Co-authored-by: Rickey <ric@rf3.xyz> * Remove redundant comments * Moved error checking before joker_get_random_rarity Co-authored-by: Rickey <ric@rf3.xyz> * Fixed build error from rebase * clang-format * Added doxygen documentation for Item explaining inheritance * Removed unnecessary comment --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Rickey <ric@rf3.xyz>
214 lines
5.7 KiB
C
214 lines
5.7 KiB
C
#include "game/main_menu.h"
|
|
|
|
#include "affine_background.h"
|
|
#include "audio_utils.h"
|
|
#include "background_main_menu_gfx.h"
|
|
#include "button.h"
|
|
#include "card.h"
|
|
#include "game.h"
|
|
#include "game/common_ui.h"
|
|
#include "game_variables.h"
|
|
#include "graphic_utils.h"
|
|
#include "selection_grid.h"
|
|
#include "soundbank.h"
|
|
#include "sprite.h"
|
|
#include "version.h"
|
|
|
|
#include <stdint.h>
|
|
#include <tonc.h>
|
|
#include <tonc_math.h>
|
|
#include <tonc_memdef.h>
|
|
|
|
#define PLAY_BUTTON_MAIN_COLOR_PID 1
|
|
#define PLAY_BUTTON_OUTLINE_PID 2
|
|
#define OPTIONS_BUTTON_MAIN_COLOR_PID 3
|
|
#define OPTIONS_BUTTON_OUTLINE_PID 4
|
|
|
|
enum MainButtons
|
|
{
|
|
PLAY_BTN_IDX,
|
|
OPTIONS_BTN_IDX,
|
|
MAIN_MENU_NB_BTN
|
|
};
|
|
|
|
// Pixel sizes
|
|
#define MAIN_MENU_ACE_T_X 88
|
|
#define MAIN_MENU_ACE_T_Y 26
|
|
|
|
// clang-format off
|
|
static const BG_POINT GBALATRO_VERSION_TEXT_POS = {0, 152};
|
|
static const Rect GBALATRO_VERSION_TEXT_RECT = {0, 152, 240, 160};
|
|
// clang-format on
|
|
|
|
// Define SelectionGrid for the main menu buttons
|
|
|
|
static int main_menu_return_row_size(void);
|
|
static bool main_menu_on_selection_changed(
|
|
SelectionGrid* selection_grid,
|
|
int row_idx,
|
|
const Selection* prev_selection,
|
|
const Selection* new_selection
|
|
);
|
|
static void main_menu_on_key_transit(SelectionGrid* selection_grid, Selection* selection);
|
|
|
|
static void play_on_pressed(void);
|
|
static void options_on_pressed(void);
|
|
|
|
// clang-format off
|
|
static SelectionGridRow main_menu_selection_rows[] = {
|
|
{
|
|
0,
|
|
main_menu_return_row_size,
|
|
main_menu_on_selection_changed,
|
|
main_menu_on_key_transit,
|
|
{.wrap = false}
|
|
},
|
|
};
|
|
|
|
static Button main_menu_buttons[] = {
|
|
{PLAY_BUTTON_OUTLINE_PID, PLAY_BUTTON_MAIN_COLOR_PID, play_on_pressed, NULL},
|
|
{OPTIONS_BUTTON_OUTLINE_PID, OPTIONS_BUTTON_MAIN_COLOR_PID, options_on_pressed, NULL},
|
|
};
|
|
|
|
static SelectionGrid main_menu_selection_grid = {
|
|
main_menu_selection_rows,
|
|
1,
|
|
{0, 0}
|
|
};
|
|
// clang-format on
|
|
|
|
// Main menu sprite - the ace of spades
|
|
static CardObject* main_menu_ace = NULL;
|
|
|
|
// Keep track of last highlighted button
|
|
static enum MainButtons last_highlighted_button = PLAY_BTN_IDX;
|
|
|
|
void game_main_menu_change_background(void)
|
|
{
|
|
toggle_windows(false, false);
|
|
|
|
tte_erase_screen();
|
|
GRIT_CPY(pal_bg_mem, background_main_menu_gfxPal);
|
|
GRIT_CPY(&tile_mem[MAIN_BG_CBB], background_main_menu_gfxTiles);
|
|
GRIT_CPY(&se_mem[MAIN_BG_SBB], background_main_menu_gfxMap);
|
|
|
|
// Disable all button highlight colors
|
|
for (int i = 0; i < MAIN_MENU_NB_BTN; i++)
|
|
{
|
|
button_set_highlight(&main_menu_buttons[i], false);
|
|
}
|
|
}
|
|
|
|
void game_main_menu_on_init(void)
|
|
{
|
|
affine_background_change_background(AFFINE_BG_MAIN_MENU);
|
|
change_background(BG_MAIN_MENU, true);
|
|
main_menu_ace = card_object_new(card_new(SPADES, ACE));
|
|
card_object_set_sprite(main_menu_ace, 0);
|
|
// TODO: NULL-check sprite
|
|
main_menu_ace->sprite->obj->attr0 |= ATTR0_AFF_DBL;
|
|
main_menu_ace->tscale = float2fx(0.8f);
|
|
sprite_object_position((SpriteObject*)main_menu_ace, MAIN_MENU_ACE_T_X, MAIN_MENU_ACE_T_Y);
|
|
|
|
// Select last highlighted button, Play button by default.
|
|
// e.g. if we return from the options menu, we want the Options button to be highlighted.
|
|
Selection sel_init = {last_highlighted_button, 0};
|
|
main_menu_selection_grid.selection = sel_init;
|
|
|
|
// Highlight current button
|
|
button_set_highlight(&main_menu_buttons[main_menu_selection_grid.selection.x], true);
|
|
}
|
|
|
|
void game_main_menu_on_update(void)
|
|
{
|
|
main_menu_ace->trotation = lu_sin((g_game_vars.timer << 8) / 2) / 3;
|
|
|
|
selection_grid_process_input(&main_menu_selection_grid);
|
|
}
|
|
|
|
void game_main_menu_on_exit(void)
|
|
{
|
|
// Save selected button
|
|
last_highlighted_button = main_menu_selection_grid.selection.x;
|
|
|
|
// Normally I would just cache these and hide/unhide but I didn't feel like dealing with
|
|
// defining a layer for it
|
|
card_destroy(&main_menu_ace->card);
|
|
card_object_destroy(&main_menu_ace);
|
|
}
|
|
|
|
// Implement SelectionGrid handler functions
|
|
|
|
static int main_menu_return_row_size(void)
|
|
{
|
|
return MAIN_MENU_NB_BTN;
|
|
}
|
|
|
|
static bool main_menu_on_selection_changed(
|
|
SelectionGrid* selection_grid,
|
|
int row_idx,
|
|
const Selection* prev_selection,
|
|
const Selection* new_selection
|
|
)
|
|
{
|
|
if (prev_selection->x >= 0 && prev_selection->x < MAIN_MENU_NB_BTN)
|
|
{
|
|
button_set_highlight(&main_menu_buttons[prev_selection->x], false);
|
|
}
|
|
|
|
play_sfx(SFX_BUTTON, MM_BASE_PITCH_RATE, BUTTON_SFX_VOLUME);
|
|
button_set_highlight(&main_menu_buttons[new_selection->x], true);
|
|
|
|
return true;
|
|
}
|
|
|
|
static void main_menu_on_key_transit(SelectionGrid* selection_grid, Selection* selection)
|
|
{
|
|
// DEBUG: toggle git hash display by pressing L+R+START+SELECT
|
|
static bool combo_pressed = false;
|
|
static bool show_version = false;
|
|
if (key_is_down(KEY_START) && key_is_down(KEY_SELECT) && key_is_down(KEY_L) &&
|
|
key_is_down(KEY_R))
|
|
{
|
|
if (!combo_pressed)
|
|
{
|
|
show_version = !show_version;
|
|
if (show_version)
|
|
{
|
|
tte_printf(
|
|
"#{P:%d,%d; cx:0x%X000}%s",
|
|
GBALATRO_VERSION_TEXT_POS.x,
|
|
GBALATRO_VERSION_TEXT_POS.y,
|
|
TTE_WHITE_PB,
|
|
gbalatro_version
|
|
);
|
|
}
|
|
else
|
|
{
|
|
tte_erase_rect_wrapper(GBALATRO_VERSION_TEXT_RECT);
|
|
}
|
|
}
|
|
|
|
combo_pressed = true;
|
|
}
|
|
else
|
|
{
|
|
combo_pressed = false;
|
|
}
|
|
|
|
if (key_hit(SELECT_CARD))
|
|
{
|
|
button_press(&main_menu_buttons[selection->x]);
|
|
}
|
|
}
|
|
|
|
static void play_on_pressed(void)
|
|
{
|
|
game_change_state(GAME_STATE_RUN_SETUP);
|
|
}
|
|
|
|
static void options_on_pressed(void)
|
|
{
|
|
game_change_state(GAME_STATE_OPTIONS_MENU);
|
|
}
|