AMFP Enhanced
C++ reference: the code this unofficial fork added
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
16{
20};
21
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
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
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). */
95static const int kLuxPadLayoutRevision = 3; // 3: named pad inputs on macOS / Linux (AMFP-2026)
96
97inline 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
103inline 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. */
109inline 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. */
117inline 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). */
120inline 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. */
135{
136public:
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; }
148private:
149 bool mbOn, mbMoved;
150};
151
152#endif
#define LUX_PAD_LEFT
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.
#define LUX_PAD_RIGHT
#define LUX_PAD_RB
#define LUX_PAD_X
#define LUX_PAD_Y
#define LUX_PAD_MOVE
static const cLuxPadBinding gvLuxPadClassic[]
#define LUX_PAD_B
#define LUX_PAD_RT
#define LUX_PAD_LB
static const int kLuxPadLayoutRevision
Bumped when a layout changes, so profiles on that layout get it again once.
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).
#define LUX_PAD_A
#define LUX_PAD_R3
const cLuxPadBinding & LuxPadLayoutAt(int alLayout, int alIdx)
bool LuxPadLayoutSprintToggle(int alLayout)
Modern sprints with an L3 click instead of holding a trigger.
#define LUX_PAD_LT
int LuxPadLayoutCount(int alLayout)
static const cLuxPadBinding gvLuxPadModern[]
eLuxPadLayout
@ eLuxPadLayout_Classic
@ eLuxPadLayout_LastEnum
@ eLuxPadLayout_Modern
void Update(bool abClicked, float afMoveAmount)
bool IsOn() const
const char * msInput
const char * msAction