Skip to content

Commit 98ae8bc

Browse files
committed
Menu work
1 parent 8b68db8 commit 98ae8bc

File tree

13 files changed

+429
-37
lines changed

13 files changed

+429
-37
lines changed

base/symbols_resort.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,8 @@ sDrawPass__13RPGrpRenderer=0x806f0bf8
36303630
spInstance__15RPSysTextWriter=0x806f4d08
36313631
Begin__15RPSysTextWriterFv=0x8023bdfc
36323632
mainLoop__11RPSysSystemFv=0x80237b2c
3633+
spCurrent__13RPGrpRenderer=0x806f4e04
3634+
AppendDrawObject__13RPGrpRendererFP16IRPGrpDrawObject=0x80253d44
36333635

36343636
playSound__Q23Sp27SndUtilFUlUl=0x802b735c
36353637
sInstance__Q33Sp23Swf5Scene=0x806f5ff0
@@ -3641,4 +3643,4 @@ sActiveScreen__13RPGrpRenderer=0x807cef2c
36413643
setStaticVar__Q33Sp23Cmn9StaticMemFiib=0x80269f08
36423644

36433645
setTimer__Q43Sp23Bsk3Lyt4MainFUlUl=0x80533a78
3644-
setType__Q33Sp23Bsk4BallFQ43Sp23Bsk4Ball5EType=0x804ffa44
3646+
setType__Q33Sp23Bsk4BallFQ43Sp23Bsk4Ball5EType=0x804ffa44

lib/libkiwi/core/kiwiIScene.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ class IScene : public RPSysScene {
8787
}
8888

