Пример #1
0
        private void PollMouseForAssignment(ElementAssignmentChange entry) {
            // Poll the controller via the owning player
            Player player = ReInput.players.GetPlayer(entry.playerId);
            if(player == null) {
                dialog.Cancel();
                return;
            }

            // Just poll the controller for the first axis or button press
            entry.pollingInfo = player.controllers.polling.PollControllerForFirstElementDown(entry.controllerType, entry.controllerId); // PollMouseForFirstElement_ExcludeXYAxis(entry.controllerId); // poll the mouse for all input except the primary X/Y axes -- we'll handle these separately
            if(entry.pollingInfo.success) { // polling returned a result
                dialog.Confirm(); // finish
            }
        }
Пример #2
0
        private void PollKeyboardForAssignment(ElementAssignmentChange entry) {
            int modifierPressedCount = 0; // the number of modifier keys being pressed this cycle
            ControllerPollingInfo nonModifierKeyInfo = new ControllerPollingInfo();
            ControllerPollingInfo firstModifierKeyInfo = new ControllerPollingInfo();
            ModifierKeyFlags curModifiers = ModifierKeyFlags.None;

            // Check all keys being pressed at present so we can handle modifier keys
            foreach(ControllerPollingInfo info in ReInput.controllers.Keyboard.PollForAllKeys()) {
                KeyCode key = info.keyboardKey;
                if(key == KeyCode.AltGr) continue; // skip AltGr key because it gets fired when alt and control are held on some keyboards

                // determine if a modifier key is being pressed
                if(Keyboard.IsModifierKey(info.keyboardKey)) { // a modifier key is pressed
                    if(modifierPressedCount == 0) firstModifierKeyInfo = info; // store the polling info for the first modifier key pressed in case its the only key pressed

                    curModifiers |= Keyboard.KeyCodeToModifierKeyFlags(key); // add the key to the current modifier flags
                    modifierPressedCount += 1; // count how many modifier keys are pressed

                } else { // this is not a modifier key

                    if(nonModifierKeyInfo.keyboardKey != KeyCode.None) continue; // skip after the first one detected, we only need one non-modifier key press
                    nonModifierKeyInfo = info; // store the polling info
                }

            }

            // Commit immediately if a non-modifier key was pressed
            if(nonModifierKeyInfo.keyboardKey != KeyCode.None) { // a regular key was pressed

                if(modifierPressedCount == 0) { // only the regular key was pressed

                    entry.pollingInfo = nonModifierKeyInfo; // copy polling info into entry
                    dialog.Confirm(); // finish
                    return;

                } else { // one more more modifier keys was pressed too

                    entry.pollingInfo = nonModifierKeyInfo; // copy polling info into entry
                    entry.modifierKeyFlags = curModifiers; // set the modifier key flags in the entry
                    dialog.Confirm(); // finish
                    return;

                }

            } else if(modifierPressedCount > 0) { // one or more modifier keys were pressed, but no regular keys
                dialog.StartCloseTimer(assignmentTimeout); // reset close timer if a modifier key is pressed

                if(modifierPressedCount == 1) { // only one modifier is pressed, allow assigning just the modifier key

                    // Assign the modifier key as the main key if the user holds it for 1 second
                    if(ReInput.controllers.Keyboard.GetKeyTimePressed(firstModifierKeyInfo.keyboardKey) > 1.0f) { // key was pressed for one second
                        entry.pollingInfo = firstModifierKeyInfo; // copy polling info into entry
                        dialog.Confirm(); // finish
                        return;
                    }

                    // Show the key that is being pressed
                    GUILayout.Label(Keyboard.GetKeyName(firstModifierKeyInfo.keyboardKey));

                } else { // more than one modifier key is pressed
                    // do nothing because we don't want to assign modified modifier key presses such as Control + Alt, but you could if you wanted to.

                    // Show the modifier keys being held
                    GUILayout.Label(Keyboard.ModifierKeyFlagsToString(curModifiers));

                }

            }
        }
