2019-01-24 16:43:03 +08:00
|
|
|
|
// 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;
|
2019-02-12 12:04:46 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Rulesets;
|
2019-05-28 22:04:05 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Users;
|
2019-05-31 03:48:27 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Sections
|
|
|
|
|
{
|
2019-05-29 00:39:31 +08:00
|
|
|
|
public abstract class PaginatedContainer : FillFlowContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
protected readonly FillFlowContainer ItemsContainer;
|
2019-05-28 22:04:05 +08:00
|
|
|
|
protected readonly ShowMoreButton MoreButton;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
protected readonly OsuSpriteText MissingText;
|
|
|
|
|
|
|
|
|
|
protected int VisiblePages;
|
|
|
|
|
protected int ItemsPerPage;
|
|
|
|
|
|
|
|
|
|
protected readonly Bindable<User> User = new Bindable<User>();
|
|
|
|
|
|
2019-03-13 11:56:47 +08:00
|
|
|
|
protected IAPIProvider Api;
|
2018-09-05 09:23:23 +08:00
|
|
|
|
protected APIRequest RetrievalRequest;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
protected RulesetStore Rulesets;
|
|
|
|
|
|
2019-05-29 00:53:00 +08:00
|
|
|
|
protected PaginatedContainer(Bindable<User> user, string header, string missing)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
User.BindTo(user);
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Direction = FillDirection.Vertical;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = header,
|
2019-05-28 22:04:05 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Bold),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Margin = new MarginPadding { Top = 10, Bottom = 10 },
|
|
|
|
|
},
|
|
|
|
|
ItemsContainer = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2019-05-28 22:04:05 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 2),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2019-05-28 22:04:05 +08:00
|
|
|
|
MoreButton = new ShowMoreButton
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
2019-05-28 22:04:05 +08:00
|
|
|
|
Margin = new MarginPadding { Top = 10 },
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Action = ShowMore,
|
|
|
|
|
},
|
|
|
|
|
MissingText = new OsuSpriteText
|
|
|
|
|
{
|
2019-05-28 22:04:05 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 15),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Text = missing,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-03-13 11:56:47 +08:00
|
|
|
|
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();
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
if (e.NewValue != null)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
ShowMore();
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-29 00:39:31 +08:00
|
|
|
|
protected abstract void ShowMore();
|
2019-05-28 22:04:05 +08:00
|
|
|
|
|
2019-05-31 03:48:27 +08:00
|
|
|
|
protected class ShowMoreButton : OsuHoverContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-05-28 22:04:05 +08:00
|
|
|
|
private readonly Box background;
|
|
|
|
|
private readonly LoadingAnimation loading;
|
|
|
|
|
private readonly FillFlowContainer content;
|
|
|
|
|
|
2019-05-31 03:48:27 +08:00
|
|
|
|
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
|
|
|
|
|
|
2019-05-28 22:04:05 +08:00
|
|
|
|
private bool isLoading;
|
2019-05-28 22:21:34 +08:00
|
|
|
|
|
2019-05-28 22:04:05 +08:00
|
|
|
|
public bool IsLoading
|
|
|
|
|
{
|
2019-05-29 00:39:31 +08:00
|
|
|
|
get => isLoading;
|
2019-05-28 22:04:05 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2019-05-29 00:39:31 +08:00
|
|
|
|
if (isLoading == value)
|
|
|
|
|
return;
|
2019-05-29 00:53:00 +08:00
|
|
|
|
|
2019-05-28 22:04:05 +08:00
|
|
|
|
isLoading = value;
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
2019-05-31 03:48:27 +08:00
|
|
|
|
loading.FadeIn(FADE_DURATION, Easing.OutQuint);
|
|
|
|
|
content.FadeOut(FADE_DURATION, Easing.OutQuint);
|
2019-05-28 22:04:05 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-05-31 03:48:27 +08:00
|
|
|
|
loading.FadeOut(FADE_DURATION, Easing.OutQuint);
|
|
|
|
|
content.FadeIn(FADE_DURATION, Easing.OutQuint);
|
2019-05-28 22:04:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ShowMoreButton()
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre;
|
|
|
|
|
Origin = Anchor.TopCentre;
|
2019-05-31 03:48:27 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2019-05-28 22:04:05 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-05-31 03:48:27 +08:00
|
|
|
|
new CircularContainer
|
2019-05-28 22:04:05 +08:00
|
|
|
|
{
|
2019-05-31 03:48:27 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
Size = new Vector2(140, 30),
|
2019-05-28 22:04:05 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-05-31 03:48:27 +08:00
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
content = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(7),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new ChevronIcon(),
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
|
|
|
|
|
Text = "show more".ToUpper(),
|
|
|
|
|
},
|
|
|
|
|
new ChevronIcon(),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
loading = new LoadingAnimation
|
2019-05-28 22:04:05 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2019-05-31 03:48:27 +08:00
|
|
|
|
Size = new Vector2(12)
|
2019-05-28 22:04:05 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2019-05-31 03:48:27 +08:00
|
|
|
|
}
|
2019-05-28 22:04:05 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colors)
|
|
|
|
|
{
|
2019-05-31 03:48:27 +08:00
|
|
|
|
IdleColour = colors.GreySeafoam;
|
|
|
|
|
HoverColour = colors.GreySeafoamLight;
|
2019-05-28 22:04:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
2019-05-29 00:39:31 +08:00
|
|
|
|
IsLoading = true;
|
2019-05-28 22:04:05 +08:00
|
|
|
|
return base.OnClick(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class ChevronIcon : SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
private const int bottom_margin = 2;
|
|
|
|
|
private const int icon_size = 8;
|
|
|
|
|
|
|
|
|
|
public ChevronIcon()
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
Margin = new MarginPadding { Bottom = bottom_margin };
|
|
|
|
|
Size = new Vector2(icon_size);
|
|
|
|
|
Icon = FontAwesome.Solid.ChevronDown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colors)
|
|
|
|
|
{
|
|
|
|
|
Colour = colors.Yellow;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|