finish1IterOfSwitchingUI

This commit is contained in:
polten0 2023-08-18 02:46:59 +03:00
parent bc3a55f535
commit 1f3108adcd
4 changed files with 29 additions and 26 deletions

View file

@ -51,24 +51,25 @@ public abstract class AbstractGui : IDrawableObject
{ {
string state = AppManager.Instance.InputManager.currentControlsState; string state = AppManager.Instance.InputManager.currentControlsState;
if (ActiveElements.Count != 0) if (ActiveElements.Count != 0)
{ {
switch (state) if (state == "Gamepad")
{ {
case "Gamepad": GamePadState gamePadState = GamePad.GetState(0);
GamePadState gamePadState = GamePad.GetState(0); GamepadInput(gamePadState);
GamepadInput(gamePadState); }
break; else if (state == "Keyboard" || state == "Mouse")
case "Keyboard": {
KeyboardState keyBoardState = Keyboard.GetState(0); KeyboardState keyBoardState = Keyboard.GetState();
KeyBoardInput(keyBoardState); KeyBoardInput(keyBoardState);
break;
default:
break;
} }
} }
Manager.Update(); Manager.Update();
(SelectedElement as Button).hoverState = MonogameLibrary.UI.Enums.HoverState.Hovering;
} }
public virtual void Draw(SpriteBatch spriteBatch) public virtual void Draw(SpriteBatch spriteBatch)
@ -81,6 +82,7 @@ public abstract class AbstractGui : IDrawableObject
{ {
isPressed = true; isPressed = true;
ChangeSelectedElement(-1); ChangeSelectedElement(-1);
Debug.WriteLine("switch");
} }
else if (gamePadState.DPad.Down == ButtonState.Pressed && !isPressed) 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) else if (gamePadState.Buttons.A == ButtonState.Pressed && !isPressed)
{ {
Debug.WriteLine("ssss");
isPressed = true; isPressed = true;
if (SelectedElement is ButtonText) if (SelectedElement is ButtonText)
{ {
@ -97,7 +98,9 @@ public abstract class AbstractGui : IDrawableObject
button.CallLeftBtnEvent(); 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; isPressed = false;
} }
@ -123,7 +126,9 @@ public abstract class AbstractGui : IDrawableObject
button.CallLeftBtnEvent(); button.CallLeftBtnEvent();
} }
} }
else if (isPressed) else if (isPressed && (keyboardState.IsKeyUp(Keys.Enter) &&
keyboardState.IsKeyUp(Keys.Down) &&
keyboardState.IsKeyUp(Keys.Up)))
{ {
isPressed = false; isPressed = false;
} }
@ -134,25 +139,25 @@ public abstract class AbstractGui : IDrawableObject
{ {
if (ActiveElements[i] == SelectedElement) if (ActiveElements[i] == SelectedElement)
{ {
if (i == 0) if (i + x >= ActiveElements.Count)
{ {
SelectedElement = ActiveElements.Last(); SelectedElement = ActiveElements.First();
return;
} }
else else
{ {
if (i == ActiveElements.Count - 1 && x >= 1) if (i + x < 0)
{ {
SelectedElement = ActiveElements.First(); SelectedElement = ActiveElements.Last();
return;
} }
else else
{ {
SelectedElement = ActiveElements[i + x]; SelectedElement = ActiveElements[i + x];
return;
} }
} }
} }
} }
} }
private bool CheckOnBadElements(DrawableUIElement element) private bool CheckOnBadElements(DrawableUIElement element)
@ -165,10 +170,6 @@ public abstract class AbstractGui : IDrawableObject
{ {
return true; return true;
} }
else if (element is CheckBox)
{
return true;
}
else return false; else return false;
} }
} }

View file

@ -9,6 +9,7 @@ using DangerousD.GameCore.GameObjects.PlayerDeath;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using DangerousD.GameCore.GameObjects.LivingEntities.Monsters; using DangerousD.GameCore.GameObjects.LivingEntities.Monsters;
using DangerousD.GameCore.Network;
namespace DangerousD.GameCore.GameObjects.LivingEntities namespace DangerousD.GameCore.GameObjects.LivingEntities
{ {

View file

@ -158,6 +158,7 @@ namespace DangerousD.GameCore
{ {
isShoot = false; isShoot = false;
} }
SetState(ControlsState.Keyboard);
} }
} }
} }

View file

@ -16,7 +16,7 @@ namespace MonogameLibrary.UI.Elements
public delegate void OnButtonPressed(); public delegate void OnButtonPressed();
public event OnButtonPressed? RightButtonPressed; public event OnButtonPressed? RightButtonPressed;
public event OnButtonPressed? LeftButtonPressed; public event OnButtonPressed? LeftButtonPressed;
protected HoverState hoverState = HoverState.None; public HoverState hoverState = HoverState.None;
public Button(UIManager manager, int layerIndex = 0) : base(manager, layerIndex) public Button(UIManager manager, int layerIndex = 0) : base(manager, layerIndex)
{ {