-
Notifications
You must be signed in to change notification settings - Fork 16
/
ChatTextBox.cs
81 lines (70 loc) · 2.32 KB
/
ChatTextBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using EndlessClient.Content;
using EOLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Optional;
using XNAControls;
namespace EndlessClient.UIControls
{
/// <summary>
/// Special instance of an XNATextBox that should ignore input from the number pad (which is used for Emotes)
/// </summary>
public class ChatTextBox : XNATextBox
{
private bool _ignoreAllInput;
private Option<DateTime> _endMuteTime;
public ChatTextBox(IContentProvider contentManagerProvider)
: base(new Rectangle(124, 308, 440, 19),
Constants.FontSize08,
caretTexture: contentManagerProvider.Textures[ContentProvider.Cursor])
{
MaxChars = 140;
_endMuteTime = Option.None<DateTime>();
}
public override void Initialize()
{
base.Initialize();
// This must be done after Initialize because MaxWidth uses the sprite font.
// SpriteFont is loaded in LoadContent which is called by Initialize.
MaxWidth = 440;
}
public void SetMuted(DateTime endMuteTime)
{
_ignoreAllInput = true;
_endMuteTime = Option.Some(endMuteTime);
}
protected override void OnUpdateControl(GameTime gameTime)
{
_endMuteTime.MatchSome(endTime =>
{
if (DateTime.Now > endTime)
{
_endMuteTime = Option.None<DateTime>();
_ignoreAllInput = false;
}
});
base.OnUpdateControl(gameTime);
}
public override void ReceiveTextInput(char inp)
{
if (_ignoreAllInput) return;
if (IsSpecialInput((Keys) inp))
HandleSpecialInput((Keys)inp);
else
base.ReceiveTextInput(inp);
}
private void HandleSpecialInput(Keys key)
{
if (key == Keys.Escape)
Text = "";
}
private bool IsSpecialInput(Keys k)
{
//todo: figure out how to handle num pad
return k == Keys.Escape;// || k == Keys.Decimal ||
//(k >= Keys.NumPad0 && k <= Keys.NumPad9);
}
}
}