mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 11:12:54 +08:00
Add better test for facade containers
This commit is contained in:
parent
6e98a8dd7c
commit
d37968d88d
113
osu.Game.Tests/Visual/TestCaseFacadeContainer.cs
Normal file
113
osu.Game.Tests/Visual/TestCaseFacadeContainer.cs
Normal file
@ -0,0 +1,113 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Menu;
|
||||
using osu.Game.Screens.Play;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public class TestCaseFacadeContainer : ScreenTestCase
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(PlayerLoader),
|
||||
typeof(Player),
|
||||
typeof(Facade),
|
||||
};
|
||||
|
||||
[Cached]
|
||||
private OsuLogo logo;
|
||||
|
||||
private readonly Bindable<float> uiScale = new Bindable<float>();
|
||||
|
||||
private OsuScreen baseScreen;
|
||||
|
||||
public TestCaseFacadeContainer()
|
||||
{
|
||||
Add(logo = new OsuLogo());
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
baseScreen = null;
|
||||
config.BindWith(OsuSetting.UIScale, uiScale);
|
||||
AddSliderStep("Adjust scale", 1f, 1.5f, 1f, v => uiScale.Value = v);
|
||||
AddToggleStep("Toggle mods", b => { Beatmap.Value.Mods.Value = b ? Beatmap.Value.Mods.Value.Concat(new[] { new OsuModNoFail() }) : Enumerable.Empty<Mod>(); });
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("Null screens", () => baseScreen = null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PlayerLoaderTest()
|
||||
{
|
||||
AddStep("Add new playerloader", () => LoadScreen(baseScreen = new TestPlayerLoader(() => new TestPlayer
|
||||
{
|
||||
AllowPause = false,
|
||||
AllowLeadIn = false,
|
||||
AllowResults = false,
|
||||
})));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MainMenuTest()
|
||||
{
|
||||
AddStep("Add new Main Menu", () => LoadScreen(baseScreen = new MainMenu()));
|
||||
}
|
||||
|
||||
private class TestFacadeContainer : FacadeContainer
|
||||
{
|
||||
protected override Facade CreateFacade() => new Facade
|
||||
{
|
||||
Colour = Color4.Tomato,
|
||||
Alpha = 0.35f,
|
||||
Child = new Box
|
||||
{
|
||||
Colour = Color4.Tomato,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private class TestPlayerLoader : PlayerLoader
|
||||
{
|
||||
public TestPlayerLoader(Func<Player> player)
|
||||
: base(player)
|
||||
{
|
||||
}
|
||||
|
||||
protected override FacadeContainer CreateFacadeContainer() => new TestFacadeContainer();
|
||||
}
|
||||
|
||||
private class TestPlayer : Player
|
||||
{
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
// Never finish loading
|
||||
while (true)
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -19,9 +20,11 @@ namespace osu.Game.Graphics.Containers
|
||||
private bool tracking;
|
||||
private bool smoothTransform;
|
||||
|
||||
protected virtual Facade CreateFacade() => new Facade();
|
||||
|
||||
public FacadeContainer()
|
||||
{
|
||||
facade = new Facade();
|
||||
facade = CreateFacade();
|
||||
}
|
||||
|
||||
private Vector2 logoTrackingPosition => logo.Parent.ToLocalSpace(facade.ScreenSpaceDrawQuad.Centre);
|
||||
@ -44,30 +47,26 @@ namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
base.UpdateAfterChildren();
|
||||
|
||||
facade.Size = new Vector2(logo.SizeForFlow * 0.3f);
|
||||
|
||||
if (!tracking)
|
||||
if (logo == null)
|
||||
return;
|
||||
|
||||
logo.RelativePositionAxes = Axes.None;
|
||||
facade.Size = new Vector2(logo.SizeForFlow * 0.3f);
|
||||
|
||||
bool childrenLoaded = true;
|
||||
|
||||
foreach (var d in Children)
|
||||
{
|
||||
if (!d.IsAlive)
|
||||
childrenLoaded = false;
|
||||
}
|
||||
|
||||
if (smoothTransform && childrenLoaded)
|
||||
if (smoothTransform && facade.IsLoaded && logo.Transforms.Count == 0)
|
||||
{
|
||||
// Our initial movement to the tracking location should be smooth.
|
||||
Schedule(() => logo.MoveTo(logoTrackingPosition, 500, Easing.InOutExpo));
|
||||
smoothTransform = false;
|
||||
Schedule(() =>
|
||||
{
|
||||
facade.Size = new Vector2(logo.SizeForFlow * 0.3f);
|
||||
logo.RelativePositionAxes = Axes.None;
|
||||
logo.MoveTo(logoTrackingPosition, 500, Easing.InOutExpo);
|
||||
smoothTransform = false;
|
||||
});
|
||||
}
|
||||
else if (logo.Transforms.Count == 0)
|
||||
else if (facade.IsLoaded && logo.Transforms.Count == 0)
|
||||
{
|
||||
// If all transforms have finished playing, the logo constantly track the position of the facade.
|
||||
logo.RelativePositionAxes = Axes.None;
|
||||
logo.Position = logoTrackingPosition;
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,8 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private FacadeContainer content;
|
||||
|
||||
protected virtual FacadeContainer CreateFacadeContainer() => new FacadeContainer();
|
||||
|
||||
private BeatmapMetadataDisplay info;
|
||||
|
||||
private bool hideOverlays;
|
||||
@ -60,32 +62,30 @@ namespace osu.Game.Screens.Play
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
InternalChild = content = new FacadeContainer
|
||||
InternalChild = content = CreateFacadeContainer();
|
||||
content.Anchor = Anchor.Centre;
|
||||
content.Origin = Anchor.Centre;
|
||||
content.RelativeSizeAxes = Axes.Both;
|
||||
content.Children = new Drawable[]
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
info = new BeatmapMetadataDisplay(Beatmap.Value)
|
||||
{
|
||||
info = new BeatmapMetadataDisplay(Beatmap.Value)
|
||||
Alpha = 0,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
},
|
||||
new FillFlowContainer<PlayerSettingsGroup>
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 20),
|
||||
Margin = new MarginPadding(25),
|
||||
Children = new PlayerSettingsGroup[]
|
||||
{
|
||||
Alpha = 0,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
},
|
||||
new FillFlowContainer<PlayerSettingsGroup>
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 20),
|
||||
Margin = new MarginPadding(25),
|
||||
Children = new PlayerSettingsGroup[]
|
||||
{
|
||||
VisualSettings = new VisualSettings(),
|
||||
new InputSettings()
|
||||
}
|
||||
VisualSettings = new VisualSettings(),
|
||||
new InputSettings()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user