1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 00:02:56 +08:00

Merge pull request #15518 from Susko3/use-ReadableKeyCombinationProvider

This commit is contained in:
Dean Herbert 2021-11-08 19:00:16 +09:00 committed by GitHub
commit f79c9e7f7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 50 additions and 13 deletions

View File

@ -52,7 +52,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.1106.0" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2021.1108.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Transitive Dependencies"> <ItemGroup Label="Transitive Dependencies">
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. --> <!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Database; using osu.Game.Database;
@ -33,7 +34,7 @@ namespace osu.Game.Tests.Database
storage = new NativeStorage(directory.FullName); storage = new NativeStorage(directory.FullName);
realmContextFactory = new RealmContextFactory(storage, "test"); realmContextFactory = new RealmContextFactory(storage, "test");
keyBindingStore = new RealmKeyBindingStore(realmContextFactory); keyBindingStore = new RealmKeyBindingStore(realmContextFactory, new ReadableKeyCombinationProvider());
} }
[Test] [Test]

View File

@ -3,6 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
@ -16,10 +17,12 @@ namespace osu.Game.Input
public class RealmKeyBindingStore public class RealmKeyBindingStore
{ {
private readonly RealmContextFactory realmFactory; private readonly RealmContextFactory realmFactory;
private readonly ReadableKeyCombinationProvider keyCombinationProvider;
public RealmKeyBindingStore(RealmContextFactory realmFactory) public RealmKeyBindingStore(RealmContextFactory realmFactory, ReadableKeyCombinationProvider keyCombinationProvider)
{ {
this.realmFactory = realmFactory; this.realmFactory = realmFactory;
this.keyCombinationProvider = keyCombinationProvider;
} }
/// <summary> /// <summary>
@ -35,7 +38,7 @@ namespace osu.Game.Input
{ {
foreach (var action in context.All<RealmKeyBinding>().Where(b => b.RulesetID == null && (GlobalAction)b.ActionInt == globalAction)) foreach (var action in context.All<RealmKeyBinding>().Where(b => b.RulesetID == null && (GlobalAction)b.ActionInt == globalAction))
{ {
string str = action.KeyCombination.ReadableString(); string str = keyCombinationProvider.GetReadableString(action.KeyCombination);
// even if found, the readable string may be empty for an unbound action. // even if found, the readable string may be empty for an unbound action.
if (str.Length > 0) if (str.Length > 0)

View File

@ -170,7 +170,7 @@ namespace osu.Game
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(ReadableKeyCombinationProvider keyCombinationProvider)
{ {
try try
{ {
@ -309,7 +309,7 @@ namespace osu.Game
base.Content.Add(CreateScalingContainer().WithChildren(mainContent)); base.Content.Add(CreateScalingContainer().WithChildren(mainContent));
KeyBindingStore = new RealmKeyBindingStore(realmFactory); KeyBindingStore = new RealmKeyBindingStore(realmFactory, keyCombinationProvider);
KeyBindingStore.Register(globalBindings, RulesetStore.AvailableRulesets); KeyBindingStore.Register(globalBindings, RulesetStore.AvailableRulesets);
dependencies.Cache(globalBindings); dependencies.Cache(globalBindings);

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Database; using osu.Game.Database;
@ -57,13 +58,16 @@ namespace osu.Game.Overlays.Settings.Sections.Input
public bool FilteringActive { get; set; } public bool FilteringActive { get; set; }
[Resolved]
private ReadableKeyCombinationProvider keyCombinationProvider { get; set; }
private OsuSpriteText text; private OsuSpriteText text;
private FillFlowContainer cancelAndClearButtons; private FillFlowContainer cancelAndClearButtons;
private FillFlowContainer<KeyButton> buttons; private FillFlowContainer<KeyButton> buttons;
private Bindable<bool> isDefault { get; } = new BindableBool(true); private Bindable<bool> isDefault { get; } = new BindableBool(true);
public IEnumerable<string> FilterTerms => bindings.Select(b => b.KeyCombination.ReadableString()).Prepend(text.Text.ToString()); public IEnumerable<string> FilterTerms => bindings.Select(b => keyCombinationProvider.GetReadableString(b.KeyCombination)).Prepend(text.Text.ToString());
public KeyBindingRow(object action, List<RealmKeyBinding> bindings) public KeyBindingRow(object action, List<RealmKeyBinding> bindings)
{ {
@ -422,6 +426,9 @@ namespace osu.Game.Overlays.Settings.Sections.Input
[Resolved] [Resolved]
private OverlayColourProvider colourProvider { get; set; } private OverlayColourProvider colourProvider { get; set; }
[Resolved]
private ReadableKeyCombinationProvider keyCombinationProvider { get; set; }
private bool isBinding; private bool isBinding;
public bool IsBinding public bool IsBinding
@ -470,12 +477,19 @@ namespace osu.Game.Overlays.Settings.Sections.Input
Margin = new MarginPadding(5), Margin = new MarginPadding(5),
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Text = keyBinding.KeyCombination.ReadableString(),
}, },
new HoverSounds() new HoverSounds()
}; };
} }
protected override void LoadComplete()
{
base.LoadComplete();
keyCombinationProvider.KeymapChanged += updateKeyCombinationText;
updateKeyCombinationText();
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -514,7 +528,22 @@ namespace osu.Game.Overlays.Settings.Sections.Input
return; return;
KeyBinding.KeyCombination = newCombination; KeyBinding.KeyCombination = newCombination;
Text.Text = KeyBinding.KeyCombination.ReadableString(); updateKeyCombinationText();
}
private void updateKeyCombinationText()
{
Scheduler.AddOnce(updateText);
void updateText() => Text.Text = keyCombinationProvider.GetReadableString(KeyBinding.KeyCombination);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (keyCombinationProvider != null)
keyCombinationProvider.KeymapChanged -= updateKeyCombinationText;
} }
} }
} }

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Database; using osu.Game.Database;
@ -39,6 +40,9 @@ namespace osu.Game.Overlays.Toolbar
[Resolved] [Resolved]
private TextureStore textures { get; set; } private TextureStore textures { get; set; }
[Resolved]
private ReadableKeyCombinationProvider keyCombinationProvider { get; set; }
public void SetIcon(string texture) => public void SetIcon(string texture) =>
SetIcon(new Sprite SetIcon(new Sprite
{ {
@ -207,7 +211,7 @@ namespace osu.Game.Overlays.Toolbar
if (realmKeyBinding != null) if (realmKeyBinding != null)
{ {
string keyBindingString = realmKeyBinding.KeyCombination.ReadableString(); string keyBindingString = keyCombinationProvider.GetReadableString(realmKeyBinding.KeyCombination);
if (!string.IsNullOrEmpty(keyBindingString)) if (!string.IsNullOrEmpty(keyBindingString))
keyBindingTooltip.Text = $" ({keyBindingString})"; keyBindingTooltip.Text = $" ({keyBindingString})";

View File

@ -36,7 +36,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Realm" Version="10.6.0" /> <PackageReference Include="Realm" Version="10.6.0" />
<PackageReference Include="ppy.osu.Framework" Version="2021.1106.0" /> <PackageReference Include="ppy.osu.Framework" Version="2021.1108.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" />
<PackageReference Include="Sentry" Version="3.10.0" /> <PackageReference Include="Sentry" Version="3.10.0" />
<PackageReference Include="SharpCompress" Version="0.30.0" /> <PackageReference Include="SharpCompress" Version="0.30.0" />

View File

@ -70,7 +70,7 @@
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.1106.0" /> <PackageReference Include="ppy.osu.Framework.iOS" Version="2021.1108.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.1026.0" />
</ItemGroup> </ItemGroup>
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) --> <!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
@ -93,7 +93,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ppy.osu.Framework" Version="2021.1106.0" /> <PackageReference Include="ppy.osu.Framework" Version="2021.1108.0" />
<PackageReference Include="SharpCompress" Version="0.30.0" /> <PackageReference Include="SharpCompress" Version="0.30.0" />
<PackageReference Include="NUnit" Version="3.13.2" /> <PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />