mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
Move PaginatedContainerWithHeader logic to a base class
This commit is contained in:
parent
e5f70d8eae
commit
913e3faf60
@ -14,13 +14,13 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Beatmaps
|
||||
{
|
||||
public class PaginatedBeatmapContainer : PaginatedContainerWithHeader<APIBeatmapSet>
|
||||
public class PaginatedBeatmapContainer : PaginatedContainer<APIBeatmapSet>
|
||||
{
|
||||
private const float panel_padding = 10f;
|
||||
private readonly BeatmapSetType type;
|
||||
|
||||
public PaginatedBeatmapContainer(BeatmapSetType type, Bindable<User> user, string headerText)
|
||||
: base(user, headerText, CounterVisibilityState.AlwaysVisible)
|
||||
: base(user, "", headerText, CounterVisibilityState.AlwaysVisible)
|
||||
{
|
||||
this.type = type;
|
||||
ItemsPerPage = 6;
|
||||
|
@ -13,10 +13,10 @@ using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Historical
|
||||
{
|
||||
public class PaginatedMostPlayedBeatmapContainer : PaginatedContainerWithHeader<APIUserMostPlayedBeatmap>
|
||||
public class PaginatedMostPlayedBeatmapContainer : PaginatedContainer<APIUserMostPlayedBeatmap>
|
||||
{
|
||||
public PaginatedMostPlayedBeatmapContainer(Bindable<User> user)
|
||||
: base(user, "Most Played Beatmaps", CounterVisibilityState.AlwaysHidden, "No records. :(")
|
||||
: base(user, "No records. :(")
|
||||
{
|
||||
ItemsPerPage = 5;
|
||||
}
|
||||
|
@ -36,10 +36,16 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
private readonly string missing;
|
||||
private ShowMoreButton moreButton;
|
||||
private OsuSpriteText missingText;
|
||||
private PaginatedContainerHeader header;
|
||||
|
||||
protected PaginatedContainer(Bindable<User> user, string missing = "")
|
||||
private readonly string headerText;
|
||||
private readonly CounterVisibilityState counterVisibilityState;
|
||||
|
||||
protected PaginatedContainer(Bindable<User> user, string missing = "", string headerText = "", CounterVisibilityState counterVisibilityState = CounterVisibilityState.AlwaysHidden)
|
||||
{
|
||||
this.headerText = headerText;
|
||||
this.missing = missing;
|
||||
this.counterVisibilityState = counterVisibilityState;
|
||||
User.BindTo(user);
|
||||
}
|
||||
|
||||
@ -50,9 +56,12 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Direction = FillDirection.Vertical;
|
||||
|
||||
Children = new[]
|
||||
Children = new Drawable[]
|
||||
{
|
||||
CreateHeaderContent,
|
||||
header = new PaginatedContainerHeader(headerText, counterVisibilityState)
|
||||
{
|
||||
Alpha = string.IsNullOrEmpty(headerText) ? 0 : 1
|
||||
},
|
||||
ItemsContainer = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Y,
|
||||
@ -91,7 +100,8 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
|
||||
if (e.NewValue != null)
|
||||
{
|
||||
OnUserChanged(e.NewValue);
|
||||
showMore();
|
||||
SetCount(GetCount(e.NewValue));
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,17 +140,14 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
}, loadCancellation.Token);
|
||||
});
|
||||
|
||||
protected virtual void OnUserChanged(User user)
|
||||
{
|
||||
showMore();
|
||||
}
|
||||
protected virtual int GetCount(User user) => 0;
|
||||
|
||||
protected void SetCount(int value) => header.Current.Value = value;
|
||||
|
||||
protected virtual void OnItemsReceived(List<TModel> items)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual Drawable CreateHeaderContent => Empty();
|
||||
|
||||
protected abstract APIRequest<List<TModel>> CreateRequest();
|
||||
|
||||
protected abstract Drawable CreateDrawableItem(TModel model);
|
||||
|
@ -1,34 +0,0 @@
|
||||
// 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.Framework.Graphics;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections
|
||||
{
|
||||
public abstract class PaginatedContainerWithHeader<TModel> : PaginatedContainer<TModel>
|
||||
{
|
||||
private readonly string headerText;
|
||||
private readonly CounterVisibilityState counterVisibilityState;
|
||||
|
||||
protected PaginatedContainerHeader Header { get; private set; }
|
||||
|
||||
protected PaginatedContainerWithHeader(Bindable<User> user, string headerText, CounterVisibilityState counterVisibilityState, string missing = "")
|
||||
: base(user, missing)
|
||||
{
|
||||
this.headerText = headerText;
|
||||
this.counterVisibilityState = counterVisibilityState;
|
||||
}
|
||||
|
||||
protected override Drawable CreateHeaderContent => Header = new PaginatedContainerHeader(headerText, counterVisibilityState);
|
||||
|
||||
protected override void OnUserChanged(User user)
|
||||
{
|
||||
base.OnUserChanged(user);
|
||||
Header.Current.Value = GetCount(user);
|
||||
}
|
||||
|
||||
protected virtual int GetCount(User user) => 0;
|
||||
}
|
||||
}
|
@ -14,12 +14,12 @@ using osu.Framework.Allocation;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Ranks
|
||||
{
|
||||
public class PaginatedScoreContainer : PaginatedContainerWithHeader<APILegacyScoreInfo>
|
||||
public class PaginatedScoreContainer : PaginatedContainer<APILegacyScoreInfo>
|
||||
{
|
||||
private readonly ScoreType type;
|
||||
|
||||
public PaginatedScoreContainer(ScoreType type, Bindable<User> user, string headerText, CounterVisibilityState counterVisibilityState, string missingText = "")
|
||||
: base(user, headerText, counterVisibilityState, missingText)
|
||||
: base(user, missingText, headerText, counterVisibilityState)
|
||||
{
|
||||
this.type = type;
|
||||
|
||||
@ -49,7 +49,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
|
||||
base.OnItemsReceived(items);
|
||||
|
||||
if (type == ScoreType.Recent)
|
||||
Header.Current.Value = items.Count;
|
||||
SetCount(items.Count);
|
||||
}
|
||||
|
||||
protected override APIRequest<List<APILegacyScoreInfo>> CreateRequest() =>
|
||||
|
Loading…
Reference in New Issue
Block a user