summaryrefslogtreecommitdiff
path: root/src/d/d_s_name.cpp
blob: 59d1c81974faf44d2f1df2bdc63006b65e5696bd (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
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/**
 * d_s_name.cpp
 * File Select Scene
*/

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

#include "d/d_s_name.h"
#include "JSystem/JKernel/JKRExpHeap.h"
#include "d/d_com_inf_game.h"
#include "d/d_meter2_info.h"
#include "f_op/f_op_scene_mng.h"
#include "m_Do/m_Do_Reset.h"
#include "m_Do/m_Do_graphic.h"
#include "m_Do/m_Do_machine.h"
#include "m_Do/m_Do_mtx.h"
#include "m_Do/m_Do_main.h"
#include "f_op/f_op_overlap_mng.h"

static dSn_HIO_c g_snHIO;

#if VERSION == VERSION_GCN_PAL
static int mBmgStatus;
#endif

dSn_HIO_c::dSn_HIO_c() {
    mFileSelWaitTime = 15;
}

#if DEBUG
void dSn_HIO_c::genMessage(JORMContext* mctx) {
    mctx->genLabel("\n*****表示調整用*****", 0);
    mctx->genSlider("ファイル選択開始WaitTime", &mFileSelWaitTime, 0, 120);
}
#endif

static s32 phase_1(char* i_resName) {
    mDoAud_bgmStart(-1);
    if (dComIfG_setObjectRes(i_resName, (u8)0, NULL) == 0) {
        return cPhs_ERROR_e;
    }

    return cPhs_NEXT_e;
}

static s32 phase_2(char* i_resName) {
    int rt = dComIfG_syncObjectRes(i_resName);
    if (rt < 0) {
        return cPhs_ERROR_e;
    }

    if (rt > 0) {
        return cPhs_INIT_e;
    } else {
        return cPhs_COMPLEATE_e;
    }
}

static s32 resLoad(request_of_phase_process_class* i_phase, char* i_resName) {
    static request_of_phase_process_fn l_method[2] = {
        (request_of_phase_process_fn)phase_1, 
        (request_of_phase_process_fn)phase_2
    };

    return dComLbG_PhaseHandler(i_phase, l_method, i_resName);
}

s32 dScnName_c::create() {
    int phase_state = resLoad(&phase, "fileSel");
    if (phase_state == cPhs_COMPLEATE_e) {
        mHeap = JKRCreateExpHeap(0x180000, mDoExt_getGameHeap(), false);
        JUT_ASSERT(289, mHeap != NULL);

        field_0x1d0 = (JKRExpHeap*)mDoExt_setCurrentHeap(mHeap);

        dRes_info_c* resInfo = dComIfG_getObjectResInfo("fileSel");
        JUT_ASSERT(293, resInfo != NULL);

        dFs_c = new dFile_select_c(resInfo->getArchive());
        JUT_ASSERT(297, dFs_c != NULL);


        #if VERSION == VERSION_GCN_PAL
        for (int i = 0; i < 5; i++);
        #endif

        dFs_c->_create();

        if (fpcM_GetName(this) == fpcNm_NAME_SCENE_e) {
            dFs_c->setUseType(0);

            #if !PLATFORM_SHIELD
            dComIfGs_setNoFile(0);
            #endif
        }

        mBrightCheck = new dBrightCheck_c(resInfo->getArchive());

        field_0x420 = 0;
        g_snHIO.id = mDoHIO_CREATE_CHILD("名前登録シーン", &g_snHIO);
        JKRSetCurrentHeap(field_0x1d0);

        dComIfGp_setWindowNum(1);
        dComIfGp_setWindow(0, 0.0f, 0.0f, mDoMch_render_c::getFbWidth(),
                           mDoMch_render_c::getEfbHeight(), 0.0f, 1.0f, 0, 2);
        dComIfGp_setCamera(0, &mCamera);

        dDlst_window_c* window = dComIfGp_getWindow(0);
        view_port_class* viewport = window->getViewPort();

        fopCamM_SetNear(&mCamera, 1.0f);
        fopCamM_SetFar(&mCamera, 100000.0f);
        fopCamM_SetFovy(&mCamera, 45.0f);
        fopCamM_SetAspect(&mCamera, mDoGph_gInf_c::getWidthF() / mDoGph_gInf_c::getHeightF());
        fopCamM_SetEye(&mCamera, 0.0f, 0.0f, -1000.0f);
        fopCamM_SetCenter(&mCamera, 0.0f, 0.0f, 0.0f);
        fopCamM_SetBank(&mCamera, 0);

        dComIfGp_setPlayer(0, NULL);
        dComIfGd_setWindow(window);
        dComIfGd_setViewport(viewport);
        dComIfGd_setView(&mCamera.view);
        mDoGph_gInf_c::offAutoForcus();
        setView();

        dKy_setLight_init();
        mWaitTimer = g_snHIO.mFileSelWaitTime;
        mDrawProc = 0;
        mProc = dScnName_PROC_FileSelectOpen;
        mDoGph_gInf_c::setTickRate(OS_TIMER_CLOCK / 30);

        #if VERSION == VERSION_GCN_PAL
        mBmgStatus = 0;
        #endif

        dComIfGp_getVibration().Init();
    }
    return phase_state;
}

#if VERSION == VERSION_GCN_PAL
static const char* dummyString(int i) {
    switch (i) {
    case 0: return "/res/Msguk/bmgres.arc";
    case 1: return "/res/Msgde/bmgres.arc";
    case 2: return "/res/Msgfr/bmgres.arc";
    case 3: return "/res/Msgsp/bmgres.arc";
    case 4: return "/res/Msgit/bmgres.arc";
    }
}
#endif

void dScnName_c::setView() {
    dDlst_window_c* window = dComIfGp_getWindow(0);
    view_port_class* viewport = window->getViewPort();
    camera_class* camera = &mCamera;

    C_MTXPerspective(camera->view.projMtx, camera->view.fovy, camera->view.aspect, camera->view.near,
                     camera->view.far);
    mDoMtx_lookAt(camera->view.viewMtx, &camera->view.lookat.eye, &camera->view.lookat.center,
                  camera->view.bank);
    cMtx_inverse(camera->view.viewMtx, camera->view.invViewMtx);
    MTXCopy(camera->view.viewMtx, camera->view.viewMtxNoTrans);
    camera->view.viewMtxNoTrans[0][3] = 0.0f;
    camera->view.viewMtxNoTrans[1][3] = 0.0f;
    camera->view.viewMtxNoTrans[2][3] = 0.0f;
    j3dSys.setViewMtx(camera->view.viewMtx);
    cMtx_concatProjView(camera->view.projMtx, camera->view.viewMtx, camera->view.projViewMtx);
}

#if PLATFORM_WII || PLATFORM_SHIELD
static void setBaseCsrColor(int i_no) {
    static const GXColor l_csrColor[] = {
        {255, 0, 0 , 0},
        {255, 0, 255 , 0},
        {0, 182, 255 , 0},
        {0, 255, 0 , 0},
        {255, 255, 0 , 0},
    };

    JUT_ASSERT(656, 0 <= i_no && i_no < (sizeof(l_csrColor)/sizeof(GXColor)));

    dComIfG_inf_c::baseCsr_c* baseCsr = dComIfG_inf_c::getBaseCsr();
    JUT_ASSERT(658, baseCsr != NULL);

    dDlst_blo_c* baseCsrBlo = baseCsr->getCsr();
    JUT_ASSERT(660, baseCsrBlo != NULL);

    const JUtility::TColor& color = l_csrColor[i_no];
    baseCsrBlo->setBlackColor('cursor00', color);
}
#endif

#if VERSION == VERSION_GCN_PAL
void dScnName_c::bmg_data_set() {
    if (fopAcM_GetName(this) == fpcNm_NAMEEX_SCENE_e) {
        mBmgStatus = 10;
    }
}

void dScnName_c::tex_data_set() {}
#endif

typedef void (dScnName_c::*mainProcFunc)(void);
static mainProcFunc MainProc[6] = {
    &dScnName_c::FileSelectOpen,  &dScnName_c::FileSelectMain, &dScnName_c::FileSelectClose,
    &dScnName_c::brightCheckOpen, &dScnName_c::brightCheck,    &dScnName_c::changeGameScene,
};

s32 dScnName_c::execute() {
    if (!fopOvlpM_IsPeek()) {
        dComIfG_resetToOpening(this);
    }

    if (mDoRst::isReset() && field_0x420 == 0 && !dFs_c->getFadeFlag()) {
        return 1;
    }

    (this->*MainProc[mProc])();

    #if DEBUG
    if (!fopOvlpM_IsPeek() && dComIfG_isSceneResetButton()) {
        fopScnM_ChangeReq(this, fpcNm_MENU_SCENE_e, 0, 5);
        dComIfGs_init();
        dComIfG_playerStatusD();
    }
    #endif

    return 1;
}

s32 dScnName_c::draw() {
    dComIfGp_getVibration().Run();

    switch (mDrawProc) {
    case 0:
        dFs_c->draw();
        break;
    case 1:
        mBrightCheck->draw();
        break;
    }

    #if VERSION == VERSION_SHIELD_DEBUG
    dComIfGp_particle_calc3D();
    dComIfGp_particle_calc2D();
    #endif
    return 1;
}

dScnName_c::~dScnName_c() {
    mDoHIO_DELETE_CHILD(g_snHIO.id);

    delete dFs_c;
    delete mBrightCheck;
    dComIfG_deleteObjectResMain("fileSel");
    mHeap->destroy();

    #if PLATFORM_WII || PLATFORM_SHIELD
    dComIfG_inf_c::baseCsr_c* baseCsr = dComIfG_inf_c::getBaseCsr();
    JUT_ASSERT(870, baseCsr != NULL);
    baseCsr->onNavi();
    setBaseCsrColor(2);
    #endif

    // Reset Hotspring Water bottles to normal water
    for (int i = 0; i < 4; i++) {
        dMeter2Info_changeWater(i + SLOT_11);
    }

    dComIfGp_setWindowNum(0);
    dComIfGd_setView(NULL);
}

void dScnName_c::FileSelectOpen() {
    if (mWaitTimer != 0) {
        mWaitTimer--;
    } else {
        mDoAud_bgmStreamPrepare(0x2000000);
        mDoAud_bgmStreamPlay();
        mProc = dScnName_PROC_FileSelectMain;
    }
}

void dScnName_c::FileSelectMain() {
    dFs_c->_move();

    if (fpcM_GetName(this) == fpcNm_NAME_SCENE_e) {
        FileSelectMainNormal();
    }
}

void dScnName_c::FileSelectMainNormal() {
    switch(dFs_c->isSelectEnd()) {
    case 1:
        mWaitTimer = 15;
        mDoGph_gInf_c::setFadeColor(*(JUtility::TColor*)&g_blackColor);
        mDoGph_gInf_c::startFadeOut(15);
        mProc = dScnName_PROC_FileSelectClose;
        field_0x420 = 1;
        break;
    }
}

void dScnName_c::FileSelectClose() {
    mWaitTimer--;

    if (mWaitTimer == 0) {
        mProc = dScnName_PROC_BrightCheckOpen;
        mWaitTimer = 15;
        mDrawProc = 1;
        mDoGph_gInf_c::setFadeColor(*(JUtility::TColor*)&g_blackColor);
        mDoGph_gInf_c::startFadeIn(15);
        field_0x420 = 0;
    }
}

void dScnName_c::brightCheckOpen() {
    if (!mDoRst::isReset()) {
        mWaitTimer--;
        if (mWaitTimer == 0) {
            mProc = dScnName_PROC_BrightCheck;
        }
    }
}

void dScnName_c::brightCheck() {
    mBrightCheck->_move();

    if (mBrightCheck->isEnd()) {
        dComIfGs_setSaveTotalTime(dComIfGs_getTotalTime());
        dComIfGs_setSaveStartTime(OSGetTime());
        mDoAud_bgmStop(45);

        field_0x41f = 0;
        mProc = dScnName_PROC_ChangeGameScene;

        // Reset rupee "first-time collection" flags so the collection cutscene will play again
        dComIfGs_offItemFirstBit(dItemNo_GREEN_RUPEE_e);
        dComIfGs_offItemFirstBit(dItemNo_BLUE_RUPEE_e);
        dComIfGs_offItemFirstBit(dItemNo_YELLOW_RUPEE_e);
        dComIfGs_offItemFirstBit(dItemNo_RED_RUPEE_e);
        dComIfGs_offItemFirstBit(dItemNo_PURPLE_RUPEE_e);
        dComIfGs_offItemFirstBit(dItemNo_ORANGE_RUPEE_e);
        dComIfGs_offItemFirstBit(dItemNo_SILVER_RUPEE_e);
    }
}

void dScnName_c::changeGameScene() {
    if (!mDoRst::isReset() && !fopOvlpM_IsPeek()) {
        dComIfGs_gameStart();

        #if DEBUG
        // Goto Map Select debug menu if opening File 1 with development mode on
        if (dFs_c->getSelectNum() == 0 && mDoMain::developmentMode) {
            fopScnM_ChangeReq(this, fpcNm_MENU_SCENE_e, 0, 5);
            dComIfGs_init();
            dComIfG_playerStatusD();
            return;
        }
        #endif

        #if VERSION == VERSION_SHIELD_DEBUG
        fopScnM_ChangeReq(this, fpcNm_PLAY_SCENE_e, 0, 5);
        #else
        fopScnM_ChangeReq(this, field_0x41f == 0 ? fpcNm_PLAY_SCENE_e : fpcNm_PLAY_SCENE_e, 0, 5);
        #endif
        dComIfGp_offEnableNextStage();

        if (dFs_c->isDataNew(dFs_c->getSelectNum())) {
            dComIfGp_setNextStage("F_SP108", 21, 1, 13);
        }
        
        dKy_clear_game_init();
        dComIfGs_resetDan();
        dComIfGs_setRestartRoomParam(0);
    }
}

static int dScnName_Draw(dScnName_c* i_this) {
    return i_this->draw();
}

static int dScnName_Execute(dScnName_c* i_this) {
    return i_this->execute();
}

static int dScnName_IsDelete(dScnName_c*) {
    dComIfGp_particle_cleanup();
    return 1;
}

static int dScnName_Delete(dScnName_c* i_this) {
    #if VERSION == VERSION_GCN_PAL
    i_this->bmg_data_set();
    i_this->tex_data_set();
    mBmgStatus = 0;
    #endif

    i_this->~dScnName_c();

    #if VERSION == VERSION_SHIELD_DEBUG
    dComIfGp_particle_removeScene(true);
    #endif

    return 1;
}

static int dScnName_Create(scene_class* i_this) {
    new (i_this) dScnName_c();
    return static_cast<dScnName_c*>(i_this)->create();
}

static scene_method_class l_dScnName_Method = {
    (process_method_func)dScnName_Create, (process_method_func)dScnName_Delete,
    (process_method_func)dScnName_Execute, (process_method_func)dScnName_IsDelete,
    (process_method_func)dScnName_Draw,
};

scene_process_profile_definition g_profile_NAME_SCENE = {
    /* Layer ID     */ fpcLy_ROOT_e,
    /* List ID      */ 1,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_NAME_SCENE_e,
    /* Proc SubMtd  */ &g_fpcNd_Method.base,
    /* Size         */ sizeof(dScnName_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopScn_Method.base,
    /* Scene SubMtd */ &l_dScnName_Method,
                       0,
};

scene_process_profile_definition g_profile_NAMEEX_SCENE = {
    /* Layer ID     */ fpcLy_ROOT_e,
    /* List ID      */ 1,
    /* List Prio    */ fpcPi_CURRENT_e,
    /* Proc Name    */ fpcNm_NAMEEX_SCENE_e,
    /* Proc SubMtd  */ &g_fpcNd_Method.base,
    /* Size         */ sizeof(dScnName_c),
    /* Size Other   */ 0,
    /* Parameters   */ 0,
    /* Leaf SubMtd  */ &g_fopScn_Method.base,
    /* Scene SubMtd */ &l_dScnName_Method,
                       0,
};