2020-11-14 23:48:47 +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.
|
|
|
|
|
|
2020-11-15 00:17:01 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-11-14 23:48:47 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
using static osu.Game.Users.User;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Sections.Historical
|
|
|
|
|
{
|
|
|
|
|
public abstract class ChartProfileSubsection : ProfileSubsection
|
|
|
|
|
{
|
|
|
|
|
private ProfileLineChart chart;
|
|
|
|
|
|
|
|
|
|
protected ChartProfileSubsection(Bindable<User> user, string headerText)
|
|
|
|
|
: base(user, headerText)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Drawable CreateContent() => new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 10,
|
|
|
|
|
Left = 20,
|
|
|
|
|
Right = 40
|
|
|
|
|
},
|
|
|
|
|
Child = chart = new ProfileLineChart()
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-22 07:13:35 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
User.BindValueChanged(onUserChanged, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onUserChanged(ValueChangedEvent<User> e)
|
2020-11-14 23:48:47 +08:00
|
|
|
|
{
|
|
|
|
|
var values = GetValues(e.NewValue);
|
|
|
|
|
|
|
|
|
|
if (values?.Length > 1)
|
|
|
|
|
{
|
2020-11-15 00:17:01 +08:00
|
|
|
|
// Fill dates with 0 count
|
|
|
|
|
|
|
|
|
|
var newValues = new List<UserHistoryCount> { values[0] };
|
|
|
|
|
var newLast = values[0];
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < values.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
while (hasMissingDates(newLast, values[i]))
|
|
|
|
|
{
|
|
|
|
|
newValues.Add(newLast = new UserHistoryCount
|
|
|
|
|
{
|
|
|
|
|
Count = 0,
|
|
|
|
|
Date = newLast.Date.AddMonths(1)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newValues.Add(newLast = values[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool hasMissingDates(UserHistoryCount prev, UserHistoryCount current)
|
|
|
|
|
{
|
|
|
|
|
var possibleCurrent = prev.Date.AddMonths(1);
|
|
|
|
|
return possibleCurrent != current.Date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chart.Values = newValues.ToArray();
|
2020-11-14 23:48:47 +08:00
|
|
|
|
Show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract UserHistoryCount[] GetValues(User user);
|
|
|
|
|
}
|
|
|
|
|
}
|