From 738980e3f76f8e2ddfbeab90fb40d1109e49c689 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 24 Jan 2020 10:31:47 +0300 Subject: [PATCH] Refactor OsuTabControl.AccentColour --- .../Graphics/UserInterface/OsuTabControl.cs | 30 ++++++++----------- osu.Game/Overlays/OverlayTabControl.cs | 6 ++-- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuTabControl.cs b/osu.Game/Graphics/UserInterface/OsuTabControl.cs index c0129c921e..deffa863dd 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabControl.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabControl.cs @@ -22,12 +22,20 @@ namespace osu.Game.Graphics.UserInterface { public class OsuTabControl : TabControl { - private readonly Bindable accentColour = new Bindable(); + protected readonly Bindable AccentColourBindable = new Bindable(); public Color4 AccentColour { - get => accentColour.Value; - set => accentColour.Value = value; + get => AccentColourBindable.Value; + set + { + AccentColourBindable.Value = value; + + if (Dropdown is IHasAccentColour dropdown) + dropdown.AccentColour = value; + foreach (var i in TabContainer.Children.OfType()) + i.AccentColour = value; + } } private readonly Box strip; @@ -67,24 +75,10 @@ namespace osu.Game.Graphics.UserInterface [BackgroundDependencyLoader] private void load(OsuColour colours) { - if (accentColour.Value == default) + if (AccentColour == default) AccentColour = colours.Blue; } - protected override void LoadComplete() - { - base.LoadComplete(); - accentColour.BindValueChanged(OnAccentColourChanged, true); - } - - protected virtual void OnAccentColourChanged(ValueChangedEvent colour) - { - if (Dropdown is IHasAccentColour dropdown) - dropdown.AccentColour = colour.NewValue; - foreach (var i in TabContainer.Children.OfType()) - i.AccentColour = colour.NewValue; - } - public Color4 StripColour { get => strip.Colour; diff --git a/osu.Game/Overlays/OverlayTabControl.cs b/osu.Game/Overlays/OverlayTabControl.cs index 72977d6bff..e8ef05f473 100644 --- a/osu.Game/Overlays/OverlayTabControl.cs +++ b/osu.Game/Overlays/OverlayTabControl.cs @@ -37,10 +37,10 @@ namespace osu.Game.Overlays }); } - protected override void OnAccentColourChanged(ValueChangedEvent colour) + protected override void LoadComplete() { - base.OnAccentColourChanged(colour); - bar.Colour = colour.NewValue; + base.LoadComplete(); + AccentColourBindable.BindValueChanged(colour => bar.Colour = colour.NewValue, true); } protected override Dropdown CreateDropdown() => null;