2017-02-07 04:59:30 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-10-04 10:41:18 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2016-12-01 05:22:29 +00:00
|
|
|
|
using osu.Framework.Caching;
|
2016-10-04 10:41:18 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-12-01 07:05:54 +00:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-12-01 05:22:29 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-10-04 10:41:18 +00:00
|
|
|
|
using osu.Framework.Graphics.Transformations;
|
2016-12-01 09:53:13 +00:00
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2016-12-01 05:22:29 +00:00
|
|
|
|
using osu.Game.Modes;
|
2016-10-04 10:41:18 +00:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-01-09 22:18:47 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2016-10-04 10:41:18 +00:00
|
|
|
|
|
2016-12-01 05:22:29 +00:00
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
2016-10-04 10:41:18 +00:00
|
|
|
|
{
|
|
|
|
|
class ToolbarModeSelector : Container
|
|
|
|
|
{
|
|
|
|
|
const float padding = 10;
|
|
|
|
|
|
|
|
|
|
private FlowContainer modeButtons;
|
2016-12-01 10:15:34 +00:00
|
|
|
|
private Drawable modeButtonLine;
|
2016-10-04 10:41:18 +00:00
|
|
|
|
private ToolbarModeButton activeButton;
|
|
|
|
|
|
|
|
|
|
public Action<PlayMode> OnPlayModeChange;
|
|
|
|
|
|
|
|
|
|
public ToolbarModeSelector()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2016-12-01 09:53:13 +00:00
|
|
|
|
new OpaqueBackground(),
|
2016-10-04 10:41:18 +00:00
|
|
|
|
modeButtons = new FlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2016-10-22 09:05:46 +00:00
|
|
|
|
AutoSizeAxes = Axes.X,
|
2016-10-04 10:41:18 +00:00
|
|
|
|
Direction = FlowDirection.HorizontalOnly,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2016-12-01 07:05:54 +00:00
|
|
|
|
Padding = new MarginPadding { Left = 10, Right = 10 },
|
2016-10-04 10:41:18 +00:00
|
|
|
|
},
|
2016-12-01 10:15:34 +00:00
|
|
|
|
modeButtonLine = new Container
|
2016-10-04 10:41:18 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Size = new Vector2(0.3f, 3),
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2016-12-01 08:45:21 +00:00
|
|
|
|
Origin = Anchor.TopLeft,
|
2016-12-01 10:15:34 +00:00
|
|
|
|
Masking = true,
|
|
|
|
|
EdgeEffect = new EdgeEffect
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
2017-01-12 21:38:27 +00:00
|
|
|
|
Colour = new Color4(255, 194, 224, 100),
|
2016-12-01 10:15:34 +00:00
|
|
|
|
Radius = 15,
|
|
|
|
|
Roundness = 15,
|
|
|
|
|
},
|
|
|
|
|
Children = new []
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-04 10:41:18 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-12 17:34:36 +00:00
|
|
|
|
int amountButtons = 0;
|
2016-10-04 10:41:18 +00:00
|
|
|
|
foreach (PlayMode m in Enum.GetValues(typeof(PlayMode)))
|
|
|
|
|
{
|
2016-11-12 17:34:36 +00:00
|
|
|
|
++amountButtons;
|
|
|
|
|
|
2016-10-04 10:41:18 +00:00
|
|
|
|
var localMode = m;
|
|
|
|
|
modeButtons.Add(new ToolbarModeButton
|
|
|
|
|
{
|
|
|
|
|
Mode = m,
|
|
|
|
|
Action = delegate
|
|
|
|
|
{
|
|
|
|
|
SetGameMode(localMode);
|
|
|
|
|
OnPlayModeChange?.Invoke(localMode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-12-01 07:05:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2016-10-04 10:41:18 +00:00
|
|
|
|
|
2016-12-01 07:05:54 +00:00
|
|
|
|
Size = new Vector2(modeButtons.DrawSize.X, 1);
|
2016-10-04 10:41:18 +00: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 15:53:13 +00:00
|
|
|
|
private Cached activeMode = new Cached();
|
2016-10-04 10:41:18 +00:00
|
|
|
|
|
2016-12-03 13:40:15 +00:00
|
|
|
|
protected override void UpdateAfterChildren()
|
2016-10-04 10:41:18 +00:00
|
|
|
|
{
|
2016-12-03 13:40:15 +00:00
|
|
|
|
base.UpdateAfterChildren();
|
2016-10-04 10:41:18 +00:00
|
|
|
|
|
|
|
|
|
if (!activeMode.EnsureValid())
|
2016-12-01 08:45:21 +00:00
|
|
|
|
activeMode.Refresh(() => modeButtonLine.MoveToX(activeButton.DrawPosition.X, 200, EasingTypes.OutQuint));
|
2016-10-04 10:41:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|