From 7dba870518857bb832dbf7b4a034471a3ed45f94 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 30 Jan 2024 03:07:37 +0300 Subject: [PATCH] Rework Content storage in ColumnFlow --- osu.Game.Rulesets.Mania.Tests/TestSceneStage.cs | 4 ++-- osu.Game.Rulesets.Mania/UI/ColumnFlow.cs | 16 +++++++++------- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 10 +++++----- osu.Game.Rulesets.Mania/UI/Stage.cs | 11 +++++------ 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/TestSceneStage.cs b/osu.Game.Rulesets.Mania.Tests/TestSceneStage.cs index fee3ba3e39..db04142915 100644 --- a/osu.Game.Rulesets.Mania.Tests/TestSceneStage.cs +++ b/osu.Game.Rulesets.Mania.Tests/TestSceneStage.cs @@ -91,7 +91,7 @@ private void createNote() { foreach (var stage in stages) { - for (int i = 0; i < stage.Columns.Count; i++) + for (int i = 0; i < stage.Columns.Length; i++) { var obj = new Note { Column = i, StartTime = Time.Current + 2000 }; obj.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); @@ -105,7 +105,7 @@ private void createHoldNote() { foreach (var stage in stages) { - for (int i = 0; i < stage.Columns.Count; i++) + for (int i = 0; i < stage.Columns.Length; i++) { var obj = new HoldNote { Column = i, StartTime = Time.Current + 2000, Duration = 500 }; obj.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); diff --git a/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs b/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs index 8734f8ac8a..1593e8e76f 100644 --- a/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs +++ b/osu.Game.Rulesets.Mania/UI/ColumnFlow.cs @@ -4,8 +4,6 @@ #nullable disable using System; -using System.Collections.Generic; -using System.Linq; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -28,20 +26,21 @@ public partial class ColumnFlow : CompositeDrawable /// /// All contents added to this . /// - public IReadOnlyList Content => columns.Children.Select(c => c.Count == 0 ? null : (TContent)c.Child).ToList(); + public TContent[] Content { get; } - private readonly FillFlowContainer columns; + private readonly FillFlowContainer> columns; private readonly StageDefinition stageDefinition; public ColumnFlow(StageDefinition stageDefinition) { this.stageDefinition = stageDefinition; + Content = new TContent[stageDefinition.Columns]; AutoSizeAxes = Axes.X; Masking = true; - InternalChild = columns = new FillFlowContainer + InternalChild = columns = new FillFlowContainer> { RelativeSizeAxes = Axes.Y, AutoSizeAxes = Axes.X, @@ -49,7 +48,7 @@ public ColumnFlow(StageDefinition stageDefinition) }; for (int i = 0; i < stageDefinition.Columns; i++) - columns.Add(new Container { RelativeSizeAxes = Axes.Y }); + columns.Add(new Container { RelativeSizeAxes = Axes.Y }); } private ISkinSource currentSkin; @@ -102,7 +101,10 @@ private void onSkinChanged() /// /// The index of the column to set the content of. /// The content. - public void SetContentForColumn(int column, TContent content) => columns[column].Child = content; + public void SetContentForColumn(int column, TContent content) + { + Content[column] = columns[column].Child = content; + } private void updateMobileSizing() { diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 314d199944..c8874c8ab3 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -71,7 +71,7 @@ public ManiaPlayfield(List stageDefinitions) stages.Add(newStage); AddNested(newStage); - firstColumnIndex += newStage.Columns.Count; + firstColumnIndex += newStage.Columns.Length; } } @@ -125,9 +125,9 @@ public Column GetColumn(int index) foreach (var stage in stages) { - if (index >= stage.Columns.Count) + if (index >= stage.Columns.Length) { - index -= stage.Columns.Count; + index -= stage.Columns.Length; continue; } @@ -140,7 +140,7 @@ public Column GetColumn(int index) /// /// Retrieves the total amount of columns across all stages in this playfield. /// - public int TotalColumns => stages.Sum(s => s.Columns.Count); + public int TotalColumns => stages.Sum(s => s.Columns.Length); private Stage getStageByColumn(int column) { @@ -148,7 +148,7 @@ private Stage getStageByColumn(int column) foreach (var stage in stages) { - sum += stage.Columns.Count; + sum += stage.Columns.Length; if (sum > column) return stage; } diff --git a/osu.Game.Rulesets.Mania/UI/Stage.cs b/osu.Game.Rulesets.Mania/UI/Stage.cs index 36286940a8..db06f9dbde 100644 --- a/osu.Game.Rulesets.Mania/UI/Stage.cs +++ b/osu.Game.Rulesets.Mania/UI/Stage.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Extensions.ObjectExtensions; @@ -37,7 +36,7 @@ public partial class Stage : ScrollingPlayfield public const float HIT_TARGET_POSITION = 110; - public IReadOnlyList Columns => columnFlow.Content; + public Column[] Columns => columnFlow.Content; private readonly ColumnFlow columnFlow; private readonly JudgementContainer judgements; @@ -184,13 +183,13 @@ protected override void LoadComplete() NewResult += OnNewResult; } - public override void Add(HitObject hitObject) => Columns.ElementAt(((ManiaHitObject)hitObject).Column - firstColumnIndex).Add(hitObject); + public override void Add(HitObject hitObject) => Columns[((ManiaHitObject)hitObject).Column - firstColumnIndex].Add(hitObject); - public override bool Remove(HitObject hitObject) => Columns.ElementAt(((ManiaHitObject)hitObject).Column - firstColumnIndex).Remove(hitObject); + public override bool Remove(HitObject hitObject) => Columns[((ManiaHitObject)hitObject).Column - firstColumnIndex].Remove(hitObject); - public override void Add(DrawableHitObject h) => Columns.ElementAt(((ManiaHitObject)h.HitObject).Column - firstColumnIndex).Add(h); + public override void Add(DrawableHitObject h) => Columns[((ManiaHitObject)h.HitObject).Column - firstColumnIndex].Add(h); - public override bool Remove(DrawableHitObject h) => Columns.ElementAt(((ManiaHitObject)h.HitObject).Column - firstColumnIndex).Remove(h); + public override bool Remove(DrawableHitObject h) => Columns[((ManiaHitObject)h.HitObject).Column - firstColumnIndex].Remove(h); public void Add(BarLine barLine) => base.Add(barLine);