AnotherTryFix

This commit is contained in:
polten0 2023-08-18 04:18:52 +03:00
parent 1f3108adcd
commit 6d1f7f750a
3 changed files with 65 additions and 16 deletions

View file

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -17,6 +18,7 @@ public abstract class AbstractGui : IDrawableObject
protected List<DrawableUIElement> Elements = new(); protected List<DrawableUIElement> Elements = new();
private List<DrawableUIElement> ActiveElements; private List<DrawableUIElement> ActiveElements;
protected DrawableUIElement SelectedElement; protected DrawableUIElement SelectedElement;
private bool isStartedPrint = false;
private bool isPressed = false; private bool isPressed = false;
public AbstractGui() public AbstractGui()
@ -65,11 +67,31 @@ public abstract class AbstractGui : IDrawableObject
KeyboardState keyBoardState = Keyboard.GetState(); KeyboardState keyBoardState = Keyboard.GetState();
KeyBoardInput(keyBoardState); KeyBoardInput(keyBoardState);
} }
} }
Manager.Update(); Manager.Update();
(SelectedElement as Button).hoverState = MonogameLibrary.UI.Enums.HoverState.Hovering; if (SelectedElement is not null)
{
if (SelectedElement is Button)
{
(SelectedElement as Button).hoverState = MonogameLibrary.UI.Enums.HoverState.Hovering;
}
if (SelectedElement is ButtonText)
{
(SelectedElement as ButtonText).hoverState = MonogameLibrary.UI.Enums.HoverState.Hovering;
}
if (SelectedElement is TextBox)
{
TextBox box = (TextBox)SelectedElement;
box.hoverState = MonogameLibrary.UI.Enums.HoverState.Hovering;
if (isStartedPrint)
{
box.SelectIt();
}
}
}
} }
public virtual void Draw(SpriteBatch spriteBatch) public virtual void Draw(SpriteBatch spriteBatch)
@ -92,11 +114,16 @@ public abstract class AbstractGui : IDrawableObject
else if (gamePadState.Buttons.A == ButtonState.Pressed && !isPressed) else if (gamePadState.Buttons.A == ButtonState.Pressed && !isPressed)
{ {
isPressed = true; isPressed = true;
if (SelectedElement is ButtonText) if (SelectedElement is Button)
{ {
Button button = SelectedElement as ButtonText; Button button = SelectedElement as Button;
button.CallLeftBtnEvent(); button.CallLeftBtnEvent();
} }
else if (SelectedElement is TextBox)
{
TextBox textBox = SelectedElement as TextBox;
isStartedPrint = true;
}
} }
else if (isPressed && (gamePadState.Buttons.A == ButtonState.Released && else if (isPressed && (gamePadState.Buttons.A == ButtonState.Released &&
gamePadState.DPad.Down == ButtonState.Released && gamePadState.DPad.Down == ButtonState.Released &&
@ -110,11 +137,13 @@ public abstract class AbstractGui : IDrawableObject
if (keyboardState.IsKeyDown(Keys.Up) && !isPressed) if (keyboardState.IsKeyDown(Keys.Up) && !isPressed)
{ {
isPressed = true; isPressed = true;
isStartedPrint = false;
ChangeSelectedElement(-1); ChangeSelectedElement(-1);
} }
else if (keyboardState.IsKeyDown(Keys.Down) && !isPressed) else if (keyboardState.IsKeyDown(Keys.Down) && !isPressed)
{ {
isPressed = true; isPressed = true;
isStartedPrint = false;
ChangeSelectedElement(1); ChangeSelectedElement(1);
} }
else if (keyboardState.IsKeyDown(Keys.Enter) && !isPressed) else if (keyboardState.IsKeyDown(Keys.Enter) && !isPressed)
@ -125,6 +154,11 @@ public abstract class AbstractGui : IDrawableObject
Button button = SelectedElement as Button; Button button = SelectedElement as Button;
button.CallLeftBtnEvent(); button.CallLeftBtnEvent();
} }
else if (SelectedElement is TextBox)
{
TextBox textBox = SelectedElement as TextBox;
isStartedPrint = true;
}
} }
else if (isPressed && (keyboardState.IsKeyUp(Keys.Enter) && else if (isPressed && (keyboardState.IsKeyUp(Keys.Enter) &&
keyboardState.IsKeyUp(Keys.Down) && keyboardState.IsKeyUp(Keys.Down) &&
@ -170,6 +204,10 @@ public abstract class AbstractGui : IDrawableObject
{ {
return true; return true;
} }
else if (element is TextBox)
{
return true;
}
else return false; else return false;
} }
} }

