Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
input.c
Go to the documentation of this file.
1 
3 {
7 };
8 
9 //-----------------------------------------------------------------------------
10 class 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();
111  proto native bool IsEnabledMouseAndKeyboardEvenOnServer();
112 
117  proto native bool IsMouseConnected();
118  proto native bool IsKeyboardConnected();
119 
121  proto native int GetCurrentProfile();
122  // gets currently selected profile keys for action
123  proto native void GetCurrentProfileActionKeys(int action_index, out TIntArray keys);
125  proto int GetProfileName(int profile_index, out string name);
127  proto native int GetProfilesCount();
129  proto native int SetProfile(int index);
130 
131 
132  // devices - joystick only!
133  proto native int GetDevicesCount();
134  proto int GetDeviceName(int device_index, out string name);
135  proto native int IsDeviceXInput(int device_index);
136  proto native int IsDeviceEnabled(int device_index);
137  proto native void SetDeviceEnabled(int device_index, bool enabled);
138 
140  proto bool GetGamepadThumbDirection(GamepadButton thumbButton, out float angle, out float value);
141 
143  proto native void ResetActiveGamepad();
144  proto native void SelectActiveGamepad(int gamepad);
145  proto native void GetGamepadList(out array<int> gamepads);
146  proto void GetGamepadUser(int gamepad, out BiosUser user);
151  proto native void IdentifyGamepad(GamepadButton button);
153  proto native bool IsActiveGamepadSelected();
154 
156  bool IsAnyInputDeviceActive()
157  {
158  return IsActiveGamepadSelected() || IsMouseConnected() || IsKeyboardConnected();
159  }
160 
165  bool AreAllAllowedInputDevicesActive(out array<int> unavailableDeviceList = null)
166  {
167  bool passed = true;
168  bool gamepad = IsActiveGamepadSelected();
169  bool mouse = IsMouseConnected();
170  bool keyboard = IsKeyboardConnected();
171  bool MnKEnabled;
172 
173  if (g_Game.GetGameState() != DayZGameState.IN_GAME)
174  {
175  MnKEnabled = IsEnabledMouseAndKeyboard();
176  }
177  else if (g_Game.GetGameState() != DayZGameState.MAIN_MENU)
178  {
179  MnKEnabled = IsEnabledMouseAndKeyboardEvenOnServer();
180  }
181  else
182  {
183  return true;
184  }
185 
186  if (!MnKEnabled)
187  {
188  if (!gamepad)
189  {
190  passed = false;
191  FillUnavailableDeviceArray(EUAINPUT_DEVICE_CONTROLLER,unavailableDeviceList);
192  }
193  }
194  else
195  {
196  if (!gamepad)
197  {
198  if (!mouse)
199  {
200  passed = false;
201  FillUnavailableDeviceArray(EUAINPUT_DEVICE_MOUSE,unavailableDeviceList);
202  }
203  if (!keyboard)
204  {
205  passed = false;
206  FillUnavailableDeviceArray(EUAINPUT_DEVICE_KEYBOARD,unavailableDeviceList);
207  }
208 
209  if (!passed)
210  {
211  FillUnavailableDeviceArray(EUAINPUT_DEVICE_CONTROLLER,unavailableDeviceList);
212  }
213  }
214  }
215  return passed;
216  }
217 
218  void FillUnavailableDeviceArray(int device, inout array<int> filler)
219  {
220  if (filler)
221  {
222  filler.Insert(device);
223  }
224  }
225 
227  void UpdateConnectedInputDeviceList()
228  {
229  g_Game.GetConnectedInputDeviceList().Clear();
230 
231  if (IsActiveGamepadSelected())
232  g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_CONTROLLER);
233  if (IsMouseConnected())
234  g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_MOUSE);
235  if (IsKeyboardConnected())
236  g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_KEYBOARD);
237  }
238 
243  proto native EInputDeviceType GetCurrentInputDevice();
244 
250  proto native GamepadButton GetEnterButton();
251 
253  void OnGamepadConnected(int gamepad)
254  {
255  #ifdef PLATFORM_PS4
256  BiosUser user;
257  GetGamepadUser( gamepad, user );
258  if (user && user == GetGame().GetUserManager().GetSelectedUser())
259  {
260  SelectActiveGamepad(gamepad);
261  if (GetGame().GetMission())
262  GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); //only for PS, xbox handles it on identification
263  }
264  #endif
265 
266  #ifdef PLATFORM_XBOX
267  if (gamepad == g_Game.GetPreviousGamepad())
268  {
269  SelectActiveGamepad(g_Game.GetPreviousGamepad());
270  if (GetGame().GetMission())
271  GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); //only for PS, xbox handles it on identification
272  }
273  #endif
274  }
275 
277  void OnGamepadDisconnected(int gamepad)
278  {
279  if (IsInactiveGamepadOrUserSelected(gamepad))
280  {
281  UpdateConnectedInputDeviceList();
282 
283  if (!g_Game.IsLoading())
284  {
285  DayZLoadState state = g_Game.GetLoadState();
286  if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
287  {
288  if (GetGame().GetMission())
289  GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_CONTROLLER);
290  }
291  }
292  }
293  }
294 
296  void OnGamepadIdentification(int gamepad)
297  {
298  if (gamepad > -1)
299  {
300  DayZLoadState state = g_Game.GetLoadState();
301 
302  UpdateConnectedInputDeviceList();
303  SelectActiveGamepad(gamepad);
304  g_Game.SelectUser(gamepad);
305  g_Game.SetPreviousGamepad(gamepad);
306  if (state == DayZLoadState.MAIN_MENU_START || state == DayZLoadState.MAIN_MENU_USER_SELECT)
307  {
308  if (GetGame().GetMission())
309  GetGame().GetMission().Reset();
310  }
311 
312  if (GetGame() && GetGame().GetMission() && GetGame().GetMission().GetOnInputDeviceConnected())
313  GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER);
314  }
315  }
316 
317  int GetUserGamepad( BiosUser user )
318  {
319  array<int> gamepads = new array<int>;
320  GetGamepadList( gamepads );
321  for( int i = 0; i < gamepads.Count(); i++ )
322  {
323  BiosUser user2;
324  GetGamepadUser( gamepads[i], user2 );
325  if( user == user2 )
326  return gamepads[i];
327  }
328  return -1;
329  }
330 
331  bool IsInactiveGamepadOrUserSelected( int gamepad = -1 )
332  {
333  #ifdef PLATFORM_XBOX
334  return !IsActiveGamepadSelected();
335  #endif
336  #ifdef PLATFORM_PS4
337  BiosUser user;
338  GetGamepadUser( gamepad, user );
339  return (user == GetGame().GetUserManager().GetSelectedUser());
340  #endif
341  return false;
342  }
343 
346  void OnMouseConnected()
347  {
348  UpdateConnectedInputDeviceList();
349  if (!g_Game.IsLoading() && GetGame().GetMission())
350  {
351  DayZLoadState state = g_Game.GetLoadState();
352  if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
353  {
354  GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_MOUSE);
355  }
356  }
357  }
358 
361  void OnMouseDisconnected()
362  {
363  UpdateConnectedInputDeviceList();
364  if (!g_Game.IsLoading() && GetGame().GetMission())
365  {
366  DayZLoadState state = g_Game.GetLoadState();
367  if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
368  {
369  GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_MOUSE);
370  }
371  }
372  }
373 
376  void OnKeyboardConnected()
377  {
378  UpdateConnectedInputDeviceList();
379  if (!g_Game.IsLoading() && GetGame().GetMission())
380  {
381  DayZLoadState state = g_Game.GetLoadState();
382  if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT)
383  {
384  GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_KEYBOARD);
385  }
386  }
387  }
388 
391  void OnKeyboardDisconnected()
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_KEYBOARD);
400  }
401  }
402  }
403 
405  void OnLastInputDeviceChanged(EInputDeviceType inputDevice)
406  {
407  if (GetGame().GetMission())
408  {
409  GetGame().GetMission().GetOnInputDeviceChanged().Invoke(inputDevice);
410  }
411  }
412 };
413 
GetGame
proto native CGame GetGame()
MOUSE_AND_KEYBOARD
@ MOUSE_AND_KEYBOARD
Definition: input.c:5
EInputDeviceType
EInputDeviceType
Definition: input.c:2
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
Input
Definition: input.c:10
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
CONTROLLER
@ CONTROLLER
Definition: input.c:6
BiosUser
Definition: biosusermanager.c:8
GamepadButton
GamepadButton
Definition: ensystem.c:340
UNKNOWN
@ UNKNOWN
Definition: input.c:4