diff --git a/osu.Game.Tests/Visual/Online/TestSceneVotePill.cs b/osu.Game.Tests/Visual/Online/TestSceneVotePill.cs index 6334c014c8..e9e826e62f 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneVotePill.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneVotePill.cs @@ -7,6 +7,7 @@ using osu.Game.Overlays.Comments; using osu.Game.Online.API.Requests.Responses; using osu.Framework.Allocation; using osu.Game.Overlays; +using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Containers; namespace osu.Game.Tests.Visual.Online @@ -20,7 +21,7 @@ namespace osu.Game.Tests.Visual.Online [Cached] private LoginOverlay login; - private VotePill votePill; + private TestPill votePill; private readonly Container pillContainer; public TestSceneVotePill() @@ -43,7 +44,7 @@ namespace osu.Game.Tests.Visual.Online AddStep("Hide login overlay", () => login.Hide()); AddStep("Log in", logIn); AddStep("User comment", () => addVotePill(getUserComment())); - AddAssert("Is disabled", () => !votePill.Enabled.Value); + AddAssert("Background is transparent", () => votePill.Background.Alpha == 0); AddStep("Click", () => votePill.Click()); AddAssert("Not loading", () => !votePill.IsLoading); } @@ -54,7 +55,7 @@ namespace osu.Game.Tests.Visual.Online AddStep("Hide login overlay", () => login.Hide()); AddStep("Log in", logIn); AddStep("Random comment", () => addVotePill(getRandomComment())); - AddAssert("Is enabled", () => votePill.Enabled.Value); + AddAssert("Background is visible", () => votePill.Background.Alpha == 1); AddStep("Click", () => votePill.Click()); AddAssert("Loading", () => votePill.IsLoading); } @@ -88,11 +89,21 @@ namespace osu.Game.Tests.Visual.Online private void addVotePill(Comment comment) { pillContainer.Clear(); - pillContainer.Child = votePill = new VotePill(comment) + pillContainer.Child = votePill = new TestPill(comment) { Anchor = Anchor.Centre, Origin = Anchor.Centre, }; } + + private class TestPill : VotePill + { + public new Box Background => base.Background; + + public TestPill(Comment comment) + : base(comment) + { + } + } } } diff --git a/osu.Game/Overlays/Comments/VotePill.cs b/osu.Game/Overlays/Comments/VotePill.cs index 04a0508f3d..cf3c470f96 100644 --- a/osu.Game/Overlays/Comments/VotePill.cs +++ b/osu.Game/Overlays/Comments/VotePill.cs @@ -39,9 +39,10 @@ namespace osu.Game.Overlays.Comments [Resolved] private OverlayColourProvider colourProvider { get; set; } - private bool isOwnComment; + protected Box Background { get; private set; } + private readonly Comment comment; - private Box background; + private Box hoverLayer; private CircularContainer borderContainer; private SpriteText sideNumber; @@ -63,14 +64,15 @@ namespace osu.Game.Overlays.Comments [BackgroundDependencyLoader] private void load(OsuColour colours) { - isOwnComment = api.LocalUser.Value.Id == comment.UserId; - Action = onAction; - AccentColour = borderContainer.BorderColour = sideNumber.Colour = colours.GreenLight; hoverLayer.Colour = Color4.Black.Opacity(0.5f); - background.Alpha = isOwnComment ? 0 : 1; - Enabled.Value = !isOwnComment; + var ownComment = api.LocalUser.Value.Id == comment.UserId; + + if (!ownComment) + Action = onAction; + + Background.Alpha = ownComment ? 0 : 1; } protected override void LoadComplete() @@ -78,7 +80,7 @@ namespace osu.Game.Overlays.Comments base.LoadComplete(); isVoted.Value = comment.IsVoted; votesCount.Value = comment.VotesCount; - isVoted.BindValueChanged(voted => background.Colour = voted.NewValue ? AccentColour : colourProvider.Background6, true); + isVoted.BindValueChanged(voted => Background.Colour = voted.NewValue ? AccentColour : colourProvider.Background6, true); votesCount.BindValueChanged(count => votesCounter.Text = $"+{count.NewValue}", true); } @@ -115,7 +117,7 @@ namespace osu.Game.Overlays.Comments Masking = true, Children = new Drawable[] { - background = new Box + Background = new Box { RelativeSizeAxes = Axes.Both }, @@ -149,48 +151,55 @@ namespace osu.Game.Overlays.Comments protected override void OnLoadStarted() { votesCounter.FadeOut(duration, Easing.OutQuint); - updateDisplay(false); + updateDisplay(); } protected override void OnLoadFinished() { votesCounter.FadeIn(duration, Easing.OutQuint); - updateDisplay(IsHovered); + + if (IsHovered) + onHoverAction(); } protected override bool OnHover(HoverEvent e) { - if (!isOwnComment && !IsLoading) - updateDisplay(true); - + onHoverAction(); return base.OnHover(e); } protected override void OnHoverLost(HoverLostEvent e) { - if (!isOwnComment && !IsLoading) - updateDisplay(false); - + updateDisplay(); base.OnHoverLost(e); } - private void updateDisplay(bool isHovered) + private void updateDisplay() { + if (Action == null) + return; + if (isVoted.Value) { - hoverLayer.FadeTo(isHovered ? 1 : 0); + hoverLayer.FadeTo(IsHovered ? 1 : 0); sideNumber.Hide(); } else - sideNumber.FadeTo(isHovered ? 1 : 0); + sideNumber.FadeTo(IsHovered ? 1 : 0); - borderContainer.BorderThickness = isHovered ? 3 : 0; + borderContainer.BorderThickness = IsHovered ? 3 : 0; + } + + private void onHoverAction() + { + if (!IsLoading) + updateDisplay(); } protected override void Dispose(bool isDisposing) { - request?.Cancel(); base.Dispose(isDisposing); + request?.Cancel(); } } }