Truncate Scores (#269)
* Fixed score truncation erasure, and centering for chips, mult, score and "temp score * Added centering for money * Added tests for truncate_uint_to_suffixed_str() * Fixed u32 bug with get_digits * Fixed score flames for large numbers * Small change to update documentation * Added 1 pixel on to score rect on the left to make room for full character tile + reset_top_left_panel_bottom_row() refactor * Replaced directional defines with enums * Updated ante_lut comment --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
+86
-86
@@ -342,20 +342,6 @@ static inline Card *discard_pop()
|
||||
return discard_pile[discard_top--];
|
||||
}
|
||||
|
||||
// Resets bottom row bg tiles of the top left panel (shop/blind) after
|
||||
// it is dismissed to match the rest of the game panel background.
|
||||
static inline void reset_top_left_panel_bottom_row()
|
||||
{
|
||||
int y = 6;
|
||||
|
||||
memset16(&se_mem[MAIN_BG_SBB][32 * (y - 1)], 0x0006, 1);
|
||||
memset16(&se_mem[MAIN_BG_SBB][1 + 32 * (y - 1)], 0x0007, 2);
|
||||
memset16(&se_mem[MAIN_BG_SBB][3 + 32 * (y - 1)], 0x0008, 1);
|
||||
memset16(&se_mem[MAIN_BG_SBB][4 + 32 * (y - 1)], 0x0009, 3);
|
||||
memset16(&se_mem[MAIN_BG_SBB][7 + 32 * (y - 1)], 0x000A, 1);
|
||||
memset16(&se_mem[MAIN_BG_SBB][8 + 32 * (y - 1)], 0x0406, 1);
|
||||
}
|
||||
|
||||
// get-functions, for other files to view game state (mainly for jokers)
|
||||
CardObject **get_hand_array(void)
|
||||
{
|
||||
@@ -552,6 +538,7 @@ static const Rect TOP_LEFT_PANEL_ANIM_RECT = {0, 0, 8, 4 };
|
||||
* TOP_LEFT_PANEL_ANIM_RECT should be used for animations,
|
||||
* TOP_LEFT_PANEL_RECT for copies etc. but mind the overlap
|
||||
*/
|
||||
static const Rect TOP_LEFT_PANEL_BOTTOM_ROW_RESET_RECT = {0, 28, 8, 28 };
|
||||
static const BG_POINT TOP_LEFT_BLIND_TITLE_POINT = {0, 21, };
|
||||
static const Rect BIG_BLIND_TITLE_SRC_RECT = {0, 26, 8, 26 };
|
||||
static const Rect BOSS_BLIND_TITLE_SRC_RECT = {0, 27, 8, 27 };
|
||||
@@ -580,7 +567,7 @@ static const Rect HAND_SIZE_RECT_PLAYING = {128, 152, 152, 160 };
|
||||
static const Rect HAND_TYPE_RECT = {8, 64, 64, 72 };
|
||||
// Score displayed in the same place as the hand type
|
||||
static const Rect TEMP_SCORE_RECT = {8, 64, 64, 72 };
|
||||
static const Rect SCORE_RECT = {32, 48, 64, 56 };
|
||||
static const Rect SCORE_RECT = {24, 48, 64, 56 };
|
||||
|
||||
static const Rect PLAYED_CARDS_SCORES_RECT = {72, 48, 240, 56 };
|
||||
static const Rect HELD_CARDS_SCORES_RECT = {72, 108, 240, 116 };
|
||||
@@ -647,9 +634,6 @@ static const BG_POINT MAIN_MENU_ACE_T = {88, 26};
|
||||
#define STARTING_MONEY 4
|
||||
#define STARTING_SCORE 0
|
||||
|
||||
#define TEN_K 10000
|
||||
#define ONE_K 1000
|
||||
|
||||
#define CARD_FOCUSED_UNSEL_Y 10
|
||||
#define CARD_UNFOCUSED_SEL_Y 15
|
||||
#define CARD_FOCUSED_SEL_Y 20
|
||||
@@ -886,6 +870,16 @@ void bg_copy_current_item_to_top_left_panel()
|
||||
main_bg_se_copy_rect(TOP_LEFT_ITEM_SRC_RECT, TOP_LEFT_PANEL_POINT);
|
||||
}
|
||||
|
||||
// Resets bottom row bg tiles of the top left panel (shop/blind) after
|
||||
// it is dismissed to match the rest of the game panel background.
|
||||
static inline void reset_top_left_panel_bottom_row()
|
||||
{
|
||||
BG_POINT top_left_panel_bottom_row_pos = TOP_LEFT_PANEL_POINT;
|
||||
// Use the source rect height to offset to the bottom row point
|
||||
top_left_panel_bottom_row_pos.y += rect_height(&TOP_LEFT_ITEM_SRC_RECT) - 1;
|
||||
main_bg_se_copy_rect(TOP_LEFT_PANEL_BOTTOM_ROW_RESET_RECT, top_left_panel_bottom_row_pos);
|
||||
}
|
||||
|
||||
void change_background(enum BackgroundId id)
|
||||
{
|
||||
if (background == id)
|
||||
@@ -948,7 +942,7 @@ void change_background(enum BackgroundId id)
|
||||
|
||||
for (int i = 0; i <= 2; i++)
|
||||
{
|
||||
main_bg_se_move_rect_1_tile_vert(HAND_BG_RECT_SELECTING, SE_DOWN);
|
||||
main_bg_se_move_rect_1_tile_vert(HAND_BG_RECT_SELECTING, SCREEN_DOWN);
|
||||
}
|
||||
|
||||
tte_erase_rect_wrapper(HAND_SIZE_RECT_SELECT);
|
||||
@@ -1046,7 +1040,7 @@ void change_background(enum BackgroundId id)
|
||||
int x_from = 0;
|
||||
int y_from = 27;
|
||||
|
||||
main_bg_se_copy_rect_1_tile_vert(curr_blind_rect, SE_UP);
|
||||
main_bg_se_copy_rect_1_tile_vert(curr_blind_rect, SCREEN_UP);
|
||||
|
||||
int x_to = curr_blind_rect.left;
|
||||
int y_to = 31;
|
||||
@@ -1129,53 +1123,49 @@ void change_background(enum BackgroundId id)
|
||||
|
||||
void display_temp_score(u32 value)
|
||||
{
|
||||
int x_offset = 40 - get_digits_even(value) * TILE_SIZE;
|
||||
char temp_score_str_buff[UINT_MAX_DIGITS + 1];
|
||||
Rect temp_score_rect = TEMP_SCORE_RECT;
|
||||
truncate_uint_to_suffixed_str(value, rect_width(&temp_score_rect)/TTE_CHAR_SIZE, temp_score_str_buff);
|
||||
update_text_rect_to_center_str(&temp_score_rect, temp_score_str_buff, SCREEN_RIGHT);
|
||||
|
||||
tte_erase_rect_wrapper(TEMP_SCORE_RECT);
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000}%lu", x_offset, TEMP_SCORE_RECT.top, TTE_WHITE_PB, value);
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000}%s", temp_score_rect.left, temp_score_rect.top, TTE_WHITE_PB, temp_score_str_buff);
|
||||
}
|
||||
|
||||
void display_score(u32 value)
|
||||
{
|
||||
Rect score_rect = SCORE_RECT;
|
||||
// Clear the existing text before redrawing
|
||||
tte_erase_rect_wrapper(SCORE_RECT);
|
||||
|
||||
char score_suffix = ' ';
|
||||
u32 display_value = value;
|
||||
char score_str_buff[UINT_MAX_DIGITS + 1];
|
||||
|
||||
truncate_uint_to_suffixed_str(value, rect_width(&score_rect)/TTE_CHAR_SIZE, score_str_buff);
|
||||
update_text_rect_to_center_str(&score_rect, score_str_buff, SCREEN_RIGHT);
|
||||
|
||||
if(value >= TEN_K)
|
||||
{
|
||||
score_suffix = 'k';
|
||||
display_value = value / ONE_K; // 12,986 = 12k
|
||||
}
|
||||
|
||||
// Calculate text width: digits + suffix character (if 'k')
|
||||
int num_digits = get_digits(display_value);
|
||||
int text_width = num_digits * TILE_SIZE;
|
||||
if(score_suffix == 'k')
|
||||
{
|
||||
text_width += TILE_SIZE; // Add width for 'k' suffix
|
||||
}
|
||||
|
||||
// Calculate center position within SCORE_RECT
|
||||
int rect_width = SCORE_RECT.right - SCORE_RECT.left;
|
||||
int x_offset = SCORE_RECT.left + (rect_width - text_width) / 2;
|
||||
|
||||
tte_printf("#{P:%d,48; cx:0x%X000}%lu%c", x_offset, TTE_WHITE_PB, display_value, score_suffix);
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000}%s", score_rect.left, score_rect.top, TTE_WHITE_PB, score_str_buff);
|
||||
}
|
||||
|
||||
void display_money()
|
||||
{
|
||||
int x_offset = 32 - get_digits_odd(money) * TILE_SIZE;
|
||||
Rect money_text_rect = MONEY_TEXT_RECT;
|
||||
tte_erase_rect_wrapper(MONEY_TEXT_RECT);
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000}$%d", x_offset, MONEY_TEXT_RECT.top, TTE_YELLOW_PB, money);
|
||||
|
||||
char money_str_buff[INT_MAX_DIGITS + 2]; // + 2 for null terminator and "$" sign
|
||||
snprintf(money_str_buff, sizeof(money_str_buff), "$%d", money);
|
||||
|
||||
// Bias left so the number is centered and the "$" sign is on the left
|
||||
update_text_rect_to_center_str(&money_text_rect, money_str_buff, SCREEN_LEFT);
|
||||
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000}%s", money_text_rect.left, money_text_rect.top, TTE_YELLOW_PB, money_str_buff);
|
||||
}
|
||||
|
||||
// Show/Hide flaming score effect if we will score
|
||||
// more than the required amount or not
|
||||
void check_flaming_score()
|
||||
{
|
||||
int curr_score = chips * mult;
|
||||
int required_score = blind_get_requirement(current_blind, ante);
|
||||
u32 curr_score = u32_protected_mult(chips, mult);
|
||||
u32 required_score = blind_get_requirement(current_blind, ante);
|
||||
if (curr_score >= required_score && !score_flames_active)
|
||||
{
|
||||
// start flaming score
|
||||
@@ -1198,16 +1188,32 @@ void check_flaming_score()
|
||||
void display_chips()
|
||||
{
|
||||
Rect chips_text_rect = CHIPS_TEXT_RECT;
|
||||
tte_erase_rect_wrapper(CHIPS_TEXT_RECT);
|
||||
update_text_rect_to_right_align_num(&chips_text_rect, chips, OVERFLOW_LEFT);
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000;}%lu", chips_text_rect.left, chips_text_rect.top, TTE_WHITE_PB, chips);
|
||||
|
||||
// In case of overflow, the rect overflow left by 1 char
|
||||
Rect chips_text_overflow_rect = chips_text_rect;
|
||||
chips_text_overflow_rect.left -= TTE_CHAR_SIZE;
|
||||
tte_erase_rect_wrapper(chips_text_overflow_rect);
|
||||
|
||||
char chips_str_buff[UINT_MAX_DIGITS + 1];
|
||||
truncate_uint_to_suffixed_str(chips, rect_width(&chips_text_rect)/TTE_CHAR_SIZE, chips_str_buff);
|
||||
|
||||
update_text_rect_to_right_align_str(&chips_text_rect, chips_str_buff, OVERFLOW_LEFT);
|
||||
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000;}%s", chips_text_rect.left, chips_text_rect.top, TTE_WHITE_PB, chips_str_buff);
|
||||
check_flaming_score();
|
||||
}
|
||||
|
||||
void display_mult()
|
||||
{
|
||||
tte_erase_rect_wrapper(MULT_TEXT_RECT);
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000;}%lu", MULT_TEXT_RECT.left, MULT_TEXT_RECT.top, TTE_WHITE_PB, mult);
|
||||
Rect mult_text_overflow_rect = MULT_TEXT_RECT;
|
||||
// In case of overflow the rect will overflow right by 1 char
|
||||
mult_text_overflow_rect.right += TTE_CHAR_SIZE;
|
||||
tte_erase_rect_wrapper(mult_text_overflow_rect);
|
||||
|
||||
char mult_str_buff[UINT_MAX_DIGITS + 1];
|
||||
truncate_uint_to_suffixed_str(mult, rect_width(&MULT_TEXT_RECT)/TTE_CHAR_SIZE, mult_str_buff);
|
||||
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000;}%s", MULT_TEXT_RECT.left, MULT_TEXT_RECT.top, TTE_WHITE_PB, mult_str_buff);
|
||||
check_flaming_score();
|
||||
}
|
||||
|
||||
@@ -1415,30 +1421,16 @@ static void game_round_on_init()
|
||||
}
|
||||
|
||||
Rect blind_req_text_rect = BLIND_REQ_TEXT_RECT;
|
||||
int blind_requirement = blind_get_requirement(current_blind, ante);
|
||||
u32 blind_requirement = blind_get_requirement(current_blind, ante);
|
||||
|
||||
// TODO: Address Copilot review at
|
||||
// https://github.com/cellos51/balatro-gba/pull/46#pullrequestreview-3045772903
|
||||
char score_suffix = ' ';
|
||||
if(blind_requirement >= TEN_K)
|
||||
{
|
||||
// clear existing text
|
||||
tte_erase_rect_wrapper(blind_req_text_rect);
|
||||
|
||||
score_suffix = 'k';
|
||||
blind_requirement /= ONE_K; // 11,000 = 11k
|
||||
}
|
||||
char blind_req_str_buff[UINT_MAX_DIGITS + 1];
|
||||
|
||||
truncate_uint_to_suffixed_str(blind_requirement, rect_width(&BLIND_REQ_TEXT_RECT)/TTE_CHAR_SIZE, blind_req_str_buff);
|
||||
|
||||
// Update text rect for right alignment AFTER shortening the number
|
||||
update_text_rect_to_right_align_num(&blind_req_text_rect, blind_requirement, OVERFLOW_RIGHT);
|
||||
|
||||
// If we added a suffix, adjust position to account for the extra character
|
||||
if(score_suffix == 'k')
|
||||
{
|
||||
blind_req_text_rect.left -= TILE_SIZE; // Move left by one character width to make room for 'k'
|
||||
}
|
||||
update_text_rect_to_right_align_str(&blind_req_text_rect, blind_req_str_buff, OVERFLOW_RIGHT);
|
||||
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000}%d%c", blind_req_text_rect.left, blind_req_text_rect.top, TTE_RED_PB, blind_requirement, score_suffix); // Blind requirement
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000}%s", blind_req_text_rect.left, blind_req_text_rect.top, TTE_RED_PB, blind_req_str_buff);
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000}$%d", BLIND_REWARD_RECT.left, BLIND_REWARD_RECT.top, TTE_YELLOW_PB, blind_get_reward(current_blind)); // Blind reward
|
||||
|
||||
deck_shuffle(); // Shuffle the deck at the start of the round
|
||||
@@ -2748,7 +2740,7 @@ static void game_round_end_start()
|
||||
|
||||
static void game_round_end_start_expand_popup()
|
||||
{
|
||||
main_bg_se_copy_rect_1_tile_vert(POP_MENU_ANIM_RECT, SE_UP);
|
||||
main_bg_se_copy_rect_1_tile_vert(POP_MENU_ANIM_RECT, SCREEN_UP);
|
||||
|
||||
if (timer == TM_END_POP_MENU_ANIM)
|
||||
{
|
||||
@@ -2762,7 +2754,7 @@ static void game_round_end_extend_black_panel_down(int black_panel_bottom)
|
||||
Rect single_line_rect = ROUND_END_MENU_RECT;
|
||||
single_line_rect.bottom = black_panel_bottom;
|
||||
single_line_rect.top = single_line_rect.bottom - 1;
|
||||
main_bg_se_copy_rect_1_tile_vert(single_line_rect, SE_DOWN);
|
||||
main_bg_se_copy_rect_1_tile_vert(single_line_rect, SCREEN_DOWN);
|
||||
}
|
||||
|
||||
static void game_round_end_display_finished_blind()
|
||||
@@ -2773,10 +2765,18 @@ static void game_round_end_display_finished_blind()
|
||||
if (current_blind == BLIND_TYPE_BOSS) current_ante--; // Beating the boss blind increases the ante, so we need to display the previous ante value
|
||||
|
||||
Rect blind_req_rect = ROUND_END_BLIND_REQ_RECT;
|
||||
int blind_req = blind_get_requirement(current_blind, current_ante);
|
||||
update_text_rect_to_right_align_num(&blind_req_rect, blind_req, OVERFLOW_RIGHT);
|
||||
u32 blind_req = blind_get_requirement(current_blind, current_ante);
|
||||
|
||||
/* Not bothering to truncate here because there are 8 tiles
|
||||
* and the blind requirement will not increase past ante 8
|
||||
* so there's enough room for sure.
|
||||
*/
|
||||
char blind_req_str_buff[UINT_MAX_DIGITS + 1];
|
||||
snprintf(blind_req_str_buff, sizeof(blind_req_str_buff), "%lu", blind_req);
|
||||
|
||||
update_text_rect_to_right_align_str(&blind_req_rect, blind_req_str_buff, OVERFLOW_RIGHT);
|
||||
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000}%d", blind_req_rect.left, blind_req_rect.top, TTE_RED_PB, blind_req);
|
||||
tte_printf("#{P:%d,%d; cx:0x%X000}%s", blind_req_rect.left, blind_req_rect.top, TTE_RED_PB, blind_req_str_buff);
|
||||
|
||||
if (timer == TM_START_ROUND_END_REWARDS_ANIM)
|
||||
{
|
||||
@@ -2836,7 +2836,7 @@ static void game_round_end_panel_exit()
|
||||
// magic numbers.
|
||||
if (timer < 8)
|
||||
{
|
||||
main_bg_se_copy_rect_1_tile_vert(TOP_LEFT_PANEL_ANIM_RECT, SE_UP);
|
||||
main_bg_se_copy_rect_1_tile_vert(TOP_LEFT_PANEL_ANIM_RECT, SCREEN_UP);
|
||||
|
||||
if (timer == 1) // Copied from shop. Feels slightly too niche of a function for me personally to make one.
|
||||
{
|
||||
@@ -2989,7 +2989,7 @@ static void game_round_end_dismiss_round_end_panel()
|
||||
{
|
||||
Rect round_end_down = ROUND_END_MENU_RECT;
|
||||
round_end_down.top--;
|
||||
main_bg_se_copy_rect_1_tile_vert(round_end_down, SE_DOWN);
|
||||
main_bg_se_copy_rect_1_tile_vert(round_end_down, SCREEN_DOWN);
|
||||
|
||||
if (timer >= TM_DISMISS_ROUND_END_TM)
|
||||
{
|
||||
@@ -3115,7 +3115,7 @@ static void game_shop_create_items()
|
||||
// Intro sequence (menu and shop icon coming into frame)
|
||||
static void game_shop_intro()
|
||||
{
|
||||
main_bg_se_copy_rect_1_tile_vert(POP_MENU_ANIM_RECT, SE_UP);
|
||||
main_bg_se_copy_rect_1_tile_vert(POP_MENU_ANIM_RECT, SCREEN_UP);
|
||||
|
||||
if (timer == TM_CREATE_SHOP_ITEMS_WAIT)
|
||||
{
|
||||
@@ -3426,9 +3426,9 @@ static void game_shop_lights_anim_frame()
|
||||
static void game_shop_outro()
|
||||
{
|
||||
// Shift the shop panel
|
||||
main_bg_se_move_rect_1_tile_vert(POP_MENU_ANIM_RECT, SE_DOWN);
|
||||
main_bg_se_move_rect_1_tile_vert(POP_MENU_ANIM_RECT, SCREEN_DOWN);
|
||||
|
||||
main_bg_se_copy_rect_1_tile_vert(TOP_LEFT_PANEL_ANIM_RECT, SE_UP);
|
||||
main_bg_se_copy_rect_1_tile_vert(TOP_LEFT_PANEL_ANIM_RECT, SCREEN_UP);
|
||||
|
||||
// TODO: make heads or tails of what's going on here and replace
|
||||
// magic numbers.
|
||||
@@ -3531,7 +3531,7 @@ static void game_blind_select_on_update()
|
||||
static void game_blind_select_start_anim_seq()
|
||||
{
|
||||
change_background(BG_BLIND_SELECT);
|
||||
main_bg_se_copy_rect_1_tile_vert(POP_MENU_ANIM_RECT, SE_UP);
|
||||
main_bg_se_copy_rect_1_tile_vert(POP_MENU_ANIM_RECT, SCREEN_UP);
|
||||
|
||||
for (int i = 0; i < BLIND_TYPE_MAX; i++)
|
||||
{
|
||||
@@ -3579,7 +3579,7 @@ static void game_blind_select_handle_input()
|
||||
// TODO: Create a generic vertical move by any number of tiles to avoid for loops?
|
||||
for (int i = 0; i < 12; i++)
|
||||
{
|
||||
main_bg_se_copy_rect_1_tile_vert(POP_MENU_ANIM_RECT, SE_UP);
|
||||
main_bg_se_copy_rect_1_tile_vert(POP_MENU_ANIM_RECT, SCREEN_UP);
|
||||
}
|
||||
|
||||
for (int i = 0; i < BLIND_TYPE_MAX; i++)
|
||||
@@ -3611,7 +3611,7 @@ static void game_blind_select_selected_anim_seq()
|
||||
{
|
||||
Rect blinds_rect = POP_MENU_ANIM_RECT;
|
||||
blinds_rect.top -= 1; // Because of the raised blind
|
||||
main_bg_se_move_rect_1_tile_vert(blinds_rect, SE_DOWN);
|
||||
main_bg_se_move_rect_1_tile_vert(blinds_rect, SCREEN_DOWN);
|
||||
|
||||
for (int i = 0; i < BLIND_TYPE_MAX; i++)
|
||||
{
|
||||
@@ -3817,7 +3817,7 @@ static void jokers_update_loop()
|
||||
|
||||
static void game_over_anim_frame()
|
||||
{
|
||||
main_bg_se_move_rect_1_tile_vert(GAME_OVER_ANIM_RECT, SE_UP);
|
||||
main_bg_se_move_rect_1_tile_vert(GAME_OVER_ANIM_RECT, SCREEN_UP);
|
||||
}
|
||||
|
||||
static void game_lose_on_update()
|
||||
|
||||
Reference in New Issue
Block a user