Skip to content

Commit f9aac26

Browse files
committed
initial menu rework part 1
1 parent 6b63037 commit f9aac26

8 files changed

Lines changed: 181 additions & 204 deletions

File tree

include/common.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <types.h>
4+
5+
typedef void (*GZAction)(u32 params);

include/gz_commands.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
#pragma once
22

3+
#include "common.hpp"
34
#include "gz_controls.hpp"
45
#include "gz_menu.hpp"
56

67
#include <nitro/math.h>
78

89
typedef void (*GZCmdInit)(void);
9-
typedef void (*GZCmdAction)(void);
1010

1111
struct GZCmdItem {
1212
ButtonCombo btnCombo;
13-
GZCmdAction actionCallback;
13+
GZAction actionCallback;
1414
};
1515

1616
class GZCommandManager {
1717
public:
1818
Input* mpButtons;
1919
GZCmdItem* mpCommands;
20+
GZMenu mMenu;
2021

2122
GZCommandManager();
2223

24+
void CreateMenuItems();
2325
void Update();
2426
void Draw(Vec2b* pPos);
2527
};

include/gz_menu.hpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "common.hpp"
34
#include "gz_controls.hpp"
45

56
#include <Item/ItemManager.hpp>
@@ -8,7 +9,8 @@
89
#include <nitro/math.h>
910
#include <types.h>
1011

11-
typedef void (*GZMenuAction)(u32 params);
12+
#define DRAW_TO_TOP_SCREEN 1
13+
1214
struct GZMenu;
1315

