Ejemplo n.º 1
0
 private void DrawAddActionMapButton(int playerId, InputAction action, Pole actionAxisContribution, ControlRemappingDemo1.ControllerSelection controller, ControllerMap controllerMap, bool assignFullAxis)
 {
     if (GUILayout.Button("Add...", new GUILayoutOption[]
     {
         GUILayout.ExpandWidth(false)
     }))
     {
         this.EnqueueAction(new ControlRemappingDemo1.ElementAssignmentChange(playerId, controller.id, controller.type, controllerMap, ControlRemappingDemo1.ElementAssignmentChangeType.Add, -1, action.id, actionAxisContribution, action.type, assignFullAxis, false));
     }
     GUILayout.Space(10f);
 }
Ejemplo n.º 2
0
 public void Confirm(ControlRemappingDemo1.UserResponse response)
 {
     this.resultCallback(this.currentActionId, response);
     this.Close();
 }
Ejemplo n.º 3
0
 private void DrawInvertButton(int playerId, InputAction action, Pole actionAxisContribution, ControlRemappingDemo1.ControllerSelection controller, ControllerMap controllerMap, ActionElementMap elementMap)
 {
     bool invert = elementMap.invert;
     bool flag = GUILayout.Toggle(invert, "Invert", new GUILayoutOption[]
     {
         GUILayout.ExpandWidth(false)
     });
     if (flag != invert)
     {
         elementMap.invert = flag;
     }
     GUILayout.Space(10f);
 }
Ejemplo n.º 4
0
 private void PollKeyboardForAssignment(ControlRemappingDemo1.ElementAssignmentChange entry)
 {
     int num = 0;
     ControllerPollingInfo pollingInfo = default(ControllerPollingInfo);
     ControllerPollingInfo pollingInfo2 = default(ControllerPollingInfo);
     ModifierKeyFlags modifierKeyFlags = ModifierKeyFlags.None;
     foreach (ControllerPollingInfo current in ReInput.controllers.Keyboard.PollForAllKeys())
     {
         KeyCode keyboardKey = current.keyboardKey;
         if (keyboardKey != KeyCode.AltGr)
         {
             if (Keyboard.IsModifierKey(current.keyboardKey))
             {
                 if (num == 0)
                 {
                     pollingInfo2 = current;
                 }
                 modifierKeyFlags |= Keyboard.KeyCodeToModifierKeyFlags(keyboardKey);
                 num++;
             }
             else if (pollingInfo.keyboardKey == KeyCode.None)
             {
                 pollingInfo = current;
             }
         }
     }
     if (pollingInfo.keyboardKey == KeyCode.None)
     {
         if (num > 0)
         {
             this.dialog.StartCloseTimer(5f);
             if (num == 1)
             {
                 if (ReInput.controllers.Keyboard.GetKeyTimePressed(pollingInfo2.keyboardKey) > 1f)
                 {
                     entry.pollingInfo = pollingInfo2;
                     this.dialog.Confirm();
                     return;
                 }
                 GUILayout.Label(Keyboard.GetKeyName(pollingInfo2.keyboardKey), new GUILayoutOption[0]);
             }
             else
             {
                 GUILayout.Label(Keyboard.ModifierKeyFlagsToString(modifierKeyFlags), new GUILayoutOption[0]);
             }
         }
         return;
     }
     if (num == 0)
     {
         entry.pollingInfo = pollingInfo;
         this.dialog.Confirm();
         return;
     }
     entry.pollingInfo = pollingInfo;
     entry.modifierKeyFlags = modifierKeyFlags;
     this.dialog.Confirm();
 }
Ejemplo n.º 5
0
 public ElementAssignmentChange(int playerId, int controllerId, ControllerType controllerType, ControllerMap controllerMap, ControlRemappingDemo1.ElementAssignmentChangeType changeType, int actionElementMapId, int actionId, Pole actionAxisContribution, InputActionType actionType, bool assignFullAxis, bool invert)
     : base(ControlRemappingDemo1.QueueActionType.ElementAssignment)
 {
     this.playerId = playerId;
     this.controllerId = controllerId;
     this.controllerType = controllerType;
     this.controllerMap = controllerMap;
     this.changeType = changeType;
     this.actionElementMapId = actionElementMapId;
     this.actionId = actionId;
     this.actionAxisContribution = actionAxisContribution;
     this.actionType = actionType;
     this.assignFullAxis = assignFullAxis;
     this.invert = invert;
 }
