Esempio n. 1
0
 public override void _UnhandledInput(InputEvent @event)
 {
     if (@event is InputEventKey && @event.IsPressed())
     {
         current.handleKey(@event.AsText()[0]);
         GD.Print(@event.AsText()[0]);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Called when an input event happens
        /// </summary>
        /// <param name="Event">The event</param>
        public void OnInputEvent(InputEvent Event)
        {
            MDInputType OldInputType = LastInputType;

            switch (Event)
            {
            case InputEventKey _:
            case InputEventMouse _:
                LastInputType = MDInputType.MouseAndKeyboard;
                break;

            case InputEventJoypadButton _:
            case InputEventJoypadMotion _:
                LastInputType = MDInputType.JoyPad;
                break;

            case InputEventScreenTouch _:
            case InputEventGesture _:
                LastInputType = MDInputType.Touch;
                break;

            default:
                MDLog.Warn(LOG_CAT, $"Unknown Input Event Type: {Event.AsText()}");
                break;
            }

            if (OldInputType != LastInputType)
            {
                OnInputTypeChanged(OldInputType, LastInputType);
            }
        }
Esempio n. 3
0
    public void _OnGuiInput(InputEvent ev)
    {
        GD.Print($"GUI input event {team} {spec.Text()} card {ev.AsText()}");

        if (ev is InputEventMouseButton butt)
        {
            if (butt.IsPressed())
            {
                dragOrigin = RectPosition;
            }
            else
            {
                if (dragOrigin != null)
                {
                    dragOrigin = null;
                }
            }
        }

        if (ev is InputEventMouseMotion motion)
        {
            if (dragOrigin != null)
            {
                RectPosition += motion.Relative;
            }
        }
    }
Esempio n. 4
0
    public static int GetAlphaOrSpaceJustPressed(this InputEvent e)
    {
        var key = e.GetKeyJustPressed();

        if ((key >= 65 && key <= 90) || key == 32)
        {
            GD.Print(key + "--" + e.AsText());
            return(key);
        }
        else
        {
            return(-1);
        }
    }
Esempio n. 5
0
        public static string ConvertButtonText(InputEvent @event)
        {
            if (@event is InputEventMouseButton mouseButton)
            {
                switch (mouseButton.ButtonIndex)
                {
                case 4: return("Wheel Up");

                case 5: return("Wheel Down");

                case 8: return("Mouse Button 1");

                case 9: return("Mouse Button 2");

                case var index:
                    return(((ButtonList)index).ToString() + " Click");
                }
            }

            var text = @event.AsText();

            switch (text)
            {
            case "QuoteLeft": return("`");

            case "Minus": return("-");

            case "Equal": return("=");

            case "Slash": return("/");

            case "Period": return(".");

            case "Comma": return(",");

            case "BracketLeft": return("[");

            case "BracketRight": return("]");

            case "BackSlash": return("\\");
            }

            if (text.StartsWith("Kp", StringComparison.Ordinal))
            {
                text = "NumPad" + text.Substring(2);
            }
            return(text.SpaceCapitals((c, i) => text[i - 1] != '+'));
        }
 // Deprecated for now, use AsText() instead
 //
 public static string AsPrettyText(this InputEvent _event)
 {
     if (_event is InputEventKey)
     {
         return(_event.AsText());
     }
     else if (_event is InputEventMouseButton)
     {
         return("Mouse button " + (_event as InputEventMouseButton).ButtonIndex);
     }
     else if (_event is InputEventJoypadButton)
     {
         return("Gamepad button " + (_event as InputEventJoypadButton).ButtonIndex);
     }
     else if (_event is InputEventJoypadMotion)
     {
         return("Gamepad axis " + (_event as InputEventJoypadMotion).Axis + " " + (((_event as InputEventJoypadMotion).AxisValue > 0) ? "+" : "-"));
     }
     else
     {
         return("Input not recognized");
     }
 }
    public override void _Input(InputEvent e)
    {
        if (e is InputEventKey eventKey)
        {
            if (_right.Pressed)
            {
                if (DoubleCheck(OS.FindScancodeFromString(e.AsText())))
                {
                    _right.Text    = e.AsText();
                    _rKey          = eventKey;
                    _right.Pressed = false;
                    return;
                }

                _right.Text    = OS.GetScancodeString((uint)_rValue);
                _right.Pressed = false;
                return;
            }
            else if (_left.Pressed)
            {
                if (DoubleCheck(OS.FindScancodeFromString(e.AsText())))
                {
                    _left.Text    = e.AsText();
                    _lKey         = eventKey;
                    _left.Pressed = false;
                    return;
                }

                _left.Text    = OS.GetScancodeString((uint)_lValue);
                _left.Pressed = false;
                return;
            }
            else if (_jump.Pressed)
            {
                if (DoubleCheck(OS.FindScancodeFromString(e.AsText())))
                {
                    _jump.Text    = e.AsText();
                    _jKey         = eventKey;
                    _jump.Pressed = false;
                    return;
                }

                _jump.Text    = OS.GetScancodeString((uint)_jValue);
                _jump.Pressed = false;
                return;
            }
            else if (_action.Pressed)
            {
                if (DoubleCheck(OS.FindScancodeFromString(e.AsText())))
                {
                    _action.Text    = e.AsText();
                    _aKey           = eventKey;
                    _action.Pressed = false;
                    return;
                }

                _action.Text    = OS.GetScancodeString((uint)_aValue);
                _action.Pressed = false;
                return;
            }
            else if (_pause.Pressed)
            {
                if (DoubleCheck(OS.FindScancodeFromString(e.AsText())))
                {
                    _pause.Text    = e.AsText();
                    _pKey          = eventKey;
                    _pause.Pressed = false;
                    return;
                }

                _pause.Text    = OS.GetScancodeString((uint)_pValue);
                _pause.Pressed = false;
                return;
            }
            else if (_okay.Pressed)
            {
                if (DoubleCheck(OS.FindScancodeFromString(e.AsText())))
                {
                    _okay.Text    = e.AsText();
                    _oKey         = eventKey;
                    _okay.Pressed = false;
                    return;
                }

                _okay.Text    = OS.GetScancodeString((uint)_oValue);
                _okay.Pressed = false;
                return;
            }
        }
        return;
    }
Esempio n. 8
0
 private string GetKey(int keyCode, InputEvent e)
 {
     return(keyCode == (int)KeyList.Space ? " " : e.AsText());
 }