mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 15:03:13 +08:00
Refactor
This commit is contained in:
parent
3182f88ea8
commit
06dfa42a5a
@ -2,57 +2,68 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Toolbar
|
namespace osu.Game.Overlays.Toolbar
|
||||||
{
|
{
|
||||||
public class ToolbarRulesetButton : ToolbarButton
|
public class ToolbarRulesetButton : TabItem<RulesetInfo>
|
||||||
{
|
{
|
||||||
private RulesetInfo ruleset;
|
private readonly DrawableRuleset ruleset;
|
||||||
|
|
||||||
public RulesetInfo Ruleset
|
public ToolbarRulesetButton(RulesetInfo value)
|
||||||
|
: base(value)
|
||||||
{
|
{
|
||||||
get => ruleset;
|
AutoSizeAxes = Axes.X;
|
||||||
set
|
RelativeSizeAxes = Axes.Y;
|
||||||
|
Child = ruleset = new DrawableRuleset
|
||||||
{
|
{
|
||||||
ruleset = value;
|
Active = false,
|
||||||
|
};
|
||||||
|
|
||||||
var rInstance = ruleset.CreateInstance();
|
var rInstance = value.CreateInstance();
|
||||||
|
|
||||||
TooltipMain = rInstance.Description;
|
ruleset.TooltipMain = rInstance.Description;
|
||||||
TooltipSub = $"Play some {rInstance.Description}";
|
ruleset.TooltipSub = $"Play some {rInstance.Description}";
|
||||||
SetIcon(rInstance.CreateIcon());
|
ruleset.SetIcon(rInstance.CreateIcon());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Active
|
protected override void OnActivated() => ruleset.Active = true;
|
||||||
|
|
||||||
|
protected override void OnDeactivated() => ruleset.Active = false;
|
||||||
|
|
||||||
|
private class DrawableRuleset : ToolbarButton
|
||||||
{
|
{
|
||||||
set
|
public bool Active
|
||||||
{
|
{
|
||||||
if (value)
|
set
|
||||||
{
|
{
|
||||||
IconContainer.Colour = Color4.White;
|
if (value)
|
||||||
IconContainer.EdgeEffect = new EdgeEffectParameters
|
|
||||||
{
|
{
|
||||||
Type = EdgeEffectType.Glow,
|
IconContainer.Colour = Color4.White;
|
||||||
Colour = new Color4(255, 194, 224, 100),
|
IconContainer.EdgeEffect = new EdgeEffectParameters
|
||||||
Radius = 15,
|
{
|
||||||
Roundness = 15,
|
Type = EdgeEffectType.Glow,
|
||||||
};
|
Colour = new Color4(255, 194, 224, 100),
|
||||||
}
|
Radius = 15,
|
||||||
else
|
Roundness = 15,
|
||||||
{
|
};
|
||||||
IconContainer.Colour = new Color4(255, 194, 224, 255);
|
}
|
||||||
IconContainer.EdgeEffect = new EdgeEffectParameters();
|
else
|
||||||
|
{
|
||||||
|
IconContainer.Colour = new Color4(255, 194, 224, 255);
|
||||||
|
IconContainer.EdgeEffect = new EdgeEffectParameters();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
IconContainer.Scale *= 1.4f;
|
IconContainer.Scale *= 1.4f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,53 +1,54 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Caching;
|
using osu.Framework.Caching;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Input;
|
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osuTK.Input;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Toolbar
|
namespace osu.Game.Overlays.Toolbar
|
||||||
{
|
{
|
||||||
public class ToolbarRulesetSelector : Container
|
public class ToolbarRulesetSelector : TabControl<RulesetInfo>
|
||||||
{
|
{
|
||||||
private const float padding = 10;
|
private const float padding = 10;
|
||||||
|
|
||||||
private readonly FillFlowContainer modeButtons;
|
|
||||||
private readonly Drawable modeButtonLine;
|
private readonly Drawable modeButtonLine;
|
||||||
private ToolbarRulesetButton activeButton;
|
|
||||||
|
|
||||||
private RulesetStore rulesets;
|
private RulesetStore rulesets;
|
||||||
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
|
||||||
|
public override bool HandleNonPositionalInput => !Current.Disabled && base.HandleNonPositionalInput;
|
||||||
|
public override bool HandlePositionalInput => !Current.Disabled && base.HandlePositionalInput;
|
||||||
|
|
||||||
|
public override bool PropagatePositionalInputSubTree => !Current.Disabled && base.PropagatePositionalInputSubTree;
|
||||||
|
|
||||||
|
private void disabledChanged(bool isDisabled) => this.FadeColour(isDisabled ? Color4.Gray : Color4.White, 300);
|
||||||
|
|
||||||
|
protected override Dropdown<RulesetInfo> CreateDropdown() => null;
|
||||||
|
|
||||||
|
protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new ToolbarRulesetButton(value);
|
||||||
|
|
||||||
public ToolbarRulesetSelector()
|
public ToolbarRulesetSelector()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y;
|
RelativeSizeAxes = Axes.Y;
|
||||||
AutoSizeAxes = Axes.X;
|
AutoSizeAxes = Axes.X;
|
||||||
|
|
||||||
Children = new[]
|
AddRangeInternal(new Drawable[]
|
||||||
{
|
{
|
||||||
new OpaqueBackground(),
|
new OpaqueBackground
|
||||||
modeButtons = new FillFlowContainer
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y,
|
Depth = 1,
|
||||||
AutoSizeAxes = Axes.X,
|
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
Padding = new MarginPadding { Left = padding, Right = padding },
|
|
||||||
},
|
},
|
||||||
modeButtonLine = new Container
|
modeButtonLine = new Container
|
||||||
{
|
{
|
||||||
Size = new Vector2(padding * 2 + ToolbarButton.WIDTH, 3),
|
Size = new Vector2(padding* 2 + ToolbarButton.WIDTH, 3),
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
Origin = Anchor.TopLeft,
|
Origin = Anchor.TopLeft,
|
||||||
Masking = true,
|
Masking = true,
|
||||||
@ -58,17 +59,22 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
Radius = 15,
|
Radius = 15,
|
||||||
Roundness = 15,
|
Roundness = 15,
|
||||||
},
|
},
|
||||||
Children = new[]
|
Child = new Box
|
||||||
{
|
{
|
||||||
new Box
|
RelativeSizeAxes = Axes.Both,
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Y,
|
||||||
|
AutoSizeAxes = Axes.X,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
Padding = new MarginPadding { Left = padding, Right = padding },
|
||||||
|
};
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(RulesetStore rulesets, Bindable<RulesetInfo> parentRuleset)
|
private void load(RulesetStore rulesets, Bindable<RulesetInfo> parentRuleset)
|
||||||
{
|
{
|
||||||
@ -76,16 +82,13 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
|
|
||||||
foreach (var r in rulesets.AvailableRulesets)
|
foreach (var r in rulesets.AvailableRulesets)
|
||||||
{
|
{
|
||||||
modeButtons.Add(new ToolbarRulesetButton
|
AddItem(r);
|
||||||
{
|
|
||||||
Ruleset = r,
|
|
||||||
Action = delegate { ruleset.Value = r; }
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ruleset.ValueChanged += rulesetChanged;
|
Current.BindTo(parentRuleset);
|
||||||
ruleset.DisabledChanged += disabledChanged;
|
Current.Disabled = false;
|
||||||
ruleset.BindTo(parentRuleset);
|
Current.DisabledChanged += disabledChanged;
|
||||||
|
Current.BindValueChanged(rulesetChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnKeyDown(KeyDownEvent e)
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
@ -98,43 +101,35 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
|
|
||||||
RulesetInfo found = rulesets.AvailableRulesets.Skip(requested).FirstOrDefault();
|
RulesetInfo found = rulesets.AvailableRulesets.Skip(requested).FirstOrDefault();
|
||||||
if (found != null)
|
if (found != null)
|
||||||
ruleset.Value = found;
|
Current.Value = found;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleNonPositionalInput => !ruleset.Disabled && base.HandleNonPositionalInput;
|
private readonly Cached activeMode = new Cached();
|
||||||
public override bool HandlePositionalInput => !ruleset.Disabled && base.HandlePositionalInput;
|
|
||||||
|
|
||||||
public override bool PropagatePositionalInputSubTree => !ruleset.Disabled && base.PropagatePositionalInputSubTree;
|
|
||||||
|
|
||||||
private void disabledChanged(bool isDisabled) => this.FadeColour(isDisabled ? Color4.Gray : Color4.White, 300);
|
|
||||||
|
|
||||||
private void rulesetChanged(ValueChangedEvent<RulesetInfo> e)
|
private void rulesetChanged(ValueChangedEvent<RulesetInfo> e)
|
||||||
{
|
{
|
||||||
foreach (ToolbarRulesetButton m in modeButtons.Children.Cast<ToolbarRulesetButton>())
|
|
||||||
{
|
|
||||||
bool isActive = m.Ruleset.ID == e.NewValue.ID;
|
|
||||||
m.Active = isActive;
|
|
||||||
if (isActive)
|
|
||||||
activeButton = m;
|
|
||||||
}
|
|
||||||
|
|
||||||
activeMode.Invalidate();
|
activeMode.Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cached activeMode = new Cached();
|
|
||||||
|
|
||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
{
|
{
|
||||||
base.UpdateAfterChildren();
|
base.UpdateAfterChildren();
|
||||||
|
|
||||||
if (!activeMode.IsValid)
|
if (!activeMode.IsValid)
|
||||||
{
|
{
|
||||||
modeButtonLine.MoveToX(activeButton.DrawPosition.X, 200, Easing.OutQuint);
|
foreach (TabItem<RulesetInfo> tabItem in TabContainer)
|
||||||
activeMode.Validate();
|
{
|
||||||
|
if (tabItem.Value == Current.Value)
|
||||||
|
{
|
||||||
|
modeButtonLine.MoveToX(tabItem.DrawPosition.X, 200, Easing.OutQuint);
|
||||||
|
activeMode.Validate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user