|
|
|
enum EInputDeviceType |
|
{ |
|
UNKNOWN, |
|
MOUSE_AND_KEYBOARD, |
|
CONTROLLER |
|
}; |
|
|
|
|
|
class Input |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proto native void ChangeGameFocus(int add, int input_device = -1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
proto native void ResetGameFocus(int input_device = -1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
proto native bool HasGameFocus(int input_device = -1); |
|
|
|
|
|
proto native int GetActionGroupsCount(); |
|
proto native int GetActionGroupSize(int group_index); |
|
proto int GetActionGroupName(int group_index, out string name); |
|
proto int GetActionDesc(int action_index, out string desc); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proto native float LocalValue_ID(int action, bool check_focus = true); |
|
proto native float LocalValue(string action, bool check_focus = true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proto native bool LocalPress_ID(int action, bool check_focus = true); |
|
proto native bool LocalPress(string action, bool check_focus = true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proto native bool LocalRelease_ID(int action, bool check_focus = true); |
|
proto native bool LocalRelease(string action, bool check_focus = true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proto native bool LocalHold_ID(int action, bool check_focus = true); |
|
proto native bool LocalHold(string action, bool check_focus = true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proto native bool LocalDbl_ID(int action, bool check_focus = true); |
|
proto native bool LocalDbl(string action, bool check_focus = true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proto native void DisableKey(int key); |
|
|
|
|
|
proto native void EnableMouseAndKeyboard(bool enable); |
|
|
|
proto native bool IsEnabledMouseAndKeyboard(); |
|
|
|
|
|
|
|
|
|
proto native bool IsEnabledMouseAndKeyboardEvenOnServer(); |
|
|
|
|
|
|
|
|
|
|
|
proto native bool IsMouseConnected(); |
|
proto native bool IsKeyboardConnected(); |
|
|
|
|
|
proto native int GetCurrentProfile(); |
|
|
|
proto native void GetCurrentProfileActionKeys(int action_index, out TIntArray keys); |
|
|
|
proto int GetProfileName(int profile_index, out string name); |
|
|
|
proto native int GetProfilesCount(); |
|
|
|
proto native int SetProfile(int index); |
|
|
|
|
|
|
|
proto native int GetDevicesCount(); |
|
proto int GetDeviceName(int device_index, out string name); |
|
proto native int IsDeviceXInput(int device_index); |
|
proto native int IsDeviceEnabled(int device_index); |
|
proto native void SetDeviceEnabled(int device_index, bool enabled); |
|
|
|
|
|
proto bool GetGamepadThumbDirection(GamepadButton thumbButton, out float angle, out float value); |
|
|
|
|
|
proto native void ResetActiveGamepad(); |
|
proto native void SelectActiveGamepad(int gamepad); |
|
proto native void GetGamepadList(out array<int> gamepads); |
|
proto void GetGamepadUser(int gamepad, out BiosUser user); |
|
|
|
|
|
|
|
|
|
proto native void IdentifyGamepad(GamepadButton button); |
|
|
|
proto native bool IsActiveGamepadSelected(); |
|
|
|
|
|
bool IsAnyInputDeviceActive() |
|
{ |
|
return IsActiveGamepadSelected() || IsMouseConnected() || IsKeyboardConnected(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool AreAllAllowedInputDevicesActive(out array<int> unavailableDeviceList = null) |
|
{ |
|
bool passed = true; |
|
bool gamepad = IsActiveGamepadSelected(); |
|
bool mouse = IsMouseConnected(); |
|
bool keyboard = IsKeyboardConnected(); |
|
bool MnKEnabled; |
|
|
|
if (g_Game.GetGameState() != DayZGameState.IN_GAME) |
|
{ |
|
MnKEnabled = IsEnabledMouseAndKeyboard(); |
|
} |
|
else if (g_Game.GetGameState() != DayZGameState.MAIN_MENU) |
|
{ |
|
MnKEnabled = IsEnabledMouseAndKeyboardEvenOnServer(); |
|
} |
|
else |
|
{ |
|
return true; |
|
} |
|
|
|
if (!MnKEnabled) |
|
{ |
|
if (!gamepad) |
|
{ |
|
passed = false; |
|
FillUnavailableDeviceArray(EUAINPUT_DEVICE_CONTROLLER,unavailableDeviceList); |
|
} |
|
} |
|
else |
|
{ |
|
if (!gamepad) |
|
{ |
|
if (!mouse) |
|
{ |
|
passed = false; |
|
FillUnavailableDeviceArray(EUAINPUT_DEVICE_MOUSE,unavailableDeviceList); |
|
} |
|
if (!keyboard) |
|
{ |
|
passed = false; |
|
FillUnavailableDeviceArray(EUAINPUT_DEVICE_KEYBOARD,unavailableDeviceList); |
|
} |
|
|
|
if (!passed) |
|
{ |
|
FillUnavailableDeviceArray(EUAINPUT_DEVICE_CONTROLLER,unavailableDeviceList); |
|
} |
|
} |
|
} |
|
return passed; |
|
} |
|
|
|
void FillUnavailableDeviceArray(int device, inout array<int> filler) |
|
{ |
|
if (filler) |
|
{ |
|
filler.Insert(device); |
|
} |
|
} |
|
|
|
|
|
void UpdateConnectedInputDeviceList() |
|
{ |
|
g_Game.GetConnectedInputDeviceList().Clear(); |
|
|
|
if (IsActiveGamepadSelected()) |
|
g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_CONTROLLER); |
|
if (IsMouseConnected()) |
|
g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_MOUSE); |
|
if (IsKeyboardConnected()) |
|
g_Game.GetConnectedInputDeviceList().Insert(EUAINPUT_DEVICE_KEYBOARD); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proto native EInputDeviceType GetCurrentInputDevice(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
proto native GamepadButton GetEnterButton(); |
|
|
|
|
|
void OnGamepadConnected(int gamepad) |
|
{ |
|
#ifdef PLATFORM_PS4 |
|
BiosUser user; |
|
GetGamepadUser( gamepad, user ); |
|
if (user && user == GetGame().GetUserManager().GetSelectedUser()) |
|
{ |
|
SelectActiveGamepad(gamepad); |
|
if (GetGame().GetMission()) |
|
GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); |
|
} |
|
#endif |
|
|
|
#ifdef PLATFORM_XBOX |
|
if (gamepad == g_Game.GetPreviousGamepad()) |
|
{ |
|
SelectActiveGamepad(g_Game.GetPreviousGamepad()); |
|
if (GetGame().GetMission()) |
|
GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); |
|
} |
|
#endif |
|
} |
|
|
|
|
|
void OnGamepadDisconnected(int gamepad) |
|
{ |
|
if (IsInactiveGamepadOrUserSelected(gamepad)) |
|
{ |
|
UpdateConnectedInputDeviceList(); |
|
|
|
if (!g_Game.IsLoading()) |
|
{ |
|
DayZLoadState state = g_Game.GetLoadState(); |
|
if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT) |
|
{ |
|
if (GetGame().GetMission()) |
|
GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
void OnGamepadIdentification(int gamepad) |
|
{ |
|
if (gamepad > -1) |
|
{ |
|
DayZLoadState state = g_Game.GetLoadState(); |
|
|
|
UpdateConnectedInputDeviceList(); |
|
SelectActiveGamepad(gamepad); |
|
g_Game.SelectUser(gamepad); |
|
g_Game.SetPreviousGamepad(gamepad); |
|
if (state == DayZLoadState.MAIN_MENU_START || state == DayZLoadState.MAIN_MENU_USER_SELECT) |
|
{ |
|
if (GetGame().GetMission()) |
|
GetGame().GetMission().Reset(); |
|
} |
|
|
|
if (GetGame() && GetGame().GetMission() && GetGame().GetMission().GetOnInputDeviceConnected()) |
|
GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_CONTROLLER); |
|
} |
|
} |
|
|
|
int GetUserGamepad( BiosUser user ) |
|
{ |
|
array<int> gamepads = new array<int>; |
|
GetGamepadList( gamepads ); |
|
for( int i = 0; i < gamepads.Count(); i++ ) |
|
{ |
|
BiosUser user2; |
|
GetGamepadUser( gamepads[i], user2 ); |
|
if( user == user2 ) |
|
return gamepads[i]; |
|
} |
|
return -1; |
|
} |
|
|
|
bool IsInactiveGamepadOrUserSelected( int gamepad = -1 ) |
|
{ |
|
#ifdef PLATFORM_XBOX |
|
return !IsActiveGamepadSelected(); |
|
#endif |
|
#ifdef PLATFORM_PS4 |
|
BiosUser user; |
|
GetGamepadUser( gamepad, user ); |
|
return (user == GetGame().GetUserManager().GetSelectedUser()); |
|
#endif |
|
return false; |
|
} |
|
|
|
|
|
|
|
void OnMouseConnected() |
|
{ |
|
UpdateConnectedInputDeviceList(); |
|
if (!g_Game.IsLoading() && GetGame().GetMission()) |
|
{ |
|
DayZLoadState state = g_Game.GetLoadState(); |
|
if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT) |
|
{ |
|
GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_MOUSE); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
void OnMouseDisconnected() |
|
{ |
|
UpdateConnectedInputDeviceList(); |
|
if (!g_Game.IsLoading() && GetGame().GetMission()) |
|
{ |
|
DayZLoadState state = g_Game.GetLoadState(); |
|
if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT) |
|
{ |
|
GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_MOUSE); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
void OnKeyboardConnected() |
|
{ |
|
UpdateConnectedInputDeviceList(); |
|
if (!g_Game.IsLoading() && GetGame().GetMission()) |
|
{ |
|
DayZLoadState state = g_Game.GetLoadState(); |
|
if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT) |
|
{ |
|
GetGame().GetMission().GetOnInputDeviceConnected().Invoke(EUAINPUT_DEVICE_KEYBOARD); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
void OnKeyboardDisconnected() |
|
{ |
|
UpdateConnectedInputDeviceList(); |
|
if (!g_Game.IsLoading() && GetGame().GetMission()) |
|
{ |
|
DayZLoadState state = g_Game.GetLoadState(); |
|
if (state != DayZLoadState.MAIN_MENU_START && state != DayZLoadState.MAIN_MENU_USER_SELECT) |
|
{ |
|
GetGame().GetMission().GetOnInputDeviceDisconnected().Invoke(EUAINPUT_DEVICE_KEYBOARD); |
|
} |
|
} |
|
} |
|
|
|
|
|
void OnLastInputDeviceChanged(EInputDeviceType inputDevice) |
|
{ |
|
if (GetGame().GetMission()) |
|
{ |
|
GetGame().GetMission().GetOnInputDeviceChanged().Invoke(inputDevice); |
|
} |
|
} |
|
}; |
|
|
|
|