mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 18:32:55 +08:00
Implement ProfileSubsection component
This commit is contained in:
parent
c4cb1440ab
commit
718ba9253b
@ -14,7 +14,7 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Beatmaps
|
||||
{
|
||||
public class PaginatedBeatmapContainer : PaginatedContainer<APIBeatmapSet>
|
||||
public class PaginatedBeatmapContainer : PaginatedProfileSubsection<APIBeatmapSet>
|
||||
{
|
||||
private const float panel_padding = 10f;
|
||||
private readonly BeatmapSetType type;
|
||||
|
@ -13,7 +13,7 @@ using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Historical
|
||||
{
|
||||
public class PaginatedMostPlayedBeatmapContainer : PaginatedContainer<APIUserMostPlayedBeatmap>
|
||||
public class PaginatedMostPlayedBeatmapContainer : PaginatedProfileSubsection<APIUserMostPlayedBeatmap>
|
||||
{
|
||||
public PaginatedMostPlayedBeatmapContainer(Bindable<User> user)
|
||||
: base(user, "Most Played Beatmaps", "No records. :(", CounterVisibilityState.AlwaysVisible)
|
||||
|
@ -11,7 +11,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Kudosu
|
||||
{
|
||||
public class PaginatedKudosuHistoryContainer : PaginatedContainer<APIKudosuHistory>
|
||||
public class PaginatedKudosuHistoryContainer : PaginatedProfileSubsection<APIKudosuHistory>
|
||||
{
|
||||
public PaginatedKudosuHistoryContainer(Bindable<User> user)
|
||||
: base(user, missingText: "This user hasn't received any kudosu!")
|
||||
|
@ -6,10 +6,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Users;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -18,7 +15,7 @@ using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections
|
||||
{
|
||||
public abstract class PaginatedContainer<TModel> : FillFlowContainer
|
||||
public abstract class PaginatedProfileSubsection<TModel> : ProfileSubsection
|
||||
{
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
@ -26,42 +23,25 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
protected int VisiblePages;
|
||||
protected int ItemsPerPage;
|
||||
|
||||
protected readonly Bindable<User> User = new Bindable<User>();
|
||||
protected FillFlowContainer ItemsContainer;
|
||||
protected RulesetStore Rulesets;
|
||||
protected FillFlowContainer ItemsContainer { get; private set; }
|
||||
|
||||
private APIRequest<List<TModel>> retrievalRequest;
|
||||
private CancellationTokenSource loadCancellation;
|
||||
|
||||
private readonly string missingText;
|
||||
private ShowMoreButton moreButton;
|
||||
private OsuSpriteText missing;
|
||||
private ProfileSubsectionHeader header;
|
||||
|
||||
private readonly string headerText;
|
||||
private readonly CounterVisibilityState counterVisibilityState;
|
||||
|
||||
protected PaginatedContainer(Bindable<User> user, string headerText = "", string missingText = "", CounterVisibilityState counterVisibilityState = CounterVisibilityState.AlwaysHidden)
|
||||
protected PaginatedProfileSubsection(Bindable<User> user, string headerText = "", string missingText = "", CounterVisibilityState counterVisibilityState = CounterVisibilityState.AlwaysHidden)
|
||||
: base(user, headerText, missingText, counterVisibilityState)
|
||||
{
|
||||
this.headerText = headerText;
|
||||
this.missingText = missingText;
|
||||
this.counterVisibilityState = counterVisibilityState;
|
||||
User.BindTo(user);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(RulesetStore rulesets)
|
||||
protected override Drawable CreateContent() => new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Direction = FillDirection.Vertical;
|
||||
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
header = new ProfileSubsectionHeader(headerText, counterVisibilityState)
|
||||
{
|
||||
Alpha = string.IsNullOrEmpty(headerText) ? 0 : 1
|
||||
},
|
||||
ItemsContainer = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Y,
|
||||
@ -75,22 +55,11 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
Alpha = 0,
|
||||
Margin = new MarginPadding { Top = 10 },
|
||||
Action = showMore,
|
||||
},
|
||||
missing = new OsuSpriteText
|
||||
{
|
||||
Font = OsuFont.GetFont(size: 15),
|
||||
Text = missingText,
|
||||
Alpha = 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Rulesets = rulesets;
|
||||
|
||||
User.ValueChanged += onUserChanged;
|
||||
User.TriggerChange();
|
||||
}
|
||||
|
||||
private void onUserChanged(ValueChangedEvent<User> e)
|
||||
protected override void OnUserChanged(ValueChangedEvent<User> e)
|
||||
{
|
||||
loadCancellation?.Cancel();
|
||||
retrievalRequest?.Cancel();
|
||||
@ -124,15 +93,15 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
moreButton.Hide();
|
||||
moreButton.IsLoading = false;
|
||||
|
||||
if (!string.IsNullOrEmpty(missing.Text))
|
||||
missing.Show();
|
||||
if (!string.IsNullOrEmpty(Missing.Text))
|
||||
Missing.Show();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LoadComponentsAsync(items.Select(CreateDrawableItem).Where(d => d != null), drawables =>
|
||||
{
|
||||
missing.Hide();
|
||||
Missing.Hide();
|
||||
moreButton.FadeTo(items.Count == ItemsPerPage ? 1 : 0);
|
||||
moreButton.IsLoading = false;
|
||||
|
||||
@ -142,8 +111,6 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
|
||||
protected virtual int GetCount(User user) => 0;
|
||||
|
||||
protected void SetCount(int value) => header.Current.Value = value;
|
||||
|
||||
protected virtual void OnItemsReceived(List<TModel> items)
|
||||
{
|
||||
}
|
||||
@ -154,8 +121,9 @@ namespace osu.Game.Overlays.Profile.Sections
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
retrievalRequest?.Cancel();
|
||||
loadCancellation?.Cancel();
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
}
|
||||
}
|
78
osu.Game/Overlays/Profile/Sections/ProfileSubsection.cs
Normal file
78
osu.Game/Overlays/Profile/Sections/ProfileSubsection.cs
Normal file
@ -0,0 +1,78 @@
|
||||
// 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.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Users;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections
|
||||
{
|
||||
public abstract class ProfileSubsection : FillFlowContainer
|
||||
{
|
||||
protected readonly Bindable<User> User = new Bindable<User>();
|
||||
|
||||
protected RulesetStore Rulesets { get; private set; }
|
||||
|
||||
protected OsuSpriteText Missing { get; private set; }
|
||||
|
||||
private readonly string headerText;
|
||||
private readonly string missingText;
|
||||
private readonly CounterVisibilityState counterVisibilityState;
|
||||
|
||||
private ProfileSubsectionHeader header;
|
||||
|
||||
protected ProfileSubsection(Bindable<User> user, string headerText = "", string missingText = "", CounterVisibilityState counterVisibilityState = CounterVisibilityState.AlwaysHidden)
|
||||
{
|
||||
this.headerText = headerText;
|
||||
this.missingText = missingText;
|
||||
this.counterVisibilityState = counterVisibilityState;
|
||||
User.BindTo(user);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(RulesetStore rulesets)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Direction = FillDirection.Vertical;
|
||||
|
||||
Children = new[]
|
||||
{
|
||||
header = new ProfileSubsectionHeader(headerText, counterVisibilityState)
|
||||
{
|
||||
Alpha = string.IsNullOrEmpty(headerText) ? 0 : 1
|
||||
},
|
||||
CreateContent(),
|
||||
Missing = new OsuSpriteText
|
||||
{
|
||||
Font = OsuFont.GetFont(size: 15),
|
||||
Text = missingText,
|
||||
Alpha = 0,
|
||||
},
|
||||
};
|
||||
|
||||
Rulesets = rulesets;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
User.BindValueChanged(OnUserChanged, true);
|
||||
}
|
||||
|
||||
[NotNull]
|
||||
protected abstract Drawable CreateContent();
|
||||
|
||||
protected virtual void OnUserChanged(ValueChangedEvent<User> e)
|
||||
{
|
||||
}
|
||||
|
||||
protected void SetCount(int value) => header.Current.Value = value;
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ using osu.Framework.Allocation;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Ranks
|
||||
{
|
||||
public class PaginatedScoreContainer : PaginatedContainer<APILegacyScoreInfo>
|
||||
public class PaginatedScoreContainer : PaginatedProfileSubsection<APILegacyScoreInfo>
|
||||
{
|
||||
private readonly ScoreType type;
|
||||
|
||||
|
@ -13,7 +13,7 @@ using osu.Framework.Allocation;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections.Recent
|
||||
{
|
||||
public class PaginatedRecentActivityContainer : PaginatedContainer<APIRecentActivity>
|
||||
public class PaginatedRecentActivityContainer : PaginatedProfileSubsection<APIRecentActivity>
|
||||
{
|
||||
public PaginatedRecentActivityContainer(Bindable<User> user)
|
||||
: base(user, missingText: "This user hasn't done anything notable recently!")
|
||||
|
Loading…
Reference in New Issue
Block a user