2022-03-23 09:37:53 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-03-23 09:37:53 +08:00
|
|
|
using System;
|
2022-09-01 17:53:35 +08:00
|
|
|
using System.Linq;
|
2022-03-23 09:37:53 +08:00
|
|
|
using Humanizer;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2022-03-25 17:40:32 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2022-03-23 09:37:53 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|
|
|
{
|
2022-03-24 13:28:38 +08:00
|
|
|
public class MultiplayerCountdownButton : IconButton, IHasPopover
|
2022-03-23 09:37:53 +08:00
|
|
|
{
|
|
|
|
private static readonly TimeSpan[] available_delays =
|
|
|
|
{
|
|
|
|
TimeSpan.FromSeconds(10),
|
|
|
|
TimeSpan.FromSeconds(30),
|
|
|
|
TimeSpan.FromMinutes(1),
|
|
|
|
TimeSpan.FromMinutes(2)
|
|
|
|
};
|
|
|
|
|
|
|
|
public new Action<TimeSpan> Action;
|
2022-03-26 13:29:51 +08:00
|
|
|
|
2022-03-25 17:40:32 +08:00
|
|
|
public Action CancelAction;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private MultiplayerClient multiplayerClient { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
2022-03-23 09:37:53 +08:00
|
|
|
|
|
|
|
private readonly Drawable background;
|
|
|
|
|
2022-03-24 13:28:38 +08:00
|
|
|
public MultiplayerCountdownButton()
|
2022-03-23 09:37:53 +08:00
|
|
|
{
|
2022-03-25 17:25:32 +08:00
|
|
|
Icon = FontAwesome.Regular.Clock;
|
2022-03-23 09:37:53 +08:00
|
|
|
|
|
|
|
Add(background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Depth = float.MaxValue
|
|
|
|
});
|
|
|
|
|
|
|
|
base.Action = this.ShowPopover;
|
2022-03-25 17:25:32 +08:00
|
|
|
|
|
|
|
TooltipText = "Countdown settings";
|
2022-03-23 09:37:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
background.Colour = colours.Green;
|
|
|
|
}
|
|
|
|
|
2022-03-26 13:29:51 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
multiplayerClient.RoomUpdated += onRoomUpdated;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
multiplayerClient.RoomUpdated -= onRoomUpdated;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onRoomUpdated() => Scheduler.AddOnce(() =>
|
|
|
|
{
|
2022-09-01 17:53:35 +08:00
|
|
|
bool countdownActive = multiplayerClient.Room?.ActiveCountdowns.Any(c => c is MatchStartCountdown) == true;
|
2022-03-26 13:29:51 +08:00
|
|
|
|
|
|
|
if (countdownActive)
|
|
|
|
{
|
|
|
|
background
|
|
|
|
.FadeColour(colours.YellowLight, 100, Easing.In)
|
|
|
|
.Then()
|
|
|
|
.FadeColour(colours.YellowDark, 900, Easing.OutQuint)
|
|
|
|
.Loop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
background
|
|
|
|
.FadeColour(colours.Green, 200, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-23 09:37:53 +08:00
|
|
|
public Popover GetPopover()
|
|
|
|
{
|
|
|
|
var flow = new FillFlowContainer
|
|
|
|
{
|
|
|
|
Width = 200,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(2),
|
|
|
|
};
|
|
|
|
|
|
|
|
foreach (var duration in available_delays)
|
|
|
|
{
|
2022-11-24 15:33:01 +08:00
|
|
|
flow.Add(new RoundedButton
|
2022-03-23 09:37:53 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Text = $"Start match in {duration.Humanize()}",
|
2022-03-26 13:29:51 +08:00
|
|
|
BackgroundColour = colours.Green,
|
2022-03-23 09:37:53 +08:00
|
|
|
Action = () =>
|
|
|
|
{
|
|
|
|
Action(duration);
|
|
|
|
this.HidePopover();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-01 17:53:35 +08:00
|
|
|
if (multiplayerClient.Room?.ActiveCountdowns.Any(c => c is MatchStartCountdown) == true && multiplayerClient.IsHost)
|
2022-03-25 17:40:32 +08:00
|
|
|
{
|
2022-11-24 15:33:01 +08:00
|
|
|
flow.Add(new RoundedButton
|
2022-03-25 17:40:32 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2022-03-26 13:29:51 +08:00
|
|
|
Text = "Stop countdown",
|
2022-03-25 17:40:32 +08:00
|
|
|
BackgroundColour = colours.Red,
|
|
|
|
Action = () =>
|
|
|
|
{
|
|
|
|
CancelAction();
|
|
|
|
this.HidePopover();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-23 09:37:53 +08:00
|
|
|
return new OsuPopover { Child = flow };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|