A game framework written with osu! in mind.
at master 121 lines 4.1 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using System.Linq; 6using NUnit.Framework; 7using osu.Framework.Extensions.IEnumerableExtensions; 8using osu.Framework.Graphics; 9using osu.Framework.Graphics.Containers; 10using osu.Framework.Graphics.Shapes; 11using osu.Framework.Graphics.Sprites; 12using osu.Framework.Testing; 13using osuTK; 14using osuTK.Graphics; 15 16namespace osu.Framework.Tests.Visual.Drawables 17{ 18 public class TestSceneEasingCurves : TestScene 19 { 20 private const float default_size = 200; 21 22 private FillFlowContainer easingsContainer; 23 24 [SetUp] 25 public void SetUp() => Schedule(() => 26 { 27 var easingTypes = Enum.GetValues(typeof(Easing)) 28 .OfType<Easing>() 29 .ToList(); 30 31 Child = new BasicScrollContainer 32 { 33 RelativeSizeAxes = Axes.Both, 34 Child = easingsContainer = new FillFlowContainer 35 { 36 RelativeSizeAxes = Axes.X, 37 AutoSizeAxes = Axes.Y, 38 Children = easingTypes.Select(type => new Visualiser(type)).ToArray() 39 } 40 }; 41 }); 42 43 [SetUpSteps] 44 public void SetUpSteps() 45 { 46 AddSliderStep("resize easings", default_size / 2, default_size * 2, default_size, size => 47 { 48 easingsContainer?.Children?.OfType<Visualiser>().ForEach(easing => easing.ResizeTo(new Vector2(size))); 49 }); 50 } 51 52 private class Visualiser : Container 53 { 54 private const float movement_duration = 1000f; 55 private const float pause_duration = 200f; 56 57 public readonly Easing Easing; 58 59 private readonly CircularContainer dot; 60 61 public Visualiser(Easing easing) 62 { 63 Easing = easing; 64 65 Size = new Vector2(default_size); 66 Padding = new MarginPadding(5); 67 68 InternalChildren = new Drawable[] 69 { 70 new Container 71 { 72 RelativeSizeAxes = Axes.Both, 73 Anchor = Anchor.BottomCentre, 74 Origin = Anchor.BottomCentre, 75 Children = new Drawable[] 76 { 77 new Box 78 { 79 Colour = Color4.DimGray, 80 RelativeSizeAxes = Axes.Both 81 }, 82 dot = new CircularContainer 83 { 84 Origin = Anchor.Centre, 85 RelativePositionAxes = Axes.Both, 86 Size = new Vector2(10), 87 Masking = true, 88 Child = new Box 89 { 90 RelativeSizeAxes = Axes.Both, 91 Colour = Color4.White 92 } 93 } 94 } 95 }, 96 new SpriteText 97 { 98 Anchor = Anchor.TopCentre, 99 Origin = Anchor.TopCentre, 100 Y = 10, 101 Text = easing.ToString() 102 }, 103 }; 104 } 105 106 protected override void LoadComplete() 107 { 108 base.LoadComplete(); 109 110 dot.MoveToX(1.0f, movement_duration, Easing) 111 .Then(pause_duration) 112 .MoveToX(0.0f, movement_duration, Easing) 113 .Loop(pause_duration); 114 dot.MoveToY(1.0f, movement_duration) 115 .Then(pause_duration) 116 .MoveToY(0.0f, movement_duration) 117 .Loop(pause_duration); 118 } 119 } 120 } 121}