Add global key binding for FPS toggle

This commit is contained in:
Dean Herbert
2022-07-20 21:05:20 +09:00
parent 0a1744faca
commit f54aff2ece
5 changed files with 34 additions and 6 deletions

View File

@ -20,7 +20,7 @@ using osuTK;
namespace osu.Game.Graphics.UserInterface
{
public class FPSCounter : CompositeDrawable, IHasCustomTooltip
public class FPSCounter : VisibilityContainer, IHasCustomTooltip
{
private RollingCounter<double> msCounter = null!;
private RollingCounter<double> fpsCounter = null!;
@ -31,7 +31,7 @@ namespace osu.Game.Graphics.UserInterface
private const float idle_background_alpha = 0.4f;
private Bindable<bool> showFpsDisplay = null!;
private readonly BindableBool showFpsDisplay = new BindableBool(true);
[Resolved]
private OsuColour colours { get; set; } = null!;
@ -83,7 +83,7 @@ namespace osu.Game.Graphics.UserInterface
},
};
showFpsDisplay = config.GetBindable<bool>(OsuSetting.ShowFpsDisplay);
config.BindWith(OsuSetting.ShowFpsDisplay, showFpsDisplay);
}
protected override void LoadComplete()
@ -94,11 +94,18 @@ namespace osu.Game.Graphics.UserInterface
showFpsDisplay.BindValueChanged(showFps =>
{
this.FadeTo(showFps.NewValue ? 1 : 0, 100);
displayTemporarily();
State.Value = showFps.NewValue ? Visibility.Visible : Visibility.Hidden;
if (showFps.NewValue)
displayTemporarily();
}, true);
State.BindValueChanged(state => showFpsDisplay.Value = state.NewValue == Visibility.Visible);
}
protected override void PopIn() => this.FadeIn(100);
protected override void PopOut() => this.FadeOut(100);
protected override bool OnHover(HoverEvent e)
{
background.FadeTo(1, 200);