cpak.c
7.53 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include "viewer.h"
#include "pagecommon.h"
#include "pagegame.h"
#include "texrect.h"
#include "uilogic.h"
#include "gzip.h"
#include "font.h"
#include "cpak.h"
#include "texture/player.c"
#include "audrenderer.h"
UiShadowIcon gCPakIcon[MAX_CONT_PAK];
UiCPakBind gCPakBind;
UiShadowIcon gCPakBindIcon[4];
int gCPakInit = 0;
int gCPakBindIconInit = 0;
void onCPakBindIconSelect(int idx, u32 button);
#define BSIZE 64
static void
getCPakOrigin(int i, int *x, int *y)
{
*x = 110 + BSIZE*(i%(MAX_CONT_PAK>>1));
*y = 225 + BSIZE*(i/(MAX_CONT_PAK>>1));
}
void initCPak( int mode )
{
int i;
u32 aIdx[MAX_CONT_PAK];
uiCPakRead();
for( i = 0; i < MAX_CONT_PAK; i++ ) {
aIdx[i] = gCPakList[i].cid;
}
initGameIconGroup(gCPakIcon, MAX_CONT_PAK, aIdx);
// change shadow icon defaults
for( i = 0; i <MAX_CONT_PAK; i++ ) {
gCPakIcon[i].xscale = (3<<8);
gCPakIcon[i].yscale = (3<<8);
gCPakIcon[i].posx = 126 + BSIZE*(i%(MAX_CONT_PAK>>1));
gCPakIcon[i].posy = 241 + BSIZE*(i/(MAX_CONT_PAK>>1));
}
// if mode, we need to allow for active empty icons
if( mode ) {
for( i = 0; i <MAX_CONT_PAK; i++ ) {
if( gCPakIcon[i].show == 0 ) {
gCPakIcon[i].show = 1;
gCPakIcon[i].init = 1;
gCPakIcon[i].texMap = NULL;
gCPakIcon[i].shadowMap = NULL;
gCPakIcon[i].text = NULL;
}
}
}
gCPakInit = 1;
}
void drawBox( int ux, int uy, int lx, int ly, int w )
{
// top line
gDPFillRectangle( gpGfxList++, ux, uy, lx, uy+w );
// left line
gDPFillRectangle( gpGfxList++, ux, uy, ux+w, ly);
// right line
gDPFillRectangle( gpGfxList++, lx-w, uy, lx, ly);
// bottom line
gDPFillRectangle( gpGfxList++, ux, ly-w, lx, ly);
}
void getCPakColor( int idx, int h, unsigned char *r, unsigned char *g, unsigned char *b )
{
unsigned char cl[5][3] = { { 64, 64, 64}, {128, 0, 0}, {0, 128, 0}, {128, 128, 0}, {0, 128, 128} };
unsigned char ch[5][3] = { {235, 235, 235 }, {235, 0, 0}, {0, 235, 0}, {235, 235, 0}, {0, 235, 235} };
int i;
i = (idx < 0)||(idx > 4) ? 0: idx;
if( h ) {
*r = ch[i][0]; *g = cl[i][1]; *b = ch[i][2];
} else {
*r = cl[i][0]; *g = cl[i][1]; *b = cl[i][2];
}
}
void drawCPak( int mode )
{
int i;
char *cellnum[MAX_CONT_PAK] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };
unsigned char r, g, b;
if( !gCPakInit )
initCPak(mode);
// background rectangle
gDPSetCycleType(gpGfxList++, G_CYC_FILL);
gDPSetFillColor(gpGfxList++, (GPACK_RGBA5551(0, 0, 0, 1) << 16) |
GPACK_RGBA5551(0, 0, 0, 1));
gDPFillRectangle( gpGfxList++, 108, 223, 496, 355);
// icons
drawShadowIcon(gCPakIcon, MAX_CONT_PAK, gCPakInit, initCPak);
for( i = 0; i < MAX_CONT_PAK; i++ ) {
int x, y;
int active = (gCPakList[i].cid == gGameIcons[gGameIconIdx].id) &&
(gCPakList[i].cont_id != -1);
int select = active ? gCPakList[i].cont_id+1 : 0;
getCPakOrigin(i, &x, &y);
// set fill color
getCPakColor( select, active, &r, &g, &b );
gDPSetCycleType(gpGfxList++, G_CYC_FILL);
gDPSetFillColor(gpGfxList++, (GPACK_RGBA5551(r, g, b, 1) << 16)|GPACK_RGBA5551(r, g, b, 1));
// box
if( select ) {
drawBox( x, y, x + BSIZE, y + BSIZE, 4 );
} else {
drawBox( x, y, x + BSIZE, y + BSIZE, 1 );
}
// location number
drawString(cellnum[i], gStringMap, x + 2, y + 2 );
// controller number
if( gCPakList[i].cid && gCPakList[i].cont_id != -1 ) {
getCPakColor( gCPakList[i].cont_id+1, 0, &r, &g, &b );
gDPSetCycleType(gpGfxList++, G_CYC_FILL);
gDPSetFillColor(gpGfxList++, (GPACK_RGBA5551(r, g, b, 1) << 16)|GPACK_RGBA5551(r, g, b, 1));
gDPFillRectangle( gpGfxList++, x + 48, y + 2,
x + 60, y + 14 );
}
}
// reset fill color
gDPSetFillColor(gpGfxList++, (GPACK_RGBA5551(0, 0, 0, 1) << 16) |
GPACK_RGBA5551(0, 0, 0, 1));
}
void drawCPakBinding()
{
int i;
int posx[4] = {162, 234, 306, 378};
int posy[4] = {150, 150, 150, 150};
int bsize = 64;
unsigned char r, g, b;
char *cellnum[MAX_CONT_PAK+1] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };
for( i = 0; i < gCPakBind.nCPak; i++ ) {
gDPSetCycleType(gpGfxList++, G_CYC_FILL);
getCPakColor( i+1, 0, &r, &g, &b );
gDPSetFillColor(gpGfxList++, (GPACK_RGBA5551(r, g, b, 1) << 16) | GPACK_RGBA5551(r, g, b, 1));
drawBox( posx[i], posy[i], posx[i]+bsize, posy[i]+bsize, 4 );
drawString(cellnum[gCPakBind.idxCPak[i]+1], gStringMap, posx[i] + 2, posy[i] + 2 );
}
gDPSetFillColor(gpGfxList++, (GPACK_RGBA5551(0, 0, 0, 1) << 16) |
GPACK_RGBA5551(0, 0, 0, 1));
}
void onCPakBindIconInit()
{
int i;
int posx[4] = {178, 250, 322, 394};
int posy[4] = {166, 166, 166, 166};
u16* pTex[4] = {texPlayer, texPlayer, texPlayer, texPlayer};
u8* pText[4] = {NULL, NULL, NULL, NULL};
if( !gCPakInit ) initCPak(0);
gCPakBind.nCPak = uiGetCPakCnt(gGameIcons[gGameIconIdx].id);
for (i=0; i<4; i++) gCPakBind.idxCPak[i] = -1;
for (i=0; i<MAX_CONT_PAK; i++) {
if (gGameIcons[gGameIconIdx].id == gCPakList[i].cid &&
gCPakList[i].cont_id != -1) {
gCPakBind.idxCPak[gCPakList[i].cont_id] = i;
}
}
initShadowIconGroup(gCPakBindIcon, gCPakBind.nCPak,
posx, posy,
GAME_ICON_W, GAME_ICON_H,
3<<8, 3<<8,
pTex, pText, gShadowMap);
gCPakBindIconInit = 1;
}
void onCPakBindIconHilite(int idx)
{
#if 0
int bsize = 64;
unsigned char ch[4][3] = { {235, 0, 0}, {0, 235, 0}, {235, 235, 0}, {0, 235, 235} };
int bx[4] = { 162, 234, 306, 378 }, by = 150;
gDPSetCycleType(gpGfxList++, G_CYC_FILL);
gDPSetFillColor(gpGfxList++, (GPACK_RGBA5551(ch[idx][0],ch[idx][1],ch[idx][2], 1) << 16) | GPACK_RGBA5551(ch[idx][0], ch[idx][1], ch[idx][2], 1));
PRINTF("%d %d %d %d\n", bx[idx], by, bx[idx]+bsize, by+bsize);
drawBox( bx[idx], by, bx[idx]+bsize, by+bsize, 4 );
gDPSetFillColor(gpGfxList++, (GPACK_RGBA5551(0, 0, 0, 1) << 16) |
GPACK_RGBA5551(0, 0, 0, 1));
#endif
}
void onCPakBindIconSelect(int idx, u32 button)
{
static SaCPak previous[4];
if (button==CONT_A)
{
playSound(SOUND_SELECT);
if (gCPakInit < 2) {
int i;
for (i = 0; i < 4; ++i) {
previous[i].cid = gCPakList[gCPakBind.idxCPak[i]].cid;
previous[i].cont_id = -1;
}
gCPakInit = 2;
}
if( gCPakBind.idxCPak[idx] != -1 ) {
gCPakList[gCPakBind.idxCPak[idx]] = previous[idx];
}
do {
gCPakBind.idxCPak[idx]++;
if( gCPakBind.idxCPak[idx] == MAX_CONT_PAK ) {
gCPakBind.idxCPak[idx] = -1;
break;
}
} while( gCPakList[gCPakBind.idxCPak[idx]].cid == gGameIcons[gGameIconIdx].id && gCPakList[gCPakBind.idxCPak[idx]].cont_id != -1 );
if( gCPakBind.idxCPak[idx] != -1 ) {
previous[idx] = gCPakList[gCPakBind.idxCPak[idx]];
gCPakList[gCPakBind.idxCPak[idx]].cont_id = idx;
gCPakList[gCPakBind.idxCPak[idx]].cid = gGameIcons[gGameIconIdx].id;
}
onCPakBindIconInit();
}
}
void resetCPak()
{
gCPakInit = 0;
gCPakBindIconInit = 0;
}
void saveCPak(void)
{
uiSaveCPakBindings(gCPakList);
gCPakInit = 0;
gCPakBindIconInit = 0;
}