1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 11:47:24 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Multiplayer/Match/MultiplayerCountdownButton.cs

108 lines
3.1 KiB
C#
Raw Normal View History

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.
using System;
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
{
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-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;
public MultiplayerCountdownButton()
2022-03-23 09:37:53 +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;
TooltipText = "Countdown settings";
2022-03-23 09:37:53 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
background.Colour = colours.Green;
}
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)
{
flow.Add(new OsuButton
2022-03-23 09:37:53 +08:00
{
RelativeSizeAxes = Axes.X,
Text = $"Start match in {duration.Humanize()}",
BackgroundColour = background.Colour,
Action = () =>
{
Action(duration);
this.HidePopover();
}
});
}
2022-03-25 17:40:32 +08:00
if (multiplayerClient.Room?.Countdown != null && multiplayerClient.IsHost)
{
flow.Add(new OsuButton
{
RelativeSizeAxes = Axes.X,
Text = "Cancel",
BackgroundColour = colours.Red,
Action = () =>
{
CancelAction();
this.HidePopover();
}
});
}
2022-03-23 09:37:53 +08:00
return new OsuPopover { Child = flow };
}
}
}