Merge remote-tracking branch 'upstream/master' into more-inspections

This commit is contained in:
Dean Herbert 2019-02-28 13:09:18 +09:00
commit 3e1f283281
9 changed files with 113 additions and 74 deletions

View File

@ -4,10 +4,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Screens; using osu.Framework.Platform;
using osu.Game.Screens;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using osuTK.Graphics; using osuTK.Graphics;
@ -21,8 +21,12 @@ namespace osu.Game.Tests.Visual
typeof(OsuLogo), typeof(OsuLogo),
}; };
public TestCaseOsuGame() [BackgroundDependencyLoader]
private void load(GameHost host)
{ {
OsuGame game = new OsuGame();
game.SetHost(host);
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -30,10 +34,7 @@ namespace osu.Game.Tests.Visual
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = Color4.Black, Colour = Color4.Black,
}, },
new ScreenStack(new Loader()) game
{
RelativeSizeAxes = Axes.Both,
}
}; };
} }
} }

View File

@ -15,7 +15,7 @@ namespace osu.Game.Tests.Visual
public class TestCaseSongProgress : OsuTestCase public class TestCaseSongProgress : OsuTestCase
{ {
private readonly SongProgress progress; private readonly SongProgress progress;
private readonly SongProgressGraph graph; private readonly TestSongProgressGraph graph;
private readonly StopwatchClock clock; private readonly StopwatchClock clock;
@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
}); });
Add(graph = new SongProgressGraph Add(graph = new TestSongProgressGraph
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 200, Height = 200,
@ -39,13 +39,24 @@ namespace osu.Game.Tests.Visual
Origin = Anchor.TopLeft, Origin = Anchor.TopLeft,
}); });
AddWaitStep(5);
AddAssert("ensure not created", () => graph.CreationCount == 0);
AddStep("display values", displayNewValues);
AddWaitStep(5);
AddUntilStep(() => graph.CreationCount == 1, "wait for creation count");
AddStep("Toggle Bar", () => progress.AllowSeeking = !progress.AllowSeeking); AddStep("Toggle Bar", () => progress.AllowSeeking = !progress.AllowSeeking);
AddWaitStep(5); AddWaitStep(5);
AddUntilStep(() => graph.CreationCount == 1, "wait for creation count");
AddStep("Toggle Bar", () => progress.AllowSeeking = !progress.AllowSeeking); AddStep("Toggle Bar", () => progress.AllowSeeking = !progress.AllowSeeking);
AddWaitStep(2); AddWaitStep(5);
AddUntilStep(() => graph.CreationCount == 1, "wait for creation count");
AddRepeatStep("New Values", displayNewValues, 5); AddRepeatStep("New Values", displayNewValues, 5);
displayNewValues(); AddWaitStep(5);
AddAssert("ensure debounced", () => graph.CreationCount == 2);
} }
private void displayNewValues() private void displayNewValues()
@ -60,5 +71,16 @@ namespace osu.Game.Tests.Visual
progress.AudioClock = clock; progress.AudioClock = clock;
progress.OnSeek = pos => clock.Seek(pos); progress.OnSeek = pos => clock.Seek(pos);
} }
private class TestSongProgressGraph : SongProgressGraph
{
public int CreationCount { get; private set; }
protected override void RecreateGraph()
{
base.RecreateGraph();
CreationCount++;
}
}
} }
} }

View File

@ -626,6 +626,10 @@ namespace osu.Game
try try
{ {
Logger.Log($"Loading {d}...", level: LogLevel.Debug); Logger.Log($"Loading {d}...", level: LogLevel.Debug);
if (IsDisposed)
return;
await LoadComponentAsync(d, add); await LoadComponentAsync(d, add);
Logger.Log($"Loaded {d}!", level: LogLevel.Debug); Logger.Log($"Loaded {d}!", level: LogLevel.Debug);
} }

View File

