mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 04:53:21 +08:00
Implement CommentsShowMoreButton
This commit is contained in:
parent
60954f969d
commit
a44cc2e70b
@ -47,6 +47,12 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
scrollFlow.Clear();
|
scrollFlow.Clear();
|
||||||
scrollFlow.Add(new CommentsContainer(CommentableType.Beatmapset, 24313));
|
scrollFlow.Add(new CommentsContainer(CommentableType.Beatmapset, 24313));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddStep("lazer build comments", () =>
|
||||||
|
{
|
||||||
|
scrollFlow.Clear();
|
||||||
|
scrollFlow.Add(new CommentsContainer(CommentableType.Build, 4772));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using osu.Game.Overlays.Profile.Sections;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.Online
|
||||||
{
|
{
|
||||||
@ -17,11 +18,11 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
|
|
||||||
public TestSceneShowMoreButton()
|
public TestSceneShowMoreButton()
|
||||||
{
|
{
|
||||||
ShowMoreButton button = null;
|
ProfileShowMoreButton button = null;
|
||||||
|
|
||||||
int fireCount = 0;
|
int fireCount = 0;
|
||||||
|
|
||||||
Add(button = new ShowMoreButton
|
Add(button = new ProfileShowMoreButton
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
|
@ -1,30 +1,36 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile.Sections
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
public class ShowMoreButton : OsuHoverContainer
|
public class ShowMoreButton : OsuHoverContainer
|
||||||
{
|
{
|
||||||
private const float fade_duration = 200;
|
private const float fade_duration = 200;
|
||||||
|
|
||||||
private readonly Box background;
|
private Color4 chevronIconColour;
|
||||||
private readonly LoadingAnimation loading;
|
|
||||||
private readonly FillFlowContainer content;
|
|
||||||
|
|
||||||
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
|
public Color4 ChevronIconColour
|
||||||
|
{
|
||||||
|
get => chevronIconColour;
|
||||||
|
set { chevronIconColour = leftChevron.AccentColour = rightChevron.AccentColour = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get => text.Text;
|
||||||
|
set { text.Text = value; }
|
||||||
|
}
|
||||||
|
|
||||||
private bool isLoading;
|
private bool isLoading;
|
||||||
|
|
||||||
@ -33,26 +39,32 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
get => isLoading;
|
get => isLoading;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (isLoading == value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
isLoading = value;
|
isLoading = value;
|
||||||
|
|
||||||
Enabled.Value = !isLoading;
|
Enabled.Value = !isLoading;
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
loading.FadeIn(fade_duration, Easing.OutQuint);
|
loading.Show();
|
||||||
content.FadeOut(fade_duration, Easing.OutQuint);
|
content.FadeOut(fade_duration, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
loading.FadeOut(fade_duration, Easing.OutQuint);
|
loading.Hide();
|
||||||
content.FadeIn(fade_duration, Easing.OutQuint);
|
content.FadeIn(fade_duration, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly Box background;
|
||||||
|
private readonly LoadingAnimation loading;
|
||||||
|
private readonly FillFlowContainer content;
|
||||||
|
private readonly ChevronIcon leftChevron;
|
||||||
|
private readonly ChevronIcon rightChevron;
|
||||||
|
private readonly SpriteText text;
|
||||||
|
|
||||||
|
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
|
||||||
|
|
||||||
public ShowMoreButton()
|
public ShowMoreButton()
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both;
|
AutoSizeAxes = Axes.Both;
|
||||||
@ -77,15 +89,15 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
Spacing = new Vector2(7),
|
Spacing = new Vector2(7),
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new ChevronIcon(),
|
leftChevron = new ChevronIcon(),
|
||||||
new OsuSpriteText
|
text = new OsuSpriteText
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
|
||||||
Text = "show more".ToUpper(),
|
Text = "show more".ToUpper(),
|
||||||
},
|
},
|
||||||
new ChevronIcon(),
|
rightChevron = new ChevronIcon(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loading = new LoadingAnimation
|
loading = new LoadingAnimation
|
||||||
@ -99,13 +111,6 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuColour colors)
|
|
||||||
{
|
|
||||||
IdleColour = colors.GreySeafoamDark;
|
|
||||||
HoverColour = colors.GreySeafoam;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
if (!Enabled.Value)
|
if (!Enabled.Value)
|
||||||
@ -126,6 +131,14 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
{
|
{
|
||||||
private const int icon_size = 8;
|
private const int icon_size = 8;
|
||||||
|
|
||||||
|
private Color4 accentColour;
|
||||||
|
|
||||||
|
public Color4 AccentColour
|
||||||
|
{
|
||||||
|
get => accentColour;
|
||||||
|
set { accentColour = Colour = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public ChevronIcon()
|
public ChevronIcon()
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre;
|
Anchor = Anchor.Centre;
|
||||||
@ -133,12 +146,6 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
Size = new Vector2(icon_size);
|
Size = new Vector2(icon_size);
|
||||||
Icon = FontAwesome.Solid.ChevronDown;
|
Icon = FontAwesome.Solid.ChevronDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuColour colors)
|
|
||||||
{
|
|
||||||
Colour = colors.Yellow;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,6 +16,8 @@ namespace osu.Game.Overlays.Comments
|
|||||||
{
|
{
|
||||||
public class CommentsContainer : CompositeDrawable
|
public class CommentsContainer : CompositeDrawable
|
||||||
{
|
{
|
||||||
|
private const int more_button_margin = 5;
|
||||||
|
|
||||||
private readonly CommentableType type;
|
private readonly CommentableType type;
|
||||||
private readonly long id;
|
private readonly long id;
|
||||||
|
|
||||||
@ -30,11 +32,13 @@ namespace osu.Game.Overlays.Comments
|
|||||||
|
|
||||||
private GetCommentsRequest request;
|
private GetCommentsRequest request;
|
||||||
private CancellationTokenSource loadCancellation;
|
private CancellationTokenSource loadCancellation;
|
||||||
|
private int currentPage;
|
||||||
|
private int loadedTopLevelComments;
|
||||||
|
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
private readonly FillFlowContainer content;
|
private readonly FillFlowContainer content;
|
||||||
private readonly FillFlowContainer footer;
|
|
||||||
private readonly DeletedChildsPlaceholder deletedChildsPlaceholder;
|
private readonly DeletedChildsPlaceholder deletedChildsPlaceholder;
|
||||||
|
private readonly CommentsShowMoreButton moreButton;
|
||||||
|
|
||||||
public CommentsContainer(CommentableType type, long id)
|
public CommentsContainer(CommentableType type, long id)
|
||||||
{
|
{
|
||||||
@ -78,7 +82,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = OsuColour.Gray(0.2f)
|
Colour = OsuColour.Gray(0.2f)
|
||||||
},
|
},
|
||||||
footer = new FillFlowContainer
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
@ -88,6 +92,18 @@ namespace osu.Game.Overlays.Comments
|
|||||||
deletedChildsPlaceholder = new DeletedChildsPlaceholder
|
deletedChildsPlaceholder = new DeletedChildsPlaceholder
|
||||||
{
|
{
|
||||||
ShowDeleted = { BindTarget = ShowDeleted }
|
ShowDeleted = { BindTarget = ShowDeleted }
|
||||||
|
},
|
||||||
|
new Container
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Child = moreButton = new CommentsShowMoreButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Margin = new MarginPadding(more_button_margin),
|
||||||
|
Action = () => getComments(false),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,16 +122,25 @@ namespace osu.Game.Overlays.Comments
|
|||||||
|
|
||||||
private void onSortChanged(ValueChangedEvent<CommentsSortCriteria> sort) => getComments();
|
private void onSortChanged(ValueChangedEvent<CommentsSortCriteria> sort) => getComments();
|
||||||
|
|
||||||
private void getComments()
|
private void getComments(bool initial = true)
|
||||||
{
|
{
|
||||||
|
if (initial)
|
||||||
|
{
|
||||||
|
currentPage = 1;
|
||||||
|
loadedTopLevelComments = 0;
|
||||||
|
deletedChildsPlaceholder.DeletedCount.Value = 0;
|
||||||
|
moreButton.IsLoading = true;
|
||||||
|
content.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
request?.Cancel();
|
request?.Cancel();
|
||||||
loadCancellation?.Cancel();
|
loadCancellation?.Cancel();
|
||||||
request = new GetCommentsRequest(type, id, Sort.Value);
|
request = new GetCommentsRequest(type, id, Sort.Value, currentPage++);
|
||||||
request.Success += onSuccess;
|
request.Success += response => onSuccess(response, initial);
|
||||||
api.Queue(request);
|
api.Queue(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSuccess(APICommentsController response)
|
private void onSuccess(APICommentsController response, bool initial)
|
||||||
{
|
{
|
||||||
loadCancellation = new CancellationTokenSource();
|
loadCancellation = new CancellationTokenSource();
|
||||||
|
|
||||||
@ -137,8 +162,6 @@ namespace osu.Game.Overlays.Comments
|
|||||||
|
|
||||||
LoadComponentAsync(page, loaded =>
|
LoadComponentAsync(page, loaded =>
|
||||||
{
|
{
|
||||||
content.Clear();
|
|
||||||
|
|
||||||
content.Add(loaded);
|
content.Add(loaded);
|
||||||
|
|
||||||
int deletedComments = 0;
|
int deletedComments = 0;
|
||||||
@ -149,7 +172,20 @@ namespace osu.Game.Overlays.Comments
|
|||||||
deletedComments++;
|
deletedComments++;
|
||||||
});
|
});
|
||||||
|
|
||||||
deletedChildsPlaceholder.DeletedCount.Value = deletedComments;
|
deletedChildsPlaceholder.DeletedCount.Value = initial ? deletedComments : deletedChildsPlaceholder.DeletedCount.Value + deletedComments;
|
||||||
|
|
||||||
|
if (response.HasMore)
|
||||||
|
{
|
||||||
|
response.Comments.ForEach(comment =>
|
||||||
|
{
|
||||||
|
if (comment.IsTopLevel)
|
||||||
|
loadedTopLevelComments++;
|
||||||
|
});
|
||||||
|
moreButton.Current.Value = response.TopLevelCount - loadedTopLevelComments;
|
||||||
|
moreButton.IsLoading = false;
|
||||||
|
}
|
||||||
|
moreButton.FadeTo(response.HasMore ? 1 : 0);
|
||||||
|
|
||||||
}, loadCancellation.Token);
|
}, loadCancellation.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
osu.Game/Overlays/Comments/CommentsShowMoreButton.cs
Normal file
32
osu.Game/Overlays/Comments/CommentsShowMoreButton.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// 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.Bindables;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Comments
|
||||||
|
{
|
||||||
|
public class CommentsShowMoreButton : ShowMoreButton
|
||||||
|
{
|
||||||
|
public readonly BindableInt Current = new BindableInt();
|
||||||
|
|
||||||
|
public CommentsShowMoreButton()
|
||||||
|
{
|
||||||
|
IdleColour = OsuColour.Gray(0.3f);
|
||||||
|
HoverColour = OsuColour.Gray(0.4f);
|
||||||
|
ChevronIconColour = OsuColour.Gray(0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
Current.BindValueChanged(onCurrentChanged, true);
|
||||||
|
base.LoadComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onCurrentChanged(ValueChangedEvent<int> count)
|
||||||
|
{
|
||||||
|
Text = $@"Show More ({count.NewValue})".ToUpper();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,6 @@ using osu.Game.Graphics;
|
|||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Comments
|
namespace osu.Game.Overlays.Comments
|
||||||
{
|
{
|
||||||
@ -66,7 +65,12 @@ namespace osu.Game.Overlays.Comments
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
countText.Text = $@"{count.NewValue} deleted comment{(count.NewValue.ToString().ToCharArray().Last() == '1' ? "" : "s")}";
|
string str = $@"{count.NewValue} deleted comment";
|
||||||
|
|
||||||
|
if (!(count.NewValue.ToString().EndsWith("1") && !count.NewValue.ToString().EndsWith("11")))
|
||||||
|
str += "s";
|
||||||
|
|
||||||
|
countText.Text = str;
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
{
|
{
|
||||||
public abstract class PaginatedContainer<TModel> : FillFlowContainer
|
public abstract class PaginatedContainer<TModel> : FillFlowContainer
|
||||||
{
|
{
|
||||||
private readonly ShowMoreButton moreButton;
|
private readonly ProfileShowMoreButton moreButton;
|
||||||
private readonly OsuSpriteText missingText;
|
private readonly OsuSpriteText missingText;
|
||||||
private APIRequest<List<TModel>> retrievalRequest;
|
private APIRequest<List<TModel>> retrievalRequest;
|
||||||
private CancellationTokenSource loadCancellation;
|
private CancellationTokenSource loadCancellation;
|
||||||
@ -56,7 +56,7 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Spacing = new Vector2(0, 2),
|
Spacing = new Vector2(0, 2),
|
||||||
},
|
},
|
||||||
moreButton = new ShowMoreButton
|
moreButton = new ProfileShowMoreButton
|
||||||
{
|
{
|
||||||
Anchor = Anchor.TopCentre,
|
Anchor = Anchor.TopCentre,
|
||||||
Origin = Anchor.TopCentre,
|
Origin = Anchor.TopCentre,
|
||||||
|
20
osu.Game/Overlays/Profile/Sections/ProfileShowMoreButton.cs
Normal file
20
osu.Game/Overlays/Profile/Sections/ProfileShowMoreButton.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// 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.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Profile.Sections
|
||||||
|
{
|
||||||
|
public class ProfileShowMoreButton : ShowMoreButton
|
||||||
|
{
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colors)
|
||||||
|
{
|
||||||
|
IdleColour = colors.GreySeafoamDark;
|
||||||
|
HoverColour = colors.GreySeafoam;
|
||||||
|
ChevronIconColour = colors.Yellow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user