Ejemplo n.º 6
0
 public QueueEntry(ControlRemappingDemo1.QueueActionType queueActionType)
 {
     this.id = ControlRemappingDemo1.QueueEntry.nextId;
     this.queueActionType = queueActionType;
 }
Ejemplo n.º 7
0
 private void DialogResultCallback(int queueActionId, ControlRemappingDemo1.UserResponse response)
 {
     foreach (ControlRemappingDemo1.QueueEntry current in this.actionQueue)
     {
         if (current.id == queueActionId)
         {
             if (response != ControlRemappingDemo1.UserResponse.Cancel)
             {
                 current.Confirm(response);
             }
             else
             {
                 current.Cancel();
             }
             break;
         }
     }
 }
Ejemplo n.º 8
0
 public void StartModal(int queueActionId, ControlRemappingDemo1.DialogHelper.DialogType type, ControlRemappingDemo1.WindowProperties windowProperties, Action<int, ControlRemappingDemo1.UserResponse> resultCallback, float closeTimer)
 {
     this.StartModal(queueActionId, type, windowProperties, resultCallback, closeTimer, -1f);
 }
Ejemplo n.º 9
0
 private bool ProcessElementAssignmentChange(ControlRemappingDemo1.ElementAssignmentChange entry)
 {
     switch (entry.changeType)
     {
     case ControlRemappingDemo1.ElementAssignmentChangeType.Add:
     case ControlRemappingDemo1.ElementAssignmentChangeType.Replace:
         return this.ProcessAddOrReplaceElementAssignment(entry);
     case ControlRemappingDemo1.ElementAssignmentChangeType.Remove:
         return this.ProcessRemoveElementAssignment(entry);
     case ControlRemappingDemo1.ElementAssignmentChangeType.ReassignOrRemove:
         return this.ProcessRemoveOrReassignElementAssignment(entry);
     case ControlRemappingDemo1.ElementAssignmentChangeType.ConflictCheck:
         return this.ProcessElementAssignmentConflictCheck(entry);
     default:
         throw new NotImplementedException();
     }
 }
Ejemplo n.º 10
0
 private bool ProcessElementAssignmentConflictCheck(ControlRemappingDemo1.ElementAssignmentChange entry)
 {
     if (ReInput.players.GetPlayer(entry.playerId) == null)
     {
         return true;
     }
     if (entry.controllerMap == null)
     {
         return true;
     }
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Canceled)
     {
         return true;
     }
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Confirmed)
     {
         entry.changeType = ControlRemappingDemo1.ElementAssignmentChangeType.Add;
         if (entry.response == ControlRemappingDemo1.UserResponse.Confirm)
         {
             ReInput.controllers.conflictChecking.RemoveElementAssignmentConflicts(entry.ToElementAssignmentConflictCheck());
             entry.ReplaceOrCreateActionElementMap();
         }
         else
         {
             if (entry.response != ControlRemappingDemo1.UserResponse.Custom1)
             {
                 throw new NotImplementedException();
             }
             entry.ReplaceOrCreateActionElementMap();
         }
         return true;
     }
     bool flag = false;
     foreach (ElementAssignmentConflictInfo current in ReInput.controllers.conflictChecking.ElementAssignmentConflicts(entry.ToElementAssignmentConflictCheck()))
     {
         if (!current.isUserAssignable)
         {
             flag = true;
             break;
         }
     }
     if (flag)
     {
         string message = entry.elementName + " 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.";
         this.dialog.StartModal(entry.id, ControlRemappingDemo1.DialogHelper.DialogType.AssignElement, new ControlRemappingDemo1.WindowProperties
         {
             title = "Assignment Conflict",
             message = message,
             rect = this.GetScreenCenteredRect(250f, 200f),
             windowDrawDelegate = new Action<string, string>(this.DrawElementAssignmentProtectedConflictWindow)
         }, new Action<int, ControlRemappingDemo1.UserResponse>(this.DialogResultCallback));
     }
     else
     {
         string message2 = entry.elementName + " 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.";
         this.dialog.StartModal(entry.id, ControlRemappingDemo1.DialogHelper.DialogType.AssignElement, new ControlRemappingDemo1.WindowProperties
         {
             title = "Assignment Conflict",
             message = message2,
             rect = this.GetScreenCenteredRect(250f, 200f),
             windowDrawDelegate = new Action<string, string>(this.DrawElementAssignmentNormalConflictWindow)
         }, new Action<int, ControlRemappingDemo1.UserResponse>(this.DialogResultCallback));
     }
     return false;
 }
