summaryrefslogtreecommitdiff
path: root/src/d/d_menu_calibration.cpp
blob: 72ec058eec21083bacf220208e4dfba1eeed9107 (plain)
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
/**
 * d_menu_calibration.cpp
 * Wii Remote Calibration Option Menu
 */

#include "d/dolzel.h" // IWYU pragma: keep

#include "d/d_menu_calibration.h"
#include "d/d_com_inf_game.h"
#include "d/d_select_cursor.h"
#include "d/d_meter2_info.h"
#include "d/d_meter_HIO.h"
#include "d/d_msg_string.h"
#include "m_Do/m_Do_controller_pad.h"

// Need 0xC bytes of padding with no symbol between dMenu_Calibration_c::__vtable and the end of .data
// This is likely caused by the vtable of an abstract base class getting put there and then stripped out.
// Not sure which abstract base class could go there though, so we simulate it with some dummy classes for now.
class dummy_abstract_class {
public:
    virtual void virt_func_0() = 0;
};
class dummy_child_class : dummy_abstract_class {
    virtual void virt_func_0();
};
static dummy_child_class dummy() {
    dummy_child_class temp;
    return temp;
}

typedef void (dMenu_Calibration_c::*initFunc)();
static initFunc map_init_process[] = {
    &dMenu_Calibration_c::step1_wait_init, &dMenu_Calibration_c::step1_move_init,
    &dMenu_Calibration_c::step2_wait_init, &dMenu_Calibration_c::step2_move_init,
    &dMenu_Calibration_c::step3_wait_init, &dMenu_Calibration_c::step3_move_init,
};

typedef void (dMenu_Calibration_c::*moveFunc)();
static moveFunc map_move_process[] = {
    &dMenu_Calibration_c::step1_wait_move, &dMenu_Calibration_c::step1_move_move,
    &dMenu_Calibration_c::step2_wait_move, &dMenu_Calibration_c::step2_move_move,
    &dMenu_Calibration_c::step3_wait_move, &dMenu_Calibration_c::step3_move_move,
};

dMenu_Calibration_c::~dMenu_Calibration_c() {}

void dMenu_Calibration_c::_move() {
    u8 last_process = mProcess;
    (this->*map_move_process[mProcess])();

    if (last_process != mProcess) {
        (this->*map_init_process[mProcess])();
    }

    setHIO(false);
}

void dMenu_Calibration_c::_draw() {}

void dMenu_Calibration_c::step1_wait_init() {
    field_0xfa = 0;
    setAButtonString(0);
    setBButtonString(0);
    setStepString(1240);     // "STEP 1"
    setExplainString(1245);  // "Point the Wii Remote at the screen and move the cursor vertically
                             // until it overlaps the central orange circle."

    ((J2DTextBox*)field_0x80->getPanePtr())->setFontSize(field_0xac[mCalibrationValue + 2]);

    Vec pos = field_0x68[mCalibrationValue + 2]->getGlobalVtxCenter(false, 0);
    mpSelectCursor->setPos(pos.x, pos.y, field_0x68[mCalibrationValue + 2]->getPanePtr(), false);

    field_0xfc = 0;
    field_0x7c->setAlphaRate(0.0f);
}

void dMenu_Calibration_c::step1_wait_move() {
    s16 open_frames = g_drawHIO.mCalibration.mOpenFrames;
    field_0xfa++;

    if (field_0xfa >= open_frames) {
        field_0x58[0]->setAlphaRate(1.0f);
        field_0x7c->setAlphaRate(0.0f);
        field_0x58[1]->setAlphaRate(0.0f);
        mpSelectCursor->setAlphaRate(1.0f);
        mpSelectCursor->onPlayAnime(0);
        mProcess = PROC_STEP1_MOVE;
    } else {
        f32 alpha_rate = (f32)field_0xfa / (f32)open_frames;

        field_0x58[0]->setAlphaRate(alpha_rate);
        field_0x7c->setAlphaRate(0.0f);
        mpSelectCursor->setAlphaRate(alpha_rate);

        if (field_0x58[1]->getAlphaRate() != 0.0f) {
            field_0x58[1]->setAlphaRate(1.0f - alpha_rate);
        }
    }
}

void dMenu_Calibration_c::step1_move_init() {
    setAButtonString(1032);  // "Next"
    setBButtonString(1377);  // "Cancel"
}

void dMenu_Calibration_c::step1_move_move() {
    if (mDoCPd_c::getTrigA(PAD_1)) {
        mProcess = PROC_STEP2_WAIT;
        field_0xff = 0;
        Z2GetAudioMgr()->seStart(Z2SE_SY_MENU_NEXT, NULL, 0, 0, 1.0f, 1.0f, -1.0f, -1.0f, 0);
        dMeter2Info_set2DVibration();
    } else if (mDoCPd_c::getTrigB(PAD_1)) {
        field_0x101 = 0;
        mStatus = 0;
        Z2GetAudioMgr()->seStart(Z2SE_SY_MENU_BACK, NULL, 0, 0, 1.0f, 1.0f, -1.0f, -1.0f, 0);
        dMeter2Info_set2DVibration();
    }
}

