1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include "global.h"
#include "coins.h"
#include "menu.h"
#include "string_util.h"
#include "strings.h"
#define MAX_COINS 9999
void UpdateCoinsWindow(s32 coins, u8 x, u8 y)
{
PrintCoins(coins, 4, x + 2, y + 1);
}
void ShowCoinsWindow(u32 coins, u8 x, u8 y)
{
Menu_DrawStdWindowFrame(x, y, x + 9, y + 3);
UpdateCoinsWindow(coins, x, y);
}
void HideCoinsWindow(u8 x, u8 y)
{
Menu_EraseWindowRect(x, y, x + 9, y + 3);
}
void PrintCoins(s32 coins, u8 b, u8 x, u8 y)
{
u8 string[16];
u8 *ptr;
u8 r1;
u8 foo;
ConvertIntToDecimalString(string, coins);
r1 = (b * 6 + 0x21 - 8 * (b + 2));
x = x - r1 / 8;
foo = r1 % 8;
ptr = gStringVar1;
if (foo)
{
ptr[0] = EXT_CTRL_CODE_BEGIN;
ptr[1] = 0x11;
ptr[2] = 8 - (foo);
ptr += 3;
}
ptr[0] = EXT_CTRL_CODE_BEGIN;
ptr[1] = 0x11;
ptr[2] = (b - StringLength(string)) * 6;
ptr += 3;
StringCopy(ptr, string);
Menu_PrintText(gOtherText_Coins2, x, y);
}
u16 GetCoins(void)
{
return gSaveBlock1.coins;
}
bool8 AddCoins(u16 coins)
{
u32 newCoins;
if (GetCoins() >= MAX_COINS)
return FALSE;
newCoins = coins + gSaveBlock1.coins;
if (gSaveBlock1.coins > (u16)newCoins)
gSaveBlock1.coins = MAX_COINS;
else
{
gSaveBlock1.coins = newCoins;
if ((u16)newCoins > MAX_COINS)
gSaveBlock1.coins = MAX_COINS;
}
return TRUE;
}
bool8 RemoveCoins(u16 coins)
{
if (GetCoins() >= coins)
{
gSaveBlock1.coins -= coins;
return TRUE;
}
else
return FALSE;
}
|