AnotherTryFix
This commit is contained in:
parent
1f3108adcd
commit
6d1f7f750a
3 changed files with 65 additions and 16 deletions
|
@ -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<DrawableUIElement> Elements = new();
|
||||
private List<DrawableUIElement> ActiveElements;
|
||||
protected DrawableUIElement SelectedElement;
|
||||
private bool isStartedPrint = false;
|
||||
private bool isPressed = false;
|
||||
|
||||
public AbstractGui()
|
||||
|
@ -65,12 +67,32 @@ public abstract class AbstractGui : IDrawableObject
|
|||
KeyboardState keyBoardState = Keyboard.GetState();
|
||||
KeyBoardInput(keyBoardState);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Manager.Update();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue