Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
input.c
Go to the documentation of this file.
1
8
9//-----------------------------------------------------------------------------
10class Input
11{
12 // input locking
13
20 proto native void ChangeGameFocus(int add, int input_device = -1);
21
27 proto native void ResetGameFocus(int input_device = -1);
28
34 proto native bool HasGameFocus(int input_device = -1);
35
36 // actions
37 proto native int GetActionGroupsCount();
38 proto native int GetActionGroupSize(int group_index);
39 proto int GetActionGroupName(int group_index, out string name);
40 proto int GetActionDesc(int action_index, out string desc);
41
42 // getting action state
50 proto native float LocalValue_ID(int action, bool check_focus = true);
51 proto native float LocalValue(string action, bool check_focus = true);
52
61 proto native bool LocalPress_ID(int action, bool check_focus = true);
62 proto native bool LocalPress(string action, bool check_focus = true);
63
71 proto native bool LocalRelease_ID(int action, bool check_focus = true);
72 proto native bool LocalRelease(string action, bool check_focus = true);
73
81 proto native bool LocalHold_ID(int action, bool check_focus = true);
82 proto native bool LocalHold(string action, bool check_focus = true);
83
91 proto native bool LocalDbl_ID(int action, bool check_focus = true);
92 proto native bool LocalDbl(string action, bool check_focus = true);
93
101 proto native void DisableKey(int key);
102
104 proto native void EnableMouseAndKeyboard(bool enable);
106 proto native bool IsEnabledMouseAndKeyboard();
107
109 proto native void EnableGamepad(bool enable);
111 // NOTE: not actually supported, just keeping naming consistent.
112 // Required as we need to disable gamepad on windows when in the server browser to prevent
113 // the client from freezing on gamepad queries while refreshing the server list .
114 proto native bool IsEnabledGamepad();
119 proto native bool IsEnabledMouseAndKeyboardEvenOnServer();
120
125 proto native bool IsMouseConnected();
126 proto native bool IsKeyboardConnected();
127
129 proto native int GetCurrentProfile();
130 // gets currently selected profile keys for action
131 proto native void GetCurrentProfileActionKeys(int action_index, out TIntArray keys);
133 proto int GetProfileName(int profile_index, out string name);
135 proto native int GetProfilesCount();
137 proto native int SetProfile(int index);
138
139
140 // devices - joystick only!
141 proto native int GetDevicesCount();
142 proto int GetDeviceName(int device_index, out string name);
143 proto native int IsDeviceXInput(int device_index);
144 proto native int IsDeviceEnabled(int device_index);
145 proto native void SetDeviceEnabled(int device_index, bool enabled);
146
148 proto bool GetGamepadThumbDirection(GamepadButton thumbButton, out float angle, out float value);
149
151 proto native void ResetActiveGamepad();
152 proto native void SelectActiveGamepad(int gamepad);
153 proto native void GetGamepadList(out array<int> gamepads);
154 proto void GetGamepadUser(int gamepad, out BiosUser user);
159 proto native void IdentifyGamepad(GamepadButton button);
161 proto native bool IsActiveGamepadSelected();
162
164 bool IsAnyInputDeviceActive()
165 {
166 return IsActiveGamepadSelected() || IsMouseConnected() || IsKeyboardConnected();
167 }
168
173 bool AreAllAllowedInputDevicesActive(out array<int> unavailableDeviceList = null)
174 {
175 bool passed = true;
176 bool gamepad = IsActiveGamepadSelected();
177 bool mouse = IsMouseConnected();
178 bool keyboard = IsKeyboardConnected();
179 bool MnKEnabled;
180
181 if (g_Game.GetGameState() != DayZGameState.IN_GAME)
182 {
183 MnKEnabled = IsEnabledMouseAndKeyboard();
184 }
185 else if (g_Game.GetGameState() != DayZGameState.MAIN_MENU)
186 {
187 MnKEnabled = IsEnabledMouseAndKeyboardEvenOnServer();
188 }
189 else
190 {
191 return true;
192 }
193
194 if (!MnKEnabled)
195 {
196 if (!gamepad)
197 {
198 passed = false;
199 FillUnavailableDeviceArray(EUAINPUT_DEVICE_CONTROLLER,unavailableDeviceList);
200 }
201 }
202 else
203 {
204 if (!gamepad)
205 {
206 if (!mouse)
207 {
208 passed = false;
209 FillUnavailableDeviceArray(EUAINPUT_DEVICE_MOUSE,unavailableDeviceList);
210 }
211 if (!keyboard)
212 {
213 passed = false;
214 FillUnavailableDeviceArray(EUAINPUT_DEVICE_KEYBOARD,unavailableDeviceList);
215 }
216
217 if (!passed)
218 {
219 FillUnavailableDeviceArray(EUAINPUT_DEVICE_CONTROLLER,unavailableDeviceList);
220 }
221 }
222 }
223 return passed;
224 }
225
226 void FillUnavailableDeviceArray(int device, inout array<int> filler)
227 {
228 if (filler)
229 {
230 filler.Insert(device);
231 }
232 }
233
235 void UpdateConnectedInputDeviceList()
236 {
237 g_Game.GetConnectedInputDeviceList().Clear();
238
239 if (IsActiveGamepadSelected())
240 g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_CONTROLLER);
241 if (IsMouseConnected())
242 g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_MOUSE);
243 if (IsKeyboardConnected())
244 g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_KEYBOARD);
245 }
246
251 proto native EInputDeviceType GetCurrentInputDevice();
252
258 proto native GamepadButton GetEnterButton();
259
261 void OnGamepadConnected(int gamepad)
262 {
263 if (!g_Game)
264 return;
265
266 #ifdef PLATFORM_PS4
267 BiosUser user;
268 GetGamepadUser( gamepad, user );
269 if (user && user == GetGame().GetUserManager().GetSelectedUser())
270 {
271 SelectActiveGamepad(gamepad);
272 if (GetGame().GetMission())
273 GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); //only for PS, xbox handles it on identification
274 }
275 #endif
276
277 #ifdef PLATFORM_XBOX
278 if (gamepad == g_Game.GetPreviousGamepad())
279 {
280 SelectActiveGamepad(g_Game.GetPreviousGamepad());
281 if (GetGame().GetMission())
282 GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); //only for PS, xbox handles it on identification
283 }
284 #endif
285 }
286
288 void OnGamepadDisconnected(int gamepad)
289 {
290 if (!g_Game)
291 return;
292
293 if (IsInactiveGamepadOrUserSelected(gamepad))
294 {
295 UpdateConnectedInputDeviceList();
296
297 if (!g_Game.IsLoading())
298 {
299 DayZLoadState state = g_Game.GetLoadState();
300 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
301 {
302 if (GetGame().GetMission())
303 GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_CONTROLLER);
304 }
305 }
306 }
307 }
308
310 void OnGamepadIdentification(int gamepad)
311 {
312 if (!g_Game)
313 return;
314
315 if (gamepad > -1)
316 {
317 DayZLoadState state = g_Game.GetLoadState();
318
319 UpdateConnectedInputDeviceList();
320 SelectActiveGamepad(gamepad);
321 g_Game.SelectUser(gamepad);
322 g_Game.SetPreviousGamepad(gamepad);
323 if (state == DayZLoadState.MAIN_MENU_START || state == DayZLoadState.MAIN_MENU_USER_SELECT)
324 {
325 if (GetGame().GetMission())
326 GetGame().GetMission().Reset();
327 }
328
329 if (GetGame() && GetGame().GetMission() && GetGame().GetMission().GetOnInputDeviceConnected())
330 GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER);
331 }
332 }
333
334 int GetUserGamepad( BiosUser user )
335 {
336 array<int> gamepads = new array<int>;
337 GetGamepadList( gamepads );
338 for( int i = 0; i < gamepads.Count(); i++ )
339 {
340 BiosUser user2;
341 GetGamepadUser( gamepads[i], user2 );
342 if( user == user2 )
343 return gamepads[i];
344 }
345 return -1;
346 }
347
348 bool IsInactiveGamepadOrUserSelected( int gamepad = -1 )
349 {
350 if (!g_Game)
351 return false;
352
353 #ifdef PLATFORM_CONSOLE
354 if (!GetGame().GetUserManager())
355 return false;
356 #ifdef PLATFORM_XBOX
357 return !IsActiveGamepadSelected();
358 #endif
359 #ifdef PLATFORM_PS4
360 BiosUser user;
361 GetGamepadUser( gamepad, user );
362 return (user == GetGame().GetUserManager().GetSelectedUser());
363 #endif
364 #endif
365 return false;
366 }
367
370 void OnMouseConnected()
371 {
372 if (!g_Game)
373 return;
374
375 UpdateConnectedInputDeviceList();
376 if (!g_Game.IsLoading() && GetGame().GetMission())
377 {
378 DayZLoadState state = g_Game.GetLoadState();
379 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
380 {
381 GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_MOUSE);
382 }
383 }
384 }
385
388 void OnMouseDisconnected()
389 {
390 if (!g_Game)
391 return;
392
393 UpdateConnectedInputDeviceList();
394 if (!g_Game.IsLoading() && GetGame().GetMission())
395 {
396 DayZLoadState state = g_Game.GetLoadState();
397 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
398 {
399 GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_MOUSE);
400 }
401 }
402 }
403
406 void OnKeyboardConnected()
407 {
408 if (!g_Game)
409 return;
410
411 UpdateConnectedInputDeviceList();
412 if (!g_Game.IsLoading() && GetGame().GetMission())
413 {
414 DayZLoadState state = g_Game.GetLoadState();
415 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
416 {
417 GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_KEYBOARD);
418 }
419 }
420 }
421
424 void OnKeyboardDisconnected()
425 {
426 if (!g_Game)
427 return;
428
429 UpdateConnectedInputDeviceList();
430 if (!g_Game.IsLoading() && GetGame().GetMission())
431 {
432 DayZLoadState state = g_Game.GetLoadState();
433 if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
434 {
435 GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_KEYBOARD);
436 }
437 }
438 }
439
441 void OnLastInputDeviceChanged(EInputDeviceType inputDevice)
442 {
443 if (!g_Game)
444 return;
445
446 if (GetGame().GetMission())
447 {
448 GetGame().GetMission().GetOnInputDeviceChanged().Invoke(inputDevice);
449 }
450 }
451};
452
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Definition input.c:11
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3868
proto native CGame GetGame()
GamepadButton
Definition ensystem.c:341
proto string GetProfileName()
EInputDeviceType
Definition input.c:3
@ CONTROLLER
Definition input.c:6
@ UNKNOWN
Definition input.c:4
@ MOUSE_AND_KEYBOARD
Definition input.c:5