1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 02:13:21 +08:00

Merge branch 'master' into playlist-max-room-attempts

This commit is contained in:
Dean Herbert 2021-02-05 22:13:13 +09:00
commit 3ca64a1cb2
79 changed files with 2646 additions and 701 deletions

View File

@ -5,7 +5,7 @@
# osu! # osu!
[![Build status](https://ci.appveyor.com/api/projects/status/u2p01nx7l6og8buh?svg=true)](https://ci.appveyor.com/project/peppy/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) [![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) [![dev chat](https://discordapp.com/api/guilds/188630481301012481/widget.png?style=shield)](https://discord.gg/ppy)

View File

@ -29,4 +29,3 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
} }
} }
} }

View File

@ -19,4 +19,3 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
} }
} }
} }

View File

@ -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;
}
});
}
}

View File

@ -238,6 +238,7 @@ namespace osu.Game.Rulesets.Mania
new ManiaModMirror(), new ManiaModMirror(),
new ManiaModDifficultyAdjust(), new ManiaModDifficultyAdjust(),
new ManiaModInvert(), new ManiaModInvert(),
new ManiaModConstantSpeed()
}; };
case ModType.Automation: case ModType.Automation:

View 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;
}
}
}

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -11,6 +12,7 @@ using osu.Framework.Graphics;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Configuration;
using osu.Game.Input.Handlers; using osu.Game.Input.Handlers;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps;
@ -49,6 +51,22 @@ namespace osu.Game.Rulesets.Mania.UI
protected new ManiaRulesetConfigManager Config => (ManiaRulesetConfigManager)base.Config; 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<ManiaScrollingDirection> configDirection = new Bindable<ManiaScrollingDirection>();
private readonly Bindable<double> configTimeRange = new BindableDouble(); private readonly Bindable<double> configTimeRange = new BindableDouble();

View File

@ -69,5 +69,9 @@
<Name>osu.Game</Name> <Name>osu.Game</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup Label="Package References">
<PackageReference Include="DeepEqual" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.16.0" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project> </Project>

View File

@ -45,6 +45,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="DeepEqual" Version="2.0.0" /> <PackageReference Include="DeepEqual" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.16.0" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project> </Project>

View File

@ -0,0 +1,160 @@
// 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 Moq;
using NUnit.Framework;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Utils;
namespace osu.Game.Tests.Mods
{
[TestFixture]
public class ModUtilsTest
{
[Test]
public void TestModIsCompatibleByItself()
{
var mod = new Mock<CustomMod1>();
Assert.That(ModUtils.CheckCompatibleSet(new[] { mod.Object }));
}
[Test]
public void TestIncompatibleThroughTopLevel()
{
var mod1 = new Mock<CustomMod1>();
var mod2 = new Mock<CustomMod2>();
mod1.Setup(m => m.IncompatibleMods).Returns(new[] { mod2.Object.GetType() });
// Test both orderings.
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, mod2.Object }), Is.False);
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.False);
}
[Test]
public void TestMultiModIncompatibleWithTopLevel()
{
var mod1 = new Mock<CustomMod1>();
// The nested mod.
var mod2 = new Mock<CustomMod2>();
mod2.Setup(m => m.IncompatibleMods).Returns(new[] { mod1.Object.GetType() });
var multiMod = new MultiMod(new MultiMod(mod2.Object));
// Test both orderings.
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { multiMod, mod1.Object }), Is.False);
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, multiMod }), Is.False);
}
[Test]
public void TestTopLevelIncompatibleWithMultiMod()
{
// The nested mod.
var mod1 = new Mock<CustomMod1>();
var multiMod = new MultiMod(new MultiMod(mod1.Object));
var mod2 = new Mock<CustomMod2>();
mod2.Setup(m => m.IncompatibleMods).Returns(new[] { typeof(CustomMod1) });
// Test both orderings.
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { multiMod, mod2.Object }), Is.False);
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, multiMod }), Is.False);
}
[Test]
public void TestCompatibleMods()
{
var mod1 = new Mock<CustomMod1>();
var mod2 = new Mock<CustomMod2>();
// Test both orderings.
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, mod2.Object }), Is.True);
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.True);
}
[Test]
public void TestIncompatibleThroughBaseType()
{
var mod1 = new Mock<CustomMod1>();
var mod2 = new Mock<CustomMod2>();
mod2.Setup(m => m.IncompatibleMods).Returns(new[] { typeof(Mod) });
// Test both orderings.
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod1.Object, mod2.Object }), Is.False);
Assert.That(ModUtils.CheckCompatibleSet(new Mod[] { mod2.Object, mod1.Object }), Is.False);
}
[Test]
public void TestAllowedThroughMostDerivedType()
{
var mod = new Mock<CustomMod1>();
Assert.That(ModUtils.CheckAllowed(new[] { mod.Object }, new[] { mod.Object.GetType() }));
}
[Test]
public void TestNotAllowedThroughBaseType()
{
var mod = new Mock<CustomMod1>();
Assert.That(ModUtils.CheckAllowed(new[] { mod.Object }, new[] { typeof(Mod) }), Is.False);
}
private static readonly object[] invalid_mod_test_scenarios =
{
// incompatible pair.
new object[]
{
new Mod[] { new OsuModDoubleTime(), new OsuModHalfTime() },
new[] { typeof(OsuModDoubleTime), typeof(OsuModHalfTime) }
},
// incompatible pair with derived class.
new object[]
{
new Mod[] { new OsuModNightcore(), new OsuModHalfTime() },
new[] { typeof(OsuModNightcore), typeof(OsuModHalfTime) }
},
// system mod.
new object[]
{
new Mod[] { new OsuModDoubleTime(), new OsuModTouchDevice() },
new[] { typeof(OsuModTouchDevice) }
},
// multi mod.
new object[]
{
new Mod[] { new MultiMod(new OsuModHalfTime()), new OsuModHalfTime() },
new[] { typeof(MultiMod) }
},
// valid pair.
new object[]
{
new Mod[] { new OsuModDoubleTime(), new OsuModHardRock() },
null
}
};
[TestCaseSource(nameof(invalid_mod_test_scenarios))]
public void TestInvalidModScenarios(Mod[] inputMods, Type[] expectedInvalid)
{
bool isValid = ModUtils.CheckValidForGameplay(inputMods, out var invalid);
Assert.That(isValid, Is.EqualTo(expectedInvalid == null));
if (isValid)
Assert.IsNull(invalid);
else
Assert.That(invalid?.Select(t => t.GetType()), Is.EquivalentTo(expectedInvalid));
}
public abstract class CustomMod1 : Mod
{
}
public abstract class CustomMod2 : Mod
{
}
}
}

View File

@ -3,8 +3,12 @@
using System; using System;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Screens;
using osu.Game.Screens.OnlinePlay; using osu.Game.Screens.OnlinePlay;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
@ -58,5 +62,45 @@ namespace osu.Game.Tests.NonVisual
AddStep("end operation", () => operation.Dispose()); AddStep("end operation", () => operation.Dispose());
AddAssert("operation is ended", () => !operationInProgress.Value); AddAssert("operation is ended", () => !operationInProgress.Value);
} }
[Test]
public void TestOperationDisposalAfterScreenExit()
{
TestScreenWithTracker screen = null;
OsuScreenStack stack;
IDisposable operation = null;
AddStep("create screen with tracker", () =>
{
Child = stack = new OsuScreenStack
{
RelativeSizeAxes = Axes.Both
};
stack.Push(screen = new TestScreenWithTracker());
});
AddUntilStep("wait for loaded", () => screen.IsLoaded);
AddStep("begin operation", () => operation = screen.OngoingOperationTracker.BeginOperation());
AddAssert("operation in progress", () => screen.OngoingOperationTracker.InProgress.Value);
AddStep("dispose after screen exit", () =>
{
screen.Exit();
operation.Dispose();
});
AddAssert("operation ended", () => !screen.OngoingOperationTracker.InProgress.Value);
}
private class TestScreenWithTracker : OsuScreen
{
public OngoingOperationTracker OngoingOperationTracker { get; private set; }
[BackgroundDependencyLoader]
private void load()
{
InternalChild = OngoingOperationTracker = new OngoingOperationTracker();
}
}
} }
} }

View File

@ -16,7 +16,7 @@ using osu.Game.Rulesets.UI;
namespace osu.Game.Tests.Online namespace osu.Game.Tests.Online
{ {
[TestFixture] [TestFixture]
public class TestAPIModSerialization public class TestAPIModJsonSerialization
{ {
[Test] [Test]
public void TestAcronymIsPreserved() public void TestAcronymIsPreserved()

View 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
};
}
}
}

View File

@ -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;
}
}
}

View File

@ -11,8 +11,8 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -20,6 +20,7 @@ using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens.OnlinePlay; using osu.Game.Screens.OnlinePlay;
using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Beatmaps;
using osu.Game.Users;
using osuTK; using osuTK;
using osuTK.Input; using osuTK.Input;
@ -241,7 +242,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
} }
private void moveToItem(int index, Vector2? offset = null) private void moveToItem(int index, Vector2? offset = null)
=> AddStep($"move mouse to item {index}", () => InputManager.MoveMouseTo(playlist.ChildrenOfType<OsuRearrangeableListItem<PlaylistItem>>().ElementAt(index), offset)); => AddStep($"move mouse to item {index}", () => InputManager.MoveMouseTo(playlist.ChildrenOfType<DifficultyIcon>().ElementAt(index), offset));
private void moveToDragger(int index, Vector2? offset = null) => AddStep($"move mouse to dragger {index}", () => private void moveToDragger(int index, Vector2? offset = null) => AddStep($"move mouse to dragger {index}", () =>
{ {
@ -252,7 +253,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
private void moveToDeleteButton(int index, Vector2? offset = null) => AddStep($"move mouse to delete button {index}", () => private void moveToDeleteButton(int index, Vector2? offset = null) => AddStep($"move mouse to delete button {index}", () =>
{ {
var item = playlist.ChildrenOfType<OsuRearrangeableListItem<PlaylistItem>>().ElementAt(index); var item = playlist.ChildrenOfType<OsuRearrangeableListItem<PlaylistItem>>().ElementAt(index);
InputManager.MoveMouseTo(item.ChildrenOfType<IconButton>().ElementAt(0), offset); InputManager.MoveMouseTo(item.ChildrenOfType<DrawableRoomPlaylistItem.PlaylistRemoveButton>().ElementAt(0), offset);
}); });
private void assertHandleVisibility(int index, bool visible) private void assertHandleVisibility(int index, bool visible)
@ -260,7 +261,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
() => (playlist.ChildrenOfType<OsuRearrangeableListItem<PlaylistItem>.PlaylistItemHandle>().ElementAt(index).Alpha > 0) == visible); () => (playlist.ChildrenOfType<OsuRearrangeableListItem<PlaylistItem>.PlaylistItemHandle>().ElementAt(index).Alpha > 0) == visible);
private void assertDeleteButtonVisibility(int index, bool visible) private void assertDeleteButtonVisibility(int index, bool visible)
=> AddAssert($"delete button {index} {(visible ? "is" : "is not")} visible", () => (playlist.ChildrenOfType<IconButton>().ElementAt(2 + index * 2).Alpha > 0) == visible); => AddAssert($"delete button {index} {(visible ? "is" : "is not")} visible", () => (playlist.ChildrenOfType<DrawableRoomPlaylistItem.PlaylistRemoveButton>().ElementAt(2 + index * 2).Alpha > 0) == visible);
private void createPlaylist(bool allowEdit, bool allowSelection) private void createPlaylist(bool allowEdit, bool allowSelection)
{ {
@ -278,7 +279,21 @@ namespace osu.Game.Tests.Visual.Multiplayer
playlist.Items.Add(new PlaylistItem playlist.Items.Add(new PlaylistItem
{ {
ID = i, ID = i,
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo }, Beatmap =
{
Value = i % 2 == 1
? new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo
: new BeatmapInfo
{
Metadata = new BeatmapMetadata
{
Artist = "Artist",
Author = new User { Username = "Creator name here" },
Title = "Long title used to check background colour",
},
BeatmapSet = new BeatmapSetInfo()
}
},
Ruleset = { Value = new OsuRuleset().RulesetInfo }, Ruleset = { Value = new OsuRuleset().RulesetInfo },
RequiredMods = RequiredMods =
{ {

View File

@ -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 }
};
});
}
}

View File

@ -8,6 +8,8 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Online.Multiplayer; 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.Screens.OnlinePlay.Multiplayer.Participants;
using osu.Game.Users; using osu.Game.Users;
using osuTK; 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));
}
}
} }
} }

View File