Ejemplo n.º 11
0
 private bool ProcessCalibration(ControlRemappingDemo1.Calibration entry)
 {
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Canceled)
     {
         return true;
     }
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Confirmed)
     {
         return true;
     }
     this.dialog.StartModal(entry.id, ControlRemappingDemo1.DialogHelper.DialogType.JoystickConflict, new ControlRemappingDemo1.WindowProperties
     {
         title = "Calibrate Controller",
         message = "Select an axis to calibrate on the " + entry.joystick.name + ".",
         rect = this.GetScreenCenteredRect(450f, 480f),
         windowDrawDelegate = new Action<string, string>(this.DrawCalibrationWindow)
     }, new Action<int, ControlRemappingDemo1.UserResponse>(this.DialogResultCallback));
     return false;
 }
Ejemplo n.º 12
0
 private bool ProcessAddOrReplaceElementAssignment(ControlRemappingDemo1.ElementAssignmentChange entry)
 {
     if (ReInput.players.GetPlayer(entry.playerId) == null)
     {
         return true;
     }
     if (entry.controllerMap == null)
     {
         return true;
     }
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Canceled)
     {
         return true;
     }
     if (entry.state != ControlRemappingDemo1.QueueEntry.State.Confirmed)
     {
         string text;
         if (entry.controllerType == ControllerType.Keyboard)
         {
             if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXWebPlayer)
             {
                 text = "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 ifselt this action, press and hold the key for 1 second.";
             }
             else
             {
                 text = "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.";
             }
             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.";
             }
         }
         else if (entry.controllerType == ControllerType.Mouse)
         {
             text = "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 = "Press any button or axis to assign it to this action.";
         }
         this.dialog.StartModal(entry.id, ControlRemappingDemo1.DialogHelper.DialogType.AssignElement, new ControlRemappingDemo1.WindowProperties
         {
             title = "Assign",
             message = text,
             rect = this.GetScreenCenteredRect(250f, 200f),
             windowDrawDelegate = new Action<string, string>(this.DrawElementAssignmentWindow)
         }, new Action<int, ControlRemappingDemo1.UserResponse>(this.DialogResultCallback), 5f);
         return false;
     }
     if (Event.current.type != EventType.Layout)
     {
         return false;
     }
     if (!ReInput.controllers.conflictChecking.DoesElementAssignmentConflict(entry.ToElementAssignmentConflictCheck()))
     {
         entry.ReplaceOrCreateActionElementMap();
     }
     else
     {
         ControlRemappingDemo1.ElementAssignmentChange elementAssignmentChange = new ControlRemappingDemo1.ElementAssignmentChange(entry);
         elementAssignmentChange.changeType = ControlRemappingDemo1.ElementAssignmentChangeType.ConflictCheck;
         this.actionQueue.Enqueue(elementAssignmentChange);
     }
     return true;
 }
Ejemplo n.º 13
0
 private void PollMouseForAssignment(ControlRemappingDemo1.ElementAssignmentChange entry)
 {
     Player player = ReInput.players.GetPlayer(entry.playerId);
     if (player == null)
     {
         this.dialog.Cancel();
         return;
     }
     entry.pollingInfo = player.controllers.polling.PollControllerForFirstElementDown(entry.controllerType, entry.controllerId);
     if (entry.pollingInfo.success)
     {
         this.dialog.Confirm();
     }
 }
Ejemplo n.º 14
0
 public void DrawConfirmButton(ControlRemappingDemo1.UserResponse response)
 {
     this.DrawConfirmButton(response, "Confirm");
 }
