Refactor ChatBox to use HistoryLineEdit (#728)
* Refactor ChatBox to use HistoryLineEdit * Clean up ChatBox variable localize
This commit is contained in:
@@ -17,13 +17,9 @@ namespace Content.Client.Chat
|
|||||||
|
|
||||||
public delegate void FilterToggledHandler(ChatBox chatBox, BaseButton.ButtonToggledEventArgs e);
|
public delegate void FilterToggledHandler(ChatBox chatBox, BaseButton.ButtonToggledEventArgs e);
|
||||||
|
|
||||||
private const int MaxLinePixelLength = 500;
|
private readonly ILocalizationManager _localize = IoCManager.Resolve<ILocalizationManager>();
|
||||||
|
|
||||||
private readonly IList<string> _inputHistory = new List<string>();
|
public HistoryLineEdit Input { get; private set; }
|
||||||
|
|
||||||
private readonly ILocalizationManager localize = IoCManager.Resolve<ILocalizationManager>();
|
|
||||||
|
|
||||||
public LineEdit Input { get; private set; }
|
|
||||||
public OutputPanel Contents { get; }
|
public OutputPanel Contents { get; }
|
||||||
|
|
||||||
// Buttons for filtering
|
// Buttons for filtering
|
||||||
@@ -31,16 +27,6 @@ namespace Content.Client.Chat
|
|||||||
public Button LocalButton { get; }
|
public Button LocalButton { get; }
|
||||||
public Button OOCButton { get; }
|
public Button OOCButton { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Index while cycling through the input history. -1 means not going through history.
|
|
||||||
/// </summary>
|
|
||||||
private int _inputIndex = -1;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Message that WAS being input before going through history began.
|
|
||||||
/// </summary>
|
|
||||||
private string _inputTemp;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default formatting string for the ClientChatConsole.
|
/// Default formatting string for the ClientChatConsole.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -81,14 +67,14 @@ namespace Content.Client.Chat
|
|||||||
contentMargin.AddChild(Contents);
|
contentMargin.AddChild(Contents);
|
||||||
vBox.AddChild(contentMargin);
|
vBox.AddChild(contentMargin);
|
||||||
|
|
||||||
Input = new LineEdit();
|
Input = new HistoryLineEdit();
|
||||||
Input.OnKeyBindDown += InputKeyBindDown;
|
Input.OnKeyBindDown += InputKeyBindDown;
|
||||||
Input.OnTextEntered += Input_OnTextEntered;
|
Input.OnTextEntered += Input_OnTextEntered;
|
||||||
vBox.AddChild(Input);
|
vBox.AddChild(Input);
|
||||||
|
|
||||||
AllButton = new Button
|
AllButton = new Button
|
||||||
{
|
{
|
||||||
Text = localize.GetString("All"),
|
Text = _localize.GetString("All"),
|
||||||
Name = "ALL",
|
Name = "ALL",
|
||||||
SizeFlagsHorizontal = SizeFlags.ShrinkEnd | SizeFlags.Expand,
|
SizeFlagsHorizontal = SizeFlags.ShrinkEnd | SizeFlags.Expand,
|
||||||
ToggleMode = true,
|
ToggleMode = true,
|
||||||
@@ -96,14 +82,14 @@ namespace Content.Client.Chat
|
|||||||
|
|
||||||
LocalButton = new Button
|
LocalButton = new Button
|
||||||
{
|
{
|
||||||
Text = localize.GetString("Local"),
|
Text = _localize.GetString("Local"),
|
||||||
Name = "Local",
|
Name = "Local",
|
||||||
ToggleMode = true,
|
ToggleMode = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
OOCButton = new Button
|
OOCButton = new Button
|
||||||
{
|
{
|
||||||
Text = localize.GetString("OOC"),
|
Text = _localize.GetString("OOC"),
|
||||||
Name = "OOC",
|
Name = "OOC",
|
||||||
ToggleMode = true,
|
ToggleMode = true,
|
||||||
};
|
};
|
||||||
@@ -139,44 +125,6 @@ namespace Content.Client.Chat
|
|||||||
args.Handle();
|
args.Handle();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (args.Function == EngineKeyFunctions.TextHistoryPrev)
|
|
||||||
{
|
|
||||||
if (_inputIndex == -1 && _inputHistory.Count != 0)
|
|
||||||
{
|
|
||||||
_inputTemp = Input.Text;
|
|
||||||
_inputIndex++;
|
|
||||||
}
|
|
||||||
else if (_inputIndex + 1 < _inputHistory.Count)
|
|
||||||
{
|
|
||||||
_inputIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_inputIndex != -1)
|
|
||||||
{
|
|
||||||
Input.Text = _inputHistory[_inputIndex];
|
|
||||||
}
|
|
||||||
Input.CursorPos = Input.Text.Length;
|
|
||||||
|
|
||||||
args.Handle();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (args.Function == EngineKeyFunctions.TextHistoryNext)
|
|
||||||
{
|
|
||||||
if (_inputIndex == 0)
|
|
||||||
{
|
|
||||||
Input.Text = _inputTemp;
|
|
||||||
_inputTemp = "";
|
|
||||||
_inputIndex--;
|
|
||||||
}
|
|
||||||
else if (_inputIndex != -1)
|
|
||||||
{
|
|
||||||
_inputIndex--;
|
|
||||||
Input.Text = _inputHistory[_inputIndex];
|
|
||||||
}
|
|
||||||
Input.CursorPos = Input.Text.Length;
|
|
||||||
|
|
||||||
args.Handle();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public event TextSubmitHandler TextSubmitted;
|
public event TextSubmitHandler TextSubmitted;
|
||||||
@@ -202,11 +150,8 @@ namespace Content.Client.Chat
|
|||||||
if (!string.IsNullOrWhiteSpace(args.Text))
|
if (!string.IsNullOrWhiteSpace(args.Text))
|
||||||
{
|
{
|
||||||
TextSubmitted?.Invoke(this, args.Text);
|
TextSubmitted?.Invoke(this, args.Text);
|
||||||
_inputHistory.Insert(0, args.Text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_inputIndex = -1;
|
|
||||||
|
|
||||||
Input.Clear();
|
Input.Clear();
|
||||||
|
|
||||||
if (ReleaseFocusOnEnter)
|
if (ReleaseFocusOnEnter)
|
||||||
|
|||||||
Reference in New Issue
Block a user