mirror of
https://github.com/ppy/osu
synced 2025-01-03 12:52:10 +00:00
Implement PaginatedContainerWithHeader component
This commit is contained in:
parent
b7bd084296
commit
e39609d3ca
@ -1,4 +1,7 @@
|
||||
using NUnit.Framework;
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Game.Overlays.Profile.Sections;
|
||||
using osu.Framework.Testing;
|
||||
using System.Linq;
|
||||
@ -40,7 +43,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
[Test]
|
||||
public void TestVisibleWhenZeroCounter()
|
||||
{
|
||||
AddStep("Create header", () => createHeader("Header with visible when zero counter", CounterVisibilityState.VisibleWhenNonZero));
|
||||
AddStep("Create header", () => createHeader("Header with visible when zero counter", CounterVisibilityState.VisibleWhenZero));
|
||||
AddAssert("Value is 0", () => header.Current.Value == 0);
|
||||
AddAssert("Counter is visible", () => header.ChildrenOfType<CounterPill>().First().Alpha == 1);
|
||||
AddStep("Set count 10", () => header.Current.Value = 10);
|
||||
@ -54,11 +57,11 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
[Test]
|
||||
public void TestInitialVisibility()
|
||||
{
|
||||
AddStep("Create header with 0 value", () => createHeader("Header with visible when zero counter", CounterVisibilityState.VisibleWhenNonZero, 0));
|
||||
AddStep("Create header with 0 value", () => createHeader("Header with visible when zero counter", CounterVisibilityState.VisibleWhenZero, 0));
|
||||
AddAssert("Value is 0", () => header.Current.Value == 0);
|
||||
AddAssert("Counter is visible", () => header.ChildrenOfType<CounterPill>().First().Alpha == 1);
|
||||
|
||||
AddStep("Create header with 1 value", () => createHeader("Header with visible when zero counter", CounterVisibilityState.VisibleWhenNonZero, 1));
|
||||
AddStep("Create header with 1 value", () => createHeader("Header with visible when zero counter", CounterVisibilityState.VisibleWhenZero, 1));
|
||||
AddAssert("Value is 1", () => header.Current.Value == 1);
|
||||
AddAssert("Counter is hidden", () => header.ChildrenOfType<CounterPill>().First().Alpha == 0);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Online.API;
|
||||
@ -13,21 +14,49 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Beatmaps
|
||||
{
|
||||
public class PaginatedBeatmapContainer : PaginatedContainer<APIBeatmapSet>
|
||||
public class PaginatedBeatmapContainer : PaginatedContainerWithHeader<APIBeatmapSet>
|
||||
{
|
||||
private const float panel_padding = 10f;
|
||||
private readonly BeatmapSetType type;
|
||||
|
||||
public PaginatedBeatmapContainer(BeatmapSetType type, Bindable<User> user)
|
||||
: base(user)
|
||||
public PaginatedBeatmapContainer(BeatmapSetType type, Bindable<User> user, string headerText)
|
||||
: base(user, headerText, CounterVisibilityState.AlwaysVisible)
|
||||
{
|
||||
this.type = type;
|
||||
|
||||
ItemsPerPage = 6;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
ItemsContainer.Spacing = new Vector2(panel_padding);
|
||||
}
|
||||
|
||||
protected override int GetCount(User user)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case BeatmapSetType.Favourite:
|
||||
return user.FavouriteBeatmapsetCount;
|
||||
|
||||
case BeatmapSetType.Graveyard:
|
||||
return user.GraveyardBeatmapsetCount;
|
||||
|
||||
case BeatmapSetType.Loved:
|
||||
return user.LovedBeatmapsetCount;
|
||||
|
||||
case BeatmapSetType.RankedAndApproved:
|
||||
return user.RankedAndApprovedBeatmapsetCount;
|
||||
|
||||
case BeatmapSetType.Unranked:
|
||||
return user.UnrankedBeatmapsetCount;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override APIRequest<List<APIBeatmapSet>> CreateRequest() =>
|
||||
new GetUserBeatmapsRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage);
|
||||
|
||||
|
@ -16,11 +16,11 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
{
|
||||
Children = new[]
|
||||
{
|
||||
new PaginatedBeatmapContainer(BeatmapSetType.Favourite, User),
|
||||
new PaginatedBeatmapContainer(BeatmapSetType.RankedAndApproved, User),
|
||||
new PaginatedBeatmapContainer(BeatmapSetType.Loved, User),
|
||||
new PaginatedBeatmapContainer(BeatmapSetType.Unranked, User),
|
||||
new PaginatedBeatmapContainer(BeatmapSetType.Graveyard, User)
|
||||
new PaginatedBeatmapContainer(BeatmapSetType.Favourite, User, "Favourite Beatmaps"),
|
||||
new PaginatedBeatmapContainer(BeatmapSetType.RankedAndApproved, User, "Ranked & Approved Beatmaps"),
|
||||
new PaginatedBeatmapContainer(BeatmapSetType.Loved, User, "Loved Beatmaps"),
|
||||
new PaginatedBeatmapContainer(BeatmapSetType.Unranked, User, "Pending Beatmaps"),
|
||||
new PaginatedBeatmapContainer(BeatmapSetType.Graveyard, User, "Graveyarded Beatmaps")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -12,12 +13,17 @@ using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Historical
|
||||
{
|
||||
public class PaginatedMostPlayedBeatmapContainer : PaginatedContainer<APIUserMostPlayedBeatmap>
|
||||
public class PaginatedMostPlayedBeatmapContainer : PaginatedContainerWithHeader<APIUserMostPlayedBeatmap>
|
||||
{
|
||||
public PaginatedMostPlayedBeatmapContainer(Bindable<User> user)
|
||||
: base(user, "No records. :(")
|
||||
: base(user, "Most Played Beatmaps", CounterVisibilityState.AlwaysHidden, "No records. :(")
|
||||
{
|
||||
ItemsPerPage = 5;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
ItemsContainer.Direction = FillDirection.Vertical;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new PaginatedMostPlayedBeatmapContainer(User),
|
||||
new PaginatedScoreContainer(ScoreType.Recent, User),
|
||||
new PaginatedScoreContainer(ScoreType.Recent, User, "Recent Plays (24h)", CounterVisibilityState.VisibleWhenZero),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,6 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
{
|
||||
public abstract class PaginatedContainer<TModel> : FillFlowContainer
|
||||
{
|
||||
private readonly ShowMoreButton moreButton;
|
||||
private readonly OsuSpriteText missingText;
|
||||
private APIRequest<List<TModel>> retrievalRequest;
|
||||
private CancellationTokenSource loadCancellation;
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
@ -32,19 +27,32 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
protected int ItemsPerPage;
|
||||
|
||||
protected readonly Bindable<User> User = new Bindable<User>();
|
||||
protected readonly FillFlowContainer ItemsContainer;
|
||||
protected FillFlowContainer ItemsContainer;
|
||||
protected RulesetStore Rulesets;
|
||||
|
||||
private APIRequest<List<TModel>> retrievalRequest;
|
||||
private CancellationTokenSource loadCancellation;
|
||||
|
||||
private readonly string missing;
|
||||
private ShowMoreButton moreButton;
|
||||
private OsuSpriteText missingText;
|
||||
|
||||
protected PaginatedContainer(Bindable<User> user, string missing = "")
|
||||
{
|
||||
this.missing = missing;
|
||||
User.BindTo(user);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(RulesetStore rulesets)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Direction = FillDirection.Vertical;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
CreateHeaderContent,
|
||||
ItemsContainer = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Y,
|
||||
@ -66,11 +74,7 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
Alpha = 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(RulesetStore rulesets)
|
||||
{
|
||||
Rulesets = rulesets;
|
||||
|
||||
User.ValueChanged += onUserChanged;
|
||||
@ -87,7 +91,7 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
|
||||
if (e.NewValue != null)
|
||||
{
|
||||
showMore();
|
||||
OnUserChanged(e.NewValue);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,6 +128,13 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
}, loadCancellation.Token);
|
||||
});
|
||||
|
||||
protected virtual void OnUserChanged(User user)
|
||||
{
|
||||
showMore();
|
||||
}
|
||||
|
||||
protected virtual Drawable CreateHeaderContent => Empty();
|
||||
|
||||
protected abstract APIRequest<List<TModel>> CreateRequest();
|
||||
|
||||
protected abstract Drawable CreateDrawableItem(TModel model);
|
||||
|
@ -1,4 +1,7 @@
|
||||
using osu.Framework.Allocation;
|
||||
// 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.Graphics.UserInterface;
|
||||
@ -103,7 +106,7 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
case CounterVisibilityState.AlwaysVisible:
|
||||
return 1;
|
||||
|
||||
case CounterVisibilityState.VisibleWhenNonZero:
|
||||
case CounterVisibilityState.VisibleWhenZero:
|
||||
return current.Value == 0 ? 1 : 0;
|
||||
|
||||
default:
|
||||
@ -113,7 +116,7 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
|
||||
private void onCurrentChanged(ValueChangedEvent<int> countValue)
|
||||
{
|
||||
if (counterState == CounterVisibilityState.VisibleWhenNonZero)
|
||||
if (counterState == CounterVisibilityState.VisibleWhenZero)
|
||||
{
|
||||
counterPill.Alpha = countValue.NewValue == 0 ? 1 : 0;
|
||||
}
|
||||
@ -124,6 +127,6 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
{
|
||||
AlwaysHidden,
|
||||
AlwaysVisible,
|
||||
VisibleWhenNonZero
|
||||
VisibleWhenZero
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
// 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;
|
||||
|
||||
private PaginatedContainerHeader header;
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
@ -10,22 +10,40 @@ using osu.Framework.Graphics;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Framework.Allocation;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Ranks
|
||||
{
|
||||
public class PaginatedScoreContainer : PaginatedContainer<APILegacyScoreInfo>
|
||||
public class PaginatedScoreContainer : PaginatedContainerWithHeader<APILegacyScoreInfo>
|
||||
{
|
||||
private readonly ScoreType type;
|
||||
|
||||
public PaginatedScoreContainer(ScoreType type, Bindable<User> user)
|
||||
: base(user)
|
||||
public PaginatedScoreContainer(ScoreType type, Bindable<User> user, string headerText, CounterVisibilityState counterVisibilityState, string missingText = "")
|
||||
: base(user, headerText, counterVisibilityState, missingText)
|
||||
{
|
||||
this.type = type;
|
||||
|
||||
ItemsPerPage = 5;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
ItemsContainer.Direction = FillDirection.Vertical;
|
||||
}
|
||||
|
||||
protected override int GetCount(User user)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ScoreType.Firsts:
|
||||
return user.ScoresFirstCount;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected override APIRequest<List<APILegacyScoreInfo>> CreateRequest() =>
|
||||
new GetUserScoresRequest(User.Value.Id, type, VisiblePages++, ItemsPerPage);
|
||||
|
||||
|
@ -16,8 +16,8 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
{
|
||||
Children = new[]
|
||||
{
|
||||
new PaginatedScoreContainer(ScoreType.Best, User),
|
||||
new PaginatedScoreContainer(ScoreType.Firsts, User),
|
||||
new PaginatedScoreContainer(ScoreType.Best, User, "Best Performance", CounterVisibilityState.AlwaysHidden, "No performance records. :("),
|
||||
new PaginatedScoreContainer(ScoreType.Firsts, User, "First Place Ranks", CounterVisibilityState.AlwaysVisible)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -9,15 +9,21 @@ using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.API;
|
||||
using System.Collections.Generic;
|
||||
using osuTK;
|
||||
using osu.Framework.Allocation;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Recent
|
||||
{
|
||||
public class PaginatedRecentActivityContainer : PaginatedContainer<APIRecentActivity>
|
||||
{
|
||||
public PaginatedRecentActivityContainer(Bindable<User> user)
|
||||
: base(user)
|
||||
: base(user, "This user hasn't done anything notable recently!")
|
||||
{
|
||||
ItemsPerPage = 10;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
ItemsContainer.Spacing = new Vector2(0, 8);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user