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

Merge branch 'master' into results-dynamic-pp-calc

This commit is contained in:
Dean Herbert 2020-11-02 14:47:33 +09:00
commit 73b290aca3
169 changed files with 4493 additions and 1392 deletions

View File

@ -16,9 +16,9 @@
<EmbeddedResource Include="Resources\**\*.*" /> <EmbeddedResource Include="Resources\**\*.*" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Code Analysis"> <ItemGroup Label="Code Analysis">
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.1" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CodeAnalysis\BannedSymbols.txt" /> <AdditionalFiles Include="$(MSBuildThisFileDirectory)CodeAnalysis\BannedSymbols.txt" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Code Analysis"> <PropertyGroup Label="Code Analysis">
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodeAnalysis\osu.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodeAnalysis\osu.ruleset</CodeAnalysisRuleSet>

View File

@ -34,6 +34,8 @@ If you are looking to install or test osu! without setting up a development envi
| [Windows (x64)](https://github.com/ppy/osu/releases/latest/download/install.exe) | [macOS 10.12+](https://github.com/ppy/osu/releases/latest/download/osu.app.zip) | [Linux (x64)](https://github.com/ppy/osu/releases/latest/download/osu.AppImage) | [iOS(iOS 10+)](https://osu.ppy.sh/home/testflight) | [Android (5+)](https://github.com/ppy/osu/releases/latest/download/sh.ppy.osulazer.apk) | [Windows (x64)](https://github.com/ppy/osu/releases/latest/download/install.exe) | [macOS 10.12+](https://github.com/ppy/osu/releases/latest/download/osu.app.zip) | [Linux (x64)](https://github.com/ppy/osu/releases/latest/download/osu.AppImage) | [iOS(iOS 10+)](https://osu.ppy.sh/home/testflight) | [Android (5+)](https://github.com/ppy/osu/releases/latest/download/sh.ppy.osulazer.apk)
| ------------- | ------------- | ------------- | ------------- | ------------- | | ------------- | ------------- | ------------- | ------------- | ------------- |
- The iOS testflight link may fill up (Apple has a hard limit of 10,000 users). We reset it occasionally when this happens. Please do not ask about this. Check back regularly for link resets or follow [peppy](https://twitter.com/ppy) on twitter for announcements of link resets.
- When running on Windows 7 or 8.1, **[additional prerequisites](https://docs.microsoft.com/en-us/dotnet/core/install/dependencies?tabs=netcore31&pivots=os-windows)** may be required to correctly run .NET Core applications if your operating system is not up-to-date with the latest service packs. - When running on Windows 7 or 8.1, **[additional prerequisites](https://docs.microsoft.com/en-us/dotnet/core/install/dependencies?tabs=netcore31&pivots=os-windows)** may be required to correctly run .NET Core applications if your operating system is not up-to-date with the latest service packs.
If your platform is not listed above, there is still a chance you can manually build it by following the instructions below. If your platform is not listed above, there is still a chance you can manually build it by following the instructions below.

View File

@ -5,6 +5,6 @@
"version": "3.1.100" "version": "3.1.100"
}, },
"msbuild-sdks": { "msbuild-sdks": {
"Microsoft.Build.Traversal": "2.1.1" "Microsoft.Build.Traversal": "2.2.3"
} }
} }

View File

@ -51,7 +51,7 @@
<Reference Include="Java.Interop" /> <Reference Include="Java.Interop" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.1016.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2020.1030.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2020.1019.0" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2020.1029.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -35,6 +35,7 @@ namespace osu.Game.Rulesets.Mania.Tests
objects.Add(new Note { StartTime = time }); objects.Add(new Note { StartTime = time });
// don't hit the first note
if (i > 0) if (i > 0)
{ {
frames.Add(new ManiaReplayFrame(time + 10, ManiaAction.Key1)); frames.Add(new ManiaReplayFrame(time + 10, ManiaAction.Key1));

View File

@ -6,20 +6,20 @@
"EndTime": 2750.0, "EndTime": 2750.0,
"Column": 1, "Column": 1,
"NodeSamples": [ "NodeSamples": [
["normal-hitnormal"], ["Gameplay/normal-hitnormal"],
["soft-hitnormal"], ["Gameplay/soft-hitnormal"],
["drum-hitnormal"] ["Gameplay/drum-hitnormal"]
], ],
"Samples": ["-hitnormal"] "Samples": ["Gameplay/-hitnormal"]
}, { }, {
"StartTime": 1875.0, "StartTime": 1875.0,
"EndTime": 2750.0, "EndTime": 2750.0,
"Column": 0, "Column": 0,
"NodeSamples": [ "NodeSamples": [
["soft-hitnormal"], ["Gameplay/soft-hitnormal"],
["drum-hitnormal"] ["Gameplay/drum-hitnormal"]
], ],
"Samples": ["-hitnormal"] "Samples": ["Gameplay/-hitnormal"]
}] }]
}, { }, {
"StartTime": 3750.0, "StartTime": 3750.0,
@ -27,7 +27,7 @@
"StartTime": 3750.0, "StartTime": 3750.0,
"EndTime": 3750.0, "EndTime": 3750.0,
"Column": 3, "Column": 3,
"Samples": ["normal-hitnormal"] "Samples": ["Gameplay/normal-hitnormal"]
}] }]
}] }]
} }

View File

@ -6,10 +6,10 @@
"EndTime": 1500.0, "EndTime": 1500.0,
"Column": 0, "Column": 0,
"NodeSamples": [ "NodeSamples": [
["normal-hitnormal"], ["Gameplay/normal-hitnormal"],
[] []
], ],
"Samples": ["normal-hitnormal"] "Samples": ["Gameplay/normal-hitnormal"]
}] }]
}, { }, {
"StartTime": 2000.0, "StartTime": 2000.0,
@ -18,10 +18,10 @@
"EndTime": 3000.0, "EndTime": 3000.0,
"Column": 2, "Column": 2,
"NodeSamples": [ "NodeSamples": [
["drum-hitnormal"], ["Gameplay/drum-hitnormal"],
[] []
], ],
"Samples": ["drum-hitnormal"] "Samples": ["Gameplay/drum-hitnormal"]
}] }]
}] }]
} }

View File

@ -5,17 +5,17 @@
"StartTime": 8470.0, "StartTime": 8470.0,
"EndTime": 8470.0, "EndTime": 8470.0,
"Column": 0, "Column": 0,
"Samples": ["normal-hitnormal", "normal-hitclap"] "Samples": ["Gameplay/normal-hitnormal", "Gameplay/normal-hitclap"]
}, { }, {
"StartTime": 8626.470587768974, "StartTime": 8626.470587768974,
"EndTime": 8626.470587768974, "EndTime": 8626.470587768974,
"Column": 1, "Column": 1,
"Samples": ["normal-hitnormal"] "Samples": ["Gameplay/normal-hitnormal"]
}, { }, {
"StartTime": 8782.941175537948, "StartTime": 8782.941175537948,
"EndTime": 8782.941175537948, "EndTime": 8782.941175537948,
"Column": 2, "Column": 2,
"Samples": ["normal-hitnormal", "normal-hitclap"] "Samples": ["Gameplay/normal-hitnormal", "Gameplay/normal-hitclap"]
}] }]
}] }]
} }

View File

@ -0,0 +1,41 @@
// 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.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.UI;
using osu.Game.Tests.Visual;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests
{
public class TestPlayfieldBorder : OsuTestScene
{
public TestPlayfieldBorder()
{
Bindable<PlayfieldBorderStyle> playfieldBorderStyle = new Bindable<PlayfieldBorderStyle>();
AddStep("add drawables", () =>
{
Child = new Container
{
Size = new Vector2(400, 300),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
new PlayfieldBorder
{
PlayfieldBorderStyle = { BindTarget = playfieldBorderStyle }
}
}
};
});
AddStep("Set none", () => playfieldBorderStyle.Value = PlayfieldBorderStyle.None);
AddStep("Set corners", () => playfieldBorderStyle.Value = PlayfieldBorderStyle.Corners);
AddStep("Set full", () => playfieldBorderStyle.Value = PlayfieldBorderStyle.Full);
}
}
}

View File

@ -3,6 +3,7 @@
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Configuration;
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.Configuration namespace osu.Game.Rulesets.Osu.Configuration
{ {
@ -19,6 +20,7 @@ namespace osu.Game.Rulesets.Osu.Configuration
Set(OsuRulesetSetting.SnakingInSliders, true); Set(OsuRulesetSetting.SnakingInSliders, true);
Set(OsuRulesetSetting.SnakingOutSliders, true); Set(OsuRulesetSetting.SnakingOutSliders, true);
Set(OsuRulesetSetting.ShowCursorTrail, true); Set(OsuRulesetSetting.ShowCursorTrail, true);
Set(OsuRulesetSetting.PlayfieldBorderStyle, PlayfieldBorderStyle.None);
} }
} }
@ -26,6 +28,7 @@ namespace osu.Game.Rulesets.Osu.Configuration
{ {
SnakingInSliders, SnakingInSliders,
SnakingOutSliders, SnakingOutSliders,
ShowCursorTrail ShowCursorTrail,
PlayfieldBorderStyle,
} }
} }

View File

@ -56,7 +56,18 @@ namespace osu.Game.Rulesets.Osu.Edit
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
LayerBelowRuleset.Add(distanceSnapGridContainer = new Container { RelativeSizeAxes = Axes.Both }); LayerBelowRuleset.AddRange(new Drawable[]
{
new PlayfieldBorder
{
RelativeSizeAxes = Axes.Both,
PlayfieldBorderStyle = { Value = PlayfieldBorderStyle.Corners }
},
distanceSnapGridContainer = new Container
{
RelativeSizeAxes = Axes.Both
}
});
selectedHitObjects = EditorBeatmap.SelectedHitObjects.GetBoundCopy(); selectedHitObjects = EditorBeatmap.SelectedHitObjects.GetBoundCopy();
selectedHitObjects.CollectionChanged += (_, __) => updateDistanceSnapGrid(); selectedHitObjects.CollectionChanged += (_, __) => updateDistanceSnapGrid();

View File

@ -11,7 +11,6 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Replays; using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
@ -31,7 +30,7 @@ namespace osu.Game.Rulesets.Osu.Mods
private OsuInputManager inputManager; private OsuInputManager inputManager;
private GameplayClock gameplayClock; private IFrameStableClock gameplayClock;
private List<OsuReplayFrame> replayFrames; private List<OsuReplayFrame> replayFrames;

View File

@ -64,8 +64,8 @@ namespace osu.Game.Rulesets.Osu.Mods
/// </summary> /// </summary>
private const float target_clamp = 1; private const float target_clamp = 1;
private readonly float targetBreakMultiplier = 0; private readonly float targetBreakMultiplier;
private readonly float easing = 1; private readonly float easing;
private readonly CompositeDrawable restrictTo; private readonly CompositeDrawable restrictTo;
@ -86,6 +86,9 @@ namespace osu.Game.Rulesets.Osu.Mods
{ {
this.restrictTo = restrictTo; this.restrictTo = restrictTo;
this.beatmap = beatmap; this.beatmap = beatmap;
targetBreakMultiplier = 0;
easing = 1;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -6,6 +6,7 @@ using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
@ -38,20 +39,25 @@ namespace osu.Game.Rulesets.Osu.Mods
protected void ApplyTraceableState(DrawableHitObject drawable, ArmedState state) protected void ApplyTraceableState(DrawableHitObject drawable, ArmedState state)
{ {
if (!(drawable is DrawableOsuHitObject drawableOsu)) if (!(drawable is DrawableOsuHitObject))
return; return;
var h = drawableOsu.HitObject;
//todo: expose and hide spinner background somehow //todo: expose and hide spinner background somehow
switch (drawable) switch (drawable)
{ {
case DrawableHitCircle circle: case DrawableHitCircle circle:
// we only want to see the approach circle // we only want to see the approach circle
using (circle.BeginAbsoluteSequence(h.StartTime - h.TimePreempt, true)) applyCirclePieceState(circle, circle.CirclePiece);
circle.CirclePiece.Hide(); break;
case DrawableSliderTail sliderTail:
applyCirclePieceState(sliderTail);
break;
case DrawableSliderRepeat sliderRepeat:
// show only the repeat arrow
applyCirclePieceState(sliderRepeat, sliderRepeat.CirclePiece);
break; break;
case DrawableSlider slider: case DrawableSlider slider:
@ -61,6 +67,13 @@ namespace osu.Game.Rulesets.Osu.Mods
} }
} }
private void applyCirclePieceState(DrawableOsuHitObject hitObject, IDrawable hitCircle = null)
{
var h = hitObject.HitObject;
using (hitObject.BeginAbsoluteSequence(h.StartTime - h.TimePreempt, true))
(hitCircle ?? hitObject).Hide();
}
private void applySliderState(DrawableSlider slider) private void applySliderState(DrawableSlider slider)
{ {
((PlaySliderBody)slider.Body.Drawable).AccentColour = slider.AccentColour.Value.Opacity(0); ((PlaySliderBody)slider.Body.Drawable).AccentColour = slider.AccentColour.Value.Opacity(0);

View File

@ -17,12 +17,16 @@ using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Skinning; using osu.Game.Skinning;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Rulesets.Osu.Configuration;
using osuTK; using osuTK;
namespace osu.Game.Rulesets.Osu.UI namespace osu.Game.Rulesets.Osu.UI
{ {
public class OsuPlayfield : Playfield public class OsuPlayfield : Playfield
{ {
private readonly PlayfieldBorder playfieldBorder;
private readonly ProxyContainer approachCircles; private readonly ProxyContainer approachCircles;
private readonly ProxyContainer spinnerProxies; private readonly ProxyContainer spinnerProxies;
private readonly JudgementContainer<DrawableOsuJudgement> judgementLayer; private readonly JudgementContainer<DrawableOsuJudgement> judgementLayer;
@ -33,12 +37,19 @@ namespace osu.Game.Rulesets.Osu.UI
protected override GameplayCursorContainer CreateCursor() => new OsuCursorContainer(); protected override GameplayCursorContainer CreateCursor() => new OsuCursorContainer();
private readonly Bindable<bool> playfieldBorderStyle = new BindableBool();
private readonly IDictionary<HitResult, DrawablePool<DrawableOsuJudgement>> poolDictionary = new Dictionary<HitResult, DrawablePool<DrawableOsuJudgement>>(); private readonly IDictionary<HitResult, DrawablePool<DrawableOsuJudgement>> poolDictionary = new Dictionary<HitResult, DrawablePool<DrawableOsuJudgement>>();
public OsuPlayfield() public OsuPlayfield()
{ {
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
playfieldBorder = new PlayfieldBorder
{
RelativeSizeAxes = Axes.Both,
Depth = 3
},
spinnerProxies = new ProxyContainer spinnerProxies = new ProxyContainer
{ {
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
@ -76,6 +87,12 @@ namespace osu.Game.Rulesets.Osu.UI
AddRangeInternal(poolDictionary.Values); AddRangeInternal(poolDictionary.Values);
} }
[BackgroundDependencyLoader(true)]
private void load(OsuRulesetConfigManager config)
{
config?.BindWith(OsuRulesetSetting.PlayfieldBorderStyle, playfieldBorder.PlayfieldBorderStyle);
}
public override void Add(DrawableHitObject h) public override void Add(DrawableHitObject h)
{ {
h.OnNewResult += onNewResult; h.OnNewResult += onNewResult;

View File

@ -5,6 +5,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Osu.Configuration; using osu.Game.Rulesets.Osu.Configuration;
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.UI namespace osu.Game.Rulesets.Osu.UI
{ {
@ -39,6 +40,11 @@ namespace osu.Game.Rulesets.Osu.UI
LabelText = "Cursor trail", LabelText = "Cursor trail",
Current = config.GetBindable<bool>(OsuRulesetSetting.ShowCursorTrail) Current = config.GetBindable<bool>(OsuRulesetSetting.ShowCursorTrail)
}, },
new SettingsEnumDropdown<PlayfieldBorderStyle>
{
LabelText = "Playfield border style",
Current = config.GetBindable<PlayfieldBorderStyle>(OsuRulesetSetting.PlayfieldBorderStyle),
},
}; };
} }
} }

View File

@ -162,7 +162,7 @@ namespace osu.Game.Rulesets.Taiko.Skinning
get get
{ {
foreach (var name in source.LookupNames) foreach (var name in source.LookupNames)
yield return $"taiko-{name}"; yield return name.Insert(name.LastIndexOf('/') + 1, "taiko-");
foreach (var name in source.LookupNames) foreach (var name in source.LookupNames)
yield return name; yield return name;

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Performance;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects.Drawables; using osu.Game.Rulesets.Taiko.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Rulesets.UI.Scrolling;

View File

@ -410,13 +410,13 @@ namespace osu.Game.Tests.Beatmaps.Formats
{ {
var hitObjects = decoder.Decode(stream).HitObjects; var hitObjects = decoder.Decode(stream).HitObjects;
Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[0]).LookupNames.First()); Assert.AreEqual("Gameplay/normal-hitnormal", getTestableSampleInfo(hitObjects[0]).LookupNames.First());
Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[1]).LookupNames.First()); Assert.AreEqual("Gameplay/normal-hitnormal", getTestableSampleInfo(hitObjects[1]).LookupNames.First());
Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First()); Assert.AreEqual("Gameplay/normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First());
Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[3]).LookupNames.First()); Assert.AreEqual("Gameplay/normal-hitnormal", getTestableSampleInfo(hitObjects[3]).LookupNames.First());
// The control point at the end time of the slider should be applied // The control point at the end time of the slider should be applied
Assert.AreEqual("soft-hitnormal8", getTestableSampleInfo(hitObjects[4]).LookupNames.First()); Assert.AreEqual("Gameplay/soft-hitnormal8", getTestableSampleInfo(hitObjects[4]).LookupNames.First());
} }
static HitSampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]); static HitSampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]);
@ -432,9 +432,9 @@ namespace osu.Game.Tests.Beatmaps.Formats
{ {
var hitObjects = decoder.Decode(stream).HitObjects; var hitObjects = decoder.Decode(stream).HitObjects;
Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[0]).LookupNames.First()); Assert.AreEqual("Gameplay/normal-hitnormal", getTestableSampleInfo(hitObjects[0]).LookupNames.First());
Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[1]).LookupNames.First()); Assert.AreEqual("Gameplay/normal-hitnormal2", getTestableSampleInfo(hitObjects[1]).LookupNames.First());
Assert.AreEqual("normal-hitnormal3", getTestableSampleInfo(hitObjects[2]).LookupNames.First()); Assert.AreEqual("Gameplay/normal-hitnormal3", getTestableSampleInfo(hitObjects[2]).LookupNames.First());
} }
static HitSampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]); static HitSampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(hitObject.Samples[0]);
@ -452,7 +452,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[0]).LookupNames.First()); Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[0]).LookupNames.First());
Assert.AreEqual("hit_2.wav", getTestableSampleInfo(hitObjects[1]).LookupNames.First()); Assert.AreEqual("hit_2.wav", getTestableSampleInfo(hitObjects[1]).LookupNames.First());
Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First()); Assert.AreEqual("Gameplay/normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First());
Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[3]).LookupNames.First()); Assert.AreEqual("hit_1.wav", getTestableSampleInfo(hitObjects[3]).LookupNames.First());
Assert.AreEqual(70, getTestableSampleInfo(hitObjects[3]).Volume); Assert.AreEqual(70, getTestableSampleInfo(hitObjects[3]).Volume);
} }

