Skip to content

Add control to allow changing offset from gameplay #26076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
104 changes: 104 additions & 0 deletions osu.Game/Screens/Play/GameplayOffsetControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// 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;

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
75 changes: 52 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 Down Expand Up @@ -88,28 +91,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 +224,53 @@ protected override void Dispose(bool isDisposing)
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 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);
}
}
}
}