@ -6,6 +6,7 @@ using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Testing; using osu.Framework.Testing;
@ -26,8 +27,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
public class TestSceneMultiplayerReadyButton : MultiplayerTestScene public class TestSceneMultiplayerReadyButton : MultiplayerTestScene
{ {
private MultiplayerReadyButton button; private MultiplayerReadyButton button;
private OnlinePlayBeatmapAvailablilityTracker beatmapTracker;
private BeatmapSetInfo importedSet; private BeatmapSetInfo importedSet;
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
private BeatmapManager beatmaps; private BeatmapManager beatmaps;
private RulesetStore rulesets; private RulesetStore rulesets;
@ -39,6 +43,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, host, Beatmap.Default)); Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, host, Beatmap.Default));
beatmaps.Import(TestResources.GetTestBeatmapForImport(true)).Wait(); beatmaps.Import(TestResources.GetTestBeatmapForImport(true)).Wait();
Add(beatmapTracker = new OnlinePlayBeatmapAvailablilityTracker
{
SelectedItem = { BindTarget = selectedItem }
});
Dependencies.Cache(beatmapTracker);
} }
[SetUp] [SetUp]
@ -46,20 +57,20 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First(); importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.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, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(200, 50), Size = new Vector2(200, 50),
SelectedItem =
{
Value = new PlaylistItem
{
Beatmap = { Value = Beatmap.Value.BeatmapInfo },
Ruleset = { Value = Beatmap.Value.BeatmapInfo.Ruleset }
}
},
OnReadyClick = async () => OnReadyClick = async () =>
{ {
readyClickOperation = OngoingOperationTracker.BeginOperation(); readyClickOperation = OngoingOperationTracker.BeginOperation();
@ -73,7 +84,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
await Client.ToggleReady(); await Client.ToggleReady();
readyClickOperation.Dispose(); readyClickOperation.Dispose();
} }
}; });
}); });
[Test] [Test]

View File

@ -19,11 +19,11 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.Select; using osu.Game.Screens.OnlinePlay.Playlists;
namespace osu.Game.Tests.Visual.Multiplayer namespace osu.Game.Tests.Visual.Multiplayer
{ {
public class TestSceneMatchSongSelect : RoomTestScene public class TestScenePlaylistsSongSelect : RoomTestScene
{ {
[Resolved] [Resolved]
private BeatmapManager beatmapManager { get; set; } private BeatmapManager beatmapManager { get; set; }
@ -32,7 +32,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
private RulesetStore rulesets; private RulesetStore rulesets;
private TestMatchSongSelect songSelect; private TestPlaylistsSongSelect songSelect;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio) private void load(GameHost host, AudioManager audio)
@ -89,7 +89,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Beatmap.SetDefault(); Beatmap.SetDefault();
}); });
AddStep("create song select", () => LoadScreen(songSelect = new TestMatchSongSelect())); AddStep("create song select", () => LoadScreen(songSelect = new TestPlaylistsSongSelect()));
AddUntilStep("wait for present", () => songSelect.IsCurrentScreen()); 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)); 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; public new MatchBeatmapDetailArea BeatmapDetails => (MatchBeatmapDetailArea)base.BeatmapDetails;
} }

View File

@ -8,16 +8,16 @@ using osu.Game.Users;
using osuTK; using osuTK;
using System; using System;
using System.Linq; using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Overlays.Chat; using osu.Game.Overlays.Chat;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
public class TestSceneStandAloneChatDisplay : OsuTestScene public class TestSceneStandAloneChatDisplay : OsuManualInputManagerTestScene
{ {
private readonly Channel testChannel = new Channel();
private readonly User admin = new User private readonly User admin = new User
{ {
Username = "HappyStick", Username = "HappyStick",
@ -46,92 +46,97 @@ namespace osu.Game.Tests.Visual.Online
[Cached] [Cached]
private ChannelManager channelManager = new ChannelManager(); private ChannelManager channelManager = new ChannelManager();
private readonly TestStandAloneChatDisplay chatDisplay; private TestStandAloneChatDisplay chatDisplay;
private readonly TestStandAloneChatDisplay chatDisplay2; private int messageIdSequence;
private Channel testChannel;
public TestSceneStandAloneChatDisplay() public TestSceneStandAloneChatDisplay()
{ {
Add(channelManager); Add(channelManager);
Add(chatDisplay = new TestStandAloneChatDisplay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding(20),
Size = new Vector2(400, 80)
});
Add(chatDisplay2 = new TestStandAloneChatDisplay(true)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding(20),
Size = new Vector2(400, 150)
});
} }
protected override void LoadComplete() [SetUp]
public void SetUp() => Schedule(() =>
{ {
base.LoadComplete(); messageIdSequence = 0;
channelManager.CurrentChannel.Value = testChannel = new Channel();
channelManager.CurrentChannel.Value = testChannel; Children = new[]
{
chatDisplay = new TestStandAloneChatDisplay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding(20),
Size = new Vector2(400, 80),
Channel = { Value = testChannel },
},
new TestStandAloneChatDisplay(true)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding(20),
Size = new Vector2(400, 150),
Channel = { Value = testChannel },
}
};
});
chatDisplay.Channel.Value = testChannel; [Test]
chatDisplay2.Channel.Value = testChannel; public void TestManyMessages()
{
int sequence = 0; AddStep("message from admin", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(sequence++)
{ {
Sender = admin, Sender = admin,
Content = "I am a wang!" Content = "I am a wang!"
})); }));
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(sequence++) AddStep("message from team red", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{ {
Sender = redUser, Sender = redUser,
Content = "I am team red." Content = "I am team red."
})); }));
AddStep("message from team red", () => testChannel.AddNewMessages(new Message(sequence++) AddStep("message from team red", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{ {
Sender = redUser, Sender = redUser,
Content = "I plan to win!" Content = "I plan to win!"
})); }));
AddStep("message from team blue", () => testChannel.AddNewMessages(new Message(sequence++) AddStep("message from team blue", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{ {
Sender = blueUser, Sender = blueUser,
Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand." Content = "Not on my watch. Prepare to eat saaaaaaaaaand. Lots and lots of saaaaaaand."
})); }));
AddStep("message from admin", () => testChannel.AddNewMessages(new Message(sequence++) AddStep("message from admin", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{ {
Sender = admin, Sender = admin,
Content = "Okay okay, calm down guys. Let's do this!" Content = "Okay okay, calm down guys. Let's do this!"
})); }));
AddStep("message from long username", () => testChannel.AddNewMessages(new Message(sequence++) AddStep("message from long username", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{ {
Sender = longUsernameUser, Sender = longUsernameUser,
Content = "Hi guys, my new username is lit!" Content = "Hi guys, my new username is lit!"
})); }));
AddStep("message with new date", () => testChannel.AddNewMessages(new Message(sequence++) AddStep("message with new date", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{ {
Sender = longUsernameUser, Sender = longUsernameUser,
Content = "Message from the future!", Content = "Message from the future!",
Timestamp = DateTimeOffset.Now Timestamp = DateTimeOffset.Now
})); }));
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom); checkScrolledToBottom();
const int messages_per_call = 10; const int messages_per_call = 10;
AddRepeatStep("add many messages", () => AddRepeatStep("add many messages", () =>
{ {
for (int i = 0; i < messages_per_call; i++) for (int i = 0; i < messages_per_call; i++)
{ {
testChannel.AddNewMessages(new Message(sequence++) testChannel.AddNewMessages(new Message(messageIdSequence++)
{ {
Sender = longUsernameUser, Sender = longUsernameUser,
Content = "Many messages! " + Guid.NewGuid(), Content = "Many messages! " + Guid.NewGuid(),
@ -153,9 +158,133 @@ namespace osu.Game.Tests.Visual.Online
return true; return true;
}); });
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom); checkScrolledToBottom();
} }
/// <summary>
/// Tests that when a message gets wrapped by the chat display getting contracted while scrolled to bottom, the chat will still keep scrolling down.
/// </summary>
[Test]
public void TestMessageWrappingKeepsAutoScrolling()
{
fillChat();
// send message with short words for text wrapping to occur when contracting chat.
sendMessage();
AddStep("contract chat", () => chatDisplay.Width -= 100);
checkScrolledToBottom();
AddStep("send another message", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = admin,
Content = "As we were saying...",
}));
checkScrolledToBottom();
}
[Test]
public void TestUserScrollOverride()
{
fillChat();
sendMessage();
checkScrolledToBottom();
AddStep("User scroll up", () =>
{
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre);
InputManager.PressButton(MouseButton.Left);
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre + new Vector2(0, chatDisplay.ScreenSpaceDrawQuad.Height));
InputManager.ReleaseButton(MouseButton.Left);
});
checkNotScrolledToBottom();
sendMessage();
checkNotScrolledToBottom();
AddRepeatStep("User scroll to bottom", () =>
{
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre);
InputManager.PressButton(MouseButton.Left);
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre - new Vector2(0, chatDisplay.ScreenSpaceDrawQuad.Height));
InputManager.ReleaseButton(MouseButton.Left);
}, 5);
checkScrolledToBottom();
sendMessage();
checkScrolledToBottom();
}
[Test]
public void TestLocalEchoMessageResetsScroll()
{
fillChat();
sendMessage();
checkScrolledToBottom();
AddStep("User scroll up", () =>
{
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre);
InputManager.PressButton(MouseButton.Left);
InputManager.MoveMouseTo(chatDisplay.ScreenSpaceDrawQuad.Centre + new Vector2(0, chatDisplay.ScreenSpaceDrawQuad.Height));
InputManager.ReleaseButton(MouseButton.Left);
});
checkNotScrolledToBottom();
sendMessage();
checkNotScrolledToBottom();
sendLocalMessage();
checkScrolledToBottom();
sendMessage();
checkScrolledToBottom();
}
private void fillChat()
{
AddStep("fill chat", () =>
{
for (int i = 0; i < 10; i++)
{
testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = longUsernameUser,
Content = $"some stuff {Guid.NewGuid()}",
});
}
});
checkScrolledToBottom();
}
private void sendMessage()
{
AddStep("send lorem ipsum", () => testChannel.AddNewMessages(new Message(messageIdSequence++)
{
Sender = longUsernameUser,
Content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce et bibendum velit.",
}));
}
private void sendLocalMessage()
{
AddStep("send local echo", () => testChannel.AddLocalEcho(new LocalEchoMessage
{
Sender = longUsernameUser,
Content = "This is a local echo message.",
}));
}
private void checkScrolledToBottom() =>
AddUntilStep("is scrolled to bottom", () => chatDisplay.ScrolledToBottom);
private void checkNotScrolledToBottom() =>
AddUntilStep("not scrolled to bottom", () => !chatDisplay.ScrolledToBottom);
private class TestStandAloneChatDisplay : StandAloneChatDisplay private class TestStandAloneChatDisplay : StandAloneChatDisplay
{ {
public TestStandAloneChatDisplay(bool textbox = false) public TestStandAloneChatDisplay(bool textbox = false)
@ -165,7 +294,7 @@ namespace osu.Game.Tests.Visual.Online
protected DrawableChannel DrawableChannel => InternalChildren.OfType<DrawableChannel>().First(); protected DrawableChannel DrawableChannel => InternalChildren.OfType<DrawableChannel>().First();
protected OsuScrollContainer ScrollContainer => (OsuScrollContainer)((Container)DrawableChannel.Child).Child; protected UserTrackingScrollContainer ScrollContainer => (UserTrackingScrollContainer)((Container)DrawableChannel.Child).Child;
public FillFlowContainer FillFlow => (FillFlowContainer)ScrollContainer.Child; public FillFlowContainer FillFlow => (FillFlowContainer)ScrollContainer.Child;

View File

@ -4,7 +4,6 @@
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -28,12 +27,7 @@ namespace osu.Game.Tests.Visual.Playlists
{ {
base.SetUpSteps(); base.SetUpSteps();
AddStep("push screen", () => LoadScreen(loungeScreen = new PlaylistsLoungeSubScreen AddStep("push screen", () => LoadScreen(loungeScreen = new PlaylistsLoungeSubScreen()));
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
}));
AddUntilStep("wait for present", () => loungeScreen.IsCurrentScreen()); AddUntilStep("wait for present", () => loungeScreen.IsCurrentScreen());
} }

View File

@ -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.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.UI;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneModIcon : OsuTestScene
{
[Test]
public void TestChangeModType()
{
ModIcon icon = null;
AddStep("create mod icon", () => Child = icon = new ModIcon(new OsuModDoubleTime()));
AddStep("change mod", () => icon.Mod = new OsuModEasy());
}
}
}

View File

