From 3392ff663086f5d454118b41c901c42d6a52b73e Mon Sep 17 00:00:00 2001 From: Kiwi <49212064+kiwi515@users.noreply.github.com> Date: Sun, 25 May 2025 13:38:29 -0400 Subject: [PATCH 1/4] Options link to menu not page --- lib/libkiwi/debug/kiwiDebugOption.cpp | 8 ++--- lib/libkiwi/debug/kiwiDebugOption.h | 44 +++++++++++++-------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/libkiwi/debug/kiwiDebugOption.cpp b/lib/libkiwi/debug/kiwiDebugOption.cpp index 061ac87..12138f1 100644 --- a/lib/libkiwi/debug/kiwiDebugOption.cpp +++ b/lib/libkiwi/debug/kiwiDebugOption.cpp @@ -27,15 +27,15 @@ void DebugOptionBase::SetEnabled(bool enable) { /** * @brief Constructor * - * @param rPage Parent page + * @param rMenu Parent menu * @param rName Option name * @param min Minimum value (inclusive) * @param max Maximum value (inclusive) * @param initial Initial value (optional) */ -DebugIntOption::DebugIntOption(DebugPage& rPage, const String& rName, int min, +DebugIntOption::DebugIntOption(DebugMenu& rMenu, const String& rName, int min, int max, Optional initial) - : DebugOptionBase(rPage, rName), mMin(min), mMax(max) { + : DebugOptionBase(rMenu, rName), mMin(min), mMax(max) { K_ASSERT(max >= min); @@ -237,7 +237,7 @@ EDebugMenuResult DebugOpenPageOption::OpenPageProc(void* pArg) { K_ASSERT_PTR(pArg); DebugOpenPageOption* p = static_cast(pArg); - p->GetPage().GetMenu().OpenPage(*p->mpOpenPage); + p->GetMenu().OpenPage(*p->mpOpenPage); return EDebugMenuResult_Select; } diff --git a/lib/libkiwi/debug/kiwiDebugOption.h b/lib/libkiwi/debug/kiwiDebugOption.h index 6393255..1457fdf 100644 --- a/lib/libkiwi/debug/kiwiDebugOption.h +++ b/lib/libkiwi/debug/kiwiDebugOption.h @@ -35,11 +35,11 @@ class DebugOptionBase { /** * @brief Constructor * - * @param rPage Parent page + * @param rMenu Parent menu * @param rName Option name */ - DebugOptionBase(DebugPage& rPage, const String& rName) - : mrPage(rPage), mIsEnabled(true), mName(rName) {} + DebugOptionBase(DebugMenu& rMenu, const String& rName) + : mrMenu(rMenu), mIsEnabled(true), mName(rName) {} /** * @brief Destructor @@ -47,10 +47,10 @@ class DebugOptionBase { virtual ~DebugOptionBase() {} /** - * @brief Gets the options's parent menu page + * @brief Gets the option's parent menu */ - DebugPage& GetPage() const { - return mrPage; + DebugMenu& GetMenu() const { + return mrMenu; } /** @@ -130,8 +130,8 @@ class DebugOptionBase { virtual void UpdateString() {} protected: - //! Parent menu page - DebugPage& mrPage; + //! Parent menu + DebugMenu& mrMenu; //! Enable option bool mIsEnabled; @@ -157,13 +157,13 @@ class DebugIntOption : public DebugOptionBase { /** * @brief Constructor * - * @param rPage Parent page + * @param rMenu Parent menu * @param rName Option name * @param min Minimum value (inclusive) * @param max Maximum value (inclusive) * @param initial Initial value (optional) */ - DebugIntOption(DebugPage& rPage, const String& rName, int min, int max, + DebugIntOption(DebugMenu& rMenu, const String& rName, int min, int max, Optional initial = kiwi::nullopt); /** @@ -272,12 +272,12 @@ class DebugBoolOption : public DebugIntOption { /** * @brief Constructor * - * @param rPage Parent page + * @param rMenu Parent menu * @param rName Option name * @param initial Initial value (optional) */ - DebugBoolOption(DebugPage& rPage, const String& rName, bool initial = false) - : DebugIntOption(rPage, rName, static_cast(false), + DebugBoolOption(DebugMenu& rMenu, const String& rName, bool initial = false) + : DebugIntOption(rMenu, rName, static_cast(false), static_cast(true), static_cast(initial)) { UpdateString(); @@ -312,17 +312,17 @@ class DebugEnumOption : public DebugIntOption { /** * @brief Constructor * - * @param rPage Parent page + * @param rMenu Parent menu * @param rName Option name * @param ppValues Enum value strings * @param min Minimum value (inclusive) * @param max Maximum value (inclusive) * @param initial Initial value (optional) */ - DebugEnumOption(DebugPage& rPage, const String& rName, + DebugEnumOption(DebugMenu& rMenu, const String& rName, const char** ppValues, int min, int max, Optional initial = kiwi::nullopt) - : DebugIntOption(rPage, rName, min, max, initial), mppValues(ppValues) { + : DebugIntOption(rMenu, rName, min, max, initial), mppValues(ppValues) { ASSERT(ppValues != nullptr); @@ -375,14 +375,14 @@ class DebugProcOption : public DebugOptionBase { /** * @brief Constructor * - * @param rPage Parent page + * @param rMenu Parent menu * @param rName Option name * @param pCallback Select callback function * @param pCallbackArg Select callback user argument */ - DebugProcOption(DebugPage& rPage, const String& rName, + DebugProcOption(DebugMenu& rMenu, const String& rName, SelectCallback pCallback, void* pCallbackArg = nullptr) - : DebugOptionBase(rPage, rName), + : DebugOptionBase(rMenu, rName), mpCallback(pCallback), mpCallbackArg(pCallbackArg) {} @@ -421,13 +421,13 @@ class DebugOpenPageOption : public DebugProcOption { /** * @brief Constructor * - * @param rPage Parent page + * @param rMenu Parent menu * @param rName Option name * @param rOpenPage Sub-page to open */ - DebugOpenPageOption(DebugPage& rPage, const String& rName, + DebugOpenPageOption(DebugMenu& rMenu, const String& rName, DebugPage& rOpenPage) - : DebugProcOption(rPage, rName, OpenPageProc, this) { + : DebugProcOption(rMenu, rName, OpenPageProc, this) { mpOpenPage = &rOpenPage; } From 13319045785a44224739b1b02150538270a20dd9 Mon Sep 17 00:00:00 2001 From: Kiwi <49212064+kiwi515@users.noreply.github.com> Date: Sun, 25 May 2025 14:03:37 -0400 Subject: [PATCH 2/4] Fix state machine for void types --- lib/libkiwi/util/kiwiStateMachine.h | 18 +++++++++++------- src/scene/DebugRootScene/RootPage.cpp | 2 +- src/scene/DebugRootScene/SceneSelectPage.cpp | 2 +- src/scene/DebugRootScene/SeqSelectPage.cpp | 10 +++++----- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/libkiwi/util/kiwiStateMachine.h b/lib/libkiwi/util/kiwiStateMachine.h index 3b313e6..3431470 100644 --- a/lib/libkiwi/util/kiwiStateMachine.h +++ b/lib/libkiwi/util/kiwiStateMachine.h @@ -3,6 +3,8 @@ #include #include +#include + /** * @brief Declares state calc/exit functions */ @@ -129,15 +131,17 @@ template class StateMachine { mPrevState = mState; mState = mNextState; - mDuration = 0; + mDuration = -1; mEntering = false; } - K_ASSERT(mpCalcFunctions[mState]); - TStateReturn result = (mpObject->*mpCalcFunctions[mState])(); + // Prevent overflow + if (mDuration < INT_MAX) { + mDuration++; + } - mDuration++; - return result; + K_ASSERT(mpCalcFunctions[mState]); + return (mpObject->*mpCalcFunctions[mState])(); } private: @@ -146,7 +150,7 @@ template class StateMachine { s32 mState; //!< Current state u32 mStateNum; //!< Number of possible states - u32 mDuration; //!< Current state duration + s32 mDuration; //!< Current state duration s32 mPrevState; //!< Previous state s32 mNextState; //!< Next state @@ -154,7 +158,7 @@ template class StateMachine { bool mExiting; //!< Whether to call the enter function StateFunc* mpCalcFunctions; //!< State update functions - StateFunc* mpExitFunctions; //!< State update functions + StateFunc* mpExitFunctions; //!< State exit functions }; //! @} diff --git a/src/scene/DebugRootScene/RootPage.cpp b/src/scene/DebugRootScene/RootPage.cpp index 0f75ded..8a63092 100644 --- a/src/scene/DebugRootScene/RootPage.cpp +++ b/src/scene/DebugRootScene/RootPage.cpp @@ -12,7 +12,7 @@ namespace DebugRoot { */ RootPage::RootPage(kiwi::DebugMenu& rMenu) : kiwi::DebugPage(rMenu), - mSceneSelect(*this, "Scene Select", mSceneSelectPage), + mSceneSelect(rMenu, "Scene Select", mSceneSelectPage), mSceneSelectPage(rMenu) { mOptions.PushBack(&mSceneSelect); diff --git a/src/scene/DebugRootScene/SceneSelectPage.cpp b/src/scene/DebugRootScene/SceneSelectPage.cpp index bade0d9..e119dd2 100644 --- a/src/scene/DebugRootScene/SceneSelectPage.cpp +++ b/src/scene/DebugRootScene/SceneSelectPage.cpp @@ -20,7 +20,7 @@ SceneSelectPage::SceneSelectPage(kiwi::DebugMenu& rMenu) ASSERT_PTR(pSceneName); kiwi::DebugProcOption* pOption = - new kiwi::DebugProcOption(*this, pSceneName, SelectProc, this); + new kiwi::DebugProcOption(rMenu, pSceneName, SelectProc, this); ASSERT_PTR(pOption); diff --git a/src/scene/DebugRootScene/SeqSelectPage.cpp b/src/scene/DebugRootScene/SeqSelectPage.cpp index 6e2f4c1..9005604 100644 --- a/src/scene/DebugRootScene/SeqSelectPage.cpp +++ b/src/scene/DebugRootScene/SeqSelectPage.cpp @@ -56,11 +56,11 @@ SeqSelectPage::SeqSelectPage(kiwi::DebugMenu& rMenu) mStateMachine(this, EState_Max, EState_Select), mNextScene(-1), mExitTimer(0), - mPlayerNum(*this, "PlayerNum", 1, kiwi::EPlayer_Max), - mRemoteNum(*this, "RemoteNum", 1, kiwi::EPlayer_Max), - mGameMode(*this, "GameMode", GameMode_Keys_Swf, 0, + mPlayerNum(rMenu, "PlayerNum", 1, kiwi::EPlayer_Max), + mRemoteNum(rMenu, "RemoteNum", 1, kiwi::EPlayer_Max), + mGameMode(rMenu, "GameMode", GameMode_Keys_Swf, 0, LENGTHOF(GameMode_Keys_Swf)), - mStageNo(*this, "StageNo", 0, 0) { + mStageNo(rMenu, "StageNo", 0, 0) { mStateMachine.RegistState(EState_Select, &State_Select_calc); mStateMachine.RegistState(EState_Decide, &State_Decide_calc); @@ -131,7 +131,6 @@ void SeqSelectPage::SetNextScene(s32 scene) { * @return Result of actions */ kiwi::EDebugMenuResult SeqSelectPage::State_Select_calc() { - // Press A at any point to commit settings for (int i = 0; i < kiwi::EPlayer_Max; i++) { const kiwi::WiiCtrl& rCtrl = kiwi::CtrlMgr::GetInstance().GetWiiCtrl(i); @@ -139,6 +138,7 @@ kiwi::EDebugMenuResult SeqSelectPage::State_Select_calc() { continue; } + // Press A at any point to commit settings if (rCtrl.IsTrig(kiwi::EButton_A)) { mStateMachine.ChangeState(EState_Decide); break; From e86e971446784ead004d78726534232ee8421978 Mon Sep 17 00:00:00 2001 From: kiwi515 <49212064+kiwi515@users.noreply.github.com> Date: Sun, 25 May 2025 17:16:25 -0400 Subject: [PATCH 3/4] Disable game mode option when n/a --- include/Sports2/Cmn/Sp2CmnStaticMem.h | 38 ++++++++++++++++++---- src/core/CosmeticMgr.cpp | 2 +- src/scene/DebugRootScene/SeqSelectPage.cpp | 1 + 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/Sports2/Cmn/Sp2CmnStaticMem.h b/include/Sports2/Cmn/Sp2CmnStaticMem.h index 1d80902..bb31e88 100644 --- a/include/Sports2/Cmn/Sp2CmnStaticMem.h +++ b/include/Sports2/Cmn/Sp2CmnStaticMem.h @@ -3,25 +3,45 @@ #include #include +#include + namespace Sp2 { namespace Cmn { -class StaticMem { +enum EPlayStyle { EPlayStyle_Team, EPlayStyle_Solo }; +enum EPlayTeam { EPlayTeam_Blue, EPlayTeam_Red }; + +/** + * @brief Static memory region + * @details Used for passing data between scenes + */ +class StaticMem /* : EGG::Singleton */ { RP_SINGLETON_DECL(StaticMem); public: u32 getVariable(u32 index, bool local = false); void setVariable(u32 index, u32 value, bool local = false); - u32 getSceneSeq() const { + s32 getSceneSeq() const { return mSequenceNo; } - void setSceneSeq(u32 seq); + void setSceneSeq(s32 seq) { + mSequenceNo = seq; + } u32 getSceneGroup() const { return mGroupNo; } - void setSceneGroup(u32 group); + void setSceneGroup(u32 group) { + mGroupNo = group; + } + + u32 getStageNo() const { + return mStageNo; + } + void setStageNo(u32 stage) { + mStageNo = stage; + } RPSysScene::ETime getIslandTime() const { return mIslandTime; @@ -32,10 +52,14 @@ class StaticMem { private: char _04[0x14 - 0x4]; - u32 mGroupNo; // at 0x14 - u32 mSequenceNo; // at 0x18 - char _1C[0x380 - 0x1C]; + s32 mGroupNo; // at 0x14 + u32 mSequenceNo; // at 0x18 + u32 mStageNo; // at 0x1C + EPlayStyle mPlayStyle; // at 0x20 + EPlayTeam mPlayTeams[4]; // at 0x24 + char _34[0x380 - 0x34]; RPSysScene::ETime mIslandTime; // at 0x380 + // . . . }; } // namespace Cmn diff --git a/src/core/CosmeticMgr.cpp b/src/core/CosmeticMgr.cpp index 5e57bdf..ed207d8 100644 --- a/src/core/CosmeticMgr.cpp +++ b/src/core/CosmeticMgr.cpp @@ -56,7 +56,7 @@ void CosmeticMgr::Debug() { } kiwi::Shuffle(mRandomBgmMapping, K_LENGTHOF(mRandomBgmMapping)); - mRandomBgmFlag = true; + mRandomBgmFlag = false; } } // namespace AP diff --git a/src/scene/DebugRootScene/SeqSelectPage.cpp b/src/scene/DebugRootScene/SeqSelectPage.cpp index 9005604..2f077df 100644 --- a/src/scene/DebugRootScene/SeqSelectPage.cpp +++ b/src/scene/DebugRootScene/SeqSelectPage.cpp @@ -118,6 +118,7 @@ void SeqSelectPage::SetNextScene(s32 scene) { case kiwi::ESceneID_Sp2##S##Scene: { \ mGameMode.SetEnumValues(GameMode_Keys_##S); \ mGameMode.SetRange(0, LENGTHOF(GameMode_Keys_##S) - 1); \ + mGameMode.SetEnabled(LENGTHOF(GameMode_Keys_##S) != 1); \ break; \ } From bb3033c9240cacb8e1b0634229652ff686182a54 Mon Sep 17 00:00:00 2001 From: kiwi515 <49212064+kiwi515@users.noreply.github.com> Date: Sun, 25 May 2025 19:38:57 -0400 Subject: [PATCH 4/4] Implement stage option --- include/Sports2/Cmn/Sp2CmnConst.h | 4 +- src/scene/DebugRootScene/RootPage.cpp | 15 +- src/scene/DebugRootScene/RootPage.h | 12 ++ src/scene/DebugRootScene/SeqSelectPage.cpp | 235 +++++++++++++++------ src/scene/DebugRootScene/SeqSelectPage.h | 7 +- 5 files changed, 199 insertions(+), 74 deletions(-) diff --git a/include/Sports2/Cmn/Sp2CmnConst.h b/include/Sports2/Cmn/Sp2CmnConst.h index 9de9b84..804eb58 100644 --- a/include/Sports2/Cmn/Sp2CmnConst.h +++ b/include/Sports2/Cmn/Sp2CmnConst.h @@ -48,8 +48,8 @@ enum ESeq { ESeq_Bwl_100 = 3, //!< Bowling (100-Pin Game) ESeq_Bwl_Wal = 4, //!< Bowling (Spin Control) - ESeq_Can = 7, //!< Canoeing (Speed Challenge) - ESeq_Can_Vs = 8, //!< Canoeing (VS) + ESeq_Can = 8, //!< Canoeing (Speed Challenge) + ESeq_Can_Vs = 7, //!< Canoeing (VS) ESeq_Png_Ret = 2, //!< Table Tennis (Return Challenge) ESeq_Png = 5, //!< Table Tennis (Match) diff --git a/src/scene/DebugRootScene/RootPage.cpp b/src/scene/DebugRootScene/RootPage.cpp index 8a63092..b41aa06 100644 --- a/src/scene/DebugRootScene/RootPage.cpp +++ b/src/scene/DebugRootScene/RootPage.cpp @@ -12,10 +12,21 @@ namespace DebugRoot { */ RootPage::RootPage(kiwi::DebugMenu& rMenu) : kiwi::DebugPage(rMenu), - mSceneSelect(rMenu, "Scene Select", mSceneSelectPage), - mSceneSelectPage(rMenu) { + mSceneSelect(rMenu, "Scene Debug", mSceneSelectPage), + mSceneSelectPage(rMenu), + mItemDebug(rMenu, "Item Debug", *this), + mCheckDebug(rMenu, "Check Debug", *this), + mCosmeticDebug(rMenu, "Cosmetic Debug", *this) { mOptions.PushBack(&mSceneSelect); + mOptions.PushBack(&mItemDebug); + mOptions.PushBack(&mCheckDebug); + mOptions.PushBack(&mCosmeticDebug); + + // TODO: Not yet implemented + mItemDebug.SetEnabled(false); + mCheckDebug.SetEnabled(false); + mCosmeticDebug.SetEnabled(false); } } // namespace DebugRoot diff --git a/src/scene/DebugRootScene/RootPage.h b/src/scene/DebugRootScene/RootPage.h index a600f54..d88473d 100644 --- a/src/scene/DebugRootScene/RootPage.h +++ b/src/scene/DebugRootScene/RootPage.h @@ -24,6 +24,18 @@ class RootPage : public kiwi::DebugPage { //! Debug scene select kiwi::DebugOpenPageOption mSceneSelect; SceneSelectPage mSceneSelectPage; + + //! AP item debug + kiwi::DebugOpenPageOption mItemDebug; + // ItemDebugPage mItemDebugPage; + + //! AP check debug + kiwi::DebugOpenPageOption mCheckDebug; + // ItemDebugPage mItemDebugPage; + + //! AP cosmetic debug + kiwi::DebugOpenPageOption mCosmeticDebug; + // ItemDebugPage mItemDebugPage; }; } // namespace DebugRoot diff --git a/src/scene/DebugRootScene/SeqSelectPage.cpp b/src/scene/DebugRootScene/SeqSelectPage.cpp index 2f077df..cdaddb5 100644 --- a/src/scene/DebugRootScene/SeqSelectPage.cpp +++ b/src/scene/DebugRootScene/SeqSelectPage.cpp @@ -10,40 +10,87 @@ namespace AP { namespace DebugRoot { namespace { +// clang-format off + +// List of all scenes/sequences/stages +#define USE_GAME_DATA() \ + X(Swf, \ + Y(Swf_Vs, Z(Main)) \ + Y(Swf_Prc, Z(Main)) \ + Y(Swf_Sgl, Z(Bridge) Z(Lighthouse) Z(Beach) Z(Mountain) Z(Forest) \ + Z(Ruins) Z(Waterfall) Z(Cliffs) Z(Castle) Z(Volcano) \ + Z(BridgeR) Z(LighthouseR) Z(BeachR) Z(MountainR) Z(ForestR) \ + Z(RuinsR) Z(WaterfallR) Z(CliffsR) Z(CastleR) Z(VolcanoR))) \ + X(Jsk, \ + Y(Jsk_Rng, Z(Beach) Z(Lagoon) Z(Lighthouse) Z(Marina) Z(Cavern) Z(Shoals)) \ + Y(Jsk_Vs, Z(Beach) Z(Lagoon) Z(Lighthouse) Z(Marina) Z(Cavern) Z(Shoals))) \ + X(Arc, \ + Y(Arc, Z(Beginner) Z(Intermediate) Z(Expert))) \ + X(Fld, \ + Y(Fld, Z(Main))) \ + X(Bsk, \ + Y(Bsk_3pt, Z(Main)) \ + Y(Bsk_Vs, Z(Main))) \ + X(Bwl, \ + Y(Bwl_Std, Z(Main)) \ + Y(Bwl_100, Z(Main)) \ + Y(Bwl_Wal, Z(Main))) \ + X(Can, \ + Y(Can, Z(Beginner) Z(Intermediate) Z(Expert)) \ + Y(Can_Vs, Z(Main))) \ + X(Png, \ + Y(Png, Z(Main)) \ + Y(Png_Ret, Z(Main))) \ + X(Wkb, \ + Y(Wkb, Z(Beginner) Z(Intermediate) Z(Expert))) \ + X(Pln, \ + Y(Pln, Z(Daytime) Z(Evening) Z(Night)) \ + Y(Pln_Vs, Z(Main))) \ + X(Glf, \ + Y(Glf, Z(ResortA) Z(ResortB) Z(ResortC) Z(ClassicA) Z(ClassicB) Z(ClassicC) \ + Z(Special) Z(Resort9) Z(Classic9) Z(Eighteen))) \ + X(Dgl, \ + Y(Dgl, Z(ResortA) Z(ResortB) Z(ResortC) Z(ClassicA) Z(ClassicB) Z(ClassicC) \ + Z(Special) Z(Resort9) Z(Classic9) Z(Eighteen))) \ + X(Bic, \ + Y(Bic, Z(S01) Z(S02) Z(S03) Z(S04) Z(S05) Z(S06) Z(ThreeStage) Z(SixStage)) \ + Y(Bic_Vs, Z(S01) Z(S02) Z(S03) Z(S04) Z(S05) Z(S06))) \ + X(Omk, \ + Y(Omk, Z(Main))) + +// Generate gamemode keys +#define X(S, QT) namespace S { const char* GAMEMODE_KEYS[] = { QT }; } +#define Y(Q, T) #Q, +USE_GAME_DATA(); +#undef X +#undef Y -// Sequence list -#define ALL_SEQ() \ - X(Swf, Y(Swf_Vs) Y(Swf_Prc) Y(Swf_Sgl)) \ - X(Jsk, Y(Jsk_Rng) Y(Jsk_Vs)) \ - X(Arc, Y(Arc)) \ - X(Fld, Y(Fld)) \ - X(Bsk, Y(Bsk_3pt) Y(Bsk_Vs)) \ - X(Bwl, Y(Bwl_Std) Y(Bwl_100) Y(Bwl_Wal)) \ - X(Can, Y(Can) Y(Can_Vs)) \ - X(Png, Y(Png) Y(Png_Ret)) \ - X(Wkb, Y(Wkb)) \ - X(Pln, Y(Pln) Y(Pln_Vs)) \ - X(Glf, Y(Glf)) \ - X(Dgl, Y(Dgl)) \ - X(Bic, Y(Bic) Y(Bic_Vs)) \ - X(Omk, Y(Omk)) - -// Generate arrays of keys -#define X(S, Q) const char* GameMode_Keys_##S[] = {Q}; -#define Y(Z) #Z, -ALL_SEQ(); - +// Generate gamemode values +#define X(S, QT) namespace S { const Sp2::Cmn::ESeq GAMEMODE_VALUES[] = { QT }; } +#define Y(Q, T) Sp2::Cmn::ESeq_##Q, +USE_GAME_DATA(); #undef X #undef Y -// Generate arrays of values -#define X(S, Q) u32 GameMode_Values_##S[] = {Q}; -#define Y(Z) Sp2::Cmn::ESeq_##Z, -ALL_SEQ(); +// Generate stage keys +#define X(S, QT) QT +#define Y(Q, T) namespace Q { const char* STAGENO_KEYS[] = { T }; } +#define Z(T) #T, +USE_GAME_DATA(); +#undef X +#undef Y +#undef Z +// Generate stage values +#define X(S, QT) QT +#define Y(Q, T) namespace Q { enum STAGENO_ENUM { T }; const u32 STAGENO_VALUES[] = { T }; } +#define Z(T) T, +USE_GAME_DATA(); #undef X #undef Y +#undef Z +// clang-format on } // namespace /** @@ -58,12 +105,13 @@ SeqSelectPage::SeqSelectPage(kiwi::DebugMenu& rMenu) mExitTimer(0), mPlayerNum(rMenu, "PlayerNum", 1, kiwi::EPlayer_Max), mRemoteNum(rMenu, "RemoteNum", 1, kiwi::EPlayer_Max), - mGameMode(rMenu, "GameMode", GameMode_Keys_Swf, 0, - LENGTHOF(GameMode_Keys_Swf)), - mStageNo(rMenu, "StageNo", 0, 0) { + mGameMode(rMenu, "GameMode", Swf::GAMEMODE_KEYS, 0, + LENGTHOF(Swf::GAMEMODE_KEYS)), + mStageNo(rMenu, "StageNo", Swf_Vs::STAGENO_KEYS, 0, + LENGTHOF(Swf_Vs::STAGENO_KEYS)) { - mStateMachine.RegistState(EState_Select, &State_Select_calc); - mStateMachine.RegistState(EState_Decide, &State_Decide_calc); + mStateMachine.RegistState(EState_Select, &SeqSelectPage::State_Select_calc); + mStateMachine.RegistState(EState_Decide, &SeqSelectPage::State_Decide_calc); mOptions.PushBack(&mPlayerNum); mOptions.PushBack(&mRemoteNum); @@ -71,6 +119,18 @@ SeqSelectPage::SeqSelectPage(kiwi::DebugMenu& rMenu) mOptions.PushBack(&mStageNo); } +/** + * @brief Sets the next scene ID + * + * @param scene Scene ID + */ +void SeqSelectPage::SetNextScene(s32 scene) { + ASSERT(scene >= 0); + mNextScene = scene; + + CalcOption(); +} + /** * @brief User-level render pass */ @@ -92,46 +152,15 @@ void SeqSelectPage::UserDraw() { .SetScale(1.2); } -/** - * @brief Sets the next scene ID - * - * @param scene Scene ID - */ -void SeqSelectPage::SetNextScene(s32 scene) { - ASSERT(scene >= 0); - mNextScene = scene; - - mGameMode.SetEnabled(true); - mStageNo.SetEnabled(true); - - switch (mNextScene) { - case kiwi::ESceneID_Sp2TitleScene: - case kiwi::ESceneID_Sp2MiiSelectScene: { - mGameMode.SetEnabled(false); - mStageNo.SetEnabled(false); - break; - } - } - -#define X(S, Q) Y(S) -#define Y(S) \ - case kiwi::ESceneID_Sp2##S##Scene: { \ - mGameMode.SetEnumValues(GameMode_Keys_##S); \ - mGameMode.SetRange(0, LENGTHOF(GameMode_Keys_##S) - 1); \ - mGameMode.SetEnabled(LENGTHOF(GameMode_Keys_##S) != 1); \ - break; \ - } - - switch (mNextScene) { ALL_SEQ(); } -#undef X -#undef Y -} - /** * @brief Scene select ('Select' state) * @return Result of actions */ kiwi::EDebugMenuResult SeqSelectPage::State_Select_calc() { + ASSERT(mNextScene >= 0); + + CalcOption(); + for (int i = 0; i < kiwi::EPlayer_Max; i++) { const kiwi::WiiCtrl& rCtrl = kiwi::CtrlMgr::GetInstance().GetWiiCtrl(i); @@ -168,20 +197,87 @@ kiwi::EDebugMenuResult SeqSelectPage::State_Decide_calc() { return kiwi::EDebugMenuResult_None; } +/** + * @brief Updates the option ranges + */ +void SeqSelectPage::CalcOption() { + mGameMode.SetEnabled(true); + mStageNo.SetEnabled(true); + + switch (mNextScene) { + case kiwi::ESceneID_Sp2TitleScene: + case kiwi::ESceneID_Sp2MiiSelectScene: { + mGameMode.SetEnabled(false); + mStageNo.SetEnabled(false); + break; + } + } + + // Setup GameMode option by the selected scene +#define X(S, QT) \ + case kiwi::ESceneID_Sp2##S##Scene: { \ + mGameMode.SetEnumValues(S::GAMEMODE_KEYS); \ + mGameMode.SetRange(0, LENGTHOF(S::GAMEMODE_KEYS) - 1); \ + mGameMode.SetEnabled(LENGTHOF(S::GAMEMODE_KEYS) > 1); \ + break; \ + } + + switch (mNextScene) { USE_GAME_DATA(); } +#undef X + + // Setup StageNo option by the selected sequence +#define X(S, QT) \ + case kiwi::ESceneID_Sp2##S##Scene: { \ + switch (S::GAMEMODE_VALUES[mGameMode.GetValue()]) { QT } \ + break; \ + } + +#define Y(Q, T) \ + case Sp2::Cmn::ESeq_##Q: { \ + mStageNo.SetEnumValues(Q::STAGENO_KEYS); \ + mStageNo.SetRange(0, LENGTHOF(Q::STAGENO_KEYS) - 1); \ + mStageNo.SetEnabled(LENGTHOF(Q::STAGENO_KEYS) > 1); \ + break; \ + } + + switch (mNextScene) { USE_GAME_DATA(); } +#undef X +#undef Y +} + /** * @brief Sets up the global state and changes to the next scene */ void SeqSelectPage::SetupGame() { u32 group = kiwi::SceneCreator::GetInstance().GetSceneGroup(mNextScene); u32 seq = 0; + u32 stage = 0; -#define X(S, Q) Y(S) + // Get sequence value from the GameMode option +#define X(S, QT) Y(S) #define Y(S) \ case kiwi::ESceneID_Sp2##S##Scene: { \ - seq = GameMode_Values_##S[mGameMode.GetValue()]; \ + seq = S::GAMEMODE_VALUES[mGameMode.GetValue()]; \ break; \ } - switch (mNextScene) { ALL_SEQ(); } + switch (mNextScene) { USE_GAME_DATA(); } +#undef X +#undef Y + + // Get stage value from the StageNo option +#define X(S, QT) \ + case kiwi::ESceneID_Sp2##S##Scene: { \ + switch (S::GAMEMODE_VALUES[mGameMode.GetValue()]) { QT } \ + break; \ + } + +#define Y(Q, T) \ + case Sp2::Cmn::ESeq_##Q: { \ + stage = Q::STAGENO_VALUES[mStageNo.GetValue()]; \ + break; \ + } + + switch (mNextScene) { USE_GAME_DATA(); } #undef X #undef Y @@ -191,6 +287,7 @@ void SeqSelectPage::SetupGame() { RP_GET_INSTANCE(Sp2::Cmn::StaticMem)->setSceneGroup(group); RP_GET_INSTANCE(Sp2::Cmn::StaticMem)->setSceneSeq(seq); + RP_GET_INSTANCE(Sp2::Cmn::StaticMem)->setStageNo(stage); kiwi::SceneCreator::GetInstance().ChangeSceneAfterFade(mNextScene); } diff --git a/src/scene/DebugRootScene/SeqSelectPage.h b/src/scene/DebugRootScene/SeqSelectPage.h index bd4c0d6..70c57ed 100644 --- a/src/scene/DebugRootScene/SeqSelectPage.h +++ b/src/scene/DebugRootScene/SeqSelectPage.h @@ -49,6 +49,11 @@ class SeqSelectPage : public kiwi::DebugPage { K_STATE_DECL_EX(kiwi::EDebugMenuResult, Decide); private: + /** + * @brief Updates the option ranges + */ + void CalcOption(); + /** * @brief Sets up the global state and changes to the next scene */ @@ -71,7 +76,7 @@ class SeqSelectPage : public kiwi::DebugPage { //! Game mode kiwi::DebugEnumOption mGameMode; //! Game stage - kiwi::DebugIntOption mStageNo; + kiwi::DebugEnumOption mStageNo; }; } // namespace DebugRoot