From 1f3108adcdd37ef6bbcf3653bf7ab4067dcde61c Mon Sep 17 00:00:00 2001 From: polten0 Date: Fri, 18 Aug 2023 02:46:59 +0300 Subject: [PATCH] finish1IterOfSwitchingUI --- DangerousD/GameCore/GUI/AbstractGui.cs | 51 ++++++++++--------- .../LivingEntities/Player/Player.cs | 1 + DangerousD/GameCore/InputManager.cs | 1 + MonogameLibrary/UI/Elements/Button.cs | 2 +- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/DangerousD/GameCore/GUI/AbstractGui.cs b/DangerousD/GameCore/GUI/AbstractGui.cs index 6615820..34bea14 100644 --- a/DangerousD/GameCore/GUI/AbstractGui.cs +++ b/DangerousD/GameCore/GUI/AbstractGui.cs @@ -51,24 +51,25 @@ public abstract class AbstractGui : IDrawableObject { string state = AppManager.Instance.InputManager.currentControlsState; + + if (ActiveElements.Count != 0) { - switch (state) + if (state == "Gamepad") { - case "Gamepad": - GamePadState gamePadState = GamePad.GetState(0); - GamepadInput(gamePadState); - break; - case "Keyboard": - KeyboardState keyBoardState = Keyboard.GetState(0); - KeyBoardInput(keyBoardState); - break; - default: - break; + GamePadState gamePadState = GamePad.GetState(0); + GamepadInput(gamePadState); + } + else if (state == "Keyboard" || state == "Mouse") + { + KeyboardState keyBoardState = Keyboard.GetState(); + KeyBoardInput(keyBoardState); } } Manager.Update(); + + (SelectedElement as Button).hoverState = MonogameLibrary.UI.Enums.HoverState.Hovering; } public virtual void Draw(SpriteBatch spriteBatch) @@ -81,6 +82,7 @@ public abstract class AbstractGui : IDrawableObject { isPressed = true; ChangeSelectedElement(-1); + Debug.WriteLine("switch"); } else if (gamePadState.DPad.Down == ButtonState.Pressed && !isPressed) { @@ -89,7 +91,6 @@ public abstract class AbstractGui : IDrawableObject } else if (gamePadState.Buttons.A == ButtonState.Pressed && !isPressed) { - Debug.WriteLine("ssss"); isPressed = true; if (SelectedElement is ButtonText) { @@ -97,7 +98,9 @@ public abstract class AbstractGui : IDrawableObject button.CallLeftBtnEvent(); } } - else if (isPressed) + else if (isPressed && (gamePadState.Buttons.A == ButtonState.Released && + gamePadState.DPad.Down == ButtonState.Released && + gamePadState.DPad.Up == ButtonState.Released)) { isPressed = false; } @@ -123,7 +126,9 @@ public abstract class AbstractGui : IDrawableObject button.CallLeftBtnEvent(); } } - else if (isPressed) + else if (isPressed && (keyboardState.IsKeyUp(Keys.Enter) && + keyboardState.IsKeyUp(Keys.Down) && + keyboardState.IsKeyUp(Keys.Up))) { isPressed = false; } @@ -134,25 +139,25 @@ public abstract class AbstractGui : IDrawableObject { if (ActiveElements[i] == SelectedElement) { - if (i == 0) + if (i + x >= ActiveElements.Count) { - SelectedElement = ActiveElements.Last(); + SelectedElement = ActiveElements.First(); + return; } else { - if (i == ActiveElements.Count - 1 && x >= 1) + if (i + x < 0) { - SelectedElement = ActiveElements.First(); + SelectedElement = ActiveElements.Last(); + return; } else { SelectedElement = ActiveElements[i + x]; + return; } - } - } - } } private bool CheckOnBadElements(DrawableUIElement element) @@ -165,10 +170,6 @@ public abstract class AbstractGui : IDrawableObject { return true; } - else if (element is CheckBox) - { - return true; - } else return false; } } \ No newline at end of file diff --git a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs index 066b1d4..eef557f 100644 --- a/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs +++ b/DangerousD/GameCore/GameObjects/LivingEntities/Player/Player.cs @@ -9,6 +9,7 @@ using DangerousD.GameCore.GameObjects.PlayerDeath; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Graphics; using DangerousD.GameCore.GameObjects.LivingEntities.Monsters; +using DangerousD.GameCore.Network; namespace DangerousD.GameCore.GameObjects.LivingEntities { diff --git a/DangerousD/GameCore/InputManager.cs b/DangerousD/GameCore/InputManager.cs index c171d6b..3846bc2 100644 --- a/DangerousD/GameCore/InputManager.cs +++ b/DangerousD/GameCore/InputManager.cs @@ -158,6 +158,7 @@ namespace DangerousD.GameCore { isShoot = false; } + SetState(ControlsState.Keyboard); } } } diff --git a/MonogameLibrary/UI/Elements/Button.cs b/MonogameLibrary/UI/Elements/Button.cs index 051f31f..769335f 100644 --- a/MonogameLibrary/UI/Elements/Button.cs +++ b/MonogameLibrary/UI/Elements/Button.cs @@ -16,7 +16,7 @@ namespace MonogameLibrary.UI.Elements public delegate void OnButtonPressed(); public event OnButtonPressed? RightButtonPressed; public event OnButtonPressed? LeftButtonPressed; - protected HoverState hoverState = HoverState.None; + public HoverState hoverState = HoverState.None; public Button(UIManager manager, int layerIndex = 0) : base(manager, layerIndex) {