2019-04-25 19:30:16 +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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2021-06-26 01:10:04 +08:00
|
|
|
using osu.Framework.Localisation;
|
2021-07-17 21:18:45 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2019-04-25 19:30:16 +08:00
|
|
|
|
2019-04-26 12:49:44 +08:00
|
|
|
namespace osu.Game.Overlays.Profile.Header.Components
|
2019-04-25 19:30:16 +08:00
|
|
|
{
|
2023-01-01 00:51:58 +08:00
|
|
|
public partial class TotalPlayTime : CompositeDrawable, IHasTooltip
|
2019-04-25 19:30:16 +08:00
|
|
|
{
|
2023-01-11 02:24:54 +08:00
|
|
|
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();
|
2019-04-25 19:30:16 +08:00
|
|
|
|
2021-06-26 01:10:04 +08:00
|
|
|
public LocalisableString TooltipText { get; set; }
|
2019-04-25 19:30:16 +08:00
|
|
|
|
2023-01-01 00:51:58 +08:00
|
|
|
private ProfileValueDisplay info = null!;
|
2019-04-25 19:30:16 +08:00
|
|
|
|
2023-01-01 00:51:58 +08:00
|
|
|
public TotalPlayTime()
|
2019-04-25 19:30:16 +08:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
TooltipText = "0 hours";
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-01-01 00:51:58 +08:00
|
|
|
private void load()
|
2019-04-25 19:30:16 +08:00
|
|
|
{
|
2023-01-01 00:51:58 +08:00
|
|
|
InternalChild = info = new ProfileValueDisplay(minimumWidth: 140)
|
2019-04-25 19:30:16 +08:00
|
|
|
{
|
2021-07-17 21:18:45 +08:00
|
|
|
Title = UsersStrings.ShowStatsPlayTime,
|
2019-04-25 19:30:16 +08:00
|
|
|
};
|
|
|
|
|
2023-01-11 02:24:54 +08:00
|
|
|
User.BindValueChanged(updateTime, true);
|
2019-04-25 19:30:16 +08:00
|
|
|
}
|
|
|
|
|
2023-01-11 02:24:54 +08:00
|
|
|
private void updateTime(ValueChangedEvent<UserProfileData?> user)
|
2019-04-25 19:30:16 +08:00
|
|
|
{
|
2023-01-11 02:24:54 +08:00
|
|
|
int? playTime = user.NewValue?.User.Statistics?.PlayTime;
|
2022-12-30 21:56:19 +08:00
|
|
|
TooltipText = (playTime ?? 0) / 3600 + " hours";
|
|
|
|
info.Content = formatTime(playTime);
|
2019-04-25 19:30:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private string formatTime(int? secondsNull)
|
|
|
|
{
|
|
|
|
if (secondsNull == null) return "0h 0m";
|
|
|
|
|
|
|
|
int seconds = secondsNull.Value;
|
|
|
|
string time = "";
|
|
|
|
|
|
|
|
int days = seconds / 86400;
|
|
|
|
seconds -= days * 86400;
|
|
|
|
if (days > 0)
|
|
|
|
time += days + "d ";
|
|
|
|
|
|
|
|
int hours = seconds / 3600;
|
|
|
|
seconds -= hours * 3600;
|
|
|
|
time += hours + "h ";
|
|
|
|
|
|
|
|
int minutes = seconds / 60;
|
|
|
|
time += minutes + "m";
|
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|