Ejemplo n.º 15
0
 private bool ProcessFallbackJoystickIdentification(ControlRemappingDemo1.FallbackJoystickIdentification entry)
 {
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Canceled)
     {
         return true;
     }
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Confirmed)
     {
         return true;
     }
     this.dialog.StartModal(entry.id, ControlRemappingDemo1.DialogHelper.DialogType.JoystickConflict, new ControlRemappingDemo1.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 = this.GetScreenCenteredRect(250f, 200f),
         windowDrawDelegate = new Action<string, string>(this.DrawFallbackJoystickIdentificationWindow)
     }, new Action<int, ControlRemappingDemo1.UserResponse>(this.DialogResultCallback), 0f, 1f);
     return false;
 }
Ejemplo n.º 16
0
 public void DrawConfirmButton(ControlRemappingDemo1.UserResponse response, string title)
 {
     bool enabled = GUI.enabled;
     if (this.busy)
     {
         GUI.enabled = false;
     }
     if (GUILayout.Button(title, new GUILayoutOption[0]))
     {
         this.Confirm(response);
     }
     if (GUI.enabled != enabled)
     {
         GUI.enabled = enabled;
     }
 }
Ejemplo n.º 17
0
 private bool ProcessJoystickAssignmentChange(ControlRemappingDemo1.JoystickAssignmentChange entry)
 {
     if (entry.state == ControlRemappingDemo1.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);
         this.ControllerSelectionChanged();
         return true;
     }
     if (player.controllers.ContainsController(ControllerType.Joystick, entry.joystickId))
     {
         return true;
     }
     bool flag = ReInput.controllers.IsJoystickAssigned(entry.joystickId);
     if (!flag || entry.state == ControlRemappingDemo1.QueueEntry.State.Confirmed)
     {
         player.controllers.AddController(ControllerType.Joystick, entry.joystickId, true);
         this.ControllerSelectionChanged();
         return true;
     }
     this.dialog.StartModal(entry.id, ControlRemappingDemo1.DialogHelper.DialogType.JoystickConflict, new ControlRemappingDemo1.WindowProperties
     {
         title = "Joystick Reassignment",
         message = "This joystick is already assigned to another player. Do you want to reassign this joystick to " + player.descriptiveName + "?",
         rect = this.GetScreenCenteredRect(250f, 200f),
         windowDrawDelegate = new Action<string, string>(this.DrawModalWindow)
     }, new Action<int, ControlRemappingDemo1.UserResponse>(this.DialogResultCallback));
     return false;
 }
Ejemplo n.º 18
0
 public void StartModal(int queueActionId, ControlRemappingDemo1.DialogHelper.DialogType type, ControlRemappingDemo1.WindowProperties windowProperties, Action<int, ControlRemappingDemo1.UserResponse> resultCallback, float closeTimer, float openBusyDelay)
 {
     this.currentActionId = queueActionId;
     this.windowProperties = windowProperties;
     this.type = type;
     this.resultCallback = resultCallback;
     if (closeTimer > 0f)
     {
         this.StartCloseTimer(closeTimer);
     }
     if (openBusyDelay >= 0f)
     {
         this.StateChanged(openBusyDelay);
     }
 }
Ejemplo n.º 19
0
 private bool ProcessRemoveElementAssignment(ControlRemappingDemo1.ElementAssignmentChange entry)
 {
     if (entry.controllerMap == null)
     {
         return true;
     }
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Canceled)
     {
         return true;
     }
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Confirmed)
     {
         entry.controllerMap.DeleteElementMap(entry.actionElementMapId);
         return true;
     }
     this.dialog.StartModal(entry.id, ControlRemappingDemo1.DialogHelper.DialogType.DeleteAssignmentConfirmation, new ControlRemappingDemo1.WindowProperties
     {
         title = "Remove Assignment",
         message = "Are you sure you want to remove this assignment?",
         rect = this.GetScreenCenteredRect(250f, 200f),
         windowDrawDelegate = new Action<string, string>(this.DrawModalWindow)
     }, new Action<int, ControlRemappingDemo1.UserResponse>(this.DialogResultCallback));
     return false;
 }
Ejemplo n.º 20
0
 public ElementAssignmentChange(ControlRemappingDemo1.ElementAssignmentChange source)
     : base(ControlRemappingDemo1.QueueActionType.ElementAssignment)
 {
     this.playerId = source.playerId;
     this.controllerId = source.controllerId;
     this.controllerType = source.controllerType;
     this.controllerMap = source.controllerMap;
     this.changeType = source.changeType;
     this.actionElementMapId = source.actionElementMapId;
     this.actionId = source.actionId;
     this.actionAxisContribution = source.actionAxisContribution;
     this.actionType = source.actionType;
     this.assignFullAxis = source.assignFullAxis;
     this.invert = source.invert;
     this.pollingInfo = source.pollingInfo;
     this.modifierKeyFlags = source.modifierKeyFlags;
 }
Ejemplo n.º 21
0
 private bool ProcessRemoveOrReassignElementAssignment(ControlRemappingDemo1.ElementAssignmentChange entry)
 {
     if (entry.controllerMap == null)
     {
         return true;
     }
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Canceled)
     {
         ControlRemappingDemo1.ElementAssignmentChange elementAssignmentChange = new ControlRemappingDemo1.ElementAssignmentChange(entry);
         elementAssignmentChange.changeType = ControlRemappingDemo1.ElementAssignmentChangeType.Remove;
         this.actionQueue.Enqueue(elementAssignmentChange);
         return true;
     }
     if (entry.state == ControlRemappingDemo1.QueueEntry.State.Confirmed)
     {
         ControlRemappingDemo1.ElementAssignmentChange elementAssignmentChange2 = new ControlRemappingDemo1.ElementAssignmentChange(entry);
         elementAssignmentChange2.changeType = ControlRemappingDemo1.ElementAssignmentChangeType.Replace;
         this.actionQueue.Enqueue(elementAssignmentChange2);
         return true;
     }
     this.dialog.StartModal(entry.id, ControlRemappingDemo1.DialogHelper.DialogType.AssignElement, new ControlRemappingDemo1.WindowProperties
     {
         title = "Reassign or Remove",
         message = "Do you want to reassign or remove this assignment?",
         rect = this.GetScreenCenteredRect(250f, 200f),
         windowDrawDelegate = new Action<string, string>(this.DrawReassignOrRemoveElementAssignmentWindow)
     }, new Action<int, ControlRemappingDemo1.UserResponse>(this.DialogResultCallback));
     return false;
 }
Ejemplo n.º 22
0
 public void Confirm(ControlRemappingDemo1.UserResponse response)
 {
     this.state = ControlRemappingDemo1.QueueEntry.State.Confirmed;
     this.response = response;
 }
Ejemplo n.º 23
0
 private void DrawActionAssignmentButton(int playerId, InputAction action, Pole actionAxisContribution, ControlRemappingDemo1.ControllerSelection controller, ControllerMap controllerMap, bool assignFullAxis, ActionElementMap elementMap)
 {
     if (GUILayout.Button(elementMap.elementIdentifierName, new GUILayoutOption[]
     {
         GUILayout.ExpandWidth(false),
         GUILayout.MinWidth(30f)
     }))
     {
         this.EnqueueAction(new ControlRemappingDemo1.ElementAssignmentChange(playerId, controller.id, controller.type, controllerMap, ControlRemappingDemo1.ElementAssignmentChangeType.ReassignOrRemove, elementMap.id, action.id, actionAxisContribution, action.type, assignFullAxis, elementMap.invert));
     }
     GUILayout.Space(4f);
 }
Ejemplo n.º 24
0
 private void EnqueueAction(ControlRemappingDemo1.QueueEntry entry)
 {
     if (entry == null)
     {
         return;
     }
     this.busy = true;
     GUI.enabled = false;
     this.actionQueue.Enqueue(entry);
 }
Ejemplo n.º 25
0
 private void PollControllerForAssignment(ControlRemappingDemo1.ElementAssignmentChange entry)
 {
     if (this.dialog.busy)
     {
         return;
     }
     switch (entry.controllerType)
     {
     case ControllerType.Keyboard:
         this.PollKeyboardForAssignment(entry);
         break;
     case ControllerType.Mouse:
         this.PollMouseForAssignment(entry);
         break;
     case ControllerType.Joystick:
         this.PollJoystickForAssignment(entry);
         break;
     }
 }