Projekt přejmenován. Neko nastaven na výchozí pozici
This commit is contained in:
parent
1a27dd6fab
commit
ceac37920b
104 changed files with 873 additions and 208 deletions
42
ONDClient/GUI/TextBoxUIElement.cs
Normal file
42
ONDClient/GUI/TextBoxUIElement.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MonoGameLibrary;
|
||||
using MonoGameLibrary.Graphics;
|
||||
using MonoGameLibrary.Input;
|
||||
|
||||
namespace ONDClient.GUI;
|
||||
|
||||
public class TextBoxUIElement : TextUIElement {
|
||||
public bool Focused{ get; set; } = false;
|
||||
public Action OnFocused{ get; set; } = () => { };
|
||||
public Action OnUnfocused{ get; set; } = () => { };
|
||||
|
||||
public TextBoxUIElement(SpriteFont font, Point corner1, Point corner2) : base(corner1, corner2, font) {
|
||||
Core.Instance.Window.TextInput += TextInputHandler;
|
||||
InputManager.AddListener(InputManager.MouseButton.LEFT, () => {
|
||||
if (!IsWithinBounds(InputManager.MouseState.Position)){
|
||||
Focused = false;
|
||||
OnUnfocused();
|
||||
}
|
||||
},
|
||||
InputTiming.PRESS, new InputListenerHook(true));
|
||||
Pressable = true;
|
||||
|
||||
OnMousePress = () => {
|
||||
Focused = true;
|
||||
OnFocused();
|
||||
};
|
||||
}
|
||||
|
||||
public void TextInputHandler(object sender, TextInputEventArgs e) {
|
||||
if (!Focused) return;
|
||||
if (e.Character == '\b') {
|
||||
if (Text.Length > 0) Text = Text[..^1];
|
||||
return;
|
||||
}
|
||||
|
||||
if(Font.Characters.Contains(e.Character))
|
||||
Text += e.Character;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue