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