1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 07:22:55 +08:00

General refactoring

This commit is contained in:
smoogipoo 2019-06-26 17:52:25 +09:00
parent 08e31159fc
commit 6ce86e6083
3 changed files with 41 additions and 42 deletions

View File

@ -86,7 +86,8 @@ namespace osu.Game.Overlays.Toolbar
} }
}; };
rulesetSelector.Current.BindTarget = parentRuleset; // Bound after the selector is added to the hierarchy to give it a chance to load the available rulesets
rulesetSelector.Current.BindTo(parentRuleset);
State.ValueChanged += visibility => State.ValueChanged += visibility =>
{ {

View File

@ -1,7 +1,6 @@
// 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 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;
@ -13,28 +12,25 @@ using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osuTK.Input; using osuTK.Input;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
namespace osu.Game.Overlays.Toolbar namespace osu.Game.Overlays.Toolbar
{ {
public class ToolbarRulesetSelector : RulesetSelector public class ToolbarRulesetSelector : RulesetSelector
{ {
private const float padding = 10; private const float padding = 10;
private readonly Drawable modeButtonLine;
public override bool HandleNonPositionalInput => !Current.Disabled && base.HandleNonPositionalInput; private Drawable modeButtonLine;
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 TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new ToolbarRulesetTabButton(value);
public ToolbarRulesetSelector() public ToolbarRulesetSelector()
{ {
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;
}
[BackgroundDependencyLoader]
private void load()
{
AddRangeInternal(new[] AddRangeInternal(new[]
{ {
new OpaqueBackground new OpaqueBackground
@ -60,11 +56,36 @@ namespace osu.Game.Overlays.Toolbar
} }
} }
}); });
Current.DisabledChanged += disabledChanged;
Current.ValueChanged += value => activeMode.Invalidate();
} }
protected override void LoadComplete()
{
base.LoadComplete();
Current.BindDisabledChanged(disabled => this.FadeColour(disabled ? Color4.Gray : Color4.White, 300), true);
Current.BindValueChanged(_ => moveLineToCurrent(), true);
}
private void moveLineToCurrent()
{
foreach (TabItem<RulesetInfo> tabItem in TabContainer)
{
if (tabItem.Value == Current.Value)
{
modeButtonLine.MoveToX(tabItem.DrawPosition.X, 200, Easing.OutQuint);
break;
}
}
}
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);
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
{ {
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
@ -81,7 +102,7 @@ namespace osu.Game.Overlays.Toolbar
{ {
int requested = e.Key - Key.Number1; int requested = e.Key - Key.Number1;
RulesetInfo found = AvaliableRulesets.AvailableRulesets.Skip(requested).FirstOrDefault(); RulesetInfo found = Rulesets.AvailableRulesets.Skip(requested).FirstOrDefault();
if (found != null) if (found != null)
Current.Value = found; Current.Value = found;
return true; return true;
@ -89,25 +110,5 @@ namespace osu.Game.Overlays.Toolbar
return false; return false;
} }
private readonly Cached activeMode = new Cached();
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
if (!activeMode.IsValid)
{
foreach (TabItem<RulesetInfo> tabItem in TabContainer)
{
if (tabItem.Value == Current.Value)
{
modeButtonLine.MoveToX(tabItem.DrawPosition.X, 200, Easing.OutQuint);
activeMode.Validate();
return;
}
}
}
}
} }
} }

View File

@ -8,19 +8,16 @@ namespace osu.Game.Rulesets
{ {
public abstract class RulesetSelector : TabControl<RulesetInfo> public abstract class RulesetSelector : TabControl<RulesetInfo>
{ {
protected RulesetStore AvaliableRulesets; [Resolved]
protected RulesetStore Rulesets { get; private set; }
protected override Dropdown<RulesetInfo> CreateDropdown() => null; protected override Dropdown<RulesetInfo> CreateDropdown() => null;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(RulesetStore rulesets) private void load()
{
AvaliableRulesets = rulesets;
foreach (var r in rulesets.AvailableRulesets)
{ {
foreach (var r in Rulesets.AvailableRulesets)
AddItem(r); AddItem(r);
} }
} }
}
} }