AMFP Enhanced
C++ reference: the code this unofficial fork added
Toggle main menu visibility
Loading...
Searching...
No Matches
LuxPadLayout.h
Go to the documentation of this file.
1
/*
2
* AMFP-2026: Classic / Modern gamepad layouts (Input tab). A layout sets the gamepad input of
3
* each listed action in the profile's user_keys.cfg; keyboard / mouse bindings are kept.
4
* Pure data and string logic, unit tested in tests/cpp/test_pad_layout.cpp.
5
*
6
* Modern (user approved): RT interact, LT lean, RB throw, Y journal, L3 sprint toggle,
7
* plus aliases added at load (not saved): View journal, D-pad up lantern.
8
*/
9
#ifndef LUX_PAD_LAYOUT_H
10
#define LUX_PAD_LAYOUT_H
11
12
#include <cstring>
13
#include <string>
14
15
enum
eLuxPadLayout
16
{
17
eLuxPadLayout_Classic
,
18
eLuxPadLayout_Modern
,
19
eLuxPadLayout_LastEnum
20
};
21
22
struct
cLuxPadBinding
23
{
24
const
char
*
msAction
;
// action name in user_keys.cfg
25
const
char
*
msInput
;
// "" = no gamepad input
26
};
27
28
#ifdef _WIN32
29
// Windows reads the pad in the SDL1 order (HPL2 GamepadSDL2.cpp remap): buttons by number,
30
// D-pad as hat 0, both triggers on axis 2 (LT positive, RT negative). Named strings such as
31
// "Button RightShoulder" are not parsed there, so layouts write these.
32
#define LUX_PAD_A "GamepadButton.Button 0"
33
#define LUX_PAD_B "GamepadButton.Button 1"
34
#define LUX_PAD_X "GamepadButton.Button 2"
35
#define LUX_PAD_Y "GamepadButton.Button 3"
36
#define LUX_PAD_LB "GamepadButton.Button 4"
37
#define LUX_PAD_RB "GamepadButton.Button 5"
38
#define LUX_PAD_VIEW "GamepadButton.Button 6"
39
#define LUX_PAD_L3 "GamepadButton.Button 8"
40
#define LUX_PAD_R3 "GamepadButton.Button 9"
41
#define LUX_PAD_LEFT "GamepadHat.Hat 0.Left"
42
#define LUX_PAD_RIGHT "GamepadHat.Hat 0.Right"
43
#define LUX_PAD_LT "GamepadAxis.Axis 2.Positive"
44
#define LUX_PAD_RT "GamepadAxis.Axis 2.Negative"
45
46
#define LUX_PAD_MOVE { "Forward", "GamepadAxis.Axis 1.Negative" }, { "Backward", "GamepadAxis.Axis 1.Positive" }, { "Right", "GamepadAxis.Axis 0.Positive" }, { "Left", "GamepadAxis.Axis 0.Negative" }
47
#else
48
// AMFP-2026: macOS / Linux read the pad in the SDL2 order, where iGamepad::StringToButton /
49
// StringToAxis parse only names (as the stock Mac / Linux key files use): the Windows numbers
50
// above came out as no input at all, so a pad could not walk, interact, jump or run. The D-pad
51
// is hat 0 on every platform (GamepadSDL2.cpp).
52
#define LUX_PAD_A "GamepadButton.Button A"
53
#define LUX_PAD_B "GamepadButton.Button B"
54
#define LUX_PAD_X "GamepadButton.Button X"
55
#define LUX_PAD_Y "GamepadButton.Button Y"
56
#define LUX_PAD_LB "GamepadButton.Button LeftShoulder"
57
#define LUX_PAD_RB "GamepadButton.Button RightShoulder"
58
#define LUX_PAD_VIEW "GamepadButton.Button Back"
59
#define LUX_PAD_L3 "GamepadButton.Button LeftStick"
60
#define LUX_PAD_R3 "GamepadButton.Button RightStick"
61
#define LUX_PAD_LEFT "GamepadHat.Hat 0.Left"
62
#define LUX_PAD_RIGHT "GamepadHat.Hat 0.Right"
63
#define LUX_PAD_LT "GamepadAxis.Axis LeftTrigger.Positive"
64
#define LUX_PAD_RT "GamepadAxis.Axis RightTrigger.Positive"
65
66
#define LUX_PAD_MOVE { "Forward", "GamepadAxis.Axis LeftY.Negative" }, { "Backward", "GamepadAxis.Axis LeftY.Positive" }, { "Right", "GamepadAxis.Axis LeftX.Positive" }, { "Left", "GamepadAxis.Axis LeftX.Negative" }
67
#endif
68
69
static
const
cLuxPadBinding
gvLuxPadClassic
[] = {
70
LUX_PAD_MOVE
,
71
{
"Jump"
,
LUX_PAD_A
}, {
"Crouch"
,
LUX_PAD_B
},
72
{
"Lantern"
,
LUX_PAD_X
}, {
"Journal"
,
LUX_PAD_Y
},
73
{
"Interact"
,
LUX_PAD_RB
}, {
"Attack"
,
LUX_PAD_LB
},
74
{
"Run"
,
LUX_PAD_LT
}, {
"Lean"
,
LUX_PAD_RT
},
75
{
"Rotate"
,
LUX_PAD_R3
},
76
{
"QuestLog"
,
LUX_PAD_RIGHT
}, {
"RecentText"
,
LUX_PAD_LEFT
},
77
{
"Inventory"
,
""
},
// AMFP has no inventory screen; stock bound it to B with Crouch
78
};
79
80
static
const
cLuxPadBinding
gvLuxPadModern
[] = {
81
LUX_PAD_MOVE
,
82
{
"Jump"
,
LUX_PAD_A
}, {
"Crouch"
,
LUX_PAD_B
},
83
{
"Lantern"
,
LUX_PAD_X
}, {
"Journal"
,
LUX_PAD_Y
},
84
{
"Interact"
,
LUX_PAD_RT
}, {
"Attack"
,
LUX_PAD_RB
},
85
{
"Run"
,
""
}, {
"Lean"
,
LUX_PAD_LT
},
// sprint: L3 click (LuxPadLayoutSprintToggle)
86
{
"Rotate"
,
LUX_PAD_R3
},
87
{
"QuestLog"
,
LUX_PAD_RIGHT
}, {
"RecentText"
,
LUX_PAD_LEFT
},
88
{
"Inventory"
,
""
},
89
};
90
91
#undef LUX_PAD_MOVE
92
93
/** Bumped when a layout changes, so profiles on that layout get it again once.
94
* 2: Modern journal moved from View to Y (View stays, as an alias). */
95
static
const
int
kLuxPadLayoutRevision
= 3;
// 3: named pad inputs on macOS / Linux (AMFP-2026)
96
97
inline
int
LuxPadLayoutCount
(
int
alLayout)
98
{
99
return
alLayout ==
eLuxPadLayout_Modern
? (int)(
sizeof
(
gvLuxPadModern
) /
sizeof
(
gvLuxPadModern
[0]))
100
: (int)(
sizeof
(
gvLuxPadClassic
) /
sizeof
(
gvLuxPadClassic
[0]));
101
}
102
103
inline
const
cLuxPadBinding
&
LuxPadLayoutAt
(
int
alLayout,
int
alIdx)
104
{
105
return
alLayout ==
eLuxPadLayout_Modern
?
gvLuxPadModern
[alIdx] :
gvLuxPadClassic
[alIdx];
106
}
107
108
/** The layout's gamepad input for an action, "" for none, NULL if the layout leaves it alone. */
109
inline
const
char
*
LuxPadLayoutInput
(
int
alLayout,
const
char
* asAction)
110
{
111
for
(
int
i = 0; i <
LuxPadLayoutCount
(alLayout); ++i)
112
if
(std::strcmp(
LuxPadLayoutAt
(alLayout, i).msAction, asAction) == 0)
return
LuxPadLayoutAt
(alLayout, i).
msInput
;
113
return
NULL;
114
}
115
116
/** Modern sprints with an L3 click instead of holding a trigger. */
117
inline
bool
LuxPadLayoutSprintToggle
(
int
alLayout) {
return
alLayout ==
eLuxPadLayout_Modern
; }
118
119
/** New Primary / Secondary for an action: its non-gamepad inputs first, then asPad (if any). */
120
inline
void
LuxMergePadInput
(
const
std::string& asPrimary,
const
std::string& asSecondary,
const
std::string& asPad,
121
std::string& asOutPrimary, std::string& asOutSecondary)
122
{
123
std::string vSlots[3];
124
int
n = 0;
125
const
std::string* vIn[2] = { &asPrimary, &asSecondary };
126
for
(
int
i = 0; i < 2; ++i)
127
if
(vIn[i]->empty() ==
false
&& vIn[i]->compare(0, 7,
"Gamepad"
) != 0) vSlots[n++] = *vIn[i];
128
if
(asPad.empty() ==
false
) vSlots[n++] = asPad;
129
asOutPrimary = vSlots[0];
130
asOutSecondary = vSlots[1];
131
}
132
133
/** L3 sprint: a click toggles it; it ends once you have moved and then stopped. */
134
class
cLuxSprintToggle
135
{
136
public
:
137
cLuxSprintToggle
() : mbOn(false), mbMoved(false) {}
138
void
Update
(
bool
abClicked,
float
afMoveAmount)
139
{
140
bool
bMoving = afMoveAmount > 0.2f;
141
if
(abClicked) { mbOn = !mbOn; mbMoved = bMoving;
return
; }
142
if
(mbOn ==
false
)
return
;
143
if
(bMoving) mbMoved =
true
;
144
else
if
(mbMoved) mbOn =
false
;
145
}
146
bool
IsOn
()
const
{
return
mbOn; }
147
void
Reset
() { mbOn = mbMoved =
false
; }
148
private
:
149
bool
mbOn, mbMoved;
150
};
151
152
#endif
LUX_PAD_LEFT
#define LUX_PAD_LEFT
Definition
LuxPadLayout.h:61
LuxPadLayoutInput
const char * LuxPadLayoutInput(int alLayout, const char *asAction)
The layout's gamepad input for an action, "" for none, NULL if the layout leaves it alone.
Definition
LuxPadLayout.h:109
LUX_PAD_RIGHT
#define LUX_PAD_RIGHT
Definition
LuxPadLayout.h:62
LUX_PAD_RB
#define LUX_PAD_RB
Definition
LuxPadLayout.h:57
LUX_PAD_X
#define LUX_PAD_X
Definition
LuxPadLayout.h:54
LUX_PAD_Y
#define LUX_PAD_Y
Definition
LuxPadLayout.h:55
LUX_PAD_MOVE
#define LUX_PAD_MOVE
Definition
LuxPadLayout.h:66
gvLuxPadClassic
static const cLuxPadBinding gvLuxPadClassic[]
Definition
LuxPadLayout.h:69
LUX_PAD_B
#define LUX_PAD_B
Definition
LuxPadLayout.h:53
LUX_PAD_RT
#define LUX_PAD_RT
Definition
LuxPadLayout.h:64
LUX_PAD_LB
#define LUX_PAD_LB
Definition
LuxPadLayout.h:56
kLuxPadLayoutRevision
static const int kLuxPadLayoutRevision
Bumped when a layout changes, so profiles on that layout get it again once.
Definition
LuxPadLayout.h:95
LuxMergePadInput
void LuxMergePadInput(const std::string &asPrimary, const std::string &asSecondary, const std::string &asPad, std::string &asOutPrimary, std::string &asOutSecondary)
New Primary / Secondary for an action: its non-gamepad inputs first, then asPad (if any).
Definition
LuxPadLayout.h:120
LUX_PAD_A
#define LUX_PAD_A
Definition
LuxPadLayout.h:52
LUX_PAD_R3
#define LUX_PAD_R3
Definition
LuxPadLayout.h:60
LuxPadLayoutAt
const cLuxPadBinding & LuxPadLayoutAt(int alLayout, int alIdx)
Definition
LuxPadLayout.h:103
LuxPadLayoutSprintToggle
bool LuxPadLayoutSprintToggle(int alLayout)
Modern sprints with an L3 click instead of holding a trigger.
Definition
LuxPadLayout.h:117
LUX_PAD_LT
#define LUX_PAD_LT
Definition
LuxPadLayout.h:63
LuxPadLayoutCount
int LuxPadLayoutCount(int alLayout)
Definition
LuxPadLayout.h:97
gvLuxPadModern
static const cLuxPadBinding gvLuxPadModern[]
Definition
LuxPadLayout.h:80
eLuxPadLayout
eLuxPadLayout
Definition
LuxPadLayout.h:16
eLuxPadLayout_Classic
@ eLuxPadLayout_Classic
Definition
LuxPadLayout.h:17
eLuxPadLayout_LastEnum
@ eLuxPadLayout_LastEnum
Definition
LuxPadLayout.h:19
eLuxPadLayout_Modern
@ eLuxPadLayout_Modern
Definition
LuxPadLayout.h:18
cLuxSprintToggle::Update
void Update(bool abClicked, float afMoveAmount)
Definition
LuxPadLayout.h:138
cLuxSprintToggle::Reset
void Reset()
Definition
LuxPadLayout.h:147
cLuxSprintToggle::cLuxSprintToggle
cLuxSprintToggle()
Definition
LuxPadLayout.h:137
cLuxSprintToggle::IsOn
bool IsOn() const
Definition
LuxPadLayout.h:146
cLuxPadBinding
Definition
LuxPadLayout.h:23
cLuxPadBinding::msInput
const char * msInput
Definition
LuxPadLayout.h:25
cLuxPadBinding::msAction
const char * msAction
Definition
LuxPadLayout.h:24
Game
src
game
LuxPadLayout.h
Generated by
1.18.0