1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 07:32:55 +08:00

Clean up syntax for readability

This commit is contained in:
mk56-spn 2022-12-16 17:40:39 +01:00
parent 0c177aa7de
commit f3873b73e3
4 changed files with 19 additions and 77 deletions

View File

@ -81,9 +81,6 @@ namespace osu.Game.Tests.Visual.Gameplay
AddRepeatStep("Add judgement", () => applyOneJudgement(HitResult.Great), 2);
AddRepeatStep("Add judgement", () => applyOneJudgement(HitResult.Miss), 2);
AddRepeatStep("Add judgement", () => applyOneJudgement(HitResult.Meh), 2);
AddRepeatStep("Add judgement", () => applyOneJudgement(HitResult.LargeTickHit), 2);
AddStep("Show all judgements", () => counterDisplay.Mode.Value = JudgementCounterDisplay.DisplayMode.All);
AddAssert("Check value added whilst hidden", () => hiddenCount() == 2);
}
[Test]
@ -105,8 +102,10 @@ namespace osu.Game.Tests.Visual.Gameplay
public void TestToggleJudgementNames()
{
AddStep("Hide judgement names", () => counterDisplay.ShowName.Value = false);
AddWaitStep("wait some", 2);
AddAssert("Assert hidden", () => counterDisplay.JudgementContainer.Children.OfType<JudgementCounter>().First().ResultName.Alpha == 0);
AddStep("Hide judgement names", () => counterDisplay.ShowName.Value = true);
AddWaitStep("wait some", 2);
AddAssert("Assert shown", () => counterDisplay.JudgementContainer.Children.OfType<JudgementCounter>().First().ResultName.Alpha == 1);
}

View File

@ -20,10 +20,7 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
public readonly JudgementCounterInfo Result;
public JudgementCounter(JudgementCounterInfo result)
{
Result = result;
}
public JudgementCounter(JudgementCounterInfo result) => Result = result;
public OsuSpriteText ResultName = null!;
private FillFlowContainer flowContainer = null!;
@ -52,45 +49,18 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
var result = Result.Type;
if (result.IsBasic())
{
Colour = colours.ForHitResult(Result.Type);
return;
}
if (!result.IsBonus())
{
Colour = colours.PurpleLight;
return;
}
Colour = colours.PurpleLighter;
Colour = result.IsBasic() ? colours.ForHitResult(Result.Type) : !result.IsBonus() ? colours.PurpleLight : colours.PurpleLighter;
}
protected override void LoadComplete()
{
ShowName.BindValueChanged(value =>
{
if (value.NewValue)
{
ResultName.Show();
return;
}
ResultName.Hide();
}, true);
ResultName.FadeTo(value.NewValue ? 1 : 0, JudgementCounterDisplay.TRANSFORM_DURATION, Easing.OutQuint), true);
Direction.BindValueChanged(direction =>
{
flowContainer.Direction = direction.NewValue;
if (direction.NewValue == FillDirection.Vertical)
{
changeAnchor(Anchor.TopLeft);
return;
}
changeAnchor(Anchor.BottomLeft);
changeAnchor(direction.NewValue == FillDirection.Vertical ? Anchor.TopLeft : Anchor.BottomLeft);
void changeAnchor(Anchor anchor) => counter.Anchor = ResultName.Anchor = counter.Origin = ResultName.Origin = anchor;
}, true);
@ -98,15 +68,8 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
base.LoadComplete();
}
protected override void PopIn()
{
this.FadeIn(500, Easing.OutQuint);
}
protected override void PopOut()
{
this.FadeOut(100);
}
protected override void PopIn() => this.FadeIn(JudgementCounterDisplay.TRANSFORM_DURATION, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(100);
private sealed partial class JudgementRollingCounter : RollingCounter<int>
{

View File

@ -16,6 +16,7 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
{
public partial class JudgementCounterDisplay : CompositeDrawable, ISkinnableDrawable
{
public const int TRANSFORM_DURATION = 500;
public bool UsesFixedAnchor { get; set; }
[SettingSource("Display mode")]
@ -47,9 +48,7 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
};
foreach (var result in tally.Results)
{
JudgementContainer.Add(createCounter(result));
}
}
protected override void LoadComplete()
@ -62,22 +61,13 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
//Can't pass directly due to Enum conversion
foreach (var counter in JudgementContainer.Children.OfType<JudgementCounter>())
{
counter.Direction.Value = getFlow(direction.NewValue);
}
}, true);
Mode.BindValueChanged(_ => updateMode(), true);
ShowMax.BindValueChanged(value =>
{
var firstChild = JudgementContainer.Children.FirstOrDefault();
if (value.NewValue)
{
firstChild?.Show();
return;
}
firstChild?.Hide();
firstChild.FadeTo(value.NewValue ? 1 : 0, TRANSFORM_DURATION, Easing.OutQuint);
}, true);
}
@ -89,22 +79,14 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
{
case DisplayMode.Simple:
counter.Hide();
break;
case DisplayMode.Normal:
if (counter.Result.Type.IsBonus())
{
counter.Hide();
break;
}
counter.Show();
counter.FadeTo(counter.Result.Type.IsBonus() ? 0 : 1);
break;
case DisplayMode.All:
counter.Show();
break;
default:

View File

@ -7,6 +7,7 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
namespace osu.Game.Screens.Play.HUD.JudgementCounter
@ -35,17 +36,14 @@ namespace osu.Game.Screens.Play.HUD.JudgementCounter
{
base.LoadComplete();
scoreProcessor.NewJudgement += judgement =>
{
foreach (JudgementCounterInfo result in Results.Where(result => result.Type == judgement.Type))
result.ResultCount.Value++;
};
scoreProcessor.NewJudgement += judgement => updateCount(judgement, false);
scoreProcessor.JudgementReverted += judgement => updateCount(judgement, true);
}
scoreProcessor.JudgementReverted += judgement =>
{
foreach (JudgementCounterInfo result in Results.Where(result => result.Type == judgement.Type))
result.ResultCount.Value--;
};
private void updateCount(JudgementResult judgement, bool revert)
{
foreach (JudgementCounterInfo result in Results.Where(result => result.Type == judgement.Type))
result.ResultCount.Value = revert ? result.ResultCount.Value - 1 : result.ResultCount.Value + 1;
}
}
}