View File

@ -821,15 +821,13 @@ namespace osu.Game.Tests.Beatmaps.IO
var manager = osu.Dependencies.Get<BeatmapManager>(); var manager = osu.Dependencies.Get<BeatmapManager>();
await manager.Import(temp); var importedSet = await manager.Import(temp);
var imported = manager.GetAllUsableBeatmapSets();
ensureLoaded(osu); ensureLoaded(osu);
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000); waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
return imported.LastOrDefault(); return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.ID);
} }
private void deleteBeatmapSet(BeatmapSetInfo imported, OsuGameBase osu) private void deleteBeatmapSet(BeatmapSetInfo imported, OsuGameBase osu)

View File

@ -81,8 +81,8 @@ namespace osu.Game.Tests.Gameplay
private class TestHitObjectWithCombo : ConvertHitObject, IHasComboInformation private class TestHitObjectWithCombo : ConvertHitObject, IHasComboInformation
{ {
public bool NewCombo { get; set; } = false; public bool NewCombo { get; set; }
public int ComboOffset { get; } = 0; public int ComboOffset => 0;
public Bindable<int> IndexInCurrentComboBindable { get; } = new Bindable<int>(); public Bindable<int> IndexInCurrentComboBindable { get; } = new Bindable<int>();

View File

@ -0,0 +1,196 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Textures;
using osu.Game.Configuration;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Tests.Visual.Background
{
public class TestSceneSeasonalBackgroundLoader : ScreenTestScene
{
[Resolved]
private OsuConfigManager config { get; set; }
[Resolved]
private SessionStatics statics { get; set; }
[Cached(typeof(LargeTextureStore))]
private LookupLoggingTextureStore textureStore = new LookupLoggingTextureStore();
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
private SeasonalBackgroundLoader backgroundLoader;
private Container backgroundContainer;
// in real usages these would be online URLs, but correct execution of this test
// shouldn't be coupled to existence of online assets.
private static readonly List<string> seasonal_background_urls = new List<string>
{
"Backgrounds/bg2",
"Backgrounds/bg4",
"Backgrounds/bg3"
};
[BackgroundDependencyLoader]
private void load(LargeTextureStore wrappedStore)
{
textureStore.AddStore(wrappedStore);
Add(backgroundContainer = new Container
{
RelativeSizeAxes = Axes.Both
});
}
[SetUp]
public void SetUp() => Schedule(() =>
{
// reset API response in statics to avoid test crosstalk.
statics.Set<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
textureStore.PerformedLookups.Clear();
dummyAPI.SetState(APIState.Online);
backgroundContainer.Clear();
});
[TestCase(-5)]
[TestCase(5)]
public void TestAlwaysSeasonal(int daysOffset)
{
registerBackgroundsResponse(DateTimeOffset.Now.AddDays(daysOffset));
setSeasonalBackgroundMode(SeasonalBackgroundMode.Always);
createLoader();
for (int i = 0; i < 4; ++i)
loadNextBackground();
AddAssert("all backgrounds cycled", () => new HashSet<string>(textureStore.PerformedLookups).SetEquals(seasonal_background_urls));
}
[TestCase(-5)]
[TestCase(5)]
public void TestNeverSeasonal(int daysOffset)
{
registerBackgroundsResponse(DateTimeOffset.Now.AddDays(daysOffset));
setSeasonalBackgroundMode(SeasonalBackgroundMode.Never);
createLoader();
assertNoBackgrounds();
}
[Test]
public void TestSometimesInSeason()
{
registerBackgroundsResponse(DateTimeOffset.Now.AddDays(5));
setSeasonalBackgroundMode(SeasonalBackgroundMode.Sometimes);
createLoader();
assertAnyBackground();
}
[Test]
public void TestSometimesOutOfSeason()
{
registerBackgroundsResponse(DateTimeOffset.Now.AddDays(-10));
setSeasonalBackgroundMode(SeasonalBackgroundMode.Sometimes);
createLoader();
assertNoBackgrounds();
}
[Test]
public void TestDelayedConnectivity()
{
registerBackgroundsResponse(DateTimeOffset.Now.AddDays(30));
setSeasonalBackgroundMode(SeasonalBackgroundMode.Always);
AddStep("go offline", () => dummyAPI.SetState(APIState.Offline));
createLoader();
assertNoBackgrounds();
AddStep("go online", () => dummyAPI.SetState(APIState.Online));
assertAnyBackground();
}
private void registerBackgroundsResponse(DateTimeOffset endDate)
=> AddStep("setup request handler", () =>
{
dummyAPI.HandleRequest = request =>
{
if (dummyAPI.State.Value != APIState.Online || !(request is GetSeasonalBackgroundsRequest backgroundsRequest))
return;
backgroundsRequest.TriggerSuccess(new APISeasonalBackgrounds
{
Backgrounds = seasonal_background_urls.Select(url => new APISeasonalBackground { Url = url }).ToList(),
EndDate = endDate
});
};
});
private void setSeasonalBackgroundMode(SeasonalBackgroundMode mode)
=> AddStep($"set seasonal mode to {mode}", () => config.Set(OsuSetting.SeasonalBackgroundMode, mode));
private void createLoader()
=> AddStep("create loader", () =>
{
if (backgroundLoader != null)
Remove(backgroundLoader);
Add(backgroundLoader = new SeasonalBackgroundLoader());
});
private void loadNextBackground()
{
SeasonalBackground background = null;
AddStep("create next background", () =>
{
background = backgroundLoader.LoadNextBackground();
LoadComponentAsync(background, bg => backgroundContainer.Child = bg);
});
AddUntilStep("background loaded", () => background.IsLoaded);
}
private void assertAnyBackground()
{
loadNextBackground();
AddAssert("background looked up", () => textureStore.PerformedLookups.Any());
}
private void assertNoBackgrounds()
{
AddAssert("no background available", () => backgroundLoader.LoadNextBackground() == null);
AddAssert("no lookups performed", () => !textureStore.PerformedLookups.Any());
}
private class LookupLoggingTextureStore : LargeTextureStore
{
public List<string> PerformedLookups { get; } = new List<string>();
public override Texture Get(string name, WrapMode wrapModeS, WrapMode wrapModeT)
{
PerformedLookups.Add(name);
return base.Get(name, wrapModeS, wrapModeT);
}
}
}
}

View 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 NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Skinning;
using osu.Game.Storyboards;
using osu.Game.Storyboards.Drawables;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneDrawableStoryboardSprite : SkinnableTestScene
{
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
[Cached]
private Storyboard storyboard { get; set; } = new Storyboard();
[Test]
public void TestSkinSpriteDisallowedByDefault()
{
const string lookup_name = "hitcircleoverlay";
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = false);
AddStep("create sprites", () => SetContents(
() => createSprite(lookup_name, Anchor.TopLeft, Vector2.Zero)));
assertSpritesFromSkin(false);
}
[Test]
public void TestAllowLookupFromSkin()
{
const string lookup_name = "hitcircleoverlay";
AddStep("allow skin lookup", () => storyboard.UseSkinSprites = true);
AddStep("create sprites", () => SetContents(
() => createSprite(lookup_name, Anchor.Centre, Vector2.Zero)));
assertSpritesFromSkin(true);
}
private DrawableStoryboardSprite createSprite(string lookupName, Anchor origin, Vector2 initialPosition)
=> new DrawableStoryboardSprite(
new StoryboardSprite(lookupName, origin, initialPosition)
).With(s =>
{
s.LifetimeStart = double.MinValue;
s.LifetimeEnd = double.MaxValue;
});
private void assertSpritesFromSkin(bool fromSkin) =>
AddAssert($"sprites are {(fromSkin ? "from skin" : "from storyboard")}",
() => this.ChildrenOfType<DrawableStoryboardSprite>()
.All(sprite => sprite.ChildrenOfType<SkinnableSprite>().Any() == fromSkin));
}
}

View File

@ -9,7 +9,6 @@ using osu.Framework.Testing;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Skinning; using osu.Game.Skinning;
@ -22,11 +21,11 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
DrawableSlider slider = null; DrawableSlider slider = null;
DrawableSample[] samples = null; DrawableSample[] samples = null;
ISamplePlaybackDisabler gameplayClock = null; ISamplePlaybackDisabler sampleDisabler = null;
AddStep("get variables", () => AddStep("get variables", () =>
{ {
gameplayClock = Player.ChildrenOfType<FrameStabilityContainer>().First(); sampleDisabler = Player;
slider = Player.ChildrenOfType<DrawableSlider>().OrderBy(s => s.HitObject.StartTime).First(); slider = Player.ChildrenOfType<DrawableSlider>().OrderBy(s => s.HitObject.StartTime).First();
samples = slider.ChildrenOfType<DrawableSample>().ToArray(); samples = slider.ChildrenOfType<DrawableSample>().ToArray();
}); });
@ -43,16 +42,16 @@ namespace osu.Game.Tests.Visual.Gameplay
return true; return true;
}); });
AddAssert("sample playback disabled", () => gameplayClock.SamplePlaybackDisabled.Value); AddAssert("sample playback disabled", () => sampleDisabler.SamplePlaybackDisabled.Value);
// because we are in frame stable context, it's quite likely that not all samples are "played" at this point. // because we are in frame stable context, it's quite likely that not all samples are "played" at this point.
// the important thing is that at least one started, and that sample has since stopped. // the important thing is that at least one started, and that sample has since stopped.
AddAssert("all looping samples stopped immediately", () => allStopped(allLoopingSounds)); AddAssert("all looping samples stopped immediately", () => allStopped(allLoopingSounds));
AddUntilStep("all samples stopped eventually", () => allStopped(allSounds)); AddUntilStep("all samples stopped eventually", () => allStopped(allSounds));
AddAssert("sample playback still disabled", () => gameplayClock.SamplePlaybackDisabled.Value); AddAssert("sample playback still disabled", () => sampleDisabler.SamplePlaybackDisabled.Value);
AddUntilStep("seek finished, sample playback enabled", () => !gameplayClock.SamplePlaybackDisabled.Value); AddUntilStep("seek finished, sample playback enabled", () => !sampleDisabler.SamplePlaybackDisabled.Value);
AddUntilStep("any sample is playing", () => Player.ChildrenOfType<PausableSkinnableSound>().Any(s => s.IsPlaying)); AddUntilStep("any sample is playing", () => Player.ChildrenOfType<PausableSkinnableSound>().Any(s => s.IsPlaying));
} }

View File

@ -2,29 +2,23 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osuTK.Input; using osuTK.Input;
namespace osu.Game.Tests.Visual.Gameplay namespace osu.Game.Tests.Visual.Gameplay
{ {
public class TestSceneHUDOverlay : SkinnableTestScene public class TestSceneHUDOverlay : OsuManualInputManagerTestScene
{ {
private HUDOverlay hudOverlay; private HUDOverlay hudOverlay;
private IEnumerable<HUDOverlay> hudOverlays => CreatedDrawables.OfType<HUDOverlay>();
// best way to check without exposing. // best way to check without exposing.
private Drawable hideTarget => hudOverlay.KeyCounter; private Drawable hideTarget => hudOverlay.KeyCounter;
private FillFlowContainer<KeyCounter> keyCounterFlow => hudOverlay.KeyCounter.ChildrenOfType<FillFlowContainer<KeyCounter>>().First(); private FillFlowContainer<KeyCounter> keyCounterFlow => hudOverlay.KeyCounter.ChildrenOfType<FillFlowContainer<KeyCounter>>().First();
@ -37,17 +31,9 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
createNew(); createNew();
AddRepeatStep("increase combo", () => AddRepeatStep("increase combo", () => { hudOverlay.ComboCounter.Current.Value++; }, 10);
{
foreach (var hud in hudOverlays)
hud.ComboCounter.Current.Value++;
}, 10);
AddStep("reset combo", () => AddStep("reset combo", () => { hudOverlay.ComboCounter.Current.Value = 0; });
{
foreach (var hud in hudOverlays)
hud.ComboCounter.Current.Value = 0;
});
} }
[Test] [Test]
@ -77,7 +63,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
createNew(); createNew();
AddStep("set showhud false", () => hudOverlays.ForEach(h => h.ShowHud.Value = false)); AddStep("set showhud false", () => hudOverlay.ShowHud.Value = false);
AddUntilStep("hidetarget is hidden", () => !hideTarget.IsPresent); AddUntilStep("hidetarget is hidden", () => !hideTarget.IsPresent);
AddAssert("pause button is still visible", () => hudOverlay.HoldToQuit.IsPresent); AddAssert("pause button is still visible", () => hudOverlay.HoldToQuit.IsPresent);
@ -86,20 +72,42 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("key counter flow not affected", () => keyCounterFlow.IsPresent); AddAssert("key counter flow not affected", () => keyCounterFlow.IsPresent);
} }
[Test]
public void TestMomentaryShowHUD()
{
createNew();
HUDVisibilityMode originalConfigValue = HUDVisibilityMode.HideDuringGameplay;
AddStep("get original config value", () => originalConfigValue = config.Get<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode));
AddStep("set hud to never show", () => config.Set(OsuSetting.HUDVisibilityMode, HUDVisibilityMode.Never));
AddUntilStep("wait for fade", () => !hideTarget.IsPresent);
AddStep("trigger momentary show", () => InputManager.PressKey(Key.ControlLeft));
AddUntilStep("wait for visible", () => hideTarget.IsPresent);
AddStep("stop trigering", () => InputManager.ReleaseKey(Key.ControlLeft));
AddUntilStep("wait for fade", () => !hideTarget.IsPresent);
AddStep("set original config value", () => config.Set(OsuSetting.HUDVisibilityMode, originalConfigValue));
}
[Test] [Test]
public void TestExternalHideDoesntAffectConfig() public void TestExternalHideDoesntAffectConfig()
{ {
bool originalConfigValue = false; HUDVisibilityMode originalConfigValue = HUDVisibilityMode.HideDuringGameplay;
createNew(); createNew();
AddStep("get original config value", () => originalConfigValue = config.Get<bool>(OsuSetting.ShowInterface)); AddStep("get original config value", () => originalConfigValue = config.Get<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode));
AddStep("set showhud false", () => hudOverlay.ShowHud.Value = false); AddStep("set showhud false", () => hudOverlay.ShowHud.Value = false);
AddAssert("config unchanged", () => originalConfigValue == config.Get<bool>(OsuSetting.ShowInterface)); AddAssert("config unchanged", () => originalConfigValue == config.Get<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode));
AddStep("set showhud true", () => hudOverlay.ShowHud.Value = true); AddStep("set showhud true", () => hudOverlay.ShowHud.Value = true);
AddAssert("config unchanged", () => originalConfigValue == config.Get<bool>(OsuSetting.ShowInterface)); AddAssert("config unchanged", () => originalConfigValue == config.Get<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode));
} }
[Test] [Test]
@ -113,14 +121,14 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("set keycounter visible false", () => AddStep("set keycounter visible false", () =>
{ {
config.Set<bool>(OsuSetting.KeyOverlay, false); config.Set<bool>(OsuSetting.KeyOverlay, false);
hudOverlays.ForEach(h => h.KeyCounter.AlwaysVisible.Value = false); hudOverlay.KeyCounter.AlwaysVisible.Value = false;
}); });
AddStep("set showhud false", () => hudOverlays.ForEach(h => h.ShowHud.Value = false)); AddStep("set showhud false", () => hudOverlay.ShowHud.Value = false);
AddUntilStep("hidetarget is hidden", () => !hideTarget.IsPresent); AddUntilStep("hidetarget is hidden", () => !hideTarget.IsPresent);
AddAssert("key counters hidden", () => !keyCounterFlow.IsPresent); AddAssert("key counters hidden", () => !keyCounterFlow.IsPresent);
AddStep("set showhud true", () => hudOverlays.ForEach(h => h.ShowHud.Value = true)); AddStep("set showhud true", () => hudOverlay.ShowHud.Value = true);
AddUntilStep("hidetarget is visible", () => hideTarget.IsPresent); AddUntilStep("hidetarget is visible", () => hideTarget.IsPresent);
AddAssert("key counters still hidden", () => !keyCounterFlow.IsPresent); AddAssert("key counters still hidden", () => !keyCounterFlow.IsPresent);
@ -131,22 +139,17 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
AddStep("create overlay", () => AddStep("create overlay", () =>
{ {
SetContents(() => hudOverlay = new HUDOverlay(null, null, null, Array.Empty<Mod>());
{
hudOverlay = new HUDOverlay(null, null, null, Array.Empty<Mod>());
// Add any key just to display the key counter visually. // Add any key just to display the key counter visually.
hudOverlay.KeyCounter.Add(new KeyCounterKeyboard(Key.Space)); hudOverlay.KeyCounter.Add(new KeyCounterKeyboard(Key.Space));
hudOverlay.ComboCounter.Current.Value = 1; hudOverlay.ComboCounter.Current.Value = 1;
action?.Invoke(hudOverlay); action?.Invoke(hudOverlay);
return hudOverlay; Child = hudOverlay;
});
}); });
} }
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
} }
} }

View File

