mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 17:33:15 +08:00
Merge pull request #7655 from EVAST9919/no-comments-placeholder
Add placeholder for no comments case in CommentsContainer
This commit is contained in:
commit
176be108fe
@ -25,7 +25,8 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
typeof(SortTabControl),
|
typeof(SortTabControl),
|
||||||
typeof(ShowChildrenButton),
|
typeof(ShowChildrenButton),
|
||||||
typeof(DeletedCommentsCounter),
|
typeof(DeletedCommentsCounter),
|
||||||
typeof(VotePill)
|
typeof(VotePill),
|
||||||
|
typeof(CommentsPage),
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override bool UseOnlineAPI => true;
|
protected override bool UseOnlineAPI => true;
|
||||||
|
162
osu.Game.Tests/Visual/Online/TestSceneCommentsPage.cs
Normal file
162
osu.Game.Tests/Visual/Online/TestSceneCommentsPage.cs
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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.Game.Overlays.Comments;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Users;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Online
|
||||||
|
{
|
||||||
|
public class TestSceneCommentsPage : OsuTestScene
|
||||||
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(DrawableComment),
|
||||||
|
typeof(CommentsPage),
|
||||||
|
};
|
||||||
|
|
||||||
|
[Cached]
|
||||||
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
|
||||||
|
|
||||||
|
private readonly BindableBool showDeleted = new BindableBool();
|
||||||
|
private readonly Container content;
|
||||||
|
|
||||||
|
public TestSceneCommentsPage()
|
||||||
|
{
|
||||||
|
Add(new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
Spacing = new Vector2(0, 10),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Container
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Width = 200,
|
||||||
|
Child = new OsuCheckbox
|
||||||
|
{
|
||||||
|
Current = showDeleted,
|
||||||
|
LabelText = @"Show Deleted"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
content = new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("load comments", () => createPage(comment_bundle));
|
||||||
|
AddStep("load empty comments", () => createPage(empty_comment_bundle));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createPage(CommentBundle commentBundle)
|
||||||
|
{
|
||||||
|
content.Clear();
|
||||||
|
content.Add(new CommentsPage(commentBundle)
|
||||||
|
{
|
||||||
|
ShowDeleted = { BindTarget = showDeleted }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly CommentBundle empty_comment_bundle = new CommentBundle
|
||||||
|
{
|
||||||
|
Comments = new List<Comment>(),
|
||||||
|
Total = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly CommentBundle comment_bundle = new CommentBundle
|
||||||
|
{
|
||||||
|
Comments = new List<Comment>
|
||||||
|
{
|
||||||
|
new Comment
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Message = "Simple test comment",
|
||||||
|
LegacyName = "TestUser1",
|
||||||
|
CreatedAt = DateTimeOffset.Now,
|
||||||
|
VotesCount = 5
|
||||||
|
},
|
||||||
|
new Comment
|
||||||
|
{
|
||||||
|
Id = 2,
|
||||||
|
Message = "This comment has been deleted :( but visible for admins",
|
||||||
|
LegacyName = "TestUser2",
|
||||||
|
CreatedAt = DateTimeOffset.Now,
|
||||||
|
DeletedAt = DateTimeOffset.Now,
|
||||||
|
VotesCount = 5
|
||||||
|
},
|
||||||
|
new Comment
|
||||||
|
{
|
||||||
|
Id = 3,
|
||||||
|
Message = "This comment is a top level",
|
||||||
|
LegacyName = "TestUser3",
|
||||||
|
CreatedAt = DateTimeOffset.Now,
|
||||||
|
RepliesCount = 2,
|
||||||
|
},
|
||||||
|
new Comment
|
||||||
|
{
|
||||||
|
Id = 4,
|
||||||
|
ParentId = 3,
|
||||||
|
Message = "And this is a reply",
|
||||||
|
RepliesCount = 1,
|
||||||
|
LegacyName = "TestUser1",
|
||||||
|
CreatedAt = DateTimeOffset.Now,
|
||||||
|
},
|
||||||
|
new Comment
|
||||||
|
{
|
||||||
|
Id = 15,
|
||||||
|
ParentId = 4,
|
||||||
|
Message = "Reply to reply",
|
||||||
|
LegacyName = "TestUser1",
|
||||||
|
CreatedAt = DateTimeOffset.Now,
|
||||||
|
},
|
||||||
|
new Comment
|
||||||
|
{
|
||||||
|
Id = 6,
|
||||||
|
ParentId = 3,
|
||||||
|
LegacyName = "TestUser11515",
|
||||||
|
CreatedAt = DateTimeOffset.Now,
|
||||||
|
DeletedAt = DateTimeOffset.Now,
|
||||||
|
},
|
||||||
|
new Comment
|
||||||
|
{
|
||||||
|
Id = 5,
|
||||||
|
Message = "This comment is voted and edited",
|
||||||
|
LegacyName = "BigBrainUser",
|
||||||
|
CreatedAt = DateTimeOffset.Now,
|
||||||
|
EditedAt = DateTimeOffset.Now,
|
||||||
|
VotesCount = 1000,
|
||||||
|
EditedById = 1,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
IncludedComments = new List<Comment>(),
|
||||||
|
UserVotes = new List<long>
|
||||||
|
{
|
||||||
|
5
|
||||||
|
},
|
||||||
|
Users = new List<User>
|
||||||
|
{
|
||||||
|
new User
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Username = "Good_Admin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
TopLevelCount = 4,
|
||||||
|
Total = 7
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -40,13 +40,14 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
public ShowMoreButton()
|
public ShowMoreButton()
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both;
|
Height = 30;
|
||||||
|
Width = 140;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateContent() => new CircularContainer
|
protected override Drawable CreateContent() => new CircularContainer
|
||||||
{
|
{
|
||||||
Masking = true,
|
Masking = true,
|
||||||
Size = new Vector2(140, 30),
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
background = new Box
|
background = new Box
|
||||||
|
@ -6,8 +6,6 @@ using osu.Game.Users;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace osu.Game.Online.API.Requests.Responses
|
namespace osu.Game.Online.API.Requests.Responses
|
||||||
{
|
{
|
||||||
@ -70,12 +68,10 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
|
|
||||||
public bool IsDeleted => DeletedAt.HasValue;
|
public bool IsDeleted => DeletedAt.HasValue;
|
||||||
|
|
||||||
public bool HasMessage => !string.IsNullOrEmpty(MessageHtml);
|
public bool HasMessage => !string.IsNullOrEmpty(Message);
|
||||||
|
|
||||||
public bool IsVoted { get; set; }
|
public bool IsVoted { get; set; }
|
||||||
|
|
||||||
public string GetMessage => HasMessage ? WebUtility.HtmlDecode(Regex.Replace(MessageHtml, @"<(.|\n)*?>", string.Empty)) : string.Empty;
|
|
||||||
|
|
||||||
public int DeletedChildrenCount => ChildComments.Count(c => c.IsDeleted);
|
public int DeletedChildrenCount => ChildComments.Count(c => c.IsDeleted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,17 +47,18 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
[JsonProperty(@"included_comments")]
|
[JsonProperty(@"included_comments")]
|
||||||
public List<Comment> IncludedComments { get; set; }
|
public List<Comment> IncludedComments { get; set; }
|
||||||
|
|
||||||
|
private List<long> userVotes;
|
||||||
|
|
||||||
[JsonProperty(@"user_votes")]
|
[JsonProperty(@"user_votes")]
|
||||||
private List<long> userVotes
|
public List<long> UserVotes
|
||||||
{
|
{
|
||||||
set => value.ForEach(v =>
|
get => userVotes;
|
||||||
|
set
|
||||||
{
|
{
|
||||||
Comments.ForEach(c =>
|
userVotes = value;
|
||||||
{
|
|
||||||
if (v == c.Id)
|
Comments.ForEach(c => c.IsVoted = value.Contains(c.Id));
|
||||||
c.IsVoted = true;
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<User> users;
|
private List<User> users;
|
||||||
|
@ -68,6 +68,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
},
|
},
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
|
Name = @"Footer",
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
@ -154,6 +155,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
{
|
{
|
||||||
currentPage = 1;
|
currentPage = 1;
|
||||||
deletedCommentsCounter.Count.Value = 0;
|
deletedCommentsCounter.Count.Value = 0;
|
||||||
|
moreButton.Show();
|
||||||
moreButton.IsLoading = true;
|
moreButton.IsLoading = true;
|
||||||
content.Clear();
|
content.Clear();
|
||||||
}
|
}
|
||||||
@ -162,25 +164,10 @@ namespace osu.Game.Overlays.Comments
|
|||||||
{
|
{
|
||||||
loadCancellation = new CancellationTokenSource();
|
loadCancellation = new CancellationTokenSource();
|
||||||
|
|
||||||
var page = new FillFlowContainer
|
LoadComponentAsync(new CommentsPage(response)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
ShowDeleted = { BindTarget = ShowDeleted }
|
||||||
AutoSizeAxes = Axes.Y,
|
}, loaded =>
|
||||||
Direction = FillDirection.Vertical,
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (var c in response.Comments)
|
|
||||||
{
|
|
||||||
if (c.IsTopLevel)
|
|
||||||
{
|
|
||||||
page.Add(new DrawableComment(c)
|
|
||||||
{
|
|
||||||
ShowDeleted = { BindTarget = ShowDeleted }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadComponentAsync(page, loaded =>
|
|
||||||
{
|
{
|
||||||
content.Add(loaded);
|
content.Add(loaded);
|
||||||
|
|
||||||
@ -194,10 +181,12 @@ namespace osu.Game.Overlays.Comments
|
|||||||
moreButton.Current.Value = response.TopLevelCount - loadedTopLevelComments;
|
moreButton.Current.Value = response.TopLevelCount - loadedTopLevelComments;
|
||||||
moreButton.IsLoading = false;
|
moreButton.IsLoading = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
moreButton.Hide();
|
||||||
|
}
|
||||||
|
|
||||||
commentCounter.Current.Value = response.Total;
|
commentCounter.Current.Value = response.Total;
|
||||||
|
|
||||||
moreButton.FadeTo(response.HasMore ? 1 : 0);
|
|
||||||
}, loadCancellation.Token);
|
}, loadCancellation.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
92
osu.Game/Overlays/Comments/CommentsPage.cs
Normal file
92
osu.Game/Overlays/Comments/CommentsPage.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Comments
|
||||||
|
{
|
||||||
|
public class CommentsPage : CompositeDrawable
|
||||||
|
{
|
||||||
|
public readonly BindableBool ShowDeleted = new BindableBool();
|
||||||
|
|
||||||
|
private readonly CommentBundle commentBundle;
|
||||||
|
|
||||||
|
public CommentsPage(CommentBundle commentBundle)
|
||||||
|
{
|
||||||
|
this.commentBundle = commentBundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OverlayColourProvider colourProvider)
|
||||||
|
{
|
||||||
|
FillFlowContainer flow;
|
||||||
|
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
|
|
||||||
|
AddRangeInternal(new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = colourProvider.Background5
|
||||||
|
},
|
||||||
|
flow = new FillFlowContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!commentBundle.Comments.Any())
|
||||||
|
{
|
||||||
|
flow.Add(new NoCommentsPlaceholder());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var c in commentBundle.Comments)
|
||||||
|
{
|
||||||
|
if (c.IsTopLevel)
|
||||||
|
{
|
||||||
|
flow.Add(new DrawableComment(c)
|
||||||
|
{
|
||||||
|
ShowDeleted = { BindTarget = ShowDeleted }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NoCommentsPlaceholder : CompositeDrawable
|
||||||
|
{
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OverlayColourProvider colourProvider)
|
||||||
|
{
|
||||||
|
Height = 80;
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
AddRangeInternal(new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = colourProvider.Background4
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Margin = new MarginPadding { Left = 50 },
|
||||||
|
Text = @"No comments yet."
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,8 @@ namespace osu.Game.Overlays.Comments
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OverlayColourProvider colourProvider)
|
private void load(OverlayColourProvider colourProvider)
|
||||||
{
|
{
|
||||||
|
Height = 20;
|
||||||
|
|
||||||
IdleColour = colourProvider.Background2;
|
IdleColour = colourProvider.Background2;
|
||||||
HoverColour = colourProvider.Background1;
|
HoverColour = colourProvider.Background1;
|
||||||
ChevronIconColour = colourProvider.Foreground1;
|
ChevronIconColour = colourProvider.Foreground1;
|
||||||
|
@ -213,7 +213,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
|
|
||||||
if (comment.HasMessage)
|
if (comment.HasMessage)
|
||||||
{
|
{
|
||||||
var formattedSource = MessageFormatter.FormatText(comment.GetMessage);
|
var formattedSource = MessageFormatter.FormatText(comment.Message);
|
||||||
message.AddLinks(formattedSource.Text, formattedSource.Links);
|
message.AddLinks(formattedSource.Text, formattedSource.Links);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,7 +343,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
if (parentComment == null)
|
if (parentComment == null)
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
|
||||||
return parentComment.HasMessage ? parentComment.GetMessage : parentComment.IsDeleted ? @"deleted" : string.Empty;
|
return parentComment.HasMessage ? parentComment.Message : parentComment.IsDeleted ? @"deleted" : string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user