mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 09:02:58 +08:00
Merge branch 'master' into instant-pause-on-focus-loss
This commit is contained in:
commit
93f1a3c1bf
@ -5,7 +5,7 @@
|
||||
# osu!
|
||||
|
||||
[![Build status](https://ci.appveyor.com/api/projects/status/u2p01nx7l6og8buh?svg=true)](https://ci.appveyor.com/project/peppy/osu)
|
||||
[![GitHub release](https://img.shields.io/github/release/ppy/osu.svg)]()
|
||||
[![GitHub release](https://img.shields.io/github/release/ppy/osu.svg)](https://github.com/ppy/osu/releases/latest)
|
||||
[![CodeFactor](https://www.codefactor.io/repository/github/ppy/osu/badge)](https://www.codefactor.io/repository/github/ppy/osu)
|
||||
[![dev chat](https://discordapp.com/api/guilds/188630481301012481/widget.png?style=shield)](https://discord.gg/ppy)
|
||||
|
||||
|
@ -29,4 +29,3 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,4 +19,3 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
// 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.Testing;
|
||||
using osu.Game.Rulesets.Mania.Mods;
|
||||
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
||||
using osu.Game.Rulesets.UI.Scrolling;
|
||||
using osu.Game.Rulesets.UI.Scrolling.Algorithms;
|
||||
using osu.Game.Tests.Visual;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Tests.Mods
|
||||
{
|
||||
public class TestSceneManiaModConstantSpeed : ModTestScene
|
||||
{
|
||||
protected override Ruleset CreatePlayerRuleset() => new ManiaRuleset();
|
||||
|
||||
[Test]
|
||||
public void TestConstantScroll() => CreateModTest(new ModTestData
|
||||
{
|
||||
Mod = new ManiaModConstantSpeed(),
|
||||
PassCondition = () =>
|
||||
{
|
||||
var hitObject = Player.ChildrenOfType<DrawableManiaHitObject>().FirstOrDefault();
|
||||
return hitObject?.Dependencies.Get<IScrollingInfo>().Algorithm is ConstantScrollAlgorithm;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -238,6 +238,7 @@ namespace osu.Game.Rulesets.Mania
|
||||
new ManiaModMirror(),
|
||||
new ManiaModDifficultyAdjust(),
|
||||
new ManiaModInvert(),
|
||||
new ManiaModConstantSpeed()
|
||||
};
|
||||
|
||||
case ModType.Automation:
|
||||
|
35
osu.Game.Rulesets.Mania/Mods/ManiaModConstantSpeed.cs
Normal file
35
osu.Game.Rulesets.Mania/Mods/ManiaModConstantSpeed.cs
Normal file
@ -0,0 +1,35 @@
|
||||
// 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 osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets.Mania.Objects;
|
||||
using osu.Game.Rulesets.Mania.UI;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Mods
|
||||
{
|
||||
public class ManiaModConstantSpeed : Mod, IApplicableToDrawableRuleset<ManiaHitObject>
|
||||
{
|
||||
public override string Name => "Constant Speed";
|
||||
|
||||
public override string Acronym => "CS";
|
||||
|
||||
public override double ScoreMultiplier => 1;
|
||||
|
||||
public override string Description => "No more tricky speed changes!";
|
||||
|
||||
public override IconUsage? Icon => FontAwesome.Solid.Equals;
|
||||
|
||||
public override ModType Type => ModType.Conversion;
|
||||
|
||||
public override bool Ranked => false;
|
||||
|
||||
public void ApplyToDrawableRuleset(DrawableRuleset<ManiaHitObject> drawableRuleset)
|
||||
{
|
||||
var maniaRuleset = (DrawableManiaRuleset)drawableRuleset;
|
||||
maniaRuleset.ScrollMethod = ScrollVisualisationMethod.Constant;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
@ -11,6 +12,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Input.Handlers;
|
||||
using osu.Game.Replays;
|
||||
using osu.Game.Rulesets.Mania.Beatmaps;
|
||||
@ -49,6 +51,22 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
|
||||
protected new ManiaRulesetConfigManager Config => (ManiaRulesetConfigManager)base.Config;
|
||||
|
||||
public ScrollVisualisationMethod ScrollMethod
|
||||
{
|
||||
get => scrollMethod;
|
||||
set
|
||||
{
|
||||
if (IsLoaded)
|
||||
throw new InvalidOperationException($"Can't alter {nameof(ScrollMethod)} after ruleset is already loaded");
|
||||
|
||||
scrollMethod = value;
|
||||
}
|
||||
}
|
||||
|
||||
private ScrollVisualisationMethod scrollMethod = ScrollVisualisationMethod.Sequential;
|
||||
|
||||
protected override ScrollVisualisationMethod VisualisationMethod => scrollMethod;
|
||||
|
||||
private readonly Bindable<ManiaScrollingDirection> configDirection = new Bindable<ManiaScrollingDirection>();
|
||||
private readonly Bindable<double> configTimeRange = new BindableDouble();
|
||||
|
||||
|
@ -16,7 +16,7 @@ using osu.Game.Rulesets.UI;
|
||||
namespace osu.Game.Tests.Online
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestAPIModSerialization
|
||||
public class TestAPIModJsonSerialization
|
||||
{
|
||||
[Test]
|
||||
public void TestAcronymIsPreserved()
|
139
osu.Game.Tests/Online/TestAPIModMessagePackSerialization.cs
Normal file
139
osu.Game.Tests/Online/TestAPIModMessagePackSerialization.cs
Normal file
@ -0,0 +1,139 @@
|
||||
// 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.Collections.Generic;
|
||||
using MessagePack;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Tests.Online
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestAPIModMessagePackSerialization
|
||||
{
|
||||
[Test]
|
||||
public void TestAcronymIsPreserved()
|
||||
{
|
||||
var apiMod = new APIMod(new TestMod());
|
||||
|
||||
var deserialized = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
||||
|
||||
Assert.That(deserialized.Acronym, Is.EqualTo(apiMod.Acronym));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRawSettingIsPreserved()
|
||||
{
|
||||
var apiMod = new APIMod(new TestMod { TestSetting = { Value = 2 } });
|
||||
|
||||
var deserialized = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
||||
|
||||
Assert.That(deserialized.Settings, Contains.Key("test_setting").With.ContainValue(2.0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestConvertedModHasCorrectSetting()
|
||||
{
|
||||
var apiMod = new APIMod(new TestMod { TestSetting = { Value = 2 } });
|
||||
|
||||
var deserialized = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
||||
var converted = (TestMod)deserialized.ToMod(new TestRuleset());
|
||||
|
||||
Assert.That(converted.TestSetting.Value, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserialiseTimeRampMod()
|
||||
{
|
||||
// Create the mod with values different from default.
|
||||
var apiMod = new APIMod(new TestModTimeRamp
|
||||
{
|
||||
AdjustPitch = { Value = false },
|
||||
InitialRate = { Value = 1.25 },
|
||||
FinalRate = { Value = 0.25 }
|
||||
});
|
||||
|
||||
var deserialised = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
||||
var converted = (TestModTimeRamp)deserialised.ToMod(new TestRuleset());
|
||||
|
||||
Assert.That(converted.AdjustPitch.Value, Is.EqualTo(false));
|
||||
Assert.That(converted.InitialRate.Value, Is.EqualTo(1.25));
|
||||
Assert.That(converted.FinalRate.Value, Is.EqualTo(0.25));
|
||||
}
|
||||
|
||||
private class TestRuleset : Ruleset
|
||||
{
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type) => new Mod[]
|
||||
{
|
||||
new TestMod(),
|
||||
new TestModTimeRamp(),
|
||||
};
|
||||
|
||||
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => throw new System.NotImplementedException();
|
||||
|
||||
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new System.NotImplementedException();
|
||||
|
||||
public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new System.NotImplementedException();
|
||||
|
||||
public override string Description { get; } = string.Empty;
|
||||
public override string ShortName { get; } = string.Empty;
|
||||
}
|
||||
|
||||
private class TestMod : Mod
|
||||
{
|
||||
public override string Name => "Test Mod";
|
||||
public override string Acronym => "TM";
|
||||
public override double ScoreMultiplier => 1;
|
||||
|
||||
[SettingSource("Test")]
|
||||
public BindableNumber<double> TestSetting { get; } = new BindableDouble
|
||||
{
|
||||
MinValue = 0,
|
||||
MaxValue = 10,
|
||||
Default = 5,
|
||||
Precision = 0.01,
|
||||
};
|
||||
}
|
||||
|
||||
private class TestModTimeRamp : ModTimeRamp
|
||||
{
|
||||
public override string Name => "Test Mod";
|
||||
public override string Acronym => "TMTR";
|
||||
public override double ScoreMultiplier => 1;
|
||||
|
||||
[SettingSource("Initial rate", "The starting speed of the track")]
|
||||
public override BindableNumber<double> InitialRate { get; } = new BindableDouble
|
||||
{
|
||||
MinValue = 1,
|
||||
MaxValue = 2,
|
||||
Default = 1.5,
|
||||
Value = 1.5,
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
[SettingSource("Final rate", "The speed increase to ramp towards")]
|
||||
public override BindableNumber<double> FinalRate { get; } = new BindableDouble
|
||||
{
|
||||
MinValue = 0,
|
||||
MaxValue = 1,
|
||||
Default = 0.5,
|
||||
Value = 0.5,
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
[SettingSource("Adjust pitch", "Should pitch be adjusted with speed")]
|
||||
public override BindableBool AdjustPitch { get; } = new BindableBool
|
||||
{
|
||||
Default = true,
|
||||
Value = true
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,188 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Formats;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.IO.Archives;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Tests.Resources;
|
||||
using osu.Game.Tests.Visual;
|
||||
|
||||
namespace osu.Game.Tests.Online
|
||||
{
|
||||
[HeadlessTest]
|
||||
public class TestSceneOnlinePlayBeatmapAvailabilityTracker : OsuTestScene
|
||||
{
|
||||
private RulesetStore rulesets;
|
||||
private TestBeatmapManager beatmaps;
|
||||
|
||||
private string testBeatmapFile;
|
||||
private BeatmapInfo testBeatmapInfo;
|
||||
private BeatmapSetInfo testBeatmapSet;
|
||||
|
||||
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
||||
private OnlinePlayBeatmapAvailablilityTracker availablilityTracker;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio, GameHost host)
|
||||
{
|
||||
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
||||
Dependencies.CacheAs<BeatmapManager>(beatmaps = new TestBeatmapManager(LocalStorage, ContextFactory, rulesets, API, audio, host, Beatmap.Default));
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() => Schedule(() =>
|
||||
{
|
||||
beatmaps.AllowImport = new TaskCompletionSource<bool>();
|
||||
|
||||
testBeatmapFile = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
testBeatmapInfo = getTestBeatmapInfo(testBeatmapFile);
|
||||
testBeatmapSet = testBeatmapInfo.BeatmapSet;
|
||||
|
||||
var existing = beatmaps.QueryBeatmapSet(s => s.OnlineBeatmapSetID == testBeatmapSet.OnlineBeatmapSetID);
|
||||
if (existing != null)
|
||||
beatmaps.Delete(existing);
|
||||
|
||||
selectedItem.Value = new PlaylistItem
|
||||
{
|
||||
Beatmap = { Value = testBeatmapInfo },
|
||||
Ruleset = { Value = testBeatmapInfo.Ruleset },
|
||||
};
|
||||
|
||||
Child = availablilityTracker = new OnlinePlayBeatmapAvailablilityTracker
|
||||
{
|
||||
SelectedItem = { BindTarget = selectedItem, }
|
||||
};
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestBeatmapDownloadingFlow()
|
||||
{
|
||||
AddAssert("ensure beatmap unavailable", () => !beatmaps.IsAvailableLocally(testBeatmapSet));
|
||||
addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded);
|
||||
|
||||
AddStep("start downloading", () => beatmaps.Download(testBeatmapSet));
|
||||
addAvailabilityCheckStep("state downloading 0%", () => BeatmapAvailability.Downloading(0.0f));
|
||||
|
||||
AddStep("set progress 40%", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).SetProgress(0.4f));
|
||||
addAvailabilityCheckStep("state downloading 40%", () => BeatmapAvailability.Downloading(0.4f));
|
||||
|
||||
AddStep("finish download", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).TriggerSuccess(testBeatmapFile));
|
||||
addAvailabilityCheckStep("state importing", BeatmapAvailability.Importing);
|
||||
|
||||
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
|
||||
AddUntilStep("wait for import", () => beatmaps.CurrentImportTask?.IsCompleted == true);
|
||||
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTrackerRespectsSoftDeleting()
|
||||
{
|
||||
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
|
||||
AddStep("import beatmap", () => beatmaps.Import(testBeatmapFile).Wait());
|
||||
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
|
||||
|
||||
AddStep("delete beatmap", () => beatmaps.Delete(beatmaps.QueryBeatmapSet(b => b.OnlineBeatmapSetID == testBeatmapSet.OnlineBeatmapSetID)));
|
||||
addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded);
|
||||
|
||||
AddStep("undelete beatmap", () => beatmaps.Undelete(beatmaps.QueryBeatmapSet(b => b.OnlineBeatmapSetID == testBeatmapSet.OnlineBeatmapSetID)));
|
||||
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTrackerRespectsChecksum()
|
||||
{
|
||||
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
|
||||
|
||||
AddStep("import altered beatmap", () =>
|
||||
{
|
||||
beatmaps.Import(TestResources.GetTestBeatmapForImport(true)).Wait();
|
||||
});
|
||||
addAvailabilityCheckStep("state still not downloaded", BeatmapAvailability.NotDownloaded);
|
||||
|
||||
AddStep("recreate tracker", () => Child = availablilityTracker = new OnlinePlayBeatmapAvailablilityTracker
|
||||
{
|
||||
SelectedItem = { BindTarget = selectedItem }
|
||||
});
|
||||
addAvailabilityCheckStep("state not downloaded as well", BeatmapAvailability.NotDownloaded);
|
||||
}
|
||||
|
||||
private void addAvailabilityCheckStep(string description, Func<BeatmapAvailability> expected)
|
||||
{
|
||||
AddAssert(description, () => availablilityTracker.Availability.Value.Equals(expected.Invoke()));
|
||||
}
|
||||
|
||||
private static BeatmapInfo getTestBeatmapInfo(string archiveFile)
|
||||
{
|
||||
BeatmapInfo info;
|
||||
|
||||
using (var archive = new ZipArchiveReader(File.OpenRead(archiveFile)))
|
||||
using (var stream = archive.GetStream("Soleily - Renatus (Gamu) [Insane].osu"))
|
||||
using (var reader = new LineBufferedReader(stream))
|
||||
{
|
||||
var decoder = Decoder.GetDecoder<Beatmap>(reader);
|
||||
var beatmap = decoder.Decode(reader);
|
||||
|
||||
info = beatmap.BeatmapInfo;
|
||||
info.BeatmapSet.Beatmaps = new List<BeatmapInfo> { info };
|
||||
info.BeatmapSet.Metadata = info.Metadata;
|
||||
info.MD5Hash = stream.ComputeMD5Hash();
|
||||
info.Hash = stream.ComputeSHA2Hash();
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
private class TestBeatmapManager : BeatmapManager
|
||||
{
|
||||
public TaskCompletionSource<bool> AllowImport = new TaskCompletionSource<bool>();
|
||||
|
||||
public Task<BeatmapSetInfo> CurrentImportTask { get; private set; }
|
||||
|
||||
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize)
|
||||
=> new TestDownloadRequest(set);
|
||||
|
||||
public TestBeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, GameHost host = null, WorkingBeatmap defaultBeatmap = null, bool performOnlineLookups = false)
|
||||
: base(storage, contextFactory, rulesets, api, audioManager, host, defaultBeatmap, performOnlineLookups)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task<BeatmapSetInfo> Import(BeatmapSetInfo item, ArchiveReader archive = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await AllowImport.Task;
|
||||
return await (CurrentImportTask = base.Import(item, archive, cancellationToken));
|
||||
}
|
||||
}
|
||||
|
||||
private class TestDownloadRequest : ArchiveDownloadRequest<BeatmapSetInfo>
|
||||
{
|
||||
public new void SetProgress(float progress) => base.SetProgress(progress);
|
||||
public new void TriggerSuccess(string filename) => base.TriggerSuccess(filename);
|
||||
|
||||
public TestDownloadRequest(BeatmapSetInfo model)
|
||||
: base(model)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string Target => null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Screens.OnlinePlay;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneFreeModSelectOverlay : MultiplayerTestScene
|
||||
{
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
Child = new FreeModSelectOverlay
|
||||
{
|
||||
State = { Value = Visibility.Visible }
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
@ -8,6 +8,8 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
|
||||
using osu.Game.Users;
|
||||
using osuTK;
|
||||
@ -123,5 +125,32 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUserWithMods()
|
||||
{
|
||||
AddStep("add user", () =>
|
||||
{
|
||||
Client.AddUser(new User
|
||||
{
|
||||
Id = 0,
|
||||
Username = "User 0",
|
||||
CurrentModeRank = RNG.Next(1, 100000),
|
||||
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
|
||||
});
|
||||
|
||||
Client.ChangeUserMods(0, new Mod[]
|
||||
{
|
||||
new OsuModHardRock(),
|
||||
new OsuModDifficultyAdjust { ApproachRate = { Value = 1 } }
|
||||
});
|
||||
});
|
||||
|
||||
for (var i = MultiplayerUserState.Idle; i < MultiplayerUserState.Results; i++)
|
||||
{
|
||||
var state = i;
|
||||
AddStep($"set state: {state}", () => Client.ChangeUserState(0, state));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
@ -26,8 +27,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
public class TestSceneMultiplayerReadyButton : MultiplayerTestScene
|
||||
{
|
||||
private MultiplayerReadyButton button;
|
||||
private OnlinePlayBeatmapAvailablilityTracker beatmapTracker;
|
||||
private BeatmapSetInfo importedSet;
|
||||
|
||||
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
||||
|
||||
private BeatmapManager beatmaps;
|
||||
private RulesetStore rulesets;
|
||||
|
||||
@ -39,6 +43,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
||||
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, host, Beatmap.Default));
|
||||
beatmaps.Import(TestResources.GetTestBeatmapForImport(true)).Wait();
|
||||
|
||||
Add(beatmapTracker = new OnlinePlayBeatmapAvailablilityTracker
|
||||
{
|
||||
SelectedItem = { BindTarget = selectedItem }
|
||||
});
|
||||
|
||||
Dependencies.Cache(beatmapTracker);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@ -46,20 +57,20 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
|
||||
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
|
||||
selectedItem.Value = new PlaylistItem
|
||||
{
|
||||
Beatmap = { Value = Beatmap.Value.BeatmapInfo },
|
||||
Ruleset = { Value = Beatmap.Value.BeatmapInfo.Ruleset },
|
||||
};
|
||||
|
||||
Child = button = new MultiplayerReadyButton
|
||||
if (button != null)
|
||||
Remove(button);
|
||||
|
||||
Add(button = new MultiplayerReadyButton
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200, 50),
|
||||
SelectedItem =
|
||||
{
|
||||
Value = new PlaylistItem
|
||||
{
|
||||
Beatmap = { Value = Beatmap.Value.BeatmapInfo },
|
||||
Ruleset = { Value = Beatmap.Value.BeatmapInfo.Ruleset }
|
||||
}
|
||||
},
|
||||
OnReadyClick = async () =>
|
||||
{
|
||||
readyClickOperation = OngoingOperationTracker.BeginOperation();
|
||||
@ -73,7 +84,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
await Client.ToggleReady();
|
||||
readyClickOperation.Dispose();
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
[Test]
|
||||
|
@ -19,11 +19,11 @@ using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.Select;
|
||||
using osu.Game.Screens.OnlinePlay.Playlists;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMatchSongSelect : RoomTestScene
|
||||
public class TestScenePlaylistsSongSelect : RoomTestScene
|
||||
{
|
||||
[Resolved]
|
||||
private BeatmapManager beatmapManager { get; set; }
|
||||
@ -32,7 +32,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
private RulesetStore rulesets;
|
||||
|
||||
private TestMatchSongSelect songSelect;
|
||||
private TestPlaylistsSongSelect songSelect;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
@ -89,7 +89,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Beatmap.SetDefault();
|
||||
});
|
||||
|
||||
AddStep("create song select", () => LoadScreen(songSelect = new TestMatchSongSelect()));
|
||||
AddStep("create song select", () => LoadScreen(songSelect = new TestPlaylistsSongSelect()));
|
||||
AddUntilStep("wait for present", () => songSelect.IsCurrentScreen());
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddAssert("item has rate 1.5", () => Precision.AlmostEquals(1.5, ((OsuModDoubleTime)Room.Playlist.First().RequiredMods[0]).SpeedChange.Value));
|
||||
}
|
||||
|
||||
private class TestMatchSongSelect : MatchSongSelect
|
||||
private class TestPlaylistsSongSelect : PlaylistsSongSelect
|
||||
{
|
||||
public new MatchBeatmapDetailArea BeatmapDetails => (MatchBeatmapDetailArea)base.BeatmapDetails;
|
||||
}
|
@ -8,6 +8,7 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -46,6 +47,32 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddStep("show", () => modSelect.Show());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAnimationFlushOnClose()
|
||||
{
|
||||
changeRuleset(0);
|
||||
|
||||
AddStep("Select all fun mods", () =>
|
||||
{
|
||||
modSelect.ModSectionsContainer
|
||||
.Single(c => c.ModType == ModType.DifficultyIncrease)
|
||||
.SelectAll();
|
||||
});
|
||||
|
||||
AddUntilStep("many mods selected", () => modDisplay.Current.Value.Count >= 5);
|
||||
|
||||
AddStep("trigger deselect and close overlay", () =>
|
||||
{
|
||||
modSelect.ModSectionsContainer
|
||||
.Single(c => c.ModType == ModType.DifficultyIncrease)
|
||||
.DeselectAll();
|
||||
|
||||
modSelect.Hide();
|
||||
});
|
||||
|
||||
AddAssert("all mods deselected", () => modDisplay.Current.Value.Count == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOsuMods()
|
||||
{
|
||||
@ -145,11 +172,11 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddAssert("double time visible", () => modSelect.ChildrenOfType<ModButton>().Any(b => b.Mods.Any(m => m is OsuModDoubleTime)));
|
||||
|
||||
AddStep("make double time invalid", () => modSelect.IsValidMod = m => !(m is OsuModDoubleTime));
|
||||
AddAssert("double time not visible", () => modSelect.ChildrenOfType<ModButton>().All(b => !b.Mods.Any(m => m is OsuModDoubleTime)));
|
||||
AddUntilStep("double time not visible", () => modSelect.ChildrenOfType<ModButton>().All(b => !b.Mods.Any(m => m is OsuModDoubleTime)));
|
||||
AddAssert("nightcore still visible", () => modSelect.ChildrenOfType<ModButton>().Any(b => b.Mods.Any(m => m is OsuModNightcore)));
|
||||
|
||||
AddStep("make double time valid again", () => modSelect.IsValidMod = m => true);
|
||||
AddAssert("double time visible", () => modSelect.ChildrenOfType<ModButton>().Any(b => b.Mods.Any(m => m is OsuModDoubleTime)));
|
||||
AddUntilStep("double time visible", () => modSelect.ChildrenOfType<ModButton>().Any(b => b.Mods.Any(m => m is OsuModDoubleTime)));
|
||||
AddAssert("nightcore still visible", () => modSelect.ChildrenOfType<ModButton>().Any(b => b.Mods.Any(m => m is OsuModNightcore)));
|
||||
}
|
||||
|
||||
@ -306,12 +333,15 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
};
|
||||
}
|
||||
|
||||
private class TestModSelectOverlay : SoloModSelectOverlay
|
||||
private class TestModSelectOverlay : LocalPlayerModSelectOverlay
|
||||
{
|
||||
public new Bindable<IReadOnlyList<Mod>> SelectedMods => base.SelectedMods;
|
||||
|
||||
public bool AllLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded);
|
||||
|
||||
public new FillFlowContainer<ModSection> ModSectionsContainer =>
|
||||
base.ModSectionsContainer;
|
||||
|
||||
public ModButton GetModButton(Mod mod)
|
||||
{
|
||||
var section = ModSectionsContainer.Children.Single(s => s.ModType == mod.Type);
|
||||
|
@ -151,7 +151,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddUntilStep("wait for ready", () => modSelect.State.Value == Visibility.Visible && modSelect.ButtonsLoaded);
|
||||
}
|
||||
|
||||
private class TestModSelectOverlay : SoloModSelectOverlay
|
||||
private class TestModSelectOverlay : LocalPlayerModSelectOverlay
|
||||
{
|
||||
public new VisibilityContainer ModSettingsContainer => base.ModSettingsContainer;
|
||||
public new TriangleButton CustomiseButton => base.CustomiseButton;
|
||||
|
@ -308,7 +308,7 @@ namespace osu.Game.Database
|
||||
/// <param name="item">The model to be imported.</param>
|
||||
/// <param name="archive">An optional archive to use for model population.</param>
|
||||
/// <param name="cancellationToken">An optional cancellation token.</param>
|
||||
public async Task<TModel> Import(TModel item, ArchiveReader archive = null, CancellationToken cancellationToken = default) => await Task.Factory.StartNew(async () =>
|
||||
public virtual async Task<TModel> Import(TModel item, ArchiveReader archive = null, CancellationToken cancellationToken = default) => await Task.Factory.StartNew(async () =>
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
|
@ -42,13 +42,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
},
|
||||
};
|
||||
|
||||
Current.ValueChanged += filled =>
|
||||
{
|
||||
if (filled.NewValue)
|
||||
fill.FadeIn(200, Easing.OutQuint);
|
||||
else
|
||||
fill.FadeTo(0.01f, 200, Easing.OutQuint); //todo: remove once we figure why containers aren't drawing at all times
|
||||
};
|
||||
Current.ValueChanged += filled => fill.FadeTo(filled.NewValue ? 1 : 0, 200, Easing.OutQuint);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -5,6 +5,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics.Containers;
|
||||
@ -18,6 +19,11 @@ namespace osu.Game.Graphics.UserInterface
|
||||
public Color4 UncheckedColor { get; set; } = Color4.White;
|
||||
public int FadeDuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to play sounds when the state changes as a result of user interaction.
|
||||
/// </summary>
|
||||
protected virtual bool PlaySoundsOnUserChange => true;
|
||||
|
||||
public string LabelText
|
||||
{
|
||||
set
|
||||
@ -43,7 +49,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
private SampleChannel sampleChecked;
|
||||
private SampleChannel sampleUnchecked;
|
||||
|
||||
public OsuCheckbox()
|
||||
public OsuCheckbox(bool nubOnRight = true)
|
||||
{
|
||||
AutoSizeAxes = Axes.Y;
|
||||
RelativeSizeAxes = Axes.X;
|
||||
@ -52,26 +58,42 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
labelText = new OsuTextFlowContainer
|
||||
labelText = new OsuTextFlowContainer(ApplyLabelParameters)
|
||||
{
|
||||
AutoSizeAxes = Axes.Y,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Padding = new MarginPadding { Right = Nub.EXPANDED_SIZE + nub_padding }
|
||||
},
|
||||
Nub = new Nub
|
||||
{
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
Margin = new MarginPadding { Right = nub_padding },
|
||||
},
|
||||
Nub = new Nub(),
|
||||
new HoverClickSounds()
|
||||
};
|
||||
|
||||
if (nubOnRight)
|
||||
{
|
||||
Nub.Anchor = Anchor.CentreRight;
|
||||
Nub.Origin = Anchor.CentreRight;
|
||||
Nub.Margin = new MarginPadding { Right = nub_padding };
|
||||
labelText.Padding = new MarginPadding { Right = Nub.EXPANDED_SIZE + nub_padding * 2 };
|
||||
}
|
||||
else
|
||||
{
|
||||
Nub.Anchor = Anchor.CentreLeft;
|
||||
Nub.Origin = Anchor.CentreLeft;
|
||||
Nub.Margin = new MarginPadding { Left = nub_padding };
|
||||
labelText.Padding = new MarginPadding { Left = Nub.EXPANDED_SIZE + nub_padding * 2 };
|
||||
}
|
||||
|
||||
Nub.Current.BindTo(Current);
|
||||
|
||||
Current.DisabledChanged += disabled => labelText.Alpha = Nub.Alpha = disabled ? 0.3f : 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A function which can be overridden to change the parameters of the label's text.
|
||||
/// </summary>
|
||||
protected virtual void ApplyLabelParameters(SpriteText text)
|
||||
{
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
@ -96,10 +118,14 @@ namespace osu.Game.Graphics.UserInterface
|
||||
protected override void OnUserChange(bool value)
|
||||
{
|
||||
base.OnUserChange(value);
|
||||
if (value)
|
||||
sampleChecked?.Play();
|
||||
else
|
||||
sampleUnchecked?.Play();
|
||||
|
||||
if (PlaySoundsOnUserChange)
|
||||
{
|
||||
if (value)
|
||||
sampleChecked?.Play();
|
||||
else
|
||||
sampleUnchecked?.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.IO;
|
||||
using osu.Framework.IO.Network;
|
||||
|
||||
@ -28,13 +29,19 @@ namespace osu.Game.Online.API
|
||||
|
||||
private void request_Progress(long current, long total) => API.Schedule(() => Progressed?.Invoke(current, total));
|
||||
|
||||
protected APIDownloadRequest()
|
||||
protected void TriggerSuccess(string filename)
|
||||
{
|
||||
base.Success += onSuccess;
|
||||
if (this.filename != null)
|
||||
throw new InvalidOperationException("Attempted to trigger success more than once");
|
||||
|
||||
this.filename = filename;
|
||||
|
||||
TriggerSuccess();
|
||||
}
|
||||
|
||||
private void onSuccess()
|
||||
internal override void TriggerSuccess()
|
||||
{
|
||||
base.TriggerSuccess();
|
||||
Success?.Invoke(filename);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ namespace osu.Game.Online.API
|
||||
|
||||
[JsonProperty("settings")]
|
||||
[Key(1)]
|
||||
[MessagePackFormatter(typeof(ModSettingsDictionaryFormatter))]
|
||||
public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>();
|
||||
|
||||
[JsonConstructor]
|
||||
|
@ -10,7 +10,7 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
public readonly TModel Model;
|
||||
|
||||
public float Progress;
|
||||
public float Progress { get; private set; }
|
||||
|
||||
public event Action<float> DownloadProgressed;
|
||||
|
||||
@ -18,7 +18,13 @@ namespace osu.Game.Online.API
|
||||
{
|
||||
Model = model;
|
||||
|
||||
Progressed += (current, total) => DownloadProgressed?.Invoke(Progress = (float)current / total);
|
||||
Progressed += (current, total) => SetProgress((float)current / total);
|
||||
}
|
||||
|
||||
protected void SetProgress(float progress)
|
||||
{
|
||||
Progress = progress;
|
||||
DownloadProgressed?.Invoke(progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
67
osu.Game/Online/API/ModSettingsDictionaryFormatter.cs
Normal file
67
osu.Game/Online/API/ModSettingsDictionaryFormatter.cs
Normal file
@ -0,0 +1,67 @@
|
||||
// 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.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using MessagePack;
|
||||
using MessagePack.Formatters;
|
||||
using osu.Framework.Bindables;
|
||||
|
||||
namespace osu.Game.Online.API
|
||||
{
|
||||
public class ModSettingsDictionaryFormatter : IMessagePackFormatter<Dictionary<string, object>>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, Dictionary<string, object> value, MessagePackSerializerOptions options)
|
||||
{
|
||||
var primitiveFormatter = PrimitiveObjectFormatter.Instance;
|
||||
|
||||
writer.WriteArrayHeader(value.Count);
|
||||
|
||||
foreach (var kvp in value)
|
||||
{
|
||||
var stringBytes = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(kvp.Key));
|
||||
writer.WriteString(in stringBytes);
|
||||
|
||||
switch (kvp.Value)
|
||||
{
|
||||
case Bindable<double> d:
|
||||
primitiveFormatter.Serialize(ref writer, d.Value, options);
|
||||
break;
|
||||
|
||||
case Bindable<int> i:
|
||||
primitiveFormatter.Serialize(ref writer, i.Value, options);
|
||||
break;
|
||||
|
||||
case Bindable<float> f:
|
||||
primitiveFormatter.Serialize(ref writer, f.Value, options);
|
||||
break;
|
||||
|
||||
case Bindable<bool> b:
|
||||
primitiveFormatter.Serialize(ref writer, b.Value, options);
|
||||
break;
|
||||
|
||||
default:
|
||||
// fall back for non-bindable cases.
|
||||
primitiveFormatter.Serialize(ref writer, kvp.Value, options);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, object> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
var output = new Dictionary<string, object>();
|
||||
|
||||
int itemCount = reader.ReadArrayHeader();
|
||||
|
||||
for (int i = 0; i < itemCount; i++)
|
||||
{
|
||||
output[reader.ReadString()] =
|
||||
PrimitiveObjectFormatter.Instance.Deserialize(ref reader, options);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -20,7 +21,7 @@ namespace osu.Game.Online
|
||||
protected readonly Bindable<TModel> Model = new Bindable<TModel>();
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private TModelManager manager { get; set; }
|
||||
protected TModelManager Manager { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the current download state of the <typeparamref name="TModel"/>, whether is has already been downloaded, is in progress, or is not downloaded.
|
||||
@ -46,25 +47,41 @@ namespace osu.Game.Online
|
||||
{
|
||||
if (modelInfo.NewValue == null)
|
||||
attachDownload(null);
|
||||
else if (manager?.IsAvailableLocally(modelInfo.NewValue) == true)
|
||||
else if (IsModelAvailableLocally())
|
||||
State.Value = DownloadState.LocallyAvailable;
|
||||
else
|
||||
attachDownload(manager?.GetExistingDownload(modelInfo.NewValue));
|
||||
attachDownload(Manager?.GetExistingDownload(modelInfo.NewValue));
|
||||
}, true);
|
||||
|
||||
if (manager == null)
|
||||
if (Manager == null)
|
||||
return;
|
||||
|
||||
managerDownloadBegan = manager.DownloadBegan.GetBoundCopy();
|
||||
managerDownloadBegan = Manager.DownloadBegan.GetBoundCopy();
|
||||
managerDownloadBegan.BindValueChanged(downloadBegan);
|
||||
managerDownloadFailed = manager.DownloadFailed.GetBoundCopy();
|
||||
managerDownloadFailed = Manager.DownloadFailed.GetBoundCopy();
|
||||
managerDownloadFailed.BindValueChanged(downloadFailed);
|
||||
managedUpdated = manager.ItemUpdated.GetBoundCopy();
|
||||
managedUpdated = Manager.ItemUpdated.GetBoundCopy();
|
||||
managedUpdated.BindValueChanged(itemUpdated);
|
||||
managerRemoved = manager.ItemRemoved.GetBoundCopy();
|
||||
managerRemoved = Manager.ItemRemoved.GetBoundCopy();
|
||||
managerRemoved.BindValueChanged(itemRemoved);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks that a database model matches the one expected to be downloaded.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// For online play, this could be used to check that the databased model matches the online beatmap.
|
||||
/// </example>
|
||||
/// <param name="databasedModel">The model in database.</param>
|
||||
protected virtual bool VerifyDatabasedModel([NotNull] TModel databasedModel) => true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the given model is available in the database.
|
||||
/// By default, this calls <see cref="IModelDownloader{TModel}.IsAvailableLocally"/>,
|
||||
/// but can be overriden to add additional checks for verifying the model in database.
|
||||
/// </summary>
|
||||
protected virtual bool IsModelAvailableLocally() => Manager?.IsAvailableLocally(Model.Value) == true;
|
||||
|
||||
private void downloadBegan(ValueChangedEvent<WeakReference<ArchiveDownloadRequest<TModel>>> weakRequest)
|
||||
{
|
||||
if (weakRequest.NewValue.TryGetTarget(out var request))
|
||||
@ -134,23 +151,35 @@ namespace osu.Game.Online
|
||||
private void itemUpdated(ValueChangedEvent<WeakReference<TModel>> weakItem)
|
||||
{
|
||||
if (weakItem.NewValue.TryGetTarget(out var item))
|
||||
setDownloadStateFromManager(item, DownloadState.LocallyAvailable);
|
||||
{
|
||||
Schedule(() =>
|
||||
{
|
||||
if (!item.Equals(Model.Value))
|
||||
return;
|
||||
|
||||
if (!VerifyDatabasedModel(item))
|
||||
{
|
||||
State.Value = DownloadState.NotDownloaded;
|
||||
return;
|
||||
}
|
||||
|
||||
State.Value = DownloadState.LocallyAvailable;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void itemRemoved(ValueChangedEvent<WeakReference<TModel>> weakItem)
|
||||
{
|
||||
if (weakItem.NewValue.TryGetTarget(out var item))
|
||||
setDownloadStateFromManager(item, DownloadState.NotDownloaded);
|
||||
{
|
||||
Schedule(() =>
|
||||
{
|
||||
if (item.Equals(Model.Value))
|
||||
State.Value = DownloadState.NotDownloaded;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void setDownloadStateFromManager(TModel s, DownloadState state) => Schedule(() =>
|
||||
{
|
||||
if (!s.Equals(Model.Value))
|
||||
return;
|
||||
|
||||
State.Value = state;
|
||||
});
|
||||
|
||||
#region Disposal
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
@ -1,7 +1,9 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
@ -55,6 +57,13 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <param name="beatmapAvailability">The new beatmap availability state of the user.</param>
|
||||
Task UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability);
|
||||
|
||||
/// <summary>
|
||||
/// Signals that a user in this room changed their local mods.
|
||||
/// </summary>
|
||||
/// <param name="userId">The ID of the user whose mods have changed.</param>
|
||||
/// <param name="mods">The user's new local mods.</param>
|
||||
Task UserModsChanged(int userId, IEnumerable<APIMod> mods);
|
||||
|
||||
/// <summary>
|
||||
/// Signals that a match is to be started. This will *only* be sent to clients which are to begin loading at this point.
|
||||
/// </summary>
|
||||
|
@ -1,7 +1,9 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
@ -47,6 +49,12 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <param name="newBeatmapAvailability">The proposed new beatmap availability state.</param>
|
||||
Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability);
|
||||
|
||||
/// <summary>
|
||||
/// Change the local user's mods in the currently joined room.
|
||||
/// </summary>
|
||||
/// <param name="newMods">The proposed new mods, excluding any required by the room itself.</param>
|
||||
Task ChangeUserMods(IEnumerable<APIMod> newMods);
|
||||
|
||||
/// <summary>
|
||||
/// As the host of a room, start the match.
|
||||
/// </summary>
|
||||
|
@ -4,7 +4,7 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
@ -26,11 +26,15 @@ namespace osu.Game.Online.Multiplayer
|
||||
private readonly Bindable<bool> isConnected = new Bindable<bool>();
|
||||
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
|
||||
|
||||
private readonly SemaphoreSlim connectionLock = new SemaphoreSlim(1);
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
private HubConnection? connection;
|
||||
|
||||
private CancellationTokenSource connectCancelSource = new CancellationTokenSource();
|
||||
|
||||
private readonly string endpoint;
|
||||
|
||||
public MultiplayerClient(EndpointConfiguration endpoints)
|
||||
@ -51,20 +55,21 @@ namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
case APIState.Failing:
|
||||
case APIState.Offline:
|
||||
connection?.StopAsync();
|
||||
connection = null;
|
||||
Task.Run(() => disconnect(true));
|
||||
break;
|
||||
|
||||
case APIState.Online:
|
||||
Task.Run(Connect);
|
||||
Task.Run(connect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual async Task Connect()
|
||||
private async Task connect()
|
||||
{
|
||||
if (connection != null)
|
||||
return;
|
||||
cancelExistingConnect();
|
||||
|
||||
if (!await connectionLock.WaitAsync(10000))
|
||||
throw new TimeoutException("Could not obtain a lock to connect. A previous attempt is likely stuck.");
|
||||
|
||||
var builder = new HubConnectionBuilder()
|
||||
.WithUrl(endpoint, options => { options.Headers.Add("Authorization", $"Bearer {api.AccessToken}"); });
|
||||
@ -80,57 +85,51 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
connection = builder.Build();
|
||||
|
||||
// this is kind of SILLY
|
||||
// https://github.com/dotnet/aspnetcore/issues/15198
|
||||
connection.On<MultiplayerRoomState>(nameof(IMultiplayerClient.RoomStateChanged), ((IMultiplayerClient)this).RoomStateChanged);
|
||||
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserJoined), ((IMultiplayerClient)this).UserJoined);
|
||||
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserLeft), ((IMultiplayerClient)this).UserLeft);
|
||||
connection.On<int>(nameof(IMultiplayerClient.HostChanged), ((IMultiplayerClient)this).HostChanged);
|
||||
connection.On<MultiplayerRoomSettings>(nameof(IMultiplayerClient.SettingsChanged), ((IMultiplayerClient)this).SettingsChanged);
|
||||
connection.On<int, MultiplayerUserState>(nameof(IMultiplayerClient.UserStateChanged), ((IMultiplayerClient)this).UserStateChanged);
|
||||
connection.On(nameof(IMultiplayerClient.LoadRequested), ((IMultiplayerClient)this).LoadRequested);
|
||||
connection.On(nameof(IMultiplayerClient.MatchStarted), ((IMultiplayerClient)this).MatchStarted);
|
||||
connection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady);
|
||||
|
||||
connection.Closed += async ex =>
|
||||
try
|
||||
{
|
||||
isConnected.Value = false;
|
||||
|
||||
Logger.Log(ex != null
|
||||
? $"Multiplayer client lost connection: {ex}"
|
||||
: "Multiplayer client disconnected", LoggingTarget.Network);
|
||||
|
||||
if (connection != null)
|
||||
await tryUntilConnected();
|
||||
};
|
||||
|
||||
await tryUntilConnected();
|
||||
|
||||
async Task tryUntilConnected()
|
||||
{
|
||||
Logger.Log("Multiplayer client connecting...", LoggingTarget.Network);
|
||||
|
||||
while (api.State.Value == APIState.Online)
|
||||
{
|
||||
// ensure any previous connection was disposed.
|
||||
// this will also create a new cancellation token source.
|
||||
await disconnect(false);
|
||||
|
||||
// this token will be valid for the scope of this connection.
|
||||
// if cancelled, we can be sure that a disconnect or reconnect is handled elsewhere.
|
||||
var cancellationToken = connectCancelSource.Token;
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
Logger.Log("Multiplayer client connecting...", LoggingTarget.Network);
|
||||
|
||||
try
|
||||
{
|
||||
Debug.Assert(connection != null);
|
||||
// importantly, rebuild the connection each attempt to get an updated access token.
|
||||
connection = createConnection(cancellationToken);
|
||||
|
||||
await connection.StartAsync(cancellationToken);
|
||||
|
||||
// reconnect on any failure
|
||||
await connection.StartAsync();
|
||||
Logger.Log("Multiplayer client connected!", LoggingTarget.Network);
|
||||
|
||||
// Success.
|
||||
isConnected.Value = true;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
//connection process was cancelled.
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log($"Multiplayer client connection error: {e}", LoggingTarget.Network);
|
||||
await Task.Delay(5000);
|
||||
|
||||
// retry on any failure.
|
||||
await Task.Delay(5000, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
connectionLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
protected override Task<MultiplayerRoom> JoinRoom(long roomId)
|
||||
@ -189,6 +188,14 @@ namespace osu.Game.Online.Multiplayer
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeBeatmapAvailability), newBeatmapAvailability);
|
||||
}
|
||||
|
||||
public override Task ChangeUserMods(IEnumerable<APIMod> newMods)
|
||||
{
|
||||
if (!isConnected.Value)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeUserMods), newMods);
|
||||
}
|
||||
|
||||
public override Task StartMatch()
|
||||
{
|
||||
if (!isConnected.Value)
|
||||
@ -196,5 +203,76 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.StartMatch));
|
||||
}
|
||||
|
||||
private async Task disconnect(bool takeLock)
|
||||
{
|
||||
cancelExistingConnect();
|
||||
|
||||
if (takeLock)
|
||||
{
|
||||
if (!await connectionLock.WaitAsync(10000))
|
||||
throw new TimeoutException("Could not obtain a lock to disconnect. A previous attempt is likely stuck.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (connection != null)
|
||||
await connection.DisposeAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
connection = null;
|
||||
if (takeLock)
|
||||
connectionLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelExistingConnect()
|
||||
{
|
||||
connectCancelSource.Cancel();
|
||||
connectCancelSource = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
private HubConnection createConnection(CancellationToken cancellationToken)
|
||||
{
|
||||
var newConnection = new HubConnectionBuilder()
|
||||
.WithUrl(endpoint, options => { options.Headers.Add("Authorization", $"Bearer {api.AccessToken}"); })
|
||||
.AddNewtonsoftJsonProtocol(options => { options.PayloadSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; })
|
||||
.Build();
|
||||
|
||||
// this is kind of SILLY
|
||||
// https://github.com/dotnet/aspnetcore/issues/15198
|
||||
newConnection.On<MultiplayerRoomState>(nameof(IMultiplayerClient.RoomStateChanged), ((IMultiplayerClient)this).RoomStateChanged);
|
||||
newConnection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserJoined), ((IMultiplayerClient)this).UserJoined);
|
||||
newConnection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserLeft), ((IMultiplayerClient)this).UserLeft);
|
||||
newConnection.On<int>(nameof(IMultiplayerClient.HostChanged), ((IMultiplayerClient)this).HostChanged);
|
||||
newConnection.On<MultiplayerRoomSettings>(nameof(IMultiplayerClient.SettingsChanged), ((IMultiplayerClient)this).SettingsChanged);
|
||||
newConnection.On<int, MultiplayerUserState>(nameof(IMultiplayerClient.UserStateChanged), ((IMultiplayerClient)this).UserStateChanged);
|
||||
newConnection.On(nameof(IMultiplayerClient.LoadRequested), ((IMultiplayerClient)this).LoadRequested);
|
||||
newConnection.On(nameof(IMultiplayerClient.MatchStarted), ((IMultiplayerClient)this).MatchStarted);
|
||||
newConnection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady);
|
||||
newConnection.On<int, IEnumerable<APIMod>>(nameof(IMultiplayerClient.UserModsChanged), ((IMultiplayerClient)this).UserModsChanged);
|
||||
|
||||
newConnection.Closed += ex =>
|
||||
{
|
||||
isConnected.Value = false;
|
||||
|
||||
Logger.Log(ex != null ? $"Multiplayer client lost connection: {ex}" : "Multiplayer client disconnected", LoggingTarget.Network);
|
||||
|
||||
// make sure a disconnect wasn't triggered (and this is still the active connection).
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
Task.Run(connect, default);
|
||||
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
return newConnection;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
cancelExistingConnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,15 +30,24 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
[NotNull]
|
||||
[Key(4)]
|
||||
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
|
||||
public IEnumerable<APIMod> RequiredMods { get; set; } = Enumerable.Empty<APIMod>();
|
||||
|
||||
[NotNull]
|
||||
[Key(5)]
|
||||
public IEnumerable<APIMod> AllowedMods { get; set; } = Enumerable.Empty<APIMod>();
|
||||
|
||||
public bool Equals(MultiplayerRoomSettings other)
|
||||
=> BeatmapID == other.BeatmapID
|
||||
&& BeatmapChecksum == other.BeatmapChecksum
|
||||
&& Mods.SequenceEqual(other.Mods)
|
||||
&& RequiredMods.SequenceEqual(other.RequiredMods)
|
||||
&& AllowedMods.SequenceEqual(other.AllowedMods)
|
||||
&& RulesetID == other.RulesetID
|
||||
&& Name.Equals(other.Name, StringComparison.Ordinal);
|
||||
|
||||
public override string ToString() => $"Name:{Name} Beatmap:{BeatmapID} ({BeatmapChecksum}) Mods:{string.Join(',', Mods)} Ruleset:{RulesetID}";
|
||||
public override string ToString() => $"Name:{Name}"
|
||||
+ $" Beatmap:{BeatmapID} ({BeatmapChecksum})"
|
||||
+ $" RequiredMods:{string.Join(',', RequiredMods)}"
|
||||
+ $" AllowedMods:{string.Join(',', AllowedMods)}"
|
||||
+ $" Ruleset:{RulesetID}";
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,12 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Users;
|
||||
|
||||
@ -27,6 +31,13 @@ namespace osu.Game.Online.Multiplayer
|
||||
[Key(2)]
|
||||
public BeatmapAvailability BeatmapAvailability { get; set; } = BeatmapAvailability.LocallyAvailable();
|
||||
|
||||
/// <summary>
|
||||
/// Any mods applicable only to the local user.
|
||||
/// </summary>
|
||||
[Key(3)]
|
||||
[NotNull]
|
||||
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
|
||||
|
||||
[IgnoreMember]
|
||||
public User? User { get; set; }
|
||||
|
||||
|
@ -21,6 +21,7 @@ using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Online.Rooms.RoomStatuses;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Utils;
|
||||
|
||||
@ -191,7 +192,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
BeatmapID = item.GetOr(existingPlaylistItem).BeatmapID,
|
||||
BeatmapChecksum = item.GetOr(existingPlaylistItem).Beatmap.Value.MD5Hash,
|
||||
RulesetID = item.GetOr(existingPlaylistItem).RulesetID,
|
||||
Mods = item.HasValue ? item.Value.AsNonNull().RequiredMods.Select(m => new APIMod(m)).ToList() : Room.Settings.Mods
|
||||
RequiredMods = item.HasValue ? item.Value.AsNonNull().RequiredMods.Select(m => new APIMod(m)).ToList() : Room.Settings.RequiredMods,
|
||||
AllowedMods = item.HasValue ? item.Value.AsNonNull().AllowedMods.Select(m => new APIMod(m)).ToList() : Room.Settings.AllowedMods
|
||||
});
|
||||
}
|
||||
|
||||
@ -229,6 +231,14 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
public abstract Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability);
|
||||
|
||||
/// <summary>
|
||||
/// Change the local user's mods in the currently joined room.
|
||||
/// </summary>
|
||||
/// <param name="newMods">The proposed new mods, excluding any required by the room itself.</param>
|
||||
public Task ChangeUserMods(IEnumerable<Mod> newMods) => ChangeUserMods(newMods.Select(m => new APIMod(m)).ToList());
|
||||
|
||||
public abstract Task ChangeUserMods(IEnumerable<APIMod> newMods);
|
||||
|
||||
public abstract Task StartMatch();
|
||||
|
||||
Task IMultiplayerClient.RoomStateChanged(MultiplayerRoomState state)
|
||||
@ -377,6 +387,27 @@ namespace osu.Game.Online.Multiplayer
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task UserModsChanged(int userId, IEnumerable<APIMod> mods)
|
||||
{
|
||||
if (Room == null)
|
||||
return Task.CompletedTask;
|
||||
|
||||
Scheduler.Add(() =>
|
||||
{
|
||||
var user = Room?.Users.SingleOrDefault(u => u.UserID == userId);
|
||||
|
||||
// errors here are not critical - user mods are mostly for display.
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
user.Mods = mods;
|
||||
|
||||
RoomUpdated?.Invoke();
|
||||
}, false);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
Task IMultiplayerClient.LoadRequested()
|
||||
{
|
||||
if (Room == null)
|
||||
@ -500,7 +531,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
beatmap.MD5Hash = settings.BeatmapChecksum;
|
||||
|
||||
var ruleset = rulesets.GetRuleset(settings.RulesetID).CreateInstance();
|
||||
var mods = settings.Mods.Select(m => m.ToMod(ruleset));
|
||||
var mods = settings.RequiredMods.Select(m => m.ToMod(ruleset));
|
||||
var allowedMods = settings.AllowedMods.Select(m => m.ToMod(ruleset));
|
||||
|
||||
PlaylistItem playlistItem = new PlaylistItem
|
||||
{
|
||||
@ -510,6 +542,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
};
|
||||
|
||||
playlistItem.RequiredMods.AddRange(mods);
|
||||
playlistItem.AllowedMods.AddRange(allowedMods);
|
||||
|
||||
apiRoom.Playlist.Clear(); // Clearing should be unnecessary, but here for sanity.
|
||||
apiRoom.Playlist.Add(playlistItem);
|
||||
|
@ -23,17 +23,17 @@ namespace osu.Game.Online.Rooms
|
||||
/// The beatmap's downloading progress, null when not in <see cref="DownloadState.Downloading"/> state.
|
||||
/// </summary>
|
||||
[Key(1)]
|
||||
public readonly double? DownloadProgress;
|
||||
public readonly float? DownloadProgress;
|
||||
|
||||
[JsonConstructor]
|
||||
public BeatmapAvailability(DownloadState state, double? downloadProgress = null)
|
||||
public BeatmapAvailability(DownloadState state, float? downloadProgress = null)
|
||||
{
|
||||
State = state;
|
||||
DownloadProgress = downloadProgress;
|
||||
}
|
||||
|
||||
public static BeatmapAvailability NotDownloaded() => new BeatmapAvailability(DownloadState.NotDownloaded);
|
||||
public static BeatmapAvailability Downloading(double progress) => new BeatmapAvailability(DownloadState.Downloading, progress);
|
||||
public static BeatmapAvailability Downloading(float progress) => new BeatmapAvailability(DownloadState.Downloading, progress);
|
||||
public static BeatmapAvailability Importing() => new BeatmapAvailability(DownloadState.Importing);
|
||||
public static BeatmapAvailability LocallyAvailable() => new BeatmapAvailability(DownloadState.LocallyAvailable);
|
||||
|
||||
|
@ -0,0 +1,92 @@
|
||||
// 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 osu.Framework.Bindables;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Beatmaps;
|
||||
|
||||
namespace osu.Game.Online.Rooms
|
||||
{
|
||||
/// <summary>
|
||||
/// Represent a checksum-verifying beatmap availability tracker usable for online play screens.
|
||||
///
|
||||
/// This differs from a regular download tracking composite as this accounts for the
|
||||
/// databased beatmap set's checksum, to disallow from playing with an altered version of the beatmap.
|
||||
/// </summary>
|
||||
public class OnlinePlayBeatmapAvailablilityTracker : DownloadTrackingComposite<BeatmapSetInfo, BeatmapManager>
|
||||
{
|
||||
public readonly IBindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
||||
|
||||
/// <summary>
|
||||
/// The availability state of the currently selected playlist item.
|
||||
/// </summary>
|
||||
public IBindable<BeatmapAvailability> Availability => availability;
|
||||
|
||||
private readonly Bindable<BeatmapAvailability> availability = new Bindable<BeatmapAvailability>();
|
||||
|
||||
public OnlinePlayBeatmapAvailablilityTracker()
|
||||
{
|
||||
State.BindValueChanged(_ => updateAvailability());
|
||||
Progress.BindValueChanged(_ => updateAvailability(), true);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
SelectedItem.BindValueChanged(item => Model.Value = item.NewValue?.Beatmap.Value.BeatmapSet, true);
|
||||
}
|
||||
|
||||
protected override bool VerifyDatabasedModel(BeatmapSetInfo databasedSet)
|
||||
{
|
||||
int? beatmapId = SelectedItem.Value.Beatmap.Value.OnlineBeatmapID;
|
||||
string checksum = SelectedItem.Value.Beatmap.Value.MD5Hash;
|
||||
|
||||
var matchingBeatmap = databasedSet.Beatmaps.FirstOrDefault(b => b.OnlineBeatmapID == beatmapId && b.MD5Hash == checksum);
|
||||
|
||||
if (matchingBeatmap == null)
|
||||
{
|
||||
Logger.Log("The imported beatmap set does not match the online version.", LoggingTarget.Runtime, LogLevel.Important);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool IsModelAvailableLocally()
|
||||
{
|
||||
int? beatmapId = SelectedItem.Value.Beatmap.Value.OnlineBeatmapID;
|
||||
string checksum = SelectedItem.Value.Beatmap.Value.MD5Hash;
|
||||
|
||||
var beatmap = Manager.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId && b.MD5Hash == checksum);
|
||||
return beatmap?.BeatmapSet.DeletePending == false;
|
||||
}
|
||||
|
||||
private void updateAvailability()
|
||||
{
|
||||
switch (State.Value)
|
||||
{
|
||||
case DownloadState.NotDownloaded:
|
||||
availability.Value = BeatmapAvailability.NotDownloaded();
|
||||
break;
|
||||
|
||||
case DownloadState.Downloading:
|
||||
availability.Value = BeatmapAvailability.Downloading((float)Progress.Value);
|
||||
break;
|
||||
|
||||
case DownloadState.Importing:
|
||||
availability.Value = BeatmapAvailability.Importing();
|
||||
break;
|
||||
|
||||
case DownloadState.LocallyAvailable:
|
||||
availability.Value = BeatmapAvailability.LocallyAvailable();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(State));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -469,6 +469,10 @@ namespace osu.Game
|
||||
{
|
||||
updateModDefaults();
|
||||
|
||||
// a lease may be taken on the mods bindable, at which point we can't really ensure valid mods.
|
||||
if (SelectedMods.Disabled)
|
||||
return;
|
||||
|
||||
if (!ModUtils.CheckValidForGameplay(mods.NewValue, out var invalid))
|
||||
{
|
||||
// ensure we always have a valid set of mods.
|
||||
|
@ -5,7 +5,7 @@ using osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
public class SoloModSelectOverlay : ModSelectOverlay
|
||||
public class LocalPlayerModSelectOverlay : ModSelectOverlay
|
||||
{
|
||||
protected override void OnModSelected(Mod mod)
|
||||
{
|
@ -33,6 +33,8 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
private CancellationTokenSource modsLoadCts;
|
||||
|
||||
protected bool SelectionAnimationRunning => pendingSelectionOperations.Count > 0;
|
||||
|
||||
/// <summary>
|
||||
/// True when all mod icons have completed loading.
|
||||
/// </summary>
|
||||
@ -49,7 +51,11 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
return new ModButton(m)
|
||||
{
|
||||
SelectionChanged = Action,
|
||||
SelectionChanged = mod =>
|
||||
{
|
||||
ModButtonStateChanged(mod);
|
||||
Action?.Invoke(mod);
|
||||
},
|
||||
};
|
||||
}).ToArray();
|
||||
|
||||
@ -78,6 +84,10 @@ namespace osu.Game.Overlays.Mods
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void ModButtonStateChanged(Mod mod)
|
||||
{
|
||||
}
|
||||
|
||||
private ModButton[] buttons = Array.Empty<ModButton>();
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
@ -94,30 +104,75 @@ namespace osu.Game.Overlays.Mods
|
||||
return base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
public void DeselectAll() => DeselectTypes(buttons.Select(b => b.SelectedMod?.GetType()).Where(t => t != null));
|
||||
private const double initial_multiple_selection_delay = 120;
|
||||
|
||||
private double selectionDelay = initial_multiple_selection_delay;
|
||||
private double lastSelection;
|
||||
|
||||
private readonly Queue<Action> pendingSelectionOperations = new Queue<Action>();
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (selectionDelay == initial_multiple_selection_delay || Time.Current - lastSelection >= selectionDelay)
|
||||
{
|
||||
if (pendingSelectionOperations.TryDequeue(out var dequeuedAction))
|
||||
{
|
||||
dequeuedAction();
|
||||
|
||||
// each time we play an animation, we decrease the time until the next animation (to ramp the visual and audible elements).
|
||||
selectionDelay = Math.Max(30, selectionDelay * 0.8f);
|
||||
lastSelection = Time.Current;
|
||||
}
|
||||
else
|
||||
{
|
||||
// reset the selection delay after all animations have been completed.
|
||||
// this will cause the next action to be immediately performed.
|
||||
selectionDelay = initial_multiple_selection_delay;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects all mods.
|
||||
/// </summary>
|
||||
public void SelectAll()
|
||||
{
|
||||
pendingSelectionOperations.Clear();
|
||||
|
||||
foreach (var button in buttons.Where(b => !b.Selected))
|
||||
pendingSelectionOperations.Enqueue(() => button.SelectAt(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deselects all mods.
|
||||
/// </summary>
|
||||
public void DeselectAll()
|
||||
{
|
||||
pendingSelectionOperations.Clear();
|
||||
DeselectTypes(buttons.Select(b => b.SelectedMod?.GetType()).Where(t => t != null));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deselect one or more mods in this section.
|
||||
/// </summary>
|
||||
/// <param name="modTypes">The types of <see cref="Mod"/>s which should be deselected.</param>
|
||||
/// <param name="immediate">Set to true to bypass animations and update selections immediately.</param>
|
||||
/// <param name="immediate">Whether the deselection should happen immediately. Should only be used when required to ensure correct selection flow.</param>
|
||||
public void DeselectTypes(IEnumerable<Type> modTypes, bool immediate = false)
|
||||
{
|
||||
int delay = 0;
|
||||
|
||||
foreach (var button in buttons)
|
||||
{
|
||||
Mod selected = button.SelectedMod;
|
||||
if (selected == null) continue;
|
||||
if (button.SelectedMod == null) continue;
|
||||
|
||||
foreach (var type in modTypes)
|
||||
{
|
||||
if (type.IsInstanceOfType(selected))
|
||||
if (type.IsInstanceOfType(button.SelectedMod))
|
||||
{
|
||||
if (immediate)
|
||||
button.Deselect();
|
||||
else
|
||||
Scheduler.AddDelayed(button.Deselect, delay += 50);
|
||||
pendingSelectionOperations.Enqueue(button.Deselect);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -184,5 +239,14 @@ namespace osu.Game.Overlays.Mods
|
||||
Font = OsuFont.GetFont(weight: FontWeight.Bold),
|
||||
Text = text
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Play out all remaining animations immediately to leave mods in a good (final) state.
|
||||
/// </summary>
|
||||
public void FlushAnimation()
|
||||
{
|
||||
while (pendingSelectionOperations.TryDequeue(out var dequeuedAction))
|
||||
dequeuedAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,11 @@ namespace osu.Game.Overlays.Mods
|
||||
protected readonly TriangleButton CustomiseButton;
|
||||
protected readonly TriangleButton CloseButton;
|
||||
|
||||
protected readonly Drawable MultiplierSection;
|
||||
protected readonly OsuSpriteText MultiplierLabel;
|
||||
|
||||
protected readonly FillFlowContainer FooterContainer;
|
||||
|
||||
protected override bool BlockNonPositionalInput => false;
|
||||
|
||||
protected override bool DimMainContent => false;
|
||||
@ -79,8 +82,6 @@ namespace osu.Game.Overlays.Mods
|
||||
private const float content_width = 0.8f;
|
||||
private const float footer_button_spacing = 20;
|
||||
|
||||
private readonly FillFlowContainer footerContainer;
|
||||
|
||||
private SampleChannel sampleOn, sampleOff;
|
||||
|
||||
protected ModSelectOverlay()
|
||||
@ -269,7 +270,7 @@ namespace osu.Game.Overlays.Mods
|
||||
Colour = new Color4(172, 20, 116, 255),
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
footerContainer = new FillFlowContainer
|
||||
FooterContainer = new FillFlowContainer
|
||||
{
|
||||
Origin = Anchor.BottomCentre,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
@ -283,7 +284,7 @@ namespace osu.Game.Overlays.Mods
|
||||
Vertical = 15,
|
||||
Horizontal = OsuScreen.HORIZONTAL_OVERFLOW_PADDING
|
||||
},
|
||||
Children = new Drawable[]
|
||||
Children = new[]
|
||||
{
|
||||
DeselectAllButton = new TriangleButton
|
||||
{
|
||||
@ -310,7 +311,7 @@ namespace osu.Game.Overlays.Mods
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
},
|
||||
new FillFlowContainer
|
||||
MultiplierSection = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Spacing = new Vector2(footer_button_spacing / 2, 0),
|
||||
@ -378,8 +379,13 @@ namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
base.PopOut();
|
||||
|
||||
footerContainer.MoveToX(content_width, WaveContainer.DISAPPEAR_DURATION, Easing.InSine);
|
||||
footerContainer.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.InSine);
|
||||
foreach (var section in ModSectionsContainer)
|
||||
{
|
||||
section.FlushAnimation();
|
||||
}
|
||||
|
||||
FooterContainer.MoveToX(content_width, WaveContainer.DISAPPEAR_DURATION, Easing.InSine);
|
||||
FooterContainer.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.InSine);
|
||||
|
||||
foreach (var section in ModSectionsContainer.Children)
|
||||
{
|
||||
@ -393,8 +399,8 @@ namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
base.PopIn();
|
||||
|
||||
footerContainer.MoveToX(0, WaveContainer.APPEAR_DURATION, Easing.OutQuint);
|
||||
footerContainer.FadeIn(WaveContainer.APPEAR_DURATION, Easing.OutQuint);
|
||||
FooterContainer.MoveToX(0, WaveContainer.APPEAR_DURATION, Easing.OutQuint);
|
||||
FooterContainer.FadeIn(WaveContainer.APPEAR_DURATION, Easing.OutQuint);
|
||||
|
||||
foreach (var section in ModSectionsContainer.Children)
|
||||
{
|
||||
@ -498,7 +504,8 @@ namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
if (selectedMod != null)
|
||||
{
|
||||
if (State.Value == Visibility.Visible) sampleOn?.Play();
|
||||
if (State.Value == Visibility.Visible)
|
||||
Scheduler.AddOnce(playSelectedSound);
|
||||
|
||||
OnModSelected(selectedMod);
|
||||
|
||||
@ -506,12 +513,16 @@ namespace osu.Game.Overlays.Mods
|
||||
}
|
||||
else
|
||||
{
|
||||
if (State.Value == Visibility.Visible) sampleOff?.Play();
|
||||
if (State.Value == Visibility.Visible)
|
||||
Scheduler.AddOnce(playDeselectedSound);
|
||||
}
|
||||
|
||||
refreshSelectedMods();
|
||||
}
|
||||
|
||||
private void playSelectedSound() => sampleOn?.Play();
|
||||
private void playDeselectedSound() => sampleOff?.Play();
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a new <see cref="Mod"/> has been selected.
|
||||
/// </summary>
|
||||
|
@ -91,7 +91,11 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
scrollingInfo = new LocalScrollingInfo();
|
||||
scrollingInfo.Direction.BindTo(Direction);
|
||||
scrollingInfo.TimeRange.BindTo(TimeRange);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
switch (VisualisationMethod)
|
||||
{
|
||||
case ScrollVisualisationMethod.Sequential:
|
||||
@ -106,11 +110,7 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
scrollingInfo.Algorithm = new ConstantScrollAlgorithm();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
double lastObjectTime = Objects.LastOrDefault()?.GetEndTime() ?? double.MaxValue;
|
||||
double baseBeatLength = TimingControlPoint.DEFAULT_BEAT_LENGTH;
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
{
|
||||
public class ModeTypeInfo : OnlinePlayComposite
|
||||
{
|
||||
private const float height = 30;
|
||||
private const float height = 28;
|
||||
private const float transition_duration = 100;
|
||||
|
||||
private Container drawableRuleset;
|
||||
|
@ -1,77 +1,29 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Components
|
||||
{
|
||||
public abstract class ReadyButton : TriangleButton
|
||||
{
|
||||
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
||||
|
||||
public new readonly BindableBool Enabled = new BindableBool();
|
||||
|
||||
[Resolved]
|
||||
protected IBindable<WorkingBeatmap> GameBeatmap { get; private set; }
|
||||
|
||||
[Resolved]
|
||||
private BeatmapManager beatmaps { get; set; }
|
||||
|
||||
private bool hasBeatmap;
|
||||
|
||||
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
|
||||
private IBindable<WeakReference<BeatmapSetInfo>> managerRemoved;
|
||||
private IBindable<BeatmapAvailability> availability;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
private void load(OnlinePlayBeatmapAvailablilityTracker beatmapTracker)
|
||||
{
|
||||
managerUpdated = beatmaps.ItemUpdated.GetBoundCopy();
|
||||
managerUpdated.BindValueChanged(beatmapUpdated);
|
||||
managerRemoved = beatmaps.ItemRemoved.GetBoundCopy();
|
||||
managerRemoved.BindValueChanged(beatmapRemoved);
|
||||
availability = beatmapTracker.Availability.GetBoundCopy();
|
||||
|
||||
SelectedItem.BindValueChanged(item => updateSelectedItem(item.NewValue), true);
|
||||
availability.BindValueChanged(_ => updateState());
|
||||
Enabled.BindValueChanged(_ => updateState(), true);
|
||||
}
|
||||
|
||||
private void updateSelectedItem(PlaylistItem _) => Scheduler.AddOnce(updateBeatmapState);
|
||||
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> _) => Scheduler.AddOnce(updateBeatmapState);
|
||||
private void beatmapRemoved(ValueChangedEvent<WeakReference<BeatmapSetInfo>> _) => Scheduler.AddOnce(updateBeatmapState);
|
||||
|
||||
private void updateBeatmapState()
|
||||
{
|
||||
int? beatmapId = SelectedItem.Value?.Beatmap.Value?.OnlineBeatmapID;
|
||||
string checksum = SelectedItem.Value?.Beatmap.Value?.MD5Hash;
|
||||
|
||||
if (beatmapId == null || checksum == null)
|
||||
return;
|
||||
|
||||
var databasedBeatmap = beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId && b.MD5Hash == checksum);
|
||||
|
||||
hasBeatmap = databasedBeatmap?.BeatmapSet?.DeletePending == false;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
updateEnabledState();
|
||||
}
|
||||
|
||||
private void updateEnabledState()
|
||||
{
|
||||
if (GameBeatmap.Value == null || SelectedItem.Value == null)
|
||||
{
|
||||
base.Enabled.Value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
base.Enabled.Value = hasBeatmap && Enabled.Value;
|
||||
}
|
||||
private void updateState() => base.Enabled.Value = availability.Value.State == DownloadState.LocallyAvailable && Enabled.Value;
|
||||
}
|
||||
}
|
||||
|
50
osu.Game/Screens/OnlinePlay/Components/RoomLocalUserInfo.cs
Normal file
50
osu.Game/Screens/OnlinePlay/Components/RoomLocalUserInfo.cs
Normal file
@ -0,0 +1,50 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Components
|
||||
{
|
||||
public class RoomLocalUserInfo : OnlinePlayComposite
|
||||
{
|
||||
private OsuSpriteText attemptDisplay;
|
||||
|
||||
public RoomLocalUserInfo()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
InternalChild = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
attemptDisplay = new OsuSpriteText
|
||||
{
|
||||
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14)
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
MaxAttempts.BindValueChanged(attempts =>
|
||||
{
|
||||
attemptDisplay.Text = attempts.NewValue == null
|
||||
? string.Empty
|
||||
: $"Maximum attempts: {attempts.NewValue:N0}";
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
63
osu.Game/Screens/OnlinePlay/FooterButtonFreeMods.cs
Normal file
63
osu.Game/Screens/OnlinePlay/FooterButtonFreeMods.cs
Normal file
@ -0,0 +1,63 @@
|
||||
// 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.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osu.Game.Screens.Select;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay
|
||||
{
|
||||
public class FooterButtonFreeMods : FooterButton, IHasCurrentValue<IReadOnlyList<Mod>>
|
||||
{
|
||||
public Bindable<IReadOnlyList<Mod>> Current
|
||||
{
|
||||
get => modDisplay.Current;
|
||||
set => modDisplay.Current = value;
|
||||
}
|
||||
|
||||
private readonly ModDisplay modDisplay;
|
||||
|
||||
public FooterButtonFreeMods()
|
||||
{
|
||||
ButtonContentContainer.Add(modDisplay = new ModDisplay
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
DisplayUnrankedText = false,
|
||||
Scale = new Vector2(0.8f),
|
||||
ExpansionMode = ExpansionMode.AlwaysContracted,
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
SelectedColour = colours.Yellow;
|
||||
DeselectedColour = SelectedColour.Opacity(0.5f);
|
||||
Text = @"freemods";
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Current.BindValueChanged(_ => updateModDisplay(), true);
|
||||
}
|
||||
|
||||
private void updateModDisplay()
|
||||
{
|
||||
if (Current.Value?.Count > 0)
|
||||
modDisplay.FadeIn();
|
||||
else
|
||||
modDisplay.FadeOut();
|
||||
}
|
||||
}
|
||||
}
|
145
osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs
Normal file
145
osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs
Normal file
@ -0,0 +1,145 @@
|
||||
// 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 osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="ModSelectOverlay"/> used for free-mod selection in online play.
|
||||
/// </summary>
|
||||
public class FreeModSelectOverlay : ModSelectOverlay
|
||||
{
|
||||
protected override bool Stacked => false;
|
||||
|
||||
public new Func<Mod, bool> IsValidMod
|
||||
{
|
||||
get => base.IsValidMod;
|
||||
set => base.IsValidMod = m => m.HasImplementation && !m.RequiresConfiguration && !(m is ModAutoplay) && value(m);
|
||||
}
|
||||
|
||||
public FreeModSelectOverlay()
|
||||
{
|
||||
IsValidMod = m => true;
|
||||
|
||||
CustomiseButton.Alpha = 0;
|
||||
MultiplierSection.Alpha = 0;
|
||||
DeselectAllButton.Alpha = 0;
|
||||
|
||||
Drawable selectAllButton;
|
||||
Drawable deselectAllButton;
|
||||
|
||||
FooterContainer.AddRange(new[]
|
||||
{
|
||||
selectAllButton = new TriangleButton
|
||||
{
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Width = 180,
|
||||
Text = "Select All",
|
||||
Action = selectAll,
|
||||
},
|
||||
// Unlike the base mod select overlay, this button deselects mods instantaneously.
|
||||
deselectAllButton = new TriangleButton
|
||||
{
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Width = 180,
|
||||
Text = "Deselect All",
|
||||
Action = deselectAll,
|
||||
},
|
||||
});
|
||||
|
||||
FooterContainer.SetLayoutPosition(selectAllButton, -2);
|
||||
FooterContainer.SetLayoutPosition(deselectAllButton, -1);
|
||||
}
|
||||
|
||||
private void selectAll()
|
||||
{
|
||||
foreach (var section in ModSectionsContainer.Children)
|
||||
section.SelectAll();
|
||||
}
|
||||
|
||||
private void deselectAll()
|
||||
{
|
||||
foreach (var section in ModSectionsContainer.Children)
|
||||
section.DeselectAll();
|
||||
}
|
||||
|
||||
protected override ModSection CreateModSection(ModType type) => new FreeModSection(type);
|
||||
|
||||
private class FreeModSection : ModSection
|
||||
{
|
||||
private HeaderCheckbox checkbox;
|
||||
|
||||
public FreeModSection(ModType type)
|
||||
: base(type)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Drawable CreateHeader(string text) => new Container
|
||||
{
|
||||
AutoSizeAxes = Axes.Y,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Child = checkbox = new HeaderCheckbox
|
||||
{
|
||||
LabelText = text,
|
||||
Changed = onCheckboxChanged
|
||||
}
|
||||
};
|
||||
|
||||
private void onCheckboxChanged(bool value)
|
||||
{
|
||||
if (value)
|
||||
SelectAll();
|
||||
else
|
||||
DeselectAll();
|
||||
}
|
||||
|
||||
protected override void ModButtonStateChanged(Mod mod)
|
||||
{
|
||||
base.ModButtonStateChanged(mod);
|
||||
|
||||
if (!SelectionAnimationRunning)
|
||||
{
|
||||
var validButtons = ButtonsContainer.OfType<ModButton>().Where(b => b.Mod.HasImplementation);
|
||||
checkbox.Current.Value = validButtons.All(b => b.Selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class HeaderCheckbox : OsuCheckbox
|
||||
{
|
||||
public Action<bool> Changed;
|
||||
|
||||
protected override bool PlaySoundsOnUserChange => false;
|
||||
|
||||
public HeaderCheckbox()
|
||||
: base(false)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
protected override void ApplyLabelParameters(SpriteText text)
|
||||
{
|
||||
base.ApplyLabelParameters(text);
|
||||
|
||||
text.Font = OsuFont.GetFont(weight: FontWeight.Bold);
|
||||
}
|
||||
|
||||
protected override void OnUserChange(bool value)
|
||||
{
|
||||
base.OnUserChange(value);
|
||||
Changed?.Invoke(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -63,7 +63,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
summary = new OsuSpriteText
|
||||
{
|
||||
Text = "0 participants",
|
||||
Font = OsuFont.GetFont(size: 14)
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -20,41 +20,34 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
{
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
RoomLocalUserInfo localUserInfo;
|
||||
RoomStatusInfo statusInfo;
|
||||
ModeTypeInfo typeInfo;
|
||||
ParticipantInfo participantInfo;
|
||||
|
||||
InternalChild = new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Spacing = new Vector2(0, 10),
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 4),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
roomName = new OsuTextFlowContainer(t => t.Font = OsuFont.GetFont(size: 30))
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
},
|
||||
participantInfo = new ParticipantInfo(),
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
roomName = new OsuTextFlowContainer(t => t.Font = OsuFont.GetFont(size: 30))
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
},
|
||||
statusInfo = new RoomStatusInfo(),
|
||||
}
|
||||
},
|
||||
statusInfo = new RoomStatusInfo(),
|
||||
typeInfo = new ModeTypeInfo
|
||||
{
|
||||
Anchor = Anchor.BottomRight,
|
||||
@ -62,20 +55,21 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
}
|
||||
}
|
||||
},
|
||||
participantInfo = new ParticipantInfo(),
|
||||
localUserInfo = new RoomLocalUserInfo(),
|
||||
}
|
||||
};
|
||||
|
||||
statusElements.AddRange(new Drawable[] { statusInfo, typeInfo, participantInfo });
|
||||
statusElements.AddRange(new Drawable[]
|
||||
{
|
||||
statusInfo, typeInfo, participantInfo, localUserInfo
|
||||
});
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
if (RoomID.Value == null)
|
||||
statusElements.ForEach(e => e.FadeOut());
|
||||
|
||||
RoomID.BindValueChanged(id =>
|
||||
{
|
||||
if (id.NewValue == null)
|
||||
@ -83,7 +77,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
else
|
||||
statusElements.ForEach(e => e.FadeIn(100));
|
||||
}, true);
|
||||
|
||||
RoomName.BindValueChanged(name =>
|
||||
{
|
||||
roomName.Text = name.NewValue ?? "No room selected";
|
||||
|
@ -3,13 +3,11 @@
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Playlists;
|
||||
using osuTK;
|
||||
|
||||
@ -20,7 +18,6 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
public const float HEIGHT = 50;
|
||||
|
||||
public Action OnStart;
|
||||
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
||||
|
||||
private readonly Drawable background;
|
||||
|
||||
@ -37,7 +34,6 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(600, 50),
|
||||
SelectedItem = { BindTarget = SelectedItem },
|
||||
Action = () => OnStart?.Invoke()
|
||||
}
|
||||
};
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
@ -29,6 +30,11 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
[Resolved(typeof(Room), nameof(Room.Playlist))]
|
||||
protected BindableList<PlaylistItem> Playlist { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Any mods applied by/to the local user.
|
||||
/// </summary>
|
||||
protected readonly Bindable<IReadOnlyList<Mod>> UserMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||
|
||||
[Resolved]
|
||||
private MusicController music { get; set; }
|
||||
|
||||
@ -40,6 +46,20 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
|
||||
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
|
||||
|
||||
[Cached]
|
||||
protected OnlinePlayBeatmapAvailablilityTracker BeatmapAvailablilityTracker { get; }
|
||||
|
||||
protected RoomSubScreen()
|
||||
{
|
||||
AddInternal(BeatmapAvailablilityTracker = new OnlinePlayBeatmapAvailablilityTracker
|
||||
{
|
||||
SelectedItem = { BindTarget = SelectedItem }
|
||||
});
|
||||
}
|
||||
|
||||
protected override void ClearInternal(bool disposeChildren = true) =>
|
||||
throw new InvalidOperationException($"{nameof(RoomSubScreen)}'s children should not be cleared as it will remove required components");
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
@ -55,6 +75,8 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
|
||||
managerUpdated = beatmapManager.ItemUpdated.GetBoundCopy();
|
||||
managerUpdated.BindValueChanged(beatmapUpdated);
|
||||
|
||||
UserMods.BindValueChanged(_ => updateMods());
|
||||
}
|
||||
|
||||
public override void OnEntering(IScreen last)
|
||||
@ -73,6 +95,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
{
|
||||
base.OnResuming(last);
|
||||
beginHandlingTrack();
|
||||
updateMods();
|
||||
}
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
@ -95,12 +118,17 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
{
|
||||
updateWorkingBeatmap();
|
||||
|
||||
var item = SelectedItem.Value;
|
||||
if (SelectedItem.Value == null)
|
||||
return;
|
||||
|
||||
Mods.Value = item?.RequiredMods?.ToArray() ?? Array.Empty<Mod>();
|
||||
// Remove any user mods that are no longer allowed.
|
||||
UserMods.Value = UserMods.Value
|
||||
.Where(m => SelectedItem.Value.AllowedMods.Any(a => m.GetType() == a.GetType()))
|
||||
.ToList();
|
||||
|
||||
if (item?.Ruleset != null)
|
||||
Ruleset.Value = item.Ruleset.Value;
|
||||
updateMods();
|
||||
|
||||
Ruleset.Value = SelectedItem.Value.Ruleset.Value;
|
||||
}
|
||||
|
||||
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet) => Schedule(updateWorkingBeatmap);
|
||||
@ -115,6 +143,14 @@ namespace osu.Game.Screens.OnlinePlay.Match
|
||||
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap);
|
||||
}
|
||||
|
||||
private void updateMods()
|
||||
{
|
||||
if (SelectedItem.Value == null)
|
||||
return;
|
||||
|
||||
Mods.Value = UserMods.Value.Concat(SelectedItem.Value.RequiredMods).ToList();
|
||||
}
|
||||
|
||||
private void beginHandlingTrack()
|
||||
{
|
||||
Beatmap.BindValueChanged(applyLoopingToTrack, true);
|
||||
|
@ -3,13 +3,11 @@
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
@ -18,8 +16,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
public const float HEIGHT = 50;
|
||||
|
||||
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
|
||||
|
||||
public Action OnReadyClick
|
||||
{
|
||||
set => readyButton.OnReadyClick = value;
|
||||
@ -41,7 +37,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(600, 50),
|
||||
SelectedItem = { BindTarget = SelectedItem }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Backgrounds;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osuTK;
|
||||
|
||||
@ -21,8 +20,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
public class MultiplayerReadyButton : MultiplayerRoomComposite
|
||||
{
|
||||
public Bindable<PlaylistItem> SelectedItem => button.SelectedItem;
|
||||
|
||||
public Action OnReadyClick
|
||||
{
|
||||
set => button.Action = value;
|
||||
|
@ -1,70 +1,32 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Screens.Select;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
public class MultiplayerMatchSongSelect : SongSelect, IOnlinePlaySubScreen
|
||||
public class MultiplayerMatchSongSelect : OnlinePlaySongSelect
|
||||
{
|
||||
public string ShortTitle => "song selection";
|
||||
|
||||
public override string Title => ShortTitle.Humanize();
|
||||
|
||||
[Resolved(typeof(Room), nameof(Room.Playlist))]
|
||||
private BindableList<PlaylistItem> playlist { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private StatefulMultiplayerClient client { get; set; }
|
||||
|
||||
private LoadingLayer loadingLayer;
|
||||
|
||||
private WorkingBeatmap initialBeatmap;
|
||||
private RulesetInfo initialRuleset;
|
||||
private IReadOnlyList<Mod> initialMods;
|
||||
|
||||
private bool itemSelected;
|
||||
|
||||
public MultiplayerMatchSongSelect()
|
||||
{
|
||||
Padding = new MarginPadding { Horizontal = HORIZONTAL_OVERFLOW_PADDING };
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
AddInternal(loadingLayer = new LoadingLayer(true));
|
||||
initialBeatmap = Beatmap.Value;
|
||||
initialRuleset = Ruleset.Value;
|
||||
initialMods = Mods.Value.ToList();
|
||||
}
|
||||
|
||||
protected override bool OnStart()
|
||||
protected override void SelectItem(PlaylistItem item)
|
||||
{
|
||||
itemSelected = true;
|
||||
var item = new PlaylistItem();
|
||||
|
||||
item.Beatmap.Value = Beatmap.Value.BeatmapInfo;
|
||||
item.Ruleset.Value = Ruleset.Value;
|
||||
|
||||
item.RequiredMods.Clear();
|
||||
item.RequiredMods.AddRange(Mods.Value.Select(m => m.CreateCopy()));
|
||||
|
||||
// If the client is already in a room, update via the client.
|
||||
// Otherwise, update the playlist directly in preparation for it to be submitted to the API on match creation.
|
||||
if (client.Room != null)
|
||||
@ -89,30 +51,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
}
|
||||
else
|
||||
{
|
||||
playlist.Clear();
|
||||
playlist.Add(item);
|
||||
Playlist.Clear();
|
||||
Playlist.Add(item);
|
||||
this.Exit();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
if (!itemSelected)
|
||||
{
|
||||
Beatmap.Value = initialBeatmap;
|
||||
Ruleset.Value = initialRuleset;
|
||||
Mods.Value = initialMods;
|
||||
}
|
||||
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
|
||||
protected override BeatmapDetailArea CreateBeatmapDetailArea() => new PlayBeatmapDetailArea();
|
||||
|
||||
protected override ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay { IsValidMod = isValidMod };
|
||||
|
||||
private bool isValidMod(Mod mod) => !(mod is ModAutoplay) && (mod as MultiMod)?.Mods.Any(mm => mm is ModAutoplay) != true;
|
||||
protected override bool IsValidFreeMod(Mod mod) => base.IsValidFreeMod(mod) && !(mod is ModTimeRamp) && !(mod is ModRateAdjust) && !mod.RequiresConfiguration;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
@ -13,12 +14,16 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Match;
|
||||
using osu.Game.Screens.OnlinePlay.Match.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osu.Game.Users;
|
||||
using osuTK;
|
||||
using ParticipantsList = osu.Game.Screens.OnlinePlay.Multiplayer.Participants.ParticipantsList;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
@ -36,7 +41,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
[Resolved]
|
||||
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||
|
||||
private ModSelectOverlay userModsSelectOverlay;
|
||||
private MultiplayerMatchSettingsOverlay settingsOverlay;
|
||||
private Drawable userModsSection;
|
||||
|
||||
private IBindable<bool> isConnected;
|
||||
|
||||
@ -54,7 +61,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
AddRangeInternal(new Drawable[]
|
||||
{
|
||||
mainContent = new GridContainer
|
||||
{
|
||||
@ -90,18 +97,25 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
},
|
||||
new Drawable[]
|
||||
{
|
||||
new GridContainer
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Content = new[]
|
||||
Padding = new MarginPadding { Horizontal = 5, Vertical = 10 },
|
||||
Child = new GridContainer
|
||||
{
|
||||
new Drawable[]
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
ColumnDimensions = new[]
|
||||
{
|
||||
new Container
|
||||
new Dimension(GridSizeMode.Relative, size: 0.5f, maxSize: 400),
|
||||
new Dimension(),
|
||||
new Dimension(GridSizeMode.Relative, size: 0.5f, maxSize: 600),
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Horizontal = 5, Vertical = 10 },
|
||||
Child = new GridContainer
|
||||
// Main left column
|
||||
new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RowDimensions = new[]
|
||||
@ -119,19 +133,62 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Horizontal = 5 },
|
||||
Children = new Drawable[]
|
||||
},
|
||||
// Spacer
|
||||
null,
|
||||
// Main right column
|
||||
new FillFlowContainer
|
||||
{
|
||||
new OverlinedHeader("Beatmap"),
|
||||
new BeatmapSelectionControl { RelativeSizeAxes = Axes.X }
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new[]
|
||||
{
|
||||
new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OverlinedHeader("Beatmap"),
|
||||
new BeatmapSelectionControl { RelativeSizeAxes = Axes.X }
|
||||
}
|
||||
},
|
||||
userModsSection = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Margin = new MarginPadding { Top = 10 },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OverlinedHeader("Extra mods"),
|
||||
new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(10, 0),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new PurpleTriangleButton
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Width = 90,
|
||||
Text = "Select",
|
||||
Action = () => userModsSelectOverlay.Show()
|
||||
},
|
||||
new ModDisplay
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
DisplayUnrankedText = false,
|
||||
Current = UserMods,
|
||||
Scale = new Vector2(0.8f),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -162,7 +219,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
new MultiplayerMatchFooter
|
||||
{
|
||||
SelectedItem = { BindTarget = SelectedItem },
|
||||
OnReadyClick = onReadyClick
|
||||
}
|
||||
}
|
||||
@ -173,12 +229,24 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
}
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Height = 0.5f,
|
||||
Child = userModsSelectOverlay = new UserModSelectOverlay
|
||||
{
|
||||
SelectedMods = { BindTarget = UserMods },
|
||||
IsValidMod = _ => false
|
||||
}
|
||||
},
|
||||
settingsOverlay = new MultiplayerMatchSettingsOverlay
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
State = { Value = client.Room == null ? Visibility.Visible : Visibility.Hidden }
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
if (client.Room == null)
|
||||
{
|
||||
@ -199,6 +267,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
base.LoadComplete();
|
||||
|
||||
Playlist.BindCollectionChanged(onPlaylistChanged, true);
|
||||
UserMods.BindValueChanged(onUserModsChanged);
|
||||
|
||||
client.LoadRequested += onLoadRequested;
|
||||
|
||||
@ -218,10 +287,39 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
return true;
|
||||
}
|
||||
|
||||
if (userModsSelectOverlay.State.Value == Visibility.Visible)
|
||||
{
|
||||
userModsSelectOverlay.Hide();
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnBackButton();
|
||||
}
|
||||
|
||||
private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e) => SelectedItem.Value = Playlist.FirstOrDefault();
|
||||
private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
SelectedItem.Value = Playlist.FirstOrDefault();
|
||||
|
||||
if (SelectedItem.Value?.AllowedMods.Any() != true)
|
||||
{
|
||||
userModsSection.Hide();
|
||||
userModsSelectOverlay.Hide();
|
||||
userModsSelectOverlay.IsValidMod = _ => false;
|
||||
}
|
||||
else
|
||||
{
|
||||
userModsSection.Show();
|
||||
userModsSelectOverlay.IsValidMod = m => SelectedItem.Value.AllowedMods.Any(a => a.GetType() == m.GetType());
|
||||
}
|
||||
}
|
||||
|
||||
private void onUserModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
||||
{
|
||||
if (client.Room == null)
|
||||
return;
|
||||
|
||||
client.ChangeUserMods(mods.NewValue);
|
||||
}
|
||||
|
||||
private void onReadyClick()
|
||||
{
|
||||
@ -274,5 +372,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
if (client != null)
|
||||
client.LoadRequested -= onLoadRequested;
|
||||
}
|
||||
|
||||
private class UserModSelectOverlay : LocalPlayerModSelectOverlay
|
||||
{
|
||||
public UserModSelectOverlay()
|
||||
{
|
||||
CustomiseButton.Alpha = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -15,6 +16,8 @@ using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Users.Drawables;
|
||||
using osuTK;
|
||||
@ -29,6 +32,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private RulesetStore rulesets { get; set; }
|
||||
|
||||
private ModDisplay userModsDisplay;
|
||||
private StateDisplay userStateDisplay;
|
||||
private SpriteIcon crown;
|
||||
|
||||
@ -121,6 +128,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
}
|
||||
}
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Margin = new MarginPadding { Right = 70 },
|
||||
Child = userModsDisplay = new ModDisplay
|
||||
{
|
||||
Scale = new Vector2(0.5f),
|
||||
ExpansionMode = ExpansionMode.AlwaysContracted,
|
||||
DisplayUnrankedText = false,
|
||||
}
|
||||
},
|
||||
userStateDisplay = new StateDisplay
|
||||
{
|
||||
Anchor = Anchor.CentreRight,
|
||||
@ -148,6 +168,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
crown.FadeIn(fade_time);
|
||||
else
|
||||
crown.FadeOut(fade_time);
|
||||
|
||||
// If the mods are updated at the end of the frame, the flow container will skip a reflow cycle: https://github.com/ppy/osu-framework/issues/4187
|
||||
// This looks particularly jarring here, so re-schedule the update to that start of our frame as a fix.
|
||||
Schedule(() =>
|
||||
{
|
||||
var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID).CreateInstance();
|
||||
userModsDisplay.Current.Value = User.Mods.Select(m => m.ToMod(ruleset)).ToList();
|
||||
});
|
||||
}
|
||||
|
||||
public MenuItem[] ContextMenuItems
|
||||
|
@ -39,6 +39,9 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
[Resolved(typeof(Room))]
|
||||
protected Bindable<int?> MaxParticipants { get; private set; }
|
||||
|
||||
[Resolved(typeof(Room))]
|
||||
protected Bindable<int?> MaxAttempts { get; private set; }
|
||||
|
||||
[Resolved(typeof(Room))]
|
||||
protected Bindable<DateTimeOffset?> EndDate { get; private set; }
|
||||
|
||||
|
154
osu.Game/Screens/OnlinePlay/OnlinePlaySongSelect.cs
Normal file
154
osu.Game/Screens/OnlinePlay/OnlinePlaySongSelect.cs
Normal file
@ -0,0 +1,154 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Screens.Select;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay
|
||||
{
|
||||
public abstract class OnlinePlaySongSelect : SongSelect, IOnlinePlaySubScreen
|
||||
{
|
||||
public string ShortTitle => "song selection";
|
||||
|
||||
public override string Title => ShortTitle.Humanize();
|
||||
|
||||
public override bool AllowEditing => false;
|
||||
|
||||
[Resolved(typeof(Room), nameof(Room.Playlist))]
|
||||
protected BindableList<PlaylistItem> Playlist { get; private set; }
|
||||
|
||||
private readonly Bindable<IReadOnlyList<Mod>> freeMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||
private readonly FreeModSelectOverlay freeModSelectOverlay;
|
||||
|
||||
private WorkingBeatmap initialBeatmap;
|
||||
private RulesetInfo initialRuleset;
|
||||
private IReadOnlyList<Mod> initialMods;
|
||||
private bool itemSelected;
|
||||
|
||||
protected OnlinePlaySongSelect()
|
||||
{
|
||||
Padding = new MarginPadding { Horizontal = HORIZONTAL_OVERFLOW_PADDING };
|
||||
|
||||
freeModSelectOverlay = new FreeModSelectOverlay
|
||||
{
|
||||
SelectedMods = { BindTarget = freeMods },
|
||||
IsValidMod = IsValidFreeMod,
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
initialBeatmap = Beatmap.Value;
|
||||
initialRuleset = Ruleset.Value;
|
||||
initialMods = Mods.Value.ToList();
|
||||
|
||||
FooterPanels.Add(freeModSelectOverlay);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
// At this point, Mods contains both the required and allowed mods. For selection purposes, it should only contain the required mods.
|
||||
// Similarly, freeMods is currently empty but should only contain the allowed mods.
|
||||
Mods.Value = Playlist.FirstOrDefault()?.RequiredMods.Select(m => m.CreateCopy()).ToArray() ?? Array.Empty<Mod>();
|
||||
freeMods.Value = Playlist.FirstOrDefault()?.AllowedMods.Select(m => m.CreateCopy()).ToArray() ?? Array.Empty<Mod>();
|
||||
|
||||
Ruleset.BindValueChanged(onRulesetChanged);
|
||||
}
|
||||
|
||||
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> ruleset)
|
||||
{
|
||||
freeMods.Value = Array.Empty<Mod>();
|
||||
}
|
||||
|
||||
protected sealed override bool OnStart()
|
||||
{
|
||||
itemSelected = true;
|
||||
|
||||
var item = new PlaylistItem();
|
||||
|
||||
item.Beatmap.Value = Beatmap.Value.BeatmapInfo;
|
||||
item.Ruleset.Value = Ruleset.Value;
|
||||
|
||||
item.RequiredMods.Clear();
|
||||
item.RequiredMods.AddRange(Mods.Value.Select(m => m.CreateCopy()));
|
||||
|
||||
item.AllowedMods.Clear();
|
||||
item.AllowedMods.AddRange(freeMods.Value.Select(m => m.CreateCopy()));
|
||||
|
||||
SelectItem(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the user has requested a selection of a beatmap.
|
||||
/// </summary>
|
||||
/// <param name="item">The resultant <see cref="PlaylistItem"/>. This item has not yet been added to the <see cref="Room"/>'s.</param>
|
||||
protected abstract void SelectItem(PlaylistItem item);
|
||||
|
||||
public override bool OnBackButton()
|
||||
{
|
||||
if (freeModSelectOverlay.State.Value == Visibility.Visible)
|
||||
{
|
||||
freeModSelectOverlay.Hide();
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnBackButton();
|
||||
}
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
if (!itemSelected)
|
||||
{
|
||||
Beatmap.Value = initialBeatmap;
|
||||
Ruleset.Value = initialRuleset;
|
||||
Mods.Value = initialMods;
|
||||
}
|
||||
|
||||
return base.OnExiting(next);
|
||||
}
|
||||
|
||||
protected override ModSelectOverlay CreateModSelectOverlay() => new LocalPlayerModSelectOverlay
|
||||
{
|
||||
IsValidMod = IsValidMod
|
||||
};
|
||||
|
||||
protected override IEnumerable<(FooterButton, OverlayContainer)> CreateFooterButtons()
|
||||
{
|
||||
var buttons = base.CreateFooterButtons().ToList();
|
||||
buttons.Insert(buttons.FindIndex(b => b.Item1 is FooterButtonMods) + 1, (new FooterButtonFreeMods { Current = freeMods }, freeModSelectOverlay));
|
||||
return buttons;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a given <see cref="Mod"/> is valid for global selection.
|
||||
/// </summary>
|
||||
/// <param name="mod">The <see cref="Mod"/> to check.</param>
|
||||
/// <returns>Whether <paramref name="mod"/> is a valid mod for online play.</returns>
|
||||
protected virtual bool IsValidMod(Mod mod) => mod.HasImplementation && !ModUtils.FlattenMod(mod).Any(m => m is ModAutoplay);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a given <see cref="Mod"/> is valid for per-player free-mod selection.
|
||||
/// </summary>
|
||||
/// <param name="mod">The <see cref="Mod"/> to check.</param>
|
||||
/// <returns>Whether <paramref name="mod"/> is a selectable free-mod.</returns>
|
||||
protected virtual bool IsValidFreeMod(Mod mod) => IsValidMod(mod);
|
||||
}
|
||||
}
|
@ -42,15 +42,13 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
public Action EditPlaylist;
|
||||
|
||||
public OsuTextBox NameField, MaxParticipantsField;
|
||||
public OsuTextBox NameField, MaxParticipantsField, MaxAttemptsField;
|
||||
public OsuDropdown<TimeSpan> DurationField;
|
||||
public RoomAvailabilityPicker AvailabilityPicker;
|
||||
public GameTypePicker TypePicker;
|
||||
public TriangleButton ApplyButton;
|
||||
|
||||
public OsuSpriteText ErrorText;
|
||||
|
||||
private OsuSpriteText typeLabel;
|
||||
private LoadingLayer loadingLayer;
|
||||
private DrawableRoomPlaylist playlist;
|
||||
private OsuSpriteText playlistLength;
|
||||
@ -134,6 +132,15 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
}
|
||||
}
|
||||
},
|
||||
new Section("Allowed attempts (across all playlist items)")
|
||||
{
|
||||
Child = MaxAttemptsField = new SettingsNumberTextBox
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
TabbableContentContainer = this,
|
||||
PlaceholderText = "Unlimited",
|
||||
},
|
||||
},
|
||||
new Section("Room visibility")
|
||||
{
|
||||
Alpha = disabled_alpha,
|
||||
@ -142,30 +149,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
Enabled = { Value = false }
|
||||
},
|
||||
},
|
||||
new Section("Game type")
|
||||
{
|
||||
Alpha = disabled_alpha,
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Y,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(7),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
TypePicker = new GameTypePicker
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Enabled = { Value = false }
|
||||
},
|
||||
typeLabel = new OsuSpriteText
|
||||
{
|
||||
Font = OsuFont.GetFont(size: 14),
|
||||
Colour = colours.Yellow
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
new Section("Max participants")
|
||||
{
|
||||
Alpha = disabled_alpha,
|
||||
@ -294,11 +277,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
loadingLayer = new LoadingLayer(true)
|
||||
};
|
||||
|
||||
TypePicker.Current.BindValueChanged(type => typeLabel.Text = type.NewValue?.Name ?? string.Empty, true);
|
||||
RoomName.BindValueChanged(name => NameField.Text = name.NewValue, true);
|
||||
Availability.BindValueChanged(availability => AvailabilityPicker.Current.Value = availability.NewValue, true);
|
||||
Type.BindValueChanged(type => TypePicker.Current.Value = type.NewValue, true);
|
||||
MaxParticipants.BindValueChanged(count => MaxParticipantsField.Text = count.NewValue?.ToString(), true);
|
||||
MaxAttempts.BindValueChanged(count => MaxAttemptsField.Text = count.NewValue?.ToString(), true);
|
||||
Duration.BindValueChanged(duration => DurationField.Current.Value = duration.NewValue ?? TimeSpan.FromMinutes(30), true);
|
||||
|
||||
playlist.Items.BindTo(Playlist);
|
||||
@ -326,13 +308,17 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
RoomName.Value = NameField.Text;
|
||||
Availability.Value = AvailabilityPicker.Current.Value;
|
||||
Type.Value = TypePicker.Current.Value;
|
||||
|
||||
if (int.TryParse(MaxParticipantsField.Text, out int max))
|
||||
MaxParticipants.Value = max;
|
||||
else
|
||||
MaxParticipants.Value = null;
|
||||
|
||||
if (int.TryParse(MaxAttemptsField.Text, out max))
|
||||
MaxAttempts.Value = max;
|
||||
else
|
||||
MaxAttempts.Value = null;
|
||||
|
||||
Duration.Value = DurationField.Current.Value;
|
||||
|
||||
manager?.CreateRoom(currentRoom.Value, onSuccess, onError);
|
||||
|
@ -65,7 +65,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
failed = true;
|
||||
|
||||
Logger.Error(e, "Failed to retrieve a score submission token.\n\nThis may happen if you are running an old or non-official release of osu! (ie. you are self-compiling).");
|
||||
if (string.IsNullOrEmpty(e.Message))
|
||||
Logger.Error(e, "Failed to retrieve a score submission token.");
|
||||
else
|
||||
Logger.Log($"You are not able to submit a score: {e.Message}", level: LogLevel.Important);
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
@ -15,6 +16,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
[Resolved(typeof(Room), nameof(Room.EndDate))]
|
||||
private Bindable<DateTimeOffset?> endDate { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private IBindable<WorkingBeatmap> gameBeatmap { get; set; }
|
||||
|
||||
public PlaylistsReadyButton()
|
||||
{
|
||||
Text = "Start";
|
||||
@ -32,7 +36,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
base.Update();
|
||||
|
||||
Enabled.Value = endDate.Value != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(GameBeatmap.Value.Track.Length) < endDate.Value;
|
||||
Enabled.Value = endDate.Value != null && DateTimeOffset.UtcNow.AddSeconds(30).AddMilliseconds(gameBeatmap.Value.Track.Length) < endDate.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Match;
|
||||
using osu.Game.Screens.OnlinePlay.Match.Components;
|
||||
using osu.Game.Screens.Select;
|
||||
using osu.Game.Users;
|
||||
using Footer = osu.Game.Screens.OnlinePlay.Match.Components.Footer;
|
||||
|
||||
@ -44,7 +43,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
AddRangeInternal(new Drawable[]
|
||||
{
|
||||
mainContent = new GridContainer
|
||||
{
|
||||
@ -175,7 +174,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
new Footer
|
||||
{
|
||||
OnStart = onStart,
|
||||
SelectedItem = { BindTarget = SelectedItem }
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -188,10 +186,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
settingsOverlay = new PlaylistsMatchSettingsOverlay
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
EditPlaylist = () => this.Push(new MatchSongSelect()),
|
||||
EditPlaylist = () => this.Push(new PlaylistsSongSelect()),
|
||||
State = { Value = roomId.Value == null ? Visibility.Visible : Visibility.Hidden }
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
if (roomId.Value == null)
|
||||
{
|
||||
|
@ -1,48 +1,27 @@
|
||||
// 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 Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Screens.OnlinePlay;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.Select;
|
||||
|
||||
namespace osu.Game.Screens.Select
|
||||
namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
public class MatchSongSelect : SongSelect, IOnlinePlaySubScreen
|
||||
public class PlaylistsSongSelect : OnlinePlaySongSelect
|
||||
{
|
||||
public Action<PlaylistItem> Selected;
|
||||
|
||||
public string ShortTitle => "song selection";
|
||||
public override string Title => ShortTitle.Humanize();
|
||||
|
||||
public override bool AllowEditing => false;
|
||||
|
||||
[Resolved(typeof(Room), nameof(Room.Playlist))]
|
||||
protected BindableList<PlaylistItem> Playlist { get; private set; }
|
||||
|
||||
[Resolved]
|
||||
private BeatmapManager beatmaps { get; set; }
|
||||
|
||||
public MatchSongSelect()
|
||||
{
|
||||
Padding = new MarginPadding { Horizontal = HORIZONTAL_OVERFLOW_PADDING };
|
||||
}
|
||||
|
||||
protected override BeatmapDetailArea CreateBeatmapDetailArea() => new MatchBeatmapDetailArea
|
||||
{
|
||||
CreateNewItem = createNewItem
|
||||
};
|
||||
|
||||
protected override bool OnStart()
|
||||
protected override void SelectItem(PlaylistItem item)
|
||||
{
|
||||
switch (Playlist.Count)
|
||||
{
|
||||
@ -56,8 +35,6 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
|
||||
this.Exit();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void createNewItem()
|
||||
@ -80,9 +57,5 @@ namespace osu.Game.Screens.Select
|
||||
item.RequiredMods.Clear();
|
||||
item.RequiredMods.AddRange(Mods.Value.Select(m => m.CreateCopy()));
|
||||
}
|
||||
|
||||
protected override ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay { IsValidMod = isValidMod };
|
||||
|
||||
private bool isValidMod(Mod mod) => !(mod is ModAutoplay) && (mod as MultiMod)?.Mods.Any(mm => mm is ModAutoplay) != true;
|
||||
}
|
||||
}
|
@ -23,32 +23,6 @@ namespace osu.Game.Screens.Play
|
||||
/// </summary>
|
||||
public class BeatmapMetadataDisplay : Container
|
||||
{
|
||||
private class MetadataLine : Container
|
||||
{
|
||||
public MetadataLine(string left, string right)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopRight,
|
||||
Margin = new MarginPadding { Right = 5 },
|
||||
Colour = OsuColour.Gray(0.8f),
|
||||
Text = left,
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopLeft,
|
||||
Margin = new MarginPadding { Left = 5 },
|
||||
Text = string.IsNullOrEmpty(right) ? @"-" : right,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private readonly WorkingBeatmap beatmap;
|
||||
private readonly Bindable<IReadOnlyList<Mod>> mods;
|
||||
private readonly Drawable facade;
|
||||
@ -144,15 +118,34 @@ namespace osu.Game.Screens.Play
|
||||
Bottom = 40
|
||||
},
|
||||
},
|
||||
new MetadataLine("Source", metadata.Source)
|
||||
new GridContainer
|
||||
{
|
||||
Origin = Anchor.TopCentre,
|
||||
Anchor = Anchor.TopCentre,
|
||||
},
|
||||
new MetadataLine("Mapper", metadata.AuthorString)
|
||||
{
|
||||
Origin = Anchor.TopCentre,
|
||||
Anchor = Anchor.TopCentre,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
RowDimensions = new[]
|
||||
{
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
},
|
||||
ColumnDimensions = new[]
|
||||
{
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
new Dimension(GridSizeMode.AutoSize),
|
||||
},
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[]
|
||||
{
|
||||
new MetadataLineLabel("Source"),
|
||||
new MetadataLineInfo(metadata.Source)
|
||||
},
|
||||
new Drawable[]
|
||||
{
|
||||
new MetadataLineLabel("Mapper"),
|
||||
new MetadataLineInfo(metadata.AuthorString)
|
||||
}
|
||||
}
|
||||
},
|
||||
new ModDisplay
|
||||
{
|
||||
@ -168,5 +161,26 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
Loading = true;
|
||||
}
|
||||
|
||||
private class MetadataLineLabel : OsuSpriteText
|
||||
{
|
||||
public MetadataLineLabel(string text)
|
||||
{
|
||||
Anchor = Anchor.TopRight;
|
||||
Origin = Anchor.TopRight;
|
||||
Margin = new MarginPadding { Right = 5 };
|
||||
Colour = OsuColour.Gray(0.8f);
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
|
||||
private class MetadataLineInfo : OsuSpriteText
|
||||
{
|
||||
public MetadataLineInfo(string text)
|
||||
{
|
||||
Margin = new MarginPadding { Left = 5 };
|
||||
Text = string.IsNullOrEmpty(text) ? @"-" : text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,19 +28,16 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
|
||||
|
||||
/// <param name="button">THe button to be added.</param>
|
||||
/// <param name="button">The button to be added.</param>
|
||||
/// <param name="overlay">The <see cref="OverlayContainer"/> to be toggled by this button.</param>
|
||||
public void AddButton(FooterButton button, OverlayContainer overlay)
|
||||
{
|
||||
overlays.Add(overlay);
|
||||
button.Action = () => showOverlay(overlay);
|
||||
if (overlay != null)
|
||||
{
|
||||
overlays.Add(overlay);
|
||||
button.Action = () => showOverlay(overlay);
|
||||
}
|
||||
|
||||
AddButton(button);
|
||||
}
|
||||
|
||||
/// <param name="button">Button to be added.</param>
|
||||
public void AddButton(FooterButton button)
|
||||
{
|
||||
button.Hovered = updateModeLight;
|
||||
button.HoverLost = updateModeLight;
|
||||
|
||||
|
@ -263,9 +263,8 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
if (Footer != null)
|
||||
{
|
||||
Footer.AddButton(new FooterButtonMods { Current = Mods }, ModSelect);
|
||||
Footer.AddButton(new FooterButtonRandom { Action = triggerRandom });
|
||||
Footer.AddButton(new FooterButtonOptions(), BeatmapOptions);
|
||||
foreach (var (button, overlay) in CreateFooterButtons())
|
||||
Footer.AddButton(button, overlay);
|
||||
|
||||
BeatmapOptions.AddButton(@"Manage", @"collections", FontAwesome.Solid.Book, colours.Green, () => manageCollectionsDialog?.Show());
|
||||
BeatmapOptions.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, colours.Pink, () => delete(Beatmap.Value.BeatmapSetInfo));
|
||||
@ -301,7 +300,18 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay();
|
||||
/// <summary>
|
||||
/// Creates the buttons to be displayed in the footer.
|
||||
/// </summary>
|
||||
/// <returns>A set of <see cref="FooterButton"/> and an optional <see cref="OverlayContainer"/> which the button opens when pressed.</returns>
|
||||
protected virtual IEnumerable<(FooterButton, OverlayContainer)> CreateFooterButtons() => new (FooterButton, OverlayContainer)[]
|
||||
{
|
||||
(new FooterButtonMods { Current = Mods }, ModSelect),
|
||||
(new FooterButtonRandom { Action = triggerRandom }, null),
|
||||
(new FooterButtonOptions(), BeatmapOptions)
|
||||
};
|
||||
|
||||
protected virtual ModSelectOverlay CreateModSelectOverlay() => new LocalPlayerModSelectOverlay();
|
||||
|
||||
protected virtual void ApplyFilterToCarousel(FilterCriteria criteria)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -11,6 +12,7 @@ using osu.Framework.Bindables;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
@ -122,6 +124,21 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void ChangeUserMods(int userId, IEnumerable<Mod> newMods)
|
||||
=> ChangeUserMods(userId, newMods.Select(m => new APIMod(m)).ToList());
|
||||
|
||||
public void ChangeUserMods(int userId, IEnumerable<APIMod> newMods)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
((IMultiplayerClient)this).UserModsChanged(userId, newMods.ToList());
|
||||
}
|
||||
|
||||
public override Task ChangeUserMods(IEnumerable<APIMod> newMods)
|
||||
{
|
||||
ChangeUserMods(api.LocalUser.Value.Id, newMods);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task StartMatch()
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
@ -20,11 +20,13 @@
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="DiffPlex" Version="1.6.3" />
|
||||
<PackageReference Include="Humanizer" Version="2.8.26" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.10" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.11" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="3.1.10" />
|
||||
<PackageReference Include="MessagePack" Version="2.2.85" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.NETCore.Targets" Version="3.1.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.128.0" />
|
||||
|
@ -80,6 +80,9 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.0.3" />
|
||||
<PackageReference Include="MessagePack" Version="1.7.3.7" />
|
||||
<PackageReference Include="MessagePack.Annotations" Version="2.2.85" />
|
||||
</ItemGroup>
|
||||
<!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. -->
|
||||
<ItemGroup Label="Transitive Dependencies">
|
||||
|
Loading…
Reference in New Issue
Block a user