@ -13,6 +13,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -35,6 +36,8 @@ namespace osu.Game.Tests.Visual.Gameplay
private TestPlayerLoaderContainer container; private TestPlayerLoaderContainer container;
private TestPlayer player; private TestPlayer player;
private bool epilepsyWarning;
[Resolved] [Resolved]
private AudioManager audioManager { get; set; } private AudioManager audioManager { get; set; }
@ -59,6 +62,7 @@ namespace osu.Game.Tests.Visual.Gameplay
beforeLoadAction?.Invoke(); beforeLoadAction?.Invoke();
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
Beatmap.Value.BeatmapInfo.EpilepsyWarning = epilepsyWarning;
foreach (var mod in SelectedMods.Value.OfType<IApplicableToTrack>()) foreach (var mod in SelectedMods.Value.OfType<IApplicableToTrack>())
mod.ApplyToTrack(Beatmap.Value.Track); mod.ApplyToTrack(Beatmap.Value.Track);
@ -251,6 +255,38 @@ namespace osu.Game.Tests.Visual.Gameplay
AddUntilStep("wait for player load", () => player.IsLoaded); AddUntilStep("wait for player load", () => player.IsLoaded);
} }
[TestCase(true)]
[TestCase(false)]
public void TestEpilepsyWarning(bool warning)
{
AddStep("change epilepsy warning", () => epilepsyWarning = warning);
AddStep("load dummy beatmap", () => ResetPlayer(false));
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
AddAssert($"epilepsy warning {(warning ? "present" : "absent")}", () => this.ChildrenOfType<EpilepsyWarning>().Any() == warning);
if (warning)
{
AddUntilStep("sound volume decreased", () => Beatmap.Value.Track.AggregateVolume.Value == 0.25);
AddUntilStep("sound volume restored", () => Beatmap.Value.Track.AggregateVolume.Value == 1);
}
}
[Test]
public void TestEpilepsyWarningEarlyExit()
{
AddStep("set epilepsy warning", () => epilepsyWarning = true);
AddStep("load dummy beatmap", () => ResetPlayer(false));
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
AddUntilStep("wait for epilepsy warning", () => loader.ChildrenOfType<EpilepsyWarning>().Single().Alpha > 0);
AddStep("exit early", () => loader.Exit());
AddUntilStep("sound volume restored", () => Beatmap.Value.Track.AggregateVolume.Value == 1);
}
private class TestPlayerLoaderContainer : Container private class TestPlayerLoaderContainer : Container
{ {
[Cached] [Cached]

View File

@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
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.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
@ -12,11 +13,13 @@ using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges; using osu.Framework.Input.StateChanges;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual.UserInterface; using osu.Game.Tests.Visual.UserInterface;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -33,6 +36,9 @@ namespace osu.Game.Tests.Visual.Gameplay
private TestReplayRecorder recorder; private TestReplayRecorder recorder;
[Cached]
private GameplayBeatmap gameplayBeatmap = new GameplayBeatmap(new Beatmap());
[SetUp] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() =>
{ {
@ -166,6 +172,12 @@ namespace osu.Game.Tests.Visual.Gameplay
playbackManager?.ReplayInputHandler.SetFrameFromTime(Time.Current - 100); playbackManager?.ReplayInputHandler.SetFrameFromTime(Time.Current - 100);
} }
[TearDownSteps]
public void TearDown()
{
AddStep("stop recorder", () => recorder.Expire());
}
public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame> public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame>
{ {
public TestFramedReplayInputHandler(Replay replay) public TestFramedReplayInputHandler(Replay replay)

View File

@ -2,17 +2,20 @@
// 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.Collections.Generic;
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.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges; using osu.Framework.Input.StateChanges;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual.UserInterface; using osu.Game.Tests.Visual.UserInterface;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -25,6 +28,9 @@ namespace osu.Game.Tests.Visual.Gameplay
private readonly TestRulesetInputManager recordingManager; private readonly TestRulesetInputManager recordingManager;
[Cached]
private GameplayBeatmap gameplayBeatmap = new GameplayBeatmap(new Beatmap());
public TestSceneReplayRecording() public TestSceneReplayRecording()
{ {
Replay replay = new Replay(); Replay replay = new Replay();

View File

@ -0,0 +1,99 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneSkinnableHUDOverlay : SkinnableTestScene
{
private HUDOverlay hudOverlay;
private IEnumerable<HUDOverlay> hudOverlays => CreatedDrawables.OfType<HUDOverlay>();
// best way to check without exposing.
private Drawable hideTarget => hudOverlay.KeyCounter;
private FillFlowContainer<KeyCounter> keyCounterFlow => hudOverlay.KeyCounter.ChildrenOfType<FillFlowContainer<KeyCounter>>().First();
[Resolved]
private OsuConfigManager config { get; set; }
[Test]
public void TestComboCounterIncrementing()
{
createNew();
AddRepeatStep("increase combo", () =>
{
foreach (var hud in hudOverlays)
hud.ComboCounter.Current.Value++;
}, 10);
AddStep("reset combo", () =>
{
foreach (var hud in hudOverlays)
hud.ComboCounter.Current.Value = 0;
});
}
[Test]
public void TestFadesInOnLoadComplete()
{
float? initialAlpha = null;
createNew(h => h.OnLoadComplete += _ => initialAlpha = hideTarget.Alpha);
AddUntilStep("wait for load", () => hudOverlay.IsAlive);
AddAssert("initial alpha was less than 1", () => initialAlpha < 1);
}
[Test]
public void TestHideExternally()
{
createNew();
AddStep("set showhud false", () => hudOverlays.ForEach(h => h.ShowHud.Value = false));
AddUntilStep("hidetarget is hidden", () => !hideTarget.IsPresent);
AddAssert("pause button is still visible", () => hudOverlay.HoldToQuit.IsPresent);
// Key counter flow container should not be affected by this, only the key counter display will be hidden as checked above.
AddAssert("key counter flow not affected", () => keyCounterFlow.IsPresent);
}
private void createNew(Action<HUDOverlay> action = null)
{
AddStep("create overlay", () =>
{
SetContents(() =>
{
hudOverlay = new HUDOverlay(null, null, null, Array.Empty<Mod>());
// Add any key just to display the key counter visually.
hudOverlay.KeyCounter.Add(new KeyCounterKeyboard(Key.Space));
hudOverlay.ComboCounter.Current.Value = 1;
action?.Invoke(hudOverlay);
return hudOverlay;
});
});
}
protected override Ruleset CreateRulesetForSkinProvider() => new OsuRuleset();
}
}

View File

@ -34,7 +34,7 @@ namespace osu.Game.Tests.Visual.Gameplay
skinSource = new TestSkinSourceContainer skinSource = new TestSkinSourceContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = skinnableSound = new PausableSkinnableSound(new SampleInfo("normal-sliderslide")) Child = skinnableSound = new PausableSkinnableSound(new SampleInfo("Gameplay/normal-sliderslide"))
}, },
}; };
}); });

View File

@ -0,0 +1,361 @@
// 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.Collections.Specialized;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges;
using osu.Framework.Logging;
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.Spectator;
using osu.Game.Replays;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Replays.Types;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual.UserInterface;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneSpectatorPlayback : OsuManualInputManagerTestScene
{
protected override bool UseOnlineAPI => true;
private TestRulesetInputManager playbackManager;
private TestRulesetInputManager recordingManager;
private Replay replay;
private IBindableList<int> users;
private TestReplayRecorder recorder;
private readonly ManualClock manualClock = new ManualClock();
private OsuSpriteText latencyDisplay;
private TestFramedReplayInputHandler replayHandler;
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private SpectatorStreamingClient streamingClient { get; set; }
[Cached]
private GameplayBeatmap gameplayBeatmap = new GameplayBeatmap(new Beatmap());
[SetUp]
public void SetUp() => Schedule(() =>
{
replay = new Replay();
users = streamingClient.PlayingUsers.GetBoundCopy();
users.BindCollectionChanged((obj, args) =>
{
switch (args.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (int user in args.NewItems)
{
if (user == api.LocalUser.Value.Id)
streamingClient.WatchUser(user);
}
break;
case NotifyCollectionChangedAction.Remove:
foreach (int user in args.OldItems)
{
if (user == api.LocalUser.Value.Id)
streamingClient.StopWatchingUser(user);
}
break;
}
}, true);
streamingClient.OnNewFrames += onNewFrames;
Add(new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
recordingManager = new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
{
Recorder = recorder = new TestReplayRecorder
{
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos),
},
Child = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
Colour = Color4.Brown,
RelativeSizeAxes = Axes.Both,
},
new OsuSpriteText
{
Text = "Sending",
Scale = new Vector2(3),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
new TestInputConsumer()
}
},
}
},
new Drawable[]
{
playbackManager = new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
{
Clock = new FramedClock(manualClock),
ReplayInputHandler = replayHandler = new TestFramedReplayInputHandler(replay)
{
GamefieldToScreenSpace = pos => playbackManager.ToScreenSpace(pos),
},
Child = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
Colour = Color4.DarkBlue,
RelativeSizeAxes = Axes.Both,
},
new OsuSpriteText
{
Text = "Receiving",
Scale = new Vector2(3),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
new TestInputConsumer()
}
},
}
}
}
});
Add(latencyDisplay = new OsuSpriteText());
});
private void onNewFrames(int userId, FrameDataBundle frames)
{
Logger.Log($"Received {frames.Frames.Count()} new frames ({string.Join(',', frames.Frames.Select(f => ((int)f.Time).ToString()))})");
foreach (var legacyFrame in frames.Frames)
{
var frame = new TestReplayFrame();
frame.FromLegacy(legacyFrame, null, null);
replay.Frames.Add(frame);
}
}
[Test]
public void TestBasic()
{
}
private double latency = SpectatorStreamingClient.TIME_BETWEEN_SENDS;
protected override void Update()
{
base.Update();
if (latencyDisplay == null) return;
// propagate initial time value
if (manualClock.CurrentTime == 0)
{
manualClock.CurrentTime = Time.Current;
return;
}
if (replayHandler.NextFrame != null)
{
var lastFrame = replay.Frames.LastOrDefault();
// this isn't perfect as we basically can't be aware of the rate-of-send here (the streamer is not sending data when not being moved).
// in gameplay playback, the case where NextFrame is null would pause gameplay and handle this correctly; it's strictly a test limitation / best effort implementation.
if (lastFrame != null)
latency = Math.Max(latency, Time.Current - lastFrame.Time);
latencyDisplay.Text = $"latency: {latency:N1}";
double proposedTime = Time.Current - latency + Time.Elapsed;
// this will either advance by one or zero frames.
double? time = replayHandler.SetFrameFromTime(proposedTime);
if (time == null)
return;
manualClock.CurrentTime = time.Value;
}
}
[TearDownSteps]
public void TearDown()
{
AddStep("stop recorder", () =>
{
recorder.Expire();
streamingClient.OnNewFrames -= onNewFrames;
});
}
public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame>
{
public TestFramedReplayInputHandler(Replay replay)
: base(replay)
{
}
public override void CollectPendingInputs(List<IInput> inputs)
{
inputs.Add(new MousePositionAbsoluteInput { Position = GamefieldToScreenSpace(CurrentFrame?.Position ?? Vector2.Zero) });
inputs.Add(new ReplayState<TestAction> { PressedActions = CurrentFrame?.Actions ?? new List<TestAction>() });
}
}
public class TestInputConsumer : CompositeDrawable, IKeyBindingHandler<TestAction>
{
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent.ReceivePositionalInputAt(screenSpacePos);
private readonly Box box;
public TestInputConsumer()
{
Size = new Vector2(30);
Origin = Anchor.Centre;
InternalChildren = new Drawable[]
{
box = new Box
{
Colour = Color4.Black,
RelativeSizeAxes = Axes.Both,
},
};
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
Position = e.MousePosition;
return base.OnMouseMove(e);
}
public bool OnPressed(TestAction action)
{
box.Colour = Color4.White;
return true;
}
public void OnReleased(TestAction action)
{
box.Colour = Color4.Black;
}
}
public class TestRulesetInputManager : RulesetInputManager<TestAction>
{
public TestRulesetInputManager(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
: base(ruleset, variant, unique)
{
}
protected override KeyBindingContainer<TestAction> CreateKeyBindingContainer(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
=> new TestKeyBindingContainer();
internal class TestKeyBindingContainer : KeyBindingContainer<TestAction>
{
public override IEnumerable<KeyBinding> DefaultKeyBindings => new[]
{
new KeyBinding(InputKey.MouseLeft, TestAction.Down),
};
}
}
public class TestReplayFrame : ReplayFrame, IConvertibleReplayFrame
{
public Vector2 Position;
public List<TestAction> Actions = new List<TestAction>();
public TestReplayFrame(double time, Vector2 position, params TestAction[] actions)
: base(time)
{
Position = position;
Actions.AddRange(actions);
}
public TestReplayFrame()
{
}
public void FromLegacy(LegacyReplayFrame currentFrame, IBeatmap beatmap, ReplayFrame lastFrame = null)
{
Position = currentFrame.Position;
Time = currentFrame.Time;
if (currentFrame.MouseLeft)
Actions.Add(TestAction.Down);
}
public LegacyReplayFrame ToLegacy(IBeatmap beatmap)
{
ReplayButtonState state = ReplayButtonState.None;
if (Actions.Contains(TestAction.Down))
state |= ReplayButtonState.Left1;
return new LegacyReplayFrame(Time, Position.X, Position.Y, state);
}
}
public enum TestAction
{
Down,
}
internal class TestReplayRecorder : ReplayRecorder<TestAction>
{
public TestReplayRecorder()
: base(new Replay())
{
}
protected override ReplayFrame HandleFrame(Vector2 mousePosition, List<TestAction> actions, ReplayFrame previousFrame)
{
return new TestReplayFrame(Time.Current, mousePosition, actions.ToArray());
}
}
}
}

View File

@ -135,7 +135,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true); public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
public IBindableList<Room> Rooms { get; } = null; public IBindableList<Room> Rooms => null;
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
{ {

View File

@ -3,14 +3,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics.Containers;
using osu.Game.Overlays.Dashboard.Friends;
using osu.Framework.Graphics;
using osu.Game.Users;
using osu.Game.Overlays;
using osu.Framework.Allocation;
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Online.API; using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Overlays;
using osu.Game.Overlays.Dashboard.Friends;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -36,7 +35,7 @@ namespace osu.Game.Tests.Visual.Online
[Test] [Test]
public void TestOffline() public void TestOffline()
{ {
AddStep("Populate", () => display.Users = getUsers()); AddStep("Populate with offline test users", () => display.Users = getUsers());
} }
[Test] [Test]
@ -80,14 +79,7 @@ namespace osu.Game.Tests.Visual.Online
private class TestFriendDisplay : FriendDisplay private class TestFriendDisplay : FriendDisplay
{ {
public void Fetch() public void Fetch() => PerformFetch();
{
base.APIStateChanged(API, APIState.Online);
}
public override void APIStateChanged(IAPIProvider api, APIState state)
{
}
} }
} }
} }

View File

@ -32,7 +32,7 @@ namespace osu.Game.Tests.Visual.Online
[Test] [Test]
public void TestOnlineStateVisibility() public void TestOnlineStateVisibility()
{ {
AddStep("set status to online", () => ((DummyAPIAccess)API).State = APIState.Online); AddStep("set status to online", () => ((DummyAPIAccess)API).SetState(APIState.Online));
AddUntilStep("children are visible", () => onlineView.ViewTarget.IsPresent); AddUntilStep("children are visible", () => onlineView.ViewTarget.IsPresent);
AddUntilStep("loading animation is not visible", () => !onlineView.LoadingSpinner.IsPresent); AddUntilStep("loading animation is not visible", () => !onlineView.LoadingSpinner.IsPresent);
@ -41,7 +41,7 @@ namespace osu.Game.Tests.Visual.Online
[Test] [Test]
public void TestOfflineStateVisibility() public void TestOfflineStateVisibility()
{ {
AddStep("set status to offline", () => ((DummyAPIAccess)API).State = APIState.Offline); AddStep("set status to offline", () => ((DummyAPIAccess)API).SetState(APIState.Offline));
AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent); AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent);
AddUntilStep("loading animation is not visible", () => !onlineView.LoadingSpinner.IsPresent); AddUntilStep("loading animation is not visible", () => !onlineView.LoadingSpinner.IsPresent);
@ -50,7 +50,7 @@ namespace osu.Game.Tests.Visual.Online
[Test] [Test]
public void TestConnectingStateVisibility() public void TestConnectingStateVisibility()
{ {
AddStep("set status to connecting", () => ((DummyAPIAccess)API).State = APIState.Connecting); AddStep("set status to connecting", () => ((DummyAPIAccess)API).SetState(APIState.Connecting));
AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent); AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent);
AddUntilStep("loading animation is visible", () => onlineView.LoadingSpinner.IsPresent); AddUntilStep("loading animation is visible", () => onlineView.LoadingSpinner.IsPresent);
@ -59,7 +59,7 @@ namespace osu.Game.Tests.Visual.Online
[Test] [Test]
public void TestFailingStateVisibility() public void TestFailingStateVisibility()
{ {
AddStep("set status to failing", () => ((DummyAPIAccess)API).State = APIState.Failing); AddStep("set status to failing", () => ((DummyAPIAccess)API).SetState(APIState.Failing));
AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent); AddUntilStep("children are not visible", () => !onlineView.ViewTarget.IsPresent);
AddUntilStep("loading animation is visible", () => onlineView.LoadingSpinner.IsPresent); AddUntilStep("loading animation is visible", () => onlineView.LoadingSpinner.IsPresent);

View File

@ -120,7 +120,7 @@ namespace osu.Game.Tests.Visual.Ranking
} }
} }
}, },
new AccuracyCircle(score) new AccuracyCircle(score, true)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,

View File

@ -103,7 +103,7 @@ namespace osu.Game.Tests.Visual.Ranking
private void addPanelStep(ScoreInfo score, PanelState state = PanelState.Expanded) => AddStep("add panel", () => private void addPanelStep(ScoreInfo score, PanelState state = PanelState.Expanded) => AddStep("add panel", () =>
{ {
Child = panel = new ScorePanel(score) Child = panel = new ScorePanel(score, true)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,

View File

@ -18,13 +18,13 @@ namespace osu.Game.Tests.Visual.Ranking
Origin = Anchor.Centre, Origin = Anchor.Centre,
Children = new Drawable[] Children = new Drawable[]
{ {
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 1.23 }), new StarRatingDisplay(new StarDifficulty(1.23, 0)),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 2.34 }), new StarRatingDisplay(new StarDifficulty(2.34, 0)),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 3.45 }), new StarRatingDisplay(new StarDifficulty(3.45, 0)),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 4.56 }), new StarRatingDisplay(new StarDifficulty(4.56, 0)),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 5.67 }), new StarRatingDisplay(new StarDifficulty(5.67, 0)),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 6.78 }), new StarRatingDisplay(new StarDifficulty(6.78, 0)),
new StarRatingDisplay(new BeatmapInfo { StarDifficulty = 10.11 }), new StarRatingDisplay(new StarDifficulty(10.11, 0)),
} }
}; };
} }

View File

