Update `CatchComboDisplay` implementation to use newly exposed bindable

This commit is contained in:
Dean Herbert 2022-10-12 15:14:33 +09:00
parent d2d589a156
commit 652bc4ac61
1 changed files with 10 additions and 54 deletions

View File

@ -6,11 +6,9 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Configuration;
using osu.Game.Rulesets.Catch.Objects.Drawables; using osu.Game.Rulesets.Catch.Objects.Drawables;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK.Graphics; using osuTK.Graphics;
@ -27,14 +25,7 @@ public class CatchComboDisplay : SkinnableDrawable
[CanBeNull] [CanBeNull]
public ICatchComboCounter ComboCounter => Drawable as ICatchComboCounter; public ICatchComboCounter ComboCounter => Drawable as ICatchComboCounter;
private Bindable<HUDVisibilityMode> hudVisibilityMode = null!; private readonly IBindable<bool> showCombo = new BindableBool(true);
private readonly BindableBool replayLoaded = new BindableBool();
private readonly BindableBool showCombo = new BindableBool();
[Resolved]
private OsuConfigManager config { get; set; }
public CatchComboDisplay() public CatchComboDisplay()
: base(new CatchSkinComponent(CatchSkinComponents.CatchComboCounter), _ => Empty()) : base(new CatchSkinComponent(CatchSkinComponents.CatchComboCounter), _ => Empty())
@ -42,51 +33,18 @@ public CatchComboDisplay()
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(DrawableRuleset drawableRuleset, HUDOverlay hud) private void load(Player player)
{ {
hudVisibilityMode = config.GetBindable<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode); if (player != null)
hudVisibilityMode.BindValueChanged(s =>
{ {
updateVisibilityState(); showCombo.BindTo(player.ShowingOverlayComponents);
}); showCombo.BindValueChanged(s =>
if (drawableRuleset != null)
replayLoaded.BindTo(drawableRuleset.HasReplayLoaded);
replayLoaded.BindValueChanged(s =>
{
updateVisibilityState();
});
showCombo.BindValueChanged(s =>
{
if (ComboCounter == null) return;
if (!s.NewValue)
{ {
ComboCounter.Hide(); if (!s.NewValue)
} ComboCounter?.Hide();
}); else
ComboCounter?.Show();
updateVisibilityState(); }, true);
void updateVisibilityState()
{
switch (hudVisibilityMode.Value)
{
case HUDVisibilityMode.Never:
showCombo.Value = false;
break;
case HUDVisibilityMode.HideDuringGameplay:
showCombo.Value = replayLoaded.Value;
break;
case HUDVisibilityMode.Always:
showCombo.Value = true;
break;
}
} }
} }
@ -120,8 +78,6 @@ public void OnRevertResult(DrawableCatchHitObject judgedObject, JudgementResult
private void updateCombo(int newCombo, Color4? hitObjectColour) private void updateCombo(int newCombo, Color4? hitObjectColour)
{ {
if (!showCombo.Value) return;
currentCombo = newCombo; currentCombo = newCombo;
ComboCounter?.UpdateCombo(newCombo, hitObjectColour); ComboCounter?.UpdateCombo(newCombo, hitObjectColour);
} }