NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_SmallScore.cpp
1#include <game/bases/d_SmallScore.hpp>
3#include <game/bases/d_info.hpp>
4#include <game/bases/d_game_com.hpp>
5#include <lib/nw4r/ut/color.hpp>
6#include <lib/nw4r/lyt/lyt_material.hpp>
7#include <game/mLib/m_video.hpp>
8#include <game/mLib/m_vec.hpp>
9#include <game/bases/d_bg_parameter.hpp>
10#include <lib/egg/math.hpp>
11
12dSmallScore_c *dSmallScore_c::m_instance = nullptr;
13
14dSmallScore_c::dSmallScore_c() : mPos(0.0f, 0.0f), mScale(1.0f, 1.0f), mPosDelta(0.0f, 0.0f), mInitialized(false), mIsGoalScore(false) {
15 mPlayerType = 0;
16}
17
18dSmallScore_c::~dSmallScore_c() {
19 dSmallScore_c::m_instance = nullptr;
20}
21
22bool dSmallScore_c::createLayout(d2d::ResAccMultLoader_c *res) {
23 static const char *T_PANE_NAME_TBL[] = {
24 "T_100_00", "T_1000_00", "T_red2_00", "T_1UP_00", "T_coin_x_00",
25 "T_coinPoint_00",
26 };
27
28 static const char *N_PANE_NAME_TBL[] = {
29 "N_coin_00"
30 };
31
32 if (mInitialized) {
33 return true;
34 }
35
36 mLayout.mpResAccessor = res;
37 mLayout.build("pointGet_02.brlyt", nullptr);
38 mpRootPane = mLayout.getRootPane();
39
40 mLayout.TPaneRegister(T_PANE_NAME_TBL, &T_100_00, ARRAY_SIZE(T_PANE_NAME_TBL));
41 T_coin_x_00->setMessage(dMessage_c::getMesRes(), BMG_CATEGORY_SMALL_SCORE, MSG_LOWERCASE_X, 0);
42
43 mLayout.NPaneRegister(N_PANE_NAME_TBL, &N_coin_00, ARRAY_SIZE(N_PANE_NAME_TBL));
44
45 T_100_00->setVisible(false);
46 T_1000_00->setVisible(false);
47 T_red2_00->setVisible(false);
48 T_1UP_00->setVisible(false);
49 T_coin_x_00->setVisible(false);
50 T_coinPoint_00->setVisible(false);
51
52 N_coin_00->setVisible(false);
53 mpRootPane->setVisible(false);
54
55 mLayout.mDrawOrder = 7;
56 mState = dSmallScore_c::STATE_NONE;
57 mInitialized = true;
58 mEnableColorChange = false;
59 mEnableBigSmallAnim = false;
60 mHasBlueColor = false;
61
62 return true;
63}
64
65void dSmallScore_c::execute() {
66
67 static const ProcFunc Proc_tbl[] = {
68 &dSmallScore_c::MakeStart,
69 &dSmallScore_c::UpMove,
70 &dSmallScore_c::DispWait,
71 &dSmallScore_c::GoalScoreDisp,
72 };
73
74 if (mState == dSmallScore_c::STATE_NONE) {
75 return;
76 }
77
78 (this->*Proc_tbl[mState])();
79 PositionSet();
80 mLayout.calc();
81}
82
83void dSmallScore_c::draw() {
84 if (mState == dSmallScore_c::STATE_NONE) {
85 return;
86 }
87
88 if (mState <= dSmallScore_c::STATE_MAKE_START) {
89 return;
90 }
91
92 mLayout.entry();
93}
94
95void dSmallScore_c::doDelete() {
96 mLayout.doDelete();
97}
98
99void dSmallScore_c::setPlayer1upColor(int player_id) {
100 dGameCom::Player1upColor(T_1UP_00, player_id);
101}
102
103void dSmallScore_c::setPlayer1000Color(int player_id) {
104 static const nw4r::ut::Color UP_COLOR_DATA_TBL[] = {
105 nw4r::ut::Color(255, 120, 0, 255), // #FF7800
106 nw4r::ut::Color(50, 250, 50, 255), // #32FA32
107 nw4r::ut::Color(0, 185, 220, 255), // #00B9DC
108 nw4r::ut::Color(255, 255, 0, 255), // #FFFF00
109 nw4r::ut::Color(255, 255, 255, 255), // #FFFFFF
110 };
111
112 static const nw4r::ut::Color DOWN_COLOR_DATA_TBL[] = {
113 nw4r::ut::Color(255, 200, 40, 255), // #FFC828
114 nw4r::ut::Color(255, 255, 0, 255), // #FFFF00
115 nw4r::ut::Color(210, 255, 250, 255), // #D2FFFA
116 nw4r::ut::Color(255, 255, 180, 255), // #FFFFB4
117 nw4r::ut::Color(255, 255, 255, 255), // #FFFFFF
118 };
119
120 T_1000_00->SetVtxColor(0, UP_COLOR_DATA_TBL[player_id]);
121 T_1000_00->SetVtxColor(2, DOWN_COLOR_DATA_TBL[player_id]);
122}
123
124void dSmallScore_c::setPlayer100Color(int playerType) {
125 static const nw4r::ut::Color COLOR_DATA_TBL[] = {
126 nw4r::ut::Color(255, 150, 85, 255), // #FF9655
127 nw4r::ut::Color(70, 250, 70, 255), // #46FA46
128 nw4r::ut::Color(70, 200, 230, 255), // #46C8E6
129 nw4r::ut::Color(250, 255, 80, 255), // #FAFF50
130 nw4r::ut::Color(250, 255, 255, 255), // #FFFFFF
131 };
132
133 nw4r::lyt::Material *mat = T_100_00->GetMaterial();
134 mat->setTev(1, nw4r::lyt::GXColorS10(COLOR_DATA_TBL[playerType]));
135}
136
137void dSmallScore_c::chgColor() {
138 if (!mEnableColorChange) {
139 return;
140 }
141 if (++mChgColorCounter < 10) {
142 return;
143 }
145
146 int type = mPlayerColor;
147
148 while (true) {
149 if (++type >= 4) {
150 type = 0;
151 break;
152 }
153
154 if (dInfo_c::m_instance->mCharIDs[type] == 3) {
155 break;
156 }
157 }
158
159 setPlayer1upColor(type);
160 mPlayerColor = type;
161}
162
163void dSmallScore_c::setNormalOrBlueColor() {
164 static const nw4r::ut::Color UP_COLOR_DATA_TBL[] = {
165 nw4r::ut::Color(255, 10, 10, 255), // #FF0A0A
166 nw4r::ut::Color(60, 120, 255, 255), // #3C78FF
167 };
168 static const nw4r::ut::Color DOWN_COLOR_DATA_TBL[] = {
169 nw4r::ut::Color(255, 150, 150, 255), // #FF9696
170 nw4r::ut::Color(200, 240, 255, 255), // #C8F0FF
171 };
172
173 int colorIdx = 0;
174 if (mHasBlueColor) {
175 mHasBlueColor = false;
176 colorIdx = 1;
177 }
178
179 T_red2_00->SetVtxColor(0, UP_COLOR_DATA_TBL[colorIdx]);
180 T_red2_00->SetVtxColor(2, DOWN_COLOR_DATA_TBL[colorIdx]);
181}
182
183void dSmallScore_c::ScissorMaskSet() {
184 d2d::ClipSettings clip;
185
186 if (dGameCom::GetAspectRatio() == 0) {
187 clip.mPos.y = (mVideo::m_video->mRenderModeObj.mEFBHeight - mClipScale.y) * 0.5f;
188 clip.mSize = mClipScale;
189 clip.mEnabled = 1;
190 }
191
192 mLayout.mClipSettings = clip;
193}
194
195void dSmallScore_c::BigSmallAnime() {
196 mVec2_c sum = mScale;
197 mVec2_c delta(0.08f, 0.08f);
198 sum += mAnimScale;
199
200 getTextBox(mCurTextbox)->setScale(sum);
201 if (++mAnimCounter >= 10) {
202 mAnimCounter = 0;
203
204 if (mAnimIsShrinking) {
205 mAnimIsShrinking = false;
206 } else {
207 mAnimIsShrinking = true;
208 }
209 }
210
211 if (mAnimIsShrinking) {
212 mAnimScale -= delta;
213 } else {
214 mAnimScale += delta;
215 }
216}
217
218void dSmallScore_c::MakeStart() {
219 static const u32 SUB_ID_TBL[] = {
220 MSG_100, MSG_200, MSG_400, MSG_800, MSG_1000, MSG_2000, MSG_4000,
221 MSG_8000, MSG_ONE, MSG_TWO, MSG_THREE, MSG_FOUR, MSG_FIVE, MSG_SIX,
222 MSG_SEVEN, MSG_EIGHT, MSG_1UP, MSG_2UP, MSG_3UP, MSG_4UP, MSG_1UP,
223 MSG_COIN_2, MSG_COIN_3, MSG_COIN_5, MSG_COIN_10, MSG_COIN_15,
224 MSG_COIN_20
225 };
226
227 int temp = mPopupType;
228 mPlayerColor = mPlayerType;
229 if (temp >= 21) {
230 temp = 5;
231
232 T_coin_x_00->setVisible(true);
233 T_coinPoint_00->setVisible(true);
234 N_coin_00->setVisible(true);
235 } else {
236 if (temp <= 3) {
237 setPlayer100Color(mPlayerType);
238 temp = 0;
239 } else if (temp <= 7) {
240 setPlayer1000Color(mPlayerType);
241 temp = 1;
242 } else if (temp <= 15) {
243 setNormalOrBlueColor();
244 temp = 2;
245 } else {
246 setPlayer1upColor(mPlayerType);
247 temp = 3;
248 }
249
250 getTextBox(temp)->setVisible(true);
251 }
252
253 MsgRes_c *bmg = dMessage_c::getMesRes();
254
255 getTextBox(temp)->setMessage(bmg, BMG_CATEGORY_SMALL_SCORE, SUB_ID_TBL[mPopupType], 0);
256 getTextBox(temp)->setScale(mScale);
257 mCurTextbox = temp;
258 mMaxHeight = dBgParameter_c::ms_Instance_p->mPos.y - 20.0f;
259 mpRootPane->setVisible(true);
260
261 if (mIsGoalScore) {
262 mState = dSmallScore_c::STATE_GOAL_DISP;
263 } else {
264 mPosDelta.y = 1.0f;
265 mPosDeceleration.y = 0.025f;
266 mDispWaitTime = 0;
268 mAnimCounter = 0;
269 mAnimIsShrinking = false;
270 mAnimScale.x = 0.0f;
271 mAnimScale.y = 0.0f;
272 mState = dSmallScore_c::STATE_UP_MOVE;
273 }
274
275 if (mPopupType == 20) {
276 mEnableColorChange = true;
277 } else {
278 mEnableColorChange = false;
279 }
280
282 ScissorMaskSet();
283}
284
285void dSmallScore_c::UpMove() {
286 if (mEnableBigSmallAnim) {
287 BigSmallAnime();
288 mDispWaitTime = 120;
289 }
290
291 chgColor();
292
293 if (mPosDelta.y == EGG::Math<float>::zero()) {
294 mState = dSmallScore_c::STATE_DISP_WAIT;
295 if (mPopupType >= 21) {
296 mDispWaitTime = 30;
297 }
298 }
299}
300
301void dSmallScore_c::DispWait() {
302 if (mEnableBigSmallAnim) {
303 BigSmallAnime();
304 }
305
306 chgColor();
307
309 if (mPlayerType == 4) {
310 if (mDispWaitCounter < 60) {
311 return;
312 }
313 } else if (mDispWaitCounter < mDispWaitTime) {
314 return;
315 }
316
318 mpRootPane->setVisible(false);
319 T_100_00->setVisible(false);
320 T_1000_00->setVisible(false);
321 T_red2_00->setVisible(false);
322 T_1UP_00->setVisible(false);
323 T_coin_x_00->setVisible(false);
324 T_coinPoint_00->setVisible(false);
325 N_coin_00->setVisible(false);
326 mEnableBigSmallAnim = false;
327 getTextBox(mCurTextbox)->setScale(mScale);
328 mState = dSmallScore_c::STATE_NONE;
329}
330
331void dSmallScore_c::GoalScoreDisp() {}
332
333void dSmallScore_c::PositionSet() {
334 if (!(mpRootPane->mFlags & 1)) {
335 return;
336 }
337
338 if (mPosDelta.y <= 0.0f) {
339 mPosDelta.y = 0.0f;
340 } else {
341 mPosOffset.y += mPosDelta.y;
342 mPosDelta.y -= mPosDeceleration.y;
343 }
344
345 mVec3_c globalPos;
346 globalPos.x = mPos.x;
347 globalPos.y = mPos.y + mPosOffset.y;
348
349 if (globalPos.y >= mMaxHeight) {
350 globalPos.y = mMaxHeight;
351 }
352
353 dGameCom::getGlbPosToLyt(globalPos);
354 mVec2_c pos;
355 pos.x = globalPos.x;
356 pos.y = globalPos.y;
357
358 mpRootPane->mPos = mVec3_c(pos, 0.0f);
359}
360
361void dSmallScore_c::CreateSmallScore(const mVec3_c &pos, int popupType, int playerType) {
362 mpRootPane->setVisible(false);
363
364 if ((dInfo_c::mGameFlag & 0x40) && (popupType <= 7))
365 return;
366
367 mPopupType = popupType;
368 mPlayerType = playerType;
369 mPos.x = pos.x;
370 mPos.y = pos.y;
371 mPosDelta.x = 0.0f;
372 mPosDelta.y = 0.0f;
373 mPosOffset.x = 0.0f;
374 mPosOffset.y = 0.0f;
375 mIsGoalScore = false;
376 mState = dSmallScore_c::STATE_MAKE_START;
377}
378
379void dSmallScore_c::PosSet(const mVec3_c &pos) {
380 mPos.x = pos.x;
381 mPos.y = pos.y;
382}
int mChgColorCounter
Counter that is incremented every call to dSmallScore_c::chgColor(), which ensures that the 1-up colo...
STATE_e mState
Determines the state the score popup is in.
int mDispWaitCounter
Counter that is incremented every frame while in the 'DispWait' state.
int mDispWaitTime
Number of frames to wait in 'DispWait' (unless mPlayerType is 4, in which case the default value is 6...
LytTextBox_c * getTextBox(int n)
Gets the n-th text box.
A three-dimensional floating point vector.
Definition m_vec.hpp:100