diff options
author | DizzyEggg <jajkodizzy@wp.pl> | 2017-09-29 00:11:42 +0200 |
---|---|---|
committer | DizzyEggg <jajkodizzy@wp.pl> | 2017-09-29 00:11:42 +0200 |
commit | e41b9cbbb37c908f77a9ce440f33b76b35139311 (patch) | |
tree | e4e999cceda6f627b3d038b4c2c332a959a3a4a3 /src | |
parent | 3c8091393ca12b8eeb26f236a997b70eea5688c6 (diff) |
decompile money
Diffstat (limited to 'src')
-rw-r--r-- | src/coins.c | 3 | ||||
-rw-r--r-- | src/money.c | 145 |
2 files changed, 146 insertions, 2 deletions
diff --git a/src/coins.c b/src/coins.c index 84a79f5f2..4ee601b22 100644 --- a/src/coins.c +++ b/src/coins.c @@ -4,14 +4,13 @@ #include "window.h" #include "text_window.h" #include "string_util.h" +#include "menu.h" #define MAX_COINS 9999 EWRAM_DATA u8 sCoinsWindowId = 0; extern s32 GetStringRightAlignXOffset(u8 fontId, u8 *str, s32 totalWidth); -extern void SetWindowTemplateFields(struct WindowTemplate* template, u8 priority, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 palNum, u16 baseBlock); -extern void SetWindowBorderStyle(u8 windowId, bool8 copyToVram, s16 tileStart, s8 palette); extern void sub_819746C(u8 windowId, bool8 copyToVram); extern const u8 gText_Coins[]; diff --git a/src/money.c b/src/money.c index be64d9633..65a45b158 100644 --- a/src/money.c +++ b/src/money.c @@ -1,8 +1,77 @@ #include "global.h" #include "money.h" +#include "event_data.h" +#include "string_util.h" +#include "text.h" +#include "menu.h" +#include "window.h" +#include "sprite.h" +#include "decompress.h" + +extern const u8 gText_PokedollarVar1[]; + +extern const u8 gMenuMoneyGfx[]; +extern const u8 gMenuMoneyPal[]; #define MAX_MONEY 999999 +EWRAM_DATA static u8 sMoneyBoxWindowId = 0; +EWRAM_DATA static u8 sMoneyLabelSpriteId = 0; + +#define MONEY_LABEL_TAG 0x2722 + +static const struct OamData sOamData_MoneyLabel = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 1, + .x = 0, + .matrixNum = 0, + .size = 2, + .tileNum = 0, + .priority = 0, + .paletteNum = 0, + .affineParam = 0, +}; + +static const union AnimCmd sSpriteAnim_MoneyLabel[] = +{ + ANIMCMD_FRAME(0, 0), + ANIMCMD_END +}; + +static const union AnimCmd *const sSpriteAnimTable_MoneyLabel[] = +{ + sSpriteAnim_MoneyLabel, +}; + +static const struct SpriteTemplate sSpriteTemplate_MoneyLabel = +{ + .tileTag = MONEY_LABEL_TAG, + .paletteTag = MONEY_LABEL_TAG, + .oam = &sOamData_MoneyLabel, + .anims = sSpriteAnimTable_MoneyLabel, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; + +static const struct CompressedSpriteSheet sSpriteSheet_MoneyLabel = +{ + .data = gMenuMoneyGfx, + .size = 256, + .tag = MONEY_LABEL_TAG, +}; + +static const struct CompressedSpritePalette sSpritePalette_MoneyLabel = +{ + .data = gMenuMoneyPal, + .tag = MONEY_LABEL_TAG +}; + u32 GetMoney(u32* moneyPtr) { return *moneyPtr ^ gSaveBlock2Ptr->encryptionKey; @@ -53,3 +122,79 @@ void SubtractMoney(u32* moneyPtr, u32 toSub) SetMoney(moneyPtr, toSet); } + +bool8 IsEnoughForCostInVar0x8005(void) +{ + return IsEnoughMoney(&gSaveBlock1Ptr->money, gSpecialVar_0x8005); +} + +void SubtractMoneyFromVar0x8005(void) +{ + SubtractMoney(&gSaveBlock1Ptr->money, gSpecialVar_0x8005); +} + +void PrintMoneyAmountInMoneyBox(u8 windowId, int amount, u8 speed) +{ + PrintMoneyAmount(windowId, 0x26, 1, amount, speed); +} + +void PrintMoneyAmount(u8 windowId, u8 x, u8 y, int amount, u8 speed) +{ + u8 *txtPtr; + s32 strLength; + + ConvertIntToDecimalStringN(gStringVar1, amount, STR_CONV_MODE_LEFT_ALIGN, 6); + + strLength = 6 - StringLength(gStringVar1); + txtPtr = gStringVar4; + + while (strLength-- > 0) + *(txtPtr++) = 0x77; + + StringExpandPlaceholders(txtPtr, gText_PokedollarVar1); + PrintTextOnWindow(windowId, 1, gStringVar4, x, y, speed, NULL); +} + +void PrintMoneyAmountInMoneyBoxWithBorder(u8 windowId, u16 tileStart, u8 pallete, int amount) +{ + SetWindowBorderStyle(windowId, FALSE, tileStart, pallete); + PrintMoneyAmountInMoneyBox(windowId, amount, 0); +} + +void ChangeAmountInMoneyBox(int amount) +{ + PrintMoneyAmountInMoneyBox(sMoneyBoxWindowId, amount, 0); +} + +void DrawMoneyBox(int amount, u8 x, u8 y) +{ + struct WindowTemplate template; + + SetWindowTemplateFields(&template, 0, x + 1, y + 1, 10, 2, 15, 8); + sMoneyBoxWindowId = AddWindow(&template); + FillWindowPixelBuffer(sMoneyBoxWindowId, 0); + PutWindowTilemap(sMoneyBoxWindowId); + CopyWindowToVram(sMoneyBoxWindowId, 1); + PrintMoneyAmountInMoneyBoxWithBorder(sMoneyBoxWindowId, 0x214, 14, amount); + AddMoneyLabelObject((8 * x) + 19, (8 * y) + 11); +} + +void HideMoneyBox(void) +{ + RemoveMoneyLabelObject(); + sub_8198070(sMoneyBoxWindowId, FALSE); + CopyWindowToVram(sMoneyBoxWindowId, 2); + RemoveWindow(sMoneyBoxWindowId); +} + +void AddMoneyLabelObject(u16 x, u16 y) +{ + LoadCompressedObjectPic(&sSpriteSheet_MoneyLabel); + LoadCompressedObjectPalette(&sSpritePalette_MoneyLabel); + sMoneyLabelSpriteId = CreateSprite(&sSpriteTemplate_MoneyLabel, x, y, 0); +} + +void RemoveMoneyLabelObject(void) +{ + DestroySpriteAndFreeResources(&gSprites[sMoneyLabelSpriteId]); +} |