mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 16:59:53 +09:00
Move toolbar to own namespace.
This commit is contained in:
100
osu.Game/Overlays/Toolbar/ToolbarModeSelector.cs
Normal file
100
osu.Game/Overlays/Toolbar/ToolbarModeSelector.cs
Normal file
@ -0,0 +1,100 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Caching;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Game.Modes;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Toolbar
|
||||
{
|
||||
class ToolbarModeSelector : Container
|
||||
{
|
||||
const float padding = 10;
|
||||
|
||||
private FlowContainer modeButtons;
|
||||
private Box modeButtonLine;
|
||||
private ToolbarModeButton activeButton;
|
||||
|
||||
public Action<PlayMode> OnPlayModeChange;
|
||||
|
||||
public ToolbarModeSelector()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = new Color4(20, 20, 20, 255)
|
||||
},
|
||||
modeButtons = new FlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
AutoSizeAxes = Axes.X,
|
||||
Direction = FlowDirection.HorizontalOnly,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
},
|
||||
modeButtonLine = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Size = new Vector2(0.3f, 3),
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.TopCentre,
|
||||
Colour = Color4.White
|
||||
}
|
||||
};
|
||||
|
||||
int amountButtons = 0;
|
||||
foreach (PlayMode m in Enum.GetValues(typeof(PlayMode)))
|
||||
{
|
||||
++amountButtons;
|
||||
|
||||
var localMode = m;
|
||||
modeButtons.Add(new ToolbarModeButton
|
||||
{
|
||||
Mode = m,
|
||||
Action = delegate
|
||||
{
|
||||
SetGameMode(localMode);
|
||||
OnPlayModeChange?.Invoke(localMode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// We need to set the size within LoadComplete, because
|
||||
Size = new Vector2(amountButtons * ToolbarButton.WIDTH + padding * 2, 1);
|
||||
}
|
||||
|
||||
public void SetGameMode(PlayMode mode)
|
||||
{
|
||||
foreach (ToolbarModeButton m in modeButtons.Children.Cast<ToolbarModeButton>())
|
||||
{
|
||||
bool isActive = m.Mode == mode;
|
||||
m.Active = isActive;
|
||||
if (isActive)
|
||||
activeButton = m;
|
||||
}
|
||||
|
||||
activeMode.Invalidate();
|
||||
}
|
||||
|
||||
private Cached activeMode = new Cached();
|
||||
|
||||
protected override void UpdateLayout()
|
||||
{
|
||||
base.UpdateLayout();
|
||||
|
||||
if (!activeMode.EnsureValid())
|
||||
activeMode.Refresh(() => modeButtonLine.MoveToX(activeButton.DrawPosition.X + activeButton.DrawSize.X / 2 + padding, 200, EasingTypes.OutQuint));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user