2017-01-11 06:43:00 +08:00
|
|
|
|
using System;
|
2017-02-01 08:00:54 +08:00
|
|
|
|
using System.Linq;
|
2017-01-11 06:43:00 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-01-30 23:16:55 +08:00
|
|
|
|
using OpenTK.Input;
|
2017-01-11 06:43:00 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2017-01-30 23:16:55 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-01-11 06:43:00 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select
|
|
|
|
|
{
|
|
|
|
|
public class SearchTextBox : TextBox
|
|
|
|
|
{
|
|
|
|
|
protected override Color4 BackgroundUnfocused => new Color4(10, 10, 10, 255);
|
|
|
|
|
protected override Color4 BackgroundFocused => new Color4(10, 10, 10, 255);
|
2017-02-01 08:00:54 +08:00
|
|
|
|
public Action Exit;
|
2017-02-03 18:12:57 +08:00
|
|
|
|
|
|
|
|
|
private bool focus;
|
|
|
|
|
public bool HoldFocus
|
|
|
|
|
{
|
|
|
|
|
get { return focus; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
focus = value;
|
|
|
|
|
if (!focus)
|
|
|
|
|
TriggerFocusLost();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 06:43:00 +08:00
|
|
|
|
private SpriteText placeholder;
|
|
|
|
|
|
|
|
|
|
protected override string InternalText
|
|
|
|
|
{
|
|
|
|
|
get { return base.InternalText; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.InternalText = value;
|
|
|
|
|
if (placeholder != null)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
|
|
|
placeholder.Text = "type to search";
|
|
|
|
|
else
|
|
|
|
|
placeholder.Text = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-03 18:12:57 +08:00
|
|
|
|
|
2017-01-11 06:43:00 +08:00
|
|
|
|
public SearchTextBox()
|
|
|
|
|
{
|
|
|
|
|
Height = 35;
|
|
|
|
|
TextContainer.Padding = new MarginPadding(5);
|
|
|
|
|
Add(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
placeholder = new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = @"Exo2.0-MediumItalic",
|
|
|
|
|
Text = "type to search",
|
|
|
|
|
Colour = new Color4(180, 180, 180, 255),
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Margin = new MarginPadding { Left = 10 },
|
|
|
|
|
},
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.fa_search,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Margin = new MarginPadding { Right = 10 },
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-02-03 18:12:57 +08:00
|
|
|
|
|
2017-01-31 02:43:21 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
2017-02-03 18:12:57 +08:00
|
|
|
|
if (HoldFocus) RequestFocus();
|
2017-01-31 02:43:21 +08:00
|
|
|
|
base.Update();
|
2017-01-11 06:43:00 +08:00
|
|
|
|
}
|
2017-02-03 18:12:57 +08:00
|
|
|
|
|
2017-02-01 08:00:54 +08:00
|
|
|
|
protected override void OnFocusLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (state.Keyboard.Keys.Any(key => key == Key.Escape))
|
|
|
|
|
Exit?.Invoke();
|
|
|
|
|
base.OnFocusLost(state);
|
|
|
|
|
}
|
2017-02-03 18:12:57 +08:00
|
|
|
|
|
2017-01-30 23:16:55 +08:00
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
|
{
|
2017-02-01 08:00:54 +08:00
|
|
|
|
if (args.Key == Key.Left || args.Key == Key.Right || args.Key == Key.Enter)
|
2017-01-30 23:16:55 +08:00
|
|
|
|
return false;
|
|
|
|
|
return base.OnKeyDown(state, args);
|
|
|
|
|
}
|
2017-01-11 06:43:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|