@ -11,6 +11,7 @@ using osu.Framework.Allocation;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -40,6 +41,12 @@ namespace osu.Game.Tests.Visual.SongSelect
this.rulesets = rulesets; this.rulesets = rulesets;
} }
[Test]
public void TestManyPanels()
{
loadBeatmaps(count: 5000, randomDifficulties: true);
}
[Test] [Test]
public void TestKeyRepeat() public void TestKeyRepeat()
{ {
@ -707,21 +714,22 @@ namespace osu.Game.Tests.Visual.SongSelect
checkVisibleItemCount(true, 15); checkVisibleItemCount(true, 15);
} }
private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets = null, Func<FilterCriteria> initialCriteria = null, Action<BeatmapCarousel> carouselAdjust = null) private void loadBeatmaps(List<BeatmapSetInfo> beatmapSets = null, Func<FilterCriteria> initialCriteria = null, Action<BeatmapCarousel> carouselAdjust = null, int? count = null, bool randomDifficulties = false)
{ {
createCarousel(carouselAdjust);
if (beatmapSets == null)
{
beatmapSets = new List<BeatmapSetInfo>();
for (int i = 1; i <= set_count; i++)
beatmapSets.Add(createTestBeatmapSet(i));
}
bool changed = false; bool changed = false;
AddStep($"Load {(beatmapSets.Count > 0 ? beatmapSets.Count.ToString() : "some")} beatmaps", () =>
createCarousel(c =>
{ {
carouselAdjust?.Invoke(c);
if (beatmapSets == null)
{
beatmapSets = new List<BeatmapSetInfo>();
for (int i = 1; i <= (count ?? set_count); i++)
beatmapSets.Add(createTestBeatmapSet(i, randomDifficulties));
}
carousel.Filter(initialCriteria?.Invoke() ?? new FilterCriteria()); carousel.Filter(initialCriteria?.Invoke() ?? new FilterCriteria());
carousel.BeatmapSetsChanged = () => changed = true; carousel.BeatmapSetsChanged = () => changed = true;
carousel.BeatmapSets = beatmapSets; carousel.BeatmapSets = beatmapSets;
@ -807,7 +815,7 @@ namespace osu.Game.Tests.Visual.SongSelect
private bool selectedBeatmapVisible() private bool selectedBeatmapVisible()
{ {
var currentlySelected = carousel.Items.Find(s => s.Item is CarouselBeatmap && s.Item.State.Value == CarouselItemState.Selected); var currentlySelected = carousel.Items.FirstOrDefault(s => s.Item is CarouselBeatmap && s.Item.State.Value == CarouselItemState.Selected);
if (currentlySelected == null) if (currentlySelected == null)
return true; return true;
@ -820,7 +828,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("Selection is visible", selectedBeatmapVisible); AddAssert("Selection is visible", selectedBeatmapVisible);
} }
private BeatmapSetInfo createTestBeatmapSet(int id) private BeatmapSetInfo createTestBeatmapSet(int id, bool randomDifficultyCount = false)
{ {
return new BeatmapSetInfo return new BeatmapSetInfo
{ {
@ -834,42 +842,37 @@ namespace osu.Game.Tests.Visual.SongSelect
Title = $"test set #{id}!", Title = $"test set #{id}!",
AuthorString = string.Concat(Enumerable.Repeat((char)('z' - Math.Min(25, id - 1)), 5)) AuthorString = string.Concat(Enumerable.Repeat((char)('z' - Math.Min(25, id - 1)), 5))
}, },
Beatmaps = new List<BeatmapInfo>(new[] Beatmaps = getBeatmaps(randomDifficultyCount ? RNG.Next(1, 20) : 3).ToList()
{
new BeatmapInfo
{
OnlineBeatmapID = id * 10,
Version = "Normal",
StarDifficulty = 2,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = 3.5f,
}
},
new BeatmapInfo
{
OnlineBeatmapID = id * 10 + 1,
Version = "Hard",
StarDifficulty = 5,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = 5,
}
},
new BeatmapInfo
{
OnlineBeatmapID = id * 10 + 2,
Version = "Insane",
StarDifficulty = 6,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = 7,
}
},
}),
}; };
} }
private IEnumerable<BeatmapInfo> getBeatmaps(int count)
{
int id = 0;
for (int i = 0; i < count; i++)
{
float diff = (float)i / count * 10;
string version = "Normal";
if (diff > 6.6)
version = "Insane";
else if (diff > 3.3)
version = "Hard";
yield return new BeatmapInfo
{
OnlineBeatmapID = id++ * 10,
Version = version,
StarDifficulty = diff,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = diff,
}
};
}
}
private BeatmapSetInfo createTestBeatmapSetWithManyDifficulties(int id) private BeatmapSetInfo createTestBeatmapSetWithManyDifficulties(int id)
{ {
var toReturn = new BeatmapSetInfo var toReturn = new BeatmapSetInfo
@ -908,10 +911,25 @@ namespace osu.Game.Tests.Visual.SongSelect
private class TestBeatmapCarousel : BeatmapCarousel private class TestBeatmapCarousel : BeatmapCarousel
{ {
public new List<DrawableCarouselItem> Items => base.Items;
public bool PendingFilterTask => PendingFilter != null; public bool PendingFilterTask => PendingFilter != null;
public IEnumerable<DrawableCarouselItem> Items
{
get
{
foreach (var item in ScrollableContent)
{
yield return item;
if (item is DrawableCarouselBeatmapSet set)
{
foreach (var difficulty in set.DrawableBeatmaps)
yield return difficulty;
}
}
}
}
protected override IEnumerable<BeatmapSetInfo> GetLoadableBeatmaps() => Enumerable.Empty<BeatmapSetInfo>(); protected override IEnumerable<BeatmapSetInfo> GetLoadableBeatmaps() => Enumerable.Empty<BeatmapSetInfo>();
} }
} }

View File

@ -197,8 +197,8 @@ namespace osu.Game.Tests.Visual.SongSelect
private class TestHitObject : ConvertHitObject, IHasPosition private class TestHitObject : ConvertHitObject, IHasPosition
{ {
public float X { get; } = 0; public float X => 0;
public float Y { get; } = 0; public float Y => 0;
public Vector2 Position { get; } = Vector2.Zero; public Vector2 Position { get; } = Vector2.Zero;
} }
} }

View File

@ -507,7 +507,7 @@ namespace osu.Game.Tests.Visual.SongSelect
var selectedPanel = songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet>().First(s => s.Item.State.Value == CarouselItemState.Selected); var selectedPanel = songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet>().First(s => s.Item.State.Value == CarouselItemState.Selected);
// special case for converts checked here. // special case for converts checked here.
return selectedPanel.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>().All(i => return selectedPanel.ChildrenOfType<FilterableDifficultyIcon>().All(i =>
i.IsFiltered || i.Item.Beatmap.Ruleset.ID == targetRuleset || i.Item.Beatmap.Ruleset.ID == 0); i.IsFiltered || i.Item.Beatmap.Ruleset.ID == targetRuleset || i.Item.Beatmap.Ruleset.ID == 0);
}); });
@ -606,10 +606,10 @@ namespace osu.Game.Tests.Visual.SongSelect
set = songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet>().First(); set = songSelect.Carousel.ChildrenOfType<DrawableCarouselBeatmapSet>().First();
}); });
DrawableCarouselBeatmapSet.FilterableDifficultyIcon difficultyIcon = null; FilterableDifficultyIcon difficultyIcon = null;
AddStep("Find an icon", () => AddStep("Find an icon", () =>
{ {
difficultyIcon = set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>() difficultyIcon = set.ChildrenOfType<FilterableDifficultyIcon>()
.First(icon => getDifficultyIconIndex(set, icon) != getCurrentBeatmapIndex()); .First(icon => getDifficultyIconIndex(set, icon) != getCurrentBeatmapIndex());
}); });
@ -634,13 +634,13 @@ namespace osu.Game.Tests.Visual.SongSelect
})); }));
BeatmapInfo filteredBeatmap = null; BeatmapInfo filteredBeatmap = null;
DrawableCarouselBeatmapSet.FilterableDifficultyIcon filteredIcon = null; FilterableDifficultyIcon filteredIcon = null;
AddStep("Get filtered icon", () => AddStep("Get filtered icon", () =>
{ {
filteredBeatmap = songSelect.Carousel.SelectedBeatmapSet.Beatmaps.First(b => b.BPM < maxBPM); filteredBeatmap = songSelect.Carousel.SelectedBeatmapSet.Beatmaps.First(b => b.BPM < maxBPM);
int filteredBeatmapIndex = getBeatmapIndex(filteredBeatmap.BeatmapSet, filteredBeatmap); int filteredBeatmapIndex = getBeatmapIndex(filteredBeatmap.BeatmapSet, filteredBeatmap);
filteredIcon = set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>().ElementAt(filteredBeatmapIndex); filteredIcon = set.ChildrenOfType<FilterableDifficultyIcon>().ElementAt(filteredBeatmapIndex);
}); });
AddStep("Click on a filtered difficulty", () => AddStep("Click on a filtered difficulty", () =>
@ -674,10 +674,10 @@ namespace osu.Game.Tests.Visual.SongSelect
return set != null; return set != null;
}); });
DrawableCarouselBeatmapSet.FilterableDifficultyIcon difficultyIcon = null; FilterableDifficultyIcon difficultyIcon = null;
AddStep("Find an icon for different ruleset", () => AddStep("Find an icon for different ruleset", () =>
{ {
difficultyIcon = set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>() difficultyIcon = set.ChildrenOfType<FilterableDifficultyIcon>()
.First(icon => icon.Item.Beatmap.Ruleset.ID == 3); .First(icon => icon.Item.Beatmap.Ruleset.ID == 3);
}); });
@ -725,10 +725,10 @@ namespace osu.Game.Tests.Visual.SongSelect
return set != null; return set != null;
}); });
DrawableCarouselBeatmapSet.FilterableGroupedDifficultyIcon groupIcon = null; FilterableGroupedDifficultyIcon groupIcon = null;
AddStep("Find group icon for different ruleset", () => AddStep("Find group icon for different ruleset", () =>
{ {
groupIcon = set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableGroupedDifficultyIcon>() groupIcon = set.ChildrenOfType<FilterableGroupedDifficultyIcon>()
.First(icon => icon.Items.First().Beatmap.Ruleset.ID == 3); .First(icon => icon.Items.First().Beatmap.Ruleset.ID == 3);
}); });
@ -821,9 +821,9 @@ namespace osu.Game.Tests.Visual.SongSelect
private int getCurrentBeatmapIndex() => getBeatmapIndex(songSelect.Carousel.SelectedBeatmapSet, songSelect.Carousel.SelectedBeatmap); private int getCurrentBeatmapIndex() => getBeatmapIndex(songSelect.Carousel.SelectedBeatmapSet, songSelect.Carousel.SelectedBeatmap);
private int getDifficultyIconIndex(DrawableCarouselBeatmapSet set, DrawableCarouselBeatmapSet.FilterableDifficultyIcon icon) private int getDifficultyIconIndex(DrawableCarouselBeatmapSet set, FilterableDifficultyIcon icon)
{ {
return set.ChildrenOfType<DrawableCarouselBeatmapSet.FilterableDifficultyIcon>().ToList().FindIndex(i => i == icon); return set.ChildrenOfType<FilterableDifficultyIcon>().ToList().FindIndex(i => i == icon);
} }
private void addRulesetImportStep(int id) => AddStep($"import test map for ruleset {id}", () => importForRuleset(id)); private void addRulesetImportStep(int id) => AddStep($"import test map for ruleset {id}", () => importForRuleset(id));

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -27,6 +28,9 @@ namespace osu.Game.Tests.Visual.UserInterface
OsuSpriteText category; OsuSpriteText category;
OsuSpriteText genre; OsuSpriteText genre;
OsuSpriteText language; OsuSpriteText language;
OsuSpriteText extra;
OsuSpriteText ranks;
OsuSpriteText played;
Add(control = new BeatmapListingSearchControl Add(control = new BeatmapListingSearchControl
{ {
@ -46,6 +50,9 @@ namespace osu.Game.Tests.Visual.UserInterface
category = new OsuSpriteText(), category = new OsuSpriteText(),
genre = new OsuSpriteText(), genre = new OsuSpriteText(),
language = new OsuSpriteText(), language = new OsuSpriteText(),
extra = new OsuSpriteText(),
ranks = new OsuSpriteText(),
played = new OsuSpriteText()
} }
}); });
@ -54,6 +61,9 @@ namespace osu.Game.Tests.Visual.UserInterface
control.Category.BindValueChanged(c => category.Text = $"Category: {c.NewValue}", true); control.Category.BindValueChanged(c => category.Text = $"Category: {c.NewValue}", true);
control.Genre.BindValueChanged(g => genre.Text = $"Genre: {g.NewValue}", true); control.Genre.BindValueChanged(g => genre.Text = $"Genre: {g.NewValue}", true);
control.Language.BindValueChanged(l => language.Text = $"Language: {l.NewValue}", true); control.Language.BindValueChanged(l => language.Text = $"Language: {l.NewValue}", true);
control.Extra.BindCollectionChanged((u, v) => extra.Text = $"Extra: {(control.Extra.Any() ? string.Join('.', control.Extra.Select(i => i.ToString().ToLowerInvariant())) : "")}", true);
control.Ranks.BindCollectionChanged((u, v) => ranks.Text = $"Ranks: {(control.Ranks.Any() ? string.Join('.', control.Ranks.Select(i => i.ToString())) : "")}", true);
control.Played.BindValueChanged(p => played.Text = $"Played: {p.NewValue}", true);
} }
[Test] [Test]

View File

