summaryrefslogtreecommitdiff
path: root/src/d/msg/d_msg_scrn_light.cpp
blob: 945d3f3a939923cc1abb3239e63ea131cbabc717 (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
#include "d/msg/d_msg_scrn_light.h"
#include "JSystem/J2DGraph/J2DAnmLoader.h"
#include "JSystem/J2DGraph/J2DGrafContext.h"
#include "JSystem/J2DGraph/J2DScreen.h"
#include "d/com/d_com_inf_game.h"
#include "d/pane/d_pane_class.h"

class dMsgScrnLight_HIO_c {
public:
    /* 8024575C */ dMsgScrnLight_HIO_c();
    /* 802457C4 */ void updateColor(u8);
    /* 80246348 */ virtual ~dMsgScrnLight_HIO_c() {}

    enum {
        COLOR_DEFAULT_e,
        COLOR_RED_e,
        COLOR_GREEN_e,
        COLOR_BLUE_e,
        COLOR_YELLOW_e,
        COLOR_LIGHT_BLUE_e,
        COLOR_PURPLE_e,
        COLOR_GREY_e,
        COLOR_ORANGE_e,
        COLOR_MAX_e,
    };

    /* 0x04 */ s8 field_0x04;
    /* 0x05 */ bool mDebugON;
    /* 0x06 */ u8 mBlackR[COLOR_MAX_e];
    /* 0x0F */ u8 mWhiteR[COLOR_MAX_e];
    /* 0x18 */ u8 mBlackG[COLOR_MAX_e];
    /* 0x21 */ u8 mWhiteG[COLOR_MAX_e];
    /* 0x2A */ u8 mBlackB[COLOR_MAX_e];
    /* 0x33 */ u8 mWhiteB[COLOR_MAX_e];
    /* 0x3C */ u8 mBlackA[COLOR_MAX_e];
    /* 0x45 */ u8 mWhiteA[COLOR_MAX_e];
};

/* 8024575C-802457C4 24009C 0068+00 1/1 0/0 0/0 .text            __ct__19dMsgScrnLight_HIO_cFv */
dMsgScrnLight_HIO_c::dMsgScrnLight_HIO_c() {
    mDebugON = false;

    for (int i = 0; i < COLOR_MAX_e; i++) {
        mBlackR[i] = 160;
        mBlackG[i] = 135;
        mBlackB[i] = 20;
        mBlackA[i] = 0;

        mWhiteR[i] = 225;
        mWhiteG[i] = 210;
        mWhiteB[i] = 110;
        mWhiteA[i] = 210;
    }
}

/* 802457C4-80245934 240104 0170+00 1/1 0/0 0/0 .text updateColor__19dMsgScrnLight_HIO_cFUc */
void dMsgScrnLight_HIO_c::updateColor(u8 i_colorType) {
    switch (i_colorType) {
    case 0:
        for (int i = 0; i < COLOR_MAX_e; i++) {
            mBlackR[i] = 160;
            mBlackG[i] = 135;
            mBlackB[i] = 20;
            mBlackA[i] = 0;

            mWhiteR[i] = 225;
            mWhiteG[i] = 210;
            mWhiteB[i] = 110;
            mWhiteA[i] = 160;
        }
        break;
    case 2:
        for (int i = 0; i < COLOR_MAX_e; i++) {
            mBlackR[i] = 255;
            mBlackG[i] = 250;
            mBlackB[i] = 150;
            mBlackA[i] = 0;

            mWhiteR[i] = 255;
            mWhiteG[i] = 255;
            mWhiteB[i] = 110;
            mWhiteA[i] = 210;
        }
        break;
    case 1:
        for (int i = 0; i < COLOR_MAX_e; i++) {
            mBlackR[i] = 40;
            mBlackG[i] = 110;
            mBlackB[i] = 180;
            mBlackA[i] = 0;

            mWhiteR[i] = 40;
            mWhiteG[i] = 110;
            mWhiteB[i] = 180;
            mWhiteA[i] = 120;
        }
        break;
    case 4:
        for (int i = 0; i < COLOR_MAX_e; i++) {
            mBlackR[i] = 70;
            mBlackG[i] = 150;
            mBlackB[i] = 0;
            mBlackA[i] = 0;

            mWhiteR[i] = 70;
            mWhiteG[i] = 150;
            mWhiteB[i] = 0;
            mWhiteA[i] = 150;
        }
        break;
    }
}

/* 804306D4-80430728 05D3F4 0050+04 3/3 0/0 0/0 .bss             g_MsgScrnLight_HIO_c */
static dMsgScrnLight_HIO_c g_MsgScrnLight_HIO_c;

static u8 l_lightCount;

/* 80245934-80245B00 240274 01CC+00 0/0 4/4 1/1 .text            __ct__15dMsgScrnLight_cFUcUc */
dMsgScrnLight_c::dMsgScrnLight_c(u8 i_colorType, u8 param_1) {
    mColorType = i_colorType;
    field_0x21 = param_1;

    if (l_lightCount == 0) {
        g_MsgScrnLight_HIO_c.field_0x04 = -1;
    }
    l_lightCount++;

    g_MsgScrnLight_HIO_c.updateColor(i_colorType);

    mpScreen = new J2DScreen();
    JUT_ASSERT(mpScreen != 0);
    bool fg = mpScreen->setPriority("zelda_message_window_text_light.blo", 0x20000,
                                    dComIfGp_getMain2DArchive());
    JUT_ASSERT(fg != false);
    dPaneClass_showNullPane(mpScreen);

    OSInitFastCast();
    mpBck = (J2DAnmTransform*)J2DAnmLoaderDataBase::load(
        JKRGetNameResource("zelda_message_window_text_light.bck", dComIfGp_getMain2DArchive()));
    mBckFrame = 0.0f;

    mpBpk = (J2DAnmColorKey*)J2DAnmLoaderDataBase::load(
        JKRGetNameResource("zelda_message_window_text_light.bpk", dComIfGp_getMain2DArchive()));
    mpBpk->searchUpdateMaterialID(mpScreen);
    mBpkFrame = 0.0f;

    mpParent_c = new CPaneMgr(mpScreen, 'moya00', 0, NULL);
    JUT_ASSERT(mpParent_c != 0);

    mpParent_c->getPanePtr()->setAnimation(mpBck);
    mpParent_c->getPanePtr()->setAnimation(mpBpk);
    mPlayAnim = true;
    mAlpha = 0.0f;
}

/* 80245B00-80245C04 240440 0104+00 1/0 0/0 0/0 .text            __dt__15dMsgScrnLight_cFv */
dMsgScrnLight_c::~dMsgScrnLight_c() {
    l_lightCount--;

    delete mpScreen;
    mpScreen = NULL;

    delete mpBck;
    mpBck = NULL;

    delete mpBpk;
    mpBpk = NULL;

    delete mpParent_c;
    mpParent_c = NULL;
}

/* 80245C04-80245F90 240544 038C+00 0/0 2/2 0/0 .text            draw__15dMsgScrnLight_cFPffffffUc
 */
void dMsgScrnLight_c::draw(f32* i_anmFrame, f32 i_posX, f32 i_posY, f32 i_scaleX, f32 i_scaleY,
                           f32 i_alpha, u8 i_colorType) {
    if (g_MsgScrnLight_HIO_c.mDebugON) {
        if (i_colorType < dMsgScrnLight_HIO_c::COLOR_MAX_e) {
            mpParent_c->setBlackWhite(JUtility::TColor(g_MsgScrnLight_HIO_c.mBlackR[i_colorType],
                                                       g_MsgScrnLight_HIO_c.mBlackG[i_colorType],
                                                       g_MsgScrnLight_HIO_c.mBlackB[i_colorType],
                                                       g_MsgScrnLight_HIO_c.mBlackA[i_colorType]),
                                      JUtility::TColor(g_MsgScrnLight_HIO_c.mWhiteR[i_colorType],
                                                       g_MsgScrnLight_HIO_c.mWhiteG[i_colorType],
                                                       g_MsgScrnLight_HIO_c.mWhiteB[i_colorType],
                                                       g_MsgScrnLight_HIO_c.mWhiteA[i_colorType]));
        } else {
            mpParent_c->setBlackWhite(mpParent_c->getInitBlack(), mpParent_c->getInitWhite());
        }
    } else {
        if (mColorType == 0) {
            mpParent_c->setBlackWhite(JUtility::TColor(160, 135, 20, 0),
                                      JUtility::TColor(225, 210, 110, 160));
        } else if (mColorType == 2) {
            mpParent_c->setBlackWhite(JUtility::TColor(255, 255, 150, 0),
                                      JUtility::TColor(255, 255, 110, 210));
        } else if (mColorType == 1) {
            mpParent_c->setBlackWhite(JUtility::TColor(40, 110, 180, 0),
                                      JUtility::TColor(40, 110, 180, 120));
        } else if (mColorType == 4) {
            mpParent_c->setBlackWhite(JUtility::TColor(70, 150, 0, 0),
                                      JUtility::TColor(70, 150, 0, 150));
        } else {
            mpParent_c->setBlackWhite(mpParent_c->getInitBlack(), mpParent_c->getInitWhite());
        }
    }

    if (mPlayAnim) {
        *i_anmFrame += 1.0f;
        if (*i_anmFrame >= mpBck->getFrameMax()) {
            *i_anmFrame = 0.0f;
        }

        mBckFrame = *i_anmFrame;
        mBpkFrame = *i_anmFrame;
    }

    drawCommon(i_posX, i_posY, i_scaleX, i_scaleY, i_alpha);
}

/* 80245F90-802460DC 2408D0 014C+00 0/0 1/1 1/1 .text
 * draw__15dMsgScrnLight_cFPfffffffQ28JUtility6TColorQ28JUtility6TColor */
void dMsgScrnLight_c::draw(f32* i_anmFrame, f32 i_posX, f32 i_posY, f32 i_scaleX, f32 i_scaleY,
                           f32 i_alpha, f32 i_anmRate, JUtility::TColor i_black,
                           JUtility::TColor i_white) {
    mpParent_c->setBlackWhite(i_black, i_white);

    if (mPlayAnim) {
        *i_anmFrame += i_anmRate;

        if (*i_anmFrame >= mpBck->getFrameMax()) {
            *i_anmFrame = 0.0f;
        }

        mBckFrame = *i_anmFrame;
        mBpkFrame = *i_anmFrame;
    }

    drawCommon(i_posX, i_posY, i_scaleX, i_scaleY, i_alpha);
}

/* 802460DC-80246348 240A1C 026C+00 2/2 0/0 0/0 .text            drawCommon__15dMsgScrnLight_cFfffff
 */
void dMsgScrnLight_c::drawCommon(f32 i_posX, f32 i_posY, f32 i_scaleX, f32 i_scaleY, f32 i_alpha) {
    J2DGrafContext* graf_ctx = dComIfGp_getCurrentGrafPort();
    graf_ctx->setup2D();

    f32 alpha_rate = mpParent_c->getAlphaRate();

    if (((field_0x21 == 3 || field_0x21 == 5) && i_alpha < mAlpha) ||
        (field_0x21 != 3 && field_0x21 != 5 && i_alpha != 1.0f))
    {
        if (mPlayAnim) {
            mpParent_c->getPanePtr()->setAnimation((J2DAnmTransform*)NULL);
            mpParent_c->getPanePtr()->setAnimation((J2DAnmColorKey*)NULL);
            mPlayAnim = false;
        }

        mpParent_c->setAlphaRate(alpha_rate * i_alpha);
    } else if (!mPlayAnim) {
        mpParent_c->getPanePtr()->setAnimation(mpBck);
        mpParent_c->getPanePtr()->setAnimation(mpBpk);
        mPlayAnim = true;
    }

    if (mPlayAnim) {
        mpBck->setFrame(mBckFrame);
        mpBpk->setFrame(mBpkFrame);
        mpParent_c->getPanePtr()->animationTransform();
        mpScreen->animation();
    }

    mpParent_c->translate(i_posX, i_posY);

    f32 init_scale_x = mpParent_c->getInitScaleX();
    f32 init_scale_y = mpParent_c->getInitScaleY();
    mpParent_c->scale(init_scale_x * i_scaleX, init_scale_y * i_scaleY);
    mpScreen->draw(0.0f, 0.0f, graf_ctx);

    if (i_alpha != 1.0f) {
        mpParent_c->setAlphaRate(alpha_rate);
    }

    mAlpha = i_alpha;
}