View file

@ -40,6 +40,20 @@ namespace DangerousD.GameCore.GUI
fontName = "ButtonFont" fontName = "ButtonFont"
}); });
Button backButton = new Button(Manager)
{
rectangle = new Rectangle(screenWidth / 20, screenHeight / 15, (int)(40 * 2.4), (int)(40 * 2.4)),
text = "<-",
scale = 0.72f,
fontColor = Color.Black,
fontName = "font2",
textureName = "textboxbackground1-1"
};
backButton.LeftButtonPressed += () => {
AppManager.Instance.ChangeGameState(GameState.Menu);
};
Elements.Add(backButton);
// TextBox-ы // TextBox-ы
{ {
TextBox loginTextBox = new TextBox(Manager) TextBox loginTextBox = new TextBox(Manager)
@ -67,6 +81,7 @@ namespace DangerousD.GameCore.GUI
loginTextBox.fontColor = Color.Gray; loginTextBox.fontColor = Color.Gray;
} }
}; };
Elements.Add(loginTextBox);
TextBox passwordTextBox = new TextBox(Manager) TextBox passwordTextBox = new TextBox(Manager)
{ {
@ -92,6 +107,7 @@ namespace DangerousD.GameCore.GUI
passwordTextBox.fontColor = Color.Gray; passwordTextBox.fontColor = Color.Gray;
} }
}; };
Elements.Add(passwordTextBox);
} }
// Кнопки // Кнопки
@ -110,6 +126,7 @@ namespace DangerousD.GameCore.GUI
AppManager.Instance.ChangeGameState(GameState.Lobby); AppManager.Instance.ChangeGameState(GameState.Lobby);
} }
}; };
Elements.Add(logButton);
Button regButton = new Button(Manager) Button regButton = new Button(Manager)
{ {
@ -121,19 +138,9 @@ namespace DangerousD.GameCore.GUI
textureName = "textboxbackground2-1" textureName = "textboxbackground2-1"
}; };
regButton.LeftButtonPressed += GoToRegWebServer; regButton.LeftButtonPressed += GoToRegWebServer;
Elements.Add(regButton);
Button backButton = new Button(Manager)
{
rectangle = new Rectangle(screenWidth / 20, screenHeight / 15, (int)(40 * 2.4), (int)(40 * 2.4)),
text = "<-",
scale = 0.72f,
fontColor = Color.Black,
fontName = "font2",
textureName = "textboxbackground1-1"
};
backButton.LeftButtonPressed += () => {
AppManager.Instance.ChangeGameState(GameState.Menu);
};
} }
} }

View file

@ -26,9 +26,13 @@ namespace MonogameLibrary.UI.Elements
public event OnTextChange? StopChanging; public event OnTextChange? StopChanging;
public event OnTextChange? OnEnter; public event OnTextChange? OnEnter;
protected HoverState hoverState = HoverState.None; public HoverState hoverState = HoverState.None;
protected IsSelected isSelected = IsSelected.NotSelected; protected IsSelected isSelected = IsSelected.NotSelected;
public bool shouldEndOnEnter; public bool shouldEndOnEnter;
public void SelectIt()
{
isSelected = IsSelected.Selected;
}
public virtual bool InteractUpdate(MouseState mouseState, MouseState prevmouseState) public virtual bool InteractUpdate(MouseState mouseState, MouseState prevmouseState)
{ {