mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 16:02:58 +08:00
Merge branch 'master' into skin-nullable
This commit is contained in:
commit
2d8d177807
@ -51,8 +51,8 @@
|
||||
<Reference Include="Java.Interop" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.304.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2022.314.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.325.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2022.325.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Transitive Dependencies">
|
||||
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->
|
||||
|
@ -8,6 +8,7 @@ using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Replays;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Catch;
|
||||
@ -64,6 +65,62 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(3, true)]
|
||||
[TestCase(6, false)]
|
||||
[TestCase(LegacyBeatmapDecoder.LATEST_VERSION, false)]
|
||||
public void TestLegacyBeatmapReplayOffsetsDecode(int beatmapVersion, bool offsetApplied)
|
||||
{
|
||||
const double first_frame_time = 48;
|
||||
const double second_frame_time = 65;
|
||||
|
||||
var decoder = new TestLegacyScoreDecoder(beatmapVersion);
|
||||
|
||||
using (var resourceStream = TestResources.OpenResource("Replays/mania-replay.osr"))
|
||||
{
|
||||
var score = decoder.Parse(resourceStream);
|
||||
|
||||
Assert.That(score.Replay.Frames[0].Time, Is.EqualTo(first_frame_time + (offsetApplied ? LegacyBeatmapDecoder.EARLY_VERSION_TIMING_OFFSET : 0)));
|
||||
Assert.That(score.Replay.Frames[1].Time, Is.EqualTo(second_frame_time + (offsetApplied ? LegacyBeatmapDecoder.EARLY_VERSION_TIMING_OFFSET : 0)));
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(3)]
|
||||
[TestCase(6)]
|
||||
[TestCase(LegacyBeatmapDecoder.LATEST_VERSION)]
|
||||
public void TestLegacyBeatmapReplayOffsetsEncodeDecode(int beatmapVersion)
|
||||
{
|
||||
const double first_frame_time = 2000;
|
||||
const double second_frame_time = 3000;
|
||||
|
||||
var ruleset = new OsuRuleset().RulesetInfo;
|
||||
var scoreInfo = TestResources.CreateTestScoreInfo(ruleset);
|
||||
var beatmap = new TestBeatmap(ruleset)
|
||||
{
|
||||
BeatmapInfo =
|
||||
{
|
||||
BeatmapVersion = beatmapVersion
|
||||
}
|
||||
};
|
||||
|
||||
var score = new Score
|
||||
{
|
||||
ScoreInfo = scoreInfo,
|
||||
Replay = new Replay
|
||||
{
|
||||
Frames = new List<ReplayFrame>
|
||||
{
|
||||
new OsuReplayFrame(first_frame_time, OsuPlayfield.BASE_SIZE / 2, OsuAction.LeftButton),
|
||||
new OsuReplayFrame(second_frame_time, OsuPlayfield.BASE_SIZE / 2, OsuAction.LeftButton)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var decodedAfterEncode = encodeThenDecode(beatmapVersion, score, beatmap);
|
||||
|
||||
Assert.That(decodedAfterEncode.Replay.Frames[0].Time, Is.EqualTo(first_frame_time));
|
||||
Assert.That(decodedAfterEncode.Replay.Frames[1].Time, Is.EqualTo(second_frame_time));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCultureInvariance()
|
||||
{
|
||||
@ -86,15 +143,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
// rather than the classic ASCII U+002D HYPHEN-MINUS.
|
||||
CultureInfo.CurrentCulture = new CultureInfo("se");
|
||||
|
||||
var encodeStream = new MemoryStream();
|
||||
|
||||
var encoder = new LegacyScoreEncoder(score, beatmap);
|
||||
encoder.Encode(encodeStream);
|
||||
|
||||
var decodeStream = new MemoryStream(encodeStream.GetBuffer());
|
||||
|
||||
var decoder = new TestLegacyScoreDecoder();
|
||||
var decodedAfterEncode = decoder.Parse(decodeStream);
|
||||
var decodedAfterEncode = encodeThenDecode(LegacyBeatmapDecoder.LATEST_VERSION, score, beatmap);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -110,6 +159,20 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
});
|
||||
}
|
||||
|
||||
private static Score encodeThenDecode(int beatmapVersion, Score score, TestBeatmap beatmap)
|
||||
{
|
||||
var encodeStream = new MemoryStream();
|
||||
|
||||
var encoder = new LegacyScoreEncoder(score, beatmap);
|
||||
encoder.Encode(encodeStream);
|
||||
|
||||
var decodeStream = new MemoryStream(encodeStream.GetBuffer());
|
||||
|
||||
var decoder = new TestLegacyScoreDecoder(beatmapVersion);
|
||||
var decodedAfterEncode = decoder.Parse(decodeStream);
|
||||
return decodedAfterEncode;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
@ -118,6 +181,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
|
||||
private class TestLegacyScoreDecoder : LegacyScoreDecoder
|
||||
{
|
||||
private readonly int beatmapVersion;
|
||||
|
||||
private static readonly Dictionary<int, Ruleset> rulesets = new Ruleset[]
|
||||
{
|
||||
new OsuRuleset(),
|
||||
@ -126,6 +191,11 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
new ManiaRuleset()
|
||||
}.ToDictionary(ruleset => ((ILegacyRuleset)ruleset).LegacyID);
|
||||
|
||||
public TestLegacyScoreDecoder(int beatmapVersion = LegacyBeatmapDecoder.LATEST_VERSION)
|
||||
{
|
||||
this.beatmapVersion = beatmapVersion;
|
||||
}
|
||||
|
||||
protected override Ruleset GetRuleset(int rulesetId) => rulesets[rulesetId];
|
||||
|
||||
protected override WorkingBeatmap GetBeatmap(string md5Hash) => new TestWorkingBeatmap(new Beatmap
|
||||
@ -134,7 +204,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
{
|
||||
MD5Hash = md5Hash,
|
||||
Ruleset = new OsuRuleset().RulesetInfo,
|
||||
Difficulty = new BeatmapDifficulty()
|
||||
Difficulty = new BeatmapDifficulty(),
|
||||
BeatmapVersion = beatmapVersion,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -147,7 +147,10 @@ namespace osu.Game.Tests.Database
|
||||
Live<BeatmapSetInfo>? imported;
|
||||
|
||||
using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream()))
|
||||
{
|
||||
imported = await importer.Import(reader);
|
||||
EnsureLoaded(realm.Realm);
|
||||
}
|
||||
|
||||
Assert.AreEqual(1, realm.Realm.All<BeatmapSetInfo>().Count());
|
||||
|
||||
@ -510,6 +513,8 @@ namespace osu.Game.Tests.Database
|
||||
new ImportTask(zipStream, string.Empty)
|
||||
);
|
||||
|
||||
realm.Run(r => r.Refresh());
|
||||
|
||||
checkBeatmapSetCount(realm.Realm, 0);
|
||||
checkBeatmapCount(realm.Realm, 0);
|
||||
|
||||
@ -565,6 +570,8 @@ namespace osu.Game.Tests.Database
|
||||
{
|
||||
}
|
||||
|
||||
EnsureLoaded(realm.Realm);
|
||||
|
||||
checkBeatmapSetCount(realm.Realm, 1);
|
||||
checkBeatmapCount(realm.Realm, 12);
|
||||
|
||||
@ -726,6 +733,8 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
var imported = importer.Import(toImport);
|
||||
|
||||
realm.Run(r => r.Refresh());
|
||||
|
||||
Assert.NotNull(imported);
|
||||
Debug.Assert(imported != null);
|
||||
|
||||
@ -891,6 +900,8 @@ namespace osu.Game.Tests.Database
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
await importer.Import(temp);
|
||||
|
||||
EnsureLoaded(realm.Realm);
|
||||
|
||||
// Update via the beatmap, not the beatmap info, to ensure correct linking
|
||||
BeatmapSetInfo setToUpdate = realm.Realm.All<BeatmapSetInfo>().First();
|
||||
|
||||
|
338
osu.Game.Tests/Visual/Multiplayer/TestSceneMatchStartControl.cs
Normal file
338
osu.Game.Tests/Visual/Multiplayer/TestSceneMatchStartControl.cs
Normal file
@ -0,0 +1,338 @@
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
||||
using osu.Game.Tests.Resources;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMatchStartControl : MultiplayerTestScene
|
||||
{
|
||||
private MatchStartControl control;
|
||||
private BeatmapSetInfo importedSet;
|
||||
|
||||
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
||||
|
||||
private BeatmapManager beatmaps;
|
||||
private RulesetStore rulesets;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
|
||||
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default));
|
||||
Dependencies.Cache(Realm);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
AvailabilityTracker.SelectedItem.BindTo(selectedItem);
|
||||
|
||||
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
|
||||
importedSet = beatmaps.GetAllUsableBeatmapSets().First();
|
||||
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
|
||||
|
||||
selectedItem.Value = new PlaylistItem(Beatmap.Value.BeatmapInfo)
|
||||
{
|
||||
RulesetID = Beatmap.Value.BeatmapInfo.Ruleset.OnlineID
|
||||
};
|
||||
|
||||
Child = new PopoverContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = control = new MatchStartControl
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200, 50),
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestStartWithCountdown()
|
||||
{
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<MultiplayerCountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<MultiplayerCountdownButton>();
|
||||
AddStep("click the first countdown button", () =>
|
||||
{
|
||||
var popoverButton = this.ChildrenOfType<Popover>().Single().ChildrenOfType<OsuButton>().First();
|
||||
InputManager.MoveMouseTo(popoverButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddAssert("countdown button not visible", () => !this.ChildrenOfType<MultiplayerCountdownButton>().Single().IsPresent);
|
||||
AddStep("finish countdown", () => MultiplayerClient.SkipToEndOfCountdown());
|
||||
AddUntilStep("match started", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.WaitingForLoad);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCancelCountdown()
|
||||
{
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<MultiplayerCountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<MultiplayerCountdownButton>();
|
||||
AddStep("click the first countdown button", () =>
|
||||
{
|
||||
var popoverButton = this.ChildrenOfType<Popover>().Single().ChildrenOfType<OsuButton>().First();
|
||||
InputManager.MoveMouseTo(popoverButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
|
||||
AddStep("finish countdown", () => MultiplayerClient.SkipToEndOfCountdown());
|
||||
AddUntilStep("match not started", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Ready);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReadyAndUnReadyDuringCountdown()
|
||||
{
|
||||
AddStep("add second user as host", () =>
|
||||
{
|
||||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
MultiplayerClient.TransferHost(2);
|
||||
});
|
||||
|
||||
AddStep("start with countdown", () => MultiplayerClient.SendMatchRequest(new StartMatchCountdownRequest { Duration = TimeSpan.FromMinutes(2) }).WaitSafely());
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is idle", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Idle);
|
||||
}
|
||||
|
||||
[Test]
|
||||
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<MultiplayerCountdownButton>().Single().IsPresent);
|
||||
AddAssert("countdown button disabled", () => !this.ChildrenOfType<MultiplayerCountdownButton>().Single().Enabled.Value);
|
||||
|
||||
AddStep("add second user", () => MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" }));
|
||||
AddAssert("countdown button disabled", () => !this.ChildrenOfType<MultiplayerCountdownButton>().Single().Enabled.Value);
|
||||
|
||||
AddStep("set second user ready", () => MultiplayerClient.ChangeUserState(2, MultiplayerUserState.Ready));
|
||||
AddAssert("countdown button enabled", () => this.ChildrenOfType<MultiplayerCountdownButton>().Single().Enabled.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSpectatingDuringCountdownWithNoReadyUsersCancelsCountdown()
|
||||
{
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<MultiplayerCountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<MultiplayerCountdownButton>();
|
||||
AddStep("click the first countdown button", () =>
|
||||
{
|
||||
var popoverButton = this.ChildrenOfType<Popover>().Single().ChildrenOfType<OsuButton>().First();
|
||||
InputManager.MoveMouseTo(popoverButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
AddStep("set spectating", () => MultiplayerClient.ChangeUserState(API.LocalUser.Value.OnlineID, MultiplayerUserState.Spectating));
|
||||
AddUntilStep("local user is spectating", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Spectating);
|
||||
|
||||
AddStep("finish countdown", () => MultiplayerClient.SkipToEndOfCountdown());
|
||||
AddUntilStep("match not started", () => MultiplayerClient.Room?.State == MultiplayerRoomState.Open);
|
||||
}
|
||||
|
||||
[Test]
|
||||
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>();
|
||||
AddUntilStep("countdown button shown", () => this.ChildrenOfType<MultiplayerCountdownButton>().SingleOrDefault()?.IsPresent == true);
|
||||
ClickButtonWhenEnabled<MultiplayerCountdownButton>();
|
||||
AddStep("click the first countdown button", () =>
|
||||
{
|
||||
var popoverButton = this.ChildrenOfType<Popover>().Single().ChildrenOfType<OsuButton>().First();
|
||||
InputManager.MoveMouseTo(popoverButton);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
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>().Single().Enabled.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBecomeHostDuringCountdownAndReady()
|
||||
{
|
||||
AddStep("add second user as host", () =>
|
||||
{
|
||||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
MultiplayerClient.TransferHost(2);
|
||||
});
|
||||
|
||||
AddStep("start countdown", () => MultiplayerClient.SendMatchRequest(new StartMatchCountdownRequest { Duration = TimeSpan.FromMinutes(1) }).WaitSafely());
|
||||
AddUntilStep("countdown started", () => MultiplayerClient.Room?.Countdown != null);
|
||||
|
||||
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>();
|
||||
AddUntilStep("local user became ready", () => MultiplayerClient.LocalUser?.State == MultiplayerUserState.Ready);
|
||||
AddAssert("countdown still active", () => MultiplayerClient.Room?.Countdown != null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeletedBeatmapDisableReady()
|
||||
{
|
||||
OsuButton readyButton = null;
|
||||
|
||||
AddUntilStep("ensure ready button enabled", () =>
|
||||
{
|
||||
readyButton = control.ChildrenOfType<OsuButton>().Single();
|
||||
return readyButton.Enabled.Value;
|
||||
});
|
||||
|
||||
AddStep("delete beatmap", () => beatmaps.Delete(importedSet));
|
||||
AddUntilStep("ready button disabled", () => !readyButton.Enabled.Value);
|
||||
AddStep("undelete beatmap", () => beatmaps.Undelete(importedSet));
|
||||
AddUntilStep("ready button enabled back", () => readyButton.Enabled.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestToggleStateWhenNotHost()
|
||||
{
|
||||
AddStep("add second user as host", () =>
|
||||
{
|
||||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
MultiplayerClient.TransferHost(2);
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is idle", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Idle);
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void TestToggleStateWhenHost(bool allReady)
|
||||
{
|
||||
AddStep("setup", () =>
|
||||
{
|
||||
MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[0].UserID ?? 0);
|
||||
|
||||
if (!allReady)
|
||||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
verifyGameplayStartFlow();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBecomeHostWhileReady()
|
||||
{
|
||||
AddStep("add host", () =>
|
||||
{
|
||||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
MultiplayerClient.TransferHost(2);
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddStep("make user host", () => MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[0].UserID ?? 0));
|
||||
|
||||
verifyGameplayStartFlow();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoseHostWhileReady()
|
||||
{
|
||||
AddStep("setup", () =>
|
||||
{
|
||||
MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[0].UserID ?? 0);
|
||||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
AddStep("transfer host", () => MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[1].UserID ?? 0));
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is idle (match not started)", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Idle);
|
||||
AddUntilStep("ready button enabled", () => control.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void TestManyUsersChangingState(bool isHost)
|
||||
{
|
||||
const int users = 10;
|
||||
AddStep("setup", () =>
|
||||
{
|
||||
MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[0].UserID ?? 0);
|
||||
for (int i = 0; i < users; i++)
|
||||
MultiplayerClient.AddUser(new APIUser { Id = i, Username = "Another user" });
|
||||
});
|
||||
|
||||
if (!isHost)
|
||||
AddStep("transfer host", () => MultiplayerClient.TransferHost(2));
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
|
||||
AddRepeatStep("change user ready state", () =>
|
||||
{
|
||||
MultiplayerClient.ChangeUserState(RNG.Next(0, users), RNG.NextBool() ? MultiplayerUserState.Ready : MultiplayerUserState.Idle);
|
||||
}, 20);
|
||||
|
||||
AddRepeatStep("ready all users", () =>
|
||||
{
|
||||
var nextUnready = MultiplayerClient.Room?.Users.FirstOrDefault(c => c.State == MultiplayerUserState.Idle);
|
||||
if (nextUnready != null)
|
||||
MultiplayerClient.ChangeUserState(nextUnready.UserID, MultiplayerUserState.Ready);
|
||||
}, users);
|
||||
}
|
||||
|
||||
private void verifyGameplayStartFlow()
|
||||
{
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user waiting for load", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.WaitingForLoad);
|
||||
|
||||
AddStep("finish gameplay", () =>
|
||||
{
|
||||
MultiplayerClient.ChangeUserState(MultiplayerClient.Room?.Users[0].UserID ?? 0, MultiplayerUserState.Loaded);
|
||||
MultiplayerClient.ChangeUserState(MultiplayerClient.Room?.Users[0].UserID ?? 0, MultiplayerUserState.FinishedPlay);
|
||||
});
|
||||
|
||||
AddUntilStep("ready button enabled", () => control.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -41,6 +41,7 @@ using osu.Game.Screens.Ranking;
|
||||
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
|
||||
{
|
||||
@ -424,7 +425,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
AddUntilStep("Beatmap doesn't match current item", () => Beatmap.Value.BeatmapInfo.OnlineID != multiplayerClient.Room?.Playlist.First().BeatmapID);
|
||||
|
||||
AddStep("start match externally", () => multiplayerClient.StartMatch());
|
||||
AddStep("start match externally", () => multiplayerClient.StartMatch().WaitSafely());
|
||||
|
||||
AddUntilStep("play started", () => multiplayerComponents.CurrentScreen is Player);
|
||||
|
||||
@ -462,7 +463,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
AddUntilStep("Ruleset doesn't match current item", () => Ruleset.Value.OnlineID != multiplayerClient.Room?.Playlist.First().RulesetID);
|
||||
|
||||
AddStep("start match externally", () => multiplayerClient.StartMatch());
|
||||
AddStep("start match externally", () => multiplayerClient.StartMatch().WaitSafely());
|
||||
|
||||
AddUntilStep("play started", () => multiplayerComponents.CurrentScreen is Player);
|
||||
|
||||
@ -500,7 +501,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
AddAssert("Mods don't match current item", () => !SelectedMods.Value.Select(m => m.Acronym).SequenceEqual(multiplayerClient.Room.AsNonNull().Playlist.First().RequiredMods.Select(m => m.Acronym)));
|
||||
|
||||
AddStep("start match externally", () => multiplayerClient.StartMatch());
|
||||
AddStep("start match externally", () => multiplayerClient.StartMatch().WaitSafely());
|
||||
|
||||
AddUntilStep("play started", () => multiplayerComponents.CurrentScreen is Player);
|
||||
|
||||
@ -535,7 +536,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
AddUntilStep("wait for spectating user state", () => multiplayerClient.LocalUser?.State == MultiplayerUserState.Spectating);
|
||||
|
||||
AddStep("start match externally", () => multiplayerClient.StartMatch());
|
||||
AddStep("start match externally", () => multiplayerClient.StartMatch().WaitSafely());
|
||||
|
||||
AddAssert("play not started", () => multiplayerComponents.IsCurrentScreen());
|
||||
}
|
||||
@ -568,7 +569,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
AddUntilStep("wait for spectating user state", () => multiplayerClient.LocalUser?.State == MultiplayerUserState.Spectating);
|
||||
|
||||
AddStep("start match externally", () => multiplayerClient.StartMatch());
|
||||
AddStep("start match externally", () => multiplayerClient.StartMatch().WaitSafely());
|
||||
|
||||
AddStep("restore beatmap", () =>
|
||||
{
|
||||
@ -883,7 +884,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddStep("start match by other user", () =>
|
||||
{
|
||||
multiplayerClient.ChangeUserState(1234, MultiplayerUserState.Ready);
|
||||
multiplayerClient.StartMatch();
|
||||
multiplayerClient.StartMatch().WaitSafely();
|
||||
});
|
||||
|
||||
AddUntilStep("wait for loading", () => multiplayerClient.Room?.State == MultiplayerRoomState.WaitingForLoad);
|
||||
|
@ -1,199 +0,0 @@
|
||||
// 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.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
||||
using osu.Game.Tests.Resources;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiplayerReadyButton : MultiplayerTestScene
|
||||
{
|
||||
private MultiplayerReadyButton button;
|
||||
private BeatmapSetInfo importedSet;
|
||||
|
||||
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
||||
|
||||
private BeatmapManager beatmaps;
|
||||
private RulesetStore rulesets;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
|
||||
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default));
|
||||
Dependencies.Cache(Realm);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
AvailabilityTracker.SelectedItem.BindTo(selectedItem);
|
||||
|
||||
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
|
||||
importedSet = beatmaps.GetAllUsableBeatmapSets().First();
|
||||
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
|
||||
|
||||
selectedItem.Value = new PlaylistItem(Beatmap.Value.BeatmapInfo)
|
||||
{
|
||||
RulesetID = Beatmap.Value.BeatmapInfo.Ruleset.OnlineID
|
||||
};
|
||||
|
||||
if (button != null)
|
||||
Remove(button);
|
||||
|
||||
Add(button = new MultiplayerReadyButton
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200, 50),
|
||||
});
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestDeletedBeatmapDisableReady()
|
||||
{
|
||||
OsuButton readyButton = null;
|
||||
|
||||
AddUntilStep("ensure ready button enabled", () =>
|
||||
{
|
||||
readyButton = button.ChildrenOfType<OsuButton>().Single();
|
||||
return readyButton.Enabled.Value;
|
||||
});
|
||||
|
||||
AddStep("delete beatmap", () => beatmaps.Delete(importedSet));
|
||||
AddUntilStep("ready button disabled", () => !readyButton.Enabled.Value);
|
||||
AddStep("undelete beatmap", () => beatmaps.Undelete(importedSet));
|
||||
AddUntilStep("ready button enabled back", () => readyButton.Enabled.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestToggleStateWhenNotHost()
|
||||
{
|
||||
AddStep("add second user as host", () =>
|
||||
{
|
||||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
MultiplayerClient.TransferHost(2);
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is idle", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Idle);
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void TestToggleStateWhenHost(bool allReady)
|
||||
{
|
||||
AddStep("setup", () =>
|
||||
{
|
||||
MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[0].UserID ?? 0);
|
||||
|
||||
if (!allReady)
|
||||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
verifyGameplayStartFlow();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBecomeHostWhileReady()
|
||||
{
|
||||
AddStep("add host", () =>
|
||||
{
|
||||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
MultiplayerClient.TransferHost(2);
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddStep("make user host", () => MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[0].UserID ?? 0));
|
||||
|
||||
verifyGameplayStartFlow();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLoseHostWhileReady()
|
||||
{
|
||||
AddStep("setup", () =>
|
||||
{
|
||||
MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[0].UserID ?? 0);
|
||||
MultiplayerClient.AddUser(new APIUser { Id = 2, Username = "Another user" });
|
||||
});
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
|
||||
AddStep("transfer host", () => MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[1].UserID ?? 0));
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user is idle (match not started)", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Idle);
|
||||
AddUntilStep("ready button enabled", () => button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||
}
|
||||
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
public void TestManyUsersChangingState(bool isHost)
|
||||
{
|
||||
const int users = 10;
|
||||
AddStep("setup", () =>
|
||||
{
|
||||
MultiplayerClient.TransferHost(MultiplayerClient.Room?.Users[0].UserID ?? 0);
|
||||
for (int i = 0; i < users; i++)
|
||||
MultiplayerClient.AddUser(new APIUser { Id = i, Username = "Another user" });
|
||||
});
|
||||
|
||||
if (!isHost)
|
||||
AddStep("transfer host", () => MultiplayerClient.TransferHost(2));
|
||||
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
|
||||
AddRepeatStep("change user ready state", () =>
|
||||
{
|
||||
MultiplayerClient.ChangeUserState(RNG.Next(0, users), RNG.NextBool() ? MultiplayerUserState.Ready : MultiplayerUserState.Idle);
|
||||
}, 20);
|
||||
|
||||
AddRepeatStep("ready all users", () =>
|
||||
{
|
||||
var nextUnready = MultiplayerClient.Room?.Users.FirstOrDefault(c => c.State == MultiplayerUserState.Idle);
|
||||
if (nextUnready != null)
|
||||
MultiplayerClient.ChangeUserState(nextUnready.UserID, MultiplayerUserState.Ready);
|
||||
}, users);
|
||||
}
|
||||
|
||||
private void verifyGameplayStartFlow()
|
||||
{
|
||||
AddUntilStep("user is ready", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.Ready);
|
||||
ClickButtonWhenEnabled<MultiplayerReadyButton>();
|
||||
AddUntilStep("user waiting for load", () => MultiplayerClient.Room?.Users[0].State == MultiplayerUserState.WaitingForLoad);
|
||||
|
||||
AddStep("finish gameplay", () =>
|
||||
{
|
||||
MultiplayerClient.ChangeUserState(MultiplayerClient.Room?.Users[0].UserID ?? 0, MultiplayerUserState.Loaded);
|
||||
MultiplayerClient.ChangeUserState(MultiplayerClient.Room?.Users[0].UserID ?? 0, MultiplayerUserState.FinishedPlay);
|
||||
});
|
||||
|
||||
AddUntilStep("ready button enabled", () => button.ChildrenOfType<OsuButton>().Single().Enabled.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ 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.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -26,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>();
|
||||
|
||||
@ -56,23 +57,27 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
RulesetID = Beatmap.Value.BeatmapInfo.Ruleset.OnlineID,
|
||||
};
|
||||
|
||||
Child = new FillFlowContainer
|
||||
Child = new PopoverContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
spectateButton = new MultiplayerSpectateButton
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200, 50),
|
||||
},
|
||||
readyButton = new MultiplayerReadyButton
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200, 50),
|
||||
spectateButton = new MultiplayerSpectateButton
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200, 50),
|
||||
},
|
||||
startControl = new MatchStartControl
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200, 50),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -141,6 +146,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
=> 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<MultiplayerReadyButton>().Single().Enabled.Value == shouldBeEnabled);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace osu.Game.Tournament.Screens.Setup
|
||||
dropdown.Current.BindValueChanged(v => Button.Enabled.Value = v.NewValue != startupTournament, true);
|
||||
|
||||
Action = () => game.GracefullyExit();
|
||||
folderButton.Action = storage.PresentExternally;
|
||||
folderButton.Action = () => storage.PresentExternally();
|
||||
|
||||
ButtonText = "Close osu!";
|
||||
}
|
||||
|
@ -19,6 +19,11 @@ namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
public class LegacyBeatmapDecoder : LegacyDecoder<Beatmap>
|
||||
{
|
||||
/// <summary>
|
||||
/// An offset which needs to be applied to old beatmaps (v4 and lower) to correct timing changes that were applied at a game client level.
|
||||
/// </summary>
|
||||
public const int EARLY_VERSION_TIMING_OFFSET = 24;
|
||||
|
||||
internal static RulesetStore RulesetStore;
|
||||
|
||||
private Beatmap beatmap;
|
||||
@ -50,8 +55,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
RulesetStore = new AssemblyRulesetStore();
|
||||
}
|
||||
|
||||
// BeatmapVersion 4 and lower had an incorrect offset (stable has this set as 24ms off)
|
||||
offset = FormatVersion < 5 ? 24 : 0;
|
||||
offset = FormatVersion < 5 ? EARLY_VERSION_TIMING_OFFSET : 0;
|
||||
}
|
||||
|
||||
protected override Beatmap CreateTemplateObject()
|
||||
|
@ -1,6 +1,8 @@
|
||||
// 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.
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -17,6 +19,7 @@ using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Statistics;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Input.Bindings;
|
||||
@ -28,8 +31,6 @@ using osu.Game.Stores;
|
||||
using Realms;
|
||||
using Realms.Exceptions;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
/// <summary>
|
||||
@ -46,6 +47,8 @@ namespace osu.Game.Database
|
||||
|
||||
private readonly IDatabaseContextFactory? efContextFactory;
|
||||
|
||||
private readonly SynchronizationContext? updateThreadSyncContext;
|
||||
|
||||
/// <summary>
|
||||
/// Version history:
|
||||
/// 6 ~2021-10-18 First tracked version.
|
||||
@ -143,12 +146,15 @@ namespace osu.Game.Database
|
||||
/// </summary>
|
||||
/// <param name="storage">The game storage which will be used to create the realm backing file.</param>
|
||||
/// <param name="filename">The filename to use for the realm backing file. A ".realm" extension will be added automatically if not specified.</param>
|
||||
/// <param name="updateThread">The game update thread, used to post realm operations into a thread-safe context.</param>
|
||||
/// <param name="efContextFactory">An EF factory used only for migration purposes.</param>
|
||||
public RealmAccess(Storage storage, string filename, IDatabaseContextFactory? efContextFactory = null)
|
||||
public RealmAccess(Storage storage, string filename, GameThread? updateThread = null, IDatabaseContextFactory? efContextFactory = null)
|
||||
{
|
||||
this.storage = storage;
|
||||
this.efContextFactory = efContextFactory;
|
||||
|
||||
updateThreadSyncContext = updateThread?.SynchronizationContext ?? SynchronizationContext.Current;
|
||||
|
||||
Filename = filename;
|
||||
|
||||
if (!Filename.EndsWith(realm_extension, StringComparison.Ordinal))
|
||||
@ -379,9 +385,6 @@ namespace osu.Game.Database
|
||||
public IDisposable RegisterForNotifications<T>(Func<Realm, IQueryable<T>> query, NotificationCallbackDelegate<T> callback)
|
||||
where T : RealmObjectBase
|
||||
{
|
||||
if (!ThreadSafety.IsUpdateThread)
|
||||
throw new InvalidOperationException(@$"{nameof(RegisterForNotifications)} must be called from the update thread.");
|
||||
|
||||
lock (realmLock)
|
||||
{
|
||||
Func<Realm, IDisposable?> action = realm => query(realm).QueryAsyncWithNotifications(callback);
|
||||
@ -459,23 +462,24 @@ namespace osu.Game.Database
|
||||
/// <returns>An <see cref="IDisposable"/> which should be disposed to unsubscribe any inner subscription.</returns>
|
||||
public IDisposable RegisterCustomSubscription(Func<Realm, IDisposable?> action)
|
||||
{
|
||||
if (!ThreadSafety.IsUpdateThread)
|
||||
throw new InvalidOperationException(@$"{nameof(RegisterForNotifications)} must be called from the update thread.");
|
||||
|
||||
var syncContext = SynchronizationContext.Current;
|
||||
if (updateThreadSyncContext == null)
|
||||
throw new InvalidOperationException("Attempted to register a realm subscription before update thread registration.");
|
||||
|
||||
total_subscriptions.Value++;
|
||||
|
||||
registerSubscription(action);
|
||||
if (ThreadSafety.IsUpdateThread)
|
||||
updateThreadSyncContext.Send(_ => registerSubscription(action), null);
|
||||
else
|
||||
updateThreadSyncContext.Post(_ => registerSubscription(action), null);
|
||||
|
||||
// This token is returned to the consumer.
|
||||
// When disposed, it will cause the registration to be permanently ceased (unsubscribed with realm and unregistered by this class).
|
||||
return new InvokeOnDisposal(() =>
|
||||
{
|
||||
if (ThreadSafety.IsUpdateThread)
|
||||
syncContext.Send(_ => unsubscribe(), null);
|
||||
updateThreadSyncContext.Send(_ => unsubscribe(), null);
|
||||
else
|
||||
syncContext.Post(_ => unsubscribe(), null);
|
||||
updateThreadSyncContext.Post(_ => unsubscribe(), null);
|
||||
|
||||
void unsubscribe()
|
||||
{
|
||||
|
@ -70,9 +70,9 @@ namespace osu.Game.IO
|
||||
public override Stream GetStream(string path, FileAccess access = FileAccess.Read, FileMode mode = FileMode.OpenOrCreate) =>
|
||||
UnderlyingStorage.GetStream(MutatePath(path), access, mode);
|
||||
|
||||
public override void OpenFileExternally(string filename) => UnderlyingStorage.OpenFileExternally(MutatePath(filename));
|
||||
public override bool OpenFileExternally(string filename) => UnderlyingStorage.OpenFileExternally(MutatePath(filename));
|
||||
|
||||
public override void PresentFileExternally(string filename) => UnderlyingStorage.PresentFileExternally(MutatePath(filename));
|
||||
public override bool PresentFileExternally(string filename) => UnderlyingStorage.PresentFileExternally(MutatePath(filename));
|
||||
|
||||
public override Storage GetStorageForDirectory(string path)
|
||||
{
|
||||
|
@ -0,0 +1,22 @@
|
||||
// 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.
|
||||
|
||||
#nullable enable
|
||||
|
||||
using MessagePack;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer.Countdown
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates a change to the <see cref="MultiplayerRoom"/>'s countdown.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class CountdownChangedEvent : MatchServerEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// The new countdown.
|
||||
/// </summary>
|
||||
[Key(0)]
|
||||
public MultiplayerCountdown? Countdown { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
// 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 MessagePack;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Online.Multiplayer.Countdown
|
||||
{
|
||||
/// <summary>
|
||||
/// A request for a countdown to start the match.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class StartMatchCountdownRequest : MatchUserRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// How long the countdown should last.
|
||||
/// </summary>
|
||||
[Key(0)]
|
||||
public TimeSpan Duration { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
// 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.
|
||||
|
||||
#nullable enable
|
||||
|
||||
using MessagePack;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer.Countdown
|
||||
{
|
||||
/// <summary>
|
||||
/// Request to stop the current countdown.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class StopCountdownRequest : MatchUserRequest
|
||||
{
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
// 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.
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using MessagePack;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
@ -11,6 +14,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[MessagePackObject]
|
||||
// IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
|
||||
[Union(0, typeof(CountdownChangedEvent))]
|
||||
public abstract class MatchServerEvent
|
||||
{
|
||||
}
|
||||
|
17
osu.Game/Online/Multiplayer/MatchStartCountdown.cs
Normal file
17
osu.Game/Online/Multiplayer/MatchStartCountdown.cs
Normal file
@ -0,0 +1,17 @@
|
||||
// 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.
|
||||
|
||||
#nullable enable
|
||||
|
||||
using MessagePack;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="MultiplayerCountdown"/> which will start the match after ending.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class MatchStartCountdown : MultiplayerCountdown
|
||||
{
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using MessagePack;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer.MatchTypes.TeamVersus
|
||||
{
|
||||
[MessagePackObject]
|
||||
public class ChangeTeamRequest : MatchUserRequest
|
||||
{
|
||||
[Key(0)]
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using MessagePack;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
@ -12,7 +13,10 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[MessagePackObject]
|
||||
[Union(0, typeof(ChangeTeamRequest))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
|
||||
// IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
|
||||
[Union(0, typeof(ChangeTeamRequest))]
|
||||
[Union(1, typeof(StartMatchCountdownRequest))]
|
||||
[Union(2, typeof(StopCountdownRequest))]
|
||||
public abstract class MatchUserRequest
|
||||
{
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ using osu.Framework.Logging;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Online.Rooms.RoomStatuses;
|
||||
using osu.Game.Rulesets;
|
||||
@ -170,6 +171,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
Room = joinedRoom;
|
||||
APIRoom = room;
|
||||
|
||||
Debug.Assert(joinedRoom.Playlist.Count > 0);
|
||||
|
||||
APIRoom.Playlist.Clear();
|
||||
APIRoom.Playlist.AddRange(joinedRoom.Playlist.Select(createPlaylistItem));
|
||||
|
||||
@ -534,7 +537,24 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
public Task MatchEvent(MatchServerEvent e)
|
||||
{
|
||||
// not used by any match types just yet.
|
||||
if (Room == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
Scheduler.Add(() =>
|
||||
{
|
||||
if (Room == null)
|
||||
return;
|
||||
|
||||
switch (e)
|
||||
{
|
||||
case CountdownChangedEvent countdownChangedEvent:
|
||||
Room.Countdown = countdownChangedEvent.Countdown;
|
||||
break;
|
||||
}
|
||||
|
||||
RoomUpdated?.Invoke();
|
||||
}, false);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@ -665,6 +685,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
Room.Playlist.Remove(Room.Playlist.Single(existing => existing.ID == playlistItemId));
|
||||
APIRoom.Playlist.RemoveAll(existing => existing.ID == playlistItemId);
|
||||
|
||||
Debug.Assert(Room.Playlist.Count > 0);
|
||||
|
||||
ItemRemoved?.Invoke(playlistItemId);
|
||||
RoomUpdated?.Invoke();
|
||||
});
|
||||
|
28
osu.Game/Online/Multiplayer/MultiplayerCountdown.cs
Normal file
28
osu.Game/Online/Multiplayer/MultiplayerCountdown.cs
Normal file
@ -0,0 +1,28 @@
|
||||
// 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.
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using MessagePack;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes the current countdown in a <see cref="MultiplayerRoom"/>.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
[Union(0, typeof(MatchStartCountdown))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
|
||||
public abstract class MultiplayerCountdown
|
||||
{
|
||||
/// <summary>
|
||||
/// The amount of time remaining in the countdown.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is only sent once from the server upon initial retrieval of the <see cref="MultiplayerRoom"/> or via a <see cref="CountdownChangedEvent"/>.
|
||||
/// </remarks>
|
||||
[Key(0)]
|
||||
public TimeSpan TimeRemaining { get; set; }
|
||||
}
|
||||
}
|
@ -54,6 +54,12 @@ namespace osu.Game.Online.Multiplayer
|
||||
[Key(6)]
|
||||
public IList<MultiplayerPlaylistItem> Playlist { get; set; } = new List<MultiplayerPlaylistItem>();
|
||||
|
||||
/// <summary>
|
||||
/// The currently-running countdown.
|
||||
/// </summary>
|
||||
[Key(7)]
|
||||
public MultiplayerCountdown? Countdown { get; set; }
|
||||
|
||||
[JsonConstructor]
|
||||
[SerializationConstructor]
|
||||
public MultiplayerRoom(long roomId)
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||
|
||||
namespace osu.Game.Online
|
||||
@ -18,8 +19,12 @@ namespace osu.Game.Online
|
||||
internal static readonly IReadOnlyList<(Type derivedType, Type baseType)> BASE_TYPE_MAPPING = new[]
|
||||
{
|
||||
(typeof(ChangeTeamRequest), typeof(MatchUserRequest)),
|
||||
(typeof(StartMatchCountdownRequest), typeof(MatchUserRequest)),
|
||||
(typeof(StopCountdownRequest), typeof(MatchUserRequest)),
|
||||
(typeof(CountdownChangedEvent), typeof(MatchServerEvent)),
|
||||
(typeof(TeamVersusRoomState), typeof(MatchRoomState)),
|
||||
(typeof(TeamVersusUserState), typeof(MatchUserState)),
|
||||
(typeof(MatchStartCountdown), typeof(MultiplayerCountdown))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ namespace osu.Game
|
||||
if (Storage.Exists(DatabaseContextFactory.DATABASE_NAME))
|
||||
dependencies.Cache(EFContextFactory = new DatabaseContextFactory(Storage));
|
||||
|
||||
dependencies.Cache(realm = new RealmAccess(Storage, "client", EFContextFactory));
|
||||
dependencies.Cache(realm = new RealmAccess(Storage, "client", Host.UpdateThread, EFContextFactory));
|
||||
|
||||
dependencies.CacheAs<RulesetStore>(RulesetStore = new RealmRulesetStore(realm, Storage));
|
||||
dependencies.CacheAs<IRulesetStore>(RulesetStore);
|
||||
|
@ -68,7 +68,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
||||
Add(new SettingsButton
|
||||
{
|
||||
Text = GeneralSettingsStrings.OpenOsuFolder,
|
||||
Action = storage.PresentExternally,
|
||||
Action = () => storage.PresentExternally(),
|
||||
});
|
||||
|
||||
Add(new SettingsButton
|
||||
|
@ -500,12 +500,15 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
||||
=> new LegacyHitSampleInfo(newName.GetOr(Name), newBank.GetOr(Bank), newVolume.GetOr(Volume), newCustomSampleBank.GetOr(CustomSampleBank), newIsLayered.GetOr(IsLayered));
|
||||
|
||||
public bool Equals(LegacyHitSampleInfo? other)
|
||||
=> base.Equals(other) && CustomSampleBank == other.CustomSampleBank;
|
||||
// The additions to equality checks here are *required* to ensure that pooling works correctly.
|
||||
// Of note, `IsLayered` may cause the usage of `SampleVirtual` instead of an actual sample (in cases playback is not required).
|
||||
// Removing it would cause samples which may actually require playback to potentially source for a `SampleVirtual` sample pool.
|
||||
=> base.Equals(other) && CustomSampleBank == other.CustomSampleBank && IsLayered == other.IsLayered;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
=> obj is LegacyHitSampleInfo other && Equals(other);
|
||||
|
||||
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), CustomSampleBank);
|
||||
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), CustomSampleBank, IsLayered);
|
||||
}
|
||||
|
||||
private class FileHitSampleInfo : LegacyHitSampleInfo, IEquatable<FileHitSampleInfo>
|
||||
|
@ -23,6 +23,8 @@ namespace osu.Game.Scoring.Legacy
|
||||
private IBeatmap currentBeatmap;
|
||||
private Ruleset currentRuleset;
|
||||
|
||||
private float beatmapOffset;
|
||||
|
||||
public Score Parse(Stream stream)
|
||||
{
|
||||
var score = new Score
|
||||
@ -72,6 +74,9 @@ namespace osu.Game.Scoring.Legacy
|
||||
currentBeatmap = workingBeatmap.GetPlayableBeatmap(currentRuleset.RulesetInfo, scoreInfo.Mods);
|
||||
scoreInfo.BeatmapInfo = currentBeatmap.BeatmapInfo;
|
||||
|
||||
// As this is baked into hitobject timing (see `LegacyBeatmapDecoder`) we also need to apply this to replay frame timing.
|
||||
beatmapOffset = currentBeatmap.BeatmapInfo.BeatmapVersion < 5 ? LegacyBeatmapDecoder.EARLY_VERSION_TIMING_OFFSET : 0;
|
||||
|
||||
/* score.HpGraphString = */
|
||||
sr.ReadString();
|
||||
|
||||
@ -229,7 +234,7 @@ namespace osu.Game.Scoring.Legacy
|
||||
|
||||
private void readLegacyReplay(Replay replay, StreamReader reader)
|
||||
{
|
||||
float lastTime = 0;
|
||||
float lastTime = beatmapOffset;
|
||||
ReplayFrame currentFrame = null;
|
||||
|
||||
string[] frames = reader.ReadToEnd().Split(',');
|
||||
|
@ -1,12 +1,15 @@
|
||||
// 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.
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.IO.Legacy;
|
||||
using osu.Game.Replays.Legacy;
|
||||
@ -14,8 +17,6 @@ using osu.Game.Rulesets.Replays;
|
||||
using osu.Game.Rulesets.Replays.Types;
|
||||
using SharpCompress.Compressors.LZMA;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Scoring.Legacy
|
||||
{
|
||||
public class LegacyScoreEncoder
|
||||
@ -111,6 +112,9 @@ namespace osu.Game.Scoring.Legacy
|
||||
{
|
||||
StringBuilder replayData = new StringBuilder();
|
||||
|
||||
// As this is baked into hitobject timing (see `LegacyBeatmapDecoder`) we also need to apply this to replay frame timing.
|
||||
double offset = beatmap?.BeatmapInfo.BeatmapVersion < 5 ? -LegacyBeatmapDecoder.EARLY_VERSION_TIMING_OFFSET : 0;
|
||||
|
||||
if (score.Replay != null)
|
||||
{
|
||||
int lastTime = 0;
|
||||
@ -120,7 +124,7 @@ namespace osu.Game.Scoring.Legacy
|
||||
var legacyFrame = getLegacyFrame(f);
|
||||
|
||||
// Rounding because stable could only parse integral values
|
||||
int time = (int)Math.Round(legacyFrame.Time);
|
||||
int time = (int)Math.Round(legacyFrame.Time + offset);
|
||||
replayData.Append(FormattableString.Invariant($"{time - lastTime}|{legacyFrame.MouseX ?? 0}|{legacyFrame.MouseY ?? 0}|{(int)legacyFrame.ButtonState},"));
|
||||
lastTime = time;
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
{
|
||||
public new readonly BindableBool Enabled = new BindableBool();
|
||||
|
||||
private IBindable<BeatmapAvailability> availability;
|
||||
private readonly IBindable<BeatmapAvailability> availability = new Bindable<BeatmapAvailability>();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OnlinePlayBeatmapAvailabilityTracker beatmapTracker)
|
||||
{
|
||||
availability = beatmapTracker.Availability.GetBoundCopy();
|
||||
availability.BindTo(beatmapTracker.Availability);
|
||||
|
||||
availability.BindValueChanged(_ => updateState());
|
||||
Enabled.BindValueChanged(_ => updateState(), true);
|
||||
|
@ -12,6 +12,7 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Audio;
|
||||
@ -100,122 +101,126 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
{
|
||||
sampleStart = audio.Samples.Get(@"SongSelect/confirm-selection");
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
InternalChild = new PopoverContainer
|
||||
{
|
||||
beatmapAvailabilityTracker,
|
||||
new MultiplayerRoomSounds(),
|
||||
new GridContainer
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RowDimensions = new[]
|
||||
beatmapAvailabilityTracker,
|
||||
new MultiplayerRoomSounds(),
|
||||
new GridContainer
|
||||
{
|
||||
new Dimension(),
|
||||
new Dimension(GridSizeMode.Absolute, 50)
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
// Padded main content (drawable room + main content)
|
||||
new Drawable[]
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RowDimensions = new[]
|
||||
{
|
||||
new Container
|
||||
new Dimension(),
|
||||
new Dimension(GridSizeMode.Absolute, 50)
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
// Padded main content (drawable room + main content)
|
||||
new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding
|
||||
new Container
|
||||
{
|
||||
Horizontal = WaveOverlayContainer.WIDTH_PADDING,
|
||||
Bottom = 30
|
||||
},
|
||||
Children = new[]
|
||||
{
|
||||
mainContent = new GridContainer
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RowDimensions = new[]
|
||||
Horizontal = WaveOverlayContainer.WIDTH_PADDING,
|
||||
Bottom = 30
|
||||
},
|
||||
Children = new[]
|
||||
{
|
||||
mainContent = new GridContainer
|
||||
{
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(GridSizeMode.Absolute, 10)
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[]
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RowDimensions = new[]
|
||||
{
|
||||
new DrawableMatchRoom(Room, allowEdit)
|
||||
{
|
||||
OnEdit = () => settingsOverlay.Show(),
|
||||
SelectedItem = { BindTarget = SelectedItem }
|
||||
}
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(GridSizeMode.Absolute, 10)
|
||||
},
|
||||
null,
|
||||
new Drawable[]
|
||||
Content = new[]
|
||||
{
|
||||
new Container
|
||||
new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new[]
|
||||
new DrawableMatchRoom(Room, allowEdit)
|
||||
{
|
||||
new Container
|
||||
OnEdit = () => settingsOverlay.Show(),
|
||||
SelectedItem = { BindTarget = SelectedItem }
|
||||
}
|
||||
},
|
||||
null,
|
||||
new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
CornerRadius = 10,
|
||||
Child = new Box
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4Extensions.FromHex(@"3e3a44") // Temporary.
|
||||
Masking = true,
|
||||
CornerRadius = 10,
|
||||
Child = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4Extensions.FromHex(@"3e3a44") // Temporary.
|
||||
},
|
||||
},
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(20),
|
||||
Child = CreateMainContent(),
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Child = userModsSelectOverlay = new UserModSelectOverlay
|
||||
new Container
|
||||
{
|
||||
SelectedMods = { BindTarget = UserMods },
|
||||
IsValidMod = _ => false
|
||||
}
|
||||
},
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(20),
|
||||
Child = CreateMainContent(),
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Child = userModsSelectOverlay = new UserModSelectOverlay
|
||||
{
|
||||
SelectedMods = { BindTarget = UserMods },
|
||||
IsValidMod = _ => false
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
// Resolves 1px masking errors between the settings overlay and the room panel.
|
||||
Padding = new MarginPadding(-1),
|
||||
Child = settingsOverlay = CreateRoomSettingsOverlay(Room)
|
||||
}
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
// Resolves 1px masking errors between the settings overlay and the room panel.
|
||||
Padding = new MarginPadding(-1),
|
||||
Child = settingsOverlay = CreateRoomSettingsOverlay(Room)
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
// Footer
|
||||
new Drawable[]
|
||||
{
|
||||
new Container
|
||||
// Footer
|
||||
new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
new Container
|
||||
{
|
||||
new Box
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4Extensions.FromHex(@"28242d") // Temporary.
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(5),
|
||||
Child = CreateFooter()
|
||||
},
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4Extensions.FromHex(@"28242d") // Temporary.
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding(5),
|
||||
Child = CreateFooter()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,224 @@
|
||||
// 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.Diagnostics;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
public class MatchStartControl : MultiplayerRoomComposite
|
||||
{
|
||||
[Resolved]
|
||||
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||
|
||||
[CanBeNull]
|
||||
private IDisposable clickOperation;
|
||||
|
||||
private Sample sampleReady;
|
||||
private Sample sampleReadyAll;
|
||||
private Sample sampleUnready;
|
||||
|
||||
private readonly BindableBool enabled = new BindableBool();
|
||||
private readonly MultiplayerCountdownButton countdownButton;
|
||||
private int countReady;
|
||||
private ScheduledDelegate readySampleDelegate;
|
||||
private IBindable<bool> operationInProgress;
|
||||
|
||||
public MatchStartControl()
|
||||
{
|
||||
InternalChild = new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
ColumnDimensions = new[]
|
||||
{
|
||||
new Dimension(),
|
||||
new Dimension(GridSizeMode.AutoSize)
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[]
|
||||
{
|
||||
new MultiplayerReadyButton
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One,
|
||||
Action = onReadyClick,
|
||||
Enabled = { BindTarget = enabled },
|
||||
},
|
||||
countdownButton = new MultiplayerCountdownButton
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Size = new Vector2(40, 1),
|
||||
Alpha = 0,
|
||||
Action = startCountdown,
|
||||
Enabled = { BindTarget = enabled }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
operationInProgress = ongoingOperationTracker.InProgress.GetBoundCopy();
|
||||
operationInProgress.BindValueChanged(_ => updateState());
|
||||
|
||||
sampleReady = audio.Samples.Get(@"Multiplayer/player-ready");
|
||||
sampleReadyAll = audio.Samples.Get(@"Multiplayer/player-ready-all");
|
||||
sampleUnready = audio.Samples.Get(@"Multiplayer/player-unready");
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
CurrentPlaylistItem.BindValueChanged(_ => updateState());
|
||||
}
|
||||
|
||||
protected override void OnRoomUpdated()
|
||||
{
|
||||
base.OnRoomUpdated();
|
||||
updateState();
|
||||
}
|
||||
|
||||
protected override void OnRoomLoadRequested()
|
||||
{
|
||||
base.OnRoomLoadRequested();
|
||||
endOperation();
|
||||
}
|
||||
|
||||
private void onReadyClick()
|
||||
{
|
||||
if (Room == null)
|
||||
return;
|
||||
|
||||
Debug.Assert(clickOperation == null);
|
||||
clickOperation = ongoingOperationTracker.BeginOperation();
|
||||
|
||||
// Ensure the current user becomes ready before being able to do anything else (start match, stop countdown, unready).
|
||||
if (!isReady() || !Client.IsHost)
|
||||
{
|
||||
toggleReady();
|
||||
return;
|
||||
}
|
||||
|
||||
// Local user is the room host and is in a ready state.
|
||||
// The only action they can take is to stop a countdown if one's currently running.
|
||||
if (Room.Countdown != null)
|
||||
{
|
||||
stopCountdown();
|
||||
return;
|
||||
}
|
||||
|
||||
// And if a countdown isn't running, start the match.
|
||||
startMatch();
|
||||
|
||||
bool isReady() => Client.LocalUser?.State == MultiplayerUserState.Ready || Client.LocalUser?.State == MultiplayerUserState.Spectating;
|
||||
|
||||
void toggleReady() => Client.ToggleReady().ContinueWith(_ => endOperation());
|
||||
|
||||
void stopCountdown() => Client.SendMatchRequest(new StopCountdownRequest()).ContinueWith(_ => endOperation());
|
||||
|
||||
void startMatch() => Client.StartMatch().ContinueWith(t =>
|
||||
{
|
||||
// accessing Exception here silences any potential errors from the antecedent task
|
||||
if (t.Exception != null)
|
||||
{
|
||||
// gameplay was not started due to an exception; unblock button.
|
||||
endOperation();
|
||||
}
|
||||
|
||||
// gameplay is starting, the button will be unblocked on load requested.
|
||||
});
|
||||
}
|
||||
|
||||
private void startCountdown(TimeSpan duration)
|
||||
{
|
||||
Debug.Assert(clickOperation == null);
|
||||
clickOperation = ongoingOperationTracker.BeginOperation();
|
||||
|
||||
Client.SendMatchRequest(new StartMatchCountdownRequest { Duration = duration }).ContinueWith(_ => endOperation());
|
||||
}
|
||||
|
||||
private void endOperation()
|
||||
{
|
||||
clickOperation?.Dispose();
|
||||
clickOperation = null;
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
if (Room == null)
|
||||
{
|
||||
enabled.Value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var localUser = Client.LocalUser;
|
||||
|
||||
int newCountReady = Room.Users.Count(u => u.State == MultiplayerUserState.Ready);
|
||||
int newCountTotal = Room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
|
||||
|
||||
if (Room.Countdown != null)
|
||||
countdownButton.Alpha = 0;
|
||||
else
|
||||
{
|
||||
switch (localUser?.State)
|
||||
{
|
||||
default:
|
||||
countdownButton.Alpha = 0;
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
countdownButton.Alpha = Room.Host?.Equals(localUser) == true ? 1 : 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
enabled.Value =
|
||||
Room.State == MultiplayerRoomState.Open
|
||||
&& CurrentPlaylistItem.Value?.ID == Room.Settings.PlaylistItemId
|
||||
&& !Room.Playlist.Single(i => i.ID == Room.Settings.PlaylistItemId).Expired
|
||||
&& !operationInProgress.Value;
|
||||
|
||||
// When the local user is the host and spectating the match, the "start match" state should be enabled if any users are ready.
|
||||
if (localUser?.State == MultiplayerUserState.Spectating)
|
||||
enabled.Value &= Room.Host?.Equals(localUser) == true && newCountReady > 0;
|
||||
|
||||
if (newCountReady == countReady)
|
||||
return;
|
||||
|
||||
readySampleDelegate?.Cancel();
|
||||
readySampleDelegate = Schedule(() =>
|
||||
{
|
||||
if (newCountReady > countReady)
|
||||
{
|
||||
if (newCountReady == newCountTotal)
|
||||
sampleReadyAll?.Play();
|
||||
else
|
||||
sampleReady?.Play();
|
||||
}
|
||||
else if (newCountReady < countReady)
|
||||
{
|
||||
sampleUnready?.Play();
|
||||
}
|
||||
|
||||
countReady = newCountReady;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
// 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 MultiplayerCountdownButton : 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 MultiplayerCountdownButton()
|
||||
{
|
||||
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 OsuButton
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Text = $"Start match in {duration.Humanize()}",
|
||||
BackgroundColour = background.Colour,
|
||||
Action = () =>
|
||||
{
|
||||
Action(duration);
|
||||
this.HidePopover();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return new OsuPopover { Child = flow };
|
||||
}
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
null,
|
||||
new MultiplayerReadyButton
|
||||
new MatchStartControl
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
|
@ -2,210 +2,177 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Backgrounds;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
public class MultiplayerReadyButton : MultiplayerRoomComposite
|
||||
public class MultiplayerReadyButton : ReadyButton
|
||||
{
|
||||
public new Triangles Triangles => base.Triangles;
|
||||
|
||||
[Resolved]
|
||||
private MultiplayerClient multiplayerClient { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||
|
||||
[CanBeNull]
|
||||
private IDisposable clickOperation;
|
||||
|
||||
private Sample sampleReady;
|
||||
private Sample sampleReadyAll;
|
||||
private Sample sampleUnready;
|
||||
|
||||
private readonly ButtonWithTrianglesExposed button;
|
||||
private int countReady;
|
||||
private ScheduledDelegate readySampleDelegate;
|
||||
private IBindable<bool> operationInProgress;
|
||||
|
||||
public MultiplayerReadyButton()
|
||||
{
|
||||
InternalChild = button = new ButtonWithTrianglesExposed
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One,
|
||||
Action = onReadyClick,
|
||||
Enabled = { Value = true },
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
operationInProgress = ongoingOperationTracker.InProgress.GetBoundCopy();
|
||||
operationInProgress.BindValueChanged(_ => updateState());
|
||||
|
||||
sampleReady = audio.Samples.Get(@"Multiplayer/player-ready");
|
||||
sampleReadyAll = audio.Samples.Get(@"Multiplayer/player-ready-all");
|
||||
sampleUnready = audio.Samples.Get(@"Multiplayer/player-unready");
|
||||
}
|
||||
private MultiplayerRoom room => multiplayerClient.Room;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
CurrentPlaylistItem.BindValueChanged(_ => updateState());
|
||||
multiplayerClient.RoomUpdated += onRoomUpdated;
|
||||
onRoomUpdated();
|
||||
}
|
||||
|
||||
protected override void OnRoomUpdated()
|
||||
private MultiplayerCountdown countdown;
|
||||
private DateTimeOffset countdownReceivedTime;
|
||||
private ScheduledDelegate countdownUpdateDelegate;
|
||||
|
||||
private void onRoomUpdated() => Scheduler.AddOnce(() =>
|
||||
{
|
||||
base.OnRoomUpdated();
|
||||
updateState();
|
||||
}
|
||||
if (countdown == null && room?.Countdown != null)
|
||||
countdownReceivedTime = DateTimeOffset.Now;
|
||||
|
||||
protected override void OnRoomLoadRequested()
|
||||
{
|
||||
base.OnRoomLoadRequested();
|
||||
endOperation();
|
||||
}
|
||||
countdown = room?.Countdown;
|
||||
|
||||
private void onReadyClick()
|
||||
{
|
||||
if (Room == null)
|
||||
return;
|
||||
|
||||
Debug.Assert(clickOperation == null);
|
||||
clickOperation = ongoingOperationTracker.BeginOperation();
|
||||
|
||||
// Ensure the current user becomes ready before being able to do anything else (start match, stop countdown, unready).
|
||||
if (!isReady() || !Client.IsHost)
|
||||
if (room?.Countdown != null)
|
||||
countdownUpdateDelegate ??= Scheduler.AddDelayed(updateButtonText, 1000, true);
|
||||
else
|
||||
{
|
||||
toggleReady();
|
||||
countdownUpdateDelegate?.Cancel();
|
||||
countdownUpdateDelegate = null;
|
||||
}
|
||||
|
||||
updateButtonText();
|
||||
updateButtonColour();
|
||||
});
|
||||
|
||||
private void updateButtonText()
|
||||
{
|
||||
if (room == null)
|
||||
{
|
||||
Text = "Ready";
|
||||
return;
|
||||
}
|
||||
|
||||
// And if a countdown isn't running, start the match.
|
||||
startMatch();
|
||||
var localUser = multiplayerClient.LocalUser;
|
||||
|
||||
bool isReady() => Client.LocalUser?.State == MultiplayerUserState.Ready || Client.LocalUser?.State == MultiplayerUserState.Spectating;
|
||||
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)";
|
||||
|
||||
void toggleReady() => Client.ToggleReady().ContinueWith(_ => endOperation());
|
||||
|
||||
void startMatch() => Client.StartMatch().ContinueWith(t =>
|
||||
if (countdown != null)
|
||||
{
|
||||
// accessing Exception here silences any potential errors from the antecedent task
|
||||
if (t.Exception != null)
|
||||
TimeSpan timeElapsed = DateTimeOffset.Now - countdownReceivedTime;
|
||||
TimeSpan countdownRemaining;
|
||||
|
||||
if (timeElapsed > countdown.TimeRemaining)
|
||||
countdownRemaining = TimeSpan.Zero;
|
||||
else
|
||||
countdownRemaining = countdown.TimeRemaining - timeElapsed;
|
||||
|
||||
string countdownText = $"Starting in {countdownRemaining:mm\\:ss}";
|
||||
|
||||
switch (localUser?.State)
|
||||
{
|
||||
// gameplay was not started due to an exception; unblock button.
|
||||
endOperation();
|
||||
default:
|
||||
Text = $"Ready ({countdownText.ToLowerInvariant()})";
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
Text = $"{countdownText} {countText}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (localUser?.State)
|
||||
{
|
||||
default:
|
||||
Text = "Ready";
|
||||
break;
|
||||
|
||||
// gameplay is starting, the button will be unblocked on load requested.
|
||||
});
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
Text = room.Host?.Equals(localUser) == true
|
||||
? $"Start match {countText}"
|
||||
: $"Waiting for host... {countText}";
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void endOperation()
|
||||
private void updateButtonColour()
|
||||
{
|
||||
clickOperation?.Dispose();
|
||||
clickOperation = null;
|
||||
}
|
||||
if (room == null)
|
||||
{
|
||||
setGreen();
|
||||
return;
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
var localUser = Client.LocalUser;
|
||||
|
||||
int newCountReady = Room?.Users.Count(u => u.State == MultiplayerUserState.Ready) ?? 0;
|
||||
int newCountTotal = Room?.Users.Count(u => u.State != MultiplayerUserState.Spectating) ?? 0;
|
||||
var localUser = multiplayerClient.LocalUser;
|
||||
|
||||
switch (localUser?.State)
|
||||
{
|
||||
default:
|
||||
button.Text = "Ready";
|
||||
updateButtonColour(true);
|
||||
setGreen();
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
string countText = $"({newCountReady} / {newCountTotal} ready)";
|
||||
|
||||
if (Room?.Host?.Equals(localUser) == true)
|
||||
{
|
||||
button.Text = $"Start match {countText}";
|
||||
updateButtonColour(true);
|
||||
}
|
||||
if (room?.Host?.Equals(localUser) == true && room.Countdown == null)
|
||||
setGreen();
|
||||
else
|
||||
{
|
||||
button.Text = $"Waiting for host... {countText}";
|
||||
updateButtonColour(false);
|
||||
}
|
||||
setYellow();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
bool enableButton =
|
||||
Room?.State == MultiplayerRoomState.Open
|
||||
&& CurrentPlaylistItem.Value?.ID == Room.Settings.PlaylistItemId
|
||||
&& !Room.Playlist.Single(i => i.ID == Room.Settings.PlaylistItemId).Expired
|
||||
&& !operationInProgress.Value;
|
||||
|
||||
// When the local user is the host and spectating the match, the "start match" state should be enabled if any users are ready.
|
||||
if (localUser?.State == MultiplayerUserState.Spectating)
|
||||
enableButton &= Room?.Host?.Equals(localUser) == true && newCountReady > 0;
|
||||
|
||||
button.Enabled.Value = enableButton;
|
||||
|
||||
if (newCountReady == countReady)
|
||||
return;
|
||||
|
||||
readySampleDelegate?.Cancel();
|
||||
readySampleDelegate = Schedule(() =>
|
||||
void setYellow()
|
||||
{
|
||||
if (newCountReady > countReady)
|
||||
{
|
||||
if (newCountReady == newCountTotal)
|
||||
sampleReadyAll?.Play();
|
||||
else
|
||||
sampleReady?.Play();
|
||||
}
|
||||
else if (newCountReady < countReady)
|
||||
{
|
||||
sampleUnready?.Play();
|
||||
}
|
||||
|
||||
countReady = newCountReady;
|
||||
});
|
||||
}
|
||||
|
||||
private void updateButtonColour(bool green)
|
||||
{
|
||||
if (green)
|
||||
{
|
||||
button.BackgroundColour = colours.Green;
|
||||
button.Triangles.ColourDark = colours.Green;
|
||||
button.Triangles.ColourLight = colours.GreenLight;
|
||||
BackgroundColour = colours.YellowDark;
|
||||
Triangles.ColourDark = colours.YellowDark;
|
||||
Triangles.ColourLight = colours.Yellow;
|
||||
}
|
||||
else
|
||||
|
||||
void setGreen()
|
||||
{
|
||||
button.BackgroundColour = colours.YellowDark;
|
||||
button.Triangles.ColourDark = colours.YellowDark;
|
||||
button.Triangles.ColourLight = colours.Yellow;
|
||||
BackgroundColour = colours.Green;
|
||||
Triangles.ColourDark = colours.Green;
|
||||
Triangles.ColourLight = colours.GreenLight;
|
||||
}
|
||||
}
|
||||
|
||||
private class ButtonWithTrianglesExposed : ReadyButton
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
public new Triangles Triangles => base.Triangles;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
@ -187,9 +186,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
const double fade_time = 50;
|
||||
|
||||
var currentItem = Playlist.GetCurrentItem();
|
||||
Debug.Assert(currentItem != null);
|
||||
|
||||
var ruleset = rulesets.GetRuleset(currentItem.RulesetID)?.CreateInstance();
|
||||
var ruleset = currentItem != null ? rulesets.GetRuleset(currentItem.RulesetID)?.CreateInstance() : null;
|
||||
|
||||
int? currentModeRank = ruleset != null ? User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.GlobalRank : null;
|
||||
userRankText.Text = currentModeRank != null ? $"#{currentModeRank.Value:N0}" : string.Empty;
|
||||
|
@ -359,26 +359,15 @@ namespace osu.Game.Skinning
|
||||
}
|
||||
})
|
||||
{
|
||||
Children = this.HasFont(LegacyFont.Score)
|
||||
? new Drawable[]
|
||||
{
|
||||
new LegacyComboCounter(),
|
||||
new LegacyScoreCounter(),
|
||||
new LegacyAccuracyCounter(),
|
||||
new LegacyHealthDisplay(),
|
||||
new SongProgress(),
|
||||
new BarHitErrorMeter(),
|
||||
}
|
||||
: new Drawable[]
|
||||
{
|
||||
// TODO: these should fallback to using osu!classic skin textures, rather than doing this.
|
||||
new DefaultComboCounter(),
|
||||
new DefaultScoreCounter(),
|
||||
new DefaultAccuracyCounter(),
|
||||
new DefaultHealthDisplay(),
|
||||
new SongProgress(),
|
||||
new BarHitErrorMeter(),
|
||||
}
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new LegacyComboCounter(),
|
||||
new LegacyScoreCounter(),
|
||||
new LegacyAccuracyCounter(),
|
||||
new LegacyHealthDisplay(),
|
||||
new SongProgress(),
|
||||
new BarHitErrorMeter(),
|
||||
}
|
||||
};
|
||||
|
||||
return skinnableTargetWrapper;
|
||||
|
@ -27,12 +27,12 @@ namespace osu.Game.Skinning
|
||||
public abstract class Skin : IDisposable, ISkin
|
||||
{
|
||||
/// <summary>
|
||||
/// A texture store which can be used to perform user file loops for this skin.
|
||||
/// A texture store which can be used to perform user file lookups for this skin.
|
||||
/// </summary>
|
||||
protected TextureStore? Textures { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A sample store which can be used to perform user file loops for this skin.
|
||||
/// A sample store which can be used to perform user file lookups for this skin.
|
||||
/// </summary>
|
||||
protected ISampleStore? Samples { get; }
|
||||
|
||||
@ -57,7 +57,7 @@ namespace osu.Game.Skinning
|
||||
/// </summary>
|
||||
/// <param name="skin">The skin's metadata. Usually a live realm object.</param>
|
||||
/// <param name="resources">Access to game-wide resources.</param>
|
||||
/// <param name="storage">An optional store which will be used for looking up skin resources. If null, one will be created from realm <see cref="IHasRealmFiles"/> pattern.</param>
|
||||
/// <param name="storage">An optional store which will *replace* all file lookups that are usually sourced from <paramref name="skin"/>.</param>
|
||||
/// <param name="configurationFilename">An optional filename to read the skin configuration from. If not provided, the configuration will be retrieved from the storage using "skin.ini".</param>
|
||||
protected Skin(SkinInfo skin, IStorageResourceProvider? resources, IResourceStore<byte[]>? storage = null, string configurationFilename = @"skin.ini")
|
||||
{
|
||||
|
@ -7,12 +7,15 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Development;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
@ -114,12 +117,24 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
public void ChangeUserState(int userId, MultiplayerUserState newState)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
||||
((IMultiplayerClient)this).UserStateChanged(userId, newState);
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
switch (Room.State)
|
||||
{
|
||||
case MultiplayerRoomState.Open:
|
||||
// If there are no remaining ready users or the host is not ready, stop any existing countdown.
|
||||
// Todo: When we have an "automatic start" mode, this should also start a new countdown if any users _are_ ready.
|
||||
// Todo: This doesn't yet support non-match-start countdowns.
|
||||
bool shouldStopCountdown = Room.Users.All(u => u.State != MultiplayerUserState.Ready);
|
||||
shouldStopCountdown |= Room.Host?.State != MultiplayerUserState.Ready && Room.Host?.State != MultiplayerUserState.Spectating;
|
||||
|
||||
if (shouldStopCountdown)
|
||||
countdownStopSource?.Cancel();
|
||||
break;
|
||||
|
||||
case MultiplayerRoomState.WaitingForLoad:
|
||||
if (Room.Users.All(u => u.State != MultiplayerUserState.WaitingForLoad))
|
||||
{
|
||||
@ -282,6 +297,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private CancellationTokenSource? countdownSkipSource;
|
||||
private CancellationTokenSource? countdownStopSource;
|
||||
private Task countdownTask = Task.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Skips to the end of the currently-running countdown, if one is running,
|
||||
/// and runs the callback (e.g. to start the match) as soon as possible unless the countdown has been cancelled.
|
||||
/// </summary>
|
||||
public void SkipToEndOfCountdown() => countdownSkipSource?.Cancel();
|
||||
|
||||
public override async Task SendMatchRequest(MatchUserRequest request)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
@ -289,6 +314,67 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
switch (request)
|
||||
{
|
||||
case StartMatchCountdownRequest matchCountdownRequest:
|
||||
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||
|
||||
countdownStopSource?.Cancel();
|
||||
|
||||
// Note that this will leak CTSs, however this is a test method and we haven't noticed foregoing disposal of non-linked CTSs to be detrimental.
|
||||
// If necessary, this can be moved into the final schedule below, and the class-level fields be nulled out accordingly.
|
||||
var stopSource = countdownStopSource = new CancellationTokenSource();
|
||||
var skipSource = countdownSkipSource = new CancellationTokenSource();
|
||||
var countdown = new MatchStartCountdown { TimeRemaining = matchCountdownRequest.Duration };
|
||||
|
||||
Task lastCountdownTask = countdownTask;
|
||||
countdownTask = start();
|
||||
|
||||
async Task start()
|
||||
{
|
||||
await lastCountdownTask;
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
if (stopSource.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
Room.Countdown = countdown;
|
||||
MatchEvent(new CountdownChangedEvent { Countdown = countdown });
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
using (var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(stopSource.Token, skipSource.Token))
|
||||
await Task.Delay(matchCountdownRequest.Duration, cancellationSource.Token).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Clients need to be notified of cancellations in the following code.
|
||||
}
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
if (Room.Countdown != countdown)
|
||||
return;
|
||||
|
||||
Room.Countdown = null;
|
||||
MatchEvent(new CountdownChangedEvent { Countdown = null });
|
||||
|
||||
if (stopSource.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
StartMatch().WaitSafely();
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case StopCountdownRequest _:
|
||||
countdownStopSource?.Cancel();
|
||||
|
||||
Room.Countdown = null;
|
||||
await MatchEvent(new CountdownChangedEvent { Countdown = Room.Countdown });
|
||||
break;
|
||||
|
||||
case ChangeTeamRequest changeTeam:
|
||||
|
||||
TeamVersusRoomState roomState = (TeamVersusRoomState)Room.MatchState!;
|
||||
|
@ -36,8 +36,8 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Realm" Version="10.10.0" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2022.314.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.304.0" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2022.325.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.325.0" />
|
||||
<PackageReference Include="Sentry" Version="3.14.1" />
|
||||
<PackageReference Include="SharpCompress" Version="0.30.1" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
|
@ -61,8 +61,8 @@
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="ppy.osu.Framework.iOS" Version="2022.314.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.304.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.iOS" Version="2022.325.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.325.0" />
|
||||
</ItemGroup>
|
||||
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net6.0) -->
|
||||
<PropertyGroup>
|
||||
@ -84,7 +84,7 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.14" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="5.0.14" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2022.314.0" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2022.325.0" />
|
||||
<PackageReference Include="SharpCompress" Version="0.30.1" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||
|
Loading…
Reference in New Issue
Block a user