@ -8,6 +8,7 @@ using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -38,28 +39,7 @@ namespace osu.Game.Tests.Visual.UserInterface
} }
[SetUp] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() => createDisplay(() => new TestModSelectOverlay()));
{
SelectedMods.Value = Array.Empty<Mod>();
Children = new Drawable[]
{
modSelect = new TestModSelectOverlay
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
SelectedMods = { BindTarget = SelectedMods }
},
modDisplay = new ModDisplay
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
Position = new Vector2(-5, 25),
Current = { BindTarget = modSelect.SelectedMods }
}
};
});
[SetUpSteps] [SetUpSteps]
public void SetUpSteps() public void SetUpSteps()
@ -67,6 +47,32 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("show", () => modSelect.Show()); 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] [Test]
public void TestOsuMods() public void TestOsuMods()
{ {
@ -146,6 +152,46 @@ namespace osu.Game.Tests.Visual.UserInterface
}); });
} }
[Test]
public void TestNonStacked()
{
changeRuleset(0);
AddStep("create overlay", () => createDisplay(() => new TestNonStackedModSelectOverlay()));
AddStep("show", () => modSelect.Show());
AddAssert("ensure all buttons are spread out", () => modSelect.ChildrenOfType<ModButton>().All(m => m.Mods.Length <= 1));
}
[Test]
public void TestChangeIsValidChangesButtonVisibility()
{
changeRuleset(0);
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));
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);
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)));
}
[Test]
public void TestChangeIsValidPreservesSelection()
{
changeRuleset(0);
AddStep("select DT + HD", () => SelectedMods.Value = new Mod[] { new OsuModDoubleTime(), new OsuModHidden() });
AddAssert("DT + HD selected", () => modSelect.ChildrenOfType<ModButton>().Count(b => b.Selected) == 2);
AddStep("make NF invalid", () => modSelect.IsValidMod = m => !(m is ModNoFail));
AddAssert("DT + HD still selected", () => modSelect.ChildrenOfType<ModButton>().Count(b => b.Selected) == 2);
}
private void testSingleMod(Mod mod) private void testSingleMod(Mod mod)
{ {
selectNext(mod); selectNext(mod);
@ -265,12 +311,37 @@ namespace osu.Game.Tests.Visual.UserInterface
private void checkLabelColor(Func<Color4> getColour) => AddAssert("check label has expected colour", () => modSelect.MultiplierLabel.Colour.AverageColour == getColour()); private void checkLabelColor(Func<Color4> getColour) => AddAssert("check label has expected colour", () => modSelect.MultiplierLabel.Colour.AverageColour == getColour());
private class TestModSelectOverlay : ModSelectOverlay private void createDisplay(Func<TestModSelectOverlay> createOverlayFunc)
{
SelectedMods.Value = Array.Empty<Mod>();
Children = new Drawable[]
{
modSelect = createOverlayFunc().With(d =>
{
d.Origin = Anchor.BottomCentre;
d.Anchor = Anchor.BottomCentre;
d.SelectedMods.BindTarget = SelectedMods;
}),
modDisplay = new ModDisplay
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
Position = new Vector2(-5, 25),
Current = { BindTarget = modSelect.SelectedMods }
}
};
}
private class TestModSelectOverlay : SoloModSelectOverlay
{ {
public new Bindable<IReadOnlyList<Mod>> SelectedMods => base.SelectedMods; public new Bindable<IReadOnlyList<Mod>> SelectedMods => base.SelectedMods;
public bool AllLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded); public bool AllLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded);
public new FillFlowContainer<ModSection> ModSectionsContainer =>
base.ModSectionsContainer;
public ModButton GetModButton(Mod mod) public ModButton GetModButton(Mod mod)
{ {
var section = ModSectionsContainer.Children.Single(s => s.ModType == mod.Type); var section = ModSectionsContainer.Children.Single(s => s.ModType == mod.Type);
@ -283,5 +354,10 @@ namespace osu.Game.Tests.Visual.UserInterface
public new Color4 LowMultiplierColour => base.LowMultiplierColour; public new Color4 LowMultiplierColour => base.LowMultiplierColour;
public new Color4 HighMultiplierColour => base.HighMultiplierColour; public new Color4 HighMultiplierColour => base.HighMultiplierColour;
} }
private class TestNonStackedModSelectOverlay : TestModSelectOverlay
{
protected override bool Stacked => false;
}
} }
} }

View File

@ -151,7 +151,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddUntilStep("wait for ready", () => modSelect.State.Value == Visibility.Visible && modSelect.ButtonsLoaded); AddUntilStep("wait for ready", () => modSelect.State.Value == Visibility.Visible && modSelect.ButtonsLoaded);
} }
private class TestModSelectOverlay : ModSelectOverlay private class TestModSelectOverlay : SoloModSelectOverlay
{ {
public new VisibilityContainer ModSettingsContainer => base.ModSettingsContainer; public new VisibilityContainer ModSettingsContainer => base.ModSettingsContainer;
public new TriangleButton CustomiseButton => base.CustomiseButton; public new TriangleButton CustomiseButton => base.CustomiseButton;

View File

@ -7,6 +7,7 @@
<PackageReference Include="NUnit" Version="3.12.0" /> <PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" /> <PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" /> <PackageReference Update="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Moq" Version="4.16.0" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Project"> <PropertyGroup Label="Project">
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>

View File

@ -308,7 +308,7 @@ namespace osu.Game.Database
/// <param name="item">The model to be imported.</param> /// <param name="item">The model to be imported.</param>
/// <param name="archive">An optional archive to use for model population.</param> /// <param name="archive">An optional archive to use for model population.</param>
/// <param name="cancellationToken">An optional cancellation token.</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(); cancellationToken.ThrowIfCancellationRequested();

View File

@ -25,6 +25,8 @@ namespace osu.Game.Graphics.Containers
/// </summary> /// </summary>
public bool UserScrolling { get; private set; } public bool UserScrolling { get; private set; }
public void CancelUserScroll() => UserScrolling = false;
public UserTrackingScrollContainer() public UserTrackingScrollContainer()
{ {
} }
@ -45,5 +47,11 @@ namespace osu.Game.Graphics.Containers
UserScrolling = false; UserScrolling = false;
base.ScrollTo(value, animated, distanceDecay); base.ScrollTo(value, animated, distanceDecay);
} }
public new void ScrollToEnd(bool animated = true, bool allowDuringDrag = false)
{
UserScrolling = false;
base.ScrollToEnd(animated, allowDuringDrag);
}
} }
} }

View File

@ -4,54 +4,38 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Online; using osu.Game.Online;
using osuTK; using osuTK;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
public class DownloadButton : OsuAnimatedButton public class DownloadButton : GrayButton
{ {
public readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
private readonly SpriteIcon icon;
private readonly SpriteIcon checkmark;
private readonly Box background;
[Resolved] [Resolved]
private OsuColour colours { get; set; } private OsuColour colours { get; set; }
public readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
private SpriteIcon checkmark;
public DownloadButton() public DownloadButton()
: base(FontAwesome.Solid.Download)
{ {
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue
},
icon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(13),
Icon = FontAwesome.Solid.Download,
},
checkmark = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
X = 8,
Size = Vector2.Zero,
Icon = FontAwesome.Solid.Check,
}
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
AddInternal(checkmark = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
X = 8,
Size = Vector2.Zero,
Icon = FontAwesome.Solid.Check,
});
State.BindValueChanged(updateState, true); State.BindValueChanged(updateState, true);
} }
@ -60,27 +44,27 @@ namespace osu.Game.Graphics.UserInterface
switch (state.NewValue) switch (state.NewValue)
{ {
case DownloadState.NotDownloaded: case DownloadState.NotDownloaded:
background.FadeColour(colours.Gray4, 500, Easing.InOutExpo); Background.FadeColour(colours.Gray4, 500, Easing.InOutExpo);
icon.MoveToX(0, 500, Easing.InOutExpo); Icon.MoveToX(0, 500, Easing.InOutExpo);
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo); checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
TooltipText = "Download"; TooltipText = "Download";
break; break;
case DownloadState.Downloading: case DownloadState.Downloading:
background.FadeColour(colours.Blue, 500, Easing.InOutExpo); Background.FadeColour(colours.Blue, 500, Easing.InOutExpo);
icon.MoveToX(0, 500, Easing.InOutExpo); Icon.MoveToX(0, 500, Easing.InOutExpo);
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo); checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
TooltipText = "Downloading..."; TooltipText = "Downloading...";
break; break;
case DownloadState.Importing: case DownloadState.Importing:
background.FadeColour(colours.Yellow, 500, Easing.InOutExpo); Background.FadeColour(colours.Yellow, 500, Easing.InOutExpo);
TooltipText = "Importing"; TooltipText = "Importing";
break; break;
case DownloadState.LocallyAvailable: case DownloadState.LocallyAvailable:
background.FadeColour(colours.Green, 500, Easing.InOutExpo); Background.FadeColour(colours.Green, 500, Easing.InOutExpo);
icon.MoveToX(-8, 500, Easing.InOutExpo); Icon.MoveToX(-8, 500, Easing.InOutExpo);
checkmark.ScaleTo(new Vector2(13), 500, Easing.InOutExpo); checkmark.ScaleTo(new Vector2(13), 500, Easing.InOutExpo);
break; break;
} }

View File

@ -0,0 +1,48 @@
// 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.Shapes;
using osu.Framework.Graphics.Sprites;
using osuTK;
namespace osu.Game.Graphics.UserInterface
{
public class GrayButton : OsuAnimatedButton
{
protected SpriteIcon Icon { get; private set; }
protected Box Background { get; private set; }
private readonly IconUsage icon;
[Resolved]
private OsuColour colours { get; set; }
public GrayButton(IconUsage icon)
{
this.icon = icon;
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
Background = new Box
{
Colour = colours.Gray4,
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue
},
Icon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(13),
Icon = icon,
},
};
}
}
}

View File

@ -42,13 +42,7 @@ namespace osu.Game.Graphics.UserInterface
}, },
}; };
Current.ValueChanged += filled => Current.ValueChanged += filled => fill.FadeTo(filled.NewValue ? 1 : 0, 200, Easing.OutQuint);
{
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
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -5,6 +5,7 @@ using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -18,6 +19,11 @@ namespace osu.Game.Graphics.UserInterface
public Color4 UncheckedColor { get; set; } = Color4.White; public Color4 UncheckedColor { get; set; } = Color4.White;
public int FadeDuration { get; set; } 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 public string LabelText
{ {
set set
@ -43,7 +49,7 @@ namespace osu.Game.Graphics.UserInterface
private SampleChannel sampleChecked; private SampleChannel sampleChecked;
private SampleChannel sampleUnchecked; private SampleChannel sampleUnchecked;
public OsuCheckbox() public OsuCheckbox(bool nubOnRight = true)
{ {
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -52,26 +58,42 @@ namespace osu.Game.Graphics.UserInterface
Children = new Drawable[] Children = new Drawable[]
{ {
labelText = new OsuTextFlowContainer labelText = new OsuTextFlowContainer(ApplyLabelParameters)
{ {
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X, 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() 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); Nub.Current.BindTo(Current);
Current.DisabledChanged += disabled => labelText.Alpha = Nub.Alpha = disabled ? 0.3f : 1; 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] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load(AudioManager audio)
{ {
@ -96,10 +118,14 @@ namespace osu.Game.Graphics.UserInterface
protected override void OnUserChange(bool value) protected override void OnUserChange(bool value)
{ {
base.OnUserChange(value); base.OnUserChange(value);
if (value)
sampleChecked?.Play(); if (PlaySoundsOnUserChange)
else {
sampleUnchecked?.Play(); if (value)
sampleChecked?.Play();
else
sampleUnchecked?.Play();
}
} }
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.IO; using System.IO;
using osu.Framework.IO.Network; 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)); 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); Success?.Invoke(filename);
} }

View File

@ -23,6 +23,7 @@ namespace osu.Game.Online.API
[JsonProperty("settings")] [JsonProperty("settings")]
[Key(1)] [Key(1)]
[MessagePackFormatter(typeof(ModSettingsDictionaryFormatter))]
public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>(); public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>();
[JsonConstructor] [JsonConstructor]

View File

@ -10,7 +10,7 @@ namespace osu.Game.Online.API
{ {
public readonly TModel Model; public readonly TModel Model;
public float Progress; public float Progress { get; private set; }
public event Action<float> DownloadProgressed; public event Action<float> DownloadProgressed;
@ -18,7 +18,13 @@ namespace osu.Game.Online.API
{ {
Model = model; 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);
} }
} }
} }

View 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;
}
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -20,7 +21,7 @@ namespace osu.Game.Online
protected readonly Bindable<TModel> Model = new Bindable<TModel>(); protected readonly Bindable<TModel> Model = new Bindable<TModel>();
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private TModelManager manager { get; set; } protected TModelManager Manager { get; private set; }
/// <summary> /// <summary>
/// Holds the current download state of the <typeparamref name="TModel"/>, whether is has already been downloaded, is in progress, or is not downloaded. /// 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) if (modelInfo.NewValue == null)
attachDownload(null); attachDownload(null);
else if (manager?.IsAvailableLocally(modelInfo.NewValue) == true) else if (IsModelAvailableLocally())
State.Value = DownloadState.LocallyAvailable; State.Value = DownloadState.LocallyAvailable;
else else
attachDownload(manager?.GetExistingDownload(modelInfo.NewValue)); attachDownload(Manager?.GetExistingDownload(modelInfo.NewValue));
}, true); }, true);
if (manager == null) if (Manager == null)
return; return;
managerDownloadBegan = manager.DownloadBegan.GetBoundCopy(); managerDownloadBegan = Manager.DownloadBegan.GetBoundCopy();
managerDownloadBegan.BindValueChanged(downloadBegan); managerDownloadBegan.BindValueChanged(downloadBegan);
managerDownloadFailed = manager.DownloadFailed.GetBoundCopy(); managerDownloadFailed = Manager.DownloadFailed.GetBoundCopy();
managerDownloadFailed.BindValueChanged(downloadFailed); managerDownloadFailed.BindValueChanged(downloadFailed);
managedUpdated = manager.ItemUpdated.GetBoundCopy(); managedUpdated = Manager.ItemUpdated.GetBoundCopy();
managedUpdated.BindValueChanged(itemUpdated); managedUpdated.BindValueChanged(itemUpdated);
managerRemoved = manager.ItemRemoved.GetBoundCopy(); managerRemoved = Manager.ItemRemoved.GetBoundCopy();
managerRemoved.BindValueChanged(itemRemoved); 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) private void downloadBegan(ValueChangedEvent<WeakReference<ArchiveDownloadRequest<TModel>>> weakRequest)
{ {
if (weakRequest.NewValue.TryGetTarget(out var request)) if (weakRequest.NewValue.TryGetTarget(out var request))
@ -134,23 +151,35 @@ namespace osu.Game.Online
private void itemUpdated(ValueChangedEvent<WeakReference<TModel>> weakItem) private void itemUpdated(ValueChangedEvent<WeakReference<TModel>> weakItem)
{ {
if (weakItem.NewValue.TryGetTarget(out var item)) 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) private void itemRemoved(ValueChangedEvent<WeakReference<TModel>> weakItem)
{ {
if (weakItem.NewValue.TryGetTarget(out var item)) 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 #region Disposal
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)

View File

@ -1,7 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Game.Online.API;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
namespace osu.Game.Online.Multiplayer 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> /// <param name="beatmapAvailability">The new beatmap availability state of the user.</param>
Task UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability); 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> /// <summary>
/// Signals that a match is to be started. This will *only* be sent to clients which are to begin loading at this point. /// Signals that a match is to be started. This will *only* be sent to clients which are to begin loading at this point.
/// </summary> /// </summary>

View File

@ -1,7 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Game.Online.API;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
namespace osu.Game.Online.Multiplayer namespace osu.Game.Online.Multiplayer
@ -47,6 +49,12 @@ namespace osu.Game.Online.Multiplayer
/// <param name="newBeatmapAvailability">The proposed new beatmap availability state.</param> /// <param name="newBeatmapAvailability">The proposed new beatmap availability state.</param>
Task ChangeBeatmapAvailability(BeatmapAvailability newBeatmapAvailability); 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> /// <summary>
/// As the host of a room, start the match. /// As the host of a room, start the match.
/// </summary> /// </summary>

View File

@ -4,6 +4,7 @@
#nullable enable #nullable enable
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -91,6 +92,7 @@ namespace osu.Game.Online.Multiplayer
connection.On(nameof(IMultiplayerClient.LoadRequested), ((IMultiplayerClient)this).LoadRequested); connection.On(nameof(IMultiplayerClient.LoadRequested), ((IMultiplayerClient)this).LoadRequested);
connection.On(nameof(IMultiplayerClient.MatchStarted), ((IMultiplayerClient)this).MatchStarted); connection.On(nameof(IMultiplayerClient.MatchStarted), ((IMultiplayerClient)this).MatchStarted);
connection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady); connection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady);
connection.On<int, IEnumerable<APIMod>>(nameof(IMultiplayerClient.UserModsChanged), ((IMultiplayerClient)this).UserModsChanged);
connection.Closed += async ex => connection.Closed += async ex =>
{ {
@ -189,6 +191,14 @@ namespace osu.Game.Online.Multiplayer
return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeBeatmapAvailability), newBeatmapAvailability); 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() public override Task StartMatch()
{ {
if (!isConnected.Value) if (!isConnected.Value)

View File

@ -30,15 +30,24 @@ namespace osu.Game.Online.Multiplayer
[NotNull] [NotNull]
[Key(4)] [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) public bool Equals(MultiplayerRoomSettings other)
=> BeatmapID == other.BeatmapID => BeatmapID == other.BeatmapID
&& BeatmapChecksum == other.BeatmapChecksum && BeatmapChecksum == other.BeatmapChecksum
&& Mods.SequenceEqual(other.Mods) && RequiredMods.SequenceEqual(other.RequiredMods)
&& AllowedMods.SequenceEqual(other.AllowedMods)
&& RulesetID == other.RulesetID && RulesetID == other.RulesetID
&& Name.Equals(other.Name, StringComparison.Ordinal); && 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}";
} }
} }