@ -4,19 +4,24 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.Tournament.Models; using osu.Game.Tournament.Models;
using osuTK;
namespace osu.Game.Tournament.Components namespace osu.Game.Tournament.Components
{ {
public class DrawableTeamFlag : Sprite public class DrawableTeamFlag : Container
{ {
private readonly TournamentTeam team; private readonly TournamentTeam team;
[UsedImplicitly] [UsedImplicitly]
private Bindable<string> flag; private Bindable<string> flag;
private Sprite flagSprite;
public DrawableTeamFlag(TournamentTeam team) public DrawableTeamFlag(TournamentTeam team)
{ {
this.team = team; this.team = team;
@ -27,7 +32,18 @@ namespace osu.Game.Tournament.Components
{ {
if (team == null) return; if (team == null) return;
(flag = team.FlagName.GetBoundCopy()).BindValueChanged(acronym => Texture = textures.Get($@"Flags/{team.FlagName}"), true); Size = new Vector2(75, 50);
Masking = true;
CornerRadius = 5;
Child = flagSprite = new Sprite
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill
};
(flag = team.FlagName.GetBoundCopy()).BindValueChanged(acronym => flagSprite.Texture = textures.Get($@"Flags/{team.FlagName}"), true);
} }
} }
} }

View File

@ -4,9 +4,7 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Tournament.Models; using osu.Game.Tournament.Models;
@ -17,7 +15,7 @@ namespace osu.Game.Tournament.Components
{ {
public readonly TournamentTeam Team; public readonly TournamentTeam Team;
protected readonly Sprite Flag; protected readonly Container Flag;
protected readonly TournamentSpriteText AcronymText; protected readonly TournamentSpriteText AcronymText;
[UsedImplicitly] [UsedImplicitly]
@ -27,12 +25,7 @@ namespace osu.Game.Tournament.Components
{ {
Team = team; Team = team;
Flag = new DrawableTeamFlag(team) Flag = new DrawableTeamFlag(team);
{
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit
};
AcronymText = new TournamentSpriteText AcronymText = new TournamentSpriteText
{ {
Font = OsuFont.Torus.With(weight: FontWeight.Regular), Font = OsuFont.Torus.With(weight: FontWeight.Regular),

View File

@ -27,6 +27,7 @@ namespace osu.Game.Tournament.Screens.Drawings.Components
AcronymText.Origin = Anchor.TopCentre; AcronymText.Origin = Anchor.TopCentre;
AcronymText.Text = team.Acronym.Value.ToUpperInvariant(); AcronymText.Text = team.Acronym.Value.ToUpperInvariant();
AcronymText.Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 10); AcronymText.Font = OsuFont.Torus.With(weight: FontWeight.Bold, size: 10);
Flag.Scale = new Vector2(0.48f);
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {

View File

@ -29,7 +29,7 @@ namespace osu.Game.Tournament.Screens.Gameplay.Components
var anchor = flip ? Anchor.TopLeft : Anchor.TopRight; var anchor = flip ? Anchor.TopLeft : Anchor.TopRight;
Flag.RelativeSizeAxes = Axes.None; Flag.RelativeSizeAxes = Axes.None;
Flag.Size = new Vector2(60, 40); Flag.Scale = new Vector2(0.8f);
Flag.Origin = anchor; Flag.Origin = anchor;
Flag.Anchor = anchor; Flag.Anchor = anchor;

View File

@ -63,7 +63,7 @@ namespace osu.Game.Tournament.Screens.Ladder.Components
this.losers = losers; this.losers = losers;
Size = new Vector2(150, 40); Size = new Vector2(150, 40);
Flag.Scale = new Vector2(0.9f); Flag.Scale = new Vector2(0.54f);
Flag.Anchor = Flag.Origin = Anchor.CentreLeft; Flag.Anchor = Flag.Origin = Anchor.CentreLeft;
AcronymText.Anchor = AcronymText.Origin = Anchor.CentreLeft; AcronymText.Anchor = AcronymText.Origin = Anchor.CentreLeft;

View File

@ -288,8 +288,7 @@ namespace osu.Game.Tournament.Screens.TeamIntro
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Flag.RelativeSizeAxes = Axes.None; Flag.RelativeSizeAxes = Axes.None;
Flag.Size = new Vector2(300, 200); Flag.Scale = new Vector2(1.2f);
Flag.Scale = new Vector2(0.3f);
InternalChild = new FillFlowContainer InternalChild = new FillFlowContainer
{ {

View File

@ -90,11 +90,10 @@ namespace osu.Game.Tournament.Screens.TeamWin
{ {
new DrawableTeamFlag(match.Winner) new DrawableTeamFlag(match.Winner)
{ {
Size = new Vector2(300, 200),
Scale = new Vector2(0.5f),
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Position = new Vector2(-300, 10), Position = new Vector2(-300, 10),
Scale = new Vector2(2f)
}, },
new FillFlowContainer new FillFlowContainer
{ {

View File

@ -50,9 +50,9 @@ namespace osu.Game.Audio
get get
{ {
if (!string.IsNullOrEmpty(Suffix)) if (!string.IsNullOrEmpty(Suffix))
yield return $"{Bank}-{Name}{Suffix}"; yield return $"Gameplay/{Bank}-{Name}{Suffix}";
yield return $"{Bank}-{Name}"; yield return $"Gameplay/{Bank}-{Name}";
} }
} }

View File

@ -10,14 +10,14 @@ namespace osu.Game.Audio
/// </summary> /// </summary>
public class SampleInfo : ISampleInfo public class SampleInfo : ISampleInfo
{ {
private readonly string sampleName; private readonly string[] sampleNames;
public SampleInfo(string sampleName) public SampleInfo(params string[] sampleNames)
{ {
this.sampleName = sampleName; this.sampleNames = sampleNames;
} }
public IEnumerable<string> LookupNames => new[] { sampleName }; public IEnumerable<string> LookupNames => sampleNames;
public int Volume { get; } = 100; public int Volume { get; } = 100;
} }

View File

@ -92,6 +92,7 @@ namespace osu.Game.Beatmaps
public bool LetterboxInBreaks { get; set; } public bool LetterboxInBreaks { get; set; }
public bool WidescreenStoryboard { get; set; } public bool WidescreenStoryboard { get; set; }
public bool EpilepsyWarning { get; set; }
// Editor // Editor
// This bookmarks stuff is necessary because DB doesn't know how to store int[] // This bookmarks stuff is necessary because DB doesn't know how to store int[]

View File

@ -63,7 +63,7 @@ namespace osu.Game.Beatmaps
if (checkLocalCache(set, beatmap)) if (checkLocalCache(set, beatmap))
return; return;
if (api?.State != APIState.Online) if (api?.State.Value != APIState.Online)
return; return;
var req = new GetBeatmapRequest(beatmap); var req = new GetBeatmapRequest(beatmap);

View File

@ -47,7 +47,10 @@ namespace osu.Game.Beatmaps.Drawables
private readonly IReadOnlyList<Mod> mods; private readonly IReadOnlyList<Mod> mods;
private readonly bool shouldShowTooltip; private readonly bool shouldShowTooltip;
private readonly IBindable<StarDifficulty> difficultyBindable = new Bindable<StarDifficulty>();
private readonly bool performBackgroundDifficultyLookup;
private readonly Bindable<StarDifficulty> difficultyBindable = new Bindable<StarDifficulty>();
private Drawable background; private Drawable background;
@ -70,10 +73,12 @@ namespace osu.Game.Beatmaps.Drawables
/// </summary> /// </summary>
/// <param name="beatmap">The beatmap to show the difficulty of.</param> /// <param name="beatmap">The beatmap to show the difficulty of.</param>
/// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param> /// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param>
public DifficultyIcon([NotNull] BeatmapInfo beatmap, bool shouldShowTooltip = true) /// <param name="performBackgroundDifficultyLookup">Whether to perform difficulty lookup (including calculation if necessary).</param>
public DifficultyIcon([NotNull] BeatmapInfo beatmap, bool shouldShowTooltip = true, bool performBackgroundDifficultyLookup = true)
{ {
this.beatmap = beatmap ?? throw new ArgumentNullException(nameof(beatmap)); this.beatmap = beatmap ?? throw new ArgumentNullException(nameof(beatmap));
this.shouldShowTooltip = shouldShowTooltip; this.shouldShowTooltip = shouldShowTooltip;
this.performBackgroundDifficultyLookup = performBackgroundDifficultyLookup;
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
@ -112,9 +117,13 @@ namespace osu.Game.Beatmaps.Drawables
// the null coalesce here is only present to make unit tests work (ruleset dlls aren't copied correctly for testing at the moment) // the null coalesce here is only present to make unit tests work (ruleset dlls aren't copied correctly for testing at the moment)
Icon = (ruleset ?? beatmap.Ruleset)?.CreateInstance()?.CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle } Icon = (ruleset ?? beatmap.Ruleset)?.CreateInstance()?.CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle }
}, },
new DelayedLoadUnloadWrapper(() => new DifficultyRetriever(beatmap, ruleset, mods) { StarDifficulty = { BindTarget = difficultyBindable } }, 0),
}; };
if (performBackgroundDifficultyLookup)
iconContainer.Add(new DelayedLoadUnloadWrapper(() => new DifficultyRetriever(beatmap, ruleset, mods) { StarDifficulty = { BindTarget = difficultyBindable } }, 0));
else
difficultyBindable.Value = new StarDifficulty(beatmap.StarDifficulty, 0);
difficultyBindable.BindValueChanged(difficulty => background.Colour = colours.ForDifficultyRating(difficulty.NewValue.DifficultyRating)); difficultyBindable.BindValueChanged(difficulty => background.Colour = colours.ForDifficultyRating(difficulty.NewValue.DifficultyRating));
} }

View File

@ -175,6 +175,10 @@ namespace osu.Game.Beatmaps.Formats
case @"WidescreenStoryboard": case @"WidescreenStoryboard":
beatmap.BeatmapInfo.WidescreenStoryboard = Parsing.ParseInt(pair.Value) == 1; beatmap.BeatmapInfo.WidescreenStoryboard = Parsing.ParseInt(pair.Value) == 1;
break; break;
case @"EpilepsyWarning":
beatmap.BeatmapInfo.EpilepsyWarning = Parsing.ParseInt(pair.Value) == 1;
break;
} }
} }

View File

@ -417,7 +417,7 @@ namespace osu.Game.Beatmaps.Formats
string sampleFilename = samples.FirstOrDefault(s => string.IsNullOrEmpty(s.Name))?.LookupNames.First() ?? string.Empty; string sampleFilename = samples.FirstOrDefault(s => string.IsNullOrEmpty(s.Name))?.LookupNames.First() ?? string.Empty;
int volume = samples.FirstOrDefault()?.Volume ?? 100; int volume = samples.FirstOrDefault()?.Volume ?? 100;
sb.Append(":"); sb.Append(':');
sb.Append(FormattableString.Invariant($"{customSampleBank}:")); sb.Append(FormattableString.Invariant($"{customSampleBank}:"));
sb.Append(FormattableString.Invariant($"{volume}:")); sb.Append(FormattableString.Invariant($"{volume}:"));
sb.Append(FormattableString.Invariant($"{sampleFilename}")); sb.Append(FormattableString.Invariant($"{sampleFilename}"));

View File

@ -48,6 +48,10 @@ namespace osu.Game.Beatmaps.Formats
switch (section) switch (section)
{ {
case Section.General:
handleGeneral(storyboard, line);
return;
case Section.Events: case Section.Events:
handleEvents(line); handleEvents(line);
return; return;
@ -60,6 +64,18 @@ namespace osu.Game.Beatmaps.Formats
base.ParseLine(storyboard, section, line); base.ParseLine(storyboard, section, line);
} }
private void handleGeneral(Storyboard storyboard, string line)
{
var pair = SplitKeyVal(line);
switch (pair.Key)
{
case "UseSkinSprites":
storyboard.UseSkinSprites = pair.Value == "1";
break;
}
}
private void handleEvents(string line) private void handleEvents(string line)
{ {
var depth = 0; var depth = 0;
@ -331,7 +347,7 @@ namespace osu.Game.Beatmaps.Formats
/// <param name="line">The line which may contains variables.</param> /// <param name="line">The line which may contains variables.</param>
private void decodeVariables(ref string line) private void decodeVariables(ref string line)
{ {
while (line.IndexOf('$') >= 0) while (line.Contains('$'))
{ {
string origLine = line; string origLine = line;

View File

@ -0,0 +1,17 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.ComponentModel;
namespace osu.Game.Configuration
{
public enum HUDVisibilityMode
{
Never,
[Description("Hide during gameplay")]
HideDuringGameplay,
Always
}
}

View File

@ -90,7 +90,7 @@ namespace osu.Game.Configuration
Set(OsuSetting.HitLighting, true); Set(OsuSetting.HitLighting, true);
Set(OsuSetting.ShowInterface, true); Set(OsuSetting.HUDVisibilityMode, HUDVisibilityMode.Always);
Set(OsuSetting.ShowProgressGraph, true); Set(OsuSetting.ShowProgressGraph, true);
Set(OsuSetting.ShowHealthDisplayWhenCantFail, true); Set(OsuSetting.ShowHealthDisplayWhenCantFail, true);
Set(OsuSetting.FadePlayfieldWhenHealthLow, true); Set(OsuSetting.FadePlayfieldWhenHealthLow, true);
@ -131,6 +131,7 @@ namespace osu.Game.Configuration
Set(OsuSetting.IntroSequence, IntroSequence.Triangles); Set(OsuSetting.IntroSequence, IntroSequence.Triangles);
Set(OsuSetting.MenuBackgroundSource, BackgroundSource.Skin); Set(OsuSetting.MenuBackgroundSource, BackgroundSource.Skin);
Set(OsuSetting.SeasonalBackgroundMode, SeasonalBackgroundMode.Sometimes);
} }
public OsuConfigManager(Storage storage) public OsuConfigManager(Storage storage)
@ -170,6 +171,7 @@ namespace osu.Game.Configuration
public override TrackedSettings CreateTrackedSettings() => new TrackedSettings public override TrackedSettings CreateTrackedSettings() => new TrackedSettings
{ {
new TrackedSetting<bool>(OsuSetting.MouseDisableButtons, v => new SettingDescription(!v, "gameplay mouse buttons", v ? "disabled" : "enabled")), new TrackedSetting<bool>(OsuSetting.MouseDisableButtons, v => new SettingDescription(!v, "gameplay mouse buttons", v ? "disabled" : "enabled")),
new TrackedSetting<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode, m => new SettingDescription(m, "HUD Visibility", m.GetDescription())),
new TrackedSetting<ScalingMode>(OsuSetting.Scaling, m => new SettingDescription(m, "scaling", m.GetDescription())), new TrackedSetting<ScalingMode>(OsuSetting.Scaling, m => new SettingDescription(m, "scaling", m.GetDescription())),
}; };
} }
@ -190,7 +192,7 @@ namespace osu.Game.Configuration
AlwaysPlayFirstComboBreak, AlwaysPlayFirstComboBreak,
ScoreMeter, ScoreMeter,
FloatingComments, FloatingComments,
ShowInterface, HUDVisibilityMode,
ShowProgressGraph, ShowProgressGraph,
ShowHealthDisplayWhenCantFail, ShowHealthDisplayWhenCantFail,
FadePlayfieldWhenHealthLow, FadePlayfieldWhenHealthLow,
@ -239,5 +241,6 @@ namespace osu.Game.Configuration
HitLighting, HitLighting,
MenuBackgroundSource, MenuBackgroundSource,
GameplayDisableWinKey, GameplayDisableWinKey,
SeasonalBackgroundMode
} }
} }

View File

@ -0,0 +1,23 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
namespace osu.Game.Configuration
{
public enum SeasonalBackgroundMode
{
/// <summary>
/// Seasonal backgrounds are shown regardless of season, if at all available.
/// </summary>
Always,
/// <summary>
/// Seasonal backgrounds are shown only during their corresponding season.
/// </summary>
Sometimes,
/// <summary>
/// Seasonal backgrounds are never shown.
/// </summary>
Never
}
}

View File

@ -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 osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Configuration namespace osu.Game.Configuration
{ {
/// <summary> /// <summary>
@ -12,12 +14,19 @@ namespace osu.Game.Configuration
{ {
Set(Static.LoginOverlayDisplayed, false); Set(Static.LoginOverlayDisplayed, false);
Set(Static.MutedAudioNotificationShownOnce, false); Set(Static.MutedAudioNotificationShownOnce, false);
Set<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
} }
} }
public enum Static public enum Static
{ {
LoginOverlayDisplayed, LoginOverlayDisplayed,
MutedAudioNotificationShownOnce MutedAudioNotificationShownOnce,
/// <summary>
/// Info about seasonal backgrounds available fetched from API - see <see cref="APISeasonalBackgrounds"/>.
/// Value under this lookup can be <c>null</c> if there are no backgrounds available (or API is not reachable).
/// </summary>
SeasonalBackgrounds,
} }
} }

View File

@ -26,7 +26,7 @@ namespace osu.Game.Database
/// Whether this write usage will commit a transaction on completion. /// Whether this write usage will commit a transaction on completion.
/// If false, there is a parent usage responsible for transaction commit. /// If false, there is a parent usage responsible for transaction commit.
/// </summary> /// </summary>
public bool IsTransactionLeader = false; public bool IsTransactionLeader;
protected void Dispose(bool disposing) protected void Dispose(bool disposing)
{ {

View File

@ -0,0 +1,103 @@
// 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Graphics.Backgrounds
{
public class SeasonalBackgroundLoader : Component
{
/// <summary>
/// Fired when background should be changed due to receiving backgrounds from API
/// or when the user setting is changed (as it might require unloading the seasonal background).
/// </summary>
public event Action SeasonalBackgroundChanged;
[Resolved]
private IAPIProvider api { get; set; }
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
private Bindable<SeasonalBackgroundMode> seasonalBackgroundMode;
private Bindable<APISeasonalBackgrounds> seasonalBackgrounds;
private int current;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, SessionStatics sessionStatics)
{
seasonalBackgroundMode = config.GetBindable<SeasonalBackgroundMode>(OsuSetting.SeasonalBackgroundMode);
seasonalBackgroundMode.BindValueChanged(_ => SeasonalBackgroundChanged?.Invoke());
seasonalBackgrounds = sessionStatics.GetBindable<APISeasonalBackgrounds>(Static.SeasonalBackgrounds);
seasonalBackgrounds.BindValueChanged(_ => SeasonalBackgroundChanged?.Invoke());
apiState.BindTo(api.State);
apiState.BindValueChanged(fetchSeasonalBackgrounds, true);
}
private void fetchSeasonalBackgrounds(ValueChangedEvent<APIState> stateChanged)
{
if (seasonalBackgrounds.Value != null || stateChanged.NewValue != APIState.Online)
return;
var request = new GetSeasonalBackgroundsRequest();
request.Success += response =>
{
seasonalBackgrounds.Value = response;
current = RNG.Next(0, response.Backgrounds?.Count ?? 0);
};
api.PerformAsync(request);
}
public SeasonalBackground LoadNextBackground()
{
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Never
|| (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && !isInSeason))
{
return null;
}
var backgrounds = seasonalBackgrounds.Value?.Backgrounds;
if (backgrounds == null || !backgrounds.Any())
return null;
current = (current + 1) % backgrounds.Count;
string url = backgrounds[current].Url;
return new SeasonalBackground(url);
}
private bool isInSeason => seasonalBackgrounds.Value != null && DateTimeOffset.Now < seasonalBackgrounds.Value.EndDate;
}
[LongRunningLoad]
public class SeasonalBackground : Background
{
private readonly string url;
private const string fallback_texture_name = @"Backgrounds/bg1";
public SeasonalBackground(string url)
{
this.url = url;
}
[BackgroundDependencyLoader]
private void load(LargeTextureStore textures)
{
Sprite.Texture = textures.Get(url) ?? textures.Get(fallback_texture_name);
// ensure we're not loading in without a transition.
this.FadeInFromZero(200, Easing.InOutSine);
}
}
}

View File

@ -21,7 +21,7 @@ namespace osu.Game.Graphics.Containers
/// Allows controlling the scroll bar from any position in the container using the right mouse button. /// Allows controlling the scroll bar from any position in the container using the right mouse button.
/// Uses the value of <see cref="DistanceDecayOnRightMouseScrollbar"/> to smoothly scroll to the dragged location. /// Uses the value of <see cref="DistanceDecayOnRightMouseScrollbar"/> to smoothly scroll to the dragged location.
/// </summary> /// </summary>
public bool RightMouseScrollbar = false; public bool RightMouseScrollbar;
/// <summary> /// <summary>
/// Controls the rate with which the target position is approached when performing a relative drag. Default is 0.02. /// Controls the rate with which the target position is approached when performing a relative drag. Default is 0.02.

View File

@ -44,6 +44,11 @@ namespace osu.Game.Graphics.UserInterface
// blocking scroll can cause weird behaviour when this layer is used within a ScrollContainer. // blocking scroll can cause weird behaviour when this layer is used within a ScrollContainer.
case ScrollEvent _: case ScrollEvent _:
return false; return false;
// blocking touch events causes the ISourcedFromTouch versions to not be fired, potentially impeding behaviour of drawables *above* the loading layer that may utilise these.
// note that this will not work well if touch handling elements are beneath this loading layer (something to consider for the future).
case TouchEvent _:
return false;
} }
return true; return true;

View File

@ -41,7 +41,7 @@ namespace osu.Game.IO.Archives
return null; return null;
byte[] buffer = new byte[input.Length]; byte[] buffer = new byte[input.Length];
await input.ReadAsync(buffer, 0, buffer.Length); await input.ReadAsync(buffer);
return buffer; return buffer;
} }
} }

View File

@ -67,6 +67,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(new[] { InputKey.Control, InputKey.Plus }, GlobalAction.IncreaseScrollSpeed), new KeyBinding(new[] { InputKey.Control, InputKey.Plus }, GlobalAction.IncreaseScrollSpeed),
new KeyBinding(new[] { InputKey.Control, InputKey.Minus }, GlobalAction.DecreaseScrollSpeed), new KeyBinding(new[] { InputKey.Control, InputKey.Minus }, GlobalAction.DecreaseScrollSpeed),
new KeyBinding(InputKey.MouseMiddle, GlobalAction.PauseGameplay), new KeyBinding(InputKey.MouseMiddle, GlobalAction.PauseGameplay),
new KeyBinding(InputKey.Control, GlobalAction.HoldForHUD),
}; };
public IEnumerable<KeyBinding> AudioControlKeyBindings => new[] public IEnumerable<KeyBinding> AudioControlKeyBindings => new[]
@ -187,5 +188,8 @@ namespace osu.Game.Input.Bindings
[Description("Timing Mode")] [Description("Timing Mode")]
EditorTimingMode, EditorTimingMode,
[Description("Hold for HUD")]
HoldForHUD,
} }
} }

View File

