From 7befcf74ffbb54fc4783d22f9235667db6c0e1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 17 May 2021 18:53:09 +0200 Subject: [PATCH] Split value change callbacks out to separate methods --- .../Overlays/News/Sidebar/MonthSection.cs | 36 ++++++++++--------- osu.Game/Overlays/News/Sidebar/YearsPanel.cs | 28 ++++++++------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/osu.Game/Overlays/News/Sidebar/MonthSection.cs b/osu.Game/Overlays/News/Sidebar/MonthSection.cs index 20c4d2e83e..77f09b750d 100644 --- a/osu.Game/Overlays/News/Sidebar/MonthSection.cs +++ b/osu.Game/Overlays/News/Sidebar/MonthSection.cs @@ -153,28 +153,30 @@ namespace osu.Game.Overlays.News.Sidebar { base.LoadComplete(); - IsOpen.BindValueChanged(open => - { - ClearTransforms(true); - - if (open.NewValue) - { - AutoSizeAxes = Axes.Y; - content.FadeIn(animation_duration, Easing.OutQuint); - } - else - { - AutoSizeAxes = Axes.None; - this.ResizeHeightTo(0, animation_duration, Easing.OutQuint); - - content.FadeOut(animation_duration, Easing.OutQuint); - } - }, true); + IsOpen.BindValueChanged(_ => updateState(), true); // First state change should be instant. FinishTransforms(true); } + private void updateState() + { + ClearTransforms(true); + + if (IsOpen.Value) + { + AutoSizeAxes = Axes.Y; + content.FadeIn(animation_duration, Easing.OutQuint); + } + else + { + AutoSizeAxes = Axes.None; + this.ResizeHeightTo(0, animation_duration, Easing.OutQuint); + + content.FadeOut(animation_duration, Easing.OutQuint); + } + } + private bool shouldUpdateAutosize = true; // Workaround to allow the dropdown to be opened immediately since FinishTransforms doesn't work for AutosizeDuration. diff --git a/osu.Game/Overlays/News/Sidebar/YearsPanel.cs b/osu.Game/Overlays/News/Sidebar/YearsPanel.cs index ffdb5cf22e..849cdbf659 100644 --- a/osu.Game/Overlays/News/Sidebar/YearsPanel.cs +++ b/osu.Game/Overlays/News/Sidebar/YearsPanel.cs @@ -56,23 +56,25 @@ namespace osu.Game.Overlays.News.Sidebar { base.LoadComplete(); - metadata.BindValueChanged(m => + metadata.BindValueChanged(_ => recreateDrawables(), true); + } + + private void recreateDrawables() + { + yearsFlow.Clear(); + + if (metadata.Value == null) { - yearsFlow.Clear(); + Hide(); + return; + } - if (m.NewValue == null) - { - Hide(); - return; - } + var currentYear = metadata.Value.CurrentYear; - var currentYear = m.NewValue.CurrentYear; + foreach (var y in metadata.Value.Years) + yearsFlow.Add(new YearButton(y, y == currentYear)); - foreach (var y in m.NewValue.Years) - yearsFlow.Add(new YearButton(y, y == currentYear)); - - Show(); - }, true); + Show(); } public class YearButton : OsuHoverContainer