Allow users to increase MAX_MONEY (#4943)

* Added GetMaxNumMoneyDigits and GetMoneyBoxHorizontalPosition to header
Replaced use of PrintMoneyAmount

* Added define for MAX_MONEY_DIGITS
Removed GetMaxNumMoneyDigits
Converted uses of ConvertIntToDecimalStringN that called for 7 money digits to use MAX_MONEY_DIGITS
Replaced 6 money digits in PrintMoneyAmount with MAX_MONEY_DIGITS

* Use preproc and MAX_MONEY_DIGITS to increase the width of the sell item money box

* Added GetItemSoldMoneyHorizonalPosition and fixed ConvertInt in PrintMoneyAmount to use MAX_MONEY_DIGITS

* Added GetItemSoldMoneyHorizonalPosition and fixed ConvertInt in PrintMoneyAmount to use MAX_MONEY_DIGITS

* Removed width and tilemap changes

* Modified CountDigits to count digits greater than 1
Fixed PrintMoneyAmount to work with large digits

* Added an early return to PrependFontIdToFit

* First prototype working

* Updated GetMoneyBoxHorizontalPosition with amount

* Updated GetMoneyBoxHorizontalPosition with amount

* Got version working with one space before

* Got version working with one space before

* Got version working with all spacingOC

* cleaned up PrintMoneyAmount

* Created CalculateleadingSpacesForMoney

* Cleaned up for PR

* Changed tabs to spaces per https://github.com/rh-hideout/pokeemerald-expansion/pull/4943\#issuecomment-2223023365
This commit is contained in:
psf 2024-07-13 02:16:34 -07:00 committed by GitHub
parent 7c23a39c5e
commit 522a8ba3f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 58 additions and 37 deletions

View file

@ -2155,21 +2155,17 @@ u32 GetFontIdToFit(const u8 *string, u32 fontId, u32 letterSpacing, u32 widthPx)
u8 *PrependFontIdToFit(u8 *start, u8 *end, u32 fontId, u32 width) u8 *PrependFontIdToFit(u8 *start, u8 *end, u32 fontId, u32 width)
{ {
u32 fitFontId = GetFontIdToFit(start, fontId, 0, width); u32 fitFontId = GetFontIdToFit(start, fontId, 0, width);
if (fitFontId != fontId)
{ if (fitFontId == fontId)
memmove(&start[3], &start[0], end - start);
start[0] = EXT_CTRL_CODE_BEGIN;
start[1] = EXT_CTRL_CODE_FONT;
start[2] = fitFontId;
end[3] = EOS;
return end + 3;
}
else
{
return end; return end;
}
memmove(&start[3], &start[0], end - start);
start[0] = EXT_CTRL_CODE_BEGIN;
start[1] = EXT_CTRL_CODE_FONT;
start[2] = fitFontId;
end[3] = EOS;
return end + 3;
} }
u8 *WrapFontIdToFit(u8 *start, u8 *end, u32 fontId, u32 width) u8 *WrapFontIdToFit(u8 *start, u8 *end, u32 fontId, u32 width)

View file

@ -1,7 +1,17 @@
#ifndef GUARD_MONEY_H #ifndef GUARD_MONEY_H
#define GUARD_MONEY_H #define GUARD_MONEY_H
#define MAX_MONEY 999999 #define MAX_MONEY 999999 // Can be increased to INT_MAX
#define MAX_MONEY_DIGITS ((MAX_MONEY > 999999999) ? 10 : \
(MAX_MONEY > 99999999) ? 9 : \
(MAX_MONEY > 9999999) ? 8 : \
(MAX_MONEY > 999999) ? 7 : \
(MAX_MONEY > 99999) ? 6 : \
(MAX_MONEY > 9999) ? 5 : \
(MAX_MONEY > 999) ? 4 : \
(MAX_MONEY > 99) ? 3 : \
(MAX_MONEY > 9) ? 2 : 1)
u32 GetMoney(u32 *moneyPtr); u32 GetMoney(u32 *moneyPtr);
void SetMoney(u32 *moneyPtr, u32 newValue); void SetMoney(u32 *moneyPtr, u32 newValue);
@ -18,5 +28,6 @@ void DrawMoneyBox(int amount, u8 x, u8 y);
void HideMoneyBox(void); void HideMoneyBox(void);
void AddMoneyLabelObject(u16 x, u16 y); void AddMoneyLabelObject(u16 x, u16 y);
void RemoveMoneyLabelObject(void); void RemoveMoneyLabelObject(void);
u32 CalculateMoneyTextHorizontalPosition(u32 amount);
#endif // GUARD_MONEY_H #endif // GUARD_MONEY_H

