1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
#include "d/lyt/d_lyt_cursor_stick.h"
#include "common.h"
#include "d/d_gfx.h"
#include "m/m_vec.h"
#include "nw4r/lyt/lyt_types.h"
#include "toBeSorted/arc_managers/layout_arc_manager.h"
STATE_DEFINE(dLytCursorStick_c, Off);
STATE_DEFINE(dLytCursorStick_c, On);
static const d2d::LytBrlanMapping brlanMap[] = {
{"cursorStick_00_loop.brlan", "G_loop_00"},
};
#define CURSOR_STICK_ANIM_LOOP 0
#define CURSOR_STICK_NUM_ANIMS 1
static const char *sPaneNames[] = {
"N_all_00", "N_RT_00", "N_LT_00", "N_LD_00", "N_RD_00",
};
#define CURSOR_STICK_PANE_ALL 0
#define CURSOR_STICK_PANE_RT 1
#define CURSOR_STICK_PANE_LT 2
#define CURSOR_STICK_PANE_LD 3
#define CURSOR_STICK_PANE_RD 4
#define CURSOR_STICK_NUM_PANES 5
dLytCursorStick_c *dLytCursorStick_c::sInstance;
bool dLytCursorStick_c::build() {
sInstance->build_();
return true;
}
bool dLytCursorStick_c::remove() {
if (sInstance != nullptr) {
sInstance->remove_();
sInstance = nullptr;
}
return true;
}
bool dLytCursorStick_c::execute() {
if (sInstance != nullptr) {
sInstance->execute_();
}
return true;
}
bool dLytCursorStick_c::draw() {
if (sInstance != nullptr) {
sInstance->draw_();
}
return true;
}
bool dLytCursorStick_c::drawDirectly() {
if (sInstance != nullptr) {
sInstance->drawDirectly_();
}
return true;
}
bool dLytCursorStick_c::build_() {
void *data = LayoutArcManager::GetInstance()->getLoadedData("CursorStick");
mResAcc.attach(data, "");
mLyt.setResAcc(&mResAcc);
mLyt.build("cursorStick_00.brlyt", nullptr);
mLyt.setPriority(0x8A);
for (int i = 0; i < CURSOR_STICK_NUM_ANIMS; i++) {
mAnm[i].init(brlanMap[i].mFile, &mResAcc, mLyt.getLayout(), brlanMap[i].mName);
mAnm[i].bind(false);
mAnm[i].setAnimEnable(false);
}
for (int i = 0; i < CURSOR_STICK_NUM_PANES; i++) {
mpPanes[i] = mLyt.findPane(sPaneNames[i]);
}
mStateMgr.changeState(StateID_Off);
mLyt.calc();
mShouldBeOn = false;
mpTargetPane = nullptr;
return true;
}
bool dLytCursorStick_c::remove_() {
for (int i = 0; i < CURSOR_STICK_NUM_ANIMS; i++) {
mAnm[i].unbind();
mAnm[i].remove();
}
mResAcc.detach();
return true;
}
bool dLytCursorStick_c::execute_() {
mStateMgr.executeState();
if (mShouldBeOn) {
mLyt.calc();
}
return true;
}
bool dLytCursorStick_c::draw_() {
if (mShouldBeOn) {
mLyt.addToDrawList();
}
return true;
}
bool dLytCursorStick_c::drawDirectly_() {
if (mShouldBeOn) {
mLyt.draw();
}
return true;
}
void dLytCursorStick_c::setPriority(u8 priority) {
mLyt.setPriority(priority);
}
void dLytCursorStick_c::initializeState_Off() {}
void dLytCursorStick_c::executeState_Off() {
if (mShouldBeOn) {
mAnm[CURSOR_STICK_ANIM_LOOP].setAnimEnable(true);
mAnm[CURSOR_STICK_ANIM_LOOP].setFrame(0.0f);
mStateMgr.changeState(StateID_On);
}
}
void dLytCursorStick_c::finalizeState_Off() {}
void dLytCursorStick_c::initializeState_On() {}
void dLytCursorStick_c::executeState_On() {
if (!mShouldBeOn) {
mAnm[CURSOR_STICK_ANIM_LOOP].setAnimEnable(false);
mAnm[CURSOR_STICK_ANIM_LOOP].setFrame(0.0f);
mStateMgr.changeState(StateID_Off);
}
positionToTarget();
if (mAnm[CURSOR_STICK_ANIM_LOOP].isEnabled()) {
mAnm[CURSOR_STICK_ANIM_LOOP].play();
}
}
void dLytCursorStick_c::finalizeState_On() {}
void dLytCursorStick_c::setTargetPane(const nw4r::lyt::Pane *pane) {
mpTargetPane = pane;
positionToTarget();
}
void dLytCursorStick_c::positionToTarget() {
if (mpTargetPane == nullptr) {
return;
}
u8 positionV = mpTargetPane->GetPositionV();
u8 positionH = mpTargetPane->GetPositionH();
nw4r::math::MTX34 mtx = mpTargetPane->GetGlobalMtx();
nw4r::lyt::Size size = mpTargetPane->GetSize();
f32 halfWidthScaled = size.width / 2.0f / dGfx_c::get16x9to4x3WidthScaleF();
f32 posX;
f32 posY;
if (positionH == 0) {
posX = mtx._03 + halfWidthScaled;
} else if (positionH == 1) {
posX = mtx._03;
} else {
posX = mtx._03 - halfWidthScaled;
}
if (positionV == 0) {
posY = mtx._13 - size.height / 2.0f;
} else if (positionV == 1) {
posY = mtx._13;
} else {
posY = mtx._13 + size.height / 2.0f;
}
mVec3_c v(posX, posY, 0.0f);
mpPanes[CURSOR_STICK_PANE_ALL]->SetTranslate(v);
v.x = -size.width / 2.0f;
v.y = size.height / 2.0f;
mpPanes[CURSOR_STICK_PANE_LT]->SetTranslate(v);
v.x = size.width / 2.0f;
v.y = size.height / 2.0f;
mpPanes[CURSOR_STICK_PANE_RT]->SetTranslate(v);
v.x = -size.width / 2.0f;
v.y = -size.height / 2.0f;
mpPanes[CURSOR_STICK_PANE_LD]->SetTranslate(v);
v.x = size.width / 2.0f;
v.y = -size.height / 2.0f;
mpPanes[CURSOR_STICK_PANE_RD]->SetTranslate(v);
mLyt.calc();
}
|