2019-10-10 17:06:25 +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.
|
|
|
|
|
|
|
|
|
|
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 osuTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Comments
|
|
|
|
|
{
|
2019-10-10 20:56:08 +08:00
|
|
|
|
public class SortSelector : OsuTabControl<CommentsSortCriteria>
|
2019-10-10 17:06:25 +08:00
|
|
|
|
{
|
|
|
|
|
private const int spacing = 5;
|
|
|
|
|
|
2019-10-10 20:56:08 +08:00
|
|
|
|
protected override Dropdown<CommentsSortCriteria> CreateDropdown() => null;
|
2019-10-10 17:06:25 +08:00
|
|
|
|
|
2019-10-10 20:56:08 +08:00
|
|
|
|
protected override TabItem<CommentsSortCriteria> CreateTabItem(CommentsSortCriteria value) => new SortTabItem(value);
|
2019-10-10 17:06:25 +08:00
|
|
|
|
|
|
|
|
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(spacing, 0),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public SortSelector()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-10 20:56:08 +08:00
|
|
|
|
private class SortTabItem : TabItem<CommentsSortCriteria>
|
2019-10-10 17:06:25 +08:00
|
|
|
|
{
|
|
|
|
|
private readonly TabContent content;
|
|
|
|
|
|
2019-10-10 20:56:08 +08:00
|
|
|
|
public SortTabItem(CommentsSortCriteria value)
|
2019-10-10 17:06:25 +08:00
|
|
|
|
: base(value)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Child = content = new TabContent(value)
|
|
|
|
|
{
|
|
|
|
|
Active = { BindTarget = Active }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnActivated() => content.Activate();
|
|
|
|
|
|
|
|
|
|
protected override void OnDeactivated() => content.Deactivate();
|
|
|
|
|
|
|
|
|
|
private class TabContent : HeaderButton
|
|
|
|
|
{
|
|
|
|
|
private const int text_size = 14;
|
|
|
|
|
|
|
|
|
|
public readonly BindableBool Active = new BindableBool();
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
|
|
private readonly SpriteText text;
|
|
|
|
|
|
2019-10-10 20:56:08 +08:00
|
|
|
|
public TabContent(CommentsSortCriteria value)
|
2019-10-10 17:06:25 +08:00
|
|
|
|
{
|
|
|
|
|
Add(text = new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = OsuFont.GetFont(size: text_size),
|
|
|
|
|
Text = value.ToString()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Activate()
|
|
|
|
|
{
|
2019-10-14 20:32:16 +08:00
|
|
|
|
ShowBackground();
|
2019-10-10 17:06:25 +08:00
|
|
|
|
text.Font = text.Font.With(weight: FontWeight.Bold);
|
|
|
|
|
text.Colour = colours.BlueLighter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Deactivate()
|
|
|
|
|
{
|
|
|
|
|
if (!IsHovered)
|
2019-10-14 20:32:16 +08:00
|
|
|
|
HideBackground();
|
2019-10-10 17:06:25 +08:00
|
|
|
|
|
|
|
|
|
text.Font = text.Font.With(weight: FontWeight.Medium);
|
|
|
|
|
text.Colour = Color4.White;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (!Active.Value) base.OnHoverLost(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-10 20:56:08 +08:00
|
|
|
|
public enum CommentsSortCriteria
|
2019-10-10 17:06:25 +08:00
|
|
|
|
{
|
|
|
|
|
New,
|
|
|
|
|
Old,
|
|
|
|
|
Top
|
|
|
|
|
}
|
|
|
|
|
}
|