1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 20:32:56 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsRoomFooter.cs

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

115 lines
3.6 KiB
C#
Raw Normal View History

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;
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
{
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
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,
Size = new Vector2(200, 1),
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)
{
if (e.PropertyName == nameof(Room.Status) || e.PropertyName == nameof(Room.Host) || e.PropertyName == nameof(Room.StartDate))
updateState();
}
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
}
}