From 35fccfcd83e180b9c63f53973da3cdfda271b410 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 28 Aug 2019 19:36:24 +0200 Subject: [PATCH] added generic isdown, ispressed and isup methods to InputHandler --- MLEM/Input/InputHandler.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/MLEM/Input/InputHandler.cs b/MLEM/Input/InputHandler.cs index e1639b7..39a7e95 100644 --- a/MLEM/Input/InputHandler.cs +++ b/MLEM/Input/InputHandler.cs @@ -130,6 +130,36 @@ namespace MLEM.Input { return this.WasGamepadButtonUp(index, button) && this.IsGamepadButtonDown(index, button); } + public bool IsDown(object control, int index = 0) { + if (control is Keys key) + return this.IsKeyDown(key); + if (control is Buttons button) + return this.IsGamepadButtonDown(index, button); + if (control is MouseButton mouse) + return this.IsMouseButtonDown(mouse); + throw new ArgumentException(nameof(control)); + } + + public bool IsUp(object control, int index = 0) { + if (control is Keys key) + return this.IsKeyUp(key); + if (control is Buttons button) + return this.IsGamepadButtonUp(index, button); + if (control is MouseButton mouse) + return this.IsMouseButtonUp(mouse); + throw new ArgumentException(nameof(control)); + } + + public bool IsPressed(object control, int index = 0) { + if (control is Keys key) + return this.IsKeyPressed(key); + if (control is Buttons button) + return this.IsGamepadButtonPressed(index, button); + if (control is MouseButton mouse) + return this.IsMouseButtonPressed(mouse); + throw new ArgumentException(nameof(control)); + } + private static ButtonState GetState(MouseState state, MouseButton button) { switch (button) { case MouseButton.Left: