2022-04-21 04:59:36 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-04-21 04:59:36 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Overlays;
|
2022-04-22 23:01:56 +08:00
|
|
|
using osu.Game.Overlays.Mods;
|
2022-05-03 13:28:58 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2022-04-21 04:59:36 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
{
|
|
|
|
public class ShearedSearchTextBox : CompositeDrawable, IHasCurrentValue<string>
|
|
|
|
{
|
2022-04-22 23:01:56 +08:00
|
|
|
private const float corner_radius = 7;
|
2022-05-03 13:30:38 +08:00
|
|
|
|
2022-05-03 12:25:14 +08:00
|
|
|
private readonly Box background;
|
|
|
|
private readonly SearchTextBox textBox;
|
2022-04-21 04:59:36 +08:00
|
|
|
|
|
|
|
public Bindable<string> Current
|
|
|
|
{
|
2022-05-03 12:25:14 +08:00
|
|
|
get => textBox.Current;
|
|
|
|
set => textBox.Current = value;
|
2022-04-21 04:59:36 +08:00
|
|
|
}
|
|
|
|
|
2022-05-03 12:25:14 +08:00
|
|
|
public bool HoldFocus
|
|
|
|
{
|
|
|
|
get => textBox.HoldFocus;
|
|
|
|
set => textBox.HoldFocus = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void TakeFocus() => textBox.TakeFocus();
|
|
|
|
|
|
|
|
public void KillFocus() => textBox.KillFocus();
|
|
|
|
|
|
|
|
public ShearedSearchTextBox()
|
2022-04-21 04:59:36 +08:00
|
|
|
{
|
2022-05-03 13:30:38 +08:00
|
|
|
Height = 42;
|
|
|
|
Shear = new Vector2(ShearedOverlayContainer.SHEAR, 0);
|
2022-04-21 04:59:36 +08:00
|
|
|
Masking = true;
|
|
|
|
CornerRadius = corner_radius;
|
2022-05-03 13:34:18 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
2022-04-21 04:59:36 +08:00
|
|
|
{
|
2022-05-03 13:34:18 +08:00
|
|
|
background = new Box
|
2022-04-21 04:59:36 +08:00
|
|
|
{
|
2022-05-03 13:34:18 +08:00
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
},
|
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Content = new[]
|
2022-04-21 04:59:36 +08:00
|
|
|
{
|
2022-05-03 13:34:18 +08:00
|
|
|
new Drawable[]
|
2022-04-21 04:59:36 +08:00
|
|
|
{
|
2022-05-03 13:45:17 +08:00
|
|
|
textBox = new InnerSearchTextBox
|
2022-04-21 04:59:36 +08:00
|
|
|
{
|
2022-05-03 13:45:17 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-05-03 13:34:18 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-05-03 13:45:17 +08:00
|
|
|
Size = Vector2.One
|
2022-05-03 13:34:18 +08:00
|
|
|
},
|
2022-05-03 13:48:00 +08:00
|
|
|
new SpriteIcon
|
2022-05-03 13:34:18 +08:00
|
|
|
{
|
2022-05-03 13:48:00 +08:00
|
|
|
Icon = FontAwesome.Solid.Search,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Size = new Vector2(16),
|
|
|
|
Shear = -Shear
|
2022-04-21 04:59:36 +08:00
|
|
|
}
|
2022-05-03 13:30:38 +08:00
|
|
|
}
|
2022-05-03 13:34:18 +08:00
|
|
|
},
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(),
|
2022-05-03 13:48:00 +08:00
|
|
|
new Dimension(GridSizeMode.Absolute, 50),
|
2022-04-21 04:59:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-03 12:25:14 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
{
|
|
|
|
background.Colour = colourProvider.Background3;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool HandleNonPositionalInput => textBox.HandleNonPositionalInput;
|
2022-04-21 04:59:36 +08:00
|
|
|
|
2022-05-03 12:24:48 +08:00
|
|
|
private class InnerSearchTextBox : SearchTextBox
|
2022-04-21 04:59:36 +08:00
|
|
|
{
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
{
|
|
|
|
BackgroundFocused = colourProvider.Background4;
|
|
|
|
BackgroundUnfocused = colourProvider.Background4;
|
2022-05-03 13:28:58 +08:00
|
|
|
|
|
|
|
Placeholder.Font = OsuFont.GetFont(size: CalculatedTextSize, weight: FontWeight.SemiBold);
|
|
|
|
PlaceholderText = CommonStrings.InputSearch;
|
2022-05-03 13:45:17 +08:00
|
|
|
|
|
|
|
CornerRadius = corner_radius;
|
|
|
|
TextContainer.Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0);
|
2022-04-21 04:59:36 +08:00
|
|
|
}
|
|
|
|
|
2022-05-03 13:28:58 +08:00
|
|
|
protected override SpriteText CreatePlaceholder() => new SearchPlaceholder();
|
|
|
|
|
|
|
|
internal class SearchPlaceholder : SpriteText
|
2022-04-21 04:59:36 +08:00
|
|
|
{
|
2022-05-03 13:28:58 +08:00
|
|
|
public override void Show()
|
|
|
|
{
|
|
|
|
this
|
|
|
|
.MoveToY(0, 250, Easing.OutQuint)
|
|
|
|
.FadeIn(250, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Hide()
|
|
|
|
{
|
|
|
|
this
|
|
|
|
.MoveToY(3, 250, Easing.OutQuint)
|
|
|
|
.FadeOut(250, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
2022-04-21 04:59:36 +08:00
|
|
|
|
|
|
|
protected override Drawable GetDrawableCharacter(char c) => new FallingDownContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Child = new OsuSpriteText { Text = c.ToString(), Font = OsuFont.GetFont(size: 20, weight: FontWeight.SemiBold) },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|