mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Add the ability for the game OSD to display user bindings
Adds binding display for mouse button toggle / HUD toggle keys. - [ ] Depends on #10786 for ease-of-merge
This commit is contained in:
parent
9caa56c64f
commit
6014751e29
@ -2,6 +2,7 @@
|
|||||||
// 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 System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Configuration.Tracking;
|
using osu.Framework.Configuration.Tracking;
|
||||||
@ -9,6 +10,7 @@ using osu.Framework.Extensions;
|
|||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Input;
|
using osu.Game.Input;
|
||||||
|
using osu.Game.Input.Bindings;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Screens.Select;
|
using osu.Game.Screens.Select;
|
||||||
@ -173,19 +175,28 @@ namespace osu.Game.Configuration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override TrackedSettings CreateTrackedSettings() => new TrackedSettings
|
public override TrackedSettings CreateTrackedSettings()
|
||||||
{
|
{
|
||||||
new TrackedSetting<bool>(OsuSetting.MouseDisableButtons, v => new SettingDescription(!v, "gameplay mouse buttons", v ? "disabled" : "enabled")),
|
// these need to be assigned in normal game startup scenarios.
|
||||||
new TrackedSetting<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode, m => new SettingDescription(m, "HUD Visibility", m.GetDescription())),
|
Debug.Assert(LookupKeyBindings != null);
|
||||||
new TrackedSetting<ScalingMode>(OsuSetting.Scaling, m => new SettingDescription(m, "scaling", m.GetDescription())),
|
Debug.Assert(LookupSkinName != null);
|
||||||
new TrackedSetting<int>(OsuSetting.Skin, m =>
|
|
||||||
{
|
|
||||||
string skinName = LookupSkinName?.Invoke(m) ?? string.Empty;
|
|
||||||
return new SettingDescription(skinName, "skin", skinName);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
public Func<int, string> LookupSkinName { get; set; }
|
return new TrackedSettings
|
||||||
|
{
|
||||||
|
new TrackedSetting<bool>(OsuSetting.MouseDisableButtons, v => new SettingDescription(!v, "gameplay mouse buttons", v ? "disabled" : "enabled", LookupKeyBindings(GlobalAction.ToggleGameplayMouseButtons))),
|
||||||
|
new TrackedSetting<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode, m => new SettingDescription(m, "HUD Visibility", m.GetDescription(), $"cycle: shift-tab quick view: {LookupKeyBindings(GlobalAction.HoldForHUD)}")),
|
||||||
|
new TrackedSetting<ScalingMode>(OsuSetting.Scaling, m => new SettingDescription(m, "scaling", m.GetDescription())),
|
||||||
|
new TrackedSetting<int>(OsuSetting.Skin, m =>
|
||||||
|
{
|
||||||
|
string skinName = LookupSkinName(m) ?? string.Empty;
|
||||||
|
return new SettingDescription(skinName, "skin", skinName);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Func<int, string> LookupSkinName { private get; set; }
|
||||||
|
|
||||||
|
public Func<GlobalAction, string> LookupKeyBindings { private get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum OsuSetting
|
public enum OsuSetting
|
||||||
|
@ -32,6 +32,23 @@ namespace osu.Game.Input
|
|||||||
|
|
||||||
public void Register(KeyBindingContainer manager) => insertDefaults(manager.DefaultKeyBindings);
|
public void Register(KeyBindingContainer manager) => insertDefaults(manager.DefaultKeyBindings);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieve all user-defined key combinations (in a format that can be displayed) for a specific action.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="globalAction">The action to lookup.</param>
|
||||||
|
/// <returns>A set of display strings for all the user's key configuration for the action.</returns>
|
||||||
|
public IEnumerable<string> GetReadableKeyCombinationsFor(GlobalAction globalAction)
|
||||||
|
{
|
||||||
|
foreach (var action in Query().Where(b => (GlobalAction)b.Action == globalAction))
|
||||||
|
{
|
||||||
|
string str = action.KeyCombination.ReadableString();
|
||||||
|
|
||||||
|
// even if found, the readable string may be empty for an unbound action.
|
||||||
|
if (str.Length > 0)
|
||||||
|
yield return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void insertDefaults(IEnumerable<KeyBinding> defaults, int? rulesetId = null, int? variant = null)
|
private void insertDefaults(IEnumerable<KeyBinding> defaults, int? rulesetId = null, int? variant = null)
|
||||||
{
|
{
|
||||||
using (var usage = ContextFactory.GetForWrite())
|
using (var usage = ContextFactory.GetForWrite())
|
||||||
|
@ -552,6 +552,16 @@ namespace osu.Game
|
|||||||
// if this becomes a more common thing, tracked settings should be reconsidered to allow local DI.
|
// if this becomes a more common thing, tracked settings should be reconsidered to allow local DI.
|
||||||
LocalConfig.LookupSkinName = id => SkinManager.GetAllUsableSkins().FirstOrDefault(s => s.ID == id)?.ToString() ?? "Unknown";
|
LocalConfig.LookupSkinName = id => SkinManager.GetAllUsableSkins().FirstOrDefault(s => s.ID == id)?.ToString() ?? "Unknown";
|
||||||
|
|
||||||
|
LocalConfig.LookupKeyBindings = l =>
|
||||||
|
{
|
||||||
|
var combinations = KeyBindingStore.GetReadableKeyCombinationsFor(l).ToArray();
|
||||||
|
|
||||||
|
if (combinations.Length == 0)
|
||||||
|
return "none";
|
||||||
|
|
||||||
|
return string.Join(" or ", combinations);
|
||||||
|
};
|
||||||
|
|
||||||
Container logoContainer;
|
Container logoContainer;
|
||||||
BackButton.Receptor receptor;
|
BackButton.Receptor receptor;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user