2020-01-23 15:22:43 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2020-02-05 14:58:35 +08:00
|
|
|
using System;
|
2020-02-05 18:43:13 +08:00
|
|
|
using System.Collections.Generic;
|
2020-09-29 15:42:54 +08:00
|
|
|
using System.Linq;
|
2020-01-23 15:22:43 +08:00
|
|
|
using JetBrains.Annotations;
|
2020-02-05 16:16:37 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-01-23 15:22:43 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2020-09-29 16:22:47 +08:00
|
|
|
using osu.Framework.Graphics.Colour;
|
2020-01-23 15:22:43 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-02-05 18:43:13 +08:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2020-01-23 15:22:43 +08:00
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-02-05 16:16:37 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2020-09-29 16:04:59 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-02-05 18:43:13 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-01-23 15:22:43 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-09-29 15:42:54 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2020-01-23 15:22:43 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|
|
|
{
|
|
|
|
public class TimelineHitObjectBlueprint : SelectionBlueprint
|
|
|
|
{
|
|
|
|
private readonly Circle circle;
|
|
|
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
private readonly Bindable<double> startTime;
|
|
|
|
|
2020-02-05 14:58:35 +08:00
|
|
|
public Action<DragEvent> OnDragHandled;
|
|
|
|
|
2020-02-05 18:43:13 +08:00
|
|
|
private readonly DragBar dragBar;
|
|
|
|
|
|
|
|
private readonly List<Container> shadowComponents = new List<Container>();
|
|
|
|
|
2020-09-29 15:42:54 +08:00
|
|
|
private DrawableHitObject drawableHitObject;
|
|
|
|
|
|
|
|
private Bindable<Color4> comboColour;
|
|
|
|
|
2020-09-29 16:04:59 +08:00
|
|
|
private readonly Container mainComponents;
|
|
|
|
|
|
|
|
private readonly OsuSpriteText comboIndexText;
|
|
|
|
|
|
|
|
private Bindable<int> comboIndex;
|
|
|
|
|
2020-02-05 18:43:13 +08:00
|
|
|
private const float thickness = 5;
|
|
|
|
|
|
|
|
private const float shadow_radius = 5;
|
2020-01-23 15:22:43 +08:00
|
|
|
|
2020-09-29 16:04:59 +08:00
|
|
|
private const float circle_size = 24;
|
2020-01-23 15:22:43 +08:00
|
|
|
|
|
|
|
public TimelineHitObjectBlueprint(HitObject hitObject)
|
|
|
|
: base(hitObject)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft;
|
|
|
|
Origin = Anchor.CentreLeft;
|
|
|
|
|
|
|
|
startTime = hitObject.StartTimeBindable.GetBoundCopy();
|
|
|
|
startTime.BindValueChanged(time => X = (float)time.NewValue, true);
|
|
|
|
|
|
|
|
RelativePositionAxes = Axes.X;
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
2020-09-29 16:04:59 +08:00
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
{
|
|
|
|
mainComponents = new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
},
|
|
|
|
comboIndexText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.Numeric.With(size: circle_size / 2, weight: FontWeight.Black),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-02-05 18:43:13 +08:00
|
|
|
circle = new Circle
|
2020-01-23 15:22:43 +08:00
|
|
|
{
|
|
|
|
Size = new Vector2(circle_size),
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.Centre,
|
2020-02-05 18:43:13 +08:00
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = shadow_radius,
|
|
|
|
Colour = Color4.Black
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
shadowComponents.Add(circle);
|
2020-02-05 16:16:37 +08:00
|
|
|
|
2020-05-27 11:38:39 +08:00
|
|
|
if (hitObject is IHasDuration)
|
2020-02-05 16:16:37 +08:00
|
|
|
{
|
2020-02-05 18:43:13 +08:00
|
|
|
DragBar dragBarUnderlay;
|
|
|
|
Container extensionBar;
|
|
|
|
|
2020-09-29 16:04:59 +08:00
|
|
|
mainComponents.AddRange(new Drawable[]
|
2020-02-05 16:16:37 +08:00
|
|
|
{
|
|
|
|
extensionBar = new Container
|
|
|
|
{
|
|
|
|
Masking = true,
|
2020-02-05 18:43:13 +08:00
|
|
|
Size = new Vector2(1, thickness),
|
2020-02-05 16:16:37 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2020-02-05 18:43:13 +08:00
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = shadow_radius,
|
|
|
|
Colour = Color4.Black
|
|
|
|
},
|
2020-02-05 16:16:37 +08:00
|
|
|
Child = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
},
|
2020-02-05 18:43:13 +08:00
|
|
|
circle,
|
|
|
|
// only used for drawing the shadow
|
|
|
|
dragBarUnderlay = new DragBar(null),
|
|
|
|
// cover up the shadow on the join
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Height = thickness,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
},
|
|
|
|
dragBar = new DragBar(hitObject) { OnDragHandled = e => OnDragHandled?.Invoke(e) },
|
2020-02-05 16:16:37 +08:00
|
|
|
});
|
2020-02-05 18:43:13 +08:00
|
|
|
|
|
|
|
shadowComponents.Add(dragBarUnderlay);
|
|
|
|
shadowComponents.Add(extensionBar);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-29 16:04:59 +08:00
|
|
|
mainComponents.Add(circle);
|
2020-02-05 16:16:37 +08:00
|
|
|
}
|
2020-02-05 18:43:13 +08:00
|
|
|
|
|
|
|
updateShadows();
|
2020-02-05 16:16:37 +08:00
|
|
|
}
|
|
|
|
|
2020-09-29 15:42:54 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(HitObjectComposer composer)
|
|
|
|
{
|
|
|
|
if (composer != null)
|
|
|
|
{
|
|
|
|
// best effort to get the drawable representation for grabbing colour and what not.
|
|
|
|
drawableHitObject = composer.HitObjects.FirstOrDefault(d => d.HitObject == HitObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2020-09-29 16:04:59 +08:00
|
|
|
if (HitObject is IHasComboInformation comboInfo)
|
|
|
|
{
|
|
|
|
comboIndex = comboInfo.IndexInCurrentComboBindable.GetBoundCopy();
|
|
|
|
comboIndex.BindValueChanged(combo =>
|
|
|
|
{
|
|
|
|
comboIndexText.Text = (combo.NewValue + 1).ToString();
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:42:54 +08:00
|
|
|
if (drawableHitObject != null)
|
|
|
|
{
|
|
|
|
comboColour = drawableHitObject.AccentColour.GetBoundCopy();
|
|
|
|
comboColour.BindValueChanged(colour =>
|
|
|
|
{
|
2020-09-29 16:34:50 +08:00
|
|
|
if (HitObject is IHasDuration)
|
|
|
|
mainComponents.Colour = ColourInfo.GradientHorizontal(drawableHitObject.AccentColour.Value, Color4.White);
|
|
|
|
else
|
|
|
|
mainComponents.Colour = drawableHitObject.AccentColour.Value;
|
2020-09-29 16:04:59 +08:00
|
|
|
|
2020-09-30 16:10:22 +08:00
|
|
|
var col = mainComponents.Colour.TopLeft.Linear;
|
2020-09-29 16:04:59 +08:00
|
|
|
float brightness = col.R + col.G + col.B;
|
|
|
|
|
|
|
|
// decide the combo index colour based on brightness?
|
|
|
|
comboIndexText.Colour = brightness > 0.5f ? Color4.Black : Color4.White;
|
2020-09-29 15:42:54 +08:00
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 18:43:13 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
// no bindable so we perform this every update
|
|
|
|
Width = (float)(HitObject.GetEndTime() - HitObject.StartTime);
|
|
|
|
}
|
|
|
|
|
2020-02-06 13:35:45 +08:00
|
|
|
protected override bool ShouldBeConsideredForInput(Drawable child) => true;
|
|
|
|
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
|
|
|
|
base.ReceivePositionalInputAt(screenSpacePos) ||
|
|
|
|
circle.ReceivePositionalInputAt(screenSpacePos) ||
|
|
|
|
dragBar?.ReceivePositionalInputAt(screenSpacePos) == true;
|
|
|
|
|
2020-02-05 18:43:13 +08:00
|
|
|
protected override void OnSelected()
|
|
|
|
{
|
|
|
|
updateShadows();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateShadows()
|
|
|
|
{
|
|
|
|
foreach (var s in shadowComponents)
|
|
|
|
{
|
|
|
|
if (State == SelectionState.Selected)
|
|
|
|
{
|
|
|
|
s.EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = shadow_radius / 2,
|
|
|
|
Colour = Color4.Orange,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s.EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = shadow_radius,
|
|
|
|
Colour = State == SelectionState.Selected ? Color4.Orange : Color4.Black
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDeselected()
|
|
|
|
{
|
|
|
|
updateShadows();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Quad SelectionQuad
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
// correctly include the circle in the selection quad region, as it is usually outside the blueprint itself.
|
|
|
|
var leftQuad = circle.ScreenSpaceDrawQuad;
|
|
|
|
var rightQuad = dragBar?.ScreenSpaceDrawQuad ?? ScreenSpaceDrawQuad;
|
|
|
|
|
|
|
|
return new Quad(leftQuad.TopLeft, Vector2.ComponentMax(rightQuad.TopRight, leftQuad.TopRight),
|
|
|
|
leftQuad.BottomLeft, Vector2.ComponentMax(rightQuad.BottomRight, leftQuad.BottomRight));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-20 16:48:43 +08:00
|
|
|
public override Vector2 ScreenSpaceSelectionPoint => ScreenSpaceDrawQuad.TopLeft;
|
2020-02-05 18:43:13 +08:00
|
|
|
|
|
|
|
public class DragBar : Container
|
2020-02-05 16:16:37 +08:00
|
|
|
{
|
|
|
|
private readonly HitObject hitObject;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private Timeline timeline { get; set; }
|
|
|
|
|
2020-02-05 14:58:35 +08:00
|
|
|
public Action<DragEvent> OnDragHandled;
|
|
|
|
|
2020-02-05 18:43:13 +08:00
|
|
|
public override bool HandlePositionalInput => hitObject != null;
|
|
|
|
|
2020-02-05 16:16:37 +08:00
|
|
|
public DragBar(HitObject hitObject)
|
|
|
|
{
|
|
|
|
this.hitObject = hitObject;
|
|
|
|
|
|
|
|
CornerRadius = 2;
|
|
|
|
Masking = true;
|
2020-02-05 18:43:13 +08:00
|
|
|
Size = new Vector2(5, 1);
|
2020-02-05 16:16:37 +08:00
|
|
|
Anchor = Anchor.CentreRight;
|
2020-02-05 18:43:13 +08:00
|
|
|
Origin = Anchor.Centre;
|
2020-02-05 16:16:37 +08:00
|
|
|
RelativePositionAxes = Axes.X;
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2020-02-05 18:43:13 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
2020-02-05 16:16:37 +08:00
|
|
|
{
|
2020-02-05 18:43:13 +08:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
2020-02-05 16:16:37 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-05 14:33:04 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool hasMouseDown;
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
|
|
|
hasMouseDown = true;
|
|
|
|
updateState();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
|
|
|
hasMouseDown = false;
|
|
|
|
updateState();
|
|
|
|
base.OnMouseUp(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
2020-02-05 18:43:13 +08:00
|
|
|
Colour = IsHovered || hasMouseDown ? Color4.OrangeRed : Color4.White;
|
2020-02-05 14:33:04 +08:00
|
|
|
}
|
|
|
|
|
2020-02-05 16:16:37 +08:00
|
|
|
[Resolved]
|
|
|
|
private EditorBeatmap beatmap { get; set; }
|
|
|
|
|
2020-02-05 15:35:07 +08:00
|
|
|
[Resolved]
|
|
|
|
private IBeatSnapProvider beatSnapProvider { get; set; }
|
|
|
|
|
2020-04-09 21:00:56 +08:00
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
private IEditorChangeHandler changeHandler { get; set; }
|
|
|
|
|
|
|
|
protected override bool OnDragStart(DragStartEvent e)
|
|
|
|
{
|
|
|
|
changeHandler?.BeginChange();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-05 16:16:37 +08:00
|
|
|
protected override void OnDrag(DragEvent e)
|
|
|
|
{
|
|
|
|
base.OnDrag(e);
|
|
|
|
|
2020-02-05 14:58:35 +08:00
|
|
|
OnDragHandled?.Invoke(e);
|
|
|
|
|
2020-05-20 17:19:21 +08:00
|
|
|
if (timeline.SnapScreenSpacePositionToValidTime(e.ScreenSpaceMousePosition).Time is double time)
|
2020-02-05 16:16:37 +08:00
|
|
|
{
|
2020-05-20 17:19:21 +08:00
|
|
|
switch (hitObject)
|
|
|
|
{
|
|
|
|
case IHasRepeats repeatHitObject:
|
|
|
|
// find the number of repeats which can fit in the requested time.
|
|
|
|
var lengthOfOneRepeat = repeatHitObject.Duration / (repeatHitObject.RepeatCount + 1);
|
2020-05-22 18:23:07 +08:00
|
|
|
var proposedCount = Math.Max(0, (int)Math.Round((time - hitObject.StartTime) / lengthOfOneRepeat) - 1);
|
2020-02-05 14:32:51 +08:00
|
|
|
|
2020-05-20 17:19:21 +08:00
|
|
|
if (proposedCount == repeatHitObject.RepeatCount)
|
|
|
|
return;
|
2020-02-05 14:32:51 +08:00
|
|
|
|
2020-05-20 17:19:21 +08:00
|
|
|
repeatHitObject.RepeatCount = proposedCount;
|
|
|
|
break;
|
2020-02-05 16:16:37 +08:00
|
|
|
|
2020-05-27 11:38:39 +08:00
|
|
|
case IHasDuration endTimeHitObject:
|
2020-05-20 17:19:21 +08:00
|
|
|
var snappedTime = Math.Max(hitObject.StartTime, beatSnapProvider.SnapTime(time));
|
2020-02-05 15:35:07 +08:00
|
|
|
|
2020-05-20 17:19:21 +08:00
|
|
|
if (endTimeHitObject.EndTime == snappedTime)
|
|
|
|
return;
|
2020-02-05 15:35:07 +08:00
|
|
|
|
2020-05-27 11:37:44 +08:00
|
|
|
endTimeHitObject.Duration = snappedTime - hitObject.StartTime;
|
2020-05-20 17:19:21 +08:00
|
|
|
break;
|
|
|
|
}
|
2020-02-05 16:16:37 +08:00
|
|
|
|
2020-05-20 17:19:21 +08:00
|
|
|
beatmap.UpdateHitObject(hitObject);
|
|
|
|
}
|
2020-02-05 16:16:37 +08:00
|
|
|
}
|
2020-02-05 14:58:35 +08:00
|
|
|
|
|
|
|
protected override void OnDragEnd(DragEndEvent e)
|
|
|
|
{
|
|
|
|
base.OnDragEnd(e);
|
|
|
|
|
|
|
|
OnDragHandled?.Invoke(null);
|
2020-04-09 21:00:56 +08:00
|
|
|
changeHandler?.EndChange();
|
2020-02-05 14:58:35 +08:00
|
|
|
}
|
2020-01-23 15:22:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|