2016-10-04 18:41:18 +08:00
|
|
|
|
//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.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Transformations;
|
|
|
|
|
using osu.Game.GameModes.Play;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2016-10-10 16:17:26 +08:00
|
|
|
|
using osu.Framework;
|
2016-10-22 16:50:42 +08:00
|
|
|
|
using osu.Framework.Caching;
|
2016-10-16 20:10:06 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 22:24:14 +08:00
|
|
|
|
protected override void Load(BaseGame game)
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-10-10 16:17:26 +08:00
|
|
|
|
base.Load(game);
|
2016-10-04 18:41:18 +08:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = new Color4(20, 20, 20, 255)
|
|
|
|
|
},
|
|
|
|
|
modeButtons = new FlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2016-10-22 17:05:46 +08:00
|
|
|
|
AutoSizeAxes = Axes.X,
|
2016-10-04 18:41:18 +08:00
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (PlayMode m in Enum.GetValues(typeof(PlayMode)))
|
|
|
|
|
{
|
|
|
|
|
var localMode = m;
|
|
|
|
|
modeButtons.Add(new ToolbarModeButton
|
|
|
|
|
{
|
|
|
|
|
Mode = m,
|
|
|
|
|
Action = delegate
|
|
|
|
|
{
|
|
|
|
|
SetGameMode(localMode);
|
|
|
|
|
OnPlayModeChange?.Invoke(localMode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
Size = new Vector2(modeButtons.Children.Count() * 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();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 18:57:32 +08:00
|
|
|
|
private Cached<Drawable> activeMode = new Cached<Drawable>();
|
2016-10-04 18:41:18 +08:00
|
|
|
|
|
|
|
|
|
protected override void UpdateLayout()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateLayout();
|
|
|
|
|
|
|
|
|
|
if (!activeMode.EnsureValid())
|
2016-10-19 00:53:31 +08:00
|
|
|
|
activeMode.Refresh(() => modeButtonLine.MoveToX(activeButton.DrawPosition.X + activeButton.DrawSize.X / 2 + padding, 200, EasingTypes.OutQuint));
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|