View File

@ -4,8 +4,12 @@
#nullable enable #nullable enable
using System; using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using MessagePack; using MessagePack;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Game.Online.API;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Users; using osu.Game.Users;
@ -27,6 +31,13 @@ namespace osu.Game.Online.Multiplayer
[Key(2)] [Key(2)]
public BeatmapAvailability BeatmapAvailability { get; set; } = BeatmapAvailability.LocallyAvailable(); 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] [IgnoreMember]
public User? User { get; set; } public User? User { get; set; }

View File

@ -21,6 +21,7 @@ using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Online.Rooms.RoomStatuses;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Utils; using osu.Game.Utils;
@ -191,7 +192,8 @@ namespace osu.Game.Online.Multiplayer
BeatmapID = item.GetOr(existingPlaylistItem).BeatmapID, BeatmapID = item.GetOr(existingPlaylistItem).BeatmapID,
BeatmapChecksum = item.GetOr(existingPlaylistItem).Beatmap.Value.MD5Hash, BeatmapChecksum = item.GetOr(existingPlaylistItem).Beatmap.Value.MD5Hash,
RulesetID = item.GetOr(existingPlaylistItem).RulesetID, 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); 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(); public abstract Task StartMatch();
Task IMultiplayerClient.RoomStateChanged(MultiplayerRoomState state) Task IMultiplayerClient.RoomStateChanged(MultiplayerRoomState state)
@ -377,6 +387,27 @@ namespace osu.Game.Online.Multiplayer
return Task.CompletedTask; 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() Task IMultiplayerClient.LoadRequested()
{ {
if (Room == null) if (Room == null)
@ -500,7 +531,8 @@ namespace osu.Game.Online.Multiplayer
beatmap.MD5Hash = settings.BeatmapChecksum; beatmap.MD5Hash = settings.BeatmapChecksum;
var ruleset = rulesets.GetRuleset(settings.RulesetID).CreateInstance(); 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 PlaylistItem playlistItem = new PlaylistItem
{ {
@ -510,6 +542,7 @@ namespace osu.Game.Online.Multiplayer
}; };
playlistItem.RequiredMods.AddRange(mods); playlistItem.RequiredMods.AddRange(mods);
playlistItem.AllowedMods.AddRange(allowedMods);
apiRoom.Playlist.Clear(); // Clearing should be unnecessary, but here for sanity. apiRoom.Playlist.Clear(); // Clearing should be unnecessary, but here for sanity.
apiRoom.Playlist.Add(playlistItem); apiRoom.Playlist.Add(playlistItem);

View File

@ -23,17 +23,17 @@ namespace osu.Game.Online.Rooms
/// The beatmap's downloading progress, null when not in <see cref="DownloadState.Downloading"/> state. /// The beatmap's downloading progress, null when not in <see cref="DownloadState.Downloading"/> state.
/// </summary> /// </summary>
[Key(1)] [Key(1)]
public readonly double? DownloadProgress; public readonly float? DownloadProgress;
[JsonConstructor] [JsonConstructor]
public BeatmapAvailability(DownloadState state, double? downloadProgress = null) public BeatmapAvailability(DownloadState state, float? downloadProgress = null)
{ {
State = state; State = state;
DownloadProgress = downloadProgress; DownloadProgress = downloadProgress;
} }
public static BeatmapAvailability NotDownloaded() => new BeatmapAvailability(DownloadState.NotDownloaded); 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 Importing() => new BeatmapAvailability(DownloadState.Importing);
public static BeatmapAvailability LocallyAvailable() => new BeatmapAvailability(DownloadState.LocallyAvailable); public static BeatmapAvailability LocallyAvailable() => new BeatmapAvailability(DownloadState.LocallyAvailable);

View File

@ -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));
}
}
}
}

View File

@ -468,6 +468,12 @@ namespace osu.Game
private void modsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods) private void modsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
{ {
updateModDefaults(); updateModDefaults();
if (!ModUtils.CheckValidForGameplay(mods.NewValue, out var invalid))
{
// ensure we always have a valid set of mods.
SelectedMods.Value = mods.NewValue.Except(invalid).ToArray();
}
} }
private void updateModDefaults() private void updateModDefaults()

View File

@ -16,6 +16,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Utils;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
namespace osu.Game.Overlays.Chat namespace osu.Game.Overlays.Chat
@ -24,7 +25,7 @@ namespace osu.Game.Overlays.Chat
{ {
public readonly Channel Channel; public readonly Channel Channel;
protected FillFlowContainer ChatLineFlow; protected FillFlowContainer ChatLineFlow;
private OsuScrollContainer scroll; private ChannelScrollContainer scroll;
private bool scrollbarVisible = true; private bool scrollbarVisible = true;
@ -56,7 +57,7 @@ namespace osu.Game.Overlays.Chat
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
Child = scroll = new OsuScrollContainer Child = scroll = new ChannelScrollContainer
{ {
ScrollbarVisible = scrollbarVisible, ScrollbarVisible = scrollbarVisible,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -80,12 +81,6 @@ namespace osu.Game.Overlays.Chat
Channel.PendingMessageResolved += pendingMessageResolved; Channel.PendingMessageResolved += pendingMessageResolved;
} }
protected override void LoadComplete()
{
base.LoadComplete();
scrollToEnd();
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
@ -113,8 +108,6 @@ namespace osu.Game.Overlays.Chat
ChatLineFlow.Clear(); ChatLineFlow.Clear();
} }
bool shouldScrollToEnd = scroll.IsScrolledToEnd(10) || !chatLines.Any() || newMessages.Any(m => m is LocalMessage);
// Add up to last Channel.MAX_HISTORY messages // Add up to last Channel.MAX_HISTORY messages
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY)); var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
@ -153,8 +146,10 @@ namespace osu.Game.Overlays.Chat
} }
} }
if (shouldScrollToEnd) // due to the scroll adjusts from old messages removal above, a scroll-to-end must be enforced,
scrollToEnd(); // to avoid making the container think the user has scrolled back up and unwantedly disable auto-scrolling.
if (newMessages.Any(m => m is LocalMessage))
scroll.ScrollToEnd();
}); });
private void pendingMessageResolved(Message existing, Message updated) => Schedule(() => private void pendingMessageResolved(Message existing, Message updated) => Schedule(() =>
@ -178,8 +173,6 @@ namespace osu.Game.Overlays.Chat
private IEnumerable<ChatLine> chatLines => ChatLineFlow.Children.OfType<ChatLine>(); private IEnumerable<ChatLine> chatLines => ChatLineFlow.Children.OfType<ChatLine>();
private void scrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd());
public class DaySeparator : Container public class DaySeparator : Container
{ {
public float TextSize public float TextSize
@ -243,5 +236,51 @@ namespace osu.Game.Overlays.Chat
}; };
} }
} }
/// <summary>
/// An <see cref="OsuScrollContainer"/> with functionality to automatically scroll whenever the maximum scrollable distance increases.
/// </summary>
private class ChannelScrollContainer : UserTrackingScrollContainer
{
/// <summary>
/// The chat will be automatically scrolled to end if and only if
/// the distance between the current scroll position and the end of the scroll
/// is less than this value.
/// </summary>
private const float auto_scroll_leniency = 10f;
private float? lastExtent;
protected override void OnUserScroll(float value, bool animated = true, double? distanceDecay = default)
{
base.OnUserScroll(value, animated, distanceDecay);
lastExtent = null;
}
protected override void Update()
{
base.Update();
// If the user has scrolled to the bottom of the container, we should resume tracking new content.
if (UserScrolling && IsScrolledToEnd(auto_scroll_leniency))
CancelUserScroll();
// If the user hasn't overridden our behaviour and there has been new content added to the container, we should update our scroll position to track it.
bool requiresScrollUpdate = !UserScrolling && (lastExtent == null || Precision.AlmostBigger(ScrollableExtent, lastExtent.Value));
if (requiresScrollUpdate)
{
// Schedule required to allow FillFlow to be the correct size.
Schedule(() =>
{
if (!UserScrolling)
{
ScrollToEnd();
lastExtent = ScrollableExtent;
}
});
}
}
}
} }
} }

View File

