mirror of https://github.com/ppy/osu
Split MultiplayerReadyButton
This commit is contained in:
parent
483fb84b56
commit
9138aaf780
|
@ -95,10 +95,10 @@ public void TestCreatedWithCorrectMode()
|
|||
protected void RunGameplay()
|
||||
{
|
||||
AddUntilStep("wait for idle", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Idle);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
|
||||
AddUntilStep("wait for ready", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Ready);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
|
||||
AddUntilStep("wait for player", () => multiplayerComponents.CurrentScreen is Player player && player.IsLoaded);
|
||||
AddStep("exit player", () => multiplayerComponents.MultiplayerScreen.MakeCurrent());
|
||||
|
|
|
@ -102,10 +102,10 @@ public void TestCorrectRulesetSelectedAfterNewItemAdded()
|
|||
AddUntilStep("selected beatmap is initial beatmap", () => Beatmap.Value.BeatmapInfo.OnlineID == InitialBeatmap.OnlineID);
|
||||
|
||||
AddUntilStep("wait for idle", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Idle);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
|
||||
AddUntilStep("wait for ready", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Ready);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
|
||||
AddUntilStep("wait for player", () => CurrentScreen is Player player && player.IsLoaded);
|
||||
AddAssert("ruleset is correct", () => ((Player)CurrentScreen).Ruleset.Value.Equals(new OsuRuleset().RulesetInfo));
|
||||
|
@ -119,10 +119,10 @@ public void TestCorrectModsSelectedAfterNewItemAdded()
|
|||
AddUntilStep("selected beatmap is initial beatmap", () => Beatmap.Value.BeatmapInfo.OnlineID == InitialBeatmap.OnlineID);
|
||||
|
||||
AddUntilStep("wait for idle", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Idle);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
|
||||
AddUntilStep("wait for ready", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Ready);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
|
||||
AddUntilStep("wait for player", () => CurrentScreen is Player player && player.IsLoaded);
|
||||
AddAssert("mods are correct", () => !((Player)CurrentScreen).Mods.Value.Any());
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiplayerReadyButton : MultiplayerTestScene
|
||||
public class TestSceneMatchStartControl : MultiplayerTestScene
|
||||
{
|
||||
private MultiplayerReadyButton button;
|
||||
private MatchStartControl control;
|
||||
private BeatmapSetInfo importedSet;
|
||||
|
||||
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
||||
|
@ -62,7 +62,7 @@ private void load(GameHost host, AudioManager audio)
|
|||
Child = new PopoverContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = button = new MultiplayerReadyButton
|
||||
Child = control = new MatchStartControl
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
|
@ -74,17 +74,17 @@ private void load(GameHost host, AudioManager audio)
|
|||
[Test]
|
||||
public void TestStartWithCountdown()
|
||||
{
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<MultiplayerReadyButton.CountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.CountdownButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<CountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<CountdownButton>();
|
||||
AddStep("click the first countdown button", () =>
|
||||
{
|
||||
var popoverButton = this.ChildrenOfType<MultiplayerReadyButton.CountdownButton.PopoverButton>().First();
|
||||
var popoverButton = this.ChildrenOfType<CountdownButton.PopoverButton>().First();
|
||||
InputManager.MoveMouseTo(popoverButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddAssert("countdown button not visible", () => !this.ChildrenOfType<MultiplayerReadyButton.CountdownButton>().Single().IsPresent);
|
||||
AddAssert("countdown button not visible", () => !this.ChildrenOfType<CountdownButton>().Single().IsPresent);
|
||||
AddStep("finish countdown", () => MultiplayerClient.FinishCountdown());
|
||||
AddUntilStep("match started", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.WaitingForLoad);
|
||||
}
|
||||
|
@ -92,17 +92,17 @@ public void TestStartWithCountdown()
|
|||
[Test]
|
||||
public void TestCancelCountdown()
|
||||
{
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<MultiplayerReadyButton.CountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.CountdownButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<CountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<CountdownButton>();
|
||||
AddStep("click the first countdown button", () =>
|
||||
{
|
||||
var popoverButton = this.ChildrenOfType<MultiplayerReadyButton.CountdownButton.PopoverButton>().First();
|
||||
var popoverButton = this.ChildrenOfType<CountdownButton.PopoverButton>().First();
|
||||
InputManager.MoveMouseTo(popoverButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
|
||||
AddStep("finish countdown", () => MultiplayerClient.FinishCountdown());
|
||||
AddUntilStep("match not started", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Ready);
|
||||
|
@ -119,10 +119,10 @@ public void TestReadyAndUnReadyDuringCountdown()
|
|||
|
||||
AddStep("start with countdown", () => MultiplayerClient.SendMatchRequest(new StartMatchCountdownRequest { Delay = TimeSpan.FromMinutes(2) }).WaitSafely());
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("user is idle", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Idle);
|
||||
}
|
||||
|
||||
|
@ -132,25 +132,25 @@ public void TestCountdownButtonEnablementAndVisibilityWhileSpectating()
|
|||
AddStep("set spectating", () => MultiplayerClient.ChangeUserState(API.LocalUser.Value.OnlineID, MultiplayerUserState.Spectating));
|
||||
AddUntilStep("local user is spectating", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Spectating);
|
||||
|
||||
AddAssert("countdown button is visible", () => this.ChildrenOfType<MultiplayerReadyButton.CountdownButton>().Single().IsPresent);
|
||||
AddAssert("countdown button disabled", () => !this.ChildrenOfType<MultiplayerReadyButton.CountdownButton>().Single().Enabled.Value);
|
||||
AddAssert("countdown button is visible", () => this.ChildrenOfType<CountdownButton>().Single().IsPresent);
|
||||
AddAssert("countdown button disabled", () => !this.ChildrenOfType<CountdownButton>().Single().Enabled.Value);
|
||||
|
||||
AddStep("add second user", () => MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" }));
|
||||
AddAssert("countdown button disabled", () => !this.ChildrenOfType<MultiplayerReadyButton.CountdownButton>().Single().Enabled.Value);
|
||||
AddAssert("countdown button disabled", () => !this.ChildrenOfType<CountdownButton>().Single().Enabled.Value);
|
||||
|
||||
AddStep("set second user ready", () => MultiplayerClient.ChangeUserState(2, MultiplayerUserState.Ready));
|
||||
AddAssert("countdown button enabled", () => this.ChildrenOfType<MultiplayerReadyButton.CountdownButton>().Single().Enabled.Value);
|
||||
AddAssert("countdown button enabled", () => this.ChildrenOfType<CountdownButton>().Single().Enabled.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSpectatingDuringCountdownWithNoReadyUsersCancelsCountdown()
|
||||
{
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<MultiplayerReadyButton.CountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.CountdownButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<CountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<CountdownButton>();
|
||||
AddStep("click the first countdown button", () =>
|
||||
{
|
||||
var popoverButton = this.ChildrenOfType<MultiplayerReadyButton.CountdownButton.PopoverButton>().First();
|
||||
var popoverButton = this.ChildrenOfType<CountdownButton.PopoverButton>().First();
|
||||
InputManager.MoveMouseTo(popoverButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
@ -168,12 +168,12 @@ public void TestReadyButtonEnabledWhileSpectatingDuringCountdown()
|
|||
AddStep("add second user", () => MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" }));
|
||||
AddStep("set second user ready", () => MultiplayerClient.ChangeUserState(2, MultiplayerUserState.Ready));
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<MultiplayerReadyButton.CountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.CountdownButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<CountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<CountdownButton>();
|
||||
AddStep("click the first countdown button", () =>
|
||||
{
|
||||
var popoverButton = this.ChildrenOfType<MultiplayerReadyButton.CountdownButton.PopoverButton>().First();
|
||||
var popoverButton = this.ChildrenOfType<CountdownButton.PopoverButton>().First();
|
||||
InputManager.MoveMouseTo(popoverButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
@ -181,7 +181,7 @@ public void TestReadyButtonEnabledWhileSpectatingDuringCountdown()
|
|||
AddStep("set spectating", () => MultiplayerClient.ChangeUserState(API.LocalUser.Value.OnlineID, MultiplayerUserState.Spectating));
|
||||
AddUntilStep("local user is spectating", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Spectating);
|
||||
|
||||
AddAssert("ready button enabled", () => this.ChildrenOfType<MultiplayerReadyButton.ReadyButton>().Single().Enabled.Value);
|
||||
AddAssert("ready button enabled", () => this.ChildrenOfType<ReadyButton>().Single().Enabled.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -199,7 +199,7 @@ public void TestBecomeHostDuringCountdownAndReady()
|
|||
AddStep("transfer host to local user", () => MultiplayerClient.TransferHost(API.LocalUser.Value.OnlineID));
|
||||
AddUntilStep("local user is host", () => MultiplayerClient.Room?.Host?.Equals(MultiplayerClient.LocalUser) == true);
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("local user became ready", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Ready);
|
||||
AddAssert("countdown still active", () => MultiplayerClient.Room?.Countdown != null);
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ public void TestDeletedBeatmapDisableReady()
|
|||
|
||||
AddUntilStep("ensure ready button enabled", () =>
|
||||
{
|
||||
readyButton = button.ChildrenOfType<OsuButton>().Single();
|
||||
readyButton = control.ChildrenOfType<OsuButton>().Single();
|
||||
return readyButton.Enabled.Value;
|
||||
});
|
||||
|
||||
|
@ -230,10 +230,10 @@ public void TestToggleStateWhenNotHost()
|
|||
MultiplayerClient.TransferHost(2);
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("user is idle", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Idle);
|
||||
}
|
||||
|
||||
|
@ -249,7 +249,7 @@ public void TestToggleStateWhenHost(bool allReady)
|
|||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
verifyGameplayStartFlow();
|
||||
|
@ -264,7 +264,7 @@ public void TestBecomeHostWhileReady()
|
|||
MultiplayerClient.TransferHost(2);
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddStep("make user host", () => MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[0].UserID ?? 0));
|
||||
|
||||
verifyGameplayStartFlow();
|
||||
|
@ -279,14 +279,14 @@ public void TestLoseHostWhileReady()
|
|||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
AddStep("transfer host", () => MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[1].UserID ?? 0));
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("user is idle (match not started)", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Idle);
|
||||
AddAssert("ready button enabled", () => button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||
AddAssert("ready button enabled", () => control.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
|
@ -304,7 +304,7 @@ public void TestManyUsersChangingState(bool isHost)
|
|||
if (!isHost)
|
||||
AddStep("transfer host", () => MultiplayerClient.TransferHost(2));
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
|
||||
AddRepeatStep("change user ready state", () =>
|
||||
{
|
||||
|
@ -322,7 +322,7 @@ public void TestManyUsersChangingState(bool isHost)
|
|||
private void verifyGameplayStartFlow()
|
||||
{
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
AddUntilStep("user waiting for load", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.WaitingForLoad);
|
||||
|
||||
AddStep("finish gameplay", () =>
|
||||
|
@ -331,7 +331,7 @@ private void verifyGameplayStartFlow()
|
|||
MultiplayerClient.ChangeUserState(MultiplayerClient.Room?.Users[0].UserID ?? 0, MultiplayerUserState.FinishedPlay);
|
||||
});
|
||||
|
||||
AddUntilStep("ready button enabled", () => button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||
AddUntilStep("ready button enabled", () => control.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,6 +41,7 @@
|
|||
using osu.Game.Screens.Spectate;
|
||||
using osu.Game.Tests.Resources;
|
||||
using osuTK.Input;
|
||||
using ReadyButton = osu.Game.Screens.OnlinePlay.Components.ReadyButton;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
|
|
|
@ -145,7 +145,7 @@ public void TestStartMatchWhileSpectating()
|
|||
|
||||
AddUntilStep("wait for spectating user state", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Spectating);
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton.ReadyButton>();
|
||||
ClickButtonWhenEnabled<ReadyButton>();
|
||||
|
||||
AddUntilStep("match started", () => MultiplayerClient.Room?.State == MultiplayerRoomState.WaitingForLoad);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||
public class TestSceneMultiplayerSpectateButton : MultiplayerTestScene
|
||||
{
|
||||
private MultiplayerSpectateButton spectateButton;
|
||||
private MultiplayerReadyButton readyButton;
|
||||
private MatchStartControl startControl;
|
||||
|
||||
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
||||
|
||||
|
@ -72,7 +72,7 @@ private void load(GameHost host, AudioManager audio)
|
|||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200, 50),
|
||||
},
|
||||
readyButton = new MultiplayerReadyButton
|
||||
startControl = new MatchStartControl
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
|
@ -146,6 +146,6 @@ private void assertSpectateButtonEnablement(bool shouldBeEnabled)
|
|||
=> AddUntilStep($"spectate button {(shouldBeEnabled ? "is" : "is not")} enabled", () => spectateButton.ChildrenOfType<OsuButton>().Single().Enabled.Value == shouldBeEnabled);
|
||||
|
||||
private void assertReadyButtonEnablement(bool shouldBeEnabled)
|
||||
=> AddUntilStep($"ready button {(shouldBeEnabled ? "is" : "is not")} enabled", () => readyButton.ChildrenOfType<OsuButton>().Single().Enabled.Value == shouldBeEnabled);
|
||||
=> AddUntilStep($"ready button {(shouldBeEnabled ? "is" : "is not")} enabled", () => startControl.ChildrenOfType<ReadyButton>().Single().Enabled.Value == shouldBeEnabled);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
// 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;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
public class CountdownButton : IconButton, IHasPopover
|
||||
{
|
||||
private static readonly TimeSpan[] available_delays =
|
||||
{
|
||||
TimeSpan.FromSeconds(10),
|
||||
TimeSpan.FromSeconds(30),
|
||||
TimeSpan.FromMinutes(1),
|
||||
TimeSpan.FromMinutes(2)
|
||||
};
|
||||
|
||||
public new Action<TimeSpan> Action;
|
||||
|
||||
private readonly Drawable background;
|
||||
|
||||
public CountdownButton()
|
||||
{
|
||||
Icon = FontAwesome.Solid.CaretDown;
|
||||
IconScale = new Vector2(0.6f);
|
||||
|
||||
Add(background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Depth = float.MaxValue
|
||||
});
|
||||
|
||||
base.Action = this.ShowPopover;
|
||||
}
|
||||
|
||||
[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 PopoverButton
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Text = $"Start match in {duration.Humanize()}",
|
||||
BackgroundColour = background.Colour,
|
||||
Action = () =>
|
||||
{
|
||||
Action(duration);
|
||||
this.HidePopover();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return new OsuPopover { Child = flow };
|
||||
}
|
||||
|
||||
public class PopoverButton : OsuButton
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,32 +4,21 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Humanizer;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
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.Framework.Localisation;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Backgrounds;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
public class MultiplayerReadyButton : MultiplayerRoomComposite
|
||||
public class MatchStartControl : MultiplayerRoomComposite
|
||||
{
|
||||
[Resolved]
|
||||
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||
|
@ -47,7 +36,7 @@ public class MultiplayerReadyButton : MultiplayerRoomComposite
|
|||
private ScheduledDelegate readySampleDelegate;
|
||||
private IBindable<bool> operationInProgress;
|
||||
|
||||
public MultiplayerReadyButton()
|
||||
public MatchStartControl()
|
||||
{
|
||||
InternalChild = new GridContainer
|
||||
{
|
||||
|
@ -231,220 +220,5 @@ private void updateState()
|
|||
countReady = newCountReady;
|
||||
});
|
||||
}
|
||||
|
||||
public class ReadyButton : Components.ReadyButton
|
||||
{
|
||||
public new Triangles Triangles => base.Triangles;
|
||||
|
||||
[Resolved]
|
||||
private MultiplayerClient multiplayerClient { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
[CanBeNull]
|
||||
private MultiplayerRoom room => multiplayerClient.Room;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
multiplayerClient.RoomUpdated += () => Scheduler.AddOnce(onRoomUpdated);
|
||||
onRoomUpdated();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (room?.Countdown != null)
|
||||
{
|
||||
// Update the countdown timer.
|
||||
onRoomUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private void onRoomUpdated()
|
||||
{
|
||||
updateButtonText();
|
||||
updateButtonColour();
|
||||
}
|
||||
|
||||
private void updateButtonText()
|
||||
{
|
||||
if (room == null)
|
||||
{
|
||||
Text = "Ready";
|
||||
return;
|
||||
}
|
||||
|
||||
var localUser = multiplayerClient.LocalUser;
|
||||
|
||||
int countReady = room.Users.Count(u => u.State == MultiplayerUserState.Ready);
|
||||
int countTotal = room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
|
||||
string countText = $"({countReady} / {countTotal} ready)";
|
||||
|
||||
if (room.Countdown != null)
|
||||
{
|
||||
string countdownText = $"Starting in {room.Countdown.EndTime - DateTimeOffset.Now:mm\\:ss}";
|
||||
|
||||
switch (localUser?.State)
|
||||
{
|
||||
default:
|
||||
Text = $"Ready ({countdownText.ToLowerInvariant()})";
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
Text = $"{countdownText} {countText}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (localUser?.State)
|
||||
{
|
||||
default:
|
||||
Text = "Ready";
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
Text = room.Host?.Equals(localUser) == true
|
||||
? $"Start match {countText}"
|
||||
: $"Waiting for host... {countText}";
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateButtonColour()
|
||||
{
|
||||
if (room == null)
|
||||
{
|
||||
setGreen();
|
||||
return;
|
||||
}
|
||||
|
||||
var localUser = multiplayerClient.LocalUser;
|
||||
|
||||
switch (localUser?.State)
|
||||
{
|
||||
default:
|
||||
setGreen();
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
if (room?.Host?.Equals(localUser) == true && room.Countdown == null)
|
||||
setGreen();
|
||||
else
|
||||
setYellow();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
void setYellow()
|
||||
{
|
||||
BackgroundColour = colours.YellowDark;
|
||||
Triangles.ColourDark = colours.YellowDark;
|
||||
Triangles.ColourLight = colours.Yellow;
|
||||
}
|
||||
|
||||
void setGreen()
|
||||
{
|
||||
BackgroundColour = colours.Green;
|
||||
Triangles.ColourDark = colours.Green;
|
||||
Triangles.ColourLight = colours.GreenLight;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (multiplayerClient != null)
|
||||
multiplayerClient.RoomUpdated -= onRoomUpdated;
|
||||
}
|
||||
|
||||
public override LocalisableString TooltipText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (room?.Countdown != null && multiplayerClient.IsHost && multiplayerClient.LocalUser?.State == MultiplayerUserState.Ready)
|
||||
return "Cancel countdown";
|
||||
|
||||
return base.TooltipText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CountdownButton : IconButton, IHasPopover
|
||||
{
|
||||
private static readonly TimeSpan[] available_delays =
|
||||
{
|
||||
TimeSpan.FromSeconds(10),
|
||||
TimeSpan.FromSeconds(30),
|
||||
TimeSpan.FromMinutes(1),
|
||||
TimeSpan.FromMinutes(2)
|
||||
};
|
||||
|
||||
public new Action<TimeSpan> Action;
|
||||
|
||||
private readonly Drawable background;
|
||||
|
||||
public CountdownButton()
|
||||
{
|
||||
Icon = FontAwesome.Solid.CaretDown;
|
||||
IconScale = new Vector2(0.6f);
|
||||
|
||||
Add(background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Depth = float.MaxValue
|
||||
});
|
||||
|
||||
base.Action = this.ShowPopover;
|
||||
}
|
||||
|
||||
[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 PopoverButton
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Text = $"Start match in {duration.Humanize()}",
|
||||
BackgroundColour = background.Colour,
|
||||
Action = () =>
|
||||
{
|
||||
Action(duration);
|
||||
this.HidePopover();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return new OsuPopover { Child = flow };
|
||||
}
|
||||
|
||||
public class PopoverButton : OsuButton
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ public MultiplayerMatchFooter()
|
|||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
null,
|
||||
new MultiplayerReadyButton
|
||||
new MatchStartControl
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
// 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 System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Backgrounds;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
public class ReadyButton : Components.ReadyButton
|
||||
{
|
||||
public new Triangles Triangles => base.Triangles;
|
||||
|
||||
[Resolved]
|
||||
private MultiplayerClient multiplayerClient { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
[CanBeNull]
|
||||
private MultiplayerRoom room => multiplayerClient.Room;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
multiplayerClient.RoomUpdated += () => Scheduler.AddOnce(onRoomUpdated);
|
||||
onRoomUpdated();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (room?.Countdown != null)
|
||||
{
|
||||
// Update the countdown timer.
|
||||
onRoomUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private void onRoomUpdated()
|
||||
{
|
||||
updateButtonText();
|
||||
updateButtonColour();
|
||||
}
|
||||
|
||||
private void updateButtonText()
|
||||
{
|
||||
if (room == null)
|
||||
{
|
||||
Text = "Ready";
|
||||
return;
|
||||
}
|
||||
|
||||
var localUser = multiplayerClient.LocalUser;
|
||||
|
||||
int countReady = room.Users.Count(u => u.State == MultiplayerUserState.Ready);
|
||||
int countTotal = room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
|
||||
string countText = $"({countReady} / {countTotal} ready)";
|
||||
|
||||
if (room.Countdown != null)
|
||||
{
|
||||
string countdownText = $"Starting in {room.Countdown.EndTime - DateTimeOffset.Now:mm\\:ss}";
|
||||
|
||||
switch (localUser?.State)
|
||||
{
|
||||
default:
|
||||
Text = $"Ready ({countdownText.ToLowerInvariant()})";
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
Text = $"{countdownText} {countText}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (localUser?.State)
|
||||
{
|
||||
default:
|
||||
Text = "Ready";
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
Text = room.Host?.Equals(localUser) == true
|
||||
? $"Start match {countText}"
|
||||
: $"Waiting for host... {countText}";
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateButtonColour()
|
||||
{
|
||||
if (room == null)
|
||||
{
|
||||
setGreen();
|
||||
return;
|
||||
}
|
||||
|
||||
var localUser = multiplayerClient.LocalUser;
|
||||
|
||||
switch (localUser?.State)
|
||||
{
|
||||
default:
|
||||
setGreen();
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
if (room?.Host?.Equals(localUser) == true && room.Countdown == null)
|
||||
setGreen();
|
||||
else
|
||||
setYellow();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
void setYellow()
|
||||
{
|
||||
BackgroundColour = colours.YellowDark;
|
||||
Triangles.ColourDark = colours.YellowDark;
|
||||
Triangles.ColourLight = colours.Yellow;
|
||||
}
|
||||
|
||||
void setGreen()
|
||||
{
|
||||
BackgroundColour = colours.Green;
|
||||
Triangles.ColourDark = colours.Green;
|
||||
Triangles.ColourLight = colours.GreenLight;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (multiplayerClient != null)
|
||||
multiplayerClient.RoomUpdated -= onRoomUpdated;
|
||||
}
|
||||
|
||||
public override LocalisableString TooltipText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (room?.Countdown != null && multiplayerClient.IsHost && multiplayerClient.LocalUser?.State == MultiplayerUserState.Ready)
|
||||
return "Cancel countdown";
|
||||
|
||||
return base.TooltipText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue