diff --git a/DangerousD/GameCore/GUI/AbstractGui.cs b/DangerousD/GameCore/GUI/AbstractGui.cs index 34bea14..9b08d60 100644 --- a/DangerousD/GameCore/GUI/AbstractGui.cs +++ b/DangerousD/GameCore/GUI/AbstractGui.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -17,6 +18,7 @@ public abstract class AbstractGui : IDrawableObject protected List Elements = new(); private List ActiveElements; protected DrawableUIElement SelectedElement; + private bool isStartedPrint = false; private bool isPressed = false; public AbstractGui() @@ -65,11 +67,31 @@ public abstract class AbstractGui : IDrawableObject KeyboardState keyBoardState = Keyboard.GetState(); KeyBoardInput(keyBoardState); } + } 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) @@ -92,11 +114,16 @@ public abstract class AbstractGui : IDrawableObject else if (gamePadState.Buttons.A == ButtonState.Pressed && !isPressed) { isPressed = true; - if (SelectedElement is ButtonText) + if (SelectedElement is Button) { - Button button = SelectedElement as ButtonText; + Button button = SelectedElement as Button; button.CallLeftBtnEvent(); } + else if (SelectedElement is TextBox) + { + TextBox textBox = SelectedElement as TextBox; + isStartedPrint = true; + } } else if (isPressed && (gamePadState.Buttons.A == ButtonState.Released && gamePadState.DPad.Down == ButtonState.Released && @@ -110,11 +137,13 @@ public abstract class AbstractGui : IDrawableObject if (keyboardState.IsKeyDown(Keys.Up) && !isPressed) { isPressed = true; + isStartedPrint = false; ChangeSelectedElement(-1); } else if (keyboardState.IsKeyDown(Keys.Down) && !isPressed) { isPressed = true; + isStartedPrint = false; ChangeSelectedElement(1); } else if (keyboardState.IsKeyDown(Keys.Enter) && !isPressed) @@ -125,6 +154,11 @@ public abstract class AbstractGui : IDrawableObject Button button = SelectedElement as Button; button.CallLeftBtnEvent(); } + else if (SelectedElement is TextBox) + { + TextBox textBox = SelectedElement as TextBox; + isStartedPrint = true; + } } else if (isPressed && (keyboardState.IsKeyUp(Keys.Enter) && keyboardState.IsKeyUp(Keys.Down) && @@ -170,6 +204,10 @@ public abstract class AbstractGui : IDrawableObject { return true; } + else if (element is TextBox) + { + return true; + } else return false; } } \ No newline at end of file diff --git a/DangerousD/GameCore/GUI/LoginGUI.cs b/DangerousD/GameCore/GUI/LoginGUI.cs index 37a62eb..45a6de8 100644 --- a/DangerousD/GameCore/GUI/LoginGUI.cs +++ b/DangerousD/GameCore/GUI/LoginGUI.cs @@ -40,6 +40,20 @@ namespace DangerousD.GameCore.GUI 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 loginTextBox = new TextBox(Manager) @@ -67,6 +81,7 @@ namespace DangerousD.GameCore.GUI loginTextBox.fontColor = Color.Gray; } }; + Elements.Add(loginTextBox); TextBox passwordTextBox = new TextBox(Manager) { @@ -92,6 +107,7 @@ namespace DangerousD.GameCore.GUI passwordTextBox.fontColor = Color.Gray; } }; + Elements.Add(passwordTextBox); } // Кнопки @@ -110,6 +126,7 @@ namespace DangerousD.GameCore.GUI AppManager.Instance.ChangeGameState(GameState.Lobby); } }; + Elements.Add(logButton); Button regButton = new Button(Manager) { @@ -121,19 +138,9 @@ namespace DangerousD.GameCore.GUI textureName = "textboxbackground2-1" }; 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); - }; } } diff --git a/MonogameLibrary/UI/Elements/TextBox.cs b/MonogameLibrary/UI/Elements/TextBox.cs index 3649692..87534eb 100644 --- a/MonogameLibrary/UI/Elements/TextBox.cs +++ b/MonogameLibrary/UI/Elements/TextBox.cs @@ -26,9 +26,13 @@ namespace MonogameLibrary.UI.Elements public event OnTextChange? StopChanging; public event OnTextChange? OnEnter; - protected HoverState hoverState = HoverState.None; + public HoverState hoverState = HoverState.None; protected IsSelected isSelected = IsSelected.NotSelected; public bool shouldEndOnEnter; + public void SelectIt() + { + isSelected = IsSelected.Selected; + } public virtual bool InteractUpdate(MouseState mouseState, MouseState prevmouseState) {