mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Merge pull request #14506 from peppy/skip-overlay-optimisations
Remove delegate overhead in `SkipOverlay`
This commit is contained in:
@ -12,7 +12,6 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
@ -37,6 +36,8 @@ namespace osu.Game.Screens.Play
|
||||
private FadeContainer fadeContainer;
|
||||
private double displayTime;
|
||||
|
||||
private bool isClickable;
|
||||
|
||||
[Resolved]
|
||||
private GameplayClock gameplayClock { get; set; }
|
||||
|
||||
@ -101,7 +102,7 @@ namespace osu.Game.Screens.Play
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
fadeContainer.Show();
|
||||
fadeContainer.TriggerShow();
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -118,24 +119,27 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
button.Action = () => RequestSkip?.Invoke();
|
||||
displayTime = gameplayClock.CurrentTime;
|
||||
|
||||
fadeContainer.TriggerShow();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
var progress = fadeOutBeginTime <= displayTime ? 1 : Math.Max(0, 1 - (gameplayClock.CurrentTime - displayTime) / (fadeOutBeginTime - displayTime));
|
||||
double progress = fadeOutBeginTime <= displayTime ? 1 : Math.Max(0, 1 - (gameplayClock.CurrentTime - displayTime) / (fadeOutBeginTime - displayTime));
|
||||
|
||||
remainingTimeBox.Width = (float)Interpolation.Lerp(remainingTimeBox.Width, progress, Math.Clamp(Time.Elapsed / 40, 0, 1));
|
||||
|
||||
button.Enabled.Value = progress > 0;
|
||||
buttonContainer.State.Value = progress > 0 ? Visibility.Visible : Visibility.Hidden;
|
||||
isClickable = progress > 0;
|
||||
button.Enabled.Value = isClickable;
|
||||
buttonContainer.State.Value = isClickable ? Visibility.Visible : Visibility.Hidden;
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
if (!e.HasAnyButtonPressed)
|
||||
fadeContainer.Show();
|
||||
if (isClickable && !e.HasAnyButtonPressed)
|
||||
fadeContainer.TriggerShow();
|
||||
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
@ -164,34 +168,45 @@ namespace osu.Game.Screens.Play
|
||||
public event Action<Visibility> StateChanged;
|
||||
|
||||
private Visibility state;
|
||||
private ScheduledDelegate scheduledHide;
|
||||
private double? nextHideTime;
|
||||
|
||||
public override bool IsPresent => true;
|
||||
|
||||
public void TriggerShow()
|
||||
{
|
||||
Show();
|
||||
|
||||
if (!IsHovered && !IsDragged)
|
||||
nextHideTime = Time.Current + 1000;
|
||||
else
|
||||
nextHideTime = null;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (nextHideTime != null && nextHideTime <= Time.Current)
|
||||
{
|
||||
Hide();
|
||||
nextHideTime = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Visibility State
|
||||
{
|
||||
get => state;
|
||||
set
|
||||
{
|
||||
bool stateChanged = value != state;
|
||||
if (value == state)
|
||||
return;
|
||||
|
||||
state = value;
|
||||
|
||||
scheduledHide?.Cancel();
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case Visibility.Visible:
|
||||
// we may be triggered to become visible multiple times but we only want to transform once.
|
||||
if (stateChanged)
|
||||
this.FadeIn(500, Easing.OutExpo);
|
||||
|
||||
if (!IsHovered && !IsDragged)
|
||||
{
|
||||
using (BeginDelayedSequence(1000))
|
||||
scheduledHide = Schedule(Hide);
|
||||
}
|
||||
|
||||
this.FadeIn(500, Easing.OutExpo);
|
||||
break;
|
||||
|
||||
case Visibility.Hidden:
|
||||
@ -212,7 +227,7 @@ namespace osu.Game.Screens.Play
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
Show();
|
||||
scheduledHide?.Cancel();
|
||||
nextHideTime = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user