8989
#if defined(PACK_RESORT)
90+
/**
91+
* @brief Gets the scene's group ID
92+
*/
93+
virtual EGroupID GetGroup() const {
94+
return EGroupID_Cmn;
95+
}
96+
97+
/**
98+
* @brief Tests whether to show the warning screen while loading
99+
*/
100+
virtual bool GetWarnAsLoading() const {
101+
return false;
102+
}
103+
90104
/**
91105
* @brief Gets the scene's type
92106
*/
@@ -244,6 +258,10 @@ template <typename T> class SceneDecl {
244258
static_cast<T*>(nullptr)->T::GetName(),
245259
static_cast<T*>(nullptr)->T::GetDirectory(),
246260
static_cast<T*>(nullptr)->T::GetID(),
261+
#if defined(PACK_RESORT)
262+
static_cast<T*>(nullptr)->T::GetWarnAsLoading(),
263+
static_cast<T*>(nullptr)->T::GetGroup(),
264+
#endif
247265
static_cast<T*>(nullptr)->T::GetPack(),
248266
static_cast<T*>(nullptr)->T::GetCreateType(),
249267
static_cast<T*>(nullptr)->T::GetExitType(),

lib/libkiwi/core/kiwiSceneHookMgr.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ void SceneHookMgr::DoEnter() {
7171
GetCurrentScene()->Configure();
7272

7373
// Global hooks
74-
K_FOREACH (GetInstance().mGlobalHooks) {
74+
K_FOREACH (it, GetInstance().mGlobalHooks) {
7575
it->Configure(GetCurrentScene());
7676
}
7777

7878
// Hooks for game scene
7979
if (IsPackScene()) {
80-
K_FOREACH (GetInstance().GetActiveHooks()) {
80+
K_FOREACH (it, GetInstance().GetActiveHooks()) {
8181
it->Configure(GetCurrentScene());
8282
}
8383
}
@@ -93,27 +93,27 @@ KOKESHI_BY_PACK(KM_CALL(0x8018532c, SceneHookMgr::DoEnter), // Wii Sports
9393
*/
9494
void SceneHookMgr::DoReset() {
9595
// Global hooks
96-
K_FOREACH (GetInstance().mGlobalHooks) {
96+
K_FOREACH (it, GetInstance().mGlobalHooks) {
9797
it->BeforeReset(GetCurrentScene());
9898
}
9999

100100
// Hooks for game scene
101101
if (IsPackScene()) {
102-
K_FOREACH (GetInstance().GetActiveHooks()) {
102+
K_FOREACH (it, GetInstance().GetActiveHooks()) {
103103
it->BeforeReset(GetCurrentScene());
104104
}
105105
}
106106

107107
GetCurrentScene()->Reset();
108108

109109
// Global hooks
110-
K_FOREACH (GetInstance().mGlobalHooks) {
110+
K_FOREACH (it, GetInstance().mGlobalHooks) {
111111
it->AfterReset(GetCurrentScene());
112112
}
113113

114114
// Hooks for game scene
115115
if (IsPackScene()) {
116-
K_FOREACH (GetInstance().GetActiveHooks()) {
116+
K_FOREACH (it, GetInstance().GetActiveHooks()) {
117117
it->AfterReset(GetCurrentScene());
118118
}
119119
}
@@ -132,13 +132,13 @@ KOKESHI_BY_PACK(KM_CALL(0x801853d4, SceneHookMgr::DoReset), // Wii Sports
132132
*/
133133
void SceneHookMgr::DoLoadResource() {
134134
// Global hooks
135-
K_FOREACH (GetInstance().mGlobalHooks) {
135+
K_FOREACH (it, GetInstance().mGlobalHooks) {
136136
it->LoadResource(GetCurrentScene());
137137
}
138138

139139
// Hooks for game scene
140140
if (IsPackScene()) {
141-
K_FOREACH (GetInstance().GetActiveHooks()) {
141+
K_FOREACH (it, GetInstance().GetActiveHooks()) {
142142
it->LoadResource(GetCurrentScene());
143143
}
144144
}
@@ -154,13 +154,13 @@ KOKESHI_BY_PACK(KM_BRANCH(0x8018695c, SceneHookMgr::DoLoadResource), // Wii Spo
154154
*/
155155
void SceneHookMgr::DoCalculate() {
156156
// Global hooks
157-
K_FOREACH (GetInstance().mGlobalHooks) {
157+
K_FOREACH (it, GetInstance().mGlobalHooks) {
158158
it->BeforeCalculate(GetCurrentScene());
159159
}
160160

161161
// Hooks for game scene
162162
if (IsPackScene()) {
163-
K_FOREACH (GetInstance().GetActiveHooks()) {
163+
K_FOREACH (it, GetInstance().GetActiveHooks()) {
164164
it->BeforeCalculate(GetCurrentScene());
165165
}
166166
}
@@ -170,13 +170,13 @@ void SceneHookMgr::DoCalculate() {
170170
RP_GET_INSTANCE(RPSysSceneMgr)->SceneManager::calcCurrentScene();
171171

172172
// Global hooks
173-
K_FOREACH (GetInstance().mGlobalHooks) {
173+
K_FOREACH (it, GetInstance().mGlobalHooks) {
174174
it->AfterCalculate(GetCurrentScene());
175175
}
176176

177177
// Hooks for game scene
178178
if (IsPackScene()) {
179-
K_FOREACH (GetInstance().GetActiveHooks()) {
179+
K_FOREACH (it, GetInstance().GetActiveHooks()) {
180180
it->AfterCalculate(GetCurrentScene());
181181
}
182182
}
@@ -192,13 +192,13 @@ KOKESHI_BY_PACK(KM_BRANCH(0x80185868, SceneHookMgr::DoCalculate), // Wii Sports
192192
*/
193193
void SceneHookMgr::DoExit() {
194194
// Global hooks
195-
K_FOREACH (GetInstance().mGlobalHooks) {
195+
K_FOREACH (it, GetInstance().mGlobalHooks) {
196196
it->Exit(GetCurrentScene());
197197
}
198198

199199
// Hooks for game scene
200200
if (IsPackScene()) {
201-
K_FOREACH (GetInstance().GetActiveHooks()) {
201+
K_FOREACH (it, GetInstance().GetActiveHooks()) {
202202
it->Exit(GetCurrentScene());
203203
}
204204
}
@@ -214,13 +214,13 @@ KOKESHI_BY_PACK(KM_BRANCH(0x80185000, SceneHookMgr::DoExit), // Wii Sports
214214
*/
215215
void SceneHookMgr::DoPause() {
216216
// Global hooks
217-
K_FOREACH (GetInstance().mGlobalHooks) {
217+
K_FOREACH (it, GetInstance().mGlobalHooks) {
218218
it->Pause(GetCurrentScene(), true);
219219
}
220220

221221
// Hooks for game scene
222222
if (IsPackScene()) {
223-
K_FOREACH (GetInstance().GetActiveHooks()) {
223+
K_FOREACH (it, GetInstance().GetActiveHooks()) {
224224
it->Pause(GetCurrentScene(), true);
225225
}
226226
}
@@ -236,13 +236,13 @@ KOKESHI_BY_PACK(KM_BRANCH(0x801b68ec, SceneHookMgr::DoPause), // Wii Sports
236236
*/
237237
void SceneHookMgr::DoUnPause() {
238238
// Global hooks
239-
K_FOREACH (GetInstance().mGlobalHooks) {
239+
K_FOREACH (it, GetInstance().mGlobalHooks) {
240240
it->Pause(GetCurrentScene(), false);
241241
}
242242

243243
// Hooks for game scene
244244
if (IsPackScene()) {
245-
K_FOREACH (GetInstance().GetActiveHooks()) {
245+
K_FOREACH (it, GetInstance().GetActiveHooks()) {
246246
it->Pause(GetCurrentScene(), false);
247247
}
248248
}
Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,155 @@
11
#include <libkiwi.h>
22

3+
#include <RPGraphics.h>
4+
35
namespace kiwi {
46

5-
;
7+
/******************************************************************************
8+
*
9+
* DebugMenu
10+
*
11+
******************************************************************************/
12+
13+
/**
14+
* @brief Constructor
15+
*
16+
* @param pRootPage Menu root page
17+
*/
18+
DebugMenu::DebugMenu(DebugPage* pRootPage) {
19+
K_ASSERT(pRootPage != nullptr);
20+
mPageStack.Push(pRootPage);
21+
22+
RPGrpRenderer::GetCurrent()->AppendDrawObject(this);
23+
}
24+
25+
/**
26+
* @brief Updates the menu state
27+
* @return Result of actions
28+
*/
29+
DebugMenu::EResult DebugMenu::Calculate() {
30+
if (mPageStack.Empty()) {
31+
return EResult_None;
32+
}
33+
34+
return mPageStack.Top().Calculate();
35+
}
36+
37+
/**
38+
* @brief User-level render pass
39+
*/
40+
void DebugMenu::UserDraw() {
41+
if (mPageStack.Empty()) {
42+
return;
43+
}
44+
45+
mPageStack.Top().UserDraw();
46+
}
47+
48+
/******************************************************************************
49+
*
50+
* DebugPage
51+
*
52+
******************************************************************************/
53+
54+
/**
55+
* @brief Appends a new option to the page
56+
*
57+
* @param pOption Debug option
58+
* @return Success
59+
*/
60+
bool DebugPage::AddOption(DebugOptionBase* pOption) {
61+
K_ASSERT(pOption != nullptr);
62+
63+
if (mOptions.Size() >= mMaxOptions) {
64+
K_LOG_EX("Can't add option: %s\n", pOption->GetName().CStr());
65+
return false;
66+
}
67+
68+
mOptions.PushBack(pOption);
69+
return true;
70+
}
71+
72+
/**
73+
* @brief Updates the menu state
74+
* @return Result of actions
75+
*/
76+
DebugMenu::EResult DebugPage::Calculate() {
77+
for (int i = 0; i < EPlayer_Max; i++) {
78+
const WiiCtrl& rCtrl =
79+
CtrlMgr::GetInstance().GetWiiCtrl(static_cast<EPlayer>(i));
80+
81+
if (!rCtrl.IsConnected()) {
82+
continue;
83+
}
84+
85+
// Highlight option with Up/Down
86+
if (rCtrl.IsTrig(EButton_Up)) {
87+
mCursor = mCursor == 0 ? mOptions.Size() - 1 : mCursor - 1;
88+
return DebugMenu::EResult_Change;
89+
} else if (rCtrl.IsTrig(EButton_Down)) {
90+
mCursor = mCursor == mOptions.Size() - 1 ? 0 : mCursor + 1;
91+
return DebugMenu::EResult_Change;
92+
}
93+
94+
K_ASSERT(0 <= mCursor && mCursor < mOptions.Size());
95+
96+
DebugOptionBase* pOption = mOptions[mCursor];
97+
K_ASSERT(pOption != nullptr);
98+
99+
// Change option with Left/Right
100+
if (rCtrl.IsTrig(EButton_Right)) {
101+
pOption->Increment();
102+
return DebugMenu::EResult_Change;
103+
} else if (rCtrl.IsTrig(EButton_Left)) {
104+
pOption->Decrement();
105+
return DebugMenu::EResult_Change;
106+
}
107+
108+
// Select option with A
109+
if (rCtrl.IsTrig(EButton_A)) {
110+
pOption->Select();
111+
return DebugMenu::EResult_Change;
112+
}
113+
114+
// Close page with B
115+
if (rCtrl.IsTrig(EButton_B)) {
116+
return DebugMenu::EResult_Close;
117+
}
118+
}
119+
120+
return DebugMenu::EResult_None;
121+
}
122+
123+
/**
124+
* @brief User-level render pass
125+
*/
126+
void DebugPage::UserDraw() {
127+
f32 x = 0.25f;
128+
f32 y = 0.20f;
129+
static const f32 row = 0.05f;
130+
131+
for (u32 i = 0; i < mOptions.Size(); i++) {
132+
// clang-format off
133+
Text(mOptions[i]->GetName())
134+
.SetPosition(x + 0.00, y + 0.00)
135+
.SetScale(0.8);
136+
137+
Text(mOptions[i]->GetValueText())
138+
.SetPosition(x + 0.15, y + 0.00)
139+
.SetScale(0.8);
140+
// clang-format on
141+
142+
// Show cursor at selected option
143+
if (i == mCursor) {
144+
// clang-format off
145+
Text("*")
146+
.SetPosition(x - 0.015, y)
147+
.SetScale(0.8);
148+
// clang-format on
149+
}
150+
151+
y += row;
152+
}
153+
}
6154

7155
} // namespace kiwi

0 commit comments

Comments
 (0)