From 5f30a89f763f4289653a184f6d8ef35fe650d182 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 11 May 2017 16:09:48 +0900 Subject: [PATCH] General refactoring + renaming of TimingSectionContainer. --- .../Timing/DrawableTimingSection.cs | 27 ----- .../Timing/TimeRelativeContainer.cs | 102 ++++++++++++++++++ osu.Game.Rulesets.Mania/UI/Column.cs | 4 +- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 4 +- .../UI/TimingSectionContainer.cs | 36 ------- .../osu.Game.Rulesets.Mania.csproj | 2 +- 6 files changed, 107 insertions(+), 68 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/Timing/TimeRelativeContainer.cs delete mode 100644 osu.Game.Rulesets.Mania/UI/TimingSectionContainer.cs diff --git a/osu.Game.Rulesets.Mania/Timing/DrawableTimingSection.cs b/osu.Game.Rulesets.Mania/Timing/DrawableTimingSection.cs index 2225a63cdf..0ffdb837f2 100644 --- a/osu.Game.Rulesets.Mania/Timing/DrawableTimingSection.cs +++ b/osu.Game.Rulesets.Mania/Timing/DrawableTimingSection.cs @@ -7,32 +7,5 @@ using osu.Framework.Graphics.Containers; namespace osu.Game.Rulesets.Mania.Timing { - /// - /// A container that contains hit objects within the time span of a timing section. - /// - public class DrawableTimingSection : Container - { - public readonly TimingSection TimingSection; - public DrawableTimingSection(TimingSection section) - { - TimingSection = section; - - Anchor = Anchor.BottomCentre; - Origin = Anchor.BottomCentre; - - RelativePositionAxes = Axes.Y; - Y = -(float)section.StartTime; - - RelativeSizeAxes = Axes.Both; - Height = (float)section.Duration; - - RelativeCoordinateSpace = new Vector2(1, Height); - } - - protected override void Update() - { - Y = (float)(Time.Current - TimingSection.StartTime); - } - } } \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/Timing/TimeRelativeContainer.cs b/osu.Game.Rulesets.Mania/Timing/TimeRelativeContainer.cs new file mode 100644 index 0000000000..d3fcb56174 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Timing/TimeRelativeContainer.cs @@ -0,0 +1,102 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using OpenTK; + +namespace osu.Game.Rulesets.Mania.Timing +{ + /// + /// A container in which the Y-relative coordinate space is spanned by a length of time. + /// + /// This container contains s which scroll inside this container. + /// Drawables added to this container are moved inside the relevant , + /// and as such, will scroll along with the s. + /// + /// + public class TimeRelativeContainer : Container + { + /// + /// The amount of time which the height of this container spans. + /// + public double TimeSpan + { + get { return RelativeCoordinateSpace.Y; } + set { RelativeCoordinateSpace = new Vector2(1, (float)value); } + } + + public TimeRelativeContainer(IEnumerable timingSections) + { + Children = timingSections.Select(t => new DrawableTimingSection(t)); + } + + /// + /// Adds a drawable to this container. Note that the drawable added must have a + /// Y-position as a time relative to this container. + /// + /// The drawable to add. + public override void Add(Drawable drawable) + { + // Always add timing sections to ourselves + if (drawable is DrawableTimingSection) + { + base.Add(drawable); + return; + } + + var section = (Children.LastOrDefault(t => t.Y >= drawable.Y) ?? Children.First()) as DrawableTimingSection; + + if (section == null) + throw new Exception("Could not find suitable timing section to add object to."); + + section.Add(drawable); + } + + /// + /// A container that contains drawables within the time span of a timing section. + /// + /// Scrolls relative to the current time. + /// + /// + private class DrawableTimingSection : Container + { + private readonly TimingSection section; + + public DrawableTimingSection(TimingSection section) + { + this.section = section; + + Anchor = Anchor.BottomCentre; + Origin = Anchor.BottomCentre; + + RelativePositionAxes = Axes.Y; + Y = -(float)section.StartTime; + + RelativeSizeAxes = Axes.Both; + Height = (float)section.Duration; + + RelativeCoordinateSpace = new Vector2(1, Height); + } + + protected override void Update() + { + Y = (float)(Time.Current - section.StartTime); + } + + public override void Add(Drawable drawable) + { + // The previously relatively-positioned drawable will now become relative to us, but since the drawable has no knowledge of us, + // we need to offset it back by our position so that it becomes correctly relatively-positioned to us + // This can be removed if hit objects were stored such that either their StartTime or their "beat offset" was relative to the timing section + // they belonged to, but this requires a radical change to the beatmap format which we're not ready to do just yet + drawable.Y -= Y; + + base.Add(drawable); + } + } + } +} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 4f89d3b634..96f4b17ff8 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -38,7 +38,7 @@ namespace osu.Game.Rulesets.Mania.UI private readonly Container hitTargetBar; private readonly Container keyIcon; - public readonly TimingSectionContainer TimingSectionContainer; + public readonly TimeRelativeContainer TimingSectionContainer; public Column(IEnumerable timingSections) { @@ -87,7 +87,7 @@ namespace osu.Game.Rulesets.Mania.UI } } }, - TimingSectionContainer = new TimingSectionContainer(timingSections) + TimingSectionContainer = new TimeRelativeContainer(timingSections) { Name = "Hit objects", RelativeSizeAxes = Axes.Both, diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 75c1140a9a..826f7262f6 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -55,7 +55,7 @@ namespace osu.Game.Rulesets.Mania.UI public readonly FlowContainer Columns; - private readonly TimingSectionContainer barlineContainer; + private readonly TimeRelativeContainer barlineContainer; private List normalColumnColours = new List(); private Color4 specialColumnColour; @@ -93,7 +93,7 @@ namespace osu.Game.Rulesets.Mania.UI Padding = new MarginPadding { Left = 1, Right = 1 }, Spacing = new Vector2(1, 0) }, - barlineContainer = new TimingSectionContainer(timingSections) + barlineContainer = new TimeRelativeContainer(timingSections) { Name = "Barlines", Anchor = Anchor.BottomCentre, diff --git a/osu.Game.Rulesets.Mania/UI/TimingSectionContainer.cs b/osu.Game.Rulesets.Mania/UI/TimingSectionContainer.cs deleted file mode 100644 index 9a63c17c59..0000000000 --- a/osu.Game.Rulesets.Mania/UI/TimingSectionContainer.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System.Collections.Generic; -using System.Linq; -using OpenTK; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Game.Rulesets.Mania.Timing; - -namespace osu.Game.Rulesets.Mania.UI -{ - public class TimingSectionContainer : Container - { - /// - /// The amount of time which the length of this container spans. - /// - public double TimeSpan - { - get { return RelativeCoordinateSpace.Y; } - set { RelativeCoordinateSpace = new Vector2(1, (float)value); } - } - - public TimingSectionContainer(IEnumerable timingSections) - { - Children = timingSections.Select(t => new DrawableTimingSection(t)); - } - - public void Add(Drawable drawable) - { - var section = Children.LastOrDefault(t => t.Y >= drawable.Y) ?? Children.First(); - drawable.Y -= section.Y; - section.Add(drawable); - } - } -} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj index e1d033c214..948f25a80b 100644 --- a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj +++ b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj @@ -70,7 +70,7 @@ - +