2024-06-18 20:55:59 +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.
|
|
|
|
|
2024-06-18 21:41:43 +08:00
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
2024-06-18 20:55:59 +08:00
|
|
|
using osu.Framework.Allocation;
|
2024-06-19 15:01:33 +08:00
|
|
|
using osu.Framework.Bindables;
|
2024-06-18 21:41:43 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2024-06-18 20:55:59 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2024-07-02 20:55:04 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2024-06-18 20:55:59 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2024-07-02 20:55:04 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2024-06-18 21:41:43 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2024-06-18 20:55:59 +08:00
|
|
|
using osu.Game.Beatmaps.Timing;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2024-07-02 20:55:04 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2024-06-18 21:41:43 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osuTK;
|
2024-06-18 20:55:59 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|
|
|
{
|
2024-07-02 20:55:04 +08:00
|
|
|
public partial class TimelineBreak : CompositeDrawable, IHasContextMenu
|
2024-06-18 20:55:59 +08:00
|
|
|
{
|
2024-06-19 15:01:33 +08:00
|
|
|
public Bindable<BreakPeriod> Break { get; } = new Bindable<BreakPeriod>();
|
2024-06-18 20:55:59 +08:00
|
|
|
|
2024-07-02 20:55:04 +08:00
|
|
|
public Action<BreakPeriod>? OnDeleted { get; init; }
|
|
|
|
|
2024-06-18 20:55:59 +08:00
|
|
|
public TimelineBreak(BreakPeriod b)
|
|
|
|
{
|
2024-06-19 15:01:33 +08:00
|
|
|
Break.Value = b;
|
2024-06-18 20:55:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
RelativePositionAxes = Axes.X;
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
Origin = Anchor.TopLeft;
|
2024-06-18 21:41:43 +08:00
|
|
|
Padding = new MarginPadding { Horizontal = -5 };
|
2024-06-18 20:55:59 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2024-06-18 21:41:43 +08:00
|
|
|
new Container
|
2024-06-18 20:55:59 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2024-06-18 21:41:43 +08:00
|
|
|
Padding = new MarginPadding { Horizontal = 5 },
|
2024-07-12 14:41:51 +08:00
|
|
|
Child = new Box
|
2024-06-18 20:55:59 +08:00
|
|
|
{
|
2024-06-18 21:41:43 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2024-06-19 22:02:10 +08:00
|
|
|
Colour = colours.Gray5,
|
2024-07-12 14:41:51 +08:00
|
|
|
Alpha = 0.9f,
|
2024-06-18 20:55:59 +08:00
|
|
|
},
|
|
|
|
},
|
2024-06-19 15:01:33 +08:00
|
|
|
new DragHandle(isStartHandle: true)
|
2024-06-18 20:55:59 +08:00
|
|
|
{
|
2024-06-19 15:01:33 +08:00
|
|
|
Break = { BindTarget = Break },
|
2024-06-18 21:41:43 +08:00
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Origin = Anchor.TopLeft,
|
2024-06-19 16:11:04 +08:00
|
|
|
Action = (time, breakPeriod) => new ManualBreakPeriod(time, breakPeriod.EndTime),
|
2024-06-18 20:55:59 +08:00
|
|
|
},
|
2024-06-19 15:01:33 +08:00
|
|
|
new DragHandle(isStartHandle: false)
|
2024-06-18 20:55:59 +08:00
|
|
|
{
|
2024-06-19 15:01:33 +08:00
|
|
|
Break = { BindTarget = Break },
|
2024-06-18 20:55:59 +08:00
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
2024-06-19 16:11:04 +08:00
|
|
|
Action = (time, breakPeriod) => new ManualBreakPeriod(breakPeriod.StartTime, time),
|
2024-06-18 20:55:59 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2024-06-18 21:41:43 +08:00
|
|
|
|
2024-06-19 15:01:33 +08:00
|
|
|
protected override void LoadComplete()
|
2024-06-18 21:41:43 +08:00
|
|
|
{
|
2024-06-19 15:01:33 +08:00
|
|
|
base.LoadComplete();
|
2024-06-18 21:41:43 +08:00
|
|
|
|
2024-06-19 15:01:33 +08:00
|
|
|
Break.BindValueChanged(_ =>
|
|
|
|
{
|
|
|
|
X = (float)Break.Value.StartTime;
|
|
|
|
Width = (float)Break.Value.Duration;
|
|
|
|
}, true);
|
2024-06-18 21:41:43 +08:00
|
|
|
}
|
|
|
|
|
2024-07-03 14:17:00 +08:00
|
|
|
public MenuItem[] ContextMenuItems => new MenuItem[]
|
2024-07-02 20:55:04 +08:00
|
|
|
{
|
|
|
|
new OsuMenuItem(CommonStrings.ButtonsDelete, MenuItemType.Destructive, () => OnDeleted?.Invoke(Break.Value)),
|
|
|
|
};
|
|
|
|
|
2024-06-18 21:41:43 +08:00
|
|
|
private partial class DragHandle : FillFlowContainer
|
|
|
|
{
|
2024-06-19 15:01:33 +08:00
|
|
|
public Bindable<BreakPeriod> Break { get; } = new Bindable<BreakPeriod>();
|
|
|
|
|
2024-06-18 21:41:43 +08:00
|
|
|
public new Anchor Anchor
|
|
|
|
{
|
|
|
|
get => base.Anchor;
|
|
|
|
init => base.Anchor = value;
|
|
|
|
}
|
|
|
|
|
2024-06-19 15:01:33 +08:00
|
|
|
public Func<double, BreakPeriod, BreakPeriod>? Action { get; init; }
|
2024-06-18 21:41:43 +08:00
|
|
|
|
|
|
|
private readonly bool isStartHandle;
|
|
|
|
|
|
|
|
private Container handle = null!;
|
|
|
|
private (double min, double max)? allowedDragRange;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private EditorBeatmap beatmap { get; set; } = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private Timeline timeline { get; set; } = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IEditorChangeHandler? changeHandler { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
|
|
|
|
2024-06-19 15:01:33 +08:00
|
|
|
public DragHandle(bool isStartHandle)
|
2024-06-18 21:41:43 +08:00
|
|
|
{
|
|
|
|
this.isStartHandle = isStartHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
Direction = FillDirection.Horizontal;
|
|
|
|
Spacing = new Vector2(5);
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
handle = new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor,
|
|
|
|
Origin = Anchor,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2024-07-12 14:41:51 +08:00
|
|
|
CornerRadius = 4,
|
2024-06-18 21:41:43 +08:00
|
|
|
Masking = true,
|
|
|
|
Child = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Colour4.White,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
BypassAutoSizeAxes = Axes.X,
|
|
|
|
Anchor = Anchor,
|
|
|
|
Origin = Anchor,
|
|
|
|
Text = "Break",
|
|
|
|
Margin = new MarginPadding { Top = 2, },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
updateState();
|
|
|
|
FinishTransforms(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnDragStart(DragStartEvent e)
|
|
|
|
{
|
|
|
|
changeHandler?.BeginChange();
|
|
|
|
updateState();
|
|
|
|
|
2024-06-25 18:25:37 +08:00
|
|
|
double min = beatmap.HitObjects.LastOrDefault(ho => ho.GetEndTime() <= Break.Value.StartTime)?.GetEndTime() ?? double.NegativeInfinity;
|
|
|
|
double max = beatmap.HitObjects.FirstOrDefault(ho => ho.StartTime >= Break.Value.EndTime)?.StartTime ?? double.PositiveInfinity;
|
2024-06-18 21:41:43 +08:00
|
|
|
|
|
|
|
if (isStartHandle)
|
2024-06-19 15:01:33 +08:00
|
|
|
max = Math.Min(max, Break.Value.EndTime - BreakPeriod.MIN_BREAK_DURATION);
|
2024-06-18 21:41:43 +08:00
|
|
|
else
|
2024-06-19 15:01:33 +08:00
|
|
|
min = Math.Max(min, Break.Value.StartTime + BreakPeriod.MIN_BREAK_DURATION);
|
2024-06-18 21:41:43 +08:00
|
|
|
|
|
|
|
allowedDragRange = (min, max);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDrag(DragEvent e)
|
|
|
|
{
|
|
|
|
base.OnDrag(e);
|
|
|
|
|
|
|
|
Debug.Assert(allowedDragRange != null);
|
|
|
|
|
2024-06-19 15:01:33 +08:00
|
|
|
if (Action != null
|
|
|
|
&& timeline.FindSnappedPositionAndTime(e.ScreenSpaceMousePosition).Time is double time
|
2024-06-18 21:41:43 +08:00
|
|
|
&& time > allowedDragRange.Value.min
|
|
|
|
&& time < allowedDragRange.Value.max)
|
|
|
|
{
|
2024-06-19 15:01:33 +08:00
|
|
|
int index = beatmap.Breaks.IndexOf(Break.Value);
|
|
|
|
beatmap.Breaks[index] = Break.Value = Action.Invoke(time, Break.Value);
|
2024-06-18 21:41:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDragEnd(DragEndEvent e)
|
|
|
|
{
|
|
|
|
changeHandler?.EndChange();
|
|
|
|
updateState();
|
|
|
|
base.OnDragEnd(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
bool active = IsHovered || IsDragged;
|
|
|
|
|
2024-06-19 22:02:10 +08:00
|
|
|
var colour = colours.Gray8;
|
2024-06-18 21:41:43 +08:00
|
|
|
if (active)
|
|
|
|
colour = colour.Lighten(0.3f);
|
|
|
|
|
2024-07-12 14:41:51 +08:00
|
|
|
handle.FadeColour(colour, 400, Easing.OutQuint);
|
|
|
|
handle.ResizeWidthTo(active ? 10 : 8, 400, Easing.OutElasticHalf);
|
2024-06-18 21:41:43 +08:00
|
|
|
}
|
|
|
|
}
|
2024-06-18 20:55:59 +08:00
|
|
|
}
|
|
|
|
}
|