Skip to content

Commit

Permalink
Merge pull request #26076 from peppy/gameplay-offset-adjust
Browse files Browse the repository at this point in the history
Add control to allow changing offset from gameplay
  • Loading branch information
bdach committed Dec 23, 2023
2 parents d72ec81 + 686b2a4 commit a0915a0
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 23 deletions.
8 changes: 8 additions & 0 deletions osu.Game/Input/Bindings/GlobalActionContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public static IEnumerable<GlobalAction> GetGlobalActionsFor(GlobalActionCategory
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[]
Expand Down Expand Up @@ -404,6 +406,12 @@ public enum GlobalAction

[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.EditorToggleRotateControl))]
EditorToggleRotateControl,

[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.IncreaseOffset))]
IncreaseOffset,

[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.DecreaseOffset))]
DecreaseOffset
}

public enum GlobalActionCategory
Expand Down
10 changes: 10 additions & 0 deletions osu.Game/Localisation/GlobalActionKeyBindingStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ public static class GlobalActionKeyBindingStrings
/// </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>
Expand Down
107 changes: 107 additions & 0 deletions osu.Game/Screens/Play/GameplayOffsetControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Screens.Play.PlayerSettings;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Screens.Play
{
/// <summary>
/// This provides the ability to change the offset while in gameplay.
/// Eventually this should be replaced with all settings from PlayerLoader being accessible from the game.
/// </summary>
internal partial class GameplayOffsetControl : VisibilityContainer
{
protected override bool StartHidden => true;

public override bool PropagateNonPositionalInputSubTree => true;

// Disable interaction for now to avoid any funny business with slider bar dragging.
public override bool PropagatePositionalInputSubTree => false;

private BeatmapOffsetControl offsetControl = null!;

private OsuTextFlowContainer text = null!;

private ScheduledDelegate? hideOp;

public GameplayOffsetControl()
{
AutoSizeAxes = Axes.Y;
Width = SettingsToolboxGroup.CONTAINER_WIDTH;

Masking = true;
CornerRadius = 5;

// Allow BeatmapOffsetControl to handle keyboard input.
AlwaysPresent = true;

Anchor = Anchor.CentreRight;
Origin = Anchor.CentreRight;

X = 100;
}

[BackgroundDependencyLoader]
private void load(OverlayColourProvider? colourProvider)
{
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.8f,
Colour = colourProvider?.Background4 ?? Color4.Black,
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(10),
Spacing = new Vector2(5),
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
offsetControl = new BeatmapOffsetControl(),
text = new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(weight: FontWeight.SemiBold))
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
TextAnchor = Anchor.TopCentre,
}
}
},
};

offsetControl.Current.BindValueChanged(val =>
{
text.Text = BeatmapOffsetControl.GetOffsetExplanatoryText(val.NewValue);
Show();
hideOp?.Cancel();
hideOp = Scheduler.AddDelayed(Hide, 500);
});
}

protected override void PopIn()
{
this.FadeIn(500, Easing.OutQuint)
.MoveToX(0, 500, Easing.OutQuint);
}

protected override void PopOut()
{
this.FadeOut(500, Easing.InQuint)
.MoveToX(100, 500, Easing.InQuint);
}
}
}
6 changes: 6 additions & 0 deletions osu.Game/Screens/Play/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ private Drawable createOverlayComponents(IWorkingBeatmap working)
OnRetry = () => Restart(),
OnQuit = () => PerformExit(true),
},
new GameplayOffsetControl
{
Margin = new MarginPadding(20),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
}
},
};

Expand Down
96 changes: 73 additions & 23 deletions osu.Game/Screens/Play/PlayerSettings/BeatmapOffsetControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
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;
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;
Expand All @@ -26,7 +29,7 @@

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?>();

Expand All @@ -48,6 +51,12 @@ public partial class BeatmapOffsetControl : CompositeDrawable
[Resolved]
private OsuColour colours { get; set; } = null!;

[Resolved]
private Player? player { get; set; }

[Resolved]
private IGameplayClock? gameplayClock { get; set; }

private double lastPlayAverage;
private double lastPlayBeatmapOffset;
private HitEventTimingDistributionGraph? lastPlayGraph;
Expand Down Expand Up @@ -88,28 +97,6 @@ public BeatmapOffsetControl()
};
}

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();
Expand Down Expand Up @@ -243,5 +230,68 @@ protected override void Dispose(bool isDisposing)
base.Dispose(isDisposing);
beatmapOffsetSubscription?.Dispose();
}

public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
// General limitations to ensure players don't do anything too weird.
// These match stable for now.
if (player is SubmittingPlayer)
{
// TODO: the blocking conditions should probably display a message.
if (player?.IsBreakTime.Value == false && gameplayClock?.CurrentTime - gameplayClock?.StartTime > 10000)
return false;

if (gameplayClock?.IsPaused.Value == true)
return false;
}

// To match stable, this should adjust by 5 ms, or 1 ms when holding alt.
// But that is hard to make work with global actions due to the operating mode.
// Let's use the more precise as a default for now.
const double amount = 1;

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 static LocalisableString GetOffsetExplanatoryText(double offset)
{
return offset == 0
? LocalisableString.Interpolate($@"{offset:0.0} ms")
: LocalisableString.Interpolate($@"{offset:0.0} ms {getEarlyLateText(offset)}");

LocalisableString getEarlyLateText(double value)
{
Debug.Assert(value != 0);

return value > 0
? BeatmapOffsetControlStrings.HitObjectsAppearEarlier
: BeatmapOffsetControlStrings.HitObjectsAppearLater;
}
}

public partial class OffsetSliderBar : PlayerSliderBar<double>
{
protected override Drawable CreateControl() => new CustomSliderBar();

protected partial class CustomSliderBar : SliderBar
{
public override LocalisableString TooltipText => GetOffsetExplanatoryText(Current.Value);
}
}
}
}

0 comments on commit a0915a0

Please sign in to comment.