mirror of
https://github.com/ppy/osu.git
synced 2025-02-10 10:22:55 +08:00
Add drawable to display (and update) relative dates
This commit is contained in:
parent
ca249ab866
commit
3b56999118
64
osu.Game/Graphics/DrawableDate.cs
Normal file
64
osu.Game/Graphics/DrawableDate.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Humanizer;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Framework.Threading;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics
|
||||||
|
{
|
||||||
|
public class DrawableDate : OsuSpriteText, IHasTooltip
|
||||||
|
{
|
||||||
|
private readonly DateTimeOffset date;
|
||||||
|
private ScheduledDelegate updateTask;
|
||||||
|
|
||||||
|
public DrawableDate(DateTimeOffset date)
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
Font = "Exo2.0-RegularItalic";
|
||||||
|
|
||||||
|
this.date = date.ToLocalTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
updateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
Scheduler.Add(updateTimeWithReschedule);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTimeWithReschedule()
|
||||||
|
{
|
||||||
|
updateTime();
|
||||||
|
|
||||||
|
var diffToNow = DateTimeOffset.Now.Subtract(date);
|
||||||
|
|
||||||
|
double timeUntilNextUpdate = 1000;
|
||||||
|
if (diffToNow.TotalSeconds > 60)
|
||||||
|
{
|
||||||
|
timeUntilNextUpdate *= 60;
|
||||||
|
if (diffToNow.TotalMinutes > 60)
|
||||||
|
{
|
||||||
|
timeUntilNextUpdate *= 60;
|
||||||
|
|
||||||
|
if (diffToNow.TotalHours > 24)
|
||||||
|
timeUntilNextUpdate *= 24;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Scheduler.AddDelayed(updateTimeWithReschedule, timeUntilNextUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTime() => Text = date.Humanize();
|
||||||
|
public string TooltipText => date.ToString();
|
||||||
|
}
|
||||||
|
}
|
@ -130,11 +130,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
infoTextLeft = new OsuTextFlowContainer(t =>
|
infoTextLeft = new OsuTextFlowContainer(t => t.TextSize = 14)
|
||||||
{
|
|
||||||
t.TextSize = 14;
|
|
||||||
t.Alpha = 0.8f;
|
|
||||||
})
|
|
||||||
{
|
{
|
||||||
X = UserProfileOverlay.CONTENT_X_MARGIN,
|
X = UserProfileOverlay.CONTENT_X_MARGIN,
|
||||||
Y = cover_height + 20,
|
Y = cover_height + 20,
|
||||||
@ -318,11 +314,23 @@ namespace osu.Game.Overlays.Profile
|
|||||||
colourBar.Show();
|
colourBar.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void boldItalic(SpriteText t)
|
void boldItalic(SpriteText t) => t.Font = @"Exo2.0-BoldItalic";
|
||||||
|
void lightText(SpriteText t) => t.Alpha = 0.8f;
|
||||||
|
|
||||||
|
OsuSpriteText createScoreText(string text) => new OsuSpriteText
|
||||||
{
|
{
|
||||||
t.Font = @"Exo2.0-BoldItalic";
|
TextSize = 14,
|
||||||
t.Alpha = 1;
|
Text = text
|
||||||
}
|
};
|
||||||
|
|
||||||
|
OsuSpriteText createScoreNumberText(string text) => new OsuSpriteText
|
||||||
|
{
|
||||||
|
TextSize = 14,
|
||||||
|
Font = @"Exo2.0-Bold",
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
|
Text = text
|
||||||
|
};
|
||||||
|
|
||||||
if (user.Age != null)
|
if (user.Age != null)
|
||||||
{
|
{
|
||||||
@ -331,7 +339,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
|
|
||||||
if (user.Country != null)
|
if (user.Country != null)
|
||||||
{
|
{
|
||||||
infoTextLeft.AddText("from ");
|
infoTextLeft.AddText("from ", lightText);
|
||||||
infoTextLeft.AddText(user.Country.FullName, boldItalic);
|
infoTextLeft.AddText(user.Country.FullName, boldItalic);
|
||||||
countryFlag.Country = user.Country;
|
countryFlag.Country = user.Country;
|
||||||
}
|
}
|
||||||
@ -344,18 +352,18 @@ namespace osu.Game.Overlays.Profile
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
infoTextLeft.AddText("Joined ");
|
infoTextLeft.AddText("Joined ", lightText);
|
||||||
infoTextLeft.AddText(user.JoinDate.LocalDateTime.ToShortDateString(), boldItalic);
|
infoTextLeft.AddText(new DrawableDate(user.JoinDate), boldItalic);
|
||||||
}
|
}
|
||||||
|
|
||||||
infoTextLeft.NewLine();
|
infoTextLeft.NewLine();
|
||||||
infoTextLeft.AddText("Last seen ");
|
infoTextLeft.AddText("Last seen ", lightText);
|
||||||
infoTextLeft.AddText(user.LastVisit.LocalDateTime.ToShortDateString(), boldItalic);
|
infoTextLeft.AddText(new DrawableDate(user.LastVisit), boldItalic);
|
||||||
infoTextLeft.NewParagraph();
|
infoTextLeft.NewParagraph();
|
||||||
|
|
||||||
if (user.PlayStyle?.Length > 0)
|
if (user.PlayStyle?.Length > 0)
|
||||||
{
|
{
|
||||||
infoTextLeft.AddText("Plays with ");
|
infoTextLeft.AddText("Plays with ", lightText);
|
||||||
infoTextLeft.AddText(string.Join(", ", user.PlayStyle), boldItalic);
|
infoTextLeft.AddText(string.Join(", ", user.PlayStyle), boldItalic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,23 +419,6 @@ namespace osu.Game.Overlays.Profile
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// These could be local functions when C# 7 enabled
|
|
||||||
|
|
||||||
private OsuSpriteText createScoreText(string text) => new OsuSpriteText
|
|
||||||
{
|
|
||||||
TextSize = 14,
|
|
||||||
Text = text
|
|
||||||
};
|
|
||||||
|
|
||||||
private OsuSpriteText createScoreNumberText(string text) => new OsuSpriteText
|
|
||||||
{
|
|
||||||
TextSize = 14,
|
|
||||||
Font = @"Exo2.0-Bold",
|
|
||||||
Anchor = Anchor.TopRight,
|
|
||||||
Origin = Anchor.TopRight,
|
|
||||||
Text = text
|
|
||||||
};
|
|
||||||
|
|
||||||
private void tryAddInfoRightLine(FontAwesome icon, string str, string url = null)
|
private void tryAddInfoRightLine(FontAwesome icon, string str, string url = null)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(str)) return;
|
if (string.IsNullOrEmpty(str)) return;
|
||||||
@ -436,10 +427,12 @@ namespace osu.Game.Overlays.Profile
|
|||||||
if (url != null)
|
if (url != null)
|
||||||
{
|
{
|
||||||
infoTextRight.AddLink(" " + str, url);
|
infoTextRight.AddLink(" " + str, url);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
infoTextRight.AddText(" " + str);
|
infoTextRight.AddText(" " + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
infoTextRight.NewLine();
|
infoTextRight.NewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,12 +54,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
|
|||||||
RightFlowContainer.SetLayoutPosition(text, 1);
|
RightFlowContainer.SetLayoutPosition(text, 1);
|
||||||
|
|
||||||
LeftFlowContainer.Add(new BeatmapMetadataContainer(Score.Beatmap));
|
LeftFlowContainer.Add(new BeatmapMetadataContainer(Score.Beatmap));
|
||||||
LeftFlowContainer.Add(new OsuSpriteText
|
LeftFlowContainer.Add(new DrawableDate(Score.Date));
|
||||||
{
|
|
||||||
Text = Score.Date.LocalDateTime.ToShortDateString(),
|
|
||||||
TextSize = 11,
|
|
||||||
Colour = OsuColour.Gray(0xAA),
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (Mod mod in Score.Mods)
|
foreach (Mod mod in Score.Mods)
|
||||||
modsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.5f) });
|
modsContainer.Add(new ModIcon(mod) { Scale = new Vector2(0.5f) });
|
||||||
|
@ -6,7 +6,6 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Online.Chat;
|
using osu.Game.Online.Chat;
|
||||||
@ -40,14 +39,12 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
|
|||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
});
|
});
|
||||||
|
|
||||||
RightFlowContainer.Add(new OsuSpriteText
|
RightFlowContainer.Add(new DrawableDate(activity.CreatedAt)
|
||||||
{
|
{
|
||||||
Text = activity.CreatedAt.LocalDateTime.ToShortDateString(),
|
TextSize = 13,
|
||||||
|
Colour = OsuColour.Gray(0xAA),
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
Origin = Anchor.TopRight,
|
Origin = Anchor.TopRight,
|
||||||
Font = "Exo2.0-RegularItalic",
|
|
||||||
TextSize = 12,
|
|
||||||
Colour = OsuColour.Gray(0xAA),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var formatted = createMessage();
|
var formatted = createMessage();
|
||||||
|
@ -287,6 +287,7 @@
|
|||||||
<Compile Include="Database\MutableDatabaseBackedStore.cs" />
|
<Compile Include="Database\MutableDatabaseBackedStore.cs" />
|
||||||
<Compile Include="Database\SingletonContextFactory.cs" />
|
<Compile Include="Database\SingletonContextFactory.cs" />
|
||||||
<Compile Include="Graphics\Containers\LinkFlowContainer.cs" />
|
<Compile Include="Graphics\Containers\LinkFlowContainer.cs" />
|
||||||
|
<Compile Include="Graphics\DrawableDate.cs" />
|
||||||
<Compile Include="Graphics\Textures\LargeTextureStore.cs" />
|
<Compile Include="Graphics\Textures\LargeTextureStore.cs" />
|
||||||
<Compile Include="IO\Archives\ArchiveReader.cs" />
|
<Compile Include="IO\Archives\ArchiveReader.cs" />
|
||||||
<Compile Include="IO\Archives\LegacyFilesystemReader.cs" />
|
<Compile Include="IO\Archives\LegacyFilesystemReader.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user