OneNightDuel/FNAF_Clone/GUI/MenuInputField.cs

45 lines
No EOL
1.6 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGameLibrary.Graphics;
namespace FNAF_Clone.GUI;
public class MenuInputField : UIElement {
private TextUIElement labelElement;
private TextBoxUIElement textBoxElement;
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;
}
public string Text => textBoxElement.Text;
public override void Draw(SpriteBatch spriteBatch) {
labelElement.Draw(spriteBatch);
textBoxElement.Draw(spriteBatch);
}
public override void Update() {
base.Update();
labelElement.Update();
textBoxElement.Update();
}
}