1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 13:07:24 +08:00
osu-lazer/osu.Game/Overlays/Comments/SortTabControl.cs

107 lines
3.1 KiB
C#
Raw Normal View History

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-14 20:32:41 +08:00
public class SortTabControl : OsuTabControl<CommentsSortCriteria>
2019-10-10 17:06:25 +08:00
{
private const int spacing = 5;
protected override Dropdown<CommentsSortCriteria> CreateDropdown() => null;
2019-10-10 17:06:25 +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),
};
2019-10-14 20:32:41 +08:00
public SortTabControl()
2019-10-10 17:06:25 +08:00
{
AutoSizeAxes = Axes.Both;
}
private class SortTabItem : TabItem<CommentsSortCriteria>
2019-10-10 17:06:25 +08:00
{
2019-10-14 20:34:16 +08:00
private readonly TabButton button;
2019-10-10 17:06:25 +08:00
public SortTabItem(CommentsSortCriteria value)
2019-10-10 17:06:25 +08:00
: base(value)
{
AutoSizeAxes = Axes.Both;
2019-10-14 20:34:16 +08:00
Child = button = new TabButton(value)
2019-10-10 17:06:25 +08:00
{
Active = { BindTarget = Active }
};
}
2019-10-14 20:34:16 +08:00
protected override void OnActivated() => button.Activate();
2019-10-10 17:06:25 +08:00
2019-10-14 20:34:16 +08:00
protected override void OnDeactivated() => button.Deactivate();
2019-10-10 17:06:25 +08:00
2019-10-14 20:34:16 +08:00
private class TabButton : HeaderButton
2019-10-10 17:06:25 +08:00
{
private const int text_size = 14;
public readonly BindableBool Active = new BindableBool();
[Resolved]
private OsuColour colours { get; set; }
private readonly SpriteText text;
2019-10-14 20:34:16 +08:00
public TabButton(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);
}
}
}
}
public enum CommentsSortCriteria
2019-10-10 17:06:25 +08:00
{
New,
Old,
Top
}
}