@ -0,0 +1,508 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using osu.Game.Database;
namespace osu.Game.Migrations
{
[DbContext(typeof(OsuDbContext))]
[Migration("20201019224408_AddEpilepsyWarning")]
partial class AddEpilepsyWarning
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.6-servicing-10079");
modelBuilder.Entity("osu.Game.Beatmaps.BeatmapDifficulty", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<float>("ApproachRate");
b.Property<float>("CircleSize");
b.Property<float>("DrainRate");
b.Property<float>("OverallDifficulty");
b.Property<double>("SliderMultiplier");
b.Property<double>("SliderTickRate");
b.HasKey("ID");
b.ToTable("BeatmapDifficulty");
});
modelBuilder.Entity("osu.Game.Beatmaps.BeatmapInfo", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<double>("AudioLeadIn");
b.Property<double>("BPM");
b.Property<int>("BaseDifficultyID");
b.Property<int>("BeatDivisor");
b.Property<int>("BeatmapSetInfoID");
b.Property<bool>("Countdown");
b.Property<double>("DistanceSpacing");
b.Property<bool>("EpilepsyWarning");
b.Property<int>("GridSize");
b.Property<string>("Hash");
b.Property<bool>("Hidden");
b.Property<double>("Length");
b.Property<bool>("LetterboxInBreaks");
b.Property<string>("MD5Hash");
b.Property<int?>("MetadataID");
b.Property<int?>("OnlineBeatmapID");
b.Property<string>("Path");
b.Property<int>("RulesetID");
b.Property<bool>("SpecialStyle");
b.Property<float>("StackLeniency");
b.Property<double>("StarDifficulty");
b.Property<int>("Status");
b.Property<string>("StoredBookmarks");
b.Property<double>("TimelineZoom");
b.Property<string>("Version");
b.Property<bool>("WidescreenStoryboard");
b.HasKey("ID");
b.HasIndex("BaseDifficultyID");
b.HasIndex("BeatmapSetInfoID");
b.HasIndex("Hash");
b.HasIndex("MD5Hash");
b.HasIndex("MetadataID");
b.HasIndex("OnlineBeatmapID")
.IsUnique();
b.HasIndex("RulesetID");
b.ToTable("BeatmapInfo");
});
modelBuilder.Entity("osu.Game.Beatmaps.BeatmapMetadata", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<string>("Artist");
b.Property<string>("ArtistUnicode");
b.Property<string>("AudioFile");
b.Property<string>("AuthorString")
.HasColumnName("Author");
b.Property<string>("BackgroundFile");
b.Property<int>("PreviewTime");
b.Property<string>("Source");
b.Property<string>("Tags");
b.Property<string>("Title");
b.Property<string>("TitleUnicode");
b.Property<string>("VideoFile");
b.HasKey("ID");
b.ToTable("BeatmapMetadata");
});
modelBuilder.Entity("osu.Game.Beatmaps.BeatmapSetFileInfo", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<int>("BeatmapSetInfoID");
b.Property<int>("FileInfoID");
b.Property<string>("Filename")
.IsRequired();
b.HasKey("ID");
b.HasIndex("BeatmapSetInfoID");
b.HasIndex("FileInfoID");
b.ToTable("BeatmapSetFileInfo");
});
modelBuilder.Entity("osu.Game.Beatmaps.BeatmapSetInfo", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<DateTimeOffset>("DateAdded");
b.Property<bool>("DeletePending");
b.Property<string>("Hash");
b.Property<int?>("MetadataID");
b.Property<int?>("OnlineBeatmapSetID");
b.Property<bool>("Protected");
b.Property<int>("Status");
b.HasKey("ID");
b.HasIndex("DeletePending");
b.HasIndex("Hash")
.IsUnique();
b.HasIndex("MetadataID");
b.HasIndex("OnlineBeatmapSetID")
.IsUnique();
b.ToTable("BeatmapSetInfo");
});
modelBuilder.Entity("osu.Game.Configuration.DatabasedSetting", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<string>("Key")
.HasColumnName("Key");
b.Property<int?>("RulesetID");
b.Property<int?>("SkinInfoID");
b.Property<string>("StringValue")
.HasColumnName("Value");
b.Property<int?>("Variant");
b.HasKey("ID");
b.HasIndex("SkinInfoID");
b.HasIndex("RulesetID", "Variant");
b.ToTable("Settings");
});
modelBuilder.Entity("osu.Game.IO.FileInfo", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<string>("Hash");
b.Property<int>("ReferenceCount");
b.HasKey("ID");
b.HasIndex("Hash")
.IsUnique();
b.HasIndex("ReferenceCount");
b.ToTable("FileInfo");
});
modelBuilder.Entity("osu.Game.Input.Bindings.DatabasedKeyBinding", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<int>("IntAction")
.HasColumnName("Action");
b.Property<string>("KeysString")
.HasColumnName("Keys");
b.Property<int?>("RulesetID");
b.Property<int?>("Variant");
b.HasKey("ID");
b.HasIndex("IntAction");
b.HasIndex("RulesetID", "Variant");
b.ToTable("KeyBinding");
});
modelBuilder.Entity("osu.Game.Rulesets.RulesetInfo", b =>
{
b.Property<int?>("ID")
.ValueGeneratedOnAdd();
b.Property<bool>("Available");
b.Property<string>("InstantiationInfo");
b.Property<string>("Name");
b.Property<string>("ShortName");
b.HasKey("ID");
b.HasIndex("Available");
b.HasIndex("ShortName")
.IsUnique();
b.ToTable("RulesetInfo");
});
modelBuilder.Entity("osu.Game.Scoring.ScoreFileInfo", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<int>("FileInfoID");
b.Property<string>("Filename")
.IsRequired();
b.Property<int?>("ScoreInfoID");
b.HasKey("ID");
b.HasIndex("FileInfoID");
b.HasIndex("ScoreInfoID");
b.ToTable("ScoreFileInfo");
});
modelBuilder.Entity("osu.Game.Scoring.ScoreInfo", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<double>("Accuracy")
.HasColumnType("DECIMAL(1,4)");
b.Property<int>("BeatmapInfoID");
b.Property<int>("Combo");
b.Property<DateTimeOffset>("Date");
b.Property<bool>("DeletePending");
b.Property<string>("Hash");
b.Property<int>("MaxCombo");
b.Property<string>("ModsJson")
.HasColumnName("Mods");
b.Property<long?>("OnlineScoreID");
b.Property<double?>("PP");
b.Property<int>("Rank");
b.Property<int>("RulesetID");
b.Property<string>("StatisticsJson")
.HasColumnName("Statistics");
b.Property<long>("TotalScore");
b.Property<long?>("UserID")
.HasColumnName("UserID");
b.Property<string>("UserString")
.HasColumnName("User");
b.HasKey("ID");
b.HasIndex("BeatmapInfoID");
b.HasIndex("OnlineScoreID")
.IsUnique();
b.HasIndex("RulesetID");
b.ToTable("ScoreInfo");
});
modelBuilder.Entity("osu.Game.Skinning.SkinFileInfo", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<int>("FileInfoID");
b.Property<string>("Filename")
.IsRequired();
b.Property<int>("SkinInfoID");
b.HasKey("ID");
b.HasIndex("FileInfoID");
b.HasIndex("SkinInfoID");
b.ToTable("SkinFileInfo");
});
modelBuilder.Entity("osu.Game.Skinning.SkinInfo", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd();
b.Property<string>("Creator");
b.Property<bool>("DeletePending");
b.Property<string>("Hash");
b.Property<string>("Name");
b.HasKey("ID");
b.HasIndex("DeletePending");
b.HasIndex("Hash")
.IsUnique();
b.ToTable("SkinInfo");
});
modelBuilder.Entity("osu.Game.Beatmaps.BeatmapInfo", b =>
{
b.HasOne("osu.Game.Beatmaps.BeatmapDifficulty", "BaseDifficulty")
.WithMany()
.HasForeignKey("BaseDifficultyID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("osu.Game.Beatmaps.BeatmapSetInfo", "BeatmapSet")
.WithMany("Beatmaps")
.HasForeignKey("BeatmapSetInfoID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("osu.Game.Beatmaps.BeatmapMetadata", "Metadata")
.WithMany("Beatmaps")
.HasForeignKey("MetadataID");
b.HasOne("osu.Game.Rulesets.RulesetInfo", "Ruleset")
.WithMany()
.HasForeignKey("RulesetID")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("osu.Game.Beatmaps.BeatmapSetFileInfo", b =>
{
b.HasOne("osu.Game.Beatmaps.BeatmapSetInfo")
.WithMany("Files")
.HasForeignKey("BeatmapSetInfoID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("osu.Game.IO.FileInfo", "FileInfo")
.WithMany()
.HasForeignKey("FileInfoID")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("osu.Game.Beatmaps.BeatmapSetInfo", b =>
{
b.HasOne("osu.Game.Beatmaps.BeatmapMetadata", "Metadata")
.WithMany("BeatmapSets")
.HasForeignKey("MetadataID");
});
modelBuilder.Entity("osu.Game.Configuration.DatabasedSetting", b =>
{
b.HasOne("osu.Game.Skinning.SkinInfo")
.WithMany("Settings")
.HasForeignKey("SkinInfoID");
});
modelBuilder.Entity("osu.Game.Scoring.ScoreFileInfo", b =>
{
b.HasOne("osu.Game.IO.FileInfo", "FileInfo")
.WithMany()
.HasForeignKey("FileInfoID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("osu.Game.Scoring.ScoreInfo")
.WithMany("Files")
.HasForeignKey("ScoreInfoID");
});
modelBuilder.Entity("osu.Game.Scoring.ScoreInfo", b =>
{
b.HasOne("osu.Game.Beatmaps.BeatmapInfo", "Beatmap")
.WithMany("Scores")
.HasForeignKey("BeatmapInfoID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("osu.Game.Rulesets.RulesetInfo", "Ruleset")
.WithMany()
.HasForeignKey("RulesetID")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("osu.Game.Skinning.SkinFileInfo", b =>
{
b.HasOne("osu.Game.IO.FileInfo", "FileInfo")
.WithMany()
.HasForeignKey("FileInfoID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("osu.Game.Skinning.SkinInfo")
.WithMany("Files")
.HasForeignKey("SkinInfoID")
.OnDelete(DeleteBehavior.Cascade);
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{
public partial class AddEpilepsyWarning : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "EpilepsyWarning",
table: "BeatmapInfo",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "EpilepsyWarning",
table: "BeatmapInfo");
}
}
}

View File

@ -57,6 +57,8 @@ namespace osu.Game.Migrations
b.Property<double>("DistanceSpacing"); b.Property<double>("DistanceSpacing");
b.Property<bool>("EpilepsyWarning");
b.Property<int>("GridSize"); b.Property<int>("GridSize");
b.Property<string>("Hash"); b.Property<string>("Hash");

View File

@ -78,26 +78,8 @@ namespace osu.Game.Online.API
private void onTokenChanged(ValueChangedEvent<OAuthToken> e) => config.Set(OsuSetting.Token, config.Get<bool>(OsuSetting.SavePassword) ? authentication.TokenString : string.Empty); private void onTokenChanged(ValueChangedEvent<OAuthToken> e) => config.Set(OsuSetting.Token, config.Get<bool>(OsuSetting.SavePassword) ? authentication.TokenString : string.Empty);
private readonly List<IOnlineComponent> components = new List<IOnlineComponent>();
internal new void Schedule(Action action) => base.Schedule(action); internal new void Schedule(Action action) => base.Schedule(action);
/// <summary>
/// Register a component to receive API events.
/// Fires <see cref="IOnlineComponent.APIStateChanged"/> once immediately to ensure a correct state.
/// </summary>
/// <param name="component"></param>
public void Register(IOnlineComponent component)
{
Schedule(() => components.Add(component));
component.APIStateChanged(this, state);
}
public void Unregister(IOnlineComponent component)
{
Schedule(() => components.Remove(component));
}
public string AccessToken => authentication.RequestAccessToken(); public string AccessToken => authentication.RequestAccessToken();
/// <summary> /// <summary>
@ -109,7 +91,7 @@ namespace osu.Game.Online.API
{ {
while (!cancellationToken.IsCancellationRequested) while (!cancellationToken.IsCancellationRequested)
{ {
switch (State) switch (State.Value)
{ {
case APIState.Failing: case APIState.Failing:
//todo: replace this with a ping request. //todo: replace this with a ping request.
@ -131,12 +113,12 @@ namespace osu.Game.Online.API
// work to restore a connection... // work to restore a connection...
if (!HasLogin) if (!HasLogin)
{ {
State = APIState.Offline; state.Value = APIState.Offline;
Thread.Sleep(50); Thread.Sleep(50);
continue; continue;
} }
State = APIState.Connecting; state.Value = APIState.Connecting;
// save the username at this point, if the user requested for it to be. // save the username at this point, if the user requested for it to be.
config.Set(OsuSetting.Username, config.Get<bool>(OsuSetting.SaveUsername) ? ProvidedUsername : string.Empty); config.Set(OsuSetting.Username, config.Get<bool>(OsuSetting.SaveUsername) ? ProvidedUsername : string.Empty);
@ -162,20 +144,20 @@ namespace osu.Game.Online.API
failureCount = 0; failureCount = 0;
//we're connected! //we're connected!
State = APIState.Online; state.Value = APIState.Online;
}; };
if (!handleRequest(userReq)) if (!handleRequest(userReq))
{ {
if (State == APIState.Connecting) if (State.Value == APIState.Connecting)
State = APIState.Failing; state.Value = APIState.Failing;
continue; continue;
} }
// The Success callback event is fired on the main thread, so we should wait for that to run before proceeding. // The Success callback event is fired on the main thread, so we should wait for that to run before proceeding.
// Without this, we will end up circulating this Connecting loop multiple times and queueing up many web requests // Without this, we will end up circulating this Connecting loop multiple times and queueing up many web requests
// before actually going online. // before actually going online.
while (State > APIState.Offline && State < APIState.Online) while (State.Value > APIState.Offline && State.Value < APIState.Online)
Thread.Sleep(500); Thread.Sleep(500);
break; break;
@ -224,7 +206,7 @@ namespace osu.Game.Online.API
public void Login(string username, string password) public void Login(string username, string password)
{ {
Debug.Assert(State == APIState.Offline); Debug.Assert(State.Value == APIState.Offline);
ProvidedUsername = username; ProvidedUsername = username;
this.password = password; this.password = password;
@ -232,7 +214,7 @@ namespace osu.Game.Online.API
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password) public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
{ {
Debug.Assert(State == APIState.Offline); Debug.Assert(State.Value == APIState.Offline);
var req = new RegistrationRequest var req = new RegistrationRequest
{ {
@ -276,7 +258,7 @@ namespace osu.Game.Online.API
req.Perform(this); req.Perform(this);
// we could still be in initialisation, at which point we don't want to say we're Online yet. // we could still be in initialisation, at which point we don't want to say we're Online yet.
if (IsLoggedIn) State = APIState.Online; if (IsLoggedIn) state.Value = APIState.Online;
failureCount = 0; failureCount = 0;
return true; return true;
@ -293,27 +275,12 @@ namespace osu.Game.Online.API
} }
} }
private APIState state; private readonly Bindable<APIState> state = new Bindable<APIState>();
public APIState State /// <summary>
{ /// The current connectivity state of the API.
get => state; /// </summary>
private set public IBindable<APIState> State => state;
{
if (state == value)
return;
APIState oldState = state;
state = value;
log.Add($@"We just went {state}!");
Schedule(() =>
{
components.ForEach(c => c.APIStateChanged(this, state));
OnStateChange?.Invoke(oldState, state);
});
}
}
private bool handleWebException(WebException we) private bool handleWebException(WebException we)
{ {
@ -343,9 +310,9 @@ namespace osu.Game.Online.API
// we might try again at an api level. // we might try again at an api level.
return false; return false;
if (State == APIState.Online) if (State.Value == APIState.Online)
{ {
State = APIState.Failing; state.Value = APIState.Failing;
flushQueue(); flushQueue();
} }
@ -362,10 +329,6 @@ namespace osu.Game.Online.API
lock (queue) queue.Enqueue(request); lock (queue) queue.Enqueue(request);
} }
public event StateChangeDelegate OnStateChange;
public delegate void StateChangeDelegate(APIState oldState, APIState newState);
private void flushQueue(bool failOldRequests = true) private void flushQueue(bool failOldRequests = true)
{ {
lock (queue) lock (queue)
@ -392,7 +355,7 @@ namespace osu.Game.Online.API
// Scheduled prior to state change such that the state changed event is invoked with the correct user present // Scheduled prior to state change such that the state changed event is invoked with the correct user present
Schedule(() => LocalUser.Value = createGuestUser()); Schedule(() => LocalUser.Value = createGuestUser());
State = APIState.Offline; state.Value = APIState.Offline;
} }
private static User createGuestUser() => new GuestUser(); private static User createGuestUser() => new GuestUser();

View File

@ -53,5 +53,13 @@ namespace osu.Game.Online.API
} }
public bool Equals(IMod other) => Acronym == other?.Acronym; public bool Equals(IMod other) => Acronym == other?.Acronym;
public override string ToString()
{
if (Settings.Count > 0)
return $"{Acronym} ({string.Join(',', Settings.Select(kvp => $"{kvp.Key}:{kvp.Value}"))})";
return $"{Acronym}";
}
} }
} }

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -21,34 +20,25 @@ namespace osu.Game.Online.API
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>(); public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
public bool IsLoggedIn => State == APIState.Online; public string AccessToken => "token";
public bool IsLoggedIn => State.Value == APIState.Online;
public string ProvidedUsername => LocalUser.Value.Username; public string ProvidedUsername => LocalUser.Value.Username;
public string Endpoint => "http://localhost"; public string Endpoint => "http://localhost";
private APIState state = APIState.Online;
private readonly List<IOnlineComponent> components = new List<IOnlineComponent>();
/// <summary> /// <summary>
/// Provide handling logic for an arbitrary API request. /// Provide handling logic for an arbitrary API request.
/// </summary> /// </summary>
public Action<APIRequest> HandleRequest; public Action<APIRequest> HandleRequest;
public APIState State private readonly Bindable<APIState> state = new Bindable<APIState>(APIState.Online);
{
get => state;
set
{
if (state == value)
return;
state = value; /// <summary>
/// The current connectivity state of the API.
Scheduler.Add(() => components.ForEach(c => c.APIStateChanged(this, value))); /// </summary>
} public IBindable<APIState> State => state;
}
public DummyAPIAccess() public DummyAPIAccess()
{ {
@ -72,17 +62,6 @@ namespace osu.Game.Online.API
return Task.CompletedTask; return Task.CompletedTask;
} }
public void Register(IOnlineComponent component)
{
Scheduler.Add(delegate { components.Add(component); });
component.APIStateChanged(this, state);
}
public void Unregister(IOnlineComponent component)
{
Scheduler.Add(delegate { components.Remove(component); });
}
public void Login(string username, string password) public void Login(string username, string password)
{ {
LocalUser.Value = new User LocalUser.Value = new User
@ -91,13 +70,13 @@ namespace osu.Game.Online.API
Id = 1001, Id = 1001,
}; };
State = APIState.Online; state.Value = APIState.Online;
} }
public void Logout() public void Logout()
{ {
LocalUser.Value = new GuestUser(); LocalUser.Value = new GuestUser();
State = APIState.Offline; state.Value = APIState.Offline;
} }
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password) public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password)
@ -105,5 +84,7 @@ namespace osu.Game.Online.API
Thread.Sleep(200); Thread.Sleep(200);
return null; return null;
} }
public void SetState(APIState newState) => state.Value = newState;
} }
} }

View File

