2020-02-16 23:20:53 +00: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 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-02-16 23:20:53 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osu.Game.Overlays.Comments;
|
|
|
|
|
using JetBrains.Annotations;
|
2020-02-24 02:47:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Extensions;
|
2021-02-22 08:14:00 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2021-06-16 07:21:36 +00:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class OverlaySortTabControl<T> : CompositeDrawable, IHasCurrentValue<T>
|
|
|
|
|
{
|
2022-09-15 00:58:32 +00:00
|
|
|
|
public TabControl<T> TabControl { get; }
|
|
|
|
|
|
2020-02-16 23:20:53 +00:00
|
|
|
|
private readonly BindableWithCurrent<T> current = new BindableWithCurrent<T>();
|
|
|
|
|
|
|
|
|
|
public Bindable<T> Current
|
|
|
|
|
{
|
|
|
|
|
get => current.Current;
|
|
|
|
|
set => current.Current = value;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-22 08:14:00 +00:00
|
|
|
|
public LocalisableString Title
|
2020-07-12 22:22:05 +00:00
|
|
|
|
{
|
|
|
|
|
get => text.Text;
|
|
|
|
|
set => text.Text = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
|
|
2020-02-16 23:20:53 +00:00
|
|
|
|
public OverlaySortTabControl()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
AddInternal(new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(10, 0),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-07-12 22:22:05 +00:00
|
|
|
|
text = new OsuSpriteText
|
2020-02-16 23:20:53 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
2020-07-12 22:22:05 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
|
2021-06-16 07:21:36 +00:00
|
|
|
|
Text = SortStrings.Default
|
2020-02-16 23:20:53 +00:00
|
|
|
|
},
|
2022-09-15 00:58:32 +00:00
|
|
|
|
TabControl = CreateControl().With(c =>
|
2020-02-16 23:20:53 +00:00
|
|
|
|
{
|
|
|
|
|
c.Anchor = Anchor.CentreLeft;
|
|
|
|
|
c.Origin = Anchor.CentreLeft;
|
|
|
|
|
c.Current = current;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NotNull]
|
|
|
|
|
protected virtual SortTabControl CreateControl() => new SortTabControl();
|
|
|
|
|
|
|
|
|
|
protected class SortTabControl : OsuTabControl<T>
|
|
|
|
|
{
|
|
|
|
|
protected override Dropdown<T> CreateDropdown() => null;
|
|
|
|
|
|
|
|
|
|
protected override TabItem<T> CreateTabItem(T value) => new SortTabItem(value);
|
|
|
|
|
|
|
|
|
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(5, 0),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public SortTabControl()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
}
|
2020-02-17 19:32:58 +00:00
|
|
|
|
}
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
protected class SortTabItem : TabItem<T>
|
|
|
|
|
{
|
|
|
|
|
public SortTabItem(T value)
|
|
|
|
|
: base(value)
|
2020-02-16 23:20:53 +00:00
|
|
|
|
{
|
2020-02-17 19:32:58 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Child = CreateTabButton(value);
|
|
|
|
|
}
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
[NotNull]
|
|
|
|
|
protected virtual TabButton CreateTabButton(T value) => new TabButton(value)
|
|
|
|
|
{
|
|
|
|
|
Active = { BindTarget = Active }
|
|
|
|
|
};
|
2020-02-17 00:38:14 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
protected override void OnActivated()
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
protected override void OnDeactivated()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
protected class TabButton : HeaderButton
|
|
|
|
|
{
|
|
|
|
|
public readonly BindableBool Active = new BindableBool();
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
2020-02-17 00:38:14 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
protected virtual Color4 ContentColour
|
|
|
|
|
{
|
|
|
|
|
set => text.Colour = value;
|
|
|
|
|
}
|
2020-02-17 00:38:14 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OverlayColourProvider colourProvider { get; set; }
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
private readonly SpriteText text;
|
|
|
|
|
private readonly FillFlowContainer content;
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
public TabButton(T value)
|
|
|
|
|
{
|
|
|
|
|
base.Content.Add(content = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(3, 0),
|
|
|
|
|
Children = new Drawable[]
|
2020-02-16 23:20:53 +00:00
|
|
|
|
{
|
2020-02-17 19:32:58 +00:00
|
|
|
|
text = new OsuSpriteText
|
2020-02-16 23:20:53 +00:00
|
|
|
|
{
|
2020-02-17 19:32:58 +00:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2020-07-12 22:22:05 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
|
2021-06-16 06:58:07 +00:00
|
|
|
|
Text = (value as Enum)?.GetLocalisableDescription() ?? value.ToString()
|
2020-02-17 19:32:58 +00:00
|
|
|
|
}
|
2020-02-16 23:20:53 +00:00
|
|
|
|
}
|
2020-02-17 19:32:58 +00:00
|
|
|
|
});
|
2021-06-18 12:00:08 +00:00
|
|
|
|
|
2022-04-28 08:30:24 +00:00
|
|
|
|
AddInternal(new HoverClickSounds(HoverSampleSet.TabSelect));
|
2020-02-17 19:32:58 +00:00
|
|
|
|
}
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
Active.BindValueChanged(_ => UpdateState(), true);
|
|
|
|
|
}
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
|
|
|
|
UpdateState();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e) => UpdateState();
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
protected virtual void UpdateState()
|
|
|
|
|
{
|
|
|
|
|
if (Active.Value || IsHovered)
|
|
|
|
|
ShowBackground();
|
|
|
|
|
else
|
|
|
|
|
HideBackground();
|
2020-02-16 23:20:53 +00:00
|
|
|
|
|
2020-02-17 19:32:58 +00:00
|
|
|
|
ContentColour = Active.Value && !IsHovered ? colourProvider.Light1 : Color4.White;
|
2020-02-17 00:38:14 +00:00
|
|
|
|
|
2020-07-12 22:22:05 +00:00
|
|
|
|
text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.SemiBold);
|
2020-02-16 23:20:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|