2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2021-04-22 05:42:10 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 05:51:28 +00:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Rulesets;
|
2019-06-08 15:27:40 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osuTK.Input;
|
|
|
|
|
using System.Linq;
|
2019-06-26 08:52:25 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-04-22 05:42:10 +00:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
|
{
|
2019-06-24 20:13:28 +00:00
|
|
|
|
public class ToolbarRulesetSelector : RulesetSelector
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-06-27 09:25:38 +00:00
|
|
|
|
protected Drawable ModeButtonLine { get; private set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-04-22 05:42:10 +00:00
|
|
|
|
private readonly Dictionary<string, Sample> selectionSamples = new Dictionary<string, Sample>();
|
|
|
|
|
|
2018-07-09 16:20:21 +00:00
|
|
|
|
public ToolbarRulesetSelector()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2019-06-06 23:39:36 +00:00
|
|
|
|
AutoSizeAxes = Axes.X;
|
2019-06-26 08:52:25 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-26 08:52:25 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2021-04-22 05:42:10 +00:00
|
|
|
|
private void load(AudioManager audio)
|
2019-06-26 08:52:25 +00:00
|
|
|
|
{
|
2019-06-10 00:35:00 +00:00
|
|
|
|
AddRangeInternal(new[]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-06-08 15:27:40 +00:00
|
|
|
|
new OpaqueBackground
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-06-08 15:27:40 +00:00
|
|
|
|
Depth = 1,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
},
|
2019-06-27 09:25:38 +00:00
|
|
|
|
ModeButtonLine = new Container
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-09-03 07:29:15 +00:00
|
|
|
|
Size = new Vector2(Toolbar.HEIGHT, 3),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
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,
|
|
|
|
|
},
|
2019-06-08 15:27:40 +00:00
|
|
|
|
Child = new Box
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-06-08 15:27:40 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-08 15:27:40 +00:00
|
|
|
|
});
|
2021-04-22 05:42:10 +00:00
|
|
|
|
|
|
|
|
|
foreach (var ruleset in Rulesets.AvailableRulesets)
|
|
|
|
|
selectionSamples[ruleset.ShortName] = audio.Samples.Get($"UI/ruleset-select-{ruleset.ShortName}");
|
2019-06-26 08:52:25 +00:00
|
|
|
|
}
|
2019-06-12 20:23:01 +00:00
|
|
|
|
|
2019-06-26 08:52:25 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2021-11-27 13:39:12 +00:00
|
|
|
|
Current.BindDisabledChanged(_ => Scheduler.AddOnce(currentDisabledChanged));
|
|
|
|
|
currentDisabledChanged();
|
2021-05-10 04:58:13 +00:00
|
|
|
|
|
2021-11-27 13:39:12 +00:00
|
|
|
|
Current.BindValueChanged(_ => moveLineToCurrent());
|
2021-05-10 04:58:13 +00:00
|
|
|
|
// Scheduled to allow the button flow layout to be computed before the line position is updated
|
|
|
|
|
ScheduleAfterChildren(moveLineToCurrent);
|
2019-06-26 08:52:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-27 13:39:12 +00:00
|
|
|
|
private void currentDisabledChanged()
|
|
|
|
|
{
|
|
|
|
|
this.FadeColour(Current.Disabled ? Color4.Gray : Color4.White, 300);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 09:25:38 +00:00
|
|
|
|
private bool hasInitialPosition;
|
|
|
|
|
|
2021-05-10 04:58:13 +00:00
|
|
|
|
private void moveLineToCurrent()
|
2019-06-26 08:52:25 +00:00
|
|
|
|
{
|
2019-07-23 06:35:12 +00:00
|
|
|
|
if (SelectedTab != null)
|
|
|
|
|
{
|
|
|
|
|
ModeButtonLine.MoveToX(SelectedTab.DrawPosition.X, !hasInitialPosition ? 0 : 200, Easing.OutQuint);
|
2021-04-22 05:42:10 +00:00
|
|
|
|
|
|
|
|
|
if (hasInitialPosition)
|
|
|
|
|
selectionSamples[SelectedTab.Value.ShortName]?.Play();
|
|
|
|
|
|
2019-07-23 06:35:12 +00:00
|
|
|
|
hasInitialPosition = true;
|
|
|
|
|
}
|
2021-05-10 04:58:13 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-26 08:52:25 +00:00
|
|
|
|
public override bool HandleNonPositionalInput => !Current.Disabled && base.HandleNonPositionalInput;
|
|
|
|
|
|
|
|
|
|
public override bool HandlePositionalInput => !Current.Disabled && base.HandlePositionalInput;
|
|
|
|
|
|
|
|
|
|
public override bool PropagatePositionalInputSubTree => !Current.Disabled && base.PropagatePositionalInputSubTree;
|
|
|
|
|
|
|
|
|
|
protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new ToolbarRulesetTabButton(value);
|
|
|
|
|
|
2019-06-08 15:27:40 +00:00
|
|
|
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2018-05-14 02:33:52 +00:00
|
|
|
|
{
|
2018-10-02 03:02:47 +00:00
|
|
|
|
base.OnKeyDown(e);
|
2018-05-14 02:33:52 +00:00
|
|
|
|
|
2018-10-02 03:44:14 +00:00
|
|
|
|
if (e.ControlPressed && !e.Repeat && e.Key >= Key.Number1 && e.Key <= Key.Number9)
|
2018-05-21 05:45:44 +00:00
|
|
|
|
{
|
2018-10-02 03:02:47 +00:00
|
|
|
|
int requested = e.Key - Key.Number1;
|
2018-05-21 05:45:44 +00:00
|
|
|
|
|
2020-01-31 17:32:47 +00:00
|
|
|
|
RulesetInfo found = Rulesets.AvailableRulesets.ElementAtOrDefault(requested);
|
2018-05-21 05:45:44 +00:00
|
|
|
|
if (found != null)
|
2019-06-08 15:27:40 +00:00
|
|
|
|
Current.Value = found;
|
2018-05-21 05:45:44 +00:00
|
|
|
|
return true;
|
2018-05-14 02:33:52 +00:00
|
|
|
|
}
|
2018-05-12 23:30:29 +00:00
|
|
|
|
|
2018-05-21 05:45:44 +00:00
|
|
|
|
return false;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|