2017-02-07 12:59:30 +08: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 18:41:18 +08:00
|
|
|
|
|
|
|
|
|
using System.Linq;
|
2017-04-17 16:43:48 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
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;
|
2017-04-17 16:43:48 +08:00
|
|
|
|
using osu.Game.Database;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-04-21 15:03:59 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
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
|
|
|
|
{
|
2017-03-07 09:59:19 +08:00
|
|
|
|
internal class ToolbarModeSelector : Container
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2017-03-07 09:59:19 +08:00
|
|
|
|
private const float padding = 10;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly FillFlowContainer modeButtons;
|
|
|
|
|
private readonly Drawable modeButtonLine;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
private ToolbarModeButton activeButton;
|
|
|
|
|
|
2017-04-21 15:03:59 +08:00
|
|
|
|
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
2017-04-06 16:21:18 +08:00
|
|
|
|
|
2016-10-04 18:41:18 +08:00
|
|
|
|
public ToolbarModeSelector()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
Children = new[]
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-12-01 17:53:13 +08:00
|
|
|
|
new OpaqueBackground(),
|
2017-03-02 02:33:01 +08:00
|
|
|
|
modeButtons = new FillFlowContainer
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2016-10-22 17:05:46 +08:00
|
|
|
|
AutoSizeAxes = Axes.X,
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
2016-10-04 18:41:18 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-02-15 12:48:49 +08:00
|
|
|
|
Padding = new MarginPadding { Left = padding, Right = padding },
|
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
|
|
|
|
{
|
2017-02-15 12:48:49 +08:00
|
|
|
|
Size = new Vector2(padding * 2 + ToolbarButton.WIDTH, 3),
|
2016-10-04 18:41:18 +08:00
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2016-12-01 16:45:21 +08:00
|
|
|
|
Origin = Anchor.TopLeft,
|
2016-12-01 18:15:34 +08:00
|
|
|
|
Masking = true,
|
2017-06-12 11:48:47 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2016-12-01 18:15:34 +08:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
2017-01-13 05:38:27 +08:00
|
|
|
|
Colour = new Color4(255, 194, 224, 100),
|
2016-12-01 18:15:34 +08:00
|
|
|
|
Radius = 15,
|
|
|
|
|
Roundness = 15,
|
|
|
|
|
},
|
2017-06-08 15:27:35 +08:00
|
|
|
|
Children = new[]
|
2016-12-01 18:15:34 +08:00
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2017-04-17 16:43:48 +08:00
|
|
|
|
}
|
2016-10-04 18:41:18 +08:00
|
|
|
|
|
2017-04-17 16:43:48 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-04-21 15:03:59 +08:00
|
|
|
|
private void load(RulesetDatabase rulesets, OsuGame game)
|
2017-04-17 16:43:48 +08:00
|
|
|
|
{
|
2017-04-21 15:03:59 +08:00
|
|
|
|
foreach (var r in rulesets.AllRulesets)
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
|
|
|
|
modeButtons.Add(new ToolbarModeButton
|
|
|
|
|
{
|
2017-04-21 15:03:59 +08:00
|
|
|
|
Ruleset = r,
|
2016-10-04 18:41:18 +08:00
|
|
|
|
Action = delegate
|
|
|
|
|
{
|
2017-04-21 15:03:59 +08:00
|
|
|
|
ruleset.Value = r;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-04-21 15:03:59 +08:00
|
|
|
|
|
|
|
|
|
ruleset.ValueChanged += rulesetChanged;
|
|
|
|
|
ruleset.DisabledChanged += disabledChanged;
|
|
|
|
|
ruleset.BindTo(game.Ruleset);
|
2016-12-01 15:05:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-21 15:03:59 +08:00
|
|
|
|
public override bool HandleInput => !ruleset.Disabled;
|
|
|
|
|
|
2017-07-15 00:18:12 +08:00
|
|
|
|
private void disabledChanged(bool isDisabled) => this.FadeColour(isDisabled ? Color4.Gray : Color4.White, 300);
|
2017-04-21 15:03:59 +08:00
|
|
|
|
|
2016-12-01 15:05:54 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
Size = new Vector2(modeButtons.DrawSize.X, 1);
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-21 15:03:59 +08:00
|
|
|
|
private void rulesetChanged(RulesetInfo ruleset)
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (ToolbarModeButton m in modeButtons.Children.Cast<ToolbarModeButton>())
|
|
|
|
|
{
|
2017-04-17 16:43:48 +08:00
|
|
|
|
bool isActive = m.Ruleset.ID == ruleset.ID;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
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
|
|
|
|
|
2017-07-02 18:00:02 +08:00
|
|
|
|
if (!activeMode.IsValid)
|
|
|
|
|
{
|
|
|
|
|
modeButtonLine.MoveToX(activeButton.DrawPosition.X, 200, EasingTypes.OutQuint);
|
|
|
|
|
activeMode.Validate();
|
|
|
|
|
}
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|