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;
|
2016-12-01 13:22:29 +08:00
|
|
|
|
using osu.Framework.Caching;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-12-01 15:05:54 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-12-01 13:22:29 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using osu.Framework.Graphics.Transformations;
|
2016-12-01 17:53:13 +08:00
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2016-12-01 13:22:29 +08:00
|
|
|
|
using osu.Game.Modes;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-01-10 06:18:47 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
|
2016-12-01 13:22:29 +08:00
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
|
|
|
|
class ToolbarModeSelector : Container
|
|
|
|
|
{
|
|
|
|
|
const float padding = 10;
|
|
|
|
|
|
|
|
|
|
private FlowContainer modeButtons;
|
2016-12-01 18:15:34 +08:00
|
|
|
|
private Drawable modeButtonLine;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
private ToolbarModeButton activeButton;
|
|
|
|
|
|
|
|
|
|
public Action<PlayMode> OnPlayModeChange;
|
|
|
|
|
|
|
|
|
|
public ToolbarModeSelector()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2016-12-01 17:53:13 +08:00
|
|
|
|
new OpaqueBackground(),
|
2016-10-04 18:41:18 +08:00
|
|
|
|
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,
|
2016-12-01 15:05:54 +08:00
|
|
|
|
Padding = new MarginPadding { Left = 10, Right = 10 },
|
2016-10-04 18:41:18 +08:00
|
|
|
|
},
|
2016-12-01 18:15:34 +08:00
|
|
|
|
modeButtonLine = new Container
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Size = new Vector2(0.3f, 3),
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2016-12-01 16:45:21 +08:00
|
|
|
|
Origin = Anchor.TopLeft,
|
2016-12-01 18:15:34 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
EdgeEffect = new EdgeEffect
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
2017-01-10 06:18:47 +08:00
|
|
|
|
Colour = OsuColor.ToolbarModeButtonIconActiveGlow,
|
2016-12-01 18:15:34 +08:00
|
|
|
|
Radius = 15,
|
|
|
|
|
Roundness = 15,
|
|
|
|
|
},
|
|
|
|
|
Children = new []
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-13 01:34:36 +08:00
|
|
|
|
int amountButtons = 0;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
foreach (PlayMode m in Enum.GetValues(typeof(PlayMode)))
|
|
|
|
|
{
|
2016-11-13 01:34:36 +08:00
|
|
|
|
++amountButtons;
|
|
|
|
|
|
2016-10-04 18:41:18 +08:00
|
|
|
|
var localMode = m;
|
|
|
|
|
modeButtons.Add(new ToolbarModeButton
|
|
|
|
|
{
|
|
|
|
|
Mode = m,
|
|
|
|
|
Action = delegate
|
|
|
|
|
{
|
|
|
|
|
SetGameMode(localMode);
|
|
|
|
|
OnPlayModeChange?.Invoke(localMode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-12-01 15:05:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2016-10-04 18:41:18 +08:00
|
|
|
|
|
2016-12-01 15:05:54 +08:00
|
|
|
|
Size = new Vector2(modeButtons.DrawSize.X, 1);
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-11-01 23:53:13 +08:00
|
|
|
|
private Cached activeMode = new Cached();
|
2016-10-04 18:41:18 +08:00
|
|
|
|
|
2016-12-03 21:40:15 +08:00
|
|
|
|
protected override void UpdateAfterChildren()
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-12-03 21:40:15 +08:00
|
|
|
|
base.UpdateAfterChildren();
|
2016-10-04 18:41:18 +08:00
|
|
|
|
|
|
|
|
|
if (!activeMode.EnsureValid())
|
2016-12-01 16:45:21 +08:00
|
|
|
|
activeMode.Refresh(() => modeButtonLine.MoveToX(activeButton.DrawPosition.X, 200, EasingTypes.OutQuint));
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|