2017-01-11 06:43:00 +08:00
|
|
|
|
using System;
|
|
|
|
|
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-01-31 02:43:21 +08:00
|
|
|
|
public bool GrabFocus = false;
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 },
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2017-01-31 02:43:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
if (GrabFocus && !HasFocus && IsVisible)
|
2017-01-31 03:03:05 +08:00
|
|
|
|
{
|
|
|
|
|
var inputManager = Parent;
|
|
|
|
|
while (inputManager != null && !(inputManager is InputManager))
|
|
|
|
|
inputManager = inputManager.Parent;
|
|
|
|
|
if (inputManager != null && (inputManager as InputManager)?.FocusedDrawable == null)
|
|
|
|
|
TriggerFocus();
|
|
|
|
|
}
|
2017-01-31 02:43:21 +08:00
|
|
|
|
base.Update();
|
2017-01-11 06:43:00 +08:00
|
|
|
|
}
|
2017-01-30 23:16:55 +08:00
|
|
|
|
|
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
|
{
|
2017-01-31 02:43:21 +08:00
|
|
|
|
if (args.Key == Key.Left || args.Key == Key.Right
|
|
|
|
|
|| args.Key == Key.Enter || args.Key == Key.Escape)
|
2017-01-30 23:16:55 +08:00
|
|
|
|
return false;
|
|
|
|
|
return base.OnKeyDown(state, args);
|
|
|
|
|
}
|
2017-01-11 06:43:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|