|
1 | 1 | // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. |
2 | 2 | // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE |
3 | 3 |
|
| 4 | +using System.Collections.Generic; |
4 | 5 | using osu.Framework; |
5 | 6 | using osu.Framework.GameModes.Testing; |
6 | 7 | using osu.Framework.Graphics; |
7 | 8 | using osu.Framework.Timing; |
8 | 9 | using OpenTK; |
9 | 10 | using osu.Framework.Allocation; |
| 11 | +using osu.Framework.Configuration; |
10 | 12 | using osu.Game.Modes.Objects; |
11 | 13 | using osu.Game.Modes.Objects.Drawables; |
12 | 14 | using osu.Game.Modes.Osu.Objects; |
13 | 15 | using osu.Game.Modes.Osu.Objects.Drawables; |
14 | 16 | using osu.Framework.Graphics.Containers; |
| 17 | +using osu.Framework.Graphics.Sprites; |
| 18 | +using osu.Framework.Graphics.UserInterface; |
15 | 19 | using osu.Game.Modes; |
| 20 | +using OpenTK.Graphics; |
16 | 21 |
|
17 | 22 | namespace osu.Desktop.VisualTests.Tests |
18 | 23 | { |
19 | 24 | class TestCaseHitObjects : TestCase |
20 | 25 | { |
21 | 26 | public override string Name => @"Hit Objects"; |
22 | 27 |
|
| 28 | + private StopwatchClock rateAdjustClock; |
| 29 | + private FramedClock framedClock; |
| 30 | + |
| 31 | + bool auto = false; |
| 32 | + |
23 | 33 | public TestCaseHitObjects() |
24 | 34 | { |
25 | | - var swClock = new StopwatchClock(true) { Rate = 0.2f }; |
26 | | - Clock = new FramedClock(swClock); |
| 35 | + rateAdjustClock = new StopwatchClock(true); |
| 36 | + framedClock = new FramedClock(rateAdjustClock); |
| 37 | + playbackSpeed.ValueChanged += delegate { rateAdjustClock.Rate = playbackSpeed.Value; }; |
| 38 | + } |
| 39 | + |
| 40 | + HitObjectType mode = HitObjectType.Spinner; |
| 41 | + |
| 42 | + BindableNumber<double> playbackSpeed = new BindableDouble(0.5) { MinValue = 0, MaxValue = 1 }; |
| 43 | + private Container playfieldContainer; |
| 44 | + private Container approachContainer; |
| 45 | + |
| 46 | + private void load(HitObjectType mode) |
| 47 | + { |
| 48 | + this.mode = mode; |
| 49 | + |
| 50 | + switch (mode) |
| 51 | + { |
| 52 | + case HitObjectType.Circle: |
| 53 | + const int count = 10; |
| 54 | + |
| 55 | + for (int i = 0; i < count; i++) |
| 56 | + { |
| 57 | + var h = new HitCircle |
| 58 | + { |
| 59 | + StartTime = framedClock.CurrentTime + 600 + i * 80, |
| 60 | + Position = new Vector2((i - count / 2) * 14), |
| 61 | + }; |
| 62 | + |
| 63 | + add(new DrawableHitCircle(h)); |
| 64 | + } |
| 65 | + break; |
| 66 | + case HitObjectType.Slider: |
| 67 | + add(new DrawableSlider(new Slider |
| 68 | + { |
| 69 | + StartTime = framedClock.CurrentTime + 600, |
| 70 | + ControlPoints = new List<Vector2>() |
| 71 | + { |
| 72 | + new Vector2(-200, 0), |
| 73 | + new Vector2(400, 0), |
| 74 | + }, |
| 75 | + Length = 400, |
| 76 | + Position = new Vector2(-200, 0), |
| 77 | + Velocity = 1, |
| 78 | + })); |
| 79 | + break; |
| 80 | + case HitObjectType.Spinner: |
| 81 | + add(new DrawableSpinner(new Spinner |
| 82 | + { |
| 83 | + StartTime = framedClock.CurrentTime + 600, |
| 84 | + Length = 1000, |
| 85 | + Position = new Vector2(0, 0), |
| 86 | + })); |
| 87 | + break; |
| 88 | + } |
27 | 89 | } |
28 | 90 |
|
29 | 91 | public override void Reset() |
30 | 92 | { |
31 | 93 | base.Reset(); |
32 | 94 |
|
33 | | - Clock.ProcessFrame(); |
| 95 | + playbackSpeed.TriggerChange(); |
34 | 96 |
|
35 | | - Container approachContainer = new Container { Depth = float.MinValue, }; |
| 97 | + AddButton(@"circles", () => load(HitObjectType.Circle)); |
| 98 | + AddButton(@"slider", () => load(HitObjectType.Slider)); |
| 99 | + AddButton(@"spinner", () => load(HitObjectType.Spinner)); |
36 | 100 |
|
37 | | - Add(approachContainer); |
| 101 | + AddToggle(@"auto", () => { auto = !auto; load(mode); }); |
38 | 102 |
|
39 | | - const int count = 10; |
| 103 | + ButtonsContainer.Add(new SpriteText { Text = "Playback Speed" }); |
| 104 | + ButtonsContainer.Add(new BasicSliderBar<double> |
| 105 | + { |
| 106 | + Width = 150, |
| 107 | + Height = 10, |
| 108 | + SelectionColor = Color4.Orange, |
| 109 | + Bindable = playbackSpeed |
| 110 | + }); |
40 | 111 |
|
41 | | - for (int i = 0; i < count; i++) |
| 112 | + framedClock.ProcessFrame(); |
| 113 | + |
| 114 | + var clockAdjustContainer = new Container |
42 | 115 | { |
43 | | - var h = new HitCircle |
| 116 | + RelativeSizeAxes = Axes.Both, |
| 117 | + Clock = framedClock, |
| 118 | + Children = new[] |
44 | 119 | { |
45 | | - StartTime = Clock.CurrentTime + 600 + i * 80, |
46 | | - Position = new Vector2((i - count / 2) * 14), |
47 | | - }; |
| 120 | + playfieldContainer = new Container { RelativeSizeAxes = Axes.Both }, |
| 121 | + approachContainer = new Container { RelativeSizeAxes = Axes.Both } |
| 122 | + } |
| 123 | + }; |
48 | 124 |
|
49 | | - DrawableHitCircle d = new DrawableHitCircle(h) |
50 | | - { |
51 | | - Anchor = Anchor.Centre, |
52 | | - Depth = i, |
53 | | - State = ArmedState.Hit, |
54 | | - Judgement = new OsuJudgementInfo { Result = HitResult.Hit } |
55 | | - }; |
| 125 | + Add(clockAdjustContainer); |
56 | 126 |
|
| 127 | + load(mode); |
| 128 | + } |
| 129 | + |
| 130 | + int depth; |
| 131 | + void add(DrawableHitObject h) |
| 132 | + { |
| 133 | + h.Anchor = Anchor.Centre; |
| 134 | + h.Depth = depth++; |
57 | 135 |
|
58 | | - approachContainer.Add(d.ApproachCircle.CreateProxy()); |
59 | | - Add(d); |
| 136 | + if (auto) |
| 137 | + { |
| 138 | + h.State = ArmedState.Hit; |
| 139 | + h.Judgement = new OsuJudgementInfo { Result = HitResult.Hit }; |
60 | 140 | } |
| 141 | + |
| 142 | + playfieldContainer.Add(h); |
| 143 | + var proxyable = h as IDrawableHitObjectWithProxiedApproach; |
| 144 | + if (proxyable != null) |
| 145 | + approachContainer.Add(proxyable.ProxiedLayer.CreateProxy()); |
61 | 146 | } |
62 | 147 | } |
63 | 148 | } |
0 commit comments