1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 03:12:54 +08:00
osu-lazer/osu.Game/Overlays/Toolbar/ToolbarModeSelector.cs

124 lines
4.0 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
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;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Configuration;
using osu.Framework.Graphics.Shapes;
2017-07-26 12:22:46 +08:00
using osu.Game.Rulesets;
2016-12-01 13:22:29 +08:00
namespace osu.Game.Overlays.Toolbar
{
public class ToolbarModeSelector : Container
{
2017-03-07 09:59:19 +08:00
private const float padding = 10;
private readonly FillFlowContainer modeButtons;
private readonly Drawable modeButtonLine;
private ToolbarModeButton activeButton;
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
public ToolbarModeSelector()
{
RelativeSizeAxes = Axes.Y;
2017-03-07 09:59:19 +08:00
Children = new[]
{
new OpaqueBackground(),
2017-03-02 02:33:01 +08:00
modeButtons = new FillFlowContainer
{
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,
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,
2017-06-12 11:48:47 +08:00
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = new Color4(255, 194, 224, 100),
Radius = 15,
Roundness = 15,
},
2017-06-08 15:27:35 +08:00
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
}
}
}
};
2017-04-17 16:43:48 +08:00
}
2017-04-17 16:43:48 +08:00
[BackgroundDependencyLoader]
private void load(RulesetStore rulesets, OsuGame game)
2017-04-17 16:43:48 +08:00
{
2017-10-16 16:02:31 +08:00
foreach (var r in rulesets.AvailableRulesets)
{
modeButtons.Add(new ToolbarModeButton
{
Ruleset = r,
Action = delegate
{
ruleset.Value = r;
}
});
}
ruleset.ValueChanged += rulesetChanged;
ruleset.DisabledChanged += disabledChanged;
ruleset.BindTo(game.Ruleset);
}
public override bool HandleInput => !ruleset.Disabled;
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);
}
private void rulesetChanged(RulesetInfo ruleset)
{
foreach (ToolbarModeButton m in modeButtons.Children.Cast<ToolbarModeButton>())
{
2017-10-14 13:28:25 +08:00
bool isActive = m.Ruleset.ID == ruleset.ID;
m.Active = isActive;
if (isActive)
activeButton = m;
}
activeMode.Invalidate();
}
2016-11-01 23:53:13 +08:00
private Cached activeMode = new Cached();
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
if (!activeMode.IsValid)
{
2017-07-23 02:50:25 +08:00
modeButtonLine.MoveToX(activeButton.DrawPosition.X, 200, Easing.OutQuint);
activeMode.Validate();
}
}
}
}