Exemplo n.º 1
0
    void KeyboardAction(InputEventKey key)
    {
        Vector2 input_movement_vector = new Vector2();
        Vector3 Direction             = new Vector3();

        switch (key.Scancode)
        {
        case (int)KeyList.W:
        case (int)KeyList.Up:
            input_movement_vector.y -= 1;
            break;

        case (int)KeyList.S:
        case (int)KeyList.Down:
            input_movement_vector.y += 1;
            break;

        case (int)KeyList.A:
        case (int)KeyList.Left:
            input_movement_vector.x -= 1;
            break;

        case (int)KeyList.D:
        case (int)KeyList.Right:
            input_movement_vector.x += 1;
            break;
        }
        Direction  = GlobalTransform.basis.z.Normalized() * input_movement_vector.y;
        Direction += GlobalTransform.basis.x.Normalized() * input_movement_vector.x * 2;
        AddGlobalOrigin(Direction);
    }
 public override void _UnhandledKeyInput(InputEventKey @event)
 {
     if (Input.IsKeyPressed((int)KeyList.Space))
     {
         GenerateGalaxy();
     }
 }
Exemplo n.º 3
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);
                }
            }
        }
    }
Exemplo n.º 4
0
    public void DoCameraZoom(Player instance, InputEventKey emb)
    {
        if (currentZoom == null)
        {
            currentZoom = new Vector2();
        }

        if (emb.IsPressed())
        {
            if (emb.Scancode == Keybinds.KEYBIND_ZOOM_IN)
            {
                if (zoomVal > instance.MinZoom)
                {
                    currentZoom.x = instance.camera.Translation.z + instance.ZoomSpeed;
                    currentZoom.y = instance.camera.Translation.y - 0.05f;
                    zoomVal      -= instance.ZoomSpeed;
                    UpdateCameraZoom(instance);
                }
            }
            else if (emb.Scancode == Keybinds.KEYBIND_ZOOM_OUT)
            {
                if (zoomVal < instance.MaxZoom)
                {
                    currentZoom.x = instance.camera.Translation.z - instance.ZoomSpeed;
                    currentZoom.y = instance.camera.Translation.y + 0.05f;
                    zoomVal      += instance.ZoomSpeed;
                    UpdateCameraZoom(instance);
                }
            }
        }
    }
Exemplo n.º 5
0
    public static void CheckAndAddAction(string action, KeyList key, bool ctrl = false, bool alt = false, bool shift = false, bool cmd = false)
    {
        if (!InputMap.HasAction(action))
        {
            //Tell user that input was added
            string message = action + " not found in Input Map. Action was added and set to ";
            if (ctrl || alt || shift || cmd)
            {
                message += (ctrl ? "ctrl + " : "") + (alt ? "alt + " : "") + (shift ? "shift + " : "") + (cmd ? "cmd + " : "");
            }
            message += key.ToString();
            GD.Print(message);

            //Add the action
            InputMap.AddAction(action);

            //Create the event
            InputEventWithModifiers inputEventWithModifiers = new InputEventKey
            {
                Scancode = (uint)key
            };
            inputEventWithModifiers.Control = ctrl;
            inputEventWithModifiers.Alt     = alt;
            inputEventWithModifiers.Shift   = shift;
            inputEventWithModifiers.Command = cmd;

            //Add event to action
            InputMap.ActionAddEvent(action, inputEventWithModifiers);
        }
    }
Exemplo n.º 6
0
 internal InputKeyThrottleAxis(string a_eventKeyName,
                               InputEventKey a_positive,
                               InputEventKey a_negative,
                               float a_gravity     = 0f,
                               float a_sensitivity = 2f) : base(a_eventKeyName, a_positive, a_negative, a_gravity, a_sensitivity)
 {
 }
Exemplo n.º 7
0
 public override void _UnhandledKeyInput(InputEventKey @event)
 {
     if (@event.IsActionPressed("ui_do_less"))
     {
         OnButtonPressed();
     }
 }
