mirror of
https://github.com/ppy/osu
synced 2025-01-10 08:09:40 +00:00
Implement SortSelector component
This commit is contained in:
parent
574170124c
commit
29b0eacc82
@ -20,6 +20,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
typeof(CommentsHeader),
|
||||
typeof(DrawableComment),
|
||||
typeof(HeaderButton),
|
||||
typeof(SortSelector)
|
||||
};
|
||||
|
||||
protected override bool UseOnlineAPI => true;
|
||||
|
@ -28,7 +28,7 @@ namespace osu.Game.Online.API.Requests
|
||||
|
||||
req.AddParameter("commentable_type", type.ToString().Underscore().ToLowerInvariant());
|
||||
req.AddParameter("commentable_id", id.ToString());
|
||||
req.AddParameter("sort", sort.ToString());
|
||||
req.AddParameter("sort", sort.ToString().ToLowerInvariant());
|
||||
req.AddParameter("page", page.ToString());
|
||||
|
||||
return req;
|
||||
|
@ -31,7 +31,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
public Comment ParentComment { get; set; }
|
||||
|
||||
[JsonProperty(@"user_id")]
|
||||
public long UserId { get; set; }
|
||||
public long? UserId { get; set; }
|
||||
|
||||
public User User { get; set; }
|
||||
|
||||
|
@ -79,6 +79,7 @@ namespace osu.Game.Overlays.Comments
|
||||
private void getComments()
|
||||
{
|
||||
request?.Cancel();
|
||||
content.Clear();
|
||||
request = new GetCommentsRequest(type, id, Sort.Value);
|
||||
request.Success += onSuccess;
|
||||
api.Queue(request);
|
||||
@ -86,8 +87,6 @@ namespace osu.Game.Overlays.Comments
|
||||
|
||||
private void onSuccess(APICommentsController response)
|
||||
{
|
||||
content.Clear();
|
||||
|
||||
foreach (var c in response.Comments)
|
||||
{
|
||||
if (!c.IsDeleted && c.IsTopLevel)
|
||||
|
@ -53,8 +53,16 @@ namespace osu.Game.Overlays.Comments
|
||||
{
|
||||
new SpriteText
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Font = OsuFont.GetFont(size: text_size),
|
||||
Text = @"Sort by"
|
||||
},
|
||||
new SortSelector
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Current = { BindTarget = Sort }
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -161,7 +161,14 @@ namespace osu.Game.Overlays.Comments
|
||||
}
|
||||
};
|
||||
|
||||
username.AddUserLink(comment.User);
|
||||
if (comment.UserId == null)
|
||||
{
|
||||
username.AddText(comment.LegacyName);
|
||||
}
|
||||
else
|
||||
{
|
||||
username.AddUserLink(comment.User);
|
||||
}
|
||||
|
||||
comment.ChildComments.ForEach(c =>
|
||||
{
|
||||
|
@ -55,14 +55,18 @@ namespace osu.Game.Overlays.Comments
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
background.FadeIn(duration, Easing.OutQuint);
|
||||
FadeInBackground();
|
||||
return base.OnHover(e);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
base.OnHoverLost(e);
|
||||
background.FadeOut(duration, Easing.OutQuint);
|
||||
FadeOutBackground();
|
||||
}
|
||||
|
||||
public void FadeInBackground() => background.FadeIn(duration, Easing.OutQuint);
|
||||
|
||||
public void FadeOutBackground() => background.FadeOut(duration, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
|
75
osu.Game/Overlays/Comments/SortSelector.cs
Normal file
75
osu.Game/Overlays/Comments/SortSelector.cs
Normal file
@ -0,0 +1,75 @@
|
||||
// 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.Game.Online.API.Requests;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Bindables;
|
||||
|
||||
namespace osu.Game.Overlays.Comments
|
||||
{
|
||||
public class SortSelector : OsuTabControl<SortCommentsBy>
|
||||
{
|
||||
private const int spacing = 5;
|
||||
|
||||
protected override Dropdown<SortCommentsBy> CreateDropdown() => null;
|
||||
|
||||
protected override TabItem<SortCommentsBy> CreateTabItem(SortCommentsBy value) => new SortTabItem(value);
|
||||
|
||||
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(spacing, 0),
|
||||
};
|
||||
|
||||
public SortSelector()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
private class SortTabItem : TabItem<SortCommentsBy>
|
||||
{
|
||||
private readonly TabContent content;
|
||||
|
||||
public SortTabItem(SortCommentsBy value)
|
||||
: base(value)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Child = content = new TabContent(value)
|
||||
{ Active = { BindTarget = Active } };
|
||||
}
|
||||
|
||||
protected override void OnActivated() => content.FadeInBackground();
|
||||
|
||||
protected override void OnDeactivated() => content.FadeOutBackground();
|
||||
|
||||
private class TabContent : HeaderButton
|
||||
{
|
||||
private const int text_size = 14;
|
||||
|
||||
public readonly BindableBool Active = new BindableBool();
|
||||
|
||||
public TabContent(SortCommentsBy value)
|
||||
{
|
||||
Add(new SpriteText
|
||||
{
|
||||
Font = OsuFont.GetFont(size: text_size),
|
||||
Text = value.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
if (!Active.Value) base.OnHoverLost(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user