1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

Use existing PageTabControl for layout

This commit is contained in:
Andrei Zavatski 2019-08-12 13:16:57 +03:00
parent fc521ac93b
commit ba49a4c2da

View File

@ -8,25 +8,24 @@ using osu.Framework.Graphics.Containers;
using osuTK; using osuTK;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Sprites;
using osu.Framework.Extensions;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Framework.Input.Events;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
using osu.Framework.Input.Events;
namespace osu.Game.Overlays.BeatmapSet namespace osu.Game.Overlays.BeatmapSet
{ {
public class LeaderboardScopeSelector : TabControl<BeatmapLeaderboardScope> public class LeaderboardScopeSelector : PageTabControl<BeatmapLeaderboardScope>
{ {
protected override bool AddAllItemsIfEnum => false;
protected override Dropdown<BeatmapLeaderboardScope> CreateDropdown() => null; protected override Dropdown<BeatmapLeaderboardScope> CreateDropdown() => null;
protected override TabItem<BeatmapLeaderboardScope> CreateTabItem(BeatmapLeaderboardScope value) => new ScopeSelectorTabItem(value); protected override TabItem<BeatmapLeaderboardScope> CreateTabItem(BeatmapLeaderboardScope value) => new ScopeSelectorTabItem(value);
public LeaderboardScopeSelector() public LeaderboardScopeSelector()
{ {
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AddItem(BeatmapLeaderboardScope.Global); AddItem(BeatmapLeaderboardScope.Global);
@ -42,57 +41,31 @@ namespace osu.Game.Overlays.BeatmapSet
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.BottomCentre,
Origin = Anchor.TopCentre, Origin = Anchor.BottomCentre,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Spacing = new Vector2(20, 0), Spacing = new Vector2(20, 0),
}; };
private class ScopeSelectorTabItem : TabItem<BeatmapLeaderboardScope> private class ScopeSelectorTabItem : PageTabItem
{ {
private const float transition_duration = 100;
private readonly Box box;
protected readonly OsuSpriteText Text;
public ScopeSelectorTabItem(BeatmapLeaderboardScope value) public ScopeSelectorTabItem(BeatmapLeaderboardScope value)
: base(value) : base(value)
{ {
AutoSizeAxes = Axes.Both; Text.Font = OsuFont.GetFont(size: 16);
Children = new Drawable[]
{
Text = new OsuSpriteText
{
Margin = new MarginPadding { Bottom = 8 },
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
Text = value.GetDescription(),
Font = OsuFont.GetFont(weight: FontWeight.Regular),
},
box = new Box
{
RelativeSizeAxes = Axes.X,
Height = 5,
Scale = new Vector2(1f, 0f),
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
},
new HoverClickSounds()
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
box.Colour = colours.Blue; BoxColour = colours.Blue;
} }
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
Text.FadeColour(Color4.LightSkyBlue); Text.FadeColour(BoxColour);
return base.OnHover(e); return base.OnHover(e);
} }
@ -103,18 +76,6 @@ namespace osu.Game.Overlays.BeatmapSet
Text.FadeColour(Color4.White); Text.FadeColour(Color4.White);
} }
protected override void OnActivated()
{
box.ScaleTo(new Vector2(1f), transition_duration);
Text.Font = Text.Font.With(weight: FontWeight.Black);
}
protected override void OnDeactivated()
{
box.ScaleTo(new Vector2(1f, 0f), transition_duration);
Text.Font = Text.Font.With(weight: FontWeight.Regular);
}
} }
private class Line : GridContainer private class Line : GridContainer