mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 07:33:55 +09:00
Initial refactoring of key binding logic
This commit is contained in:
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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),
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user