1416
typedef enum InventoryAmountType {
@@ -24,18 +26,18 @@ typedef enum InventoryAmountType {
2426
} InventoryAmountType;
2527

2628
struct GZMenuItem {
27-
const char* mName; // menu item name
28-
GZMenuAction mActionCallback; // associated action
29-
u32 params; // parameters for the action callback
30-
GZMenu* mSubMenu; // tied submenu
31-
bool needSaveFile; // does it require the save data
32-
s32 value; // misc value for internal use
29+
const char* name;
30+
GZAction action;
31+
u32 params;
32+
GZMenu* submenu;
33+
int value;
3334
};
3435

3536
struct GZMenu {
36-
GZMenuItem* mpItems;
37+
GZMenuItem* entries;
3738
s32 mCount;
38-
GZMenu* mPrev;
39+
bool needSaveFile;
40+
s16 itemIndex;
3941
};
4042

4143
struct GZMenuState {
@@ -78,6 +80,7 @@ class GZMenuManager {
7880
public:
7981
GZMenuState mState;
8082
GZMenu* mpActiveMenu;
83+
GZMenu* mpPrevMenu;
8184
GZMenuControls mControls;
8285
Input* mpButtons;
8386

@@ -90,7 +93,7 @@ class GZMenuManager {
9093
this->mState.isOpened = false;
9194
}
9295

93-
GZMenuItem* GetActiveMenuItem() { return &this->mpActiveMenu->mpItems[this->mState.itemIndex]; }
96+
GZMenuItem* GetActiveMenuItem() { return &this->mpActiveMenu->entries[this->mState.itemIndex]; }
9497

9598
bool IsInventoryMenuActive();
9699
bool IsAmountsMenuActive();

include/gz_settings.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ extern "C" void func_02030d58(u16 lockID); // CARD_UnlockBackup
1616
#define MAX_POS_SLOTS 8
1717
#define MAX_SAVE_PROFILES 8
1818

19-
//! TODO: make it one setting set per save file
20-
2119
extern "C" {
2220
typedef struct GZProfileHeader {
2321
u8 curProfileIndex;
2422
} GZProfileHeader __attribute__((aligned(32)));
2523

2624
// the save file is large so we don't care about packing stuff to save space
2725
typedef struct GZProfile {
28-
u8 profileIndex;
2926
bool mFasterTitleScreen; // goes into the "touch or start to exit" state immediately
3027
bool mSkipTitleScreen; // same as above except it jump straight into the file select without requiring any input
3128
s8 mPositionIndex;

src/gz_commands.cpp

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
extern "C" void DisplayDebugText(int, void*, int, int, const char*);
1313
extern "C" void DisplayDebugTextF(int, void*, int, int, const char*, ...);
1414

15-
static void ExecuteLevitate();
16-
static void ExecutePause();
17-
static void ExecuteFrameAdvance();
18-
static void ExecutePrevPosition();
19-
static void ExecuteNextPosition();
20-
static void ExecuteSavePosition();
21-
static void ExecuteLoadPosition();
22-
static void ExecuteVoidOut();
23-
static void ExecuteTurbo();
24-
25-
// commands with default button combos
15+
static void ExecuteLevitate(u32 params);
16+
static void ExecutePause(u32 params);
17+
static void ExecuteFrameAdvance(u32 params);
18+
static void ExecutePrevPosition(u32 params);
19+
static void ExecuteNextPosition(u32 params);
20+
static void ExecuteSavePosition(u32 params);
21+
static void ExecuteLoadPosition(u32 params);
22+
static void ExecuteVoidOut(u32 params);
23+
static void ExecuteTurbo(u32 params);
24+
25+
// commands with default button combos, assigning the held btn to none means it's not required (and vice versa)
2626
static GZCmdItem sCommands[] = {
2727
{ButtonCombo("Levitate", BTN_X, BTN_NONE), ExecuteLevitate},
2828
{ButtonCombo("Pause/Unpause", BTN_NONE, BTN_DDOWN), ExecutePause},
@@ -35,19 +35,19 @@ static GZCmdItem sCommands[] = {
3535
{ButtonCombo("Turbo", BTN_R, BTN_B), ExecuteTurbo},
3636
};
3737

38-
static void ExecuteLevitate() { data_027e0478.mPlayer.mVel.y = FLOAT_TO_Q20(0.334375f); }
38+
static void ExecuteLevitate(u32 params) { data_027e0478.mPlayer.mVel.y = FLOAT_TO_Q20(0.334375f); }
3939

40-
static void ExecutePause() {
40+
static void ExecutePause(u32 params) {
4141
if (!gGZ.mState.isPaused) {
4242
gGZ.mState.isPaused = true;
4343
} else {
4444
gGZ.mState.isPaused = false;
4545
}
4646
}
4747

48-
static void ExecuteFrameAdvance() { gGZ.mState.requestedFrames++; }
48+
static void ExecuteFrameAdvance(u32 params) { gGZ.mState.requestedFrames++; }
4949

50-
static void ExecutePrevPosition() {
50+
static void ExecutePrevPosition(u32 params) {
5151
GZProfile* pProfile = gSettings.GetProfile();
5252

5353
pProfile->mPositionIndex--;
@@ -57,7 +57,7 @@ static void ExecutePrevPosition() {
5757
}
5858
}
5959

60-
static void ExecuteNextPosition() {
60+
static void ExecuteNextPosition(u32 params) {
6161
GZProfile* pProfile = gSettings.GetProfile();
6262

6363
pProfile->mPositionIndex++;
@@ -67,31 +67,42 @@ static void ExecuteNextPosition() {
6767
}
6868
}
6969

70-
static void ExecuteSavePosition() {
70+
static void ExecuteSavePosition(u32 params) {
7171
GZProfile* pProfile = gSettings.GetProfile();
7272
Vec3p* pPosArray = gSettings.GetPosArray();
7373
pPosArray[pProfile->mPositionIndex] = data_027e0478.mPlayer.mPos;
7474
}
7575

76-
static void ExecuteLoadPosition() {
76+
static void ExecuteLoadPosition(u32 params) {
7777
GZProfile* pProfile = gSettings.GetProfile();
7878
Vec3p* pPosArray = gSettings.GetPosArray();
7979
data_027e0478.mPlayer.mPos = pPosArray[pProfile->mPositionIndex];
8080
}
8181

82-
static void ExecuteVoidOut() {
82+
static void ExecuteVoidOut(u32 params) {
8383
if (gGZ.IsOnLand()) {
8484
data_027e0478.mPlayer.mPos.y = FLOAT_TO_Q20(-4000.0f);
8585
}
8686
}
8787

88-
static void ExecuteTurbo() {}
88+
static void ExecuteTurbo(u32 params) {}
8989

9090
GZCommandManager gCommandManager;
9191

9292
GZCommandManager::GZCommandManager() {
9393
this->mpButtons = &gGZ.mButtons;
9494
this->mpCommands = sCommands;
95+
this->CreateMenuItems();
96+
}
97+
98+
void GZCommandManager::CreateMenuItems() {
99+
this->mMenu.entries = new GZMenuItem[ARRAY_LEN(sCommands)];
100+
101+
for (int i = 0; i < ARRAY_LEN(sCommands); i++) {
102+
this->mMenu.entries[i].name = sCommands[i].btnCombo.name;
103+
this->mMenu.entries[i].action = sCommands[i].actionCallback;
104+
this->mMenu.entries[i].submenu = NULL;
105+
}
95106
}
96107

97108
void GZCommandManager::Update() {
@@ -104,7 +115,7 @@ void GZCommandManager::Update() {
104115

105116
if (pCmd->btnCombo.Executed(this->mpButtons)) {
106117
if (pCmd->actionCallback != NULL) {
107-
pCmd->actionCallback();
118+
pCmd->actionCallback(0);
108119
}
109120
}
110121
}
@@ -118,7 +129,7 @@ void GZCommandManager::Draw(Vec2b* pPos) {
118129
bool selected = i + 1 == gMenuManager.mState.itemIndex;
119130

120131
pCmd->btnCombo.SetComboString();
121-
DisplayDebugText(0, &elemPos, 0, selected, pCmd->btnCombo.fullName);
132+
DisplayDebugText(DRAW_TO_TOP_SCREEN, &elemPos, 0, selected, pCmd->btnCombo.fullName);
122133
elemPos.y++;
123134
}
124135
}

src/gz_game.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,7 @@ void CustomGame::Run() {
6262

6363
do {
6464
gGZ.Update();
65-
66-
{
67-
gMenuManager.Update();
68-
69-
if (gMenuManager.IsActive()) {
70-
gMenuManager.Draw();
71-
}
72-
}
65+
gMenuManager.Update();
7366

7467
// stgz: pause and frame advance block
7568
{

0 commit comments

Comments
 (0)