1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Merge branch 'master' into editor-object-object-snapping

This commit is contained in:
Dean Herbert 2020-09-25 12:15:10 +09:00
commit b9196718b7
7 changed files with 245 additions and 67 deletions

View File

@ -0,0 +1,134 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Textures;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.UI;
using osu.Game.Tests.Visual;
namespace osu.Game.Tests.Rulesets
{
public class TestSceneDrawableRulesetDependencies : OsuTestScene
{
[Test]
public void TestDisposalDoesNotDisposeParentStores()
{
DrawableWithDependencies drawable = null;
TestTextureStore textureStore = null;
TestSampleStore sampleStore = null;
AddStep("add dependencies", () =>
{
Child = drawable = new DrawableWithDependencies();
textureStore = drawable.ParentTextureStore;
sampleStore = drawable.ParentSampleStore;
});
AddStep("clear children", Clear);
AddUntilStep("wait for disposal", () => drawable.IsDisposed);
AddStep("GC", () =>
{
drawable = null;
GC.Collect();
GC.WaitForPendingFinalizers();
});
AddAssert("parent texture store not disposed", () => !textureStore.IsDisposed);
AddAssert("parent sample store not disposed", () => !sampleStore.IsDisposed);
}
private class DrawableWithDependencies : CompositeDrawable
{
public TestTextureStore ParentTextureStore { get; private set; }
public TestSampleStore ParentSampleStore { get; private set; }
public DrawableWithDependencies()
{
InternalChild = new Box { RelativeSizeAxes = Axes.Both };
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs<TextureStore>(ParentTextureStore = new TestTextureStore());
dependencies.CacheAs<ISampleStore>(ParentSampleStore = new TestSampleStore());
return new DrawableRulesetDependencies(new OsuRuleset(), dependencies);
}
public new bool IsDisposed { get; private set; }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
IsDisposed = true;
}
}
private class TestTextureStore : TextureStore
{
public override Texture Get(string name, WrapMode wrapModeS, WrapMode wrapModeT) => null;
public bool IsDisposed { get; private set; }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
IsDisposed = true;
}
}
private class TestSampleStore : ISampleStore
{
public bool IsDisposed { get; private set; }
public void Dispose()
{
IsDisposed = true;
}
public SampleChannel Get(string name) => null;
public Task<SampleChannel> GetAsync(string name) => null;
public Stream GetStream(string name) => null;
public IEnumerable<string> GetAvailableResources() => throw new NotImplementedException();
public BindableNumber<double> Volume => throw new NotImplementedException();
public BindableNumber<double> Balance => throw new NotImplementedException();
public BindableNumber<double> Frequency => throw new NotImplementedException();
public BindableNumber<double> Tempo => throw new NotImplementedException();
public void AddAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable) => throw new NotImplementedException();
public void RemoveAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable) => throw new NotImplementedException();
public void RemoveAllAdjustments(AdjustableProperty type) => throw new NotImplementedException();
public IBindable<double> AggregateVolume => throw new NotImplementedException();
public IBindable<double> AggregateBalance => throw new NotImplementedException();
public IBindable<double> AggregateFrequency => throw new NotImplementedException();
public IBindable<double> AggregateTempo => throw new NotImplementedException();
public int PlaybackConcurrency { get; set; }
}
}
}

View File

@ -220,7 +220,7 @@ namespace osu.Game.Tests.Visual.Ranking
AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen()));
AddAssert("download button is disabled", () => !screen.ChildrenOfType<DownloadButton>().Single().Enabled.Value);
AddAssert("download button is disabled", () => !screen.ChildrenOfType<DownloadButton>().Last().Enabled.Value);
AddStep("click contracted panel", () =>
{
@ -229,7 +229,7 @@ namespace osu.Game.Tests.Visual.Ranking
InputManager.Click(MouseButton.Left);
});
AddAssert("download button is enabled", () => screen.ChildrenOfType<DownloadButton>().Single().Enabled.Value);
AddAssert("download button is enabled", () => screen.ChildrenOfType<DownloadButton>().Last().Enabled.Value);
}
private class TestResultsContainer : Container

