2026-03-11 22:35:30 +01:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
2026-03-22 18:31:05 +01:00
|
|
|
namespace ONDClient.GUI;
|
2026-03-11 22:35:30 +01:00
|
|
|
|
|
|
|
|
public class MenuInputField : UIElement {
|
2026-03-28 09:59:31 +01:00
|
|
|
private readonly TextUIElement labelElement;
|
|
|
|
|
private readonly TextBoxUIElement textBoxElement;
|
2026-03-11 22:35:30 +01:00
|
|
|
|
|
|
|
|
public MenuInputField(SpriteFont font, Point position, string label, string defaultValue = "") : base(position, position) {
|
|
|
|
|
labelElement =
|
|
|
|
|
new TextUIElement(position, font){Text = label, Color = Color.Gray};
|
|
|
|
|
textBoxElement =
|
|
|
|
|
new TextBoxUIElement(font,
|
|
|
|
|
new(labelElement.Bounds.Item1.X + (int)labelElement.Measure().X, labelElement.Bounds.Item1.Y),
|
|
|
|
|
new(640, labelElement.Bounds.Item2.Y + (int)labelElement.Measure().Y));
|
|
|
|
|
textBoxElement.OnFocused = () => {
|
|
|
|
|
textBoxElement.Color = Color.LightGreen;
|
|
|
|
|
labelElement.Color = Color.DarkGreen;
|
|
|
|
|
};
|
|
|
|
|
textBoxElement.OnUnfocused = () => {
|
|
|
|
|
textBoxElement.Color = Color.White;
|
|
|
|
|
labelElement.Color = Color.Gray;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Bounds = (labelElement.Bounds.Item1, textBoxElement.Bounds.Item2);
|
|
|
|
|
Pressable = true;
|
|
|
|
|
OnMousePress = textBoxElement.OnMousePress;
|
|
|
|
|
textBoxElement.Text = defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 20:14:29 +01:00
|
|
|
public string Text{
|
|
|
|
|
get => textBoxElement.Text;
|
|
|
|
|
set => textBoxElement.Text = value;
|
|
|
|
|
}
|
2026-03-11 22:35:30 +01:00
|
|
|
|
|
|
|
|
public override void Draw(SpriteBatch spriteBatch) {
|
|
|
|
|
labelElement.Draw(spriteBatch);
|
|
|
|
|
textBoxElement.Draw(spriteBatch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update() {
|
|
|
|
|
base.Update();
|
|
|
|
|
labelElement.Update();
|
|
|
|
|
textBoxElement.Update();
|
|
|
|
|
}
|
|
|
|
|
}
|