mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 19:22:54 +08:00
Make KeyBindingOverlay support variants as settings sub sections.
This commit is contained in:
parent
38a4c84163
commit
c1860f2ce2
@ -3,21 +3,29 @@
|
||||
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Overlays.Settings;
|
||||
|
||||
namespace osu.Game.Overlays.KeyBinding
|
||||
{
|
||||
public class GlobalKeyBindingsSection : KeyBindingsSection
|
||||
public class GlobalKeyBindingsSection : SettingsSection
|
||||
{
|
||||
private readonly string name;
|
||||
public override FontAwesome Icon => FontAwesome.fa_osu_hot;
|
||||
public override string Header => "Global";
|
||||
|
||||
public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail;
|
||||
public override string Header => name;
|
||||
|
||||
public GlobalKeyBindingsSection(KeyBindingInputManager manager, string name)
|
||||
public GlobalKeyBindingsSection(KeyBindingInputManager manager)
|
||||
{
|
||||
this.name = name;
|
||||
Add(new DefaultBindingsSubsection(manager));
|
||||
}
|
||||
|
||||
Defaults = manager.DefaultKeyBindings;
|
||||
private class DefaultBindingsSubsection : KeyBindingsSubsection
|
||||
{
|
||||
protected override string Header => string.Empty;
|
||||
|
||||
public DefaultBindingsSubsection(KeyBindingInputManager manager)
|
||||
: base(0)
|
||||
{
|
||||
Defaults = manager.DefaultKeyBindings;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
@ -12,38 +11,34 @@ using OpenTK;
|
||||
|
||||
namespace osu.Game.Overlays.KeyBinding
|
||||
{
|
||||
public abstract class KeyBindingsSection : SettingsSection
|
||||
public abstract class KeyBindingsSubsection : SettingsSubsection
|
||||
{
|
||||
protected IEnumerable<Framework.Input.Bindings.KeyBinding> Defaults;
|
||||
|
||||
protected RulesetInfo Ruleset;
|
||||
|
||||
protected KeyBindingsSection()
|
||||
private readonly int variant;
|
||||
|
||||
protected KeyBindingsSubsection(int variant)
|
||||
{
|
||||
this.variant = variant;
|
||||
|
||||
FlowContent.Spacing = new Vector2(0, 1);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(KeyBindingStore store)
|
||||
{
|
||||
var enumType = Defaults?.FirstOrDefault()?.Action?.GetType();
|
||||
|
||||
if (enumType == null) return;
|
||||
|
||||
// for now let's just assume a variant of zero.
|
||||
// this will need to be implemented in a better way in the future.
|
||||
int? variant = null;
|
||||
if (Ruleset != null)
|
||||
variant = 0;
|
||||
|
||||
var bindings = store.Query(Ruleset?.ID, variant);
|
||||
|
||||
foreach (Enum v in Enum.GetValues(enumType))
|
||||
foreach (var defaultBinding in Defaults)
|
||||
{
|
||||
// one row per valid action.
|
||||
Add(new KeyBindingRow(v, bindings.Where(b => b.Action.Equals((int)(object)v)))
|
||||
Add(new KeyBindingRow(defaultBinding.Action, bindings.Where(b => b.Action.Equals((int)defaultBinding.Action)))
|
||||
{
|
||||
AllowMainMouseButtons = Ruleset != null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,20 +2,26 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Overlays.Settings;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Overlays.KeyBinding
|
||||
{
|
||||
public class RulesetBindingsSection : KeyBindingsSection
|
||||
public class RulesetBindingsSection : SettingsSection
|
||||
{
|
||||
public override FontAwesome Icon => FontAwesome.fa_osu_mod_nofail;
|
||||
public override string Header => Ruleset.Name;
|
||||
public override FontAwesome Icon => FontAwesome.fa_osu_hot;
|
||||
public override string Header => ruleset.Name;
|
||||
|
||||
private readonly RulesetInfo ruleset;
|
||||
|
||||
public RulesetBindingsSection(RulesetInfo ruleset)
|
||||
{
|
||||
Ruleset = ruleset;
|
||||
this.ruleset = ruleset;
|
||||
|
||||
Defaults = ruleset.CreateInstance().GetDefaultKeyBindings();
|
||||
var r = ruleset.CreateInstance();
|
||||
|
||||
foreach (var variant in r.AvailableVariants)
|
||||
Add(new VariantBindingsSubsection(ruleset, variant));
|
||||
}
|
||||
}
|
||||
}
|
23
osu.Game/Overlays/KeyBinding/VariantBindingsSubsection.cs
Normal file
23
osu.Game/Overlays/KeyBinding/VariantBindingsSubsection.cs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Overlays.KeyBinding
|
||||
{
|
||||
public class VariantBindingsSubsection : KeyBindingsSubsection
|
||||
{
|
||||
protected override string Header => variant > 0 ? $"Variant: {variant}" : string.Empty;
|
||||
|
||||
private readonly int variant;
|
||||
|
||||
public VariantBindingsSubsection(RulesetInfo ruleset, int variant)
|
||||
: base(variant)
|
||||
{
|
||||
this.variant = variant;
|
||||
|
||||
Ruleset = ruleset;
|
||||
Defaults = ruleset.CreateInstance().GetDefaultKeyBindings(variant);
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ namespace osu.Game.Overlays
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(RulesetStore rulesets, GlobalKeyBindingInputManager global)
|
||||
{
|
||||
AddSection(new GlobalKeyBindingsSection(global, "Global"));
|
||||
AddSection(new GlobalKeyBindingsSection(global));
|
||||
|
||||
foreach (var ruleset in rulesets.AllRulesets)
|
||||
AddSection(new RulesetBindingsSection(ruleset));
|
||||
|
@ -105,9 +105,10 @@
|
||||
<Compile Include="Overlays\Chat\ChatTabControl.cs" />
|
||||
<Compile Include="Overlays\KeyBinding\GlobalKeyBindingsSection.cs" />
|
||||
<Compile Include="Overlays\KeyBinding\KeyBindingRow.cs" />
|
||||
<Compile Include="Overlays\KeyBinding\KeyBindingsSection.cs" />
|
||||
<Compile Include="Overlays\KeyBinding\KeyBindingsSubsection.cs" />
|
||||
<Compile Include="Overlays\KeyBindingOverlay.cs" />
|
||||
<Compile Include="Overlays\KeyBinding\RulesetBindingsSection.cs" />
|
||||
<Compile Include="Overlays\KeyBinding\VariantBindingsSubsection.cs" />
|
||||
<Compile Include="Overlays\MainSettings.cs" />
|
||||
<Compile Include="Overlays\Music\CollectionsDropdown.cs" />
|
||||
<Compile Include="Overlays\Music\FilterControl.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user