mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:37:28 +08:00
Tidy up implementation of PlaybackSettings
This commit is contained in:
parent
e73910571f
commit
dafff26d0e
@ -11,9 +11,9 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Localisation;
|
||||||
using osu.Game.Screens.Edit.Timing;
|
using osu.Game.Screens.Edit.Timing;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osu.Game.Localisation;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play.PlayerSettings
|
namespace osu.Game.Screens.Play.PlayerSettings
|
||||||
{
|
{
|
||||||
@ -28,26 +28,31 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
|||||||
Precision = 0.01,
|
Precision = 0.01,
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly PlayerSliderBar<double> rateSlider;
|
private PlayerSliderBar<double> rateSlider = null!;
|
||||||
|
|
||||||
private readonly OsuSpriteText multiplierText;
|
private OsuSpriteText multiplierText = null!;
|
||||||
|
|
||||||
private readonly BindableBool isPaused = new BindableBool();
|
private readonly IBindable<bool> isPaused = new BindableBool();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private GameplayClockContainer? gameplayClock { get; set; }
|
private GameplayClockContainer gameplayClock { get; set; } = null!;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private GameplayState? gameplayState { get; set; }
|
private GameplayState gameplayState { get; set; } = null!;
|
||||||
|
|
||||||
|
private IconButton pausePlay = null!;
|
||||||
|
|
||||||
public PlaybackSettings()
|
public PlaybackSettings()
|
||||||
: base("playback")
|
: base("playback")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
{
|
{
|
||||||
const double seek_amount = 5000;
|
const double seek_amount = 5000;
|
||||||
const double seek_fast_amount = 10000;
|
const double seek_fast_amount = 10000;
|
||||||
|
|
||||||
IconButton play;
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new FillFlowContainer
|
new FillFlowContainer
|
||||||
@ -82,7 +87,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
|||||||
Action = () => seek(-1, seek_amount),
|
Action = () => seek(-1, seek_amount),
|
||||||
TooltipText = PlayerSettingsOverlayStrings.SeekBackwardSeconds(seek_amount / 1000),
|
TooltipText = PlayerSettingsOverlayStrings.SeekBackwardSeconds(seek_amount / 1000),
|
||||||
},
|
},
|
||||||
play = new IconButton
|
pausePlay = new IconButton
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
@ -91,13 +96,10 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
|||||||
Icon = FontAwesome.Regular.PlayCircle,
|
Icon = FontAwesome.Regular.PlayCircle,
|
||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
if (gameplayClock != null)
|
if (gameplayClock.IsRunning)
|
||||||
{
|
gameplayClock.Stop();
|
||||||
if (gameplayClock.IsRunning)
|
else
|
||||||
gameplayClock.Stop();
|
gameplayClock.Start();
|
||||||
else
|
|
||||||
gameplayClock.Start();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
new SeekButton
|
new SeekButton
|
||||||
@ -141,26 +143,6 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
isPaused.BindValueChanged(paused =>
|
|
||||||
{
|
|
||||||
if (!paused.NewValue)
|
|
||||||
{
|
|
||||||
play.TooltipText = ToastStrings.PauseTrack;
|
|
||||||
play.Icon = FontAwesome.Regular.PauseCircle;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
play.TooltipText = ToastStrings.PlayTrack;
|
|
||||||
play.Icon = FontAwesome.Regular.PlayCircle;
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
void seek(int direction, double amount)
|
|
||||||
{
|
|
||||||
double target = Math.Clamp((gameplayClock?.CurrentTime ?? 0) + (direction * amount), 0, gameplayState?.Beatmap.GetLastObjectTime() ?? 0);
|
|
||||||
gameplayClock?.Seek(target);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -168,8 +150,26 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
rateSlider.Current.BindValueChanged(multiplier => multiplierText.Text = $"{multiplier.NewValue:0.00}x", true);
|
rateSlider.Current.BindValueChanged(multiplier => multiplierText.Text = $"{multiplier.NewValue:0.00}x", true);
|
||||||
|
|
||||||
if (gameplayClock != null)
|
isPaused.BindTo(gameplayClock.IsPaused);
|
||||||
isPaused.BindTarget = gameplayClock.IsPaused;
|
isPaused.BindValueChanged(paused =>
|
||||||
|
{
|
||||||
|
if (!paused.NewValue)
|
||||||
|
{
|
||||||
|
pausePlay.TooltipText = ToastStrings.PauseTrack;
|
||||||
|
pausePlay.Icon = FontAwesome.Regular.PauseCircle;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pausePlay.TooltipText = ToastStrings.PlayTrack;
|
||||||
|
pausePlay.Icon = FontAwesome.Regular.PlayCircle;
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void seek(int direction, double amount)
|
||||||
|
{
|
||||||
|
double target = Math.Clamp(gameplayClock.CurrentTime + (direction * amount), 0, gameplayState.Beatmap.GetLastObjectTime());
|
||||||
|
gameplayClock.Seek(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
private partial class SeekButton : IconButton
|
private partial class SeekButton : IconButton
|
||||||
|
Loading…
Reference in New Issue
Block a user