diff --git a/osu.Game.Tests/Visual/Online/TestSceneCommentsHeader.cs b/osu.Game.Tests/Visual/Online/TestSceneCommentsHeader.cs new file mode 100644 index 0000000000..949dbbe5c4 --- /dev/null +++ b/osu.Game.Tests/Visual/Online/TestSceneCommentsHeader.cs @@ -0,0 +1,39 @@ +// 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 NUnit.Framework; +using osu.Framework.Bindables; +using osu.Game.Overlays.Comments; + +namespace osu.Game.Tests.Visual.Online +{ + [TestFixture] + public class TestSceneCommentsHeader : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(CommentsHeader), + typeof(HeaderButton), + typeof(SortSelector), + }; + + private readonly Bindable sort = new Bindable(); + private readonly BindableBool showDeleted = new BindableBool(); + + public TestSceneCommentsHeader() + { + Add(new CommentsHeader + { + Sort = { BindTarget = sort }, + ShowDeleted = { BindTarget = showDeleted } + }); + + AddStep("Trigger ShowDeleted", () => showDeleted.Value = !showDeleted.Value); + AddStep("Select old", () => sort.Value = CommentsSortCriteria.Old); + AddStep("Select new", () => sort.Value = CommentsSortCriteria.New); + AddStep("Select top", () => sort.Value = CommentsSortCriteria.Top); + } + } +} diff --git a/osu.Game/Online/API/Requests/GetCommentsRequest.cs b/osu.Game/Online/API/Requests/GetCommentsRequest.cs index fb30130ee9..834a5106a0 100644 --- a/osu.Game/Online/API/Requests/GetCommentsRequest.cs +++ b/osu.Game/Online/API/Requests/GetCommentsRequest.cs @@ -13,9 +13,9 @@ namespace osu.Game.Online.API.Requests private readonly long id; private readonly int page; private readonly CommentableType type; - private readonly SortCommentsBy sort; + private readonly CommentsSortCriteria sort; - public GetCommentsRequest(CommentableType type, long id, SortCommentsBy sort = SortCommentsBy.New, int page = 1) + public GetCommentsRequest(CommentableType type, long id, CommentsSortCriteria sort = CommentsSortCriteria.New, int page = 1) { this.type = type; this.sort = sort; diff --git a/osu.Game/Overlays/Comments/CommentsContainer.cs b/osu.Game/Overlays/Comments/CommentsContainer.cs index 314376f5ff..265793226e 100644 --- a/osu.Game/Overlays/Comments/CommentsContainer.cs +++ b/osu.Game/Overlays/Comments/CommentsContainer.cs @@ -18,7 +18,7 @@ namespace osu.Game.Overlays.Comments private readonly CommentableType type; private readonly long id; - public readonly Bindable Sort = new Bindable(); + public readonly Bindable Sort = new Bindable(); public readonly BindableBool ShowDeleted = new BindableBool(); [Resolved] @@ -74,7 +74,7 @@ namespace osu.Game.Overlays.Comments base.LoadComplete(); } - private void onSortChanged(ValueChangedEvent sort) => getComments(); + private void onSortChanged(ValueChangedEvent sort) => getComments(); private void getComments() { diff --git a/osu.Game/Overlays/Comments/CommentsHeader.cs b/osu.Game/Overlays/Comments/CommentsHeader.cs index 6e9864f153..2bd2bf21a6 100644 --- a/osu.Game/Overlays/Comments/CommentsHeader.cs +++ b/osu.Game/Overlays/Comments/CommentsHeader.cs @@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Comments private const int padding = 50; private const int text_size = 14; - public readonly Bindable Sort = new Bindable(); + public readonly Bindable Sort = new Bindable(); public readonly BindableBool ShowDeleted = new BindableBool(); private readonly Box background; @@ -79,13 +79,11 @@ namespace osu.Game.Overlays.Comments [BackgroundDependencyLoader] private void load(OsuColour colours) { - background.Colour = colours.Gray4; + background.Colour = colours.Gray3; } private class ShowDeletedButton : HeaderButton { - private const int spacing = 5; - public readonly BindableBool Checked = new BindableBool(); private readonly SpriteIcon checkboxIcon; @@ -96,7 +94,7 @@ namespace osu.Game.Overlays.Comments { AutoSizeAxes = Axes.Both, Direction = FillDirection.Horizontal, - Spacing = new Vector2(spacing, 0), + Spacing = new Vector2(5, 0), Children = new Drawable[] { checkboxIcon = new SpriteIcon diff --git a/osu.Game/Overlays/Comments/HeaderButton.cs b/osu.Game/Overlays/Comments/HeaderButton.cs index e3729b3b05..231a364759 100644 --- a/osu.Game/Overlays/Comments/HeaderButton.cs +++ b/osu.Game/Overlays/Comments/HeaderButton.cs @@ -50,7 +50,7 @@ namespace osu.Game.Overlays.Comments [BackgroundDependencyLoader] private void load(OsuColour colours) { - background.Colour = colours.Gray6; + background.Colour = colours.Gray4; } protected override bool OnHover(HoverEvent e) @@ -65,8 +65,8 @@ namespace osu.Game.Overlays.Comments FadeOutBackground(); } - public void FadeInBackground() => background.FadeIn(duration, Easing.OutQuint); + protected void FadeInBackground() => background.FadeIn(duration, Easing.OutQuint); - public void FadeOutBackground() => background.FadeOut(duration, Easing.OutQuint); + protected void FadeOutBackground() => background.FadeOut(duration, Easing.OutQuint); } } diff --git a/osu.Game/Overlays/Comments/SortSelector.cs b/osu.Game/Overlays/Comments/SortSelector.cs index cb95a758ff..100ae83291 100644 --- a/osu.Game/Overlays/Comments/SortSelector.cs +++ b/osu.Game/Overlays/Comments/SortSelector.cs @@ -10,16 +10,18 @@ using osuTK; using osu.Game.Graphics.UserInterface; using osu.Framework.Input.Events; using osu.Framework.Bindables; +using osu.Framework.Allocation; +using osuTK.Graphics; namespace osu.Game.Overlays.Comments { - public class SortSelector : OsuTabControl + public class SortSelector : OsuTabControl { private const int spacing = 5; - protected override Dropdown CreateDropdown() => null; + protected override Dropdown CreateDropdown() => null; - protected override TabItem CreateTabItem(SortCommentsBy value) => new SortTabItem(value); + protected override TabItem CreateTabItem(CommentsSortCriteria value) => new SortTabItem(value); protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer { @@ -33,21 +35,23 @@ namespace osu.Game.Overlays.Comments AutoSizeAxes = Axes.Both; } - private class SortTabItem : TabItem + private class SortTabItem : TabItem { private readonly TabContent content; - public SortTabItem(SortCommentsBy value) + public SortTabItem(CommentsSortCriteria value) : base(value) { AutoSizeAxes = Axes.Both; Child = content = new TabContent(value) - { Active = { BindTarget = Active } }; + { + Active = { BindTarget = Active } + }; } - protected override void OnActivated() => content.FadeInBackground(); + protected override void OnActivated() => content.Activate(); - protected override void OnDeactivated() => content.FadeOutBackground(); + protected override void OnDeactivated() => content.Deactivate(); private class TabContent : HeaderButton { @@ -55,15 +59,36 @@ namespace osu.Game.Overlays.Comments public readonly BindableBool Active = new BindableBool(); - public TabContent(SortCommentsBy value) + [Resolved] + private OsuColour colours { get; set; } + + private readonly SpriteText text; + + public TabContent(CommentsSortCriteria value) { - Add(new SpriteText + Add(text = new SpriteText { Font = OsuFont.GetFont(size: text_size), Text = value.ToString() }); } + public void Activate() + { + FadeInBackground(); + text.Font = text.Font.With(weight: FontWeight.Bold); + text.Colour = colours.BlueLighter; + } + + public void Deactivate() + { + if (!IsHovered) + FadeOutBackground(); + + text.Font = text.Font.With(weight: FontWeight.Medium); + text.Colour = Color4.White; + } + protected override void OnHoverLost(HoverLostEvent e) { if (!Active.Value) base.OnHoverLost(e); @@ -72,7 +97,7 @@ namespace osu.Game.Overlays.Comments } } - public enum SortCommentsBy + public enum CommentsSortCriteria { New, Old,