1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-17 22:17:25 +08:00

Implement ProfileSubsection

This commit is contained in:
Andrei Zavatski 2020-11-14 18:21:10 +03:00
parent 01f28a35c3
commit ae4a2e74fa
4 changed files with 95 additions and 50 deletions

View File

@ -11,12 +11,12 @@ using osu.Framework.Allocation;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestScenePaginatedContainerHeader : OsuTestScene
public class TestSceneProfileSubsectionHeader : OsuTestScene
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Pink);
private PaginatedContainerHeader header;
private ProfileSubsectionHeader header;
[Test]
public void TestHiddenCounter()
@ -69,7 +69,7 @@ namespace osu.Game.Tests.Visual.UserInterface
private void createHeader(string text, CounterVisibilityState state, int initialValue = 0)
{
Clear();
Add(header = new PaginatedContainerHeader(text, state)
Add(header = new ProfileSubsectionHeader(text, state)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -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 PaginatedContainer<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;
private APIRequest<List<TModel>> retrievalRequest;
private CancellationTokenSource loadCancellation;
private readonly string missingText;
private ShowMoreButton moreButton;
private OsuSpriteText missing;
private PaginatedContainerHeader header;
private readonly string headerText;
private readonly CounterVisibilityState counterVisibilityState;
protected PaginatedContainer(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 PaginatedContainerHeader(headerText, counterVisibilityState)
{
Alpha = string.IsNullOrEmpty(headerText) ? 0 : 1
},
ItemsContainer = new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
@ -76,21 +56,10 @@ namespace osu.Game.Overlays.Profile.Sections
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)
{
}

View 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 Drawable[]
{
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;
}
}

View File

@ -14,7 +14,7 @@ using osu.Game.Graphics;
namespace osu.Game.Overlays.Profile.Sections
{
public class PaginatedContainerHeader : CompositeDrawable, IHasCurrentValue<int>
public class ProfileSubsectionHeader : CompositeDrawable, IHasCurrentValue<int>
{
private readonly BindableWithCurrent<int> current = new BindableWithCurrent<int>();
@ -29,7 +29,7 @@ namespace osu.Game.Overlays.Profile.Sections
private CounterPill counterPill;
public PaginatedContainerHeader(string text, CounterVisibilityState counterState)
public ProfileSubsectionHeader(string text, CounterVisibilityState counterState)
{
this.text = text;
this.counterState = counterState;