2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2020-05-21 08:13:22 +00:00
|
|
|
using System.Collections.Specialized;
|
2018-04-13 09:19:50 +00:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2020-09-09 10:14:28 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-14 09:34:13 +00:00
|
|
|
using osu.Framework.Input;
|
2020-01-28 06:08:02 +00:00
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Logging;
|
|
|
|
using osu.Game.Beatmaps;
|
2019-10-25 03:34:49 +00:00
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2020-09-09 10:14:28 +00:00
|
|
|
using osu.Game.Overlays.Settings;
|
2018-07-17 07:53:32 +00:00
|
|
|
using osu.Game.Rulesets.Configuration;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Rulesets.Edit.Tools;
|
2019-04-08 09:32:05 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-10-17 08:41:17 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.UI;
|
2020-05-25 10:21:53 +00:00
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2019-08-29 03:43:43 +00:00
|
|
|
using osu.Game.Screens.Edit;
|
2018-11-06 09:14:46 +00:00
|
|
|
using osu.Game.Screens.Edit.Components.RadioButtons;
|
2019-08-29 07:06:40 +00:00
|
|
|
using osu.Game.Screens.Edit.Compose;
|
2018-11-06 09:28:22 +00:00
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
2019-10-18 04:18:57 +00:00
|
|
|
using osuTK;
|
2020-08-25 11:57:31 +00:00
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
2019-08-29 09:02:50 +00:00
|
|
|
[Cached(Type = typeof(IPlacementHandler))]
|
|
|
|
public abstract class HitObjectComposer<TObject> : HitObjectComposer, IPlacementHandler
|
|
|
|
where TObject : HitObject
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2018-07-17 07:53:32 +00:00
|
|
|
protected IRulesetConfigManager Config { get; private set; }
|
2019-12-05 11:12:25 +00:00
|
|
|
|
2019-08-29 09:02:50 +00:00
|
|
|
protected readonly Ruleset Ruleset;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-10-16 11:20:07 +00:00
|
|
|
[Resolved]
|
2020-05-22 07:37:28 +00:00
|
|
|
protected EditorClock EditorClock { get; private set; }
|
2019-10-16 11:20:07 +00:00
|
|
|
|
2019-12-27 10:46:33 +00:00
|
|
|
[Resolved]
|
|
|
|
protected EditorBeatmap EditorBeatmap { get; private set; }
|
|
|
|
|
2019-10-25 03:34:49 +00:00
|
|
|
[Resolved]
|
2020-05-20 09:40:55 +00:00
|
|
|
protected IBeatSnapProvider BeatSnapProvider { get; private set; }
|
2019-10-25 03:34:49 +00:00
|
|
|
|
2020-02-07 15:12:23 +00:00
|
|
|
protected ComposeBlueprintContainer BlueprintContainer { get; private set; }
|
2020-02-07 10:08:49 +00:00
|
|
|
|
2019-08-29 09:20:43 +00:00
|
|
|
private DrawableEditRulesetWrapper<TObject> drawableRulesetWrapper;
|
2020-05-21 08:13:22 +00:00
|
|
|
|
|
|
|
protected readonly Container LayerBelowRuleset = new Container { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
2018-11-14 09:34:13 +00:00
|
|
|
private InputManager inputManager;
|
|
|
|
|
2020-01-28 06:07:37 +00:00
|
|
|
private RadioButtonCollection toolboxCollection;
|
|
|
|
|
2020-09-24 07:09:06 +00:00
|
|
|
private ToolboxGroup togglesCollection;
|
|
|
|
|
2019-08-29 09:02:50 +00:00
|
|
|
protected HitObjectComposer(Ruleset ruleset)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2018-10-17 09:01:38 +00:00
|
|
|
Ruleset = ruleset;
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-05-22 07:37:28 +00:00
|
|
|
private void load()
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2019-12-27 10:46:33 +00:00
|
|
|
Config = Dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
try
|
|
|
|
{
|
2019-12-27 10:46:33 +00:00
|
|
|
drawableRulesetWrapper = new DrawableEditRulesetWrapper<TObject>(CreateDrawableRuleset(Ruleset, EditorBeatmap.PlayableBeatmap))
|
2019-08-29 09:02:50 +00:00
|
|
|
{
|
2020-05-22 07:37:28 +00:00
|
|
|
Clock = EditorClock,
|
2019-10-18 09:21:53 +00:00
|
|
|
ProcessCustomClock = false
|
2019-08-29 09:02:50 +00:00
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2020-09-23 07:30:20 +00:00
|
|
|
Logger.Error(e, "Could not load beatmap successfully!");
|
2018-04-13 09:19:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-11 11:23:34 +00:00
|
|
|
const float toolbar_width = 200;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-09-11 11:23:34 +00:00
|
|
|
new Container
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-09-11 11:23:34 +00:00
|
|
|
Name = "Content",
|
|
|
|
Padding = new MarginPadding { Left = toolbar_width },
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-09-11 11:23:34 +00:00
|
|
|
// layers below playfield
|
|
|
|
drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer().WithChildren(new Drawable[]
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-09-11 11:23:34 +00:00
|
|
|
LayerBelowRuleset,
|
|
|
|
new EditorPlayfieldBorder { RelativeSizeAxes = Axes.Both }
|
|
|
|
}),
|
|
|
|
drawableRulesetWrapper,
|
|
|
|
// layers above playfield
|
|
|
|
drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer()
|
|
|
|
.WithChild(BlueprintContainer = CreateBlueprintContainer(HitObjects))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Name = "Sidebar",
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Width = toolbar_width,
|
|
|
|
Padding = new MarginPadding { Right = 10 },
|
|
|
|
Spacing = new Vector2(10),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new ToolboxGroup("toolbox") { Child = toolboxCollection = new RadioButtonCollection { RelativeSizeAxes = Axes.X } },
|
2020-09-24 07:09:06 +00:00
|
|
|
togglesCollection = new ToolboxGroup("toggles")
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-09-11 11:23:34 +00:00
|
|
|
ChildrenEnumerable = Toggles.Select(b => new SettingsCheckbox
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-09-11 11:23:34 +00:00
|
|
|
Bindable = b,
|
|
|
|
LabelText = b?.Description ?? "unknown"
|
|
|
|
})
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
2020-09-11 11:23:34 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-28 06:00:45 +00:00
|
|
|
toolboxCollection.Items = CompositionTools
|
|
|
|
.Prepend(new SelectTool())
|
2020-09-09 09:35:25 +00:00
|
|
|
.Select(t => new RadioButton(t.Name, () => toolSelected(t), t.CreateIcon))
|
2020-01-28 06:00:45 +00:00
|
|
|
.ToList();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-01-28 06:07:37 +00:00
|
|
|
setSelectTool();
|
2019-10-16 11:20:07 +00:00
|
|
|
|
2020-05-21 08:13:22 +00:00
|
|
|
EditorBeatmap.SelectedHitObjects.CollectionChanged += selectionChanged;
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 02:46:08 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
inputManager = GetContainingInputManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Playfield Playfield => drawableRulesetWrapper.Playfield;
|
|
|
|
|
|
|
|
public override IEnumerable<DrawableHitObject> HitObjects => drawableRulesetWrapper.Playfield.AllHitObjects;
|
|
|
|
|
|
|
|
public override bool CursorInPlacementArea => drawableRulesetWrapper.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines all available composition tools, listed on the left side of the editor screen as button controls.
|
|
|
|
/// This should usually define one tool for each <see cref="HitObject"/> type used in the target ruleset.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// A "select" tool is automatically added as the first tool.
|
|
|
|
/// </remarks>
|
|
|
|
protected abstract IReadOnlyList<HitObjectCompositionTool> CompositionTools { get; }
|
|
|
|
|
2020-09-09 10:14:28 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A collection of toggles which will be displayed to the user.
|
|
|
|
/// The display name will be decided by <see cref="Bindable{T}.Description"/>.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual IEnumerable<BindableBool> Toggles => Enumerable.Empty<BindableBool>();
|
|
|
|
|
2020-05-29 02:46:08 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Construct a relevant blueprint container. This will manage hitobject selection/placement input handling and display logic.
|
|
|
|
/// </summary>
|
2020-05-29 03:20:50 +00:00
|
|
|
/// <param name="hitObjects">A live collection of all <see cref="DrawableHitObject"/>s in the editor beatmap.</param>
|
|
|
|
protected virtual ComposeBlueprintContainer CreateBlueprintContainer(IEnumerable<DrawableHitObject> hitObjects)
|
|
|
|
=> new ComposeBlueprintContainer(hitObjects);
|
2020-05-29 02:46:08 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Construct a drawable ruleset for the provided ruleset.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// Can be overridden to add editor-specific logical changes to a <see cref="Ruleset"/>'s standard <see cref="DrawableRuleset{TObject}"/>.
|
|
|
|
/// For example, hit animations or judgement logic may be changed to give a better editor user experience.
|
|
|
|
/// </remarks>
|
|
|
|
/// <param name="ruleset">The ruleset used to construct its drawable counterpart.</param>
|
|
|
|
/// <param name="beatmap">The loaded beatmap.</param>
|
|
|
|
/// <param name="mods">The mods to be applied.</param>
|
2020-05-31 13:33:10 +00:00
|
|
|
/// <returns>An editor-relevant <see cref="DrawableRuleset{TObject}"/>.</returns>
|
2020-05-29 02:46:08 +00:00
|
|
|
protected virtual DrawableRuleset<TObject> CreateDrawableRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods = null)
|
|
|
|
=> (DrawableRuleset<TObject>)ruleset.CreateDrawableRulesetWith(beatmap, mods);
|
|
|
|
|
|
|
|
#region Tool selection logic
|
|
|
|
|
2020-01-28 06:08:02 +00:00
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
{
|
2020-09-25 07:56:39 +00:00
|
|
|
if (e.ControlPressed || e.AltPressed || e.SuperPressed)
|
|
|
|
return false;
|
|
|
|
|
2020-09-24 07:09:06 +00:00
|
|
|
if (checkLeftToggleFromKey(e.Key, out var leftIndex))
|
2020-01-28 06:08:02 +00:00
|
|
|
{
|
2020-09-24 07:09:06 +00:00
|
|
|
var item = toolboxCollection.Items.ElementAtOrDefault(leftIndex);
|
2020-01-28 06:08:02 +00:00
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
{
|
|
|
|
item.Select();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-24 07:09:06 +00:00
|
|
|
if (checkRightToggleFromKey(e.Key, out var rightIndex))
|
|
|
|
{
|
2020-09-25 04:25:42 +00:00
|
|
|
var item = togglesCollection.ElementAtOrDefault(rightIndex);
|
2020-09-24 07:09:06 +00:00
|
|
|
|
|
|
|
if (item is SettingsCheckbox checkbox)
|
|
|
|
{
|
|
|
|
checkbox.Bindable.Value = !checkbox.Bindable.Value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 06:08:02 +00:00
|
|
|
return base.OnKeyDown(e);
|
|
|
|
}
|
|
|
|
|
2020-09-24 07:09:06 +00:00
|
|
|
private bool checkLeftToggleFromKey(Key key, out int index)
|
|
|
|
{
|
|
|
|
if (key < Key.Number1 || key > Key.Number9)
|
|
|
|
{
|
|
|
|
index = -1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = key - Key.Number1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool checkRightToggleFromKey(Key key, out int index)
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case Key.Q:
|
|
|
|
index = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.W:
|
|
|
|
index = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.E:
|
|
|
|
index = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.R:
|
|
|
|
index = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.T:
|
|
|
|
index = 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.Y:
|
|
|
|
index = 5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.U:
|
|
|
|
index = 6;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.I:
|
|
|
|
index = 7;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.O:
|
|
|
|
index = 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Key.P:
|
|
|
|
index = 9;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
index = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index >= 0;
|
|
|
|
}
|
|
|
|
|
2020-05-21 08:13:22 +00:00
|
|
|
private void selectionChanged(object sender, NotifyCollectionChangedEventArgs changedArgs)
|
2019-10-16 11:20:07 +00:00
|
|
|
{
|
2020-05-21 08:13:22 +00:00
|
|
|
if (EditorBeatmap.SelectedHitObjects.Any())
|
2020-01-28 06:07:37 +00:00
|
|
|
{
|
|
|
|
// ensure in selection mode if a selection is made.
|
|
|
|
setSelectTool();
|
|
|
|
}
|
2019-10-16 11:20:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-28 06:07:37 +00:00
|
|
|
private void setSelectTool() => toolboxCollection.Items.First().Select();
|
|
|
|
|
2020-01-28 06:00:45 +00:00
|
|
|
private void toolSelected(HitObjectCompositionTool tool)
|
2019-10-16 11:20:07 +00:00
|
|
|
{
|
2020-02-07 10:08:49 +00:00
|
|
|
BlueprintContainer.CurrentTool = tool;
|
2019-10-16 11:20:07 +00:00
|
|
|
|
2020-05-21 08:13:22 +00:00
|
|
|
if (!(tool is SelectTool))
|
2020-01-28 06:07:37 +00:00
|
|
|
EditorBeatmap.SelectedHitObjects.Clear();
|
2019-10-16 11:20:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 02:46:08 +00:00
|
|
|
#endregion
|
2019-08-29 09:02:50 +00:00
|
|
|
|
2020-05-29 02:46:08 +00:00
|
|
|
#region IPlacementHandler
|
2019-08-29 07:06:40 +00:00
|
|
|
|
|
|
|
public void BeginPlacement(HitObject hitObject)
|
|
|
|
{
|
2020-02-07 09:03:14 +00:00
|
|
|
EditorBeatmap.PlacementObject.Value = hitObject;
|
2019-08-29 07:06:40 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 09:02:48 +00:00
|
|
|
public void EndPlacement(HitObject hitObject, bool commit)
|
2019-10-18 10:04:08 +00:00
|
|
|
{
|
2020-02-07 09:03:14 +00:00
|
|
|
EditorBeatmap.PlacementObject.Value = null;
|
|
|
|
|
2020-02-07 09:02:48 +00:00
|
|
|
if (commit)
|
|
|
|
{
|
|
|
|
EditorBeatmap.Add(hitObject);
|
2019-11-07 05:08:02 +00:00
|
|
|
|
2020-05-22 07:37:28 +00:00
|
|
|
if (EditorClock.CurrentTime < hitObject.StartTime)
|
2020-05-22 07:40:52 +00:00
|
|
|
EditorClock.SeekTo(hitObject.StartTime);
|
2020-02-07 09:02:48 +00:00
|
|
|
}
|
2019-10-18 10:04:08 +00:00
|
|
|
}
|
2019-08-29 07:06:40 +00:00
|
|
|
|
2019-10-16 11:10:03 +00:00
|
|
|
public void Delete(HitObject hitObject) => EditorBeatmap.Remove(hitObject);
|
2019-08-29 07:06:40 +00:00
|
|
|
|
2020-05-29 02:46:08 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IPositionSnapProvider
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Retrieve the relevant <see cref="Playfield"/> at a specified screen-space position.
|
|
|
|
/// In cases where a ruleset doesn't require custom logic (due to nested playfields, for example)
|
|
|
|
/// this will return the ruleset's main playfield.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="screenSpacePosition">The screen-space position to query.</param>
|
|
|
|
/// <returns>The most relevant <see cref="Playfield"/>.</returns>
|
2020-05-25 10:21:53 +00:00
|
|
|
protected virtual Playfield PlayfieldAtScreenSpacePosition(Vector2 screenSpacePosition) => drawableRulesetWrapper.Playfield;
|
|
|
|
|
|
|
|
public override SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition)
|
|
|
|
{
|
|
|
|
var playfield = PlayfieldAtScreenSpacePosition(screenSpacePosition);
|
|
|
|
double? targetTime = null;
|
|
|
|
|
|
|
|
if (playfield is ScrollingPlayfield scrollingPlayfield)
|
|
|
|
{
|
|
|
|
targetTime = scrollingPlayfield.TimeAtScreenSpacePosition(screenSpacePosition);
|
|
|
|
|
|
|
|
// apply beat snapping
|
|
|
|
targetTime = BeatSnapProvider.SnapTime(targetTime.Value);
|
|
|
|
|
|
|
|
// convert back to screen space
|
|
|
|
screenSpacePosition = scrollingPlayfield.ScreenSpacePositionAtTime(targetTime.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new SnapResult(screenSpacePosition, targetTime, playfield);
|
|
|
|
}
|
2019-10-25 03:34:49 +00:00
|
|
|
|
|
|
|
public override float GetBeatSnapDistanceAt(double referenceTime)
|
|
|
|
{
|
|
|
|
DifficultyControlPoint difficultyPoint = EditorBeatmap.ControlPointInfo.DifficultyPointAt(referenceTime);
|
2020-05-20 09:40:55 +00:00
|
|
|
return (float)(100 * EditorBeatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier / BeatSnapProvider.BeatDivisor);
|
2019-10-25 03:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override float DurationToDistance(double referenceTime, double duration)
|
|
|
|
{
|
2020-05-20 09:40:55 +00:00
|
|
|
double beatLength = BeatSnapProvider.GetBeatLengthAtTime(referenceTime);
|
2019-10-25 03:34:49 +00:00
|
|
|
return (float)(duration / beatLength * GetBeatSnapDistanceAt(referenceTime));
|
|
|
|
}
|
2019-10-16 11:34:02 +00:00
|
|
|
|
2019-10-25 03:34:49 +00:00
|
|
|
public override double DistanceToDuration(double referenceTime, float distance)
|
|
|
|
{
|
2020-05-20 09:40:55 +00:00
|
|
|
double beatLength = BeatSnapProvider.GetBeatLengthAtTime(referenceTime);
|
2019-10-25 03:34:49 +00:00
|
|
|
return distance / GetBeatSnapDistanceAt(referenceTime) * beatLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override double GetSnappedDurationFromDistance(double referenceTime, float distance)
|
2020-05-20 09:40:55 +00:00
|
|
|
=> BeatSnapProvider.SnapTime(referenceTime + DistanceToDuration(referenceTime, distance), referenceTime) - referenceTime;
|
2019-10-25 03:34:49 +00:00
|
|
|
|
|
|
|
public override float GetSnappedDistanceFromDistance(double referenceTime, float distance)
|
2020-02-07 07:43:50 +00:00
|
|
|
{
|
2020-08-25 09:56:15 +00:00
|
|
|
double actualDuration = referenceTime + DistanceToDuration(referenceTime, distance);
|
|
|
|
|
|
|
|
double snappedEndTime = BeatSnapProvider.SnapTime(actualDuration, referenceTime);
|
|
|
|
|
2020-08-25 11:57:31 +00:00
|
|
|
double beatLength = BeatSnapProvider.GetBeatLengthAtTime(referenceTime);
|
|
|
|
|
2020-08-25 09:56:15 +00:00
|
|
|
// we don't want to exceed the actual duration and snap to a point in the future.
|
2020-08-25 11:57:31 +00:00
|
|
|
// as we are snapping to beat length via SnapTime (which will round-to-nearest), check for snapping in the forward direction and reverse it.
|
|
|
|
if (snappedEndTime > actualDuration + 1)
|
|
|
|
snappedEndTime -= beatLength;
|
2020-02-07 07:43:50 +00:00
|
|
|
|
|
|
|
return DurationToDistance(referenceTime, snappedEndTime - referenceTime);
|
|
|
|
}
|
2020-05-29 02:46:08 +00:00
|
|
|
|
|
|
|
#endregion
|
2018-10-17 09:01:38 +00:00
|
|
|
}
|
2019-08-29 09:02:50 +00:00
|
|
|
|
2020-05-29 02:46:08 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A non-generic definition of a HitObject composer class.
|
|
|
|
/// Generally used to access certain methods without requiring a generic type for <see cref="HitObjectComposer{T}" />.
|
|
|
|
/// </summary>
|
2019-08-29 09:02:50 +00:00
|
|
|
[Cached(typeof(HitObjectComposer))]
|
2020-05-20 08:48:43 +00:00
|
|
|
[Cached(typeof(IPositionSnapProvider))]
|
|
|
|
public abstract class HitObjectComposer : CompositeDrawable, IPositionSnapProvider
|
2019-08-29 09:02:50 +00:00
|
|
|
{
|
2020-05-27 14:15:16 +00:00
|
|
|
protected HitObjectComposer()
|
2019-08-29 09:02:50 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
2020-05-29 02:46:08 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The target ruleset's playfield.
|
|
|
|
/// </summary>
|
2020-05-27 14:15:16 +00:00
|
|
|
public abstract Playfield Playfield { get; }
|
|
|
|
|
2019-08-29 09:02:50 +00:00
|
|
|
/// <summary>
|
2020-05-29 02:46:08 +00:00
|
|
|
/// All <see cref="DrawableHitObject"/>s in currently loaded beatmap.
|
2019-08-29 09:02:50 +00:00
|
|
|
/// </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-29 02:46:08 +00:00
|
|
|
#region IPositionSnapProvider
|
|
|
|
|
2020-05-20 09:19:21 +00:00
|
|
|
public abstract SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition);
|
2019-10-31 09:15:19 +00:00
|
|
|
|
2019-10-25 03:34:49 +00:00
|
|
|
public abstract float GetBeatSnapDistanceAt(double referenceTime);
|
2019-10-31 09:15:19 +00:00
|
|
|
|
2019-10-25 03:34:49 +00:00
|
|
|
public abstract float DurationToDistance(double referenceTime, double duration);
|
2019-10-31 09:15:19 +00:00
|
|
|
|
2019-10-25 03:34:49 +00:00
|
|
|
public abstract double DistanceToDuration(double referenceTime, float distance);
|
2019-10-31 09:15:19 +00:00
|
|
|
|
2019-10-25 03:34:49 +00:00
|
|
|
public abstract double GetSnappedDurationFromDistance(double referenceTime, float distance);
|
2019-10-31 09:15:19 +00:00
|
|
|
|
2019-10-25 03:34:49 +00:00
|
|
|
public abstract float GetSnappedDistanceFromDistance(double referenceTime, float distance);
|
2020-05-29 02:46:08 +00:00
|
|
|
|
|
|
|
#endregion
|
2019-08-29 09:02:50 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|