public override GameHelper.Input.InputCollection GetDefaultControls()
        {
            InputCollection      ic     = new InputCollection();
            List <ButtonBinding> flight = new List <ButtonBinding>();
            //flight.Add(new KeyBinding("right", Microsoft.Xna.Framework.Input.Keys.D, false, false, false, KeyEvent.Down, TurnRight));
            ButtonMap map = new ButtonMap("null", flight);

            ic.AddMap(map);

            //Camera
            ButtonMap camControls = new ButtonMap(GenericInputGroups.Camera.ToString());

            camControls.AddBinding(new KeyBinding("Forward", Keys.NumPad8, ButtonEvent.Down, CameraMoveForward));
            camControls.AddBinding(new KeyBinding("Left", Keys.NumPad4, ButtonEvent.Down, CameraMoveLeft));
            camControls.AddBinding(new KeyBinding("Backward", Keys.NumPad5, ButtonEvent.Down, CameraMoveBackward));
            camControls.AddBinding(new KeyBinding("Right", Keys.NumPad6, ButtonEvent.Down, CameraMoveRight));
            camControls.AddBinding(new KeyBinding("Speed Increase", Keys.NumPad7, ButtonEvent.Pressed, CameraMoveSpeedIncrease));
            camControls.AddBinding(new KeyBinding("Speed Decrease", Keys.NumPad1, ButtonEvent.Pressed, CameraMoveSpeedDecrease));
            camControls.AddBinding(new KeyBinding("Height Increase", Keys.NumPad9, ButtonEvent.Down, CameraMoveHeightIncrease));
            camControls.AddBinding(new KeyBinding("Height Decrease", Keys.NumPad3, ButtonEvent.Down, CameraMoveHeightDecrease));

            camControls.AddBinding(new KeyBinding("Change Mode", Keys.Decimal, ButtonEvent.Pressed, CameraModeCycle));
            camControls.AddBinding(new KeyBinding("Home", Keys.Multiply, ButtonEvent.Pressed, CameraMoveHome));

            camControls.AddBinding(new KeyBinding("Toggle Debug Info", Keys.F1, ButtonEvent.Pressed, ToggleDebugInfo));
            camControls.AddBinding(new KeyBinding("Toggle Physics Debug", Keys.F2, ButtonEvent.Pressed, TogglePhsyicsDebug));

            ic.AddMap(camControls);

            ButtonMap flightControls = new ButtonMap("flight");

            flightControls.AddBinding(new KeyBinding("Forward", Keys.W, ButtonEvent.Down, FeatherPitchDown));
            flightControls.AddBinding(new KeyBinding("Left", Keys.A, ButtonEvent.Down, FeatherRollLeft));
            flightControls.AddBinding(new KeyBinding("Backward", Keys.S, ButtonEvent.Down, FeatherPitchUp));
            flightControls.AddBinding(new KeyBinding("Right", Keys.D, ButtonEvent.Down, FeatherRollRight));
            flightControls.AddBinding(new KeyBinding("Accelerate", Keys.OemPlus, ButtonEvent.Down, FeatherAccelerate));
            flightControls.AddBinding(new KeyBinding("Decelerate", Keys.OemMinus, ButtonEvent.Down, FeatherDecelerate));
            flightControls.AddBinding(new KeyBinding("Fire", Keys.Space, ButtonEvent.Pressed, FeatherFire));

            flightControls.AddBinding(new GamePadButtonBinding("Accelerate_gp", Buttons.RightShoulder, ButtonEvent.Down, FeatherAccelerate));
            flightControls.AddBinding(new GamePadButtonBinding("Decelerate_gp", Buttons.LeftShoulder, ButtonEvent.Down, FeatherDecelerate));
            //flightControls.AddBinding(new GamePadButtonBinding("Fire_gp", Buttons.RightTrigger, ButtonEvent.Down, FeatherFire)); // Fires too easily, using the analog method


            ic.AddMap(flightControls);

            AnalogMap flightControlsGamePad = new AnalogMap("flight_gp");

            flightControlsGamePad.AddBinding(new GamePadThumbStickBinding("Fly", ThumbStick.Left, AnalogEvent.Always, AnalogData.Absolute, FeatherMove));
            flightControlsGamePad.AddBinding(new GamePadTriggerBinding("Fire", Trigger.Right, AnalogEvent.Always, AnalogData.Absolute, FeatherFireAnalog));

            ic.AddMap(flightControlsGamePad);


            return(ic);
        }
Beispiel #2
0
 public void RestoreFromJSON(JSONNode mapsJSON)
 {
     foreach (JSONNode mapJSON in mapsJSON.AsArray)
     {
         var map = new AnalogMap();
         map.RestoreFromJSON(mapJSON);
         maps.Add(map);
     }
     onChanged.Invoke();
 }
Beispiel #3
0
    private void SaveAnalogMap(ICommandInvoker commandInvoker, KeyChord binding, AnalogMap map)
    {
        var previousMap = analogMapManager.maps.FirstOrDefault(m => m.commandName == commandInvoker.commandName);

        if (previousMap != null)
        {
            remoteCommandsManager.UpdateValue(previousMap.commandName, 0);
            analogMapManager.maps.Remove(previousMap);
        }

        var conflictMap = analogMapManager.maps.FirstOrDefault(m => m.chord.Equals(binding) && m.axisName == map.axisName && m.leftChord.Equals(map.leftChord) && m.rightChord.Equals(map.rightChord));

        if (conflictMap != null)
        {
            remoteCommandsManager.UpdateValue(conflictMap.commandName, 0);
            analogMapManager.maps.Remove(conflictMap);
            var conflictRow = _rowGroups.SelectMany(g => g).FirstOrDefault(r => r.commandName == conflictMap.commandName);
            if (conflictRow != null)
            {
                if (conflictMap.slot == 0)
                {
                    conflictRow.bindingBtn1.label = _notBoundButtonLabel;
                }
                else if (conflictMap.slot == 0)
                {
                    conflictRow.bindingBtn2.label = _notBoundButtonLabel;
                }
                else
                {
                    throw new InvalidOperationException("Unknown slot " + conflictMap.slot);
                }
            }

            SuperController.LogMessage($"Keybindings: Reassigned binding from {conflictMap.commandName} to {commandInvoker.commandName}");
        }

        analogMapManager.maps.Add(map);
    }
Beispiel #4
0
    private IEnumerator RecordAnalog(UIDynamicButton btn, ICommandInvoker commandInvoker, Color btnColor, int slot)
    {
        isRecording = true;
        var leftKeybinding = KeyChord.empty;

        while (true)
        {
            yield return(0);

            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                continue;
            }

            if (Input.GetKeyUp(KeyCode.Mouse0))
            {
                var mapped = analogMapManager.GetMapByName(commandInvoker.commandName, slot);
                if (mapped != null)
                {
                    analogMapManager.maps.Remove(mapped);
                }
                break;
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                break;
            }

            var ctrlDown  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
            var altDown   = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);
            var shiftDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

            var keyUp = KeyCodes.bindableKeyCodes.GetCurrentUp();

            if (keyUp != KeyCode.None)
            {
                if (!KeyChord.IsValid(keyUp))
                {
                    continue;
                }

                var binding = new KeyChord(keyUp, ctrlDown, altDown, shiftDown);
                if (leftKeybinding.key == KeyCode.None)
                {
                    btn.label      = "Type other direction...";
                    leftKeybinding = binding;
                    continue;
                }
                else if (keyUp == leftKeybinding.key)
                {
                    continue;
                }

                var map = new AnalogMap(leftKeybinding, binding, commandInvoker.commandName, slot);
                SaveAnalogMap(commandInvoker, binding, map);
                StopRecording(btn, btnColor, commandInvoker, slot);
                yield break;
            }

            foreach (var axisName in _knownAxisNames)
            {
                var axisValue = AnalogMap.GetAxis(axisName);
                if (Mathf.Abs(axisValue) < 0.75f)
                {
                    continue;
                }
                var key = KeyCodes.bindableKeyCodes.GetCurrent();
                // We don't want to take over the mouse!
                if (axisName.StartsWith("Mouse") && key == KeyCode.None && !ctrlDown && !shiftDown && !altDown)
                {
                    continue;
                }
                var binding = new KeyChord(key, ctrlDown, altDown, shiftDown);
                var map     = new AnalogMap(binding, axisName, axisValue < 0, commandInvoker.commandName, slot);

                SaveAnalogMap(commandInvoker, binding, map);
                StopRecording(btn, btnColor, commandInvoker, slot);
                yield break;
            }
        }

        StopRecording(btn, btnColor, commandInvoker, slot);
    }