@ -11,14 +11,21 @@ namespace osu.Game.Online.API
{ {
/// <summary> /// <summary>
/// The local user. /// The local user.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// </summary> /// </summary>
Bindable<User> LocalUser { get; } Bindable<User> LocalUser { get; }
/// <summary> /// <summary>
/// The current user's activity. /// The current user's activity.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// </summary> /// </summary>
Bindable<UserActivity> Activity { get; } Bindable<UserActivity> Activity { get; }
/// <summary>
/// Retrieve the OAuth access token.
/// </summary>
string AccessToken { get; }
/// <summary> /// <summary>
/// Returns whether the local user is logged in. /// Returns whether the local user is logged in.
/// </summary> /// </summary>
@ -35,7 +42,11 @@ namespace osu.Game.Online.API
/// </summary> /// </summary>
string Endpoint { get; } string Endpoint { get; }
APIState State { get; } /// <summary>
/// The current connection state of the API.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// </summary>
IBindable<APIState> State { get; }
/// <summary> /// <summary>
/// Queue a new request. /// Queue a new request.
@ -61,18 +72,6 @@ namespace osu.Game.Online.API
/// <param name="request">The request to perform.</param> /// <param name="request">The request to perform.</param>
Task PerformAsync(APIRequest request); Task PerformAsync(APIRequest request);
/// <summary>
/// Register a component to receive state changes.
/// </summary>
/// <param name="component">The component to register.</param>
void Register(IOnlineComponent component);
/// <summary>
/// Unregisters a component to receive state changes.
/// </summary>
/// <param name="component">The component to unregister.</param>
void Unregister(IOnlineComponent component);
/// <summary> /// <summary>
/// Attempt to login using the provided credentials. This is a non-blocking operation. /// Attempt to login using the provided credentials. This is a non-blocking operation.
/// </summary> /// </summary>

View File

@ -0,0 +1,12 @@
// 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.Online.API.Requests.Responses;
namespace osu.Game.Online.API.Requests
{
public class GetSeasonalBackgroundsRequest : APIRequest<APISeasonalBackgrounds>
{
protected override string Target => @"seasonal-backgrounds";
}
}

View File

@ -0,0 +1,24 @@
// 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 Newtonsoft.Json;
namespace osu.Game.Online.API.Requests.Responses
{
public class APISeasonalBackgrounds
{
[JsonProperty("ends_at")]
public DateTimeOffset EndDate;
[JsonProperty("backgrounds")]
public List<APISeasonalBackground> Backgrounds { get; set; }
}
public class APISeasonalBackground
{
[JsonProperty("url")]
public string Url { get; set; }
}
}

View File

@ -1,11 +1,15 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.IO.Network; using osu.Framework.IO.Network;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing; using osu.Game.Overlays.BeatmapListing;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Scoring;
namespace osu.Game.Online.API.Requests namespace osu.Game.Online.API.Requests
{ {
@ -21,6 +25,14 @@ namespace osu.Game.Online.API.Requests
public SearchLanguage Language { get; } public SearchLanguage Language { get; }
[CanBeNull]
public IReadOnlyCollection<SearchExtra> Extra { get; }
public SearchPlayed Played { get; }
[CanBeNull]
public IReadOnlyCollection<ScoreRank> Ranks { get; }
private readonly string query; private readonly string query;
private readonly RulesetInfo ruleset; private readonly RulesetInfo ruleset;
private readonly Cursor cursor; private readonly Cursor cursor;
@ -35,7 +47,10 @@ namespace osu.Game.Online.API.Requests
SortCriteria sortCriteria = SortCriteria.Ranked, SortCriteria sortCriteria = SortCriteria.Ranked,
SortDirection sortDirection = SortDirection.Descending, SortDirection sortDirection = SortDirection.Descending,
SearchGenre genre = SearchGenre.Any, SearchGenre genre = SearchGenre.Any,
SearchLanguage language = SearchLanguage.Any) SearchLanguage language = SearchLanguage.Any,
IReadOnlyCollection<SearchExtra> extra = null,
IReadOnlyCollection<ScoreRank> ranks = null,
SearchPlayed played = SearchPlayed.Any)
{ {
this.query = string.IsNullOrEmpty(query) ? string.Empty : System.Uri.EscapeDataString(query); this.query = string.IsNullOrEmpty(query) ? string.Empty : System.Uri.EscapeDataString(query);
this.ruleset = ruleset; this.ruleset = ruleset;
@ -46,6 +61,9 @@ namespace osu.Game.Online.API.Requests
SortDirection = sortDirection; SortDirection = sortDirection;
Genre = genre; Genre = genre;
Language = language; Language = language;
Extra = extra;
Ranks = ranks;
Played = played;
} }
protected override WebRequest CreateWebRequest() protected override WebRequest CreateWebRequest()
@ -66,6 +84,15 @@ namespace osu.Game.Online.API.Requests
req.AddParameter("sort", $"{SortCriteria.ToString().ToLowerInvariant()}_{directionString}"); req.AddParameter("sort", $"{SortCriteria.ToString().ToLowerInvariant()}_{directionString}");
if (Extra != null && Extra.Any())
req.AddParameter("e", string.Join('.', Extra.Select(e => e.ToString().ToLowerInvariant())));
if (Ranks != null && Ranks.Any())
req.AddParameter("r", string.Join('.', Ranks.Select(r => r.ToString())));
if (Played != SearchPlayed.Any)
req.AddParameter("played", Played.ToString().ToLowerInvariant());
req.AddCursor(cursor); req.AddCursor(cursor);
return req; return req;

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
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;
@ -22,7 +23,7 @@ using osuTK.Graphics;
namespace osu.Game.Online.Leaderboards namespace osu.Game.Online.Leaderboards
{ {
public abstract class Leaderboard<TScope, TScoreInfo> : Container, IOnlineComponent public abstract class Leaderboard<TScope, TScoreInfo> : Container
{ {
private const double fade_duration = 300; private const double fade_duration = 300;
@ -242,16 +243,13 @@ namespace osu.Game.Online.Leaderboards
private ScheduledDelegate pendingUpdateScores; private ScheduledDelegate pendingUpdateScores;
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
api?.Register(this); apiState.BindTo(api.State);
} apiState.BindValueChanged(onlineStateChanged, true);
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
api?.Unregister(this);
} }
public void RefreshScores() => UpdateScores(); public void RefreshScores() => UpdateScores();
@ -260,9 +258,9 @@ namespace osu.Game.Online.Leaderboards
protected abstract bool IsOnlineScope { get; } protected abstract bool IsOnlineScope { get; }
public void APIStateChanged(IAPIProvider api, APIState state) private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{ {
switch (state) switch (state.NewValue)
{ {
case APIState.Online: case APIState.Online:
case APIState.Offline: case APIState.Offline:
@ -271,7 +269,7 @@ namespace osu.Game.Online.Leaderboards
break; break;
} }
} });
protected void UpdateScores() protected void UpdateScores()
{ {

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -14,7 +15,7 @@ namespace osu.Game.Online
/// A <see cref="Container"/> for displaying online content which require a local user to be logged in. /// A <see cref="Container"/> for displaying online content which require a local user to be logged in.
/// Shows its children only when the local user is logged in and supports displaying a placeholder if not. /// Shows its children only when the local user is logged in and supports displaying a placeholder if not.
/// </summary> /// </summary>
public abstract class OnlineViewContainer : Container, IOnlineComponent public abstract class OnlineViewContainer : Container
{ {
protected LoadingSpinner LoadingSpinner { get; private set; } protected LoadingSpinner LoadingSpinner { get; private set; }
@ -34,8 +35,10 @@ namespace osu.Game.Online
this.placeholderMessage = placeholderMessage; this.placeholderMessage = placeholderMessage;
} }
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(IAPIProvider api)
{ {
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
@ -46,18 +49,14 @@ namespace osu.Game.Online
Alpha = 0, Alpha = 0,
} }
}; };
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
} }
protected override void LoadComplete() private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{ {
base.LoadComplete(); switch (state.NewValue)
API.Register(this);
}
public virtual void APIStateChanged(IAPIProvider api, APIState state)
{
switch (state)
{ {
case APIState.Offline: case APIState.Offline:
PopContentOut(Content); PopContentOut(Content);
@ -79,7 +78,7 @@ namespace osu.Game.Online
placeholder.FadeOut(transform_duration / 2, Easing.OutQuint); placeholder.FadeOut(transform_duration / 2, Easing.OutQuint);
break; break;
} }
} });
/// <summary> /// <summary>
/// Applies a transform to the online content to make it hidden. /// Applies a transform to the online content to make it hidden.
@ -90,11 +89,5 @@ namespace osu.Game.Online
/// Applies a transform to the online content to make it visible. /// Applies a transform to the online content to make it visible.
/// </summary> /// </summary>
protected virtual void PopContentIn(Drawable content) => content.FadeIn(transform_duration, Easing.OutQuint); protected virtual void PopContentIn(Drawable content) => content.FadeIn(transform_duration, Easing.OutQuint);
protected override void Dispose(bool isDisposing)
{
API?.Unregister(this);
base.Dispose(isDisposing);
}
} }
} }

View File

@ -0,0 +1,20 @@
// 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 osu.Game.Replays.Legacy;
namespace osu.Game.Online.Spectator
{
[Serializable]
public class FrameDataBundle
{
public IEnumerable<LegacyReplayFrame> Frames { get; set; }
public FrameDataBundle(IEnumerable<LegacyReplayFrame> frames)
{
Frames = frames;
}
}
}

View File

@ -0,0 +1,34 @@
// 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.Threading.Tasks;
namespace osu.Game.Online.Spectator
{
/// <summary>
/// An interface defining a spectator client instance.
/// </summary>
public interface ISpectatorClient
{
/// <summary>
/// Signals that a user has begun a new play session.
/// </summary>
/// <param name="userId">The user.</param>
/// <param name="state">The state of gameplay.</param>
Task UserBeganPlaying(int userId, SpectatorState state);
/// <summary>
/// Signals that a user has finished a play session.
/// </summary>
/// <param name="userId">The user.</param>
/// <param name="state">The state of gameplay.</param>
Task UserFinishedPlaying(int userId, SpectatorState state);
/// <summary>
/// Called when new frames are available for a subscribed user's play session.
/// </summary>
/// <param name="userId">The user.</param>
/// <param name="data">The frame data.</param>
Task UserSentFrames(int userId, FrameDataBundle data);
}
}

View File

@ -0,0 +1,44 @@
// 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.Threading.Tasks;
namespace osu.Game.Online.Spectator
{
/// <summary>
/// An interface defining the spectator server instance.
/// </summary>
public interface ISpectatorServer
{
/// <summary>
/// Signal the start of a new play session.
/// </summary>
/// <param name="state">The state of gameplay.</param>
Task BeginPlaySession(SpectatorState state);
/// <summary>
/// Send a bundle of frame data for the current play session.
/// </summary>
/// <param name="data">The frame data.</param>
Task SendFrameData(FrameDataBundle data);
/// <summary>
/// Signal the end of a play session.
/// </summary>
/// <param name="state">The state of gameplay.</param>
Task EndPlaySession(SpectatorState state);
/// <summary>
/// Request spectating data for the specified user. May be called on multiple users and offline users.
/// For offline users, a subscription will be created and data will begin streaming on next play.
/// </summary>
/// <param name="userId">The user to subscribe to.</param>
Task StartWatchingUser(int userId);
/// <summary>
/// Stop requesting spectating data for the specified user. Unsubscribes from receiving further data.
/// </summary>
/// <param name="userId">The user to unsubscribe from.</param>
Task EndWatchingUser(int userId);
}
}

View File

@ -0,0 +1,26 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using osu.Game.Online.API;
namespace osu.Game.Online.Spectator
{
[Serializable]
public class SpectatorState : IEquatable<SpectatorState>
{
public int? BeatmapID { get; set; }
public int? RulesetID { get; set; }
[NotNull]
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 override string ToString() => $"Beatmap:{BeatmapID} Mods:{string.Join(',', Mods)} Ruleset:{RulesetID}";
}
}

View File

@ -0,0 +1,274 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Replays.Types;
using osu.Game.Screens.Play;
namespace osu.Game.Online.Spectator
{
public class SpectatorStreamingClient : Component, ISpectatorClient
{
/// <summary>
/// The maximum milliseconds between frame bundle sends.
/// </summary>
public const double TIME_BETWEEN_SENDS = 200;
private HubConnection connection;
private readonly List<int> watchingUsers = new List<int>();
public IBindableList<int> PlayingUsers => playingUsers;
private readonly BindableList<int> playingUsers = new BindableList<int>();
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
private bool isConnected;
[Resolved]
private IAPIProvider api { get; set; }
[CanBeNull]
private IBeatmap currentBeatmap;
[Resolved]
private IBindable<RulesetInfo> currentRuleset { get; set; }
[Resolved]
private IBindable<IReadOnlyList<Mod>> currentMods { get; set; }
private readonly SpectatorState currentState = new SpectatorState();
private bool isPlaying;
/// <summary>
/// Called whenever new frames arrive from the server.
/// </summary>
public event Action<int, FrameDataBundle> OnNewFrames;
[BackgroundDependencyLoader]
private void load()
{
apiState.BindTo(api.State);
apiState.BindValueChanged(apiStateChanged, true);
}
private void apiStateChanged(ValueChangedEvent<APIState> state)
{
switch (state.NewValue)
{
case APIState.Failing:
case APIState.Offline:
connection?.StopAsync();
connection = null;
break;
case APIState.Online:
Task.Run(connect);
break;
}
}
private const string endpoint = "https://spectator.ppy.sh/spectator";
private async Task connect()
{
if (connection != null)
return;
connection = new HubConnectionBuilder()
.WithUrl(endpoint, options =>
{
options.Headers.Add("Authorization", $"Bearer {api.AccessToken}");
})
.AddNewtonsoftJsonProtocol(options => { options.PayloadSerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; })
.Build();
// 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, FrameDataBundle>(nameof(ISpectatorClient.UserSentFrames), ((ISpectatorClient)this).UserSentFrames);
connection.On<int, SpectatorState>(nameof(ISpectatorClient.UserFinishedPlaying), ((ISpectatorClient)this).UserFinishedPlaying);
connection.Closed += async ex =>
{
isConnected = false;
playingUsers.Clear();
if (ex != null) await tryUntilConnected();
};
await tryUntilConnected();
async Task tryUntilConnected()
{
while (api.State.Value == APIState.Online)
{
try
{
// reconnect on any failure
await connection.StartAsync();
// success
isConnected = true;
// resubscribe to watched users
var users = watchingUsers.ToArray();
watchingUsers.Clear();
foreach (var userId in users)
WatchUser(userId);
// re-send state in case it wasn't received
if (isPlaying)
beginPlaying();
break;
}
catch
{
await Task.Delay(5000);
}
}
}
}
Task ISpectatorClient.UserBeganPlaying(int userId, SpectatorState state)
{
if (!playingUsers.Contains(userId))
playingUsers.Add(userId);
return Task.CompletedTask;
}
Task ISpectatorClient.UserFinishedPlaying(int userId, SpectatorState state)
{
playingUsers.Remove(userId);
return Task.CompletedTask;
}
Task ISpectatorClient.UserSentFrames(int userId, FrameDataBundle data)
{
OnNewFrames?.Invoke(userId, data);
return Task.CompletedTask;
}
public void BeginPlaying(GameplayBeatmap beatmap)
{
if (isPlaying)
throw new InvalidOperationException($"Cannot invoke {nameof(BeginPlaying)} when already playing");
isPlaying = true;
// transfer state at point of beginning play
currentState.BeatmapID = beatmap.BeatmapInfo.OnlineBeatmapID;
currentState.RulesetID = currentRuleset.Value.ID;
currentState.Mods = currentMods.Value.Select(m => new APIMod(m));
currentBeatmap = beatmap.PlayableBeatmap;
beginPlaying();
}
private void beginPlaying()
{
Debug.Assert(isPlaying);
if (!isConnected) return;
connection.SendAsync(nameof(ISpectatorServer.BeginPlaySession), currentState);
}
public void SendFrames(FrameDataBundle data)
{
if (!isConnected) return;
lastSend = connection.SendAsync(nameof(ISpectatorServer.SendFrameData), data);
}
public void EndPlaying()
{
isPlaying = false;
currentBeatmap = null;
if (!isConnected) return;
connection.SendAsync(nameof(ISpectatorServer.EndPlaySession), currentState);
}
public void WatchUser(int userId)
{
if (watchingUsers.Contains(userId))
return;
watchingUsers.Add(userId);
if (!isConnected) return;
connection.SendAsync(nameof(ISpectatorServer.StartWatchingUser), userId);
}
public void StopWatchingUser(int userId)
{
watchingUsers.Remove(userId);
if (!isConnected) return;
connection.SendAsync(nameof(ISpectatorServer.EndWatchingUser), userId);
}
private readonly Queue<LegacyReplayFrame> pendingFrames = new Queue<LegacyReplayFrame>();
private double lastSendTime;
private Task lastSend;
private const int max_pending_frames = 30;
protected override void Update()
{
base.Update();
if (pendingFrames.Count > 0 && Time.Current - lastSendTime > TIME_BETWEEN_SENDS)
purgePendingFrames();
}
public void HandleFrame(ReplayFrame frame)
{
if (frame is IConvertibleReplayFrame convertible)
pendingFrames.Enqueue(convertible.ToLegacy(currentBeatmap));
if (pendingFrames.Count > max_pending_frames)
purgePendingFrames();
}
private void purgePendingFrames()
{
if (lastSend?.IsCompleted == false)
return;
var frames = pendingFrames.ToArray();
pendingFrames.Clear();
SendFrames(new FrameDataBundle(frames));
lastSendTime = Time.Current;
}
}
}

View File

@ -30,6 +30,7 @@ using osu.Game.Database;
using osu.Game.Input; using osu.Game.Input;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Online.Spectator;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Resources; using osu.Game.Resources;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -76,6 +77,8 @@ namespace osu.Game
protected IAPIProvider API; protected IAPIProvider API;
private SpectatorStreamingClient spectatorStreaming;
protected MenuCursorContainer MenuCursorContainer; protected MenuCursorContainer MenuCursorContainer;
protected MusicController MusicController; protected MusicController MusicController;
@ -191,9 +194,9 @@ namespace osu.Game
dependencies.Cache(SkinManager = new SkinManager(Storage, contextFactory, Host, Audio, new NamespacedResourceStore<byte[]>(Resources, "Skins/Legacy"))); dependencies.Cache(SkinManager = new SkinManager(Storage, contextFactory, Host, Audio, new NamespacedResourceStore<byte[]>(Resources, "Skins/Legacy")));
dependencies.CacheAs<ISkinSource>(SkinManager); dependencies.CacheAs<ISkinSource>(SkinManager);
API ??= new APIAccess(LocalConfig); dependencies.CacheAs(API ??= new APIAccess(LocalConfig));
dependencies.CacheAs(API); dependencies.CacheAs(spectatorStreaming = new SpectatorStreamingClient());
var defaultBeatmap = new DummyWorkingBeatmap(Audio, Textures); var defaultBeatmap = new DummyWorkingBeatmap(Audio, Textures);
@ -252,8 +255,11 @@ namespace osu.Game
FileStore.Cleanup(); FileStore.Cleanup();
// add api components to hierarchy.
if (API is APIAccess apiAccess) if (API is APIAccess apiAccess)
AddInternal(apiAccess); AddInternal(apiAccess);
AddInternal(spectatorStreaming);
AddInternal(RulesetConfigCache); AddInternal(RulesetConfigCache);
MenuCursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both }; MenuCursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both };

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -17,7 +18,7 @@ using osuTK.Graphics;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public class AccountCreationOverlay : OsuFocusedOverlayContainer, IOnlineComponent public class AccountCreationOverlay : OsuFocusedOverlayContainer
{ {
private const float transition_time = 400; private const float transition_time = 400;
@ -30,10 +31,13 @@ namespace osu.Game.Overlays
Origin = Anchor.Centre; Origin = Anchor.Centre;
} }
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, IAPIProvider api) private void load(OsuColour colours, IAPIProvider api)
{ {
api.Register(this); apiState.BindTo(api.State);
apiState.BindValueChanged(apiStateChanged, true);
Children = new Drawable[] Children = new Drawable[]
{ {
@ -97,9 +101,9 @@ namespace osu.Game.Overlays
this.FadeOut(100); this.FadeOut(100);
} }
public void APIStateChanged(IAPIProvider api, APIState state) private void apiStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{ {
switch (state) switch (state.NewValue)
{ {
case APIState.Offline: case APIState.Offline:
case APIState.Failing: case APIState.Failing:
@ -112,6 +116,6 @@ namespace osu.Game.Overlays
Hide(); Hide();
break; break;
} }
} });
} }
} }

View File

