Skip to content

Commit

Permalink
Add HoldCompositionTool
Browse files Browse the repository at this point in the history
  • Loading branch information
LumpBloom7 committed May 1, 2021
1 parent dbda82c commit 2247a65
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 1 deletion.
55 changes: 55 additions & 0 deletions osu.Game.Rulesets.Sentakki/Edit/Blueprints/Holds/HoldHighlight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Game.Rulesets.Sentakki.Objects.Drawables.Pieces;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Rulesets.Sentakki.Edit.Blueprints.Holds
{
public class HoldHighlight : CompositeDrawable
{
public readonly Container Note;

// This drawable is zero width
// We should use the quad of the note container
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => ring.ReceivePositionalInputAt(screenSpacePos);
public override Quad ScreenSpaceDrawQuad => ring.ScreenSpaceDrawQuad.AABBFloat;

private readonly RingPiece ring;

public HoldHighlight()
{
Anchor = Origin = Anchor.Centre;
Colour = Color4.YellowGreen;
Alpha = 0.5f;
InternalChildren = new Drawable[]
{
Note = new Container{
Anchor = Anchor.Centre,
Origin = Anchor.BottomCentre,
Children = new Drawable[]{
new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(-75/2),
Child = ring = new RingPiece()
},
new DotPiece(squared: true)
{
Anchor = Anchor.TopCentre,
Rotation = 45,
},
new DotPiece(squared: true)
{
Anchor = Anchor.BottomCentre,
Rotation = 45,
},
}
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Sentakki.Objects;
using osu.Game.Rulesets.Sentakki.UI;
using osuTK.Input;

namespace osu.Game.Rulesets.Sentakki.Edit.Blueprints.Holds
{
public class HoldPlacementBlueprint : PlacementBlueprint
{
private readonly HoldHighlight highlight;

public new Hold HitObject => (Hold)base.HitObject;

public HoldPlacementBlueprint()
: base(new Hold())
{
Anchor = Origin = Anchor.Centre;
InternalChild = highlight = new HoldHighlight();
highlight.Note.Y = -SentakkiPlayfield.INTERSECTDISTANCE;
}

protected override void Update()
{
highlight.Rotation = HitObject.Lane.GetRotationForLane();
}

protected override bool OnMouseDown(MouseDownEvent e)
{
if (e.Button != MouseButton.Left)
return false;

BeginPlacement(true);

return base.OnMouseDown(e);
}

protected override void OnMouseUp(MouseUpEvent e)
{
if (e.Button != MouseButton.Left)
return;

EndPlacement(true);
}

private double originalStartTime;

public override void UpdateTimeAndPosition(SnapResult result)
{
base.UpdateTimeAndPosition(result);

if (PlacementActive == PlacementState.Active)
{
if (result.Time is double endTime)
{
HitObject.StartTime = endTime < originalStartTime ? endTime : originalStartTime;
HitObject.Duration = Math.Abs(endTime - originalStartTime);
}
}
else
{
HitObject.Lane = OriginPosition.GetDegreesFromPosition(ToLocalSpace(result.ScreenSpacePosition)).GetNoteLaneFromDegrees();
if (result.Time is double startTime)
originalStartTime = HitObject.StartTime = startTime;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using osu.Framework.Graphics.Primitives;
using osu.Game.Rulesets.Sentakki.Edit.Blueprints.Taps;
using osu.Game.Rulesets.Sentakki.Objects.Drawables;
using osu.Game.Rulesets.Sentakki.UI;
using osuTK;

namespace osu.Game.Rulesets.Sentakki.Edit.Blueprints.Holds
{
public class HoldSelectionBlueprint : SentakkiSelectionBlueprint
{
public new DrawableHold DrawableObject => (DrawableHold)base.DrawableObject;


private readonly HoldHighlight highlight;

public HoldSelectionBlueprint(DrawableHold drawableHold)
: base(drawableHold)
{
InternalChild = highlight = new HoldHighlight();
}

protected override void Update()
{
base.Update();

highlight.Rotation = DrawableObject.HitObject.Lane.GetRotationForLane();
highlight.Note.Y = Math.Max(DrawableObject.NoteBody.Y, -SentakkiPlayfield.INTERSECTDISTANCE);
highlight.Note.Height = DrawableObject.NoteBody.Height;
highlight.Note.Scale = DrawableObject.NoteBody.Scale;
}

public override Vector2 ScreenSpaceSelectionPoint => highlight.ScreenSpaceDrawQuad.Centre;

public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => highlight.ReceivePositionalInputAt(screenSpacePos);

public override Quad SelectionQuad => highlight.ScreenSpaceDrawQuad;
}
}
21 changes: 21 additions & 0 deletions osu.Game.Rulesets.Sentakki/Edit/HoldCompositionTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Sentakki.Edit.Blueprints.Holds;
using osu.Game.Rulesets.Sentakki.Objects;

namespace osu.Game.Rulesets.Sentakki.Edit
{
public class HoldCompositionTool : HitObjectCompositionTool
{
public HoldCompositionTool()
: base(nameof(Hold))
{
}

public override Drawable CreateIcon() => new BeatmapStatisticIcon(BeatmapStatisticsIconType.Sliders);

public override PlacementBlueprint CreatePlacementBlueprint() => new HoldPlacementBlueprint();
}
}
3 changes: 3 additions & 0 deletions osu.Game.Rulesets.Sentakki/Edit/SentakkiBlueprintContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using osu.Framework.Graphics;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Sentakki.Edit.Blueprints.Holds;
using osu.Game.Rulesets.Sentakki.Edit.Blueprints.Taps;
using osu.Game.Rulesets.Sentakki.Objects.Drawables;
using osu.Game.Screens.Edit.Components.TernaryButtons;
Expand All @@ -23,6 +24,8 @@ public override OverlaySelectionBlueprint CreateBlueprintFor(DrawableHitObject h
{
case DrawableTap t:
return new TapSelectionBlueprint(t);
case DrawableHold h:
return new HoldSelectionBlueprint(h);
}
return base.CreateBlueprintFor(hitObject);
}
Expand Down
3 changes: 2 additions & 1 deletion osu.Game.Rulesets.Sentakki/Edit/SentakkiHitObjectComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public SentakkiHitObjectComposer(SentakkiRuleset ruleset)

protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new HitObjectCompositionTool[]
{
new TapCompositionTool()
new TapCompositionTool(),
new HoldCompositionTool(),
};

protected override ComposeBlueprintContainer CreateBlueprintContainer() => new SentakkiBlueprintContainer(this);
Expand Down

0 comments on commit 2247a65

Please sign in to comment.