Exemplo n.º 8
0
        public override void _Ready()
        {
            GetPopup().AddCheckItem("Show Inspector");
            GetPopup().AddCheckItem("Show Binder");
            GetPopup().AddCheckItem("Show Dock");
            GetPopup().AddCheckItem("Big Icons");

            Array         inspectorActionList = InputMap.GetActionList("inspector_toggle");
            InputEventKey inspectorKey        = (InputEventKey)inspectorActionList[0];

            GetPopup().SetItemAccelerator(0, inspectorKey.GetScancodeWithModifiers());

            Array         binderActionList = InputMap.GetActionList("binder_toggle");
            InputEventKey binderKey        = (InputEventKey)binderActionList[0];

            GetPopup().SetItemAccelerator(1, binderKey.GetScancodeWithModifiers());

            Array         dockActionList = InputMap.GetActionList("dock_toggle");
            InputEventKey dockKey        = (InputEventKey)dockActionList[0];

            GetPopup().SetItemAccelerator(2, dockKey.GetScancodeWithModifiers());

            GetPopup().Connect("index_pressed", this, nameof(OnItemPressed));

            CallDeferred(nameof(SetValues));
        }
Exemplo n.º 9
0
    public static InputEventKey GetInputFromKey(Keys key)
    {
        InputEventKey inputEvent = new InputEventKey();

        inputEvent.Scancode = (uint)OS.FindScancodeFromString((string)SettingsData[InputHandler.GetNameFromKey(key)]);
        return(inputEvent);
    }
Exemplo n.º 10
0
        private void LoadInputMapConfiguration(string configPath, string defaultPath)
        {
            ConfigFile configFile = new ConfigFile();
            Directory  directory  = new Directory();
            Dictionary <string, Dictionary <string, object> > config = this.LoadConfig(configPath, defaultPath, configFile, directory);

            foreach (var item in config)
            {
                var action   = item.Key;
                var value    = item.Value;
                var deadzone = value.ContainsKey("deadzone") ? (float)value["deadzone"] : 0.5f;
                var gamepad  = value.ContainsKey("GamePad") ? (int)value["GamePad"] : -1;
                var keyboard = value.ContainsKey("Keyboard") ? value["Keyboard"] as string : "";
                if (action != "" && gamepad != -1 && keyboard != "")
                {
                    if (!InputMap.HasAction(action))
                    {
                        InputMap.AddAction(action);
                    }
                    var inputKey = new InputEventKey();
                    inputKey.Scancode = (uint)OS.FindScancodeFromString(keyboard);
                    InputMap.ActionAddEvent(action, inputKey);
                    var inputjoy = new InputEventJoypadButton();
                    inputjoy.ButtonIndex = gamepad;
                    InputMap.ActionAddEvent(action, inputjoy);
                    InputMap.ActionSetDeadzone(action, deadzone);
                }
            }
        }
Exemplo n.º 11
0
 public override void _UnhandledKeyInput(InputEventKey @event)
 {
     if (@event.Pressed && @event.Scancode == (int)KeyList.Escape)
     {
         _on_BtnReturn_pressed();
     }
 }
Exemplo n.º 12
0
	internal InputEventToggle(string a_eventKeyName, InputEventKey a_input, bool a_state = false) : base(a_eventKeyName)
	{
		_isActive = a_state;
		
		toggleKey = a_input;
		toggleKey.onActivation += OnToggle;
	}
Exemplo n.º 13
0
    public void mimic_esc()
    {
        var e = new InputEventKey();

        e.Scancode = (uint)KeyList.Escape;
        Input.ParseInputEvent(e);
    }
Exemplo n.º 14
0
    internal InputEventToggle(string a_eventKeyName, InputEventKey a_input, bool a_state = false) : base(a_eventKeyName)
    {
        _isActive = a_state;

        toggleKey = a_input;
        toggleKey.onActivation += OnToggle;
    }
Exemplo n.º 15
0
 public override void _UnhandledKeyInput(InputEventKey @event)
 {
     if (@event.IsActionPressed("main_save"))
     {
         GetNode <EditorControls>("..").SaveDiagram();
     }
 }
