1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 11:22:57 +08:00

Refactor update logic to be easier to follow

This commit is contained in:
Dean Herbert 2023-01-19 19:27:05 +09:00
parent b22363ed8c
commit 2ce32e3209

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -66,30 +65,27 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
counter.Direction.Value = convertedDirection;
}, true);
Mode.BindValueChanged(_ =>
{
updateMode();
//Refreshing the counter causes the first child to become visible, so we want to make sure it isn't if it shouldn't be
updateFirstChildVisibility();
}, true);
ShowMaxJudgement.BindValueChanged(showMax =>
updateFirstChildVisibility(), true);
Mode.BindValueChanged(_ => updateDisplay());
ShowMaxJudgement.BindValueChanged(_ => updateDisplay(), true);
}
private void updateMode()
private void updateDisplay()
{
foreach (var counter in CounterFlow.Children)
for (int i = 0; i < CounterFlow.Children.Count; i++)
{
if (shouldShow(counter))
JudgementCounter counter = CounterFlow.Children[i];
if (shouldShow(i, counter))
counter.Show();
else
counter.Hide();
}
bool shouldShow(JudgementCounter counter)
bool shouldShow(int index, JudgementCounter counter)
{
if (index == 0 && !ShowMaxJudgement.Value)
return false;
if (counter.Result.Type.IsBasic())
return true;
@ -110,14 +106,6 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
}
}
private void updateFirstChildVisibility()
{
var firstChild = CounterFlow.Children.FirstOrDefault();
if (firstChild != null)
firstChild.State.Value = ShowMaxJudgement.Value ? Visibility.Visible : Visibility.Hidden;
}
private FillDirection getFillDirection(Direction flow)
{
switch (flow)