@ -63,8 +63,11 @@ namespace osu.Game.Overlays.Direct
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
beatmaps.BeatmapDownloadBegan -= attachDownload; if (beatmaps != null)
beatmaps.ItemAdded -= setAdded; {
beatmaps.BeatmapDownloadBegan -= attachDownload;
beatmaps.ItemAdded -= setAdded;
}
State.UnbindAll(); State.UnbindAll();

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using osu.Framework; using osu.Framework;
using osu.Framework.Caching; using osu.Framework.Caching;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -12,14 +13,16 @@ using osu.Framework.Graphics.Containers;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Allocation;
using osu.Framework.Threading;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
public class SquareGraph : BufferedContainer public class SquareGraph : Container
{ {
private Column[] columns = { }; private BufferedContainer<Column> columns;
public int ColumnCount => columns.Length; public int ColumnCount => columns?.Children.Count ?? 0;
private int progress; private int progress;
@ -65,13 +68,6 @@ namespace osu.Game.Screens.Play
} }
} }
public SquareGraph()
{
CacheDrawnFrameBuffer = true;
}
private Cached layout = new Cached();
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true) public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
{ {
if ((invalidation & Invalidation.DrawSize) > 0) if ((invalidation & Invalidation.DrawSize) > 0)
@ -79,25 +75,70 @@ namespace osu.Game.Screens.Play
return base.Invalidate(invalidation, source, shallPropagate); return base.Invalidate(invalidation, source, shallPropagate);
} }
private Cached layout = new Cached();
private ScheduledDelegate scheduledCreate;
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
if (!layout.IsValid) if (values != null && !layout.IsValid)
{ {
recreateGraph(); columns?.FadeOut(500, Easing.OutQuint).Expire();
scheduledCreate?.Cancel();
scheduledCreate = Scheduler.AddDelayed(RecreateGraph, 500);
layout.Validate(); layout.Validate();
} }
} }
private CancellationTokenSource cts;
/// <summary>
/// Recreates the entire graph.
/// </summary>
protected virtual void RecreateGraph()
{
var newColumns = new BufferedContainer<Column>
{
CacheDrawnFrameBuffer = true,
RelativeSizeAxes = Axes.Both,
};
for (float x = 0; x < DrawWidth; x += Column.WIDTH)
{
newColumns.Add(new Column(DrawHeight)
{
LitColour = fillColour,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Position = new Vector2(x, 0),
State = ColumnState.Dimmed,
});
}
cts?.Cancel();
LoadComponentAsync(newColumns, c =>
{
Child = columns = c;
columns.FadeInFromZero(500, Easing.OutQuint);
recalculateValues();
redrawFilled();
redrawProgress();
}, (cts = new CancellationTokenSource()).Token);
}
/// <summary> /// <summary>
/// Redraws all the columns to match their lit/dimmed state. /// Redraws all the columns to match their lit/dimmed state.
/// </summary> /// </summary>
private void redrawProgress() private void redrawProgress()
{ {
for (int i = 0; i < columns.Length; i++) for (int i = 0; i < ColumnCount; i++)
columns[i].State = i <= progress ? ColumnState.Lit : ColumnState.Dimmed; columns[i].State = i <= progress ? ColumnState.Lit : ColumnState.Dimmed;
ForceRedraw(); columns?.ForceRedraw();
} }
/// <summary> /// <summary>
@ -107,7 +148,7 @@ namespace osu.Game.Screens.Play
{ {
for (int i = 0; i < ColumnCount; i++) for (int i = 0; i < ColumnCount; i++)
columns[i].Filled = calculatedValues.ElementAtOrDefault(i); columns[i].Filled = calculatedValues.ElementAtOrDefault(i);
ForceRedraw(); columns?.ForceRedraw();
} }
/// <summary> /// <summary>
@ -136,34 +177,6 @@ namespace osu.Game.Screens.Play
calculatedValues = newValues.ToArray(); calculatedValues = newValues.ToArray();
} }
/// <summary>
/// Recreates the entire graph.
/// </summary>
private void recreateGraph()
{
var newColumns = new List<Column>();
for (float x = 0; x < DrawWidth; x += Column.WIDTH)
{
newColumns.Add(new Column
{
LitColour = fillColour,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Height = DrawHeight,
Position = new Vector2(x, 0),
State = ColumnState.Dimmed,
});
}
columns = newColumns.ToArray();
Children = columns;
recalculateValues();
redrawFilled();
redrawProgress();
}
public class Column : Container, IStateful<ColumnState> public class Column : Container, IStateful<ColumnState>
{ {
protected readonly Color4 EmptyColour = Color4.White.Opacity(20); protected readonly Color4 EmptyColour = Color4.White.Opacity(20);
@ -210,21 +223,20 @@ namespace osu.Game.Screens.Play
} }
} }
public Column() public Column(float height)
{ {
Width = WIDTH; Width = WIDTH;
Height = height;
} }
protected override void LoadComplete() [BackgroundDependencyLoader]
private void load()
{ {
for (int r = 0; r < cubeCount; r++) drawableRows.AddRange(Enumerable.Range(0, (int)cubeCount).Select(r => new Box
{ {
drawableRows.Add(new Box Size = new Vector2(cube_size),
{ Position = new Vector2(0, r * WIDTH + padding),
Size = new Vector2(cube_size), }));
Position = new Vector2(0, r * WIDTH + padding),
});
}
Children = drawableRows; Children = drawableRows;

View File

@ -512,12 +512,6 @@ namespace osu.Game.Screens.Select
if (base.OnExiting(next)) if (base.OnExiting(next))
return true; return true;
if (ModSelect.State == Visibility.Visible)
{
ModSelect.Hide();
return true;
}
beatmapInfoWedge.State = Visibility.Hidden; beatmapInfoWedge.State = Visibility.Hidden;
this.FadeOut(100); this.FadeOut(100);

View File

@ -92,6 +92,9 @@ namespace osu.Game.Skinning
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
// Must be done before base.Dispose()
SourceChanged = null;
base.Dispose(isDisposing); base.Dispose(isDisposing);
if (fallbackSource != null) if (fallbackSource != null)

View File

@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.223.0" /> <PackageReference Include="ppy.osu.Framework" Version="2019.227.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" /> <PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" /> <PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />

View File

@ -105,8 +105,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.223.0" /> <PackageReference Include="ppy.osu.Framework" Version="2019.227.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.223.0" /> <PackageReference Include="ppy.osu.Framework.iOS" Version="2019.227.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" /> <PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" /> <PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />