Skip to content

Commit fdaabe3

Browse files
committed
Example menu
1 parent 0d9d8d8 commit fdaabe3

File tree

10 files changed

+164
-25
lines changed

10 files changed

+164
-25
lines changed

base/symbols_resort.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3637,7 +3637,10 @@ CreateView2D__13RPGrpRendererFUcP11RPGrpScreen=0x80253e1c
36373637
CorrectView__13RPGrpRendererFv=0x80253d68
36383638
__vt__11RPGrpScreen=0x806b5358
36393639

3640-
playSound__Q23Sp27SndUtilFUlUl=0x802b735c
3640+
startSeWithRemote__Q23Sp23SndFUlUl=0x802b735c
3641+
startSe__Q23Sp23SndFUl=0x802b73bc
3642+
startBgm__Q23Sp23SndFUl=0x802b7228
3643+
36413644
sInstance__Q33Sp23Swf5Scene=0x806f5ff0
36423645
spInstance__Q33Sp23Cmn9StaticMem=0x806f4e98
36433646
spInstance__17RPSysSystemWinMgr=0x806f4cd0

include/Sports2/Snd/Sp2SndUtil.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
#include <Sports2/Sp2Types.h>
44

55
namespace Sp2 {
6+
namespace Snd {
67

7-
class SndUtil {
8-
public:
9-
static void playBgm(u32 id);
10-
static void playSound(u32 id, u32 spkFlag);
11-
};
8+
void startBgm(u32 id);
9+
void startSe(u32 id);
10+
void startSeWithRemote(u32 id, u32 spkFlag);
1211

12+
} // namespace Snd
1313
} // namespace Sp2
1414

15-
#endif
15+
#endif

lib/libkiwi/debug/kiwiDebugMenu.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@ EDebugMenuResult DebugMenu::Calculate() {
2727
return EDebugMenuResult_None;
2828
}
2929

30-
return mPageStack.Top().Calculate();
30+
EDebugMenuResult result = mPageStack.Top().Calculate();
31+
32+
if (result == EDebugMenuResult_Close) {
33+
// Can't close the root page
34+
if (mPageStack.Size() > 1) {
35+
mPageStack.Pop();
36+
} else {
37+
result = EDebugMenuResult_Invalid;
38+
}
39+
}
40+
41+
return result;
3142
}
3243

3344
/**
@@ -59,7 +70,9 @@ bool DebugPage::AddOption(DebugOptionBase& rOption) {
5970
return false;
6071
}
6172

73+
rOption.SetParent(*this);
6274
mOptions.PushBack(&rOption);
75+
6376
return true;
6477
}
6578

@@ -93,18 +106,14 @@ EDebugMenuResult DebugPage::Calculate() {
93106

94107
// Change option with Left/Right
95108
if (rCtrl.IsTrig(EButton_Right)) {
96-
pOption->Increment();
97-
return EDebugMenuResult_Change;
98-
109+
return pOption->Increment();
99110
} else if (rCtrl.IsTrig(EButton_Left)) {
100-
pOption->Decrement();
101-
return EDebugMenuResult_Change;
111+
return pOption->Decrement();
102112
}
103113

104114
// Select option with A
105115
if (rCtrl.IsTrig(EButton_A)) {
106-
pOption->Select();
107-
return EDebugMenuResult_Select;
116+
return pOption->Select();
108117
}
109118

110119
// Close page with B

lib/libkiwi/debug/kiwiDebugOption.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ EDebugMenuResult DebugProcOption::Select() {
227227
EDebugMenuResult DebugOpenPageOption::OpenPageProc(void* pArg) {
228228
K_ASSERT(pArg != nullptr);
229229

230-
DebugPage* pPage = static_cast<DebugPage*>(pArg);
231-
pPage->GetParent().OpenPage(*pPage);
230+
DebugOpenPageOption* p = static_cast<DebugOpenPageOption*>(pArg);
231+
p->GetParent().GetParent().OpenPage(*p->mpPage);
232232

233233
return EDebugMenuResult_Select;
234234
}

lib/libkiwi/debug/kiwiDebugOption.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ class DebugOptionBase {
4545
*/
4646
virtual ~DebugOptionBase() {}
4747

48+
/**
49+
* @brief Gets the options's parent menu page
50+
*/
51+
DebugPage& GetParent() const {
52+
K_ASSERT(mpParent != nullptr);
53+
return *mpParent;
54+
}
55+
/**
56+
* @brief Sets the options's parent menu page
57+
*
58+
* @param rPage Parent menu page
59+
*/
60+
void SetParent(DebugPage& rPage) {
61+
mpParent = &rPage;
62+
}
63+
4864
/**
4965
* @brief Gets the type of the option
5066
*/
@@ -122,6 +138,9 @@ class DebugOptionBase {
122138
virtual void UpdateString() {}
123139

124140
protected:
141+
//! Parent menu page
142+
DebugPage* mpParent;
143+
125144
//! Enable option
126145
bool mIsEnabled;
127146

@@ -409,7 +428,7 @@ class DebugOpenPageOption : public DebugProcOption {
409428
* @param rPage Sub-page to open
410429
*/
411430
DebugOpenPageOption(const String& rName, DebugPage& rPage)
412-
: DebugProcOption(rName, OpenPageProc, mpPage) {
431+
: DebugProcOption(rName, OpenPageProc, this) {
413432

414433
mpPage = &rPage;
415434
}

src/scene/DebugRootScene/MainPage.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ namespace DebugRoot {
1111
MainPage::MainPage()
1212
: mDummyIntOption("DummyInt", 0, 5),
1313
mDummyBoolOption("DummyBool"),
14-
mDummyProcOption("DummyProc", ReturnToMenuProc) {
14+
mDummyOpenPageOption("DummyOpenPage", mSubPage),
15+
mGotoMenuOption("Goto Menu", GotoMenuProc) {
1516

1617
AddOption(mDummyIntOption);
1718
AddOption(mDummyBoolOption);
18-
AddOption(mDummyProcOption);
19+
AddOption(mDummyOpenPageOption);
20+
AddOption(mGotoMenuOption);
1921
}
2022

2123
/**
2224
* @brief Returns to the main menu scene
2325
*/
24-
kiwi::EDebugMenuResult MainPage::ReturnToMenuProc(void* pArg) {
26+
kiwi::EDebugMenuResult MainPage::GotoMenuProc(void* pArg) {
2527
kiwi::SceneCreator::GetInstance().ChangeSceneAfterFade(
2628
kiwi::SceneCreator::GetMenuScene());
2729

28-
return kiwi::EDebugMenuResult_Close;
30+
return kiwi::EDebugMenuResult_Select;
2931
}
3032

3133
} // namespace DebugRoot

src/scene/DebugRootScene/MainPage.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef APCLIENT_SCENE_DEBUGROOTSCENE_MAIN_PAGE_H
22
#define APCLIENT_SCENE_DEBUGROOTSCENE_MAIN_PAGE_H
33
#include "core/const.h"
4+
#include "scene/DebugRootScene/SubPage.h"
45

56
#include <libkiwi.h>
67

@@ -25,12 +26,20 @@ class MainPage : public kiwi::DebugPage {
2526
/**
2627
* @brief Returns to the main menu scene
2728
*/
28-
static kiwi::EDebugMenuResult ReturnToMenuProc(void* pArg);
29+
static kiwi::EDebugMenuResult GotoMenuProc(void* pArg);
2930

3031
private:
32+
//! Example integer option
3133
kiwi::DebugIntOption mDummyIntOption;
34+
//! Example boolean option
3235
kiwi::DebugBoolOption mDummyBoolOption;
33-
kiwi::DebugProcOption mDummyProcOption;
36+
37+
//! Example sub-page, and the option to open it
38+
SubPage mSubPage;
39+
kiwi::DebugOpenPageOption mDummyOpenPageOption;
40+
41+
//! Example procedure option (goto menu scene)
42+
kiwi::DebugProcOption mGotoMenuOption;
3443
};
3544

3645
} // namespace DebugRoot

src/scene/DebugRootScene/Scene.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "scene/DebugRootScene/Scene.h"
22

3+
#include <Sports2/Sp2Snd.h>
4+
35
#include <libkiwi.h>
46

57
namespace AP {
@@ -23,7 +25,39 @@ void Scene::OnConfigure() {
2325
* @brief Calculate state user callback
2426
*/
2527
void Scene::OnCalculate() {
26-
mDebugMenu.Calculate();
28+
kiwi::EDebugMenuResult result = mDebugMenu.Calculate();
29+
30+
switch (result) {
31+
case kiwi::EDebugMenuResult_Invalid: {
32+
Sp2::Snd::startSe(SE_CMN_NG_01);
33+
break;
34+
}
35+
36+
case kiwi::EDebugMenuResult_Cursor: {
37+
Sp2::Snd::startSe(SE_CMN_CURSOR_01);
38+
break;
39+
}
40+
41+
case kiwi::EDebugMenuResult_Change: {
42+
Sp2::Snd::startSe(SE_CMN_CURSOR_01);
43+
break;
44+
}
45+
46+
case kiwi::EDebugMenuResult_Select: {
47+
Sp2::Snd::startSe(SE_CMN_DECIDE_01);
48+
break;
49+
}
50+
51+
case kiwi::EDebugMenuResult_Close: {
52+
Sp2::Snd::startSe(SE_CMN_CANCEL_01);
53+
break;
54+
}
55+
56+
case kiwi::EDebugMenuResult_None:
57+
default: {
58+
break;
59+
}
60+
}
2761
}
2862

2963
/**
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "scene/DebugRootScene/SubPage.h"
2+
3+
#include <libkiwi.h>
4+
5+
namespace AP {
6+
namespace DebugRoot {
7+
8+
/**
9+
* @brief Constructor
10+
*/
11+
SubPage::SubPage()
12+
: mDummyProcOption("Nothing here - press B to close page", DummyProc) {
13+
14+
AddOption(mDummyProcOption);
15+
}
16+
17+
/**
18+
* @brief Placeholder procedure
19+
*/
20+
kiwi::EDebugMenuResult SubPage::DummyProc(void* pArg) {
21+
return kiwi::EDebugMenuResult_Invalid;
22+
}
23+
24+
} // namespace DebugRoot
25+
} // namespace AP

src/scene/DebugRootScene/SubPage.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef APCLIENT_SCENE_DEBUGROOTSCENE_SUB_PAGE_H
2+
#define APCLIENT_SCENE_DEBUGROOTSCENE_SUB_PAGE_H
3+
#include "core/const.h"
4+
5+
#include <libkiwi.h>
6+
7+
namespace AP {
8+
namespace DebugRoot {
9+
10+
/**
11+
* @brief Debug menu example sub-page
12+
*/
13+
class SubPage : public kiwi::DebugPage {
14+
public:
15+
/**
16+
* @brief Constructor
17+
*/
18+
SubPage();
19+
20+
/**
21+
* @brief Destructor
22+
*/
23+
virtual ~SubPage() {}
24+
25+
/**
26+
* @brief Placeholder procedure
27+
*/
28+
static kiwi::EDebugMenuResult DummyProc(void* pArg);
29+
30+
private:
31+
//! Example procedure option (doesn't actually do anything)
32+
kiwi::DebugProcOption mDummyProcOption;
33+
};
34+
35+
} // namespace DebugRoot
36+
} // namespace AP
37+
38+
#endif

0 commit comments

Comments
 (0)