Merge pull request #108 from Lorenzooone/cash_window_consistent

Fix cash not being always formatted
This commit is contained in:
jeffman 2020-03-07 10:26:05 -05:00 committed by GitHub
commit 0bb2099850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 1 deletions

View File

@ -95,7 +95,7 @@ English names:
[00]: A menu
[01]: Money
[02]: ?
[03]: Action subject ("Who?", etc.)
[03]: Action subject ("Who?", etc.) / Money window (called by script)
[04]: New equipment selection
[05]: Offense/Defense
[06]: Equip

View File

@ -841,6 +841,60 @@ int print_string(byte *str, int x, int y)
return (charCount & 0xFFFF) | (totalWidth << 16);
}
// Edited version which recognizes the 5F FF code
// Returns: ____XXXX = number of characters printed
// XXXX____ = number of pixels printed
// x, y: pixels
int print_string_edited(byte *str, int x, int y)
{
if (str == NULL)
return 0;
byte chr;
int initial_x = x;
int charCount = 0;
while (!(str[1] == 0xFF && str[0] == 0x00))
{
if(str[1] != 0xFF)
{
x += print_character(decode_character(*str++), x, y);
charCount++;
}
else if(str[0] == 0x5F)
{
x = initial_x + str[2];
str += 3;
}
}
int totalWidth = x - initial_x;
return (charCount & 0xFFFF) | (totalWidth << 16);
}
unsigned short printstr_hlight_edited(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight)
{
return printstr_hlight_pixels_edited(window, str, x << 3, y << 4, highlight);
}
unsigned short printstr_hlight_pixels_edited(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight)
{
unsigned short printX = x + ((window->window_x) << 3);
unsigned short printY = y + ((window->window_y) << 3);
unsigned short tmpPaletteMsk = (*palette_mask);
unsigned short palette_mask_highlight = tmpPaletteMsk;
if(highlight)
palette_mask_highlight += 0x1000;
(*palette_mask) = palette_mask_highlight;
unsigned short printed_Characters = print_string_edited(str, printX, printY);
(*palette_mask) = tmpPaletteMsk;
return printed_Characters;
}
int print_menu_string(WINDOW* window)
{
byte *menu_text = window->menu_text;

View File

@ -76,6 +76,9 @@ void copy_tile(int xSource, int ySource, int xDest, int yDest);
void copy_tile_up(int x, int y);
void print_space(WINDOW *window);
int print_string(byte *str, int x, int y);
int print_string_edited(byte *str, int x, int y);
unsigned short printstr_hlight_edited(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight);
unsigned short printstr_hlight_pixels_edited(WINDOW* window, byte* str, unsigned short x, unsigned short y, bool highlight);
int print_menu_string(WINDOW* window);
void print_number_menu(WINDOW* window, int style);
void print_number_menu_current(byte digit, WINDOW* window);

View File

@ -877,6 +877,19 @@ b 0x80B8A2E
.org 0x80B785C :: mov r0,0xC // allocate 2 extra bytes for cash window string
.org 0x80B786C :: mov r3,6 // make window 1 fewer tiles wide
//---------------------------------------------------------
// B8A60 hacks (print current cash balance, called from script. Since the script is already executing,
// this version cannot use m2_printnextch, so it requires an edited version of m2_printstr_hlight which recognizes 5F FF)
//---------------------------------------------------------
.org 0x80B8A80
ldr r2,[r5,#0]
mov r1,0x30 // right-align to 48 pixels
bl format_cash_window
b 0x80B8AAA
.org 0x80B8AC0 :: bl printstr_hlight_edited
//---------------------------------------------------------
// [68 FF] - clear window
//---------------------------------------------------------