mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Merge branch 'master' into zero-spinner-slider
This commit is contained in:
@ -5,7 +5,7 @@
|
|||||||
# osu!
|
# osu!
|
||||||
|
|
||||||
[](https://ci.appveyor.com/project/peppy/osu)
|
[](https://ci.appveyor.com/project/peppy/osu)
|
||||||
[]()
|
[](https://github.com/ppy/osu/releases/latest)
|
||||||
[](https://www.codefactor.io/repository/github/ppy/osu)
|
[](https://www.codefactor.io/repository/github/ppy/osu)
|
||||||
[](https://discord.gg/ppy)
|
[](https://discord.gg/ppy)
|
||||||
|
|
||||||
|
@ -52,6 +52,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.1202.0" />
|
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.1202.0" />
|
||||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.118.0" />
|
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.128.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -24,16 +24,13 @@
|
|||||||
<ProjectReference Include="..\osu.Game.Rulesets.Taiko\osu.Game.Rulesets.Taiko.csproj" />
|
<ProjectReference Include="..\osu.Game.Rulesets.Taiko\osu.Game.Rulesets.Taiko.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Label="Package References">
|
<ItemGroup Label="Package References">
|
||||||
|
<PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0" />
|
||||||
<PackageReference Include="System.IO.Packaging" Version="5.0.0" />
|
<PackageReference Include="System.IO.Packaging" Version="5.0.0" />
|
||||||
<PackageReference Include="ppy.squirrel.windows" Version="1.9.0.4" />
|
<PackageReference Include="ppy.squirrel.windows" Version="1.9.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.6" />
|
||||||
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
|
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
|
||||||
<PackageReference Include="DiscordRichPresence" Version="1.0.169" />
|
<PackageReference Include="DiscordRichPresence" Version="1.0.175" />
|
||||||
<!-- .NET 3.1 SDK seems to cause issues with a runtime specification. This will likely be resolved in .NET 5. -->
|
|
||||||
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
|
|
||||||
<PackageReference Include="System.Runtime.Handles" Version="4.3.0" />
|
|
||||||
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Label="Resources">
|
<ItemGroup Label="Resources">
|
||||||
<EmbeddedResource Include="lazer.ico" />
|
<EmbeddedResource Include="lazer.ico" />
|
||||||
|
@ -45,6 +45,11 @@ namespace osu.Game.Rulesets.Catch.Replays
|
|||||||
float positionChange = Math.Abs(lastPosition - h.EffectiveX);
|
float positionChange = Math.Abs(lastPosition - h.EffectiveX);
|
||||||
double timeAvailable = h.StartTime - lastTime;
|
double timeAvailable = h.StartTime - lastTime;
|
||||||
|
|
||||||
|
if (timeAvailable < 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// So we can either make it there without a dash or not.
|
// So we can either make it there without a dash or not.
|
||||||
// If positionChange is 0, we don't need to move, so speedRequired should also be 0 (could be NaN if timeAvailable is 0 too)
|
// If positionChange is 0, we don't need to move, so speedRequired should also be 0 (could be NaN if timeAvailable is 0 too)
|
||||||
// The case where positionChange > 0 and timeAvailable == 0 results in PositiveInfinity which provides expected beheaviour.
|
// The case where positionChange > 0 and timeAvailable == 0 results in PositiveInfinity which provides expected beheaviour.
|
||||||
|
@ -29,4 +29,3 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,4 +19,3 @@ namespace osu.Game.Rulesets.Catch.Skinning.Default
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Rulesets.Mania.Mods;
|
||||||
|
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
||||||
|
using osu.Game.Rulesets.UI.Scrolling;
|
||||||
|
using osu.Game.Rulesets.UI.Scrolling.Algorithms;
|
||||||
|
using osu.Game.Tests.Visual;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Mania.Tests.Mods
|
||||||
|
{
|
||||||
|
public class TestSceneManiaModConstantSpeed : ModTestScene
|
||||||
|
{
|
||||||
|
protected override Ruleset CreatePlayerRuleset() => new ManiaRuleset();
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestConstantScroll() => CreateModTest(new ModTestData
|
||||||
|
{
|
||||||
|
Mod = new ManiaModConstantSpeed(),
|
||||||
|
PassCondition = () =>
|
||||||
|
{
|
||||||
|
var hitObject = Player.ChildrenOfType<DrawableManiaHitObject>().FirstOrDefault();
|
||||||
|
return hitObject?.Dependencies.Get<IScrollingInfo>().Algorithm is ConstantScrollAlgorithm;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -238,6 +238,7 @@ namespace osu.Game.Rulesets.Mania
|
|||||||
new ManiaModMirror(),
|
new ManiaModMirror(),
|
||||||
new ManiaModDifficultyAdjust(),
|
new ManiaModDifficultyAdjust(),
|
||||||
new ManiaModInvert(),
|
new ManiaModInvert(),
|
||||||
|
new ManiaModConstantSpeed()
|
||||||
};
|
};
|
||||||
|
|
||||||
case ModType.Automation:
|
case ModType.Automation:
|
||||||
|
35
osu.Game.Rulesets.Mania/Mods/ManiaModConstantSpeed.cs
Normal file
35
osu.Game.Rulesets.Mania/Mods/ManiaModConstantSpeed.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Rulesets.Mania.Objects;
|
||||||
|
using osu.Game.Rulesets.Mania.UI;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Mania.Mods
|
||||||
|
{
|
||||||
|
public class ManiaModConstantSpeed : Mod, IApplicableToDrawableRuleset<ManiaHitObject>
|
||||||
|
{
|
||||||
|
public override string Name => "Constant Speed";
|
||||||
|
|
||||||
|
public override string Acronym => "CS";
|
||||||
|
|
||||||
|
public override double ScoreMultiplier => 1;
|
||||||
|
|
||||||
|
public override string Description => "No more tricky speed changes!";
|
||||||
|
|
||||||
|
public override IconUsage? Icon => FontAwesome.Solid.Equals;
|
||||||
|
|
||||||
|
public override ModType Type => ModType.Conversion;
|
||||||
|
|
||||||
|
public override bool Ranked => false;
|
||||||
|
|
||||||
|
public void ApplyToDrawableRuleset(DrawableRuleset<ManiaHitObject> drawableRuleset)
|
||||||
|
{
|
||||||
|
var maniaRuleset = (DrawableManiaRuleset)drawableRuleset;
|
||||||
|
maniaRuleset.ScrollMethod = ScrollVisualisationMethod.Constant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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();
|
||||||
|
|
||||||
|
@ -243,7 +243,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
if (HandleUserInput)
|
if (HandleUserInput)
|
||||||
RotationTracker.Tracking = !Result.HasResult && (OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false);
|
{
|
||||||
|
bool isValidSpinningTime = Time.Current >= HitObject.StartTime && Time.Current <= HitObject.EndTime;
|
||||||
|
bool correctButtonPressed = (OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false);
|
||||||
|
|
||||||
|
RotationTracker.Tracking = !Result.HasResult
|
||||||
|
&& correctButtonPressed
|
||||||
|
&& isValidSpinningTime;
|
||||||
|
}
|
||||||
|
|
||||||
if (spinningSample != null && spinnerFrequencyModulate)
|
if (spinningSample != null && spinnerFrequencyModulate)
|
||||||
spinningSample.Frequency.Value = spinning_sample_modulated_base_frequency + Progress;
|
spinningSample.Frequency.Value = spinning_sample_modulated_base_frequency + Progress;
|
||||||
@ -255,6 +262,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
|
|
||||||
if (!SpmCounter.IsPresent && RotationTracker.Tracking)
|
if (!SpmCounter.IsPresent && RotationTracker.Tracking)
|
||||||
SpmCounter.FadeIn(HitObject.TimeFadeIn);
|
SpmCounter.FadeIn(HitObject.TimeFadeIn);
|
||||||
|
|
||||||
SpmCounter.SetRotation(Result.RateAdjustedRotation);
|
SpmCounter.SetRotation(Result.RateAdjustedRotation);
|
||||||
|
|
||||||
updateBonusScore();
|
updateBonusScore();
|
||||||
|
@ -4,16 +4,21 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu.Skinning.Default
|
namespace osu.Game.Rulesets.Osu.Skinning.Default
|
||||||
{
|
{
|
||||||
public class SpinnerSpmCounter : Container
|
public class SpinnerSpmCounter : Container
|
||||||
{
|
{
|
||||||
|
[Resolved]
|
||||||
|
private DrawableHitObject drawableSpinner { get; set; }
|
||||||
|
|
||||||
private readonly OsuSpriteText spmText;
|
private readonly OsuSpriteText spmText;
|
||||||
|
|
||||||
public SpinnerSpmCounter()
|
public SpinnerSpmCounter()
|
||||||
@ -38,6 +43,12 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
drawableSpinner.HitObjectApplied += resetState;
|
||||||
|
}
|
||||||
|
|
||||||
private double spm;
|
private double spm;
|
||||||
|
|
||||||
public double SpinsPerMinute
|
public double SpinsPerMinute
|
||||||
@ -82,5 +93,19 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
|
|||||||
|
|
||||||
records.Enqueue(new RotationRecord { Rotation = currentRotation, Time = Time.Current });
|
records.Enqueue(new RotationRecord { Rotation = currentRotation, Time = Time.Current });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetState(DrawableHitObject hitObject)
|
||||||
|
{
|
||||||
|
SpinsPerMinute = 0;
|
||||||
|
records.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
|
if (drawableSpinner != null)
|
||||||
|
drawableSpinner.HitObjectApplied -= resetState;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,45 @@
|
|||||||
// 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.Bindables;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.Mods
|
namespace osu.Game.Rulesets.Taiko.Mods
|
||||||
{
|
{
|
||||||
public class TaikoModDifficultyAdjust : ModDifficultyAdjust
|
public class TaikoModDifficultyAdjust : ModDifficultyAdjust
|
||||||
{
|
{
|
||||||
|
[SettingSource("Scroll Speed", "Adjust a beatmap's set scroll speed", LAST_SETTING_ORDER + 1)]
|
||||||
|
public BindableNumber<float> ScrollSpeed { get; } = new BindableFloat
|
||||||
|
{
|
||||||
|
Precision = 0.05f,
|
||||||
|
MinValue = 0.25f,
|
||||||
|
MaxValue = 4,
|
||||||
|
Default = 1,
|
||||||
|
Value = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
public override string SettingDescription
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string scrollSpeed = ScrollSpeed.IsDefault ? string.Empty : $"Scroll x{ScrollSpeed.Value:N1}";
|
||||||
|
|
||||||
|
return string.Join(", ", new[]
|
||||||
|
{
|
||||||
|
base.SettingDescription,
|
||||||
|
scrollSpeed
|
||||||
|
}.Where(s => !string.IsNullOrEmpty(s)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ApplySettings(BeatmapDifficulty difficulty)
|
||||||
|
{
|
||||||
|
base.ApplySettings(difficulty);
|
||||||
|
|
||||||
|
ApplySetting(ScrollSpeed, scroll => difficulty.SliderMultiplier *= scroll);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.Mods
|
namespace osu.Game.Rulesets.Taiko.Mods
|
||||||
@ -8,5 +9,16 @@ namespace osu.Game.Rulesets.Taiko.Mods
|
|||||||
public class TaikoModEasy : ModEasy
|
public class TaikoModEasy : ModEasy
|
||||||
{
|
{
|
||||||
public override string Description => @"Beats move slower, and less accuracy required!";
|
public override string Description => @"Beats move slower, and less accuracy required!";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Multiplier factor added to the scrolling speed.
|
||||||
|
/// </summary>
|
||||||
|
private const double slider_multiplier = 0.8;
|
||||||
|
|
||||||
|
public override void ApplyToDifficulty(BeatmapDifficulty difficulty)
|
||||||
|
{
|
||||||
|
base.ApplyToDifficulty(difficulty);
|
||||||
|
difficulty.SliderMultiplier *= slider_multiplier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.Mods
|
namespace osu.Game.Rulesets.Taiko.Mods
|
||||||
@ -9,5 +10,21 @@ namespace osu.Game.Rulesets.Taiko.Mods
|
|||||||
{
|
{
|
||||||
public override double ScoreMultiplier => 1.06;
|
public override double ScoreMultiplier => 1.06;
|
||||||
public override bool Ranked => true;
|
public override bool Ranked => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Multiplier factor added to the scrolling speed.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This factor is made up of two parts: the base part (1.4) and the aspect ratio adjustment (4/3).
|
||||||
|
/// Stable applies the latter by dividing the width of the user's display by the width of a display with the same height, but 4:3 aspect ratio.
|
||||||
|
/// TODO: Revisit if taiko playfield ever changes away from a hard-coded 16:9 (see https://github.com/ppy/osu/issues/5685).
|
||||||
|
/// </remarks>
|
||||||
|
private const double slider_multiplier = 1.4 * 4 / 3;
|
||||||
|
|
||||||
|
public override void ApplyToDifficulty(BeatmapDifficulty difficulty)
|
||||||
|
{
|
||||||
|
base.ApplyToDifficulty(difficulty);
|
||||||
|
difficulty.SliderMultiplier *= slider_multiplier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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>
|
@ -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>
|
@ -129,5 +129,25 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
Assert.AreEqual(3456, ((StoryboardSprite)background.Elements.Single()).InitialPosition.X);
|
Assert.AreEqual(3456, ((StoryboardSprite)background.Elements.Single()).InitialPosition.X);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDecodeOutOfRangeLoopAnimationType()
|
||||||
|
{
|
||||||
|
var decoder = new LegacyStoryboardDecoder();
|
||||||
|
|
||||||
|
using (var resStream = TestResources.OpenResource("animation-types.osb"))
|
||||||
|
using (var stream = new LineBufferedReader(resStream))
|
||||||
|
{
|
||||||
|
var storyboard = decoder.Decode(stream);
|
||||||
|
|
||||||
|
StoryboardLayer foreground = storyboard.Layers.Single(l => l.Depth == 0);
|
||||||
|
Assert.AreEqual(AnimationLoopType.LoopForever, ((StoryboardAnimation)foreground.Elements[0]).LoopType);
|
||||||
|
Assert.AreEqual(AnimationLoopType.LoopOnce, ((StoryboardAnimation)foreground.Elements[1]).LoopType);
|
||||||
|
Assert.AreEqual(AnimationLoopType.LoopForever, ((StoryboardAnimation)foreground.Elements[2]).LoopType);
|
||||||
|
Assert.AreEqual(AnimationLoopType.LoopOnce, ((StoryboardAnimation)foreground.Elements[3]).LoopType);
|
||||||
|
Assert.AreEqual(AnimationLoopType.LoopForever, ((StoryboardAnimation)foreground.Elements[4]).LoopType);
|
||||||
|
Assert.AreEqual(AnimationLoopType.LoopForever, ((StoryboardAnimation)foreground.Elements[5]).LoopType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
160
osu.Game.Tests/Mods/ModUtilsTest.cs
Normal file
160
osu.Game.Tests/Mods/ModUtilsTest.cs
Normal 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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
106
osu.Game.Tests/NonVisual/OngoingOperationTrackerTest.cs
Normal file
106
osu.Game.Tests/NonVisual/OngoingOperationTrackerTest.cs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
// 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 NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Screens;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Screens;
|
||||||
|
using osu.Game.Screens.OnlinePlay;
|
||||||
|
using osu.Game.Tests.Visual;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.NonVisual
|
||||||
|
{
|
||||||
|
[HeadlessTest]
|
||||||
|
public class OngoingOperationTrackerTest : OsuTestScene
|
||||||
|
{
|
||||||
|
private OngoingOperationTracker tracker;
|
||||||
|
private IBindable<bool> operationInProgress;
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
AddStep("create tracker", () => Child = tracker = new OngoingOperationTracker());
|
||||||
|
AddStep("bind to operation status", () => operationInProgress = tracker.InProgress.GetBoundCopy());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestOperationTracking()
|
||||||
|
{
|
||||||
|
IDisposable firstOperation = null;
|
||||||
|
IDisposable secondOperation = null;
|
||||||
|
|
||||||
|
AddStep("begin first operation", () => firstOperation = tracker.BeginOperation());
|
||||||
|
AddAssert("first operation in progress", () => operationInProgress.Value);
|
||||||
|
|
||||||
|
AddStep("cannot start another operation",
|
||||||
|
() => Assert.Throws<InvalidOperationException>(() => tracker.BeginOperation()));
|
||||||
|
|
||||||
|
AddStep("end first operation", () => firstOperation.Dispose());
|
||||||
|
AddAssert("first operation is ended", () => !operationInProgress.Value);
|
||||||
|
|
||||||
|
AddStep("start second operation", () => secondOperation = tracker.BeginOperation());
|
||||||
|
AddAssert("second operation in progress", () => operationInProgress.Value);
|
||||||
|
|
||||||
|
AddStep("dispose first operation again", () => firstOperation.Dispose());
|
||||||
|
AddAssert("second operation still in progress", () => operationInProgress.Value);
|
||||||
|
|
||||||
|
AddStep("dispose second operation", () => secondOperation.Dispose());
|
||||||
|
AddAssert("second operation is ended", () => !operationInProgress.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestOperationDisposalAfterTracker()
|
||||||
|
{
|
||||||
|
IDisposable operation = null;
|
||||||
|
|
||||||
|
AddStep("begin operation", () => operation = tracker.BeginOperation());
|
||||||
|
AddStep("dispose tracker", () => tracker.Expire());
|
||||||
|
AddStep("end operation", () => operation.Dispose());
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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()
|
139
osu.Game.Tests/Online/TestAPIModMessagePackSerialization.cs
Normal file
139
osu.Game.Tests/Online/TestAPIModMessagePackSerialization.cs
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using MessagePack;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Difficulty;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Online
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class TestAPIModMessagePackSerialization
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestAcronymIsPreserved()
|
||||||
|
{
|
||||||
|
var apiMod = new APIMod(new TestMod());
|
||||||
|
|
||||||
|
var deserialized = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
||||||
|
|
||||||
|
Assert.That(deserialized.Acronym, Is.EqualTo(apiMod.Acronym));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestRawSettingIsPreserved()
|
||||||
|
{
|
||||||
|
var apiMod = new APIMod(new TestMod { TestSetting = { Value = 2 } });
|
||||||
|
|
||||||
|
var deserialized = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
||||||
|
|
||||||
|
Assert.That(deserialized.Settings, Contains.Key("test_setting").With.ContainValue(2.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestConvertedModHasCorrectSetting()
|
||||||
|
{
|
||||||
|
var apiMod = new APIMod(new TestMod { TestSetting = { Value = 2 } });
|
||||||
|
|
||||||
|
var deserialized = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
||||||
|
var converted = (TestMod)deserialized.ToMod(new TestRuleset());
|
||||||
|
|
||||||
|
Assert.That(converted.TestSetting.Value, Is.EqualTo(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDeserialiseTimeRampMod()
|
||||||
|
{
|
||||||
|
// Create the mod with values different from default.
|
||||||
|
var apiMod = new APIMod(new TestModTimeRamp
|
||||||
|
{
|
||||||
|
AdjustPitch = { Value = false },
|
||||||
|
InitialRate = { Value = 1.25 },
|
||||||
|
FinalRate = { Value = 0.25 }
|
||||||
|
});
|
||||||
|
|
||||||
|
var deserialised = MessagePackSerializer.Deserialize<APIMod>(MessagePackSerializer.Serialize(apiMod));
|
||||||
|
var converted = (TestModTimeRamp)deserialised.ToMod(new TestRuleset());
|
||||||
|
|
||||||
|
Assert.That(converted.AdjustPitch.Value, Is.EqualTo(false));
|
||||||
|
Assert.That(converted.InitialRate.Value, Is.EqualTo(1.25));
|
||||||
|
Assert.That(converted.FinalRate.Value, Is.EqualTo(0.25));
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestRuleset : Ruleset
|
||||||
|
{
|
||||||
|
public override IEnumerable<Mod> GetModsFor(ModType type) => new Mod[]
|
||||||
|
{
|
||||||
|
new TestMod(),
|
||||||
|
new TestModTimeRamp(),
|
||||||
|
};
|
||||||
|
|
||||||
|
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => throw new System.NotImplementedException();
|
||||||
|
|
||||||
|
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new System.NotImplementedException();
|
||||||
|
|
||||||
|
public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new System.NotImplementedException();
|
||||||
|
|
||||||
|
public override string Description { get; } = string.Empty;
|
||||||
|
public override string ShortName { get; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestMod : Mod
|
||||||
|
{
|
||||||
|
public override string Name => "Test Mod";
|
||||||
|
public override string Acronym => "TM";
|
||||||
|
public override double ScoreMultiplier => 1;
|
||||||
|
|
||||||
|
[SettingSource("Test")]
|
||||||
|
public BindableNumber<double> TestSetting { get; } = new BindableDouble
|
||||||
|
{
|
||||||
|
MinValue = 0,
|
||||||
|
MaxValue = 10,
|
||||||
|
Default = 5,
|
||||||
|
Precision = 0.01,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestModTimeRamp : ModTimeRamp
|
||||||
|
{
|
||||||
|
public override string Name => "Test Mod";
|
||||||
|
public override string Acronym => "TMTR";
|
||||||
|
public override double ScoreMultiplier => 1;
|
||||||
|
|
||||||
|
[SettingSource("Initial rate", "The starting speed of the track")]
|
||||||
|
public override BindableNumber<double> InitialRate { get; } = new BindableDouble
|
||||||
|
{
|
||||||
|
MinValue = 1,
|
||||||
|
MaxValue = 2,
|
||||||
|
Default = 1.5,
|
||||||
|
Value = 1.5,
|
||||||
|
Precision = 0.01,
|
||||||
|
};
|
||||||
|
|
||||||
|
[SettingSource("Final rate", "The speed increase to ramp towards")]
|
||||||
|
public override BindableNumber<double> FinalRate { get; } = new BindableDouble
|
||||||
|
{
|
||||||
|
MinValue = 0,
|
||||||
|
MaxValue = 1,
|
||||||
|
Default = 0.5,
|
||||||
|
Value = 0.5,
|
||||||
|
Precision = 0.01,
|
||||||
|
};
|
||||||
|
|
||||||
|
[SettingSource("Adjust pitch", "Should pitch be adjusted with speed")]
|
||||||
|
public override BindableBool AdjustPitch { get; } = new BindableBool
|
||||||
|
{
|
||||||
|
Default = true,
|
||||||
|
Value = true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,188 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Beatmaps.Formats;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.IO;
|
||||||
|
using osu.Game.IO.Archives;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Tests.Resources;
|
||||||
|
using osu.Game.Tests.Visual;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Online
|
||||||
|
{
|
||||||
|
[HeadlessTest]
|
||||||
|
public class TestSceneOnlinePlayBeatmapAvailabilityTracker : OsuTestScene
|
||||||
|
{
|
||||||
|
private RulesetStore rulesets;
|
||||||
|
private TestBeatmapManager beatmaps;
|
||||||
|
|
||||||
|
private string testBeatmapFile;
|
||||||
|
private BeatmapInfo testBeatmapInfo;
|
||||||
|
private BeatmapSetInfo testBeatmapSet;
|
||||||
|
|
||||||
|
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
||||||
|
private OnlinePlayBeatmapAvailablilityTracker availablilityTracker;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(AudioManager audio, GameHost host)
|
||||||
|
{
|
||||||
|
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
||||||
|
Dependencies.CacheAs<BeatmapManager>(beatmaps = new TestBeatmapManager(LocalStorage, ContextFactory, rulesets, API, audio, host, Beatmap.Default));
|
||||||
|
}
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp() => Schedule(() =>
|
||||||
|
{
|
||||||
|
beatmaps.AllowImport = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
|
testBeatmapFile = TestResources.GetTestBeatmapForImport();
|
||||||
|
|
||||||
|
testBeatmapInfo = getTestBeatmapInfo(testBeatmapFile);
|
||||||
|
testBeatmapSet = testBeatmapInfo.BeatmapSet;
|
||||||
|
|
||||||
|
var existing = beatmaps.QueryBeatmapSet(s => s.OnlineBeatmapSetID == testBeatmapSet.OnlineBeatmapSetID);
|
||||||
|
if (existing != null)
|
||||||
|
beatmaps.Delete(existing);
|
||||||
|
|
||||||
|
selectedItem.Value = new PlaylistItem
|
||||||
|
{
|
||||||
|
Beatmap = { Value = testBeatmapInfo },
|
||||||
|
Ruleset = { Value = testBeatmapInfo.Ruleset },
|
||||||
|
};
|
||||||
|
|
||||||
|
Child = availablilityTracker = new OnlinePlayBeatmapAvailablilityTracker
|
||||||
|
{
|
||||||
|
SelectedItem = { BindTarget = selectedItem, }
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBeatmapDownloadingFlow()
|
||||||
|
{
|
||||||
|
AddAssert("ensure beatmap unavailable", () => !beatmaps.IsAvailableLocally(testBeatmapSet));
|
||||||
|
addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded);
|
||||||
|
|
||||||
|
AddStep("start downloading", () => beatmaps.Download(testBeatmapSet));
|
||||||
|
addAvailabilityCheckStep("state downloading 0%", () => BeatmapAvailability.Downloading(0.0f));
|
||||||
|
|
||||||
|
AddStep("set progress 40%", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).SetProgress(0.4f));
|
||||||
|
addAvailabilityCheckStep("state downloading 40%", () => BeatmapAvailability.Downloading(0.4f));
|
||||||
|
|
||||||
|
AddStep("finish download", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).TriggerSuccess(testBeatmapFile));
|
||||||
|
addAvailabilityCheckStep("state importing", BeatmapAvailability.Importing);
|
||||||
|
|
||||||
|
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
|
||||||
|
AddUntilStep("wait for import", () => beatmaps.CurrentImportTask?.IsCompleted == true);
|
||||||
|
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestTrackerRespectsSoftDeleting()
|
||||||
|
{
|
||||||
|
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
|
||||||
|
AddStep("import beatmap", () => beatmaps.Import(testBeatmapFile).Wait());
|
||||||
|
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
|
||||||
|
|
||||||
|
AddStep("delete beatmap", () => beatmaps.Delete(beatmaps.QueryBeatmapSet(b => b.OnlineBeatmapSetID == testBeatmapSet.OnlineBeatmapSetID)));
|
||||||
|
addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded);
|
||||||
|
|
||||||
|
AddStep("undelete beatmap", () => beatmaps.Undelete(beatmaps.QueryBeatmapSet(b => b.OnlineBeatmapSetID == testBeatmapSet.OnlineBeatmapSetID)));
|
||||||
|
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestTrackerRespectsChecksum()
|
||||||
|
{
|
||||||
|
AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
|
||||||
|
|
||||||
|
AddStep("import altered beatmap", () =>
|
||||||
|
{
|
||||||
|
beatmaps.Import(TestResources.GetTestBeatmapForImport(true)).Wait();
|
||||||
|
});
|
||||||
|
addAvailabilityCheckStep("state still not downloaded", BeatmapAvailability.NotDownloaded);
|
||||||
|
|
||||||
|
AddStep("recreate tracker", () => Child = availablilityTracker = new OnlinePlayBeatmapAvailablilityTracker
|
||||||
|
{
|
||||||
|
SelectedItem = { BindTarget = selectedItem }
|
||||||
|
});
|
||||||
|
addAvailabilityCheckStep("state not downloaded as well", BeatmapAvailability.NotDownloaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addAvailabilityCheckStep(string description, Func<BeatmapAvailability> expected)
|
||||||
|
{
|
||||||
|
AddAssert(description, () => availablilityTracker.Availability.Value.Equals(expected.Invoke()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BeatmapInfo getTestBeatmapInfo(string archiveFile)
|
||||||
|
{
|
||||||
|
BeatmapInfo info;
|
||||||
|
|
||||||
|
using (var archive = new ZipArchiveReader(File.OpenRead(archiveFile)))
|
||||||
|
using (var stream = archive.GetStream("Soleily - Renatus (Gamu) [Insane].osu"))
|
||||||
|
using (var reader = new LineBufferedReader(stream))
|
||||||
|
{
|
||||||
|
var decoder = Decoder.GetDecoder<Beatmap>(reader);
|
||||||
|
var beatmap = decoder.Decode(reader);
|
||||||
|
|
||||||
|
info = beatmap.BeatmapInfo;
|
||||||
|
info.BeatmapSet.Beatmaps = new List<BeatmapInfo> { info };
|
||||||
|
info.BeatmapSet.Metadata = info.Metadata;
|
||||||
|
info.MD5Hash = stream.ComputeMD5Hash();
|
||||||
|
info.Hash = stream.ComputeSHA2Hash();
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestBeatmapManager : BeatmapManager
|
||||||
|
{
|
||||||
|
public TaskCompletionSource<bool> AllowImport = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
|
public Task<BeatmapSetInfo> CurrentImportTask { get; private set; }
|
||||||
|
|
||||||
|
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize)
|
||||||
|
=> new TestDownloadRequest(set);
|
||||||
|
|
||||||
|
public TestBeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, GameHost host = null, WorkingBeatmap defaultBeatmap = null, bool performOnlineLookups = false)
|
||||||
|
: base(storage, contextFactory, rulesets, api, audioManager, host, defaultBeatmap, performOnlineLookups)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<BeatmapSetInfo> Import(BeatmapSetInfo item, ArchiveReader archive = null, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
await AllowImport.Task;
|
||||||
|
return await (CurrentImportTask = base.Import(item, archive, cancellationToken));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestDownloadRequest : ArchiveDownloadRequest<BeatmapSetInfo>
|
||||||
|
{
|
||||||
|
public new void SetProgress(float progress) => base.SetProgress(progress);
|
||||||
|
public new void TriggerSuccess(string filename) => base.TriggerSuccess(filename);
|
||||||
|
|
||||||
|
public TestDownloadRequest(BeatmapSetInfo model)
|
||||||
|
: base(model)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Target => null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
osu.Game.Tests/Resources/animation-types.osb
Normal file
9
osu.Game.Tests/Resources/animation-types.osb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
osu file format v14
|
||||||
|
|
||||||
|
[Events]
|
||||||
|
Animation,Foreground,Centre,"forever-string.png",330,240,10,108,LoopForever
|
||||||
|
Animation,Foreground,Centre,"once-string.png",330,240,10,108,LoopOnce
|
||||||
|
Animation,Foreground,Centre,"forever-number.png",330,240,10,108,0
|
||||||
|
Animation,Foreground,Centre,"once-number.png",330,240,10,108,1
|
||||||
|
Animation,Foreground,Centre,"undefined-number.png",330,240,10,108,16
|
||||||
|
Animation,Foreground,Centre,"omitted.png",330,240,10,108
|
113
osu.Game.Tests/Rulesets/Mods/ModTimeRampTest.cs
Normal file
113
osu.Game.Tests/Rulesets/Mods/ModTimeRampTest.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
// 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.Audio.Track;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Rulesets.Mods
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ModTimeRampTest
|
||||||
|
{
|
||||||
|
private const double start_time = 1000;
|
||||||
|
private const double duration = 9000;
|
||||||
|
|
||||||
|
private TrackVirtual track;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp()
|
||||||
|
{
|
||||||
|
track = new TrackVirtual(20_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase(0, 1)]
|
||||||
|
[TestCase(start_time, 1)]
|
||||||
|
[TestCase(start_time + duration * ModTimeRamp.FINAL_RATE_PROGRESS / 2, 1.25)]
|
||||||
|
[TestCase(start_time + duration * ModTimeRamp.FINAL_RATE_PROGRESS, 1.5)]
|
||||||
|
[TestCase(start_time + duration, 1.5)]
|
||||||
|
[TestCase(15000, 1.5)]
|
||||||
|
public void TestModWindUp(double time, double expectedRate)
|
||||||
|
{
|
||||||
|
var beatmap = createSingleSpinnerBeatmap();
|
||||||
|
var mod = new ModWindUp();
|
||||||
|
mod.ApplyToBeatmap(beatmap);
|
||||||
|
mod.ApplyToTrack(track);
|
||||||
|
|
||||||
|
seekTrackAndUpdateMod(mod, time);
|
||||||
|
|
||||||
|
Assert.That(mod.SpeedChange.Value, Is.EqualTo(expectedRate));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase(0, 1)]
|
||||||
|
[TestCase(start_time, 1)]
|
||||||
|
[TestCase(start_time + duration * ModTimeRamp.FINAL_RATE_PROGRESS / 2, 0.75)]
|
||||||
|
[TestCase(start_time + duration * ModTimeRamp.FINAL_RATE_PROGRESS, 0.5)]
|
||||||
|
[TestCase(start_time + duration, 0.5)]
|
||||||
|
[TestCase(15000, 0.5)]
|
||||||
|
public void TestModWindDown(double time, double expectedRate)
|
||||||
|
{
|
||||||
|
var beatmap = createSingleSpinnerBeatmap();
|
||||||
|
var mod = new ModWindDown
|
||||||
|
{
|
||||||
|
FinalRate = { Value = 0.5 }
|
||||||
|
};
|
||||||
|
mod.ApplyToBeatmap(beatmap);
|
||||||
|
mod.ApplyToTrack(track);
|
||||||
|
|
||||||
|
seekTrackAndUpdateMod(mod, time);
|
||||||
|
|
||||||
|
Assert.That(mod.SpeedChange.Value, Is.EqualTo(expectedRate));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase(0, 1)]
|
||||||
|
[TestCase(start_time, 1)]
|
||||||
|
[TestCase(2 * start_time, 1.5)]
|
||||||
|
public void TestZeroDurationMap(double time, double expectedRate)
|
||||||
|
{
|
||||||
|
var beatmap = createSingleObjectBeatmap();
|
||||||
|
var mod = new ModWindUp();
|
||||||
|
mod.ApplyToBeatmap(beatmap);
|
||||||
|
mod.ApplyToTrack(track);
|
||||||
|
|
||||||
|
seekTrackAndUpdateMod(mod, time);
|
||||||
|
|
||||||
|
Assert.That(mod.SpeedChange.Value, Is.EqualTo(expectedRate));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void seekTrackAndUpdateMod(ModTimeRamp mod, double time)
|
||||||
|
{
|
||||||
|
track.Seek(time);
|
||||||
|
// update the mod via a fake playfield to re-calculate the current rate.
|
||||||
|
mod.Update(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Beatmap createSingleSpinnerBeatmap()
|
||||||
|
{
|
||||||
|
return new Beatmap
|
||||||
|
{
|
||||||
|
HitObjects =
|
||||||
|
{
|
||||||
|
new Spinner
|
||||||
|
{
|
||||||
|
StartTime = start_time,
|
||||||
|
Duration = duration
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Beatmap createSingleObjectBeatmap()
|
||||||
|
{
|
||||||
|
return new Beatmap
|
||||||
|
{
|
||||||
|
HitObjects =
|
||||||
|
{
|
||||||
|
new HitCircle { StartTime = start_time }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,8 @@ using NUnit.Framework;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
||||||
|
using osu.Game.Screens.Edit;
|
||||||
using osu.Game.Screens.Edit.Components.Timelines.Summary;
|
using osu.Game.Screens.Edit.Components.Timelines.Summary;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
@ -13,6 +15,9 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneEditorSummaryTimeline : EditorClockTestScene
|
public class TestSceneEditorSummaryTimeline : EditorClockTestScene
|
||||||
{
|
{
|
||||||
|
[Cached(typeof(EditorBeatmap))]
|
||||||
|
private readonly EditorBeatmap editorBeatmap = new EditorBeatmap(new OsuBeatmap());
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
|
@ -17,10 +17,12 @@ using osu.Framework.Utils;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Difficulty;
|
using osu.Game.Rulesets.Difficulty;
|
||||||
|
using osu.Game.Rulesets.Judgements;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
using osu.Game.Rulesets.Objects.Legacy;
|
using osu.Game.Rulesets.Objects.Legacy;
|
||||||
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -129,6 +131,31 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddUntilStep("no DHOs shown", () => !this.ChildrenOfType<DrawableTestHitObject>().Any());
|
AddUntilStep("no DHOs shown", () => !this.ChildrenOfType<DrawableTestHitObject>().Any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestApplyHitResultOnKilled()
|
||||||
|
{
|
||||||
|
ManualClock clock = null;
|
||||||
|
bool anyJudged = false;
|
||||||
|
|
||||||
|
void onNewResult(JudgementResult _) => anyJudged = true;
|
||||||
|
|
||||||
|
var beatmap = new Beatmap();
|
||||||
|
beatmap.HitObjects.Add(new TestKilledHitObject { Duration = 20 });
|
||||||
|
|
||||||
|
createTest(beatmap, 10, () => new FramedClock(clock = new ManualClock()));
|
||||||
|
|
||||||
|
AddStep("subscribe to new result", () =>
|
||||||
|
{
|
||||||
|
anyJudged = false;
|
||||||
|
drawableRuleset.NewResult += onNewResult;
|
||||||
|
});
|
||||||
|
AddStep("skip past object", () => clock.CurrentTime = beatmap.HitObjects[0].GetEndTime() + 1000);
|
||||||
|
|
||||||
|
AddAssert("object judged", () => anyJudged);
|
||||||
|
|
||||||
|
AddStep("clean up", () => drawableRuleset.NewResult -= onNewResult);
|
||||||
|
}
|
||||||
|
|
||||||
private void createTest(IBeatmap beatmap, int poolSize, Func<IFrameBasedClock> createClock = null) => AddStep("create test", () =>
|
private void createTest(IBeatmap beatmap, int poolSize, Func<IFrameBasedClock> createClock = null) => AddStep("create test", () =>
|
||||||
{
|
{
|
||||||
var ruleset = new TestPoolingRuleset();
|
var ruleset = new TestPoolingRuleset();
|
||||||
@ -192,6 +219,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
RegisterPool<TestHitObject, DrawableTestHitObject>(poolSize);
|
RegisterPool<TestHitObject, DrawableTestHitObject>(poolSize);
|
||||||
|
RegisterPool<TestKilledHitObject, DrawableTestKilledHitObject>(poolSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override HitObjectLifetimeEntry CreateLifetimeEntry(HitObject hitObject) => new TestHitObjectLifetimeEntry(hitObject);
|
protected override HitObjectLifetimeEntry CreateLifetimeEntry(HitObject hitObject) => new TestHitObjectLifetimeEntry(hitObject);
|
||||||
@ -220,19 +248,30 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
protected override IEnumerable<TestHitObject> ConvertHitObject(HitObject original, IBeatmap beatmap, CancellationToken cancellationToken)
|
protected override IEnumerable<TestHitObject> ConvertHitObject(HitObject original, IBeatmap beatmap, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
yield return new TestHitObject
|
switch (original)
|
||||||
{
|
{
|
||||||
StartTime = original.StartTime,
|
case TestKilledHitObject h:
|
||||||
Duration = 250
|
yield return h;
|
||||||
};
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
yield return new TestHitObject
|
||||||
|
{
|
||||||
|
StartTime = original.StartTime,
|
||||||
|
Duration = 250
|
||||||
|
};
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region HitObject
|
#region HitObjects
|
||||||
|
|
||||||
private class TestHitObject : ConvertHitObject
|
private class TestHitObject : ConvertHitObject, IHasDuration
|
||||||
{
|
{
|
||||||
public double EndTime => StartTime + Duration;
|
public double EndTime => StartTime + Duration;
|
||||||
|
|
||||||
@ -287,6 +326,30 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class TestKilledHitObject : TestHitObject
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DrawableTestKilledHitObject : DrawableHitObject<TestKilledHitObject>
|
||||||
|
{
|
||||||
|
public DrawableTestKilledHitObject()
|
||||||
|
: base(null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateHitStateTransforms(ArmedState state)
|
||||||
|
{
|
||||||
|
base.UpdateHitStateTransforms(state);
|
||||||
|
Expire();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnKilled()
|
||||||
|
{
|
||||||
|
base.OnKilled();
|
||||||
|
ApplyResult(r => r.Type = r.Judgement.MinResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Storyboards;
|
||||||
|
using osu.Game.Storyboards.Drawables;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Gameplay
|
||||||
|
{
|
||||||
|
public class TestSceneStoryboardSamplePlayback : PlayerTestScene
|
||||||
|
{
|
||||||
|
private Storyboard storyboard;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuConfigManager config)
|
||||||
|
{
|
||||||
|
config.Set(OsuSetting.ShowStoryboard, true);
|
||||||
|
|
||||||
|
storyboard = new Storyboard();
|
||||||
|
var backgroundLayer = storyboard.GetLayer("Background");
|
||||||
|
backgroundLayer.Add(new StoryboardSampleInfo("Intro/welcome.mp3", time: -7000, volume: 20));
|
||||||
|
backgroundLayer.Add(new StoryboardSampleInfo("Intro/welcome.mp3", time: -5000, volume: 20));
|
||||||
|
backgroundLayer.Add(new StoryboardSampleInfo("Intro/welcome.mp3", time: 0, volume: 20));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestStoryboardSamplesStopDuringPause()
|
||||||
|
{
|
||||||
|
checkForFirstSamplePlayback();
|
||||||
|
|
||||||
|
AddStep("player paused", () => Player.Pause());
|
||||||
|
AddAssert("player is currently paused", () => Player.GameplayClockContainer.IsPaused.Value);
|
||||||
|
AddAssert("all storyboard samples stopped immediately", () => allStoryboardSamples.All(sound => !sound.IsPlaying));
|
||||||
|
|
||||||
|
AddStep("player resume", () => Player.Resume());
|
||||||
|
AddUntilStep("any storyboard samples playing after resume", () => allStoryboardSamples.Any(sound => sound.IsPlaying));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestStoryboardSamplesStopOnSkip()
|
||||||
|
{
|
||||||
|
checkForFirstSamplePlayback();
|
||||||
|
|
||||||
|
AddStep("skip intro", () => InputManager.Key(osuTK.Input.Key.Space));
|
||||||
|
AddAssert("all storyboard samples stopped immediately", () => allStoryboardSamples.All(sound => !sound.IsPlaying));
|
||||||
|
|
||||||
|
AddUntilStep("any storyboard samples playing after skip", () => allStoryboardSamples.Any(sound => sound.IsPlaying));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkForFirstSamplePlayback()
|
||||||
|
{
|
||||||
|
AddUntilStep("storyboard loaded", () => Player.Beatmap.Value.StoryboardLoaded);
|
||||||
|
AddUntilStep("any storyboard samples playing", () => allStoryboardSamples.Any(sound => sound.IsPlaying));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<DrawableStoryboardSample> allStoryboardSamples => Player.ChildrenOfType<DrawableStoryboardSample>();
|
||||||
|
|
||||||
|
protected override bool AllowFail => false;
|
||||||
|
|
||||||
|
protected override Ruleset CreatePlayerRuleset() => new OsuRuleset();
|
||||||
|
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(true, false);
|
||||||
|
|
||||||
|
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) =>
|
||||||
|
new ClockBackedTestWorkingBeatmap(beatmap, storyboard ?? this.storyboard, Clock, Audio);
|
||||||
|
}
|
||||||
|
}
|
@ -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 =
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Screens.OnlinePlay;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Multiplayer
|
||||||
|
{
|
||||||
|
public class TestSceneFreeModSelectOverlay : MultiplayerTestScene
|
||||||
|
{
|
||||||
|
[SetUp]
|
||||||
|
public new void Setup() => Schedule(() =>
|
||||||
|
{
|
||||||
|
Child = new FreeModSelectOverlay
|
||||||
|
{
|
||||||
|
State = { Value = Visibility.Visible }
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,8 @@ using osu.Framework.Graphics.Sprites;
|
|||||||
using osu.Framework.Testing;
|
using osu.Framework.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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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]
|
||||||
|
@ -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;
|
||||||
}
|
}
|
@ -1,32 +1,81 @@
|
|||||||
// 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 osu.Game.Overlays;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.BeatmapListing;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.Online
|
||||||
{
|
{
|
||||||
public class TestSceneBeatmapListingOverlay : OsuTestScene
|
public class TestSceneBeatmapListingOverlay : OsuTestScene
|
||||||
{
|
{
|
||||||
protected override bool UseOnlineAPI => true;
|
private readonly List<APIBeatmapSet> setsForResponse = new List<APIBeatmapSet>();
|
||||||
|
|
||||||
private readonly BeatmapListingOverlay overlay;
|
private BeatmapListingOverlay overlay;
|
||||||
|
|
||||||
public TestSceneBeatmapListingOverlay()
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
{
|
{
|
||||||
Add(overlay = new BeatmapListingOverlay());
|
Child = overlay = new BeatmapListingOverlay { State = { Value = Visibility.Visible } };
|
||||||
|
|
||||||
|
((DummyAPIAccess)API).HandleRequest = req =>
|
||||||
|
{
|
||||||
|
if (req is SearchBeatmapSetsRequest searchBeatmapSetsRequest)
|
||||||
|
{
|
||||||
|
searchBeatmapSetsRequest.TriggerSuccess(new SearchBeatmapSetsResponse
|
||||||
|
{
|
||||||
|
BeatmapSets = setsForResponse,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestShow()
|
public void TestNoBeatmapsPlaceholder()
|
||||||
{
|
{
|
||||||
AddStep("Show", overlay.Show);
|
AddStep("fetch for 0 beatmaps", () => fetchFor());
|
||||||
|
AddUntilStep("placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true);
|
||||||
|
|
||||||
|
AddStep("fetch for 1 beatmap", () => fetchFor(CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet));
|
||||||
|
AddUntilStep("placeholder hidden", () => !overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().Any());
|
||||||
|
|
||||||
|
AddStep("fetch for 0 beatmaps", () => fetchFor());
|
||||||
|
AddUntilStep("placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true);
|
||||||
|
|
||||||
|
// fetch once more to ensure nothing happens in displaying placeholder again when it already is present.
|
||||||
|
AddStep("fetch for 0 beatmaps again", () => fetchFor());
|
||||||
|
AddUntilStep("placeholder shown", () => overlay.ChildrenOfType<BeatmapListingOverlay.NotFoundDrawable>().SingleOrDefault()?.IsPresent == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
private void fetchFor(params BeatmapSetInfo[] beatmaps)
|
||||||
public void TestHide()
|
|
||||||
{
|
{
|
||||||
AddStep("Hide", overlay.Hide);
|
setsForResponse.Clear();
|
||||||
|
setsForResponse.AddRange(beatmaps.Select(b => new TestAPIBeatmapSet(b)));
|
||||||
|
|
||||||
|
// trigger arbitrary change for fetching.
|
||||||
|
overlay.ChildrenOfType<BeatmapListingSearchControl>().Single().Query.TriggerChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestAPIBeatmapSet : APIBeatmapSet
|
||||||
|
{
|
||||||
|
private readonly BeatmapSetInfo beatmapSet;
|
||||||
|
|
||||||
|
public TestAPIBeatmapSet(BeatmapSetInfo beatmapSet)
|
||||||
|
{
|
||||||
|
this.beatmapSet = beatmapSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override BeatmapSetInfo ToBeatmapSet(RulesetStore rulesets) => beatmapSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,8 +231,8 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("shown beatmaps of current ruleset", () => overlay.Header.Picker.Difficulties.All(b => b.Beatmap.Ruleset.Equals(overlay.Header.RulesetSelector.Current.Value)));
|
AddAssert("shown beatmaps of current ruleset", () => overlay.Header.HeaderContent.Picker.Difficulties.All(b => b.Beatmap.Ruleset.Equals(overlay.Header.RulesetSelector.Current.Value)));
|
||||||
AddAssert("left-most beatmap selected", () => overlay.Header.Picker.Difficulties.First().State == BeatmapPicker.DifficultySelectorState.Selected);
|
AddAssert("left-most beatmap selected", () => overlay.Header.HeaderContent.Picker.Difficulties.First().State == BeatmapPicker.DifficultySelectorState.Selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -310,12 +310,12 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
|
|
||||||
private void downloadAssert(bool shown)
|
private void downloadAssert(bool shown)
|
||||||
{
|
{
|
||||||
AddAssert($"is download button {(shown ? "shown" : "hidden")}", () => overlay.Header.DownloadButtonsVisible == shown);
|
AddAssert($"is download button {(shown ? "shown" : "hidden")}", () => overlay.Header.HeaderContent.DownloadButtonsVisible == shown);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestBeatmapSetOverlay : BeatmapSetOverlay
|
private class TestBeatmapSetOverlay : BeatmapSetOverlay
|
||||||
{
|
{
|
||||||
public new Header Header => base.Header;
|
public new BeatmapSetHeader Header => base.Header;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
// 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.Overlays;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Online
|
||||||
|
{
|
||||||
|
[Description("uses online API")]
|
||||||
|
public class TestSceneOnlineBeatmapListingOverlay : OsuTestScene
|
||||||
|
{
|
||||||
|
protected override bool UseOnlineAPI => true;
|
||||||
|
|
||||||
|
private readonly BeatmapListingOverlay overlay;
|
||||||
|
|
||||||
|
public TestSceneOnlineBeatmapListingOverlay()
|
||||||
|
{
|
||||||
|
Add(overlay = new BeatmapListingOverlay());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestShow()
|
||||||
|
{
|
||||||
|
AddStep("Show", overlay.Show);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestHide()
|
||||||
|
{
|
||||||
|
AddStep("Hide", overlay.Hide);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ using osu.Game.Overlays.Comments;
|
|||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.Online
|
||||||
{
|
{
|
||||||
@ -16,13 +18,33 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
[Cached]
|
[Cached]
|
||||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
||||||
|
|
||||||
private VotePill votePill;
|
[Cached]
|
||||||
|
private LoginOverlay login;
|
||||||
|
|
||||||
|
private TestPill votePill;
|
||||||
|
private readonly Container pillContainer;
|
||||||
|
|
||||||
|
public TestSceneVotePill()
|
||||||
|
{
|
||||||
|
AddRange(new Drawable[]
|
||||||
|
{
|
||||||
|
pillContainer = new Container
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
AutoSizeAxes = Axes.Both
|
||||||
|
},
|
||||||
|
login = new LoginOverlay()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestUserCommentPill()
|
public void TestUserCommentPill()
|
||||||
{
|
{
|
||||||
|
AddStep("Hide login overlay", () => login.Hide());
|
||||||
AddStep("Log in", logIn);
|
AddStep("Log in", logIn);
|
||||||
AddStep("User comment", () => addVotePill(getUserComment()));
|
AddStep("User comment", () => addVotePill(getUserComment()));
|
||||||
|
AddAssert("Background is transparent", () => votePill.Background.Alpha == 0);
|
||||||
AddStep("Click", () => votePill.Click());
|
AddStep("Click", () => votePill.Click());
|
||||||
AddAssert("Not loading", () => !votePill.IsLoading);
|
AddAssert("Not loading", () => !votePill.IsLoading);
|
||||||
}
|
}
|
||||||
@ -30,8 +52,10 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestRandomCommentPill()
|
public void TestRandomCommentPill()
|
||||||
{
|
{
|
||||||
|
AddStep("Hide login overlay", () => login.Hide());
|
||||||
AddStep("Log in", logIn);
|
AddStep("Log in", logIn);
|
||||||
AddStep("Random comment", () => addVotePill(getRandomComment()));
|
AddStep("Random comment", () => addVotePill(getRandomComment()));
|
||||||
|
AddAssert("Background is visible", () => votePill.Background.Alpha == 1);
|
||||||
AddStep("Click", () => votePill.Click());
|
AddStep("Click", () => votePill.Click());
|
||||||
AddAssert("Loading", () => votePill.IsLoading);
|
AddAssert("Loading", () => votePill.IsLoading);
|
||||||
}
|
}
|
||||||
@ -39,10 +63,11 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestOfflineRandomCommentPill()
|
public void TestOfflineRandomCommentPill()
|
||||||
{
|
{
|
||||||
|
AddStep("Hide login overlay", () => login.Hide());
|
||||||
AddStep("Log out", API.Logout);
|
AddStep("Log out", API.Logout);
|
||||||
AddStep("Random comment", () => addVotePill(getRandomComment()));
|
AddStep("Random comment", () => addVotePill(getRandomComment()));
|
||||||
AddStep("Click", () => votePill.Click());
|
AddStep("Click", () => votePill.Click());
|
||||||
AddAssert("Not loading", () => !votePill.IsLoading);
|
AddAssert("Login overlay is visible", () => login.State.Value == Visibility.Visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logIn() => API.Login("localUser", "password");
|
private void logIn() => API.Login("localUser", "password");
|
||||||
@ -63,12 +88,22 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
|
|
||||||
private void addVotePill(Comment comment)
|
private void addVotePill(Comment comment)
|
||||||
{
|
{
|
||||||
Clear();
|
pillContainer.Clear();
|
||||||
Add(votePill = new VotePill(comment)
|
pillContainer.Child = votePill = new TestPill(comment)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestPill : VotePill
|
||||||
|
{
|
||||||
|
public new Box Background => base.Background;
|
||||||
|
|
||||||
|
public TestPill(Comment comment)
|
||||||
|
: base(comment)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
|
21
osu.Game.Tests/Visual/UserInterface/TestSceneModIcon.cs
Normal file
21
osu.Game.Tests/Visual/UserInterface/TestSceneModIcon.cs
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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,27 +39,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp() => Schedule(() =>
|
public void SetUp() => Schedule(() => createDisplay(() => new TestModSelectOverlay()));
|
||||||
{
|
|
||||||
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()
|
||||||
@ -66,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()
|
||||||
{
|
{
|
||||||
@ -134,6 +141,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestExternallySetCustomizedMod()
|
public void TestExternallySetCustomizedMod()
|
||||||
{
|
{
|
||||||
|
changeRuleset(0);
|
||||||
|
|
||||||
AddStep("set customized mod externally", () => SelectedMods.Value = new[] { new OsuModDoubleTime { SpeedChange = { Value = 1.01 } } });
|
AddStep("set customized mod externally", () => SelectedMods.Value = new[] { new OsuModDoubleTime { SpeedChange = { Value = 1.01 } } });
|
||||||
|
|
||||||
AddAssert("ensure button is selected and customized accordingly", () =>
|
AddAssert("ensure button is selected and customized accordingly", () =>
|
||||||
@ -143,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);
|
||||||
@ -262,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 : LocalPlayerModSelectOverlay
|
||||||
{
|
{
|
||||||
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);
|
||||||
@ -280,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 : LocalPlayerModSelectOverlay
|
||||||
{
|
{
|
||||||
public new VisibilityContainer ModSettingsContainer => base.ModSettingsContainer;
|
public new VisibilityContainer ModSettingsContainer => base.ModSettingsContainer;
|
||||||
public new TriangleButton CustomiseButton => base.CustomiseButton;
|
public new TriangleButton CustomiseButton => base.CustomiseButton;
|
||||||
|
@ -0,0 +1,122 @@
|
|||||||
|
// 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.Graphics;
|
||||||
|
using osu.Framework.Graphics.Colour;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
|
{
|
||||||
|
public class TestSceneSectionsContainer : OsuManualInputManagerTestScene
|
||||||
|
{
|
||||||
|
private readonly SectionsContainer<TestSection> container;
|
||||||
|
private float custom;
|
||||||
|
private const float header_height = 100;
|
||||||
|
|
||||||
|
public TestSceneSectionsContainer()
|
||||||
|
{
|
||||||
|
container = new SectionsContainer<TestSection>
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Y,
|
||||||
|
Width = 300,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
FixedHeader = new Box
|
||||||
|
{
|
||||||
|
Alpha = 0.5f,
|
||||||
|
Width = 300,
|
||||||
|
Height = header_height,
|
||||||
|
Colour = Color4.Red
|
||||||
|
}
|
||||||
|
};
|
||||||
|
container.SelectedSection.ValueChanged += section =>
|
||||||
|
{
|
||||||
|
if (section.OldValue != null)
|
||||||
|
section.OldValue.Selected = false;
|
||||||
|
if (section.NewValue != null)
|
||||||
|
section.NewValue.Selected = true;
|
||||||
|
};
|
||||||
|
Add(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSelection()
|
||||||
|
{
|
||||||
|
AddStep("clear", () => container.Clear());
|
||||||
|
AddStep("add 1/8th", () => append(1 / 8.0f));
|
||||||
|
AddStep("add third", () => append(1 / 3.0f));
|
||||||
|
AddStep("add half", () => append(1 / 2.0f));
|
||||||
|
AddStep("add full", () => append(1));
|
||||||
|
AddSliderStep("set custom", 0.1f, 1.1f, 0.5f, i => custom = i);
|
||||||
|
AddStep("add custom", () => append(custom));
|
||||||
|
AddStep("scroll to previous", () => container.ScrollTo(
|
||||||
|
container.Children.Reverse().SkipWhile(s => s != container.SelectedSection.Value).Skip(1).FirstOrDefault() ?? container.Children.First()
|
||||||
|
));
|
||||||
|
AddStep("scroll to next", () => container.ScrollTo(
|
||||||
|
container.Children.SkipWhile(s => s != container.SelectedSection.Value).Skip(1).FirstOrDefault() ?? container.Children.Last()
|
||||||
|
));
|
||||||
|
AddStep("scroll up", () => triggerUserScroll(1));
|
||||||
|
AddStep("scroll down", () => triggerUserScroll(-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCorrectSectionSelected()
|
||||||
|
{
|
||||||
|
const int sections_count = 11;
|
||||||
|
float[] alternating = { 0.07f, 0.33f, 0.16f, 0.33f };
|
||||||
|
AddStep("clear", () => container.Clear());
|
||||||
|
AddStep("fill with sections", () =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < sections_count; i++)
|
||||||
|
append(alternating[i % alternating.Length]);
|
||||||
|
});
|
||||||
|
|
||||||
|
void step(int scrollIndex)
|
||||||
|
{
|
||||||
|
AddStep($"scroll to section {scrollIndex + 1}", () => container.ScrollTo(container.Children[scrollIndex]));
|
||||||
|
AddUntilStep("correct section selected", () => container.SelectedSection.Value == container.Children[scrollIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i < sections_count; i++)
|
||||||
|
step(i);
|
||||||
|
for (int i = sections_count - 2; i >= 0; i--)
|
||||||
|
step(i);
|
||||||
|
|
||||||
|
AddStep("scroll almost to end", () => container.ScrollTo(container.Children[sections_count - 2]));
|
||||||
|
AddUntilStep("correct section selected", () => container.SelectedSection.Value == container.Children[sections_count - 2]);
|
||||||
|
AddStep("scroll down", () => triggerUserScroll(-1));
|
||||||
|
AddUntilStep("correct section selected", () => container.SelectedSection.Value == container.Children[sections_count - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly ColourInfo selected_colour = ColourInfo.GradientVertical(Color4.Yellow, Color4.Gold);
|
||||||
|
private static readonly ColourInfo default_colour = ColourInfo.GradientVertical(Color4.White, Color4.DarkGray);
|
||||||
|
|
||||||
|
private void append(float multiplier)
|
||||||
|
{
|
||||||
|
container.Add(new TestSection
|
||||||
|
{
|
||||||
|
Width = 300,
|
||||||
|
Height = (container.ChildSize.Y - header_height) * multiplier,
|
||||||
|
Colour = default_colour
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void triggerUserScroll(float direction)
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(container);
|
||||||
|
InputManager.ScrollVerticalBy(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestSection : Box
|
||||||
|
{
|
||||||
|
public bool Selected
|
||||||
|
{
|
||||||
|
set => Colour = value ? selected_colour : default_colour;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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>
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Tournament.Components;
|
||||||
|
|
||||||
|
namespace osu.Game.Tournament.Tests.Components
|
||||||
|
{
|
||||||
|
public class TestSceneTournamentModDisplay : TournamentTestScene
|
||||||
|
{
|
||||||
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
|
private FillFlowContainer<TournamentBeatmapPanel> fillFlow;
|
||||||
|
|
||||||
|
private BeatmapInfo beatmap;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = 490154 });
|
||||||
|
req.Success += success;
|
||||||
|
api.Queue(req);
|
||||||
|
|
||||||
|
Add(fillFlow = new FillFlowContainer<TournamentBeatmapPanel>
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Direction = FillDirection.Full,
|
||||||
|
Spacing = new osuTK.Vector2(10)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void success(APIBeatmap apiBeatmap)
|
||||||
|
{
|
||||||
|
beatmap = apiBeatmap.ToBeatmap(rulesets);
|
||||||
|
var mods = rulesets.GetRuleset(Ladder.Ruleset.Value.ID ?? 0).CreateInstance().GetAllMods();
|
||||||
|
|
||||||
|
foreach (var mod in mods)
|
||||||
|
{
|
||||||
|
fillFlow.Add(new TournamentBeatmapPanel(beatmap, mod.Acronym)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
// 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 NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Tournament.Components;
|
using osu.Game.Tournament.Components;
|
||||||
@ -16,5 +18,23 @@ namespace osu.Game.Tournament.Tests.Screens
|
|||||||
Add(new TourneyVideo("main") { RelativeSizeAxes = Axes.Both });
|
Add(new TourneyVideo("main") { RelativeSizeAxes = Axes.Both });
|
||||||
Add(new ScheduleScreen());
|
Add(new ScheduleScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCurrentMatchTime()
|
||||||
|
{
|
||||||
|
setMatchDate(TimeSpan.FromDays(-1));
|
||||||
|
setMatchDate(TimeSpan.FromSeconds(5));
|
||||||
|
setMatchDate(TimeSpan.FromMinutes(4));
|
||||||
|
setMatchDate(TimeSpan.FromHours(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMatchDate(TimeSpan relativeTime)
|
||||||
|
// Humanizer cannot handle negative timespans.
|
||||||
|
=> AddStep($"start time is {relativeTime}", () =>
|
||||||
|
{
|
||||||
|
var match = CreateSampleMatch();
|
||||||
|
match.Date.Value = DateTimeOffset.Now + relativeTime;
|
||||||
|
Ladder.CurrentMatch.Value = match;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ using osu.Framework.Bindables;
|
|||||||
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.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -23,7 +22,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
public class TournamentBeatmapPanel : CompositeDrawable
|
public class TournamentBeatmapPanel : CompositeDrawable
|
||||||
{
|
{
|
||||||
public readonly BeatmapInfo Beatmap;
|
public readonly BeatmapInfo Beatmap;
|
||||||
private readonly string mods;
|
private readonly string mod;
|
||||||
|
|
||||||
private const float horizontal_padding = 10;
|
private const float horizontal_padding = 10;
|
||||||
private const float vertical_padding = 10;
|
private const float vertical_padding = 10;
|
||||||
@ -33,12 +32,12 @@ namespace osu.Game.Tournament.Components
|
|||||||
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
|
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
|
||||||
private Box flash;
|
private Box flash;
|
||||||
|
|
||||||
public TournamentBeatmapPanel(BeatmapInfo beatmap, string mods = null)
|
public TournamentBeatmapPanel(BeatmapInfo beatmap, string mod = null)
|
||||||
{
|
{
|
||||||
if (beatmap == null) throw new ArgumentNullException(nameof(beatmap));
|
if (beatmap == null) throw new ArgumentNullException(nameof(beatmap));
|
||||||
|
|
||||||
Beatmap = beatmap;
|
Beatmap = beatmap;
|
||||||
this.mods = mods;
|
this.mod = mod;
|
||||||
Width = 400;
|
Width = 400;
|
||||||
Height = HEIGHT;
|
Height = HEIGHT;
|
||||||
}
|
}
|
||||||
@ -122,23 +121,15 @@ namespace osu.Game.Tournament.Components
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(mods))
|
if (!string.IsNullOrEmpty(mod))
|
||||||
{
|
{
|
||||||
AddInternal(new Container
|
AddInternal(new TournamentModIcon(mod)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y,
|
|
||||||
Width = 60,
|
|
||||||
Anchor = Anchor.CentreRight,
|
Anchor = Anchor.CentreRight,
|
||||||
Origin = Anchor.CentreRight,
|
Origin = Anchor.CentreRight,
|
||||||
Margin = new MarginPadding(10),
|
Margin = new MarginPadding(10),
|
||||||
Child = new Sprite
|
Width = 60,
|
||||||
{
|
RelativeSizeAxes = Axes.Y,
|
||||||
FillMode = FillMode.Fit,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Anchor = Anchor.CentreRight,
|
|
||||||
Origin = Anchor.CentreRight,
|
|
||||||
Texture = textures.Get($"mods/{mods}"),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
65
osu.Game.Tournament/Components/TournamentModIcon.cs
Normal file
65
osu.Game.Tournament/Components/TournamentModIcon.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
using osu.Game.Tournament.Models;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Tournament.Components
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Mod icon displayed in tournament usages, allowing user overridden graphics.
|
||||||
|
/// </summary>
|
||||||
|
public class TournamentModIcon : CompositeDrawable
|
||||||
|
{
|
||||||
|
private readonly string modAcronym;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
|
public TournamentModIcon(string modAcronym)
|
||||||
|
{
|
||||||
|
this.modAcronym = modAcronym;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(TextureStore textures, LadderInfo ladderInfo)
|
||||||
|
{
|
||||||
|
var customTexture = textures.Get($"mods/{modAcronym}");
|
||||||
|
|
||||||
|
if (customTexture != null)
|
||||||
|
{
|
||||||
|
AddInternal(new Sprite
|
||||||
|
{
|
||||||
|
FillMode = FillMode.Fit,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.CentreRight,
|
||||||
|
Origin = Anchor.CentreRight,
|
||||||
|
Texture = customTexture
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ruleset = rulesets.GetRuleset(ladderInfo.Ruleset.Value?.ID ?? 0);
|
||||||
|
var modIcon = ruleset?.CreateInstance().GetAllMods().FirstOrDefault(mod => mod.Acronym == modAcronym);
|
||||||
|
|
||||||
|
if (modIcon == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AddInternal(new ModIcon(modIcon, false)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Scale = new Vector2(0.5f)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -192,12 +192,7 @@ namespace osu.Game.Tournament.Screens.Schedule
|
|||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new TournamentSpriteText
|
new ScheduleMatchDate(match.NewValue.Date.Value)
|
||||||
{
|
|
||||||
Text = "Starting ",
|
|
||||||
Font = OsuFont.Torus.With(size: 24, weight: FontWeight.Regular)
|
|
||||||
},
|
|
||||||
new DrawableDate(match.NewValue.Date.Value)
|
|
||||||
{
|
{
|
||||||
Font = OsuFont.Torus.With(size: 24, weight: FontWeight.Regular)
|
Font = OsuFont.Torus.With(size: 24, weight: FontWeight.Regular)
|
||||||
}
|
}
|
||||||
@ -251,6 +246,18 @@ namespace osu.Game.Tournament.Screens.Schedule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ScheduleMatchDate : DrawableDate
|
||||||
|
{
|
||||||
|
public ScheduleMatchDate(DateTimeOffset date, float textSize = OsuFont.DEFAULT_FONT_SIZE, bool italic = true)
|
||||||
|
: base(date, textSize, italic)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Format() => Date < DateTimeOffset.Now
|
||||||
|
? $"Started {base.Format()}"
|
||||||
|
: $"Starting {base.Format()}";
|
||||||
|
}
|
||||||
|
|
||||||
public class ScheduleContainer : Container
|
public class ScheduleContainer : Container
|
||||||
{
|
{
|
||||||
protected override Container<Drawable> Content => content;
|
protected override Container<Drawable> Content => content;
|
||||||
|
@ -50,15 +50,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
IBeatmap IBeatmap.Clone() => Clone();
|
IBeatmap IBeatmap.Clone() => Clone();
|
||||||
|
|
||||||
public Beatmap<T> Clone()
|
public Beatmap<T> Clone() => (Beatmap<T>)MemberwiseClone();
|
||||||
{
|
|
||||||
var clone = (Beatmap<T>)MemberwiseClone();
|
|
||||||
|
|
||||||
clone.ControlPointInfo = ControlPointInfo.CreateCopy();
|
|
||||||
// todo: deep clone other elements as required.
|
|
||||||
|
|
||||||
return clone;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Beatmap : Beatmap<HitObject>
|
public class Beatmap : Beatmap<HitObject>
|
||||||
|
@ -7,7 +7,6 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dapper;
|
|
||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
using osu.Framework.Development;
|
using osu.Framework.Development;
|
||||||
using osu.Framework.IO.Network;
|
using osu.Framework.IO.Network;
|
||||||
@ -154,20 +153,31 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
using (var db = new SqliteConnection(storage.GetDatabaseConnectionString("online")))
|
using (var db = new SqliteConnection(storage.GetDatabaseConnectionString("online")))
|
||||||
{
|
{
|
||||||
var found = db.QuerySingleOrDefault<CachedOnlineBeatmapLookup>(
|
db.Open();
|
||||||
"SELECT * FROM osu_beatmaps WHERE checksum = @MD5Hash OR beatmap_id = @OnlineBeatmapID OR filename = @Path", beatmap);
|
|
||||||
|
|
||||||
if (found != null)
|
using (var cmd = db.CreateCommand())
|
||||||
{
|
{
|
||||||
var status = (BeatmapSetOnlineStatus)found.approved;
|
cmd.CommandText = "SELECT beatmapset_id, beatmap_id, approved FROM osu_beatmaps WHERE checksum = @MD5Hash OR beatmap_id = @OnlineBeatmapID OR filename = @Path";
|
||||||
|
|
||||||
beatmap.Status = status;
|
cmd.Parameters.Add(new SqliteParameter("@MD5Hash", beatmap.MD5Hash));
|
||||||
beatmap.BeatmapSet.Status = status;
|
cmd.Parameters.Add(new SqliteParameter("@OnlineBeatmapID", beatmap.OnlineBeatmapID ?? (object)DBNull.Value));
|
||||||
beatmap.BeatmapSet.OnlineBeatmapSetID = found.beatmapset_id;
|
cmd.Parameters.Add(new SqliteParameter("@Path", beatmap.Path));
|
||||||
beatmap.OnlineBeatmapID = found.beatmap_id;
|
|
||||||
|
|
||||||
LogForModel(set, $"Cached local retrieval for {beatmap}.");
|
using (var reader = cmd.ExecuteReader())
|
||||||
return true;
|
{
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
var status = (BeatmapSetOnlineStatus)reader.GetByte(2);
|
||||||
|
|
||||||
|
beatmap.Status = status;
|
||||||
|
beatmap.BeatmapSet.Status = status;
|
||||||
|
beatmap.BeatmapSet.OnlineBeatmapSetID = reader.GetInt32(0);
|
||||||
|
beatmap.OnlineBeatmapID = reader.GetInt32(1);
|
||||||
|
|
||||||
|
LogForModel(set, $"Cached local retrieval for {beatmap}.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
// this is random as hell but taken straight from osu-stable.
|
// this is random as hell but taken straight from osu-stable.
|
||||||
frameDelay = Math.Round(0.015 * frameDelay) * 1.186 * (1000 / 60f);
|
frameDelay = Math.Round(0.015 * frameDelay) * 1.186 * (1000 / 60f);
|
||||||
|
|
||||||
var loopType = split.Length > 8 ? (AnimationLoopType)Enum.Parse(typeof(AnimationLoopType), split[8]) : AnimationLoopType.LoopForever;
|
var loopType = split.Length > 8 ? parseAnimationLoopType(split[8]) : AnimationLoopType.LoopForever;
|
||||||
storyboardSprite = new StoryboardAnimation(path, origin, new Vector2(x, y), frameCount, frameDelay, loopType);
|
storyboardSprite = new StoryboardAnimation(path, origin, new Vector2(x, y), frameCount, frameDelay, loopType);
|
||||||
storyboard.GetLayer(layer).Add(storyboardSprite);
|
storyboard.GetLayer(layer).Add(storyboardSprite);
|
||||||
break;
|
break;
|
||||||
@ -341,6 +341,12 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AnimationLoopType parseAnimationLoopType(string value)
|
||||||
|
{
|
||||||
|
var parsed = (AnimationLoopType)Enum.Parse(typeof(AnimationLoopType), value);
|
||||||
|
return Enum.IsDefined(typeof(AnimationLoopType), parsed) ? parsed : AnimationLoopType.LoopForever;
|
||||||
|
}
|
||||||
|
|
||||||
private void handleVariables(string line)
|
private void handleVariables(string line)
|
||||||
{
|
{
|
||||||
var pair = SplitKeyVal(line, '=');
|
var pair = SplitKeyVal(line, '=');
|
||||||
|
@ -24,7 +24,7 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The control points in this beatmap.
|
/// The control points in this beatmap.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ControlPointInfo ControlPointInfo { get; }
|
ControlPointInfo ControlPointInfo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The breaks in this beatmap.
|
/// The breaks in this beatmap.
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
@ -1,36 +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.
|
|
||||||
|
|
||||||
#nullable enable
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using osu.Framework.Extensions.ExceptionExtensions;
|
|
||||||
using osu.Framework.Logging;
|
|
||||||
|
|
||||||
namespace osu.Game.Extensions
|
|
||||||
{
|
|
||||||
public static class TaskExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Denote a task which is to be run without local error handling logic, where failure is not catastrophic.
|
|
||||||
/// Avoids unobserved exceptions from being fired.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="task">The task.</param>
|
|
||||||
/// <param name="logAsError">
|
|
||||||
/// Whether errors should be logged as errors visible to users, or as debug messages.
|
|
||||||
/// Logging as debug will essentially silence the errors on non-release builds.
|
|
||||||
/// </param>
|
|
||||||
public static void CatchUnobservedExceptions(this Task task, bool logAsError = false)
|
|
||||||
{
|
|
||||||
task.ContinueWith(t =>
|
|
||||||
{
|
|
||||||
Exception? exception = t.Exception?.AsSingular();
|
|
||||||
if (logAsError)
|
|
||||||
Logger.Error(exception, $"Error running task: {exception?.Message ?? "(unknown)"}", LoggingTarget.Runtime, true);
|
|
||||||
else
|
|
||||||
Logger.Log($"Error running task: {exception}", LoggingTarget.Runtime, LogLevel.Debug);
|
|
||||||
}, TaskContinuationOptions.NotOnRanToCompletion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,6 +24,10 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
private Bindable<bool> parallaxEnabled;
|
private Bindable<bool> parallaxEnabled;
|
||||||
|
|
||||||
|
private const float parallax_duration = 100;
|
||||||
|
|
||||||
|
private bool firstUpdate = true;
|
||||||
|
|
||||||
public ParallaxContainer()
|
public ParallaxContainer()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
@ -60,17 +64,27 @@ namespace osu.Game.Graphics.Containers
|
|||||||
input = GetContainingInputManager();
|
input = GetContainingInputManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool firstUpdate = true;
|
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
if (parallaxEnabled.Value)
|
if (parallaxEnabled.Value)
|
||||||
{
|
{
|
||||||
Vector2 offset = (input.CurrentState.Mouse == null ? Vector2.Zero : ToLocalSpace(input.CurrentState.Mouse.Position) - DrawSize / 2) * ParallaxAmount;
|
Vector2 offset = Vector2.Zero;
|
||||||
|
|
||||||
const float parallax_duration = 100;
|
if (input.CurrentState.Mouse != null)
|
||||||
|
{
|
||||||
|
var sizeDiv2 = DrawSize / 2;
|
||||||
|
|
||||||
|
Vector2 relativeAmount = ToLocalSpace(input.CurrentState.Mouse.Position) - sizeDiv2;
|
||||||
|
|
||||||
|
const float base_factor = 0.999f;
|
||||||
|
|
||||||
|
relativeAmount.X = (float)(Math.Sign(relativeAmount.X) * Interpolation.Damp(0, 1, base_factor, Math.Abs(relativeAmount.X)));
|
||||||
|
relativeAmount.Y = (float)(Math.Sign(relativeAmount.Y) * Interpolation.Damp(0, 1, base_factor, Math.Abs(relativeAmount.Y)));
|
||||||
|
|
||||||
|
offset = relativeAmount * sizeDiv2 * ParallaxAmount;
|
||||||
|
}
|
||||||
|
|
||||||
double elapsed = Math.Clamp(Clock.ElapsedFrameTime, 0, parallax_duration);
|
double elapsed = Math.Clamp(Clock.ElapsedFrameTime, 0, parallax_duration);
|
||||||
|
|
||||||
|
@ -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.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -9,6 +10,7 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Layout;
|
using osu.Framework.Layout;
|
||||||
|
using osu.Framework.Utils;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Containers
|
namespace osu.Game.Graphics.Containers
|
||||||
{
|
{
|
||||||
@ -20,6 +22,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
where T : Drawable
|
where T : Drawable
|
||||||
{
|
{
|
||||||
public Bindable<T> SelectedSection { get; } = new Bindable<T>();
|
public Bindable<T> SelectedSection { get; } = new Bindable<T>();
|
||||||
|
private Drawable lastClickedSection;
|
||||||
|
|
||||||
public Drawable ExpandableHeader
|
public Drawable ExpandableHeader
|
||||||
{
|
{
|
||||||
@ -36,7 +39,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
if (value == null) return;
|
if (value == null) return;
|
||||||
|
|
||||||
AddInternal(expandableHeader);
|
AddInternal(expandableHeader);
|
||||||
lastKnownScroll = float.NaN;
|
lastKnownScroll = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +55,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
if (value == null) return;
|
if (value == null) return;
|
||||||
|
|
||||||
AddInternal(fixedHeader);
|
AddInternal(fixedHeader);
|
||||||
lastKnownScroll = float.NaN;
|
lastKnownScroll = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +74,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
footer.Anchor |= Anchor.y2;
|
footer.Anchor |= Anchor.y2;
|
||||||
footer.Origin |= Anchor.y2;
|
footer.Origin |= Anchor.y2;
|
||||||
scrollContainer.Add(footer);
|
scrollContainer.Add(footer);
|
||||||
lastKnownScroll = float.NaN;
|
lastKnownScroll = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,21 +92,26 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
headerBackgroundContainer.Add(headerBackground);
|
headerBackgroundContainer.Add(headerBackground);
|
||||||
|
|
||||||
lastKnownScroll = float.NaN;
|
lastKnownScroll = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Container<T> Content => scrollContentContainer;
|
protected override Container<T> Content => scrollContentContainer;
|
||||||
|
|
||||||
private readonly OsuScrollContainer scrollContainer;
|
private readonly UserTrackingScrollContainer scrollContainer;
|
||||||
private readonly Container headerBackgroundContainer;
|
private readonly Container headerBackgroundContainer;
|
||||||
private readonly MarginPadding originalSectionsMargin;
|
private readonly MarginPadding originalSectionsMargin;
|
||||||
private Drawable expandableHeader, fixedHeader, footer, headerBackground;
|
private Drawable expandableHeader, fixedHeader, footer, headerBackground;
|
||||||
private FlowContainer<T> scrollContentContainer;
|
private FlowContainer<T> scrollContentContainer;
|
||||||
|
|
||||||
private float headerHeight, footerHeight;
|
private float? headerHeight, footerHeight;
|
||||||
|
|
||||||
private float lastKnownScroll;
|
private float? lastKnownScroll;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The percentage of the container to consider the centre-point for deciding the active section (and scrolling to a requested section).
|
||||||
|
/// </summary>
|
||||||
|
private const float scroll_y_centre = 0.1f;
|
||||||
|
|
||||||
public SectionsContainer()
|
public SectionsContainer()
|
||||||
{
|
{
|
||||||
@ -128,18 +136,24 @@ namespace osu.Game.Graphics.Containers
|
|||||||
public override void Add(T drawable)
|
public override void Add(T drawable)
|
||||||
{
|
{
|
||||||
base.Add(drawable);
|
base.Add(drawable);
|
||||||
lastKnownScroll = float.NaN;
|
|
||||||
headerHeight = float.NaN;
|
Debug.Assert(drawable != null);
|
||||||
footerHeight = float.NaN;
|
|
||||||
|
lastKnownScroll = null;
|
||||||
|
headerHeight = null;
|
||||||
|
footerHeight = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ScrollTo(Drawable section) =>
|
public void ScrollTo(Drawable section)
|
||||||
scrollContainer.ScrollTo(scrollContainer.GetChildPosInContent(section) - (FixedHeader?.BoundingBox.Height ?? 0));
|
{
|
||||||
|
lastClickedSection = section;
|
||||||
|
scrollContainer.ScrollTo(scrollContainer.GetChildPosInContent(section) - scrollContainer.DisplayableContent * scroll_y_centre - (FixedHeader?.BoundingBox.Height ?? 0));
|
||||||
|
}
|
||||||
|
|
||||||
public void ScrollToTop() => scrollContainer.ScrollTo(0);
|
public void ScrollToTop() => scrollContainer.ScrollTo(0);
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
protected virtual OsuScrollContainer CreateScrollContainer() => new OsuScrollContainer();
|
protected virtual UserTrackingScrollContainer CreateScrollContainer() => new UserTrackingScrollContainer();
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
protected virtual FlowContainer<T> CreateScrollContentContainer() =>
|
protected virtual FlowContainer<T> CreateScrollContentContainer() =>
|
||||||
@ -156,7 +170,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
if (source == InvalidationSource.Child && (invalidation & Invalidation.DrawSize) != 0)
|
if (source == InvalidationSource.Child && (invalidation & Invalidation.DrawSize) != 0)
|
||||||
{
|
{
|
||||||
lastKnownScroll = -1;
|
lastKnownScroll = null;
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +181,10 @@ namespace osu.Game.Graphics.Containers
|
|||||||
{
|
{
|
||||||
base.UpdateAfterChildren();
|
base.UpdateAfterChildren();
|
||||||
|
|
||||||
float headerH = (ExpandableHeader?.LayoutSize.Y ?? 0) + (FixedHeader?.LayoutSize.Y ?? 0);
|
float fixedHeaderSize = FixedHeader?.LayoutSize.Y ?? 0;
|
||||||
|
float expandableHeaderSize = ExpandableHeader?.LayoutSize.Y ?? 0;
|
||||||
|
|
||||||
|
float headerH = expandableHeaderSize + fixedHeaderSize;
|
||||||
float footerH = Footer?.LayoutSize.Y ?? 0;
|
float footerH = Footer?.LayoutSize.Y ?? 0;
|
||||||
|
|
||||||
if (headerH != headerHeight || footerH != footerHeight)
|
if (headerH != headerHeight || footerH != footerHeight)
|
||||||
@ -183,28 +200,39 @@ namespace osu.Game.Graphics.Containers
|
|||||||
{
|
{
|
||||||
lastKnownScroll = currentScroll;
|
lastKnownScroll = currentScroll;
|
||||||
|
|
||||||
|
// reset last clicked section because user started scrolling themselves
|
||||||
|
if (scrollContainer.UserScrolling)
|
||||||
|
lastClickedSection = null;
|
||||||
|
|
||||||
if (ExpandableHeader != null && FixedHeader != null)
|
if (ExpandableHeader != null && FixedHeader != null)
|
||||||
{
|
{
|
||||||
float offset = Math.Min(ExpandableHeader.LayoutSize.Y, currentScroll);
|
float offset = Math.Min(expandableHeaderSize, currentScroll);
|
||||||
|
|
||||||
ExpandableHeader.Y = -offset;
|
ExpandableHeader.Y = -offset;
|
||||||
FixedHeader.Y = -offset + ExpandableHeader.LayoutSize.Y;
|
FixedHeader.Y = -offset + expandableHeaderSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
headerBackgroundContainer.Height = (ExpandableHeader?.LayoutSize.Y ?? 0) + (FixedHeader?.LayoutSize.Y ?? 0);
|
headerBackgroundContainer.Height = expandableHeaderSize + fixedHeaderSize;
|
||||||
headerBackgroundContainer.Y = ExpandableHeader?.Y ?? 0;
|
headerBackgroundContainer.Y = ExpandableHeader?.Y ?? 0;
|
||||||
|
|
||||||
float scrollOffset = FixedHeader?.LayoutSize.Y ?? 0;
|
var smallestSectionHeight = Children.Count > 0 ? Children.Min(d => d.Height) : 0;
|
||||||
Func<T, float> diff = section => scrollContainer.GetChildPosInContent(section) - currentScroll - scrollOffset;
|
|
||||||
|
|
||||||
if (scrollContainer.IsScrolledToEnd())
|
// scroll offset is our fixed header height if we have it plus 10% of content height
|
||||||
{
|
// plus 5% to fix floating point errors and to not have a section instantly unselect when scrolling upwards
|
||||||
SelectedSection.Value = Children.LastOrDefault();
|
// but the 5% can't be bigger than our smallest section height, otherwise it won't get selected correctly
|
||||||
}
|
float selectionLenienceAboveSection = Math.Min(smallestSectionHeight / 2.0f, scrollContainer.DisplayableContent * 0.05f);
|
||||||
|
|
||||||
|
float scrollCentre = fixedHeaderSize + scrollContainer.DisplayableContent * scroll_y_centre + selectionLenienceAboveSection;
|
||||||
|
|
||||||
|
if (Precision.AlmostBigger(0, scrollContainer.Current))
|
||||||
|
SelectedSection.Value = lastClickedSection as T ?? Children.FirstOrDefault();
|
||||||
|
else if (Precision.AlmostBigger(scrollContainer.Current, scrollContainer.ScrollableExtent))
|
||||||
|
SelectedSection.Value = lastClickedSection as T ?? Children.LastOrDefault();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SelectedSection.Value = Children.TakeWhile(section => diff(section) <= 0).LastOrDefault()
|
SelectedSection.Value = Children
|
||||||
?? Children.FirstOrDefault();
|
.TakeWhile(section => scrollContainer.GetChildPosInContent(section) - currentScroll - scrollCentre <= 0)
|
||||||
|
.LastOrDefault() ?? Children.FirstOrDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,8 +242,9 @@ namespace osu.Game.Graphics.Containers
|
|||||||
if (!Children.Any()) return;
|
if (!Children.Any()) return;
|
||||||
|
|
||||||
var newMargin = originalSectionsMargin;
|
var newMargin = originalSectionsMargin;
|
||||||
newMargin.Top += headerHeight;
|
|
||||||
newMargin.Bottom += footerHeight;
|
newMargin.Top += (headerHeight ?? 0);
|
||||||
|
newMargin.Bottom += (footerHeight ?? 0);
|
||||||
|
|
||||||
scrollContentContainer.Margin = newMargin;
|
scrollContentContainer.Margin = newMargin;
|
||||||
}
|
}
|
||||||
|
57
osu.Game/Graphics/Containers/UserTrackingScrollContainer.cs
Normal file
57
osu.Game/Graphics/Containers/UserTrackingScrollContainer.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// 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;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.Containers
|
||||||
|
{
|
||||||
|
public class UserTrackingScrollContainer : UserTrackingScrollContainer<Drawable>
|
||||||
|
{
|
||||||
|
public UserTrackingScrollContainer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserTrackingScrollContainer(Direction direction)
|
||||||
|
: base(direction)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UserTrackingScrollContainer<T> : OsuScrollContainer<T>
|
||||||
|
where T : Drawable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the last scroll event was user triggered, directly on the scroll container.
|
||||||
|
/// </summary>
|
||||||
|
public bool UserScrolling { get; private set; }
|
||||||
|
|
||||||
|
public void CancelUserScroll() => UserScrolling = false;
|
||||||
|
|
||||||
|
public UserTrackingScrollContainer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserTrackingScrollContainer(Direction direction)
|
||||||
|
: base(direction)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnUserScroll(float value, bool animated = true, double? distanceDecay = default)
|
||||||
|
{
|
||||||
|
UserScrolling = true;
|
||||||
|
base.OnUserScroll(value, animated, distanceDecay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public new void ScrollTo(float value, bool animated = true, double? distanceDecay = null)
|
||||||
|
{
|
||||||
|
UserScrolling = false;
|
||||||
|
base.ScrollTo(value, animated, distanceDecay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public new void ScrollToEnd(bool animated = true, bool allowDuringDrag = false)
|
||||||
|
{
|
||||||
|
UserScrolling = false;
|
||||||
|
base.ScrollToEnd(animated, allowDuringDrag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
}
|
}
|
||||||
|
48
osu.Game/Graphics/UserInterface/GrayButton.cs
Normal file
48
osu.Game/Graphics/UserInterface/GrayButton.cs
Normal 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,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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]
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
|
using MessagePack;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
@ -13,16 +14,21 @@ using osu.Game.Rulesets.Mods;
|
|||||||
|
|
||||||
namespace osu.Game.Online.API
|
namespace osu.Game.Online.API
|
||||||
{
|
{
|
||||||
|
[MessagePackObject]
|
||||||
public class APIMod : IMod
|
public class APIMod : IMod
|
||||||
{
|
{
|
||||||
[JsonProperty("acronym")]
|
[JsonProperty("acronym")]
|
||||||
|
[Key(0)]
|
||||||
public string Acronym { get; set; }
|
public string Acronym { get; set; }
|
||||||
|
|
||||||
[JsonProperty("settings")]
|
[JsonProperty("settings")]
|
||||||
|
[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]
|
||||||
private APIMod()
|
[SerializationConstructor]
|
||||||
|
public APIMod()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
67
osu.Game/Online/API/ModSettingsDictionaryFormatter.cs
Normal file
67
osu.Game/Online/API/ModSettingsDictionaryFormatter.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Buffers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using MessagePack;
|
||||||
|
using MessagePack.Formatters;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API
|
||||||
|
{
|
||||||
|
public class ModSettingsDictionaryFormatter : IMessagePackFormatter<Dictionary<string, object>>
|
||||||
|
{
|
||||||
|
public void Serialize(ref MessagePackWriter writer, Dictionary<string, object> value, MessagePackSerializerOptions options)
|
||||||
|
{
|
||||||
|
var primitiveFormatter = PrimitiveObjectFormatter.Instance;
|
||||||
|
|
||||||
|
writer.WriteArrayHeader(value.Count);
|
||||||
|
|
||||||
|
foreach (var kvp in value)
|
||||||
|
{
|
||||||
|
var stringBytes = new ReadOnlySequence<byte>(Encoding.UTF8.GetBytes(kvp.Key));
|
||||||
|
writer.WriteString(in stringBytes);
|
||||||
|
|
||||||
|
switch (kvp.Value)
|
||||||
|
{
|
||||||
|
case Bindable<double> d:
|
||||||
|
primitiveFormatter.Serialize(ref writer, d.Value, options);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Bindable<int> i:
|
||||||
|
primitiveFormatter.Serialize(ref writer, i.Value, options);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Bindable<float> f:
|
||||||
|
primitiveFormatter.Serialize(ref writer, f.Value, options);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Bindable<bool> b:
|
||||||
|
primitiveFormatter.Serialize(ref writer, b.Value, options);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// fall back for non-bindable cases.
|
||||||
|
primitiveFormatter.Serialize(ref writer, kvp.Value, options);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dictionary<string, object> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||||
|
{
|
||||||
|
var output = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
int itemCount = reader.ReadArrayHeader();
|
||||||
|
|
||||||
|
for (int i = 0; i < itemCount; i++)
|
||||||
|
{
|
||||||
|
output[reader.ReadString()] =
|
||||||
|
PrimitiveObjectFormatter.Instance.Deserialize(ref reader, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -81,7 +81,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
[JsonProperty(@"beatmaps")]
|
[JsonProperty(@"beatmaps")]
|
||||||
private IEnumerable<APIBeatmap> beatmaps { get; set; }
|
private IEnumerable<APIBeatmap> beatmaps { get; set; }
|
||||||
|
|
||||||
public BeatmapSetInfo ToBeatmapSet(RulesetStore rulesets)
|
public virtual BeatmapSetInfo ToBeatmapSet(RulesetStore rulesets)
|
||||||
{
|
{
|
||||||
var beatmapSet = new BeatmapSetInfo
|
var beatmapSet = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
|
@ -339,7 +339,7 @@ namespace osu.Game.Online.Chat
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Joins a channel if it has not already been joined.
|
/// Joins a channel if it has not already been joined. Must be called from the update thread.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="channel">The channel to join.</param>
|
/// <param name="channel">The channel to join.</param>
|
||||||
/// <returns>The joined channel. Note that this may not match the parameter channel as it is a backed object.</returns>
|
/// <returns>The joined channel. Note that this may not match the parameter channel as it is a backed object.</returns>
|
||||||
@ -399,7 +399,11 @@ namespace osu.Game.Online.Chat
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LeaveChannel(Channel channel)
|
/// <summary>
|
||||||
|
/// Leave the specified channel. Can be called from any thread.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="channel">The channel to leave.</param>
|
||||||
|
public void LeaveChannel(Channel channel) => Schedule(() =>
|
||||||
{
|
{
|
||||||
if (channel == null) return;
|
if (channel == null) return;
|
||||||
|
|
||||||
@ -413,7 +417,7 @@ namespace osu.Game.Online.Chat
|
|||||||
api.Queue(new LeaveChannelRequest(channel));
|
api.Queue(new LeaveChannelRequest(channel));
|
||||||
channel.Joined.Value = false;
|
channel.Joined.Value = false;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
private long lastMessageId;
|
private long lastMessageId;
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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>
|
||||||
|
@ -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>
|
||||||
|
@ -4,12 +4,14 @@
|
|||||||
#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;
|
||||||
using Microsoft.AspNetCore.SignalR.Client;
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using osu.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
@ -65,13 +67,19 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
if (connection != null)
|
if (connection != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
connection = new HubConnectionBuilder()
|
var builder = new HubConnectionBuilder()
|
||||||
.WithUrl(endpoint, options =>
|
.WithUrl(endpoint, options => { options.Headers.Add("Authorization", $"Bearer {api.AccessToken}"); });
|
||||||
{
|
|
||||||
options.Headers.Add("Authorization", $"Bearer {api.AccessToken}");
|
if (RuntimeInfo.SupportsJIT)
|
||||||
})
|
builder.AddMessagePackProtocol();
|
||||||
.AddNewtonsoftJsonProtocol(options => { options.PayloadSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; })
|
else
|
||||||
.Build();
|
{
|
||||||
|
// eventually we will precompile resolvers for messagepack, but this isn't working currently
|
||||||
|
// see https://github.com/neuecc/MessagePack-CSharp/issues/780#issuecomment-768794308.
|
||||||
|
builder.AddNewtonsoftJsonProtocol(options => { options.PayloadSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; });
|
||||||
|
}
|
||||||
|
|
||||||
|
connection = builder.Build();
|
||||||
|
|
||||||
// this is kind of SILLY
|
// this is kind of SILLY
|
||||||
// https://github.com/dotnet/aspnetcore/issues/15198
|
// https://github.com/dotnet/aspnetcore/issues/15198
|
||||||
@ -84,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 =>
|
||||||
{
|
{
|
||||||
@ -182,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)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using MessagePack;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace osu.Game.Online.Multiplayer
|
namespace osu.Game.Online.Multiplayer
|
||||||
@ -13,35 +14,42 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
/// A multiplayer room.
|
/// A multiplayer room.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
[MessagePackObject]
|
||||||
public class MultiplayerRoom
|
public class MultiplayerRoom
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ID of the room, used for database persistence.
|
/// The ID of the room, used for database persistence.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(0)]
|
||||||
public readonly long RoomID;
|
public readonly long RoomID;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current state of the room (ie. whether it is in progress or otherwise).
|
/// The current state of the room (ie. whether it is in progress or otherwise).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(1)]
|
||||||
public MultiplayerRoomState State { get; set; }
|
public MultiplayerRoomState State { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All currently enforced game settings for this room.
|
/// All currently enforced game settings for this room.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(2)]
|
||||||
public MultiplayerRoomSettings Settings { get; set; } = new MultiplayerRoomSettings();
|
public MultiplayerRoomSettings Settings { get; set; } = new MultiplayerRoomSettings();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All users currently in this room.
|
/// All users currently in this room.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(3)]
|
||||||
public List<MultiplayerRoomUser> Users { get; set; } = new List<MultiplayerRoomUser>();
|
public List<MultiplayerRoomUser> Users { get; set; } = new List<MultiplayerRoomUser>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The host of this room, in control of changing room settings.
|
/// The host of this room, in control of changing room settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(4)]
|
||||||
public MultiplayerRoomUser? Host { get; set; }
|
public MultiplayerRoomUser? Host { get; set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public MultiplayerRoom(in long roomId)
|
[SerializationConstructor]
|
||||||
|
public MultiplayerRoom(long roomId)
|
||||||
{
|
{
|
||||||
RoomID = roomId;
|
RoomID = roomId;
|
||||||
}
|
}
|
||||||
|
@ -7,31 +7,47 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using MessagePack;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
|
|
||||||
namespace osu.Game.Online.Multiplayer
|
namespace osu.Game.Online.Multiplayer
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
[MessagePackObject]
|
||||||
public class MultiplayerRoomSettings : IEquatable<MultiplayerRoomSettings>
|
public class MultiplayerRoomSettings : IEquatable<MultiplayerRoomSettings>
|
||||||
{
|
{
|
||||||
|
[Key(0)]
|
||||||
public int BeatmapID { get; set; }
|
public int BeatmapID { get; set; }
|
||||||
|
|
||||||
|
[Key(1)]
|
||||||
public int RulesetID { get; set; }
|
public int RulesetID { get; set; }
|
||||||
|
|
||||||
|
[Key(2)]
|
||||||
public string BeatmapChecksum { get; set; } = string.Empty;
|
public string BeatmapChecksum { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Key(3)]
|
||||||
public string Name { get; set; } = "Unnamed room";
|
public string Name { get; set; } = "Unnamed room";
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
|
[Key(4)]
|
||||||
|
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}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,28 +4,45 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
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;
|
||||||
|
|
||||||
namespace osu.Game.Online.Multiplayer
|
namespace osu.Game.Online.Multiplayer
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
[MessagePackObject]
|
||||||
public class MultiplayerRoomUser : IEquatable<MultiplayerRoomUser>
|
public class MultiplayerRoomUser : IEquatable<MultiplayerRoomUser>
|
||||||
{
|
{
|
||||||
|
[Key(0)]
|
||||||
public readonly int UserID;
|
public readonly int UserID;
|
||||||
|
|
||||||
|
[Key(1)]
|
||||||
public MultiplayerUserState State { get; set; } = MultiplayerUserState.Idle;
|
public MultiplayerUserState State { get; set; } = MultiplayerUserState.Idle;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The availability state of the current beatmap.
|
/// The availability state of the current beatmap.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[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]
|
||||||
public User? User { get; set; }
|
public User? User { get; set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public MultiplayerRoomUser(in int userId)
|
public MultiplayerRoomUser(int userId)
|
||||||
{
|
{
|
||||||
UserID = userId;
|
UserID = userId;
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,13 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Extensions;
|
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
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;
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
if (!connected.NewValue && Room != null)
|
if (!connected.NewValue && Room != null)
|
||||||
{
|
{
|
||||||
Logger.Log("Connection to multiplayer server was lost.", LoggingTarget.Runtime, LogLevel.Important);
|
Logger.Log("Connection to multiplayer server was lost.", LoggingTarget.Runtime, LogLevel.Important);
|
||||||
LeaveRoom().CatchUnobservedExceptions();
|
LeaveRoom();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -192,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
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,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)
|
||||||
@ -378,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)
|
||||||
@ -501,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
|
||||||
{
|
{
|
||||||
@ -511,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);
|
||||||
|
@ -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 MessagePack;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace osu.Game.Online.Rooms
|
namespace osu.Game.Online.Rooms
|
||||||
@ -9,27 +10,30 @@ namespace osu.Game.Online.Rooms
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The local availability information about a certain beatmap for the client.
|
/// The local availability information about a certain beatmap for the client.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[MessagePackObject]
|
||||||
public class BeatmapAvailability : IEquatable<BeatmapAvailability>
|
public class BeatmapAvailability : IEquatable<BeatmapAvailability>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The beatmap's availability state.
|
/// The beatmap's availability state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(0)]
|
||||||
public readonly DownloadState State;
|
public readonly DownloadState State;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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>
|
||||||
public readonly double? DownloadProgress;
|
[Key(1)]
|
||||||
|
public readonly float? DownloadProgress;
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
private 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);
|
||||||
|
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using MessagePack;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Game.Replays.Legacy;
|
using osu.Game.Replays.Legacy;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
@ -12,10 +13,13 @@ using osu.Game.Scoring;
|
|||||||
namespace osu.Game.Online.Spectator
|
namespace osu.Game.Online.Spectator
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
[MessagePackObject]
|
||||||
public class FrameDataBundle
|
public class FrameDataBundle
|
||||||
{
|
{
|
||||||
|
[Key(0)]
|
||||||
public FrameHeader Header { get; set; }
|
public FrameHeader Header { get; set; }
|
||||||
|
|
||||||
|
[Key(1)]
|
||||||
public IEnumerable<LegacyReplayFrame> Frames { get; set; }
|
public IEnumerable<LegacyReplayFrame> Frames { get; set; }
|
||||||
|
|
||||||
public FrameDataBundle(ScoreInfo score, IEnumerable<LegacyReplayFrame> frames)
|
public FrameDataBundle(ScoreInfo score, IEnumerable<LegacyReplayFrame> frames)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using MessagePack;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
@ -12,31 +13,37 @@ using osu.Game.Scoring;
|
|||||||
namespace osu.Game.Online.Spectator
|
namespace osu.Game.Online.Spectator
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
[MessagePackObject]
|
||||||
public class FrameHeader
|
public class FrameHeader
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current accuracy of the score.
|
/// The current accuracy of the score.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(0)]
|
||||||
public double Accuracy { get; set; }
|
public double Accuracy { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current combo of the score.
|
/// The current combo of the score.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(1)]
|
||||||
public int Combo { get; set; }
|
public int Combo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum combo achieved up to the current point in time.
|
/// The maximum combo achieved up to the current point in time.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(2)]
|
||||||
public int MaxCombo { get; set; }
|
public int MaxCombo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cumulative hit statistics.
|
/// Cumulative hit statistics.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(3)]
|
||||||
public Dictionary<HitResult, int> Statistics { get; set; }
|
public Dictionary<HitResult, int> Statistics { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The time at which this frame was received by the server.
|
/// The time at which this frame was received by the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Key(4)]
|
||||||
public DateTimeOffset ReceivedTime { get; set; }
|
public DateTimeOffset ReceivedTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -54,7 +61,8 @@ namespace osu.Game.Online.Spectator
|
|||||||
}
|
}
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public FrameHeader(int combo, int maxCombo, double accuracy, Dictionary<HitResult, int> statistics, DateTimeOffset receivedTime)
|
[SerializationConstructor]
|
||||||
|
public FrameHeader(double accuracy, int combo, int maxCombo, Dictionary<HitResult, int> statistics, DateTimeOffset receivedTime)
|
||||||
{
|
{
|
||||||
Combo = combo;
|
Combo = combo;
|
||||||
MaxCombo = maxCombo;
|
MaxCombo = maxCombo;
|
||||||
|
@ -5,18 +5,23 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using MessagePack;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
|
|
||||||
namespace osu.Game.Online.Spectator
|
namespace osu.Game.Online.Spectator
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
[MessagePackObject]
|
||||||
public class SpectatorState : IEquatable<SpectatorState>
|
public class SpectatorState : IEquatable<SpectatorState>
|
||||||
{
|
{
|
||||||
|
[Key(0)]
|
||||||
public int? BeatmapID { get; set; }
|
public int? BeatmapID { get; set; }
|
||||||
|
|
||||||
|
[Key(1)]
|
||||||
public int? RulesetID { get; set; }
|
public int? RulesetID { get; set; }
|
||||||
|
|
||||||
[NotNull]
|
[NotNull]
|
||||||
|
[Key(2)]
|
||||||
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
|
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
|
||||||
|
|
||||||
public bool Equals(SpectatorState other) => BeatmapID == other?.BeatmapID && Mods.SequenceEqual(other?.Mods) && RulesetID == other?.RulesetID;
|
public bool Equals(SpectatorState other) => BeatmapID == other?.BeatmapID && Mods.SequenceEqual(other?.Mods) && RulesetID == other?.RulesetID;
|
||||||
|
@ -10,6 +10,7 @@ using JetBrains.Annotations;
|
|||||||
using Microsoft.AspNetCore.SignalR.Client;
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using osu.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;
|
||||||
@ -116,14 +117,19 @@ namespace osu.Game.Online.Spectator
|
|||||||
if (connection != null)
|
if (connection != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
connection = new HubConnectionBuilder()
|
var builder = new HubConnectionBuilder()
|
||||||
.WithUrl(endpoint, options =>
|
.WithUrl(endpoint, options => { options.Headers.Add("Authorization", $"Bearer {api.AccessToken}"); });
|
||||||
{
|
|
||||||
options.Headers.Add("Authorization", $"Bearer {api.AccessToken}");
|
|
||||||
})
|
|
||||||
.AddNewtonsoftJsonProtocol(options => { options.PayloadSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; })
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
|
if (RuntimeInfo.SupportsJIT)
|
||||||
|
builder.AddMessagePackProtocol();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// eventually we will precompile resolvers for messagepack, but this isn't working currently
|
||||||
|
// see https://github.com/neuecc/MessagePack-CSharp/issues/780#issuecomment-768794308.
|
||||||
|
builder.AddNewtonsoftJsonProtocol(options => { options.PayloadSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; });
|
||||||
|
}
|
||||||
|
|
||||||
|
connection = builder.Build();
|
||||||
// until strong typed client support is added, each method must be manually bound (see https://github.com/dotnet/aspnetcore/issues/15198)
|
// until strong typed client support is added, each method must be manually bound (see https://github.com/dotnet/aspnetcore/issues/15198)
|
||||||
connection.On<int, SpectatorState>(nameof(ISpectatorClient.UserBeganPlaying), ((ISpectatorClient)this).UserBeganPlaying);
|
connection.On<int, SpectatorState>(nameof(ISpectatorClient.UserBeganPlaying), ((ISpectatorClient)this).UserBeganPlaying);
|
||||||
connection.On<int, FrameDataBundle>(nameof(ISpectatorClient.UserSentFrames), ((ISpectatorClient)this).UserSentFrames);
|
connection.On<int, FrameDataBundle>(nameof(ISpectatorClient.UserSentFrames), ((ISpectatorClient)this).UserSentFrames);
|
||||||
|
@ -468,6 +468,16 @@ namespace osu.Game
|
|||||||
private void modsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
private void modsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
||||||
{
|
{
|
||||||
updateModDefaults();
|
updateModDefaults();
|
||||||
|
|
||||||
|
// a lease may be taken on the mods bindable, at which point we can't really ensure valid mods.
|
||||||
|
if (SelectedMods.Disabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!ModUtils.CheckValidForGameplay(mods.NewValue, out var invalid))
|
||||||
|
{
|
||||||
|
// ensure we always have a valid set of mods.
|
||||||
|
SelectedMods.Value = mods.NewValue.Except(invalid).ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateModDefaults()
|
private void updateModDefaults()
|
||||||
|
@ -12,7 +12,7 @@ using osu.Game.Graphics.Sprites;
|
|||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
using osu.Game.Utils;
|
using osu.Framework.Extensions.EnumExtensions;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapListing
|
namespace osu.Game.Overlays.BeatmapListing
|
||||||
{
|
{
|
||||||
@ -80,7 +80,7 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
|
|
||||||
if (typeof(T).IsEnum)
|
if (typeof(T).IsEnum)
|
||||||
{
|
{
|
||||||
foreach (var val in OrderAttributeUtils.GetValuesInOrder<T>())
|
foreach (var val in EnumExtensions.GetValuesInOrder<T>())
|
||||||
AddItem(val);
|
AddItem(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +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 osu.Game.Utils;
|
using osu.Framework.Utils;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapListing
|
namespace osu.Game.Overlays.BeatmapListing
|
||||||
{
|
{
|
||||||
|
@ -176,23 +176,34 @@ namespace osu.Game.Overlays
|
|||||||
loadingLayer.Hide();
|
loadingLayer.Hide();
|
||||||
lastFetchDisplayedTime = Time.Current;
|
lastFetchDisplayedTime = Time.Current;
|
||||||
|
|
||||||
|
if (content == currentContent)
|
||||||
|
return;
|
||||||
|
|
||||||
var lastContent = currentContent;
|
var lastContent = currentContent;
|
||||||
|
|
||||||
if (lastContent != null)
|
if (lastContent != null)
|
||||||
{
|
{
|
||||||
lastContent.FadeOut(100, Easing.OutQuint).Expire();
|
var transform = lastContent.FadeOut(100, Easing.OutQuint);
|
||||||
|
|
||||||
// Consider the case when the new content is smaller than the last content.
|
if (lastContent == notFoundContent)
|
||||||
// If the auto-size computation is delayed until fade out completes, the background remain high for too long making the resulting transition to the smaller height look weird.
|
{
|
||||||
// At the same time, if the last content's height is bypassed immediately, there is a period where the new content is at Alpha = 0 when the auto-sized height will be 0.
|
// not found display may be used multiple times, so don't expire/dispose it.
|
||||||
// To resolve both of these issues, the bypass is delayed until a point when the content transitions (fade-in and fade-out) overlap and it looks good to do so.
|
transform.Schedule(() => panelTarget.Remove(lastContent));
|
||||||
lastContent.Delay(25).Schedule(() => lastContent.BypassAutoSizeAxes = Axes.Y).Then().Schedule(() => panelTarget.Remove(lastContent));
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Consider the case when the new content is smaller than the last content.
|
||||||
|
// If the auto-size computation is delayed until fade out completes, the background remain high for too long making the resulting transition to the smaller height look weird.
|
||||||
|
// At the same time, if the last content's height is bypassed immediately, there is a period where the new content is at Alpha = 0 when the auto-sized height will be 0.
|
||||||
|
// To resolve both of these issues, the bypass is delayed until a point when the content transitions (fade-in and fade-out) overlap and it looks good to do so.
|
||||||
|
lastContent.Delay(25).Schedule(() => lastContent.BypassAutoSizeAxes = Axes.Y).Then().Schedule(() => lastContent.Expire());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!content.IsAlive)
|
if (!content.IsAlive)
|
||||||
panelTarget.Add(content);
|
panelTarget.Add(content);
|
||||||
content.FadeIn(200, Easing.OutQuint);
|
|
||||||
|
|
||||||
|
content.FadeInFromZero(200, Easing.OutQuint);
|
||||||
currentContent = content;
|
currentContent = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +213,7 @@ namespace osu.Game.Overlays
|
|||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NotFoundDrawable : CompositeDrawable
|
public class NotFoundDrawable : CompositeDrawable
|
||||||
{
|
{
|
||||||
public NotFoundDrawable()
|
public NotFoundDrawable()
|
||||||
{
|
{
|
||||||
|
@ -1,25 +1,55 @@
|
|||||||
// 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 osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Effects;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapSet
|
namespace osu.Game.Overlays.BeatmapSet
|
||||||
{
|
{
|
||||||
public class BeatmapSetHeader : OverlayHeader
|
public class BeatmapSetHeader : OverlayHeader
|
||||||
{
|
{
|
||||||
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
|
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>();
|
||||||
|
|
||||||
|
public BeatmapSetHeaderContent HeaderContent { get; private set; }
|
||||||
|
|
||||||
|
[Cached]
|
||||||
public BeatmapRulesetSelector RulesetSelector { get; private set; }
|
public BeatmapRulesetSelector RulesetSelector { get; private set; }
|
||||||
|
|
||||||
protected override OverlayTitle CreateTitle() => new BeatmapHeaderTitle();
|
[Cached(typeof(IBindable<RulesetInfo>))]
|
||||||
|
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
||||||
|
|
||||||
|
public BeatmapSetHeader()
|
||||||
|
{
|
||||||
|
Masking = true;
|
||||||
|
|
||||||
|
EdgeEffect = new EdgeEffectParameters
|
||||||
|
{
|
||||||
|
Colour = Color4.Black.Opacity(0.25f),
|
||||||
|
Type = EdgeEffectType.Shadow,
|
||||||
|
Radius = 3,
|
||||||
|
Offset = new Vector2(0f, 1f),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Drawable CreateContent() => HeaderContent = new BeatmapSetHeaderContent
|
||||||
|
{
|
||||||
|
BeatmapSet = { BindTarget = BeatmapSet }
|
||||||
|
};
|
||||||
|
|
||||||
protected override Drawable CreateTitleContent() => RulesetSelector = new BeatmapRulesetSelector
|
protected override Drawable CreateTitleContent() => RulesetSelector = new BeatmapRulesetSelector
|
||||||
{
|
{
|
||||||
Current = Ruleset
|
Current = ruleset
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected override OverlayTitle CreateTitle() => new BeatmapHeaderTitle();
|
||||||
|
|
||||||
private class BeatmapHeaderTitle : OverlayTitle
|
private class BeatmapHeaderTitle : OverlayTitle
|
||||||
{
|
{
|
||||||
public BeatmapHeaderTitle()
|
public BeatmapHeaderTitle()
|
||||||
|
@ -3,12 +3,10 @@
|
|||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
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.Colour;
|
using osu.Framework.Graphics.Colour;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Effects;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Beatmaps.Drawables;
|
using osu.Game.Beatmaps.Drawables;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
@ -18,18 +16,21 @@ using osu.Game.Online;
|
|||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Overlays.BeatmapListing.Panels;
|
using osu.Game.Overlays.BeatmapListing.Panels;
|
||||||
using osu.Game.Overlays.BeatmapSet.Buttons;
|
using osu.Game.Overlays.BeatmapSet.Buttons;
|
||||||
using osu.Game.Rulesets;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapSet
|
namespace osu.Game.Overlays.BeatmapSet
|
||||||
{
|
{
|
||||||
public class Header : BeatmapDownloadTrackingComposite
|
public class BeatmapSetHeaderContent : BeatmapDownloadTrackingComposite
|
||||||
{
|
{
|
||||||
private const float transition_duration = 200;
|
private const float transition_duration = 200;
|
||||||
private const float buttons_height = 45;
|
private const float buttons_height = 45;
|
||||||
private const float buttons_spacing = 5;
|
private const float buttons_spacing = 5;
|
||||||
|
|
||||||
|
public bool DownloadButtonsVisible => downloadButtonsContainer.Any();
|
||||||
|
|
||||||
|
public readonly Details Details;
|
||||||
|
public readonly BeatmapPicker Picker;
|
||||||
|
|
||||||
private readonly UpdateableBeatmapSetCover cover;
|
private readonly UpdateableBeatmapSetCover cover;
|
||||||
private readonly Box coverGradient;
|
private readonly Box coverGradient;
|
||||||
private readonly OsuSpriteText title, artist;
|
private readonly OsuSpriteText title, artist;
|
||||||
@ -38,185 +39,154 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
private readonly FillFlowContainer downloadButtonsContainer;
|
private readonly FillFlowContainer downloadButtonsContainer;
|
||||||
private readonly BeatmapAvailability beatmapAvailability;
|
private readonly BeatmapAvailability beatmapAvailability;
|
||||||
private readonly BeatmapSetOnlineStatusPill onlineStatusPill;
|
private readonly BeatmapSetOnlineStatusPill onlineStatusPill;
|
||||||
public Details Details;
|
private readonly FavouriteButton favouriteButton;
|
||||||
|
private readonly FillFlowContainer fadeContent;
|
||||||
public bool DownloadButtonsVisible => downloadButtonsContainer.Any();
|
private readonly LoadingSpinner loading;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
public BeatmapRulesetSelector RulesetSelector => beatmapSetHeader.RulesetSelector;
|
[Resolved]
|
||||||
public readonly BeatmapPicker Picker;
|
private BeatmapRulesetSelector rulesetSelector { get; set; }
|
||||||
|
|
||||||
private readonly FavouriteButton favouriteButton;
|
public BeatmapSetHeaderContent()
|
||||||
private readonly FillFlowContainer fadeContent;
|
|
||||||
private readonly LoadingSpinner loading;
|
|
||||||
private readonly BeatmapSetHeader beatmapSetHeader;
|
|
||||||
|
|
||||||
[Cached(typeof(IBindable<RulesetInfo>))]
|
|
||||||
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
|
|
||||||
|
|
||||||
public Header()
|
|
||||||
{
|
{
|
||||||
ExternalLinkButton externalLink;
|
ExternalLinkButton externalLink;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
Masking = true;
|
InternalChild = new Container
|
||||||
|
|
||||||
EdgeEffect = new EdgeEffectParameters
|
|
||||||
{
|
|
||||||
Colour = Color4.Black.Opacity(0.25f),
|
|
||||||
Type = EdgeEffectType.Shadow,
|
|
||||||
Radius = 3,
|
|
||||||
Offset = new Vector2(0f, 1f),
|
|
||||||
};
|
|
||||||
|
|
||||||
InternalChild = new FillFlowContainer
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Direction = FillDirection.Vertical,
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
beatmapSetHeader = new BeatmapSetHeader
|
new Container
|
||||||
{
|
{
|
||||||
Ruleset = { BindTarget = ruleset },
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
cover = new UpdateableBeatmapSetCover
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Masking = true,
|
||||||
|
},
|
||||||
|
coverGradient = new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Padding = new MarginPadding
|
||||||
|
{
|
||||||
|
Vertical = BeatmapSetOverlay.Y_PADDING,
|
||||||
|
Left = BeatmapSetOverlay.X_PADDING,
|
||||||
|
Right = BeatmapSetOverlay.X_PADDING + BeatmapSetOverlay.RIGHT_WIDTH,
|
||||||
|
},
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Container
|
fadeContent = new FillFlowContainer
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
cover = new UpdateableBeatmapSetCover
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Masking = true,
|
|
||||||
},
|
|
||||||
coverGradient = new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
new Container
|
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Padding = new MarginPadding
|
Direction = FillDirection.Vertical,
|
||||||
{
|
|
||||||
Vertical = BeatmapSetOverlay.Y_PADDING,
|
|
||||||
Left = BeatmapSetOverlay.X_PADDING,
|
|
||||||
Right = BeatmapSetOverlay.X_PADDING + BeatmapSetOverlay.RIGHT_WIDTH,
|
|
||||||
},
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
fadeContent = new FillFlowContainer
|
new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Direction = FillDirection.Vertical,
|
Child = Picker = new BeatmapPicker(),
|
||||||
|
},
|
||||||
|
new FillFlowContainer
|
||||||
|
{
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Margin = new MarginPadding { Top = 15 },
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Container
|
title = new OsuSpriteText
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
Font = OsuFont.GetFont(size: 30, weight: FontWeight.SemiBold, italics: true)
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
Child = Picker = new BeatmapPicker(),
|
|
||||||
},
|
},
|
||||||
new FillFlowContainer
|
externalLink = new ExternalLinkButton
|
||||||
{
|
{
|
||||||
Direction = FillDirection.Horizontal,
|
Anchor = Anchor.BottomLeft,
|
||||||
AutoSizeAxes = Axes.Both,
|
Origin = Anchor.BottomLeft,
|
||||||
Margin = new MarginPadding { Top = 15 },
|
Margin = new MarginPadding { Left = 5, Bottom = 4 }, // To better lineup with the font
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
title = new OsuSpriteText
|
|
||||||
{
|
|
||||||
Font = OsuFont.GetFont(size: 30, weight: FontWeight.SemiBold, italics: true)
|
|
||||||
},
|
|
||||||
externalLink = new ExternalLinkButton
|
|
||||||
{
|
|
||||||
Anchor = Anchor.BottomLeft,
|
|
||||||
Origin = Anchor.BottomLeft,
|
|
||||||
Margin = new MarginPadding { Left = 5, Bottom = 4 }, // To better lineup with the font
|
|
||||||
},
|
|
||||||
explicitContentPill = new ExplicitContentBeatmapPill
|
|
||||||
{
|
|
||||||
Alpha = 0f,
|
|
||||||
Anchor = Anchor.BottomLeft,
|
|
||||||
Origin = Anchor.BottomLeft,
|
|
||||||
Margin = new MarginPadding { Left = 10, Bottom = 4 },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
artist = new OsuSpriteText
|
explicitContentPill = new ExplicitContentBeatmapPill
|
||||||
{
|
{
|
||||||
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Medium, italics: true),
|
Alpha = 0f,
|
||||||
Margin = new MarginPadding { Bottom = 20 }
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
|
Margin = new MarginPadding { Left = 10, Bottom = 4 },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
artist = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Medium, italics: true),
|
||||||
|
Margin = new MarginPadding { Bottom = 20 }
|
||||||
|
},
|
||||||
|
new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Child = author = new AuthorInfo(),
|
||||||
|
},
|
||||||
|
beatmapAvailability = new BeatmapAvailability(),
|
||||||
|
new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Height = buttons_height,
|
||||||
|
Margin = new MarginPadding { Top = 10 },
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
favouriteButton = new FavouriteButton
|
||||||
|
{
|
||||||
|
BeatmapSet = { BindTarget = BeatmapSet }
|
||||||
},
|
},
|
||||||
new Container
|
downloadButtonsContainer = new FillFlowContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.Both,
|
||||||
AutoSizeAxes = Axes.Y,
|
Padding = new MarginPadding { Left = buttons_height + buttons_spacing },
|
||||||
Child = author = new AuthorInfo(),
|
Spacing = new Vector2(buttons_spacing),
|
||||||
},
|
|
||||||
beatmapAvailability = new BeatmapAvailability(),
|
|
||||||
new Container
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Height = buttons_height,
|
|
||||||
Margin = new MarginPadding { Top = 10 },
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
favouriteButton = new FavouriteButton
|
|
||||||
{
|
|
||||||
BeatmapSet = { BindTarget = BeatmapSet }
|
|
||||||
},
|
|
||||||
downloadButtonsContainer = new FillFlowContainer
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Padding = new MarginPadding { Left = buttons_height + buttons_spacing },
|
|
||||||
Spacing = new Vector2(buttons_spacing),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
|
||||||
},
|
|
||||||
loading = new LoadingSpinner
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Scale = new Vector2(1.5f),
|
|
||||||
},
|
|
||||||
new FillFlowContainer
|
|
||||||
{
|
|
||||||
Anchor = Anchor.BottomRight,
|
|
||||||
Origin = Anchor.BottomRight,
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Margin = new MarginPadding { Top = BeatmapSetOverlay.Y_PADDING, Right = BeatmapSetOverlay.X_PADDING },
|
|
||||||
Direction = FillDirection.Vertical,
|
|
||||||
Spacing = new Vector2(10),
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
onlineStatusPill = new BeatmapSetOnlineStatusPill
|
|
||||||
{
|
|
||||||
Anchor = Anchor.TopRight,
|
|
||||||
Origin = Anchor.TopRight,
|
|
||||||
TextSize = 14,
|
|
||||||
TextPadding = new MarginPadding { Horizontal = 35, Vertical = 10 }
|
|
||||||
},
|
|
||||||
Details = new Details(),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
loading = new LoadingSpinner
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Scale = new Vector2(1.5f),
|
||||||
|
},
|
||||||
|
new FillFlowContainer
|
||||||
|
{
|
||||||
|
Anchor = Anchor.BottomRight,
|
||||||
|
Origin = Anchor.BottomRight,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Margin = new MarginPadding { Top = BeatmapSetOverlay.Y_PADDING, Right = BeatmapSetOverlay.X_PADDING },
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
Spacing = new Vector2(10),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
onlineStatusPill = new BeatmapSetOnlineStatusPill
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
|
TextSize = 14,
|
||||||
|
TextPadding = new MarginPadding { Horizontal = 35, Vertical = 10 }
|
||||||
|
},
|
||||||
|
Details = new Details(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -239,7 +209,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
|
|
||||||
BeatmapSet.BindValueChanged(setInfo =>
|
BeatmapSet.BindValueChanged(setInfo =>
|
||||||
{
|
{
|
||||||
Picker.BeatmapSet = RulesetSelector.BeatmapSet = author.BeatmapSet = beatmapAvailability.BeatmapSet = Details.BeatmapSet = setInfo.NewValue;
|
Picker.BeatmapSet = rulesetSelector.BeatmapSet = author.BeatmapSet = beatmapAvailability.BeatmapSet = Details.BeatmapSet = setInfo.NewValue;
|
||||||
cover.BeatmapSet = setInfo.NewValue;
|
cover.BeatmapSet = setInfo.NewValue;
|
||||||
|
|
||||||
if (setInfo.NewValue == null)
|
if (setInfo.NewValue == null)
|
@ -7,6 +7,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
|
using osu.Framework.Extensions.EnumExtensions;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
@ -15,7 +16,6 @@ using osu.Game.Rulesets.Scoring;
|
|||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Users.Drawables;
|
using osu.Game.Users.Drawables;
|
||||||
using osu.Game.Utils;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
|||||||
|
|
||||||
var ruleset = scores.First().Ruleset.CreateInstance();
|
var ruleset = scores.First().Ruleset.CreateInstance();
|
||||||
|
|
||||||
foreach (var result in OrderAttributeUtils.GetValuesInOrder<HitResult>())
|
foreach (var result in EnumExtensions.GetValuesInOrder<HitResult>())
|
||||||
{
|
{
|
||||||
if (!allScoreStatistics.Contains(result))
|
if (!allScoreStatistics.Contains(result))
|
||||||
continue;
|
continue;
|
||||||
|
@ -19,15 +19,12 @@ using osuTK;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
public class BeatmapSetOverlay : FullscreenOverlay<OverlayHeader> // we don't provide a standard header for now.
|
public class BeatmapSetOverlay : FullscreenOverlay<BeatmapSetHeader>
|
||||||
{
|
{
|
||||||
public const float X_PADDING = 40;
|
public const float X_PADDING = 40;
|
||||||
public const float Y_PADDING = 25;
|
public const float Y_PADDING = 25;
|
||||||
public const float RIGHT_WIDTH = 275;
|
public const float RIGHT_WIDTH = 275;
|
||||||
|
|
||||||
//todo: should be an OverlayHeader? or maybe not?
|
|
||||||
protected new readonly Header Header;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private RulesetStore rulesets { get; set; }
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
@ -39,7 +36,7 @@ namespace osu.Game.Overlays
|
|||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
|
|
||||||
public BeatmapSetOverlay()
|
public BeatmapSetOverlay()
|
||||||
: base(OverlayColourScheme.Blue, null)
|
: base(OverlayColourScheme.Blue, new BeatmapSetHeader())
|
||||||
{
|
{
|
||||||
OverlayScrollContainer scroll;
|
OverlayScrollContainer scroll;
|
||||||
Info info;
|
Info info;
|
||||||
@ -72,14 +69,14 @@ namespace osu.Game.Overlays
|
|||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
Header = new Header(),
|
Header,
|
||||||
info = new Info()
|
info = new Info()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
new ScoresContainer
|
new ScoresContainer
|
||||||
{
|
{
|
||||||
Beatmap = { BindTarget = Header.Picker.Beatmap }
|
Beatmap = { BindTarget = Header.HeaderContent.Picker.Beatmap }
|
||||||
},
|
},
|
||||||
comments = new CommentsSection()
|
comments = new CommentsSection()
|
||||||
},
|
},
|
||||||
@ -91,7 +88,7 @@ namespace osu.Game.Overlays
|
|||||||
info.BeatmapSet.BindTo(beatmapSet);
|
info.BeatmapSet.BindTo(beatmapSet);
|
||||||
comments.BeatmapSet.BindTo(beatmapSet);
|
comments.BeatmapSet.BindTo(beatmapSet);
|
||||||
|
|
||||||
Header.Picker.Beatmap.ValueChanged += b =>
|
Header.HeaderContent.Picker.Beatmap.ValueChanged += b =>
|
||||||
{
|
{
|
||||||
info.Beatmap = b.NewValue;
|
info.Beatmap = b.NewValue;
|
||||||
|
|
||||||
@ -125,7 +122,7 @@ namespace osu.Game.Overlays
|
|||||||
req.Success += res =>
|
req.Success += res =>
|
||||||
{
|
{
|
||||||
beatmapSet.Value = res.ToBeatmapSet(rulesets);
|
beatmapSet.Value = res.ToBeatmapSet(rulesets);
|
||||||
Header.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId);
|
Header.HeaderContent.Picker.Beatmap.Value = Header.BeatmapSet.Value.Beatmaps.First(b => b.OnlineBeatmapID == beatmapId);
|
||||||
};
|
};
|
||||||
API.Queue(req);
|
API.Queue(req);
|
||||||
|
|
||||||
|
@ -190,13 +190,13 @@ namespace osu.Game.Overlays.Chat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
updateMessageContent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
updateMessageContent();
|
||||||
FinishTransforms(true);
|
FinishTransforms(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,16 @@ namespace osu.Game.Overlays.Comments
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
|
[Resolved(canBeNull: true)]
|
||||||
|
private LoginOverlay login { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OverlayColourProvider colourProvider { get; set; }
|
private OverlayColourProvider colourProvider { get; set; }
|
||||||
|
|
||||||
|
protected Box Background { get; private set; }
|
||||||
|
|
||||||
private readonly Comment comment;
|
private readonly Comment comment;
|
||||||
private Box background;
|
|
||||||
private Box hoverLayer;
|
private Box hoverLayer;
|
||||||
private CircularContainer borderContainer;
|
private CircularContainer borderContainer;
|
||||||
private SpriteText sideNumber;
|
private SpriteText sideNumber;
|
||||||
@ -62,8 +67,12 @@ namespace osu.Game.Overlays.Comments
|
|||||||
AccentColour = borderContainer.BorderColour = sideNumber.Colour = colours.GreenLight;
|
AccentColour = borderContainer.BorderColour = sideNumber.Colour = colours.GreenLight;
|
||||||
hoverLayer.Colour = Color4.Black.Opacity(0.5f);
|
hoverLayer.Colour = Color4.Black.Opacity(0.5f);
|
||||||
|
|
||||||
if (api.IsLoggedIn && api.LocalUser.Value.Id != comment.UserId)
|
var ownComment = api.LocalUser.Value.Id == comment.UserId;
|
||||||
|
|
||||||
|
if (!ownComment)
|
||||||
Action = onAction;
|
Action = onAction;
|
||||||
|
|
||||||
|
Background.Alpha = ownComment ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -71,12 +80,18 @@ namespace osu.Game.Overlays.Comments
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
isVoted.Value = comment.IsVoted;
|
isVoted.Value = comment.IsVoted;
|
||||||
votesCount.Value = comment.VotesCount;
|
votesCount.Value = comment.VotesCount;
|
||||||
isVoted.BindValueChanged(voted => background.Colour = voted.NewValue ? AccentColour : colourProvider.Background6, true);
|
isVoted.BindValueChanged(voted => Background.Colour = voted.NewValue ? AccentColour : colourProvider.Background6, true);
|
||||||
votesCount.BindValueChanged(count => votesCounter.Text = $"+{count.NewValue}", true);
|
votesCount.BindValueChanged(count => votesCounter.Text = $"+{count.NewValue}", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onAction()
|
private void onAction()
|
||||||
{
|
{
|
||||||
|
if (!api.IsLoggedIn)
|
||||||
|
{
|
||||||
|
login?.Show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
request = new CommentVoteRequest(comment.Id, isVoted.Value ? CommentVoteAction.UnVote : CommentVoteAction.Vote);
|
request = new CommentVoteRequest(comment.Id, isVoted.Value ? CommentVoteAction.UnVote : CommentVoteAction.Vote);
|
||||||
request.Success += onSuccess;
|
request.Success += onSuccess;
|
||||||
api.Queue(request);
|
api.Queue(request);
|
||||||
@ -102,7 +117,7 @@ namespace osu.Game.Overlays.Comments
|
|||||||
Masking = true,
|
Masking = true,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
background = new Box
|
Background = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both
|
RelativeSizeAxes = Axes.Both
|
||||||
},
|
},
|
||||||
|
18
osu.Game/Overlays/Mods/LocalPlayerModSelectOverlay.cs
Normal file
18
osu.Game/Overlays/Mods/LocalPlayerModSelectOverlay.cs
Normal 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 LocalPlayerModSelectOverlay : ModSelectOverlay
|
||||||
|
{
|
||||||
|
protected override void OnModSelected(Mod mod)
|
||||||
|
{
|
||||||
|
base.OnModSelected(mod);
|
||||||
|
|
||||||
|
foreach (var section in ModSectionsContainer.Children)
|
||||||
|
section.DeselectTypes(mod.IncompatibleMods, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -236,13 +236,13 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
iconsContainer.AddRange(new[]
|
iconsContainer.AddRange(new[]
|
||||||
{
|
{
|
||||||
backgroundIcon = new PassThroughTooltipModIcon(Mods[1])
|
backgroundIcon = new ModIcon(Mods[1], false)
|
||||||
{
|
{
|
||||||
Origin = Anchor.BottomRight,
|
Origin = Anchor.BottomRight,
|
||||||
Anchor = Anchor.BottomRight,
|
Anchor = Anchor.BottomRight,
|
||||||
Position = new Vector2(1.5f),
|
Position = new Vector2(1.5f),
|
||||||
},
|
},
|
||||||
foregroundIcon = new PassThroughTooltipModIcon(Mods[0])
|
foregroundIcon = new ModIcon(Mods[0], false)
|
||||||
{
|
{
|
||||||
Origin = Anchor.BottomRight,
|
Origin = Anchor.BottomRight,
|
||||||
Anchor = Anchor.BottomRight,
|
Anchor = Anchor.BottomRight,
|
||||||
@ -252,7 +252,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
iconsContainer.Add(foregroundIcon = new PassThroughTooltipModIcon(Mod)
|
iconsContainer.Add(foregroundIcon = new ModIcon(Mod, false)
|
||||||
{
|
{
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -297,15 +297,5 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
Mod = mod;
|
Mod = mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PassThroughTooltipModIcon : ModIcon
|
|
||||||
{
|
|
||||||
public override string TooltipText => null;
|
|
||||||
|
|
||||||
public PassThroughTooltipModIcon(Mod mod)
|
|
||||||
: base(mod)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -216,9 +255,9 @@ namespace osu.Game.Overlays.Mods
|
|||||||
},
|
},
|
||||||
new Drawable[]
|
new Drawable[]
|
||||||
{
|
{
|
||||||
// Footer
|
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
|
Name = "Footer content",
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
Origin = Anchor.TopCentre,
|
Origin = Anchor.TopCentre,
|
||||||
@ -231,22 +270,21 @@ 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,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
RelativePositionAxes = Axes.X,
|
||||||
Width = content_width,
|
Width = content_width,
|
||||||
Spacing = new Vector2(footer_button_spacing, footer_button_spacing / 2),
|
Spacing = new Vector2(footer_button_spacing, footer_button_spacing / 2),
|
||||||
LayoutDuration = 100,
|
|
||||||
LayoutEasing = Easing.OutQuint,
|
|
||||||
Padding = new MarginPadding
|
Padding = new MarginPadding
|
||||||
{
|
{
|
||||||
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
|
||||||
{
|
{
|
||||||
@ -273,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),
|
||||||
@ -329,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(footerContainer.DrawSize.X, 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)
|
||||||
{
|
{
|
||||||
@ -369,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)
|
||||||
{
|
{
|
||||||
@ -401,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();
|
||||||
}
|
}
|
||||||
@ -439,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)
|
||||||
|
@ -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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user