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;
|
2024-11-13 19:20:14 +08:00
|
|
|
|
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;
|
2024-11-13 19:20:14 +08:00
|
|
|
|
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
|
|
|
|
{
|
2024-11-13 19:20:14 +08:00
|
|
|
|
private readonly Room room;
|
|
|
|
|
|
|
|
|
|
public EndDateInfo(Room room)
|
2021-07-12 14:11:07 +08:00
|
|
|
|
{
|
2024-11-13 19:20:14 +08:00
|
|
|
|
this.room = room;
|
2021-07-12 14:11:07 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2024-11-13 19:20:14 +08:00
|
|
|
|
InternalChild = new EndDatePart(room)
|
2021-07-12 14:11:07 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
2024-11-13 19:20:14 +08:00
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 12)
|
2021-07-12 14:11:07 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private partial class EndDatePart : DrawableDate
|
|
|
|
|
{
|
2024-11-13 19:20:14 +08:00
|
|
|
|
private readonly Room room;
|
2021-07-12 14:11:07 +08:00
|
|
|
|
|
2024-11-13 19:20:14 +08:00
|
|
|
|
public EndDatePart(Room room)
|
2021-07-12 14:11:07 +08:00
|
|
|
|
: base(DateTimeOffset.UtcNow)
|
|
|
|
|
{
|
2024-11-13 19:20:14 +08:00
|
|
|
|
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()
|
|
|
|
|
{
|
2024-11-13 19:20:14 +08:00
|
|
|
|
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()}";
|
|
|
|
|
}
|
2024-11-13 19:20:14 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
room.PropertyChanged -= onRoomPropertyChanged;
|
|
|
|
|
}
|
2021-07-12 14:11:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|