View file

@ -1225,7 +1225,7 @@ static void PrintItemSoldAmount(int windowId, int numSold, int moneyEarned)
ConvertIntToDecimalStringN(gStringVar1, numSold, STR_CONV_MODE_LEADING_ZEROS, MAX_ITEM_DIGITS); ConvertIntToDecimalStringN(gStringVar1, numSold, STR_CONV_MODE_LEADING_ZEROS, MAX_ITEM_DIGITS);
StringExpandPlaceholders(gStringVar4, gText_xVar1); StringExpandPlaceholders(gStringVar4, gText_xVar1);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gStringVar4, 0, 1, TEXT_SKIP_DRAW, 0); AddTextPrinterParameterized(windowId, FONT_NORMAL, gStringVar4, 0, 1, TEXT_SKIP_DRAW, 0);
PrintMoneyAmount(windowId, 38, 1, moneyEarned, 0); PrintMoneyAmount(windowId, CalculateMoneyTextHorizontalPosition(moneyEarned), 1, moneyEarned, 0);
} }
static void Task_BagMenu_HandleInput(u8 taskId) static void Task_BagMenu_HandleInput(u8 taskId)
@ -2129,7 +2129,7 @@ static void DisplaySellItemPriceAndConfirm(u8 taskId)
{ {
s16 *data = gTasks[taskId].data; s16 *data = gTasks[taskId].data;
ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / ITEM_SELL_FACTOR) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, 6); ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / ITEM_SELL_FACTOR) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_MONEY_DIGITS);
StringExpandPlaceholders(gStringVar4, gText_ICanPayVar1); StringExpandPlaceholders(gStringVar4, gText_ICanPayVar1);
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, AskSellItems); DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, AskSellItems);
} }
@ -2189,7 +2189,7 @@ static void ConfirmSell(u8 taskId)
s16 *data = gTasks[taskId].data; s16 *data = gTasks[taskId].data;
CopyItemName(gSpecialVar_ItemId, gStringVar2); CopyItemName(gSpecialVar_ItemId, gStringVar2);
ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / ITEM_SELL_FACTOR) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, 6); ConvertIntToDecimalStringN(gStringVar1, (ItemId_GetPrice(gSpecialVar_ItemId) / ITEM_SELL_FACTOR) * tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_MONEY_DIGITS);
StringExpandPlaceholders(gStringVar4, gText_TurnedOverVar1ForVar2); StringExpandPlaceholders(gStringVar4, gText_TurnedOverVar1ForVar2);
DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, SellItem); DisplayItemMessage(taskId, FONT_NORMAL, gStringVar4, SellItem);
} }

View file

