1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 08:07:40 +08:00
osu-lazer/osu.Game/Overlays/Profile/Sections/PaginatedContainer.cs

113 lines
3.6 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Rulesets;
using osu.Game.Users;
namespace osu.Game.Overlays.Profile.Sections
{
public class PaginatedContainer : FillFlowContainer
{
protected readonly FillFlowContainer ItemsContainer;
protected readonly OsuHoverContainer ShowMoreButton;
protected readonly LoadingAnimation ShowMoreLoading;
protected readonly OsuSpriteText MissingText;
protected int VisiblePages;
protected int ItemsPerPage;
protected readonly Bindable<User> User = new Bindable<User>();
protected IAPIProvider Api;
protected APIRequest RetrievalRequest;
2018-04-13 17:19:50 +08:00
protected RulesetStore Rulesets;
public PaginatedContainer(Bindable<User> user, string header, string missing)
{
User.BindTo(user);
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Direction = FillDirection.Vertical;
Children = new Drawable[]
{
new OsuSpriteText
{
Text = header,
2019-02-20 15:52:36 +08:00
Font = OsuFont.GetFont(size: 15, weight: FontWeight.Regular, italics: true),
2018-04-13 17:19:50 +08:00
Margin = new MarginPadding { Top = 10, Bottom = 10 },
},
ItemsContainer = new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding { Bottom = 10 }
},
ShowMoreButton = new OsuHoverContainer
{
Alpha = 0,
Action = ShowMore,
AutoSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Child = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 14),
2018-04-13 17:19:50 +08:00
Text = "show more",
2019-02-28 12:31:40 +08:00
Padding = new MarginPadding { Vertical = 10, Horizontal = 15 },
2018-04-13 17:19:50 +08:00
}
},
ShowMoreLoading = new LoadingAnimation
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Size = new Vector2(14),
},
MissingText = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 14),
2018-04-13 17:19:50 +08:00
Text = missing,
Alpha = 0,
},
};
}
[BackgroundDependencyLoader]
private void load(IAPIProvider api, RulesetStore rulesets)
2018-04-13 17:19:50 +08:00
{
Api = api;
Rulesets = rulesets;
User.ValueChanged += onUserChanged;
User.TriggerChange();
}
2019-02-21 17:56:34 +08:00
private void onUserChanged(ValueChangedEvent<User> e)
2018-04-13 17:19:50 +08:00
{
VisiblePages = 0;
ItemsContainer.Clear();
ShowMoreButton.Hide();
2019-02-21 17:56:34 +08:00
if (e.NewValue != null)
2018-04-13 17:19:50 +08:00
ShowMore();
}
protected virtual void ShowMore()
{
ShowMoreLoading.Show();
ShowMoreButton.Hide();
}
}
}