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
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
20
21bool dSmallScore_c::createLayout(d2d::ResAccMultLoader_c *res) {
22 static const char *T_PANE_NAME_TBL[T_COUNT] = {
23 "T_100_00",
24 "T_1000_00",
25 "T_red2_00",
26 "T_1UP_00",
27 "T_coin_x_00",
28 "T_coinPoint_00",
29 };
30
31 static const char *N_PANE_NAME_TBL[N_COUNT] = {
32 "N_coin_00"
33 };
34
35 if (mInitialized) {
36 return true;
37 }
38
39 mLayout.mpResAccessor = res;
40 mLayout.build("pointGet_02.brlyt", nullptr);
41 mpRootPane = mLayout.getRootPane();
42
43 mLayout.TPaneRegister(T_PANE_NAME_TBL, mpTextBoxes, T_COUNT);
44 mpTextBoxes[T_coin_x_00]->setMessage(dMessage_c::getMesRes(), BMG_CATEGORY_SMALL_SCORE, MSG_LOWERCASE_X, 0);
45 mLayout.NPaneRegister(N_PANE_NAME_TBL, mpNullPanes, N_COUNT);
46
47 mpTextBoxes[T_100_00]->SetVisible(false);
48 mpTextBoxes[T_1000_00]->SetVisible(false);
49 mpTextBoxes[T_red2_00]->SetVisible(false);
50 mpTextBoxes[T_1UP_00]->SetVisible(false);
51 mpTextBoxes[T_coin_x_00]->SetVisible(false);
52 mpTextBoxes[T_coinPoint_00]->SetVisible(false);
53
54 mpNullPanes[N_coin_00]->SetVisible(false);
55 mpRootPane->SetVisible(false);
56
57 mLayout.mDrawOrder = m2d::DRAW_ORDER_SMALL_SCORE;
58 mState = dSmallScore_c::STATE_NONE;
59 mInitialized = true;
60 mEnableColorChange = false;
61 mEnableBigSmallAnim = false;
62 mHasBlueColor = false;
63
64 return true;
65}
66
67void dSmallScore_c::execute() {
68
69 static const ProcFunc Proc_tbl[STATE_COUNT] = {
70 &dSmallScore_c::MakeStart,
71 &dSmallScore_c::UpMove,
72 &dSmallScore_c::DispWait,
73 &dSmallScore_c::GoalScoreDisp,
74 };
75
76 if (mState == dSmallScore_c::STATE_NONE) {
77 return;
78 }
79
80 (this->*Proc_tbl[mState])();
81 PositionSet();
82 mLayout.calc();
83}
84
85void dSmallScore_c::draw() {
86 if (mState == dSmallScore_c::STATE_NONE) {
87 return;
88 }
89
90 if (mState <= dSmallScore_c::STATE_MAKE_START) {
91 return;
92 }
93
94 mLayout.entry();
95}
96
97bool dSmallScore_c::doDelete() {
98 return mLayout.doDelete();
99}
100
101void dSmallScore_c::setPlayer1upColor(int player_id) {
102 dGameCom::Player1upColor(mpTextBoxes[T_1UP_00], player_id);
103}
104
105void dSmallScore_c::setPlayer1000Color(int player_id) {
106 static const nw4r::ut::Color UP_COLOR_DATA_TBL[] = {
107 nw4r::ut::Color(255, 120, 0, 255), // #FF7800
108 nw4r::ut::Color(50, 250, 50, 255), // #32FA32
109 nw4r::ut::Color(0, 185, 220, 255), // #00B9DC
110 nw4r::ut::Color(255, 255, 0, 255), // #FFFF00
111 nw4r::ut::Color(255, 255, 255, 255), // #FFFFFF
112 };
113
114 static const nw4r::ut::Color DOWN_COLOR_DATA_TBL[] = {
115 nw4r::ut::Color(255, 200, 40, 255), // #FFC828
116 nw4r::ut::Color(255, 255, 0, 255), // #FFFF00
117 nw4r::ut::Color(210, 255, 250, 255), // #D2FFFA
118 nw4r::ut::Color(255, 255, 180, 255), // #FFFFB4
119 nw4r::ut::Color(255, 255, 255, 255), // #FFFFFF
120 };
121
122 mpTextBoxes[T_1000_00]->SetVtxColor(nw4r::lyt::VERTEXCOLOR_LT, UP_COLOR_DATA_TBL[player_id]);
123 mpTextBoxes[T_1000_00]->SetVtxColor(nw4r::lyt::VERTEXCOLOR_LB, DOWN_COLOR_DATA_TBL[player_id]);
124}
125
126void dSmallScore_c::setPlayer100Color(int playerType) {
127 static const nw4r::ut::Color COLOR_DATA_TBL[] = {
128 nw4r::ut::Color(255, 150, 85, 255), // #FF9655
129 nw4r::ut::Color(70, 250, 70, 255), // #46FA46
130 nw4r::ut::Color(70, 200, 230, 255), // #46C8E6
131 nw4r::ut::Color(250, 255, 80, 255), // #FAFF50
132 nw4r::ut::Color(250, 255, 255, 255), // #FFFFFF
133 };
134
135 nw4r::lyt::Material *mat = mpTextBoxes[T_100_00]->GetMaterial();
136 GXColorS10 col = nw4r::g3d::detail::GetRGBAS10(COLOR_DATA_TBL[playerType]);
137 mat->SetTevColor(1, col);
138}
139
140void dSmallScore_c::chgColor() {
141 if (!mEnableColorChange) {
142 return;
143 }
144 if (++mChgColorCounter < 10) {
145 return;
146 }
148
149 int type = mPlayerColor;
150
151 while (true) {
152 if (++type >= 4) {
153 type = 0;
154 break;
155 }
156
157 if (dInfo_c::m_instance->mCharIDs[type] == 3) {
158 break;
159 }
160 }
161
162 setPlayer1upColor(type);
163 mPlayerColor = type;
164}
165
166void dSmallScore_c::setNormalOrBlueColor() {
167 static const nw4r::ut::Color UP_COLOR_DATA_TBL[] = {
168 nw4r::ut::Color(255, 10, 10, 255), // #FF0A0A
169 nw4r::ut::Color(60, 120, 255, 255), // #3C78FF
170 };
171 static const nw4r::ut::Color DOWN_COLOR_DATA_TBL[] = {
172 nw4r::ut::Color(255, 150, 150, 255), // #FF9696
173 nw4r::ut::Color(200, 240, 255, 255), // #C8F0FF
174 };
175
176 int colorIdx = 0;
177 if (mHasBlueColor) {
178 mHasBlueColor = false;
179 colorIdx = 1;
180 }
181
182 mpTextBoxes[T_red2_00]->SetVtxColor(nw4r::lyt::VERTEXCOLOR_LT, UP_COLOR_DATA_TBL[colorIdx]);
183 mpTextBoxes[T_red2_00]->SetVtxColor(nw4r::lyt::VERTEXCOLOR_LB, DOWN_COLOR_DATA_TBL[colorIdx]);
184}
185
186void dSmallScore_c::ScissorMaskSet() {
187 d2d::ScissorMask scissorMask;
188 scissorMask.mPos.x = 0.0f;
189 scissorMask.mPos.y = 0.0f;
190 scissorMask.mSize.x = 0.0f;
191 scissorMask.mSize.y = 0.0f;
192 scissorMask.mEnabled = false;
193
194 if (dGameCom::GetAspectRatio() == 0) {
195 scissorMask.mPos.y = (mVideo::m_video->mRenderModeObj.efbHeight - mClipScale.y) * 0.5f;
196 scissorMask.mSize = mClipScale;
197 scissorMask.mEnabled = 1;
198 }
199
200 mLayout.mScissorMask = scissorMask;
201}
202
203void dSmallScore_c::BigSmallAnime() {
204 mVec2_c sum = mScale;
205 mVec2_c delta(0.08f, 0.08f);
206 sum += mAnimScale;
207
208 mpTextBoxes[mCurTextbox]->SetScale(sum);
209 if (++mAnimCounter >= 10) {
210 mAnimCounter = 0;
211
212 if (mAnimIsShrinking) {
213 mAnimIsShrinking = false;
214 } else {
215 mAnimIsShrinking = true;
216 }
217 }
218
219 if (mAnimIsShrinking) {
220 mAnimScale -= delta;
221 } else {
222 mAnimScale += delta;
223 }
224}
225
226void dSmallScore_c::MakeStart() {
227 static const u32 SUB_ID_TBL[] = {
228 MSG_100, MSG_200, MSG_400, MSG_800, MSG_1000, MSG_2000, MSG_4000,
229 MSG_8000, MSG_ONE, MSG_TWO, MSG_THREE, MSG_FOUR, MSG_FIVE, MSG_SIX,
230 MSG_SEVEN, MSG_EIGHT, MSG_1UP, MSG_2UP, MSG_3UP, MSG_4UP, MSG_1UP,
231 MSG_COIN_2, MSG_COIN_3, MSG_COIN_5, MSG_COIN_10, MSG_COIN_15,
232 MSG_COIN_20
233 };
234
235 int temp = mPopupType;
236 mPlayerColor = mPlayerType;
237 if (temp >= 21) {
238 temp = 5;
239
240 mpTextBoxes[T_coin_x_00]->SetVisible(true);
241 mpTextBoxes[T_coinPoint_00]->SetVisible(true);
242 mpNullPanes[N_coin_00]->SetVisible(true);
243 } else {
244 if (temp <= 3) {
245 setPlayer100Color(mPlayerType);
246 temp = 0;
247 } else if (temp <= 7) {
248 setPlayer1000Color(mPlayerType);
249 temp = 1;
250 } else if (temp <= 15) {
251 setNormalOrBlueColor();
252 temp = 2;
253 } else {
254 setPlayer1upColor(mPlayerType);
255 temp = 3;
256 }
257
258 mpTextBoxes[temp]->SetVisible(true);
259 }
260
261 MsgRes_c *bmg = dMessage_c::getMesRes();
262
263 mpTextBoxes[temp]->setMessage(bmg, BMG_CATEGORY_SMALL_SCORE, SUB_ID_TBL[mPopupType], 0);
264 mpTextBoxes[temp]->SetScale(mScale);
265 mCurTextbox = temp;
266 mMaxHeight = dBgParameter_c::ms_Instance_p->mPos.y - 20.0f;
267 mpRootPane->SetVisible(true);
268
269 if (mIsGoalScore) {
270 mState = dSmallScore_c::STATE_GOAL_DISP;
271 } else {
272 mPosDelta.y = 1.0f;
273 mPosDeceleration.y = 0.025f;
274 mDispWaitTime = 0;
276 mAnimCounter = 0;
277 mAnimIsShrinking = false;
278 mAnimScale.x = 0.0f;
279 mAnimScale.y = 0.0f;
280 mState = dSmallScore_c::STATE_UP_MOVE;
281 }
282
284 mEnableColorChange = true;
285 } else {
286 mEnableColorChange = false;
287 }
288
290 ScissorMaskSet();
291}
292
293void dSmallScore_c::UpMove() {
294 if (mEnableBigSmallAnim) {
295 BigSmallAnime();
296 mDispWaitTime = 120;
297 }
298
299 chgColor();
300
301 if (mPosDelta.y == EGG::Mathf::zero()) {
302 mState = dSmallScore_c::STATE_DISP_WAIT;
304 mDispWaitTime = 30;
305 }
306 }
307}
308
309void dSmallScore_c::DispWait() {
310 if (mEnableBigSmallAnim) {
311 BigSmallAnime();
312 }
313
314 chgColor();
315
317 if (mPlayerType == 4) {
318 if (mDispWaitCounter < 60) {
319 return;
320 }
321 } else if (mDispWaitCounter < mDispWaitTime) {
322 return;
323 }
324
326 mpRootPane->SetVisible(false);
327 mpTextBoxes[T_100_00]->SetVisible(false);
328 mpTextBoxes[T_1000_00]->SetVisible(false);
329 mpTextBoxes[T_red2_00]->SetVisible(false);
330 mpTextBoxes[T_1UP_00]->SetVisible(false);
331 mpTextBoxes[T_coin_x_00]->SetVisible(false);
332 mpTextBoxes[T_coinPoint_00]->SetVisible(false);
333 mpNullPanes[N_coin_00]->SetVisible(false);
334 mEnableBigSmallAnim = false;
335 mpTextBoxes[mCurTextbox]->SetScale(mScale);
336 mState = dSmallScore_c::STATE_NONE;
337}
338
339void dSmallScore_c::GoalScoreDisp() {}
340
341void dSmallScore_c::PositionSet() {
342 if (!mpRootPane->IsVisible()) {
343 return;
344 }
345
346 if (mPosDelta.y <= 0.0f) {
347 mPosDelta.y = 0.0f;
348 } else {
349 mPosOffset.y += mPosDelta.y;
350 mPosDelta.y -= mPosDeceleration.y;
351 }
352
353 mVec3_c globalPos;
354 globalPos.x = mPos.x;
355 globalPos.y = mPos.y + mPosOffset.y;
356
357 if (globalPos.y >= mMaxHeight) {
358 globalPos.y = mMaxHeight;
359 }
360
361 dGameCom::getGlbPosToLyt(globalPos);
362 mVec2_c pos;
363 pos.x = globalPos.x;
364 pos.y = globalPos.y;
365
366 mpRootPane->SetTranslate(mVec3_c(pos, 0.0f));
367}
368
369void dSmallScore_c::CreateSmallScore(const mVec3_c &pos, int popupType, int playerType) {
370 mpRootPane->SetVisible(false);
371
372 if ((dInfo_c::mGameFlag & dInfo_c::GAME_FLAG_IS_COIN_COURSE) && popupType <= POPUP_TYPE_8000)
373 return;
374
375 mPopupType = popupType;
376 mPlayerType = playerType;
377 mPos.x = pos.x;
378 mPos.y = pos.y;
379 mPosDelta.x = 0.0f;
380 mPosDelta.y = 0.0f;
381 mPosOffset.x = 0.0f;
382 mPosOffset.y = 0.0f;
383 mIsGoalScore = false;
384 mState = dSmallScore_c::STATE_MAKE_START;
385}
386
387void dSmallScore_c::PosSet(const mVec3_c &pos) {
388 mPos.x = pos.x;
389 mPos.y = pos.y;
390}
static unsigned int mGameFlag
See GAME_FLAG_e.
Definition d_info.hpp:90
Displays a small popup score indicator.
bool mHasBlueColor
Whether counter type score popups should be colored blue instead of red.
int mChgColorCounter
Counter that is incremented every call to chgColor(), which ensures that the 1-UP color is only set o...
static dSmallScore_c * m_instance
The instance of the score popup creator.
LytBase_c mLayout
The layout for the score popup.
virtual ~dSmallScore_c()
Destroys the score popup creator.
STATE_e mState
The state the score popup is in.
dSmallScore_c()
Constructs a new score popup creator.
nw4r::lyt::Pane * mpRootPane
The root pane of the layout.
u32 mCurTextbox
The textbox currently displayed. Value is a T_PANE_e.
@ POPUP_TYPE_8000
The number 8000.
@ POPUP_TYPE_1UP_COLOR_CHANGE
The text "1-UP", but changes color (see chgColor). Used when a 1-UP is awarded to multiple players.
@ POPUP_TYPE_COIN_2
[Coin icon]x2. Used in Coin Battle.
LytTextBox_c * mpTextBoxes[T_COUNT]
The text boxes used for the layout.
int mDispWaitCounter
The amount of frames the DispWait state has been active.
float mMaxHeight
The maximum height the score popup can be displayed at.
int mDispWaitTime
The number of frames to wait in the DispWait state.
int mPopupType
The popup type. Value is a POPUP_TYPE_e.
bool mInitialized
Whether the layout has been initialized.
nw4r::lyt::Pane * mpNullPanes[N_COUNT]
The null panes used for the layout.
A three-dimensional floating point vector.
Definition m_vec.hpp:107