88
99// ////////////////////////////////////////////////////////////////////////
1010
11- struct ActionDefaulMapping
11+ struct DefaultActionMapping
1212{
1313public:
14- ActionDefaulMapping (ePedestrianAction action, eKeycode keycode, eGamepadButton gpButton = eGamepadButton_null)
15- : mAction (action)
14+ DefaultActionMapping (ePedActionsGroup group, ePedestrianAction action, eKeycode keycode, eGamepadButton gpButton = eGamepadButton_null)
15+ : mActionGroup (group)
16+ , mAction (action)
1617 , mKeycode (keycode)
1718 , mGpButton (gpButton)
1819 {
1920 }
2021public:
22+ ePedActionsGroup mActionGroup ;
2123 ePedestrianAction mAction ;
2224 eKeycode mKeycode ;
2325 eGamepadButton mGpButton ;
2426};
2527
26- static const ActionDefaulMapping ActionsInCar [] =
28+ static const DefaultActionMapping gDefaultActionsMapping [] =
2729{
28- {ePedestrianAction_LeaveCar, eKeycode_ENTER},
29- {ePedestrianAction_HandBrake, eKeycode_SPACE},
30- {ePedestrianAction_Accelerate, eKeycode_UP},
31- {ePedestrianAction_Reverse, eKeycode_DOWN},
32- {ePedestrianAction_SteerLeft, eKeycode_LEFT},
33- {ePedestrianAction_SteerRight, eKeycode_RIGHT},
34- {ePedestrianAction_Horn, eKeycode_TAB},
35- };
36-
37- static const ActionDefaulMapping ActionsOnFoot[] =
38- {
39- {ePedestrianAction_TurnLeft, eKeycode_LEFT},
40- {ePedestrianAction_TurnRight, eKeycode_RIGHT},
41- {ePedestrianAction_Jump, eKeycode_SPACE},
42- {ePedestrianAction_WalkBackward, eKeycode_DOWN},
43- {ePedestrianAction_Run, eKeycode_UP},
44- {ePedestrianAction_Shoot, eKeycode_LEFT_CTRL},
45- {ePedestrianAction_NextWeapon, eKeycode_X},
46- {ePedestrianAction_PrevWeapon, eKeycode_Z},
47- {ePedestrianAction_EnterCar, eKeycode_ENTER},
48- {ePedestrianAction_EnterCarAsPassenger, eKeycode_F},
30+ // common
31+ {ePedActionsGroup_Common, ePedestrianAction_NextWeapon, eKeycode_X},
32+ {ePedActionsGroup_Common, ePedestrianAction_PrevWeapon, eKeycode_Z},
33+
34+ // in car
35+ {ePedActionsGroup_InCar, ePedestrianAction_LeaveCar, eKeycode_ENTER},
36+ {ePedActionsGroup_InCar, ePedestrianAction_HandBrake, eKeycode_SPACE},
37+ {ePedActionsGroup_InCar, ePedestrianAction_Accelerate, eKeycode_UP},
38+ {ePedActionsGroup_InCar, ePedestrianAction_Reverse, eKeycode_DOWN},
39+ {ePedActionsGroup_InCar, ePedestrianAction_SteerLeft, eKeycode_LEFT},
40+ {ePedActionsGroup_InCar, ePedestrianAction_SteerRight, eKeycode_RIGHT},
41+ {ePedActionsGroup_InCar, ePedestrianAction_Horn, eKeycode_TAB},
42+
43+ // on foot
44+ {ePedActionsGroup_OnFoot, ePedestrianAction_TurnLeft, eKeycode_LEFT},
45+ {ePedActionsGroup_OnFoot, ePedestrianAction_TurnRight, eKeycode_RIGHT},
46+ {ePedActionsGroup_OnFoot, ePedestrianAction_Jump, eKeycode_SPACE},
47+ {ePedActionsGroup_OnFoot, ePedestrianAction_WalkBackward, eKeycode_DOWN},
48+ {ePedActionsGroup_OnFoot, ePedestrianAction_Run, eKeycode_UP},
49+ {ePedActionsGroup_OnFoot, ePedestrianAction_Shoot, eKeycode_LEFT_CTRL},
50+ {ePedActionsGroup_OnFoot, ePedestrianAction_EnterCar, eKeycode_ENTER},
51+ {ePedActionsGroup_OnFoot, ePedestrianAction_EnterCarAsPassenger, eKeycode_F},
4952};
5053
5154InputActionsMapping::InputActionsMapping ()
@@ -64,13 +67,7 @@ void InputActionsMapping::SetNull()
6467void InputActionsMapping::SetDefaults ()
6568{
6669 mControllerType = eInputControllerType_Keyboard;
67- // keys in car
68- for (const ActionDefaulMapping& curr: ActionsInCar)
69- {
70- mKeycodes [curr.mAction ] = curr.mKeycode ;
71- }
72- // keys on foot
73- for (const ActionDefaulMapping& curr: ActionsOnFoot)
70+ for (const DefaultActionMapping& curr: gDefaultActionsMapping )
7471 {
7572 mKeycodes [curr.mAction ] = curr.mKeycode ;
7673 }
@@ -137,48 +134,26 @@ void InputActionsMapping::SetFromConfig(cxx::config_node& configNode)
137134
138135ePedestrianAction InputActionsMapping::GetAction (ePedActionsGroup group, eKeycode keycode) const
139136{
140- if (group == ePedActionsGroup_InCar)
141- {
142- for (const ActionDefaulMapping& curr: ActionsInCar)
143- {
144- if (mKeycodes [curr.mAction ] == keycode)
145- return curr.mAction ;
146- }
147- return ePedestrianAction_null;
148- }
149-
150- if (group == ePedActionsGroup_OnFoot)
137+ for (const DefaultActionMapping& curr: gDefaultActionsMapping )
151138 {
152- for (const ActionDefaulMapping& curr: ActionsOnFoot)
139+ if ((curr.mActionGroup == ePedActionsGroup_Common || curr.mActionGroup == group) &&
140+ mKeycodes [curr.mAction ] == keycode)
153141 {
154- if (mKeycodes [curr.mAction ] == keycode)
155- return curr.mAction ;
142+ return curr.mAction ;
156143 }
157- return ePedestrianAction_null;
158144 }
159145 return ePedestrianAction_null;
160146}
161147
162148ePedestrianAction InputActionsMapping::GetAction (ePedActionsGroup group, eGamepadButton gpButton) const
163149{
164- if (group == ePedActionsGroup_InCar)
165- {
166- for (const ActionDefaulMapping& curr: ActionsInCar)
167- {
168- if (mGpButtons [curr.mAction ] == gpButton)
169- return curr.mAction ;
170- }
171- return ePedestrianAction_null;
172- }
173-
174- if (group == ePedActionsGroup_OnFoot)
150+ for (const DefaultActionMapping& curr: gDefaultActionsMapping )
175151 {
176- for (const ActionDefaulMapping& curr: ActionsOnFoot)
152+ if ((curr.mActionGroup == ePedActionsGroup_Common || curr.mActionGroup == group) &&
153+ mGpButtons [curr.mAction ] == gpButton)
177154 {
178- if (mGpButtons [curr.mAction ] == gpButton)
179- return curr.mAction ;
155+ return curr.mAction ;
180156 }
181- return ePedestrianAction_null;
182157 }
183158 return ePedestrianAction_null;
184159}
0 commit comments