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 <nw4r/ut.h>
6#include <game/mLib/m_video.hpp>
7#include <game/mLib/m_vec.hpp>
8#include <game/bases/d_bg_parameter.hpp>
9#include <lib/egg/math/eggMath.h>
10
11dSmallScore_c *dSmallScore_c::m_instance = nullptr;
12
13dSmallScore_c::dSmallScore_c() : mPos(0.0f, 0.0f), mScale(1.0f, 1.0f), mPosDelta(0.0f, 0.0f), mInitialized(false), mIsGoalScore(false) {
14 mPlayerType = 0;
15}
16
17dSmallScore_c::~dSmallScore_c() {
18 dSmallScore_c::m_instance = nullptr;
19}
20
21bool dSmallScore_c::createLayout(d2d::ResAccMultLoader_c *res) {
22 static const char *T_PANE_NAME_TBL[] = {
23 "T_100_00", "T_1000_00", "T_red2_00", "T_1UP_00", "T_coin_x_00",
24 "T_coinPoint_00",
25 };
26
27 static const char *N_PANE_NAME_TBL[] = {
28 "N_coin_00"
29 };
30
31 if (mInitialized) {
32 return true;
33 }
34
35 mLayout.mpResAccessor = res;
36 mLayout.build("pointGet_02.brlyt", nullptr);
37 mpRootPane = mLayout.getRootPane();
38
39 mLayout.TPaneRegister(T_PANE_NAME_TBL, &T_100_00, ARRAY_SIZE(T_PANE_NAME_TBL));
40 T_coin_x_00->setMessage(dMessage_c::getMesRes(), BMG_CATEGORY_SMALL_SCORE, MSG_LOWERCASE_X, 0);
41
42 mLayout.NPaneRegister(N_PANE_NAME_TBL, &N_coin_00, ARRAY_SIZE(N_PANE_NAME_TBL));
43
44 T_100_00->SetVisible(false);
45 T_1000_00->SetVisible(false);
46 T_red2_00->SetVisible(false);
47 T_1UP_00->SetVisible(false);
48 T_coin_x_00->SetVisible(false);
49 T_coinPoint_00->SetVisible(false);
50
51 N_coin_00->SetVisible(false);
52 mpRootPane->SetVisible(false);
53
54 mLayout.mDrawOrder = 7;
55 mState = dSmallScore_c::STATE_NONE;
56 mInitialized = true;
57 mEnableColorChange = false;
58 mEnableBigSmallAnim = false;
59 mHasBlueColor = false;
60
61 return true;
62}
63
64void dSmallScore_c::execute() {
65
66 static const ProcFunc Proc_tbl[] = {
67 &dSmallScore_c::MakeStart,
68 &dSmallScore_c::UpMove,
69 &dSmallScore_c::DispWait,
70 &dSmallScore_c::GoalScoreDisp,
71 };
72
73 if (mState == dSmallScore_c::STATE_NONE) {
74 return;
75 }
76
77 (this->*Proc_tbl[mState])();
78 PositionSet();
79 mLayout.calc();
80}
81
82void dSmallScore_c::draw() {
83 if (mState == dSmallScore_c::STATE_NONE) {
84 return;
85 }
86
87 if (mState <= dSmallScore_c::STATE_MAKE_START) {
88 return;
89 }
90
91 mLayout.entry();
92}
93
94bool dSmallScore_c::doDelete() {
95 return mLayout.doDelete();
96}
97
98void dSmallScore_c::setPlayer1upColor(int player_id) {
99 dGameCom::Player1upColor(T_1UP_00, player_id);
100}
101
102void dSmallScore_c::setPlayer1000Color(int player_id) {
103 static const nw4r::ut::Color UP_COLOR_DATA_TBL[] = {
104 nw4r::ut::Color(255, 120, 0, 255), // #FF7800
105 nw4r::ut::Color(50, 250, 50, 255), // #32FA32
106 nw4r::ut::Color(0, 185, 220, 255), // #00B9DC
107 nw4r::ut::Color(255, 255, 0, 255), // #FFFF00
108 nw4r::ut::Color(255, 255, 255, 255), // #FFFFFF
109 };
110
111 static const nw4r::ut::Color DOWN_COLOR_DATA_TBL[] = {
112 nw4r::ut::Color(255, 200, 40, 255), // #FFC828
113 nw4r::ut::Color(255, 255, 0, 255), // #FFFF00
114 nw4r::ut::Color(210, 255, 250, 255), // #D2FFFA
115 nw4r::ut::Color(255, 255, 180, 255), // #FFFFB4
116 nw4r::ut::Color(255, 255, 255, 255), // #FFFFFF
117 };
118
119 T_1000_00->SetVtxColor(0, UP_COLOR_DATA_TBL[player_id]);
120 T_1000_00->SetVtxColor(2, DOWN_COLOR_DATA_TBL[player_id]);
121}
122
123void dSmallScore_c::setPlayer100Color(int playerType) {
124 static const nw4r::ut::Color COLOR_DATA_TBL[] = {
125 nw4r::ut::Color(255, 150, 85, 255), // #FF9655
126 nw4r::ut::Color(70, 250, 70, 255), // #46FA46
127 nw4r::ut::Color(70, 200, 230, 255), // #46C8E6
128 nw4r::ut::Color(250, 255, 80, 255), // #FAFF50
129 nw4r::ut::Color(250, 255, 255, 255), // #FFFFFF
130 };
131
132 nw4r::lyt::Material *mat = T_100_00->GetMaterial();
133 GXColorS10 col = nw4r::g3d::detail::GetRGBAS10(COLOR_DATA_TBL[playerType]);
134 mat->SetTevColor(1, col);
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::ScissorMask scissorMask;
185 scissorMask.mPos.x = 0.0f;
186 scissorMask.mPos.y = 0.0f;
187 scissorMask.mSize.x = 0.0f;
188 scissorMask.mSize.y = 0.0f;
189 scissorMask.mEnabled = false;
190
191 if (dGameCom::GetAspectRatio() == 0) {
192 scissorMask.mPos.y = (mVideo::m_video->mRenderModeObj.efbHeight - mClipScale.y) * 0.5f;
193 scissorMask.mSize = mClipScale;
194 scissorMask.mEnabled = 1;
195 }
196
197 mLayout.mScissorMask = scissorMask;
198}
199
200void dSmallScore_c::BigSmallAnime() {
201 mVec2_c sum = mScale;
202 mVec2_c delta(0.08f, 0.08f);
203 sum += mAnimScale;
204
205 getTextBox(mCurTextbox)->SetScale(sum);
206 if (++mAnimCounter >= 10) {
207 mAnimCounter = 0;
208
209 if (mAnimIsShrinking) {
210 mAnimIsShrinking = false;
211 } else {
212 mAnimIsShrinking = true;
213 }
214 }
215
216 if (mAnimIsShrinking) {
217 mAnimScale -= delta;
218 } else {
219 mAnimScale += delta;
220 }
221}
222
223void dSmallScore_c::MakeStart() {
224 static const u32 SUB_ID_TBL[] = {
225 MSG_100, MSG_200, MSG_400, MSG_800, MSG_1000, MSG_2000, MSG_4000,
226 MSG_8000, MSG_ONE, MSG_TWO, MSG_THREE, MSG_FOUR, MSG_FIVE, MSG_SIX,
227 MSG_SEVEN, MSG_EIGHT, MSG_1UP, MSG_2UP, MSG_3UP, MSG_4UP, MSG_1UP,
228 MSG_COIN_2, MSG_COIN_3, MSG_COIN_5, MSG_COIN_10, MSG_COIN_15,
229 MSG_COIN_20
230 };
231
232 int temp = mPopupType;
233 mPlayerColor = mPlayerType;
234 if (temp >= 21) {
235 temp = 5;
236
237 T_coin_x_00->SetVisible(true);
238 T_coinPoint_00->SetVisible(true);
239 N_coin_00->SetVisible(true);
240 } else {
241 if (temp <= 3) {
242 setPlayer100Color(mPlayerType);
243 temp = 0;
244 } else if (temp <= 7) {
245 setPlayer1000Color(mPlayerType);
246 temp = 1;
247 } else if (temp <= 15) {
248 setNormalOrBlueColor();
249 temp = 2;
250 } else {
251 setPlayer1upColor(mPlayerType);
252 temp = 3;
253 }
254
255 getTextBox(temp)->SetVisible(true);
256 }
257
258 MsgRes_c *bmg = dMessage_c::getMesRes();
259
260 getTextBox(temp)->setMessage(bmg, BMG_CATEGORY_SMALL_SCORE, SUB_ID_TBL[mPopupType], 0);
261 getTextBox(temp)->SetScale(mScale);
262 mCurTextbox = temp;
263 mMaxHeight = dBgParameter_c::ms_Instance_p->mPos.y - 20.0f;
264 mpRootPane->SetVisible(true);
265
266 if (mIsGoalScore) {
267 mState = dSmallScore_c::STATE_GOAL_DISP;
268 } else {
269 mPosDelta.y = 1.0f;
270 mPosDeceleration.y = 0.025f;
271 mDispWaitTime = 0;
273 mAnimCounter = 0;
274 mAnimIsShrinking = false;
275 mAnimScale.x = 0.0f;
276 mAnimScale.y = 0.0f;
277 mState = dSmallScore_c::STATE_UP_MOVE;
278 }
279
280 if (mPopupType == 20) {
281 mEnableColorChange = true;
282 } else {
283 mEnableColorChange = false;
284 }
285
287 ScissorMaskSet();
288}
289
290void dSmallScore_c::UpMove() {
291 if (mEnableBigSmallAnim) {
292 BigSmallAnime();
293 mDispWaitTime = 120;
294 }
295
296 chgColor();
297
298 if (mPosDelta.y == EGG::Math<float>::zero()) {
299 mState = dSmallScore_c::STATE_DISP_WAIT;
300 if (mPopupType >= 21) {
301 mDispWaitTime = 30;
302 }
303 }
304}
305
306void dSmallScore_c::DispWait() {
307 if (mEnableBigSmallAnim) {
308 BigSmallAnime();
309 }
310
311 chgColor();
312
314 if (mPlayerType == 4) {
315 if (mDispWaitCounter < 60) {
316 return;
317 }
318 } else if (mDispWaitCounter < mDispWaitTime) {
319 return;
320 }
321
323 mpRootPane->SetVisible(false);
324 T_100_00->SetVisible(false);
325 T_1000_00->SetVisible(false);
326 T_red2_00->SetVisible(false);
327 T_1UP_00->SetVisible(false);
328 T_coin_x_00->SetVisible(false);
329 T_coinPoint_00->SetVisible(false);
330 N_coin_00->SetVisible(false);
331 mEnableBigSmallAnim = false;
332 getTextBox(mCurTextbox)->SetScale(mScale);
333 mState = dSmallScore_c::STATE_NONE;
334}
335
336void dSmallScore_c::GoalScoreDisp() {}
337
338void dSmallScore_c::PositionSet() {
339 if (!mpRootPane->IsVisible()) {
340 return;
341 }
342
343 if (mPosDelta.y <= 0.0f) {
344 mPosDelta.y = 0.0f;
345 } else {
346 mPosOffset.y += mPosDelta.y;
347 mPosDelta.y -= mPosDeceleration.y;
348 }
349
350 mVec3_c globalPos;
351 globalPos.x = mPos.x;
352 globalPos.y = mPos.y + mPosOffset.y;
353
354 if (globalPos.y >= mMaxHeight) {
355 globalPos.y = mMaxHeight;
356 }
357
358 dGameCom::getGlbPosToLyt(globalPos);
359 mVec2_c pos;
360 pos.x = globalPos.x;
361 pos.y = globalPos.y;
362
363 mpRootPane->SetTranslate(mVec3_c(pos, 0.0f));
364}
365
366void dSmallScore_c::CreateSmallScore(const mVec3_c &pos, int popupType, int playerType) {
367 mpRootPane->SetVisible(false);
368
369 if ((dInfo_c::mGameFlag & dInfo_c::GAME_FLAG_IS_COIN_COURSE) && (popupType <= 7))
370 return;
371
372 mPopupType = popupType;
373 mPlayerType = playerType;
374 mPos.x = pos.x;
375 mPos.y = pos.y;
376 mPosDelta.x = 0.0f;
377 mPosDelta.y = 0.0f;
378 mPosOffset.x = 0.0f;
379 mPosOffset.y = 0.0f;
380 mIsGoalScore = false;
381 mState = dSmallScore_c::STATE_MAKE_START;
382}
383
384void dSmallScore_c::PosSet(const mVec3_c &pos) {
385 mPos.x = pos.x;
386 mPos.y = pos.y;
387}
void setMessage(MsgRes_c *bmg, ulong messageGroup, ulong messageID, long placeholderCount,...)
Sets the message to display in the text box.
static unsigned int mGameFlag
See GAME_FLAG_e.
Definition d_info.hpp:89
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