mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Moved implementation to ChatRecentTextBox.cs and derived ChatTextBox.cs and StandAloneChatDisplay.cs from it.
This commit is contained in:
@ -12,7 +12,6 @@ using osu.Framework.Graphics.Shapes;
|
|||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Overlays.Chat;
|
using osu.Game.Overlays.Chat;
|
||||||
using osu.Game.Resources.Localisation.Web;
|
using osu.Game.Resources.Localisation.Web;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -120,18 +119,21 @@ namespace osu.Game.Online.Chat
|
|||||||
AddInternal(drawableChannel);
|
AddInternal(drawableChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ChatTextBox : FocusedTextBox
|
public class ChatTextBox : ChatRecentTextBox
|
||||||
{
|
{
|
||||||
protected override bool OnKeyDown(KeyDownEvent e)
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
{
|
{
|
||||||
// Chat text boxes are generally used in places where they retain focus, but shouldn't block interaction with other
|
// Chat text boxes are generally used in places where they retain focus, but shouldn't block interaction with other
|
||||||
// elements on the same screen.
|
// elements on the same screen.
|
||||||
|
if (!HoldFocus)
|
||||||
|
{
|
||||||
switch (e.Key)
|
switch (e.Key)
|
||||||
{
|
{
|
||||||
case Key.Up:
|
case Key.Up:
|
||||||
case Key.Down:
|
case Key.Down:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return base.OnKeyDown(e);
|
return base.OnKeyDown(e);
|
||||||
}
|
}
|
||||||
|
74
osu.Game/Overlays/Chat/ChatRecentTextBox.cs
Normal file
74
osu.Game/Overlays/Chat/ChatRecentTextBox.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Chat
|
||||||
|
{
|
||||||
|
public class ChatRecentTextBox : FocusedTextBox
|
||||||
|
{
|
||||||
|
private readonly List<string> messageHistory = new List<string>();
|
||||||
|
|
||||||
|
private int messageIndex = -1;
|
||||||
|
|
||||||
|
private string originalMessage = string.Empty;
|
||||||
|
|
||||||
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
|
{
|
||||||
|
/* Behavior:
|
||||||
|
* add when on last element -> last element stays
|
||||||
|
* subtract when on first element -> sets to original text
|
||||||
|
* reset indexing when Text is set to Empty
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch (e.Key)
|
||||||
|
{
|
||||||
|
case Key.Up:
|
||||||
|
if (messageIndex == -1)
|
||||||
|
originalMessage = Text;
|
||||||
|
|
||||||
|
if (messageIndex == messageHistory.Count - 1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Text = messageHistory[++messageIndex];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case Key.Down:
|
||||||
|
if (messageIndex == -1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (messageIndex == 0)
|
||||||
|
{
|
||||||
|
messageIndex = -1;
|
||||||
|
Text = originalMessage;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Text = messageHistory[--messageIndex];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool onKeyDown = base.OnKeyDown(e);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(Text))
|
||||||
|
messageIndex = -1;
|
||||||
|
|
||||||
|
return onKeyDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Commit()
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(Text))
|
||||||
|
messageHistory.Insert(0, Text);
|
||||||
|
|
||||||
|
messageIndex = -1;
|
||||||
|
|
||||||
|
base.Commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,23 +1,13 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osu.Game.Resources.Localisation.Web;
|
using osu.Game.Resources.Localisation.Web;
|
||||||
using osuTK.Input;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Chat
|
namespace osu.Game.Overlays.Chat
|
||||||
{
|
{
|
||||||
public class ChatTextBox : FocusedTextBox
|
public class ChatTextBox : ChatRecentTextBox
|
||||||
{
|
{
|
||||||
private readonly List<string> messageHistory = new List<string>();
|
|
||||||
|
|
||||||
private int messageIndex = -1;
|
|
||||||
|
|
||||||
private string originalMessage = string.Empty;
|
|
||||||
|
|
||||||
public readonly BindableBool ShowSearch = new BindableBool();
|
public readonly BindableBool ShowSearch = new BindableBool();
|
||||||
|
|
||||||
public override bool HandleLeftRightArrows => !ShowSearch.Value;
|
public override bool HandleLeftRightArrows => !ShowSearch.Value;
|
||||||
@ -37,59 +27,11 @@ namespace osu.Game.Overlays.Chat
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnKeyDown(KeyDownEvent e)
|
|
||||||
{
|
|
||||||
/* Behavior:
|
|
||||||
* add when on last element -> last element stays
|
|
||||||
* subtract when on first element -> sets to original text
|
|
||||||
* reset indexing when Text is set to Empty
|
|
||||||
*/
|
|
||||||
|
|
||||||
switch (e.Key)
|
|
||||||
{
|
|
||||||
case Key.Up:
|
|
||||||
if (messageIndex == -1)
|
|
||||||
originalMessage = Text;
|
|
||||||
|
|
||||||
if (messageIndex == messageHistory.Count - 1)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
Text = messageHistory[++messageIndex];
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case Key.Down:
|
|
||||||
if (messageIndex == -1)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (messageIndex == 0)
|
|
||||||
{
|
|
||||||
messageIndex = -1;
|
|
||||||
Text = originalMessage;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Text = messageHistory[--messageIndex];
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool onKeyDown = base.OnKeyDown(e);
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(Text))
|
|
||||||
messageIndex = -1;
|
|
||||||
|
|
||||||
return onKeyDown;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Commit()
|
protected override void Commit()
|
||||||
{
|
{
|
||||||
if (ShowSearch.Value)
|
if (ShowSearch.Value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
messageHistory.Insert(0, Text);
|
|
||||||
messageIndex = -1;
|
|
||||||
|
|
||||||
base.Commit();
|
base.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user