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

Add basic hotkey offset adjust support (via existing offset control)

This commit is contained in:
Dean Herbert 2023-12-23 19:55:05 +09:00
parent fc56188b95
commit 27a9dcc5a1
No known key found for this signature in database
3 changed files with 68 additions and 23 deletions

View File

@ -160,6 +160,8 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.Enter, GlobalAction.ToggleChatFocus),
new KeyBinding(InputKey.F1, GlobalAction.SaveReplay),
new KeyBinding(InputKey.F2, GlobalAction.ExportReplay),
new KeyBinding(InputKey.Plus, GlobalAction.IncreaseOffset),
new KeyBinding(InputKey.Minus, GlobalAction.DecreaseOffset),
};
private static IEnumerable<KeyBinding> replayKeyBindings => new[]
@ -404,6 +406,12 @@ namespace osu.Game.Input.Bindings
[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.EditorToggleRotateControl))]
EditorToggleRotateControl,
[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.IncreaseOffset))]
IncreaseOffset,
[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.DecreaseOffset))]
DecreaseOffset
}
public enum GlobalActionCategory

View File

@ -344,6 +344,16 @@ namespace osu.Game.Localisation
/// </summary>
public static LocalisableString ExportReplay => new TranslatableString(getKey(@"export_replay"), @"Export replay");
/// <summary>
/// "Increase offset"
/// </summary>
public static LocalisableString IncreaseOffset => new TranslatableString(getKey(@"increase_offset"), @"Increase offset");
/// <summary>
/// "Decrease offset"
/// </summary>
public static LocalisableString DecreaseOffset => new TranslatableString(getKey(@"decrease_offset"), @"Decrease offset");
/// <summary>
/// "Toggle rotate control"
/// </summary>

View File

@ -9,6 +9,8 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
@ -16,6 +18,7 @@ using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Mods;
@ -26,7 +29,7 @@ using osuTK;
namespace osu.Game.Screens.Play.PlayerSettings
{
public partial class BeatmapOffsetControl : CompositeDrawable
public partial class BeatmapOffsetControl : CompositeDrawable, IKeyBindingHandler<GlobalAction>
{
public Bindable<ScoreInfo?> ReferenceScore { get; } = new Bindable<ScoreInfo?>();
@ -88,28 +91,6 @@ namespace osu.Game.Screens.Play.PlayerSettings
};
}
public partial class OffsetSliderBar : PlayerSliderBar<double>
{
protected override Drawable CreateControl() => new CustomSliderBar();
protected partial class CustomSliderBar : SliderBar
{
public override LocalisableString TooltipText =>
Current.Value == 0
? LocalisableString.Interpolate($@"{base.TooltipText} ms")
: LocalisableString.Interpolate($@"{base.TooltipText} ms {getEarlyLateText(Current.Value)}");
private LocalisableString getEarlyLateText(double value)
{
Debug.Assert(value != 0);
return value > 0
? BeatmapOffsetControlStrings.HitObjectsAppearEarlier
: BeatmapOffsetControlStrings.HitObjectsAppearLater;
}
}
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -243,5 +224,51 @@ namespace osu.Game.Screens.Play.PlayerSettings
base.Dispose(isDisposing);
beatmapOffsetSubscription?.Dispose();
}
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
double amount = e.AltPressed ? 1 : 5;
switch (e.Action)
{
case GlobalAction.IncreaseOffset:
Current.Value += amount;
return true;
case GlobalAction.DecreaseOffset:
Current.Value -= amount;
return true;
}
return false;
}
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
public partial class OffsetSliderBar : PlayerSliderBar<double>
{
protected override Drawable CreateControl() => new CustomSliderBar();
protected partial class CustomSliderBar : SliderBar
{
public override LocalisableString TooltipText =>
Current.Value == 0
? LocalisableString.Interpolate($@"{base.TooltipText} ms")
: LocalisableString.Interpolate($@"{base.TooltipText} ms {getEarlyLateText(Current.Value)}");
private LocalisableString getEarlyLateText(double value)
{
Debug.Assert(value != 0);
return value > 0
? BeatmapOffsetControlStrings.HitObjectsAppearEarlier
: BeatmapOffsetControlStrings.HitObjectsAppearLater;
}
}
}
}
}