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
|
#include <common.h>
#include <game.h>
#include "msgbox.h"
// Replaces: EN_LIFT_ROTATION_HALF (Sprite 107; Profile ID 481 @ 80AF96F8)
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
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",
};
static const char *groupNames[2] = {
"G_Box", "G_Box",
};
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 = 140;
layoutLoaded = true;
}
visible = false;
return true;
}
int dMsgBoxManager_c::onExecute() {
state.execute();
layout.execAnimations();
layout.update();
return true;
}
int dMsgBoxManager_c::onDraw() {
if (visible) {
layout.scheduleForDrawing();
}
return true;
}
int dMsgBoxManager_c::onDelete() {
instance = 0;
MessageBoxIsShowing = false;
if (canCancel && StageC4::instance)
StageC4::instance->_1D = 0; // disable no-pause
msgDataLoader.unload();
return layout.free();
}
/*****************************************************************************/
// Load Resources
CREATE_STATE_E(dMsgBoxManager_c, LoadRes);
void dMsgBoxManager_c::executeState_LoadRes() {
if (msgDataLoader.load("/NewerRes/Messages.bin")) {
state.setState(&StateID_Wait);
} else {
}
}
/*****************************************************************************/
// Waiting
CREATE_STATE_E(dMsgBoxManager_c, Wait);
void dMsgBoxManager_c::executeState_Wait() {
// null
}
/*****************************************************************************/
// Show Box
void dMsgBoxManager_c::showMessage(int id, bool canCancel, int delay) {
if (!this) {
OSReport("ADD A MESSAGE BOX MANAGER YOU MORON\n");
return;
}
// 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("Message Box: Message %08x not found\n", id);
return;
}
layout.findTextBoxByName("T_title")->SetString(title);
layout.findTextBoxByName("T_msg")->SetString(msg);
this->canCancel = canCancel;
this->delay = delay;
layout.findPictureByName("button")->SetVisible(canCancel);
state.setState(&StateID_BoxAppearWait);
}
CREATE_STATE(dMsgBoxManager_c, BoxAppearWait);
void dMsgBoxManager_c::beginState_BoxAppearWait() {
visible = true;
MessageBoxIsShowing = true;
StageC4::instance->_1D = 1; // enable no-pause
layout.enableNonLoopAnim(ANIM_BOX_APPEAR);
nw4r::snd::SoundHandle handle;
PlaySoundWithFunctionB4(SoundRelatedClass, &handle, SE_SYS_KO_DIALOGUE_IN, 1);
}
void dMsgBoxManager_c::executeState_BoxAppearWait() {
if (!layout.isAnimOn(ANIM_BOX_APPEAR)) {
state.setState(&StateID_ShownWait);
}
}
void dMsgBoxManager_c::endState_BoxAppearWait() { }
/*****************************************************************************/
// Wait For Player To Finish
CREATE_STATE(dMsgBoxManager_c, ShownWait);
void dMsgBoxManager_c::beginState_ShownWait() { }
void dMsgBoxManager_c::executeState_ShownWait() {
if (canCancel) {
int nowPressed = Remocon_GetPressed(GetActiveRemocon());
if (nowPressed & WPAD_TWO)
state.setState(&StateID_BoxDisappearWait);
}
if (delay > 0) {
delay--;
if (delay == 0)
state.setState(&StateID_BoxDisappearWait);
}
}
void dMsgBoxManager_c::endState_ShownWait() { }
/*****************************************************************************/
// Hide Box
CREATE_STATE(dMsgBoxManager_c, BoxDisappearWait);
void dMsgBoxManager_c::beginState_BoxDisappearWait() {
layout.enableNonLoopAnim(ANIM_BOX_DISAPPEAR);
nw4r::snd::SoundHandle handle;
PlaySoundWithFunctionB4(SoundRelatedClass, &handle, SE_SYS_DIALOGUE_OUT_AUTO, 1);
}
void dMsgBoxManager_c::executeState_BoxDisappearWait() {
if (!layout.isAnimOn(ANIM_BOX_DISAPPEAR)) {
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;
if (canCancel && StageC4::instance)
StageC4::instance->_1D = 0; // disable no-pause
}
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
// 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() {
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);
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;
if (dMsgBoxManager_c::instance)
dMsgBoxManager_c::instance->showMessage(settings);
else
Delete(false);
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;
}
}
|