View File

@ -10,6 +10,7 @@ using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Game.Rulesets.Configuration;
@ -46,12 +47,11 @@ namespace osu.Game.Rulesets.UI
if (resources != null)
{
TextureStore = new TextureStore(new TextureLoaderStore(new NamespacedResourceStore<byte[]>(resources, @"Textures")));
TextureStore.AddStore(parent.Get<TextureStore>());
Cache(TextureStore);
CacheAs(TextureStore = new FallbackTextureStore(TextureStore, parent.Get<TextureStore>()));
SampleStore = parent.Get<AudioManager>().GetSampleStore(new NamespacedResourceStore<byte[]>(resources, @"Samples"));
SampleStore.PlaybackConcurrency = OsuGameBase.SAMPLE_CONCURRENCY;
CacheAs<ISampleStore>(new FallbackSampleStore(SampleStore, parent.Get<ISampleStore>()));
CacheAs(SampleStore = new FallbackSampleStore(SampleStore, parent.Get<ISampleStore>()));
}
RulesetConfigManager = parent.Get<RulesetConfigCache>().GetConfigFor(ruleset);
@ -82,69 +82,92 @@ namespace osu.Game.Rulesets.UI
isDisposed = true;
SampleStore?.Dispose();
TextureStore?.Dispose();
RulesetConfigManager = null;
}
#endregion
}
/// <summary>
/// A sample store which adds a fallback source.
/// </summary>
/// <remarks>
/// This is a temporary implementation to workaround ISampleStore limitations.
/// </remarks>
public class FallbackSampleStore : ISampleStore
{
private readonly ISampleStore primary;
private readonly ISampleStore secondary;
public FallbackSampleStore(ISampleStore primary, ISampleStore secondary)
/// <summary>
/// A sample store which adds a fallback source and prevents disposal of the fallback source.
/// </summary>
private class FallbackSampleStore : ISampleStore
{
this.primary = primary;
this.secondary = secondary;
private readonly ISampleStore primary;
private readonly ISampleStore fallback;
public FallbackSampleStore(ISampleStore primary, ISampleStore fallback)
{
this.primary = primary;
this.fallback = fallback;
}
public SampleChannel Get(string name) => primary.Get(name) ?? fallback.Get(name);
public Task<SampleChannel> GetAsync(string name) => primary.GetAsync(name) ?? fallback.GetAsync(name);
public Stream GetStream(string name) => primary.GetStream(name) ?? fallback.GetStream(name);
public IEnumerable<string> GetAvailableResources() => throw new NotSupportedException();
public void AddAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable) => throw new NotSupportedException();
public void RemoveAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable) => throw new NotSupportedException();
public void RemoveAllAdjustments(AdjustableProperty type) => throw new NotSupportedException();
public BindableNumber<double> Volume => throw new NotSupportedException();
public BindableNumber<double> Balance => throw new NotSupportedException();
public BindableNumber<double> Frequency => throw new NotSupportedException();
public BindableNumber<double> Tempo => throw new NotSupportedException();
public IBindable<double> GetAggregate(AdjustableProperty type) => throw new NotSupportedException();
public IBindable<double> AggregateVolume => throw new NotSupportedException();
public IBindable<double> AggregateBalance => throw new NotSupportedException();
public IBindable<double> AggregateFrequency => throw new NotSupportedException();
public IBindable<double> AggregateTempo => throw new NotSupportedException();
public int PlaybackConcurrency
{
get => throw new NotSupportedException();
set => throw new NotSupportedException();
}
public void Dispose()
{
primary?.Dispose();
}
}
public SampleChannel Get(string name) => primary.Get(name) ?? secondary.Get(name);
public Task<SampleChannel> GetAsync(string name) => primary.GetAsync(name) ?? secondary.GetAsync(name);
public Stream GetStream(string name) => primary.GetStream(name) ?? secondary.GetStream(name);
public IEnumerable<string> GetAvailableResources() => throw new NotSupportedException();
public void AddAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable) => throw new NotSupportedException();
public void RemoveAdjustment(AdjustableProperty type, BindableNumber<double> adjustBindable) => throw new NotSupportedException();
public void RemoveAllAdjustments(AdjustableProperty type) => throw new NotSupportedException();
public BindableNumber<double> Volume => throw new NotSupportedException();
public BindableNumber<double> Balance => throw new NotSupportedException();
public BindableNumber<double> Frequency => throw new NotSupportedException();
public BindableNumber<double> Tempo => throw new NotSupportedException();
public IBindable<double> GetAggregate(AdjustableProperty type) => throw new NotSupportedException();
public IBindable<double> AggregateVolume => throw new NotSupportedException();
public IBindable<double> AggregateBalance => throw new NotSupportedException();
public IBindable<double> AggregateFrequency => throw new NotSupportedException();
public IBindable<double> AggregateTempo => throw new NotSupportedException();
public int PlaybackConcurrency
/// <summary>
/// A texture store which adds a fallback source and prevents disposal of the fallback source.
/// </summary>
private class FallbackTextureStore : TextureStore
{
get => throw new NotSupportedException();
set => throw new NotSupportedException();
}
private readonly TextureStore primary;
private readonly TextureStore fallback;
public void Dispose()
{
public FallbackTextureStore(TextureStore primary, TextureStore fallback)
{
this.primary = primary;
this.fallback = fallback;
}
public override Texture Get(string name, WrapMode wrapModeS, WrapMode wrapModeT)
=> primary.Get(name, wrapModeS, wrapModeT) ?? fallback.Get(name, wrapModeS, wrapModeT);
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
primary?.Dispose();
}
}
}
}

