1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-20 19:42:55 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Lounge/Components/EndDateInfo.cs

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

92 lines
2.6 KiB
C#
Raw Normal View History

2021-07-12 14:11:07 +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 System;
using System.ComponentModel;
2021-07-12 14:11:07 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
2024-11-15 12:20:09 +08:00
using osu.Framework.Graphics.Containers;
2021-07-12 14:11:07 +08:00
using osu.Game.Graphics;
using osu.Game.Online.Rooms;
2021-07-12 14:11:07 +08:00
2021-07-13 15:02:18 +08:00
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
2021-07-12 14:11:07 +08:00
{
2024-11-15 12:20:09 +08:00
public partial class EndDateInfo : CompositeDrawable
2021-07-12 14:11:07 +08:00
{
private readonly Room room;
public EndDateInfo(Room room)
2021-07-12 14:11:07 +08:00
{
this.room = room;
2021-07-12 14:11:07 +08:00
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new EndDatePart(room)
2021-07-12 14:11:07 +08:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 12)
2021-07-12 14:11:07 +08:00
};
}
private partial class EndDatePart : DrawableDate
{
private readonly Room room;
2021-07-12 14:11:07 +08:00
public EndDatePart(Room room)
2021-07-12 14:11:07 +08:00
: base(DateTimeOffset.UtcNow)
{
this.room = room;
}
protected override void LoadComplete()
{
base.LoadComplete();
room.PropertyChanged += onRoomPropertyChanged;
updateEndDate();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.EndDate))
updateEndDate();
}
private void updateEndDate()
{
// If null, set a very large future date to prevent unnecessary schedules.
Date = room.EndDate ?? DateTimeOffset.Now.AddYears(1);
2021-07-12 14:11:07 +08:00
}
protected override string Format()
{
if (room.EndDate == null)
2021-07-12 14:11:07 +08:00
return string.Empty;
var diffToNow = Date.Subtract(DateTimeOffset.Now);
if (diffToNow.TotalSeconds < -5)
return $"Closed {base.Format()}";
if (diffToNow.TotalSeconds < 0)
return "Closed";
if (diffToNow.TotalSeconds < 5)
return "Closing soon";
return $"Closing {base.Format()}";
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
}
2021-07-12 14:11:07 +08:00
}
}
}