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

@ -224,6 +224,12 @@ namespace osu.Game.Configuration
return new TrackedSettings return new TrackedSettings
{ {
new TrackedSetting<bool>(OsuSetting.ShowFpsDisplay, state => new SettingDescription(
rawValue: state,
name: GlobalActionKeyBindingStrings.ToggleFPSCounter,
value: state ? CommonStrings.Enabled.ToLower() : CommonStrings.Disabled.ToLower(),
shortcut: LookupKeyBindings(GlobalAction.ToggleFPSDisplay))
),
new TrackedSetting<bool>(OsuSetting.MouseDisableButtons, disabledState => new SettingDescription( new TrackedSetting<bool>(OsuSetting.MouseDisableButtons, disabledState => new SettingDescription(
rawValue: !disabledState, rawValue: !disabledState,
name: GlobalActionKeyBindingStrings.ToggleGameplayMouseButtons, name: GlobalActionKeyBindingStrings.ToggleGameplayMouseButtons,

View File

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

View File

@ -45,6 +45,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.F9, GlobalAction.ToggleSocial), new KeyBinding(InputKey.F9, GlobalAction.ToggleSocial),
new KeyBinding(InputKey.F10, GlobalAction.ToggleGameplayMouseButtons), new KeyBinding(InputKey.F10, GlobalAction.ToggleGameplayMouseButtons),
new KeyBinding(InputKey.F12, GlobalAction.TakeScreenshot), new KeyBinding(InputKey.F12, GlobalAction.TakeScreenshot),
new KeyBinding(new[] { InputKey.Control, InputKey.Shift, InputKey.F }, GlobalAction.ToggleFPSDisplay),
new KeyBinding(new[] { InputKey.Control, InputKey.Alt, InputKey.R }, GlobalAction.ResetInputSettings), new KeyBinding(new[] { InputKey.Control, InputKey.Alt, InputKey.R }, GlobalAction.ResetInputSettings),
new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar), new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar),
@ -328,5 +329,8 @@ namespace osu.Game.Input.Bindings
[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.EditorTapForBPM))] [LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.EditorTapForBPM))]
EditorTapForBPM, EditorTapForBPM,
[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.ToggleFPSCounter))]
ToggleFPSDisplay,
} }
} }

View File

@ -274,6 +274,11 @@ namespace osu.Game.Localisation
/// </summary> /// </summary>
public static LocalisableString ToggleSkinEditor => new TranslatableString(getKey(@"toggle_skin_editor"), @"Toggle skin editor"); public static LocalisableString ToggleSkinEditor => new TranslatableString(getKey(@"toggle_skin_editor"), @"Toggle skin editor");
/// <summary>
/// "Toggle FPS counter"
/// </summary>
public static LocalisableString ToggleFPSCounter => new TranslatableString(getKey(@"toggle_fps_counter"), @"Toggle FPS counter");
/// <summary> /// <summary>
/// "Previous volume meter" /// "Previous volume meter"
/// </summary> /// </summary>

View File

@ -159,6 +159,8 @@ namespace osu.Game
protected FirstRunSetupOverlay FirstRunOverlay { get; private set; } protected FirstRunSetupOverlay FirstRunOverlay { get; private set; }
private FPSCounter fpsCounter;
private VolumeOverlay volume; private VolumeOverlay volume;
private OsuLogo osuLogo; private OsuLogo osuLogo;
@ -814,7 +816,7 @@ namespace osu.Game
ScreenStack.ScreenPushed += screenPushed; ScreenStack.ScreenPushed += screenPushed;
ScreenStack.ScreenExited += screenExited; ScreenStack.ScreenExited += screenExited;
loadComponentSingleFile(new FPSCounter loadComponentSingleFile(fpsCounter = new FPSCounter
{ {
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight, Origin = Anchor.BottomRight,
@ -1121,6 +1123,10 @@ namespace osu.Game
switch (e.Action) switch (e.Action)
{ {
case GlobalAction.ToggleFPSDisplay:
fpsCounter.ToggleVisibility();
return true;
case GlobalAction.ToggleSkinEditor: case GlobalAction.ToggleSkinEditor:
skinEditor.ToggleVisibility(); skinEditor.ToggleVisibility();
return true; return true;