1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 21:27:24 +08:00

TimeRelativeContainer -> ControlPointContainer, optimize AutoTimeRelativeContainer a little bit (only recompute on invalidation).

This commit is contained in:
smoogipooo 2017-05-16 17:50:09 +09:00
parent 7039205363
commit ac02d1ab10
5 changed files with 23 additions and 18 deletions

View File

@ -9,7 +9,7 @@ using osu.Game.Rulesets.Mania.UI;
using System.Linq;
using System;
using System.Collections.Generic;
using osu.Game.Rulesets.Mania.Timing;
using osu.Game.Beatmaps.Timing;
namespace osu.Desktop.VisualTests.Tests
{
@ -28,7 +28,7 @@ namespace osu.Desktop.VisualTests.Tests
Action<int, SpecialColumnPosition> createPlayfield = (cols, pos) =>
{
Clear();
Add(new ManiaPlayfield(cols, new List<TimingSection>())
Add(new ManiaPlayfield(cols, new List<ControlPoint>())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -19,20 +19,16 @@ namespace osu.Game.Rulesets.Mania.Timing
/// and as such, will scroll along with the <see cref="ControlPoint"/>s.
/// </para>
/// </summary>
public class TimeRelativeContainer : Container<Drawable>
public class ControlPointContainer : Container<Drawable>
{
/// <summary>
/// The amount of time which the height of this container spans.
/// </summary>
public double TimeSpan
{
get { return RelativeCoordinateSpace.Y; }
set { RelativeCoordinateSpace = new Vector2(1, (float)value); }
}
public double TimeSpan { get; set; }
private readonly List<DrawableTimingSection> drawableTimingSections;
public TimeRelativeContainer(IEnumerable<ControlPoint> timingChanges)
public ControlPointContainer(IEnumerable<ControlPoint> timingChanges)
{
drawableTimingSections = timingChanges.Select(t => new DrawableTimingSection(t)).ToList();
@ -99,10 +95,10 @@ namespace osu.Game.Rulesets.Mania.Timing
protected override void Update()
{
var parent = (TimeRelativeContainer)Parent;
var parent = (ControlPointContainer)Parent;
// Adjust our height to account for the speed changes
Height = (float)(parent.TimeSpan * 1000 / timingChange.BeatLength / timingChange.SpeedMultiplier);
Height = (float)(1000 / timingChange.BeatLength / timingChange.SpeedMultiplier);
RelativeCoordinateSpace = new Vector2(1, (float)parent.TimeSpan);
// Scroll the content
@ -127,10 +123,19 @@ namespace osu.Game.Rulesets.Mania.Timing
/// <param name="drawable">The drawable to check.</param>
public bool CanContain(Drawable drawable) => content.Y <= drawable.Y;
/// <summary>
/// A container which always keeps its height and relative coordinate space "auto-sized" to its children.
/// </summary>
private class AutoTimeRelativeContainer : Container
{
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
public override void InvalidateFromChild(Invalidation invalidation)
{
if ((invalidation & Invalidation.Geometry) == 0)
{
base.InvalidateFromChild(invalidation);
return;
}
float height = 0;
foreach (Drawable child in Children)
@ -143,7 +148,7 @@ namespace osu.Game.Rulesets.Mania.Timing
Height = height;
RelativeCoordinateSpace = new Vector2(1, height);
return base.Invalidate(invalidation, source, shallPropagate);
base.InvalidateFromChild(invalidation);
}
}
}

View File

@ -40,7 +40,7 @@ namespace osu.Game.Rulesets.Mania.UI
private readonly Container hitTargetBar;
private readonly Container keyIcon;
public readonly TimeRelativeContainer TimingSectionContainer;
public readonly ControlPointContainer TimingSectionContainer;
public Column(IEnumerable<ControlPoint> timingChanges)
{
@ -91,7 +91,7 @@ namespace osu.Game.Rulesets.Mania.UI
}
}
},
TimingSectionContainer = new TimeRelativeContainer(timingChanges)
TimingSectionContainer = new ControlPointContainer(timingChanges)
{
Name = "Hit objects",
RelativeSizeAxes = Axes.Both,

View File

@ -56,7 +56,7 @@ namespace osu.Game.Rulesets.Mania.UI
public readonly FlowContainer<Column> Columns;
private readonly TimeRelativeContainer barlineContainer;
private readonly ControlPointContainer barlineContainer;
private List<Color4> normalColumnColours = new List<Color4>();
private Color4 specialColumnColour;
@ -101,7 +101,7 @@ namespace osu.Game.Rulesets.Mania.UI
Padding = new MarginPadding { Top = HIT_TARGET_POSITION },
Children = new[]
{
barlineContainer = new TimeRelativeContainer(timingChanges)
barlineContainer = new ControlPointContainer(timingChanges)
{
Name = "Bar lines",
RelativeSizeAxes = Axes.Both,

View File

@ -68,7 +68,7 @@
<Compile Include="ManiaRuleset.cs" />
<Compile Include="Mods\ManiaMod.cs" />
<Compile Include="UI\SpecialColumnPosition.cs" />
<Compile Include="Timing\TimeRelativeContainer.cs" />
<Compile Include="Timing\ControlPointContainer.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">