From a9f366fda3a74c2054d450251f9bbaf07f34f37d Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 17 Feb 2020 02:20:53 +0300 Subject: [PATCH 1/7] Implement OverlaySortTabControl component --- .../Online/TestSceneCommentsContainer.cs | 2 +- .../Visual/Online/TestSceneCommentsHeader.cs | 2 +- osu.Game/Overlays/Comments/CommentsHeader.cs | 33 ++-- osu.Game/Overlays/Comments/SortTabControl.cs | 110 ------------- osu.Game/Overlays/OverlaySortTabControl.cs | 147 ++++++++++++++++++ 5 files changed, 159 insertions(+), 135 deletions(-) delete mode 100644 osu.Game/Overlays/Comments/SortTabControl.cs create mode 100644 osu.Game/Overlays/OverlaySortTabControl.cs diff --git a/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs index 2a43ba3f99..ece280659c 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs @@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Online typeof(CommentsHeader), typeof(DrawableComment), typeof(HeaderButton), - typeof(SortTabControl), + typeof(OverlaySortTabControl<>), typeof(ShowChildrenButton), typeof(DeletedCommentsCounter), typeof(VotePill), diff --git a/osu.Game.Tests/Visual/Online/TestSceneCommentsHeader.cs b/osu.Game.Tests/Visual/Online/TestSceneCommentsHeader.cs index a60f220e4b..c688d600a3 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneCommentsHeader.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneCommentsHeader.cs @@ -18,7 +18,7 @@ namespace osu.Game.Tests.Visual.Online { typeof(CommentsHeader), typeof(HeaderButton), - typeof(SortTabControl), + typeof(OverlaySortTabControl<>), }; [Cached] diff --git a/osu.Game/Overlays/Comments/CommentsHeader.cs b/osu.Game/Overlays/Comments/CommentsHeader.cs index ad80e67330..1aa40201f1 100644 --- a/osu.Game/Overlays/Comments/CommentsHeader.cs +++ b/osu.Game/Overlays/Comments/CommentsHeader.cs @@ -16,8 +16,6 @@ namespace osu.Game.Overlays.Comments { public class CommentsHeader : CompositeDrawable { - private const int font_size = 14; - public readonly Bindable Sort = new Bindable(); public readonly BindableBool ShowDeleted = new BindableBool(); @@ -40,29 +38,11 @@ namespace osu.Game.Overlays.Comments Padding = new MarginPadding { Horizontal = 50 }, Children = new Drawable[] { - new FillFlowContainer + new OverlaySortTabControl { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(10, 0), Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Children = new Drawable[] - { - new OsuSpriteText - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Font = OsuFont.GetFont(size: font_size), - Text = @"Sort by" - }, - new SortTabControl - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - Current = Sort - } - } + Current = Sort }, new ShowDeletedButton { @@ -106,7 +86,7 @@ namespace osu.Game.Overlays.Comments { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Font = OsuFont.GetFont(size: font_size), + Font = OsuFont.GetFont(size: 12), Text = @"Show deleted" } }, @@ -126,4 +106,11 @@ namespace osu.Game.Overlays.Comments } } } + + public enum CommentsSortCriteria + { + New, + Old, + Top + } } diff --git a/osu.Game/Overlays/Comments/SortTabControl.cs b/osu.Game/Overlays/Comments/SortTabControl.cs deleted file mode 100644 index 700d63351f..0000000000 --- a/osu.Game/Overlays/Comments/SortTabControl.cs +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics; -using osu.Framework.Graphics.UserInterface; -using osu.Framework.Graphics.Sprites; -using osu.Game.Graphics; -using osuTK; -using osu.Game.Graphics.UserInterface; -using osu.Framework.Input.Events; -using osu.Framework.Bindables; -using osu.Framework.Allocation; -using osu.Game.Graphics.Sprites; -using osuTK.Graphics; - -namespace osu.Game.Overlays.Comments -{ - public class SortTabControl : OsuTabControl - { - protected override Dropdown CreateDropdown() => null; - - protected override TabItem CreateTabItem(CommentsSortCriteria value) => new SortTabItem(value); - - protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer - { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(5, 0), - }; - - public SortTabControl() - { - AutoSizeAxes = Axes.Both; - } - - private class SortTabItem : TabItem - { - public SortTabItem(CommentsSortCriteria value) - : base(value) - { - AutoSizeAxes = Axes.Both; - Child = new TabButton(value) { Active = { BindTarget = Active } }; - } - - protected override void OnActivated() - { - } - - protected override void OnDeactivated() - { - } - - private class TabButton : HeaderButton - { - public readonly BindableBool Active = new BindableBool(); - - [Resolved] - private OverlayColourProvider colourProvider { get; set; } - - private readonly SpriteText text; - - public TabButton(CommentsSortCriteria value) - { - Add(text = new OsuSpriteText - { - Font = OsuFont.GetFont(size: 14), - Text = value.ToString() - }); - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - Active.BindValueChanged(active => - { - updateBackgroundState(); - - text.Font = text.Font.With(weight: active.NewValue ? FontWeight.Bold : FontWeight.Medium); - text.Colour = active.NewValue ? colourProvider.Light1 : Color4.White; - }, true); - } - - protected override bool OnHover(HoverEvent e) - { - updateBackgroundState(); - return true; - } - - protected override void OnHoverLost(HoverLostEvent e) => updateBackgroundState(); - - private void updateBackgroundState() - { - if (Active.Value || IsHovered) - ShowBackground(); - else - HideBackground(); - } - } - } - } - - public enum CommentsSortCriteria - { - New, - Old, - Top - } -} diff --git a/osu.Game/Overlays/OverlaySortTabControl.cs b/osu.Game/Overlays/OverlaySortTabControl.cs new file mode 100644 index 0000000000..0b91de2682 --- /dev/null +++ b/osu.Game/Overlays/OverlaySortTabControl.cs @@ -0,0 +1,147 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; +using osuTK; +using osu.Game.Graphics.UserInterface; +using osu.Framework.Input.Events; +using osu.Framework.Bindables; +using osu.Framework.Allocation; +using osu.Game.Graphics.Sprites; +using osuTK.Graphics; +using osu.Game.Overlays.Comments; +using JetBrains.Annotations; + +namespace osu.Game.Overlays +{ + public class OverlaySortTabControl : CompositeDrawable, IHasCurrentValue + { + private readonly BindableWithCurrent current = new BindableWithCurrent(); + + public Bindable Current + { + get => current.Current; + set => current.Current = value; + } + + public OverlaySortTabControl() + { + AutoSizeAxes = Axes.Both; + AddInternal(new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(10, 0), + Children = new Drawable[] + { + new OsuSpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Font = OsuFont.GetFont(size: 12), + Text = @"Sort by" + }, + CreateControl().With(c => + { + c.Anchor = Anchor.CentreLeft; + c.Origin = Anchor.CentreLeft; + c.Current = current; + }) + } + }); + } + + [NotNull] + protected virtual SortTabControl CreateControl() => new SortTabControl(); + + protected class SortTabControl : OsuTabControl + { + protected override Dropdown CreateDropdown() => null; + + protected override TabItem CreateTabItem(T value) => new SortTabItem(value); + + protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer + { + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(5, 0), + }; + + public SortTabControl() + { + AutoSizeAxes = Axes.Both; + } + + protected class SortTabItem : TabItem + { + public SortTabItem(T value) + : base(value) + { + AutoSizeAxes = Axes.Both; + Child = new TabButton(value) { Active = { BindTarget = Active } }; + } + + protected override void OnActivated() + { + } + + protected override void OnDeactivated() + { + } + + private class TabButton : HeaderButton + { + public readonly BindableBool Active = new BindableBool(); + + [Resolved] + private OverlayColourProvider colourProvider { get; set; } + + private readonly SpriteText text; + + public TabButton(T value) + { + Add(text = new OsuSpriteText + { + Font = OsuFont.GetFont(size: 12), + Text = value.ToString() + }); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + Active.BindValueChanged(_ => updateState(), true); + } + + protected override bool OnHover(HoverEvent e) + { + updateHoverState(); + return true; + } + + protected override void OnHoverLost(HoverLostEvent e) => updateHoverState(); + + private void updateState() + { + updateHoverState(); + text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Medium); + } + + private void updateHoverState() + { + if (Active.Value || IsHovered) + ShowBackground(); + else + HideBackground(); + + text.Colour = Active.Value && !IsHovered ? colourProvider.Light1 : Color4.White; + } + } + } + } + } +} From 2ba0bd872bd41428a9da62a020be1d231f73a321 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 17 Feb 2020 02:35:46 +0300 Subject: [PATCH 2/7] Implement basic BeatmapListingSortTabControl --- .../TestSceneBeatmapListingSort.cs | 33 +++++++++++++++++++ .../BeatmapListingSortTabControl.cs | 24 ++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs create mode 100644 osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs new file mode 100644 index 0000000000..28549f4306 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs @@ -0,0 +1,33 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Overlays; +using osu.Game.Overlays.BeatmapListing; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneBeatmapListingSort : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(BeatmapListingSortTabControl), + typeof(OverlaySortTabControl<>), + }; + + [Cached] + private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); + + public TestSceneBeatmapListingSort() + { + Add(new BeatmapListingSortTabControl + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }); + } + } +} diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs new file mode 100644 index 0000000000..0a002325e7 --- /dev/null +++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs @@ -0,0 +1,24 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Overlays.BeatmapListing +{ + public class BeatmapListingSortTabControl : OverlaySortTabControl + { + public BeatmapListingSortTabControl() + { + Current.Value = BeatmapSortCriteria.Ranked; + } + } + + public enum BeatmapSortCriteria + { + Title, + Artist, + Difficulty, + Ranked, + Rating, + Plays, + Favourites, + } +} From fe7923b7e824449c0d06baf2a6729ccf935ae4ed Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 17 Feb 2020 03:38:14 +0300 Subject: [PATCH 3/7] Add SortDirection Bindable and refactor to make everything work --- .../TestSceneBeatmapListingSort.cs | 30 +++++- .../BeatmapListingSortTabControl.cs | 95 +++++++++++++++++++ osu.Game/Overlays/OverlaySortTabControl.cs | 53 +++++++---- 3 files changed, 161 insertions(+), 17 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs index 28549f4306..40c694e224 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs @@ -5,8 +5,11 @@ using System; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics.Sprites; using osu.Game.Overlays; using osu.Game.Overlays.BeatmapListing; +using osuTK; namespace osu.Game.Tests.Visual.UserInterface { @@ -20,14 +23,39 @@ namespace osu.Game.Tests.Visual.UserInterface [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); + private readonly FillFlowContainer placeholder; + private readonly BeatmapListingSortTabControl control; public TestSceneBeatmapListingSort() { - Add(new BeatmapListingSortTabControl + Add(control = new BeatmapListingSortTabControl { Anchor = Anchor.Centre, Origin = Anchor.Centre, }); + + Add(placeholder = new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), + }); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + control.SortDirection.BindValueChanged(_ => updateBindablesVisual()); + control.Current.BindValueChanged(_ => updateBindablesVisual(), true); + } + + private void updateBindablesVisual() + { + placeholder.Clear(); + + placeholder.Add(new OsuSpriteText { Text = $"Current: {control.Current.Value}" }); + placeholder.Add(new OsuSpriteText { Text = $"Sort direction: {control.SortDirection.Value}" }); } } } diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs index 0a002325e7..3f69c76da7 100644 --- a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs +++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs @@ -1,14 +1,109 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.Bindables; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Graphics; +using osuTK.Graphics; +using osuTK; +using osu.Framework.Input.Events; + namespace osu.Game.Overlays.BeatmapListing { public class BeatmapListingSortTabControl : OverlaySortTabControl { + public readonly Bindable SortDirection = new Bindable(Overlays.SortDirection.Descending); + public BeatmapListingSortTabControl() { Current.Value = BeatmapSortCriteria.Ranked; } + + protected override SortTabControl CreateControl() => new BeatmapSortTabControl + { + SortDirection = { BindTarget = SortDirection } + }; + + private class BeatmapSortTabControl : SortTabControl + { + public readonly Bindable SortDirection = new Bindable(); + + protected override TabItem CreateTabItem(BeatmapSortCriteria value) => new BeatmapSortTabItem(value) + { + SortDirection = { BindTarget = SortDirection } + }; + + private class BeatmapSortTabItem : SortTabItem + { + public readonly Bindable SortDirection = new Bindable(); + + public BeatmapSortTabItem(BeatmapSortCriteria value) + : base(value) + { + } + + protected override TabButton CreateTabButton(BeatmapSortCriteria value) => new BeatmapTabButton(value) + { + Active = { BindTarget = Active }, + SortDirection = { BindTarget = SortDirection } + }; + + private class BeatmapTabButton : TabButton + { + public readonly Bindable SortDirection = new Bindable(); + + protected override Color4 ContentColour + { + set + { + base.ContentColour = value; + icon.Colour = value; + } + } + + private readonly SpriteIcon icon; + + public BeatmapTabButton(BeatmapSortCriteria value) + : base(value) + { + Add(icon = new SpriteIcon + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AlwaysPresent = true, + Alpha = 0, + Size = new Vector2(6) + }); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + SortDirection.BindValueChanged(direction => + { + icon.Icon = direction.NewValue == Overlays.SortDirection.Ascending ? FontAwesome.Solid.CaretUp : FontAwesome.Solid.CaretDown; + icon.Margin = direction.NewValue == Overlays.SortDirection.Ascending ? new MarginPadding { Top = 1 } : new MarginPadding { Top = 2 }; + }, true); + } + + protected override void UpdateState() + { + base.UpdateState(); + icon.FadeTo(Active.Value || IsHovered ? 1 : 0, 200, Easing.OutQuint); + } + + protected override bool OnClick(ClickEvent e) + { + if (Active.Value) + SortDirection.Value = SortDirection.Value == Overlays.SortDirection.Ascending ? Overlays.SortDirection.Descending : Overlays.SortDirection.Ascending; + + return base.OnClick(e); + } + } + } + } } public enum BeatmapSortCriteria diff --git a/osu.Game/Overlays/OverlaySortTabControl.cs b/osu.Game/Overlays/OverlaySortTabControl.cs index 0b91de2682..487dd70db9 100644 --- a/osu.Game/Overlays/OverlaySortTabControl.cs +++ b/osu.Game/Overlays/OverlaySortTabControl.cs @@ -82,9 +82,15 @@ namespace osu.Game.Overlays : base(value) { AutoSizeAxes = Axes.Both; - Child = new TabButton(value) { Active = { BindTarget = Active } }; + Child = CreateTabButton(value); } + [NotNull] + protected virtual TabButton CreateTabButton(T value) => new TabButton(value) + { + Active = { BindTarget = Active } + }; + protected override void OnActivated() { } @@ -93,52 +99,67 @@ namespace osu.Game.Overlays { } - private class TabButton : HeaderButton + protected class TabButton : HeaderButton { public readonly BindableBool Active = new BindableBool(); + protected override Container Content => content; + + protected virtual Color4 ContentColour + { + set => text.Colour = value; + } + [Resolved] private OverlayColourProvider colourProvider { get; set; } private readonly SpriteText text; + private readonly FillFlowContainer content; public TabButton(T value) { - Add(text = new OsuSpriteText + base.Content.Add(content = new FillFlowContainer { - Font = OsuFont.GetFont(size: 12), - Text = value.ToString() + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(3, 0), + Children = new Drawable[] + { + text = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 12), + Text = value.ToString() + } + } }); } protected override void LoadComplete() { base.LoadComplete(); - Active.BindValueChanged(_ => updateState(), true); + Active.BindValueChanged(_ => UpdateState(), true); } protected override bool OnHover(HoverEvent e) { - updateHoverState(); + UpdateState(); return true; } - protected override void OnHoverLost(HoverLostEvent e) => updateHoverState(); + protected override void OnHoverLost(HoverLostEvent e) => UpdateState(); - private void updateState() - { - updateHoverState(); - text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Medium); - } - - private void updateHoverState() + protected virtual void UpdateState() { if (Active.Value || IsHovered) ShowBackground(); else HideBackground(); - text.Colour = Active.Value && !IsHovered ? colourProvider.Light1 : Color4.White; + ContentColour = Active.Value && !IsHovered ? colourProvider.Light1 : Color4.White; + + text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Medium); } } } From d985a22f7758b8de3651f15141178b6a5140a53a Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 17 Feb 2020 03:52:26 +0300 Subject: [PATCH 4/7] Add missing blank line --- .../Visual/UserInterface/TestSceneBeatmapListingSort.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs index 40c694e224..4638b2bb54 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs @@ -23,6 +23,7 @@ namespace osu.Game.Tests.Visual.UserInterface [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); + private readonly FillFlowContainer placeholder; private readonly BeatmapListingSortTabControl control; From 19872d9e24009e29ae27f547d8ee568268f26b16 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 17 Feb 2020 22:05:10 +0300 Subject: [PATCH 5/7] Simplify test scene --- .../TestSceneBeatmapListingSort.cs | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs index 4638b2bb54..a5fa085abf 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSort.cs @@ -24,39 +24,32 @@ namespace osu.Game.Tests.Visual.UserInterface [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); - private readonly FillFlowContainer placeholder; - private readonly BeatmapListingSortTabControl control; - public TestSceneBeatmapListingSort() { + BeatmapListingSortTabControl control; + OsuSpriteText current; + OsuSpriteText direction; + Add(control = new BeatmapListingSortTabControl { Anchor = Anchor.Centre, Origin = Anchor.Centre, }); - Add(placeholder = new FillFlowContainer + Add(new FillFlowContainer { AutoSizeAxes = Axes.Both, Direction = FillDirection.Vertical, Spacing = new Vector2(0, 5), + Children = new Drawable[] + { + current = new OsuSpriteText(), + direction = new OsuSpriteText() + } }); - } - protected override void LoadComplete() - { - base.LoadComplete(); - - control.SortDirection.BindValueChanged(_ => updateBindablesVisual()); - control.Current.BindValueChanged(_ => updateBindablesVisual(), true); - } - - private void updateBindablesVisual() - { - placeholder.Clear(); - - placeholder.Add(new OsuSpriteText { Text = $"Current: {control.Current.Value}" }); - placeholder.Add(new OsuSpriteText { Text = $"Sort direction: {control.SortDirection.Value}" }); + control.SortDirection.BindValueChanged(sortDirection => direction.Text = $"Sort direction: {sortDirection.NewValue}", true); + control.Current.BindValueChanged(criteria => current.Text = $"Criteria: {criteria.NewValue}", true); } } } From 519548c99f5c1349bb3c774406897e0f14168e42 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 17 Feb 2020 22:06:46 +0300 Subject: [PATCH 6/7] Remove not necessary icon margin changes --- osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs index 3f69c76da7..d6841da408 100644 --- a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs +++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs @@ -84,7 +84,6 @@ namespace osu.Game.Overlays.BeatmapListing SortDirection.BindValueChanged(direction => { icon.Icon = direction.NewValue == Overlays.SortDirection.Ascending ? FontAwesome.Solid.CaretUp : FontAwesome.Solid.CaretDown; - icon.Margin = direction.NewValue == Overlays.SortDirection.Ascending ? new MarginPadding { Top = 1 } : new MarginPadding { Top = 2 }; }, true); } From bce9e7a356912cd7eb7c1d4fd6a35a6cc2ad1163 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 17 Feb 2020 22:32:58 +0300 Subject: [PATCH 7/7] Remove too much nesting for OverlaySortTabControl class --- .../BeatmapListingSortTabControl.cs | 112 ++++++------- osu.Game/Overlays/OverlaySortTabControl.cs | 150 +++++++++--------- 2 files changed, 131 insertions(+), 131 deletions(-) diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs index d6841da408..cb41b33bc4 100644 --- a/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs +++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingSortTabControl.cs @@ -33,74 +33,74 @@ namespace osu.Game.Overlays.BeatmapListing { SortDirection = { BindTarget = SortDirection } }; + } - private class BeatmapSortTabItem : SortTabItem + private class BeatmapSortTabItem : SortTabItem + { + public readonly Bindable SortDirection = new Bindable(); + + public BeatmapSortTabItem(BeatmapSortCriteria value) + : base(value) { - public readonly Bindable SortDirection = new Bindable(); + } - public BeatmapSortTabItem(BeatmapSortCriteria value) - : base(value) + protected override TabButton CreateTabButton(BeatmapSortCriteria value) => new BeatmapTabButton(value) + { + Active = { BindTarget = Active }, + SortDirection = { BindTarget = SortDirection } + }; + } + + private class BeatmapTabButton : TabButton + { + public readonly Bindable SortDirection = new Bindable(); + + protected override Color4 ContentColour + { + set { + base.ContentColour = value; + icon.Colour = value; } + } - protected override TabButton CreateTabButton(BeatmapSortCriteria value) => new BeatmapTabButton(value) + private readonly SpriteIcon icon; + + public BeatmapTabButton(BeatmapSortCriteria value) + : base(value) + { + Add(icon = new SpriteIcon { - Active = { BindTarget = Active }, - SortDirection = { BindTarget = SortDirection } - }; + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + AlwaysPresent = true, + Alpha = 0, + Size = new Vector2(6) + }); + } - private class BeatmapTabButton : TabButton + protected override void LoadComplete() + { + base.LoadComplete(); + + SortDirection.BindValueChanged(direction => { - public readonly Bindable SortDirection = new Bindable(); + icon.Icon = direction.NewValue == Overlays.SortDirection.Ascending ? FontAwesome.Solid.CaretUp : FontAwesome.Solid.CaretDown; + }, true); + } - protected override Color4 ContentColour - { - set - { - base.ContentColour = value; - icon.Colour = value; - } - } + protected override void UpdateState() + { + base.UpdateState(); + icon.FadeTo(Active.Value || IsHovered ? 1 : 0, 200, Easing.OutQuint); + } - private readonly SpriteIcon icon; + protected override bool OnClick(ClickEvent e) + { + if (Active.Value) + SortDirection.Value = SortDirection.Value == Overlays.SortDirection.Ascending ? Overlays.SortDirection.Descending : Overlays.SortDirection.Ascending; - public BeatmapTabButton(BeatmapSortCriteria value) - : base(value) - { - Add(icon = new SpriteIcon - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - AlwaysPresent = true, - Alpha = 0, - Size = new Vector2(6) - }); - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - SortDirection.BindValueChanged(direction => - { - icon.Icon = direction.NewValue == Overlays.SortDirection.Ascending ? FontAwesome.Solid.CaretUp : FontAwesome.Solid.CaretDown; - }, true); - } - - protected override void UpdateState() - { - base.UpdateState(); - icon.FadeTo(Active.Value || IsHovered ? 1 : 0, 200, Easing.OutQuint); - } - - protected override bool OnClick(ClickEvent e) - { - if (Active.Value) - SortDirection.Value = SortDirection.Value == Overlays.SortDirection.Ascending ? Overlays.SortDirection.Descending : Overlays.SortDirection.Ascending; - - return base.OnClick(e); - } - } + return base.OnClick(e); } } } diff --git a/osu.Game/Overlays/OverlaySortTabControl.cs b/osu.Game/Overlays/OverlaySortTabControl.cs index 487dd70db9..5a713ab08e 100644 --- a/osu.Game/Overlays/OverlaySortTabControl.cs +++ b/osu.Game/Overlays/OverlaySortTabControl.cs @@ -75,93 +75,93 @@ namespace osu.Game.Overlays { AutoSizeAxes = Axes.Both; } + } - protected class SortTabItem : TabItem + protected class SortTabItem : TabItem + { + public SortTabItem(T value) + : base(value) { - public SortTabItem(T value) - : base(value) + AutoSizeAxes = Axes.Both; + Child = CreateTabButton(value); + } + + [NotNull] + protected virtual TabButton CreateTabButton(T value) => new TabButton(value) + { + Active = { BindTarget = Active } + }; + + protected override void OnActivated() + { + } + + protected override void OnDeactivated() + { + } + } + + protected class TabButton : HeaderButton + { + public readonly BindableBool Active = new BindableBool(); + + protected override Container Content => content; + + protected virtual Color4 ContentColour + { + set => text.Colour = value; + } + + [Resolved] + private OverlayColourProvider colourProvider { get; set; } + + private readonly SpriteText text; + private readonly FillFlowContainer content; + + public TabButton(T value) + { + base.Content.Add(content = new FillFlowContainer { - AutoSizeAxes = Axes.Both; - Child = CreateTabButton(value); - } - - [NotNull] - protected virtual TabButton CreateTabButton(T value) => new TabButton(value) - { - Active = { BindTarget = Active } - }; - - protected override void OnActivated() - { - } - - protected override void OnDeactivated() - { - } - - protected class TabButton : HeaderButton - { - public readonly BindableBool Active = new BindableBool(); - - protected override Container Content => content; - - protected virtual Color4 ContentColour + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(3, 0), + Children = new Drawable[] { - set => text.Colour = value; - } - - [Resolved] - private OverlayColourProvider colourProvider { get; set; } - - private readonly SpriteText text; - private readonly FillFlowContainer content; - - public TabButton(T value) - { - base.Content.Add(content = new FillFlowContainer + text = new OsuSpriteText { - AutoSizeAxes = Axes.Both, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(3, 0), - Children = new Drawable[] - { - text = new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Font = OsuFont.GetFont(size: 12), - Text = value.ToString() - } - } - }); + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 12), + Text = value.ToString() + } } + }); + } - protected override void LoadComplete() - { - base.LoadComplete(); - Active.BindValueChanged(_ => UpdateState(), true); - } + protected override void LoadComplete() + { + base.LoadComplete(); + Active.BindValueChanged(_ => UpdateState(), true); + } - protected override bool OnHover(HoverEvent e) - { - UpdateState(); - return true; - } + protected override bool OnHover(HoverEvent e) + { + UpdateState(); + return true; + } - protected override void OnHoverLost(HoverLostEvent e) => UpdateState(); + protected override void OnHoverLost(HoverLostEvent e) => UpdateState(); - protected virtual void UpdateState() - { - if (Active.Value || IsHovered) - ShowBackground(); - else - HideBackground(); + protected virtual void UpdateState() + { + if (Active.Value || IsHovered) + ShowBackground(); + else + HideBackground(); - ContentColour = Active.Value && !IsHovered ? colourProvider.Light1 : Color4.White; + ContentColour = Active.Value && !IsHovered ? colourProvider.Light1 : Color4.White; - text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Medium); - } - } + text.Font = text.Font.With(weight: Active.Value ? FontWeight.Bold : FontWeight.Medium); } } }