From 4385edeb453103fe817e6af7326046d040dd046b Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 28 Aug 2017 11:01:53 +0900 Subject: [PATCH 1/3] Update usages of Menu to reflect ValueChanged events. --- osu-framework | 2 +- .../Graphics/UserInterface/OsuContextMenu.cs | 59 +++++++++++-------- .../Graphics/UserInterface/OsuDropdown.cs | 50 +++++++++------- 3 files changed, 64 insertions(+), 47 deletions(-) diff --git a/osu-framework b/osu-framework index 926d7c971d..743ad1129e 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 926d7c971d059c7aeb3ccfb09d06910c46aa3a40 +Subproject commit 743ad1129edbc1cb8faa14ebc9a6d1846780795c diff --git a/osu.Game/Graphics/UserInterface/OsuContextMenu.cs b/osu.Game/Graphics/UserInterface/OsuContextMenu.cs index ad4cd1edbc..9bc2f381c0 100644 --- a/osu.Game/Graphics/UserInterface/OsuContextMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuContextMenu.cs @@ -111,34 +111,45 @@ namespace osu.Game.Graphics.UserInterface return base.OnClick(state); } - protected override Drawable CreateContent() => new Container + protected override Drawable CreateContent() { - AutoSizeAxes = Axes.Both, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Children = new Drawable[] + var container = new Container { - text = new OsuSpriteText + AutoSizeAxes = Axes.Both, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Children = new Drawable[] { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - TextSize = text_size, - Text = Item.Text, - Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, - }, - textBold = new OsuSpriteText - { - AlwaysPresent = true, - Alpha = 0, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - TextSize = text_size, - Text = Item.Text, - Font = @"Exo2.0-Bold", - Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, + text = new OsuSpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + TextSize = text_size, + Text = Item.Text, + Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, + }, + textBold = new OsuSpriteText + { + AlwaysPresent = true, + Alpha = 0, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + TextSize = text_size, + Text = Item.Text, + Font = @"Exo2.0-Bold", + Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, + } } - } - }; + }; + + Item.Text.ValueChanged += newText => + { + text.Text = newText; + textBold.Text = newText; + }; + + return container; + } } #endregion } diff --git a/osu.Game/Graphics/UserInterface/OsuDropdown.cs b/osu.Game/Graphics/UserInterface/OsuDropdown.cs index 2c691b7763..8984ba1eba 100644 --- a/osu.Game/Graphics/UserInterface/OsuDropdown.cs +++ b/osu.Game/Graphics/UserInterface/OsuDropdown.cs @@ -120,32 +120,38 @@ namespace osu.Game.Graphics.UserInterface chevron.Alpha = IsHovered ? 1 : 0; } - protected override Drawable CreateContent() => new FillFlowContainer + protected override Drawable CreateContent() { - Direction = FillDirection.Horizontal, - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Children = new Drawable[] + var container = new FillFlowContainer { - chevron = new SpriteIcon + Direction = FillDirection.Horizontal, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Children = new Drawable[] { - AlwaysPresent = true, - Icon = FontAwesome.fa_chevron_right, - Colour = Color4.Black, - Alpha = 0.5f, - Size = new Vector2(8), - Margin = new MarginPadding { Left = 3, Right = 3 }, - Origin = Anchor.CentreLeft, - Anchor = Anchor.CentreLeft, - }, - Label = new OsuSpriteText - { - Text = Item.Text, - Origin = Anchor.CentreLeft, - Anchor = Anchor.CentreLeft, + chevron = new SpriteIcon + { + AlwaysPresent = true, + Icon = FontAwesome.fa_chevron_right, + Colour = Color4.Black, + Alpha = 0.5f, + Size = new Vector2(8), + Margin = new MarginPadding { Left = 3, Right = 3 }, + Origin = Anchor.CentreLeft, + Anchor = Anchor.CentreLeft, + }, + Label = new OsuSpriteText + { + Text = Item.Text, + Origin = Anchor.CentreLeft, + Anchor = Anchor.CentreLeft, + } } - } - }; + }; + + Item.Text.ValueChanged += newText => Label.Text = newText; + return container; + } } #endregion } From b5c1c05af5443246a1ec19a4cf09d03a7384ed88 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 28 Aug 2017 11:03:51 +0900 Subject: [PATCH 2/3] Remove poop. --- osu.Game/Graphics/UserInterface/OsuTabControl.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/OsuTabControl.cs b/osu.Game/Graphics/UserInterface/OsuTabControl.cs index 58d853d97e..faa7b269bb 100644 --- a/osu.Game/Graphics/UserInterface/OsuTabControl.cs +++ b/osu.Game/Graphics/UserInterface/OsuTabControl.cs @@ -181,9 +181,9 @@ namespace osu.Game.Graphics.UserInterface protected override DrawableMenuItem CreateDrawableMenuItem(DropdownMenuItem item) { - var poop = new DrawableOsuTabDropdownMenuItem(this, item); - poop.AccentColour.BindTo(AccentColour); - return poop; + var result = new DrawableOsuTabDropdownMenuItem(this, item); + result.AccentColour.BindTo(AccentColour); + return result; } private class DrawableOsuTabDropdownMenuItem : DrawableOsuDropdownMenuItem From 66db3389f6f8f7ce58e42fb008980fb923739366 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 28 Aug 2017 12:33:31 +0900 Subject: [PATCH 3/3] Update in line with framework changes. --- osu-framework | 2 +- .../Graphics/UserInterface/OsuContextMenu.cs | 63 ++++++++++--------- .../Graphics/UserInterface/OsuDropdown.cs | 38 ++++++----- .../Sections/General/LoginSettings.cs | 6 +- 4 files changed, 64 insertions(+), 45 deletions(-) diff --git a/osu-framework b/osu-framework index 743ad1129e..2958d6fda1 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 743ad1129edbc1cb8faa14ebc9a6d1846780795c +Subproject commit 2958d6fda1be252a0f479609090e72814b177c91 diff --git a/osu.Game/Graphics/UserInterface/OsuContextMenu.cs b/osu.Game/Graphics/UserInterface/OsuContextMenu.cs index 9bc2f381c0..4ec349edd7 100644 --- a/osu.Game/Graphics/UserInterface/OsuContextMenu.cs +++ b/osu.Game/Graphics/UserInterface/OsuContextMenu.cs @@ -8,6 +8,7 @@ using osu.Framework.Audio.Sample; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; using osu.Game.Graphics.Sprites; @@ -54,8 +55,7 @@ namespace osu.Game.Graphics.UserInterface private SampleChannel sampleClick; private SampleChannel sampleHover; - private OsuSpriteText text; - private OsuSpriteText textBold; + private TextContainer text; public DrawableOsuContextMenuItem(Menu menu, TItem item) : base(item) @@ -79,13 +79,13 @@ namespace osu.Game.Graphics.UserInterface switch (Item.Type) { case MenuItemType.Standard: - textBold.Colour = text.Colour = Color4.White; + text.Colour = Color4.White; break; case MenuItemType.Destructive: - textBold.Colour = text.Colour = Color4.Red; + text.Colour = Color4.Red; break; case MenuItemType.Highlighted: - textBold.Colour = text.Colour = OsuColour.FromHex(@"ffcc22"); + text.Colour = OsuColour.FromHex(@"ffcc22"); break; } } @@ -93,15 +93,15 @@ namespace osu.Game.Graphics.UserInterface protected override bool OnHover(InputState state) { sampleHover.Play(); - textBold.FadeIn(transition_length, Easing.OutQuint); - text.FadeOut(transition_length, Easing.OutQuint); + text.BoldText.FadeIn(transition_length, Easing.OutQuint); + text.NormalText.FadeOut(transition_length, Easing.OutQuint); return base.OnHover(state); } protected override void OnHoverLost(InputState state) { - textBold.FadeOut(transition_length, Easing.OutQuint); - text.FadeIn(transition_length, Easing.OutQuint); + text.BoldText.FadeOut(transition_length, Easing.OutQuint); + text.NormalText.FadeIn(transition_length, Easing.OutQuint); base.OnHoverLost(state); } @@ -111,44 +111,51 @@ namespace osu.Game.Graphics.UserInterface return base.OnClick(state); } - protected override Drawable CreateContent() + protected override Drawable CreateContent() => text = new TextContainer(); + + private class TextContainer : Container, IHasText { - var container = new Container + public string Text { - AutoSizeAxes = Axes.Both, - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, + get { return NormalText.Text; } + set + { + NormalText.Text = value; + BoldText.Text = value; + } + } + + public readonly SpriteText NormalText; + public readonly SpriteText BoldText; + + public TextContainer() + { + Anchor = Anchor.CentreLeft; + Origin = Anchor.CentreLeft; + + AutoSizeAxes = Axes.Both; + Children = new Drawable[] { - text = new OsuSpriteText + NormalText = new OsuSpriteText { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, TextSize = text_size, - Text = Item.Text, Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, }, - textBold = new OsuSpriteText + BoldText = new OsuSpriteText { AlwaysPresent = true, Alpha = 0, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, TextSize = text_size, - Text = Item.Text, Font = @"Exo2.0-Bold", Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, } - } - }; - - Item.Text.ValueChanged += newText => - { - text.Text = newText; - textBold.Text = newText; - }; - - return container; + }; + } } } #endregion diff --git a/osu.Game/Graphics/UserInterface/OsuDropdown.cs b/osu.Game/Graphics/UserInterface/OsuDropdown.cs index 8984ba1eba..d67a995e67 100644 --- a/osu.Game/Graphics/UserInterface/OsuDropdown.cs +++ b/osu.Game/Graphics/UserInterface/OsuDropdown.cs @@ -81,8 +81,7 @@ namespace osu.Game.Graphics.UserInterface { public readonly Bindable AccentColour = new Bindable(); - private SpriteIcon chevron; - protected OsuSpriteText Label; + private TextContainer textContainer; private Color4 nonAccentHoverColour; private Color4 nonAccentSelectedColour; @@ -117,19 +116,32 @@ namespace osu.Game.Graphics.UserInterface protected override void UpdateForegroundColour() { base.UpdateForegroundColour(); - chevron.Alpha = IsHovered ? 1 : 0; + + textContainer.Chevron.Alpha = IsHovered ? 1 : 0; } - protected override Drawable CreateContent() + protected override Drawable CreateContent() => textContainer = new TextContainer(); + + protected class TextContainer : FillFlowContainer, IHasText { - var container = new FillFlowContainer + public string Text { - Direction = FillDirection.Horizontal, - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, + get { return Label.Text; } + set { Label.Text = value; } + } + + public readonly OsuSpriteText Label; + public readonly SpriteIcon Chevron; + + public TextContainer() + { + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + Direction = FillDirection.Horizontal; + Children = new Drawable[] { - chevron = new SpriteIcon + Chevron = new SpriteIcon { AlwaysPresent = true, Icon = FontAwesome.fa_chevron_right, @@ -142,15 +154,11 @@ namespace osu.Game.Graphics.UserInterface }, Label = new OsuSpriteText { - Text = Item.Text, Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, } - } - }; - - Item.Text.ValueChanged += newText => Label.Text = newText; - return container; + }; + } } } #endregion diff --git a/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs b/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs index ad7c7cf092..609b4b1e16 100644 --- a/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs @@ -316,9 +316,13 @@ namespace osu.Game.Overlays.Settings.Sections.General : base(item) { Foreground.Padding = new MarginPadding { Top = 5, Bottom = 5, Left = 10, Right = 5 }; - Label.Margin = new MarginPadding { Left = UserDropdownHeader.LABEL_LEFT_MARGIN - 11 }; CornerRadius = 5; } + + protected override Drawable CreateContent() => new TextContainer + { + Label = { Margin = new MarginPadding { Left = UserDropdownHeader.LABEL_LEFT_MARGIN - 11 } } + }; } }