From bd915e8dca19e43468b12a3a592249064c5e8137 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 4 Oct 2018 13:44:49 +0900 Subject: [PATCH] Implement initial slider placement (linear) --- .../Edit/Masks/SliderPlacementMask.cs | 99 +++++++++++++++++++ ...SliderPlacementMask_CirclePlacementMask.cs | 29 ++++++ .../Edit/OsuHitObjectComposer.cs | 3 +- .../Edit/SliderCompositionTool.cs | 20 ++++ .../Visual/TestCaseHitObjectComposer.cs | 1 + 5 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 osu.Game.Rulesets.Osu/Edit/Masks/SliderPlacementMask.cs create mode 100644 osu.Game.Rulesets.Osu/Edit/Masks/SliderPlacementMask_CirclePlacementMask.cs create mode 100644 osu.Game.Rulesets.Osu/Edit/SliderCompositionTool.cs diff --git a/osu.Game.Rulesets.Osu/Edit/Masks/SliderPlacementMask.cs b/osu.Game.Rulesets.Osu/Edit/Masks/SliderPlacementMask.cs new file mode 100644 index 0000000000..287d19ed93 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Masks/SliderPlacementMask.cs @@ -0,0 +1,99 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using System.Drawing.Imaging; +using System.Linq; +using osu.Framework.Graphics; +using osu.Framework.Input.Events; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Objects.Types; +using osu.Game.Rulesets.Osu.Objects; +using OpenTK; + +namespace osu.Game.Rulesets.Osu.Edit.Masks +{ + public partial class SliderPlacementMask : PlacementMask + { + public new Slider HitObject => (Slider)base.HitObject; + + private readonly CirclePlacementMask headMask; + private readonly CirclePlacementMask tailMask; + + private readonly List controlPoints = new List(); + + private PlacementState state = PlacementState.Head; + + public SliderPlacementMask() + : base(new Slider()) + { + RelativeSizeAxes = Axes.Both; + + InternalChildren = new Drawable[] + { + headMask = new CirclePlacementMask(), + tailMask = new CirclePlacementMask(), + }; + + setState(PlacementState.Head); + } + + protected override bool OnMouseMove(MouseMoveEvent e) + { + switch (state) + { + case PlacementState.Head: + headMask.Position = e.MousePosition; + return true; + case PlacementState.Tail: + tailMask.Position = ToLocalSpace(e.ScreenSpaceMousePosition); + return true; + } + + return false; + } + + protected override bool OnClick(ClickEvent e) + { + switch (state) + { + case PlacementState.Head: + setState(PlacementState.Tail); + controlPoints.Add(Vector2.Zero); + break; + case PlacementState.Tail: + controlPoints.Add(tailMask.Position - headMask.Position); + HitObject.Position = headMask.Position; + HitObject.ControlPoints = controlPoints.ToList(); + HitObject.CurveType = CurveType.Linear; + HitObject.Distance = Vector2.Distance(controlPoints.First(), controlPoints.Last()); + Finish(); + break; + } + + return base.OnClick(e); + } + + private void setState(PlacementState newState) + { + switch (newState) + { + case PlacementState.Head: + tailMask.Alpha = 0; + break; + case PlacementState.Tail: + tailMask.Alpha = 1; + break; + } + + state = newState; + } + + private enum PlacementState + { + Head, + Body, + Tail + } + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/Masks/SliderPlacementMask_CirclePlacementMask.cs b/osu.Game.Rulesets.Osu/Edit/Masks/SliderPlacementMask_CirclePlacementMask.cs new file mode 100644 index 0000000000..4a3574c885 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/Masks/SliderPlacementMask_CirclePlacementMask.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.Graphics; +using osu.Framework.Input.Events; +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Osu.Objects; + +namespace osu.Game.Rulesets.Osu.Edit.Masks +{ + public partial class SliderPlacementMask + { + private class CirclePlacementMask : PlacementMask + { + public new HitCircle HitObject => (HitCircle)base.HitObject; + + public CirclePlacementMask() + : base(new HitCircle()) + { + Origin = Anchor.Centre; + AutoSizeAxes = Axes.Both; + + InternalChild = new HitCircleMask(HitObject); + } + + protected override bool Handle(UIEvent e) => false; + } + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs index ac41d6ef27..c54cec94f6 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs @@ -27,9 +27,10 @@ public OsuHitObjectComposer(Ruleset ruleset) protected override RulesetContainer CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) => new OsuEditRulesetContainer(ruleset, beatmap); - protected override IReadOnlyList CompositionTools => new[] + protected override IReadOnlyList CompositionTools => new HitObjectCompositionTool[] { new HitCircleCompositionTool(), + new SliderCompositionTool(), }; protected override Container CreateLayerContainer() => new PlayfieldAdjustmentContainer { RelativeSizeAxes = Axes.Both }; diff --git a/osu.Game.Rulesets.Osu/Edit/SliderCompositionTool.cs b/osu.Game.Rulesets.Osu/Edit/SliderCompositionTool.cs new file mode 100644 index 0000000000..f7cdd76655 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Edit/SliderCompositionTool.cs @@ -0,0 +1,20 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Edit; +using osu.Game.Rulesets.Edit.Tools; +using osu.Game.Rulesets.Osu.Edit.Masks; +using osu.Game.Rulesets.Osu.Objects; + +namespace osu.Game.Rulesets.Osu.Edit +{ + public class SliderCompositionTool : HitObjectCompositionTool + { + public SliderCompositionTool() + : base(nameof(Slider)) + { + } + + public override PlacementMask CreatePlacementMask() => new SliderPlacementMask(); + } +} diff --git a/osu.Game.Tests/Visual/TestCaseHitObjectComposer.cs b/osu.Game.Tests/Visual/TestCaseHitObjectComposer.cs index 99a8f3f51b..196cb9320a 100644 --- a/osu.Game.Tests/Visual/TestCaseHitObjectComposer.cs +++ b/osu.Game.Tests/Visual/TestCaseHitObjectComposer.cs @@ -38,6 +38,7 @@ public class TestCaseHitObjectComposer : OsuTestCase, IPlacementHandler typeof(HitCircleSelectionMask), typeof(HitCirclePlacementMask), typeof(SliderSelectionMask), + typeof(SliderPlacementMask) }; private HitObjectComposer composer;