NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_lytbase.cpp
1#include <game/bases/d_lytbase.hpp>
2#include <game/bases/d_game_com.hpp>
3#include <game/bases/d_lyttextBox.hpp>
4#include <game/mLib/m_mtx.hpp>
5#include <game/mLib/m_video.hpp>
6
7#define TEXTBOX_STRING_BUFFER_SIZE 0x1FF
8
10
12
14
15bool LytBase_c::build(const char *name, d2d::ResAccMult_c *resAcc) {
16 bool res = d2d::Multi_c::build(name, resAcc);
17 if (res) {
19 mLayout.SetTagProcessor(&s_TagPrc);
20 }
21 return res;
22}
23
27
28void LytBase_c::allocStringBuffer(nw4r::lyt::Pane *pane) {
29 nw4r::lyt::TextBox *box = nw4r::ut::DynamicCast<nw4r::lyt::TextBox *>(pane);
30 if (box != nullptr) {
31 const wchar_t *buf = box->GetStringBuffer();
32 box->AllocStringBuffer(TEXTBOX_STRING_BUFFER_SIZE);
33 if (buf != nullptr) {
34 box->SetString(buf, 0);
35 }
36 }
37 for (
38 nw4r::lyt::PaneList::Iterator it = pane->GetChildList().GetBeginIter();
39 it != pane->GetChildList().GetEndIter();
40 it++
41 ) {
43 }
44}
45
46bool LytBase_c::ReadResourceEx(const char *name, int allocDirection, bool isLocalized) {
47 char resourcePath[100];
48 if (isLocalized) {
49 char nonLocalizedPath[100] = "Layout/";
50 strncat(nonLocalizedPath, name, ARRAY_MAX_STRLEN(nonLocalizedPath));
51 dGameCom::AreaLanguageFolder(nonLocalizedPath, resourcePath);
52 } else {
53 memset(resourcePath, 0, ARRAY_SIZE(resourcePath));
54 strncat(resourcePath, "Layout/", ARRAY_MAX_STRLEN(resourcePath));
55 strncat(resourcePath, name, ARRAY_MAX_STRLEN(resourcePath));
56 }
57 if (!mResAccessorLoader.requestEx(resourcePath, allocDirection)) {
58 return false;
59 }
60
62 return true;
63}
64
65bool LytBase_c::ReadResource(const char *name, bool isLocalized) {
66 return ReadResourceEx(name, 0, isLocalized);
67}
68
69bool LytBase_c::ReadResource2(const char *name, int allocDirection) {
70 char resourcePath[100];
71 memset(resourcePath, 0, ARRAY_SIZE(resourcePath));
72 strncat(resourcePath, "EU/", ARRAY_MAX_STRLEN(resourcePath));
73 strncat(resourcePath, "Layout/", ARRAY_MAX_STRLEN(resourcePath));
74 strncat(resourcePath, name, ARRAY_MAX_STRLEN(resourcePath));
75 if (!mResAccessorLoader.requestEx(resourcePath, 0)) {
76 return false;
77 }
78
80 return true;
81}
82
83bool LytBase_c::ReadResource3(const char *name, int i) {
84 char resourcePath[100];
85 memset(resourcePath, 0, ARRAY_SIZE(resourcePath));
86 strncat(resourcePath, "EU/NedEU/Layout/", ARRAY_MAX_STRLEN(resourcePath));
87 strncat(resourcePath, name, ARRAY_MAX_STRLEN(resourcePath));
88 if (!mResAccessorLoader.requestEx(resourcePath, i)) {
89 return false;
90 }
91
93 return true;
94}
95
96void LytBase_c::NPaneRegister(const char **paneNames, nw4r::lyt::Pane **panes, int count) {
97 for (int i = 0; i < count; i++) {
98 panes[i] = findPaneByName(paneNames[i]);
99 }
100}
101
102void LytBase_c::WPaneRegister(const char **windowPaneNames, nw4r::lyt::Window **panes, int count) {
103 for (int i = 0; i < count; i++) {
104 panes[i] = findWindowByName(windowPaneNames[i]);
105 }
106}
107
108void LytBase_c::PPaneRegister(const char **picPaneNames, nw4r::lyt::Picture **panes, int count) {
109 for (int i = 0; i < count; i++) {
110 panes[i] = findPictureByName(picPaneNames[i]);
111 }
112}
113
114void LytBase_c::TPaneRegister(const char **textboxNames, LytTextBox_c **panes, int count) {
115 for (int i = 0; i < count; i++) {
116 panes[i] = findTextBox(textboxNames[i]);
117 }
118}
119
120void LytBase_c::TPaneNameRegister(const char **textboxNames, const int *messageIDs, int messageGroup, int count) {
121 MsgRes_c *bmg = dMessage_c::getMesRes();
122 for (int i = 0; i < count; i++) {
123 LytTextBox_c *box = findTextBox(textboxNames[i]);
124 box->setMessage(bmg, messageGroup, messageIDs[i], 0);
125 }
126}
127
128void LytBase_c::AnimeResRegister(const char **animeNames, int count) {
130 mpAnimRes = new m2d::AnmResV2_c[count];
131 mAnimCount = count;
132 for (int i = 0; i < count; i++) {
133 mpAnimRes[i].create(animeNames[i], resAcc, &mLayout, true);
134 }
135}
136
137void LytBase_c::GroupRegister(const char **groupNames, const int *animeIdxs, int count) {
138 mpAnimGroup = new m2d::AnmGroup_c[count];
139 mpEnabledAnims = new bool[count];
140 mAnimGroupCount = count;
141 for (int i = 0; i < count; i++) {
142 mpAnimGroup[i].create(&mpAnimRes[animeIdxs[i]], groupNames[i]);
143 }
144}
145
147 float dummy_float = 0.5f; // [For .sdata2 ordering]
148 mpAnimGroup[animeIdx].setAnmEnable(true);
149 m2d::AnmGroup_c &animeGroup = mpAnimGroup[animeIdx];
150 animeGroup.mpFrameCtrl->setFrame(0.0f);
151 animeGroup.updateFrame();
152 mpEnabledAnims[animeIdx] = true;
153 mLastStartedAnimNum = animeIdx;
154}
155
156void LytBase_c::AnimeStartSetup(int animeIdx, bool startAtEnd) {
157 AnimeStartBaseSetup(animeIdx);
158 if (startAtEnd) {
159 mpAnimGroup[animeIdx].setLast();
160 }
161 mpAnimGroup[animeIdx].mpFrameCtrl->setFlags(false, false);
162}
163
165 AnimeStartBaseSetup(animeIdx);
166 mpAnimGroup[animeIdx].mpFrameCtrl->setFlags(true, false);
167}
168
169void LytBase_c::ReverseAnimeStartSetup(int animeIdx, bool startAtEnd) {
170 AnimeStartBaseSetup(animeIdx);
171 if (startAtEnd) {
172 mpAnimGroup[animeIdx].mpFrameCtrl->setFlags(false, false);
173 mpAnimGroup[animeIdx].setEnd();
174 } else {
175 mpAnimGroup[animeIdx].setStart();
176 }
177 mpAnimGroup[animeIdx].mpFrameCtrl->setFlags(false, true);
178}
179
180void LytBase_c::AnimeEndSetup(int animeIdx) {
181 if (mpEnabledAnims[animeIdx]) {
182 mpAnimGroup[animeIdx].setAnmEnable(false);
183 mpEnabledAnims[animeIdx] = false;
184 }
185}
186
188 for (int i = 0; i < mAnimGroupCount; i++) {
189 AnimeEndSetup(i);
190 }
192}
193
195 for (int i = 0; i < mAnimGroupCount; i++) {
196 if (mpEnabledAnims[i]) {
197 if (mpAnimGroup[i].mpFrameCtrl->isStop()) {
198 AnimeEndSetup(i);
199 } else {
200 mpAnimGroup[i].play();
201 }
202 }
203 }
204}
205
206bool LytBase_c::isAnime(int animeIdx) {
207 if (animeIdx < 0) {
209 }
210 return mpEnabledAnims[animeIdx];
211}
212
214 for (int i = 0; i < mAnimGroupCount; i++) {
215 if (mpEnabledAnims[i]) {
216 return true;
217 }
218 }
219 return false;
220}
221
222void LytBase_c::SetScissorMask(const nw4r::lyt::Pane *pane, d2d::ScissorMask &scissorMask) {
223 nw4r::ut::Rect view = mDrawInfo.GetViewRect();
224 mVec2_c paneSize;
225 mVec2_c scissorPos;
226 mVec2_c scissorSize;
227 mVec2_c scale = mDrawInfo.GetLocationAdjustScale();
228
229 float actualScaleY = scale.y;
230 if (actualScaleY <= 1e-6f) {
231 actualScaleY = 1e-6f;
232 }
233 float height = view.GetHeight() / actualScaleY;
234
235 float actualScaleX = scale.x;
236 if (actualScaleX <= 1e-6f) {
237 actualScaleX = 1e-6f;
238 }
239 float width = view.GetWidth() / actualScaleX;
240
241 if (width < 0.0f) {
242 width *= -1.0f;
243 }
244 if (height < 0.0f) {
245 height *= -1.0f;
246 }
247
248 mMtx_c paneMtx = pane->GetGlobalMtx();
249
250 paneSize.x = pane->GetSize().width;
251 paneSize.y = pane->GetSize().height;
252
253 float ratioX = mVideo::m_video->getWidth() / width;
254 float ratioY = mVideo::m_video->getHeight() / height;
255
256 float trueSizeX = paneMtx.m[1][1] * (paneSize.x * ratioX);
257 float trueSizeY = paneMtx.m[1][1] * (paneSize.y * ratioY);
258
259 float translateX = paneMtx.m[0][3] / actualScaleX;
260 float translateY = paneMtx.m[1][3] * -1.0f;
261
262 translateX *= ratioX;
263 translateY *= ratioY;
264
265 u32 scX, scY, scW, scH;
266 GXGetScissor(&scX, &scY, &scW, &scH);
267 scissorPos.x = scX + scW * 0.5f + (translateX - trueSizeX * 0.5f);
268 scissorPos.y = scY + scH * 0.5f + (translateY - trueSizeY * 0.5f);
269 scissorSize.x = trueSizeX + 0.5f;
270 scissorSize.y = trueSizeY + 0.5f;
271 scissorMask.setSize(scissorSize);
272 scissorMask.setPos(scissorPos);
273 scissorMask.mEnabled = true;
274}
275
277 if (mAnimCount != 0) {
278 for (int i = 0; i < mAnimCount; i++) {
279 if (!mpAnimRes[i].remove()) {
280 return false;
281 }
282 }
283 delete[] mpAnimRes;
284 mAnimCount = 0;
285 }
286
287 if (mAnimGroupCount != 0) {
288 delete[] mpAnimGroup;
289 delete[] mpEnabledAnims;
290 mAnimGroupCount = 0;
291 }
292
293 if (!mResAccessorLoader.remove()) {
294 return false;
295 }
296
297 return true;
298}
LytTextBox_c * findTextBox(const char *name)
Finds a text box by name.
Definition d_lytbase.cpp:24
bool isAnime(int animeIdx)
Returns whether the specified animation is currently playing.
bool ReadResource3(const char *name, int allocDirection)
Reads an .arc file which contains the layout.
Definition d_lytbase.cpp:83
void AnimeResRegister(const char **animeNames, int count)
Loads animation resources given by their names.
bool ReadResourceEx(const char *name, int allocDirection, bool isLocalized)
Reads an .arc file which contains the layout.
Definition d_lytbase.cpp:46
void NPaneRegister(const char **paneNames, nw4r::lyt::Pane **panes, int count)
Finds null panes by name and registers them to the list.
Definition d_lytbase.cpp:96
bool * mpEnabledAnims
A list of the enabled animations.
void TPaneNameRegister(const char **textboxNames, const int *messageIDs, int messageGroup, int count)
Finds text boxes by name, sets their messages, and registers them to the list.
void GroupRegister(const char **groupNames, const int *animeIdxs, int count)
Registers animation groups to the layout.
void TPaneRegister(const char **textboxNames, LytTextBox_c **panes, int count)
Finds text boxes by name and registers them to the list.
static TagProcessor_c s_TagPrc
The tag processor for layouts.
void AnimePlay()
Starts playing all enabled animations.
bool ReadResource(const char *name, bool isLocalized)
Reads an .arc file which contains the layout.
Definition d_lytbase.cpp:65
int mAnimGroupCount
The number of animation groups used by the layout.
bool isAllAnime()
Returns whether any animation is currently playing.
void LoopAnimeStartSetup(int animeIdx)
Prepares a looping animation to be played.
int mAnimCount
The number of animations used by the layout.
m2d::AnmResV2_c * mpAnimRes
The animations used by the layout.
m2d::AnmGroup_c * mpAnimGroup
The animation groups used by the layout.
void WPaneRegister(const char **windowPaneNames, nw4r::lyt::Window **panes, int count)
Finds windows by name and registers them to the list.
void allocStringBuffer(nw4r::lyt::Pane *pane)
Recursively allocates string buffers for all text boxes in the layout.
Definition d_lytbase.cpp:28
void SetScissorMask(const nw4r::lyt::Pane *pane, d2d::ScissorMask &scissorMask)
void ReverseAnimeStartSetup(int animeIdx, bool startAtEnd)
Prepares a reverse animation to be played.
virtual ~LytBase_c()
Destroys the layout.
Definition d_lytbase.cpp:13
virtual bool build(const char *name, d2d::ResAccMult_c *resAcc)
Builds the layout from a binary layout file.
Definition d_lytbase.cpp:15
LytBase_c()
Constructs a new layout.
Definition d_lytbase.cpp:11
void PPaneRegister(const char **picPaneNames, nw4r::lyt::Picture **panes, int count)
Finds picture panes by name and registers them to the list.
void AllAnimeEndSetup()
Prepares all animations to be stopped.
bool ReadResource2(const char *name, int allocDirection)
Reads an .arc file which contains the layout.
Definition d_lytbase.cpp:69
bool doDelete()
Cleans up all resources used by the layout.
d2d::ResAccMultLoader_c mResAccessorLoader
The resource loader used to load the layout's resources.
void AnimeEndSetup(int animeIdx)
Prepares an animation to be stopped.
void AnimeStartBaseSetup(int animeIdx)
Base setup for starting an animation.
int mLastStartedAnimNum
The number of the most recently started animation.
void AnimeStartSetup(int animeIdx, bool startAtEnd)
Prepares an animation to be played.
A text box class with BMG message support.
void setMessage(MsgRes_c *bmg, ulong messageGroup, ulong messageID, long placeholderCount,...)
Sets the message to display in the text box.
m2d::Layout_c mLayout
The layout instance.
Definition multi.hpp:60
nw4r::lyt::Picture * findPictureByName(const char *name)
Finds a picture pane by name.
Definition d_2d.cpp:216
nw4r::lyt::DrawInfo mDrawInfo
The parameters for drawing the layout.
Definition multi.hpp:61
nw4r::lyt::TextBox * findTextBoxByName(const char *name)
Finds a text box pane by name.
Definition d_2d.cpp:207
nw4r::lyt::Pane * getRootPane()
Gets the root pane of the layout.
Definition d_2d.cpp:178
ResAccMult_c * mpResAccessor
The resource accessor for the layout.
Definition multi.hpp:64
nw4r::lyt::Pane * findPaneByName(const char *name)
Finds a pane by name.
Definition d_2d.cpp:203
virtual bool build(const char *name, ResAccMult_c *resAcc)
Builds the layout from a binary layout file.
Definition d_2d.cpp:182
nw4r::lyt::Window * findWindowByName(const char *name)
Finds a window pane by name.
Definition d_2d.cpp:225
A 3x4 matrix.
Definition m_mtx.hpp:9
A two-dimensional floating point vector.
Definition m_vec.hpp:16
Stores clipping settings for a layout.
Definition multi.hpp:11