Skip to content

Commit

Permalink
Expose HoldingForHUD state from HUDOverlay as bindable
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed May 11, 2022
1 parent 396be1b commit 1c36995
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions osu.Game/Screens/Play/HUDOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public class HUDOverlay : Container, IKeyBindingHandler<GlobalAction>

internal readonly IBindable<bool> IsPlaying = new Bindable<bool>();

private bool holdingForHUD;
public IBindable<bool> HoldingForHUD => holdingForHUD;

private readonly BindableBool holdingForHUD = new BindableBool();

private readonly SkinnableTargetContainer mainComponents;

Expand Down Expand Up @@ -144,14 +146,16 @@ private void load(OsuConfigManager config, INotificationOverlay notificationOver
hideTargets.ForEach(d => d.Hide());
}

public override void Hide() => throw new InvalidOperationException($"{nameof(HUDOverlay)} should not be hidden as it will remove the ability of a user to quit. Use {nameof(ShowHud)} instead.");
public override void Hide() =>
throw new InvalidOperationException($"{nameof(HUDOverlay)} should not be hidden as it will remove the ability of a user to quit. Use {nameof(ShowHud)} instead.");

protected override void LoadComplete()
{
base.LoadComplete();

ShowHud.BindValueChanged(visible => hideTargets.ForEach(d => d.FadeTo(visible.NewValue ? 1 : 0, FADE_DURATION, FADE_EASING)));

holdingForHUD.BindValueChanged(_ => updateVisibility());
IsPlaying.BindValueChanged(_ => updateVisibility());
configVisibilityMode.BindValueChanged(_ => updateVisibility(), true);

Expand Down Expand Up @@ -204,7 +208,7 @@ private void updateVisibility()
if (ShowHud.Disabled)
return;

if (holdingForHUD)
if (holdingForHUD.Value)
{
ShowHud.Value = true;
return;
Expand Down Expand Up @@ -287,8 +291,7 @@ public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
switch (e.Action)
{
case GlobalAction.HoldForHUD:
holdingForHUD = true;
updateVisibility();
holdingForHUD.Value = true;
return true;

case GlobalAction.ToggleInGameInterface:
Expand Down Expand Up @@ -318,8 +321,7 @@ public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
switch (e.Action)
{
case GlobalAction.HoldForHUD:
holdingForHUD = false;
updateVisibility();
holdingForHUD.Value = false;
break;
}
}
Expand Down

0 comments on commit 1c36995

Please sign in to comment.