Пример #3
0
        private void PollJoystickForAssignment(ElementAssignmentChange entry) {
            // Poll the controller via the owning player
            Player player = ReInput.players.GetPlayer(entry.playerId);
            if(player == null) {
                dialog.Cancel();
                return;
            }

            // Just poll the controller for the first axis or button press
            entry.pollingInfo = player.controllers.polling.PollControllerForFirstElementDown(entry.controllerType, entry.controllerId);
            if(entry.pollingInfo.success) { // polling returned a result
                dialog.Confirm(); // finish
            }
        }
Пример #4
0
 public ElementAssignmentChange(ElementAssignmentChange source) : base(QueueActionType.ElementAssignment) {
     // Clones but with new id
     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;
 }
Пример #5
0
        private void PollControllerForAssignment(ElementAssignmentChange entry) {
            if(dialog.busy) return; // do not allow assignment until dialog is ready

            switch (entry.controllerType) {
                case ControllerType.Keyboard:
                    PollKeyboardForAssignment(entry); // poll keyboard for key presses
                    break;
                case ControllerType.Joystick:
                    PollJoystickForAssignment(entry); // poll joystick for element activations
                    break;
                case ControllerType.Mouse:
                    PollMouseForAssignment(entry); // poll mouse for element activations
                    break;
            }
        }
Пример #6
0
        private bool ProcessElementAssignmentConflictCheck(ElementAssignmentChange entry) {
            Player player = ReInput.players.GetPlayer(entry.playerId);
            if(player == null) return true;
            if(entry.controllerMap == null) return true;
            if(entry.state == QueueEntry.State.Canceled) return true; // user canceled

            // Check for user confirmation
            if(entry.state == QueueEntry.State.Confirmed) {
                
                entry.changeType = ElementAssignmentChangeType.Add; // set the change type back to add before we add the assignment
                
                if(entry.response == UserResponse.Confirm) { // remove and add

                    ReInput.controllers.conflictChecking.RemoveElementAssignmentConflicts(entry.ToElementAssignmentConflictCheck()); // remove conflicts
                    entry.ReplaceOrCreateActionElementMap(); // create or replace the element

                } else if(entry.response == UserResponse.Custom1) { // add without removing

                    entry.ReplaceOrCreateActionElementMap(); // add the element

                } else throw new System.NotImplementedException();


                return true; // finished
            }

            // Do a detailed conflict check
            bool protectedConflictFound = false;
            foreach(ElementAssignmentConflictInfo info in ReInput.controllers.conflictChecking.ElementAssignmentConflicts(entry.ToElementAssignmentConflictCheck())) {
                // Check if this conflict is with a protected assignment
                if(!info.isUserAssignable) {
                    protectedConflictFound = true;
                    break;
                }
            }

            // Open a different dialog depending on if a protected conflict was found
            if(protectedConflictFound) {
                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.";

                // Create dialog and start waiting for user assignment
                dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties {
                    title = "Assignment Conflict",
                    message = message,
                    rect = GetScreenCenteredRect(defaultModalWidth, defaultModalHeight),
                    windowDrawDelegate = DrawElementAssignmentProtectedConflictWindow
                },
                DialogResultCallback);

            } else {
                string message = 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.";

                // Create dialog and start waiting for user assignment
                dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties {
                    title = "Assignment Conflict",
                    message = message,
                    rect = GetScreenCenteredRect(defaultModalWidth, defaultModalHeight),
                    windowDrawDelegate = DrawElementAssignmentNormalConflictWindow
                },
                DialogResultCallback);

            }

            return false;
        }
Пример #7
0
        private bool ProcessAddOrReplaceElementAssignment(ElementAssignmentChange entry) {
            Player player = ReInput.players.GetPlayer(entry.playerId);
            if(player == null) return true;
            if(entry.controllerMap == null) return true;
            if(entry.state == QueueEntry.State.Canceled) return true; // user canceled

            // Check for user confirmation
            if(entry.state == QueueEntry.State.Confirmed) { // the action assignment has been confirmed
                if(Event.current.type != EventType.Layout) return false; // only make changes in layout to avoid GUI errors when new controls appear

                // Do a check for element assignment conflicts
                if(!ReInput.controllers.conflictChecking.DoesElementAssignmentConflict(entry.ToElementAssignmentConflictCheck())) {  // no conflicts
                    entry.ReplaceOrCreateActionElementMap(); // make the assignment, done

                } else { // we had conflicts
                    
                    // Enqueue a conflict check
                    ElementAssignmentChange newEntry = new ElementAssignmentChange(entry); // clone the entry
                    newEntry.changeType = ElementAssignmentChangeType.ConflictCheck; // set the new type to check for conflicts
                    actionQueue.Enqueue(newEntry); // enqueue the new entry
                }
                
                return true; // finished
            }

            // Customize the message for different controller types and different platforms
            string message;
            if(entry.controllerType == ControllerType.Keyboard) {

                if(Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXWebPlayer) {
                    message = "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 {
                    message = "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.";
                }

                // Editor modifier key disclaimer
                if(Application.isEditor) {
                    message += "\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) {
                message = "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 {
                message = "Press any button or axis to assign it to this action.";
            }

            // Create dialog and start waiting for user assignment
            dialog.StartModal(entry.id, DialogHelper.DialogType.AssignElement, new WindowProperties {
                title = "Assign",
                message = message,
                rect = GetScreenCenteredRect(defaultModalWidth, defaultModalHeight),
                windowDrawDelegate = DrawElementAssignmentWindow
            },
            DialogResultCallback,
            assignmentTimeout);

            return false;
        }
Пример #8
0
        private bool ProcessRemoveElementAssignment(ElementAssignmentChange entry) {
            if(entry.controllerMap == null) return true;
            if(entry.state == QueueEntry.State.Canceled) return true; // user canceled

            // Delete element
            if(entry.state == QueueEntry.State.Confirmed) { // user confirmed, delete it
                entry.controllerMap.DeleteElementMap(entry.actionElementMapId);
                return true;
            }
            
            // Create dialog and start waiting for user confirmation
            dialog.StartModal(entry.id, DialogHelper.DialogType.DeleteAssignmentConfirmation, new WindowProperties {
                title = "Remove Assignment",
                message = "Are you sure you want to remove this assignment?",
                rect = GetScreenCenteredRect(defaultModalWidth, defaultModalHeight),
                windowDrawDelegate = DrawModalWindow
            },
            DialogResultCallback);
            return false; // don't process anything more in this queue
        }
Пример #9
0
        private bool ProcessRemoveOrReassignElementAssignment(ElementAssignmentChange entry) {
            if(entry.controllerMap == null) return true;
            
            if(entry.state == QueueEntry.State.Canceled) { // delete entry
                // Enqueue a new action to delete the entry
                ElementAssignmentChange newEntry = new ElementAssignmentChange(entry); // copy the entry
                newEntry.changeType = ElementAssignmentChangeType.Remove; // change the type to Remove
                actionQueue.Enqueue(newEntry); // enqueue the new entry
                return true;
            }

            // Check for user confirmation
            if(entry.state == QueueEntry.State.Confirmed) { // reassign entry
                // Enqueue a new action to reassign the entry
                ElementAssignmentChange newEntry = new ElementAssignmentChange(entry); // copy the entry
                newEntry.changeType = ElementAssignmentChangeType.Replace; // change the type to Replace
                actionQueue.Enqueue(newEntry); // enqueue the new entry
                return true;
            }

            // Create dialog and start waiting for user assignment
            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(defaultModalWidth, defaultModalHeight),
                windowDrawDelegate = DrawReassignOrRemoveElementAssignmentWindow
            },
            DialogResultCallback);

            return false;
        }
Пример #10
0
        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 System.NotImplementedException();
            }
        }