Skip to content

Commit

Permalink
Merge pull request #7 from jdgleaver/menu-toggle-combo
Browse files Browse the repository at this point in the history
(GCW0/RS90) Enable configuration of the button combo used to toggle the menu
  • Loading branch information
jdgleaver authored Mar 8, 2022
2 parents 511dc07 + c2d1f84 commit 4396f9e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
13 changes: 9 additions & 4 deletions source/opendingux/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,12 @@ static struct MenuEntry HotkeyMenu_FastForward = {
ENTRY_OPTIONAL_HOTKEY
};

#if !defined GCW_ZERO
#if (defined(GCW_ZERO) || defined(RS90))
static struct MenuEntry HotkeyMenu_MenuToggleCombo = {
ENTRY_OPTION("menu_toggle_combo", "Menu", &MenuToggleCombo),
.ChoiceCount = 4, .Choices = { { "Power/Start+Select", "power_or_start_select" }, { "Power/L3+R3", "power_or_l3_r3" }, { "Power", "power" }, { "Start+Select", "start_select" } }
};
#else
static struct MenuEntry HotkeyMenu_Menu = {
ENTRY_OPTION("hotkey_menu", "Menu", &Hotkeys[1]),
ENTRY_MANDATORY_HOTKEY
Expand Down Expand Up @@ -1476,10 +1481,10 @@ static struct Menu HotkeyMenu = {
.Parent = &MainMenu, .Title = "Hotkeys",
.AlternateVersion = &PerGameHotkeyMenu,
.Entries = {
#if !defined GCW_ZERO
&HotkeyMenu_Menu,
#if (defined(GCW_ZERO) || defined(RS90))
&HotkeyMenu_MenuToggleCombo,
#else
&Strut,
&HotkeyMenu_Menu,
#endif
&HotkeyMenu_FastForward, &HotkeyMenu_FastForwardToggle, &HotkeyMenu_QuickLoadState, &HotkeyMenu_QuickSaveState, NULL
}
Expand Down
41 changes: 35 additions & 6 deletions source/opendingux/od-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ enum OpenDingux_Buttons Hotkeys[5] = {
0, // Quick save state #1
};

#if (defined(GCW_ZERO) || defined(RS90))
uint32_t MenuToggleCombo = 0;
#endif

// The menu keys, in decreasing order of priority when two or more are
// pressed. For example, when the user keeps a direction pressed but also
// presses A, start ignoring the direction.
Expand Down Expand Up @@ -362,6 +366,7 @@ enum ReGBA_Buttons ReGBA_GetPressedButtons()
{
uint_fast8_t i;
enum ReGBA_Buttons Result = 0;
bool toggle_menu = false;

UpdateOpenDinguxButtons();

Expand Down Expand Up @@ -389,18 +394,42 @@ enum ReGBA_Buttons ReGBA_GetPressedButtons()
if ((Result & REGBA_BUTTON_UP) && (Result & REGBA_BUTTON_DOWN))
Result &= ~REGBA_BUTTON_UP;

if (
#if defined(GCW_ZERO) || defined(RS90)
// Unified emulator menu buttons: Start+Select
((LastButtons & (OPENDINGUX_BUTTON_START | OPENDINGUX_BUTTON_SELECT)) == (OPENDINGUX_BUTTON_START | OPENDINGUX_BUTTON_SELECT))
#if (defined(GCW_ZERO) || defined(RS90))
switch (MenuToggleCombo)
{
case MENU_TOGGLE_POWER_OR_L3_R3:
if ((LastButtons & OPENDINGUX_BUTTON_MENU) ||
((LastButtons & (OPENDINGUX_BUTTON_L3 | OPENDINGUX_BUTTON_R3)) ==
(OPENDINGUX_BUTTON_L3 | OPENDINGUX_BUTTON_R3)))
toggle_menu = true;
case MENU_TOGGLE_POWER:
if (LastButtons & OPENDINGUX_BUTTON_MENU)
toggle_menu = true;
break;
case MENU_TOGGLE_START_SELECT:
if ((LastButtons & (OPENDINGUX_BUTTON_START | OPENDINGUX_BUTTON_SELECT)) ==
(OPENDINGUX_BUTTON_START | OPENDINGUX_BUTTON_SELECT))
toggle_menu = true;
break;
case MENU_TOGGLE_POWER_OR_START_SELECT:
default:
if ((LastButtons & OPENDINGUX_BUTTON_MENU) ||
((LastButtons & (OPENDINGUX_BUTTON_START | OPENDINGUX_BUTTON_SELECT)) ==
(OPENDINGUX_BUTTON_START | OPENDINGUX_BUTTON_SELECT)))
toggle_menu = true;
break;
}
#else
// The ReGBA Menu key should be pressed if ONLY the hotkey bound to it
// is pressed on the native device.
// This is not in ProcessSpecialKeys because REGBA_BUTTON_MENU needs to
// be returned by ReGBA_GetPressedButtons.
LastButtons == Hotkeys[1]
if ((LastButtons == Hotkeys[1]) ||
(LastButtons & OPENDINGUX_BUTTON_MENU))
toggle_menu = true;
#endif
|| (LastButtons & OPENDINGUX_BUTTON_MENU))

if (toggle_menu)
Result |= REGBA_BUTTON_MENU;

return Result;
Expand Down
21 changes: 21 additions & 0 deletions source/opendingux/od-input.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ enum Joystick_Stick_Axis {
JS_AXIS_RIGHT_VERTICAL = 3,
};

#if (defined(GCW_ZERO) || defined(RS90))
/* Note: We do not offer an L3+R3 combo *without*
* power, since this would lock users out of the
* menu on devices without L3/R3 buttons */
enum Menu_Toggle_Combo {
MENU_TOGGLE_POWER_OR_START_SELECT = 0,
MENU_TOGGLE_POWER_OR_L3_R3 = 1,
MENU_TOGGLE_POWER = 2,
MENU_TOGGLE_START_SELECT = 3,
};
#endif

// 0 if not fast-forwarding.
// Otherwise, the amount of frames to skip per rendered frame.
// 1 amounts to targetting 200% real-time;
Expand Down Expand Up @@ -174,6 +186,15 @@ extern enum OpenDingux_Buttons KeypadRemapping[12];
extern enum OpenDingux_Buttons PerGameHotkeys[5];
extern enum OpenDingux_Buttons Hotkeys[5];

#if (defined(GCW_ZERO) || defined(RS90))
// A value indicating which button combos will open the menu.
// 0 means POWER or START+SELECT
// 1 means POWER or L3+R3
// 2 means POWER
// 3 means START+SELECT
extern uint32_t MenuToggleCombo;
#endif

/*
* Returns true if the given hotkey is completely impossible to input on the
* port being compiled.
Expand Down
4 changes: 4 additions & 0 deletions source/opendingux/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ static void FixUpSettings()
if (IsImpossibleHotkey(PerGameHotkeys[4]))
PerGameHotkeys[4] = 0;

#if (defined(GCW_ZERO) || defined(RS90))
MenuToggleCombo = (MenuToggleCombo > MENU_TOGGLE_START_SELECT) ? MENU_TOGGLE_START_SELECT : MenuToggleCombo;
#endif

/* Colour correction and interframe blending options
* are converted to an enum via bit manipulation. It
* is therefore essential that the associated settings
Expand Down

0 comments on commit 4396f9e

Please sign in to comment.