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
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2023-12-28 03:06:29 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-06-08 23:27:40 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Input.Events;
|
2023-12-28 03:06:29 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2019-06-08 23:27:40 +08:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class ToolbarRulesetSelector : RulesetSelector
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-27 17:25:38 +08:00
|
|
|
|
protected Drawable ModeButtonLine { get; private set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-10 00:20:21 +08:00
|
|
|
|
public ToolbarRulesetSelector()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2019-06-07 07:39:36 +08:00
|
|
|
|
AutoSizeAxes = Axes.X;
|
2019-06-26 16:52:25 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-26 16:52:25 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2024-05-22 16:29:39 +08:00
|
|
|
|
private void load()
|
2019-06-26 16:52:25 +08:00
|
|
|
|
{
|
2019-06-10 08:35:00 +08:00
|
|
|
|
AddRangeInternal(new[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-08 23:27:40 +08:00
|
|
|
|
new OpaqueBackground
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-08 23:27:40 +08:00
|
|
|
|
Depth = 1,
|
2023-12-28 02:43:38 +08:00
|
|
|
|
Masking = true,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2019-06-27 17:25:38 +08:00
|
|
|
|
ModeButtonLine = new Container
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-09-03 15:29:15 +08:00
|
|
|
|
Size = new Vector2(Toolbar.HEIGHT, 3),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2023-12-28 03:06:29 +08:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Y = -1,
|
|
|
|
|
Children = new Drawable[]
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2023-12-28 03:06:29 +08:00
|
|
|
|
new Circle
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(18, 3),
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2023-12-28 03:06:29 +08:00
|
|
|
|
},
|
2019-06-08 23:27:40 +08:00
|
|
|
|
});
|
2019-06-26 16:52:25 +08:00
|
|
|
|
}
|
2019-06-13 04:23:01 +08:00
|
|
|
|
|
2019-06-26 16:52:25 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2021-11-27 21:39:12 +08:00
|
|
|
|
Current.BindDisabledChanged(_ => Scheduler.AddOnce(currentDisabledChanged));
|
|
|
|
|
currentDisabledChanged();
|
2021-05-10 12:58:13 +08:00
|
|
|
|
|
2021-11-27 21:39:12 +08:00
|
|
|
|
Current.BindValueChanged(_ => moveLineToCurrent());
|
2021-05-10 12:58:13 +08:00
|
|
|
|
// Scheduled to allow the button flow layout to be computed before the line position is updated
|
|
|
|
|
ScheduleAfterChildren(moveLineToCurrent);
|
2019-06-26 16:52:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-27 21:39:12 +08:00
|
|
|
|
private void currentDisabledChanged()
|
|
|
|
|
{
|
|
|
|
|
this.FadeColour(Current.Disabled ? Color4.Gray : Color4.White, 300);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 17:25:38 +08:00
|
|
|
|
private bool hasInitialPosition;
|
|
|
|
|
|
2021-05-10 12:58:13 +08:00
|
|
|
|
private void moveLineToCurrent()
|
2019-06-26 16:52:25 +08:00
|
|
|
|
{
|
2019-07-23 14:35:12 +08:00
|
|
|
|
if (SelectedTab != null)
|
|
|
|
|
{
|
2023-12-28 03:06:29 +08:00
|
|
|
|
ModeButtonLine.MoveToX(SelectedTab.DrawPosition.X, !hasInitialPosition ? 0 : 500, Easing.OutElasticQuarter);
|
2019-07-23 14:35:12 +08:00
|
|
|
|
hasInitialPosition = true;
|
|
|
|
|
}
|
2021-05-10 12:58:13 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-26 16:52:25 +08: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 23:27:40 +08:00
|
|
|
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
|
|
2020-02-01 01:32:47 +08:00
|
|
|
|
RulesetInfo found = Rulesets.AvailableRulesets.ElementAtOrDefault(requested);
|
2018-05-21 13:45:44 +08:00
|
|
|
|
if (found != null)
|
2024-05-22 16:29:39 +08:00
|
|
|
|
SelectItem(found);
|
2018-05-21 13:45:44 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|