diff --git a/osu.Game/Graphics/UserInterface/OsuDropdown.cs b/osu.Game/Graphics/UserInterface/OsuDropdown.cs index 9c816b8230..37bd4f2395 100644 --- a/osu.Game/Graphics/UserInterface/OsuDropdown.cs +++ b/osu.Game/Graphics/UserInterface/OsuDropdown.cs @@ -1,9 +1,9 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Linq; using OpenTK.Graphics; using osu.Framework.Allocation; -using osu.Framework.Configuration; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -14,35 +14,43 @@ using OpenTK; namespace osu.Game.Graphics.UserInterface { - public class OsuDropdown : Dropdown + public class OsuDropdown : Dropdown, IHasAccentColour { - public readonly Bindable AccentColour = new Bindable(); + private Color4 accentColour; + public Color4 AccentColour + { + get { return accentColour; } + set + { + accentColour = value; + updateAccentColour(); + } + } [BackgroundDependencyLoader] private void load(OsuColour colours) { - if (AccentColour.Value == null) - AccentColour.Value = colours.PinkDarker; + if (accentColour == default(Color4)) + accentColour = colours.PinkDarker; + updateAccentColour(); + } - protected override DropdownHeader CreateHeader() + private void updateAccentColour() { - var newHeader = new OsuDropdownHeader(); - newHeader.AccentColour.BindTo(AccentColour); + var header = Header as IHasAccentColour; + if (header != null) header.AccentColour = accentColour; - return newHeader; + var menu = Menu as IHasAccentColour; + if (menu != null) menu.AccentColour = accentColour; } - protected override DropdownMenu CreateMenu() - { - var newMenu = new OsuDropdownMenu(); - newMenu.AccentColour.BindTo(AccentColour); + protected override DropdownHeader CreateHeader() => new OsuDropdownHeader(); - return newMenu; - } + protected override DropdownMenu CreateMenu() => new OsuDropdownMenu(); #region OsuDropdownMenu - protected class OsuDropdownMenu : DropdownMenu + protected class OsuDropdownMenu : DropdownMenu, IHasAccentColour { // todo: this uses the same styling as OsuMenu. hopefully we can just use OsuMenu in the future with some refactoring public OsuDropdownMenu() @@ -65,23 +73,41 @@ namespace osu.Game.Graphics.UserInterface this.ResizeHeightTo(State == MenuState.Opened ? actualHeight : 0, 300, Easing.OutQuint); } - public readonly Bindable AccentColour = new Bindable(); - - - protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) + private Color4 accentColour; + public Color4 AccentColour { - var newItem = new DrawableOsuDropdownMenuItem(item); - newItem.AccentColour.BindTo(AccentColour); - - return newItem; + get { return accentColour; } + set + { + accentColour = value; + foreach (var c in Children.OfType()) + c.AccentColour = value; + } } - #region DrawableOsuDropdownMenuItem - protected class DrawableOsuDropdownMenuItem : DrawableDropdownMenuItem - { - public readonly Bindable AccentColour = new Bindable(); + protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableOsuDropdownMenuItem(item) { AccentColour = accentColour }; - private TextContainer textContainer; + #region DrawableOsuDropdownMenuItem + protected class DrawableOsuDropdownMenuItem : DrawableDropdownMenuItem, IHasAccentColour + { + private Color4? accentColour; + public Color4 AccentColour + { + get { return accentColour ?? nonAccentSelectedColour; } + set + { + accentColour = value; + updateColours(); + } + } + + private void updateColours() + { + BackgroundColourHover = accentColour ?? nonAccentHoverColour; + BackgroundColourSelected = accentColour ?? nonAccentSelectedColour; + UpdateBackgroundColour(); + UpdateForegroundColour(); + } private Color4 nonAccentHoverColour; private Color4 nonAccentSelectedColour; @@ -93,36 +119,29 @@ namespace osu.Game.Graphics.UserInterface Masking = true; CornerRadius = 6; - - AccentColour.ValueChanged += updateAccent; } [BackgroundDependencyLoader] private void load(OsuColour colours) { BackgroundColour = Color4.Transparent; + nonAccentHoverColour = colours.PinkDarker; nonAccentSelectedColour = Color4.Black.Opacity(0.5f); - } - - private void updateAccent(Color4? newValue) - { - BackgroundColourHover = newValue ?? nonAccentHoverColour; - BackgroundColourSelected = newValue ?? nonAccentSelectedColour; - UpdateBackgroundColour(); - UpdateForegroundColour(); + updateColours(); } protected override void UpdateForegroundColour() { base.UpdateForegroundColour(); - textContainer.Chevron.Alpha = IsHovered ? 1 : 0; + var content = Foreground.Child as Content; + if (content != null) content.Chevron.Alpha = IsHovered ? 1 : 0; } - protected override Drawable CreateContent() => textContainer = new TextContainer(); + protected override Drawable CreateContent() => new Content(); - protected class TextContainer : FillFlowContainer, IHasText + protected class Content : FillFlowContainer, IHasText { public string Text { @@ -133,7 +152,7 @@ namespace osu.Game.Graphics.UserInterface public readonly OsuSpriteText Label; public readonly SpriteIcon Chevron; - public TextContainer() + public Content() { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -165,7 +184,7 @@ namespace osu.Game.Graphics.UserInterface } #endregion - public class OsuDropdownHeader : DropdownHeader + public class OsuDropdownHeader : DropdownHeader, IHasAccentColour { protected readonly SpriteText Text; protected override string Label @@ -176,7 +195,16 @@ namespace osu.Game.Graphics.UserInterface protected readonly SpriteIcon Icon; - public readonly Bindable AccentColour = new Bindable(); + private Color4 accentColour; + public virtual Color4 AccentColour + { + get { return accentColour; } + set + { + accentColour = value; + BackgroundColourHover = accentColour; + } + } public OsuDropdownHeader() { @@ -203,20 +231,13 @@ namespace osu.Game.Graphics.UserInterface Size = new Vector2(20), } }; - - AccentColour.ValueChanged += accentColourChanged; } [BackgroundDependencyLoader] private void load(OsuColour colours) { BackgroundColour = Color4.Black.Opacity(0.5f); - BackgroundColourHover = AccentColour?.Value ?? colours.PinkDarker; - } - - private void accentColourChanged(Color4? newValue) - { - BackgroundColourHover = newValue ?? Color4.White; + BackgroundColourHover = colours.PinkDarker; } } } diff --git a/osu.Game/Graphics/UserInterface/OsuTabControl.cs b/osu.Game/Graphics/UserInterface/OsuTabControl.cs index 32d2bc7c53..89b1f4124b 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabControl.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabControl.cs @@ -37,34 +37,34 @@ namespace osu.Game.Graphics.UserInterface [BackgroundDependencyLoader] private void load(OsuColour colours) { - if (accentColour == null) + if (accentColour == default(Color4)) AccentColour = colours.Blue; } - private Color4? accentColour; + private Color4 accentColour; public Color4 AccentColour { - get { return accentColour.GetValueOrDefault(); } + get { return accentColour; } set { accentColour = value; - var dropdown = Dropdown as OsuTabDropdown; + var dropdown = Dropdown as IHasAccentColour; if (dropdown != null) - dropdown.AccentColour.Value = value; - foreach (var item in TabContainer.Children.OfType()) - item.AccentColour = value; + dropdown.AccentColour = value; + foreach (var i in TabContainer.Children.OfType()) + i.AccentColour = value; } } - public class OsuTabItem : TabItem + public class OsuTabItem : TabItem, IHasAccentColour { protected readonly SpriteText Text; private readonly Box box; - private Color4? accentColour; + private Color4 accentColour; public Color4 AccentColour { - get { return accentColour.GetValueOrDefault(); } + get { return accentColour; } set { accentColour = value; @@ -103,7 +103,7 @@ namespace osu.Game.Graphics.UserInterface [BackgroundDependencyLoader] private void load(OsuColour colours) { - if (accentColour == null) + if (accentColour == default(Color4)) AccentColour = colours.Blue; } @@ -148,25 +148,13 @@ namespace osu.Game.Graphics.UserInterface RelativeSizeAxes = Axes.X; } - protected override DropdownMenu CreateMenu() + protected override DropdownMenu CreateMenu() => new OsuTabDropdownMenu(); + + protected override DropdownHeader CreateHeader() => new OsuTabDropdownHeader { - var menu = new OsuTabDropdownMenu(); - menu.AccentColour.BindTo(AccentColour); - return menu; - } - - protected override DropdownHeader CreateHeader() - { - var newHeader = new OsuTabDropdownHeader - { - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight - }; - - newHeader.AccentColour.BindTo(AccentColour); - - return newHeader; - } + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight + }; private class OsuTabDropdownMenu : OsuDropdownMenu { @@ -179,12 +167,7 @@ namespace osu.Game.Graphics.UserInterface MaxHeight = 400; } - protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) - { - var result = new DrawableOsuTabDropdownMenuItem(item); - result.AccentColour.BindTo(AccentColour); - return result; - } + protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableOsuTabDropdownMenuItem(item) { AccentColour = AccentColour }; private class DrawableOsuTabDropdownMenuItem : DrawableOsuDropdownMenuItem { @@ -199,6 +182,20 @@ namespace osu.Game.Graphics.UserInterface protected class OsuTabDropdownHeader : OsuDropdownHeader { + public override Color4 AccentColour + { + get + { + return base.AccentColour; + } + + set + { + base.AccentColour = value; + Foreground.Colour = value; + } + } + public OsuTabDropdownHeader() { RelativeSizeAxes = Axes.None; @@ -227,13 +224,6 @@ namespace osu.Game.Graphics.UserInterface }; Padding = new MarginPadding { Left = 5, Right = 5 }; - - AccentColour.ValueChanged += accentColourChanged; - } - - private void accentColourChanged(Color4? newValue) - { - Foreground.Colour = newValue ?? Color4.White; } protected override bool OnHover(InputState state) diff --git a/osu.Game/Overlays/Direct/FilterControl.cs b/osu.Game/Overlays/Direct/FilterControl.cs index ca9e8667e6..28d26d0641 100644 --- a/osu.Game/Overlays/Direct/FilterControl.cs +++ b/osu.Game/Overlays/Direct/FilterControl.cs @@ -36,7 +36,7 @@ namespace osu.Game.Overlays.Direct [BackgroundDependencyLoader(true)] private void load(OsuGame game, RulesetStore rulesets, OsuColour colours) { - DisplayStyleControl.Dropdown.AccentColour.Value = colours.BlueDark; + DisplayStyleControl.Dropdown.AccentColour = colours.BlueDark; Ruleset.BindTo(game?.Ruleset ?? new Bindable { Value = rulesets.GetRuleset(0) }); foreach (var r in rulesets.AllRulesets) diff --git a/osu.Game/Overlays/Music/CollectionsDropdown.cs b/osu.Game/Overlays/Music/CollectionsDropdown.cs index be72d4481a..3b11d9f52a 100644 --- a/osu.Game/Overlays/Music/CollectionsDropdown.cs +++ b/osu.Game/Overlays/Music/CollectionsDropdown.cs @@ -18,16 +18,10 @@ namespace osu.Game.Overlays.Music [BackgroundDependencyLoader] private void load(OsuColour colours) { - AccentColour.Value = colours.Gray6; + AccentColour = colours.Gray6; } - protected override DropdownHeader CreateHeader() - { - var newHeader = new CollectionsHeader(); - newHeader.AccentColour.BindTo(AccentColour); - - return newHeader; - } + protected override DropdownHeader CreateHeader() => new CollectionsHeader(); protected override DropdownMenu CreateMenu() => new CollectionsMenu(); diff --git a/osu.Game/Overlays/SearchableList/SlimEnumDropdown.cs b/osu.Game/Overlays/SearchableList/SlimEnumDropdown.cs index e68cddb293..2870607519 100644 --- a/osu.Game/Overlays/SearchableList/SlimEnumDropdown.cs +++ b/osu.Game/Overlays/SearchableList/SlimEnumDropdown.cs @@ -12,13 +12,7 @@ namespace osu.Game.Overlays.SearchableList { public class SlimEnumDropdown : OsuEnumDropdown { - protected override DropdownHeader CreateHeader() - { - var newHeader = new SlimDropdownHeader(); - newHeader.AccentColour.BindTo(AccentColour); - - return newHeader; - } + protected override DropdownHeader CreateHeader() => new SlimDropdownHeader(); protected override DropdownMenu CreateMenu() => new SlimMenu(); diff --git a/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs b/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs index cf12c8a8e8..a816fa56c1 100644 --- a/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs @@ -257,13 +257,7 @@ namespace osu.Game.Overlays.Settings.Sections.General private class UserDropdown : OsuEnumDropdown { - protected override DropdownHeader CreateHeader() - { - var newHeader = new UserDropdownHeader(); - newHeader.AccentColour.BindTo(AccentColour); - - return newHeader; - } + protected override DropdownHeader CreateHeader() => new UserDropdownHeader(); protected override DropdownMenu CreateMenu() => new UserDropdownMenu(); @@ -280,7 +274,7 @@ namespace osu.Game.Overlays.Settings.Sections.General [BackgroundDependencyLoader] private void load(OsuColour colours) { - AccentColour.Value = colours.Gray5; + AccentColour = colours.Gray5; } private class UserDropdownMenu : OsuDropdownMenu @@ -319,7 +313,7 @@ namespace osu.Game.Overlays.Settings.Sections.General CornerRadius = 5; } - protected override Drawable CreateContent() => new TextContainer + protected override Drawable CreateContent() => new Content { Label = { Margin = new MarginPadding { Left = UserDropdownHeader.LABEL_LEFT_MARGIN - 11 } } };