From bbe7765a95d7a8ece6dedaffc6edeff74ae1696b Mon Sep 17 00:00:00 2001 From: AlFasGD Date: Tue, 22 May 2018 09:03:47 +0300 Subject: [PATCH] Add files to not require dependencies from #2534 --- .../Edit/ManiaEditPlayfield.cs | 29 +++++ .../Edit/ManiaEditRulesetContainer.cs | 102 ++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 osu.Game.Rulesets.Mania/Edit/ManiaEditPlayfield.cs create mode 100644 osu.Game.Rulesets.Mania/Edit/ManiaEditRulesetContainer.cs diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaEditPlayfield.cs b/osu.Game.Rulesets.Mania/Edit/ManiaEditPlayfield.cs new file mode 100644 index 0000000000..15ab4be52b --- /dev/null +++ b/osu.Game.Rulesets.Mania/Edit/ManiaEditPlayfield.cs @@ -0,0 +1,29 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Extensions.IEnumerableExtensions; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Mania.Beatmaps; +using osu.Game.Rulesets.Mania.UI; +using System.Collections.Generic; +using System.Linq; + +namespace osu.Game.Rulesets.Mania.Edit +{ + public class ManiaEditPlayfield : ManiaPlayfield + { + protected override bool DisplayJudgements => false; + + public ManiaEditPlayfield(List stages) + : base(stages) + { + } + + public void Add(EditSnapLine editSnapLine) => Stages.Cast().ForEach(s => s.Add(editSnapLine)); + public void Remove(DrawableManiaEditSnapLine editSnapLine) => Stages.Cast().ForEach(s => s.Remove(editSnapLine)); + public void ClearEditSnapLines() => Stages.Cast().ForEach(s => s.ClearEditSnapLines()); + + protected override ManiaStage CreateStage(int firstColumnIndex, StageDefinition definition, ref ManiaAction normalColumnStartAction, ref ManiaAction specialColumnStartAction) + => new ManiaEditStage(firstColumnIndex, definition, ref normalColumnStartAction, ref specialColumnStartAction); + } +} diff --git a/osu.Game.Rulesets.Mania/Edit/ManiaEditRulesetContainer.cs b/osu.Game.Rulesets.Mania/Edit/ManiaEditRulesetContainer.cs new file mode 100644 index 0000000000..49c13044e9 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Edit/ManiaEditRulesetContainer.cs @@ -0,0 +1,102 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using osu.Framework.Allocation; +using osu.Framework.Graphics.Cursor; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Mania.UI; +using osu.Game.Rulesets.Objects.Types; +using osu.Game.Rulesets.UI; +using osu.Game.Screens.Edit.Screens.Compose; +using System.Collections.Generic; +using System.Linq; + +namespace osu.Game.Rulesets.Mania.Edit +{ + public class ManiaEditRulesetContainer : ManiaRulesetContainer + { + public BindableBeatDivisor BeatDivisor; + + public List EditSnapLines; + + public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap, BindableBeatDivisor beatDivisor) + : base(ruleset, beatmap) + { + BeatDivisor = beatDivisor; + } + + [BackgroundDependencyLoader] + private void load() + { + BeatDivisor.ValueChanged += OnBeatSnapDivisorChange; + OnBeatSnapDivisorChange(BeatDivisor.Value); + } + + public void OnBeatSnapDivisorChange(int newDivisor) + { + generateEditSnapLines(newDivisor); + } + + private void generateEditSnapLines(int newDivisor) + { + // Generate the edit lines + double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue; + + var timingPoints = Beatmap.ControlPointInfo.TimingPoints; + EditSnapLines = new List(); + + // Create lines before the beginning of the first timing point + if (timingPoints.Any()) + { + double step = timingPoints[0].BeatLength / newDivisor; + int index = (int)(timingPoints[0].Time / step); + index += newDivisor - index % newDivisor - 1; + for (double t = timingPoints[0].Time - step; t >= 0; t -= step, index--) + { + EditSnapLines.Add(new EditSnapLine + { + StartTime = t, + ControlPoint = timingPoints[0], + BeatDivisor = BeatDivisor, + BeatIndex = index, + }); + } + } + + for (int i = 0; i < timingPoints.Count; i++) + { + TimingControlPoint point = timingPoints[i]; + + // Stop 1ms before the end of the timing point before the next one if any, otherwise stop at the last object's time + double endTime = i < timingPoints.Count - 1 ? timingPoints[i + 1].Time - 1 : lastObjectTime + point.BeatLength * (int)point.TimeSignature; + + int index = 0; + double step = point.BeatLength / newDivisor; + for (double t = timingPoints[i].Time; t <= endTime; t += step, index++) + { + EditSnapLines.Add(new EditSnapLine + { + StartTime = t, + ControlPoint = point, + BeatDivisor = BeatDivisor, + BeatIndex = index, + }); + } + } + + var editPlayfield = (ManiaEditPlayfield)Playfield; + + editPlayfield.ClearEditSnapLines(); + EditSnapLines.ForEach(editPlayfield.Add); + } + + protected override Playfield CreatePlayfield() => new ManiaEditPlayfield(Beatmap.Stages); + + protected override Vector2 PlayfieldArea => Vector2.One; + + protected override CursorContainer CreateCursor() => null; + } +}