mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 18:27:26 +08:00
Merge pull request #3896 from peppy/backwards-drawable-date
Allow DrawableDate to be used to display future dates
This commit is contained in:
commit
29fd1719da
67
osu.Game.Tests/Visual/TestCaseDrawableDate.cs
Normal file
67
osu.Game.Tests/Visual/TestCaseDrawableDate.cs
Normal file
@ -0,0 +1,67 @@
|
||||
// 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 osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public class TestCaseDrawableDate : OsuTestCase
|
||||
{
|
||||
public TestCaseDrawableDate()
|
||||
{
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
Direction = FillDirection.Vertical,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new PokeyDrawableDate(DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(60))),
|
||||
new PokeyDrawableDate(DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(55))),
|
||||
new PokeyDrawableDate(DateTimeOffset.Now.Subtract(TimeSpan.FromSeconds(50))),
|
||||
new PokeyDrawableDate(DateTimeOffset.Now),
|
||||
new PokeyDrawableDate(DateTimeOffset.Now.Add(TimeSpan.FromSeconds(60))),
|
||||
new PokeyDrawableDate(DateTimeOffset.Now.Add(TimeSpan.FromSeconds(65))),
|
||||
new PokeyDrawableDate(DateTimeOffset.Now.Add(TimeSpan.FromSeconds(70))),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private class PokeyDrawableDate : CompositeDrawable
|
||||
{
|
||||
public PokeyDrawableDate(DateTimeOffset date)
|
||||
{
|
||||
const float box_size = 10;
|
||||
|
||||
DrawableDate drawableDate;
|
||||
Box flash;
|
||||
|
||||
AutoSizeAxes = Axes.Both;
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
flash = new Box
|
||||
{
|
||||
Colour = Color4.Yellow,
|
||||
Size = new Vector2(box_size),
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Alpha = 0
|
||||
},
|
||||
drawableDate = new DrawableDate(date)
|
||||
{
|
||||
X = box_size + 2,
|
||||
}
|
||||
};
|
||||
|
||||
drawableDate.Current.ValueChanged += v => flash.FadeOutFromOne(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
|
||||
@ -11,13 +12,27 @@ namespace osu.Game.Graphics
|
||||
{
|
||||
public class DrawableDate : OsuSpriteText, IHasTooltip
|
||||
{
|
||||
protected readonly DateTimeOffset Date;
|
||||
private DateTimeOffset date;
|
||||
|
||||
public DateTimeOffset Date
|
||||
{
|
||||
get => date;
|
||||
set
|
||||
{
|
||||
if (date == value)
|
||||
return;
|
||||
date = value.ToLocalTime();
|
||||
|
||||
if (LoadState >= LoadState.Ready)
|
||||
updateTime();
|
||||
}
|
||||
}
|
||||
|
||||
public DrawableDate(DateTimeOffset date)
|
||||
{
|
||||
Font = "Exo2.0-RegularItalic";
|
||||
|
||||
Date = date.ToLocalTime();
|
||||
Date = date;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -39,14 +54,14 @@ namespace osu.Game.Graphics
|
||||
var diffToNow = DateTimeOffset.Now.Subtract(Date);
|
||||
|
||||
double timeUntilNextUpdate = 1000;
|
||||
if (diffToNow.TotalSeconds > 60)
|
||||
if (Math.Abs(diffToNow.TotalSeconds) > 120)
|
||||
{
|
||||
timeUntilNextUpdate *= 60;
|
||||
if (diffToNow.TotalMinutes > 60)
|
||||
if (Math.Abs(diffToNow.TotalMinutes) > 120)
|
||||
{
|
||||
timeUntilNextUpdate *= 60;
|
||||
|
||||
if (diffToNow.TotalHours > 24)
|
||||
if (Math.Abs(diffToNow.TotalHours) > 48)
|
||||
timeUntilNextUpdate *= 24;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user