From aded12af9e157ea0535dfbf8da48ed7fe3a8c2f0 Mon Sep 17 00:00:00 2001
From: Andrei Zavatski <megaman9919@gmail.com>
Date: Sun, 22 Dec 2019 03:30:17 +0300
Subject: [PATCH] Refactoor to avoid bindable usage

---
 .../HUD/HitErrorMeters/ColourHitErrorMeter.cs | 54 ++++++-------------
 1 file changed, 15 insertions(+), 39 deletions(-)

diff --git a/osu.Game/Screens/Play/HUD/HitErrorMeters/ColourHitErrorMeter.cs b/osu.Game/Screens/Play/HUD/HitErrorMeters/ColourHitErrorMeter.cs
index b76f2c7817..196eb23da6 100644
--- a/osu.Game/Screens/Play/HUD/HitErrorMeters/ColourHitErrorMeter.cs
+++ b/osu.Game/Screens/Play/HUD/HitErrorMeters/ColourHitErrorMeter.cs
@@ -1,9 +1,7 @@
 // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
 // See the LICENCE file in the repository root for full licence text.
 
-using System.Collections.Generic;
 using System.Linq;
-using osu.Framework.Bindables;
 using osu.Framework.Graphics;
 using osu.Framework.Graphics.Containers;
 using osu.Framework.Graphics.Shapes;
@@ -16,11 +14,9 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
 {
     public class ColourHitErrorMeter : HitErrorMeter
     {
-        private const int max_available_judgements = 20;
         private const int animation_duration = 200;
 
         private readonly JudgementFlow judgementsFlow;
-        private readonly BindableList<(Color4 colour, JudgementResult result)> judgements = new BindableList<(Color4 colour, JudgementResult result)>();
 
         public ColourHitErrorMeter(HitWindows hitWindows)
             : base(hitWindows)
@@ -29,69 +25,43 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
             InternalChild = judgementsFlow = new JudgementFlow();
         }
 
-        protected override void LoadComplete()
-        {
-            base.LoadComplete();
-            judgementsFlow.Judgements.BindTo(judgements);
-        }
-
-        public override void OnNewJudgement(JudgementResult judgement)
-        {
-            judgements.Add((GetColourForHitResult(HitWindows.ResultFor(judgement.TimeOffset)), judgement));
-
-            if (judgements.Count > max_available_judgements)
-                judgements.RemoveAt(0);
-        }
+        public override void OnNewJudgement(JudgementResult judgement) => judgementsFlow.Push(GetColourForHitResult(HitWindows.ResultFor(judgement.TimeOffset)));
 
         private class JudgementFlow : FillFlowContainer<DrawableResult>
         {
+            private const int max_available_judgements = 20;
             private const int drawable_judgement_size = 8;
             private const int spacing = 2;
 
-            public readonly BindableList<(Color4 colour, JudgementResult result)> Judgements = new BindableList<(Color4 colour, JudgementResult result)>();
-
             private int runningDepth;
 
             public JudgementFlow()
             {
                 AutoSizeAxes = Axes.X;
-                Height = max_available_judgements * (drawable_judgement_size + spacing);
+                Height = max_available_judgements * (drawable_judgement_size + spacing) - spacing;
                 Spacing = new Vector2(0, spacing);
                 Direction = FillDirection.Vertical;
                 LayoutDuration = animation_duration;
                 LayoutEasing = Easing.OutQuint;
             }
 
-            protected override void LoadComplete()
+            public void Push(Color4 colour)
             {
-                base.LoadComplete();
-                Judgements.ItemsAdded += push;
-                Judgements.ItemsRemoved += pop;
-            }
+                Insert(runningDepth--, new DrawableResult(colour, drawable_judgement_size));
 
-            private void push(IEnumerable<(Color4 colour, JudgementResult result)> judgements)
-            {
-                var (colour, result) = judgements.Single();
-                Insert(runningDepth--, new DrawableResult(colour, result, drawable_judgement_size));
-            }
-
-            private void pop(IEnumerable<(Color4 colour, JudgementResult result)> judgements)
-            {
-                var (colour, result) = judgements.Single();
-                Children.FirstOrDefault(c => c.Result == result).FadeOut(animation_duration, Easing.OutQuint).Expire();
+                if (Children.Count > max_available_judgements)
+                    Children.FirstOrDefault(c => !c.IsRemoved).Remove();
             }
         }
 
         private class DrawableResult : Container
         {
-            public JudgementResult Result { get; private set; }
+            public bool IsRemoved { get; private set; }
 
             private readonly CircularContainer content;
 
-            public DrawableResult(Color4 colour, JudgementResult result, int size)
+            public DrawableResult(Color4 colour, int size)
             {
-                Result = result;
-
                 Size = new Vector2(size);
                 Child = content = new CircularContainer
                 {
@@ -113,6 +83,12 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
                 content.MoveToY(-DrawSize.Y);
                 content.MoveToY(0, animation_duration, Easing.OutQuint);
             }
+
+            public void Remove()
+            {
+                IsRemoved = true;
+                this.FadeOut(animation_duration, Easing.OutQuint).Expire();
+            }
         }
     }
 }