Exemplo n.º 16
0
 internal InputKeyThrottleAxis(EInputAxisKey a_eventKey,
                               InputEventKey a_positive,
                               InputEventKey a_negative,
                               float a_gravity     = 0f,
                               float a_sensitivity = 2f) : this(a_eventKey.ToString(), a_positive, a_negative, a_gravity, a_sensitivity)
 {
 }
Exemplo n.º 17
0
    public static void SetActionFromString(string key, string code)
    {
        InputEventKey inputEvent = new InputEventKey();

        inputEvent.Scancode = (uint)OS.FindScancodeFromString(code);
        SetActionFromInput(key, inputEvent);
    }
Exemplo n.º 18
0
	internal InputKeyAxis(EInputAxisKey a_eventKey, 
	                      InputEventKey a_positive,
	                      InputEventKey a_negative,
                          float a_gravity = 0f,
                  		  float a_sensitivity = 2f) : this(a_eventKey.ToString(), a_positive, a_negative, a_gravity, a_sensitivity)
	{
	}
Exemplo n.º 19
0
	internal InputKeyThrottleAxis(string a_eventKeyName, 
	                              InputEventKey a_positive,
	                              InputEventKey a_negative,
	                              float a_gravity = 0f,
	                              float a_sensitivity = 2f) : base(a_eventKeyName, a_positive, a_negative, a_gravity, a_sensitivity)
	{
	}
Exemplo n.º 20
0
    private static void applyKey(string action_name, string key)
    {
        int scancode = OS.FindScancodeFromString(key);
        var e        = new InputEventKey();

        e.Scancode = (uint)scancode;
        InputMap.ActionAddEvent(action_name, e);
    }
Exemplo n.º 21
0
    public void UpdatingKeyConfig()
    {
        InputEventKey updatedKey = SettingsOptions.GetInputFromKey(input);

        InputHandler.SetActionFromInput(InputHandler.GetNameFromKey(input), updatedKey);
        button.Text  = OS.GetScancodeString(updatedKey.Scancode);
        previousText = button.Text;
    }
Exemplo n.º 22
0
 public override void _UnhandledKeyInput(InputEventKey @event)
 {
     if (@event.IsActionPressed("ui_cancel", true))
     {
         OnCloseButtonPressed();
         return;
     }
 }
Exemplo n.º 23
0
    public static string GetScanCode(string key)
    {
        string        holder   = "";
        InputEventKey eventKey = (InputEventKey)InputMap.GetActionList(key)[0];

        holder = OS.GetScancodeString(eventKey.Scancode);
        return(holder);
    }
Exemplo n.º 24
0
 public static void UpdateKeyData(Keys name, InputEventKey key)
 {
     if (SettingsData == null)
     {
         UpdateDataFromSource();
     }
     NewSettings[InputHandler.GetNameFromKey(name)] = OS.GetScancodeString(key.Scancode);
 }
Exemplo n.º 25
0
    public override void _UnhandledKeyInput(InputEventKey @event)
    {
        if (AcceptInput)
        {
            System.Console.WriteLine(@event.Scancode == (int)'K');
        }

        AcceptInput = !AcceptInput;
    }
 public override void _UnhandledKeyInput(InputEventKey key)
 {
     if (Pressed && key.IsActionPressed("main_remove"))
     {
         OnItemSelected(0);
         Pressed = false;
         ReleaseFocus();
         GetPopup().Visible = false;
     }
 }
Exemplo n.º 27
0
    protected virtual void Awake()
    {
        Debug.Log(name + " : " + key.ToString());
        keycodebutton.callback     += ModifyKeyCode;
        triggerModeButton.callback += ToggleActivationMode;

        _inputKey = new InputEventKey(key, binding);

        UpdateDisplay();
    }