@ -11,31 +11,30 @@ using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using Humanizer;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
namespace osu.Game.Overlays.Mods namespace osu.Game.Overlays.Mods
{ {
public abstract class ModSection : Container public class ModSection : CompositeDrawable
{ {
private readonly OsuSpriteText headerLabel; private readonly Drawable header;
public FillFlowContainer<ModButtonEmpty> ButtonsContainer { get; } public FillFlowContainer<ModButtonEmpty> ButtonsContainer { get; }
public Action<Mod> Action; public Action<Mod> Action;
protected abstract Key[] ToggleKeys { get; }
public abstract ModType ModType { get; }
public string Header public Key[] ToggleKeys;
{
get => headerLabel.Text; public readonly ModType ModType;
set => headerLabel.Text = value;
}
public IEnumerable<Mod> SelectedMods => buttons.Select(b => b.SelectedMod).Where(m => m != null); public IEnumerable<Mod> SelectedMods => buttons.Select(b => b.SelectedMod).Where(m => m != null);
private CancellationTokenSource modsLoadCts; private CancellationTokenSource modsLoadCts;
protected bool SelectionAnimationRunning => pendingSelectionOperations.Count > 0;
/// <summary> /// <summary>
/// True when all mod icons have completed loading. /// True when all mod icons have completed loading.
/// </summary> /// </summary>
@ -52,7 +51,11 @@ namespace osu.Game.Overlays.Mods
return new ModButton(m) return new ModButton(m)
{ {
SelectionChanged = Action, SelectionChanged = mod =>
{
ModButtonStateChanged(mod);
Action?.Invoke(mod);
},
}; };
}).ToArray(); }).ToArray();
@ -61,7 +64,7 @@ namespace osu.Game.Overlays.Mods
if (modContainers.Length == 0) if (modContainers.Length == 0)
{ {
ModIconsLoaded = true; ModIconsLoaded = true;
headerLabel.Hide(); header.Hide();
Hide(); Hide();
return; return;
} }
@ -76,11 +79,15 @@ namespace osu.Game.Overlays.Mods
buttons = modContainers.OfType<ModButton>().ToArray(); buttons = modContainers.OfType<ModButton>().ToArray();
headerLabel.FadeIn(200); header.FadeIn(200);
this.FadeIn(200); this.FadeIn(200);
} }
} }
protected virtual void ModButtonStateChanged(Mod mod)
{
}
private ModButton[] buttons = Array.Empty<ModButton>(); private ModButton[] buttons = Array.Empty<ModButton>();
protected override bool OnKeyDown(KeyDownEvent e) protected override bool OnKeyDown(KeyDownEvent e)
@ -97,30 +104,75 @@ namespace osu.Game.Overlays.Mods
return base.OnKeyDown(e); 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> /// <summary>
/// Deselect one or more mods in this section. /// Deselect one or more mods in this section.
/// </summary> /// </summary>
/// <param name="modTypes">The types of <see cref="Mod"/>s which should be deselected.</param> /// <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) public void DeselectTypes(IEnumerable<Type> modTypes, bool immediate = false)
{ {
int delay = 0;
foreach (var button in buttons) foreach (var button in buttons)
{ {
Mod selected = button.SelectedMod; if (button.SelectedMod == null) continue;
if (selected == null) continue;
foreach (var type in modTypes) foreach (var type in modTypes)
{ {
if (type.IsInstanceOfType(selected)) if (type.IsInstanceOfType(button.SelectedMod))
{ {
if (immediate) if (immediate)
button.Deselect(); button.Deselect();
else else
Scheduler.AddDelayed(button.Deselect, delay += 50); pendingSelectionOperations.Enqueue(button.Deselect);
} }
} }
} }
@ -130,13 +182,13 @@ namespace osu.Game.Overlays.Mods
/// Updates all buttons with the given list of selected mods. /// Updates all buttons with the given list of selected mods.
/// </summary> /// </summary>
/// <param name="newSelectedMods">The new list of selected mods to select.</param> /// <param name="newSelectedMods">The new list of selected mods to select.</param>
public void UpdateSelectedMods(IReadOnlyList<Mod> newSelectedMods) public void UpdateSelectedButtons(IReadOnlyList<Mod> newSelectedMods)
{ {
foreach (var button in buttons) foreach (var button in buttons)
updateButtonMods(button, newSelectedMods); updateButtonSelection(button, newSelectedMods);
} }
private void updateButtonMods(ModButton button, IReadOnlyList<Mod> newSelectedMods) private void updateButtonSelection(ModButton button, IReadOnlyList<Mod> newSelectedMods)
{ {
foreach (var mod in newSelectedMods) foreach (var mod in newSelectedMods)
{ {
@ -153,23 +205,19 @@ namespace osu.Game.Overlays.Mods
button.Deselect(); button.Deselect();
} }
protected ModSection() public ModSection(ModType type)
{ {
ModType = type;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Origin = Anchor.TopCentre; Origin = Anchor.TopCentre;
Anchor = Anchor.TopCentre; Anchor = Anchor.TopCentre;
Children = new Drawable[] InternalChildren = new[]
{ {
headerLabel = new OsuSpriteText header = CreateHeader(type.Humanize(LetterCasing.Title)),
{
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
Position = new Vector2(0f, 0f),
Font = OsuFont.GetFont(weight: FontWeight.Bold)
},
ButtonsContainer = new FillFlowContainer<ModButtonEmpty> ButtonsContainer = new FillFlowContainer<ModButtonEmpty>
{ {
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
@ -185,5 +233,20 @@ namespace osu.Game.Overlays.Mods
}, },
}; };
} }
protected virtual Drawable CreateHeader(string text) => new OsuSpriteText
{
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();
}
} }
} }

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
@ -19,30 +20,54 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Overlays.Mods.Sections;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Utils;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using osuTK.Input; using osuTK.Input;
namespace osu.Game.Overlays.Mods namespace osu.Game.Overlays.Mods
{ {
public class ModSelectOverlay : WaveOverlayContainer public abstract class ModSelectOverlay : WaveOverlayContainer
{ {
private readonly Func<Mod, bool> isValidMod;
public const float HEIGHT = 510; public const float HEIGHT = 510;
protected readonly TriangleButton DeselectAllButton; protected readonly TriangleButton DeselectAllButton;
protected readonly TriangleButton CustomiseButton; protected readonly TriangleButton CustomiseButton;
protected readonly TriangleButton CloseButton; protected readonly TriangleButton CloseButton;
protected readonly Drawable MultiplierSection;
protected readonly OsuSpriteText MultiplierLabel; protected readonly OsuSpriteText MultiplierLabel;
protected readonly FillFlowContainer FooterContainer;
protected override bool BlockNonPositionalInput => false; protected override bool BlockNonPositionalInput => false;
protected override bool DimMainContent => false; protected override bool DimMainContent => false;
/// <summary>
/// Whether <see cref="Mod"/>s underneath the same <see cref="MultiMod"/> instance should appear as stacked buttons.
/// </summary>
protected virtual bool Stacked => true;
[NotNull]
private Func<Mod, bool> isValidMod = m => true;
/// <summary>
/// A function that checks whether a given mod is selectable.
/// </summary>
[NotNull]
public Func<Mod, bool> IsValidMod
{
get => isValidMod;
set
{
isValidMod = value ?? throw new ArgumentNullException(nameof(value));
updateAvailableMods();
}
}
protected readonly FillFlowContainer<ModSection> ModSectionsContainer; protected readonly FillFlowContainer<ModSection> ModSectionsContainer;
protected readonly ModSettingsContainer ModSettingsContainer; protected readonly ModSettingsContainer ModSettingsContainer;
@ -57,14 +82,10 @@ namespace osu.Game.Overlays.Mods
private const float content_width = 0.8f; private const float content_width = 0.8f;
private const float footer_button_spacing = 20; private const float footer_button_spacing = 20;
private readonly FillFlowContainer footerContainer;
private SampleChannel sampleOn, sampleOff; private SampleChannel sampleOn, sampleOff;
public ModSelectOverlay(Func<Mod, bool> isValidMod = null) protected ModSelectOverlay()
{ {
this.isValidMod = isValidMod ?? (m => true);
Waves.FirstWaveColour = Color4Extensions.FromHex(@"19b0e2"); Waves.FirstWaveColour = Color4Extensions.FromHex(@"19b0e2");
Waves.SecondWaveColour = Color4Extensions.FromHex(@"2280a2"); Waves.SecondWaveColour = Color4Extensions.FromHex(@"2280a2");
Waves.ThirdWaveColour = Color4Extensions.FromHex(@"005774"); Waves.ThirdWaveColour = Color4Extensions.FromHex(@"005774");
@ -190,13 +211,31 @@ namespace osu.Game.Overlays.Mods
Width = content_width, Width = content_width,
LayoutDuration = 200, LayoutDuration = 200,
LayoutEasing = Easing.OutQuint, LayoutEasing = Easing.OutQuint,
Children = new ModSection[] Children = new[]
{ {
new DifficultyReductionSection { Action = modButtonPressed }, CreateModSection(ModType.DifficultyReduction).With(s =>
new DifficultyIncreaseSection { Action = modButtonPressed }, {
new AutomationSection { Action = modButtonPressed }, s.ToggleKeys = new[] { Key.Q, Key.W, Key.E, Key.R, Key.T, Key.Y, Key.U, Key.I, Key.O, Key.P };
new ConversionSection { Action = modButtonPressed }, s.Action = modButtonPressed;
new FunSection { Action = modButtonPressed }, }),
CreateModSection(ModType.DifficultyIncrease).With(s =>
{
s.ToggleKeys = new[] { Key.A, Key.S, Key.D, Key.F, Key.G, Key.H, Key.J, Key.K, Key.L };
s.Action = modButtonPressed;
}),
CreateModSection(ModType.Automation).With(s =>
{
s.ToggleKeys = new[] { Key.Z, Key.X, Key.C, Key.V, Key.B, Key.N, Key.M };
s.Action = modButtonPressed;
}),
CreateModSection(ModType.Conversion).With(s =>
{
s.Action = modButtonPressed;
}),
CreateModSection(ModType.Fun).With(s =>
{
s.Action = modButtonPressed;
}),
} }
}, },
} }
@ -231,7 +270,7 @@ namespace osu.Game.Overlays.Mods
Colour = new Color4(172, 20, 116, 255), Colour = new Color4(172, 20, 116, 255),
Alpha = 0.5f, Alpha = 0.5f,
}, },
footerContainer = new FillFlowContainer FooterContainer = new FillFlowContainer
{ {
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
@ -245,7 +284,7 @@ namespace osu.Game.Overlays.Mods
Vertical = 15, Vertical = 15,
Horizontal = OsuScreen.HORIZONTAL_OVERFLOW_PADDING Horizontal = OsuScreen.HORIZONTAL_OVERFLOW_PADDING
}, },
Children = new Drawable[] Children = new[]
{ {
DeselectAllButton = new TriangleButton DeselectAllButton = new TriangleButton
{ {
@ -272,7 +311,7 @@ namespace osu.Game.Overlays.Mods
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
}, },
new FillFlowContainer MultiplierSection = new FillFlowContainer
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Spacing = new Vector2(footer_button_spacing / 2, 0), Spacing = new Vector2(footer_button_spacing / 2, 0),
@ -328,33 +367,25 @@ namespace osu.Game.Overlays.Mods
refreshSelectedMods(); refreshSelectedMods();
} }
/// <summary>
/// Deselect one or more mods.
/// </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>
private void deselectTypes(Type[] modTypes, bool immediate = false)
{
if (modTypes.Length == 0) return;
foreach (var section in ModSectionsContainer.Children)
section.DeselectTypes(modTypes, immediate);
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
availableMods.BindValueChanged(availableModsChanged, true); availableMods.BindValueChanged(_ => updateAvailableMods(), true);
SelectedMods.BindValueChanged(selectedModsChanged, true); SelectedMods.BindValueChanged(_ => updateSelectedButtons(), true);
} }
protected override void PopOut() protected override void PopOut()
{ {
base.PopOut(); base.PopOut();
footerContainer.MoveToX(content_width, WaveContainer.DISAPPEAR_DURATION, Easing.InSine); foreach (var section in ModSectionsContainer)
footerContainer.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.InSine); {
section.FlushAnimation();
}
FooterContainer.MoveToX(content_width, WaveContainer.DISAPPEAR_DURATION, Easing.InSine);
FooterContainer.FadeOut(WaveContainer.DISAPPEAR_DURATION, Easing.InSine);
foreach (var section in ModSectionsContainer.Children) foreach (var section in ModSectionsContainer.Children)
{ {
@ -368,8 +399,8 @@ namespace osu.Game.Overlays.Mods
{ {
base.PopIn(); base.PopIn();
footerContainer.MoveToX(0, WaveContainer.APPEAR_DURATION, Easing.OutQuint); FooterContainer.MoveToX(0, WaveContainer.APPEAR_DURATION, Easing.OutQuint);
footerContainer.FadeIn(WaveContainer.APPEAR_DURATION, Easing.OutQuint); FooterContainer.FadeIn(WaveContainer.APPEAR_DURATION, Easing.OutQuint);
foreach (var section in ModSectionsContainer.Children) foreach (var section in ModSectionsContainer.Children)
{ {
@ -400,18 +431,53 @@ namespace osu.Game.Overlays.Mods
public override bool OnPressed(GlobalAction action) => false; // handled by back button public override bool OnPressed(GlobalAction action) => false; // handled by back button
private void availableModsChanged(ValueChangedEvent<Dictionary<ModType, IReadOnlyList<Mod>>> mods) private void updateAvailableMods()
{ {
if (mods.NewValue == null) return; if (availableMods?.Value == null)
return;
foreach (var section in ModSectionsContainer.Children) foreach (var section in ModSectionsContainer.Children)
section.Mods = mods.NewValue[section.ModType].Where(isValidMod); {
IEnumerable<Mod> modEnumeration = availableMods.Value[section.ModType];
if (!Stacked)
modEnumeration = ModUtils.FlattenMods(modEnumeration);
section.Mods = modEnumeration.Select(getValidModOrNull).Where(m => m != null);
}
updateSelectedButtons();
} }
private void selectedModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods) /// <summary>
/// Returns a valid form of a given <see cref="Mod"/> if possible, or null otherwise.
/// </summary>
/// <remarks>
/// This is a recursive process during which any invalid mods are culled while preserving <see cref="MultiMod"/> structures where possible.
/// </remarks>
/// <param name="mod">The <see cref="Mod"/> to check.</param>
/// <returns>A valid form of <paramref name="mod"/> if exists, or null otherwise.</returns>
[CanBeNull]
private Mod getValidModOrNull([NotNull] Mod mod)
{ {
if (!(mod is MultiMod multi))
return IsValidMod(mod) ? mod : null;
var validSubset = multi.Mods.Select(getValidModOrNull).Where(m => m != null).ToArray();
if (validSubset.Length == 0)
return null;
return validSubset.Length == 1 ? validSubset[0] : new MultiMod(validSubset);
}
private void updateSelectedButtons()
{
// Enumeration below may update the bindable list.
var selectedMods = SelectedMods.Value.ToList();
foreach (var section in ModSectionsContainer.Children) foreach (var section in ModSectionsContainer.Children)
section.UpdateSelectedMods(mods.NewValue); section.UpdateSelectedButtons(selectedMods);
updateMods(); updateMods();
} }
@ -438,22 +504,42 @@ namespace osu.Game.Overlays.Mods
{ {
if (selectedMod != null) if (selectedMod != null)
{ {
if (State.Value == Visibility.Visible) sampleOn?.Play(); if (State.Value == Visibility.Visible)
Scheduler.AddOnce(playSelectedSound);
deselectTypes(selectedMod.IncompatibleMods, true); OnModSelected(selectedMod);
if (selectedMod.RequiresConfiguration) ModSettingsContainer.Show(); if (selectedMod.RequiresConfiguration) ModSettingsContainer.Show();
} }
else else
{ {
if (State.Value == Visibility.Visible) sampleOff?.Play(); if (State.Value == Visibility.Visible)
Scheduler.AddOnce(playDeselectedSound);
} }
refreshSelectedMods(); refreshSelectedMods();
} }
private void playSelectedSound() => sampleOn?.Play();
private void playDeselectedSound() => sampleOff?.Play();
/// <summary>
/// Invoked when a new <see cref="Mod"/> has been selected.
/// </summary>
/// <param name="mod">The <see cref="Mod"/> that has been selected.</param>
protected virtual void OnModSelected(Mod mod)
{
}
private void refreshSelectedMods() => SelectedMods.Value = ModSectionsContainer.Children.SelectMany(s => s.SelectedMods).ToArray(); private void refreshSelectedMods() => SelectedMods.Value = ModSectionsContainer.Children.SelectMany(s => s.SelectedMods).ToArray();
/// <summary>
/// Creates a <see cref="ModSection"/> that groups <see cref="Mod"/>s with the same <see cref="ModType"/>.
/// </summary>
/// <param name="type">The <see cref="ModType"/> of <see cref="Mod"/>s in the section.</param>
/// <returns>The <see cref="ModSection"/>.</returns>
protected virtual ModSection CreateModSection(ModType type) => new ModSection(type);
#region Disposal #region Disposal
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)

View File

@ -1,19 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Rulesets.Mods;
using osuTK.Input;
namespace osu.Game.Overlays.Mods.Sections
{
public class AutomationSection : ModSection
{
protected override Key[] ToggleKeys => new[] { Key.Z, Key.X, Key.C, Key.V, Key.B, Key.N, Key.M };
public override ModType ModType => ModType.Automation;
public AutomationSection()
{
Header = @"Automation";
}
}
}

View File

@ -1,19 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Rulesets.Mods;
using osuTK.Input;
namespace osu.Game.Overlays.Mods.Sections
{
public class ConversionSection : ModSection
{
protected override Key[] ToggleKeys => null;
public override ModType ModType => ModType.Conversion;
public ConversionSection()
{
Header = @"Conversion";
}
}
}

View File

@ -1,19 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Rulesets.Mods;
using osuTK.Input;
namespace osu.Game.Overlays.Mods.Sections
{
public class DifficultyIncreaseSection : ModSection
{
protected override Key[] ToggleKeys => new[] { Key.A, Key.S, Key.D, Key.F, Key.G, Key.H, Key.J, Key.K, Key.L };
public override ModType ModType => ModType.DifficultyIncrease;
public DifficultyIncreaseSection()
{
Header = @"Difficulty Increase";
}
}
}

View File

@ -1,19 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Rulesets.Mods;
using osuTK.Input;
namespace osu.Game.Overlays.Mods.Sections
{
public class DifficultyReductionSection : ModSection
{
protected override Key[] ToggleKeys => new[] { Key.Q, Key.W, Key.E, Key.R, Key.T, Key.Y, Key.U, Key.I, Key.O, Key.P };
public override ModType ModType => ModType.DifficultyReduction;
public DifficultyReductionSection()
{
Header = @"Difficulty Reduction";
}
}
}

View File

@ -1,19 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Rulesets.Mods;
using osuTK.Input;
namespace osu.Game.Overlays.Mods.Sections
{
public class FunSection : ModSection
{
protected override Key[] ToggleKeys => null;
public override ModType ModType => ModType.Fun;
public FunSection()
{
Header = @"Fun";
}
}
}

View File

@ -0,0 +1,18 @@
// 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.Game.Rulesets.Mods;
namespace osu.Game.Overlays.Mods
{
public class SoloModSelectOverlay : ModSelectOverlay
{
protected override void OnModSelected(Mod mod)
{
base.OnModSelected(mod);
foreach (var section in ModSectionsContainer.Children)
section.DeselectTypes(mod.IncompatibleMods, true);
}
}
}

View File

@ -29,8 +29,6 @@ namespace osu.Game.Rulesets.UI
private const float size = 80; private const float size = 80;
private readonly ModType type;
public virtual string TooltipText => showTooltip ? mod.IconTooltip : null; public virtual string TooltipText => showTooltip ? mod.IconTooltip : null;
private Mod mod; private Mod mod;
@ -42,10 +40,18 @@ namespace osu.Game.Rulesets.UI
set set
{ {
mod = value; mod = value;
updateMod(value);
if (IsLoaded)
updateMod(value);
} }
} }
[Resolved]
private OsuColour colours { get; set; }
private Color4 backgroundColour;
private Color4 highlightedColour;
/// <summary> /// <summary>
/// Construct a new instance. /// Construct a new instance.
/// </summary> /// </summary>
@ -56,8 +62,6 @@ namespace osu.Game.Rulesets.UI
this.mod = mod ?? throw new ArgumentNullException(nameof(mod)); this.mod = mod ?? throw new ArgumentNullException(nameof(mod));
this.showTooltip = showTooltip; this.showTooltip = showTooltip;
type = mod.Type;
Size = new Vector2(size); Size = new Vector2(size);
Children = new Drawable[] Children = new Drawable[]
@ -89,6 +93,13 @@ namespace osu.Game.Rulesets.UI
Icon = FontAwesome.Solid.Question Icon = FontAwesome.Solid.Question
}, },
}; };
}
protected override void LoadComplete()
{
base.LoadComplete();
Selected.BindValueChanged(_ => updateColour());
updateMod(mod); updateMod(mod);
} }
@ -102,20 +113,14 @@ namespace osu.Game.Rulesets.UI
{ {
modIcon.FadeOut(); modIcon.FadeOut();
modAcronym.FadeIn(); modAcronym.FadeIn();
return; }
else
{
modIcon.FadeIn();
modAcronym.FadeOut();
} }
modIcon.FadeIn(); switch (value.Type)
modAcronym.FadeOut();
}
private Color4 backgroundColour;
private Color4 highlightedColour;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
switch (type)
{ {
default: default:
case ModType.DifficultyIncrease: case ModType.DifficultyIncrease:
@ -149,12 +154,13 @@ namespace osu.Game.Rulesets.UI
modIcon.Colour = colours.Yellow; modIcon.Colour = colours.Yellow;
break; break;
} }
updateColour();
} }
protected override void LoadComplete() private void updateColour()
{ {
base.LoadComplete(); background.Colour = Selected.Value ? highlightedColour : backgroundColour;
Selected.BindValueChanged(selected => background.Colour = selected.NewValue ? highlightedColour : backgroundColour, true);
} }
} }
} }

