d24b0b5619
* 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>
128 lines
3.8 KiB
C
128 lines
3.8 KiB
C
#include "game/joker_row.h"
|
|
|
|
#include "game.h"
|
|
#include "game_variables.h"
|
|
#include "joker.h"
|
|
#include "layout.h"
|
|
#include "list.h"
|
|
#include "sprite.h"
|
|
#include "util.h"
|
|
|
|
int jokers_sel_row_get_size(void)
|
|
{
|
|
return list_get_len(get_jokers_list());
|
|
}
|
|
|
|
bool jokers_sel_row_on_selection_changed(
|
|
SelectionGrid* selection_grid,
|
|
int row_idx,
|
|
const Selection* prev_selection,
|
|
const Selection* new_selection
|
|
)
|
|
{
|
|
List* owned_jokers_list = get_jokers_list();
|
|
|
|
// swap Jokers if the A button is held down and all Jokers are on the same row
|
|
bool swapping =
|
|
key_is_down(SELECT_CARD) && new_selection->y == row_idx && prev_selection->y == row_idx;
|
|
|
|
if (prev_selection->y == row_idx)
|
|
{
|
|
JokerObject* joker_object =
|
|
(JokerObject*)list_get_at_idx(owned_jokers_list, prev_selection->x);
|
|
// Don't change focus from current Joker if swapping
|
|
if (joker_object != NULL && !swapping)
|
|
{
|
|
sprite_object_erase_text_under((SpriteObject*)joker_object);
|
|
sprite_object_set_focus((SpriteObject*)joker_object, false);
|
|
}
|
|
}
|
|
|
|
if (new_selection->y == row_idx)
|
|
{
|
|
JokerObject* joker_object =
|
|
(JokerObject*)list_get_at_idx(owned_jokers_list, new_selection->x);
|
|
if (joker_object != NULL)
|
|
{
|
|
if (!swapping)
|
|
{
|
|
sprite_object_set_focus((SpriteObject*)joker_object, true);
|
|
}
|
|
// If we land on this row while the A button is being held, we are in swapping mode
|
|
// This means that we need to hide the price, whether we were already
|
|
// on this row or if we come from another
|
|
if (!key_is_down(SELECT_CARD))
|
|
{
|
|
sprite_object_print_price_under(
|
|
(SpriteObject*)joker_object,
|
|
joker_get_sell_value(joker_object->joker)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (swapping)
|
|
{
|
|
list_swap(
|
|
owned_jokers_list,
|
|
(unsigned int)prev_selection->x,
|
|
(unsigned int)new_selection->x
|
|
);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static inline void joker_start_discard_animation(JokerObject* joker_object)
|
|
{
|
|
joker_object->tx = int2fx(JOKER_DISCARD_TARGET.x);
|
|
joker_object->ty = int2fx(JOKER_DISCARD_TARGET.y);
|
|
list_push_back(get_discarded_jokers_list(), joker_object);
|
|
}
|
|
|
|
static inline void game_sell_joker(int joker_idx)
|
|
{
|
|
List* owned_jokers_list = get_jokers_list();
|
|
|
|
if (joker_idx < 0 || joker_idx >= list_get_len(owned_jokers_list))
|
|
return;
|
|
|
|
JokerObject* joker_object = (JokerObject*)list_get_at_idx(owned_jokers_list, joker_idx);
|
|
g_game_vars.money += joker_get_sell_value(joker_object->joker);
|
|
display_money();
|
|
sprite_object_erase_text_under((SpriteObject*)joker_object);
|
|
|
|
remove_owned_joker(joker_idx);
|
|
|
|
joker_start_discard_animation(joker_object);
|
|
}
|
|
|
|
void jokers_sel_row_on_key_transit(SelectionGrid* selection_grid, Selection* selection)
|
|
{
|
|
JokerObject* joker_object = (JokerObject*)list_get_at_idx(get_jokers_list(), selection->x);
|
|
if (joker_object != NULL)
|
|
{
|
|
if (key_hit(SELECT_CARD))
|
|
{
|
|
sprite_object_erase_text_under((SpriteObject*)joker_object);
|
|
}
|
|
else if (key_released(SELECT_CARD))
|
|
{
|
|
sprite_object_print_price_under(
|
|
(SpriteObject*)joker_object,
|
|
joker_get_sell_value(joker_object->joker)
|
|
);
|
|
}
|
|
}
|
|
|
|
if (key_hit(SELL_KEY))
|
|
{
|
|
int sold_joker_idx = selection->x;
|
|
|
|
// Move the selection away from the jokers so it doesn't point to an invalid place
|
|
// Do this before selling the joker so valid row sizes are used
|
|
selection_grid_move_selection_vert(selection_grid, SCREEN_DOWN);
|
|
|
|
game_sell_joker(sold_joker_idx);
|
|
}
|
|
} |