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