2019-01-24 08:43:03 +00: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.
|
2018-12-27 07:18:48 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-27 07:18:48 +00:00
|
|
|
using osu.Framework.Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics;
|
2020-12-25 04:38:11 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
|
|
|
using osu.Game.Online.Rooms.RoomStatuses;
|
2018-12-27 07:18:48 +00:00
|
|
|
|
2020-12-25 15:50:00 +00:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Components
|
2018-12-27 07:18:48 +00:00
|
|
|
{
|
2020-12-25 16:12:33 +00:00
|
|
|
public class RoomStatusInfo : OnlinePlayComposite
|
2018-12-27 07:18:48 +00:00
|
|
|
{
|
2019-02-05 10:00:01 +00:00
|
|
|
public RoomStatusInfo()
|
2018-12-27 07:18:48 +00:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2019-02-05 10:00:01 +00:00
|
|
|
}
|
2018-12-27 07:18:48 +00:00
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2018-12-27 07:18:48 +00:00
|
|
|
StatusPart statusPart;
|
|
|
|
EndDatePart endDatePart;
|
|
|
|
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
statusPart = new StatusPart
|
|
|
|
{
|
2019-02-12 04:04:46 +00:00
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14)
|
2018-12-27 07:18:48 +00:00
|
|
|
},
|
2019-02-12 04:04:46 +00:00
|
|
|
endDatePart = new EndDatePart { Font = OsuFont.GetFont(size: 14) }
|
2018-12-27 07:18:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-05 10:00:01 +00:00
|
|
|
statusPart.EndDate.BindTo(EndDate);
|
|
|
|
statusPart.Status.BindTo(Status);
|
|
|
|
statusPart.Availability.BindTo(Availability);
|
|
|
|
endDatePart.EndDate.BindTo(EndDate);
|
2018-12-27 07:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private class EndDatePart : DrawableDate
|
|
|
|
{
|
2020-12-21 07:18:39 +00:00
|
|
|
public readonly IBindable<DateTimeOffset?> EndDate = new Bindable<DateTimeOffset?>();
|
2018-12-27 07:18:48 +00:00
|
|
|
|
|
|
|
public EndDatePart()
|
|
|
|
: base(DateTimeOffset.UtcNow)
|
|
|
|
{
|
2020-12-21 07:18:39 +00:00
|
|
|
EndDate.BindValueChanged(date =>
|
|
|
|
{
|
|
|
|
// If null, set a very large future date to prevent unnecessary schedules.
|
|
|
|
Date = date.NewValue ?? DateTimeOffset.Now.AddYears(1);
|
|
|
|
}, true);
|
2018-12-27 07:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override string Format()
|
|
|
|
{
|
2020-12-21 07:18:39 +00:00
|
|
|
if (EndDate.Value == null)
|
|
|
|
return string.Empty;
|
|
|
|
|
2018-12-27 07:18:48 +00:00
|
|
|
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()}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class StatusPart : EndDatePart
|
|
|
|
{
|
|
|
|
public readonly IBindable<RoomStatus> Status = new Bindable<RoomStatus>();
|
|
|
|
public readonly IBindable<RoomAvailability> Availability = new Bindable<RoomAvailability>();
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
public StatusPart()
|
|
|
|
{
|
|
|
|
EndDate.BindValueChanged(_ => Format());
|
|
|
|
Status.BindValueChanged(_ => Format());
|
|
|
|
Availability.BindValueChanged(_ => Format());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Text = Format();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override string Format()
|
|
|
|
{
|
|
|
|
if (!IsLoaded)
|
|
|
|
return string.Empty;
|
|
|
|
|
|
|
|
RoomStatus status = Date < DateTimeOffset.Now ? new RoomStatusEnded() : Status.Value ?? new RoomStatusOpen();
|
|
|
|
|
|
|
|
this.FadeColour(status.GetAppropriateColour(colours), 100);
|
|
|
|
return $"{Availability.Value.GetDescription()}, {status.Message}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|