1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 09:30:08 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/Components/OverlinedTotalPlayTime.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
2.1 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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
2021-07-17 21:18:45 +08:00
using osu.Game.Resources.Localisation.Web;
2019-04-26 12:49:44 +08:00
namespace osu.Game.Overlays.Profile.Header.Components
{
public partial class OverlinedTotalPlayTime : CompositeDrawable, IHasTooltip
{
public readonly Bindable<UserProfileData?> UserProfileData = new Bindable<UserProfileData?>();
public LocalisableString TooltipText { get; set; }
2022-12-30 20:17:59 +08:00
private OverlinedInfoContainer info = null!;
public OverlinedTotalPlayTime()
{
AutoSizeAxes = Axes.Both;
TooltipText = "0 hours";
}
[BackgroundDependencyLoader]
2020-01-30 04:57:43 +08:00
private void load(OverlayColourProvider colourProvider)
{
InternalChild = info = new OverlinedInfoContainer
{
2021-07-17 21:18:45 +08:00
Title = UsersStrings.ShowStatsPlayTime,
2020-01-30 04:57:43 +08:00
LineColour = colourProvider.Highlight1,
};
UserProfileData.BindValueChanged(updateTime, true);
}
private void updateTime(ValueChangedEvent<UserProfileData?> data)
{
int? playTime = data.NewValue?.User.Statistics?.PlayTime;
TooltipText = (playTime ?? 0) / 3600 + " hours";
info.Content = formatTime(playTime);
}
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;
}
}
}