NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_SelectCursor.cpp
1#include <game/bases/d_SelectCursor.hpp>
2
3ACTOR_PROFILE(SELECT_CURSOR, dSelectCursor_c, 0);
4
6
11
15
17 static const char *AnmNameTbl[ANIM_COUNT] = {
18 "select_cursor_04_loopCursor.brlan"
19 };
20
21 static const char *GROUP_NAME_DT[ANIM_COUNT] = {
22 "A00_cursor"
23 };
24
25 static const int ANIME_INDEX_TBL[ANIM_COUNT] = {
26 ANIM_CURSOR
27 };
28
29 static const char *PPANE_TABLE[P_COUNT] = {
30 "P_cursor_00",
31 "P_cursor_01",
32 "P_cursor_02",
33 "P_cursor_03"
34 };
35
36 static const char *NPANE_TABLE[N_COUNT] = {
37 "N_cursor_00",
38 "N_LU_00",
39 "N_RU_00",
40 "N_LD_00",
41 "N_RD_00"
42 };
43
44
45 if (mHasLoadedLayout) {
46 return SUCCEEDED;
47 }
48
49 if (!mResLoader.request("Layout/select_cursor/select_cursor.arc")) {
50 return NOT_READY;
51 }
52
53 for (int i = 0; i < LAYOUT_COUNT; i++) {
54 mLayouts[i].mBase.mpResAccessor = &mResLoader;
55 }
56
57 for (int i = 0; i < LAYOUT_COUNT; i++) {
58 mLayouts[i].mBase.build("select_cursor_04.brlyt", nullptr);
59 mLayouts[i].mBase.AnimeResRegister(AnmNameTbl, ANIM_COUNT);
60 mLayouts[i].mBase.GroupRegister(GROUP_NAME_DT, ANIME_INDEX_TBL, ANIM_COUNT);
61 mLayouts[i].mpRootPane = mLayouts[i].mBase.getRootPane();
62 mLayouts[i].mBase.PPaneRegister(PPANE_TABLE, mLayouts[i].mpPicturePanes, P_COUNT);
63 mLayouts[i].mBase.NPaneRegister(NPANE_TABLE, mLayouts[i].mpNullPanes, N_COUNT);
64 mLayouts[i].mpRootPane->SetVisible(false);
65 Cancel(i);
66
67 if (i == UNK_4) {
68 mLayouts[i].mBase.mDrawOrder = 14;
69 } else {
70 mLayouts[i].mBase.mDrawOrder = 147;
71 }
72
73 mLayouts[i].mBase.LoopAnimeStartSetup(ANIM_CURSOR);
74 }
75
76 mHasLoadedLayout = true;
77 return SUCCEEDED;
78}
79
80
82 for (int i = 0; i < LAYOUT_COUNT; i++) {
83 if (mLayouts[i].mIsActive) {
84 PosSet(i);
85 mLayouts[i].mBase.AnimePlay();
86 mLayouts[i].mBase.calc();
87 }
88 }
89
90 return SUCCEEDED;
91}
92
94 for (int i = 0; i < LAYOUT_COUNT; i++) {
95 if (mLayouts[i].mIsActive) {
96 mLayouts[i].mBase.entry();
97 }
98 }
99
100 return SUCCEEDED;
101}
102
104 if (!mResLoader.remove()) {
105 return NOT_READY;
106 }
107
108 for (int i = 0; i < LAYOUT_COUNT; i++) {
109 if (!mLayouts[i].mBase.doDelete()) {
110 return NOT_READY;
111 }
112 }
113
114 return SUCCEEDED;
115}
116
117void dSelectCursor_c::PosSet(int layoutId) {
118 mLayouts[layoutId].mpRootPane->SetVisible(true);
119
120 mVec2_c panePos;
121 float paneHalfWidth, paneHalfHeight, paneScaleX, paneScaleY;
122
123 paneScaleX = mLayouts[layoutId].mPaneGlbMtxScale.x;
124 paneScaleY = mLayouts[layoutId].mPaneGlbMtxScale.y;
125
126 paneHalfWidth = mLayouts[layoutId].mPaneSize.width / 2.0f;
127 paneHalfHeight = mLayouts[layoutId].mPaneSize.height / 2.0f;
128
129 panePos.x = mLayouts[layoutId].mPaneGlbMtxTrans.x + mLayouts[layoutId].mRootPaneOffset.x;
130 if (mLayouts[layoutId].mPaneBasePosH == nw4r::lyt::HORIZONTALPOSITION_LEFT) {
131 panePos.x += paneHalfWidth * paneScaleX;
132 } else if (mLayouts[layoutId].mPaneBasePosH == nw4r::lyt::HORIZONTALPOSITION_RIGHT) {
133 panePos.x -= paneHalfWidth * paneScaleX;
134 }
135
136 panePos.y = mLayouts[layoutId].mPaneGlbMtxTrans.y + mLayouts[layoutId].mRootPaneOffset.y;
137 if (mLayouts[layoutId].mPaneBasePosV == nw4r::lyt::VERTICALPOSITION_TOP) {
138 panePos.y -= paneHalfHeight * paneScaleY;
139 } else if (mLayouts[layoutId].mPaneBasePosV == nw4r::lyt::VERTICALPOSITION_BOTTOM) {
140 panePos.y += paneHalfHeight * paneScaleY;
141 }
142
143 mLayouts[layoutId].mpRootPane->SetTranslate(mVec3_c(panePos, 0.0f));
144 float hOffset = mLayouts[layoutId].mPaneOffset.width;
145 float vOffset = mLayouts[layoutId].mPaneOffset.height;
146
147 for (int cornerPane = N_LU_00; cornerPane < N_COUNT; cornerPane++) {
148 mVec3_c cornerPos;
149 if (cornerPane == N_LU_00 || cornerPane == N_LD_00) {
150 cornerPos.x = paneHalfWidth * paneScaleX;
151 cornerPos.x = -cornerPos.x;
152 cornerPos.x -= hOffset;
153 } else {
154 cornerPos.x = paneHalfWidth * paneScaleX;
155 cornerPos.x += hOffset;
156 }
157
158 if (cornerPane == N_LU_00 || cornerPane == N_RU_00) {
159 cornerPos.y = paneHalfHeight * paneScaleY;
160 cornerPos.y += vOffset;
161 } else {
162 cornerPos.y = paneHalfHeight * paneScaleY;
163 cornerPos.y = -cornerPos.y;
164 cornerPos.y -= vOffset;
165 }
166
167 cornerPos.z = 0.0f;
168 mLayouts[layoutId].mpNullPanes[cornerPane]->SetTranslate(cornerPos);
169 }
170
171 if (mLayouts[layoutId].mDoFade) {
172 mLayouts[layoutId].mPaneAlpha -= (255 / 10) + 1;
173 mLayouts[layoutId].mpNullPanes[N_cursor_00]->SetAlpha(mLayouts[layoutId].mPaneAlpha);
174
175 if (mLayouts[layoutId].mPaneAlpha < 0) {
176 mLayouts[layoutId].mPaneAlpha = 0;
177 mLayouts[layoutId].mDoFade = false;
178 Cancel(layoutId);
179 }
180 }
181}
182
183void dSelectCursor_c::Cancel(int layoutId) {
184 if (mLayouts[layoutId].mIsActive) {
185 mLayouts[layoutId].mIsActive = false;
186 strcpy(mLayouts[layoutId].mPaneName, "");
187 mLayouts[layoutId].mpRootPane->SetVisible(false);
188 }
189}
190
191void dSelectCursor_c::SetPane(const nw4r::lyt::Pane *pane, int layoutId, bool forceTopDrawOrder) {
192 mLayouts[layoutId].mIsActive = true;
193
194 strcpy(mLayouts[layoutId].mPaneName, pane->GetName());
195 mLayouts[layoutId].mPaneSize.width = pane->GetSize().width;
196 mLayouts[layoutId].mPaneSize.height = pane->GetSize().height;
197
198 nw4r::math::MTX34 mtx = pane->GetGlobalMtx();
199 mLayouts[layoutId].mPaneGlbMtxTrans.x = mtx._03;
200 mLayouts[layoutId].mPaneGlbMtxTrans.y = mtx._13;
201 mLayouts[layoutId].mPaneGlbMtxScale.x = mtx._00;
202 mLayouts[layoutId].mPaneGlbMtxScale.y = mtx._11;
203
204 mLayouts[layoutId].mPaneBasePosH = pane->GetBasePositionH();
205 mLayouts[layoutId].mPaneBasePosV = pane->GetBasePositionV();
206
207 mLayouts[layoutId].mPaneOffset.width = 0.0f;
208 mLayouts[layoutId].mPaneOffset.height = 0.0f;
209 mLayouts[layoutId].mRootPaneOffset.x = 0.0f;
210 mLayouts[layoutId].mRootPaneOffset.y = 0.0f;
211 mLayouts[layoutId].m_254 = 0.0f;
212 mLayouts[layoutId].mPaneAlpha = 0xff;
213 mLayouts[layoutId].mDoFade = false;
214
215 if (forceTopDrawOrder) {
216 mLayouts[layoutId].mBase.mDrawOrder = 152;
217 } else {
218 for (int i = 0; i < LAYOUT_COUNT; i++) {
219 if (i == UNK_4) {
220 mLayouts[i].mBase.mDrawOrder = 14;
221 } else {
222 mLayouts[i].mBase.mDrawOrder = 147;
223 }
224 }
225 }
226}
227
228void dSelectCursor_c::SetAlpha(const nw4r::lyt::Pane *pane, int layoutId) {
229 u8 alpha = pane->GetGlbAlpha();
230 Layout_c &layout = mLayouts[layoutId];
231
232 for (int i = 0; i < P_COUNT; i++) {
233 layout.mpPicturePanes[i]->SetAlpha(alpha);
234 }
235}
A cursor layout instance.
nw4r::lyt::Picture * mpPicturePanes[P_COUNT]
The picture panes of the view.
Manages the animated L-shaped corner rectangles around selected buttons.
void PosSet(int layoutId)
Updates the position of an attached cursor layout.
void Cancel(int layoutId)
Deactivates and hides the specified cursor layout.
dSelectCursor_c()
Constructs a new base.
int execute()
do method for the execute operation.
bool mHasLoadedLayout
Whether the layout has been loaded.
int doDelete()
do method for the delete operation.
void SetPane(const nw4r::lyt::Pane *pane, int layoutId, bool forceTopDrawOrder)
Attaches a cursor to the given pane.
void SetAlpha(const nw4r::lyt::Pane *pane, int layoutId)
Sets the alpha of a cursor to match the given pane.
virtual ~dSelectCursor_c()
Destroys the base.
Layout_c mLayouts[LAYOUT_COUNT]
The cursor layout instances.
d2d::ResAccMultLoader_c mResLoader
The resource loader for the layout.
int create()
do method for the create operation.
static dSelectCursor_c * m_instance
The static instance of the selection cursor manager.
int draw()
do method for the draw operation.
@ NOT_READY
The step could not completed at this time.
Definition f_base.hpp:44
@ SUCCEEDED
The step was completed successfully.
Definition f_base.hpp:45
A two-dimensional floating point vector.
Definition m_vec.hpp:16
A three-dimensional floating point vector.
Definition m_vec.hpp:107
#define ACTOR_PROFILE(profName, className, properties)
Creates an actor profile, using the profile number as the execute and draw order value.
Definition f_profile.hpp:29