Skip to content

Commit 0d9d8d8

Browse files
committed
More work
1 parent 2e71f32 commit 0d9d8d8

11 files changed

Lines changed: 238 additions & 100 deletions

File tree

lib/libkiwi/core/kiwiSceneCreator.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ TMap<s32, SceneCreator::Info> SceneCreator::sUserScenes;
7979

8080
//! Root debug menu scene ID
8181
s32 SceneCreator::sDebugRootID = -1;
82+
//! Whether to boot into the root debug menu
83+
bool SceneCreator::sDebugRootBootUp = false;
8284
//! Root debug menu button combination (held)
8385
u16 SceneCreator::sDebugRootButtons = 0xFFFF;
8486

@@ -132,16 +134,19 @@ void SceneCreator::RegistScene(const Info& rInfo) {
132134
/**
133135
* @brief Registers root debug menu information
134136
* @details The debug root scene is entered when transitioning to the main
135-
* menu while the specified button mask is held.
137+
* menu while the specified button mask is held, or always on first boot
138+
* if the bootUp flag is set.
136139
*
137140
* @param id Debug root scene ID (-1 to disable)
138-
* @param buttons Buttons that must be held to visit the debug menu
139-
* (defaults to B+Minus+1+2)
141+
* @param bootUp Whether to boot into the debug root scene
142+
* @param buttons Buttons that must be held to visit the debug root scene
143+
* (defaults to B+MINUS)
140144
*/
141-
void SceneCreator::RegistDebugRoot(s32 id, u16 buttons) {
145+
void SceneCreator::RegistDebugRoot(s32 id, bool bootUp, u16 buttons) {
142146
K_ASSERT_EX(id >= 0 || id == -1, "Invalid scene ID");
143147

144148
sDebugRootID = id;
149+
sDebugRootBootUp = bootUp;
145150
sDebugRootButtons = buttons;
146151
}
147152

@@ -194,13 +199,18 @@ bool SceneCreator::ChangeSceneAfterFade(s32 id, bool reload) {
194199
}
195200

196201
// Visit debug root instead of menu if buttons are held
197-
if (id == GetMenuScene() && mLastSceneID != sDebugRootID) {
202+
if (id == GetMenuScene() && current != sDebugRootID) {
198203
for (int i = 0; i < EPlayer_Max; i++) {
199204
const WiiCtrl& rCtrl =
200205
CtrlMgr::GetInstance().GetWiiCtrl(static_cast<EPlayer>(i));
201206

202-
if (sDebugRootButtons == 0 ||
203-
rCtrl.IsConnected() && rCtrl.IsHold(sDebugRootButtons)) {
207+
bool visit = sDebugRootBootUp; // Visit on boot
208+
visit |= sDebugRootButtons == 0; // Always visit
209+
visit |= rCtrl.IsConnected() &&
210+
rCtrl.IsHold(sDebugRootButtons); // Button combo held
211+
212+
if (visit) {
213+
sDebugRootBootUp = false;
204214
id = sDebugRootID;
205215
break;
206216
}
@@ -244,14 +254,19 @@ bool SceneCreator::ChangeSceneAfterFade(s32 id, const nw4r::ut::Color* pColor) {
244254
id = current;
245255
}
246256

247-
// Visit debug root instead of menu if buttons are held
248-
if (id == GetMenuScene() && mLastSceneID != sDebugRootID) {
257+
// Visit debug root instead of menu if on boot, or if buttons are held
258+
if (id == GetMenuScene() && current != sDebugRootID) {
249259
for (int i = 0; i < EPlayer_Max; i++) {
250260
const WiiCtrl& rCtrl =
251261
CtrlMgr::GetInstance().GetWiiCtrl(static_cast<EPlayer>(i));
252262

253-
if (sDebugRootButtons == 0 ||
254-
rCtrl.IsConnected() && rCtrl.IsHold(sDebugRootButtons)) {
263+
bool visit = sDebugRootBootUp; // Visit on boot
264+
visit |= sDebugRootButtons == 0; // Always visit
265+
visit |= rCtrl.IsConnected() &&
266+
rCtrl.IsHold(sDebugRootButtons); // Button combo held
267+
268+
if (visit) {
269+
sDebugRootBootUp = false;
255270
id = sDebugRootID;
256271
break;
257272
}

lib/libkiwi/core/kiwiSceneCreator.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,16 @@ class SceneCreator : public ExtSingletonPtr<RPSysSceneCreator, SceneCreator> {
192192
/**
193193
* @brief Registers root debug menu information
194194
* @details The debug root scene is entered when transitioning to the main
195-
* menu while the specified button mask is held.
195+
* menu while the specified button mask is held, or always on first boot
196+
* if the bootUp flag is set.
196197
*
197198
* @param id Debug root scene ID (-1 to disable)
198-
* @param buttons Buttons that must be held to visit the debug menu
199-
* (defaults to B+MINUS+2)
199+
* @param bootUp Whether to boot into the debug root scene
200+
* @param buttons Buttons that must be held to visit the debug root scene
201+
* (defaults to B+MINUS)
200202
*/
201-
static void RegistDebugRoot(s32 id,
202-
u16 buttons = (EButton_B | EButton_Minus |
203-
EButton_2));
203+
static void RegistDebugRoot(s32 id, bool bootUp = true,
204+
u16 buttons = EButton_B | EButton_Minus);
204205

205206
/**
206207
* @brief Gets the scene ID of the main menu scene
@@ -347,6 +348,8 @@ class SceneCreator : public ExtSingletonPtr<RPSysSceneCreator, SceneCreator> {
347348

348349
//! Root debug menu scene ID
349350
static s32 sDebugRootID;
351+
//! Whether to boot into the root debug menu
352+
static bool sDebugRootBootUp;
350353
//! Root debug menu button combination (held)
351354
static u16 sDebugRootButtons;
352355
};

lib/libkiwi/debug/kiwiDebugMenu.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ namespace kiwi {
99
******************************************************************************/
1010

1111
/**
12-
* @brief Constructor
12+
* @brief Opens a new menu page
1313
*
14-
* @param pRootPage Menu root page
14+
* @param rPage Menu page
1515
*/
16-
DebugMenu::DebugMenu(DebugPage* pRootPage) {
17-
K_ASSERT(pRootPage != nullptr);
18-
mPageStack.Push(pRootPage);
16+
void DebugMenu::OpenPage(DebugPage& rPage) {
17+
rPage.SetParent(*this);
18+
mPageStack.Push(&rPage);
1919
}
2020

2121
/**
2222
* @brief Updates the menu state
2323
* @return Result of actions
2424
*/
25-
DebugMenu::EResult DebugMenu::Calculate() {
25+
EDebugMenuResult DebugMenu::Calculate() {
2626
if (mPageStack.Empty()) {
27-
return EResult_None;
27+
return EDebugMenuResult_None;
2828
}
2929

3030
return mPageStack.Top().Calculate();
@@ -50,26 +50,24 @@ void DebugMenu::UserDraw() {
5050
/**
5151
* @brief Appends a new option to the page
5252
*
53-
* @param pOption Debug option
53+
* @param rOption Debug option
5454
* @return Success
5555
*/
56-
bool DebugPage::AddOption(DebugOptionBase* pOption) {
57-
K_ASSERT(pOption != nullptr);
58-
56+
bool DebugPage::AddOption(DebugOptionBase& rOption) {
5957
if (mOptions.Size() >= mMaxOptions) {
60-
K_LOG_EX("Can't add option: %s\n", pOption->GetName().CStr());
58+
K_LOG_EX("Can't add option: %s\n", rOption.GetName().CStr());
6159
return false;
6260
}
6361

64-
mOptions.PushBack(pOption);
62+
mOptions.PushBack(&rOption);
6563
return true;
6664
}
6765

6866
/**
6967
* @brief Updates the menu state
7068
* @return Result of actions
7169
*/
72-
DebugMenu::EResult DebugPage::Calculate() {
70+
EDebugMenuResult DebugPage::Calculate() {
7371
for (int i = 0; i < EPlayer_Max; i++) {
7472
const WiiCtrl& rCtrl =
7573
CtrlMgr::GetInstance().GetWiiCtrl(static_cast<EPlayer>(i));
@@ -81,10 +79,11 @@ DebugMenu::EResult DebugPage::Calculate() {
8179
// Highlight option with Up/Down
8280
if (rCtrl.IsTrig(EButton_Up)) {
8381
mCursor = mCursor == 0 ? mOptions.Size() - 1 : mCursor - 1;
84-
return DebugMenu::EResult_Change;
82+
return EDebugMenuResult_Cursor;
83+
8584
} else if (rCtrl.IsTrig(EButton_Down)) {
8685
mCursor = mCursor == mOptions.Size() - 1 ? 0 : mCursor + 1;
87-
return DebugMenu::EResult_Change;
86+
return EDebugMenuResult_Cursor;
8887
}
8988

9089
K_ASSERT(0 <= mCursor && mCursor < mOptions.Size());
@@ -95,52 +94,53 @@ DebugMenu::EResult DebugPage::Calculate() {
9594
// Change option with Left/Right
9695
if (rCtrl.IsTrig(EButton_Right)) {
9796
pOption->Increment();
98-
return DebugMenu::EResult_Change;
97+
return EDebugMenuResult_Change;
98+
9999
} else if (rCtrl.IsTrig(EButton_Left)) {
100100
pOption->Decrement();
101-
return DebugMenu::EResult_Change;
101+
return EDebugMenuResult_Change;
102102
}
103103

104104
// Select option with A
105105
if (rCtrl.IsTrig(EButton_A)) {
106106
pOption->Select();
107-
return DebugMenu::EResult_Change;
107+
return EDebugMenuResult_Select;
108108
}
109109

110110
// Close page with B
111111
if (rCtrl.IsTrig(EButton_B)) {
112-
return DebugMenu::EResult_Close;
112+
return EDebugMenuResult_Close;
113113
}
114114
}
115115

116-
return DebugMenu::EResult_None;
116+
return EDebugMenuResult_None;
117117
}
118118

119119
/**
120120
* @brief User-level render pass
121121
*/
122122
void DebugPage::UserDraw() {
123-
f32 x = 0.25f;
123+
f32 x = 0.15f;
124124
f32 y = 0.20f;
125+
126+
static const f32 cursor = 0.015f;
127+
static const f32 option = 0.25f;
125128
static const f32 row = 0.05f;
126129

127130
for (u32 i = 0; i < mOptions.Size(); i++) {
128131
Text(mOptions[i]->GetName())
129132
.SetStrokeType(ETextStroke_Outline)
130-
.SetPosition(x + 0.00, y + 0.00)
131-
.SetScale(0.8);
133+
.SetPosition(x, y);
132134

133135
Text(mOptions[i]->GetValueText())
134136
.SetStrokeType(ETextStroke_Outline)
135-
.SetPosition(x + 0.15, y + 0.00)
136-
.SetScale(0.8);
137+
.SetPosition(x + option, y);
137138

138139
// Show cursor at selected option
139140
if (i == mCursor) {
140141
Text("*")
141142
.SetStrokeType(ETextStroke_Outline)
142-
.SetPosition(x - 0.015, y)
143-
.SetScale(0.8);
143+
.SetPosition(x - cursor, y);
144144
}
145145

146146
y += row;

lib/libkiwi/debug/kiwiDebugMenu.h

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,49 @@ namespace kiwi {
1313
class DebugOptionBase;
1414
class DebugPage;
1515

16+
/**
17+
* @brief Debug menu action result
18+
*/
19+
enum EDebugMenuResult {
20+
EDebugMenuResult_None, //!< Nothing happened
21+
EDebugMenuResult_Invalid, //!< State failed to change
22+
EDebugMenuResult_Cursor, //!< Cursor changed
23+
EDebugMenuResult_Change, //!< State changed
24+
EDebugMenuResult_Select, //!< Button selected
25+
EDebugMenuResult_Close, //!< Request to close page/menu
26+
};
27+
1628
/**
1729
* @brief Debug menu
1830
*/
1931
class DebugMenu : public IRPGrpDrawObject {
20-
public:
21-
/**
22-
* @brief Option action result
23-
*/
24-
enum EResult {
25-
EResult_None, //!< Nothing happened
26-
EResult_Invalid, //!< State failed to change
27-
EResult_Change, //!< State changed
28-
EResult_Close, //!< Request to close menu
29-
};
30-
3132
public:
3233
/**
3334
* @brief Constructor
3435
*
35-
* @param pRootPage Menu root page
36+
* @param rRootPage Menu root page
3637
*/
37-
DebugMenu(DebugPage* pRootPage);
38+
DebugMenu(DebugPage& rRootPage) {
39+
OpenPage(rRootPage);
40+
}
3841

3942
/**
4043
* @brief Destructor
4144
*/
4245
virtual ~DebugMenu() {}
4346

47+
/**
48+
* @brief Opens a new menu page
49+
*
50+
* @param rPage Menu page
51+
*/
52+
void OpenPage(DebugPage& rPage);
53+
4454
/**
4555
* @brief Updates the menu state
4656
* @return Result of actions
4757
*/
48-
virtual EResult Calculate();
58+
virtual EDebugMenuResult Calculate();
4959

5060
/**
5161
* @brief User-level render pass
@@ -74,26 +84,45 @@ class DebugPage {
7484
DebugPage(u32 maxOptions = DEFAULT_MAX_OPTIONS)
7585
: mCursor(0), mMaxOptions(maxOptions) {}
7686

87+
/**
88+
* @brief Gets the page's parent menu
89+
*/
90+
DebugMenu& GetParent() const {
91+
K_ASSERT(mpParent != nullptr);
92+
return *mpParent;
93+
}
94+
/**
95+
* @brief Sets the page's parent menu
96+
*
97+
* @param rMenu Parent menu
98+
*/
99+
void SetParent(DebugMenu& rMenu) {
100+
mpParent = &rMenu;
101+
}
102+
77103
/**
78104
* @brief Appends a new option to the page
79105
*
80-
* @param pOption Debug option
106+
* @param rOption Debug option
81107
* @return Success
82108
*/
83-
bool AddOption(DebugOptionBase* pOption);
109+
bool AddOption(DebugOptionBase& rOption);
84110

85111
/**
86112
* @brief Updates the menu state
87113
* @return Result of actions
88114
*/
89-
virtual DebugMenu::EResult Calculate();
115+
virtual EDebugMenuResult Calculate();
90116

91117
/**
92118
* @brief User-level render pass
93119
*/
94120
virtual void UserDraw();
95121

96122
protected:
123+
//! Parent menu
124+
DebugMenu* mpParent;
125+
97126
//! Cursor position
98127
u32 mCursor;
99128
//! Maximum number of options

0 commit comments

Comments
 (0)