Ejemplo n.º 1
0
    public void ScrambleControls()
    {
        // Add rotate inputs to the scramble if the player has unlocked it.
        if (PlayerEvolution > 3 && !_actions.Contains("rotate_left") && !_actions.Contains("rotate_right"))
        {
            _actions.Add("rotate_left");
            _actions.Add("rotate_right");
        }

        var activeInputs = new ArrayList();

        foreach (string action in _actions)
        {
            activeInputs.Add(InputMap.GetActionList(action)[0]);
            InputMap.ActionEraseEvents(action);
        }

        // Randomly assign inputs to said events.
        var random = new Random();

        foreach (string action in _actions)
        {
            int index = random.Next(activeInputs.Count);
            InputMap.ActionAddEvent(action, (InputEvent)activeInputs[index]);
            activeInputs.RemoveAt(index);
        }
    }
Ejemplo n.º 2
0
    private void AddKeyboardInputsToGameMapping()
    {
        string        playerPrefix;
        string        action;
        InputEventKey iek;

        SC.IDictionaryEnumerator it;
        Dictionary mapping;

        for (int i = 1; i <= playerAmount; i++)
        {
            playerPrefix = this.CreateString("p", i, "_");
            mapping      = keyboardInputMapping[i.ToString()] as Dictionary;

            if (mapping != null)
            {
                it = mapping.GetEnumerator();

                while (it.MoveNext())
                {
                    action = this.CreateString(playerPrefix, it.Entry.Key);
                    InputMap.ActionEraseEvents(action);
                    iek          = new InputEventKey();
                    iek.Scancode = uint.Parse(it.Entry.Value as string);
                    InputMap.ActionAddEvent(action, iek);
                }
            }
        }
    }
Ejemplo n.º 3
0
 private static void applyAction(string name)
 {
     // Clear the action
     InputMap.ActionEraseEvents(name);
     applyInput(name, name + "0");
     applyInput(name, name + "1");
 }
 private void EmptyInputMap()
 {
     InputMap.ActionEraseEvents("Move-Left");
     InputMap.ActionEraseEvents("Move-Right");
     InputMap.ActionEraseEvents("Jump");
     InputMap.ActionEraseEvents("Action");
     InputMap.ActionEraseEvents("Pause");
     InputMap.ActionEraseEvents("Okay");
 }
Ejemplo n.º 5
0
        public void SetInputMap()
        {
            var actions = Enum.GetValues(typeof(ActionType)).Cast <ActionType>();

            foreach (var action in actions)
            {
                var name = action.ToString();
                InputMap.ActionEraseEvents(name);
                foreach (var bind in Settings.ActionControls[action])
                {
                    var inputEvent = bind.ToInputEvent();
                    InputMap.ActionAddEvent(name, inputEvent);
                }
            }
        }
Ejemplo n.º 6
0
 private void on_add_input_map()
 {
     if (GamePad == null && Keyboard == null && action == "")
     {
         return;
     }
     GD.Print("add");
     if (!InputMap.HasAction(action))
     {
         InputMap.AddAction(action, deadzone);
     }
     InputMap.ActionEraseEvents(action);
     InputMap.ActionAddEvent(action, GamePad);
     InputMap.ActionAddEvent(action, Keyboard);
 }
Ejemplo n.º 7
0
    /// <summary>
    ///   Applies the current controls (from Data) to the global InputMap.
    /// </summary>
    internal void ApplyToGodotInputMap()
    {
        foreach (var action in Data)
        {
            // Clear all old input keys
            InputMap.ActionEraseEvents(action.Key);

            // Register the new input keys
            foreach (var inputEvent in action.Value)
            {
                // If the game is waiting for an input for this thing, skip trying to apply it
                if (inputEvent == null)
                    return;

                InputMap.ActionAddEvent(action.Key, inputEvent.ToInputEvent());
            }
        }

        InputsRemapped?.Invoke(this, EventArgs.Empty);
    }