private void ProcessJump(FullInputData data, vec2 flatDirection)
        {
            // If this is true, it's assumed that the jump bind must have been populated. Note that this behavior (jump
            // limiting) applies to multiple kinds of jumps (including regular jumps, breaking ascends, wall jumps, and
            // maybe more).
            if ((player.State & PlayerStates.Jumping) > 0)
            {
                if (data.Query(jumpBindUsed, InputStates.ReleasedThisFrame) &&
                    player.ControllingBody.LinearVelocity.Y > playerData.JumpLimit)
                {
                    player.LimitJump();
                    jumpBindUsed = null;
                }

                return;
            }

            // This also accounts for jump being unlocked.
            if (player.JumpsRemaining == 0)
            {
                return;
            }

            if (data.Query(controls.Jump, InputStates.PressedThisFrame, out var bind))
            {
                player.Jump(flatDirection);
                jumpBindUsed = bind;
            }
        }
        public static InputEvent ToInputEvent(this InputBind inputBind)
        {
            if (inputBind.EventType == InputEventType.InputEventKey)
            {
                return(new InputEventKey
                {
                    Scancode = (uint)inputBind.Index
                });
            }

            if (inputBind.EventType == InputEventType.InputEventJoypadButton)
            {
                return(new InputEventJoypadButton
                {
                    Device = inputBind.Device,
                    ButtonIndex = inputBind.Index
                });
            }

            if (inputBind.EventType == InputEventType.InputEventJoypadMotion)
            {
                return(new InputEventJoypadMotion
                {
                    Device = inputBind.Device,
                    Axis = inputBind.Axis,
                    AxisValue = inputBind.AxisValue
                });
            }

            return(null);
        }
Exemple #3
0
 public static void Bind(string name, Key[] keys, MouseButton[] mbtns)
 {
     if (Binds.ContainsKey(name))
     {
         Binds[name] = new InputBind(keys, mbtns);
     }
     else
     {
         Binds.Add(name, new InputBind(keys, mbtns));
     }
 }
        /*
         * private void ProcessGrab(FullInputData data, float dt)
         * {
         *      // TODO: Player actions (in relation to state) will likely need to be refined. In this case, could other states prevent grabbing?
         *      if (player.State != PlayerStates.Grabbing)
         *      {
         *              if (grabBuffer.Refresh(data, dt, out grabBindUsed))
         *              {
         *                      player.TryGrab();
         *              }
         *
         *              return;
         *      }
         *
         *      // Ladders are special among grabbable objects in that a toggle is always used to attach or detach from the
         *      // ladder (regardless of control settings). I've never played a game where you have to hold a button to
         *      // remain on a ladder.
         *      bool shouldRelease = settings.UseToggleGrab || player.IsOnLadder
         *              ? data.Query(controls.Grab, InputStates.ReleasedThisFrame)
         *              : data.Query(grabBindUsed, InputStates.ReleasedThisFrame);
         *
         *      if (shouldRelease)
         *      {
         *              player.ReleaseGrab();
         *      }
         * }
         */

        private bool ProcessWallJump(FullInputData data)
        {
            if (player.IsWallJumpAvailable && data.Query(controls.Jump, InputStates.PressedThisFrame,
                                                         out var bind))
            {
                player.WallJump();
                jumpBindUsed = bind;

                return(true);
            }

            return(false);
        }
Exemple #5
0
        public void NewBind(ActionType action, InputBind bind)
        {
            var eventNode = (HBoxContainer)_controlBind.Instance();

            var parent = _actionNodes[action];

            parent.AddChild(eventNode);

            var bindName = (Label)eventNode.FindNode("Name");

            var remove = (Button)eventNode.FindNode("RemoveAction");

            bindName.Text = GetInputEventName(bind);
            remove.Connect("pressed", this, "RemoveControl", new Array {
                action, bind, eventNode
            });
            _guiBrain.EmitSignal("NewScrollContainerButton", eventNode);
        }
        private void ProcessAttack(FullInputData data, float dt)
        {
            var weapon = player.Weapon;

            if (attackBindUsed != null)
            {
                if (data.Query(attackBindUsed, InputStates.ReleasedThisFrame))
                {
                    weapon.ReleasePrimary();
                    attackBindUsed = null;
                }

                return;
            }

            // TODO: Process weapon cooldown as needed.
            if (attackBuffer.Refresh(data, dt, out var bind))
            {
                attackBindUsed = bind;
                activeAttack   = weapon.TriggerPrimary();
            }
        }
        public void AddBind(string action, KeyId id)
        {
            var binds = GetBinds(id);

            if (binds == null)
            {
                binds = new List <InputBind>();
            }


            if (DoesBindExist(id, action) == false)
            {
                var newBind = new InputBind(id, action);
                binds.Add(newBind);
                _bindedActions.Add(PrefixActionCache(id, action));
            }
            else
            {
                Debug.Log("Bind already exists " + action + " - " + id);
            }

            _inputBinds[id] = binds;
        }
Exemple #8
0
        public string GetInputEventName(InputBind bind)
        {
            var text = "";

            if (bind.EventType == InputEventType.InputEventKey)
            {
                text = "Keyboard: " + OS.GetScancodeString((uint)bind.Index);
            }
            else if (bind.EventType == InputEventType.InputEventJoypadButton)
            {
                text = "Gamepad: ";

                if (Input.IsJoyKnown(bind.Device))
                {
                    text += Input.GetJoyButtonString(bind.Index);
                }
                else
                {
                    text += $"Btn. {bind.Index.ToString()}";
                }
            }
            else if (bind.EventType == InputEventType.InputEventJoypadMotion)
            {
                text = "Gamepad: ";
                if (Input.IsJoyKnown(bind.Device))
                {
                    text += $"{Input.GetJoyAxisString(bind.Axis)} ";
                }
                else
                {
                    text += $"Axis: {bind.Axis} ";
                }
                text += Mathf.Round(bind.AxisValue);
            }
            return(text);
        }
 public void NullifyJumpBind()
 {
     jumpBindUsed = null;
 }