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