2017-08-15 23:08:59 +08:00
|
|
|
// 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;
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Game.Input;
|
|
|
|
using osu.Game.Overlays.Settings;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.KeyConfiguration
|
|
|
|
{
|
|
|
|
public abstract class KeyBindingsSection : SettingsSection
|
|
|
|
{
|
|
|
|
protected IEnumerable<KeyBinding> Defaults;
|
|
|
|
|
|
|
|
protected RulesetInfo Ruleset;
|
|
|
|
|
|
|
|
protected KeyBindingsSection()
|
|
|
|
{
|
|
|
|
FlowContent.Spacing = new Vector2(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(KeyBindingStore store)
|
|
|
|
{
|
2017-08-16 00:19:21 +08:00
|
|
|
var enumType = Defaults?.FirstOrDefault()?.Action?.GetType();
|
2017-08-15 23:08:59 +08:00
|
|
|
|
2017-08-16 00:19:21 +08:00
|
|
|
if (enumType == null) return;
|
2017-08-15 23:08:59 +08:00
|
|
|
|
|
|
|
// for now let's just assume a variant of zero.
|
|
|
|
// this will need to be implemented in a better way in the future.
|
2017-08-16 00:19:21 +08:00
|
|
|
int? variant = null;
|
2017-08-15 23:08:59 +08:00
|
|
|
if (Ruleset != null)
|
|
|
|
variant = 0;
|
|
|
|
|
|
|
|
var bindings = store.Query(Ruleset?.ID, variant);
|
|
|
|
|
2017-08-16 00:19:21 +08:00
|
|
|
foreach (Enum v in Enum.GetValues(enumType))
|
|
|
|
// one row per valid action.
|
2017-08-16 00:14:37 +08:00
|
|
|
Add(new KeyBindingRow(v, bindings.Where(b => b.Action.Equals((int)(object)v))));
|
2017-08-15 23:08:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|