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