Make ScrollingPlayfield.Reversed protected; make ManiaPlayfield 'invertible'.

This commit is contained in:
smoogipooo 2017-08-23 20:50:03 +09:00
parent 17900fea62
commit 115e5c95af
4 changed files with 45 additions and 27 deletions

View File

@ -1,7 +1,6 @@
// 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;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
@ -13,7 +12,6 @@
using osu.Game.Rulesets.Mania.Timing;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Timing;
using OpenTK;
using osu.Game.Rulesets;
namespace osu.Desktop.Tests.Visual
@ -39,12 +37,12 @@ public TestCaseManiaPlayfield()
AddStep("8 columns", () => createPlayfield(8, SpecialColumnPosition.Normal));
AddStep("Left special style", () => createPlayfield(8, SpecialColumnPosition.Left));
AddStep("Right special style", () => createPlayfield(8, SpecialColumnPosition.Right));
AddStep("Reversed", () => createPlayfield(4, SpecialColumnPosition.Normal, true));
AddStep("Notes with input", () => createPlayfieldWithNotes(false));
AddWaitStep((int)Math.Ceiling((start_time + duration) / TimePerAction));
AddStep("Notes with input (reversed)", () => createPlayfieldWithNotes(false, true));
AddStep("Notes with gravity", () => createPlayfieldWithNotes(true));
AddWaitStep((int)Math.Ceiling((start_time + duration) / TimePerAction));
AddStep("Notes with gravity (reversed)", () => createPlayfieldWithNotes(true, true));
}
[BackgroundDependencyLoader]
@ -58,23 +56,25 @@ private void load(RulesetStore rulesets)
TimingPoint = { BeatLength = 1000 }
}, gravity ? ScrollingAlgorithm.Gravity : ScrollingAlgorithm.Basic);
private void createPlayfield(int cols, SpecialColumnPosition specialPos)
private void createPlayfield(int cols, SpecialColumnPosition specialPos, bool inverted = false)
{
Clear();
var inputManager = new ManiaInputManager(maniaRuleset, cols) { RelativeSizeAxes = Axes.Both };
Add(inputManager);
inputManager.Add(new ManiaPlayfield(cols)
ManiaPlayfield playfield;
inputManager.Add(playfield = new ManiaPlayfield(cols)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
SpecialColumnPosition = specialPos,
Scale = new Vector2(1, -1)
SpecialColumnPosition = specialPos
});
playfield.Inverted.Value = inverted;
}
private void createPlayfieldWithNotes(bool gravity)
private void createPlayfieldWithNotes(bool gravity, bool inverted = false)
{
Clear();
@ -83,33 +83,34 @@ private void createPlayfieldWithNotes(bool gravity)
var inputManager = new ManiaInputManager(maniaRuleset, 4) { RelativeSizeAxes = Axes.Both };
Add(inputManager);
ManiaPlayfield playField;
inputManager.Add(playField = new ManiaPlayfield(4)
ManiaPlayfield playfield;
inputManager.Add(playfield = new ManiaPlayfield(4)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(1, -1),
Clock = new FramedClock(rateAdjustClock)
});
playfield.Inverted.Value = inverted;
if (!gravity)
playField.Columns.ForEach(c => c.Add(createTimingChange(0, false)));
playfield.Columns.ForEach(c => c.Add(createTimingChange(0, false)));
for (double t = start_time; t <= start_time + duration; t += 100)
{
if (gravity)
playField.Columns.ElementAt(0).Add(createTimingChange(t, true));
playfield.Columns.ElementAt(0).Add(createTimingChange(t, true));
playField.Add(new DrawableNote(new Note
playfield.Add(new DrawableNote(new Note
{
StartTime = t,
Column = 0
}, ManiaAction.Key1));
if (gravity)
playField.Columns.ElementAt(3).Add(createTimingChange(t, true));
playfield.Columns.ElementAt(3).Add(createTimingChange(t, true));
playField.Add(new DrawableNote(new Note
playfield.Add(new DrawableNote(new Note
{
StartTime = t,
Column = 3
@ -117,9 +118,9 @@ private void createPlayfieldWithNotes(bool gravity)
}
if (gravity)
playField.Columns.ElementAt(1).Add(createTimingChange(start_time, true));
playfield.Columns.ElementAt(1).Add(createTimingChange(start_time, true));
playField.Add(new DrawableHoldNote(new HoldNote
playfield.Add(new DrawableHoldNote(new HoldNote
{
StartTime = start_time,
Duration = duration,
@ -127,9 +128,9 @@ private void createPlayfieldWithNotes(bool gravity)
}, ManiaAction.Key2));
if (gravity)
playField.Columns.ElementAt(2).Add(createTimingChange(start_time, true));
playfield.Columns.ElementAt(2).Add(createTimingChange(start_time, true));
playField.Add(new DrawableHoldNote(new HoldNote
playfield.Add(new DrawableHoldNote(new HoldNote
{
StartTime = start_time,
Duration = duration,

View File

@ -64,8 +64,8 @@ public TestCaseScrollingPlayfield()
AddStep("Reverse direction", () =>
{
horizontalRulesetContainer.Playfield.Reversed.Toggle();
verticalRulesetContainer.Playfield.Reversed.Toggle();
horizontalRulesetContainer.Playfield.Reverse();
verticalRulesetContainer.Playfield.Reverse();
});
}
@ -210,6 +210,8 @@ public TestPlayfield(Axes scrollingAxes)
content = new Container { RelativeSizeAxes = Axes.Both }
};
}
public void Reverse() => Reversed.Toggle();
}

View File

@ -14,6 +14,7 @@
using OpenTK.Input;
using System.Linq;
using System.Collections.Generic;
using osu.Framework.Configuration;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Framework.Graphics.Shapes;
@ -45,6 +46,11 @@ public SpecialColumnPosition SpecialColumnPosition
}
}
/// <summary>
/// Whether this playfield should be inverted. This flips everything inside the playfield.
/// </summary>
public readonly Bindable<bool> Inverted = new Bindable<bool>(true);
private readonly FlowContainer<Column> columns;
public IEnumerable<Column> Columns => columns.Children;
@ -64,6 +70,8 @@ public ManiaPlayfield(int columnCount)
if (columnCount <= 0)
throw new ArgumentException("Can't have zero or fewer columns.");
Inverted.Value = true;
InternalChildren = new Drawable[]
{
new Container
@ -126,7 +134,6 @@ public ManiaPlayfield(int columnCount)
for (int i = 0; i < columnCount; i++)
{
var c = new Column();
c.Reversed.BindTo(Reversed);
c.VisibleTimeRange.BindTo(VisibleTimeRange);
c.IsSpecial = isSpecialColumn(i);
@ -135,6 +142,14 @@ public ManiaPlayfield(int columnCount)
columns.Add(c);
AddNested(c);
}
Inverted.ValueChanged += invertedChanged;
Inverted.TriggerChange();
}
private void invertedChanged(bool newValue)
{
Scale = new Vector2(1, newValue ? -1 : 1);
}
[BackgroundDependencyLoader]

View File

@ -55,9 +55,9 @@ public class ScrollingPlayfield<TObject, TJudgement> : Playfield<TObject, TJudge
};
/// <summary>
/// Whether to reverse the scrolling direction is reversed.
/// Whether to reverse the scrolling direction is reversed. Note that this does _not_ invert the hit objects.
/// </summary>
public readonly BindableBool Reversed = new BindableBool();
protected readonly BindableBool Reversed = new BindableBool();
/// <summary>
/// The container that contains the <see cref="SpeedAdjustmentContainer"/>s and <see cref="DrawableHitObject"/>s.