2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Caching;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Input;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
|
{
|
2018-07-10 00:20:21 +08:00
|
|
|
|
public class ToolbarRulesetSelector : Container
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
private const float padding = 10;
|
|
|
|
|
|
|
|
|
|
private readonly FillFlowContainer modeButtons;
|
|
|
|
|
private readonly Drawable modeButtonLine;
|
2018-07-10 00:20:21 +08:00
|
|
|
|
private ToolbarRulesetButton activeButton;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-05-14 10:33:52 +08:00
|
|
|
|
private RulesetStore rulesets;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
|
|
|
|
|
2018-07-10 00:20:21 +08:00
|
|
|
|
public ToolbarRulesetSelector()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new OpaqueBackground(),
|
|
|
|
|
modeButtons = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Padding = new MarginPadding { Left = padding, Right = padding },
|
|
|
|
|
},
|
|
|
|
|
modeButtonLine = new Container
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(padding * 2 + ToolbarButton.WIDTH, 3),
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
Masking = true,
|
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Colour = new Color4(255, 194, 224, 100),
|
|
|
|
|
Radius = 15,
|
|
|
|
|
Roundness = 15,
|
|
|
|
|
},
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-26 17:24:34 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2018-06-26 15:32:20 +08:00
|
|
|
|
private void load(RulesetStore rulesets, Bindable<RulesetInfo> parentRuleset)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-05-14 10:33:52 +08:00
|
|
|
|
this.rulesets = rulesets;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
foreach (var r in rulesets.AvailableRulesets)
|
|
|
|
|
{
|
2018-07-10 00:20:21 +08:00
|
|
|
|
modeButtons.Add(new ToolbarRulesetButton
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Ruleset = r,
|
2018-10-05 23:37:44 +08:00
|
|
|
|
Action = delegate { ruleset.Value = r; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ruleset.ValueChanged += rulesetChanged;
|
|
|
|
|
ruleset.DisabledChanged += disabledChanged;
|
2018-06-26 17:24:34 +08:00
|
|
|
|
ruleset.BindTo(parentRuleset);
|
2018-05-14 10:33:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2018-05-14 10:33:52 +08:00
|
|
|
|
{
|
2018-10-02 11:02:47 +08:00
|
|
|
|
base.OnKeyDown(e);
|
2018-05-14 10:33:52 +08:00
|
|
|
|
|
2018-10-02 11:44:14 +08:00
|
|
|
|
if (e.ControlPressed && !e.Repeat && e.Key >= Key.Number1 && e.Key <= Key.Number9)
|
2018-05-21 13:45:44 +08:00
|
|
|
|
{
|
2018-10-02 11:02:47 +08:00
|
|
|
|
int requested = e.Key - Key.Number1;
|
2018-05-21 13:45:44 +08:00
|
|
|
|
|
|
|
|
|
RulesetInfo found = rulesets.AvailableRulesets.Skip(requested).FirstOrDefault();
|
|
|
|
|
if (found != null)
|
|
|
|
|
ruleset.Value = found;
|
|
|
|
|
return true;
|
2018-05-14 10:33:52 +08:00
|
|
|
|
}
|
2018-05-13 07:30:29 +08:00
|
|
|
|
|
2018-05-21 13:45:44 +08:00
|
|
|
|
return false;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public override bool HandleNonPositionalInput => !ruleset.Disabled && base.HandleNonPositionalInput;
|
|
|
|
|
public override bool HandlePositionalInput => !ruleset.Disabled && base.HandlePositionalInput;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-09 23:05:15 +08:00
|
|
|
|
public override bool PropagatePositionalInputSubTree => !ruleset.Disabled && base.PropagatePositionalInputSubTree;
|
2018-10-05 23:37:44 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private void disabledChanged(bool isDisabled) => this.FadeColour(isDisabled ? Color4.Gray : Color4.White, 300);
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
Size = new Vector2(modeButtons.DrawSize.X, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
private void rulesetChanged(ValueChangedEvent<RulesetInfo> e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-07-10 00:20:21 +08:00
|
|
|
|
foreach (ToolbarRulesetButton m in modeButtons.Children.Cast<ToolbarRulesetButton>())
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
|
bool isActive = m.Ruleset.ID == e.NewValue.ID;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
m.Active = isActive;
|
|
|
|
|
if (isActive)
|
|
|
|
|
activeButton = m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
activeMode.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Cached activeMode = new Cached();
|
|
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
|
|
if (!activeMode.IsValid)
|
|
|
|
|
{
|
|
|
|
|
modeButtonLine.MoveToX(activeButton.DrawPosition.X, 200, Easing.OutQuint);
|
|
|
|
|
activeMode.Validate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|