View File

@ -91,7 +91,11 @@ namespace osu.Game.Rulesets.UI.Scrolling
scrollingInfo = new LocalScrollingInfo(); scrollingInfo = new LocalScrollingInfo();
scrollingInfo.Direction.BindTo(Direction); scrollingInfo.Direction.BindTo(Direction);
scrollingInfo.TimeRange.BindTo(TimeRange); scrollingInfo.TimeRange.BindTo(TimeRange);
}
[BackgroundDependencyLoader]
private void load()
{
switch (VisualisationMethod) switch (VisualisationMethod)
{ {
case ScrollVisualisationMethod.Sequential: case ScrollVisualisationMethod.Sequential:
@ -106,11 +110,7 @@ namespace osu.Game.Rulesets.UI.Scrolling
scrollingInfo.Algorithm = new ConstantScrollAlgorithm(); scrollingInfo.Algorithm = new ConstantScrollAlgorithm();
break; break;
} }
}
[BackgroundDependencyLoader]
private void load()
{
double lastObjectTime = Objects.LastOrDefault()?.GetEndTime() ?? double.MaxValue; double lastObjectTime = Objects.LastOrDefault()?.GetEndTime() ?? double.MaxValue;
double baseBeatLength = TimingControlPoint.DEFAULT_BEAT_LENGTH; double baseBeatLength = TimingControlPoint.DEFAULT_BEAT_LENGTH;

View File

@ -1,77 +1,29 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
namespace osu.Game.Screens.OnlinePlay.Components namespace osu.Game.Screens.OnlinePlay.Components
{ {
public abstract class ReadyButton : TriangleButton public abstract class ReadyButton : TriangleButton
{ {
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
public new readonly BindableBool Enabled = new BindableBool(); public new readonly BindableBool Enabled = new BindableBool();
[Resolved] private IBindable<BeatmapAvailability> availability;
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;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OnlinePlayBeatmapAvailablilityTracker beatmapTracker)
{ {
managerUpdated = beatmaps.ItemUpdated.GetBoundCopy(); availability = beatmapTracker.Availability.GetBoundCopy();
managerUpdated.BindValueChanged(beatmapUpdated);
managerRemoved = beatmaps.ItemRemoved.GetBoundCopy();
managerRemoved.BindValueChanged(beatmapRemoved);
SelectedItem.BindValueChanged(item => updateSelectedItem(item.NewValue), true); availability.BindValueChanged(_ => updateState());
Enabled.BindValueChanged(_ => updateState(), true);
} }
private void updateSelectedItem(PlaylistItem _) => Scheduler.AddOnce(updateBeatmapState); private void updateState() => base.Enabled.Value = availability.Value.State == DownloadState.LocallyAvailable && Enabled.Value;
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;
}
} }
} }

View File