void dMenu_Calibration_c::step2_wait_init() {
    field_0xfa = 0;
    setAButtonString(0);
    setBButtonString(0);
    setStepString(1242);     // "STEP 2"
    setExplainString(1241);  // "Please adjust the orange bar so that it matches the exact size and
                             // position of the Sensor Bar."
    mpSelectCursor->offPlayAnime(0);
}

void dMenu_Calibration_c::step2_wait_move() {
    s16 open_frames = g_drawHIO.mCalibration.mOpenFrames;
    field_0xfa++;

    if (field_0xfa >= open_frames) {
        field_0x58[1]->setAlphaRate(1.0f);
        field_0x58[0]->setAlphaRate(0.0f);
        field_0x7c->setAlphaRate(0.0f);
        field_0x58[2]->setAlphaRate(0.0f);
        field_0x90->setAlphaRate(0.0f);

        if (field_0xff == 0) {
            mpSelectCursor->setAlphaRate(0.0f);
        }

        mProcess = PROC_STEP2_MOVE;
    } else {
        f32 alpha_rate = (f32)field_0xfa / (f32)open_frames;

        field_0x58[1]->setAlphaRate(alpha_rate);

        if (field_0x58[0]->getAlphaRate() != 0.0f) {
            field_0x58[0]->setAlphaRate(1.0f - alpha_rate);
            field_0x7c->setAlphaRate(1.0f - alpha_rate);
        }

        if (field_0x58[2]->getAlphaRate() != 0.0f) {
            field_0x58[2]->setAlphaRate(1.0f - alpha_rate);
            field_0x90->setAlphaRate(1.0f - alpha_rate);
        }

        if (field_0xff == 0) {
            mpSelectCursor->setAlphaRate(alpha_rate);
        }
    }
}

void dMenu_Calibration_c::step2_move_init() {
    setAButtonString(1032);  // "Next"
    setBButtonString(1017);  // "Back"
}

void dMenu_Calibration_c::step2_move_move() {
    if (mDoCPd_c::getTrigA(PAD_1)) {
        mProcess = PROC_STEP3_WAIT;
        field_0xff = 0;
        Z2GetAudioMgr()->seStart(Z2SE_SY_MENU_NEXT, NULL, 0, 0, 1.0f, 1.0f, -1.0f, -1.0f, 0);
        dMeter2Info_set2DVibration();
    } else if (mDoCPd_c::getTrigB(PAD_1)) {
        mProcess = PROC_STEP1_WAIT;
        field_0xff = 1;
        Z2GetAudioMgr()->seStart(Z2SE_SY_MENU_BACK, NULL, 0, 0, 1.0f, 1.0f, -1.0f, -1.0f, 0);
        dMeter2Info_set2DVibration();
    }
}

void dMenu_Calibration_c::step3_wait_init() {
    field_0xfa = 0;
    setAButtonString(0);
    setBButtonString(0);
    setStepString(1244);     // "STEP 3"
    setExplainString(1243);  // "Point the Wii Remote at the screen and adjust your distance from
                             // the screen until the blue circle overlaps the orange circle."
    field_0xfc = 0;

    field_0x90->setAlphaRate(0.0f);
}

void dMenu_Calibration_c::step3_wait_move() {
    s16 open_frames = g_drawHIO.mCalibration.mOpenFrames;
    field_0xfa++;

    if (field_0xfa >= open_frames) {
        field_0x58[2]->setAlphaRate(1.0f);
        field_0x90->setAlphaRate(0.0f);
        field_0x58[1]->setAlphaRate(0.0f);

        mProcess = PROC_STEP3_MOVE;
    } else {
        f32 alpha_rate = (f32)field_0xfa / (f32)open_frames;

        field_0x58[2]->setAlphaRate(alpha_rate);
        field_0x90->setAlphaRate(0.0f);

        if (field_0x58[1]->getAlphaRate() != 0.0f) {
            field_0x58[1]->setAlphaRate(1.0f - alpha_rate);
        }
    }
}

void dMenu_Calibration_c::step3_move_init() {
    setAButtonString(1378);  // "End"
    setBButtonString(1017);  // "Back"
}

