internal override bool OnUpdate() { double value = 0; if (BoundAxis != null) { value = BoundAxis.GetValue(0); } else if (PositiveButton != null) { if (BoundInput == BoundInputTypes.Hat) { Joystick.Hat hat = PositiveButton as Joystick.Hat; if (HatVertAxis) { if (hat.OrdinalIsPressed(Joystick.Hat.Ordinals.North) || hat.OrdinalIsPressed(Joystick.Hat.Ordinals.NorthEast) || hat.OrdinalIsPressed(Joystick.Hat.Ordinals.NorthWest)) { value = 1; } else if (hat.OrdinalIsPressed(Joystick.Hat.Ordinals.South) || hat.OrdinalIsPressed(Joystick.Hat.Ordinals.SouthEast) || hat.OrdinalIsPressed(Joystick.Hat.Ordinals.SouthWest)) { value = -1; } } else { if (hat.OrdinalIsPressed(Joystick.Hat.Ordinals.East) || hat.OrdinalIsPressed(Joystick.Hat.Ordinals.NorthEast) || hat.OrdinalIsPressed(Joystick.Hat.Ordinals.SouthEast)) { value = 1; } else if (hat.OrdinalIsPressed(Joystick.Hat.Ordinals.West) || hat.OrdinalIsPressed(Joystick.Hat.Ordinals.SouthWest) || hat.OrdinalIsPressed(Joystick.Hat.Ordinals.NorthWest)) { value = -1; } } } else { value = PositiveButton.GetValue(PositiveIndex); if (NegativeButton != null) { value = PositiveButton.GetValue(NegativeIndex) > 0 ? (value > 0 ? 0 : -1) : value; } } } if (Sign == AxisSignTypes.Unsigned) { value = (value + 1.0) * 0.5; if (Inversion == InverseTypes.Inverted) { value = 1.0 - value; } if (value < 0) { value = 0; } if (value > 1) { value = 1; } } if (Negation == NegationTypes.Negated) { value = -1 * value; } bool changed = value != LastValue; LastValue = value; return(changed); }
private static void ControlMapSetter_ControllChanged(object sender, Device.Control e) { if (Done || CommandToTest == null) { return; } Joystick stick = sender as Joystick; if (stick == null) { return; } ControlMapping.Command.Input iInput = null; if (CommandToTest as ControlMapping.Axis != null) { ControlMapping.Axis.AxisInput aInput = new ControlMapping.Axis.AxisInput(); if (InputToUpdate != null && InputToUpdate as ControlMapping.Axis.AxisInput != null) { aInput = InputToUpdate as ControlMapping.Axis.AxisInput; } if (e as Joystick.Axis != null) { aInput.DeviceName = stick.DeviceName; aInput.DeviceGUID = stick.GUID; aInput.BoundInputName = e.Name; } else if (e as Joystick.Button != null) { aInput.DeviceName = stick.DeviceName; aInput.DeviceGUID = stick.GUID; if (SetPositiveKeyAxis) { if (aInput.BoundInputName.Contains(":")) { aInput.BoundInputName = e.Name + ":" + aInput.BoundInputName.Substring(aInput.BoundInputName.IndexOf(':') + 1); } else { aInput.BoundInputName = e.Name; } } else { if (aInput.BoundInputName.Contains(":")) { aInput.BoundInputName = aInput.BoundInputName.Substring(0, aInput.BoundInputName.IndexOf(':') - 1); } aInput.BoundInputName = aInput.BoundInputName + ":" + e.Name; } } else if (e as Joystick.Hat != null) { aInput.DeviceName = stick.DeviceName; aInput.DeviceGUID = stick.GUID; aInput.BoundInputName = e.Name; Joystick.Hat hat = e as Joystick.Hat; if (hat.OrdinalIsPressed(Joystick.Hat.Ordinals.North) || hat.OrdinalIsPressed(Joystick.Hat.Ordinals.South)) { aInput.BoundInputName += ":V"; } else { aInput.BoundInputName += ":H"; } } iInput = aInput; } else if (CommandToTest as ControlMapping.Button != null) { ControlMapping.Button.ButtonInput bInput = new ControlMapping.Button.ButtonInput(); if (InputToUpdate != null && InputToUpdate as ControlMapping.Button.ButtonInput != null) { bInput = InputToUpdate as ControlMapping.Button.ButtonInput; } bInput.DeviceName = stick.DeviceName; bInput.DeviceGUID = stick.GUID; bInput.BoundInputName = e.Name; bInput.TriggerValue = e.GetValue(0) > 0 ? 1 : -1; if (e as Joystick.Hat != null) { bInput.TriggerValue = e.GetValue(0); } iInput = bInput; } if (AddInput && iInput != null) { CommandToTest.Inputs.Add(iInput); } Done = true; }