@ -9,6 +9,7 @@
#include "sprite.h" #include "sprite.h"
#include "strings.h" #include "strings.h"
#include "decompress.h" #include "decompress.h"
#include "tv.h"
EWRAM_DATA static u8 sMoneyBoxWindowId = 0; EWRAM_DATA static u8 sMoneyBoxWindowId = 0;
EWRAM_DATA static u8 sMoneyLabelSpriteId = 0; EWRAM_DATA static u8 sMoneyLabelSpriteId = 0;
@ -130,23 +131,33 @@ void SubtractMoneyFromVar0x8005(void)
void PrintMoneyAmountInMoneyBox(u8 windowId, int amount, u8 speed) void PrintMoneyAmountInMoneyBox(u8 windowId, int amount, u8 speed)
{ {
PrintMoneyAmount(windowId, 38, 1, amount, speed); PrintMoneyAmount(windowId, CalculateMoneyTextHorizontalPosition(amount), 1, amount, speed);
}
static u32 CalculateLeadingSpacesForMoney(u32 numDigits)
{
u32 leadingSpaces = CountDigits(INT_MAX) - StringLength(gStringVar1);
return (numDigits > 8) ? leadingSpaces : leadingSpaces - 2;
} }
void PrintMoneyAmount(u8 windowId, u8 x, u8 y, int amount, u8 speed) void PrintMoneyAmount(u8 windowId, u8 x, u8 y, int amount, u8 speed)
{ {
u8 *txtPtr; u8 *txtPtr = gStringVar4;
s32 strLength; u32 numDigits = CountDigits(amount);
u32 maxDigits = (numDigits > 6) ? MAX_MONEY_DIGITS: 6;
u32 leadingSpaces;
ConvertIntToDecimalStringN(gStringVar1, amount, STR_CONV_MODE_LEFT_ALIGN, 6); ConvertIntToDecimalStringN(gStringVar1, amount, STR_CONV_MODE_LEFT_ALIGN, maxDigits);
strLength = 6 - StringLength(gStringVar1); leadingSpaces = CalculateLeadingSpacesForMoney(numDigits);
txtPtr = gStringVar4;
while (strLength-- > 0) while (leadingSpaces-- > 0)
*(txtPtr++) = CHAR_SPACER; *(txtPtr++) = CHAR_SPACER;
StringExpandPlaceholders(txtPtr, gText_PokedollarVar1); StringExpandPlaceholders(txtPtr, gText_PokedollarVar1);
if (numDigits > 8)
PrependFontIdToFit(gStringVar4, txtPtr + 1 + numDigits, FONT_NORMAL, 54);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gStringVar4, x, y, speed, NULL); AddTextPrinterParameterized(windowId, FONT_NORMAL, gStringVar4, x, y, speed, NULL);
} }
@ -161,6 +172,11 @@ void ChangeAmountInMoneyBox(int amount)
PrintMoneyAmountInMoneyBox(sMoneyBoxWindowId, amount, 0); PrintMoneyAmountInMoneyBox(sMoneyBoxWindowId, amount, 0);
} }
u32 CalculateMoneyTextHorizontalPosition(u32 amount)
{
return (CountDigits(amount) > 8) ? 34 : 26;
}
void DrawMoneyBox(int amount, u8 x, u8 y) void DrawMoneyBox(int amount, u8 x, u8 y)
{ {
struct WindowTemplate template; struct WindowTemplate template;

View file

@ -1035,7 +1035,7 @@ static void Task_BuyMenu(u8 taskId)
else else
{ {
StringCopy(gStringVar1, gDecorations[itemId].name); StringCopy(gStringVar1, gDecorations[itemId].name);
ConvertIntToDecimalStringN(gStringVar2, sShopData->totalCost, STR_CONV_MODE_LEFT_ALIGN, 6); ConvertIntToDecimalStringN(gStringVar2, sShopData->totalCost, STR_CONV_MODE_LEFT_ALIGN, MAX_MONEY_DIGITS);
if (sMartInfo.martType == MART_TYPE_DECOR) if (sMartInfo.martType == MART_TYPE_DECOR)
StringExpandPlaceholders(gStringVar4, gText_Var1IsItThatllBeVar2); StringExpandPlaceholders(gStringVar4, gText_Var1IsItThatllBeVar2);
@ -1097,7 +1097,7 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId)
PutWindowTilemap(WIN_ITEM_LIST); PutWindowTilemap(WIN_ITEM_LIST);
CopyItemName(tItemId, gStringVar1); CopyItemName(tItemId, gStringVar1);
ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_ITEM_DIGITS); ConvertIntToDecimalStringN(gStringVar2, tItemCount, STR_CONV_MODE_LEFT_ALIGN, MAX_ITEM_DIGITS);
ConvertIntToDecimalStringN(gStringVar3, sShopData->totalCost, STR_CONV_MODE_LEFT_ALIGN, 6); ConvertIntToDecimalStringN(gStringVar3, sShopData->totalCost, STR_CONV_MODE_LEFT_ALIGN, MAX_MONEY_DIGITS);
BuyMenuDisplayMessage(taskId, gText_Var1AndYouWantedVar2, BuyMenuConfirmPurchase); BuyMenuDisplayMessage(taskId, gText_Var1AndYouWantedVar2, BuyMenuConfirmPurchase);
} }
else if (JOY_NEW(B_BUTTON)) else if (JOY_NEW(B_BUTTON))
@ -1226,7 +1226,7 @@ static void BuyMenuPrintItemQuantityAndPrice(u8 taskId)
s16 *data = gTasks[taskId].data; s16 *data = gTasks[taskId].data;
FillWindowPixelBuffer(WIN_QUANTITY_PRICE, PIXEL_FILL(1)); FillWindowPixelBuffer(WIN_QUANTITY_PRICE, PIXEL_FILL(1));
PrintMoneyAmount(WIN_QUANTITY_PRICE, 38, 1, sShopData->totalCost, TEXT_SKIP_DRAW); PrintMoneyAmount(WIN_QUANTITY_PRICE, CalculateMoneyTextHorizontalPosition(sShopData->totalCost), 1, sShopData->totalCost, TEXT_SKIP_DRAW);
ConvertIntToDecimalStringN(gStringVar1, tItemCount, STR_CONV_MODE_LEADING_ZEROS, MAX_ITEM_DIGITS); ConvertIntToDecimalStringN(gStringVar1, tItemCount, STR_CONV_MODE_LEADING_ZEROS, MAX_ITEM_DIGITS);
StringExpandPlaceholders(gStringVar4, gText_xVar1); StringExpandPlaceholders(gStringVar4, gText_xVar1);
BuyMenuPrint(WIN_QUANTITY_PRICE, gStringVar4, 0, 1, 0, COLORID_NORMAL); BuyMenuPrint(WIN_QUANTITY_PRICE, gStringVar4, 0, 1, 0, COLORID_NORMAL);