void dMenu_Calibration_c::step3_move_move() {
    if (mDoCPd_c::getTrigA(PAD_1)) {
        mStatus = 0;
        field_0x101 = 1;
        Z2GetAudioMgr()->seStart(Z2SE_SY_MENU_BACK, NULL, 0, 0, 1.0f, 1.0f, -1.0f, -1.0f, 0);
        dMeter2Info_set2DVibration();
        setCalibrationValue();
    } else if (mDoCPd_c::getTrigB(PAD_1)) {
        mProcess = PROC_STEP2_WAIT;
        field_0xff = 1;
        Z2GetAudioMgr()->seStart(Z2SE_SY_MENU_BACK, NULL, 0, 0, 1.0f, 1.0f, -1.0f, -1.0f, 0);
        dMeter2Info_set2DVibration();
    }
}

void dMenu_Calibration_c::setCalibrationValue() {
    dComIfGs_setOptCalValue(mCalibrationValue);
    dComIfGs_setOptCalibrateDist(mCalibrateDist);
    field_0xec = mCalibrationValue;
    field_0xf6 = mCalibrateDist;
}

void dMenu_Calibration_c::setAButtonString(u16 i_stringID) {
    if (i_stringID == 0) {
        for (int i = 0; i < 5; i++) {
            strcpy(mpAButtonString[i]->getStringPtr(), "");
        }
    } else {
        for (int i = 0; i < 5; i++) {
            dMeter2Info_getStringKanji(i_stringID, mpAButtonString[i]->getStringPtr(), NULL);
        }
    }
}

void dMenu_Calibration_c::setBButtonString(u16 i_stringID) {
    if (i_stringID == 0) {
        for (int i = 0; i < 5; i++) {
            strcpy(mpBButtonString[i]->getStringPtr(), "");
        }
    } else {
        for (int i = 0; i < 5; i++) {
            dMeter2Info_getStringKanji(i_stringID, mpBButtonString[i]->getStringPtr(), NULL);
        }
    }
}

void dMenu_Calibration_c::setStepString(u16 i_stringID) {
    if (i_stringID == 0) {
        for (int i = 0; i < 3; i++) {
            strcpy(mpStepString[i]->getStringPtr(), "");
        }
    } else {
        for (int i = 0; i < 3; i++) {
            dMeter2Info_getStringKanji(i_stringID, mpStepString[i]->getStringPtr(), NULL);
        }
    }
}

void dMenu_Calibration_c::setExplainString(u16 i_stringID) {
    if (i_stringID == 0) {
        for (int i = 0; i < 3; i++) {
            strcpy(mpExplainString[i]->getStringPtr(), "");
        }
    } else {
        for (int i = 0; i < 3; i++) {
            mpMsgString->getString(i_stringID, mpExplainString[i], NULL, NULL, NULL, 0);
        }
    }
}

void dMenu_Calibration_c::setHIO(bool i_useHIO) {
    if (i_useHIO || g_drawHIO.mCalibration.mDebug) {
        field_0x7c->scale(g_drawHIO.mCalibration.mCircleScale, g_drawHIO.mCalibration.mCircleScale);
        field_0x90->scale(g_drawHIO.mCalibration.mCircleScale2,
                          g_drawHIO.mCalibration.mCircleScale2);
    }

    if (g_drawHIO.mCollectScreen.mButtonDebugON || i_useHIO) {
        if (field_0x94 != NULL) {
            field_0x94->paneTrans(g_drawHIO.mCollectScreen.mButtonAPosX,
                                  g_drawHIO.mCollectScreen.mButtonAPosY);
            field_0x94->scale(g_drawHIO.mCollectScreen.mButtonAScale,
                              g_drawHIO.mCollectScreen.mButtonAScale);
        }

        if (field_0x98 != NULL) {
            field_0x98->paneTrans(g_drawHIO.mCollectScreen.mButtonBPosX,
                                  g_drawHIO.mCollectScreen.mButtonBPosY);
            field_0x98->scale(g_drawHIO.mCollectScreen.mButtonBScale,
                              g_drawHIO.mCollectScreen.mButtonBScale);
        }

        if (field_0x9c != NULL) {
            field_0x9c->paneTrans(g_drawHIO.mCollectScreen.mButtonATextPosX,
                                  g_drawHIO.mCollectScreen.mButtonATextPosY);
            field_0x9c->scale(g_drawHIO.mCollectScreen.mButtonATextScale,
                              g_drawHIO.mCollectScreen.mButtonATextScale);
        }

        if (field_0xa0 != NULL) {
            field_0xa0->paneTrans(g_drawHIO.mCollectScreen.mButtonBTextPosX,
                                  g_drawHIO.mCollectScreen.mButtonBTextPosY);
            field_0xa0->scale(g_drawHIO.mCollectScreen.mButtonBTextScale,
                              g_drawHIO.mCollectScreen.mButtonBTextScale);
        }
    }
}

void dMenu_Calibration_c::draw() {
    _draw();
}