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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
#include <common.h>
#include <game.h>
// Replaces: EN_LIFT_ROTATION_HALF (Sprite 107; Profile ID 481 @ 80AF96F8)
class dMsgBoxManager_c : public dStageActor_c {
public:
void showMessage(int id);
dMsgBoxManager_c() : state(this, &StateID_LoadRes) { }
int onCreate();
int onDelete();
int onExecute();
int onDraw();
int beforeExecute() { return true; }
int afterExecute(int) { return true; }
m2d::EmbedLayout_c layout;
dDvdLoader_c msgDataLoader;
bool layoutLoaded;
bool visible;
dStateWrapper_c<dMsgBoxManager_c> state;
USING_STATES(dMsgBoxManager_c);
DECLARE_STATE(LoadRes);
DECLARE_STATE(Wait);
DECLARE_STATE(BoxAppearWait);
// DECLARE_STATE(ButtonAppearWait);
DECLARE_STATE(ShownWait);
// DECLARE_STATE(ButtonDisappearWait);
DECLARE_STATE(BoxDisappearWait);
static dMsgBoxManager_c *instance;
static dMsgBoxManager_c *build();
private:
struct entry_s {
u32 id;
u32 titleOffset;
u32 msgOffset;
};
struct header_s {
u32 count;
entry_s entry[1];
};
};
dMsgBoxManager_c *dMsgBoxManager_c::instance = 0;
dMsgBoxManager_c *dMsgBoxManager_c::build() {
void *buffer = AllocFromGameHeap1(sizeof(dMsgBoxManager_c));
dMsgBoxManager_c *c = new(buffer) dMsgBoxManager_c;
instance = c;
return c;
}
#define ANIM_BOX_APPEAR 0
#define ANIM_BOX_DISAPPEAR 1
//#define ANIM_BUTTON_APPEAR 2
//#define ANIM_BUTTON_DISAPPEAR 3
extern int MessageBoxIsShowing;
/*****************************************************************************/
// Events
int dMsgBoxManager_c::onCreate() {
if (!layoutLoaded) {
if (!layout.loadArc("msgbox.arc", false))
return false;
static const char *brlanNames[2] = {
"BoxAppear.brlan",
"BoxDisappear.brlan",
// "ButtonAppear.brlan",
// "ButtonDisappear.brlan"
};
static const char *groupNames[2] = {
"G_Box", "G_Box",
// "G_Button", "G_Button"
};
layout.build("MessageBox.brlyt");
if (IsWideScreen()) {
layout.layout.rootPane->scale.x = 0.7711f;
}
layout.loadAnimations(brlanNames, 2);
layout.loadGroups(groupNames, (int[2]){0,1}, 2);
layout.disableAllAnimations();
layout.drawOrder = 0xA0;
layoutLoaded = true;
}
visible = false;
return true;
}
int dMsgBoxManager_c::onExecute() {
//OSReport("E: %s\n", state.getCurrentState()->getName());
state.execute();
layout.execAnimations();
layout.update();
return true;
}
int dMsgBoxManager_c::onDraw() {
if (visible) {
layout.scheduleForDrawing();
}
return true;
}
int dMsgBoxManager_c::onDelete() {
instance = 0;
return layout.free();
}
/*****************************************************************************/
// Load Resources
CREATE_STATE_E(dMsgBoxManager_c, LoadRes);
void dMsgBoxManager_c::executeState_LoadRes() {
OSReport("Trying to load\n");
if (msgDataLoader.load("/NewerRes/Messages.bin")) {
OSReport(":)\n");
state.setState(&StateID_Wait);
OSReport("changed\n");
} else {
OSReport(":(\n");
}
}
/*****************************************************************************/
// Waiting
CREATE_STATE_E(dMsgBoxManager_c, Wait);
void dMsgBoxManager_c::executeState_Wait() {
// null
}
/*****************************************************************************/
// Show Box
void dMsgBoxManager_c::showMessage(int id) {
// get the data file
header_s *data = (header_s*)msgDataLoader.buffer;
const wchar_t *title = 0, *msg = 0;
for (int i = 0; i < data->count; i++) {
if (data->entry[i].id == id) {
title = (const wchar_t*)((u32)data + data->entry[i].titleOffset);
msg = (const wchar_t*)((u32)data + data->entry[i].msgOffset);
break;
}
}
if (title == 0) {
OSReport("WARNING! Tried to show message %x but it could not be found!\n", id);
return;
}
layout.findTextBoxByName("T_title")->SetString(title);
layout.findTextBoxByName("T_msg")->SetString(msg);
state.setState(&StateID_BoxAppearWait);
}
CREATE_STATE(dMsgBoxManager_c, BoxAppearWait);
void dMsgBoxManager_c::beginState_BoxAppearWait() {
visible = true;
MessageBoxIsShowing = true;
layout.enableNonLoopAnim(ANIM_BOX_APPEAR);
OSReport("Enabling box appear @ %d\n", GlobalTickCount);
}
void dMsgBoxManager_c::executeState_BoxAppearWait() {
if (!layout.isAnimOn(ANIM_BOX_APPEAR)) {
OSReport("Box appeared @ %d\n", GlobalTickCount);
state.setState(&StateID_ShownWait);
}
}
void dMsgBoxManager_c::endState_BoxAppearWait() { }
/*****************************************************************************/
// Show Button
/*CREATE_STATE(dMsgBoxManager_c, ButtonAppearWait);
void dMsgBoxManager_c::beginState_ButtonAppearWait() {
layout.enableNonLoopAnim(ANIM_BUTTON_APPEAR);
OSReport("Enabling button appear @ %d\n", GlobalTickCount);
}
void dMsgBoxManager_c::executeState_ButtonAppearWait() {
if (!layout.isAnimOn(ANIM_BUTTON_APPEAR)) {
OSReport("Button appeared @ %d\n", GlobalTickCount);
state.setState(&StateID_ShownWait);
}
}
void dMsgBoxManager_c::endState_ButtonAppearWait() { }*/
/*****************************************************************************/
// Wait For Player To Finish
CREATE_STATE(dMsgBoxManager_c, ShownWait);
void dMsgBoxManager_c::beginState_ShownWait() { }
void dMsgBoxManager_c::executeState_ShownWait() {
int nowPressed = Remocon_GetPressed(GetActiveRemocon());
if (nowPressed & WPAD_TWO) {
state.setState(&StateID_BoxDisappearWait);
}
}
void dMsgBoxManager_c::endState_ShownWait() { }
/*****************************************************************************/
// Hide Button
/*CREATE_STATE(dMsgBoxManager_c, ButtonDisappearWait);
void dMsgBoxManager_c::beginState_ButtonDisappearWait() {
layout.enableNonLoopAnim(ANIM_BUTTON_DISAPPEAR);
OSReport("Enabling button disappear @ %d\n", GlobalTickCount);
}
void dMsgBoxManager_c::executeState_ButtonDisappearWait() {
if (!layout.isAnimOn(ANIM_BUTTON_DISAPPEAR)) {
OSReport("Button disappeared @ %d\n", GlobalTickCount);
state.setState(&StateID_BoxDisappearWait);
}
}
void dMsgBoxManager_c::endState_ButtonDisappearWait() { }*/
/*****************************************************************************/
// Hide Box
CREATE_STATE(dMsgBoxManager_c, BoxDisappearWait);
void dMsgBoxManager_c::beginState_BoxDisappearWait() {
layout.enableNonLoopAnim(ANIM_BOX_DISAPPEAR);
OSReport("Enabling box disappear @ %d\n", GlobalTickCount);
}
void dMsgBoxManager_c::executeState_BoxDisappearWait() {
if (!layout.isAnimOn(ANIM_BOX_DISAPPEAR)) {
OSReport("Box disappeared @ %d\n", GlobalTickCount);
state.setState(&StateID_Wait);
for (int i = 0; i < 2; i++)
layout.resetAnim(i);
layout.disableAllAnimations();
}
}
void dMsgBoxManager_c::endState_BoxDisappearWait() {
visible = false;
MessageBoxIsShowing = false;
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
// Replaces: EN_BLUR (Sprite 152; Profile ID 603 @ 80ADD890)
class daEnMsgBlock_c : public daEnBlockMain_c {
public:
TileRenderer tile;
Physics::Info physicsInfo;
int onCreate();
int onDelete();
int onExecute();
void calledWhenUpMoveExecutes();
void calledWhenDownMoveExecutes();
void blockWasHit(bool isDown);
USING_STATES(daEnMsgBlock_c);
DECLARE_STATE(Wait);
static daEnMsgBlock_c *build();
};
CREATE_STATE(daEnMsgBlock_c, Wait);
int daEnMsgBlock_c::onCreate() {
OSReport("Creating Block\n");
blockInit(pos.y);
physicsInfo.x1 = -8;
physicsInfo.y1 = 16;
physicsInfo.x2 = 8;
physicsInfo.y2 = 0;
physicsInfo.otherCallback1 = &daEnBlockMain_c::OPhysicsCallback1;
physicsInfo.otherCallback2 = &daEnBlockMain_c::OPhysicsCallback2;
physicsInfo.otherCallback3 = &daEnBlockMain_c::OPhysicsCallback3;
physics.setup(this, &physicsInfo, 3, currentLayerID);
physics.flagsMaybe = 0x260;
physics.callback1 = &daEnBlockMain_c::PhysicsCallback1;
physics.callback2 = &daEnBlockMain_c::PhysicsCallback2;
physics.callback3 = &daEnBlockMain_c::PhysicsCallback3;
physics.addToList();
TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0);
list->add(&tile);
tile.x = pos.x - 8;
tile.y = -(16 + pos.y);
tile.tileNumber = 0x98;
doStateChange(&daEnMsgBlock_c::StateID_Wait);
OSReport("Created Block\n");
return true;
}
int daEnMsgBlock_c::onDelete() {
TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0);
list->remove(&tile);
physics.removeFromList();
return true;
}
int daEnMsgBlock_c::onExecute() {
acState.execute();
physics.update();
blockUpdate();
tile.setPosition(pos.x-8, -(16+pos.y), pos.z);
tile.setVars(scale.x);
// now check zone bounds based on state
if (acState.getCurrentState()->isEqual(&StateID_Wait)) {
checkZoneBoundaries(0);
}
return true;
}
daEnMsgBlock_c *daEnMsgBlock_c::build() {
void *buffer = AllocFromGameHeap1(sizeof(daEnMsgBlock_c));
return new(buffer) daEnMsgBlock_c;
}
void daEnMsgBlock_c::blockWasHit(bool isDown) {
pos.y = initialY;
dMsgBoxManager_c::instance->showMessage(settings);
physics.setup(this, &physicsInfo, 3, currentLayerID);
physics.addToList();
doStateChange(&StateID_Wait);
}
void daEnMsgBlock_c::calledWhenUpMoveExecutes() {
if (initialY >= pos.y)
blockWasHit(false);
}
void daEnMsgBlock_c::calledWhenDownMoveExecutes() {
if (initialY <= pos.y)
blockWasHit(true);
}
void daEnMsgBlock_c::beginState_Wait() {
}
void daEnMsgBlock_c::endState_Wait() {
}
void daEnMsgBlock_c::executeState_Wait() {
int result = blockResult();
if (result == 0)
return;
if (result == 1) {
doStateChange(&daEnBlockMain_c::StateID_UpMove);
anotherFlag = 2;
isGroundPound = false;
} else {
doStateChange(&daEnBlockMain_c::StateID_DownMove);
anotherFlag = 1;
isGroundPound = true;
}
}
|