mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:02:55 +08:00
Hook up api and implement some visual comments representation
This commit is contained in:
parent
e772822bd5
commit
aa8df0fa20
@ -6,6 +6,8 @@ using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
@ -17,12 +19,21 @@ namespace osu.Game.Tests.Visual.Online
|
||||
typeof(CommentsContainer),
|
||||
};
|
||||
|
||||
protected override bool UseOnlineAPI => true;
|
||||
|
||||
public TestSceneCommentsContainer()
|
||||
{
|
||||
BasicScrollContainer scrollFlow;
|
||||
|
||||
Add(scrollFlow = new BasicScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
});
|
||||
|
||||
AddStep("Big Black comments", () =>
|
||||
{
|
||||
Clear();
|
||||
Add(new CommentsContainer(CommentableType.Beatmapset, 41823));
|
||||
scrollFlow.Clear();
|
||||
scrollFlow.Add(new CommentsContainer(CommentableType.Beatmapset, 41823));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
public bool HasMore { get; set; }
|
||||
|
||||
[JsonProperty(@"has_more_id")]
|
||||
public long HasMoreId { get; set; }
|
||||
public long? HasMoreId { get; set; }
|
||||
|
||||
[JsonProperty(@"user_follow")]
|
||||
public bool UserFollow { get; set; }
|
||||
|
@ -52,16 +52,16 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
[JsonProperty(@"updated_at")]
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
|
||||
[JsonProperty(@"deleted_at")]
|
||||
public DateTimeOffset DeletedAt { get; set; }
|
||||
public DateTimeOffset? DeletedAt { get; set; }
|
||||
|
||||
[JsonProperty(@"edited_at")]
|
||||
public DateTimeOffset EditedAt { get; set; }
|
||||
public DateTimeOffset? EditedAt { get; set; }
|
||||
|
||||
[JsonProperty(@"edited_by_id")]
|
||||
public long EditedById { get; set; }
|
||||
public long? EditedById { get; set; }
|
||||
|
||||
public bool IsTopLevel { get; set; }
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osuTK;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
@ -24,8 +25,14 @@ namespace osu.Game.Overlays
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
private GetCommentsRequest request;
|
||||
|
||||
private readonly CommentsHeader header;
|
||||
private readonly Box background;
|
||||
private readonly FillFlowContainer content;
|
||||
|
||||
public CommentsContainer(CommentableType type, long id)
|
||||
{
|
||||
@ -40,15 +47,86 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
header = new CommentsHeader
|
||||
new FillFlowContainer
|
||||
{
|
||||
Sort = { BindTarget = Sort }
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
header = new CommentsHeader
|
||||
{
|
||||
Sort = { BindTarget = Sort }
|
||||
},
|
||||
content = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
Sort.BindValueChanged(onSortChanged, true);
|
||||
base.LoadComplete();
|
||||
}
|
||||
|
||||
private void onSortChanged(ValueChangedEvent<SortCommentsBy> sort) => getComments();
|
||||
|
||||
private void getComments()
|
||||
{
|
||||
request?.Cancel();
|
||||
request = new GetCommentsRequest(type, id, Sort.Value);
|
||||
request.Success += onSuccess;
|
||||
api.Queue(request);
|
||||
}
|
||||
|
||||
private void onSuccess(APIComments response)
|
||||
{
|
||||
content.Clear();
|
||||
|
||||
foreach (var c in response.Comments)
|
||||
{
|
||||
createDrawableComment(c);
|
||||
}
|
||||
}
|
||||
|
||||
private void createDrawableComment(Comment comment)
|
||||
{
|
||||
content.Add(new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 70,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Text = comment.MessageHTML,
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 1,
|
||||
Child = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.Gray1,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
private void load()
|
||||
{
|
||||
background.Colour = colours.Gray3;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user