Created
February 27, 2017 07:23
-
-
Save peppy/6975f3b34da7ffef550aa62c20589fe5 to your computer and use it in GitHub Desktop.
TestCaseFlagContainer.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
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. | |
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE | |
using System.Linq; | |
using osu.Framework.Graphics; | |
using osu.Framework.Screens.Testing; | |
using osu.Framework.Graphics.Containers; | |
using osu.Framework.Graphics.Sprites; | |
using osu.Framework.MathUtils; | |
using osu.Framework.Threading; | |
using osu.Game.Overlays; | |
using OpenTK; | |
using OpenTK.Graphics; | |
using osu.Framework.Input; | |
namespace osu.Desktop.VisualTests.Tests | |
{ | |
class TestCaseFlagContainer : TestCase | |
{ | |
class Flag : Box | |
{ | |
public const float WIDTH = 60; | |
public const float HEIGHT = 40; | |
public override bool HandleInput => true; | |
public Flag() | |
{ | |
Size = new Vector2(WIDTH, HEIGHT); | |
Colour = new Color4(RNG.NextSingle(), RNG.NextSingle(), RNG.NextSingle(), 1); | |
} | |
protected override bool OnClick(InputState state) | |
{ | |
FadeOut(100); | |
Expire(); | |
return base.OnClick(state); | |
} | |
} | |
class FlagContainer : Container<Flag> | |
{ | |
private const float spacing = 5; | |
int expiredCount = 0; | |
protected override void Update() | |
{ | |
base.Update(); | |
while (Children.Count() < DrawWidth / 60) | |
addFlag(); | |
float pos = leftPos; | |
foreach (var f in Children) | |
{ | |
if (f.Position.X + f.DrawSize.X < 0) | |
{ | |
f.LifetimeEnd = Time.Current; | |
expiredCount++; | |
} | |
f.MoveToX(pos, 100); | |
pos += Flag.WIDTH + spacing; | |
} | |
} | |
private float leftPos => -(float)(Time.Current / 40) + expiredCount * Flag.WIDTH; | |
private void addFlag() | |
{ | |
Add(new Flag | |
{ | |
X = DrawWidth + leftPos | |
}); | |
} | |
} | |
public override string Name => @"Flags"; | |
public override string Description => @"scrolling flags"; | |
public override void Reset() | |
{ | |
base.Reset(); | |
Add(new FlagContainer() | |
{ | |
Anchor = Anchor.Centre, | |
Origin = Anchor.Centre, | |
RelativeSizeAxes = Axes.X, | |
AutoSizeAxes = Axes.Y, | |
Width = 1.1f, | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment