/// <summary> /// Validate input keycode against target key sequence /// </summary> /// <param name="Input"></param> /// <param name="TargetInput"></param> /// <returns></returns> public static bool ValidateKeyPress(IOperatorInputMsg Input, string TargetInput) { var eq1 = string.Equals(TargetInput, Input.KeyInfo.KeyChar.ToString(), StringComparison.OrdinalIgnoreCase); var eq2 = eq1 || string.Equals(TargetInput, Input.KeyInfo.Key.ToString(), StringComparison.OrdinalIgnoreCase); var eq3 = eq2 || string.Equals(TargetInput, Input.KeyInfo.Modifiers.ToString(), StringComparison.OrdinalIgnoreCase); return(eq3); }
/// <summary> /// Input extension for <see cref="IOperatorInputModule"/>. Uses early return semantics based on IsHandled flag /// </summary> /// <param name="list"></param> /// <param name="msg"></param> public static void SendInput(this IEnumerable <IOperatorInputModule> list, IOperatorInputMsg msg) { //Pattern: Chain of Responsibility //Pattern: Iterator foreach (var itm in list) { if (msg.IsHandled) { return; } itm.HandleInput(msg); } }
public override void HandleInput(IOperatorInputMsg Input) { if (Input.InputType == KeyInputType.KeyUp) { return; } var keyConfig = _keyBinding.CurrentValue.FireControl; //fire primary if (ValidateKeyPress(Input, keyConfig.Primary)) { _cmdDelegate.FirePrimary(); Input.IsHandled = true; } //fire secondary else if (ValidateKeyPress(Input, keyConfig.Secondary)) { _cmdDelegate.FireSecondary(); Input.IsHandled = true; } }
public override void HandleInput(IOperatorInputMsg Input) { if (Input.InputType == KeyInputType.KeyUp) { return; } var keyConfig = _keyBinding.CurrentValue.GunLoader; //fire primary if (ValidateKeyPress(Input, keyConfig.Load)) { _cmdDelegate.Load(); Input.IsHandled = true; } //fire secondary else if (ValidateKeyPress(Input, keyConfig.CycleAmmo)) { _cmdDelegate.CycleAmmoType(); Input.IsHandled = true; } }
/// <summary> /// Handle input key sequence /// </summary> /// <param name="Input"></param> public abstract void HandleInput(IOperatorInputMsg Input);
public override void HandleInput(IOperatorInputMsg Input) { var keyConfig = _keyBinding.CurrentValue.RangeFinder; //farther if (ValidateKeyPress(Input, keyConfig.Farther)) { if (Input.InputType == KeyInputType.KeyPress) { if (_currDirection == RangeDirection.Farther) { _currDirection = RangeDirection.Stop; _cmdDelegate.Stop(); } else { _currDirection = RangeDirection.Farther; _cmdDelegate.AimFarther(); } } else if (Input.InputType == KeyInputType.KeyDown) { _currDirection = RangeDirection.Farther; _cmdDelegate.AimFarther(); } else { if (_currDirection == RangeDirection.Farther) { _currDirection = RangeDirection.Stop; _cmdDelegate.Stop(); } } Input.IsHandled = true; } //closer else if (ValidateKeyPress(Input, keyConfig.Closer)) { if (Input.InputType == KeyInputType.KeyPress) { if (_currDirection == RangeDirection.Closer) { _currDirection = RangeDirection.Stop; _cmdDelegate.Stop(); } else { _currDirection = RangeDirection.Closer; _cmdDelegate.AimCloser(); } } else if (Input.InputType == KeyInputType.KeyDown) { _currDirection = RangeDirection.Closer; _cmdDelegate.AimCloser(); } else { if (_currDirection == RangeDirection.Closer) { _currDirection = RangeDirection.Stop; _cmdDelegate.Stop(); } } Input.IsHandled = true; } }
public override void HandleInput(IOperatorInputMsg Input) { var keyConfig = _keyBinding.CurrentValue.Driver; //forward if (ValidateKeyPress(Input, keyConfig.Forward)) { if (Input.InputType == KeyInputType.KeyPress) { if (_currDirection == DriveDirection.Forward) { _currDirection = DriveDirection.Stop; _cmdDelegate.Stop(); } else { _currDirection = DriveDirection.Forward; _cmdDelegate.DriveForward(); } } else if (Input.InputType == KeyInputType.KeyDown) { _currDirection = DriveDirection.Forward; _cmdDelegate.DriveForward(); } else { if (_currDirection == DriveDirection.Forward) { _currDirection = DriveDirection.Stop; _cmdDelegate.Stop(); } } Input.IsHandled = true; } //back else if (ValidateKeyPress(Input, keyConfig.Backward)) { if (Input.InputType == KeyInputType.KeyPress) { if (_currDirection == DriveDirection.Backward) { _currDirection = DriveDirection.Stop; _cmdDelegate.Stop(); } else { _currDirection = DriveDirection.Backward; _cmdDelegate.DriveBackward(); } } else if (Input.InputType == KeyInputType.KeyDown) { _currDirection = DriveDirection.Backward; _cmdDelegate.DriveBackward(); } else { if (_currDirection == DriveDirection.Backward) { _currDirection = DriveDirection.Stop; _cmdDelegate.Stop(); } } Input.IsHandled = true; } }
public override void HandleInput(IOperatorInputMsg Input) { var keyConfig = _keyBinding.CurrentValue.GunRotation; //left if (ValidateKeyPress(Input, keyConfig.Left)) { if (Input.InputType == KeyInputType.KeyPress) { if (_currDirection == RotationDirection.Left) { _currDirection = RotationDirection.Stop; _cmdDelegate.Stop(); } else { _currDirection = RotationDirection.Left; _cmdDelegate.TurnLeft(); } } else if (Input.InputType == KeyInputType.KeyDown) { _currDirection = RotationDirection.Left; _cmdDelegate.TurnLeft(); } else { if (_currDirection == RotationDirection.Left) { _currDirection = RotationDirection.Stop; _cmdDelegate.Stop(); } } Input.IsHandled = true; } //right else if (ValidateKeyPress(Input, keyConfig.Right)) { if (Input.InputType == KeyInputType.KeyPress) { if (_currDirection == RotationDirection.Right) { _currDirection = RotationDirection.Stop; _cmdDelegate.Stop(); } else { _currDirection = RotationDirection.Right; _cmdDelegate.TurnRight(); } } else if (Input.InputType == KeyInputType.KeyDown) { _currDirection = RotationDirection.Right; _cmdDelegate.TurnRight(); } else { if (_currDirection == RotationDirection.Right) { _currDirection = RotationDirection.Stop; _cmdDelegate.Stop(); } } Input.IsHandled = true; } }