summaryrefslogtreecommitdiff
path: root/src/core/ControllerConfig.h
blob: 82174343782e2fb3d43c9ee47595e6dcda3c789c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#pragma once


// based on x-gtasa

enum eControllerType
{
	KEYBOARD = 0,
	OPTIONAL_EXTRA,
	MOUSE,
	JOYSTICK,
	MAX_CONTROLLERTYPES,
};

enum e_ControllerAction
{
	PED_FIREWEAPON = 0,
	PED_CYCLE_WEAPON_RIGHT,
	PED_CYCLE_WEAPON_LEFT,
	GO_FORWARD,
	GO_BACK,
	GO_LEFT,
	GO_RIGHT,
	PED_SNIPER_ZOOM_IN,
	PED_SNIPER_ZOOM_OUT,
	VEHICLE_ENTER_EXIT,
	CAMERA_CHANGE_VIEW_ALL_SITUATIONS,
	PED_JUMPING,
	PED_SPRINT,
	PED_LOOKBEHIND,
	VEHICLE_ACCELERATE,
	VEHICLE_BRAKE,
	VEHICLE_CHANGE_RADIO_STATION,
	VEHICLE_HORN,
	TOGGLE_SUBMISSIONS,
	VEHICLE_HANDBRAKE,
	PED_1RST_PERSON_LOOK_LEFT,
	PED_1RST_PERSON_LOOK_RIGHT,
	VEHICLE_LOOKLEFT,
	VEHICLE_LOOKRIGHT,
	VEHICLE_LOOKBEHIND,
	VEHICLE_TURRETLEFT,
	VEHICLE_TURRETRIGHT,
	VEHICLE_TURRETUP,
	VEHICLE_TURRETDOWN,
	PED_CYCLE_TARGET_LEFT,
	PED_CYCLE_TARGET_RIGHT,
	PED_CENTER_CAMERA_BEHIND_PLAYER,
	PED_LOCK_TARGET,
	NETWORK_TALK,
	PED_1RST_PERSON_LOOK_UP,
	PED_1RST_PERSON_LOOK_DOWN,
	_CONTROLLERACTION_36,					// Unused
	TOGGLE_DPAD,
	SWITCH_DEBUG_CAM_ON,
	TAKE_SCREEN_SHOT,
	SHOW_MOUSE_POINTER_TOGGLE,
	MAX_CONTROLLERACTIONS,
};

enum e_ControllerActionType
{
	ACTIONTYPE_1RSTPERSON = 0,
	ACTIONTYPE_3RDPERSON,
	ACTIONTYPE_VEHICLE,
	ACTIONTYPE_VEHICLE_3RDPERSON,
	ACTIONTYPE_COMMON,
	ACTIONTYPE_1RST3RDPERSON,
	ACTIONTYPE_NONE,
};

enum eContSetOrder
{
	SETORDER_NONE = 0,
	SETORDER_1,
	SETORDER_2,
	SETORDER_3,
	SETORDER_4,
	MAX_SETORDERS,
};

enum eSimCheckers
{
	SIM_X1 = 0, SIM_Y1,	// DPad
	SIM_X2, SIM_Y2,	    // LeftStick

	MAX_SIMS
};

class CMouseControllerState;
class CControllerState;


#define JOY_BUTTONS 16
#define MAX_BUTTONS (JOY_BUTTONS+1)

#define ACTIONNAME_LENGTH 40

class CControllerConfigManager
{
public:
	struct tControllerConfigBind
	{
		int32      m_Key;
		int32      m_ContSetOrder;

		tControllerConfigBind()
		{
			m_Key = 0;
			m_ContSetOrder = 0;
		}
	};

	bool                  m_bFirstCapture;
#ifdef __DINPUT_INCLUDED__
	DIJOYSTATE2           m_OldState;
	DIJOYSTATE2           m_NewState;
#else
	uint32 ___padd[0x110 / 4 * 2];
#endif
	wchar                 m_aActionNames[MAX_CONTROLLERACTIONS][ACTIONNAME_LENGTH];
	bool                  m_aButtonStates[MAX_BUTTONS];
	tControllerConfigBind m_aSettings[MAX_CONTROLLERACTIONS][MAX_CONTROLLERTYPES];
	bool                  m_aSimCheckers[MAX_SIMS][MAX_CONTROLLERTYPES];
	bool                  m_bMouseAssociated;
	
	CControllerConfigManager();

	void  MakeControllerActionsBlank();
	
