mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 15:33:05 +08:00
Show LoginOverlay if not logged-in when clicking on a pill
This commit is contained in:
parent
6379381f95
commit
20161aea6a
@ -8,6 +8,7 @@ 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
|
||||
{
|
||||
@ -17,11 +18,30 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Cached]
|
||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
||||
|
||||
[Cached]
|
||||
private LoginOverlay login;
|
||||
|
||||
private TestPill votePill;
|
||||
private readonly Container pillContainer;
|
||||
|
||||
public TestSceneVotePill()
|
||||
{
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
pillContainer = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
AutoSizeAxes = Axes.Both
|
||||
},
|
||||
login = new LoginOverlay()
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUserCommentPill()
|
||||
{
|
||||
AddStep("Hide login overlay", () => login.Hide());
|
||||
AddStep("Log in", logIn);
|
||||
AddStep("User comment", () => addVotePill(getUserComment()));
|
||||
AddAssert("Background is transparent", () => votePill.Background.Alpha == 0);
|
||||
@ -32,9 +52,10 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Test]
|
||||
public void TestRandomCommentPill()
|
||||
{
|
||||
AddStep("Hide login overlay", () => login.Hide());
|
||||
AddStep("Log in", logIn);
|
||||
AddStep("Random comment", () => addVotePill(getRandomComment()));
|
||||
AddAssert("Background is not transparent", () => votePill.Background.Alpha == 1);
|
||||
AddAssert("Background is visible", () => votePill.Background.Alpha == 1);
|
||||
AddStep("Click", () => votePill.Click());
|
||||
AddAssert("Loading", () => votePill.IsLoading);
|
||||
}
|
||||
@ -42,10 +63,11 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Test]
|
||||
public void TestOfflineRandomCommentPill()
|
||||
{
|
||||
AddStep("Hide login overlay", () => login.Hide());
|
||||
AddStep("Log out", API.Logout);
|
||||
AddStep("Random comment", () => addVotePill(getRandomComment()));
|
||||
AddStep("Click", () => votePill.Click());
|
||||
AddAssert("Not loading", () => !votePill.IsLoading);
|
||||
AddAssert("Login overlay is visible", () => login.State.Value == Visibility.Visible);
|
||||
}
|
||||
|
||||
private void logIn() => API.Login("localUser", "password");
|
||||
@ -66,12 +88,12 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
private void addVotePill(Comment comment)
|
||||
{
|
||||
Clear();
|
||||
Add(votePill = new TestPill(comment)
|
||||
pillContainer.Clear();
|
||||
pillContainer.Child = votePill = new TestPill(comment)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
private class TestPill : VotePill
|
||||
|
@ -33,6 +33,9 @@ namespace osu.Game.Overlays.Comments
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private LoginOverlay login { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OverlayColourProvider colourProvider { get; set; }
|
||||
|
||||
@ -66,7 +69,7 @@ namespace osu.Game.Overlays.Comments
|
||||
|
||||
var ownComment = api.LocalUser.Value.Id == comment.UserId;
|
||||
|
||||
if (api.IsLoggedIn && !ownComment)
|
||||
if (!ownComment)
|
||||
Action = onAction;
|
||||
|
||||
Background.Alpha = ownComment ? 0 : 1;
|
||||
@ -83,6 +86,12 @@ namespace osu.Game.Overlays.Comments
|
||||
|
||||
private void onAction()
|
||||
{
|
||||
if (!api.IsLoggedIn)
|
||||
{
|
||||
login?.Show();
|
||||
return;
|
||||
}
|
||||
|
||||
request = new CommentVoteRequest(comment.Id, isVoted.Value ? CommentVoteAction.UnVote : CommentVoteAction.Vote);
|
||||
request.Success += onSuccess;
|
||||
api.Queue(request);
|
||||
|
Loading…
Reference in New Issue
Block a user