Merge branch 'main' into refactors

This commit is contained in:
MeirGavish
2025-07-20 02:28:38 +03:00
3 changed files with 53 additions and 10 deletions
+17
View File
@@ -36,6 +36,9 @@
#define SE_UP -1
#define SE_DOWN 1
#define OVERFLOW_LEFT -1
#define OVERFLOW_RIGHT 1
// Tile size in pixels, both height and width as tiles are square
#define TILE_SIZE 8
@@ -101,4 +104,18 @@ void main_bg_se_move_rect_1_tile_vert(Rect se_rect, int direction);
// A wrapper for tte_erase_rect that would use the rect struct
void tte_erase_rect_wrapper(Rect rect);
/* Changes rect->left so it fits the digits of num exactly when right aligned to rect->right.
* Assumes num is not negative.
*
* overflow_direction determines the direction the number will overflow
* if it's too large to fit inside the rect.
* Should be either OVERFLOW_LEFT or OVERFLOW_RIGHT.
*
* The rect is in number of pixels but should be a multiple of TILE_SIZE
* so it's a whole number of tiles to fit TTE characters
*
* Note that both rect->left and rect-right need to be defined, top and bottom don't matter
*/
void update_text_rect_to_right_align_num(Rect* rect, int num, int overflow_direction);
#endif //GRAPHIC_UTILS_H
+19 -10
View File
@@ -158,7 +158,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 = {32, 48, 64, 56 };
static const Rect PLAYED_CARDS_SCORES_RECT = {72, 48, 240, 56 };
static const Rect BLIND_TOKEN_TEXT_RECT = {80, 72, 200, 160 };
@@ -166,7 +166,7 @@ static const Rect MONEY_TEXT_RECT = {8, 120, 64, 120 };
static const Rect CHIPS_TEXT_RECT = {8, 80, 32, 88 };
static const Rect MULT_TEXT_RECT = {40, 80, 64, 88 };
static const Rect BLIND_REWARD_RECT = {40, 32, 64, 40 };
static const Rect BLIND_REQ_TEXT_RECT = {40, 24, 64, 32 };
static const Rect BLIND_REQ_TEXT_RECT = {32, 24, 64, 32 };
// Rects with UNDEFINED are only used in tte_printf, they need to be fully defined
// to be used with tte_erase_rect_wrapper()
@@ -175,7 +175,7 @@ static const Rect DISCARDS_TEXT_RECT = {48, 104, UNDEFINED, UNDEF
static const Rect DECK_SIZE_RECT = {200, 152, UNDEFINED, UNDEFINED };
static const Rect ROUND_TEXT_RECT = {48, 144, UNDEFINED, UNDEFINED };
static const Rect ANTE_TEXT_RECT = {8, 144, UNDEFINED, UNDEFINED };
static const Rect ROUND_END_BLIND_REQ_RECT = {112, 96, UNDEFINED, UNDEFINED };
static const Rect ROUND_END_BLIND_REQ_RECT = {112, 96, 136, UNDEFINED };
static const Rect ROUND_END_BLIND_REWARD_RECT = { 168, 96, UNDEFINED, UNDEFINED };
static const Rect ROUND_END_NUM_HANDS_RECT = {88, 116, UNDEFINED, UNDEFINED };
static const Rect HAND_REWARD_RECT = {168, UNDEFINED, UNDEFINED, UNDEFINED };
@@ -593,7 +593,7 @@ void change_background(int id)
void set_temp_score(int value)
{
int x_offset = 40 - get_digits_even(value) * 8;
int x_offset = 40 - get_digits_even(value) * TILE_SIZE;
tte_erase_rect_wrapper(TEMP_SCORE_RECT);
tte_printf("#{P:%d,%d; cx:0xF000}%d", x_offset, TEMP_SCORE_RECT.top, value);
}
@@ -613,16 +613,17 @@ void set_score(int value)
void set_money(int value)
{
int x_offset = 32 - get_digits_odd(value) * 8;
int x_offset = 32 - get_digits_odd(value) * TILE_SIZE;
tte_erase_rect_wrapper(MONEY_TEXT_RECT);
tte_printf("#{P:%d,%d; cx:0xC000}$%d", x_offset, MONEY_TEXT_RECT.top, value);
}
void set_chips(int value)
{
int x_offset = 32 - get_digits(value) * 8; // Adjust the x offset based on the number of digits in chips
Rect chips_text_rect = CHIPS_TEXT_RECT;
tte_erase_rect_wrapper(CHIPS_TEXT_RECT);
tte_printf("#{P:%d,%d; cx:0xF000;}%d", x_offset, CHIPS_TEXT_RECT.top, value);
update_text_rect_to_right_align_num(&chips_text_rect, value, OVERFLOW_LEFT);
tte_printf("#{P:%d,%d; cx:0xF000;}%d", chips_text_rect.left, chips_text_rect.top, value);
}
void set_mult(int value)
@@ -892,7 +893,11 @@ void game_round_init()
obj_hide(round_end_blind_token->obj); // Hide the blind token sprite for now
}
tte_printf("#{P:%d,%d; cx:0xE000}%d", BLIND_REQ_TEXT_RECT.left, BLIND_REQ_TEXT_RECT.top, blind_get_requirement(current_blind, ante)); // Blind requirement
Rect blind_req_text_rect = BLIND_REQ_TEXT_RECT;
int blind_requirement = blind_get_requirement(current_blind, ante);
update_text_rect_to_right_align_num(&blind_req_text_rect, blind_requirement, OVERFLOW_RIGHT);
tte_printf("#{P:%d,%d; cx:0xE000}%d", blind_req_text_rect.left, blind_req_text_rect.top, blind_requirement); // Blind requirement
tte_printf("#{P:%d,%d; cx:0xC000}$%d", BLIND_REWARD_RECT.left, BLIND_REWARD_RECT.top, blind_get_reward(current_blind)); // Blind reward
deck_shuffle(); // Shuffle the deck at the start of the round
@@ -1706,7 +1711,11 @@ void game_round_end()
int current_ante = ante;
if (current_blind == BOSS_BLIND) current_ante--; // Beating the boss blind increases the ante, so we need to display the previous ante value
tte_printf("#{P:%d,%d; cx:0xE000}%d", ROUND_END_BLIND_REQ_RECT.left, ROUND_END_BLIND_REQ_RECT.top, blind_get_requirement(current_blind, current_ante));
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);
tte_printf("#{P:%d,%d; cx:0xE000}%d", blind_req_rect.left, blind_req_rect.top, blind_req);
if (timer == 1)
{
@@ -1752,7 +1761,7 @@ void game_round_end()
{
blind_reward--;
tte_printf("#{P:%d,%d; cx:0xC000}$%d", BLIND_REWARD_RECT.left , BLIND_REWARD_RECT.top, blind_reward);
tte_printf("#{P:%d,%d; cx:0xC000}$%d", ROUND_END_BLIND_REWARD_RECT.left, ROUND_END_BLIND_REQ_RECT.top, blind_get_reward(current_blind) - blind_reward);
tte_printf("#{P:%d,%d; cx:0xC000}$%d", ROUND_END_BLIND_REWARD_RECT.left, ROUND_END_BLIND_REWARD_RECT.top, blind_get_reward(current_blind) - blind_reward);
}
else if (timer > FRAMES(20))
{
+17
View File
@@ -2,6 +2,7 @@
#include <tonc_tte.h>
#include <tonc_math.h>
#include "util.h"
#include "graphic_utils.h"
const Rect FULL_SCREENBLOCK_RECT = { 0, 0, SE_ROW_LEN - 1, SE_COL_LEN - 1};
@@ -151,3 +152,19 @@ void tte_erase_rect_wrapper(Rect rect)
tte_erase_rect(rect.left, rect.top, rect.right, rect.bottom);
}
void update_text_rect_to_right_align_num(Rect* rect, int num, int overflow_direction)
{
int num_digits = get_digits(num);
if (overflow_direction == OVERFLOW_RIGHT)
{
rect->left = max(0, rect->right - num_digits * TILE_SIZE);
}
else if (overflow_direction == OVERFLOW_LEFT)
{
int num_fitting_digits = rect_width(rect) / TILE_SIZE;
if (num_digits < num_fitting_digits)
rect->left += (num_fitting_digits - num_digits) * TILE_SIZE;
//else nothing is to be updated, entire rect is filled and may overflow
}
}