@ -124,101 +124,111 @@ namespace osu.Game.Screens.OnlinePlay
modDisplay.Current.Value = requiredMods.ToArray(); modDisplay.Current.Value = requiredMods.ToArray();
} }
protected override Drawable CreateContent() => maskingContainer = new Container protected override Drawable CreateContent()
{ {
RelativeSizeAxes = Axes.X, Action<SpriteText> fontParameters = s => s.Font = OsuFont.Default.With(weight: FontWeight.SemiBold);
Height = 50,
Masking = true, return maskingContainer = new Container
CornerRadius = 10,
Children = new Drawable[]
{ {
new Box // A transparent box that forces the border to be drawn if the panel background is opaque RelativeSizeAxes = Axes.X,
Height = 50,
Masking = true,
CornerRadius = 10,
Children = new Drawable[]
{ {
RelativeSizeAxes = Axes.Both, new Box // A transparent box that forces the border to be drawn if the panel background is opaque
Alpha = 0,
AlwaysPresent = true
},
new PanelBackground
{
RelativeSizeAxes = Axes.Both,
Beatmap = { BindTarget = beatmap }
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 8 },
Spacing = new Vector2(8, 0),
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{ {
difficultyIconContainer = new Container RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
},
new PanelBackground
{
RelativeSizeAxes = Axes.Both,
Beatmap = { BindTarget = beatmap }
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 8 },
Spacing = new Vector2(8, 0),
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{ {
Anchor = Anchor.CentreLeft, difficultyIconContainer = new Container
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
},
new FillFlowContainer
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{ {
beatmapText = new LinkFlowContainer { AutoSizeAxes = Axes.Both }, Anchor = Anchor.CentreLeft,
new FillFlowContainer Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
},
new FillFlowContainer
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{ {
AutoSizeAxes = Axes.Both, beatmapText = new LinkFlowContainer(fontParameters) { AutoSizeAxes = Axes.Both },
Direction = FillDirection.Horizontal, new FillFlowContainer
Spacing = new Vector2(10f, 0),
Children = new Drawable[]
{ {
new FillFlowContainer AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10f, 0),
Children = new Drawable[]
{ {
AutoSizeAxes = Axes.Both, new FillFlowContainer
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10f, 0),
Children = new Drawable[]
{ {
authorText = new LinkFlowContainer { AutoSizeAxes = Axes.Both }, AutoSizeAxes = Axes.Both,
explicitContentPill = new ExplicitContentBeatmapPill Direction = FillDirection.Horizontal,
Spacing = new Vector2(10f, 0),
Children = new Drawable[]
{ {
Alpha = 0f, authorText = new LinkFlowContainer(fontParameters) { AutoSizeAxes = Axes.Both },
Anchor = Anchor.CentreLeft, explicitContentPill = new ExplicitContentBeatmapPill
Origin = Anchor.CentreLeft, {
Margin = new MarginPadding { Top = 3f }, Alpha = 0f,
} Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Top = 3f },
}
},
}, },
}, new Container
new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Child = modDisplay = new ModDisplay
{ {
Scale = new Vector2(0.4f), Anchor = Anchor.CentreLeft,
DisplayUnrankedText = false, Origin = Anchor.CentreLeft,
ExpansionMode = ExpansionMode.AlwaysExpanded AutoSizeAxes = Axes.Both,
Child = modDisplay = new ModDisplay
{
Scale = new Vector2(0.4f),
DisplayUnrankedText = false,
ExpansionMode = ExpansionMode.AlwaysExpanded
}
} }
} }
} }
} }
} }
} }
},
new FillFlowContainer
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(5),
X = -10,
ChildrenEnumerable = CreateButtons().Select(button => button.With(b =>
{
b.Anchor = Anchor.Centre;
b.Origin = Anchor.Centre;
}))
} }
},
new FillFlowContainer
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
X = -18,
ChildrenEnumerable = CreateButtons()
} }
} };
}; }
protected virtual IEnumerable<Drawable> CreateButtons() => protected virtual IEnumerable<Drawable> CreateButtons() =>
new Drawable[] new Drawable[]
@ -227,14 +237,29 @@ namespace osu.Game.Screens.OnlinePlay
{ {
Size = new Vector2(50, 30) Size = new Vector2(50, 30)
}, },
new IconButton new PlaylistRemoveButton
{ {
Icon = FontAwesome.Solid.MinusSquare, Size = new Vector2(30, 30),
Alpha = allowEdit ? 1 : 0, Alpha = allowEdit ? 1 : 0,
Action = () => RequestDeletion?.Invoke(Model), Action = () => RequestDeletion?.Invoke(Model),
}, },
}; };
public class PlaylistRemoveButton : GrayButton
{
public PlaylistRemoveButton()
: base(FontAwesome.Solid.MinusSquare)
{
TooltipText = "Remove from playlist";
}
[BackgroundDependencyLoader]
private void load()
{
Icon.Scale = new Vector2(0.8f);
}
}
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
if (allowSelection) if (allowSelection)
@ -318,24 +343,18 @@ namespace osu.Game.Screens.OnlinePlay
Colour = Color4.Black, Colour = Color4.Black,
Width = 0.4f, Width = 0.4f,
}, },
// Piecewise-linear gradient with 3 segments to make it appear smoother // Piecewise-linear gradient with 2 segments to make it appear smoother
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.9f)), Colour = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.7f)),
Width = 0.05f, Width = 0.4f,
}, },
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)), Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.7f), new Color4(0, 0, 0, 0.4f)),
Width = 0.2f, Width = 0.4f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
Width = 0.05f,
}, },
} }
} }

View 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();
}
}
}

View 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);
}
}
}
}

View File

@ -3,13 +3,11 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Playlists; using osu.Game.Screens.OnlinePlay.Playlists;
using osuTK; using osuTK;
@ -20,7 +18,6 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
public const float HEIGHT = 50; public const float HEIGHT = 50;
public Action OnStart; public Action OnStart;
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
private readonly Drawable background; private readonly Drawable background;
@ -37,7 +34,6 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(600, 50), Size = new Vector2(600, 50),
SelectedItem = { BindTarget = SelectedItem },
Action = () => OnStart?.Invoke() Action = () => OnStart?.Invoke()
} }
}; };

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
@ -29,6 +30,11 @@ namespace osu.Game.Screens.OnlinePlay.Match
[Resolved(typeof(Room), nameof(Room.Playlist))] [Resolved(typeof(Room), nameof(Room.Playlist))]
protected BindableList<PlaylistItem> Playlist { get; private set; } 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] [Resolved]
private MusicController music { get; set; } private MusicController music { get; set; }
@ -40,6 +46,20 @@ namespace osu.Game.Screens.OnlinePlay.Match
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated; 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] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load(AudioManager audio)
{ {
@ -55,6 +75,8 @@ namespace osu.Game.Screens.OnlinePlay.Match
managerUpdated = beatmapManager.ItemUpdated.GetBoundCopy(); managerUpdated = beatmapManager.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(beatmapUpdated); managerUpdated.BindValueChanged(beatmapUpdated);
UserMods.BindValueChanged(_ => updateMods());
} }
public override void OnEntering(IScreen last) public override void OnEntering(IScreen last)
@ -73,6 +95,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
{ {
base.OnResuming(last); base.OnResuming(last);
beginHandlingTrack(); beginHandlingTrack();
updateMods();
} }
public override bool OnExiting(IScreen next) public override bool OnExiting(IScreen next)
@ -95,12 +118,17 @@ namespace osu.Game.Screens.OnlinePlay.Match
{ {
updateWorkingBeatmap(); 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) updateMods();
Ruleset.Value = item.Ruleset.Value;
Ruleset.Value = SelectedItem.Value.Ruleset.Value;
} }
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet) => Schedule(updateWorkingBeatmap); private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> weakSet) => Schedule(updateWorkingBeatmap);
@ -115,6 +143,14 @@ namespace osu.Game.Screens.OnlinePlay.Match
Beatmap.Value = beatmapManager.GetWorkingBeatmap(localBeatmap); 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() private void beginHandlingTrack()
{ {
Beatmap.BindValueChanged(applyLoopingToTrack, true); Beatmap.BindValueChanged(applyLoopingToTrack, true);

View File

@ -3,13 +3,11 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.Rooms;
using osuTK; using osuTK;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
@ -18,8 +16,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
{ {
public const float HEIGHT = 50; public const float HEIGHT = 50;
public readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
public Action OnReadyClick public Action OnReadyClick
{ {
set => readyButton.OnReadyClick = value; set => readyButton.OnReadyClick = value;
@ -41,7 +37,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(600, 50), Size = new Vector2(600, 50),
SelectedItem = { BindTarget = SelectedItem }
} }
}; };
} }

View File

@ -13,7 +13,6 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Backgrounds;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Components;
using osuTK; using osuTK;
@ -21,8 +20,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
{ {
public class MultiplayerReadyButton : MultiplayerRoomComposite public class MultiplayerReadyButton : MultiplayerRoomComposite
{ {
public Bindable<PlaylistItem> SelectedItem => button.SelectedItem;
public Action OnReadyClick public Action OnReadyClick
{ {
set => button.Action = value; set => button.Action = value;

View File

@ -1,70 +1,32 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select; using osu.Game.Screens.Select;
namespace osu.Game.Screens.OnlinePlay.Multiplayer 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] [Resolved]
private StatefulMultiplayerClient client { get; set; } private StatefulMultiplayerClient client { get; set; }
private LoadingLayer loadingLayer; 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] [BackgroundDependencyLoader]
private void load() private void load()
{ {
AddInternal(loadingLayer = new LoadingLayer(true)); 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. // 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. // Otherwise, update the playlist directly in preparation for it to be submitted to the API on match creation.
if (client.Room != null) if (client.Room != null)
@ -89,30 +51,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
} }
else else
{ {
playlist.Clear(); Playlist.Clear();
playlist.Add(item); Playlist.Add(item);
this.Exit(); 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 BeatmapDetailArea CreateBeatmapDetailArea() => new PlayBeatmapDetailArea();
protected override ModSelectOverlay CreateModSelectOverlay() => new ModSelectOverlay(isValidMod); protected override bool IsValidFreeMod(Mod mod) => base.IsValidFreeMod(mod) && !(mod is ModTimeRamp) && !(mod is ModRateAdjust) && !mod.RequiresConfiguration;
private bool isValidMod(Mod mod) => !(mod is ModAutoplay) && (mod as MultiMod)?.Mods.Any(mm => mm is ModAutoplay) != true;
} }
} }

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -13,12 +14,16 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms; 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.Components;
using osu.Game.Screens.OnlinePlay.Match; using osu.Game.Screens.OnlinePlay.Match;
using osu.Game.Screens.OnlinePlay.Match.Components; using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.OnlinePlay.Multiplayer.Match; using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants; using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
using osu.Game.Screens.Play.HUD;
using osu.Game.Users; using osu.Game.Users;
using osuTK;
using ParticipantsList = osu.Game.Screens.OnlinePlay.Multiplayer.Participants.ParticipantsList; using ParticipantsList = osu.Game.Screens.OnlinePlay.Multiplayer.Participants.ParticipantsList;
namespace osu.Game.Screens.OnlinePlay.Multiplayer namespace osu.Game.Screens.OnlinePlay.Multiplayer
@ -36,7 +41,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
[Resolved] [Resolved]
private OngoingOperationTracker ongoingOperationTracker { get; set; } private OngoingOperationTracker ongoingOperationTracker { get; set; }
private ModSelectOverlay userModsSelectOverlay;
private MultiplayerMatchSettingsOverlay settingsOverlay; private MultiplayerMatchSettingsOverlay settingsOverlay;
private Drawable userModsSection;
private IBindable<bool> isConnected; private IBindable<bool> isConnected;
@ -54,7 +61,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
InternalChildren = new Drawable[] AddRangeInternal(new Drawable[]
{ {
mainContent = new GridContainer mainContent = new GridContainer
{ {
@ -90,18 +97,25 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
}, },
new Drawable[] new Drawable[]
{ {
new GridContainer new Container
{ {
RelativeSizeAxes = Axes.Both, 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, // Main left column
Padding = new MarginPadding { Horizontal = 5, Vertical = 10 }, new GridContainer
Child = new GridContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
RowDimensions = new[] RowDimensions = new[]
@ -119,19 +133,62 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
}, },
} }
} }
} },
}, // Spacer
new FillFlowContainer null,
{ // Main right column
Anchor = Anchor.Centre, new FillFlowContainer
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = 5 },
Children = new Drawable[]
{ {
new OverlinedHeader("Beatmap"), RelativeSizeAxes = Axes.X,
new BeatmapSelectionControl { 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 new MultiplayerMatchFooter
{ {
SelectedItem = { BindTarget = SelectedItem },
OnReadyClick = onReadyClick OnReadyClick = onReadyClick
} }
} }
@ -173,12 +229,24 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
new Dimension(GridSizeMode.AutoSize), 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 settingsOverlay = new MultiplayerMatchSettingsOverlay
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
State = { Value = client.Room == null ? Visibility.Visible : Visibility.Hidden } State = { Value = client.Room == null ? Visibility.Visible : Visibility.Hidden }
} }
}; });
if (client.Room == null) if (client.Room == null)
{ {
@ -199,6 +267,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
base.LoadComplete(); base.LoadComplete();
Playlist.BindCollectionChanged(onPlaylistChanged, true); Playlist.BindCollectionChanged(onPlaylistChanged, true);
UserMods.BindValueChanged(onUserModsChanged);
client.LoadRequested += onLoadRequested; client.LoadRequested += onLoadRequested;
@ -218,10 +287,39 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
return true; return true;
} }
if (userModsSelectOverlay.State.Value == Visibility.Visible)
{
userModsSelectOverlay.Hide();
return true;
}
return base.OnBackButton(); 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() private void onReadyClick()
{ {
@ -274,5 +372,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
if (client != null) if (client != null)
client.LoadRequested -= onLoadRequested; client.LoadRequested -= onLoadRequested;
} }
private class UserModSelectOverlay : ModSelectOverlay
{
public UserModSelectOverlay()
{
CustomiseButton.Alpha = 0;
}
}
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -15,6 +16,8 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets;
using osu.Game.Screens.Play.HUD;
using osu.Game.Users; using osu.Game.Users;
using osu.Game.Users.Drawables; using osu.Game.Users.Drawables;
using osuTK; using osuTK;
@ -29,6 +32,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
[Resolved]
private RulesetStore rulesets { get; set; }
private ModDisplay userModsDisplay;
private StateDisplay userStateDisplay; private StateDisplay userStateDisplay;
private SpriteIcon crown; 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 userStateDisplay = new StateDisplay
{ {
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
@ -142,7 +162,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
const double fade_time = 50; const double fade_time = 50;
var ruleset = rulesets.GetRuleset(Room.Settings.RulesetID).CreateInstance();
userStateDisplay.Status = User.State; userStateDisplay.Status = User.State;
userModsDisplay.Current.Value = User.Mods.Select(m => m.ToMod(ruleset)).ToList();
if (Room.Host?.Equals(User) == true) if (Room.Host?.Equals(User) == true)
crown.FadeIn(fade_time); crown.FadeIn(fade_time);

View File

@ -47,26 +47,21 @@ namespace osu.Game.Screens.OnlinePlay
private void endOperationWithKnownLease(LeasedBindable<bool> lease) private void endOperationWithKnownLease(LeasedBindable<bool> lease)
{ {
if (lease != leasedInProgress)
return;
// for extra safety, marshal the end of operation back to the update thread if necessary. // for extra safety, marshal the end of operation back to the update thread if necessary.
Scheduler.Add(() => Scheduler.Add(() =>
{ {
leasedInProgress?.Return(); if (lease != leasedInProgress)
return;
// UnbindAll() is purposefully used instead of Return() - the two do roughly the same thing, with one difference:
// the former won't throw if the lease has already been returned before.
// this matters because framework can unbind the lease via the internal UnbindAllBindables(), which is not always detectable
// (it is in the case of disposal, but not in the case of screen exit - at least not cleanly).
leasedInProgress?.UnbindAll();
leasedInProgress = null; leasedInProgress = null;
}, false); }, false);
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
// base call does an UnbindAllBindables().
// clean up the leased reference here so that it doesn't get returned twice.
leasedInProgress = null;
}
private class OngoingOperation : IDisposable private class OngoingOperation : IDisposable
{ {
private readonly OngoingOperationTracker tracker; private readonly OngoingOperationTracker tracker;

View 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 SoloModSelectOverlay
{
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);
}
}

View File

@ -183,7 +183,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
Child = new GridContainer Child = new GridContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 300, Height = 500,
Content = new[] Content = new[]
{ {
new Drawable[] new Drawable[]

View File

@ -4,6 +4,7 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Components;
@ -15,6 +16,9 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
[Resolved(typeof(Room), nameof(Room.EndDate))] [Resolved(typeof(Room), nameof(Room.EndDate))]
private Bindable<DateTimeOffset?> endDate { get; set; } private Bindable<DateTimeOffset?> endDate { get; set; }
[Resolved]
private IBindable<WorkingBeatmap> gameBeatmap { get; set; }
public PlaylistsReadyButton() public PlaylistsReadyButton()
{ {
Text = "Start"; Text = "Start";
@ -32,7 +36,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
{ {
base.Update(); 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;
} }
} }
} }

View File

@ -13,7 +13,6 @@ using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Match; using osu.Game.Screens.OnlinePlay.Match;
using osu.Game.Screens.OnlinePlay.Match.Components; using osu.Game.Screens.OnlinePlay.Match.Components;
using osu.Game.Screens.Select;
using osu.Game.Users; using osu.Game.Users;
using Footer = osu.Game.Screens.OnlinePlay.Match.Components.Footer; using Footer = osu.Game.Screens.OnlinePlay.Match.Components.Footer;
@ -44,7 +43,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
InternalChildren = new Drawable[] AddRangeInternal(new Drawable[]
{ {
mainContent = new GridContainer mainContent = new GridContainer
{ {
@ -175,7 +174,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
new Footer new Footer
{ {
OnStart = onStart, OnStart = onStart,
SelectedItem = { BindTarget = SelectedItem }
} }
} }
}, },
@ -188,10 +186,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
settingsOverlay = new PlaylistsMatchSettingsOverlay settingsOverlay = new PlaylistsMatchSettingsOverlay
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
EditPlaylist = () => this.Push(new MatchSongSelect()), EditPlaylist = () => this.Push(new PlaylistsSongSelect()),
State = { Value = roomId.Value == null ? Visibility.Visible : Visibility.Hidden } State = { Value = roomId.Value == null ? Visibility.Visible : Visibility.Hidden }
} }
}; });
if (roomId.Value == null) if (roomId.Value == null)
{ {

View File

@ -1,48 +1,27 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq; using System.Linq;
using Humanizer;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.Rooms; 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.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] [Resolved]
private BeatmapManager beatmaps { get; set; } private BeatmapManager beatmaps { get; set; }
public MatchSongSelect()
{
Padding = new MarginPadding { Horizontal = HORIZONTAL_OVERFLOW_PADDING };
}
protected override BeatmapDetailArea CreateBeatmapDetailArea() => new MatchBeatmapDetailArea protected override BeatmapDetailArea CreateBeatmapDetailArea() => new MatchBeatmapDetailArea
{ {
CreateNewItem = createNewItem CreateNewItem = createNewItem
}; };
protected override bool OnStart() protected override void SelectItem(PlaylistItem item)
{ {
switch (Playlist.Count) switch (Playlist.Count)
{ {
@ -56,8 +35,6 @@ namespace osu.Game.Screens.Select
} }
this.Exit(); this.Exit();
return true;
} }
private void createNewItem() private void createNewItem()
@ -80,9 +57,5 @@ namespace osu.Game.Screens.Select
item.RequiredMods.Clear(); item.RequiredMods.Clear();
item.RequiredMods.AddRange(Mods.Value.Select(m => m.CreateCopy())); item.RequiredMods.AddRange(Mods.Value.Select(m => m.CreateCopy()));
} }
protected override ModSelectOverlay CreateModSelectOverlay() => new ModSelectOverlay(isValidMod);
private bool isValidMod(Mod mod) => !(mod is ModAutoplay) && (mod as MultiMod)?.Mods.Any(mm => mm is ModAutoplay) != true;
} }
} }