	int32 GetJoyButtonJustDown();
	
	void  SaveSettings(int32 file);
	void  LoadSettings(int32 file);
	
	void  InitDefaultControlConfiguration();
	void  InitDefaultControlConfigMouse(CMouseControllerState const &availableButtons);
	void  InitDefaultControlConfigJoyPad(uint32 buttons);
	void  InitialiseControllerActionNameArray();

	void  UpdateJoyInConfigMenus_ButtonDown                           (int32 button, int32 padnumber);
	void  AffectControllerStateOn_ButtonDown                          (int32 button, eControllerType type);
	void  AffectControllerStateOn_ButtonDown_Driving                  (int32 button, eControllerType type, CControllerState &state);
	void  AffectControllerStateOn_ButtonDown_FirstPersonOnly          (int32 button, eControllerType type, CControllerState &state);
	void  AffectControllerStateOn_ButtonDown_ThirdPersonOnly          (int32 button, eControllerType type, CControllerState &state);
	void  AffectControllerStateOn_ButtonDown_FirstAndThirdPersonOnly  (int32 button, eControllerType type, CControllerState &state);
	void  AffectControllerStateOn_ButtonDown_AllStates                (int32 button, eControllerType type, CControllerState &state);
	void  AffectControllerStateOn_ButtonDown_VehicleAndThirdPersonOnly(int32 button, eControllerType type, CControllerState &state);

	void  UpdateJoyInConfigMenus_ButtonUp(int32 button, int32 padnumber);
	void  AffectControllerStateOn_ButtonUp(int32 button, eControllerType type);
	void  AffectControllerStateOn_ButtonUp_All_Player_States(int32 button, eControllerType type, CControllerState &state);
	
	void  AffectPadFromKeyBoard();
	void  AffectPadFromMouse();
	
	void  ClearSimButtonPressCheckers();

	bool  GetIsKeyboardKeyDown    (RsKeyCodes keycode);
	bool  GetIsKeyboardKeyJustDown(RsKeyCodes keycode);
	bool  GetIsMouseButtonDown    (RsKeyCodes keycode);
	bool  GetIsMouseButtonUp      (RsKeyCodes keycode);


	void DeleteMatchingCommonControls           (e_ControllerAction action, int32 key, eControllerType type);
	void DeleteMatching3rdPersonControls        (e_ControllerAction action, int32 key, eControllerType type);
	void DeleteMatching1rst3rdPersonControls    (e_ControllerAction action, int32 key, eControllerType type);
	void DeleteMatchingVehicleControls          (e_ControllerAction action, int32 key, eControllerType type);
	void DeleteMatchingVehicle_3rdPersonControls(e_ControllerAction action, int32 key, eControllerType type);
	void DeleteMatching1rstPersonControls       (e_ControllerAction action, int32 key, eControllerType type);
	void DeleteMatchingActionInitiators         (e_ControllerAction action, int32 key, eControllerType type);

	bool GetIsKeyBlank(int32 key, eControllerType type);
	e_ControllerActionType GetActionType(e_ControllerAction action);

	void ClearSettingsAssociatedWithAction        (e_ControllerAction action, eControllerType type);
	wchar *GetControllerSettingTextWithOrderNumber(e_ControllerAction action, eContSetOrder setorder);
	wchar *GetControllerSettingTextKeyBoard       (e_ControllerAction action, eControllerType type);
	wchar *GetControllerSettingTextMouse          (e_ControllerAction action);
	wchar *GetControllerSettingTextJoystick       (e_ControllerAction action);

	int32 GetNumOfSettingsForAction(e_ControllerAction action);
	void  GetWideStringOfCommandKeys(uint16 action, wchar *text, uint16 leight);
	int32 GetControllerKeyAssociatedWithAction(e_ControllerAction action, eControllerType type);

	void  UpdateJoyButtonState(int32 padnumber);
	
	bool  GetIsActionAButtonCombo             (e_ControllerAction action);
	wchar *GetButtonComboText                 (e_ControllerAction action);
	void  SetControllerKeyAssociatedWithAction(e_ControllerAction action, int32 key, eControllerType type);
	int32 GetMouseButtonAssociatedWithAction  (e_ControllerAction action);
	void  SetMouseButtonAssociatedWithAction  (e_ControllerAction action, int32 button);
	void  ResetSettingOrder                   (e_ControllerAction action);
};

VALIDATE_SIZE(CControllerConfigManager, 0x143C);

extern CControllerConfigManager ControlsManager;