Exemplo n.º 28
0
    internal InputEventSwitch(string a_eventKeyName, InputEventKey a_inputOn, InputEventKey a_inputOff, bool a_state = false) : base(a_eventKeyName)
    {
        _isActive = a_state;

        toggleOn = a_inputOn;
        toggleOn.onActivation += OnToggleOn;

        toggleOff = a_inputOff;
        toggleOff.onActivation += OnToggleOff;
    }
Exemplo n.º 29
0
	internal InputEventSwitch(string a_eventKeyName, InputEventKey a_inputOn, InputEventKey a_inputOff, bool a_state = false) : base(a_eventKeyName)
	{
		_isActive = a_state;
		
		toggleOn = a_inputOn;
		toggleOn.onActivation += OnToggleOn;
		
		toggleOff = a_inputOff;
		toggleOff.onActivation += OnToggleOff;
	}
Exemplo n.º 30
0
 public override void _UnhandledKeyInput(InputEventKey @event)
 {
     if (@event.IsActionPressed("Inventory"))
     {
         HandleInventory();
     }
     else if (@event.IsActionPressed("Back"))
     {
         HandleBack();
     }
 }
Exemplo n.º 31
0
	protected virtual void Awake ()
	{
		keycodebutton.callback += ModifyKeyCode;
		triggerModeButton.callback += ToggleActivationMode;
		
		_inputKey = new InputEventKey(key,binding);
		
		//FFEngine.Inputs.Register(_inputKey);
		
		UpdateDisplay();
	}
Exemplo n.º 32
0
    /// <summary> Bind a key to fire an action. </summary>
    public static void BindKey(KeyList key, string actionName)
    {
        InputEventKey inputEvent = new InputEventKey();

        inputEvent.Scancode = (uint)key;
        if (!InputMap.HasAction(actionName))
        {
            InputMap.AddAction(actionName);
        }
        InputMap.ActionAddEvent(actionName, inputEvent);
    }
Exemplo n.º 33
0
    private void HandleInput(InputEventKey inputEventKey)
    {
        if (inputEventKey != null && inputEventKey.Pressed)
        {
            uint scancode = inputEventKey.Scancode;

            if (scancode == (uint)KeyList.End)
            {
                GetTree().Paused = !GetTree().Paused;
            }
        }
    }
Exemplo n.º 34
0
 public override void _UnhandledKeyInput(InputEventKey @event)
 {
     // I don't like iterating over every single possible action every time - surely there's a nicer way to do this?
     foreach (string mapping in ActionMapping.AllMappings)
     {
         if (@event.IsActionPressed(mapping, true) && _playerMappingQueue.Count < _queueSize)
         {
             _playerMappingQueue.Add(new InputAction(mapping));
             return;
         }
     }
 }
Exemplo n.º 35
0
    private void HandleExit(InputEventKey inputEventKey)
    {
        if (inputEventKey != null && inputEventKey.Pressed)
        {
            uint keycode = inputEventKey.Scancode;

            if ((uint)KeyList.Escape == keycode)
            {
                ShowScreen(false);
            }
        }
    }
Exemplo n.º 36
0
	internal InputKeyAxis(string a_eventKeyName, 
	                      InputEventKey a_positive,
	                      InputEventKey a_negative,
	                      float a_gravity = 0f,
	                      float a_sensitivity = 2f) : base(a_eventKeyName)
	{
		_sensitibity = a_sensitivity;
		_currentValue = 0f;
		_gravity = a_gravity;
		
		inputPositive = a_positive;
		if(inputPositive != null)
		{
			inputPositive.onActivation += Increase;
		}
		
		inputNegative = a_negative;
		if(inputNegative != null)
		{
			inputNegative.onActivation += Decrease;
		}
	}
Exemplo n.º 37
0
	internal InputEventSwitch(EInputEventKey a_eventKey, InputEventKey a_inputOn, InputEventKey a_inputOff, bool a_state = false) : this(a_eventKey.ToString(), a_inputOn, a_inputOff, a_state)
	{
	}
Exemplo n.º 38
0
	internal InputEventToggle(EInputEventKey a_eventKey, InputEventKey a_input, bool a_state = false) : this(a_eventKey.ToString(), a_input, a_state)
	{
	}