forked from ppy/osu-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
osu.Framework.Tests/Visual/Platform/TestSceneAllowExitingAndroid.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using NUnit.Framework; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Framework.Input.Events; | ||
using osu.Framework.Platform; | ||
using osuTK.Graphics; | ||
using osuTK.Input; | ||
|
||
namespace osu.Framework.Tests.Visual.Platform | ||
{ | ||
public class TestSceneAllowExitingAndroid : FrameworkTestScene | ||
{ | ||
[Resolved] | ||
private GameHost host { get; set; } | ||
|
||
private readonly BindableBool allowExit = new BindableBool(true); | ||
|
||
public TestSceneAllowExitingAndroid() | ||
{ | ||
Children = new Drawable[] | ||
{ | ||
new ExitVisualiser | ||
{ | ||
Width = 0.5f, | ||
RelativeSizeAxes = Axes.Both, | ||
}, | ||
new EscapeVisualizer | ||
{ | ||
Colour = Color4.Black, | ||
RelativeSizeAxes = Axes.Both, | ||
Width = 0.5f, | ||
Anchor = Anchor.TopRight, | ||
Origin = Anchor.TopRight, | ||
}, | ||
}; | ||
} | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
host.AllowExitingAndroid.AddSource(allowExit); | ||
} | ||
|
||
[Test] | ||
public void TestToggleSuspension() | ||
{ | ||
AddToggleStep("toggle allow exit", v => allowExit.Value = v); | ||
} | ||
|
||
protected override void Dispose(bool isDisposing) | ||
{ | ||
host.AllowExitingAndroid.RemoveSource(allowExit); | ||
base.Dispose(isDisposing); | ||
} | ||
|
||
private class ExitVisualiser : Box | ||
{ | ||
private readonly IBindable<bool> allowExit = new Bindable<bool>(); | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(GameHost host) | ||
{ | ||
allowExit.BindTo(host.AllowExitingAndroid.Result); | ||
allowExit.BindValueChanged(v => Colour = v.NewValue ? Color4.Green : Color4.Red, true); | ||
} | ||
} | ||
|
||
private class EscapeVisualizer : Box | ||
{ | ||
protected override bool OnKeyDown(KeyDownEvent e) | ||
{ | ||
if (e.Key == Key.Escape) | ||
this.FlashColour(Color4.Blue, 700, Easing.OutQuart); | ||
|
||
return base.OnKeyDown(e); | ||
} | ||
} | ||
} | ||
} |