2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2020-05-21 16:13:22 +08:00
|
|
|
using System.Collections.Specialized;
|
2018-04-13 17:19:50 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-14 17:34:13 +08:00
|
|
|
using osu.Framework.Input;
|
2020-01-28 14:08:02 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Framework.Logging;
|
|
|
|
using osu.Game.Beatmaps;
|
2019-10-25 11:34:49 +08:00
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2018-07-17 15:53:32 +08:00
|
|
|
using osu.Game.Rulesets.Configuration;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Rulesets.Edit.Tools;
|
2019-04-08 17:32:05 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-10-17 16:41:17 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.UI;
|
2019-08-29 11:43:43 +08:00
|
|
|
using osu.Game.Screens.Edit;
|
2018-11-06 17:14:46 +08:00
|
|
|
using osu.Game.Screens.Edit.Components.RadioButtons;
|
2019-08-29 15:06:40 +08:00
|
|
|
using osu.Game.Screens.Edit.Compose;
|
2018-11-06 17:28:22 +08:00
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
2019-10-18 12:18:57 +08:00
|
|
|
using osuTK;
|
2020-01-28 14:08:02 +08:00
|
|
|
using Key = osuTK.Input.Key;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
2019-08-29 17:02:50 +08:00
|
|
|
[Cached(Type = typeof(IPlacementHandler))]
|
|
|
|
public abstract class HitObjectComposer<TObject> : HitObjectComposer, IPlacementHandler
|
|
|
|
where TObject : HitObject
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-07-17 15:53:32 +08:00
|
|
|
protected IRulesetConfigManager Config { get; private set; }
|
2019-12-05 19:12:25 +08:00
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
protected readonly Ruleset Ruleset;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2019-10-16 19:20:07 +08:00
|
|
|
[Resolved]
|
2020-05-22 15:37:28 +08:00
|
|
|
protected EditorClock EditorClock { get; private set; }
|
2019-10-16 19:20:07 +08:00
|
|
|
|
2019-12-27 18:46:33 +08:00
|
|
|
[Resolved]
|
|
|
|
protected EditorBeatmap EditorBeatmap { get; private set; }
|
|
|
|
|
2019-10-25 11:34:49 +08:00
|
|
|
[Resolved]
|
2020-05-20 17:40:55 +08:00
|
|
|
protected IBeatSnapProvider BeatSnapProvider { get; private set; }
|
2019-10-25 11:34:49 +08:00
|
|
|
|
2020-02-07 23:12:23 +08:00
|
|
|
protected ComposeBlueprintContainer BlueprintContainer { get; private set; }
|
2020-02-07 18:08:49 +08:00
|
|
|
|
2019-08-29 17:20:43 +08:00
|
|
|
private DrawableEditRulesetWrapper<TObject> drawableRulesetWrapper;
|
2020-05-21 16:13:22 +08:00
|
|
|
|
|
|
|
protected readonly Container LayerBelowRuleset = new Container { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
private readonly List<Container> layerContainers = new List<Container>();
|
2018-10-17 14:46:30 +08:00
|
|
|
|
2018-11-14 17:34:13 +08:00
|
|
|
private InputManager inputManager;
|
|
|
|
|
2020-01-28 14:07:37 +08:00
|
|
|
private RadioButtonCollection toolboxCollection;
|
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
protected HitObjectComposer(Ruleset ruleset)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2018-10-17 17:01:38 +08:00
|
|
|
Ruleset = ruleset;
|
2018-04-13 17:19:50 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-05-22 15:37:28 +08:00
|
|
|
private void load()
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-12-27 18:46:33 +08:00
|
|
|
Config = Dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
try
|
|
|
|
{
|
2019-12-27 18:46:33 +08:00
|
|
|
drawableRulesetWrapper = new DrawableEditRulesetWrapper<TObject>(CreateDrawableRuleset(Ruleset, EditorBeatmap.PlayableBeatmap))
|
2019-08-29 17:02:50 +08:00
|
|
|
{
|
2020-05-22 15:37:28 +08:00
|
|
|
Clock = EditorClock,
|
2019-10-18 17:21:53 +08:00
|
|
|
ProcessCustomClock = false
|
2019-08-29 17:02:50 +08:00
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Logger.Error(e, "Could not load beatmap sucessfully!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-16 19:20:07 +08:00
|
|
|
var layerBelowRuleset = drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer().WithChildren(new Drawable[]
|
|
|
|
{
|
2020-05-21 16:13:22 +08:00
|
|
|
LayerBelowRuleset,
|
2019-10-16 19:20:07 +08:00
|
|
|
new EditorPlayfieldBorder { RelativeSizeAxes = Axes.Both }
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-02-07 18:08:49 +08:00
|
|
|
var layerAboveRuleset = drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer().WithChild(BlueprintContainer = CreateBlueprintContainer());
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
layerContainers.Add(layerBelowRuleset);
|
|
|
|
layerContainers.Add(layerAboveRuleset);
|
|
|
|
|
|
|
|
InternalChild = new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Name = "Sidebar",
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding { Right = 10 },
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new ToolboxGroup { Child = toolboxCollection = new RadioButtonCollection { RelativeSizeAxes = Axes.X } }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Name = "Content",
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
layerBelowRuleset,
|
2019-08-29 17:20:43 +08:00
|
|
|
drawableRulesetWrapper,
|
2018-04-13 17:19:50 +08:00
|
|
|
layerAboveRuleset
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.Absolute, 200),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-01-28 14:00:45 +08:00
|
|
|
toolboxCollection.Items = CompositionTools
|
|
|
|
.Prepend(new SelectTool())
|
|
|
|
.Select(t => new RadioButton(t.Name, () => toolSelected(t)))
|
|
|
|
.ToList();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-01-28 14:07:37 +08:00
|
|
|
setSelectTool();
|
2019-10-16 19:20:07 +08:00
|
|
|
|
2020-05-21 16:13:22 +08:00
|
|
|
EditorBeatmap.SelectedHitObjects.CollectionChanged += selectionChanged;
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
2020-01-28 14:08:02 +08:00
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
{
|
|
|
|
if (e.Key >= Key.Number1 && e.Key <= Key.Number9)
|
|
|
|
{
|
2020-02-01 01:32:47 +08:00
|
|
|
var item = toolboxCollection.Items.ElementAtOrDefault(e.Key - Key.Number1);
|
2020-01-28 14:08:02 +08:00
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
{
|
|
|
|
item.Select();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
}
|
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
inputManager = GetContainingInputManager();
|
2018-07-17 14:35:32 +08:00
|
|
|
}
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
{
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
layerContainers.ForEach(l =>
|
|
|
|
{
|
2019-08-29 17:20:43 +08:00
|
|
|
l.Anchor = drawableRulesetWrapper.Playfield.Anchor;
|
|
|
|
l.Origin = drawableRulesetWrapper.Playfield.Origin;
|
|
|
|
l.Position = drawableRulesetWrapper.Playfield.Position;
|
|
|
|
l.Size = drawableRulesetWrapper.Playfield.Size;
|
2018-04-13 17:19:50 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-21 16:13:22 +08:00
|
|
|
private void selectionChanged(object sender, NotifyCollectionChangedEventArgs changedArgs)
|
2019-10-16 19:20:07 +08:00
|
|
|
{
|
2020-05-21 16:13:22 +08:00
|
|
|
if (EditorBeatmap.SelectedHitObjects.Any())
|
2020-01-28 14:07:37 +08:00
|
|
|
{
|
|
|
|
// ensure in selection mode if a selection is made.
|
|
|
|
setSelectTool();
|
|
|
|
}
|
2019-10-16 19:20:07 +08:00
|
|
|
}
|
|
|
|
|
2020-01-28 14:07:37 +08:00
|
|
|
private void setSelectTool() => toolboxCollection.Items.First().Select();
|
|
|
|
|
2020-01-28 14:00:45 +08:00
|
|
|
private void toolSelected(HitObjectCompositionTool tool)
|
2019-10-16 19:20:07 +08:00
|
|
|
{
|
2020-02-07 18:08:49 +08:00
|
|
|
BlueprintContainer.CurrentTool = tool;
|
2019-10-16 19:20:07 +08:00
|
|
|
|
2020-05-21 16:13:22 +08:00
|
|
|
if (!(tool is SelectTool))
|
2020-01-28 14:07:37 +08:00
|
|
|
EditorBeatmap.SelectedHitObjects.Clear();
|
2019-10-16 19:20:07 +08:00
|
|
|
}
|
|
|
|
|
2019-08-29 17:20:43 +08:00
|
|
|
public override IEnumerable<DrawableHitObject> HitObjects => drawableRulesetWrapper.Playfield.AllHitObjects;
|
2020-05-21 16:13:22 +08:00
|
|
|
|
2019-08-29 17:20:43 +08:00
|
|
|
public override bool CursorInPlacementArea => drawableRulesetWrapper.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position);
|
2019-08-29 17:02:50 +08:00
|
|
|
|
|
|
|
protected abstract IReadOnlyList<HitObjectCompositionTool> CompositionTools { get; }
|
2018-10-17 17:01:38 +08:00
|
|
|
|
2020-01-16 10:54:03 +08:00
|
|
|
protected abstract ComposeBlueprintContainer CreateBlueprintContainer();
|
|
|
|
|
2019-12-12 14:58:11 +08:00
|
|
|
protected abstract DrawableRuleset<TObject> CreateDrawableRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods = null);
|
2019-08-29 15:06:40 +08:00
|
|
|
|
|
|
|
public void BeginPlacement(HitObject hitObject)
|
|
|
|
{
|
2020-02-07 17:03:14 +08:00
|
|
|
EditorBeatmap.PlacementObject.Value = hitObject;
|
2019-08-29 15:06:40 +08:00
|
|
|
}
|
|
|
|
|
2020-02-07 17:02:48 +08:00
|
|
|
public void EndPlacement(HitObject hitObject, bool commit)
|
2019-10-18 18:04:08 +08:00
|
|
|
{
|
2020-02-07 17:03:14 +08:00
|
|
|
EditorBeatmap.PlacementObject.Value = null;
|
|
|
|
|
2020-02-07 17:02:48 +08:00
|
|
|
if (commit)
|
|
|
|
{
|
|
|
|
EditorBeatmap.Add(hitObject);
|
2019-11-07 13:08:02 +08:00
|
|
|
|
2020-05-22 15:37:28 +08:00
|
|
|
if (EditorClock.CurrentTime < hitObject.StartTime)
|
|
|
|
EditorClock.Seek(hitObject.StartTime);
|
2020-02-07 17:02:48 +08:00
|
|
|
}
|
2019-10-18 18:04:08 +08:00
|
|
|
}
|
2019-08-29 15:06:40 +08:00
|
|
|
|
2019-10-16 19:10:03 +08:00
|
|
|
public void Delete(HitObject hitObject) => EditorBeatmap.Remove(hitObject);
|
2019-08-29 15:06:40 +08:00
|
|
|
|
2020-05-21 16:13:22 +08:00
|
|
|
public override SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition) => new SnapResult(screenSpacePosition, null);
|
2019-10-25 11:34:49 +08:00
|
|
|
|
|
|
|
public override float GetBeatSnapDistanceAt(double referenceTime)
|
|
|
|
{
|
|
|
|
DifficultyControlPoint difficultyPoint = EditorBeatmap.ControlPointInfo.DifficultyPointAt(referenceTime);
|
2020-05-20 17:40:55 +08:00
|
|
|
return (float)(100 * EditorBeatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier / BeatSnapProvider.BeatDivisor);
|
2019-10-25 11:34:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override float DurationToDistance(double referenceTime, double duration)
|
|
|
|
{
|
2020-05-20 17:40:55 +08:00
|
|
|
double beatLength = BeatSnapProvider.GetBeatLengthAtTime(referenceTime);
|
2019-10-25 11:34:49 +08:00
|
|
|
return (float)(duration / beatLength * GetBeatSnapDistanceAt(referenceTime));
|
|
|
|
}
|
2019-10-16 19:34:02 +08:00
|
|
|
|
2019-10-25 11:34:49 +08:00
|
|
|
public override double DistanceToDuration(double referenceTime, float distance)
|
|
|
|
{
|
2020-05-20 17:40:55 +08:00
|
|
|
double beatLength = BeatSnapProvider.GetBeatLengthAtTime(referenceTime);
|
2019-10-25 11:34:49 +08:00
|
|
|
return distance / GetBeatSnapDistanceAt(referenceTime) * beatLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override double GetSnappedDurationFromDistance(double referenceTime, float distance)
|
2020-05-20 17:40:55 +08:00
|
|
|
=> BeatSnapProvider.SnapTime(referenceTime + DistanceToDuration(referenceTime, distance), referenceTime) - referenceTime;
|
2019-10-25 11:34:49 +08:00
|
|
|
|
|
|
|
public override float GetSnappedDistanceFromDistance(double referenceTime, float distance)
|
2020-02-07 15:43:50 +08:00
|
|
|
{
|
2020-05-20 17:40:55 +08:00
|
|
|
var snappedEndTime = BeatSnapProvider.SnapTime(referenceTime + DistanceToDuration(referenceTime, distance), referenceTime);
|
2020-02-07 15:43:50 +08:00
|
|
|
|
|
|
|
return DurationToDistance(referenceTime, snappedEndTime - referenceTime);
|
|
|
|
}
|
2018-10-17 17:01:38 +08:00
|
|
|
}
|
2019-08-29 17:02:50 +08:00
|
|
|
|
|
|
|
[Cached(typeof(HitObjectComposer))]
|
2020-05-20 16:48:43 +08:00
|
|
|
[Cached(typeof(IPositionSnapProvider))]
|
|
|
|
public abstract class HitObjectComposer : CompositeDrawable, IPositionSnapProvider
|
2019-08-29 17:02:50 +08:00
|
|
|
{
|
|
|
|
internal HitObjectComposer()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// All the <see cref="DrawableHitObject"/>s.
|
|
|
|
/// </summary>
|
|
|
|
public abstract IEnumerable<DrawableHitObject> HitObjects { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether the user's cursor is currently in an area of the <see cref="HitObjectComposer"/> that is valid for placement.
|
|
|
|
/// </summary>
|
|
|
|
public abstract bool CursorInPlacementArea { get; }
|
|
|
|
|
2020-05-20 17:19:21 +08:00
|
|
|
public abstract SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition);
|
2019-10-31 17:15:19 +08:00
|
|
|
|
2019-10-25 11:34:49 +08:00
|
|
|
public abstract float GetBeatSnapDistanceAt(double referenceTime);
|
2019-10-31 17:15:19 +08:00
|
|
|
|
2019-10-25 11:34:49 +08:00
|
|
|
public abstract float DurationToDistance(double referenceTime, double duration);
|
2019-10-31 17:15:19 +08:00
|
|
|
|
2019-10-25 11:34:49 +08:00
|
|
|
public abstract double DistanceToDuration(double referenceTime, float distance);
|
2019-10-31 17:15:19 +08:00
|
|
|
|
2019-10-25 11:34:49 +08:00
|
|
|
public abstract double GetSnappedDurationFromDistance(double referenceTime, float distance);
|
2019-10-31 17:15:19 +08:00
|
|
|
|
2019-10-25 11:34:49 +08:00
|
|
|
public abstract float GetSnappedDistanceFromDistance(double referenceTime, float distance);
|
2019-08-29 17:02:50 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|