Skip to content

Commit

Permalink
Allow app and ingame menu to be navigated with the Circle Pad (#628)
Browse files Browse the repository at this point in the history
Co-authored-by: HylianFreddy <[email protected]>

Co-authored-by: HylianFreddy <[email protected]>
  • Loading branch information
Kewlan and HylianFreddy authored Jan 19, 2023
1 parent 33ecc08 commit ddfda21
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
4 changes: 4 additions & 0 deletions code/include/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,9 @@ typedef struct {
#define BUTTON_L1 (1 << 9)
#define BUTTON_X (1 << 10)
#define BUTTON_Y (1 << 11)
#define CPAD_RIGHT (1 << 28)
#define CPAD_LEFT (1 << 29)
#define CPAD_UP (1 << 30)
#define CPAD_DOWN (1 << 31)

#endif // HID_H
40 changes: 20 additions & 20 deletions code/src/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,26 +859,26 @@ static void Gfx_ShowMenu(void) {
} else if (curMenuIdx == PAGE_SPHERES && gSpoilerData.SphereCount > 0) {
// Spoiler log
u16 itemCount = gSpoilerData.Spheres[currentSphere].ItemCount;
if (pressed & BUTTON_LEFT) {
if (pressed & (BUTTON_LEFT | CPAD_LEFT)) {
if (currentSphere == 0) {
currentSphere = gSpoilerData.SphereCount - 1;
} else {
currentSphere--;
}
spoilerScroll = 0;
handledInput = true;
} else if (pressed & BUTTON_RIGHT) {
} else if (pressed & (BUTTON_RIGHT | CPAD_RIGHT)) {
if (currentSphere < gSpoilerData.SphereCount - 1) {
currentSphere++;
} else {
currentSphere = 0;
}
spoilerScroll = 0;
handledInput = true;
} else if (pressed & BUTTON_UP) {
} else if (pressed & (BUTTON_UP | CPAD_UP)) {
spoilerScroll = Gfx_Scroll(spoilerScroll, -1, itemCount);
handledInput = true;
} else if (pressed & BUTTON_DOWN) {
} else if (pressed & (BUTTON_DOWN | CPAD_DOWN)) {
spoilerScroll = Gfx_Scroll(spoilerScroll, 1, itemCount);
handledInput = true;
}
Expand All @@ -889,33 +889,33 @@ static void Gfx_ShowMenu(void) {
handledInput = true;
} else if (!showingLegend) {
u16 itemCount = gSpoilerData.ItemLocationsCount;
if (pressed & BUTTON_LEFT) {
if (pressed & (BUTTON_LEFT | CPAD_LEFT)) {
allItemsScroll = Gfx_Scroll(allItemsScroll, -MAX_ENTRY_LINES * 10, itemCount);
handledInput = true;
} else if (pressed & BUTTON_RIGHT) {
} else if (pressed & (BUTTON_RIGHT | CPAD_RIGHT)) {
allItemsScroll = Gfx_Scroll(allItemsScroll, MAX_ENTRY_LINES * 10, itemCount);
handledInput = true;
} else if (pressed & BUTTON_UP) {
} else if (pressed & (BUTTON_UP | CPAD_UP)) {
allItemsScroll = Gfx_Scroll(allItemsScroll, -MAX_ENTRY_LINES, itemCount);
handledInput = true;
} else if (pressed & BUTTON_DOWN) {
} else if (pressed & (BUTTON_DOWN | CPAD_DOWN)) {
allItemsScroll = Gfx_Scroll(allItemsScroll, MAX_ENTRY_LINES, itemCount);
handledInput = true;
}
}
} else if (curMenuIdx == PAGE_ITEMTRACKER_GROUPS && gSpoilerData.ItemLocationsCount > 0) {
// Grouped Items list
u16 itemCount = gSpoilerData.GroupItemCounts[currentItemGroup];
if (pressed & BUTTON_LEFT) {
if (pressed & (BUTTON_LEFT | CPAD_LEFT)) {
groupItemsScroll = Gfx_Scroll(groupItemsScroll, -MAX_ENTRY_LINES, itemCount);
handledInput = true;
} else if (pressed & BUTTON_RIGHT) {
} else if (pressed & (BUTTON_RIGHT | CPAD_RIGHT)) {
groupItemsScroll = Gfx_Scroll(groupItemsScroll, MAX_ENTRY_LINES, itemCount);
handledInput = true;
} else if (pressed & BUTTON_UP) {
} else if (pressed & (BUTTON_UP | CPAD_UP)) {
groupItemsScroll = Gfx_Scroll(groupItemsScroll, -1, itemCount);
handledInput = true;
} else if (pressed & BUTTON_DOWN) {
} else if (pressed & (BUTTON_DOWN | CPAD_DOWN)) {
groupItemsScroll = Gfx_Scroll(groupItemsScroll, 1, itemCount);
handledInput = true;
} else if (pressed & BUTTON_A) {
Expand All @@ -932,16 +932,16 @@ static void Gfx_ShowMenu(void) {
handledInput = true;
} else if (!showingLegend) {
u16 entranceCount = gEntranceTrackingData.EntranceCount;
if (pressed & BUTTON_DOWN) {
if (pressed & (BUTTON_DOWN | CPAD_DOWN)) {
allEntranceScroll = Gfx_Scroll(allEntranceScroll, MAX_ENTRY_LINES, entranceCount);
handledInput = true;
} else if (pressed & BUTTON_UP) {
} else if (pressed & (BUTTON_UP | CPAD_UP)) {
allEntranceScroll = Gfx_Scroll(allEntranceScroll, -MAX_ENTRY_LINES, entranceCount);
handledInput = true;
} else if (pressed & BUTTON_RIGHT) {
} else if (pressed & (BUTTON_RIGHT | CPAD_RIGHT)) {
allEntranceScroll = Gfx_Scroll(allEntranceScroll, MAX_ENTRY_LINES * 10, entranceCount);
handledInput = true;
} else if (pressed & BUTTON_LEFT) {
} else if (pressed & (BUTTON_LEFT | CPAD_LEFT)) {
allEntranceScroll = Gfx_Scroll(allEntranceScroll, -MAX_ENTRY_LINES * 10, entranceCount);
handledInput = true;
} else if (pressed & BUTTON_X) {
Expand All @@ -952,16 +952,16 @@ static void Gfx_ShowMenu(void) {
} else if (curMenuIdx == PAGE_ENTRANCETRACKER_GROUPS && gEntranceTrackingData.EntranceCount > 0) {
// Grouped Entrances list
u16 entranceCount = gEntranceTrackingData.GroupEntranceCounts[destListToggle][currentEntranceGroup];
if (pressed & BUTTON_DOWN) {
if (pressed & (BUTTON_DOWN | CPAD_DOWN)) {
groupEntranceScroll = Gfx_Scroll(groupEntranceScroll, 1, entranceCount);
handledInput = true;
} else if (pressed & BUTTON_UP) {
} else if (pressed & (BUTTON_UP | CPAD_UP)) {
groupEntranceScroll = Gfx_Scroll(groupEntranceScroll, -1, entranceCount);
handledInput = true;
} else if (pressed & BUTTON_RIGHT) {
} else if (pressed & (BUTTON_RIGHT | CPAD_RIGHT)) {
groupEntranceScroll = Gfx_Scroll(groupEntranceScroll, MAX_ENTRY_LINES, entranceCount);
handledInput = true;
} else if (pressed & BUTTON_LEFT) {
} else if (pressed & (BUTTON_LEFT | CPAD_LEFT)) {
groupEntranceScroll = Gfx_Scroll(groupEntranceScroll, -MAX_ENTRY_LINES, entranceCount);
handledInput = true;
} else if (pressed & BUTTON_A) {
Expand Down
8 changes: 4 additions & 4 deletions code/src/gfx_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ void PrevOption(const Option* option) {
}

void Gfx_OptionsUpdate(void) {
if (pressed & BUTTON_DOWN) {
if (pressed & (BUTTON_DOWN | CPAD_DOWN)) {
do {
selectedOption++;
if (selectedOption > ARRAY_SIZE(options) - 1) {
selectedOption = 0;
}
} while (strlen(options[selectedOption].name) == 0);
handledInput = true;
} else if (pressed & BUTTON_UP) {
} else if (pressed & (BUTTON_UP | CPAD_UP)) {
do {
selectedOption--;
if (selectedOption < 0) {
Expand All @@ -127,10 +127,10 @@ void Gfx_OptionsUpdate(void) {
handledInput = true;
}

if (pressed & BUTTON_RIGHT) {
if (pressed & (BUTTON_RIGHT | CPAD_RIGHT)) {
NextOption(&options[selectedOption]);
handledInput = true;
} else if (pressed & BUTTON_LEFT) {
} else if (pressed & (BUTTON_LEFT | CPAD_LEFT)) {
PrevOption(&options[selectedOption]);
handledInput = true;
}
Expand Down
6 changes: 1 addition & 5 deletions code/src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
#include "3ds/svc.h"
#include "utils.h"

u32 GetCurrentPadState(void) {
u32 hid_shared_mem = *(u32*)(0x005AEC5C);
return *(volatile u32*)(hid_shared_mem + 0x1C);
}
#define HID_PAD (GetCurrentPadState())
#define HID_PAD (real_hid.pad.pads[real_hid.pad.index].curr.val)

InputContext rInputCtx;

Expand Down
4 changes: 2 additions & 2 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ int main() {

// Time calculations for menu scrolling
bool updatedByHeld = false;
if (kHeld & KEY_DDOWN || kHeld & KEY_DUP || kHeld & KEY_DLEFT || kHeld & KEY_DRIGHT) {
if (kHeld & KEY_DOWN || kHeld & KEY_UP || kHeld & KEY_LEFT || kHeld & KEY_RIGHT) {
float totalHoldTime = (svcGetSystemTick() - initialHoldTime) / TICKS_PER_SEC;
float intervalElapsedTime = (svcGetSystemTick() - intervalTime) / TICKS_PER_SEC;

if (intervalElapsedTime > 0.09 && totalHoldTime > 0.4) {
kDown |= kHeld & (KEY_DUP | KEY_DDOWN | KEY_DLEFT | KEY_DRIGHT); // add input to kDown for simplicity
kDown |= kHeld & (KEY_UP | KEY_DOWN | KEY_LEFT | KEY_RIGHT); // add input to kDown for simplicity
intervalTime = svcGetSystemTick();
updatedByHeld = true;
}
Expand Down
20 changes: 10 additions & 10 deletions source/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void MoveCursor(u32 kDown, bool updatedByHeld) {
// Cancel if holding and reached first/last selectable option
if (updatedByHeld) {
bool noSelectableOption = true;
if (kDown & KEY_DUP) {
if (kDown & KEY_UP) {
for (int i = currentMenu->menuIdx - 1; i >= 0; i--) {
if (!currentMenu->settingsList->at(i)->IsHidden() &&
!currentMenu->settingsList->at(i)->IsLocked()) {
Expand All @@ -90,7 +90,7 @@ void MoveCursor(u32 kDown, bool updatedByHeld) {
}
}
}
if (kDown & KEY_DDOWN) {
if (kDown & KEY_DOWN) {
for (size_t i = currentMenu->menuIdx + 1; i < currentMenu->settingsList->size(); i++) {
if (!currentMenu->settingsList->at(i)->IsHidden() &&
!currentMenu->settingsList->at(i)->IsLocked()) {
Expand All @@ -105,10 +105,10 @@ void MoveCursor(u32 kDown, bool updatedByHeld) {
}
// Loop through settings until an unlocked one is reached
do {
if ((kDown & KEY_DUP) != 0) {
if ((kDown & KEY_UP) != 0) {
currentMenu->menuIdx--;
}
if ((kDown & KEY_DDOWN) != 0) {
if ((kDown & KEY_DOWN) != 0) {
currentMenu->menuIdx++;
}

Expand Down Expand Up @@ -138,16 +138,16 @@ void MoveCursor(u32 kDown, bool updatedByHeld) {

// Cancel if holding and reached first/last menu
if (updatedByHeld) {
if ((kDown & KEY_DUP && currentMenu->menuIdx == 0) ||
(kDown & KEY_DDOWN && currentMenu->menuIdx == max - 1)) {
if ((kDown & KEY_UP && currentMenu->menuIdx == 0) ||
(kDown & KEY_DOWN && currentMenu->menuIdx == max - 1)) {
return;
}
}

if (kDown & KEY_DUP) {
if (kDown & KEY_UP) {
currentMenu->menuIdx--;
}
if (kDown & KEY_DDOWN) {
if (kDown & KEY_DOWN) {
currentMenu->menuIdx++;
}

Expand Down Expand Up @@ -309,10 +309,10 @@ void UpdateCustomCosmeticColors(u32 kDown) {
}

void UpdateOptionSubMenu(u32 kDown) {
if ((kDown & KEY_DRIGHT) != 0) {
if ((kDown & KEY_RIGHT) != 0) {
currentSetting->NextOptionIndex();
}
if ((kDown & KEY_DLEFT) != 0) {
if ((kDown & KEY_LEFT) != 0) {
currentSetting->PrevOptionIndex();
}

Expand Down
8 changes: 4 additions & 4 deletions source/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2074,9 +2074,9 @@ void ForceChange(u32 kDown, Option* currentSetting) {
// than the number of dungeons set to MQ plus the number of dungeons set to random
u8 MQ = DungeonsOfType(1), R = DungeonsOfType(2);
if (MQDungeonCount.Value<u8>() < MQ) {
MQDungeonCount.SetSelectedIndex((currentSetting == &MQDungeonCount && (kDown & KEY_DLEFT)) ? 13 : MQ);
MQDungeonCount.SetSelectedIndex((currentSetting == &MQDungeonCount && (kDown & KEY_LEFT)) ? 13 : MQ);
} else if (MQDungeonCount.Value<u8>() != 13 && MQDungeonCount.Value<u8>() > MQ + R) {
MQDungeonCount.SetSelectedIndex((currentSetting == &MQDungeonCount && (kDown & KEY_DRIGHT)) ? 13 : MQ + R);
MQDungeonCount.SetSelectedIndex((currentSetting == &MQDungeonCount && (kDown & KEY_RIGHT)) ? 13 : MQ + R);
}
} else {
for (Option* option : dungeonOptions) {
Expand Down Expand Up @@ -2198,7 +2198,7 @@ void ForceChange(u32 kDown, Option* currentSetting) {
}

if (currentSetting != nullptr) {
if ((kDown & KEY_DLEFT || kDown & KEY_DRIGHT) && currentSetting == &ToggleAllTricks) {
if ((kDown & KEY_LEFT || kDown & KEY_RIGHT) && currentSetting == &ToggleAllTricks) {
for (u16 i = 1; i < Settings::trickOptions.size(); i++) {
trickOptions[i]->SetSelectedIndex(0);
}
Expand Down Expand Up @@ -2300,7 +2300,7 @@ void ForceChange(u32 kDown, Option* currentSetting) {
}
}

if ((kDown & KEY_DLEFT || kDown & KEY_DRIGHT) && currentSetting == &ToggleAllGlitches) {
if ((kDown & KEY_LEFT || kDown & KEY_RIGHT) && currentSetting == &ToggleAllGlitches) {
auto setDifficulty = ToggleAllGlitches.GetSelectedOptionIndex();
for (auto option : glitchCategories) {
if (option == &ToggleAllGlitches || (!RestoreISG && (option == &GlitchISG || option == &GlitchHover))) {
Expand Down

0 comments on commit ddfda21

Please sign in to comment.