diff options
Diffstat (limited to 'Thronefall_v1.0/Rewired')
43 files changed, 10276 insertions, 0 deletions
diff --git a/Thronefall_v1.0/Rewired/Rewired.Data/UserDataStore_PlayerPrefs.cs b/Thronefall_v1.0/Rewired/Rewired.Data/UserDataStore_PlayerPrefs.cs new file mode 100644 index 0000000..b5a933b --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Data/UserDataStore_PlayerPrefs.cs @@ -0,0 +1,1358 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using Rewired.Utils.Libraries.TinyJson; +using UnityEngine; + +namespace Rewired.Data; + +public class UserDataStore_PlayerPrefs : UserDataStore +{ + private class ControllerAssignmentSaveInfo + { + public class PlayerInfo + { + public int id; + + public bool hasKeyboard; + + public bool hasMouse; + + public JoystickInfo[] joysticks; + + public int joystickCount + { + get + { + if (joysticks == null) + { + return 0; + } + return joysticks.Length; + } + } + + public int IndexOfJoystick(int joystickId) + { + for (int i = 0; i < joystickCount; i++) + { + if (joysticks[i] != null && joysticks[i].id == joystickId) + { + return i; + } + } + return -1; + } + + public bool ContainsJoystick(int joystickId) + { + return IndexOfJoystick(joystickId) >= 0; + } + } + + public class JoystickInfo + { + public Guid instanceGuid; + + public string hardwareIdentifier; + + public int id; + } + + public PlayerInfo[] players; + + public int playerCount + { + get + { + if (players == null) + { + return 0; + } + return players.Length; + } + } + + public ControllerAssignmentSaveInfo() + { + } + + public ControllerAssignmentSaveInfo(int playerCount) + { + players = new PlayerInfo[playerCount]; + for (int i = 0; i < playerCount; i++) + { + players[i] = new PlayerInfo(); + } + } + + public int IndexOfPlayer(int playerId) + { + for (int i = 0; i < playerCount; i++) + { + if (players[i] != null && players[i].id == playerId) + { + return i; + } + } + return -1; + } + + public bool ContainsPlayer(int playerId) + { + return IndexOfPlayer(playerId) >= 0; + } + } + + private class JoystickAssignmentHistoryInfo + { + public readonly Joystick joystick; + + public readonly int oldJoystickId; + + public JoystickAssignmentHistoryInfo(Joystick joystick, int oldJoystickId) + { + if (joystick == null) + { + throw new ArgumentNullException("joystick"); + } + this.joystick = joystick; + this.oldJoystickId = oldJoystickId; + } + } + + private const string thisScriptName = "UserDataStore_PlayerPrefs"; + + private const string logPrefix = "Rewired: "; + + private const string editorLoadedMessage = "\n***IMPORTANT:*** Changes made to the Rewired Input Manager configuration after the last time XML data was saved WILL NOT be used because the loaded old saved data has overwritten these values. If you change something in the Rewired Input Manager such as a Joystick Map or Input Behavior settings, you will not see these changes reflected in the current configuration. Clear PlayerPrefs using the inspector option on the UserDataStore_PlayerPrefs component."; + + private const string playerPrefsKeySuffix_controllerAssignments = "ControllerAssignments"; + + private const int controllerMapPPKeyVersion_original = 0; + + private const int controllerMapPPKeyVersion_includeDuplicateJoystickIndex = 1; + + private const int controllerMapPPKeyVersion_supportDisconnectedControllers = 2; + + private const int controllerMapPPKeyVersion_includeFormatVersion = 2; + + private const int controllerMapPPKeyVersion = 2; + + [Tooltip("Should this script be used? If disabled, nothing will be saved or loaded.")] + [SerializeField] + private bool isEnabled = true; + + [Tooltip("Should saved data be loaded on start?")] + [SerializeField] + private bool loadDataOnStart = true; + + [Tooltip("Should Player Joystick assignments be saved and loaded? This is not totally reliable for all Joysticks on all platforms. Some platforms/input sources do not provide enough information to reliably save assignments from session to session and reboot to reboot.")] + [SerializeField] + private bool loadJoystickAssignments = true; + + [Tooltip("Should Player Keyboard assignments be saved and loaded?")] + [SerializeField] + private bool loadKeyboardAssignments = true; + + [Tooltip("Should Player Mouse assignments be saved and loaded?")] + [SerializeField] + private bool loadMouseAssignments = true; + + [Tooltip("The PlayerPrefs key prefix. Change this to change how keys are stored in PlayerPrefs. Changing this will make saved data already stored with the old key no longer accessible.")] + [SerializeField] + private string playerPrefsKeyPrefix = "RewiredSaveData"; + + [NonSerialized] + private bool allowImpreciseJoystickAssignmentMatching = true; + + [NonSerialized] + private bool deferredJoystickAssignmentLoadPending; + + [NonSerialized] + private bool wasJoystickEverDetected; + + [NonSerialized] + private List<int> __allActionIds; + + [NonSerialized] + private string __allActionIdsString; + + public bool IsEnabled + { + get + { + return isEnabled; + } + set + { + isEnabled = value; + } + } + + public bool LoadDataOnStart + { + get + { + return loadDataOnStart; + } + set + { + loadDataOnStart = value; + } + } + + public bool LoadJoystickAssignments + { + get + { + return loadJoystickAssignments; + } + set + { + loadJoystickAssignments = value; + } + } + + public bool LoadKeyboardAssignments + { + get + { + return loadKeyboardAssignments; + } + set + { + loadKeyboardAssignments = value; + } + } + + public bool LoadMouseAssignments + { + get + { + return loadMouseAssignments; + } + set + { + loadMouseAssignments = value; + } + } + + public string PlayerPrefsKeyPrefix + { + get + { + return playerPrefsKeyPrefix; + } + set + { + playerPrefsKeyPrefix = value; + } + } + + private string playerPrefsKey_controllerAssignments => string.Format("{0}_{1}", playerPrefsKeyPrefix, "ControllerAssignments"); + + private bool loadControllerAssignments + { + get + { + if (!loadKeyboardAssignments && !loadMouseAssignments) + { + return loadJoystickAssignments; + } + return true; + } + } + + private List<int> allActionIds + { + get + { + if (__allActionIds != null) + { + return __allActionIds; + } + List<int> list = new List<int>(); + IList<InputAction> actions = ReInput.mapping.Actions; + for (int i = 0; i < actions.Count; i++) + { + list.Add(actions[i].id); + } + __allActionIds = list; + return list; + } + } + + private string allActionIdsString + { + get + { + if (!string.IsNullOrEmpty(__allActionIdsString)) + { + return __allActionIdsString; + } + StringBuilder stringBuilder = new StringBuilder(); + List<int> list = allActionIds; + for (int i = 0; i < list.Count; i++) + { + if (i > 0) + { + stringBuilder.Append(","); + } + stringBuilder.Append(list[i]); + } + __allActionIdsString = stringBuilder.ToString(); + return __allActionIdsString; + } + } + + public override void Save() + { + if (!isEnabled) + { + Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not save any data.", this); + } + else + { + SaveAll(); + } + } + + public override void SaveControllerData(int playerId, ControllerType controllerType, int controllerId) + { + if (!isEnabled) + { + Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not save any data.", this); + } + else + { + SaveControllerDataNow(playerId, controllerType, controllerId); + } + } + + public override void SaveControllerData(ControllerType controllerType, int controllerId) + { + if (!isEnabled) + { + Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not save any data.", this); + } + else + { + SaveControllerDataNow(controllerType, controllerId); + } + } + + public override void SavePlayerData(int playerId) + { + if (!isEnabled) + { + Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not save any data.", this); + } + else + { + SavePlayerDataNow(playerId); + } + } + + public override void SaveInputBehavior(int playerId, int behaviorId) + { + if (!isEnabled) + { + Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not save any data.", this); + } + else + { + SaveInputBehaviorNow(playerId, behaviorId); + } + } + + public override void Load() + { + if (!isEnabled) + { + Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not load any data.", this); + } + else + { + LoadAll(); + } + } + + public override void LoadControllerData(int playerId, ControllerType controllerType, int controllerId) + { + if (!isEnabled) + { + Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not load any data.", this); + } + else + { + LoadControllerDataNow(playerId, controllerType, controllerId); + } + } + + public override void LoadControllerData(ControllerType controllerType, int controllerId) + { + if (!isEnabled) + { + Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not load any data.", this); + } + else + { + LoadControllerDataNow(controllerType, controllerId); + } + } + + public override void LoadPlayerData(int playerId) + { + if (!isEnabled) + { + Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not load any data.", this); + } + else + { + LoadPlayerDataNow(playerId); + } + } + + public override void LoadInputBehavior(int playerId, int behaviorId) + { + if (!isEnabled) + { + Debug.LogWarning("Rewired: UserDataStore_PlayerPrefs is disabled and will not load any data.", this); + } + else + { + LoadInputBehaviorNow(playerId, behaviorId); + } + } + + protected override void OnInitialize() + { + if (loadDataOnStart) + { + Load(); + if (loadControllerAssignments && ReInput.controllers.joystickCount > 0) + { + wasJoystickEverDetected = true; + SaveControllerAssignments(); + } + } + } + + protected override void OnControllerConnected(ControllerStatusChangedEventArgs args) + { + if (isEnabled && args.controllerType == ControllerType.Joystick) + { + LoadJoystickData(args.controllerId); + if (loadDataOnStart && loadJoystickAssignments && !wasJoystickEverDetected) + { + StartCoroutine(LoadJoystickAssignmentsDeferred()); + } + if (loadJoystickAssignments && !deferredJoystickAssignmentLoadPending) + { + SaveControllerAssignments(); + } + wasJoystickEverDetected = true; + } + } + + protected override void OnControllerPreDisconnect(ControllerStatusChangedEventArgs args) + { + if (isEnabled && args.controllerType == ControllerType.Joystick) + { + SaveJoystickData(args.controllerId); + } + } + + protected override void OnControllerDisconnected(ControllerStatusChangedEventArgs args) + { + if (isEnabled && loadControllerAssignments) + { + SaveControllerAssignments(); + } + } + + public override void SaveControllerMap(int playerId, ControllerMap controllerMap) + { + if (controllerMap != null) + { + Player player = ReInput.players.GetPlayer(playerId); + if (player != null) + { + SaveControllerMap(player, controllerMap); + } + } + } + + public override ControllerMap LoadControllerMap(int playerId, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId) + { + Player player = ReInput.players.GetPlayer(playerId); + if (player == null) + { + return null; + } + return LoadControllerMap(player, controllerIdentifier, categoryId, layoutId); + } + + private int LoadAll() + { + int num = 0; + if (loadControllerAssignments && LoadControllerAssignmentsNow()) + { + num++; + } + IList<Player> allPlayers = ReInput.players.AllPlayers; + for (int i = 0; i < allPlayers.Count; i++) + { + num += LoadPlayerDataNow(allPlayers[i]); + } + return num + LoadAllJoystickCalibrationData(); + } + + private int LoadPlayerDataNow(int playerId) + { + return LoadPlayerDataNow(ReInput.players.GetPlayer(playerId)); + } + + private int LoadPlayerDataNow(Player player) + { + if (player == null) + { + return 0; + } + int num = 0; + num += LoadInputBehaviors(player.id); + num += LoadControllerMaps(player.id, ControllerType.Keyboard, 0); + num += LoadControllerMaps(player.id, ControllerType.Mouse, 0); + foreach (Joystick joystick in player.controllers.Joysticks) + { + num += LoadControllerMaps(player.id, ControllerType.Joystick, joystick.id); + } + RefreshLayoutManager(player.id); + return num; + } + + private int LoadAllJoystickCalibrationData() + { + int num = 0; + IList<Joystick> joysticks = ReInput.controllers.Joysticks; + for (int i = 0; i < joysticks.Count; i++) + { + num += LoadJoystickCalibrationData(joysticks[i]); + } + return num; + } + + private int LoadJoystickCalibrationData(Joystick joystick) + { + if (joystick == null) + { + return 0; + } + if (!joystick.ImportCalibrationMapFromXmlString(GetJoystickCalibrationMapXml(joystick))) + { + return 0; + } + return 1; + } + + private int LoadJoystickCalibrationData(int joystickId) + { + return LoadJoystickCalibrationData(ReInput.controllers.GetJoystick(joystickId)); + } + + private int LoadJoystickData(int joystickId) + { + int num = 0; + IList<Player> allPlayers = ReInput.players.AllPlayers; + for (int i = 0; i < allPlayers.Count; i++) + { + Player player = allPlayers[i]; + if (player.controllers.ContainsController(ControllerType.Joystick, joystickId)) + { + num += LoadControllerMaps(player.id, ControllerType.Joystick, joystickId); + RefreshLayoutManager(player.id); + } + } + return num + LoadJoystickCalibrationData(joystickId); + } + + private int LoadControllerDataNow(int playerId, ControllerType controllerType, int controllerId) + { + int num = 0 + LoadControllerMaps(playerId, controllerType, controllerId); + RefreshLayoutManager(playerId); + return num + LoadControllerDataNow(controllerType, controllerId); + } + + private int LoadControllerDataNow(ControllerType controllerType, int controllerId) + { + int num = 0; + if (controllerType == ControllerType.Joystick) + { + num += LoadJoystickCalibrationData(controllerId); + } + return num; + } + + private int LoadControllerMaps(int playerId, ControllerType controllerType, int controllerId) + { + int num = 0; + Player player = ReInput.players.GetPlayer(playerId); + if (player == null) + { + return num; + } + Controller controller = ReInput.controllers.GetController(controllerType, controllerId); + if (controller == null) + { + return num; + } + IList<InputMapCategory> mapCategories = ReInput.mapping.MapCategories; + for (int i = 0; i < mapCategories.Count; i++) + { + InputMapCategory inputMapCategory = mapCategories[i]; + if (!inputMapCategory.userAssignable) + { + continue; + } + IList<InputLayout> list = ReInput.mapping.MapLayouts(controller.type); + for (int j = 0; j < list.Count; j++) + { + InputLayout inputLayout = list[j]; + ControllerMap controllerMap = LoadControllerMap(player, controller.identifier, inputMapCategory.id, inputLayout.id); + if (controllerMap != null) + { + player.controllers.maps.AddMap(controller, controllerMap); + num++; + } + } + } + return num; + } + + private ControllerMap LoadControllerMap(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId) + { + if (player == null) + { + return null; + } + string controllerMapXml = GetControllerMapXml(player, controllerIdentifier, categoryId, layoutId); + if (string.IsNullOrEmpty(controllerMapXml)) + { + return null; + } + ControllerMap controllerMap = ControllerMap.CreateFromXml(controllerIdentifier.controllerType, controllerMapXml); + if (controllerMap == null) + { + return null; + } + List<int> controllerMapKnownActionIds = GetControllerMapKnownActionIds(player, controllerIdentifier, categoryId, layoutId); + AddDefaultMappingsForNewActions(controllerIdentifier, controllerMap, controllerMapKnownActionIds); + return controllerMap; + } + + private int LoadInputBehaviors(int playerId) + { + Player player = ReInput.players.GetPlayer(playerId); + if (player == null) + { + return 0; + } + int num = 0; + IList<InputBehavior> inputBehaviors = ReInput.mapping.GetInputBehaviors(player.id); + for (int i = 0; i < inputBehaviors.Count; i++) + { + num += LoadInputBehaviorNow(player, inputBehaviors[i]); + } + return num; + } + + private int LoadInputBehaviorNow(int playerId, int behaviorId) + { + Player player = ReInput.players.GetPlayer(playerId); + if (player == null) + { + return 0; + } + InputBehavior inputBehavior = ReInput.mapping.GetInputBehavior(playerId, behaviorId); + if (inputBehavior == null) + { + return 0; + } + return LoadInputBehaviorNow(player, inputBehavior); + } + + private int LoadInputBehaviorNow(Player player, InputBehavior inputBehavior) + { + if (player == null || inputBehavior == null) + { + return 0; + } + string inputBehaviorXml = GetInputBehaviorXml(player, inputBehavior.id); + if (inputBehaviorXml == null || inputBehaviorXml == string.Empty) + { + return 0; + } + if (!inputBehavior.ImportXmlString(inputBehaviorXml)) + { + return 0; + } + return 1; + } + + private bool LoadControllerAssignmentsNow() + { + try + { + ControllerAssignmentSaveInfo controllerAssignmentSaveInfo = LoadControllerAssignmentData(); + if (controllerAssignmentSaveInfo == null) + { + return false; + } + if (loadKeyboardAssignments || loadMouseAssignments) + { + LoadKeyboardAndMouseAssignmentsNow(controllerAssignmentSaveInfo); + } + if (loadJoystickAssignments) + { + LoadJoystickAssignmentsNow(controllerAssignmentSaveInfo); + } + } + catch + { + } + return true; + } + + private bool LoadKeyboardAndMouseAssignmentsNow(ControllerAssignmentSaveInfo data) + { + try + { + if (data == null && (data = LoadControllerAssignmentData()) == null) + { + return false; + } + foreach (Player allPlayer in ReInput.players.AllPlayers) + { + if (data.ContainsPlayer(allPlayer.id)) + { + ControllerAssignmentSaveInfo.PlayerInfo playerInfo = data.players[data.IndexOfPlayer(allPlayer.id)]; + if (loadKeyboardAssignments) + { + allPlayer.controllers.hasKeyboard = playerInfo.hasKeyboard; + } + if (loadMouseAssignments) + { + allPlayer.controllers.hasMouse = playerInfo.hasMouse; + } + } + } + } + catch + { + } + return true; + } + + private bool LoadJoystickAssignmentsNow(ControllerAssignmentSaveInfo data) + { + try + { + if (ReInput.controllers.joystickCount == 0) + { + return false; + } + if (data == null && (data = LoadControllerAssignmentData()) == null) + { + return false; + } + foreach (Player allPlayer in ReInput.players.AllPlayers) + { + allPlayer.controllers.ClearControllersOfType(ControllerType.Joystick); + } + List<JoystickAssignmentHistoryInfo> list = (loadJoystickAssignments ? new List<JoystickAssignmentHistoryInfo>() : null); + foreach (Player allPlayer2 in ReInput.players.AllPlayers) + { + if (!data.ContainsPlayer(allPlayer2.id)) + { + continue; + } + ControllerAssignmentSaveInfo.PlayerInfo playerInfo = data.players[data.IndexOfPlayer(allPlayer2.id)]; + for (int i = 0; i < playerInfo.joystickCount; i++) + { + ControllerAssignmentSaveInfo.JoystickInfo joystickInfo2 = playerInfo.joysticks[i]; + if (joystickInfo2 == null) + { + continue; + } + Joystick joystick = FindJoystickPrecise(joystickInfo2); + if (joystick != null) + { + if (list.Find((JoystickAssignmentHistoryInfo x) => x.joystick == joystick) == null) + { + list.Add(new JoystickAssignmentHistoryInfo(joystick, joystickInfo2.id)); + } + allPlayer2.controllers.AddController(joystick, removeFromOtherPlayers: false); + } + } + } + if (allowImpreciseJoystickAssignmentMatching) + { + foreach (Player allPlayer3 in ReInput.players.AllPlayers) + { + if (!data.ContainsPlayer(allPlayer3.id)) + { + continue; + } + ControllerAssignmentSaveInfo.PlayerInfo playerInfo2 = data.players[data.IndexOfPlayer(allPlayer3.id)]; + for (int j = 0; j < playerInfo2.joystickCount; j++) + { + ControllerAssignmentSaveInfo.JoystickInfo joystickInfo = playerInfo2.joysticks[j]; + if (joystickInfo == null) + { + continue; + } + Joystick joystick2 = null; + int num = list.FindIndex((JoystickAssignmentHistoryInfo x) => x.oldJoystickId == joystickInfo.id); + if (num >= 0) + { + joystick2 = list[num].joystick; + } + else + { + if (!TryFindJoysticksImprecise(joystickInfo, out var matches)) + { + continue; + } + foreach (Joystick match in matches) + { + if (list.Find((JoystickAssignmentHistoryInfo x) => x.joystick == match) == null) + { + joystick2 = match; + break; + } + } + if (joystick2 == null) + { + continue; + } + list.Add(new JoystickAssignmentHistoryInfo(joystick2, joystickInfo.id)); + } + allPlayer3.controllers.AddController(joystick2, removeFromOtherPlayers: false); + } + } + } + } + catch + { + } + if (ReInput.configuration.autoAssignJoysticks) + { + ReInput.controllers.AutoAssignJoysticks(); + } + return true; + } + + private ControllerAssignmentSaveInfo LoadControllerAssignmentData() + { + try + { + if (!PlayerPrefs.HasKey(playerPrefsKey_controllerAssignments)) + { + return null; + } + string @string = PlayerPrefs.GetString(playerPrefsKey_controllerAssignments); + if (string.IsNullOrEmpty(@string)) + { + return null; + } + ControllerAssignmentSaveInfo controllerAssignmentSaveInfo = JsonParser.FromJson<ControllerAssignmentSaveInfo>(@string); + if (controllerAssignmentSaveInfo == null || controllerAssignmentSaveInfo.playerCount == 0) + { + return null; + } + return controllerAssignmentSaveInfo; + } + catch + { + return null; + } + } + + private IEnumerator LoadJoystickAssignmentsDeferred() + { + deferredJoystickAssignmentLoadPending = true; + yield return new WaitForEndOfFrame(); + if (ReInput.isReady) + { + LoadJoystickAssignmentsNow(null); + SaveControllerAssignments(); + deferredJoystickAssignmentLoadPending = false; + } + } + + private void SaveAll() + { + IList<Player> allPlayers = ReInput.players.AllPlayers; + for (int i = 0; i < allPlayers.Count; i++) + { + SavePlayerDataNow(allPlayers[i]); + } + SaveAllJoystickCalibrationData(); + if (loadControllerAssignments) + { + SaveControllerAssignments(); + } + PlayerPrefs.Save(); + } + + private void SavePlayerDataNow(int playerId) + { + SavePlayerDataNow(ReInput.players.GetPlayer(playerId)); + PlayerPrefs.Save(); + } + + private void SavePlayerDataNow(Player player) + { + if (player != null) + { + PlayerSaveData saveData = player.GetSaveData(userAssignableMapsOnly: true); + SaveInputBehaviors(player, saveData); + SaveControllerMaps(player, saveData); + } + } + + private void SaveAllJoystickCalibrationData() + { + IList<Joystick> joysticks = ReInput.controllers.Joysticks; + for (int i = 0; i < joysticks.Count; i++) + { + SaveJoystickCalibrationData(joysticks[i]); + } + } + + private void SaveJoystickCalibrationData(int joystickId) + { + SaveJoystickCalibrationData(ReInput.controllers.GetJoystick(joystickId)); + } + + private void SaveJoystickCalibrationData(Joystick joystick) + { + if (joystick != null) + { + JoystickCalibrationMapSaveData calibrationMapSaveData = joystick.GetCalibrationMapSaveData(); + PlayerPrefs.SetString(GetJoystickCalibrationMapPlayerPrefsKey(joystick), calibrationMapSaveData.map.ToXmlString()); + } + } + + private void SaveJoystickData(int joystickId) + { + IList<Player> allPlayers = ReInput.players.AllPlayers; + for (int i = 0; i < allPlayers.Count; i++) + { + Player player = allPlayers[i]; + if (player.controllers.ContainsController(ControllerType.Joystick, joystickId)) + { + SaveControllerMaps(player.id, ControllerType.Joystick, joystickId); + } + } + SaveJoystickCalibrationData(joystickId); + } + + private void SaveControllerDataNow(int playerId, ControllerType controllerType, int controllerId) + { + SaveControllerMaps(playerId, controllerType, controllerId); + SaveControllerDataNow(controllerType, controllerId); + PlayerPrefs.Save(); + } + + private void SaveControllerDataNow(ControllerType controllerType, int controllerId) + { + if (controllerType == ControllerType.Joystick) + { + SaveJoystickCalibrationData(controllerId); + } + PlayerPrefs.Save(); + } + + private void SaveControllerMaps(Player player, PlayerSaveData playerSaveData) + { + foreach (ControllerMapSaveData allControllerMapSaveDatum in playerSaveData.AllControllerMapSaveData) + { + SaveControllerMap(player, allControllerMapSaveDatum.map); + } + } + + private void SaveControllerMaps(int playerId, ControllerType controllerType, int controllerId) + { + Player player = ReInput.players.GetPlayer(playerId); + if (player == null || !player.controllers.ContainsController(controllerType, controllerId)) + { + return; + } + ControllerMapSaveData[] mapSaveData = player.controllers.maps.GetMapSaveData(controllerType, controllerId, userAssignableMapsOnly: true); + if (mapSaveData != null) + { + for (int i = 0; i < mapSaveData.Length; i++) + { + SaveControllerMap(player, mapSaveData[i].map); + } + } + } + + private void SaveControllerMap(Player player, ControllerMap controllerMap) + { + PlayerPrefs.SetString(GetControllerMapPlayerPrefsKey(player, controllerMap.controller.identifier, controllerMap.categoryId, controllerMap.layoutId, 2), controllerMap.ToXmlString()); + PlayerPrefs.SetString(GetControllerMapKnownActionIdsPlayerPrefsKey(player, controllerMap.controller.identifier, controllerMap.categoryId, controllerMap.layoutId, 2), allActionIdsString); + } + + private void SaveInputBehaviors(Player player, PlayerSaveData playerSaveData) + { + if (player != null) + { + InputBehavior[] inputBehaviors = playerSaveData.inputBehaviors; + for (int i = 0; i < inputBehaviors.Length; i++) + { + SaveInputBehaviorNow(player, inputBehaviors[i]); + } + } + } + + private void SaveInputBehaviorNow(int playerId, int behaviorId) + { + Player player = ReInput.players.GetPlayer(playerId); + if (player != null) + { + InputBehavior inputBehavior = ReInput.mapping.GetInputBehavior(playerId, behaviorId); + if (inputBehavior != null) + { + SaveInputBehaviorNow(player, inputBehavior); + PlayerPrefs.Save(); + } + } + } + + private void SaveInputBehaviorNow(Player player, InputBehavior inputBehavior) + { + if (player != null && inputBehavior != null) + { + PlayerPrefs.SetString(GetInputBehaviorPlayerPrefsKey(player, inputBehavior.id), inputBehavior.ToXmlString()); + } + } + + private bool SaveControllerAssignments() + { + try + { + ControllerAssignmentSaveInfo controllerAssignmentSaveInfo = new ControllerAssignmentSaveInfo(ReInput.players.allPlayerCount); + for (int i = 0; i < ReInput.players.allPlayerCount; i++) + { + Player player = ReInput.players.AllPlayers[i]; + ControllerAssignmentSaveInfo.PlayerInfo playerInfo = new ControllerAssignmentSaveInfo.PlayerInfo(); + controllerAssignmentSaveInfo.players[i] = playerInfo; + playerInfo.id = player.id; + playerInfo.hasKeyboard = player.controllers.hasKeyboard; + playerInfo.hasMouse = player.controllers.hasMouse; + ControllerAssignmentSaveInfo.JoystickInfo[] array = (playerInfo.joysticks = new ControllerAssignmentSaveInfo.JoystickInfo[player.controllers.joystickCount]); + for (int j = 0; j < player.controllers.joystickCount; j++) + { + Joystick joystick = player.controllers.Joysticks[j]; + ControllerAssignmentSaveInfo.JoystickInfo joystickInfo = new ControllerAssignmentSaveInfo.JoystickInfo(); + joystickInfo.instanceGuid = joystick.deviceInstanceGuid; + joystickInfo.id = joystick.id; + joystickInfo.hardwareIdentifier = joystick.hardwareIdentifier; + array[j] = joystickInfo; + } + } + PlayerPrefs.SetString(playerPrefsKey_controllerAssignments, JsonWriter.ToJson(controllerAssignmentSaveInfo)); + PlayerPrefs.Save(); + } + catch + { + } + return true; + } + + private bool ControllerAssignmentSaveDataExists() + { + if (!PlayerPrefs.HasKey(playerPrefsKey_controllerAssignments)) + { + return false; + } + if (string.IsNullOrEmpty(PlayerPrefs.GetString(playerPrefsKey_controllerAssignments))) + { + return false; + } + return true; + } + + private string GetBasePlayerPrefsKey(Player player) + { + return playerPrefsKeyPrefix + "|playerName=" + player.name; + } + + private string GetControllerMapPlayerPrefsKey(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId, int ppKeyVersion) + { + return string.Concat(GetBasePlayerPrefsKey(player) + "|dataType=ControllerMap", GetControllerMapPlayerPrefsKeyCommonSuffix(player, controllerIdentifier, categoryId, layoutId, ppKeyVersion)); + } + + private string GetControllerMapKnownActionIdsPlayerPrefsKey(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId, int ppKeyVersion) + { + return string.Concat(GetBasePlayerPrefsKey(player) + "|dataType=ControllerMap_KnownActionIds", GetControllerMapPlayerPrefsKeyCommonSuffix(player, controllerIdentifier, categoryId, layoutId, ppKeyVersion)); + } + + private static string GetControllerMapPlayerPrefsKeyCommonSuffix(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId, int ppKeyVersion) + { + string text = ""; + if (ppKeyVersion >= 2) + { + text = text + "|kv=" + ppKeyVersion; + } + text = text + "|controllerMapType=" + GetControllerMapType(controllerIdentifier.controllerType).Name; + text = text + "|categoryId=" + categoryId + "|layoutId=" + layoutId; + if (ppKeyVersion >= 2) + { + text = text + "|hardwareGuid=" + controllerIdentifier.hardwareTypeGuid.ToString(); + if (controllerIdentifier.hardwareTypeGuid == Guid.Empty) + { + text = text + "|hardwareIdentifier=" + controllerIdentifier.hardwareIdentifier; + } + if (controllerIdentifier.controllerType == ControllerType.Joystick) + { + text = text + "|duplicate=" + GetDuplicateIndex(player, controllerIdentifier); + } + } + else + { + text = text + "|hardwareIdentifier=" + controllerIdentifier.hardwareIdentifier; + if (controllerIdentifier.controllerType == ControllerType.Joystick) + { + text = text + "|hardwareGuid=" + controllerIdentifier.hardwareTypeGuid.ToString(); + if (ppKeyVersion >= 1) + { + text = text + "|duplicate=" + GetDuplicateIndex(player, controllerIdentifier); + } + } + } + return text; + } + + private string GetJoystickCalibrationMapPlayerPrefsKey(Joystick joystick) + { + return string.Concat(string.Concat(string.Concat(playerPrefsKeyPrefix + "|dataType=CalibrationMap", "|controllerType=", joystick.type.ToString()), "|hardwareIdentifier=", joystick.hardwareIdentifier), "|hardwareGuid=", joystick.hardwareTypeGuid.ToString()); + } + + private string GetInputBehaviorPlayerPrefsKey(Player player, int inputBehaviorId) + { + return string.Concat(GetBasePlayerPrefsKey(player) + "|dataType=InputBehavior", "|id=", inputBehaviorId.ToString()); + } + + private string GetControllerMapXml(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId) + { + for (int num = 2; num >= 0; num--) + { + string controllerMapPlayerPrefsKey = GetControllerMapPlayerPrefsKey(player, controllerIdentifier, categoryId, layoutId, num); + if (PlayerPrefs.HasKey(controllerMapPlayerPrefsKey)) + { + return PlayerPrefs.GetString(controllerMapPlayerPrefsKey); + } + } + return null; + } + + private List<int> GetControllerMapKnownActionIds(Player player, ControllerIdentifier controllerIdentifier, int categoryId, int layoutId) + { + List<int> list = new List<int>(); + string key = null; + bool flag = false; + for (int num = 2; num >= 0; num--) + { + key = GetControllerMapKnownActionIdsPlayerPrefsKey(player, controllerIdentifier, categoryId, layoutId, num); + if (PlayerPrefs.HasKey(key)) + { + flag = true; + break; + } + } + if (!flag) + { + return list; + } + string @string = PlayerPrefs.GetString(key); + if (string.IsNullOrEmpty(@string)) + { + return list; + } + string[] array = @string.Split(','); + for (int i = 0; i < array.Length; i++) + { + if (!string.IsNullOrEmpty(array[i]) && int.TryParse(array[i], out var result)) + { + list.Add(result); + } + } + return list; + } + + private string GetJoystickCalibrationMapXml(Joystick joystick) + { + string joystickCalibrationMapPlayerPrefsKey = GetJoystickCalibrationMapPlayerPrefsKey(joystick); + if (!PlayerPrefs.HasKey(joystickCalibrationMapPlayerPrefsKey)) + { + return string.Empty; + } + return PlayerPrefs.GetString(joystickCalibrationMapPlayerPrefsKey); + } + + private string GetInputBehaviorXml(Player player, int id) + { + string inputBehaviorPlayerPrefsKey = GetInputBehaviorPlayerPrefsKey(player, id); + if (!PlayerPrefs.HasKey(inputBehaviorPlayerPrefsKey)) + { + return string.Empty; + } + return PlayerPrefs.GetString(inputBehaviorPlayerPrefsKey); + } + + private void AddDefaultMappingsForNewActions(ControllerIdentifier controllerIdentifier, ControllerMap controllerMap, List<int> knownActionIds) + { + if (controllerMap == null || knownActionIds == null || knownActionIds == null || knownActionIds.Count == 0) + { + return; + } + ControllerMap controllerMapInstance = ReInput.mapping.GetControllerMapInstance(controllerIdentifier, controllerMap.categoryId, controllerMap.layoutId); + if (controllerMapInstance == null) + { + return; + } + List<int> list = new List<int>(); + foreach (int allActionId in allActionIds) + { + if (!knownActionIds.Contains(allActionId)) + { + list.Add(allActionId); + } + } + if (list.Count == 0) + { + return; + } + foreach (ActionElementMap allMap in controllerMapInstance.AllMaps) + { + if (list.Contains(allMap.actionId) && !controllerMap.DoesElementAssignmentConflict(allMap)) + { + ElementAssignment elementAssignment = new ElementAssignment(controllerMap.controllerType, allMap.elementType, allMap.elementIdentifierId, allMap.axisRange, allMap.keyCode, allMap.modifierKeyFlags, allMap.actionId, allMap.axisContribution, allMap.invert); + controllerMap.CreateElementMap(elementAssignment); + } + } + } + + private Joystick FindJoystickPrecise(ControllerAssignmentSaveInfo.JoystickInfo joystickInfo) + { + if (joystickInfo == null) + { + return null; + } + if (joystickInfo.instanceGuid == Guid.Empty) + { + return null; + } + IList<Joystick> joysticks = ReInput.controllers.Joysticks; + for (int i = 0; i < joysticks.Count; i++) + { + if (joysticks[i].deviceInstanceGuid == joystickInfo.instanceGuid) + { + return joysticks[i]; + } + } + return null; + } + + private bool TryFindJoysticksImprecise(ControllerAssignmentSaveInfo.JoystickInfo joystickInfo, out List<Joystick> matches) + { + matches = null; + if (joystickInfo == null) + { + return false; + } + if (string.IsNullOrEmpty(joystickInfo.hardwareIdentifier)) + { + return false; + } + IList<Joystick> joysticks = ReInput.controllers.Joysticks; + for (int i = 0; i < joysticks.Count; i++) + { + if (string.Equals(joysticks[i].hardwareIdentifier, joystickInfo.hardwareIdentifier, StringComparison.OrdinalIgnoreCase)) + { + if (matches == null) + { + matches = new List<Joystick>(); + } + matches.Add(joysticks[i]); + } + } + return matches != null; + } + + private static int GetDuplicateIndex(Player player, ControllerIdentifier controllerIdentifier) + { + Controller controller = ReInput.controllers.GetController(controllerIdentifier); + if (controller == null) + { + return 0; + } + int num = 0; + foreach (Controller controller2 in player.controllers.Controllers) + { + if (controller2.type != controller.type) + { + continue; + } + bool flag = false; + if (controller.type == ControllerType.Joystick) + { + if ((controller2 as Joystick).hardwareTypeGuid != controller.hardwareTypeGuid) + { + continue; + } + if (controller.hardwareTypeGuid != Guid.Empty) + { + flag = true; + } + } + if (flag || !(controller2.hardwareIdentifier != controller.hardwareIdentifier)) + { + if (controller2 == controller) + { + return num; + } + num++; + } + } + return num; + } + + private void RefreshLayoutManager(int playerId) + { + ReInput.players.GetPlayer(playerId)?.controllers.maps.layoutManager.Apply(); + } + + private static Type GetControllerMapType(ControllerType controllerType) + { + switch (controllerType) + { + case ControllerType.Custom: + return typeof(CustomControllerMap); + case ControllerType.Joystick: + return typeof(JoystickMap); + case ControllerType.Keyboard: + return typeof(KeyboardMap); + case ControllerType.Mouse: + return typeof(MouseMap); + default: + Debug.LogWarning("Rewired: Unknown ControllerType " + controllerType); + return null; + } + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIEffect.cs b/Thronefall_v1.0/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIEffect.cs new file mode 100644 index 0000000..695aa76 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIEffect.cs @@ -0,0 +1,57 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace Rewired.Demos.GamepadTemplateUI; + +[RequireComponent(typeof(Image))] +public class ControllerUIEffect : MonoBehaviour +{ + [SerializeField] + private Color _highlightColor = Color.white; + + private Image _image; + + private Color _color; + + private Color _origColor; + + private bool _isActive; + + private float _highlightAmount; + + private void Awake() + { + _image = GetComponent<Image>(); + _origColor = _image.color; + _color = _origColor; + } + + public void Activate(float amount) + { + amount = Mathf.Clamp01(amount); + if (!_isActive || amount != _highlightAmount) + { + _highlightAmount = amount; + _color = Color.Lerp(_origColor, _highlightColor, _highlightAmount); + _isActive = true; + RedrawImage(); + } + } + + public void Deactivate() + { + if (_isActive) + { + _color = _origColor; + _highlightAmount = 0f; + _isActive = false; + RedrawImage(); + } + } + + private void RedrawImage() + { + _image.color = _color; + _image.enabled = _isActive; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIElement.cs b/Thronefall_v1.0/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIElement.cs new file mode 100644 index 0000000..b59e6f8 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos.GamepadTemplateUI/ControllerUIElement.cs @@ -0,0 +1,186 @@ +using UnityEngine; +using UnityEngine.UI; + +namespace Rewired.Demos.GamepadTemplateUI; + +[RequireComponent(typeof(Image))] +public class ControllerUIElement : MonoBehaviour +{ + [SerializeField] + private Color _highlightColor = Color.white; + + [SerializeField] + private ControllerUIEffect _positiveUIEffect; + + [SerializeField] + private ControllerUIEffect _negativeUIEffect; + + [SerializeField] + private Text _label; + + [SerializeField] + private Text _positiveLabel; + + [SerializeField] + private Text _negativeLabel; + + [SerializeField] + private ControllerUIElement[] _childElements = new ControllerUIElement[0]; + + private Image _image; + + private Color _color; + + private Color _origColor; + + private bool _isActive; + + private float _highlightAmount; + + private bool hasEffects + { + get + { + if (!(_positiveUIEffect != null)) + { + return _negativeUIEffect != null; + } + return true; + } + } + + private void Awake() + { + _image = GetComponent<Image>(); + _origColor = _image.color; + _color = _origColor; + ClearLabels(); + } + + public void Activate(float amount) + { + amount = Mathf.Clamp(amount, -1f, 1f); + if (hasEffects) + { + if (amount < 0f && _negativeUIEffect != null) + { + _negativeUIEffect.Activate(Mathf.Abs(amount)); + } + if (amount > 0f && _positiveUIEffect != null) + { + _positiveUIEffect.Activate(Mathf.Abs(amount)); + } + } + else + { + if (_isActive && amount == _highlightAmount) + { + return; + } + _highlightAmount = amount; + _color = Color.Lerp(_origColor, _highlightColor, _highlightAmount); + } + _isActive = true; + RedrawImage(); + if (_childElements.Length == 0) + { + return; + } + for (int i = 0; i < _childElements.Length; i++) + { + if (!(_childElements[i] == null)) + { + _childElements[i].Activate(amount); + } + } + } + + public void Deactivate() + { + if (!_isActive) + { + return; + } + _color = _origColor; + _highlightAmount = 0f; + if (_positiveUIEffect != null) + { + _positiveUIEffect.Deactivate(); + } + if (_negativeUIEffect != null) + { + _negativeUIEffect.Deactivate(); + } + _isActive = false; + RedrawImage(); + if (_childElements.Length == 0) + { + return; + } + for (int i = 0; i < _childElements.Length; i++) + { + if (!(_childElements[i] == null)) + { + _childElements[i].Deactivate(); + } + } + } + + public void SetLabel(string text, AxisRange labelType) + { + Text text2 = labelType switch + { + AxisRange.Full => _label, + AxisRange.Positive => _positiveLabel, + AxisRange.Negative => _negativeLabel, + _ => null, + }; + if (text2 != null) + { + text2.text = text; + } + if (_childElements.Length == 0) + { + return; + } + for (int i = 0; i < _childElements.Length; i++) + { + if (!(_childElements[i] == null)) + { + _childElements[i].SetLabel(text, labelType); + } + } + } + + public void ClearLabels() + { + if (_label != null) + { + _label.text = string.Empty; + } + if (_positiveLabel != null) + { + _positiveLabel.text = string.Empty; + } + if (_negativeLabel != null) + { + _negativeLabel.text = string.Empty; + } + if (_childElements.Length == 0) + { + return; + } + for (int i = 0; i < _childElements.Length; i++) + { + if (!(_childElements[i] == null)) + { + _childElements[i].ClearLabels(); + } + } + } + + private void RedrawImage() + { + _image.color = _color; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos.GamepadTemplateUI/GamepadTemplateUI.cs b/Thronefall_v1.0/Rewired/Rewired.Demos.GamepadTemplateUI/GamepadTemplateUI.cs new file mode 100644 index 0000000..e56617c --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos.GamepadTemplateUI/GamepadTemplateUI.cs @@ -0,0 +1,417 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace Rewired.Demos.GamepadTemplateUI; + +public class GamepadTemplateUI : MonoBehaviour +{ + private class Stick + { + private RectTransform _transform; + + private Vector2 _origPosition; + + private int _xAxisElementId = -1; + + private int _yAxisElementId = -1; + + public Vector2 position + { + get + { + if (!(_transform != null)) + { + return Vector2.zero; + } + return _transform.anchoredPosition - _origPosition; + } + set + { + if (!(_transform == null)) + { + _transform.anchoredPosition = _origPosition + value; + } + } + } + + public Stick(RectTransform transform, int xAxisElementId, int yAxisElementId) + { + if (!(transform == null)) + { + _transform = transform; + _origPosition = _transform.anchoredPosition; + _xAxisElementId = xAxisElementId; + _yAxisElementId = yAxisElementId; + } + } + + public void Reset() + { + if (!(_transform == null)) + { + _transform.anchoredPosition = _origPosition; + } + } + + public bool ContainsElement(int elementId) + { + if (_transform == null) + { + return false; + } + if (elementId != _xAxisElementId) + { + return elementId == _yAxisElementId; + } + return true; + } + + public void SetAxisPosition(int elementId, float value) + { + if (!(_transform == null)) + { + Vector2 vector = position; + if (elementId == _xAxisElementId) + { + vector.x = value; + } + else if (elementId == _yAxisElementId) + { + vector.y = value; + } + position = vector; + } + } + } + + private class UIElement + { + public int id; + + public ControllerUIElement element; + + public UIElement(int id, ControllerUIElement element) + { + this.id = id; + this.element = element; + } + } + + private const float stickRadius = 20f; + + public int playerId; + + [SerializeField] + private RectTransform leftStick; + + [SerializeField] + private RectTransform rightStick; + + [SerializeField] + private ControllerUIElement leftStickX; + + [SerializeField] + private ControllerUIElement leftStickY; + + [SerializeField] + private ControllerUIElement leftStickButton; + + [SerializeField] + private ControllerUIElement rightStickX; + + [SerializeField] + private ControllerUIElement rightStickY; + + [SerializeField] + private ControllerUIElement rightStickButton; + + [SerializeField] + private ControllerUIElement actionBottomRow1; + + [SerializeField] + private ControllerUIElement actionBottomRow2; + + [SerializeField] + private ControllerUIElement actionBottomRow3; + + [SerializeField] + private ControllerUIElement actionTopRow1; + + [SerializeField] + private ControllerUIElement actionTopRow2; + + [SerializeField] + private ControllerUIElement actionTopRow3; + + [SerializeField] + private ControllerUIElement leftShoulder; + + [SerializeField] + private ControllerUIElement leftTrigger; + + [SerializeField] + private ControllerUIElement rightShoulder; + + [SerializeField] + private ControllerUIElement rightTrigger; + + [SerializeField] + private ControllerUIElement center1; + + [SerializeField] + private ControllerUIElement center2; + + [SerializeField] + private ControllerUIElement center3; + + [SerializeField] + private ControllerUIElement dPadUp; + + [SerializeField] + private ControllerUIElement dPadRight; + + [SerializeField] + private ControllerUIElement dPadDown; + + [SerializeField] + private ControllerUIElement dPadLeft; + + private UIElement[] _uiElementsArray; + + private Dictionary<int, ControllerUIElement> _uiElements = new Dictionary<int, ControllerUIElement>(); + + private IList<ControllerTemplateElementTarget> _tempTargetList = new List<ControllerTemplateElementTarget>(2); + + private Stick[] _sticks; + + private Player player => ReInput.players.GetPlayer(playerId); + + private void Awake() + { + _uiElementsArray = new UIElement[23] + { + new UIElement(0, leftStickX), + new UIElement(1, leftStickY), + new UIElement(17, leftStickButton), + new UIElement(2, rightStickX), + new UIElement(3, rightStickY), + new UIElement(18, rightStickButton), + new UIElement(4, actionBottomRow1), + new UIElement(5, actionBottomRow2), + new UIElement(6, actionBottomRow3), + new UIElement(7, actionTopRow1), + new UIElement(8, actionTopRow2), + new UIElement(9, actionTopRow3), + new UIElement(14, center1), + new UIElement(15, center2), + new UIElement(16, center3), + new UIElement(19, dPadUp), + new UIElement(20, dPadRight), + new UIElement(21, dPadDown), + new UIElement(22, dPadLeft), + new UIElement(10, leftShoulder), + new UIElement(11, leftTrigger), + new UIElement(12, rightShoulder), + new UIElement(13, rightTrigger) + }; + for (int i = 0; i < _uiElementsArray.Length; i++) + { + _uiElements.Add(_uiElementsArray[i].id, _uiElementsArray[i].element); + } + _sticks = new Stick[2] + { + new Stick(leftStick, 0, 1), + new Stick(rightStick, 2, 3) + }; + ReInput.ControllerConnectedEvent += OnControllerConnected; + ReInput.ControllerDisconnectedEvent += OnControllerDisconnected; + } + + private void Start() + { + if (ReInput.isReady) + { + DrawLabels(); + } + } + + private void OnDestroy() + { + ReInput.ControllerConnectedEvent -= OnControllerConnected; + ReInput.ControllerDisconnectedEvent -= OnControllerDisconnected; + } + + private void Update() + { + if (ReInput.isReady) + { + DrawActiveElements(); + } + } + + private void DrawActiveElements() + { + for (int i = 0; i < _uiElementsArray.Length; i++) + { + _uiElementsArray[i].element.Deactivate(); + } + for (int j = 0; j < _sticks.Length; j++) + { + _sticks[j].Reset(); + } + IList<InputAction> actions = ReInput.mapping.Actions; + for (int k = 0; k < actions.Count; k++) + { + ActivateElements(player, actions[k].id); + } + } + + private void ActivateElements(Player player, int actionId) + { + float axis = player.GetAxis(actionId); + if (axis == 0f) + { + return; + } + IList<InputActionSourceData> currentInputSources = player.GetCurrentInputSources(actionId); + for (int i = 0; i < currentInputSources.Count; i++) + { + InputActionSourceData inputActionSourceData = currentInputSources[i]; + IGamepadTemplate template = inputActionSourceData.controller.GetTemplate<IGamepadTemplate>(); + if (template == null) + { + continue; + } + template.GetElementTargets(inputActionSourceData.actionElementMap, _tempTargetList); + for (int j = 0; j < _tempTargetList.Count; j++) + { + ControllerTemplateElementTarget controllerTemplateElementTarget = _tempTargetList[j]; + int id = controllerTemplateElementTarget.element.id; + ControllerUIElement controllerUIElement = _uiElements[id]; + if (controllerTemplateElementTarget.elementType == ControllerTemplateElementType.Axis) + { + controllerUIElement.Activate(axis); + } + else if (controllerTemplateElementTarget.elementType == ControllerTemplateElementType.Button && (player.GetButton(actionId) || player.GetNegativeButton(actionId))) + { + controllerUIElement.Activate(1f); + } + GetStick(id)?.SetAxisPosition(id, axis * 20f); + } + } + } + + private void DrawLabels() + { + for (int i = 0; i < _uiElementsArray.Length; i++) + { + _uiElementsArray[i].element.ClearLabels(); + } + IList<InputAction> actions = ReInput.mapping.Actions; + for (int j = 0; j < actions.Count; j++) + { + DrawLabels(player, actions[j]); + } + } + + private void DrawLabels(Player player, InputAction action) + { + Controller firstControllerWithTemplate = player.controllers.GetFirstControllerWithTemplate<IGamepadTemplate>(); + if (firstControllerWithTemplate == null) + { + return; + } + IGamepadTemplate template = firstControllerWithTemplate.GetTemplate<IGamepadTemplate>(); + ControllerMap map = player.controllers.maps.GetMap(firstControllerWithTemplate, "Default", "Default"); + if (map != null) + { + for (int i = 0; i < _uiElementsArray.Length; i++) + { + ControllerUIElement element = _uiElementsArray[i].element; + int id = _uiElementsArray[i].id; + IControllerTemplateElement element2 = template.GetElement(id); + DrawLabel(element, action, map, template, element2); + } + } + } + + private void DrawLabel(ControllerUIElement uiElement, InputAction action, ControllerMap controllerMap, IControllerTemplate template, IControllerTemplateElement element) + { + if (element.source == null) + { + return; + } + if (element.source.type == ControllerTemplateElementSourceType.Axis) + { + IControllerTemplateAxisSource controllerTemplateAxisSource = element.source as IControllerTemplateAxisSource; + ActionElementMap firstElementMapWithElementTarget; + if (controllerTemplateAxisSource.splitAxis) + { + firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(controllerTemplateAxisSource.positiveTarget, action.id, skipDisabledMaps: true); + if (firstElementMapWithElementTarget != null) + { + uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Positive); + } + firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(controllerTemplateAxisSource.negativeTarget, action.id, skipDisabledMaps: true); + if (firstElementMapWithElementTarget != null) + { + uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Negative); + } + return; + } + firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(controllerTemplateAxisSource.fullTarget, action.id, skipDisabledMaps: true); + if (firstElementMapWithElementTarget != null) + { + uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Full); + return; + } + firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(new ControllerElementTarget(controllerTemplateAxisSource.fullTarget) + { + axisRange = AxisRange.Positive + }, action.id, skipDisabledMaps: true); + if (firstElementMapWithElementTarget != null) + { + uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Positive); + } + firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(new ControllerElementTarget(controllerTemplateAxisSource.fullTarget) + { + axisRange = AxisRange.Negative + }, action.id, skipDisabledMaps: true); + if (firstElementMapWithElementTarget != null) + { + uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Negative); + } + } + else if (element.source.type == ControllerTemplateElementSourceType.Button) + { + IControllerTemplateButtonSource controllerTemplateButtonSource = element.source as IControllerTemplateButtonSource; + ActionElementMap firstElementMapWithElementTarget = controllerMap.GetFirstElementMapWithElementTarget(controllerTemplateButtonSource.target, action.id, skipDisabledMaps: true); + if (firstElementMapWithElementTarget != null) + { + uiElement.SetLabel(firstElementMapWithElementTarget.actionDescriptiveName, AxisRange.Full); + } + } + } + + private Stick GetStick(int elementId) + { + for (int i = 0; i < _sticks.Length; i++) + { + if (_sticks[i].ContainsElement(elementId)) + { + return _sticks[i]; + } + } + return null; + } + + private void OnControllerConnected(ControllerStatusChangedEventArgs args) + { + DrawLabels(); + } + + private void OnControllerDisconnected(ControllerStatusChangedEventArgs args) + { + DrawLabels(); + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/Bullet.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/Bullet.cs new file mode 100644 index 0000000..bb521c8 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/Bullet.cs @@ -0,0 +1,30 @@ +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class Bullet : MonoBehaviour +{ + public float lifeTime = 3f; + + private bool die; + + private float deathTime; + + private void Start() + { + if (lifeTime > 0f) + { + deathTime = Time.time + lifeTime; + die = true; + } + } + + private void Update() + { + if (die && Time.time >= deathTime) + { + Object.Destroy(base.gameObject); + } + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/ControlRemappingDemo1.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/ControlRemappingDemo1.cs new file mode 100644 index 0000000..b0e4f51 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/ControlRemappingDemo1.cs @@ -0,0 +1,1797 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class ControlRemappingDemo1 : MonoBehaviour +{ + private class ControllerSelection + { + private int _id; + + private int _idPrev; + + private ControllerType _type; + + private ControllerType _typePrev; + + public int id + { + get + { + return _id; + } + set + { + _idPrev = _id; + _id = value; + } + } + + public ControllerType type + { + get + { + return _type; + } + set + { + _typePrev = _type; + _type = value; + } + } + + public int idPrev => _idPrev; + + public ControllerType typePrev => _typePrev; + + public bool hasSelection => _id >= 0; + + public ControllerSelection() + { + Clear(); + } + + public void Set(int id, ControllerType type) + { + this.id = id; + this.type = type; + } + + public void Clear() + { + _id = -1; + _idPrev = -1; + _type = ControllerType.Joystick; + _typePrev = ControllerType.Joystick; + } + } + + private class DialogHelper + { + public enum DialogType + { + None = 0, + JoystickConflict = 1, + ElementConflict = 2, + KeyConflict = 3, + DeleteAssignmentConfirmation = 10, + AssignElement = 11 + } + + private const float openBusyDelay = 0.25f; + + private const float closeBusyDelay = 0.1f; + + private DialogType _type; + + private bool _enabled; + + private float _busyTime; + + private bool _busyTimerRunning; + + private Action<int> drawWindowDelegate; + + private GUI.WindowFunction drawWindowFunction; + + private WindowProperties windowProperties; + + private int currentActionId; + + private Action<int, UserResponse> resultCallback; + + private float busyTimer + { + get + { + if (!_busyTimerRunning) + { + return 0f; + } + return _busyTime - Time.realtimeSinceStartup; + } + } + + public bool enabled + { + get + { + return _enabled; + } + set + { + if (value) + { + if (_type != 0) + { + StateChanged(0.25f); + } + } + else + { + _enabled = value; + _type = DialogType.None; + StateChanged(0.1f); + } + } + } + + public DialogType type + { + get + { + if (!_enabled) + { + return DialogType.None; + } + return _type; + } + set + { + if (value == DialogType.None) + { + _enabled = false; + StateChanged(0.1f); + } + else + { + _enabled = true; + StateChanged(0.25f); + } + _type = value; + } + } + + public bool busy => _busyTimerRunning; + + public DialogHelper() + { + drawWindowDelegate = DrawWindow; + drawWindowFunction = drawWindowDelegate.Invoke; + } + + public void StartModal(int queueActionId, DialogType type, WindowProperties windowProperties, Action<int, UserResponse> resultCallback) + { + StartModal(queueActionId, type, windowProperties, resultCallback, -1f); + } + + public void StartModal(int queueActionId, DialogType type, WindowProperties windowProperties, Action<int, UserResponse> resultCallback, float openBusyDelay) + { + currentActionId = queueActionId; + this.windowProperties = windowProperties; + this.type = type; + this.resultCallback = resultCallback; + if (openBusyDelay >= 0f) + { + StateChanged(openBusyDelay); + } + } + + public void Update() + { + Draw(); + UpdateTimers(); + } + + public void Draw() + { + if (_enabled) + { + bool flag = GUI.enabled; + GUI.enabled = true; + GUILayout.Window(windowProperties.windowId, windowProperties.rect, drawWindowFunction, windowProperties.title); + GUI.FocusWindow(windowProperties.windowId); + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + } + + public void DrawConfirmButton() + { + DrawConfirmButton("Confirm"); + } + + public void DrawConfirmButton(string title) + { + bool flag = GUI.enabled; + if (busy) + { + GUI.enabled = false; + } + if (GUILayout.Button(title)) + { + Confirm(UserResponse.Confirm); + } + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + + public void DrawConfirmButton(UserResponse response) + { + DrawConfirmButton(response, "Confirm"); + } + + public void DrawConfirmButton(UserResponse response, string title) + { + bool flag = GUI.enabled; + if (busy) + { + GUI.enabled = false; + } + if (GUILayout.Button(title)) + { + Confirm(response); + } + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + + public void DrawCancelButton() + { + DrawCancelButton("Cancel"); + } + + public void DrawCancelButton(string title) + { + bool flag = GUI.enabled; + if (busy) + { + GUI.enabled = false; + } + if (GUILayout.Button(title)) + { + Cancel(); + } + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + + public void Confirm() + { + Confirm(UserResponse.Confirm); + } + + public void Confirm(UserResponse response) + { + resultCallback(currentActionId, response); + Close(); + } + + public void Cancel() + { + resultCallback(currentActionId, UserResponse.Cancel); + Close(); + } + + private void DrawWindow(int windowId) + { + windowProperties.windowDrawDelegate(windowProperties.title, windowProperties.message); + } + + private void UpdateTimers() + { + if (_busyTimerRunning && busyTimer <= 0f) + { + _busyTimerRunning = false; + } + } + + private void StartBusyTimer(float time) + { + _busyTime = time + Time.realtimeSinceStartup; + _busyTimerRunning = true; + } + + private void Close() + { + Reset(); + StateChanged(0.1f); + } + + private void StateChanged(float delay) + { + StartBusyTimer(delay); + } + + private void Reset() + { + _enabled = false; + _type = DialogType.None; + currentActionId = -1; + resultCallback = null; + } + + private void ResetTimers() + { + _busyTimerRunning = false; + } + + public void FullReset() + { + Reset(); + ResetTimers(); + } + } + + private abstract class QueueEntry + { + public enum State + { + Waiting, + Confirmed, + Canceled + } + + private static int uidCounter; + + public int id { get; protected set; } + + public QueueActionType queueActionType { get; protected set; } + + public State state { get; protected set; } + + public UserResponse response { get; protected set; } + + protected static int nextId + { + get + { + int result = uidCounter; + uidCounter++; + return result; + } + } + + public QueueEntry(QueueActionType queueActionType) + { + id = nextId; + this.queueActionType = queueActionType; + } + + public void Confirm(UserResponse response) + { + state = State.Confirmed; + this.response = response; + } + + public void Cancel() + { + state = State.Canceled; + } + } + + private class JoystickAssignmentChange : QueueEntry + { + public int playerId { get; private set; } + + public int joystickId { get; private set; } + + public bool assign { get; private set; } + + public JoystickAssignmentChange(int newPlayerId, int joystickId, bool assign) + : base(QueueActionType.JoystickAssignment) + { + playerId = newPlayerId; + this.joystickId = joystickId; + this.assign = assign; + } + } + + private class ElementAssignmentChange : QueueEntry + { + public ElementAssignmentChangeType changeType { get; set; } + + public InputMapper.Context context { get; private set; } + + public ElementAssignmentChange(ElementAssignmentChangeType changeType, InputMapper.Context context) + : base(QueueActionType.ElementAssignment) + { + this.changeType = changeType; + this.context = context; + } + + public ElementAssignmentChange(ElementAssignmentChange other) + : this(other.changeType, other.context.Clone()) + { + } + } + + private class FallbackJoystickIdentification : QueueEntry + { + public int joystickId { get; private set; } + + public string joystickName { get; private set; } + + public FallbackJoystickIdentification(int joystickId, string joystickName) + : base(QueueActionType.FallbackJoystickIdentification) + { + this.joystickId = joystickId; + this.joystickName = joystickName; + } + } + + private class Calibration : QueueEntry + { + public int selectedElementIdentifierId; + + public bool recording; + + public Player player { get; private set; } + + public ControllerType controllerType { get; private set; } + + public Joystick joystick { get; private set; } + + public CalibrationMap calibrationMap { get; private set; } + + public Calibration(Player player, Joystick joystick, CalibrationMap calibrationMap) + : base(QueueActionType.Calibrate) + { + this.player = player; + this.joystick = joystick; + this.calibrationMap = calibrationMap; + selectedElementIdentifierId = -1; + } + } + + private struct WindowProperties + { + public int windowId; + + public Rect rect; + + public Action<string, string> windowDrawDelegate; + + public string title; + + public string message; + } + + private enum QueueActionType + { + None, + JoystickAssignment, + ElementAssignment, + FallbackJoystickIdentification, + Calibrate + } + + private enum ElementAssignmentChangeType + { + Add, + Replace, + Remove, + ReassignOrRemove, + ConflictCheck + } + + public enum UserResponse + { + Confirm, + Cancel, + Custom1, + Custom2 + } + + private const float defaultModalWidth = 250f; + + private const float defaultModalHeight = 200f; + + private const float assignmentTimeout = 5f; + + private DialogHelper dialog; + + private InputMapper inputMapper = new InputMapper(); + + private InputMapper.ConflictFoundEventData conflictFoundEventData; + + private bool guiState; + + private bool busy; + + private bool pageGUIState; + + private Player selectedPlayer; + + private int selectedMapCategoryId; + + private ControllerSelection selectedController; + + private ControllerMap selectedMap; + + private bool showMenu; + + private bool startListening; + + private Vector2 actionScrollPos; + + private Vector2 calibrateScrollPos; + + private Queue<QueueEntry> actionQueue; + + private bool setupFinished; + + [NonSerialized] + private bool initialized; + + private bool isCompiling; + + private GUIStyle style_wordWrap; + + private GUIStyle style_centeredBox; + + private void Awake() + { + inputMapper.options.timeout = 5f; + inputMapper.options.ignoreMouseXAxis = true; + inputMapper.options.ignoreMouseYAxis = true; + Initialize(); + } + + private void OnEnable() + { + Subscribe(); + } + + private void OnDisable() + { + Unsubscribe(); + } + + private void Initialize() + { + dialog = new DialogHelper(); + actionQueue = new Queue<QueueEntry>(); + selectedController = new ControllerSelection(); + ReInput.ControllerConnectedEvent += JoystickConnected; + ReInput.ControllerPreDisconnectEvent += JoystickPreDisconnect; + ReInput.ControllerDisconnectedEvent += JoystickDisconnected; + ResetAll(); + initialized = true; + ReInput.userDataStore.Load(); + if (ReInput.unityJoystickIdentificationRequired) + { + IdentifyAllJoysticks(); + } + } + + private void Setup() + { + if (!setupFinished) + { + style_wordWrap = new GUIStyle(GUI.skin.label); + style_wordWrap.wordWrap = true; + style_centeredBox = new GUIStyle(GUI.skin.box); + style_centeredBox.alignment = TextAnchor.MiddleCenter; + setupFinished = true; + } + } + + private void Subscribe() + { + Unsubscribe(); + inputMapper.ConflictFoundEvent += OnConflictFound; + inputMapper.StoppedEvent += OnStopped; + } + + private void Unsubscribe() + { + inputMapper.RemoveAllEventListeners(); + } + + public void OnGUI() + { + if (initialized) + { + Setup(); + HandleMenuControl(); + if (!showMenu) + { + DrawInitialScreen(); + return; + } + SetGUIStateStart(); + ProcessQueue(); + DrawPage(); + ShowDialog(); + SetGUIStateEnd(); + busy = false; + } + } + + private void HandleMenuControl() + { + if (!dialog.enabled && Event.current.type == EventType.Layout && ReInput.players.GetSystemPlayer().GetButtonDown("Menu")) + { + if (showMenu) + { + ReInput.userDataStore.Save(); + Close(); + } + else + { + Open(); + } + } + } + + private void Close() + { + ClearWorkingVars(); + showMenu = false; + } + + private void Open() + { + showMenu = true; + } + + private void DrawInitialScreen() + { + ActionElementMap firstElementMapWithAction = ReInput.players.GetSystemPlayer().controllers.maps.GetFirstElementMapWithAction("Menu", skipDisabledMaps: true); + GUIContent content = ((firstElementMapWithAction == null) ? new GUIContent("There is no element assigned to open the menu!") : new GUIContent("Press " + firstElementMapWithAction.elementIdentifierName + " to open the menu.")); + GUILayout.BeginArea(GetScreenCenteredRect(300f, 50f)); + GUILayout.Box(content, style_centeredBox, GUILayout.ExpandHeight(expand: true), GUILayout.ExpandWidth(expand: true)); + GUILayout.EndArea(); + } + + private void DrawPage() + { + if (GUI.enabled != pageGUIState) + { + GUI.enabled = pageGUIState; + } + GUILayout.BeginArea(new Rect(((float)Screen.width - (float)Screen.width * 0.9f) * 0.5f, ((float)Screen.height - (float)Screen.height * 0.9f) * 0.5f, (float)Screen.width * 0.9f, (float)Screen.height * 0.9f)); + DrawPlayerSelector(); + DrawJoystickSelector(); + DrawMouseAssignment(); + DrawControllerSelector(); + DrawCalibrateButton(); + DrawMapCategories(); + actionScrollPos = GUILayout.BeginScrollView(actionScrollPos); + DrawCategoryActions(); + GUILayout.EndScrollView(); + GUILayout.EndArea(); + } + + private void DrawPlayerSelector() + { + if (ReInput.players.allPlayerCount == 0) + { + GUILayout.Label("There are no players."); + return; + } + GUILayout.Space(15f); + GUILayout.Label("Players:"); + GUILayout.BeginHorizontal(); + foreach (Player player in ReInput.players.GetPlayers(includeSystemPlayer: true)) + { + if (selectedPlayer == null) + { + selectedPlayer = player; + } + bool flag = ((player == selectedPlayer) ? true : false); + bool flag2 = GUILayout.Toggle(flag, (player.descriptiveName != string.Empty) ? player.descriptiveName : player.name, "Button", GUILayout.ExpandWidth(expand: false)); + if (flag2 != flag && flag2) + { + selectedPlayer = player; + selectedController.Clear(); + selectedMapCategoryId = -1; + } + } + GUILayout.EndHorizontal(); + } + + private void DrawMouseAssignment() + { + bool flag = GUI.enabled; + if (selectedPlayer == null) + { + GUI.enabled = false; + } + GUILayout.Space(15f); + GUILayout.Label("Assign Mouse:"); + GUILayout.BeginHorizontal(); + bool flag2 = ((selectedPlayer != null && selectedPlayer.controllers.hasMouse) ? true : false); + bool flag3 = GUILayout.Toggle(flag2, "Assign Mouse", "Button", GUILayout.ExpandWidth(expand: false)); + if (flag3 != flag2) + { + if (flag3) + { + selectedPlayer.controllers.hasMouse = true; + foreach (Player player in ReInput.players.Players) + { + if (player != selectedPlayer) + { + player.controllers.hasMouse = false; + } + } + } + else + { + selectedPlayer.controllers.hasMouse = false; + } + } + GUILayout.EndHorizontal(); + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + + private void DrawJoystickSelector() + { + bool flag = GUI.enabled; + if (selectedPlayer == null) + { + GUI.enabled = false; + } + GUILayout.Space(15f); + GUILayout.Label("Assign Joysticks:"); + GUILayout.BeginHorizontal(); + bool flag2 = ((selectedPlayer == null || selectedPlayer.controllers.joystickCount == 0) ? true : false); + bool flag3 = GUILayout.Toggle(flag2, "None", "Button", GUILayout.ExpandWidth(expand: false)); + if (flag3 != flag2) + { + selectedPlayer.controllers.ClearControllersOfType(ControllerType.Joystick); + ControllerSelectionChanged(); + } + if (selectedPlayer != null) + { + foreach (Joystick joystick in ReInput.controllers.Joysticks) + { + flag2 = selectedPlayer.controllers.ContainsController(joystick); + flag3 = GUILayout.Toggle(flag2, joystick.name, "Button", GUILayout.ExpandWidth(expand: false)); + if (flag3 != flag2) + { + EnqueueAction(new JoystickAssignmentChange(selectedPlayer.id, joystick.id, flag3)); + } + } + } + GUILayout.EndHorizontal(); + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + + private void DrawControllerSelector() + { + if (selectedPlayer == null) + { + return; + } + bool flag = GUI.enabled; + GUILayout.Space(15f); + GUILayout.Label("Controller to Map:"); + GUILayout.BeginHorizontal(); + if (!selectedController.hasSelection) + { + selectedController.Set(0, ControllerType.Keyboard); + ControllerSelectionChanged(); + } + bool flag2 = selectedController.type == ControllerType.Keyboard; + if (GUILayout.Toggle(flag2, "Keyboard", "Button", GUILayout.ExpandWidth(expand: false)) != flag2) + { + selectedController.Set(0, ControllerType.Keyboard); + ControllerSelectionChanged(); + } + if (!selectedPlayer.controllers.hasMouse) + { + GUI.enabled = false; + } + flag2 = selectedController.type == ControllerType.Mouse; + if (GUILayout.Toggle(flag2, "Mouse", "Button", GUILayout.ExpandWidth(expand: false)) != flag2) + { + selectedController.Set(0, ControllerType.Mouse); + ControllerSelectionChanged(); + } + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + foreach (Joystick joystick in selectedPlayer.controllers.Joysticks) + { + flag2 = selectedController.type == ControllerType.Joystick && selectedController.id == joystick.id; + if (GUILayout.Toggle(flag2, joystick.name, "Button", GUILayout.ExpandWidth(expand: false)) != flag2) + { + selectedController.Set(joystick.id, ControllerType.Joystick); + ControllerSelectionChanged(); + } + } + GUILayout.EndHorizontal(); + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + + private void DrawCalibrateButton() + { + if (selectedPlayer == null) + { + return; + } + bool flag = GUI.enabled; + GUILayout.Space(10f); + Controller controller = (selectedController.hasSelection ? selectedPlayer.controllers.GetController(selectedController.type, selectedController.id) : null); + if (controller == null || selectedController.type != ControllerType.Joystick) + { + GUI.enabled = false; + GUILayout.Button("Select a controller to calibrate", GUILayout.ExpandWidth(expand: false)); + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + else if (GUILayout.Button("Calibrate " + controller.name, GUILayout.ExpandWidth(expand: false)) && controller is Joystick joystick) + { + CalibrationMap calibrationMap = joystick.calibrationMap; + if (calibrationMap != null) + { + EnqueueAction(new Calibration(selectedPlayer, joystick, calibrationMap)); + } + } + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + + private void DrawMapCategories() + { + if (selectedPlayer == null || !selectedController.hasSelection) + { + return; + } + bool flag = GUI.enabled; + GUILayout.Space(15f); + GUILayout.Label("Categories:"); + GUILayout.BeginHorizontal(); + foreach (InputMapCategory userAssignableMapCategory in ReInput.mapping.UserAssignableMapCategories) + { + if (!selectedPlayer.controllers.maps.ContainsMapInCategory(selectedController.type, userAssignableMapCategory.id)) + { + GUI.enabled = false; + } + else if (selectedMapCategoryId < 0) + { + selectedMapCategoryId = userAssignableMapCategory.id; + selectedMap = selectedPlayer.controllers.maps.GetFirstMapInCategory(selectedController.type, selectedController.id, userAssignableMapCategory.id); + } + bool flag2 = ((userAssignableMapCategory.id == selectedMapCategoryId) ? true : false); + if (GUILayout.Toggle(flag2, (userAssignableMapCategory.descriptiveName != string.Empty) ? userAssignableMapCategory.descriptiveName : userAssignableMapCategory.name, "Button", GUILayout.ExpandWidth(expand: false)) != flag2) + { + selectedMapCategoryId = userAssignableMapCategory.id; + selectedMap = selectedPlayer.controllers.maps.GetFirstMapInCategory(selectedController.type, selectedController.id, userAssignableMapCategory.id); + } + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + GUILayout.EndHorizontal(); + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + + private void DrawCategoryActions() + { + if (selectedPlayer == null || selectedMapCategoryId < 0) + { + return; + } + bool flag = GUI.enabled; + if (selectedMap == null) + { + return; + } + GUILayout.Space(15f); + GUILayout.Label("Actions:"); + InputMapCategory mapCategory = ReInput.mapping.GetMapCategory(selectedMapCategoryId); + if (mapCategory == null) + { + return; + } + InputCategory actionCategory = ReInput.mapping.GetActionCategory(mapCategory.name); + if (actionCategory == null) + { + return; + } + float width = 150f; + foreach (InputAction item in ReInput.mapping.ActionsInCategory(actionCategory.id)) + { + string text = ((item.descriptiveName != string.Empty) ? item.descriptiveName : item.name); + if (item.type == InputActionType.Button) + { + GUILayout.BeginHorizontal(); + GUILayout.Label(text, GUILayout.Width(width)); + DrawAddActionMapButton(selectedPlayer.id, item, AxisRange.Positive, selectedController, selectedMap); + foreach (ActionElementMap allMap in selectedMap.AllMaps) + { + if (allMap.actionId == item.id) + { + DrawActionAssignmentButton(selectedPlayer.id, item, AxisRange.Positive, selectedController, selectedMap, allMap); + } + } + GUILayout.EndHorizontal(); + } + else + { + if (item.type != 0) + { + continue; + } + if (selectedController.type != 0) + { + GUILayout.BeginHorizontal(); + GUILayout.Label(text, GUILayout.Width(width)); + DrawAddActionMapButton(selectedPlayer.id, item, AxisRange.Full, selectedController, selectedMap); + foreach (ActionElementMap allMap2 in selectedMap.AllMaps) + { + if (allMap2.actionId == item.id && allMap2.elementType != ControllerElementType.Button && allMap2.axisType != AxisType.Split) + { + DrawActionAssignmentButton(selectedPlayer.id, item, AxisRange.Full, selectedController, selectedMap, allMap2); + DrawInvertButton(selectedPlayer.id, item, Pole.Positive, selectedController, selectedMap, allMap2); + } + } + GUILayout.EndHorizontal(); + } + string text2 = ((item.positiveDescriptiveName != string.Empty) ? item.positiveDescriptiveName : (item.descriptiveName + " +")); + GUILayout.BeginHorizontal(); + GUILayout.Label(text2, GUILayout.Width(width)); + DrawAddActionMapButton(selectedPlayer.id, item, AxisRange.Positive, selectedController, selectedMap); + foreach (ActionElementMap allMap3 in selectedMap.AllMaps) + { + if (allMap3.actionId == item.id && allMap3.axisContribution == Pole.Positive && allMap3.axisType != AxisType.Normal) + { + DrawActionAssignmentButton(selectedPlayer.id, item, AxisRange.Positive, selectedController, selectedMap, allMap3); + } + } + GUILayout.EndHorizontal(); + string text3 = ((item.negativeDescriptiveName != string.Empty) ? item.negativeDescriptiveName : (item.descriptiveName + " -")); + GUILayout.BeginHorizontal(); + GUILayout.Label(text3, GUILayout.Width(width)); + DrawAddActionMapButton(selectedPlayer.id, item, AxisRange.Negative, selectedController, selectedMap); + foreach (ActionElementMap allMap4 in selectedMap.AllMaps) + { + if (allMap4.actionId == item.id && allMap4.axisContribution == Pole.Negative && allMap4.axisType != AxisType.Normal) + { + DrawActionAssignmentButton(selectedPlayer.id, item, AxisRange.Negative, selectedController, selectedMap, allMap4); + } + } + GUILayout.EndHorizontal(); + } + } + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + + private void DrawActionAssignmentButton(int playerId, InputAction action, AxisRange actionRange, ControllerSelection controller, ControllerMap controllerMap, ActionElementMap elementMap) + { + if (GUILayout.Button(elementMap.elementIdentifierName, GUILayout.ExpandWidth(expand: false), GUILayout.MinWidth(30f))) + { + InputMapper.Context context = new InputMapper.Context + { + actionId = action.id, + actionRange = actionRange, + controllerMap = controllerMap, + actionElementMapToReplace = elementMap + }; + EnqueueAction(new ElementAssignmentChange(ElementAssignmentChangeType.ReassignOrRemove, context)); + startListening = true; + } + GUILayout.Space(4f); + } + + private void DrawInvertButton(int playerId, InputAction action, Pole actionAxisContribution, ControllerSelection controller, ControllerMap controllerMap, ActionElementMap elementMap) + { + bool invert = elementMap.invert; + bool flag = GUILayout.Toggle(invert, "Invert", GUILayout.ExpandWidth(expand: false)); + if (flag != invert) + { + elementMap.invert = flag; + } + GUILayout.Space(10f); + } + + private void DrawAddActionMapButton(int playerId, InputAction action, AxisRange actionRange, ControllerSelection controller, ControllerMap controllerMap) + { + if (GUILayout.Button("Add...", GUILayout.ExpandWidth(expand: false))) + { + InputMapper.Context context = new InputMapper.Context + { + actionId = action.id, + actionRange = actionRange, + controllerMap = controllerMap + }; + EnqueueAction(new ElementAssignmentChange(ElementAssignmentChangeType.Add, context)); + startListening = true; + } + GUILayout.Space(10f); + } + + private void ShowDialog() + { + dialog.Update(); + } + + private void DrawModalWindow(string title, string message) + { + if (dialog.enabled) + { + GUILayout.Space(5f); + GUILayout.Label(message, style_wordWrap); + GUILayout.FlexibleSpace(); + GUILayout.BeginHorizontal(); + dialog.DrawConfirmButton("Okay"); + GUILayout.FlexibleSpace(); + dialog.DrawCancelButton(); + GUILayout.EndHorizontal(); + } + } + + private void DrawModalWindow_OkayOnly(string title, string message) + { + if (dialog.enabled) + { + GUILayout.Space(5f); + GUILayout.Label(message, style_wordWrap); + GUILayout.FlexibleSpace(); + GUILayout.BeginHorizontal(); + dialog.DrawConfirmButton("Okay"); + GUILayout.EndHorizontal(); + } + } + + private void DrawElementAssignmentWindow(string title, string message) + { + if (!dialog.enabled) + { + return; + } + GUILayout.Space(5f); + GUILayout.Label(message, style_wordWrap); + GUILayout.FlexibleSpace(); + if (!(actionQueue.Peek() is ElementAssignmentChange elementAssignmentChange)) + { + dialog.Cancel(); + return; + } + float num; + if (!dialog.busy) + { + if (startListening && inputMapper.status == InputMapper.Status.Idle) + { + inputMapper.Start(elementAssignmentChange.context); + startListening = false; + } + if (conflictFoundEventData != null) + { + dialog.Confirm(); + return; + } + num = inputMapper.timeRemaining; + if (num == 0f) + { + dialog.Cancel(); + return; + } + } + else + { + num = inputMapper.options.timeout; + } + GUILayout.Label("Assignment will be canceled in " + (int)Mathf.Ceil(num) + "...", style_wordWrap); + } + + private void DrawElementAssignmentProtectedConflictWindow(string title, string message) + { + if (dialog.enabled) + { + GUILayout.Space(5f); + GUILayout.Label(message, style_wordWrap); + GUILayout.FlexibleSpace(); + if (!(actionQueue.Peek() is ElementAssignmentChange)) + { + dialog.Cancel(); + return; + } + GUILayout.BeginHorizontal(); + dialog.DrawConfirmButton(UserResponse.Custom1, "Add"); + GUILayout.FlexibleSpace(); + dialog.DrawCancelButton(); + GUILayout.EndHorizontal(); + } + } + + private void DrawElementAssignmentNormalConflictWindow(string title, string message) + { + if (dialog.enabled) + { + GUILayout.Space(5f); + GUILayout.Label(message, style_wordWrap); + GUILayout.FlexibleSpace(); + if (!(actionQueue.Peek() is ElementAssignmentChange)) + { + dialog.Cancel(); + return; + } + GUILayout.BeginHorizontal(); + dialog.DrawConfirmButton(UserResponse.Confirm, "Replace"); + GUILayout.FlexibleSpace(); + dialog.DrawConfirmButton(UserResponse.Custom1, "Add"); + GUILayout.FlexibleSpace(); + dialog.DrawCancelButton(); + GUILayout.EndHorizontal(); + } + } + + private void DrawReassignOrRemoveElementAssignmentWindow(string title, string message) + { + if (dialog.enabled) + { + GUILayout.Space(5f); + GUILayout.Label(message, style_wordWrap); + GUILayout.FlexibleSpace(); + GUILayout.BeginHorizontal(); + dialog.DrawConfirmButton("Reassign"); + GUILayout.FlexibleSpace(); + dialog.DrawCancelButton("Remove"); + GUILayout.EndHorizontal(); + } + } + + private void DrawFallbackJoystickIdentificationWindow(string title, string message) + { + if (!dialog.enabled) + { + return; + } + if (!(actionQueue.Peek() is FallbackJoystickIdentification fallbackJoystickIdentification)) + { + dialog.Cancel(); + return; + } + GUILayout.Space(5f); + GUILayout.Label(message, style_wordWrap); + GUILayout.Label("Press any button or axis on \"" + fallbackJoystickIdentification.joystickName + "\" now.", style_wordWrap); + GUILayout.FlexibleSpace(); + if (GUILayout.Button("Skip")) + { + dialog.Cancel(); + } + else if (!dialog.busy && ReInput.controllers.SetUnityJoystickIdFromAnyButtonOrAxisPress(fallbackJoystickIdentification.joystickId, 0.8f, positiveAxesOnly: false)) + { + dialog.Confirm(); + } + } + + private void DrawCalibrationWindow(string title, string message) + { + if (!dialog.enabled) + { + return; + } + if (!(actionQueue.Peek() is Calibration calibration)) + { + dialog.Cancel(); + return; + } + GUILayout.Space(5f); + GUILayout.Label(message, style_wordWrap); + GUILayout.Space(20f); + GUILayout.BeginHorizontal(); + bool flag = GUI.enabled; + GUILayout.BeginVertical(GUILayout.Width(200f)); + calibrateScrollPos = GUILayout.BeginScrollView(calibrateScrollPos); + if (calibration.recording) + { + GUI.enabled = false; + } + IList<ControllerElementIdentifier> axisElementIdentifiers = calibration.joystick.AxisElementIdentifiers; + for (int i = 0; i < axisElementIdentifiers.Count; i++) + { + ControllerElementIdentifier controllerElementIdentifier = axisElementIdentifiers[i]; + bool flag2 = calibration.selectedElementIdentifierId == controllerElementIdentifier.id; + bool flag3 = GUILayout.Toggle(flag2, controllerElementIdentifier.name, "Button", GUILayout.ExpandWidth(expand: false)); + if (flag2 != flag3) + { + calibration.selectedElementIdentifierId = controllerElementIdentifier.id; + } + } + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + GUILayout.EndScrollView(); + GUILayout.EndVertical(); + GUILayout.BeginVertical(GUILayout.Width(200f)); + if (calibration.selectedElementIdentifierId >= 0) + { + float axisRawById = calibration.joystick.GetAxisRawById(calibration.selectedElementIdentifierId); + GUILayout.Label("Raw Value: " + axisRawById); + int axisIndexById = calibration.joystick.GetAxisIndexById(calibration.selectedElementIdentifierId); + AxisCalibration axis = calibration.calibrationMap.GetAxis(axisIndexById); + GUILayout.Label("Calibrated Value: " + calibration.joystick.GetAxisById(calibration.selectedElementIdentifierId)); + GUILayout.Label("Zero: " + axis.calibratedZero); + GUILayout.Label("Min: " + axis.calibratedMin); + GUILayout.Label("Max: " + axis.calibratedMax); + GUILayout.Label("Dead Zone: " + axis.deadZone); + GUILayout.Space(15f); + bool flag4 = GUILayout.Toggle(axis.enabled, "Enabled", "Button", GUILayout.ExpandWidth(expand: false)); + if (axis.enabled != flag4) + { + axis.enabled = flag4; + } + GUILayout.Space(10f); + bool flag5 = GUILayout.Toggle(calibration.recording, "Record Min/Max", "Button", GUILayout.ExpandWidth(expand: false)); + if (flag5 != calibration.recording) + { + if (flag5) + { + axis.calibratedMax = 0f; + axis.calibratedMin = 0f; + } + calibration.recording = flag5; + } + if (calibration.recording) + { + axis.calibratedMin = Mathf.Min(axis.calibratedMin, axisRawById, axis.calibratedMin); + axis.calibratedMax = Mathf.Max(axis.calibratedMax, axisRawById, axis.calibratedMax); + GUI.enabled = false; + } + if (GUILayout.Button("Set Zero", GUILayout.ExpandWidth(expand: false))) + { + axis.calibratedZero = axisRawById; + } + if (GUILayout.Button("Set Dead Zone", GUILayout.ExpandWidth(expand: false))) + { + axis.deadZone = axisRawById; + } + bool flag6 = GUILayout.Toggle(axis.invert, "Invert", "Button", GUILayout.ExpandWidth(expand: false)); + if (axis.invert != flag6) + { + axis.invert = flag6; + } + GUILayout.Space(10f); + if (GUILayout.Button("Reset", GUILayout.ExpandWidth(expand: false))) + { + axis.Reset(); + } + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + else + { + GUILayout.Label("Select an axis to begin."); + } + GUILayout.EndVertical(); + GUILayout.EndHorizontal(); + GUILayout.FlexibleSpace(); + if (calibration.recording) + { + GUI.enabled = false; + } + if (GUILayout.Button("Close")) + { + calibrateScrollPos = default(Vector2); + dialog.Confirm(); + } + if (GUI.enabled != flag) + { + GUI.enabled = flag; + } + } + + private void DialogResultCallback(int queueActionId, UserResponse response) + { + foreach (QueueEntry item in actionQueue) + { + if (item.id == queueActionId) + { + if (response != UserResponse.Cancel) + { + item.Confirm(response); + } + else + { + item.Cancel(); + } + break; + } + } + } + + private Rect GetScreenCenteredRect(float width, float height) + { + return new Rect((float)Screen.width * 0.5f - width * 0.5f, (float)((double)Screen.height * 0.5 - (double)(height * 0.5f)), width, height); + } + + private void EnqueueAction(QueueEntry entry) + { + if (entry != null) + { + busy = true; + GUI.enabled = false; + actionQueue.Enqueue(entry); + } + } + + private void ProcessQueue() + { + if (dialog.enabled || busy || actionQueue.Count == 0) + { + return; + } + while (actionQueue.Count > 0) + { + QueueEntry queueEntry = actionQueue.Peek(); + bool flag = false; + switch (queueEntry.queueActionType) + { + case QueueActionType.JoystickAssignment: + flag = ProcessJoystickAssignmentChange((JoystickAssignmentChange)queueEntry); + break; + case QueueActionType.ElementAssignment: + flag = ProcessElementAssignmentChange((ElementAssignmentChange)queueEntry); + break; + case QueueActionType.FallbackJoystickIdentification: + flag = ProcessFallbackJoystickIdentification((FallbackJoystickIdentification)queueEntry); + break; + case QueueActionType.Calibrate: + flag = ProcessCalibration((Calibration)queueEntry); + break; + } + if (flag) + { + actionQueue.Dequeue(); + continue; + } + break; + } + } + + private bool ProcessJoystickAssignmentChange(JoystickAssignmentChange entry) + { + if (entry.state == QueueEntry.State.Canceled) + { + return true; + } + Player player = ReInput.players.GetPlayer(entry.playerId); + if (player == null) + { + return true; + } + if (!entry.assign) + { + player.controllers.RemoveController(ControllerType.Joystick, entry.joystickId); + ControllerSelectionChanged(); + return true; + } + if (player.controllers.ContainsController(ControllerType.Joystick, entry.joystickId)) + { + return true; + } + if (!ReInput.controllers.IsJoystickAssigned(entry.joystickId) || entry.state == QueueEntry.State.Confirmed) + { + player.controllers.AddController(ControllerType.Joystick, entry.joystickId, removeFromOtherPlayers: true); + ControllerSelectionChanged(); + return true; + } + dialog.StartModal(entry.id, DialogHelper.DialogType.JoystickConflict, new WindowProperties + { + title = "Joystick Reassignment", + message = "This joystick is already assigned to another player. Do you want to reassign this joystick to " + player.descriptiveName + "?", + rect = GetScreenCenteredRect(250f, 200f), + windowDrawDelegate = DrawModalWindow + }, DialogResultCallback); + return false; + } + + private bool ProcessElementAssignmentChange(ElementAssignmentChange entry) + { + switch (entry.changeType) + { + case ElementAssignmentChangeType.ReassignOrRemove: + return ProcessRemoveOrReassignElementAssignment(entry); + case ElementAssignmentChangeType.Remove: + return ProcessRemoveElementAssignment(entry); + case ElementAssignmentChangeType.Add: + case ElementAssignmentChangeType.Replace: + return ProcessAddOrReplaceElementAssignment(entry); + case ElementAssignmentChangeType.ConflictCheck: + return ProcessElementAssignmentConflictCheck(entry); + default: + throw new NotImplementedException(); + } + } + + private bool ProcessRemoveOrReassignElementAssignment(ElementAssignmentChange entry) + { + if (entry.context.controllerMap == null) + { + return true; + } + if (entry.state == QueueEntry.State.Canceled) + { + ElementAssignmentChange elementAssignmentChange = new ElementAssignmentChange(entry); + elementAssignmentChange.changeType = ElementAssignmentChangeType.Remove; + actionQueue.Enqueue(elementAssignmentChange); + return true; + } + if (entry.state == QueueEntry.State.Confirmed) + { + ElementAssignmentChange elementAssignmentChange2 = new ElementAssignmentChange(entry); + elementAssignmentChange2.changeType = ElementAssignmentChangeType.Replace; + actionQueue.Enqueue(elementAssignmentChange2); + return true; + } + dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties + { + title = "Reassign or Remove", + message = "Do you want to reassign or remove this assignment?", + rect = GetScreenCenteredRect(250f, 200f), + windowDrawDelegate = DrawReassignOrRemoveElementAssignmentWindow + }, DialogResultCallback); + return false; + } + + private bool ProcessRemoveElementAssignment(ElementAssignmentChange entry) + { + if (entry.context.controllerMap == null) + { + return true; + } + if (entry.state == QueueEntry.State.Canceled) + { + return true; + } + if (entry.state == QueueEntry.State.Confirmed) + { + entry.context.controllerMap.DeleteElementMap(entry.context.actionElementMapToReplace.id); + return true; + } + dialog.StartModal(entry.id, DialogHelper.DialogType.DeleteAssignmentConfirmation, new WindowProperties + { + title = "Remove Assignment", + message = "Are you sure you want to remove this assignment?", + rect = GetScreenCenteredRect(250f, 200f), + windowDrawDelegate = DrawModalWindow + }, DialogResultCallback); + return false; + } + + private bool ProcessAddOrReplaceElementAssignment(ElementAssignmentChange entry) + { + if (entry.state == QueueEntry.State.Canceled) + { + inputMapper.Stop(); + return true; + } + if (entry.state == QueueEntry.State.Confirmed) + { + if (Event.current.type != EventType.Layout) + { + return false; + } + if (conflictFoundEventData != null) + { + ElementAssignmentChange elementAssignmentChange = new ElementAssignmentChange(entry); + elementAssignmentChange.changeType = ElementAssignmentChangeType.ConflictCheck; + actionQueue.Enqueue(elementAssignmentChange); + } + return true; + } + string text; + if (entry.context.controllerMap.controllerType != 0) + { + text = ((entry.context.controllerMap.controllerType != ControllerType.Mouse) ? "Press any button or axis to assign it to this action." : "Press any mouse button or axis to assign it to this action.\n\nTo assign mouse movement axes, move the mouse quickly in the direction you want mapped to the action. Slow movements will be ignored."); + } + else + { + text = ((Application.platform != 0 && Application.platform != RuntimePlatform.OSXPlayer) ? "Press any key to assign it to this action. You may also use the modifier keys Control, Alt, and Shift. If you wish to assign a modifier key itself to this action, press and hold the key for 1 second." : "Press any key to assign it to this action. You may also use the modifier keys Command, Control, Alt, and Shift. If you wish to assign a modifier key itself to this action, press and hold the key for 1 second."); + if (Application.isEditor) + { + text += "\n\nNOTE: Some modifier key combinations will not work in the Unity Editor, but they will work in a game build."; + } + } + dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties + { + title = "Assign", + message = text, + rect = GetScreenCenteredRect(250f, 200f), + windowDrawDelegate = DrawElementAssignmentWindow + }, DialogResultCallback); + return false; + } + + private bool ProcessElementAssignmentConflictCheck(ElementAssignmentChange entry) + { + if (entry.context.controllerMap == null) + { + return true; + } + if (entry.state == QueueEntry.State.Canceled) + { + inputMapper.Stop(); + return true; + } + if (conflictFoundEventData == null) + { + return true; + } + if (entry.state == QueueEntry.State.Confirmed) + { + if (entry.response == UserResponse.Confirm) + { + conflictFoundEventData.responseCallback(InputMapper.ConflictResponse.Replace); + } + else + { + if (entry.response != UserResponse.Custom1) + { + throw new NotImplementedException(); + } + conflictFoundEventData.responseCallback(InputMapper.ConflictResponse.Add); + } + return true; + } + if (conflictFoundEventData.isProtected) + { + string message = conflictFoundEventData.assignment.elementDisplayName + " is already in use and is protected from reassignment. You cannot remove the protected assignment, but you can still assign the action to this element. If you do so, the element will trigger multiple actions when activated."; + dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties + { + title = "Assignment Conflict", + message = message, + rect = GetScreenCenteredRect(250f, 200f), + windowDrawDelegate = DrawElementAssignmentProtectedConflictWindow + }, DialogResultCallback); + } + else + { + string message2 = conflictFoundEventData.assignment.elementDisplayName + " is already in use. You may replace the other conflicting assignments, add this assignment anyway which will leave multiple actions assigned to this element, or cancel this assignment."; + dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties + { + title = "Assignment Conflict", + message = message2, + rect = GetScreenCenteredRect(250f, 200f), + windowDrawDelegate = DrawElementAssignmentNormalConflictWindow + }, DialogResultCallback); + } + return false; + } + + private bool ProcessFallbackJoystickIdentification(FallbackJoystickIdentification entry) + { + if (entry.state == QueueEntry.State.Canceled) + { + return true; + } + if (entry.state == QueueEntry.State.Confirmed) + { + return true; + } + dialog.StartModal(entry.id, DialogHelper.DialogType.JoystickConflict, new WindowProperties + { + title = "Joystick Identification Required", + message = "A joystick has been attached or removed. You will need to identify each joystick by pressing a button on the controller listed below:", + rect = GetScreenCenteredRect(250f, 200f), + windowDrawDelegate = DrawFallbackJoystickIdentificationWindow + }, DialogResultCallback, 1f); + return false; + } + + private bool ProcessCalibration(Calibration entry) + { + if (entry.state == QueueEntry.State.Canceled) + { + return true; + } + if (entry.state == QueueEntry.State.Confirmed) + { + return true; + } + dialog.StartModal(entry.id, DialogHelper.DialogType.JoystickConflict, new WindowProperties + { + title = "Calibrate Controller", + message = "Select an axis to calibrate on the " + entry.joystick.name + ".", + rect = GetScreenCenteredRect(450f, 480f), + windowDrawDelegate = DrawCalibrationWindow + }, DialogResultCallback); + return false; + } + + private void PlayerSelectionChanged() + { + ClearControllerSelection(); + } + + private void ControllerSelectionChanged() + { + ClearMapSelection(); + } + + private void ClearControllerSelection() + { + selectedController.Clear(); + ClearMapSelection(); + } + + private void ClearMapSelection() + { + selectedMapCategoryId = -1; + selectedMap = null; + } + + private void ResetAll() + { + ClearWorkingVars(); + initialized = false; + showMenu = false; + } + + private void ClearWorkingVars() + { + selectedPlayer = null; + ClearMapSelection(); + selectedController.Clear(); + actionScrollPos = default(Vector2); + dialog.FullReset(); + actionQueue.Clear(); + busy = false; + startListening = false; + conflictFoundEventData = null; + inputMapper.Stop(); + } + + private void SetGUIStateStart() + { + guiState = true; + if (busy) + { + guiState = false; + } + pageGUIState = guiState && !busy && !dialog.enabled && !dialog.busy; + if (GUI.enabled != guiState) + { + GUI.enabled = guiState; + } + } + + private void SetGUIStateEnd() + { + guiState = true; + if (!GUI.enabled) + { + GUI.enabled = guiState; + } + } + + private void JoystickConnected(ControllerStatusChangedEventArgs args) + { + if (ReInput.controllers.IsControllerAssigned(args.controllerType, args.controllerId)) + { + foreach (Player allPlayer in ReInput.players.AllPlayers) + { + if (allPlayer.controllers.ContainsController(args.controllerType, args.controllerId)) + { + ReInput.userDataStore.LoadControllerData(allPlayer.id, args.controllerType, args.controllerId); + } + } + } + else + { + ReInput.userDataStore.LoadControllerData(args.controllerType, args.controllerId); + } + if (ReInput.unityJoystickIdentificationRequired) + { + IdentifyAllJoysticks(); + } + } + + private void JoystickPreDisconnect(ControllerStatusChangedEventArgs args) + { + if (selectedController.hasSelection && args.controllerType == selectedController.type && args.controllerId == selectedController.id) + { + ClearControllerSelection(); + } + if (!showMenu) + { + return; + } + if (ReInput.controllers.IsControllerAssigned(args.controllerType, args.controllerId)) + { + foreach (Player allPlayer in ReInput.players.AllPlayers) + { + if (allPlayer.controllers.ContainsController(args.controllerType, args.controllerId)) + { + ReInput.userDataStore.SaveControllerData(allPlayer.id, args.controllerType, args.controllerId); + } + } + return; + } + ReInput.userDataStore.SaveControllerData(args.controllerType, args.controllerId); + } + + private void JoystickDisconnected(ControllerStatusChangedEventArgs args) + { + if (showMenu) + { + ClearWorkingVars(); + } + if (ReInput.unityJoystickIdentificationRequired) + { + IdentifyAllJoysticks(); + } + } + + private void OnConflictFound(InputMapper.ConflictFoundEventData data) + { + conflictFoundEventData = data; + } + + private void OnStopped(InputMapper.StoppedEventData data) + { + conflictFoundEventData = null; + } + + public void IdentifyAllJoysticks() + { + if (ReInput.controllers.joystickCount == 0) + { + return; + } + ClearWorkingVars(); + Open(); + foreach (Joystick joystick in ReInput.controllers.Joysticks) + { + actionQueue.Enqueue(new FallbackJoystickIdentification(joystick.id, joystick.name)); + } + } + + protected void CheckRecompile() + { + } + + private void RecompileWindow(int windowId) + { + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/CustomControllerDemo.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/CustomControllerDemo.cs new file mode 100644 index 0000000..2c67e86 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/CustomControllerDemo.cs @@ -0,0 +1,144 @@ +using System; +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class CustomControllerDemo : MonoBehaviour +{ + public int playerId; + + public string controllerTag; + + public bool useUpdateCallbacks; + + private int buttonCount; + + private int axisCount; + + private float[] axisValues; + + private bool[] buttonValues; + + private TouchJoystickExample[] joysticks; + + private TouchButtonExample[] buttons; + + private CustomController controller; + + [NonSerialized] + private bool initialized; + + private void Awake() + { + ScreenOrientation screenOrientation = ScreenOrientation.LandscapeLeft; + if (SystemInfo.deviceType == DeviceType.Handheld && Screen.orientation != screenOrientation) + { + Screen.orientation = screenOrientation; + } + Initialize(); + } + + private void Initialize() + { + ReInput.InputSourceUpdateEvent += OnInputSourceUpdate; + joysticks = GetComponentsInChildren<TouchJoystickExample>(); + buttons = GetComponentsInChildren<TouchButtonExample>(); + axisCount = joysticks.Length * 2; + buttonCount = buttons.Length; + axisValues = new float[axisCount]; + buttonValues = new bool[buttonCount]; + Player player = ReInput.players.GetPlayer(playerId); + controller = player.controllers.GetControllerWithTag<CustomController>(controllerTag); + if (controller == null) + { + Debug.LogError("A matching controller was not found for tag \"" + controllerTag + "\""); + } + if (controller.buttonCount != buttonValues.Length || controller.axisCount != axisValues.Length) + { + Debug.LogError("Controller has wrong number of elements!"); + } + if (useUpdateCallbacks && controller != null) + { + controller.SetAxisUpdateCallback(GetAxisValueCallback); + controller.SetButtonUpdateCallback(GetButtonValueCallback); + } + initialized = true; + } + + private void Update() + { + if (ReInput.isReady && !initialized) + { + Initialize(); + } + } + + private void OnInputSourceUpdate() + { + GetSourceAxisValues(); + GetSourceButtonValues(); + if (!useUpdateCallbacks) + { + SetControllerAxisValues(); + SetControllerButtonValues(); + } + } + + private void GetSourceAxisValues() + { + for (int i = 0; i < axisValues.Length; i++) + { + if (i % 2 != 0) + { + axisValues[i] = joysticks[i / 2].position.y; + } + else + { + axisValues[i] = joysticks[i / 2].position.x; + } + } + } + + private void GetSourceButtonValues() + { + for (int i = 0; i < buttonValues.Length; i++) + { + buttonValues[i] = buttons[i].isPressed; + } + } + + private void SetControllerAxisValues() + { + for (int i = 0; i < axisValues.Length; i++) + { + controller.SetAxisValue(i, axisValues[i]); + } + } + + private void SetControllerButtonValues() + { + for (int i = 0; i < buttonValues.Length; i++) + { + controller.SetButtonValue(i, buttonValues[i]); + } + } + + private float GetAxisValueCallback(int index) + { + if (index >= axisValues.Length) + { + return 0f; + } + return axisValues[index]; + } + + private bool GetButtonValueCallback(int index) + { + if (index >= buttonValues.Length) + { + return false; + } + return buttonValues[index]; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/CustomControllerDemo_Player.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/CustomControllerDemo_Player.cs new file mode 100644 index 0000000..7c4346a --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/CustomControllerDemo_Player.cs @@ -0,0 +1,58 @@ +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +[RequireComponent(typeof(CharacterController))] +public class CustomControllerDemo_Player : MonoBehaviour +{ + public int playerId; + + public float speed = 1f; + + public float bulletSpeed = 20f; + + public GameObject bulletPrefab; + + private Player _player; + + private CharacterController cc; + + private Player player + { + get + { + if (_player == null) + { + _player = ReInput.players.GetPlayer(playerId); + } + return _player; + } + } + + private void Awake() + { + cc = GetComponent<CharacterController>(); + } + + private void Update() + { + if (ReInput.isReady) + { + Vector2 vector = new Vector2(player.GetAxis("Move Horizontal"), player.GetAxis("Move Vertical")); + cc.Move(vector * speed * Time.deltaTime); + if (player.GetButtonDown("Fire")) + { + Vector3 vector2 = Vector3.Scale(new Vector3(1f, 0f, 0f), base.transform.right); + Object.Instantiate(bulletPrefab, base.transform.position + vector2, Quaternion.identity).GetComponent<Rigidbody>().velocity = new Vector3(bulletSpeed * base.transform.right.x, 0f, 0f); + } + if (player.GetButtonDown("Change Color")) + { + Renderer component = GetComponent<Renderer>(); + Material material = component.material; + material.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1f); + component.material = material; + } + } + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/CustomControllersTiltDemo.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/CustomControllersTiltDemo.cs new file mode 100644 index 0000000..d24caf2 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/CustomControllersTiltDemo.cs @@ -0,0 +1,47 @@ +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class CustomControllersTiltDemo : MonoBehaviour +{ + public Transform target; + + public float speed = 10f; + + private CustomController controller; + + private Player player; + + private void Awake() + { + Screen.orientation = ScreenOrientation.LandscapeLeft; + player = ReInput.players.GetPlayer(0); + ReInput.InputSourceUpdateEvent += OnInputUpdate; + controller = (CustomController)player.controllers.GetControllerWithTag(ControllerType.Custom, "TiltController"); + } + + private void Update() + { + if (!(target == null)) + { + Vector3 zero = Vector3.zero; + zero.y = player.GetAxis("Tilt Vertical"); + zero.x = player.GetAxis("Tilt Horizontal"); + if (zero.sqrMagnitude > 1f) + { + zero.Normalize(); + } + zero *= Time.deltaTime; + target.Translate(zero * speed); + } + } + + private void OnInputUpdate() + { + Vector3 acceleration = Input.acceleration; + controller.SetAxisValue(0, acceleration.x); + controller.SetAxisValue(1, acceleration.y); + controller.SetAxisValue(2, acceleration.z); + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/DualShock4SpecialFeaturesExample.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/DualShock4SpecialFeaturesExample.cs new file mode 100644 index 0000000..838b779 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/DualShock4SpecialFeaturesExample.cs @@ -0,0 +1,219 @@ +using System.Collections.Generic; +using Rewired.ControllerExtensions; +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class DualShock4SpecialFeaturesExample : MonoBehaviour +{ + private class Touch + { + public GameObject go; + + public int touchId = -1; + } + + private const int maxTouches = 2; + + public int playerId; + + public Transform touchpadTransform; + + public GameObject lightObject; + + public Transform accelerometerTransform; + + private List<Touch> touches; + + private Queue<Touch> unusedTouches; + + private bool isFlashing; + + private GUIStyle textStyle; + + private Player player => ReInput.players.GetPlayer(playerId); + + private void Awake() + { + InitializeTouchObjects(); + } + + private void Update() + { + if (!ReInput.isReady) + { + return; + } + IDualShock4Extension firstDS = GetFirstDS4(player); + if (firstDS != null) + { + base.transform.rotation = firstDS.GetOrientation(); + HandleTouchpad(firstDS); + Vector3 accelerometerValue = firstDS.GetAccelerometerValue(); + accelerometerTransform.LookAt(accelerometerTransform.position + accelerometerValue); + } + if (player.GetButtonDown("CycleLight")) + { + SetRandomLightColor(); + } + if (player.GetButtonDown("ResetOrientation")) + { + ResetOrientation(); + } + if (player.GetButtonDown("ToggleLightFlash")) + { + if (isFlashing) + { + StopLightFlash(); + } + else + { + StartLightFlash(); + } + isFlashing = !isFlashing; + } + if (player.GetButtonDown("VibrateLeft")) + { + firstDS.SetVibration(0, 1f, 1f); + } + if (player.GetButtonDown("VibrateRight")) + { + firstDS.SetVibration(1, 1f, 1f); + } + } + + private void OnGUI() + { + if (textStyle == null) + { + textStyle = new GUIStyle(GUI.skin.label); + textStyle.fontSize = 20; + textStyle.wordWrap = true; + } + if (GetFirstDS4(player) != null) + { + GUILayout.BeginArea(new Rect(200f, 100f, (float)Screen.width - 400f, (float)Screen.height - 200f)); + GUILayout.Label("Rotate the Dual Shock 4 to see the model rotate in sync.", textStyle); + GUILayout.Label("Touch the touchpad to see them appear on the model.", textStyle); + ActionElementMap firstElementMapWithAction = player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "ResetOrientation", skipDisabledMaps: true); + if (firstElementMapWithAction != null) + { + GUILayout.Label("Press " + firstElementMapWithAction.elementIdentifierName + " to reset the orientation. Hold the gamepad facing the screen with sticks pointing up and press the button.", textStyle); + } + firstElementMapWithAction = player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "CycleLight", skipDisabledMaps: true); + if (firstElementMapWithAction != null) + { + GUILayout.Label("Press " + firstElementMapWithAction.elementIdentifierName + " to change the light color.", textStyle); + } + firstElementMapWithAction = player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "ToggleLightFlash", skipDisabledMaps: true); + if (firstElementMapWithAction != null) + { + GUILayout.Label("Press " + firstElementMapWithAction.elementIdentifierName + " to start or stop the light flashing.", textStyle); + } + firstElementMapWithAction = player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "VibrateLeft", skipDisabledMaps: true); + if (firstElementMapWithAction != null) + { + GUILayout.Label("Press " + firstElementMapWithAction.elementIdentifierName + " vibrate the left motor.", textStyle); + } + firstElementMapWithAction = player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Joystick, "VibrateRight", skipDisabledMaps: true); + if (firstElementMapWithAction != null) + { + GUILayout.Label("Press " + firstElementMapWithAction.elementIdentifierName + " vibrate the right motor.", textStyle); + } + GUILayout.EndArea(); + } + } + + private void ResetOrientation() + { + GetFirstDS4(player)?.ResetOrientation(); + } + + private void SetRandomLightColor() + { + IDualShock4Extension firstDS = GetFirstDS4(player); + if (firstDS != null) + { + Color color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1f); + firstDS.SetLightColor(color); + lightObject.GetComponent<MeshRenderer>().material.color = color; + } + } + + private void StartLightFlash() + { + if (GetFirstDS4(player) is DualShock4Extension dualShock4Extension) + { + dualShock4Extension.SetLightFlash(0.5f, 0.5f); + } + } + + private void StopLightFlash() + { + if (GetFirstDS4(player) is DualShock4Extension dualShock4Extension) + { + dualShock4Extension.StopLightFlash(); + } + } + + private IDualShock4Extension GetFirstDS4(Player player) + { + foreach (Joystick joystick in player.controllers.Joysticks) + { + IDualShock4Extension extension = joystick.GetExtension<IDualShock4Extension>(); + if (extension != null) + { + return extension; + } + } + return null; + } + + private void InitializeTouchObjects() + { + touches = new List<Touch>(2); + unusedTouches = new Queue<Touch>(2); + for (int i = 0; i < 2; i++) + { + Touch touch = new Touch(); + touch.go = GameObject.CreatePrimitive(PrimitiveType.Sphere); + touch.go.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); + touch.go.transform.SetParent(touchpadTransform, worldPositionStays: true); + touch.go.GetComponent<MeshRenderer>().material.color = ((i == 0) ? Color.red : Color.green); + touch.go.SetActive(value: false); + unusedTouches.Enqueue(touch); + } + } + + private void HandleTouchpad(IDualShock4Extension ds4) + { + for (int num = touches.Count - 1; num >= 0; num--) + { + Touch touch = touches[num]; + if (!ds4.IsTouchingByTouchId(touch.touchId)) + { + touch.go.SetActive(value: false); + unusedTouches.Enqueue(touch); + touches.RemoveAt(num); + } + } + for (int i = 0; i < ds4.maxTouches; i++) + { + if (ds4.IsTouching(i)) + { + int touchId = ds4.GetTouchId(i); + Touch touch2 = touches.Find((Touch x) => x.touchId == touchId); + if (touch2 == null) + { + touch2 = unusedTouches.Dequeue(); + touches.Add(touch2); + } + touch2.touchId = touchId; + touch2.go.SetActive(value: true); + ds4.GetTouchPosition(i, out var position); + touch2.go.transform.localPosition = new Vector3(position.x - 0.5f, 0.5f + touch2.go.transform.localScale.y * 0.5f, position.y - 0.5f); + } + } + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/EightPlayersExample_Player.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/EightPlayersExample_Player.cs new file mode 100644 index 0000000..0ce56e1 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/EightPlayersExample_Player.cs @@ -0,0 +1,71 @@ +using System; +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +[RequireComponent(typeof(CharacterController))] +public class EightPlayersExample_Player : MonoBehaviour +{ + public int playerId; + + public float moveSpeed = 3f; + + public float bulletSpeed = 15f; + + public GameObject bulletPrefab; + + private Player player; + + private CharacterController cc; + + private Vector3 moveVector; + + private bool fire; + + [NonSerialized] + private bool initialized; + + private void Awake() + { + cc = GetComponent<CharacterController>(); + } + + private void Initialize() + { + player = ReInput.players.GetPlayer(playerId); + initialized = true; + } + + private void Update() + { + if (ReInput.isReady) + { + if (!initialized) + { + Initialize(); + } + GetInput(); + ProcessInput(); + } + } + + private void GetInput() + { + moveVector.x = player.GetAxis("Move Horizontal"); + moveVector.y = player.GetAxis("Move Vertical"); + fire = player.GetButtonDown("Fire"); + } + + private void ProcessInput() + { + if (moveVector.x != 0f || moveVector.y != 0f) + { + cc.Move(moveVector * moveSpeed * Time.deltaTime); + } + if (fire) + { + UnityEngine.Object.Instantiate(bulletPrefab, base.transform.position + base.transform.right, base.transform.rotation).GetComponent<Rigidbody>().AddForce(base.transform.right * bulletSpeed, ForceMode.VelocityChange); + } + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs new file mode 100644 index 0000000..3213b71 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/FallbackJoystickIdentificationDemo.cs @@ -0,0 +1,114 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class FallbackJoystickIdentificationDemo : MonoBehaviour +{ + private const float windowWidth = 250f; + + private const float windowHeight = 250f; + + private const float inputDelay = 1f; + + private bool identifyRequired; + + private Queue<Joystick> joysticksToIdentify; + + private float nextInputAllowedTime; + + private GUIStyle style; + + private void Awake() + { + if (ReInput.unityJoystickIdentificationRequired) + { + ReInput.ControllerConnectedEvent += JoystickConnected; + ReInput.ControllerDisconnectedEvent += JoystickDisconnected; + IdentifyAllJoysticks(); + } + } + + private void JoystickConnected(ControllerStatusChangedEventArgs args) + { + IdentifyAllJoysticks(); + } + + private void JoystickDisconnected(ControllerStatusChangedEventArgs args) + { + IdentifyAllJoysticks(); + } + + public void IdentifyAllJoysticks() + { + Reset(); + if (ReInput.controllers.joystickCount != 0) + { + Joystick[] joysticks = ReInput.controllers.GetJoysticks(); + if (joysticks != null) + { + identifyRequired = true; + joysticksToIdentify = new Queue<Joystick>(joysticks); + SetInputDelay(); + } + } + } + + private void SetInputDelay() + { + nextInputAllowedTime = Time.time + 1f; + } + + private void OnGUI() + { + if (!identifyRequired) + { + return; + } + if (joysticksToIdentify == null || joysticksToIdentify.Count == 0) + { + Reset(); + return; + } + Rect screenRect = new Rect((float)Screen.width * 0.5f - 125f, (float)Screen.height * 0.5f - 125f, 250f, 250f); + GUILayout.Window(0, screenRect, DrawDialogWindow, "Joystick Identification Required"); + GUI.FocusWindow(0); + if (!(Time.time < nextInputAllowedTime) && ReInput.controllers.SetUnityJoystickIdFromAnyButtonOrAxisPress(joysticksToIdentify.Peek().id, 0.8f, positiveAxesOnly: false)) + { + joysticksToIdentify.Dequeue(); + SetInputDelay(); + if (joysticksToIdentify.Count == 0) + { + Reset(); + } + } + } + + private void DrawDialogWindow(int windowId) + { + if (identifyRequired) + { + if (style == null) + { + style = new GUIStyle(GUI.skin.label); + style.wordWrap = true; + } + GUILayout.Space(15f); + GUILayout.Label("A joystick has been attached or removed. You will need to identify each joystick by pressing a button on the controller listed below:", style); + Joystick joystick = joysticksToIdentify.Peek(); + GUILayout.Label("Press any button on \"" + joystick.name + "\" now.", style); + GUILayout.FlexibleSpace(); + if (GUILayout.Button("Skip")) + { + joysticksToIdentify.Dequeue(); + } + } + } + + private void Reset() + { + joysticksToIdentify = null; + identifyRequired = false; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/PlayerMouseSpriteExample.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/PlayerMouseSpriteExample.cs new file mode 100644 index 0000000..194fb5d --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/PlayerMouseSpriteExample.cs @@ -0,0 +1,116 @@ +using System; +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class PlayerMouseSpriteExample : MonoBehaviour +{ + [Tooltip("The Player that will control the mouse")] + public int playerId; + + [Tooltip("The Rewired Action used for the mouse horizontal axis.")] + public string horizontalAction = "MouseX"; + + [Tooltip("The Rewired Action used for the mouse vertical axis.")] + public string verticalAction = "MouseY"; + + [Tooltip("The Rewired Action used for the mouse wheel axis.")] + public string wheelAction = "MouseWheel"; + + [Tooltip("The Rewired Action used for the mouse left button.")] + public string leftButtonAction = "MouseLeftButton"; + + [Tooltip("The Rewired Action used for the mouse right button.")] + public string rightButtonAction = "MouseRightButton"; + + [Tooltip("The Rewired Action used for the mouse middle button.")] + public string middleButtonAction = "MouseMiddleButton"; + + [Tooltip("The distance from the camera that the pointer will be drawn.")] + public float distanceFromCamera = 1f; + + [Tooltip("The scale of the sprite pointer.")] + public float spriteScale = 0.05f; + + [Tooltip("The pointer prefab.")] + public GameObject pointerPrefab; + + [Tooltip("The click effect prefab.")] + public GameObject clickEffectPrefab; + + [Tooltip("Should the hardware pointer be hidden?")] + public bool hideHardwarePointer = true; + + [NonSerialized] + private GameObject pointer; + + [NonSerialized] + private PlayerMouse mouse; + + private void Awake() + { + pointer = UnityEngine.Object.Instantiate(pointerPrefab); + pointer.transform.localScale = new Vector3(spriteScale, spriteScale, spriteScale); + if (hideHardwarePointer) + { + Cursor.visible = false; + } + mouse = PlayerMouse.Factory.Create(); + mouse.playerId = playerId; + mouse.xAxis.actionName = horizontalAction; + mouse.yAxis.actionName = verticalAction; + mouse.wheel.yAxis.actionName = wheelAction; + mouse.leftButton.actionName = leftButtonAction; + mouse.rightButton.actionName = rightButtonAction; + mouse.middleButton.actionName = middleButtonAction; + mouse.pointerSpeed = 1f; + mouse.wheel.yAxis.repeatRate = 5f; + mouse.screenPosition = new Vector2((float)Screen.width * 0.5f, (float)Screen.height * 0.5f); + mouse.ScreenPositionChangedEvent += OnScreenPositionChanged; + OnScreenPositionChanged(mouse.screenPosition); + } + + private void Update() + { + if (ReInput.isReady) + { + pointer.transform.Rotate(Vector3.forward, mouse.wheel.yAxis.value * 20f); + if (mouse.leftButton.justPressed) + { + CreateClickEffect(new Color(0f, 1f, 0f, 1f)); + } + if (mouse.rightButton.justPressed) + { + CreateClickEffect(new Color(1f, 0f, 0f, 1f)); + } + if (mouse.middleButton.justPressed) + { + CreateClickEffect(new Color(1f, 1f, 0f, 1f)); + } + } + } + + private void OnDestroy() + { + if (ReInput.isReady) + { + mouse.ScreenPositionChangedEvent -= OnScreenPositionChanged; + } + } + + private void CreateClickEffect(Color color) + { + GameObject obj = UnityEngine.Object.Instantiate(clickEffectPrefab); + obj.transform.localScale = new Vector3(spriteScale, spriteScale, spriteScale); + obj.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(mouse.screenPosition.x, mouse.screenPosition.y, distanceFromCamera)); + obj.GetComponentInChildren<SpriteRenderer>().color = color; + UnityEngine.Object.Destroy(obj, 0.5f); + } + + private void OnScreenPositionChanged(Vector2 position) + { + Vector3 position2 = Camera.main.ScreenToWorldPoint(new Vector3(position.x, position.y, distanceFromCamera)); + pointer.transform.position = position2; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/PlayerPointerEventHandlerExample.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/PlayerPointerEventHandlerExample.cs new file mode 100644 index 0000000..dde8871 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/PlayerPointerEventHandlerExample.cs @@ -0,0 +1,138 @@ +using System.Collections.Generic; +using System.Text; +using Rewired.Integration.UnityUI; +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public sealed class PlayerPointerEventHandlerExample : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerUpHandler, IPointerDownHandler, IPointerClickHandler, IScrollHandler, IBeginDragHandler, IDragHandler, IEndDragHandler +{ + public Text text; + + private const int logLength = 10; + + private List<string> log = new List<string>(); + + private void Log(string o) + { + log.Add(o); + if (log.Count > 10) + { + log.RemoveAt(0); + } + } + + private void Update() + { + if (!(text != null)) + { + return; + } + StringBuilder stringBuilder = new StringBuilder(); + foreach (string item in log) + { + stringBuilder.AppendLine(item); + } + text.text = stringBuilder.ToString(); + } + + public void OnPointerEnter(PointerEventData eventData) + { + if (eventData is PlayerPointerEventData) + { + PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; + Log("OnPointerEnter: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData)); + } + } + + public void OnPointerExit(PointerEventData eventData) + { + if (eventData is PlayerPointerEventData) + { + PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; + Log("OnPointerExit: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData)); + } + } + + public void OnPointerUp(PointerEventData eventData) + { + if (eventData is PlayerPointerEventData) + { + PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; + Log("OnPointerUp: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); + } + } + + public void OnPointerDown(PointerEventData eventData) + { + if (eventData is PlayerPointerEventData) + { + PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; + Log("OnPointerDown: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); + } + } + + public void OnPointerClick(PointerEventData eventData) + { + if (eventData is PlayerPointerEventData) + { + PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; + Log("OnPointerClick: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); + } + } + + public void OnScroll(PointerEventData eventData) + { + if (eventData is PlayerPointerEventData) + { + PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; + Log("OnScroll: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData)); + } + } + + public void OnBeginDrag(PointerEventData eventData) + { + if (eventData is PlayerPointerEventData) + { + PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; + Log("OnBeginDrag: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); + } + } + + public void OnDrag(PointerEventData eventData) + { + if (eventData is PlayerPointerEventData) + { + PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; + Log("OnDrag: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); + } + } + + public void OnEndDrag(PointerEventData eventData) + { + if (eventData is PlayerPointerEventData) + { + PlayerPointerEventData playerPointerEventData = (PlayerPointerEventData)eventData; + Log("OnEndDrag: Player = " + playerPointerEventData.playerId + ", Pointer Index = " + playerPointerEventData.inputSourceIndex + ", Source = " + GetSourceName(playerPointerEventData) + ", Button Index = " + playerPointerEventData.buttonIndex); + } + } + + private static string GetSourceName(PlayerPointerEventData playerEventData) + { + if (playerEventData.sourceType == PointerEventType.Mouse) + { + if (playerEventData.mouseSource is Behaviour) + { + return (playerEventData.mouseSource as Behaviour).name; + } + } + else if (playerEventData.sourceType == PointerEventType.Touch && playerEventData.touchSource is Behaviour) + { + return (playerEventData.touchSource as Behaviour).name; + } + return null; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_Assigner.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_Assigner.cs new file mode 100644 index 0000000..83c25e8 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_Assigner.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class PressAnyButtonToJoinExample_Assigner : MonoBehaviour +{ + private void Update() + { + if (ReInput.isReady) + { + AssignJoysticksToPlayers(); + } + } + + private void AssignJoysticksToPlayers() + { + IList<Joystick> joysticks = ReInput.controllers.Joysticks; + for (int i = 0; i < joysticks.Count; i++) + { + Joystick joystick = joysticks[i]; + if (!ReInput.controllers.IsControllerAssigned(joystick.type, joystick.id) && joystick.GetAnyButtonDown()) + { + Player player = FindPlayerWithoutJoystick(); + if (player == null) + { + return; + } + player.controllers.AddController(joystick, removeFromOtherPlayers: false); + } + } + if (DoAllPlayersHaveJoysticks()) + { + ReInput.configuration.autoAssignJoysticks = true; + base.enabled = false; + } + } + + private Player FindPlayerWithoutJoystick() + { + IList<Player> players = ReInput.players.Players; + for (int i = 0; i < players.Count; i++) + { + if (players[i].controllers.joystickCount <= 0) + { + return players[i]; + } + } + return null; + } + + private bool DoAllPlayersHaveJoysticks() + { + return FindPlayerWithoutJoystick() == null; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_GamePlayer.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_GamePlayer.cs new file mode 100644 index 0000000..a0466ce --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/PressAnyButtonToJoinExample_GamePlayer.cs @@ -0,0 +1,67 @@ +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +[RequireComponent(typeof(CharacterController))] +public class PressAnyButtonToJoinExample_GamePlayer : MonoBehaviour +{ + public int playerId; + + public float moveSpeed = 3f; + + public float bulletSpeed = 15f; + + public GameObject bulletPrefab; + + private CharacterController cc; + + private Vector3 moveVector; + + private bool fire; + + private Player player + { + get + { + if (!ReInput.isReady) + { + return null; + } + return ReInput.players.GetPlayer(playerId); + } + } + + private void OnEnable() + { + cc = GetComponent<CharacterController>(); + } + + private void Update() + { + if (ReInput.isReady && player != null) + { + GetInput(); + ProcessInput(); + } + } + + private void GetInput() + { + moveVector.x = player.GetAxis("Move Horizontal"); + moveVector.y = player.GetAxis("Move Vertical"); + fire = player.GetButtonDown("Fire"); + } + + private void ProcessInput() + { + if (moveVector.x != 0f || moveVector.y != 0f) + { + cc.Move(moveVector * moveSpeed * Time.deltaTime); + } + if (fire) + { + Object.Instantiate(bulletPrefab, base.transform.position + base.transform.right, base.transform.rotation).GetComponent<Rigidbody>().AddForce(base.transform.right * bulletSpeed, ForceMode.VelocityChange); + } + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/PressStartToJoinExample_Assigner.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/PressStartToJoinExample_Assigner.cs new file mode 100644 index 0000000..6b23589 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/PressStartToJoinExample_Assigner.cs @@ -0,0 +1,87 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class PressStartToJoinExample_Assigner : MonoBehaviour +{ + private class PlayerMap + { + public int rewiredPlayerId; + + public int gamePlayerId; + + public PlayerMap(int rewiredPlayerId, int gamePlayerId) + { + this.rewiredPlayerId = rewiredPlayerId; + this.gamePlayerId = gamePlayerId; + } + } + + private static PressStartToJoinExample_Assigner instance; + + public int maxPlayers = 4; + + private List<PlayerMap> playerMap; + + private int gamePlayerIdCounter; + + public static Player GetRewiredPlayer(int gamePlayerId) + { + if (!ReInput.isReady) + { + return null; + } + if (instance == null) + { + Debug.LogError("Not initialized. Do you have a PressStartToJoinPlayerSelector in your scehe?"); + return null; + } + for (int i = 0; i < instance.playerMap.Count; i++) + { + if (instance.playerMap[i].gamePlayerId == gamePlayerId) + { + return ReInput.players.GetPlayer(instance.playerMap[i].rewiredPlayerId); + } + } + return null; + } + + private void Awake() + { + playerMap = new List<PlayerMap>(); + instance = this; + } + + private void Update() + { + for (int i = 0; i < ReInput.players.playerCount; i++) + { + if (ReInput.players.GetPlayer(i).GetButtonDown("JoinGame")) + { + AssignNextPlayer(i); + } + } + } + + private void AssignNextPlayer(int rewiredPlayerId) + { + if (playerMap.Count >= maxPlayers) + { + Debug.LogError("Max player limit already reached!"); + return; + } + int nextGamePlayerId = GetNextGamePlayerId(); + playerMap.Add(new PlayerMap(rewiredPlayerId, nextGamePlayerId)); + Player player = ReInput.players.GetPlayer(rewiredPlayerId); + player.controllers.maps.SetMapsEnabled(state: false, "Assignment"); + player.controllers.maps.SetMapsEnabled(state: true, "Default"); + Debug.Log("Added Rewired Player id " + rewiredPlayerId + " to game player " + nextGamePlayerId); + } + + private int GetNextGamePlayerId() + { + return gamePlayerIdCounter++; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/PressStartToJoinExample_GamePlayer.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/PressStartToJoinExample_GamePlayer.cs new file mode 100644 index 0000000..04ee6c4 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/PressStartToJoinExample_GamePlayer.cs @@ -0,0 +1,57 @@ +using UnityEngine; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +[RequireComponent(typeof(CharacterController))] +public class PressStartToJoinExample_GamePlayer : MonoBehaviour +{ + public int gamePlayerId; + + public float moveSpeed = 3f; + + public float bulletSpeed = 15f; + + public GameObject bulletPrefab; + + private CharacterController cc; + + private Vector3 moveVector; + + private bool fire; + + private Player player => PressStartToJoinExample_Assigner.GetRewiredPlayer(gamePlayerId); + + private void OnEnable() + { + cc = GetComponent<CharacterController>(); + } + + private void Update() + { + if (ReInput.isReady && player != null) + { + GetInput(); + ProcessInput(); + } + } + + private void GetInput() + { + moveVector.x = player.GetAxis("Move Horizontal"); + moveVector.y = player.GetAxis("Move Vertical"); + fire = player.GetButtonDown("Fire"); + } + + private void ProcessInput() + { + if (moveVector.x != 0f || moveVector.y != 0f) + { + cc.Move(moveVector * moveSpeed * Time.deltaTime); + } + if (fire) + { + Object.Instantiate(bulletPrefab, base.transform.position + base.transform.right, base.transform.rotation).GetComponent<Rigidbody>().AddForce(base.transform.right * bulletSpeed, ForceMode.VelocityChange); + } + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/SimpleCombinedKeyboardMouseRemapping.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/SimpleCombinedKeyboardMouseRemapping.cs new file mode 100644 index 0000000..3a2544b --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/SimpleCombinedKeyboardMouseRemapping.cs @@ -0,0 +1,225 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class SimpleCombinedKeyboardMouseRemapping : MonoBehaviour +{ + private class Row + { + public InputAction action; + + public AxisRange actionRange; + + public Button button; + + public Text text; + } + + private struct TargetMapping + { + public ControllerMap controllerMap; + + public int actionElementMapId; + } + + private const string category = "Default"; + + private const string layout = "Default"; + + private const string uiCategory = "UI"; + + private InputMapper inputMapper_keyboard = new InputMapper(); + + private InputMapper inputMapper_mouse = new InputMapper(); + + public GameObject buttonPrefab; + + public GameObject textPrefab; + + public RectTransform fieldGroupTransform; + + public RectTransform actionGroupTransform; + + public Text controllerNameUIText; + + public Text statusUIText; + + private List<Row> rows = new List<Row>(); + + private TargetMapping _replaceTargetMapping; + + private Player player => ReInput.players.GetPlayer(0); + + private void OnEnable() + { + if (ReInput.isReady) + { + inputMapper_keyboard.options.timeout = 5f; + inputMapper_mouse.options.timeout = 5f; + inputMapper_mouse.options.ignoreMouseXAxis = true; + inputMapper_mouse.options.ignoreMouseYAxis = true; + inputMapper_keyboard.options.allowButtonsOnFullAxisAssignment = false; + inputMapper_mouse.options.allowButtonsOnFullAxisAssignment = false; + inputMapper_keyboard.InputMappedEvent += OnInputMapped; + inputMapper_keyboard.StoppedEvent += OnStopped; + inputMapper_mouse.InputMappedEvent += OnInputMapped; + inputMapper_mouse.StoppedEvent += OnStopped; + InitializeUI(); + } + } + + private void OnDisable() + { + inputMapper_keyboard.Stop(); + inputMapper_mouse.Stop(); + inputMapper_keyboard.RemoveAllEventListeners(); + inputMapper_mouse.RemoveAllEventListeners(); + } + + private void RedrawUI() + { + controllerNameUIText.text = "Keyboard/Mouse"; + for (int i = 0; i < rows.Count; i++) + { + Row row = rows[i]; + InputAction action = rows[i].action; + string text = string.Empty; + int actionElementMapId = -1; + for (int j = 0; j < 2; j++) + { + ControllerType controllerType = ((j != 0) ? ControllerType.Mouse : ControllerType.Keyboard); + foreach (ActionElementMap item in player.controllers.maps.GetMap(controllerType, 0, "Default", "Default").ElementMapsWithAction(action.id)) + { + if (item.ShowInField(row.actionRange)) + { + text = item.elementIdentifierName; + actionElementMapId = item.id; + break; + } + } + if (actionElementMapId >= 0) + { + break; + } + } + row.text.text = text; + row.button.onClick.RemoveAllListeners(); + int index = i; + row.button.onClick.AddListener(delegate + { + OnInputFieldClicked(index, actionElementMapId); + }); + } + } + + private void ClearUI() + { + controllerNameUIText.text = string.Empty; + for (int i = 0; i < rows.Count; i++) + { + rows[i].text.text = string.Empty; + } + } + + private void InitializeUI() + { + foreach (Transform item in actionGroupTransform) + { + Object.Destroy(item.gameObject); + } + foreach (Transform item2 in fieldGroupTransform) + { + Object.Destroy(item2.gameObject); + } + foreach (InputAction item3 in ReInput.mapping.ActionsInCategory("Default")) + { + if (item3.type == InputActionType.Axis) + { + CreateUIRow(item3, AxisRange.Full, item3.descriptiveName); + CreateUIRow(item3, AxisRange.Positive, (!string.IsNullOrEmpty(item3.positiveDescriptiveName)) ? item3.positiveDescriptiveName : (item3.descriptiveName + " +")); + CreateUIRow(item3, AxisRange.Negative, (!string.IsNullOrEmpty(item3.negativeDescriptiveName)) ? item3.negativeDescriptiveName : (item3.descriptiveName + " -")); + } + else if (item3.type == InputActionType.Button) + { + CreateUIRow(item3, AxisRange.Positive, item3.descriptiveName); + } + } + RedrawUI(); + } + + private void CreateUIRow(InputAction action, AxisRange actionRange, string label) + { + GameObject obj = Object.Instantiate(textPrefab); + obj.transform.SetParent(actionGroupTransform); + obj.transform.SetAsLastSibling(); + obj.GetComponent<Text>().text = label; + GameObject gameObject = Object.Instantiate(buttonPrefab); + gameObject.transform.SetParent(fieldGroupTransform); + gameObject.transform.SetAsLastSibling(); + rows.Add(new Row + { + action = action, + actionRange = actionRange, + button = gameObject.GetComponent<Button>(), + text = gameObject.GetComponentInChildren<Text>() + }); + } + + private void OnInputFieldClicked(int index, int actionElementMapToReplaceId) + { + if (index >= 0 && index < rows.Count) + { + ControllerMap map = player.controllers.maps.GetMap(ControllerType.Keyboard, 0, "Default", "Default"); + ControllerMap map2 = player.controllers.maps.GetMap(ControllerType.Mouse, 0, "Default", "Default"); + ControllerMap controllerMap = (map.ContainsElementMap(actionElementMapToReplaceId) ? map : ((!map2.ContainsElementMap(actionElementMapToReplaceId)) ? null : map2)); + _replaceTargetMapping = new TargetMapping + { + actionElementMapId = actionElementMapToReplaceId, + controllerMap = controllerMap + }; + StartCoroutine(StartListeningDelayed(index, map, map2, actionElementMapToReplaceId)); + } + } + + private IEnumerator StartListeningDelayed(int index, ControllerMap keyboardMap, ControllerMap mouseMap, int actionElementMapToReplaceId) + { + yield return new WaitForSeconds(0.1f); + inputMapper_keyboard.Start(new InputMapper.Context + { + actionId = rows[index].action.id, + controllerMap = keyboardMap, + actionRange = rows[index].actionRange, + actionElementMapToReplace = keyboardMap.GetElementMap(actionElementMapToReplaceId) + }); + inputMapper_mouse.Start(new InputMapper.Context + { + actionId = rows[index].action.id, + controllerMap = mouseMap, + actionRange = rows[index].actionRange, + actionElementMapToReplace = mouseMap.GetElementMap(actionElementMapToReplaceId) + }); + player.controllers.maps.SetMapsEnabled(state: false, "UI"); + statusUIText.text = "Listening..."; + } + + private void OnInputMapped(InputMapper.InputMappedEventData data) + { + inputMapper_keyboard.Stop(); + inputMapper_mouse.Stop(); + if (_replaceTargetMapping.controllerMap != null && data.actionElementMap.controllerMap != _replaceTargetMapping.controllerMap) + { + _replaceTargetMapping.controllerMap.DeleteElementMap(_replaceTargetMapping.actionElementMapId); + } + RedrawUI(); + } + + private void OnStopped(InputMapper.StoppedEventData data) + { + statusUIText.text = string.Empty; + player.controllers.maps.SetMapsEnabled(state: true, "UI"); + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/SimpleControlRemapping.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/SimpleControlRemapping.cs new file mode 100644 index 0000000..386ebe7 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/SimpleControlRemapping.cs @@ -0,0 +1,257 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +public class SimpleControlRemapping : MonoBehaviour +{ + private class Row + { + public InputAction action; + + public AxisRange actionRange; + + public Button button; + + public Text text; + } + + private const string category = "Default"; + + private const string layout = "Default"; + + private const string uiCategory = "UI"; + + private InputMapper inputMapper = new InputMapper(); + + public GameObject buttonPrefab; + + public GameObject textPrefab; + + public RectTransform fieldGroupTransform; + + public RectTransform actionGroupTransform; + + public Text controllerNameUIText; + + public Text statusUIText; + + private ControllerType selectedControllerType; + + private int selectedControllerId; + + private List<Row> rows = new List<Row>(); + + private Player player => ReInput.players.GetPlayer(0); + + private ControllerMap controllerMap + { + get + { + if (controller == null) + { + return null; + } + return player.controllers.maps.GetMap(controller.type, controller.id, "Default", "Default"); + } + } + + private Controller controller => player.controllers.GetController(selectedControllerType, selectedControllerId); + + private void OnEnable() + { + if (ReInput.isReady) + { + inputMapper.options.timeout = 5f; + inputMapper.options.ignoreMouseXAxis = true; + inputMapper.options.ignoreMouseYAxis = true; + ReInput.ControllerConnectedEvent += OnControllerChanged; + ReInput.ControllerDisconnectedEvent += OnControllerChanged; + inputMapper.InputMappedEvent += OnInputMapped; + inputMapper.StoppedEvent += OnStopped; + InitializeUI(); + } + } + + private void OnDisable() + { + inputMapper.Stop(); + inputMapper.RemoveAllEventListeners(); + ReInput.ControllerConnectedEvent -= OnControllerChanged; + ReInput.ControllerDisconnectedEvent -= OnControllerChanged; + } + + private void RedrawUI() + { + if (controller == null) + { + ClearUI(); + return; + } + controllerNameUIText.text = controller.name; + for (int i = 0; i < rows.Count; i++) + { + Row row = rows[i]; + InputAction action = rows[i].action; + string text = string.Empty; + int actionElementMapId = -1; + foreach (ActionElementMap item in controllerMap.ElementMapsWithAction(action.id)) + { + if (item.ShowInField(row.actionRange)) + { + text = item.elementIdentifierName; + actionElementMapId = item.id; + break; + } + } + row.text.text = text; + row.button.onClick.RemoveAllListeners(); + int index = i; + row.button.onClick.AddListener(delegate + { + OnInputFieldClicked(index, actionElementMapId); + }); + } + } + + private void ClearUI() + { + if (selectedControllerType == ControllerType.Joystick) + { + controllerNameUIText.text = "No joysticks attached"; + } + else + { + controllerNameUIText.text = string.Empty; + } + for (int i = 0; i < rows.Count; i++) + { + rows[i].text.text = string.Empty; + } + } + + private void InitializeUI() + { + foreach (Transform item in actionGroupTransform) + { + Object.Destroy(item.gameObject); + } + foreach (Transform item2 in fieldGroupTransform) + { + Object.Destroy(item2.gameObject); + } + foreach (InputAction item3 in ReInput.mapping.ActionsInCategory("Default")) + { + if (item3.type == InputActionType.Axis) + { + CreateUIRow(item3, AxisRange.Full, item3.descriptiveName); + CreateUIRow(item3, AxisRange.Positive, (!string.IsNullOrEmpty(item3.positiveDescriptiveName)) ? item3.positiveDescriptiveName : (item3.descriptiveName + " +")); + CreateUIRow(item3, AxisRange.Negative, (!string.IsNullOrEmpty(item3.negativeDescriptiveName)) ? item3.negativeDescriptiveName : (item3.descriptiveName + " -")); + } + else if (item3.type == InputActionType.Button) + { + CreateUIRow(item3, AxisRange.Positive, item3.descriptiveName); + } + } + RedrawUI(); + } + + private void CreateUIRow(InputAction action, AxisRange actionRange, string label) + { + GameObject obj = Object.Instantiate(textPrefab); + obj.transform.SetParent(actionGroupTransform); + obj.transform.SetAsLastSibling(); + obj.GetComponent<Text>().text = label; + GameObject gameObject = Object.Instantiate(buttonPrefab); + gameObject.transform.SetParent(fieldGroupTransform); + gameObject.transform.SetAsLastSibling(); + rows.Add(new Row + { + action = action, + actionRange = actionRange, + button = gameObject.GetComponent<Button>(), + text = gameObject.GetComponentInChildren<Text>() + }); + } + + private void SetSelectedController(ControllerType controllerType) + { + bool flag = false; + if (controllerType != selectedControllerType) + { + selectedControllerType = controllerType; + flag = true; + } + int num = selectedControllerId; + if (selectedControllerType == ControllerType.Joystick) + { + if (player.controllers.joystickCount > 0) + { + selectedControllerId = player.controllers.Joysticks[0].id; + } + else + { + selectedControllerId = -1; + } + } + else + { + selectedControllerId = 0; + } + if (selectedControllerId != num) + { + flag = true; + } + if (flag) + { + inputMapper.Stop(); + RedrawUI(); + } + } + + public void OnControllerSelected(int controllerType) + { + SetSelectedController((ControllerType)controllerType); + } + + private void OnInputFieldClicked(int index, int actionElementMapToReplaceId) + { + if (index >= 0 && index < rows.Count && controller != null) + { + StartCoroutine(StartListeningDelayed(index, actionElementMapToReplaceId)); + } + } + + private IEnumerator StartListeningDelayed(int index, int actionElementMapToReplaceId) + { + yield return new WaitForSeconds(0.1f); + inputMapper.Start(new InputMapper.Context + { + actionId = rows[index].action.id, + controllerMap = controllerMap, + actionRange = rows[index].actionRange, + actionElementMapToReplace = controllerMap.GetElementMap(actionElementMapToReplaceId) + }); + player.controllers.maps.SetMapsEnabled(state: false, "UI"); + statusUIText.text = "Listening..."; + } + + private void OnControllerChanged(ControllerStatusChangedEventArgs args) + { + SetSelectedController(selectedControllerType); + } + + private void OnInputMapped(InputMapper.InputMappedEventData data) + { + RedrawUI(); + } + + private void OnStopped(InputMapper.StoppedEventData data) + { + statusUIText.text = string.Empty; + player.controllers.maps.SetMapsEnabled(state: true, "UI"); + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/TouchButtonExample.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/TouchButtonExample.cs new file mode 100644 index 0000000..af6edad --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/TouchButtonExample.cs @@ -0,0 +1,52 @@ +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +[RequireComponent(typeof(Image))] +public class TouchButtonExample : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler +{ + public bool allowMouseControl = true; + + public bool isPressed { get; private set; } + + private void Awake() + { + if (SystemInfo.deviceType == DeviceType.Handheld) + { + allowMouseControl = false; + } + } + + private void Restart() + { + isPressed = false; + } + + void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + if (allowMouseControl || !IsMousePointerId(eventData.pointerId)) + { + isPressed = true; + } + } + + void IPointerUpHandler.OnPointerUp(PointerEventData eventData) + { + if (allowMouseControl || !IsMousePointerId(eventData.pointerId)) + { + isPressed = false; + } + } + + private static bool IsMousePointerId(int id) + { + if (id != -1 && id != -2) + { + return id == -3; + } + return true; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/TouchJoystickExample.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/TouchJoystickExample.cs new file mode 100644 index 0000000..f05af89 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/TouchJoystickExample.cs @@ -0,0 +1,110 @@ +using System; +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +[RequireComponent(typeof(Image))] +public class TouchJoystickExample : MonoBehaviour, IPointerDownHandler, IEventSystemHandler, IPointerUpHandler, IDragHandler +{ + public bool allowMouseControl = true; + + public int radius = 50; + + private Vector2 origAnchoredPosition; + + private Vector3 origWorldPosition; + + private Vector2 origScreenResolution; + + private ScreenOrientation origScreenOrientation; + + [NonSerialized] + private bool hasFinger; + + [NonSerialized] + private int lastFingerId; + + public Vector2 position { get; private set; } + + private void Start() + { + if (SystemInfo.deviceType == DeviceType.Handheld) + { + allowMouseControl = false; + } + StoreOrigValues(); + } + + private void Update() + { + if ((float)Screen.width != origScreenResolution.x || (float)Screen.height != origScreenResolution.y || Screen.orientation != origScreenOrientation) + { + Restart(); + StoreOrigValues(); + } + } + + private void Restart() + { + hasFinger = false; + (base.transform as RectTransform).anchoredPosition = origAnchoredPosition; + position = Vector2.zero; + } + + private void StoreOrigValues() + { + origAnchoredPosition = (base.transform as RectTransform).anchoredPosition; + origWorldPosition = base.transform.position; + origScreenResolution = new Vector2(Screen.width, Screen.height); + origScreenOrientation = Screen.orientation; + } + + private void UpdateValue(Vector3 value) + { + Vector3 vector = origWorldPosition - value; + vector.y = 0f - vector.y; + vector /= (float)radius; + position = new Vector2(0f - vector.x, vector.y); + } + + void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + if (!hasFinger && (allowMouseControl || !IsMousePointerId(eventData.pointerId))) + { + hasFinger = true; + lastFingerId = eventData.pointerId; + } + } + + void IPointerUpHandler.OnPointerUp(PointerEventData eventData) + { + if (eventData.pointerId == lastFingerId && (allowMouseControl || !IsMousePointerId(eventData.pointerId))) + { + Restart(); + } + } + + void IDragHandler.OnDrag(PointerEventData eventData) + { + if (hasFinger && eventData.pointerId == lastFingerId) + { + Vector3 vector = new Vector3(eventData.position.x - origWorldPosition.x, eventData.position.y - origWorldPosition.y); + vector = Vector3.ClampMagnitude(vector, radius); + Vector3 value = origWorldPosition + vector; + base.transform.position = value; + UpdateValue(value); + } + } + + private static bool IsMousePointerId(int id) + { + if (id != -1 && id != -2) + { + return id == -3; + } + return true; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Demos/UIPointer.cs b/Thronefall_v1.0/Rewired/Rewired.Demos/UIPointer.cs new file mode 100644 index 0000000..c65fdae --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Demos/UIPointer.cs @@ -0,0 +1,98 @@ +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace Rewired.Demos; + +[AddComponentMenu("")] +[RequireComponent(typeof(RectTransform))] +public sealed class UIPointer : UIBehaviour +{ + [Tooltip("Should the hardware pointer be hidden?")] + [SerializeField] + private bool _hideHardwarePointer = true; + + [Tooltip("Sets the pointer to the last sibling in the parent hierarchy. Do not enable this on multiple UIPointers under the same parent transform or they will constantly fight each other for dominance.")] + [SerializeField] + private bool _autoSort = true; + + private Canvas _canvas; + + public bool autoSort + { + get + { + return _autoSort; + } + set + { + if (value != _autoSort) + { + _autoSort = value; + if (value) + { + base.transform.SetAsLastSibling(); + } + } + } + } + + protected override void Awake() + { + base.Awake(); + Graphic[] componentsInChildren = GetComponentsInChildren<Graphic>(); + for (int i = 0; i < componentsInChildren.Length; i++) + { + componentsInChildren[i].raycastTarget = false; + } + if (_hideHardwarePointer) + { + Cursor.visible = false; + } + if (_autoSort) + { + base.transform.SetAsLastSibling(); + } + GetDependencies(); + } + + private void Update() + { + if (_autoSort && base.transform.GetSiblingIndex() < base.transform.parent.childCount - 1) + { + base.transform.SetAsLastSibling(); + } + } + + protected override void OnTransformParentChanged() + { + base.OnTransformParentChanged(); + GetDependencies(); + } + + protected override void OnCanvasGroupChanged() + { + base.OnCanvasGroupChanged(); + GetDependencies(); + } + + public void OnScreenPositionChanged(Vector2 screenPosition) + { + if (!(_canvas == null)) + { + Camera cam = null; + RenderMode renderMode = _canvas.renderMode; + if (renderMode != 0 && (uint)(renderMode - 1) <= 1u) + { + cam = _canvas.worldCamera; + } + RectTransformUtility.ScreenPointToLocalPointInRectangle(base.transform.parent as RectTransform, screenPosition, cam, out var localPoint); + base.transform.localPosition = new Vector3(localPoint.x, localPoint.y, base.transform.localPosition.z); + } + } + + private void GetDependencies() + { + _canvas = base.transform.root.GetComponentInChildren<Canvas>(); + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/PlayerPointerEventData.cs b/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/PlayerPointerEventData.cs new file mode 100644 index 0000000..0c95915 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/PlayerPointerEventData.cs @@ -0,0 +1,41 @@ +using System.Text; +using Rewired.UI; +using UnityEngine.EventSystems; + +namespace Rewired.Integration.UnityUI; + +public class PlayerPointerEventData : PointerEventData +{ + public int playerId { get; set; } + + public int inputSourceIndex { get; set; } + + public IMouseInputSource mouseSource { get; set; } + + public ITouchInputSource touchSource { get; set; } + + public PointerEventType sourceType { get; set; } + + public int buttonIndex { get; set; } + + public PlayerPointerEventData(EventSystem eventSystem) + : base(eventSystem) + { + playerId = -1; + inputSourceIndex = -1; + buttonIndex = -1; + } + + public override string ToString() + { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.AppendLine("<b>Player Id</b>: " + playerId); + stringBuilder.AppendLine("<b>Mouse Source</b>: " + mouseSource); + stringBuilder.AppendLine("<b>Input Source Index</b>: " + inputSourceIndex); + stringBuilder.AppendLine("<b>Touch Source/b>: " + touchSource); + stringBuilder.AppendLine("<b>Source Type</b>: " + sourceType); + stringBuilder.AppendLine("<b>Button Index</b>: " + buttonIndex); + stringBuilder.Append(base.ToString()); + return stringBuilder.ToString(); + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/PointerEventType.cs b/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/PointerEventType.cs new file mode 100644 index 0000000..ce70ee8 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/PointerEventType.cs @@ -0,0 +1,7 @@ +namespace Rewired.Integration.UnityUI; + +public enum PointerEventType +{ + Mouse, + Touch +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/RewiredEventSystem.cs b/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/RewiredEventSystem.cs new file mode 100644 index 0000000..c46b002 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/RewiredEventSystem.cs @@ -0,0 +1,49 @@ +using UnityEngine; +using UnityEngine.EventSystems; + +namespace Rewired.Integration.UnityUI; + +[AddComponentMenu("Rewired/Rewired Event System")] +public class RewiredEventSystem : EventSystem +{ + [Tooltip("If enabled, the Event System will be updated every frame even if other Event Systems are enabled. Otherwise, only EventSystem.current will be updated.")] + [SerializeField] + private bool _alwaysUpdate; + + public bool alwaysUpdate + { + get + { + return _alwaysUpdate; + } + set + { + _alwaysUpdate = value; + } + } + + protected override void Update() + { + if (alwaysUpdate) + { + EventSystem eventSystem = EventSystem.current; + if (eventSystem != this) + { + EventSystem.current = this; + } + try + { + base.Update(); + return; + } + finally + { + if (eventSystem != this) + { + EventSystem.current = eventSystem; + } + } + } + base.Update(); + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/RewiredPointerInputModule.cs b/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/RewiredPointerInputModule.cs new file mode 100644 index 0000000..27d419b --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/RewiredPointerInputModule.cs @@ -0,0 +1,781 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Rewired.UI; +using Rewired.Utils; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace Rewired.Integration.UnityUI; + +public abstract class RewiredPointerInputModule : BaseInputModule +{ + protected class MouseState + { + private List<ButtonState> m_TrackedButtons = new List<ButtonState>(); + + public bool AnyPressesThisFrame() + { + for (int i = 0; i < m_TrackedButtons.Count; i++) + { + if (m_TrackedButtons[i].eventData.PressedThisFrame()) + { + return true; + } + } + return false; + } + + public bool AnyReleasesThisFrame() + { + for (int i = 0; i < m_TrackedButtons.Count; i++) + { + if (m_TrackedButtons[i].eventData.ReleasedThisFrame()) + { + return true; + } + } + return false; + } + + public ButtonState GetButtonState(int button) + { + ButtonState buttonState = null; + for (int i = 0; i < m_TrackedButtons.Count; i++) + { + if (m_TrackedButtons[i].button == button) + { + buttonState = m_TrackedButtons[i]; + break; + } + } + if (buttonState == null) + { + buttonState = new ButtonState + { + button = button, + eventData = new MouseButtonEventData() + }; + m_TrackedButtons.Add(buttonState); + } + return buttonState; + } + + public void SetButtonState(int button, PointerEventData.FramePressState stateForMouseButton, PlayerPointerEventData data) + { + ButtonState buttonState = GetButtonState(button); + buttonState.eventData.buttonState = stateForMouseButton; + buttonState.eventData.buttonData = data; + } + } + + public class MouseButtonEventData + { + public PointerEventData.FramePressState buttonState; + + public PlayerPointerEventData buttonData; + + public bool PressedThisFrame() + { + if (buttonState != 0) + { + return buttonState == PointerEventData.FramePressState.PressedAndReleased; + } + return true; + } + + public bool ReleasedThisFrame() + { + if (buttonState != PointerEventData.FramePressState.Released) + { + return buttonState == PointerEventData.FramePressState.PressedAndReleased; + } + return true; + } + } + + protected class ButtonState + { + private int m_Button; + + private MouseButtonEventData m_EventData; + + public MouseButtonEventData eventData + { + get + { + return m_EventData; + } + set + { + m_EventData = value; + } + } + + public int button + { + get + { + return m_Button; + } + set + { + m_Button = value; + } + } + } + + private sealed class UnityInputSource : IMouseInputSource, ITouchInputSource + { + private Vector2 m_MousePosition; + + private Vector2 m_MousePositionPrev; + + private int m_LastUpdatedFrame = -1; + + int IMouseInputSource.playerId + { + get + { + TryUpdate(); + return 0; + } + } + + int ITouchInputSource.playerId + { + get + { + TryUpdate(); + return 0; + } + } + + bool IMouseInputSource.enabled + { + get + { + TryUpdate(); + return Input.mousePresent; + } + } + + bool IMouseInputSource.locked + { + get + { + TryUpdate(); + return Cursor.lockState == CursorLockMode.Locked; + } + } + + int IMouseInputSource.buttonCount + { + get + { + TryUpdate(); + return 3; + } + } + + Vector2 IMouseInputSource.screenPosition + { + get + { + TryUpdate(); + return Input.mousePosition; + } + } + + Vector2 IMouseInputSource.screenPositionDelta + { + get + { + TryUpdate(); + return m_MousePosition - m_MousePositionPrev; + } + } + + Vector2 IMouseInputSource.wheelDelta + { + get + { + TryUpdate(); + return Input.mouseScrollDelta; + } + } + + bool ITouchInputSource.touchSupported + { + get + { + TryUpdate(); + return Input.touchSupported; + } + } + + int ITouchInputSource.touchCount + { + get + { + TryUpdate(); + return Input.touchCount; + } + } + + bool IMouseInputSource.GetButtonDown(int button) + { + TryUpdate(); + return Input.GetMouseButtonDown(button); + } + + bool IMouseInputSource.GetButtonUp(int button) + { + TryUpdate(); + return Input.GetMouseButtonUp(button); + } + + bool IMouseInputSource.GetButton(int button) + { + TryUpdate(); + return Input.GetMouseButton(button); + } + + Touch ITouchInputSource.GetTouch(int index) + { + TryUpdate(); + return Input.GetTouch(index); + } + + private void TryUpdate() + { + if (Time.frameCount != m_LastUpdatedFrame) + { + m_LastUpdatedFrame = Time.frameCount; + m_MousePositionPrev = m_MousePosition; + m_MousePosition = Input.mousePosition; + } + } + } + + public const int kMouseLeftId = -1; + + public const int kMouseRightId = -2; + + public const int kMouseMiddleId = -3; + + public const int kFakeTouchesId = -4; + + private const int customButtonsStartingId = -2147483520; + + private const int customButtonsMaxCount = 128; + + private const int customButtonsLastId = -2147483392; + + private readonly List<IMouseInputSource> m_MouseInputSourcesList = new List<IMouseInputSource>(); + + private Dictionary<int, Dictionary<int, PlayerPointerEventData>[]> m_PlayerPointerData = new Dictionary<int, Dictionary<int, PlayerPointerEventData>[]>(); + + private ITouchInputSource m_UserDefaultTouchInputSource; + + private UnityInputSource __m_DefaultInputSource; + + private readonly MouseState m_MouseState = new MouseState(); + + private UnityInputSource defaultInputSource + { + get + { + if (__m_DefaultInputSource == null) + { + return __m_DefaultInputSource = new UnityInputSource(); + } + return __m_DefaultInputSource; + } + } + + private IMouseInputSource defaultMouseInputSource => defaultInputSource; + + protected ITouchInputSource defaultTouchInputSource => defaultInputSource; + + protected virtual bool isMouseSupported + { + get + { + int count = m_MouseInputSourcesList.Count; + if (count == 0) + { + return defaultMouseInputSource.enabled; + } + for (int i = 0; i < count; i++) + { + if (m_MouseInputSourcesList[i].enabled) + { + return true; + } + } + return false; + } + } + + protected bool IsDefaultMouse(IMouseInputSource mouse) + { + return defaultMouseInputSource == mouse; + } + + public IMouseInputSource GetMouseInputSource(int playerId, int mouseIndex) + { + if (mouseIndex < 0) + { + throw new ArgumentOutOfRangeException("mouseIndex"); + } + if (m_MouseInputSourcesList.Count == 0 && IsDefaultPlayer(playerId)) + { + return defaultMouseInputSource; + } + int count = m_MouseInputSourcesList.Count; + int num = 0; + for (int i = 0; i < count; i++) + { + IMouseInputSource mouseInputSource = m_MouseInputSourcesList[i]; + if (!UnityTools.IsNullOrDestroyed(mouseInputSource) && mouseInputSource.playerId == playerId) + { + if (mouseIndex == num) + { + return mouseInputSource; + } + num++; + } + } + return null; + } + + public void RemoveMouseInputSource(IMouseInputSource source) + { + if (source == null) + { + throw new ArgumentNullException("source"); + } + m_MouseInputSourcesList.Remove(source); + } + + public void AddMouseInputSource(IMouseInputSource source) + { + if (UnityTools.IsNullOrDestroyed(source)) + { + throw new ArgumentNullException("source"); + } + m_MouseInputSourcesList.Add(source); + } + + public int GetMouseInputSourceCount(int playerId) + { + if (m_MouseInputSourcesList.Count == 0 && IsDefaultPlayer(playerId)) + { + return 1; + } + int count = m_MouseInputSourcesList.Count; + int num = 0; + for (int i = 0; i < count; i++) + { + IMouseInputSource mouseInputSource = m_MouseInputSourcesList[i]; + if (!UnityTools.IsNullOrDestroyed(mouseInputSource) && mouseInputSource.playerId == playerId) + { + num++; + } + } + return num; + } + + public ITouchInputSource GetTouchInputSource(int playerId, int sourceIndex) + { + if (!UnityTools.IsNullOrDestroyed(m_UserDefaultTouchInputSource)) + { + return m_UserDefaultTouchInputSource; + } + return defaultTouchInputSource; + } + + public void RemoveTouchInputSource(ITouchInputSource source) + { + if (source == null) + { + throw new ArgumentNullException("source"); + } + if (m_UserDefaultTouchInputSource == source) + { + m_UserDefaultTouchInputSource = null; + } + } + + public void AddTouchInputSource(ITouchInputSource source) + { + if (UnityTools.IsNullOrDestroyed(source)) + { + throw new ArgumentNullException("source"); + } + m_UserDefaultTouchInputSource = source; + } + + public int GetTouchInputSourceCount(int playerId) + { + if (!IsDefaultPlayer(playerId)) + { + return 0; + } + return 1; + } + + protected void ClearMouseInputSources() + { + m_MouseInputSourcesList.Clear(); + } + + protected abstract bool IsDefaultPlayer(int playerId); + + protected bool GetPointerData(int playerId, int pointerIndex, int pointerTypeId, out PlayerPointerEventData data, bool create, PointerEventType pointerEventType) + { + if (!m_PlayerPointerData.TryGetValue(playerId, out var value)) + { + value = new Dictionary<int, PlayerPointerEventData>[pointerIndex + 1]; + for (int i = 0; i < value.Length; i++) + { + value[i] = new Dictionary<int, PlayerPointerEventData>(); + } + m_PlayerPointerData.Add(playerId, value); + } + if (pointerIndex >= value.Length) + { + Dictionary<int, PlayerPointerEventData>[] array = new Dictionary<int, PlayerPointerEventData>[pointerIndex + 1]; + for (int j = 0; j < value.Length; j++) + { + array[j] = value[j]; + } + array[pointerIndex] = new Dictionary<int, PlayerPointerEventData>(); + value = array; + m_PlayerPointerData[playerId] = value; + } + Dictionary<int, PlayerPointerEventData> dictionary = value[pointerIndex]; + if (!dictionary.TryGetValue(pointerTypeId, out data)) + { + if (!create) + { + return false; + } + data = CreatePointerEventData(playerId, pointerIndex, pointerTypeId, pointerEventType); + dictionary.Add(pointerTypeId, data); + return true; + } + data.mouseSource = ((pointerEventType == PointerEventType.Mouse) ? GetMouseInputSource(playerId, pointerIndex) : null); + data.touchSource = ((pointerEventType == PointerEventType.Touch) ? GetTouchInputSource(playerId, pointerIndex) : null); + return false; + } + + private PlayerPointerEventData CreatePointerEventData(int playerId, int pointerIndex, int pointerTypeId, PointerEventType pointerEventType) + { + PlayerPointerEventData playerPointerEventData = new PlayerPointerEventData(base.eventSystem) + { + playerId = playerId, + inputSourceIndex = pointerIndex, + pointerId = pointerTypeId, + sourceType = pointerEventType + }; + switch (pointerEventType) + { + case PointerEventType.Mouse: + playerPointerEventData.mouseSource = GetMouseInputSource(playerId, pointerIndex); + break; + case PointerEventType.Touch: + playerPointerEventData.touchSource = GetTouchInputSource(playerId, pointerIndex); + break; + } + if (pointerTypeId == -1) + { + playerPointerEventData.buttonIndex = 0; + } + else if (pointerTypeId == -2) + { + playerPointerEventData.buttonIndex = 1; + } + else if (pointerTypeId == -3) + { + playerPointerEventData.buttonIndex = 2; + } + else if (pointerTypeId >= -2147483520 && pointerTypeId <= -2147483392) + { + playerPointerEventData.buttonIndex = pointerTypeId - -2147483520; + } + return playerPointerEventData; + } + + protected void RemovePointerData(PlayerPointerEventData data) + { + if (m_PlayerPointerData.TryGetValue(data.playerId, out var value) && (uint)data.inputSourceIndex < (uint)value.Length) + { + value[data.inputSourceIndex].Remove(data.pointerId); + } + } + + protected PlayerPointerEventData GetTouchPointerEventData(int playerId, int touchDeviceIndex, Touch input, out bool pressed, out bool released) + { + PlayerPointerEventData data; + bool pointerData = GetPointerData(playerId, touchDeviceIndex, input.fingerId, out data, create: true, PointerEventType.Touch); + data.Reset(); + pressed = pointerData || input.phase == TouchPhase.Began; + released = input.phase == TouchPhase.Canceled || input.phase == TouchPhase.Ended; + if (pointerData) + { + data.position = input.position; + } + if (pressed) + { + data.delta = Vector2.zero; + } + else + { + data.delta = input.position - data.position; + } + data.position = input.position; + data.button = PointerEventData.InputButton.Left; + base.eventSystem.RaycastAll(data, m_RaycastResultCache); + RaycastResult pointerCurrentRaycast = BaseInputModule.FindFirstRaycast(m_RaycastResultCache); + data.pointerCurrentRaycast = pointerCurrentRaycast; + m_RaycastResultCache.Clear(); + return data; + } + + protected virtual MouseState GetMousePointerEventData(int playerId, int mouseIndex) + { + IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, mouseIndex); + if (mouseInputSource == null) + { + return null; + } + PlayerPointerEventData data; + bool pointerData = GetPointerData(playerId, mouseIndex, -1, out data, create: true, PointerEventType.Mouse); + data.Reset(); + if (pointerData) + { + data.position = mouseInputSource.screenPosition; + } + Vector2 screenPosition = mouseInputSource.screenPosition; + if (mouseInputSource.locked || !mouseInputSource.enabled) + { + data.position = new Vector2(-1f, -1f); + data.delta = Vector2.zero; + } + else + { + data.delta = screenPosition - data.position; + data.position = screenPosition; + } + data.scrollDelta = mouseInputSource.wheelDelta; + data.button = PointerEventData.InputButton.Left; + base.eventSystem.RaycastAll(data, m_RaycastResultCache); + RaycastResult pointerCurrentRaycast = BaseInputModule.FindFirstRaycast(m_RaycastResultCache); + data.pointerCurrentRaycast = pointerCurrentRaycast; + m_RaycastResultCache.Clear(); + GetPointerData(playerId, mouseIndex, -2, out var data2, create: true, PointerEventType.Mouse); + CopyFromTo(data, data2); + data2.button = PointerEventData.InputButton.Right; + GetPointerData(playerId, mouseIndex, -3, out var data3, create: true, PointerEventType.Mouse); + CopyFromTo(data, data3); + data3.button = PointerEventData.InputButton.Middle; + for (int i = 3; i < mouseInputSource.buttonCount; i++) + { + GetPointerData(playerId, mouseIndex, -2147483520 + i, out var data4, create: true, PointerEventType.Mouse); + CopyFromTo(data, data4); + data4.button = (PointerEventData.InputButton)(-1); + } + m_MouseState.SetButtonState(0, StateForMouseButton(playerId, mouseIndex, 0), data); + m_MouseState.SetButtonState(1, StateForMouseButton(playerId, mouseIndex, 1), data2); + m_MouseState.SetButtonState(2, StateForMouseButton(playerId, mouseIndex, 2), data3); + for (int j = 3; j < mouseInputSource.buttonCount; j++) + { + GetPointerData(playerId, mouseIndex, -2147483520 + j, out var data5, create: false, PointerEventType.Mouse); + m_MouseState.SetButtonState(j, StateForMouseButton(playerId, mouseIndex, j), data5); + } + return m_MouseState; + } + + protected PlayerPointerEventData GetLastPointerEventData(int playerId, int pointerIndex, int pointerTypeId, bool ignorePointerTypeId, PointerEventType pointerEventType) + { + if (!ignorePointerTypeId) + { + GetPointerData(playerId, pointerIndex, pointerTypeId, out var data, create: false, pointerEventType); + return data; + } + if (!m_PlayerPointerData.TryGetValue(playerId, out var value)) + { + return null; + } + if ((uint)pointerIndex >= (uint)value.Length) + { + return null; + } + using (Dictionary<int, PlayerPointerEventData>.Enumerator enumerator = value[pointerIndex].GetEnumerator()) + { + if (enumerator.MoveNext()) + { + return enumerator.Current.Value; + } + } + return null; + } + + private static bool ShouldStartDrag(Vector2 pressPos, Vector2 currentPos, float threshold, bool useDragThreshold) + { + if (!useDragThreshold) + { + return true; + } + return (pressPos - currentPos).sqrMagnitude >= threshold * threshold; + } + + protected virtual void ProcessMove(PlayerPointerEventData pointerEvent) + { + GameObject newEnterTarget; + if (pointerEvent.sourceType == PointerEventType.Mouse) + { + IMouseInputSource mouseInputSource = GetMouseInputSource(pointerEvent.playerId, pointerEvent.inputSourceIndex); + newEnterTarget = ((mouseInputSource == null) ? null : ((!mouseInputSource.enabled || mouseInputSource.locked) ? null : pointerEvent.pointerCurrentRaycast.gameObject)); + } + else + { + if (pointerEvent.sourceType != PointerEventType.Touch) + { + throw new NotImplementedException(); + } + newEnterTarget = pointerEvent.pointerCurrentRaycast.gameObject; + } + HandlePointerExitAndEnter(pointerEvent, newEnterTarget); + } + + protected virtual void ProcessDrag(PlayerPointerEventData pointerEvent) + { + if (!pointerEvent.IsPointerMoving() || pointerEvent.pointerDrag == null) + { + return; + } + if (pointerEvent.sourceType == PointerEventType.Mouse) + { + IMouseInputSource mouseInputSource = GetMouseInputSource(pointerEvent.playerId, pointerEvent.inputSourceIndex); + if (mouseInputSource == null || mouseInputSource.locked || !mouseInputSource.enabled) + { + return; + } + } + if (!pointerEvent.dragging && ShouldStartDrag(pointerEvent.pressPosition, pointerEvent.position, base.eventSystem.pixelDragThreshold, pointerEvent.useDragThreshold)) + { + ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.beginDragHandler); + pointerEvent.dragging = true; + } + if (pointerEvent.dragging) + { + if (pointerEvent.pointerPress != pointerEvent.pointerDrag) + { + ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); + pointerEvent.eligibleForClick = false; + pointerEvent.pointerPress = null; + pointerEvent.rawPointerPress = null; + } + ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.dragHandler); + } + } + + public override bool IsPointerOverGameObject(int pointerTypeId) + { + foreach (KeyValuePair<int, Dictionary<int, PlayerPointerEventData>[]> playerPointerDatum in m_PlayerPointerData) + { + Dictionary<int, PlayerPointerEventData>[] value = playerPointerDatum.Value; + for (int i = 0; i < value.Length; i++) + { + if (value[i].TryGetValue(pointerTypeId, out var value2) && value2.pointerEnter != null) + { + return true; + } + } + } + return false; + } + + protected void ClearSelection() + { + BaseEventData baseEventData = GetBaseEventData(); + foreach (KeyValuePair<int, Dictionary<int, PlayerPointerEventData>[]> playerPointerDatum in m_PlayerPointerData) + { + Dictionary<int, PlayerPointerEventData>[] value = playerPointerDatum.Value; + for (int i = 0; i < value.Length; i++) + { + foreach (KeyValuePair<int, PlayerPointerEventData> item in value[i]) + { + HandlePointerExitAndEnter(item.Value, null); + } + value[i].Clear(); + } + } + base.eventSystem.SetSelectedGameObject(null, baseEventData); + } + + public override string ToString() + { + StringBuilder stringBuilder = new StringBuilder("<b>Pointer Input Module of type: </b>" + GetType()); + stringBuilder.AppendLine(); + foreach (KeyValuePair<int, Dictionary<int, PlayerPointerEventData>[]> playerPointerDatum in m_PlayerPointerData) + { + stringBuilder.AppendLine("<B>Player Id:</b> " + playerPointerDatum.Key); + Dictionary<int, PlayerPointerEventData>[] value = playerPointerDatum.Value; + for (int i = 0; i < value.Length; i++) + { + stringBuilder.AppendLine("<B>Pointer Index:</b> " + i); + foreach (KeyValuePair<int, PlayerPointerEventData> item in value[i]) + { + stringBuilder.AppendLine("<B>Button Id:</b> " + item.Key); + stringBuilder.AppendLine(item.Value.ToString()); + } + } + } + return stringBuilder.ToString(); + } + + protected void DeselectIfSelectionChanged(GameObject currentOverGo, BaseEventData pointerEvent) + { + if (ExecuteEvents.GetEventHandler<ISelectHandler>(currentOverGo) != base.eventSystem.currentSelectedGameObject) + { + base.eventSystem.SetSelectedGameObject(null, pointerEvent); + } + } + + protected void CopyFromTo(PointerEventData from, PointerEventData to) + { + to.position = from.position; + to.delta = from.delta; + to.scrollDelta = from.scrollDelta; + to.pointerCurrentRaycast = from.pointerCurrentRaycast; + to.pointerEnter = from.pointerEnter; + } + + protected PointerEventData.FramePressState StateForMouseButton(int playerId, int mouseIndex, int buttonId) + { + IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, mouseIndex); + if (mouseInputSource == null) + { + return PointerEventData.FramePressState.NotChanged; + } + bool buttonDown = mouseInputSource.GetButtonDown(buttonId); + bool buttonUp = mouseInputSource.GetButtonUp(buttonId); + if (buttonDown && buttonUp) + { + return PointerEventData.FramePressState.PressedAndReleased; + } + if (buttonDown) + { + return PointerEventData.FramePressState.Pressed; + } + if (buttonUp) + { + return PointerEventData.FramePressState.Released; + } + return PointerEventData.FramePressState.NotChanged; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/RewiredStandaloneInputModule.cs b/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/RewiredStandaloneInputModule.cs new file mode 100644 index 0000000..02245ab --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Integration.UnityUI/RewiredStandaloneInputModule.cs @@ -0,0 +1,1415 @@ +using System; +using System.Collections.Generic; +using Rewired.Components; +using Rewired.UI; +using Rewired.Utils; +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.Serialization; + +namespace Rewired.Integration.UnityUI; + +[AddComponentMenu("Rewired/Rewired Standalone Input Module")] +public sealed class RewiredStandaloneInputModule : RewiredPointerInputModule +{ + [Serializable] + public class PlayerSetting + { + public int playerId; + + public List<Rewired.Components.PlayerMouse> playerMice = new List<Rewired.Components.PlayerMouse>(); + + public PlayerSetting() + { + } + + private PlayerSetting(PlayerSetting other) + { + if (other == null) + { + throw new ArgumentNullException("other"); + } + playerId = other.playerId; + playerMice = new List<Rewired.Components.PlayerMouse>(); + if (other.playerMice == null) + { + return; + } + foreach (Rewired.Components.PlayerMouse item in other.playerMice) + { + playerMice.Add(item); + } + } + + public PlayerSetting Clone() + { + return new PlayerSetting(this); + } + } + + private const string DEFAULT_ACTION_MOVE_HORIZONTAL = "UIHorizontal"; + + private const string DEFAULT_ACTION_MOVE_VERTICAL = "UIVertical"; + + private const string DEFAULT_ACTION_SUBMIT = "UISubmit"; + + private const string DEFAULT_ACTION_CANCEL = "UICancel"; + + [Tooltip("(Optional) Link the Rewired Input Manager here for easier access to Player ids, etc.")] + [SerializeField] + private InputManager_Base rewiredInputManager; + + [SerializeField] + [Tooltip("Use all Rewired game Players to control the UI. This does not include the System Player. If enabled, this setting overrides individual Player Ids set in Rewired Player Ids.")] + private bool useAllRewiredGamePlayers; + + [SerializeField] + [Tooltip("Allow the Rewired System Player to control the UI.")] + private bool useRewiredSystemPlayer; + + [SerializeField] + [Tooltip("A list of Player Ids that are allowed to control the UI. If Use All Rewired Game Players = True, this list will be ignored.")] + private int[] rewiredPlayerIds = new int[1]; + + [SerializeField] + [Tooltip("Allow only Players with Player.isPlaying = true to control the UI.")] + private bool usePlayingPlayersOnly; + + [SerializeField] + [Tooltip("Player Mice allowed to interact with the UI. Each Player that owns a Player Mouse must also be allowed to control the UI or the Player Mouse will not function.")] + private List<Rewired.Components.PlayerMouse> playerMice = new List<Rewired.Components.PlayerMouse>(); + + [SerializeField] + [Tooltip("Makes an axis press always move only one UI selection. Enable if you do not want to allow scrolling through UI elements by holding an axis direction.")] + private bool moveOneElementPerAxisPress; + + [SerializeField] + [Tooltip("If enabled, Action Ids will be used to set the Actions. If disabled, string names will be used to set the Actions.")] + private bool setActionsById; + + [SerializeField] + [Tooltip("Id of the horizontal Action for movement (if axis events are used).")] + private int horizontalActionId = -1; + + [SerializeField] + [Tooltip("Id of the vertical Action for movement (if axis events are used).")] + private int verticalActionId = -1; + + [SerializeField] + [Tooltip("Id of the Action used to submit.")] + private int submitActionId = -1; + + [SerializeField] + [Tooltip("Id of the Action used to cancel.")] + private int cancelActionId = -1; + + [SerializeField] + [Tooltip("Name of the horizontal axis for movement (if axis events are used).")] + private string m_HorizontalAxis = "UIHorizontal"; + + [SerializeField] + [Tooltip("Name of the vertical axis for movement (if axis events are used).")] + private string m_VerticalAxis = "UIVertical"; + + [SerializeField] + [Tooltip("Name of the action used to submit.")] + private string m_SubmitButton = "UISubmit"; + + [SerializeField] + [Tooltip("Name of the action used to cancel.")] + private string m_CancelButton = "UICancel"; + + [SerializeField] + [Tooltip("Number of selection changes allowed per second when a movement button/axis is held in a direction.")] + private float m_InputActionsPerSecond = 10f; + + [SerializeField] + [Tooltip("Delay in seconds before vertical/horizontal movement starts repeating continouously when a movement direction is held.")] + private float m_RepeatDelay; + + [SerializeField] + [Tooltip("Allows the mouse to be used to select elements.")] + private bool m_allowMouseInput = true; + + [SerializeField] + [Tooltip("Allows the mouse to be used to select elements if the device also supports touch control.")] + private bool m_allowMouseInputIfTouchSupported = true; + + [SerializeField] + [Tooltip("Allows touch input to be used to select elements.")] + private bool m_allowTouchInput = true; + + [SerializeField] + [Tooltip("Deselects the current selection on mouse/touch click when the pointer is not over a selectable object.")] + private bool m_deselectIfBackgroundClicked = true; + + [SerializeField] + [Tooltip("Deselects the current selection on mouse/touch click before selecting the next object.")] + private bool m_deselectBeforeSelecting = true; + + [SerializeField] + [FormerlySerializedAs("m_AllowActivationOnMobileDevice")] + [Tooltip("Forces the module to always be active.")] + private bool m_ForceModuleActive; + + [NonSerialized] + private int[] playerIds; + + private bool recompiling; + + [NonSerialized] + private bool isTouchSupported; + + [NonSerialized] + private double m_PrevActionTime; + + [NonSerialized] + private Vector2 m_LastMoveVector; + + [NonSerialized] + private int m_ConsecutiveMoveCount; + + [NonSerialized] + private bool m_HasFocus = true; + + public InputManager_Base RewiredInputManager + { + get + { + return rewiredInputManager; + } + set + { + rewiredInputManager = value; + } + } + + public bool UseAllRewiredGamePlayers + { + get + { + return useAllRewiredGamePlayers; + } + set + { + bool num = value != useAllRewiredGamePlayers; + useAllRewiredGamePlayers = value; + if (num) + { + SetupRewiredVars(); + } + } + } + + public bool UseRewiredSystemPlayer + { + get + { + return useRewiredSystemPlayer; + } + set + { + bool num = value != useRewiredSystemPlayer; + useRewiredSystemPlayer = value; + if (num) + { + SetupRewiredVars(); + } + } + } + + public int[] RewiredPlayerIds + { + get + { + return (int[])rewiredPlayerIds.Clone(); + } + set + { + rewiredPlayerIds = ((value != null) ? ((int[])value.Clone()) : new int[0]); + SetupRewiredVars(); + } + } + + public bool UsePlayingPlayersOnly + { + get + { + return usePlayingPlayersOnly; + } + set + { + usePlayingPlayersOnly = value; + } + } + + public List<Rewired.Components.PlayerMouse> PlayerMice + { + get + { + return new List<Rewired.Components.PlayerMouse>(playerMice); + } + set + { + if (value == null) + { + playerMice = new List<Rewired.Components.PlayerMouse>(); + SetupRewiredVars(); + } + else + { + playerMice = new List<Rewired.Components.PlayerMouse>(value); + SetupRewiredVars(); + } + } + } + + public bool MoveOneElementPerAxisPress + { + get + { + return moveOneElementPerAxisPress; + } + set + { + moveOneElementPerAxisPress = value; + } + } + + public bool allowMouseInput + { + get + { + return m_allowMouseInput; + } + set + { + m_allowMouseInput = value; + } + } + + public bool allowMouseInputIfTouchSupported + { + get + { + return m_allowMouseInputIfTouchSupported; + } + set + { + m_allowMouseInputIfTouchSupported = value; + } + } + + public bool allowTouchInput + { + get + { + return m_allowTouchInput; + } + set + { + m_allowTouchInput = value; + } + } + + public bool deselectIfBackgroundClicked + { + get + { + return m_deselectIfBackgroundClicked; + } + set + { + m_deselectIfBackgroundClicked = value; + } + } + + private bool deselectBeforeSelecting + { + get + { + return m_deselectBeforeSelecting; + } + set + { + m_deselectBeforeSelecting = value; + } + } + + public bool SetActionsById + { + get + { + return setActionsById; + } + set + { + if (setActionsById != value) + { + setActionsById = value; + SetupRewiredVars(); + } + } + } + + public int HorizontalActionId + { + get + { + return horizontalActionId; + } + set + { + if (value != horizontalActionId) + { + horizontalActionId = value; + if (ReInput.isReady) + { + m_HorizontalAxis = ((ReInput.mapping.GetAction(value) != null) ? ReInput.mapping.GetAction(value).name : string.Empty); + } + } + } + } + + public int VerticalActionId + { + get + { + return verticalActionId; + } + set + { + if (value != verticalActionId) + { + verticalActionId = value; + if (ReInput.isReady) + { + m_VerticalAxis = ((ReInput.mapping.GetAction(value) != null) ? ReInput.mapping.GetAction(value).name : string.Empty); + } + } + } + } + + public int SubmitActionId + { + get + { + return submitActionId; + } + set + { + if (value != submitActionId) + { + submitActionId = value; + if (ReInput.isReady) + { + m_SubmitButton = ((ReInput.mapping.GetAction(value) != null) ? ReInput.mapping.GetAction(value).name : string.Empty); + } + } + } + } + + public int CancelActionId + { + get + { + return cancelActionId; + } + set + { + if (value != cancelActionId) + { + cancelActionId = value; + if (ReInput.isReady) + { + m_CancelButton = ((ReInput.mapping.GetAction(value) != null) ? ReInput.mapping.GetAction(value).name : string.Empty); + } + } + } + } + + protected override bool isMouseSupported + { + get + { + if (!base.isMouseSupported) + { + return false; + } + if (!m_allowMouseInput) + { + return false; + } + if (!isTouchSupported) + { + return true; + } + return m_allowMouseInputIfTouchSupported; + } + } + + private bool isTouchAllowed => m_allowTouchInput; + + [Obsolete("allowActivationOnMobileDevice has been deprecated. Use forceModuleActive instead")] + public bool allowActivationOnMobileDevice + { + get + { + return m_ForceModuleActive; + } + set + { + m_ForceModuleActive = value; + } + } + + public bool forceModuleActive + { + get + { + return m_ForceModuleActive; + } + set + { + m_ForceModuleActive = value; + } + } + + public float inputActionsPerSecond + { + get + { + return m_InputActionsPerSecond; + } + set + { + m_InputActionsPerSecond = value; + } + } + + public float repeatDelay + { + get + { + return m_RepeatDelay; + } + set + { + m_RepeatDelay = value; + } + } + + public string horizontalAxis + { + get + { + return m_HorizontalAxis; + } + set + { + if (!(m_HorizontalAxis == value)) + { + m_HorizontalAxis = value; + if (ReInput.isReady) + { + horizontalActionId = ReInput.mapping.GetActionId(value); + } + } + } + } + + public string verticalAxis + { + get + { + return m_VerticalAxis; + } + set + { + if (!(m_VerticalAxis == value)) + { + m_VerticalAxis = value; + if (ReInput.isReady) + { + verticalActionId = ReInput.mapping.GetActionId(value); + } + } + } + } + + public string submitButton + { + get + { + return m_SubmitButton; + } + set + { + if (!(m_SubmitButton == value)) + { + m_SubmitButton = value; + if (ReInput.isReady) + { + submitActionId = ReInput.mapping.GetActionId(value); + } + } + } + } + + public string cancelButton + { + get + { + return m_CancelButton; + } + set + { + if (!(m_CancelButton == value)) + { + m_CancelButton = value; + if (ReInput.isReady) + { + cancelActionId = ReInput.mapping.GetActionId(value); + } + } + } + } + + private RewiredStandaloneInputModule() + { + } + + protected override void Awake() + { + base.Awake(); + isTouchSupported = base.defaultTouchInputSource.touchSupported; + TouchInputModule component = GetComponent<TouchInputModule>(); + if (component != null) + { + component.enabled = false; + } + ReInput.InitializedEvent += OnRewiredInitialized; + InitializeRewired(); + } + + public override void UpdateModule() + { + CheckEditorRecompile(); + if (!recompiling && ReInput.isReady && !m_HasFocus) + { + ShouldIgnoreEventsOnNoFocus(); + } + } + + public override bool IsModuleSupported() + { + return true; + } + + public override bool ShouldActivateModule() + { + if (!base.ShouldActivateModule()) + { + return false; + } + if (recompiling) + { + return false; + } + if (!ReInput.isReady) + { + return false; + } + bool flag = m_ForceModuleActive; + for (int i = 0; i < playerIds.Length; i++) + { + Player player = ReInput.players.GetPlayer(playerIds[i]); + if (player != null && (!usePlayingPlayersOnly || player.isPlaying)) + { + flag |= GetButtonDown(player, submitActionId); + flag |= GetButtonDown(player, cancelActionId); + if (moveOneElementPerAxisPress) + { + flag |= GetButtonDown(player, horizontalActionId) || GetNegativeButtonDown(player, horizontalActionId); + flag |= GetButtonDown(player, verticalActionId) || GetNegativeButtonDown(player, verticalActionId); + } + else + { + flag |= !Mathf.Approximately(GetAxis(player, horizontalActionId), 0f); + flag |= !Mathf.Approximately(GetAxis(player, verticalActionId), 0f); + } + } + } + if (isMouseSupported) + { + flag |= DidAnyMouseMove(); + flag |= GetMouseButtonDownOnAnyMouse(0); + } + if (isTouchAllowed) + { + for (int j = 0; j < base.defaultTouchInputSource.touchCount; j++) + { + Touch touch = base.defaultTouchInputSource.GetTouch(j); + flag |= touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary; + } + } + return flag; + } + + public override void ActivateModule() + { + if (m_HasFocus || !ShouldIgnoreEventsOnNoFocus()) + { + base.ActivateModule(); + GameObject gameObject = base.eventSystem.currentSelectedGameObject; + if (gameObject == null) + { + gameObject = base.eventSystem.firstSelectedGameObject; + } + base.eventSystem.SetSelectedGameObject(gameObject, GetBaseEventData()); + } + } + + public override void DeactivateModule() + { + base.DeactivateModule(); + ClearSelection(); + } + + public override void Process() + { + if (!ReInput.isReady || (!m_HasFocus && ShouldIgnoreEventsOnNoFocus()) || !base.enabled || !base.gameObject.activeInHierarchy) + { + return; + } + bool flag = SendUpdateEventToSelectedObject(); + if (base.eventSystem.sendNavigationEvents) + { + if (!flag) + { + flag |= SendMoveEventToSelectedObject(); + } + if (!flag) + { + SendSubmitEventToSelectedObject(); + } + } + if (!ProcessTouchEvents() && isMouseSupported) + { + ProcessMouseEvents(); + } + } + + private bool ProcessTouchEvents() + { + if (!isTouchAllowed) + { + return false; + } + for (int i = 0; i < base.defaultTouchInputSource.touchCount; i++) + { + Touch touch = base.defaultTouchInputSource.GetTouch(i); + if (touch.type != TouchType.Indirect) + { + bool pressed; + bool released; + PlayerPointerEventData touchPointerEventData = GetTouchPointerEventData(0, 0, touch, out pressed, out released); + ProcessTouchPress(touchPointerEventData, pressed, released); + if (!released) + { + ProcessMove(touchPointerEventData); + ProcessDrag(touchPointerEventData); + } + else + { + RemovePointerData(touchPointerEventData); + } + } + } + return base.defaultTouchInputSource.touchCount > 0; + } + + private void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released) + { + GameObject gameObject = pointerEvent.pointerCurrentRaycast.gameObject; + if (pressed) + { + pointerEvent.eligibleForClick = true; + pointerEvent.delta = Vector2.zero; + pointerEvent.dragging = false; + pointerEvent.useDragThreshold = true; + pointerEvent.pressPosition = pointerEvent.position; + pointerEvent.pointerPressRaycast = pointerEvent.pointerCurrentRaycast; + HandleMouseTouchDeselectionOnSelectionChanged(gameObject, pointerEvent); + if (pointerEvent.pointerEnter != gameObject) + { + HandlePointerExitAndEnter(pointerEvent, gameObject); + pointerEvent.pointerEnter = gameObject; + } + GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy(gameObject, pointerEvent, ExecuteEvents.pointerDownHandler); + if (gameObject2 == null) + { + gameObject2 = ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject); + } + double unscaledTime = ReInput.time.unscaledTime; + if (gameObject2 == pointerEvent.lastPress) + { + if (unscaledTime - (double)pointerEvent.clickTime < 0.30000001192092896) + { + int clickCount = pointerEvent.clickCount + 1; + pointerEvent.clickCount = clickCount; + } + else + { + pointerEvent.clickCount = 1; + } + pointerEvent.clickTime = (float)unscaledTime; + } + else + { + pointerEvent.clickCount = 1; + } + pointerEvent.pointerPress = gameObject2; + pointerEvent.rawPointerPress = gameObject; + pointerEvent.clickTime = (float)unscaledTime; + pointerEvent.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(gameObject); + if (pointerEvent.pointerDrag != null) + { + ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); + } + } + if (released) + { + ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerUpHandler); + GameObject eventHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject); + if (pointerEvent.pointerPress == eventHandler && pointerEvent.eligibleForClick) + { + ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); + } + else if (pointerEvent.pointerDrag != null && pointerEvent.dragging) + { + ExecuteEvents.ExecuteHierarchy(gameObject, pointerEvent, ExecuteEvents.dropHandler); + } + pointerEvent.eligibleForClick = false; + pointerEvent.pointerPress = null; + pointerEvent.rawPointerPress = null; + if (pointerEvent.pointerDrag != null && pointerEvent.dragging) + { + ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); + } + pointerEvent.dragging = false; + pointerEvent.pointerDrag = null; + if (pointerEvent.pointerDrag != null) + { + ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.endDragHandler); + } + pointerEvent.pointerDrag = null; + ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler); + pointerEvent.pointerEnter = null; + } + } + + private bool SendSubmitEventToSelectedObject() + { + if (base.eventSystem.currentSelectedGameObject == null) + { + return false; + } + if (recompiling) + { + return false; + } + BaseEventData baseEventData = GetBaseEventData(); + for (int i = 0; i < playerIds.Length; i++) + { + Player player = ReInput.players.GetPlayer(playerIds[i]); + if (player != null && (!usePlayingPlayersOnly || player.isPlaying)) + { + if (GetButtonDown(player, submitActionId)) + { + ExecuteEvents.Execute(base.eventSystem.currentSelectedGameObject, baseEventData, ExecuteEvents.submitHandler); + break; + } + if (GetButtonDown(player, cancelActionId)) + { + ExecuteEvents.Execute(base.eventSystem.currentSelectedGameObject, baseEventData, ExecuteEvents.cancelHandler); + break; + } + } + } + return baseEventData.used; + } + + private Vector2 GetRawMoveVector() + { + if (recompiling) + { + return Vector2.zero; + } + Vector2 zero = Vector2.zero; + for (int i = 0; i < playerIds.Length; i++) + { + Player player = ReInput.players.GetPlayer(playerIds[i]); + if (player == null || (usePlayingPlayersOnly && !player.isPlaying)) + { + continue; + } + float num = GetAxis(player, horizontalActionId); + float num2 = GetAxis(player, verticalActionId); + if (Mathf.Approximately(num, 0f)) + { + num = 0f; + } + if (Mathf.Approximately(num2, 0f)) + { + num2 = 0f; + } + if (moveOneElementPerAxisPress) + { + if (GetButtonDown(player, horizontalActionId) && num > 0f) + { + zero.x += 1f; + } + if (GetNegativeButtonDown(player, horizontalActionId) && num < 0f) + { + zero.x -= 1f; + } + if (GetButtonDown(player, verticalActionId) && num2 > 0f) + { + zero.y += 1f; + } + if (GetNegativeButtonDown(player, verticalActionId) && num2 < 0f) + { + zero.y -= 1f; + } + } + else + { + if (GetButton(player, horizontalActionId) && num > 0f) + { + zero.x += 1f; + } + if (GetNegativeButton(player, horizontalActionId) && num < 0f) + { + zero.x -= 1f; + } + if (GetButton(player, verticalActionId) && num2 > 0f) + { + zero.y += 1f; + } + if (GetNegativeButton(player, verticalActionId) && num2 < 0f) + { + zero.y -= 1f; + } + } + } + return zero; + } + + private bool SendMoveEventToSelectedObject() + { + if (recompiling) + { + return false; + } + double unscaledTime = ReInput.time.unscaledTime; + Vector2 rawMoveVector = GetRawMoveVector(); + if (Mathf.Approximately(rawMoveVector.x, 0f) && Mathf.Approximately(rawMoveVector.y, 0f)) + { + m_ConsecutiveMoveCount = 0; + return false; + } + bool flag = Vector2.Dot(rawMoveVector, m_LastMoveVector) > 0f; + CheckButtonOrKeyMovement(out var downHorizontal, out var downVertical); + AxisEventData axisEventData = null; + bool flag2 = downHorizontal || downVertical; + if (flag2) + { + axisEventData = GetAxisEventData(rawMoveVector.x, rawMoveVector.y, 0f); + MoveDirection moveDir = axisEventData.moveDir; + flag2 = ((moveDir == MoveDirection.Up || moveDir == MoveDirection.Down) && downVertical) || ((moveDir == MoveDirection.Left || moveDir == MoveDirection.Right) && downHorizontal); + } + if (!flag2) + { + flag2 = ((!(m_RepeatDelay > 0f)) ? (unscaledTime > m_PrevActionTime + (double)(1f / m_InputActionsPerSecond)) : ((!flag || m_ConsecutiveMoveCount != 1) ? (unscaledTime > m_PrevActionTime + (double)(1f / m_InputActionsPerSecond)) : (unscaledTime > m_PrevActionTime + (double)m_RepeatDelay))); + } + if (!flag2) + { + return false; + } + if (axisEventData == null) + { + axisEventData = GetAxisEventData(rawMoveVector.x, rawMoveVector.y, 0f); + } + if (axisEventData.moveDir != MoveDirection.None) + { + ExecuteEvents.Execute(base.eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler); + if (!flag) + { + m_ConsecutiveMoveCount = 0; + } + if (m_ConsecutiveMoveCount == 0 || !(downHorizontal || downVertical)) + { + m_ConsecutiveMoveCount++; + } + m_PrevActionTime = unscaledTime; + m_LastMoveVector = rawMoveVector; + } + else + { + m_ConsecutiveMoveCount = 0; + } + return axisEventData.used; + } + + private void CheckButtonOrKeyMovement(out bool downHorizontal, out bool downVertical) + { + downHorizontal = false; + downVertical = false; + for (int i = 0; i < playerIds.Length; i++) + { + Player player = ReInput.players.GetPlayer(playerIds[i]); + if (player != null && (!usePlayingPlayersOnly || player.isPlaying)) + { + downHorizontal |= GetButtonDown(player, horizontalActionId) || GetNegativeButtonDown(player, horizontalActionId); + downVertical |= GetButtonDown(player, verticalActionId) || GetNegativeButtonDown(player, verticalActionId); + } + } + } + + private void ProcessMouseEvents() + { + for (int i = 0; i < playerIds.Length; i++) + { + Player player = ReInput.players.GetPlayer(playerIds[i]); + if (player != null && (!usePlayingPlayersOnly || player.isPlaying)) + { + int mouseInputSourceCount = GetMouseInputSourceCount(playerIds[i]); + for (int j = 0; j < mouseInputSourceCount; j++) + { + ProcessMouseEvent(playerIds[i], j); + } + } + } + } + + private void ProcessMouseEvent(int playerId, int pointerIndex) + { + MouseState mousePointerEventData = GetMousePointerEventData(playerId, pointerIndex); + if (mousePointerEventData == null) + { + return; + } + MouseButtonEventData eventData = mousePointerEventData.GetButtonState(0).eventData; + ProcessMousePress(eventData); + ProcessMove(eventData.buttonData); + ProcessDrag(eventData.buttonData); + ProcessMousePress(mousePointerEventData.GetButtonState(1).eventData); + ProcessDrag(mousePointerEventData.GetButtonState(1).eventData.buttonData); + ProcessMousePress(mousePointerEventData.GetButtonState(2).eventData); + ProcessDrag(mousePointerEventData.GetButtonState(2).eventData.buttonData); + IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, pointerIndex); + if (mouseInputSource != null) + { + for (int i = 3; i < mouseInputSource.buttonCount; i++) + { + ProcessMousePress(mousePointerEventData.GetButtonState(i).eventData); + ProcessDrag(mousePointerEventData.GetButtonState(i).eventData.buttonData); + } + if (!Mathf.Approximately(eventData.buttonData.scrollDelta.sqrMagnitude, 0f)) + { + ExecuteEvents.ExecuteHierarchy(ExecuteEvents.GetEventHandler<IScrollHandler>(eventData.buttonData.pointerCurrentRaycast.gameObject), eventData.buttonData, ExecuteEvents.scrollHandler); + } + } + } + + private bool SendUpdateEventToSelectedObject() + { + if (base.eventSystem.currentSelectedGameObject == null) + { + return false; + } + BaseEventData baseEventData = GetBaseEventData(); + ExecuteEvents.Execute(base.eventSystem.currentSelectedGameObject, baseEventData, ExecuteEvents.updateSelectedHandler); + return baseEventData.used; + } + + private void ProcessMousePress(MouseButtonEventData data) + { + PlayerPointerEventData buttonData = data.buttonData; + if (GetMouseInputSource(buttonData.playerId, buttonData.inputSourceIndex) == null) + { + return; + } + GameObject gameObject = buttonData.pointerCurrentRaycast.gameObject; + if (data.PressedThisFrame()) + { + buttonData.eligibleForClick = true; + buttonData.delta = Vector2.zero; + buttonData.dragging = false; + buttonData.useDragThreshold = true; + buttonData.pressPosition = buttonData.position; + buttonData.pointerPressRaycast = buttonData.pointerCurrentRaycast; + HandleMouseTouchDeselectionOnSelectionChanged(gameObject, buttonData); + GameObject gameObject2 = ExecuteEvents.ExecuteHierarchy(gameObject, buttonData, ExecuteEvents.pointerDownHandler); + if (gameObject2 == null) + { + gameObject2 = ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject); + } + double unscaledTime = ReInput.time.unscaledTime; + if (gameObject2 == buttonData.lastPress) + { + if (unscaledTime - (double)buttonData.clickTime < 0.30000001192092896) + { + int clickCount = buttonData.clickCount + 1; + buttonData.clickCount = clickCount; + } + else + { + buttonData.clickCount = 1; + } + buttonData.clickTime = (float)unscaledTime; + } + else + { + buttonData.clickCount = 1; + } + buttonData.pointerPress = gameObject2; + buttonData.rawPointerPress = gameObject; + buttonData.clickTime = (float)unscaledTime; + buttonData.pointerDrag = ExecuteEvents.GetEventHandler<IDragHandler>(gameObject); + if (buttonData.pointerDrag != null) + { + ExecuteEvents.Execute(buttonData.pointerDrag, buttonData, ExecuteEvents.initializePotentialDrag); + } + } + if (data.ReleasedThisFrame()) + { + ExecuteEvents.Execute(buttonData.pointerPress, buttonData, ExecuteEvents.pointerUpHandler); + GameObject eventHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(gameObject); + if (buttonData.pointerPress == eventHandler && buttonData.eligibleForClick) + { + ExecuteEvents.Execute(buttonData.pointerPress, buttonData, ExecuteEvents.pointerClickHandler); + } + else if (buttonData.pointerDrag != null && buttonData.dragging) + { + ExecuteEvents.ExecuteHierarchy(gameObject, buttonData, ExecuteEvents.dropHandler); + } + buttonData.eligibleForClick = false; + buttonData.pointerPress = null; + buttonData.rawPointerPress = null; + if (buttonData.pointerDrag != null && buttonData.dragging) + { + ExecuteEvents.Execute(buttonData.pointerDrag, buttonData, ExecuteEvents.endDragHandler); + } + buttonData.dragging = false; + buttonData.pointerDrag = null; + if (gameObject != buttonData.pointerEnter) + { + HandlePointerExitAndEnter(buttonData, null); + HandlePointerExitAndEnter(buttonData, gameObject); + } + } + } + + private void HandleMouseTouchDeselectionOnSelectionChanged(GameObject currentOverGo, BaseEventData pointerEvent) + { + if (m_deselectIfBackgroundClicked && m_deselectBeforeSelecting) + { + DeselectIfSelectionChanged(currentOverGo, pointerEvent); + return; + } + GameObject eventHandler = ExecuteEvents.GetEventHandler<ISelectHandler>(currentOverGo); + if (m_deselectIfBackgroundClicked) + { + if (eventHandler != base.eventSystem.currentSelectedGameObject && eventHandler != null) + { + base.eventSystem.SetSelectedGameObject(null, pointerEvent); + } + } + else if (m_deselectBeforeSelecting && eventHandler != null && eventHandler != base.eventSystem.currentSelectedGameObject) + { + base.eventSystem.SetSelectedGameObject(null, pointerEvent); + } + } + + private void OnApplicationFocus(bool hasFocus) + { + m_HasFocus = hasFocus; + } + + private bool ShouldIgnoreEventsOnNoFocus() + { + if (!ReInput.isReady) + { + return true; + } + return ReInput.configuration.ignoreInputWhenAppNotInFocus; + } + + protected override void OnDestroy() + { + base.OnDestroy(); + ReInput.InitializedEvent -= OnRewiredInitialized; + ReInput.ShutDownEvent -= OnRewiredShutDown; + ReInput.EditorRecompileEvent -= OnEditorRecompile; + } + + protected override bool IsDefaultPlayer(int playerId) + { + if (playerIds == null) + { + return false; + } + if (!ReInput.isReady) + { + return false; + } + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < playerIds.Length; j++) + { + Player player = ReInput.players.GetPlayer(playerIds[j]); + if (player != null && (i >= 1 || !usePlayingPlayersOnly || player.isPlaying) && (i >= 2 || player.controllers.hasMouse)) + { + return playerIds[j] == playerId; + } + } + } + return false; + } + + private void InitializeRewired() + { + if (!ReInput.isReady) + { + Debug.LogError("Rewired is not initialized! Are you missing a Rewired Input Manager in your scene?"); + return; + } + ReInput.ShutDownEvent -= OnRewiredShutDown; + ReInput.ShutDownEvent += OnRewiredShutDown; + ReInput.EditorRecompileEvent -= OnEditorRecompile; + ReInput.EditorRecompileEvent += OnEditorRecompile; + SetupRewiredVars(); + } + + private void SetupRewiredVars() + { + if (!ReInput.isReady) + { + return; + } + SetUpRewiredActions(); + if (useAllRewiredGamePlayers) + { + IList<Player> list = (useRewiredSystemPlayer ? ReInput.players.AllPlayers : ReInput.players.Players); + playerIds = new int[list.Count]; + for (int i = 0; i < list.Count; i++) + { + playerIds[i] = list[i].id; + } + } + else + { + bool flag = false; + List<int> list2 = new List<int>(rewiredPlayerIds.Length + 1); + for (int j = 0; j < rewiredPlayerIds.Length; j++) + { + Player player = ReInput.players.GetPlayer(rewiredPlayerIds[j]); + if (player != null && !list2.Contains(player.id)) + { + list2.Add(player.id); + if (player.id == 9999999) + { + flag = true; + } + } + } + if (useRewiredSystemPlayer && !flag) + { + list2.Insert(0, ReInput.players.GetSystemPlayer().id); + } + playerIds = list2.ToArray(); + } + SetUpRewiredPlayerMice(); + } + + private void SetUpRewiredPlayerMice() + { + if (!ReInput.isReady) + { + return; + } + ClearMouseInputSources(); + for (int i = 0; i < playerMice.Count; i++) + { + Rewired.Components.PlayerMouse playerMouse = playerMice[i]; + if (!UnityTools.IsNullOrDestroyed(playerMouse)) + { + AddMouseInputSource(playerMouse); + } + } + } + + private void SetUpRewiredActions() + { + if (!ReInput.isReady) + { + return; + } + if (!setActionsById) + { + horizontalActionId = ReInput.mapping.GetActionId(m_HorizontalAxis); + verticalActionId = ReInput.mapping.GetActionId(m_VerticalAxis); + submitActionId = ReInput.mapping.GetActionId(m_SubmitButton); + cancelActionId = ReInput.mapping.GetActionId(m_CancelButton); + return; + } + InputAction action = ReInput.mapping.GetAction(horizontalActionId); + m_HorizontalAxis = ((action != null) ? action.name : string.Empty); + if (action == null) + { + horizontalActionId = -1; + } + action = ReInput.mapping.GetAction(verticalActionId); + m_VerticalAxis = ((action != null) ? action.name : string.Empty); + if (action == null) + { + verticalActionId = -1; + } + action = ReInput.mapping.GetAction(submitActionId); + m_SubmitButton = ((action != null) ? action.name : string.Empty); + if (action == null) + { + submitActionId = -1; + } + action = ReInput.mapping.GetAction(cancelActionId); + m_CancelButton = ((action != null) ? action.name : string.Empty); + if (action == null) + { + cancelActionId = -1; + } + } + + private bool GetButton(Player player, int actionId) + { + if (actionId < 0) + { + return false; + } + return player.GetButton(actionId); + } + + private bool GetButtonDown(Player player, int actionId) + { + if (actionId < 0) + { + return false; + } + return player.GetButtonDown(actionId); + } + + private bool GetNegativeButton(Player player, int actionId) + { + if (actionId < 0) + { + return false; + } + return player.GetNegativeButton(actionId); + } + + private bool GetNegativeButtonDown(Player player, int actionId) + { + if (actionId < 0) + { + return false; + } + return player.GetNegativeButtonDown(actionId); + } + + private float GetAxis(Player player, int actionId) + { + if (actionId < 0) + { + return 0f; + } + return player.GetAxis(actionId); + } + + private void CheckEditorRecompile() + { + if (recompiling && ReInput.isReady) + { + recompiling = false; + InitializeRewired(); + } + } + + private void OnEditorRecompile() + { + recompiling = true; + ClearRewiredVars(); + } + + private void ClearRewiredVars() + { + Array.Clear(playerIds, 0, playerIds.Length); + ClearMouseInputSources(); + } + + private bool DidAnyMouseMove() + { + for (int i = 0; i < playerIds.Length; i++) + { + int playerId = playerIds[i]; + Player player = ReInput.players.GetPlayer(playerId); + if (player == null || (usePlayingPlayersOnly && !player.isPlaying)) + { + continue; + } + int mouseInputSourceCount = GetMouseInputSourceCount(playerId); + for (int j = 0; j < mouseInputSourceCount; j++) + { + IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, j); + if (mouseInputSource != null && mouseInputSource.screenPositionDelta.sqrMagnitude > 0f) + { + return true; + } + } + } + return false; + } + + private bool GetMouseButtonDownOnAnyMouse(int buttonIndex) + { + for (int i = 0; i < playerIds.Length; i++) + { + int playerId = playerIds[i]; + Player player = ReInput.players.GetPlayer(playerId); + if (player == null || (usePlayingPlayersOnly && !player.isPlaying)) + { + continue; + } + int mouseInputSourceCount = GetMouseInputSourceCount(playerId); + for (int j = 0; j < mouseInputSourceCount; j++) + { + IMouseInputSource mouseInputSource = GetMouseInputSource(playerId, j); + if (mouseInputSource != null && mouseInputSource.GetButtonDown(buttonIndex)) + { + return true; + } + } + } + return false; + } + + private void OnRewiredInitialized() + { + InitializeRewired(); + } + + private void OnRewiredShutDown() + { + ClearRewiredVars(); + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Internal/ControllerTemplateFactory.cs b/Thronefall_v1.0/Rewired/Rewired.Internal/ControllerTemplateFactory.cs new file mode 100644 index 0000000..d1ac2b5 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Internal/ControllerTemplateFactory.cs @@ -0,0 +1,59 @@ +using System; + +namespace Rewired.Internal; + +public static class ControllerTemplateFactory +{ + private static readonly Type[] _defaultTemplateTypes = new Type[6] + { + typeof(GamepadTemplate), + typeof(RacingWheelTemplate), + typeof(HOTASTemplate), + typeof(FlightYokeTemplate), + typeof(FlightPedalsTemplate), + typeof(SixDofControllerTemplate) + }; + + private static readonly Type[] _defaultTemplateInterfaceTypes = new Type[6] + { + typeof(IGamepadTemplate), + typeof(IRacingWheelTemplate), + typeof(IHOTASTemplate), + typeof(IFlightYokeTemplate), + typeof(IFlightPedalsTemplate), + typeof(ISixDofControllerTemplate) + }; + + public static Type[] templateTypes => _defaultTemplateTypes; + + public static Type[] templateInterfaceTypes => _defaultTemplateInterfaceTypes; + + public static IControllerTemplate Create(Guid typeGuid, object payload) + { + if (typeGuid == GamepadTemplate.typeGuid) + { + return new GamepadTemplate(payload); + } + if (typeGuid == RacingWheelTemplate.typeGuid) + { + return new RacingWheelTemplate(payload); + } + if (typeGuid == HOTASTemplate.typeGuid) + { + return new HOTASTemplate(payload); + } + if (typeGuid == FlightYokeTemplate.typeGuid) + { + return new FlightYokeTemplate(payload); + } + if (typeGuid == FlightPedalsTemplate.typeGuid) + { + return new FlightPedalsTemplate(payload); + } + if (typeGuid == SixDofControllerTemplate.typeGuid) + { + return new SixDofControllerTemplate(payload); + } + return null; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired.Utils/ExternalTools.cs b/Thronefall_v1.0/Rewired/Rewired.Utils/ExternalTools.cs new file mode 100644 index 0000000..d22fdd5 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired.Utils/ExternalTools.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Rewired.Internal; +using Rewired.Utils.Interfaces; +using Rewired.Utils.Platforms.Windows; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Windows; + +namespace Rewired.Utils; + +[EditorBrowsable(EditorBrowsableState.Never)] +public class ExternalTools : IExternalTools +{ + private static Func<object> _getPlatformInitializerDelegate; + + private bool _isEditorPaused; + + private Action<bool> _EditorPausedStateChangedEvent; + + public static Func<object> getPlatformInitializerDelegate + { + get + { + return _getPlatformInitializerDelegate; + } + set + { + _getPlatformInitializerDelegate = value; + } + } + + public bool isEditorPaused => _isEditorPaused; + + public bool UnityInput_IsTouchPressureSupported => UnityEngine.Input.touchPressureSupported; + + public event Action<bool> EditorPausedStateChangedEvent + { + add + { + _EditorPausedStateChangedEvent = (Action<bool>)Delegate.Combine(_EditorPausedStateChangedEvent, value); + } + remove + { + _EditorPausedStateChangedEvent = (Action<bool>)Delegate.Remove(_EditorPausedStateChangedEvent, value); + } + } + + public event Action<uint, bool> XboxOneInput_OnGamepadStateChange; + + public void Destroy() + { + } + + public object GetPlatformInitializer() + { + return Main.GetPlatformInitializer(); + } + + public string GetFocusedEditorWindowTitle() + { + return string.Empty; + } + + public bool IsEditorSceneViewFocused() + { + return false; + } + + public bool LinuxInput_IsJoystickPreconfigured(string name) + { + return false; + } + + public int XboxOneInput_GetUserIdForGamepad(uint id) + { + return 0; + } + + public ulong XboxOneInput_GetControllerId(uint unityJoystickId) + { + return 0uL; + } + + public bool XboxOneInput_IsGamepadActive(uint unityJoystickId) + { + return false; + } + + public string XboxOneInput_GetControllerType(ulong xboxControllerId) + { + return string.Empty; + } + + public uint XboxOneInput_GetJoystickId(ulong xboxControllerId) + { + return 0u; + } + + public void XboxOne_Gamepad_UpdatePlugin() + { + } + + public bool XboxOne_Gamepad_SetGamepadVibration(ulong xboxOneJoystickId, float leftMotor, float rightMotor, float leftTriggerLevel, float rightTriggerLevel) + { + return false; + } + + public void XboxOne_Gamepad_PulseVibrateMotor(ulong xboxOneJoystickId, int motorInt, float startLevel, float endLevel, ulong durationMS) + { + } + + public void GetDeviceVIDPIDs(out List<int> vids, out List<int> pids) + { + vids = new List<int>(); + pids = new List<int>(); + } + + public int GetAndroidAPILevel() + { + return -1; + } + + public void WindowsStandalone_ForwardRawInput(IntPtr rawInputHeaderIndices, IntPtr rawInputDataIndices, uint indicesCount, IntPtr rawInputData, uint rawInputDataSize) + { + UnityEngine.Windows.Input.ForwardRawInput(rawInputHeaderIndices, rawInputDataIndices, indicesCount, rawInputData, rawInputDataSize); + } + + public bool UnityUI_Graphic_GetRaycastTarget(object graphic) + { + if (graphic as Graphic == null) + { + return false; + } + return (graphic as Graphic).raycastTarget; + } + + public void UnityUI_Graphic_SetRaycastTarget(object graphic, bool value) + { + if (!(graphic as Graphic == null)) + { + (graphic as Graphic).raycastTarget = value; + } + } + + public float UnityInput_GetTouchPressure(ref Touch touch) + { + return touch.pressure; + } + + public float UnityInput_GetTouchMaximumPossiblePressure(ref Touch touch) + { + return touch.maximumPossiblePressure; + } + + public IControllerTemplate CreateControllerTemplate(Guid typeGuid, object payload) + { + return ControllerTemplateFactory.Create(typeGuid, payload); + } + + public Type[] GetControllerTemplateTypes() + { + return ControllerTemplateFactory.templateTypes; + } + + public Type[] GetControllerTemplateInterfaceTypes() + { + return ControllerTemplateFactory.templateInterfaceTypes; + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/FlightPedalsTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/FlightPedalsTemplate.cs new file mode 100644 index 0000000..29a18b5 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/FlightPedalsTemplate.cs @@ -0,0 +1,25 @@ +using System; + +namespace Rewired; + +public sealed class FlightPedalsTemplate : ControllerTemplate, IFlightPedalsTemplate, IControllerTemplate +{ + public static readonly Guid typeGuid = new Guid("f6fe76f8-be2a-4db2-b853-9e3652075913"); + + public const int elementId_leftPedal = 0; + + public const int elementId_rightPedal = 1; + + public const int elementId_slide = 2; + + IControllerTemplateAxis IFlightPedalsTemplate.leftPedal => GetElement<IControllerTemplateAxis>(0); + + IControllerTemplateAxis IFlightPedalsTemplate.rightPedal => GetElement<IControllerTemplateAxis>(1); + + IControllerTemplateAxis IFlightPedalsTemplate.slide => GetElement<IControllerTemplateAxis>(2); + + public FlightPedalsTemplate(object payload) + : base(payload) + { + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/FlightYokeTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/FlightYokeTemplate.cs new file mode 100644 index 0000000..818f761 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/FlightYokeTemplate.cs @@ -0,0 +1,265 @@ +using System; + +namespace Rewired; + +public sealed class FlightYokeTemplate : ControllerTemplate, IFlightYokeTemplate, IControllerTemplate +{ + public static readonly Guid typeGuid = new Guid("f311fa16-0ccc-41c0-ac4b-50f7100bb8ff"); + + public const int elementId_rotateYoke = 0; + + public const int elementId_yokeZ = 1; + + public const int elementId_leftPaddle = 59; + + public const int elementId_rightPaddle = 60; + + public const int elementId_lever1Axis = 2; + + public const int elementId_lever1MinDetent = 64; + + public const int elementId_lever2Axis = 3; + + public const int elementId_lever2MinDetent = 65; + + public const int elementId_lever3Axis = 4; + + public const int elementId_lever3MinDetent = 66; + + public const int elementId_lever4Axis = 5; + + public const int elementId_lever4MinDetent = 67; + + public const int elementId_lever5Axis = 6; + + public const int elementId_lever5MinDetent = 68; + + public const int elementId_leftGripButton1 = 7; + + public const int elementId_leftGripButton2 = 8; + + public const int elementId_leftGripButton3 = 9; + + public const int elementId_leftGripButton4 = 10; + + public const int elementId_leftGripButton5 = 11; + + public const int elementId_leftGripButton6 = 12; + + public const int elementId_rightGripButton1 = 13; + + public const int elementId_rightGripButton2 = 14; + + public const int elementId_rightGripButton3 = 15; + + public const int elementId_rightGripButton4 = 16; + + public const int elementId_rightGripButton5 = 17; + + public const int elementId_rightGripButton6 = 18; + + public const int elementId_centerButton1 = 19; + + public const int elementId_centerButton2 = 20; + + public const int elementId_centerButton3 = 21; + + public const int elementId_centerButton4 = 22; + + public const int elementId_centerButton5 = 23; + + public const int elementId_centerButton6 = 24; + + public const int elementId_centerButton7 = 25; + + public const int elementId_centerButton8 = 26; + + public const int elementId_wheel1Up = 53; + + public const int elementId_wheel1Down = 54; + + public const int elementId_wheel1Press = 55; + + public const int elementId_wheel2Up = 56; + + public const int elementId_wheel2Down = 57; + + public const int elementId_wheel2Press = 58; + + public const int elementId_leftGripHatUp = 27; + + public const int elementId_leftGripHatUpRight = 28; + + public const int elementId_leftGripHatRight = 29; + + public const int elementId_leftGripHatDownRight = 30; + + public const int elementId_leftGripHatDown = 31; + + public const int elementId_leftGripHatDownLeft = 32; + + public const int elementId_leftGripHatLeft = 33; + + public const int elementId_leftGripHatUpLeft = 34; + + public const int elementId_rightGripHatUp = 35; + + public const int elementId_rightGripHatUpRight = 36; + + public const int elementId_rightGripHatRight = 37; + + public const int elementId_rightGripHatDownRight = 38; + + public const int elementId_rightGripHatDown = 39; + + public const int elementId_rightGripHatDownLeft = 40; + + public const int elementId_rightGripHatLeft = 41; + + public const int elementId_rightGripHatUpLeft = 42; + + public const int elementId_consoleButton1 = 43; + + public const int elementId_consoleButton2 = 44; + + public const int elementId_consoleButton3 = 45; + + public const int elementId_consoleButton4 = 46; + + public const int elementId_consoleButton5 = 47; + + public const int elementId_consoleButton6 = 48; + + public const int elementId_consoleButton7 = 49; + + public const int elementId_consoleButton8 = 50; + + public const int elementId_consoleButton9 = 51; + + public const int elementId_consoleButton10 = 52; + + public const int elementId_mode1 = 61; + + public const int elementId_mode2 = 62; + + public const int elementId_mode3 = 63; + + public const int elementId_yoke = 69; + + public const int elementId_lever1 = 70; + + public const int elementId_lever2 = 71; + + public const int elementId_lever3 = 72; + + public const int elementId_lever4 = 73; + + public const int elementId_lever5 = 74; + + public const int elementId_leftGripHat = 75; + + public const int elementId_rightGripHat = 76; + + IControllerTemplateButton IFlightYokeTemplate.leftPaddle => GetElement<IControllerTemplateButton>(59); + + IControllerTemplateButton IFlightYokeTemplate.rightPaddle => GetElement<IControllerTemplateButton>(60); + + IControllerTemplateButton IFlightYokeTemplate.leftGripButton1 => GetElement<IControllerTemplateButton>(7); + + IControllerTemplateButton IFlightYokeTemplate.leftGripButton2 => GetElement<IControllerTemplateButton>(8); + + IControllerTemplateButton IFlightYokeTemplate.leftGripButton3 => GetElement<IControllerTemplateButton>(9); + + IControllerTemplateButton IFlightYokeTemplate.leftGripButton4 => GetElement<IControllerTemplateButton>(10); + + IControllerTemplateButton IFlightYokeTemplate.leftGripButton5 => GetElement<IControllerTemplateButton>(11); + + IControllerTemplateButton IFlightYokeTemplate.leftGripButton6 => GetElement<IControllerTemplateButton>(12); + + IControllerTemplateButton IFlightYokeTemplate.rightGripButton1 => GetElement<IControllerTemplateButton>(13); + + IControllerTemplateButton IFlightYokeTemplate.rightGripButton2 => GetElement<IControllerTemplateButton>(14); + + IControllerTemplateButton IFlightYokeTemplate.rightGripButton3 => GetElement<IControllerTemplateButton>(15); + + IControllerTemplateButton IFlightYokeTemplate.rightGripButton4 => GetElement<IControllerTemplateButton>(16); + + IControllerTemplateButton IFlightYokeTemplate.rightGripButton5 => GetElement<IControllerTemplateButton>(17); + + IControllerTemplateButton IFlightYokeTemplate.rightGripButton6 => GetElement<IControllerTemplateButton>(18); + + IControllerTemplateButton IFlightYokeTemplate.centerButton1 => GetElement<IControllerTemplateButton>(19); + + IControllerTemplateButton IFlightYokeTemplate.centerButton2 => GetElement<IControllerTemplateButton>(20); + + IControllerTemplateButton IFlightYokeTemplate.centerButton3 => GetElement<IControllerTemplateButton>(21); + + IControllerTemplateButton IFlightYokeTemplate.centerButton4 => GetElement<IControllerTemplateButton>(22); + + IControllerTemplateButton IFlightYokeTemplate.centerButton5 => GetElement<IControllerTemplateButton>(23); + + IControllerTemplateButton IFlightYokeTemplate.centerButton6 => GetElement<IControllerTemplateButton>(24); + + IControllerTemplateButton IFlightYokeTemplate.centerButton7 => GetElement<IControllerTemplateButton>(25); + + IControllerTemplateButton IFlightYokeTemplate.centerButton8 => GetElement<IControllerTemplateButton>(26); + + IControllerTemplateButton IFlightYokeTemplate.wheel1Up => GetElement<IControllerTemplateButton>(53); + + IControllerTemplateButton IFlightYokeTemplate.wheel1Down => GetElement<IControllerTemplateButton>(54); + + IControllerTemplateButton IFlightYokeTemplate.wheel1Press => GetElement<IControllerTemplateButton>(55); + + IControllerTemplateButton IFlightYokeTemplate.wheel2Up => GetElement<IControllerTemplateButton>(56); + + IControllerTemplateButton IFlightYokeTemplate.wheel2Down => GetElement<IControllerTemplateButton>(57); + + IControllerTemplateButton IFlightYokeTemplate.wheel2Press => GetElement<IControllerTemplateButton>(58); + + IControllerTemplateButton IFlightYokeTemplate.consoleButton1 => GetElement<IControllerTemplateButton>(43); + + IControllerTemplateButton IFlightYokeTemplate.consoleButton2 => GetElement<IControllerTemplateButton>(44); + + IControllerTemplateButton IFlightYokeTemplate.consoleButton3 => GetElement<IControllerTemplateButton>(45); + + IControllerTemplateButton IFlightYokeTemplate.consoleButton4 => GetElement<IControllerTemplateButton>(46); + + IControllerTemplateButton IFlightYokeTemplate.consoleButton5 => GetElement<IControllerTemplateButton>(47); + + IControllerTemplateButton IFlightYokeTemplate.consoleButton6 => GetElement<IControllerTemplateButton>(48); + + IControllerTemplateButton IFlightYokeTemplate.consoleButton7 => GetElement<IControllerTemplateButton>(49); + + IControllerTemplateButton IFlightYokeTemplate.consoleButton8 => GetElement<IControllerTemplateButton>(50); + + IControllerTemplateButton IFlightYokeTemplate.consoleButton9 => GetElement<IControllerTemplateButton>(51); + + IControllerTemplateButton IFlightYokeTemplate.consoleButton10 => GetElement<IControllerTemplateButton>(52); + + IControllerTemplateButton IFlightYokeTemplate.mode1 => GetElement<IControllerTemplateButton>(61); + + IControllerTemplateButton IFlightYokeTemplate.mode2 => GetElement<IControllerTemplateButton>(62); + + IControllerTemplateButton IFlightYokeTemplate.mode3 => GetElement<IControllerTemplateButton>(63); + + IControllerTemplateYoke IFlightYokeTemplate.yoke => GetElement<IControllerTemplateYoke>(69); + + IControllerTemplateThrottle IFlightYokeTemplate.lever1 => GetElement<IControllerTemplateThrottle>(70); + + IControllerTemplateThrottle IFlightYokeTemplate.lever2 => GetElement<IControllerTemplateThrottle>(71); + + IControllerTemplateThrottle IFlightYokeTemplate.lever3 => GetElement<IControllerTemplateThrottle>(72); + + IControllerTemplateThrottle IFlightYokeTemplate.lever4 => GetElement<IControllerTemplateThrottle>(73); + + IControllerTemplateThrottle IFlightYokeTemplate.lever5 => GetElement<IControllerTemplateThrottle>(74); + + IControllerTemplateHat IFlightYokeTemplate.leftGripHat => GetElement<IControllerTemplateHat>(75); + + IControllerTemplateHat IFlightYokeTemplate.rightGripHat => GetElement<IControllerTemplateHat>(76); + + public FlightYokeTemplate(object payload) + : base(payload) + { + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/GamepadTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/GamepadTemplate.cs new file mode 100644 index 0000000..2db2fba --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/GamepadTemplate.cs @@ -0,0 +1,149 @@ +using System; + +namespace Rewired; + +public sealed class GamepadTemplate : ControllerTemplate, IGamepadTemplate, IControllerTemplate +{ + public static readonly Guid typeGuid = new Guid("83b427e4-086f-47f3-bb06-be266abd1ca5"); + + public const int elementId_leftStickX = 0; + + public const int elementId_leftStickY = 1; + + public const int elementId_rightStickX = 2; + + public const int elementId_rightStickY = 3; + + public const int elementId_actionBottomRow1 = 4; + + public const int elementId_a = 4; + + public const int elementId_actionBottomRow2 = 5; + + public const int elementId_b = 5; + + public const int elementId_actionBottomRow3 = 6; + + public const int elementId_c = 6; + + public const int elementId_actionTopRow1 = 7; + + public const int elementId_x = 7; + + public const int elementId_actionTopRow2 = 8; + + public const int elementId_y = 8; + + public const int elementId_actionTopRow3 = 9; + + public const int elementId_z = 9; + + public const int elementId_leftShoulder1 = 10; + + public const int elementId_leftBumper = 10; + + public const int elementId_leftShoulder2 = 11; + + public const int elementId_leftTrigger = 11; + + public const int elementId_rightShoulder1 = 12; + + public const int elementId_rightBumper = 12; + + public const int elementId_rightShoulder2 = 13; + + public const int elementId_rightTrigger = 13; + + public const int elementId_center1 = 14; + + public const int elementId_back = 14; + + public const int elementId_center2 = 15; + + public const int elementId_start = 15; + + public const int elementId_center3 = 16; + + public const int elementId_guide = 16; + + public const int elementId_leftStickButton = 17; + + public const int elementId_rightStickButton = 18; + + public const int elementId_dPadUp = 19; + + public const int elementId_dPadRight = 20; + + public const int elementId_dPadDown = 21; + + public const int elementId_dPadLeft = 22; + + public const int elementId_leftStick = 23; + + public const int elementId_rightStick = 24; + + public const int elementId_dPad = 25; + + IControllerTemplateButton IGamepadTemplate.actionBottomRow1 => GetElement<IControllerTemplateButton>(4); + + IControllerTemplateButton IGamepadTemplate.a => GetElement<IControllerTemplateButton>(4); + + IControllerTemplateButton IGamepadTemplate.actionBottomRow2 => GetElement<IControllerTemplateButton>(5); + + IControllerTemplateButton IGamepadTemplate.b => GetElement<IControllerTemplateButton>(5); + + IControllerTemplateButton IGamepadTemplate.actionBottomRow3 => GetElement<IControllerTemplateButton>(6); + + IControllerTemplateButton IGamepadTemplate.c => GetElement<IControllerTemplateButton>(6); + + IControllerTemplateButton IGamepadTemplate.actionTopRow1 => GetElement<IControllerTemplateButton>(7); + + IControllerTemplateButton IGamepadTemplate.x => GetElement<IControllerTemplateButton>(7); + + IControllerTemplateButton IGamepadTemplate.actionTopRow2 => GetElement<IControllerTemplateButton>(8); + + IControllerTemplateButton IGamepadTemplate.y => GetElement<IControllerTemplateButton>(8); + + IControllerTemplateButton IGamepadTemplate.actionTopRow3 => GetElement<IControllerTemplateButton>(9); + + IControllerTemplateButton IGamepadTemplate.z => GetElement<IControllerTemplateButton>(9); + + IControllerTemplateButton IGamepadTemplate.leftShoulder1 => GetElement<IControllerTemplateButton>(10); + + IControllerTemplateButton IGamepadTemplate.leftBumper => GetElement<IControllerTemplateButton>(10); + + IControllerTemplateAxis IGamepadTemplate.leftShoulder2 => GetElement<IControllerTemplateAxis>(11); + + IControllerTemplateAxis IGamepadTemplate.leftTrigger => GetElement<IControllerTemplateAxis>(11); + + IControllerTemplateButton IGamepadTemplate.rightShoulder1 => GetElement<IControllerTemplateButton>(12); + + IControllerTemplateButton IGamepadTemplate.rightBumper => GetElement<IControllerTemplateButton>(12); + + IControllerTemplateAxis IGamepadTemplate.rightShoulder2 => GetElement<IControllerTemplateAxis>(13); + + IControllerTemplateAxis IGamepadTemplate.rightTrigger => GetElement<IControllerTemplateAxis>(13); + + IControllerTemplateButton IGamepadTemplate.center1 => GetElement<IControllerTemplateButton>(14); + + IControllerTemplateButton IGamepadTemplate.back => GetElement<IControllerTemplateButton>(14); + + IControllerTemplateButton IGamepadTemplate.center2 => GetElement<IControllerTemplateButton>(15); + + IControllerTemplateButton IGamepadTemplate.start => GetElement<IControllerTemplateButton>(15); + + IControllerTemplateButton IGamepadTemplate.center3 => GetElement<IControllerTemplateButton>(16); + + IControllerTemplateButton IGamepadTemplate.guide => GetElement<IControllerTemplateButton>(16); + + IControllerTemplateThumbStick IGamepadTemplate.leftStick => GetElement<IControllerTemplateThumbStick>(23); + + IControllerTemplateThumbStick IGamepadTemplate.rightStick => GetElement<IControllerTemplateThumbStick>(24); + + IControllerTemplateDPad IGamepadTemplate.dPad => GetElement<IControllerTemplateDPad>(25); + + public GamepadTemplate(object payload) + : base(payload) + { + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/HOTASTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/HOTASTemplate.cs new file mode 100644 index 0000000..9324f5c --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/HOTASTemplate.cs @@ -0,0 +1,525 @@ +using System; + +namespace Rewired; + +public sealed class HOTASTemplate : ControllerTemplate, IHOTASTemplate, IControllerTemplate +{ + public static readonly Guid typeGuid = new Guid("061a00cf-d8c2-4f8d-8cb5-a15a010bc53e"); + + public const int elementId_stickX = 0; + + public const int elementId_stickY = 1; + + public const int elementId_stickRotate = 2; + + public const int elementId_stickMiniStick1X = 78; + + public const int elementId_stickMiniStick1Y = 79; + + public const int elementId_stickMiniStick1Press = 80; + + public const int elementId_stickMiniStick2X = 81; + + public const int elementId_stickMiniStick2Y = 82; + + public const int elementId_stickMiniStick2Press = 83; + + public const int elementId_stickTrigger = 3; + + public const int elementId_stickTriggerStage2 = 4; + + public const int elementId_stickPinkyButton = 5; + + public const int elementId_stickPinkyTrigger = 154; + + public const int elementId_stickButton1 = 6; + + public const int elementId_stickButton2 = 7; + + public const int elementId_stickButton3 = 8; + + public const int elementId_stickButton4 = 9; + + public const int elementId_stickButton5 = 10; + + public const int elementId_stickButton6 = 11; + + public const int elementId_stickButton7 = 12; + + public const int elementId_stickButton8 = 13; + + public const int elementId_stickButton9 = 14; + + public const int elementId_stickButton10 = 15; + + public const int elementId_stickBaseButton1 = 18; + + public const int elementId_stickBaseButton2 = 19; + + public const int elementId_stickBaseButton3 = 20; + + public const int elementId_stickBaseButton4 = 21; + + public const int elementId_stickBaseButton5 = 22; + + public const int elementId_stickBaseButton6 = 23; + + public const int elementId_stickBaseButton7 = 24; + + public const int elementId_stickBaseButton8 = 25; + + public const int elementId_stickBaseButton9 = 26; + + public const int elementId_stickBaseButton10 = 27; + + public const int elementId_stickBaseButton11 = 161; + + public const int elementId_stickBaseButton12 = 162; + + public const int elementId_stickHat1Up = 28; + + public const int elementId_stickHat1UpRight = 29; + + public const int elementId_stickHat1Right = 30; + + public const int elementId_stickHat1DownRight = 31; + + public const int elementId_stickHat1Down = 32; + + public const int elementId_stickHat1DownLeft = 33; + + public const int elementId_stickHat1Left = 34; + + public const int elementId_stickHat1Up_Left = 35; + + public const int elementId_stickHat2Up = 36; + + public const int elementId_stickHat2Up_right = 37; + + public const int elementId_stickHat2Right = 38; + + public const int elementId_stickHat2Down_Right = 39; + + public const int elementId_stickHat2Down = 40; + + public const int elementId_stickHat2Down_Left = 41; + + public const int elementId_stickHat2Left = 42; + + public const int elementId_stickHat2Up_Left = 43; + + public const int elementId_stickHat3Up = 84; + + public const int elementId_stickHat3Up_Right = 85; + + public const int elementId_stickHat3Right = 86; + + public const int elementId_stickHat3Down_Right = 87; + + public const int elementId_stickHat3Down = 88; + + public const int elementId_stickHat3Down_Left = 89; + + public const int elementId_stickHat3Left = 90; + + public const int elementId_stickHat3Up_Left = 91; + + public const int elementId_stickHat4Up = 92; + + public const int elementId_stickHat4Up_Right = 93; + + public const int elementId_stickHat4Right = 94; + + public const int elementId_stickHat4Down_Right = 95; + + public const int elementId_stickHat4Down = 96; + + public const int elementId_stickHat4Down_Left = 97; + + public const int elementId_stickHat4Left = 98; + + public const int elementId_stickHat4Up_Left = 99; + + public const int elementId_mode1 = 44; + + public const int elementId_mode2 = 45; + + public const int elementId_mode3 = 46; + + public const int elementId_throttle1Axis = 49; + + public const int elementId_throttle2Axis = 155; + + public const int elementId_throttle1MinDetent = 166; + + public const int elementId_throttle2MinDetent = 167; + + public const int elementId_throttleButton1 = 50; + + public const int elementId_throttleButton2 = 51; + + public const int elementId_throttleButton3 = 52; + + public const int elementId_throttleButton4 = 53; + + public const int elementId_throttleButton5 = 54; + + public const int elementId_throttleButton6 = 55; + + public const int elementId_throttleButton7 = 56; + + public const int elementId_throttleButton8 = 57; + + public const int elementId_throttleButton9 = 58; + + public const int elementId_throttleButton10 = 59; + + public const int elementId_throttleBaseButton1 = 60; + + public const int elementId_throttleBaseButton2 = 61; + + public const int elementId_throttleBaseButton3 = 62; + + public const int elementId_throttleBaseButton4 = 63; + + public const int elementId_throttleBaseButton5 = 64; + + public const int elementId_throttleBaseButton6 = 65; + + public const int elementId_throttleBaseButton7 = 66; + + public const int elementId_throttleBaseButton8 = 67; + + public const int elementId_throttleBaseButton9 = 68; + + public const int elementId_throttleBaseButton10 = 69; + + public const int elementId_throttleBaseButton11 = 132; + + public const int elementId_throttleBaseButton12 = 133; + + public const int elementId_throttleBaseButton13 = 134; + + public const int elementId_throttleBaseButton14 = 135; + + public const int elementId_throttleBaseButton15 = 136; + + public const int elementId_throttleSlider1 = 70; + + public const int elementId_throttleSlider2 = 71; + + public const int elementId_throttleSlider3 = 72; + + public const int elementId_throttleSlider4 = 73; + + public const int elementId_throttleDial1 = 74; + + public const int elementId_throttleDial2 = 142; + + public const int elementId_throttleDial3 = 143; + + public const int elementId_throttleDial4 = 144; + + public const int elementId_throttleMiniStickX = 75; + + public const int elementId_throttleMiniStickY = 76; + + public const int elementId_throttleMiniStickPress = 77; + + public const int elementId_throttleWheel1Forward = 145; + + public const int elementId_throttleWheel1Back = 146; + + public const int elementId_throttleWheel1Press = 147; + + public const int elementId_throttleWheel2Forward = 148; + + public const int elementId_throttleWheel2Back = 149; + + public const int elementId_throttleWheel2Press = 150; + + public const int elementId_throttleWheel3Forward = 151; + + public const int elementId_throttleWheel3Back = 152; + + public const int elementId_throttleWheel3Press = 153; + + public const int elementId_throttleHat1Up = 100; + + public const int elementId_throttleHat1Up_Right = 101; + + public const int elementId_throttleHat1Right = 102; + + public const int elementId_throttleHat1Down_Right = 103; + + public const int elementId_throttleHat1Down = 104; + + public const int elementId_throttleHat1Down_Left = 105; + + public const int elementId_throttleHat1Left = 106; + + public const int elementId_throttleHat1Up_Left = 107; + + public const int elementId_throttleHat2Up = 108; + + public const int elementId_throttleHat2Up_Right = 109; + + public const int elementId_throttleHat2Right = 110; + + public const int elementId_throttleHat2Down_Right = 111; + + public const int elementId_throttleHat2Down = 112; + + public const int elementId_throttleHat2Down_Left = 113; + + public const int elementId_throttleHat2Left = 114; + + public const int elementId_throttleHat2Up_Left = 115; + + public const int elementId_throttleHat3Up = 116; + + public const int elementId_throttleHat3Up_Right = 117; + + public const int elementId_throttleHat3Right = 118; + + public const int elementId_throttleHat3Down_Right = 119; + + public const int elementId_throttleHat3Down = 120; + + public const int elementId_throttleHat3Down_Left = 121; + + public const int elementId_throttleHat3Left = 122; + + public const int elementId_throttleHat3Up_Left = 123; + + public const int elementId_throttleHat4Up = 124; + + public const int elementId_throttleHat4Up_Right = 125; + + public const int elementId_throttleHat4Right = 126; + + public const int elementId_throttleHat4Down_Right = 127; + + public const int elementId_throttleHat4Down = 128; + + public const int elementId_throttleHat4Down_Left = 129; + + public const int elementId_throttleHat4Left = 130; + + public const int elementId_throttleHat4Up_Left = 131; + + public const int elementId_leftPedal = 168; + + public const int elementId_rightPedal = 169; + + public const int elementId_slidePedals = 170; + + public const int elementId_stick = 171; + + public const int elementId_stickMiniStick1 = 172; + + public const int elementId_stickMiniStick2 = 173; + + public const int elementId_stickHat1 = 174; + + public const int elementId_stickHat2 = 175; + + public const int elementId_stickHat3 = 176; + + public const int elementId_stickHat4 = 177; + + public const int elementId_throttle1 = 178; + + public const int elementId_throttle2 = 179; + + public const int elementId_throttleMiniStick = 180; + + public const int elementId_throttleHat1 = 181; + + public const int elementId_throttleHat2 = 182; + + public const int elementId_throttleHat3 = 183; + + public const int elementId_throttleHat4 = 184; + + IControllerTemplateButton IHOTASTemplate.stickTrigger => GetElement<IControllerTemplateButton>(3); + + IControllerTemplateButton IHOTASTemplate.stickTriggerStage2 => GetElement<IControllerTemplateButton>(4); + + IControllerTemplateButton IHOTASTemplate.stickPinkyButton => GetElement<IControllerTemplateButton>(5); + + IControllerTemplateButton IHOTASTemplate.stickPinkyTrigger => GetElement<IControllerTemplateButton>(154); + + IControllerTemplateButton IHOTASTemplate.stickButton1 => GetElement<IControllerTemplateButton>(6); + + IControllerTemplateButton IHOTASTemplate.stickButton2 => GetElement<IControllerTemplateButton>(7); + + IControllerTemplateButton IHOTASTemplate.stickButton3 => GetElement<IControllerTemplateButton>(8); + + IControllerTemplateButton IHOTASTemplate.stickButton4 => GetElement<IControllerTemplateButton>(9); + + IControllerTemplateButton IHOTASTemplate.stickButton5 => GetElement<IControllerTemplateButton>(10); + + IControllerTemplateButton IHOTASTemplate.stickButton6 => GetElement<IControllerTemplateButton>(11); + + IControllerTemplateButton IHOTASTemplate.stickButton7 => GetElement<IControllerTemplateButton>(12); + + IControllerTemplateButton IHOTASTemplate.stickButton8 => GetElement<IControllerTemplateButton>(13); + + IControllerTemplateButton IHOTASTemplate.stickButton9 => GetElement<IControllerTemplateButton>(14); + + IControllerTemplateButton IHOTASTemplate.stickButton10 => GetElement<IControllerTemplateButton>(15); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton1 => GetElement<IControllerTemplateButton>(18); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton2 => GetElement<IControllerTemplateButton>(19); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton3 => GetElement<IControllerTemplateButton>(20); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton4 => GetElement<IControllerTemplateButton>(21); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton5 => GetElement<IControllerTemplateButton>(22); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton6 => GetElement<IControllerTemplateButton>(23); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton7 => GetElement<IControllerTemplateButton>(24); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton8 => GetElement<IControllerTemplateButton>(25); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton9 => GetElement<IControllerTemplateButton>(26); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton10 => GetElement<IControllerTemplateButton>(27); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton11 => GetElement<IControllerTemplateButton>(161); + + IControllerTemplateButton IHOTASTemplate.stickBaseButton12 => GetElement<IControllerTemplateButton>(162); + + IControllerTemplateButton IHOTASTemplate.mode1 => GetElement<IControllerTemplateButton>(44); + + IControllerTemplateButton IHOTASTemplate.mode2 => GetElement<IControllerTemplateButton>(45); + + IControllerTemplateButton IHOTASTemplate.mode3 => GetElement<IControllerTemplateButton>(46); + + IControllerTemplateButton IHOTASTemplate.throttleButton1 => GetElement<IControllerTemplateButton>(50); + + IControllerTemplateButton IHOTASTemplate.throttleButton2 => GetElement<IControllerTemplateButton>(51); + + IControllerTemplateButton IHOTASTemplate.throttleButton3 => GetElement<IControllerTemplateButton>(52); + + IControllerTemplateButton IHOTASTemplate.throttleButton4 => GetElement<IControllerTemplateButton>(53); + + IControllerTemplateButton IHOTASTemplate.throttleButton5 => GetElement<IControllerTemplateButton>(54); + + IControllerTemplateButton IHOTASTemplate.throttleButton6 => GetElement<IControllerTemplateButton>(55); + + IControllerTemplateButton IHOTASTemplate.throttleButton7 => GetElement<IControllerTemplateButton>(56); + + IControllerTemplateButton IHOTASTemplate.throttleButton8 => GetElement<IControllerTemplateButton>(57); + + IControllerTemplateButton IHOTASTemplate.throttleButton9 => GetElement<IControllerTemplateButton>(58); + + IControllerTemplateButton IHOTASTemplate.throttleButton10 => GetElement<IControllerTemplateButton>(59); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton1 => GetElement<IControllerTemplateButton>(60); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton2 => GetElement<IControllerTemplateButton>(61); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton3 => GetElement<IControllerTemplateButton>(62); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton4 => GetElement<IControllerTemplateButton>(63); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton5 => GetElement<IControllerTemplateButton>(64); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton6 => GetElement<IControllerTemplateButton>(65); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton7 => GetElement<IControllerTemplateButton>(66); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton8 => GetElement<IControllerTemplateButton>(67); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton9 => GetElement<IControllerTemplateButton>(68); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton10 => GetElement<IControllerTemplateButton>(69); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton11 => GetElement<IControllerTemplateButton>(132); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton12 => GetElement<IControllerTemplateButton>(133); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton13 => GetElement<IControllerTemplateButton>(134); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton14 => GetElement<IControllerTemplateButton>(135); + + IControllerTemplateButton IHOTASTemplate.throttleBaseButton15 => GetElement<IControllerTemplateButton>(136); + + IControllerTemplateAxis IHOTASTemplate.throttleSlider1 => GetElement<IControllerTemplateAxis>(70); + + IControllerTemplateAxis IHOTASTemplate.throttleSlider2 => GetElement<IControllerTemplateAxis>(71); + + IControllerTemplateAxis IHOTASTemplate.throttleSlider3 => GetElement<IControllerTemplateAxis>(72); + + IControllerTemplateAxis IHOTASTemplate.throttleSlider4 => GetElement<IControllerTemplateAxis>(73); + + IControllerTemplateAxis IHOTASTemplate.throttleDial1 => GetElement<IControllerTemplateAxis>(74); + + IControllerTemplateAxis IHOTASTemplate.throttleDial2 => GetElement<IControllerTemplateAxis>(142); + + IControllerTemplateAxis IHOTASTemplate.throttleDial3 => GetElement<IControllerTemplateAxis>(143); + + IControllerTemplateAxis IHOTASTemplate.throttleDial4 => GetElement<IControllerTemplateAxis>(144); + + IControllerTemplateButton IHOTASTemplate.throttleWheel1Forward => GetElement<IControllerTemplateButton>(145); + + IControllerTemplateButton IHOTASTemplate.throttleWheel1Back => GetElement<IControllerTemplateButton>(146); + + IControllerTemplateButton IHOTASTemplate.throttleWheel1Press => GetElement<IControllerTemplateButton>(147); + + IControllerTemplateButton IHOTASTemplate.throttleWheel2Forward => GetElement<IControllerTemplateButton>(148); + + IControllerTemplateButton IHOTASTemplate.throttleWheel2Back => GetElement<IControllerTemplateButton>(149); + + IControllerTemplateButton IHOTASTemplate.throttleWheel2Press => GetElement<IControllerTemplateButton>(150); + + IControllerTemplateButton IHOTASTemplate.throttleWheel3Forward => GetElement<IControllerTemplateButton>(151); + + IControllerTemplateButton IHOTASTemplate.throttleWheel3Back => GetElement<IControllerTemplateButton>(152); + + IControllerTemplateButton IHOTASTemplate.throttleWheel3Press => GetElement<IControllerTemplateButton>(153); + + IControllerTemplateAxis IHOTASTemplate.leftPedal => GetElement<IControllerTemplateAxis>(168); + + IControllerTemplateAxis IHOTASTemplate.rightPedal => GetElement<IControllerTemplateAxis>(169); + + IControllerTemplateAxis IHOTASTemplate.slidePedals => GetElement<IControllerTemplateAxis>(170); + + IControllerTemplateStick IHOTASTemplate.stick => GetElement<IControllerTemplateStick>(171); + + IControllerTemplateThumbStick IHOTASTemplate.stickMiniStick1 => GetElement<IControllerTemplateThumbStick>(172); + + IControllerTemplateThumbStick IHOTASTemplate.stickMiniStick2 => GetElement<IControllerTemplateThumbStick>(173); + + IControllerTemplateHat IHOTASTemplate.stickHat1 => GetElement<IControllerTemplateHat>(174); + + IControllerTemplateHat IHOTASTemplate.stickHat2 => GetElement<IControllerTemplateHat>(175); + + IControllerTemplateHat IHOTASTemplate.stickHat3 => GetElement<IControllerTemplateHat>(176); + + IControllerTemplateHat IHOTASTemplate.stickHat4 => GetElement<IControllerTemplateHat>(177); + + IControllerTemplateThrottle IHOTASTemplate.throttle1 => GetElement<IControllerTemplateThrottle>(178); + + IControllerTemplateThrottle IHOTASTemplate.throttle2 => GetElement<IControllerTemplateThrottle>(179); + + IControllerTemplateThumbStick IHOTASTemplate.throttleMiniStick => GetElement<IControllerTemplateThumbStick>(180); + + IControllerTemplateHat IHOTASTemplate.throttleHat1 => GetElement<IControllerTemplateHat>(181); + + IControllerTemplateHat IHOTASTemplate.throttleHat2 => GetElement<IControllerTemplateHat>(182); + + IControllerTemplateHat IHOTASTemplate.throttleHat3 => GetElement<IControllerTemplateHat>(183); + + IControllerTemplateHat IHOTASTemplate.throttleHat4 => GetElement<IControllerTemplateHat>(184); + + public HOTASTemplate(object payload) + : base(payload) + { + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/IFlightPedalsTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/IFlightPedalsTemplate.cs new file mode 100644 index 0000000..61f91de --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/IFlightPedalsTemplate.cs @@ -0,0 +1,10 @@ +namespace Rewired; + +public interface IFlightPedalsTemplate : IControllerTemplate +{ + IControllerTemplateAxis leftPedal { get; } + + IControllerTemplateAxis rightPedal { get; } + + IControllerTemplateAxis slide { get; } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/IFlightYokeTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/IFlightYokeTemplate.cs new file mode 100644 index 0000000..9fc5660 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/IFlightYokeTemplate.cs @@ -0,0 +1,102 @@ +namespace Rewired; + +public interface IFlightYokeTemplate : IControllerTemplate +{ + IControllerTemplateButton leftPaddle { get; } + + IControllerTemplateButton rightPaddle { get; } + + IControllerTemplateButton leftGripButton1 { get; } + + IControllerTemplateButton leftGripButton2 { get; } + + IControllerTemplateButton leftGripButton3 { get; } + + IControllerTemplateButton leftGripButton4 { get; } + + IControllerTemplateButton leftGripButton5 { get; } + + IControllerTemplateButton leftGripButton6 { get; } + + IControllerTemplateButton rightGripButton1 { get; } + + IControllerTemplateButton rightGripButton2 { get; } + + IControllerTemplateButton rightGripButton3 { get; } + + IControllerTemplateButton rightGripButton4 { get; } + + IControllerTemplateButton rightGripButton5 { get; } + + IControllerTemplateButton rightGripButton6 { get; } + + IControllerTemplateButton centerButton1 { get; } + + IControllerTemplateButton centerButton2 { get; } + + IControllerTemplateButton centerButton3 { get; } + + IControllerTemplateButton centerButton4 { get; } + + IControllerTemplateButton centerButton5 { get; } + + IControllerTemplateButton centerButton6 { get; } + + IControllerTemplateButton centerButton7 { get; } + + IControllerTemplateButton centerButton8 { get; } + + IControllerTemplateButton wheel1Up { get; } + + IControllerTemplateButton wheel1Down { get; } + + IControllerTemplateButton wheel1Press { get; } + + IControllerTemplateButton wheel2Up { get; } + + IControllerTemplateButton wheel2Down { get; } + + IControllerTemplateButton wheel2Press { get; } + + IControllerTemplateButton consoleButton1 { get; } + + IControllerTemplateButton consoleButton2 { get; } + + IControllerTemplateButton consoleButton3 { get; } + + IControllerTemplateButton consoleButton4 { get; } + + IControllerTemplateButton consoleButton5 { get; } + + IControllerTemplateButton consoleButton6 { get; } + + IControllerTemplateButton consoleButton7 { get; } + + IControllerTemplateButton consoleButton8 { get; } + + IControllerTemplateButton consoleButton9 { get; } + + IControllerTemplateButton consoleButton10 { get; } + + IControllerTemplateButton mode1 { get; } + + IControllerTemplateButton mode2 { get; } + + IControllerTemplateButton mode3 { get; } + + IControllerTemplateYoke yoke { get; } + + IControllerTemplateThrottle lever1 { get; } + + IControllerTemplateThrottle lever2 { get; } + + IControllerTemplateThrottle lever3 { get; } + + IControllerTemplateThrottle lever4 { get; } + + IControllerTemplateThrottle lever5 { get; } + + IControllerTemplateHat leftGripHat { get; } + + IControllerTemplateHat rightGripHat { get; } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/IGamepadTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/IGamepadTemplate.cs new file mode 100644 index 0000000..76b14b8 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/IGamepadTemplate.cs @@ -0,0 +1,62 @@ +namespace Rewired; + +public interface IGamepadTemplate : IControllerTemplate +{ + IControllerTemplateButton actionBottomRow1 { get; } + + IControllerTemplateButton a { get; } + + IControllerTemplateButton actionBottomRow2 { get; } + + IControllerTemplateButton b { get; } + + IControllerTemplateButton actionBottomRow3 { get; } + + IControllerTemplateButton c { get; } + + IControllerTemplateButton actionTopRow1 { get; } + + IControllerTemplateButton x { get; } + + IControllerTemplateButton actionTopRow2 { get; } + + IControllerTemplateButton y { get; } + + IControllerTemplateButton actionTopRow3 { get; } + + IControllerTemplateButton z { get; } + + IControllerTemplateButton leftShoulder1 { get; } + + IControllerTemplateButton leftBumper { get; } + + IControllerTemplateAxis leftShoulder2 { get; } + + IControllerTemplateAxis leftTrigger { get; } + + IControllerTemplateButton rightShoulder1 { get; } + + IControllerTemplateButton rightBumper { get; } + + IControllerTemplateAxis rightShoulder2 { get; } + + IControllerTemplateAxis rightTrigger { get; } + + IControllerTemplateButton center1 { get; } + + IControllerTemplateButton back { get; } + + IControllerTemplateButton center2 { get; } + + IControllerTemplateButton start { get; } + + IControllerTemplateButton center3 { get; } + + IControllerTemplateButton guide { get; } + + IControllerTemplateThumbStick leftStick { get; } + + IControllerTemplateThumbStick rightStick { get; } + + IControllerTemplateDPad dPad { get; } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/IHOTASTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/IHOTASTemplate.cs new file mode 100644 index 0000000..8a801b5 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/IHOTASTemplate.cs @@ -0,0 +1,180 @@ +namespace Rewired; + +public interface IHOTASTemplate : IControllerTemplate +{ + IControllerTemplateButton stickTrigger { get; } + + IControllerTemplateButton stickTriggerStage2 { get; } + + IControllerTemplateButton stickPinkyButton { get; } + + IControllerTemplateButton stickPinkyTrigger { get; } + + IControllerTemplateButton stickButton1 { get; } + + IControllerTemplateButton stickButton2 { get; } + + IControllerTemplateButton stickButton3 { get; } + + IControllerTemplateButton stickButton4 { get; } + + IControllerTemplateButton stickButton5 { get; } + + IControllerTemplateButton stickButton6 { get; } + + IControllerTemplateButton stickButton7 { get; } + + IControllerTemplateButton stickButton8 { get; } + + IControllerTemplateButton stickButton9 { get; } + + IControllerTemplateButton stickButton10 { get; } + + IControllerTemplateButton stickBaseButton1 { get; } + + IControllerTemplateButton stickBaseButton2 { get; } + + IControllerTemplateButton stickBaseButton3 { get; } + + IControllerTemplateButton stickBaseButton4 { get; } + + IControllerTemplateButton stickBaseButton5 { get; } + + IControllerTemplateButton stickBaseButton6 { get; } + + IControllerTemplateButton stickBaseButton7 { get; } + + IControllerTemplateButton stickBaseButton8 { get; } + + IControllerTemplateButton stickBaseButton9 { get; } + + IControllerTemplateButton stickBaseButton10 { get; } + + IControllerTemplateButton stickBaseButton11 { get; } + + IControllerTemplateButton stickBaseButton12 { get; } + + IControllerTemplateButton mode1 { get; } + + IControllerTemplateButton mode2 { get; } + + IControllerTemplateButton mode3 { get; } + + IControllerTemplateButton throttleButton1 { get; } + + IControllerTemplateButton throttleButton2 { get; } + + IControllerTemplateButton throttleButton3 { get; } + + IControllerTemplateButton throttleButton4 { get; } + + IControllerTemplateButton throttleButton5 { get; } + + IControllerTemplateButton throttleButton6 { get; } + + IControllerTemplateButton throttleButton7 { get; } + + IControllerTemplateButton throttleButton8 { get; } + + IControllerTemplateButton throttleButton9 { get; } + + IControllerTemplateButton throttleButton10 { get; } + + IControllerTemplateButton throttleBaseButton1 { get; } + + IControllerTemplateButton throttleBaseButton2 { get; } + + IControllerTemplateButton throttleBaseButton3 { get; } + + IControllerTemplateButton throttleBaseButton4 { get; } + + IControllerTemplateButton throttleBaseButton5 { get; } + + IControllerTemplateButton throttleBaseButton6 { get; } + + IControllerTemplateButton throttleBaseButton7 { get; } + + IControllerTemplateButton throttleBaseButton8 { get; } + + IControllerTemplateButton throttleBaseButton9 { get; } + + IControllerTemplateButton throttleBaseButton10 { get; } + + IControllerTemplateButton throttleBaseButton11 { get; } + + IControllerTemplateButton throttleBaseButton12 { get; } + + IControllerTemplateButton throttleBaseButton13 { get; } + + IControllerTemplateButton throttleBaseButton14 { get; } + + IControllerTemplateButton throttleBaseButton15 { get; } + + IControllerTemplateAxis throttleSlider1 { get; } + + IControllerTemplateAxis throttleSlider2 { get; } + + IControllerTemplateAxis throttleSlider3 { get; } + + IControllerTemplateAxis throttleSlider4 { get; } + + IControllerTemplateAxis throttleDial1 { get; } + + IControllerTemplateAxis throttleDial2 { get; } + + IControllerTemplateAxis throttleDial3 { get; } + + IControllerTemplateAxis throttleDial4 { get; } + + IControllerTemplateButton throttleWheel1Forward { get; } + + IControllerTemplateButton throttleWheel1Back { get; } + + IControllerTemplateButton throttleWheel1Press { get; } + + IControllerTemplateButton throttleWheel2Forward { get; } + + IControllerTemplateButton throttleWheel2Back { get; } + + IControllerTemplateButton throttleWheel2Press { get; } + + IControllerTemplateButton throttleWheel3Forward { get; } + + IControllerTemplateButton throttleWheel3Back { get; } + + IControllerTemplateButton throttleWheel3Press { get; } + + IControllerTemplateAxis leftPedal { get; } + + IControllerTemplateAxis rightPedal { get; } + + IControllerTemplateAxis slidePedals { get; } + + IControllerTemplateStick stick { get; } + + IControllerTemplateThumbStick stickMiniStick1 { get; } + + IControllerTemplateThumbStick stickMiniStick2 { get; } + + IControllerTemplateHat stickHat1 { get; } + + IControllerTemplateHat stickHat2 { get; } + + IControllerTemplateHat stickHat3 { get; } + + IControllerTemplateHat stickHat4 { get; } + + IControllerTemplateThrottle throttle1 { get; } + + IControllerTemplateThrottle throttle2 { get; } + + IControllerTemplateThumbStick throttleMiniStick { get; } + + IControllerTemplateHat throttleHat1 { get; } + + IControllerTemplateHat throttleHat2 { get; } + + IControllerTemplateHat throttleHat3 { get; } + + IControllerTemplateHat throttleHat4 { get; } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/IRacingWheelTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/IRacingWheelTemplate.cs new file mode 100644 index 0000000..fe9a246 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/IRacingWheelTemplate.cs @@ -0,0 +1,88 @@ +namespace Rewired; + +public interface IRacingWheelTemplate : IControllerTemplate +{ + IControllerTemplateAxis wheel { get; } + + IControllerTemplateAxis accelerator { get; } + + IControllerTemplateAxis brake { get; } + + IControllerTemplateAxis clutch { get; } + + IControllerTemplateButton shiftDown { get; } + + IControllerTemplateButton shiftUp { get; } + + IControllerTemplateButton wheelButton1 { get; } + + IControllerTemplateButton wheelButton2 { get; } + + IControllerTemplateButton wheelButton3 { get; } + + IControllerTemplateButton wheelButton4 { get; } + + IControllerTemplateButton wheelButton5 { get; } + + IControllerTemplateButton wheelButton6 { get; } + + IControllerTemplateButton wheelButton7 { get; } + + IControllerTemplateButton wheelButton8 { get; } + + IControllerTemplateButton wheelButton9 { get; } + + IControllerTemplateButton wheelButton10 { get; } + + IControllerTemplateButton consoleButton1 { get; } + + IControllerTemplateButton consoleButton2 { get; } + + IControllerTemplateButton consoleButton3 { get; } + + IControllerTemplateButton consoleButton4 { get; } + + IControllerTemplateButton consoleButton5 { get; } + + IControllerTemplateButton consoleButton6 { get; } + + IControllerTemplateButton consoleButton7 { get; } + + IControllerTemplateButton consoleButton8 { get; } + + IControllerTemplateButton consoleButton9 { get; } + + IControllerTemplateButton consoleButton10 { get; } + + IControllerTemplateButton shifter1 { get; } + + IControllerTemplateButton shifter2 { get; } + + IControllerTemplateButton shifter3 { get; } + + IControllerTemplateButton shifter4 { get; } + + IControllerTemplateButton shifter5 { get; } + + IControllerTemplateButton shifter6 { get; } + + IControllerTemplateButton shifter7 { get; } + + IControllerTemplateButton shifter8 { get; } + + IControllerTemplateButton shifter9 { get; } + + IControllerTemplateButton shifter10 { get; } + + IControllerTemplateButton reverseGear { get; } + + IControllerTemplateButton select { get; } + + IControllerTemplateButton start { get; } + + IControllerTemplateButton systemButton { get; } + + IControllerTemplateButton horn { get; } + + IControllerTemplateDPad dPad { get; } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/ISixDofControllerTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/ISixDofControllerTemplate.cs new file mode 100644 index 0000000..326e0c5 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/ISixDofControllerTemplate.cs @@ -0,0 +1,86 @@ +namespace Rewired; + +public interface ISixDofControllerTemplate : IControllerTemplate +{ + IControllerTemplateAxis extraAxis1 { get; } + + IControllerTemplateAxis extraAxis2 { get; } + + IControllerTemplateAxis extraAxis3 { get; } + + IControllerTemplateAxis extraAxis4 { get; } + + IControllerTemplateButton button1 { get; } + + IControllerTemplateButton button2 { get; } + + IControllerTemplateButton button3 { get; } + + IControllerTemplateButton button4 { get; } + + IControllerTemplateButton button5 { get; } + + IControllerTemplateButton button6 { get; } + + IControllerTemplateButton button7 { get; } + + IControllerTemplateButton button8 { get; } + + IControllerTemplateButton button9 { get; } + + IControllerTemplateButton button10 { get; } + + IControllerTemplateButton button11 { get; } + + IControllerTemplateButton button12 { get; } + + IControllerTemplateButton button13 { get; } + + IControllerTemplateButton button14 { get; } + + IControllerTemplateButton button15 { get; } + + IControllerTemplateButton button16 { get; } + + IControllerTemplateButton button17 { get; } + + IControllerTemplateButton button18 { get; } + + IControllerTemplateButton button19 { get; } + + IControllerTemplateButton button20 { get; } + + IControllerTemplateButton button21 { get; } + + IControllerTemplateButton button22 { get; } + + IControllerTemplateButton button23 { get; } + + IControllerTemplateButton button24 { get; } + + IControllerTemplateButton button25 { get; } + + IControllerTemplateButton button26 { get; } + + IControllerTemplateButton button27 { get; } + + IControllerTemplateButton button28 { get; } + + IControllerTemplateButton button29 { get; } + + IControllerTemplateButton button30 { get; } + + IControllerTemplateButton button31 { get; } + + IControllerTemplateButton button32 { get; } + + IControllerTemplateHat hat1 { get; } + + IControllerTemplateHat hat2 { get; } + + IControllerTemplateThrottle throttle1 { get; } + + IControllerTemplateThrottle throttle2 { get; } + + IControllerTemplateStick6D stick { get; } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/InputManager.cs b/Thronefall_v1.0/Rewired/Rewired/InputManager.cs new file mode 100644 index 0000000..1bae3e4 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/InputManager.cs @@ -0,0 +1,81 @@ +using System.ComponentModel; +using System.Text.RegularExpressions; +using Rewired.Platforms; +using Rewired.Utils; +using Rewired.Utils.Interfaces; +using UnityEngine; +using UnityEngine.SceneManagement; + +namespace Rewired; + +[AddComponentMenu("Rewired/Input Manager")] +[EditorBrowsable(EditorBrowsableState.Never)] +public sealed class InputManager : InputManager_Base +{ + private bool ignoreRecompile; + + protected override void OnInitialized() + { + SubscribeEvents(); + } + + protected override void OnDeinitialized() + { + UnsubscribeEvents(); + } + + protected override void DetectPlatform() + { + scriptingBackend = ScriptingBackend.Mono; + scriptingAPILevel = ScriptingAPILevel.Net20; + editorPlatform = EditorPlatform.None; + platform = Platform.Unknown; + webplayerPlatform = WebplayerPlatform.None; + isEditor = false; + if (SystemInfo.deviceName == null) + { + _ = string.Empty; + } + if (SystemInfo.deviceModel == null) + { + _ = string.Empty; + } + platform = Platform.Windows; + scriptingBackend = ScriptingBackend.Mono; + scriptingAPILevel = ScriptingAPILevel.NetStandard20; + } + + protected override void CheckRecompile() + { + } + + protected override IExternalTools GetExternalTools() + { + return new ExternalTools(); + } + + private bool CheckDeviceName(string searchPattern, string deviceName, string deviceModel) + { + if (!Regex.IsMatch(deviceName, searchPattern, RegexOptions.IgnoreCase)) + { + return Regex.IsMatch(deviceModel, searchPattern, RegexOptions.IgnoreCase); + } + return true; + } + + private void SubscribeEvents() + { + UnsubscribeEvents(); + SceneManager.sceneLoaded += OnSceneLoaded; + } + + private void UnsubscribeEvents() + { + SceneManager.sceneLoaded -= OnSceneLoaded; + } + + private void OnSceneLoaded(Scene scene, LoadSceneMode mode) + { + OnSceneLoaded(); + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/RacingWheelTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/RacingWheelTemplate.cs new file mode 100644 index 0000000..85fb3c3 --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/RacingWheelTemplate.cs @@ -0,0 +1,189 @@ +using System; + +namespace Rewired; + +public sealed class RacingWheelTemplate : ControllerTemplate, IRacingWheelTemplate, IControllerTemplate +{ + public static readonly Guid typeGuid = new Guid("104e31d8-9115-4dd5-a398-2e54d35e6c83"); + + public const int elementId_wheel = 0; + + public const int elementId_accelerator = 1; + + public const int elementId_brake = 2; + + public const int elementId_clutch = 3; + + public const int elementId_shiftDown = 4; + + public const int elementId_shiftUp = 5; + + public const int elementId_wheelButton1 = 6; + + public const int elementId_wheelButton2 = 7; + + public const int elementId_wheelButton3 = 8; + + public const int elementId_wheelButton4 = 9; + + public const int elementId_wheelButton5 = 10; + + public const int elementId_wheelButton6 = 11; + + public const int elementId_wheelButton7 = 12; + + public const int elementId_wheelButton8 = 13; + + public const int elementId_wheelButton9 = 14; + + public const int elementId_wheelButton10 = 15; + + public const int elementId_consoleButton1 = 16; + + public const int elementId_consoleButton2 = 17; + + public const int elementId_consoleButton3 = 18; + + public const int elementId_consoleButton4 = 19; + + public const int elementId_consoleButton5 = 20; + + public const int elementId_consoleButton6 = 21; + + public const int elementId_consoleButton7 = 22; + + public const int elementId_consoleButton8 = 23; + + public const int elementId_consoleButton9 = 24; + + public const int elementId_consoleButton10 = 25; + + public const int elementId_shifter1 = 26; + + public const int elementId_shifter2 = 27; + + public const int elementId_shifter3 = 28; + + public const int elementId_shifter4 = 29; + + public const int elementId_shifter5 = 30; + + public const int elementId_shifter6 = 31; + + public const int elementId_shifter7 = 32; + + public const int elementId_shifter8 = 33; + + public const int elementId_shifter9 = 34; + + public const int elementId_shifter10 = 35; + + public const int elementId_reverseGear = 44; + + public const int elementId_select = 36; + + public const int elementId_start = 37; + + public const int elementId_systemButton = 38; + + public const int elementId_horn = 43; + + public const int elementId_dPadUp = 39; + + public const int elementId_dPadRight = 40; + + public const int elementId_dPadDown = 41; + + public const int elementId_dPadLeft = 42; + + public const int elementId_dPad = 45; + + IControllerTemplateAxis IRacingWheelTemplate.wheel => GetElement<IControllerTemplateAxis>(0); + + IControllerTemplateAxis IRacingWheelTemplate.accelerator => GetElement<IControllerTemplateAxis>(1); + + IControllerTemplateAxis IRacingWheelTemplate.brake => GetElement<IControllerTemplateAxis>(2); + + IControllerTemplateAxis IRacingWheelTemplate.clutch => GetElement<IControllerTemplateAxis>(3); + + IControllerTemplateButton IRacingWheelTemplate.shiftDown => GetElement<IControllerTemplateButton>(4); + + IControllerTemplateButton IRacingWheelTemplate.shiftUp => GetElement<IControllerTemplateButton>(5); + + IControllerTemplateButton IRacingWheelTemplate.wheelButton1 => GetElement<IControllerTemplateButton>(6); + + IControllerTemplateButton IRacingWheelTemplate.wheelButton2 => GetElement<IControllerTemplateButton>(7); + + IControllerTemplateButton IRacingWheelTemplate.wheelButton3 => GetElement<IControllerTemplateButton>(8); + + IControllerTemplateButton IRacingWheelTemplate.wheelButton4 => GetElement<IControllerTemplateButton>(9); + + IControllerTemplateButton IRacingWheelTemplate.wheelButton5 => GetElement<IControllerTemplateButton>(10); + + IControllerTemplateButton IRacingWheelTemplate.wheelButton6 => GetElement<IControllerTemplateButton>(11); + + IControllerTemplateButton IRacingWheelTemplate.wheelButton7 => GetElement<IControllerTemplateButton>(12); + + IControllerTemplateButton IRacingWheelTemplate.wheelButton8 => GetElement<IControllerTemplateButton>(13); + + IControllerTemplateButton IRacingWheelTemplate.wheelButton9 => GetElement<IControllerTemplateButton>(14); + + IControllerTemplateButton IRacingWheelTemplate.wheelButton10 => GetElement<IControllerTemplateButton>(15); + + IControllerTemplateButton IRacingWheelTemplate.consoleButton1 => GetElement<IControllerTemplateButton>(16); + + IControllerTemplateButton IRacingWheelTemplate.consoleButton2 => GetElement<IControllerTemplateButton>(17); + + IControllerTemplateButton IRacingWheelTemplate.consoleButton3 => GetElement<IControllerTemplateButton>(18); + + IControllerTemplateButton IRacingWheelTemplate.consoleButton4 => GetElement<IControllerTemplateButton>(19); + + IControllerTemplateButton IRacingWheelTemplate.consoleButton5 => GetElement<IControllerTemplateButton>(20); + + IControllerTemplateButton IRacingWheelTemplate.consoleButton6 => GetElement<IControllerTemplateButton>(21); + + IControllerTemplateButton IRacingWheelTemplate.consoleButton7 => GetElement<IControllerTemplateButton>(22); + + IControllerTemplateButton IRacingWheelTemplate.consoleButton8 => GetElement<IControllerTemplateButton>(23); + + IControllerTemplateButton IRacingWheelTemplate.consoleButton9 => GetElement<IControllerTemplateButton>(24); + + IControllerTemplateButton IRacingWheelTemplate.consoleButton10 => GetElement<IControllerTemplateButton>(25); + + IControllerTemplateButton IRacingWheelTemplate.shifter1 => GetElement<IControllerTemplateButton>(26); + + IControllerTemplateButton IRacingWheelTemplate.shifter2 => GetElement<IControllerTemplateButton>(27); + + IControllerTemplateButton IRacingWheelTemplate.shifter3 => GetElement<IControllerTemplateButton>(28); + + IControllerTemplateButton IRacingWheelTemplate.shifter4 => GetElement<IControllerTemplateButton>(29); + + IControllerTemplateButton IRacingWheelTemplate.shifter5 => GetElement<IControllerTemplateButton>(30); + + IControllerTemplateButton IRacingWheelTemplate.shifter6 => GetElement<IControllerTemplateButton>(31); + + IControllerTemplateButton IRacingWheelTemplate.shifter7 => GetElement<IControllerTemplateButton>(32); + + IControllerTemplateButton IRacingWheelTemplate.shifter8 => GetElement<IControllerTemplateButton>(33); + + IControllerTemplateButton IRacingWheelTemplate.shifter9 => GetElement<IControllerTemplateButton>(34); + + IControllerTemplateButton IRacingWheelTemplate.shifter10 => GetElement<IControllerTemplateButton>(35); + + IControllerTemplateButton IRacingWheelTemplate.reverseGear => GetElement<IControllerTemplateButton>(44); + + IControllerTemplateButton IRacingWheelTemplate.select => GetElement<IControllerTemplateButton>(36); + + IControllerTemplateButton IRacingWheelTemplate.start => GetElement<IControllerTemplateButton>(37); + + IControllerTemplateButton IRacingWheelTemplate.systemButton => GetElement<IControllerTemplateButton>(38); + + IControllerTemplateButton IRacingWheelTemplate.horn => GetElement<IControllerTemplateButton>(43); + + IControllerTemplateDPad IRacingWheelTemplate.dPad => GetElement<IControllerTemplateDPad>(45); + + public RacingWheelTemplate(object payload) + : base(payload) + { + } +} diff --git a/Thronefall_v1.0/Rewired/Rewired/SixDofControllerTemplate.cs b/Thronefall_v1.0/Rewired/Rewired/SixDofControllerTemplate.cs new file mode 100644 index 0000000..083b9bc --- /dev/null +++ b/Thronefall_v1.0/Rewired/Rewired/SixDofControllerTemplate.cs @@ -0,0 +1,229 @@ +using System; + +namespace Rewired; + +public sealed class SixDofControllerTemplate : ControllerTemplate, ISixDofControllerTemplate, IControllerTemplate +{ + public static readonly Guid typeGuid = new Guid("2599beb3-522b-43dd-a4ef-93fd60e5eafa"); + + public const int elementId_positionX = 1; + + public const int elementId_positionY = 2; + + public const int elementId_positionZ = 0; + + public const int elementId_rotationX = 3; + + public const int elementId_rotationY = 5; + + public const int elementId_rotationZ = 4; + + public const int elementId_throttle1Axis = 6; + + public const int elementId_throttle1MinDetent = 50; + + public const int elementId_throttle2Axis = 7; + + public const int elementId_throttle2MinDetent = 51; + + public const int elementId_extraAxis1 = 8; + + public const int elementId_extraAxis2 = 9; + + public const int elementId_extraAxis3 = 10; + + public const int elementId_extraAxis4 = 11; + + public const int elementId_button1 = 12; + + public const int elementId_button2 = 13; + + public const int elementId_button3 = 14; + + public const int elementId_button4 = 15; + + public const int elementId_button5 = 16; + + public const int elementId_button6 = 17; + + public const int elementId_button7 = 18; + + public const int elementId_button8 = 19; + + public const int elementId_button9 = 20; + + public const int elementId_button10 = 21; + + public const int elementId_button11 = 22; + + public const int elementId_button12 = 23; + + public const int elementId_button13 = 24; + + public const int elementId_button14 = 25; + + public const int elementId_button15 = 26; + + public const int elementId_button16 = 27; + + public const int elementId_button17 = 28; + + public const int elementId_button18 = 29; + + public const int elementId_button19 = 30; + + public const int elementId_button20 = 31; + + public const int elementId_button21 = 55; + + public const int elementId_button22 = 56; + + public const int elementId_button23 = 57; + + public const int elementId_button24 = 58; + + public const int elementId_button25 = 59; + + public const int elementId_button26 = 60; + + public const int elementId_button27 = 61; + + public const int elementId_button28 = 62; + + public const int elementId_button29 = 63; + + public const int elementId_button30 = 64; + + public const int elementId_button31 = 65; + + public const int elementId_button32 = 66; + + public const int elementId_hat1Up = 32; + + public const int elementId_hat1UpRight = 33; + + public const int elementId_hat1Right = 34; + + public const int elementId_hat1DownRight = 35; + + public const int elementId_hat1Down = 36; + + public const int elementId_hat1DownLeft = 37; + + public const int elementId_hat1Left = 38; + + public const int elementId_hat1UpLeft = 39; + + public const int elementId_hat2Up = 40; + + public const int elementId_hat2UpRight = 41; + + public const int elementId_hat2Right = 42; + + public const int elementId_hat2DownRight = 43; + + public const int elementId_hat2Down = 44; + + public const int elementId_hat2DownLeft = 45; + + public const int elementId_hat2Left = 46; + + public const int elementId_hat2UpLeft = 47; + + public const int elementId_hat1 = 48; + + public const int elementId_hat2 = 49; + + public const int elementId_throttle1 = 52; + + public const int elementId_throttle2 = 53; + + public const int elementId_stick = 54; + + IControllerTemplateAxis ISixDofControllerTemplate.extraAxis1 => GetElement<IControllerTemplateAxis>(8); + + IControllerTemplateAxis ISixDofControllerTemplate.extraAxis2 => GetElement<IControllerTemplateAxis>(9); + + IControllerTemplateAxis ISixDofControllerTemplate.extraAxis3 => GetElement<IControllerTemplateAxis>(10); + + IControllerTemplateAxis ISixDofControllerTemplate.extraAxis4 => GetElement<IControllerTemplateAxis>(11); + + IControllerTemplateButton ISixDofControllerTemplate.button1 => GetElement<IControllerTemplateButton>(12); + + IControllerTemplateButton ISixDofControllerTemplate.button2 => GetElement<IControllerTemplateButton>(13); + + IControllerTemplateButton ISixDofControllerTemplate.button3 => GetElement<IControllerTemplateButton>(14); + + IControllerTemplateButton ISixDofControllerTemplate.button4 => GetElement<IControllerTemplateButton>(15); + + IControllerTemplateButton ISixDofControllerTemplate.button5 => GetElement<IControllerTemplateButton>(16); + + IControllerTemplateButton ISixDofControllerTemplate.button6 => GetElement<IControllerTemplateButton>(17); + + IControllerTemplateButton ISixDofControllerTemplate.button7 => GetElement<IControllerTemplateButton>(18); + + IControllerTemplateButton ISixDofControllerTemplate.button8 => GetElement<IControllerTemplateButton>(19); + + IControllerTemplateButton ISixDofControllerTemplate.button9 => GetElement<IControllerTemplateButton>(20); + + IControllerTemplateButton ISixDofControllerTemplate.button10 => GetElement<IControllerTemplateButton>(21); + + IControllerTemplateButton ISixDofControllerTemplate.button11 => GetElement<IControllerTemplateButton>(22); + + IControllerTemplateButton ISixDofControllerTemplate.button12 => GetElement<IControllerTemplateButton>(23); + + IControllerTemplateButton ISixDofControllerTemplate.button13 => GetElement<IControllerTemplateButton>(24); + + IControllerTemplateButton ISixDofControllerTemplate.button14 => GetElement<IControllerTemplateButton>(25); + + IControllerTemplateButton ISixDofControllerTemplate.button15 => GetElement<IControllerTemplateButton>(26); + + IControllerTemplateButton ISixDofControllerTemplate.button16 => GetElement<IControllerTemplateButton>(27); + + IControllerTemplateButton ISixDofControllerTemplate.button17 => GetElement<IControllerTemplateButton>(28); + + IControllerTemplateButton ISixDofControllerTemplate.button18 => GetElement<IControllerTemplateButton>(29); + + IControllerTemplateButton ISixDofControllerTemplate.button19 => GetElement<IControllerTemplateButton>(30); + + IControllerTemplateButton ISixDofControllerTemplate.button20 => GetElement<IControllerTemplateButton>(31); + + IControllerTemplateButton ISixDofControllerTemplate.button21 => GetElement<IControllerTemplateButton>(55); + + IControllerTemplateButton ISixDofControllerTemplate.button22 => GetElement<IControllerTemplateButton>(56); + + IControllerTemplateButton ISixDofControllerTemplate.button23 => GetElement<IControllerTemplateButton>(57); + + IControllerTemplateButton ISixDofControllerTemplate.button24 => GetElement<IControllerTemplateButton>(58); + + IControllerTemplateButton ISixDofControllerTemplate.button25 => GetElement<IControllerTemplateButton>(59); + + IControllerTemplateButton ISixDofControllerTemplate.button26 => GetElement<IControllerTemplateButton>(60); + + IControllerTemplateButton ISixDofControllerTemplate.button27 => GetElement<IControllerTemplateButton>(61); + + IControllerTemplateButton ISixDofControllerTemplate.button28 => GetElement<IControllerTemplateButton>(62); + + IControllerTemplateButton ISixDofControllerTemplate.button29 => GetElement<IControllerTemplateButton>(63); + + IControllerTemplateButton ISixDofControllerTemplate.button30 => GetElement<IControllerTemplateButton>(64); + + IControllerTemplateButton ISixDofControllerTemplate.button31 => GetElement<IControllerTemplateButton>(65); + + IControllerTemplateButton ISixDofControllerTemplate.button32 => GetElement<IControllerTemplateButton>(66); + + IControllerTemplateHat ISixDofControllerTemplate.hat1 => GetElement<IControllerTemplateHat>(48); + + IControllerTemplateHat ISixDofControllerTemplate.hat2 => GetElement<IControllerTemplateHat>(49); + + IControllerTemplateThrottle ISixDofControllerTemplate.throttle1 => GetElement<IControllerTemplateThrottle>(52); + + IControllerTemplateThrottle ISixDofControllerTemplate.throttle2 => GetElement<IControllerTemplateThrottle>(53); + + IControllerTemplateStick6D ISixDofControllerTemplate.stick => GetElement<IControllerTemplateStick6D>(54); + + public SixDofControllerTemplate(object payload) + : base(payload) + { + } +} |