mirror of
https://github.com/osukey/osukey.git
synced 2025-06-28 06:38:00 +09:00
Rename button classes to make more sense
This commit is contained in:
parent
db58f5de8e
commit
ee4f5c0e79
@ -10,7 +10,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
public class TestScenePageSelector : OsuTestScene
|
public class TestScenePageSelector : OsuTestScene
|
||||||
{
|
{
|
||||||
private readonly PageSelector pageSelector;
|
private readonly PageSelector pageSelector;
|
||||||
private readonly DrawablePage drawablePage;
|
private readonly PageSelectorPageButton pageSelectorPageButton;
|
||||||
|
|
||||||
public TestScenePageSelector()
|
public TestScenePageSelector()
|
||||||
{
|
{
|
||||||
@ -21,7 +21,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
},
|
},
|
||||||
drawablePage = new DrawablePage(1234)
|
pageSelectorPageButton = new PageSelectorPageButton(1234)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopCentre,
|
Anchor = Anchor.TopCentre,
|
||||||
Origin = Anchor.TopCentre,
|
Origin = Anchor.TopCentre,
|
||||||
@ -61,8 +61,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestDrawablePage()
|
public void TestDrawablePage()
|
||||||
{
|
{
|
||||||
AddStep("Select", () => drawablePage.Selected = true);
|
AddStep("Select", () => pageSelectorPageButton.Selected = true);
|
||||||
AddStep("Deselect", () => drawablePage.Selected = false);
|
AddStep("Deselect", () => pageSelectorPageButton.Selected = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMaxPages(int maxPages) => pageSelector.MaxPages.Value = maxPages;
|
private void setMaxPages(int maxPages) => pageSelector.MaxPages.Value = maxPages;
|
||||||
|
@ -13,10 +13,10 @@ namespace osu.Game.Graphics.UserInterface.PageSelector
|
|||||||
public readonly BindableInt CurrentPage = new BindableInt(1);
|
public readonly BindableInt CurrentPage = new BindableInt(1);
|
||||||
public readonly BindableInt MaxPages = new BindableInt(1);
|
public readonly BindableInt MaxPages = new BindableInt(1);
|
||||||
|
|
||||||
private readonly FillFlowContainer<DrawablePage> itemsFlow;
|
private readonly FillFlowContainer<PageSelectorPageButton> itemsFlow;
|
||||||
|
|
||||||
private readonly PageSelectorButton previousPageButton;
|
private readonly PageSelectorPrevNextButton previousPageButton;
|
||||||
private readonly PageSelectorButton nextPageButton;
|
private readonly PageSelectorPrevNextButton nextPageButton;
|
||||||
|
|
||||||
public PageSelector()
|
public PageSelector()
|
||||||
{
|
{
|
||||||
@ -28,16 +28,16 @@ namespace osu.Game.Graphics.UserInterface.PageSelector
|
|||||||
Direction = FillDirection.Horizontal,
|
Direction = FillDirection.Horizontal,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
previousPageButton = new PageSelectorButton(false, "prev")
|
previousPageButton = new PageSelectorPrevNextButton(false, "prev")
|
||||||
{
|
{
|
||||||
Action = () => CurrentPage.Value -= 1,
|
Action = () => CurrentPage.Value -= 1,
|
||||||
},
|
},
|
||||||
itemsFlow = new FillFlowContainer<DrawablePage>
|
itemsFlow = new FillFlowContainer<PageSelectorPageButton>
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Direction = FillDirection.Horizontal,
|
Direction = FillDirection.Horizontal,
|
||||||
},
|
},
|
||||||
nextPageButton = new PageSelectorButton(true, "next")
|
nextPageButton = new PageSelectorPrevNextButton(true, "next")
|
||||||
{
|
{
|
||||||
Action = () => CurrentPage.Value += 1
|
Action = () => CurrentPage.Value += 1
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ namespace osu.Game.Graphics.UserInterface.PageSelector
|
|||||||
nextPageButton.Enabled.Value = newPage != maxPages;
|
nextPageButton.Enabled.Value = newPage != maxPages;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDrawablePage(int page) => itemsFlow.Add(new DrawablePage(page)
|
private void addDrawablePage(int page) => itemsFlow.Add(new PageSelectorPageButton(page)
|
||||||
{
|
{
|
||||||
Action = () => CurrentPage.Value = page,
|
Action = () => CurrentPage.Value = page,
|
||||||
});
|
});
|
||||||
|
@ -1,88 +1,72 @@
|
|||||||
// 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.Allocation;
|
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Framework.Input.Events;
|
||||||
using osuTK;
|
using JetBrains.Annotations;
|
||||||
using osuTK.Graphics;
|
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface.PageSelector
|
namespace osu.Game.Graphics.UserInterface.PageSelector
|
||||||
{
|
{
|
||||||
public class PageSelectorButton : PageSelectorItem
|
public abstract class PageSelectorButton : OsuClickableContainer
|
||||||
{
|
{
|
||||||
private readonly string text;
|
protected const int DURATION = 200;
|
||||||
|
|
||||||
private Box fadeBox;
|
[Resolved]
|
||||||
private SpriteIcon icon;
|
protected OsuColour Colours { get; private set; }
|
||||||
private OsuSpriteText name;
|
|
||||||
|
|
||||||
private readonly Anchor alignment;
|
protected Box Background;
|
||||||
|
|
||||||
public PageSelectorButton(bool rightAligned, string text)
|
public CircularContainer CircularContent { get; private set; }
|
||||||
|
|
||||||
|
protected PageSelectorButton()
|
||||||
{
|
{
|
||||||
this.text = text;
|
AutoSizeAxes = Axes.X;
|
||||||
alignment = rightAligned ? Anchor.x0 : Anchor.x2;
|
Height = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateContent() => new Container
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Y,
|
|
||||||
AutoSizeAxes = Axes.X,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
new FillFlowContainer
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
Background.Colour = Colours.GreySeaFoamDark;
|
Add(CircularContent = new CircularContainer
|
||||||
name.Colour = icon.Colour = Colours.Lime;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
CircularContent.Add(fadeBox = new Box
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Y,
|
||||||
Colour = Color4.Black.Opacity(100)
|
AutoSizeAxes = Axes.X,
|
||||||
|
Masking = true,
|
||||||
|
Children = new[]
|
||||||
|
{
|
||||||
|
Background = new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
},
|
||||||
|
CreateContent().With(content =>
|
||||||
|
{
|
||||||
|
content.Anchor = Anchor.Centre;
|
||||||
|
content.Origin = Anchor.Centre;
|
||||||
|
content.Margin = new MarginPadding { Horizontal = 10 };
|
||||||
|
})
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Enabled.BindValueChanged(enabled => fadeBox.FadeTo(enabled.NewValue ? 0 : 1, DURATION), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateHoverState() => Background.FadeColour(IsHovered ? Colours.GreySeaFoam : Colours.GreySeaFoamDark, DURATION, Easing.OutQuint);
|
[NotNull]
|
||||||
|
protected abstract Drawable CreateContent();
|
||||||
|
|
||||||
|
protected override bool OnHover(HoverEvent e)
|
||||||
|
{
|
||||||
|
UpdateHoverState();
|
||||||
|
return base.OnHover(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
|
{
|
||||||
|
base.OnHoverLost(e);
|
||||||
|
UpdateHoverState();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void UpdateHoverState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
// 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.Allocation;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
|
||||||
using osu.Game.Graphics.Containers;
|
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface.PageSelector
|
|
||||||
{
|
|
||||||
public abstract class PageSelectorItem : OsuClickableContainer
|
|
||||||
{
|
|
||||||
protected const int DURATION = 200;
|
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
protected OsuColour Colours { get; private set; }
|
|
||||||
|
|
||||||
protected Box Background;
|
|
||||||
|
|
||||||
public CircularContainer CircularContent { get; private set; }
|
|
||||||
|
|
||||||
protected PageSelectorItem()
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.X;
|
|
||||||
Height = 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
Add(CircularContent = new CircularContainer
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Y,
|
|
||||||
AutoSizeAxes = Axes.X,
|
|
||||||
Masking = true,
|
|
||||||
Children = new[]
|
|
||||||
{
|
|
||||||
Background = new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both
|
|
||||||
},
|
|
||||||
CreateContent().With(content =>
|
|
||||||
{
|
|
||||||
content.Anchor = Anchor.Centre;
|
|
||||||
content.Origin = Anchor.Centre;
|
|
||||||
content.Margin = new MarginPadding { Horizontal = 10 };
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[NotNull]
|
|
||||||
protected abstract Drawable CreateContent();
|
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
|
||||||
{
|
|
||||||
UpdateHoverState();
|
|
||||||
return base.OnHover(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e)
|
|
||||||
{
|
|
||||||
base.OnHoverLost(e);
|
|
||||||
UpdateHoverState();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void UpdateHoverState();
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,7 +9,7 @@ using osu.Game.Graphics.Sprites;
|
|||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface.PageSelector
|
namespace osu.Game.Graphics.UserInterface.PageSelector
|
||||||
{
|
{
|
||||||
public class DrawablePage : PageSelectorItem
|
public class PageSelectorPageButton : PageSelectorButton
|
||||||
{
|
{
|
||||||
private readonly BindableBool selected = new BindableBool();
|
private readonly BindableBool selected = new BindableBool();
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ namespace osu.Game.Graphics.UserInterface.PageSelector
|
|||||||
|
|
||||||
private OsuSpriteText text;
|
private OsuSpriteText text;
|
||||||
|
|
||||||
public DrawablePage(int page)
|
public PageSelectorPageButton(int page)
|
||||||
{
|
{
|
||||||
Page = page;
|
Page = page;
|
||||||
|
|
@ -0,0 +1,88 @@
|
|||||||
|
// 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.Allocation;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.UserInterface.PageSelector
|
||||||
|
{
|
||||||
|
public class PageSelectorPrevNextButton : PageSelectorButton
|
||||||
|
{
|
||||||
|
private readonly string text;
|
||||||
|
|
||||||
|
private Box fadeBox;
|
||||||
|
private SpriteIcon icon;
|
||||||
|
private OsuSpriteText name;
|
||||||
|
|
||||||
|
private readonly Anchor alignment;
|
||||||
|
|
||||||
|
public PageSelectorPrevNextButton(bool rightAligned, string text)
|
||||||
|
{
|
||||||
|
this.text = text;
|
||||||
|
alignment = rightAligned ? Anchor.x0 : Anchor.x2;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Drawable CreateContent() => new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Y,
|
||||||
|
AutoSizeAxes = Axes.X,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
Background.Colour = Colours.GreySeaFoamDark;
|
||||||
|
name.Colour = icon.Colour = Colours.Lime;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateHoverState() => Background.FadeColour(IsHovered ? Colours.GreySeaFoam : Colours.GreySeaFoamDark, DURATION, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user