1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 23:55:35 +08:00
osu-lazer/osu.Game/Screens/Utility/LatencyArea.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

155 lines
5.0 KiB
C#
Raw Normal View History

2022-06-07 22:10:08 +08:00
// 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 System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
2022-06-07 22:10:08 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Cursor;
2022-06-07 22:10:08 +08:00
using osu.Game.Overlays;
using osu.Game.Screens.Utility.SampleComponents;
2022-06-07 22:10:08 +08:00
using osuTK.Input;
namespace osu.Game.Screens.Utility
{
[Cached]
public class LatencyArea : CompositeDrawable, IProvideCursor
2022-06-07 22:10:08 +08:00
{
[Resolved]
private OverlayColourProvider overlayColourProvider { get; set; } = null!;
public Action? ReportUserBest { get; set; }
private Drawable? background;
private readonly Key key;
private Container visualContent = null!;
2022-06-10 13:18:35 +08:00
public readonly int? TargetFrameRate;
2022-06-07 22:10:08 +08:00
public readonly BindableBool IsActiveArea = new BindableBool();
public readonly Bindable<LatencyVisualMode> VisualMode = new Bindable<LatencyVisualMode>();
public CursorContainer? MenuCursor { get; private set; }
public bool ProvidingUserCursor => IsActiveArea.Value;
2022-06-10 13:18:35 +08:00
public LatencyArea(Key key, int? targetFrameRate)
2022-06-07 22:10:08 +08:00
{
this.key = key;
TargetFrameRate = targetFrameRate;
RelativeSizeAxes = Axes.Both;
Masking = true;
}
protected override void LoadComplete()
{
base.LoadComplete();
InternalChildren = new[]
{
background = new Box
{
Colour = overlayColourProvider.Background6,
RelativeSizeAxes = Axes.Both,
},
new ButtonWithKeyBind(key)
{
Text = "Feels better",
Y = 20,
Width = 0.8f,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Action = () => ReportUserBest?.Invoke(),
},
visualContent = new Container
{
RelativeSizeAxes = Axes.Both,
},
2022-06-07 22:10:08 +08:00
};
IsActiveArea.BindValueChanged(active =>
{
background.FadeColour(active.NewValue ? overlayColourProvider.Background4 : overlayColourProvider.Background6, 200, Easing.OutQuint);
}, true);
VisualMode.BindValueChanged(mode =>
{
switch (mode.NewValue)
{
case LatencyVisualMode.Simple:
visualContent.Children = new Drawable[]
{
new LatencyMovableBox
{
RelativeSizeAxes = Axes.Both,
},
MenuCursor = new LatencyCursorContainer
{
RelativeSizeAxes = Axes.Both,
},
};
break;
case LatencyVisualMode.CircleGameplay:
visualContent.Children = new Drawable[]
{
new CircleGameplay
{
RelativeSizeAxes = Axes.Both,
},
MenuCursor = new LatencyCursorContainer
{
RelativeSizeAxes = Axes.Both,
},
};
break;
case LatencyVisualMode.ScrollingGameplay:
visualContent.Children = new Drawable[]
{
new ScrollingGameplay
{
RelativeSizeAxes = Axes.Both,
},
MenuCursor = new LatencyCursorContainer
{
RelativeSizeAxes = Axes.Both,
},
};
break;
default:
throw new ArgumentOutOfRangeException();
}
}, true);
2022-06-07 22:10:08 +08:00
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
IsActiveArea.Value = true;
return base.OnMouseMove(e);
}
private double lastFrameTime;
public override bool UpdateSubTree()
{
double elapsed = Clock.CurrentTime - lastFrameTime;
2022-06-10 13:18:35 +08:00
if (TargetFrameRate.HasValue && elapsed < 1000.0 / TargetFrameRate)
2022-06-07 22:10:08 +08:00
return false;
lastFrameTime = Clock.CurrentTime;
return base.UpdateSubTree();
}
}
}