1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:07:23 +08:00

Initial refactoring of key binding logic

This commit is contained in:
Dean Herbert 2017-08-14 20:19:25 +09:00
parent dccefe1c0e
commit 7c9d6c9c83
14 changed files with 75 additions and 49 deletions

View File

@ -1,11 +1,9 @@
// 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.Collections.Generic;
using System.ComponentModel;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
using OpenTK.Input;
namespace osu.Game.Rulesets.Catch
{
@ -15,16 +13,6 @@ namespace osu.Game.Rulesets.Catch
: base(ruleset, simultaneousMode: SimultaneousBindingMode.Unique)
{
}
protected override IEnumerable<KeyBinding> CreateDefaultMappings() => new[]
{
new KeyBinding(Key.Z, CatchAction.MoveLeft),
new KeyBinding(Key.Left, CatchAction.MoveLeft),
new KeyBinding(Key.X, CatchAction.MoveRight),
new KeyBinding(Key.Right, CatchAction.MoveRight),
new KeyBinding(Key.LShift, CatchAction.Dash),
new KeyBinding(Key.RShift, CatchAction.Dash),
};
}
public enum CatchAction

View File

@ -13,6 +13,7 @@ using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Catch.Scoring;
using osu.Game.Rulesets.Scoring;
using osu.Framework.Input.Bindings;
namespace osu.Game.Rulesets.Catch
{
@ -20,6 +21,16 @@ namespace osu.Game.Rulesets.Catch
{
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new CatchRulesetContainer(this, beatmap, isForCurrentRuleset);
public override IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0) => new[]
{
new KeyBinding(Key.Z, CatchAction.MoveLeft),
new KeyBinding(Key.Left, CatchAction.MoveLeft),
new KeyBinding(Key.X, CatchAction.MoveRight),
new KeyBinding(Key.Right, CatchAction.MoveRight),
new KeyBinding(Key.LShift, CatchAction.Dash),
new KeyBinding(Key.RShift, CatchAction.Dash),
};
public override IEnumerable<Mod> GetModsFor(ModType type)
{
switch (type)

View File

@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.Catch.UI
protected override Playfield<CatchBaseHit, CatchJudgement> CreatePlayfield() => new CatchPlayfield();
protected override PassThroughInputManager CreateActionMappingInputManager() => new CatchInputManager(Ruleset?.RulesetInfo);
public override PassThroughInputManager CreateKeyBindingInputManager() => new CatchInputManager(Ruleset?.RulesetInfo);
protected override DrawableHitObject<CatchBaseHit, CatchJudgement> GetVisualRepresentation(CatchBaseHit h)
{

View File

@ -1,7 +1,7 @@
// 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.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
@ -33,19 +33,13 @@ namespace osu.Game.Rulesets.Osu
keyboard.Keys = keyboard.Keys.Concat(new[] { Key.LastKey + 2 });
}
}
protected override IEnumerable<KeyBinding> CreateDefaultMappings() => new[]
{
new KeyBinding(Key.Z, OsuAction.LeftButton),
new KeyBinding(Key.X, OsuAction.RightButton),
new KeyBinding(Key.LastKey + 1, OsuAction.LeftButton),
new KeyBinding(Key.LastKey + 2, OsuAction.RightButton),
};
}
public enum OsuAction
{
[Description("Left Button")]
LeftButton,
[Description("Right Button")]
RightButton
}
}

View File

@ -17,6 +17,7 @@ using osu.Framework.Graphics;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Scoring;
using osu.Game.Overlays.Settings;
using osu.Framework.Input.Bindings;
namespace osu.Game.Rulesets.Osu
{
@ -24,8 +25,16 @@ namespace osu.Game.Rulesets.Osu
{
public override RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset) => new OsuRulesetContainer(this, beatmap, isForCurrentRuleset);
public override IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new[]
public override IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0) => new[]
{
new KeyBinding(Key.Z, OsuAction.LeftButton),
new KeyBinding(Key.X, OsuAction.RightButton),
new KeyBinding(Key.LastKey + 1, OsuAction.LeftButton),
new KeyBinding(Key.LastKey + 2, OsuAction.RightButton),
};
public override IEnumerable<BeatmapStatistic> GetBeatmapStatistics(WorkingBeatmap beatmap) => new[]
{
new BeatmapStatistic
{
Name = @"Circle count",

View File

@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.UI
protected override Playfield<OsuHitObject, OsuJudgement> CreatePlayfield() => new OsuPlayfield();
protected override PassThroughInputManager CreateActionMappingInputManager() => new OsuInputManager(Ruleset?.RulesetInfo);
public override PassThroughInputManager CreateKeyBindingInputManager() => new OsuInputManager(Ruleset?.RulesetInfo);
protected override DrawableHitObject<OsuHitObject, OsuJudgement> GetVisualRepresentation(OsuHitObject h)
{

View File

@ -27,7 +27,7 @@ namespace osu.Game.Input.Bindings
[Column("Action")]
public new int Action
{
get { return base.Action; }
get { return (int)base.Action; }
private set { base.Action = value; }
}
}

View File

@ -1,6 +1,7 @@
// 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.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Input.Bindings;
using osu.Game.Rulesets;
@ -18,7 +19,9 @@ namespace osu.Game.Input.Bindings
private readonly int? variant;
private BindingStore store;
private KeyBindingStore store;
public override IEnumerable<KeyBinding> DefaultMappings => ruleset.CreateInstance().GetDefaultKeyBindings();
/// <summary>
/// Create a new instance.
@ -34,24 +37,15 @@ namespace osu.Game.Input.Bindings
}
[BackgroundDependencyLoader]
private void load(BindingStore bindings)
private void load(KeyBindingStore keyBindings)
{
store = bindings;
store = keyBindings;
}
protected override void ReloadMappings()
{
// load defaults
base.ReloadMappings();
var rulesetId = ruleset?.ID;
// load from database if present.
if (store != null)
{
foreach (var b in store.Query<DatabasedKeyBinding>(b => b.RulesetID == rulesetId && b.Variant == variant))
KeyBindings.Add(b);
}
KeyBindings.Clear();
KeyBindings.AddRange(store.GetProcessedList(DefaultMappings, ruleset?.ID, variant));
}
}
}

View File

@ -21,7 +21,7 @@ namespace osu.Game.Input.Bindings
handler = game;
}
protected override IEnumerable<KeyBinding> CreateDefaultMappings() => new[]
public override IEnumerable<KeyBinding> DefaultMappings => new[]
{
new KeyBinding(Key.F8, GlobalAction.ToggleChat),
new KeyBinding(Key.F9, GlobalAction.ToggleSocial),

View File

@ -2,6 +2,8 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using osu.Framework.Input.Bindings;
using osu.Framework.Platform;
using osu.Game.Database;
using osu.Game.Input.Bindings;
@ -9,9 +11,9 @@ using SQLite.Net;
namespace osu.Game.Input
{
public class BindingStore : DatabaseBackedStore
public class KeyBindingStore : DatabaseBackedStore
{
public BindingStore(SQLiteConnection connection, Storage storage = null)
public KeyBindingStore(SQLiteConnection connection, Storage storage = null)
: base(connection, storage)
{
}
@ -44,5 +46,16 @@ namespace osu.Game.Input
typeof(DatabasedKeyBinding)
};
public List<KeyBinding> GetProcessedList(IEnumerable<KeyBinding> defaults, int? rulesetId, int? variant)
{
//todo: cache and share reference
List<KeyBinding> bindings = new List<KeyBinding>(defaults);
// load from database if present.
foreach (var b in Query<DatabasedKeyBinding>(b => b.RulesetID == rulesetId && b.Variant == variant))
bindings.Add(b);
return bindings;
}
}
}
}

View File

@ -39,7 +39,7 @@ namespace osu.Game
protected ScoreStore ScoreStore;
protected BindingStore BindingStore;
protected KeyBindingStore KeyBindingStore;
protected override string MainResourceFile => @"osu.Game.Resources.dll";
@ -108,7 +108,7 @@ namespace osu.Game
dependencies.Cache(FileStore = new FileStore(connection, Host.Storage));
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, FileStore, connection, RulesetStore, Host));
dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, connection, Host, BeatmapManager));
dependencies.Cache(BindingStore = new BindingStore(connection));
dependencies.Cache(KeyBindingStore = new KeyBindingStore(connection));
dependencies.Cache(new OsuColour());
//this completely overrides the framework default. will need to change once we make a proper FontStore.
@ -183,12 +183,14 @@ namespace osu.Game
{
base.LoadComplete();
GlobalBindingInputManager globalBinding;
base.Content.Add(new RatioAdjust
{
Children = new Drawable[]
{
Cursor = new MenuCursor(),
new GlobalBindingInputManager(this)
globalBinding = new GlobalBindingInputManager(this)
{
RelativeSizeAxes = Axes.Both,
Child = new OsuTooltipContainer(Cursor)
@ -200,6 +202,8 @@ namespace osu.Game
}
});
dependencies.Cache(globalBinding);
// TODO: This is temporary until we reimplement the local FPS display.
// It's just to allow end-users to access the framework FPS display without knowing the shortcut key.
fpsDisplayVisible = LocalConfig.GetBindable<bool>(OsuSetting.ShowFpsDisplay);

View File

@ -8,6 +8,7 @@ using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Scoring;
using osu.Game.Overlays.Settings;
@ -53,5 +54,17 @@ namespace osu.Game.Rulesets
/// Do not override this unless you are a legacy mode.
/// </summary>
public virtual int LegacyID => -1;
/// <summary>
/// A list of available variant ids.
/// </summary>
public virtual IEnumerable<int> AvailableVariants => new[] { 0 };
/// <summary>
/// Get a list of default keys for the specified variant.
/// </summary>
/// <param name="variant">A variant.</param>
/// <returns>A list of valid <see cref="KeyBinding"/>s.</returns>
public virtual IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0) => new KeyBinding[] { };
}
}

View File

@ -76,7 +76,7 @@ namespace osu.Game.Rulesets.UI
internal RulesetContainer(Ruleset ruleset)
{
Ruleset = ruleset;
KeyConversionInputManager = CreateActionMappingInputManager();
KeyConversionInputManager = CreateKeyBindingInputManager();
KeyConversionInputManager.RelativeSizeAxes = Axes.Both;
}
@ -95,7 +95,7 @@ namespace osu.Game.Rulesets.UI
/// Creates a key conversion input manager.
/// </summary>
/// <returns>The input manager.</returns>
protected virtual PassThroughInputManager CreateActionMappingInputManager() => new PassThroughInputManager();
public virtual PassThroughInputManager CreateKeyBindingInputManager() => new PassThroughInputManager();
protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new FramedReplayInputHandler(replay);

View File

@ -94,7 +94,7 @@
<Compile Include="Graphics\UserInterface\OsuContextMenuItem.cs" />
<Compile Include="Input\Bindings\DatabasedKeyBinding.cs" />
<Compile Include="Input\Bindings\DatabasedKeyBindingInputManager.cs" />
<Compile Include="Input\BindingStore.cs" />
<Compile Include="Input\KeyBindingStore.cs" />
<Compile Include="Input\Bindings\GlobalBindingInputManager.cs" />
<Compile Include="IO\FileStore.cs" />
<Compile Include="IO\FileInfo.cs" />