1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 03:22:57 +08:00
osu-lazer/osu.Game/Overlays/Comments/SortTabControl.cs

111 lines
3.3 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;
2019-11-25 10:30:55 +08:00
using osu.Game.Graphics.Sprites;
2019-10-10 17:06:25 +08:00
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
{
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,
2019-10-14 20:34:43 +08:00
Spacing = new Vector2(5, 0),
2019-10-10 17:06:25 +08:00
};
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
{
public SortTabItem(CommentsSortCriteria value)
2019-10-10 17:06:25 +08:00
: base(value)
{
AutoSizeAxes = Axes.Both;
Child = new TabButton(value) { Active = { BindTarget = Active } };
2019-10-10 17:06:25 +08:00
}
protected override void OnActivated()
{
}
2019-10-10 17:06:25 +08:00
protected override void OnDeactivated()
{
}
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
{
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
{
2019-11-25 10:30:55 +08:00
Add(text = new OsuSpriteText
2019-10-10 17:06:25 +08:00
{
2019-10-14 20:34:43 +08:00
Font = OsuFont.GetFont(size: 14),
2019-10-10 17:06:25 +08:00
Text = value.ToString()
});
}
protected override void LoadComplete()
2019-10-10 17:06:25 +08:00
{
base.LoadComplete();
Active.BindValueChanged(active =>
{
updateBackgroundState();
text.Font = text.Font.With(weight: active.NewValue ? FontWeight.Bold : FontWeight.Medium);
text.Colour = active.NewValue ? colours.BlueLighter : Color4.White;
}, true);
2019-10-10 17:06:25 +08:00
}
protected override bool OnHover(HoverEvent e)
2019-10-10 17:06:25 +08:00
{
updateBackgroundState();
return true;
2019-10-10 17:06:25 +08:00
}
protected override void OnHoverLost(HoverLostEvent e) => updateBackgroundState();
private void updateBackgroundState()
2019-10-10 17:06:25 +08:00
{
if (Active.Value || IsHovered)
ShowBackground();
else
HideBackground();
2019-10-10 17:06:25 +08:00
}
}
}
}
public enum CommentsSortCriteria
2019-10-10 17:06:25 +08:00
{
New,
Old,
Top
}
}