[Fixed] Joker shop price not properly erased on purchase (#286)

This commit is contained in:
Marcel Schulz
2025-12-11 07:39:09 +01:00
committed by GitHub
parent 1e1fe85b88
commit f9ed858549
3 changed files with 100 additions and 14 deletions
+11 -3
View File
@@ -4,9 +4,11 @@
#include <maxmod.h>
#include <tonc.h>
#define CARD_SPRITE_SIZE 32
#define MAX_SPRITES 128
#define MAX_SPRITE_OBJECTS 16
#define CARD_SPRITE_SIZE 32
#define MAX_AFFINES 32
#define MAX_SPRITES 128
#define MAX_SPRITE_OBJECTS 16
#define SPRITE_FOCUS_RAISE_PX 10
typedef struct
{
@@ -39,6 +41,9 @@ Sprite* sprite_new(u16 a0, u16 a1, u32 tid, u32 pb, int sprite_index);
Sprite* affine_sprite_new(u16 a0, u16 a1, u32 tid, u32 pb);
void sprite_destroy(Sprite** sprite);
int sprite_get_layer(Sprite* sprite);
bool sprite_get_dimensions(Sprite* sprite, int* width, int* height);
bool sprite_get_height(Sprite* sprite, int* height);
bool sprite_get_width(Sprite* sprite, int* width);
// Sprite functions
void sprite_init();
@@ -57,6 +62,9 @@ void sprite_object_set_selected(SpriteObject* sprite_object, bool selected);
bool sprite_object_is_selected(SpriteObject* sprite_object);
Sprite* sprite_object_get_sprite(SpriteObject* sprite_object);
void sprite_object_set_focus(SpriteObject* sprite_object, bool focus);
bool sprite_object_get_dimensions(SpriteObject* sprite_object, int* width, int* height);
bool sprite_object_get_height(SpriteObject* sprite_object, int* height);
bool sprite_object_get_width(SpriteObject* sprite_object, int* width);
bool sprite_object_is_focused(SpriteObject* sprite_object);
INLINE void sprite_position(Sprite* sprite, int x, int y)
+23 -7
View File
@@ -3517,22 +3517,38 @@ static void game_round_end_dismiss_round_end_panel()
static void print_price_under_sprite_object(SpriteObject* sprite_object, int price)
{
int height = 0;
if (sprite_object_get_height(sprite_object, &height) == false)
{
// fallback
height = CARD_SPRITE_SIZE;
}
int x = fx2int(sprite_object->tx) + TILE_SIZE - (get_digits_even(price) - 1) * TILE_SIZE;
// TODO: Should probably extract the sprite size
int y = fx2int(sprite_object->ty) + CARD_SPRITE_SIZE + TILE_SIZE;
int y = fx2int(sprite_object->ty) + height + TILE_SIZE;
tte_printf("#{P:%d,%d; cx:0x%X000}$%d", x, y, TTE_YELLOW_PB, price);
}
static void erase_price_under_sprite_object(SpriteObject* sprite_object)
{
int width = 0;
int height = 0;
if (sprite_object_get_dimensions(sprite_object, &width, &height) == false)
{
// fallback
height = CARD_SPRITE_SIZE;
width = CARD_SPRITE_SIZE;
}
Rect price_rect;
price_rect.left = fx2int(sprite_object->tx);
price_rect.top = fx2int(sprite_object->ty) + CARD_SPRITE_SIZE + TILE_SIZE;
// TODO: Should probably extract the size from the sprite
price_rect.top = fx2int(sprite_object->ty) + height + TILE_SIZE;
price_rect.right = price_rect.left + width;
price_rect.bottom = price_rect.top + TILE_SIZE + SPRITE_FOCUS_RAISE_PX;
price_rect.right = price_rect.left + TILE_SIZE * 3;
// Taking 2 tiles down so the highlighted case is also covered
price_rect.bottom = price_rect.top + 2 * TILE_SIZE;
tte_erase_rect_wrapper(price_rect);
}
+66 -4
View File
@@ -9,10 +9,7 @@
#include <maxmod.h>
#include <stdlib.h>
#include <tonc.h>
#define MAX_SPRITES 128
#define MAX_AFFINES 32
#define SPRITE_FOCUS_RAISE_PX 10
#include <tonc_oam.h>
OBJ_ATTR obj_buffer[MAX_SPRITES];
OBJ_AFFINE* obj_aff_buffer = (OBJ_AFFINE*)obj_buffer;
@@ -102,6 +99,41 @@ int sprite_get_layer(Sprite* sprite)
return sprite->obj - obj_buffer;
}
bool sprite_get_width(Sprite* sprite, int* width)
{
if (sprite == NULL || sprite->obj == NULL || width == NULL)
{
return false;
}
*width = obj_get_width(sprite->obj);
return true;
}
bool sprite_get_height(Sprite* sprite, int* height)
{
if (sprite == NULL || sprite->obj == NULL || height == NULL)
{
return false;
}
*height = obj_get_height(sprite->obj);
return true;
}
bool sprite_get_dimensions(Sprite* sprite, int* width, int* height)
{
if (sprite == NULL || sprite->obj == NULL || width == NULL || height == NULL)
{
return false;
}
const u8* size = obj_get_size(sprite->obj);
*width = size[0];
*height = size[1];
return true;
}
// Sprite functions
void sprite_init()
{
@@ -278,6 +310,36 @@ void sprite_object_set_focus(SpriteObject* sprite_object, bool focus)
sprite_object->ty = sprite_object->ty + int2fx((focus ? -1 : 1) * SPRITE_FOCUS_RAISE_PX);
}
bool sprite_object_get_width(SpriteObject* sprite_object, int* width)
{
if (sprite_object == NULL)
{
return false;
}
return sprite_get_width(sprite_object->sprite, width);
}
bool sprite_object_get_height(SpriteObject* sprite_object, int* height)
{
if (sprite_object == NULL)
{
return false;
}
return sprite_get_height(sprite_object->sprite, height);
}
bool sprite_object_get_dimensions(SpriteObject* sprite_object, int* width, int* height)
{
if (sprite_object == NULL)
{
return false;
}
return sprite_get_dimensions(sprite_object->sprite, width, height);
}
bool sprite_object_is_focused(SpriteObject* sprite_object)
{
return sprite_object->focused;