Clean up unnecessary complexity

This commit is contained in:
Dean Herbert 2022-01-04 16:58:32 +09:00
parent 1c899e4402
commit db58f5de8e
3 changed files with 56 additions and 44 deletions

View File

@ -15,20 +15,16 @@ namespace osu.Game.Graphics.UserInterface.PageSelector
public bool Selected public bool Selected
{ {
get => selected.Value;
set => selected.Value = value; set => selected.Value = value;
} }
public int Page { get; private set; } public int Page { get; }
private OsuSpriteText text; private OsuSpriteText text;
public DrawablePage(int page) public DrawablePage(int page)
{ {
Page = page; Page = page;
text.Text = page.ToString();
Background.Alpha = 0;
Action = () => Action = () =>
{ {
@ -40,12 +36,14 @@ namespace osu.Game.Graphics.UserInterface.PageSelector
protected override Drawable CreateContent() => text = new OsuSpriteText protected override Drawable CreateContent() => text = new OsuSpriteText
{ {
Font = OsuFont.GetFont(size: 12), Font = OsuFont.GetFont(size: 12),
Text = Page.ToString(),
}; };
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Background.Colour = Colours.Lime; Background.Colour = Colours.Lime;
Background.Alpha = 0;
} }
protected override void LoadComplete() protected override void LoadComplete()

View File

@ -1,61 +1,64 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Game.Graphics.Sprites; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osuTK.Graphics; using osu.Game.Graphics.Sprites;
using osuTK; using osuTK;
using osu.Framework.Extensions.IEnumerableExtensions; using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterface.PageSelector namespace osu.Game.Graphics.UserInterface.PageSelector
{ {
public class PageSelectorButton : PageSelectorItem public class PageSelectorButton : PageSelectorItem
{ {
private readonly Box fadeBox; private readonly string text;
private Box fadeBox;
private SpriteIcon icon; private SpriteIcon icon;
private OsuSpriteText name; private OsuSpriteText name;
private FillFlowContainer buttonContent;
private readonly Anchor alignment;
public PageSelectorButton(bool rightAligned, string text) public PageSelectorButton(bool rightAligned, string text)
{ {
Add(fadeBox = new Box this.text = text;
{ alignment = rightAligned ? Anchor.x0 : Anchor.x2;
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(100)
});
var alignment = rightAligned ? Anchor.x0 : Anchor.x2;
buttonContent.ForEach(drawable =>
{
drawable.Anchor = Anchor.y1 | alignment;
drawable.Origin = Anchor.y1 | alignment;
});
icon.Icon = alignment == Anchor.x2 ? FontAwesome.Solid.ChevronLeft : FontAwesome.Solid.ChevronRight;
name.Text = text.ToUpper();
} }
protected override Drawable CreateContent() => buttonContent = new FillFlowContainer protected override Drawable CreateContent() => new Container
{ {
AutoSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal, AutoSizeAxes = Axes.X,
Spacing = new Vector2(3, 0),
Children = new Drawable[] Children = new Drawable[]
{ {
name = new OsuSpriteText new FillFlowContainer
{ {
Font = OsuFont.GetFont(size: 12), AutoSizeAxes = Axes.Both,
}, Direction = FillDirection.Horizontal,
icon = new SpriteIcon Anchor = Anchor.Centre,
{ Origin = Anchor.Centre,
Size = new Vector2(8), Spacing = new Vector2(3, 0),
Children = new Drawable[]
{
name = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 12),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = text.ToUpper(),
},
icon = new SpriteIcon
{
Icon = alignment == Anchor.x2 ? FontAwesome.Solid.ChevronLeft : FontAwesome.Solid.ChevronRight,
Size = new Vector2(8),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
}
}, },
} }
}; };
@ -70,6 +73,13 @@ namespace osu.Game.Graphics.UserInterface.PageSelector
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
CircularContent.Add(fadeBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black.Opacity(100)
});
Enabled.BindValueChanged(enabled => fadeBox.FadeTo(enabled.NewValue ? 0 : 1, DURATION), true); Enabled.BindValueChanged(enabled => fadeBox.FadeTo(enabled.NewValue ? 0 : 1, DURATION), true);
} }

View File

@ -18,16 +18,20 @@ namespace osu.Game.Graphics.UserInterface.PageSelector
[Resolved] [Resolved]
protected OsuColour Colours { get; private set; } protected OsuColour Colours { get; private set; }
protected override Container<Drawable> Content => content; protected Box Background;
protected readonly Box Background; public CircularContainer CircularContent { get; private set; }
private readonly CircularContainer content;
protected PageSelectorItem() protected PageSelectorItem()
{ {
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;
Height = 20; Height = 20;
base.Content.Add(content = new CircularContainer }
[BackgroundDependencyLoader]
private void load()
{
Add(CircularContent = new CircularContainer
{ {
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X, AutoSizeAxes = Axes.X,