View file

@ -1045,7 +1045,7 @@ static void PrintMoneyOnCard(void)
else else
AddTextPrinterParameterized3(WIN_CARD_TEXT, FONT_NORMAL, 16, 57, sTrainerCardTextColors, TEXT_SKIP_DRAW, gText_TrainerCardMoney); AddTextPrinterParameterized3(WIN_CARD_TEXT, FONT_NORMAL, 16, 57, sTrainerCardTextColors, TEXT_SKIP_DRAW, gText_TrainerCardMoney);
ConvertIntToDecimalStringN(gStringVar1, sData->trainerCard.money, STR_CONV_MODE_LEFT_ALIGN, 6); ConvertIntToDecimalStringN(gStringVar1, sData->trainerCard.money, STR_CONV_MODE_LEFT_ALIGN, MAX_MONEY_DIGITS);
StringExpandPlaceholders(gStringVar4, gText_PokedollarVar1); StringExpandPlaceholders(gStringVar4, gText_PokedollarVar1);
if (!sData->isHoenn) if (!sData->isHoenn)
{ {

View file

@ -2760,16 +2760,14 @@ void ConvertIntToDecimalString(u8 varIdx, int value)
size_t CountDigits(int value) size_t CountDigits(int value)
{ {
if (value / 10 == 0) return 1; u32 count = 0;
if (value / 100 == 0) return 2;
if (value / 1000 == 0) return 3;
if (value / 10000 == 0) return 4;
if (value / 100000 == 0) return 5;
if (value / 1000000 == 0) return 6;
if (value / 10000000 == 0) return 7;
if (value / 100000000 == 0) return 8;
return 1; while (value > 0)
{
value /= 10;
count++;
}
return count;
} }
static void SmartShopper_BufferPurchaseTotal(u8 varIdx, TVShow *show) static void SmartShopper_BufferPurchaseTotal(u8 varIdx, TVShow *show)