mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 09:37:23 +08:00
Cleaning up
This commit is contained in:
parent
0100c01b82
commit
a9747d367c
@ -12,16 +12,18 @@ using osu.Game.Graphics.Sprites;
|
|||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneChatManipulation : OsuManualInputManagerTestScene
|
public class TestSceneHistoryTextBox : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
private HistoryTextBox box;
|
private const string temp = "Temp message";
|
||||||
private OsuSpriteText text;
|
|
||||||
|
|
||||||
private int messageCounter;
|
private int messageCounter;
|
||||||
|
|
||||||
|
private HistoryTextBox box;
|
||||||
|
private OsuSpriteText text;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp()
|
public void SetUp()
|
||||||
{
|
{
|
||||||
@ -49,6 +51,9 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
|
|
||||||
box.OnCommit += (_, __) =>
|
box.OnCommit += (_, __) =>
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(box.Text))
|
||||||
|
return;
|
||||||
|
|
||||||
text.Text = $"{nameof(box.OnCommit)}: {box.Text}";
|
text.Text = $"{nameof(box.OnCommit)}: {box.Text}";
|
||||||
box.Text = string.Empty;
|
box.Text = string.Empty;
|
||||||
box.TakeFocus();
|
box.TakeFocus();
|
||||||
@ -64,7 +69,6 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestEmptyHistory()
|
public void TestEmptyHistory()
|
||||||
{
|
{
|
||||||
const string temp = "Temp message";
|
|
||||||
AddStep("Set text", () => box.Text = temp);
|
AddStep("Set text", () => box.Text = temp);
|
||||||
|
|
||||||
AddStep("Move down", () => InputManager.Key(Key.Down));
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
||||||
@ -78,8 +82,6 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
public void TestPartialHistory()
|
public void TestPartialHistory()
|
||||||
{
|
{
|
||||||
addMessages(2);
|
addMessages(2);
|
||||||
|
|
||||||
const string temp = "Temp message";
|
|
||||||
AddStep("Set text", () => box.Text = temp);
|
AddStep("Set text", () => box.Text = temp);
|
||||||
|
|
||||||
AddStep("Move down", () => InputManager.Key(Key.Down));
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
||||||
@ -102,21 +104,18 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
public void TestFullHistory()
|
public void TestFullHistory()
|
||||||
{
|
{
|
||||||
addMessages(5);
|
addMessages(5);
|
||||||
|
AddStep("Set text", () => box.Text = temp);
|
||||||
AddAssert("History saved as <5-1>", () =>
|
AddAssert("History saved as <5-1>", () =>
|
||||||
Enumerable.Range(0, 5).Select(number => $"Message {5 - number}").SequenceEqual(box.MessageHistory));
|
Enumerable.Range(0, 5).Select(number => $"Message {5 - number}").SequenceEqual(box.MessageHistory));
|
||||||
|
|
||||||
const string temp = "Temp message";
|
|
||||||
AddStep("Set text", () => box.Text = temp);
|
|
||||||
|
|
||||||
AddStep("Move down", () => InputManager.Key(Key.Down));
|
AddStep("Move down", () => InputManager.Key(Key.Down));
|
||||||
AddAssert("Text is the same", () => box.Text == temp);
|
AddAssert("Text is the same", () => box.Text == temp);
|
||||||
|
|
||||||
addMessages(2);
|
addMessages(2);
|
||||||
|
AddStep("Set text", () => box.Text = temp);
|
||||||
AddAssert("Overrode history to <7-3>", () =>
|
AddAssert("Overrode history to <7-3>", () =>
|
||||||
Enumerable.Range(0, 5).Select(number => $"Message {7 - number}").SequenceEqual(box.MessageHistory));
|
Enumerable.Range(0, 5).Select(number => $"Message {7 - number}").SequenceEqual(box.MessageHistory));
|
||||||
|
|
||||||
AddStep("Set text", () => box.Text = temp);
|
|
||||||
|
|
||||||
AddRepeatStep("Move Up", () => InputManager.Key(Key.Up), 5);
|
AddRepeatStep("Move Up", () => InputManager.Key(Key.Up), 5);
|
||||||
AddAssert("Same as 3rd message", () => box.Text == "Message 3");
|
AddAssert("Same as 3rd message", () => box.Text == "Message 3");
|
||||||
|
|
@ -12,27 +12,27 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
public class HistoryTextBox : FocusedTextBox
|
public class HistoryTextBox : FocusedTextBox
|
||||||
{
|
{
|
||||||
private readonly int historyLimit;
|
private readonly int historyLimit;
|
||||||
|
|
||||||
private bool everythingSelected;
|
|
||||||
|
|
||||||
public int HistoryLength => messageHistory.Count;
|
|
||||||
|
|
||||||
private readonly List<string> messageHistory;
|
private readonly List<string> messageHistory;
|
||||||
|
|
||||||
public IReadOnlyList<string> MessageHistory =>
|
public IReadOnlyList<string> MessageHistory =>
|
||||||
Enumerable.Range(0, HistoryLength).Select(GetOldMessage).ToList();
|
Enumerable.Range(0, HistoryLength).Select(GetOldMessage).ToList();
|
||||||
|
|
||||||
private string originalMessage = string.Empty;
|
public int HistoryLength => messageHistory.Count;
|
||||||
|
|
||||||
private int historyIndex = -1;
|
|
||||||
|
|
||||||
private int startIndex;
|
private int startIndex;
|
||||||
|
private int selectedIndex = -1;
|
||||||
|
|
||||||
|
private string originalMessage = string.Empty;
|
||||||
|
private bool everythingSelected;
|
||||||
|
|
||||||
private int getNormalizedIndex(int index) =>
|
private int getNormalizedIndex(int index) =>
|
||||||
(HistoryLength + startIndex - index - 1) % HistoryLength;
|
(HistoryLength + startIndex - index - 1) % HistoryLength;
|
||||||
|
|
||||||
public HistoryTextBox(int historyLimit = 100)
|
public HistoryTextBox(int historyLimit = 100)
|
||||||
{
|
{
|
||||||
|
if (historyLimit <= 0)
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
|
||||||
this.historyLimit = historyLimit;
|
this.historyLimit = historyLimit;
|
||||||
messageHistory = new List<string>(historyLimit);
|
messageHistory = new List<string>(historyLimit);
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(text.NewValue) || everythingSelected)
|
if (string.IsNullOrEmpty(text.NewValue) || everythingSelected)
|
||||||
{
|
{
|
||||||
historyIndex = -1;
|
selectedIndex = -1;
|
||||||
everythingSelected = false;
|
everythingSelected = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -66,28 +66,28 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
switch (e.Key)
|
switch (e.Key)
|
||||||
{
|
{
|
||||||
case Key.Up:
|
case Key.Up:
|
||||||
if (historyIndex == HistoryLength - 1)
|
if (selectedIndex == HistoryLength - 1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (historyIndex == -1)
|
if (selectedIndex == -1)
|
||||||
originalMessage = Text;
|
originalMessage = Text;
|
||||||
|
|
||||||
Text = messageHistory[getNormalizedIndex(++historyIndex)];
|
Text = messageHistory[getNormalizedIndex(++selectedIndex)];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case Key.Down:
|
case Key.Down:
|
||||||
if (historyIndex == -1)
|
if (selectedIndex == -1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (historyIndex == 0)
|
if (selectedIndex == 0)
|
||||||
{
|
{
|
||||||
historyIndex = -1;
|
selectedIndex = -1;
|
||||||
Text = originalMessage;
|
Text = originalMessage;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Text = messageHistory[getNormalizedIndex(--historyIndex)];
|
Text = messageHistory[getNormalizedIndex(--selectedIndex)];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
historyIndex = -1;
|
selectedIndex = -1;
|
||||||
|
|
||||||
base.Commit();
|
base.Commit();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user