mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Implement an abstract RulesetSelector class
This commit is contained in:
@ -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.Allocation;
|
|
||||||
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;
|
||||||
@ -18,22 +17,18 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays.Toolbar
|
namespace osu.Game.Overlays.Toolbar
|
||||||
{
|
{
|
||||||
public class ToolbarRulesetSelector : TabControl<RulesetInfo>
|
public class ToolbarRulesetSelector : RulesetSelector
|
||||||
{
|
{
|
||||||
private const float padding = 10;
|
private const float padding = 10;
|
||||||
private readonly Drawable modeButtonLine;
|
private readonly Drawable modeButtonLine;
|
||||||
private RulesetStore rulesets;
|
|
||||||
private readonly Bindable<RulesetInfo> globalRuleset = new Bindable<RulesetInfo>();
|
|
||||||
|
|
||||||
public override bool HandleNonPositionalInput => !globalRuleset.Disabled && base.HandleNonPositionalInput;
|
public override bool HandleNonPositionalInput => !GlobalRuleset.Disabled && base.HandleNonPositionalInput;
|
||||||
public override bool HandlePositionalInput => !globalRuleset.Disabled && base.HandlePositionalInput;
|
public override bool HandlePositionalInput => !GlobalRuleset.Disabled && base.HandlePositionalInput;
|
||||||
|
|
||||||
public override bool PropagatePositionalInputSubTree => !globalRuleset.Disabled && base.PropagatePositionalInputSubTree;
|
public override bool PropagatePositionalInputSubTree => !GlobalRuleset.Disabled && base.PropagatePositionalInputSubTree;
|
||||||
|
|
||||||
private void disabledChanged(bool isDisabled) => this.FadeColour(isDisabled ? Color4.Gray : Color4.White, 300);
|
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 ToolbarRulesetTabButton(value);
|
protected override TabItem<RulesetInfo> CreateTabItem(RulesetInfo value) => new ToolbarRulesetTabButton(value);
|
||||||
|
|
||||||
public ToolbarRulesetSelector()
|
public ToolbarRulesetSelector()
|
||||||
@ -66,6 +61,8 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
GlobalRuleset.DisabledChanged += disabledChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
||||||
@ -76,24 +73,6 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
Padding = new MarginPadding { Left = padding, Right = padding },
|
Padding = new MarginPadding { Left = padding, Right = padding },
|
||||||
};
|
};
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(RulesetStore rulesets, Bindable<RulesetInfo> parentRuleset)
|
|
||||||
{
|
|
||||||
this.rulesets = rulesets;
|
|
||||||
globalRuleset.BindTo(parentRuleset);
|
|
||||||
|
|
||||||
foreach (var r in rulesets.AvailableRulesets)
|
|
||||||
{
|
|
||||||
AddItem(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
globalRuleset.BindValueChanged(globalRulesetChanged);
|
|
||||||
globalRuleset.DisabledChanged += disabledChanged;
|
|
||||||
Current.BindValueChanged(localRulesetChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void globalRulesetChanged(ValueChangedEvent<RulesetInfo> e) => Current.Value = e.NewValue;
|
|
||||||
|
|
||||||
protected override bool OnKeyDown(KeyDownEvent e)
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
{
|
{
|
||||||
base.OnKeyDown(e);
|
base.OnKeyDown(e);
|
||||||
@ -102,7 +81,7 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
{
|
{
|
||||||
int requested = e.Key - Key.Number1;
|
int requested = e.Key - Key.Number1;
|
||||||
|
|
||||||
RulesetInfo found = rulesets.AvailableRulesets.Skip(requested).FirstOrDefault();
|
RulesetInfo found = AvaliableRulesets.AvailableRulesets.Skip(requested).FirstOrDefault();
|
||||||
if (found != null)
|
if (found != null)
|
||||||
Current.Value = found;
|
Current.Value = found;
|
||||||
return true;
|
return true;
|
||||||
@ -113,12 +92,9 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
|
|
||||||
private readonly Cached activeMode = new Cached();
|
private readonly Cached activeMode = new Cached();
|
||||||
|
|
||||||
private void localRulesetChanged(ValueChangedEvent<RulesetInfo> e)
|
protected override void OnLocalRulesetChanged(ValueChangedEvent<RulesetInfo> e)
|
||||||
{
|
{
|
||||||
if (!globalRuleset.Disabled)
|
base.OnLocalRulesetChanged(e);
|
||||||
{
|
|
||||||
globalRuleset.Value = e.NewValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
activeMode.Invalidate();
|
activeMode.Invalidate();
|
||||||
}
|
}
|
||||||
|
63
osu.Game/Rulesets/RulesetSelector.cs
Normal file
63
osu.Game/Rulesets/RulesetSelector.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets
|
||||||
|
{
|
||||||
|
public abstract class RulesetSelector : TabControl<RulesetInfo>
|
||||||
|
{
|
||||||
|
protected RulesetStore AvaliableRulesets;
|
||||||
|
protected readonly Bindable<RulesetInfo> GlobalRuleset = new Bindable<RulesetInfo>();
|
||||||
|
|
||||||
|
protected override Dropdown<RulesetInfo> CreateDropdown() => null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether we want to change a global ruleset when local one is changed.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual bool AllowGlobalRulesetChange => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether we want to change a local ruleset when global one is changed.
|
||||||
|
/// /// </summary>
|
||||||
|
protected virtual bool AllowLocalRulesetChange => true;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(RulesetStore rulesets, Bindable<RulesetInfo> parentRuleset)
|
||||||
|
{
|
||||||
|
AvaliableRulesets = rulesets;
|
||||||
|
GlobalRuleset.BindTo(parentRuleset);
|
||||||
|
|
||||||
|
foreach (var r in rulesets.AvailableRulesets)
|
||||||
|
{
|
||||||
|
AddItem(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalRuleset.BindValueChanged(globalRulesetChanged);
|
||||||
|
Current.BindValueChanged(OnLocalRulesetChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void globalRulesetChanged(ValueChangedEvent<RulesetInfo> e)
|
||||||
|
{
|
||||||
|
if (AllowLocalRulesetChange)
|
||||||
|
{
|
||||||
|
OnGlobalRulesetChanged(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnGlobalRulesetChanged(ValueChangedEvent<RulesetInfo> e)
|
||||||
|
{
|
||||||
|
Current.Value = e.NewValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnLocalRulesetChanged(ValueChangedEvent<RulesetInfo> e)
|
||||||
|
{
|
||||||
|
if (!GlobalRuleset.Disabled && AllowGlobalRulesetChange)
|
||||||
|
{
|
||||||
|
GlobalRuleset.Value = e.NewValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user