2021-08-18 19:21:29 +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-22 16:55:28 +08:00
|
|
|
using System.ComponentModel;
|
|
|
|
using osu.Framework.Allocation;
|
2021-08-18 19:21:29 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2024-11-22 16:55:28 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Online.API;
|
2024-11-13 19:20:14 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2024-11-22 16:55:28 +08:00
|
|
|
using osu.Game.Online.Rooms.RoomStatuses;
|
2021-08-18 19:21:29 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Playlists
|
|
|
|
{
|
|
|
|
public partial class PlaylistsRoomFooter : CompositeDrawable
|
|
|
|
{
|
2024-11-13 19:20:14 +08:00
|
|
|
public Action? OnStart;
|
2024-11-22 16:55:28 +08:00
|
|
|
public Action? OnClose;
|
|
|
|
|
|
|
|
private readonly Room room;
|
|
|
|
private DangerousRoundedButton closeButton = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2021-08-18 19:21:29 +08:00
|
|
|
|
2024-11-13 19:20:14 +08:00
|
|
|
public PlaylistsRoomFooter(Room room)
|
2024-11-22 16:55:28 +08:00
|
|
|
{
|
|
|
|
this.room = room;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2021-08-18 19:21:29 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2024-11-22 16:55:28 +08:00
|
|
|
InternalChild = new FillFlowContainer
|
2021-08-18 19:21:29 +08:00
|
|
|
{
|
2024-11-22 16:55:28 +08:00
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(10),
|
|
|
|
Children = new Drawable[]
|
2021-08-18 19:21:29 +08:00
|
|
|
{
|
2024-11-22 16:55:28 +08:00
|
|
|
new PlaylistsReadyButton(room)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Size = new Vector2(600, 1),
|
|
|
|
Action = () => OnStart?.Invoke()
|
|
|
|
},
|
|
|
|
closeButton = new DangerousRoundedButton
|
|
|
|
{
|
|
|
|
Text = "Close",
|
|
|
|
Action = () => OnClose?.Invoke(),
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2024-11-28 21:06:12 +08:00
|
|
|
Size = new Vector2(120, 1),
|
2024-11-22 16:55:28 +08:00
|
|
|
Alpha = 0,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
}
|
2021-08-18 19:21:29 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-11-22 16:55:28 +08:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
room.PropertyChanged += onRoomChanged;
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hideCloseButton()
|
|
|
|
{
|
2024-11-28 14:42:37 +08:00
|
|
|
closeButton.ResizeWidthTo(0, 100, Easing.OutQuint)
|
2024-11-22 16:55:28 +08:00
|
|
|
.Then().FadeOut().Expire();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onRoomChanged(object? sender, PropertyChangedEventArgs e)
|
|
|
|
{
|
2024-11-28 21:04:39 +08:00
|
|
|
switch (e.PropertyName)
|
|
|
|
{
|
|
|
|
case nameof(Room.Status):
|
|
|
|
case nameof(Room.Host):
|
|
|
|
case nameof(Room.StartDate):
|
|
|
|
updateState();
|
|
|
|
break;
|
|
|
|
}
|
2024-11-22 16:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
TimeSpan? deletionGracePeriodRemaining = room.StartDate?.AddMinutes(5) - DateTimeOffset.Now;
|
|
|
|
|
|
|
|
if (room.Host?.Id == api.LocalUser.Value.Id)
|
|
|
|
{
|
|
|
|
if (deletionGracePeriodRemaining > TimeSpan.Zero && room.Status is not RoomStatusEnded)
|
|
|
|
{
|
|
|
|
closeButton.FadeIn();
|
|
|
|
using (BeginDelayedSequence(deletionGracePeriodRemaining.Value.TotalMilliseconds))
|
|
|
|
hideCloseButton();
|
|
|
|
}
|
|
|
|
else if (closeButton.Alpha > 0)
|
|
|
|
hideCloseButton();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
room.PropertyChanged -= onRoomChanged;
|
|
|
|
}
|
2021-08-18 19:21:29 +08:00
|
|
|
}
|
|
|
|
}
|