View File

@ -28,19 +28,16 @@ namespace osu.Game.Screens.Select
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>(); 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> /// <param name="overlay">The <see cref="OverlayContainer"/> to be toggled by this button.</param>
public void AddButton(FooterButton button, OverlayContainer overlay) public void AddButton(FooterButton button, OverlayContainer overlay)
{ {
overlays.Add(overlay); if (overlay != null)
button.Action = () => showOverlay(overlay); {
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.Hovered = updateModeLight;
button.HoverLost = updateModeLight; button.HoverLost = updateModeLight;

View File

@ -263,9 +263,8 @@ namespace osu.Game.Screens.Select
if (Footer != null) if (Footer != null)
{ {
Footer.AddButton(new FooterButtonMods { Current = Mods }, ModSelect); foreach (var (button, overlay) in CreateFooterButtons())
Footer.AddButton(new FooterButtonRandom { Action = triggerRandom }); Footer.AddButton(button, overlay);
Footer.AddButton(new FooterButtonOptions(), BeatmapOptions);
BeatmapOptions.AddButton(@"Manage", @"collections", FontAwesome.Solid.Book, colours.Green, () => manageCollectionsDialog?.Show()); 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)); 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 ModSelectOverlay(); /// <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 SoloModSelectOverlay();
protected virtual void ApplyFilterToCarousel(FilterCriteria criteria) protected virtual void ApplyFilterToCarousel(FilterCriteria criteria)
{ {

View File

@ -3,6 +3,7 @@
#nullable enable #nullable enable
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -11,6 +12,7 @@ using osu.Framework.Bindables;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Rulesets.Mods;
using osu.Game.Users; using osu.Game.Users;
namespace osu.Game.Tests.Visual.Multiplayer namespace osu.Game.Tests.Visual.Multiplayer
@ -122,6 +124,21 @@ namespace osu.Game.Tests.Visual.Multiplayer
return Task.CompletedTask; 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() public override Task StartMatch()
{ {
Debug.Assert(Room != null); Debug.Assert(Room != null);

133
osu.Game/Utils/ModUtils.cs Normal file
View File

@ -0,0 +1,133 @@
// 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.Diagnostics.CodeAnalysis;
using System.Linq;
using osu.Game.Rulesets.Mods;
#nullable enable
namespace osu.Game.Utils
{
/// <summary>
/// A set of utilities to handle <see cref="Mod"/> combinations.
/// </summary>
public static class ModUtils
{
/// <summary>
/// Checks that all <see cref="Mod"/>s are compatible with each-other, and that all appear within a set of allowed types.
/// </summary>
/// <remarks>
/// The allowed types must contain exact <see cref="Mod"/> types for the respective <see cref="Mod"/>s to be allowed.
/// </remarks>
/// <param name="combination">The <see cref="Mod"/>s to check.</param>
/// <param name="allowedTypes">The set of allowed <see cref="Mod"/> types.</param>
/// <returns>Whether all <see cref="Mod"/>s are compatible with each-other and appear in the set of allowed types.</returns>
public static bool CheckCompatibleSetAndAllowed(IEnumerable<Mod> combination, IEnumerable<Type> allowedTypes)
{
// Prevent multiple-enumeration.
var combinationList = combination as ICollection<Mod> ?? combination.ToArray();
return CheckCompatibleSet(combinationList, out _) && CheckAllowed(combinationList, allowedTypes);
}
/// <summary>
/// Checks that all <see cref="Mod"/>s in a combination are compatible with each-other.
/// </summary>
/// <param name="combination">The <see cref="Mod"/> combination to check.</param>
/// <returns>Whether all <see cref="Mod"/>s in the combination are compatible with each-other.</returns>
public static bool CheckCompatibleSet(IEnumerable<Mod> combination)
=> CheckCompatibleSet(combination, out _);
/// <summary>
/// Checks that all <see cref="Mod"/>s in a combination are compatible with each-other.
/// </summary>
/// <param name="combination">The <see cref="Mod"/> combination to check.</param>
/// <param name="invalidMods">Any invalid mods in the set.</param>
/// <returns>Whether all <see cref="Mod"/>s in the combination are compatible with each-other.</returns>
public static bool CheckCompatibleSet(IEnumerable<Mod> combination, [NotNullWhen(false)] out List<Mod>? invalidMods)
{
combination = FlattenMods(combination).ToArray();
invalidMods = null;
foreach (var mod in combination)
{
foreach (var type in mod.IncompatibleMods)
{
foreach (var invalid in combination.Where(m => type.IsInstanceOfType(m)))
{
invalidMods ??= new List<Mod>();
invalidMods.Add(invalid);
}
}
}
return invalidMods == null;
}
/// <summary>
/// Checks that all <see cref="Mod"/>s in a combination appear within a set of allowed types.
/// </summary>
/// <remarks>
/// The set of allowed types must contain exact <see cref="Mod"/> types for the respective <see cref="Mod"/>s to be allowed.
/// </remarks>
/// <param name="combination">The <see cref="Mod"/> combination to check.</param>
/// <param name="allowedTypes">The set of allowed <see cref="Mod"/> types.</param>
/// <returns>Whether all <see cref="Mod"/>s in the combination are allowed.</returns>
public static bool CheckAllowed(IEnumerable<Mod> combination, IEnumerable<Type> allowedTypes)
{
var allowedSet = new HashSet<Type>(allowedTypes);
return combination.SelectMany(FlattenMod)
.All(m => allowedSet.Contains(m.GetType()));
}
/// <summary>
/// Check the provided combination of mods are valid for a local gameplay session.
/// </summary>
/// <param name="mods">The mods to check.</param>
/// <param name="invalidMods">Invalid mods, if any were found. Can be null if all mods were valid.</param>
/// <returns>Whether the input mods were all valid. If false, <paramref name="invalidMods"/> will contain all invalid entries.</returns>
public static bool CheckValidForGameplay(IEnumerable<Mod> mods, out List<Mod>? invalidMods)
{
mods = mods.ToArray();
CheckCompatibleSet(mods, out invalidMods);
foreach (var mod in mods)
{
if (mod.Type == ModType.System || !mod.HasImplementation || mod is MultiMod)
{
invalidMods ??= new List<Mod>();
invalidMods.Add(mod);
}
}
return invalidMods == null;
}
/// <summary>
/// Flattens a set of <see cref="Mod"/>s, returning a new set with all <see cref="MultiMod"/>s removed.
/// </summary>
/// <param name="mods">The set of <see cref="Mod"/>s to flatten.</param>
/// <returns>The new set, containing all <see cref="Mod"/>s in <paramref name="mods"/> recursively with all <see cref="MultiMod"/>s removed.</returns>
public static IEnumerable<Mod> FlattenMods(IEnumerable<Mod> mods) => mods.SelectMany(FlattenMod);
/// <summary>
/// Flattens a <see cref="Mod"/>, returning a set of <see cref="Mod"/>s in-place of any <see cref="MultiMod"/>s.
/// </summary>
/// <param name="mod">The <see cref="Mod"/> to flatten.</param>
/// <returns>A set of singular "flattened" <see cref="Mod"/>s</returns>
public static IEnumerable<Mod> FlattenMod(Mod mod)
{
if (mod is MultiMod multi)
{
foreach (var m in multi.Mods.SelectMany(FlattenMod))
yield return m;
}
else
yield return mod;
}
}
}

View File

@ -20,11 +20,13 @@
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="DiffPlex" Version="1.6.3" /> <PackageReference Include="DiffPlex" Version="1.6.3" />
<PackageReference Include="Humanizer" Version="2.8.26" /> <PackageReference Include="Humanizer" Version="2.8.26" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.10" /> <PackageReference Include="MessagePack" Version="2.2.85" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.11" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.2" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="3.1.10" /> <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" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" 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="Microsoft.NETCore.Targets" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2021.128.0" /> <PackageReference Include="ppy.osu.Framework" Version="2021.128.0" />

View File

@ -80,6 +80,9 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.0.3" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" 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> </ItemGroup>
<!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. --> <!-- Xamarin.iOS does not automatically handle transitive dependencies from NuGet packages. -->
<ItemGroup Label="Transitive Dependencies"> <ItemGroup Label="Transitive Dependencies">