Make VotePill background transparent for own comments

This commit is contained in:
Andrei Zavatski
2021-01-22 20:46:20 +03:00
parent 26779a9403
commit 6379381f95
2 changed files with 25 additions and 6 deletions

View File

@ -7,6 +7,7 @@ using osu.Game.Overlays.Comments;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Framework.Graphics.Shapes;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -16,13 +17,14 @@ namespace osu.Game.Tests.Visual.Online
[Cached] [Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private VotePill votePill; private TestPill votePill;
[Test] [Test]
public void TestUserCommentPill() public void TestUserCommentPill()
{ {
AddStep("Log in", logIn); AddStep("Log in", logIn);
AddStep("User comment", () => addVotePill(getUserComment())); AddStep("User comment", () => addVotePill(getUserComment()));
AddAssert("Background is transparent", () => votePill.Background.Alpha == 0);
AddStep("Click", () => votePill.Click()); AddStep("Click", () => votePill.Click());
AddAssert("Not loading", () => !votePill.IsLoading); AddAssert("Not loading", () => !votePill.IsLoading);
} }
@ -32,6 +34,7 @@ namespace osu.Game.Tests.Visual.Online
{ {
AddStep("Log in", logIn); AddStep("Log in", logIn);
AddStep("Random comment", () => addVotePill(getRandomComment())); AddStep("Random comment", () => addVotePill(getRandomComment()));
AddAssert("Background is not transparent", () => votePill.Background.Alpha == 1);
AddStep("Click", () => votePill.Click()); AddStep("Click", () => votePill.Click());
AddAssert("Loading", () => votePill.IsLoading); AddAssert("Loading", () => votePill.IsLoading);
} }
@ -64,11 +67,21 @@ namespace osu.Game.Tests.Visual.Online
private void addVotePill(Comment comment) private void addVotePill(Comment comment)
{ {
Clear(); Clear();
Add(votePill = new VotePill(comment) Add(votePill = new TestPill(comment)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
}); });
} }
private class TestPill : VotePill
{
public new Box Background => base.Background;
public TestPill(Comment comment)
: base(comment)
{
}
}
} }
} }

View File

@ -36,8 +36,10 @@ namespace osu.Game.Overlays.Comments
[Resolved] [Resolved]
private OverlayColourProvider colourProvider { get; set; } private OverlayColourProvider colourProvider { get; set; }
protected Box Background { get; private set; }
private readonly Comment comment; private readonly Comment comment;
private Box background;
private Box hoverLayer; private Box hoverLayer;
private CircularContainer borderContainer; private CircularContainer borderContainer;
private SpriteText sideNumber; private SpriteText sideNumber;
@ -62,8 +64,12 @@ namespace osu.Game.Overlays.Comments
AccentColour = borderContainer.BorderColour = sideNumber.Colour = colours.GreenLight; AccentColour = borderContainer.BorderColour = sideNumber.Colour = colours.GreenLight;
hoverLayer.Colour = Color4.Black.Opacity(0.5f); hoverLayer.Colour = Color4.Black.Opacity(0.5f);
if (api.IsLoggedIn && api.LocalUser.Value.Id != comment.UserId) var ownComment = api.LocalUser.Value.Id == comment.UserId;
if (api.IsLoggedIn && !ownComment)
Action = onAction; Action = onAction;
Background.Alpha = ownComment ? 0 : 1;
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -71,7 +77,7 @@ namespace osu.Game.Overlays.Comments
base.LoadComplete(); base.LoadComplete();
isVoted.Value = comment.IsVoted; isVoted.Value = comment.IsVoted;
votesCount.Value = comment.VotesCount; 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); votesCount.BindValueChanged(count => votesCounter.Text = $"+{count.NewValue}", true);
} }
@ -102,7 +108,7 @@ namespace osu.Game.Overlays.Comments
Masking = true, Masking = true,
Children = new Drawable[] Children = new Drawable[]
{ {
background = new Box Background = new Box
{ {
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
}, },