@ -130,6 +130,9 @@ namespace osu.Game.Overlays.BeatmapListing
searchControl.Category.BindValueChanged(_ => queueUpdateSearch()); searchControl.Category.BindValueChanged(_ => queueUpdateSearch());
searchControl.Genre.BindValueChanged(_ => queueUpdateSearch()); searchControl.Genre.BindValueChanged(_ => queueUpdateSearch());
searchControl.Language.BindValueChanged(_ => queueUpdateSearch()); searchControl.Language.BindValueChanged(_ => queueUpdateSearch());
searchControl.Extra.CollectionChanged += (_, __) => queueUpdateSearch();
searchControl.Ranks.CollectionChanged += (_, __) => queueUpdateSearch();
searchControl.Played.BindValueChanged(_ => queueUpdateSearch());
sortCriteria.BindValueChanged(_ => queueUpdateSearch()); sortCriteria.BindValueChanged(_ => queueUpdateSearch());
sortDirection.BindValueChanged(_ => queueUpdateSearch()); sortDirection.BindValueChanged(_ => queueUpdateSearch());
@ -179,7 +182,10 @@ namespace osu.Game.Overlays.BeatmapListing
sortControl.Current.Value, sortControl.Current.Value,
sortControl.SortDirection.Value, sortControl.SortDirection.Value,
searchControl.Genre.Value, searchControl.Genre.Value,
searchControl.Language.Value); searchControl.Language.Value,
searchControl.Extra,
searchControl.Ranks,
searchControl.Played.Value);
getSetsRequest.Success += response => getSetsRequest.Success += response =>
{ {

View File

@ -13,6 +13,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Scoring;
namespace osu.Game.Overlays.BeatmapListing namespace osu.Game.Overlays.BeatmapListing
{ {
@ -28,6 +29,12 @@ namespace osu.Game.Overlays.BeatmapListing
public Bindable<SearchLanguage> Language => languageFilter.Current; public Bindable<SearchLanguage> Language => languageFilter.Current;
public BindableList<SearchExtra> Extra => extraFilter.Current;
public BindableList<ScoreRank> Ranks => ranksFilter.Current;
public Bindable<SearchPlayed> Played => playedFilter.Current;
public BeatmapSetInfo BeatmapSet public BeatmapSetInfo BeatmapSet
{ {
set set
@ -48,6 +55,9 @@ namespace osu.Game.Overlays.BeatmapListing
private readonly BeatmapSearchFilterRow<SearchCategory> categoryFilter; private readonly BeatmapSearchFilterRow<SearchCategory> categoryFilter;
private readonly BeatmapSearchFilterRow<SearchGenre> genreFilter; private readonly BeatmapSearchFilterRow<SearchGenre> genreFilter;
private readonly BeatmapSearchFilterRow<SearchLanguage> languageFilter; private readonly BeatmapSearchFilterRow<SearchLanguage> languageFilter;
private readonly BeatmapSearchMultipleSelectionFilterRow<SearchExtra> extraFilter;
private readonly BeatmapSearchScoreFilterRow ranksFilter;
private readonly BeatmapSearchFilterRow<SearchPlayed> playedFilter;
private readonly Box background; private readonly Box background;
private readonly UpdateableBeatmapSetCover beatmapCover; private readonly UpdateableBeatmapSetCover beatmapCover;
@ -105,6 +115,9 @@ namespace osu.Game.Overlays.BeatmapListing
categoryFilter = new BeatmapSearchFilterRow<SearchCategory>(@"Categories"), categoryFilter = new BeatmapSearchFilterRow<SearchCategory>(@"Categories"),
genreFilter = new BeatmapSearchFilterRow<SearchGenre>(@"Genre"), genreFilter = new BeatmapSearchFilterRow<SearchGenre>(@"Genre"),
languageFilter = new BeatmapSearchFilterRow<SearchLanguage>(@"Language"), languageFilter = new BeatmapSearchFilterRow<SearchLanguage>(@"Language"),
extraFilter = new BeatmapSearchMultipleSelectionFilterRow<SearchExtra>(@"Extra"),
ranksFilter = new BeatmapSearchScoreFilterRow(),
playedFilter = new BeatmapSearchFilterRow<SearchPlayed>(@"Played")
} }
} }
} }

View File

@ -1,20 +1,16 @@
// 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 JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osuTK; using osuTK;
using osuTK.Graphics;
using Humanizer; using Humanizer;
using osu.Game.Utils; using osu.Game.Utils;
@ -32,6 +28,7 @@ namespace osu.Game.Overlays.BeatmapListing
public BeatmapSearchFilterRow(string headerName) public BeatmapSearchFilterRow(string headerName)
{ {
Drawable filter;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AddInternal(new GridContainer AddInternal(new GridContainer
@ -49,7 +46,7 @@ namespace osu.Game.Overlays.BeatmapListing
}, },
Content = new[] Content = new[]
{ {
new Drawable[] new[]
{ {
new OsuSpriteText new OsuSpriteText
{ {
@ -58,17 +55,17 @@ namespace osu.Game.Overlays.BeatmapListing
Font = OsuFont.GetFont(size: 13), Font = OsuFont.GetFont(size: 13),
Text = headerName.Titleize() Text = headerName.Titleize()
}, },
CreateFilter().With(f => filter = CreateFilter()
{
f.Current = current;
})
} }
} }
}); });
if (filter is IHasCurrentValue<T> filterWithValue)
Current = filterWithValue.Current;
} }
[NotNull] [NotNull]
protected virtual BeatmapSearchFilter CreateFilter() => new BeatmapSearchFilter(); protected virtual Drawable CreateFilter() => new BeatmapSearchFilter();
protected class BeatmapSearchFilter : TabControl<T> protected class BeatmapSearchFilter : TabControl<T>
{ {
@ -97,63 +94,7 @@ namespace osu.Game.Overlays.BeatmapListing
protected override Dropdown<T> CreateDropdown() => new FilterDropdown(); protected override Dropdown<T> CreateDropdown() => new FilterDropdown();
protected override TabItem<T> CreateTabItem(T value) => new FilterTabItem(value); protected override TabItem<T> CreateTabItem(T value) => new FilterTabItem<T>(value);
protected class FilterTabItem : TabItem<T>
{
protected virtual float TextSize => 13;
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
private readonly OsuSpriteText text;
public FilterTabItem(T value)
: base(value)
{
AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
AddRangeInternal(new Drawable[]
{
text = new OsuSpriteText
{
Font = OsuFont.GetFont(size: TextSize, weight: FontWeight.Regular),
Text = (value as Enum)?.GetDescription() ?? value.ToString()
},
new HoverClickSounds()
});
Enabled.Value = true;
}
[BackgroundDependencyLoader]
private void load()
{
updateState();
}
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
updateState();
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
updateState();
}
protected override void OnActivated() => updateState();
protected override void OnDeactivated() => updateState();
private void updateState() => text.FadeColour(Active.Value ? Color4.White : getStateColour(), 200, Easing.OutQuint);
private Color4 getStateColour() => IsHovered ? colourProvider.Light1 : colourProvider.Light3;
}
private class FilterDropdown : OsuTabDropdown<T> private class FilterDropdown : OsuTabDropdown<T>
{ {

View File

@ -0,0 +1,93 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osuTK;
namespace osu.Game.Overlays.BeatmapListing
{
public class BeatmapSearchMultipleSelectionFilterRow<T> : BeatmapSearchFilterRow<List<T>>
{
public new readonly BindableList<T> Current = new BindableList<T>();
private MultipleSelectionFilter filter;
public BeatmapSearchMultipleSelectionFilterRow(string headerName)
: base(headerName)
{
Current.BindTo(filter.Current);
}
protected sealed override Drawable CreateFilter() => filter = CreateMultipleSelectionFilter();
/// <summary>
/// Creates a filter control that can be used to simultaneously select multiple values of type <typeparamref name="T"/>.
/// </summary>
protected virtual MultipleSelectionFilter CreateMultipleSelectionFilter() => new MultipleSelectionFilter();
protected class MultipleSelectionFilter : FillFlowContainer<MultipleSelectionFilterTabItem>
{
public readonly BindableList<T> Current = new BindableList<T>();
[BackgroundDependencyLoader]
private void load()
{
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
RelativeSizeAxes = Axes.X;
Height = 15;
Spacing = new Vector2(10, 0);
AddRange(GetValues().Select(CreateTabItem));
}
protected override void LoadComplete()
{
base.LoadComplete();
foreach (var item in Children)
item.Active.BindValueChanged(active => toggleItem(item.Value, active.NewValue));
}
/// <summary>
/// Returns all values to be displayed in this filter row.
/// </summary>
protected virtual IEnumerable<T> GetValues() => Enum.GetValues(typeof(T)).Cast<T>();
/// <summary>
/// Creates a <see cref="MultipleSelectionFilterTabItem"/> representing the supplied <paramref name="value"/>.
/// </summary>
protected virtual MultipleSelectionFilterTabItem CreateTabItem(T value) => new MultipleSelectionFilterTabItem(value);
private void toggleItem(T value, bool active)
{
if (active)
Current.Add(value);
else
Current.Remove(value);
}
}
protected class MultipleSelectionFilterTabItem : FilterTabItem<T>
{
public MultipleSelectionFilterTabItem(T value)
: base(value)
{
}
protected override bool OnClick(ClickEvent e)
{
base.OnClick(e);
Active.Toggle();
return true;
}
}
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets; using osu.Game.Rulesets;
namespace osu.Game.Overlays.BeatmapListing namespace osu.Game.Overlays.BeatmapListing
@ -13,7 +14,7 @@ namespace osu.Game.Overlays.BeatmapListing
{ {
} }
protected override BeatmapSearchFilter CreateFilter() => new RulesetFilter(); protected override Drawable CreateFilter() => new RulesetFilter();
private class RulesetFilter : BeatmapSearchFilter private class RulesetFilter : BeatmapSearchFilter
{ {

View File

@ -0,0 +1,50 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Extensions;
using osu.Game.Scoring;
namespace osu.Game.Overlays.BeatmapListing
{
public class BeatmapSearchScoreFilterRow : BeatmapSearchMultipleSelectionFilterRow<ScoreRank>
{
public BeatmapSearchScoreFilterRow()
: base(@"Rank Achieved")
{
}
protected override MultipleSelectionFilter CreateMultipleSelectionFilter() => new RankFilter();
private class RankFilter : MultipleSelectionFilter
{
protected override MultipleSelectionFilterTabItem CreateTabItem(ScoreRank value) => new RankItem(value);
protected override IEnumerable<ScoreRank> GetValues() => base.GetValues().Reverse();
}
private class RankItem : MultipleSelectionFilterTabItem
{
public RankItem(ScoreRank value)
: base(value)
{
}
protected override string LabelFor(ScoreRank value)
{
switch (value)
{
case ScoreRank.XH:
return @"Silver SS";
case ScoreRank.SH:
return @"Silver S";
default:
return value.GetDescription();
}
}
}
}
}

View File

@ -0,0 +1,79 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK.Graphics;
namespace osu.Game.Overlays.BeatmapListing
{
public class FilterTabItem<T> : TabItem<T>
{
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
private OsuSpriteText text;
public FilterTabItem(T value)
: base(value)
{
}
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
AddRangeInternal(new Drawable[]
{
text = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 13, weight: FontWeight.Regular),
Text = LabelFor(Value)
},
new HoverClickSounds()
});
Enabled.Value = true;
updateState();
}
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
updateState();
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
updateState();
}
protected override void OnActivated() => updateState();
protected override void OnDeactivated() => updateState();
/// <summary>
/// Returns the label text to be used for the supplied <paramref name="value"/>.
/// </summary>
protected virtual string LabelFor(T value) => (value as Enum)?.GetDescription() ?? value.ToString();
private void updateState()
{
text.FadeColour(IsHovered ? colourProvider.Light1 : getStateColour(), 200, Easing.OutQuint);
text.Font = text.Font.With(weight: Active.Value ? FontWeight.SemiBold : FontWeight.Regular);
}
private Color4 getStateColour() => Active.Value ? colourProvider.Content1 : colourProvider.Light2;
}
}

View File

@ -0,0 +1,16 @@
// 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.ComponentModel;
namespace osu.Game.Overlays.BeatmapListing
{
public enum SearchExtra
{
[Description("Has Video")]
Video,
[Description("Has Storyboard")]
Storyboard
}
}

View File

@ -1,10 +1,12 @@
// 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.
namespace osu.Game.Online.API namespace osu.Game.Overlays.BeatmapListing
{ {
public interface IOnlineComponent public enum SearchPlayed
{ {
void APIStateChanged(IAPIProvider api, APIState state); Any,
Played,
Unplayed
} }
} }

View File

@ -33,9 +33,14 @@ namespace osu.Game.Overlays
{ {
} }
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(IAPIProvider api)
{ {
apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -130,13 +135,13 @@ namespace osu.Game.Overlays
} }
} }
public override void APIStateChanged(IAPIProvider api, APIState state) private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{ {
if (State.Value == Visibility.Hidden) if (State.Value == Visibility.Hidden)
return; return;
Header.Current.TriggerChange(); Header.Current.TriggerChange();
} });
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {

View File

@ -12,7 +12,7 @@ using osuTK.Graphics;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
public abstract class FullscreenOverlay<T> : WaveOverlayContainer, IOnlineComponent, INamedOverlayComponent public abstract class FullscreenOverlay<T> : WaveOverlayContainer, INamedOverlayComponent
where T : OverlayHeader where T : OverlayHeader
{ {
public virtual string IconTexture => Header?.Title.IconTexture ?? string.Empty; public virtual string IconTexture => Header?.Title.IconTexture ?? string.Empty;
@ -86,21 +86,5 @@ namespace osu.Game.Overlays
protected virtual void PopOutComplete() protected virtual void PopOutComplete()
{ {
} }
protected override void LoadComplete()
{
base.LoadComplete();
API.Register(this);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
API?.Unregister(this);
}
public virtual void APIStateChanged(IAPIProvider api, APIState state)
{
}
} }
} }

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Online.API; using osu.Game.Online.API;
@ -15,7 +16,7 @@ namespace osu.Game.Overlays
/// Automatically performs a data fetch on load. /// Automatically performs a data fetch on load.
/// </remarks> /// </remarks>
/// <typeparam name="T">The type of the API response.</typeparam> /// <typeparam name="T">The type of the API response.</typeparam>
public abstract class OverlayView<T> : CompositeDrawable, IOnlineComponent public abstract class OverlayView<T> : CompositeDrawable
where T : class where T : class
{ {
[Resolved] [Resolved]
@ -29,10 +30,13 @@ namespace osu.Game.Overlays
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
} }
protected override void LoadComplete() private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[BackgroundDependencyLoader]
private void load()
{ {
base.LoadComplete(); apiState.BindTo(API.State);
API.Register(this); apiState.BindValueChanged(onlineStateChanged, true);
} }
/// <summary> /// <summary>
@ -59,20 +63,19 @@ namespace osu.Game.Overlays
API.Queue(request); API.Queue(request);
} }
public virtual void APIStateChanged(IAPIProvider api, APIState state) private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{ {
switch (state) switch (state.NewValue)
{ {
case APIState.Online: case APIState.Online:
PerformFetch(); PerformFetch();
break; break;
} }
} });
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
request?.Cancel(); request?.Cancel();
API?.Unregister(this);
base.Dispose(isDisposing); base.Dispose(isDisposing);
} }
} }

View File

@ -39,6 +39,12 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
LabelText = "Background source", LabelText = "Background source",
Current = config.GetBindable<BackgroundSource>(OsuSetting.MenuBackgroundSource), Current = config.GetBindable<BackgroundSource>(OsuSetting.MenuBackgroundSource),
Items = Enum.GetValues(typeof(BackgroundSource)).Cast<BackgroundSource>() Items = Enum.GetValues(typeof(BackgroundSource)).Cast<BackgroundSource>()
},
new SettingsDropdown<SeasonalBackgroundMode>
{
LabelText = "Seasonal backgrounds",
Current = config.GetBindable<SeasonalBackgroundMode>(OsuSetting.SeasonalBackgroundMode),
Items = Enum.GetValues(typeof(SeasonalBackgroundMode)).Cast<SeasonalBackgroundMode>()
} }
}; };
} }

View File

@ -37,10 +37,10 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay
LabelText = "Lighten playfield during breaks", LabelText = "Lighten playfield during breaks",
Current = config.GetBindable<bool>(OsuSetting.LightenDuringBreaks) Current = config.GetBindable<bool>(OsuSetting.LightenDuringBreaks)
}, },
new SettingsCheckbox new SettingsEnumDropdown<HUDVisibilityMode>
{ {
LabelText = "Show score overlay", LabelText = "HUD overlay visibility mode",
Current = config.GetBindable<bool>(OsuSetting.ShowInterface) Current = config.GetBindable<HUDVisibilityMode>(OsuSetting.HUDVisibilityMode)
}, },
new SettingsCheckbox new SettingsCheckbox
{ {
@ -78,7 +78,7 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay
LabelText = "Score display mode", LabelText = "Score display mode",
Current = config.GetBindable<ScoringMode>(OsuSetting.ScoreDisplayMode), Current = config.GetBindable<ScoringMode>(OsuSetting.ScoreDisplayMode),
Keywords = new[] { "scoring" } Keywords = new[] { "scoring" }
} },
}; };
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows) if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)

View File

@ -13,6 +13,7 @@ using osu.Game.Online.API;
using osuTK; using osuTK;
using osu.Game.Users; using osu.Game.Users;
using System.ComponentModel; using System.ComponentModel;
using osu.Framework.Bindables;
using osu.Game.Graphics; using osu.Game.Graphics;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -25,7 +26,7 @@ using Container = osu.Framework.Graphics.Containers.Container;
namespace osu.Game.Overlays.Settings.Sections.General namespace osu.Game.Overlays.Settings.Sections.General
{ {
public class LoginSettings : FillFlowContainer, IOnlineComponent public class LoginSettings : FillFlowContainer
{ {
private bool bounding = true; private bool bounding = true;
private LoginForm form; private LoginForm form;
@ -41,6 +42,11 @@ namespace osu.Game.Overlays.Settings.Sections.General
/// </summary> /// </summary>
public Action RequestHide; public Action RequestHide;
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[Resolved]
private IAPIProvider api { get; set; }
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty; public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
public bool Bounding public bool Bounding
@ -61,17 +67,18 @@ namespace osu.Game.Overlays.Settings.Sections.General
Spacing = new Vector2(0f, 5f); Spacing = new Vector2(0f, 5f);
} }
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader]
private void load(IAPIProvider api) private void load()
{ {
api?.Register(this); apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true);
} }
public void APIStateChanged(IAPIProvider api, APIState state) => Schedule(() => private void onlineStateChanged(ValueChangedEvent<APIState> state) => Schedule(() =>
{ {
form = null; form = null;
switch (state) switch (state.NewValue)
{ {
case APIState.Offline: case APIState.Offline:
Children = new Drawable[] Children = new Drawable[]
@ -107,7 +114,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
TextAnchor = Anchor.TopCentre, TextAnchor = Anchor.TopCentre,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Text = state == APIState.Failing ? "Connection is failing, will attempt to reconnect... " : "Attempting to connect... ", Text = state.NewValue == APIState.Failing ? "Connection is failing, will attempt to reconnect... " : "Attempting to connect... ",
Margin = new MarginPadding { Top = 10, Bottom = 10 }, Margin = new MarginPadding { Top = 10, Bottom = 10 },
}, },
}; };

Some files were not shown because too many files have changed in this diff Show More