@@ -48,10 +48,11 @@ struct InputState
4848class InputSource
4949{
5050public:
51+ virtual ~InputSource () = default ;
5152 virtual float readValue (SDL_Gamepad* gamepad) = 0;
5253 virtual bool isAxis () const = 0;
5354 virtual bool isNegated () const = 0;
54- virtual ~InputSource () = default ;
55+ virtual std::string getBindingName ( bool isSteerAction = false ) const = 0 ;
5556};
5657
5758class GamepadSource : public InputSource
@@ -105,6 +106,42 @@ class GamepadSource : public InputSource
105106
106107 bool isAxis () const override { return is_axis_; }
107108 bool isNegated () const override { return negate_; }
109+
110+ std::string getBindingName (bool isSteerAction) const override
111+ {
112+ if (isAxis ())
113+ {
114+ std::string direction = isSteerAction ? " " : (isNegated () ? " +" : " -" );
115+ switch (axis_)
116+ {
117+ case SDL_GAMEPAD_AXIS_LEFTX: return " Left Stick X" + direction;
118+ case SDL_GAMEPAD_AXIS_LEFTY: return " Left Stick Y" + direction;
119+ case SDL_GAMEPAD_AXIS_RIGHTX: return " Right Stick X" + direction;
120+ case SDL_GAMEPAD_AXIS_RIGHTY: return " Right Stick Y" + direction;
121+ case SDL_GAMEPAD_AXIS_LEFT_TRIGGER: return " Left Trigger" ;
122+ case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: return " Right Trigger" ;
123+ default : return " Unknown Axis" + direction;
124+ }
125+ }
126+
127+ switch (button_)
128+ {
129+ case SDL_GAMEPAD_BUTTON_A: return " A Button" ;
130+ case SDL_GAMEPAD_BUTTON_B: return " B Button" ;
131+ case SDL_GAMEPAD_BUTTON_X: return " X Button" ;
132+ case SDL_GAMEPAD_BUTTON_Y: return " Y Button" ;
133+ case SDL_GAMEPAD_BUTTON_BACK: return " Back" ;
134+ case SDL_GAMEPAD_BUTTON_START: return " Start" ;
135+ case SDL_GAMEPAD_BUTTON_DPAD_UP: return " D-Pad Up" ;
136+ case SDL_GAMEPAD_BUTTON_DPAD_DOWN: return " D-Pad Down" ;
137+ case SDL_GAMEPAD_BUTTON_DPAD_LEFT: return " D-Pad Left" ;
138+ case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: return " D-Pad Right" ;
139+ case SDL_GAMEPAD_BUTTON_LEFT_SHOULDER: return " L1/LB" ;
140+ case SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER: return " R1/RB" ;
141+ default : return " Unknown Button" ;
142+ }
143+ }
144+
108145 SDL_GamepadButton button () const { return button_; }
109146 SDL_GamepadAxis axis () const { return axis_; }
110147};
@@ -124,6 +161,10 @@ class KeyboardSource : public InputSource
124161
125162 bool isAxis () const override { return false ; }
126163 bool isNegated () const override { return negate_; }
164+ std::string getBindingName (bool isSteerAction) const override
165+ {
166+ return SDL_GetScancodeName (key_);
167+ }
127168 SDL_Scancode key () const { return key_; }
128169};
129170
@@ -593,58 +634,6 @@ class InputManager
593634
594635 BindingDialogState bindDialog;
595636
596- // Helper functions to get human-readable binding names
597- static std::string GetGamepadBindingName (const InputSource* source, bool isSteering)
598- {
599- if (!source) return " None" ;
600-
601- const GamepadSource* gamepadSource = dynamic_cast <const GamepadSource*>(source);
602- if (!gamepadSource) return " None" ;
603-
604- if (gamepadSource->isAxis ())
605- {
606- std::string direction = isSteering ? " " : (gamepadSource->isNegated () ? " +" : " -" );
607- switch (gamepadSource->axis ())
608- {
609- case SDL_GAMEPAD_AXIS_LEFTX: return " Left Stick X" + direction;
610- case SDL_GAMEPAD_AXIS_LEFTY: return " Left Stick Y" + direction;
611- case SDL_GAMEPAD_AXIS_RIGHTX: return " Right Stick X" + direction;
612- case SDL_GAMEPAD_AXIS_RIGHTY: return " Right Stick Y" + direction;
613- case SDL_GAMEPAD_AXIS_LEFT_TRIGGER: return " Left Trigger" ;
614- case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: return " Right Trigger" ;
615- default : return " Unknown Axis" + direction;
616- }
617- }
618- else {
619- switch (gamepadSource->button ())
620- {
621- case SDL_GAMEPAD_BUTTON_A: return " A Button" ;
622- case SDL_GAMEPAD_BUTTON_B: return " B Button" ;
623- case SDL_GAMEPAD_BUTTON_X: return " X Button" ;
624- case SDL_GAMEPAD_BUTTON_Y: return " Y Button" ;
625- case SDL_GAMEPAD_BUTTON_BACK: return " Back" ;
626- case SDL_GAMEPAD_BUTTON_START: return " Start" ;
627- case SDL_GAMEPAD_BUTTON_DPAD_UP: return " D-Pad Up" ;
628- case SDL_GAMEPAD_BUTTON_DPAD_DOWN: return " D-Pad Down" ;
629- case SDL_GAMEPAD_BUTTON_DPAD_LEFT: return " D-Pad Left" ;
630- case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: return " D-Pad Right" ;
631- case SDL_GAMEPAD_BUTTON_LEFT_SHOULDER: return " L1/LB" ;
632- case SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER: return " R1/RB" ;
633- default : return " Unknown Button" ;
634- }
635- }
636- }
637-
638- static std::string GetKeyboardBindingName (const InputSource* source)
639- {
640- if (!source) return " None" ;
641-
642- const KeyboardSource* kbSource = dynamic_cast <const KeyboardSource*>(source);
643- if (!kbSource) return " None" ;
644-
645- return SDL_GetScancodeName (kbSource->key ());
646- }
647-
648637 bool AnyInputPressed ()
649638 {
650639 int key_count = 0 ;
@@ -932,7 +921,7 @@ class InputManager
932921 {
933922 if (dynamic_cast <const GamepadSource*>(source.get ()))
934923 {
935- controllerBind = GetGamepadBindingName ( source. get (), i == 0 );
924+ controllerBind = source-> getBindingName ( i == 0 );
936925 break ;
937926 }
938927 }
@@ -957,15 +946,15 @@ class InputManager
957946 {
958947 if (volChannel != ADChannel::Steering)
959948 {
960- kbd_negative = GetKeyboardBindingName ( source. get () );
949+ kbd_negative = source-> getBindingName ( );
961950 break ;
962951 }
963952 else
964953 {
965954 if (source->isNegated ())
966- kbd_negative = GetKeyboardBindingName ( source. get () );
955+ kbd_negative = source-> getBindingName ( true );
967956 else
968- kbd_positive = GetKeyboardBindingName ( source. get () );
957+ kbd_positive = source-> getBindingName ( true );
969958 }
970959 }
971960 }
@@ -1045,7 +1034,7 @@ class InputManager
10451034 {
10461035 if (dynamic_cast <const GamepadSource*>(source.get ()))
10471036 {
1048- controllerBind = GetGamepadBindingName ( source. get (), false );
1037+ controllerBind = source-> getBindingName ( );
10491038 break ;
10501039 }
10511040 }
@@ -1067,7 +1056,7 @@ class InputManager
10671056 {
10681057 if (dynamic_cast <const KeyboardSource*>(source.get ()))
10691058 {
1070- keyboardBind = GetKeyboardBindingName ( source. get () );
1059+ keyboardBind = source-> getBindingName ( false );
10711060 break ;
10721061 }
10731062 }
0 commit comments