View File

@ -22,10 +22,12 @@ namespace osu.Game.Screens.Edit.Components
{
trackTimer = new OsuSpriteText
{
Origin = Anchor.BottomLeft,
RelativePositionAxes = Axes.Y,
Font = OsuFont.GetFont(size: 22, fixedWidth: true),
Y = 0.5f,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
// intentionally fudged centre to avoid movement of the number portion when
// going negative.
X = -35,
Font = OsuFont.GetFont(size: 25, fixedWidth: true),
}
};
}
@ -34,7 +36,8 @@ namespace osu.Game.Screens.Edit.Components
{
base.Update();
trackTimer.Text = TimeSpan.FromMilliseconds(editorClock.CurrentTime).ToString(@"mm\:ss\:fff");
var timespan = TimeSpan.FromMilliseconds(editorClock.CurrentTime);
trackTimer.Text = $"{(timespan < TimeSpan.Zero ? "-" : string.Empty)}{timespan:mm\\:ss\\:fff}";
}
}
}

View File

@ -273,10 +273,10 @@ namespace osu.Game.Screens.Ranking
detachedPanelContainer.Add(expandedPanel);
// Move into its original location in the local container first, then to the final location.
var origLocation = detachedPanelContainer.ToLocalSpace(screenSpacePos);
expandedPanel.MoveTo(origLocation)
var origLocation = detachedPanelContainer.ToLocalSpace(screenSpacePos).X;
expandedPanel.MoveToX(origLocation)
.Then()
.MoveTo(new Vector2(StatisticsPanel.SIDE_PADDING, origLocation.Y), 150, Easing.OutQuint);
.MoveToX(StatisticsPanel.SIDE_PADDING, 150, Easing.OutQuint);
// Hide contracted panels.
foreach (var contracted in ScorePanelList.GetScorePanels().Where(p => p.State == PanelState.Contracted))

View File

@ -99,6 +99,8 @@ namespace osu.Game.Screens.Ranking
{
var panel = new ScorePanel(score)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
PostExpandAction = () => PostExpandAction?.Invoke()
}.With(p =>
{

View File

@ -75,7 +75,23 @@ namespace osu.Game.Screens.Ranking.Statistics
return;
if (newScore.HitEvents == null || newScore.HitEvents.Count == 0)
content.Add(new MessagePlaceholder("Score has no statistics :("));
{
content.Add(new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new MessagePlaceholder("Extended statistics are only available after watching a replay!"),
new ReplayDownloadButton(newScore)
{
Scale = new Vector2(1.5f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
}
});
}
else
{
spinner.Show();