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
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2017-11-30 15:58:14 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2020-05-21 16:13:22 +08:00
|
|
|
using System.Collections.Specialized;
|
2017-11-30 15:58:14 +08:00
|
|
|
using System.Linq;
|
2024-06-17 18:11:19 +08:00
|
|
|
using JetBrains.Annotations;
|
2017-11-29 16:46:12 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-07-19 16:08:40 +08:00
|
|
|
using osu.Framework.Bindables;
|
2022-05-12 14:23:41 +08:00
|
|
|
using osu.Framework.Extensions.EnumExtensions;
|
2017-11-29 16:46:12 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-10-13 15:33:01 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
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;
|
2017-11-30 15:58:14 +08:00
|
|
|
using osu.Framework.Logging;
|
2017-11-30 18:19:34 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2023-02-19 02:43:45 +08:00
|
|
|
using osu.Game.Configuration;
|
2022-10-13 15:33:01 +08:00
|
|
|
using osu.Game.Overlays;
|
2018-07-17 15:53:32 +08:00
|
|
|
using osu.Game.Rulesets.Configuration;
|
2017-11-30 15:58:14 +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-03-14 14:18:21 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2017-11-30 15:58:14 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
2020-05-25 18:21:53 +08:00
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
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;
|
2020-09-25 15:33:22 +08:00
|
|
|
using osu.Game.Screens.Edit.Components.TernaryButtons;
|
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-08-25 19:57:31 +08:00
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-11-29 15:22:11 +08:00
|
|
|
namespace osu.Game.Rulesets.Edit
|
|
|
|
{
|
2020-09-25 13:08:47 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Top level container for editor compose mode.
|
|
|
|
/// Responsible for providing snapping and generally gluing components together.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TObject">The base type of supported objects.</typeparam>
|
2019-08-29 17:02:50 +08:00
|
|
|
public abstract partial class HitObjectComposer<TObject> : HitObjectComposer, IPlacementHandler
|
|
|
|
where TObject : HitObject
|
2017-11-29 15:22:11 +08:00
|
|
|
{
|
2023-07-27 01:22:46 +08:00
|
|
|
/// <summary>
|
2023-07-29 04:09:28 +08:00
|
|
|
/// Whether the playfield should be centered horizontally. Should be disabled for playfields which span the full horizontal width.
|
2023-07-27 01:22:46 +08:00
|
|
|
/// </summary>
|
2023-07-29 04:09:28 +08:00
|
|
|
protected virtual bool ApplyHorizontalCentering => true;
|
2023-07-27 01:22:46 +08:00
|
|
|
|
2018-07-17 15:53:32 +08:00
|
|
|
protected IRulesetConfigManager Config { get; private set; }
|
2019-12-05 19:12:25 +08:00
|
|
|
|
2021-06-17 09:07:52 +08:00
|
|
|
// Provides `Playfield`
|
2022-11-28 04:43:33 +08:00
|
|
|
private DependencyContainer dependencies;
|
2021-06-17 09:07:52 +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
|
|
|
|
2023-04-04 18:14:30 +08:00
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; }
|
|
|
|
|
2020-02-07 23:12:23 +08:00
|
|
|
protected ComposeBlueprintContainer BlueprintContainer { get; private set; }
|
2020-02-07 18:08:49 +08:00
|
|
|
|
2023-04-04 17:53:25 +08:00
|
|
|
protected ExpandingToolboxContainer LeftToolbox { get; private set; }
|
|
|
|
|
|
|
|
protected ExpandingToolboxContainer RightToolbox { get; private set; }
|
|
|
|
|
2021-04-26 14:37:42 +08:00
|
|
|
private DrawableEditorRulesetWrapper<TObject> drawableRulesetWrapper;
|
2020-05-21 16:13:22 +08:00
|
|
|
|
|
|
|
protected readonly Container LayerBelowRuleset = new Container { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
2023-10-17 16:09:42 +08:00
|
|
|
protected InputManager InputManager { get; private set; }
|
2018-11-14 17:34:13 +08:00
|
|
|
|
2024-06-17 18:11:19 +08:00
|
|
|
private Box leftToolboxBackground;
|
|
|
|
private Box rightToolboxBackground;
|
2020-01-28 14:07:37 +08:00
|
|
|
|
2024-06-17 18:11:19 +08:00
|
|
|
private EditorRadioButtonCollection toolboxCollection;
|
2020-09-25 15:44:37 +08:00
|
|
|
private FillFlowContainer togglesCollection;
|
2022-10-19 20:35:08 +08:00
|
|
|
private FillFlowContainer sampleBankTogglesCollection;
|
|
|
|
|
2021-07-19 16:08:40 +08:00
|
|
|
private IBindable<bool> hasTiming;
|
2023-02-19 22:06:40 +08:00
|
|
|
private Bindable<bool> autoSeekOnPlacement;
|
2024-06-17 18:11:19 +08:00
|
|
|
private readonly Bindable<bool> composerFocusMode = new Bindable<bool>();
|
2021-07-19 16:08:40 +08:00
|
|
|
|
2023-09-01 18:49:57 +08:00
|
|
|
protected DrawableRuleset<TObject> DrawableRuleset { get; private set; }
|
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
protected HitObjectComposer(Ruleset ruleset)
|
2022-11-30 19:17:58 +08:00
|
|
|
: base(ruleset)
|
2017-11-29 16:46:12 +08:00
|
|
|
{
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-06-17 09:07:52 +08:00
|
|
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
2022-11-28 04:43:33 +08:00
|
|
|
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
2021-06-17 09:07:52 +08:00
|
|
|
|
2024-06-17 18:11:19 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load(OsuConfigManager config, [CanBeNull] Editor editor)
|
2017-11-29 16:46:12 +08:00
|
|
|
{
|
2023-02-19 22:06:40 +08:00
|
|
|
autoSeekOnPlacement = config.GetBindable<bool>(OsuSetting.EditorAutoSeekOnPlacement);
|
2023-02-19 02:43:45 +08:00
|
|
|
|
2024-06-17 18:11:19 +08:00
|
|
|
if (editor != null)
|
|
|
|
composerFocusMode.BindTo(editor.ComposerFocusMode);
|
|
|
|
|
2021-12-24 02:02:10 +08:00
|
|
|
Config = Dependencies.Get<IRulesetConfigCache>().GetConfigFor(Ruleset);
|
2019-12-27 18:46:33 +08:00
|
|
|
|
2017-11-29 16:46:12 +08:00
|
|
|
try
|
|
|
|
{
|
2023-09-01 18:49:57 +08:00
|
|
|
DrawableRuleset = CreateDrawableRuleset(Ruleset, EditorBeatmap.PlayableBeatmap, new[] { Ruleset.GetAutoplayMod() });
|
|
|
|
drawableRulesetWrapper = new DrawableEditorRulesetWrapper<TObject>(DrawableRuleset)
|
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
|
|
|
};
|
2017-11-29 16:46:12 +08:00
|
|
|
}
|
2017-11-30 15:58:14 +08:00
|
|
|
catch (Exception e)
|
|
|
|
{
|
2020-09-23 15:30:20 +08:00
|
|
|
Logger.Error(e, "Could not load beatmap successfully!");
|
2017-11-30 15:58:14 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2023-10-17 15:42:22 +08:00
|
|
|
if (DrawableRuleset is IDrawableScrollingRuleset scrollingRuleset)
|
|
|
|
dependencies.CacheAs(scrollingRuleset.ScrollingInfo);
|
|
|
|
|
2021-06-17 09:07:52 +08:00
|
|
|
dependencies.CacheAs(Playfield);
|
|
|
|
|
2023-10-17 16:26:02 +08:00
|
|
|
InternalChildren = new[]
|
2017-11-30 15:58:14 +08:00
|
|
|
{
|
2024-06-17 18:11:19 +08:00
|
|
|
PlayfieldContentContainer = new ContentContainer
|
2017-11-30 15:58:14 +08:00
|
|
|
{
|
2023-07-21 14:20:19 +08:00
|
|
|
Name = "Playfield content",
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2020-09-11 19:23:34 +08:00
|
|
|
Children = new Drawable[]
|
2017-11-30 15:58:14 +08:00
|
|
|
{
|
2020-09-11 19:23:34 +08:00
|
|
|
// layers below playfield
|
2020-10-20 03:20:13 +08:00
|
|
|
drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer().WithChild(LayerBelowRuleset),
|
2020-09-11 19:23:34 +08:00
|
|
|
drawableRulesetWrapper,
|
|
|
|
// layers above playfield
|
|
|
|
drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer()
|
2020-11-12 18:52:02 +08:00
|
|
|
.WithChild(BlueprintContainer = CreateBlueprintContainer())
|
2020-09-11 19:23:34 +08:00
|
|
|
}
|
|
|
|
},
|
2022-10-13 15:33:01 +08:00
|
|
|
new Container
|
2020-09-11 19:23:34 +08:00
|
|
|
{
|
2022-10-13 15:33:01 +08:00
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
2020-09-11 19:23:34 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2024-06-17 18:11:19 +08:00
|
|
|
leftToolboxBackground = new Box
|
2017-11-30 15:58:14 +08:00
|
|
|
{
|
2022-10-13 15:33:01 +08:00
|
|
|
Colour = colourProvider.Background5,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-11-30 15:58:14 +08:00
|
|
|
},
|
2023-05-02 14:36:01 +08:00
|
|
|
LeftToolbox = new ExpandingToolboxContainer(TOOLBOX_CONTRACTED_SIZE_LEFT, 200)
|
2017-11-30 15:58:14 +08:00
|
|
|
{
|
2022-10-13 15:33:01 +08:00
|
|
|
Children = new Drawable[]
|
2017-11-30 16:38:55 +08:00
|
|
|
{
|
2022-10-13 15:33:01 +08:00
|
|
|
new EditorToolboxGroup("toolbox (1-9)")
|
|
|
|
{
|
|
|
|
Child = toolboxCollection = new EditorRadioButtonCollection { RelativeSizeAxes = Axes.X }
|
|
|
|
},
|
|
|
|
new EditorToolboxGroup("toggles (Q~P)")
|
|
|
|
{
|
|
|
|
Child = togglesCollection = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(0, 5),
|
|
|
|
},
|
2022-10-19 20:35:08 +08:00
|
|
|
},
|
|
|
|
new EditorToolboxGroup("bank (Shift-Q~R)")
|
|
|
|
{
|
|
|
|
Child = sampleBankTogglesCollection = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(0, 5),
|
|
|
|
},
|
2022-10-13 15:33:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-09-11 19:23:34 +08:00
|
|
|
}
|
2017-11-30 15:58:14 +08:00
|
|
|
},
|
2023-04-04 17:53:25 +08:00
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2024-06-17 18:11:19 +08:00
|
|
|
rightToolboxBackground = new Box
|
2023-04-04 17:53:25 +08:00
|
|
|
{
|
|
|
|
Colour = colourProvider.Background5,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2023-05-02 14:36:01 +08:00
|
|
|
RightToolbox = new ExpandingToolboxContainer(TOOLBOX_CONTRACTED_SIZE_RIGHT, 250)
|
2023-04-04 18:03:45 +08:00
|
|
|
{
|
|
|
|
Child = new EditorToolboxGroup("inspector")
|
|
|
|
{
|
2023-04-04 18:17:14 +08:00
|
|
|
Child = new HitObjectInspector()
|
2023-04-04 18:03:45 +08:00
|
|
|
},
|
|
|
|
}
|
2023-04-04 17:53:25 +08:00
|
|
|
}
|
2023-10-17 16:09:42 +08:00
|
|
|
},
|
2017-11-30 15:58:14 +08:00
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-01-28 14:00:45 +08:00
|
|
|
toolboxCollection.Items = CompositionTools
|
|
|
|
.Prepend(new SelectTool())
|
2020-09-09 17:35:25 +08:00
|
|
|
.Select(t => new RadioButton(t.Name, () => toolSelected(t), t.CreateIcon))
|
2020-01-28 14:00:45 +08:00
|
|
|
.ToList();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2024-01-25 15:24:45 +08:00
|
|
|
foreach (var item in toolboxCollection.Items)
|
|
|
|
{
|
2024-03-30 18:03:40 +08:00
|
|
|
item.Selected.DisabledChanged += isDisabled =>
|
2024-03-30 17:04:22 +08:00
|
|
|
{
|
2024-03-30 18:03:40 +08:00
|
|
|
item.TooltipText = isDisabled ? "Add at least one timing point first!" : string.Empty;
|
2024-03-30 17:04:22 +08:00
|
|
|
};
|
2024-01-25 15:24:45 +08:00
|
|
|
}
|
|
|
|
|
2020-09-25 16:45:19 +08:00
|
|
|
TernaryStates = CreateTernaryButtons().ToArray();
|
|
|
|
togglesCollection.AddRange(TernaryStates.Select(b => new DrawableTernaryButton(b)));
|
2020-09-25 16:40:43 +08:00
|
|
|
|
2022-10-19 20:35:08 +08:00
|
|
|
sampleBankTogglesCollection.AddRange(BlueprintContainer.SampleBankTernaryStates.Select(b => new DrawableTernaryButton(b)));
|
|
|
|
|
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;
|
2017-11-29 16:46:12 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2022-10-18 13:31:54 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Houses all content relevant to the playfield.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// Generally implementations should not be adding to this directly.
|
|
|
|
/// Use <see cref="LayerBelowRuleset"/> or <see cref="BlueprintContainer"/> instead.
|
|
|
|
/// </remarks>
|
|
|
|
protected Container PlayfieldContentContainer { get; private set; }
|
|
|
|
|
2020-05-29 10:46:08 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2023-10-17 16:09:42 +08:00
|
|
|
InputManager = GetContainingInputManager();
|
2021-07-19 16:08:40 +08:00
|
|
|
|
|
|
|
hasTiming = EditorBeatmap.HasTiming.GetBoundCopy();
|
|
|
|
hasTiming.BindValueChanged(timing =>
|
|
|
|
{
|
|
|
|
// it's important this is performed before the similar code in EditorRadioButton disables the button.
|
|
|
|
if (!timing.NewValue)
|
|
|
|
setSelectTool();
|
|
|
|
});
|
2024-01-25 15:24:35 +08:00
|
|
|
|
|
|
|
EditorBeatmap.HasTiming.BindValueChanged(hasTiming =>
|
|
|
|
{
|
|
|
|
foreach (var item in toolboxCollection.Items)
|
|
|
|
{
|
|
|
|
item.Selected.Disabled = !hasTiming.NewValue;
|
|
|
|
}
|
|
|
|
}, true);
|
2024-06-17 18:11:19 +08:00
|
|
|
|
|
|
|
composerFocusMode.BindValueChanged(_ =>
|
|
|
|
{
|
|
|
|
float targetAlpha = composerFocusMode.Value ? 0.5f : 1;
|
|
|
|
leftToolboxBackground.FadeTo(targetAlpha, 400, Easing.OutQuint);
|
|
|
|
rightToolboxBackground.FadeTo(targetAlpha, 400, Easing.OutQuint);
|
|
|
|
}, true);
|
2020-05-29 10:46:08 +08:00
|
|
|
}
|
|
|
|
|
2023-07-21 14:20:19 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2023-07-29 04:09:28 +08:00
|
|
|
if (ApplyHorizontalCentering)
|
2023-07-28 15:40:14 +08:00
|
|
|
{
|
|
|
|
PlayfieldContentContainer.Anchor = Anchor.Centre;
|
|
|
|
PlayfieldContentContainer.Origin = Anchor.Centre;
|
|
|
|
|
2023-07-29 04:10:10 +08:00
|
|
|
// Ensure that the playfield is always centered but also doesn't get cut off by toolboxes.
|
2023-07-28 15:40:14 +08:00
|
|
|
PlayfieldContentContainer.Width = Math.Max(1024, DrawWidth) - TOOLBOX_CONTRACTED_SIZE_RIGHT * 2;
|
|
|
|
PlayfieldContentContainer.X = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlayfieldContentContainer.Anchor = Anchor.CentreLeft;
|
|
|
|
PlayfieldContentContainer.Origin = Anchor.CentreLeft;
|
|
|
|
|
|
|
|
PlayfieldContentContainer.Width = Math.Max(1024, DrawWidth) - (TOOLBOX_CONTRACTED_SIZE_LEFT + TOOLBOX_CONTRACTED_SIZE_RIGHT);
|
|
|
|
PlayfieldContentContainer.X = TOOLBOX_CONTRACTED_SIZE_LEFT;
|
|
|
|
}
|
2023-07-21 14:20:19 +08:00
|
|
|
}
|
|
|
|
|
2020-05-29 10:46:08 +08:00
|
|
|
public override Playfield Playfield => drawableRulesetWrapper.Playfield;
|
|
|
|
|
|
|
|
public override IEnumerable<DrawableHitObject> HitObjects => drawableRulesetWrapper.Playfield.AllHitObjects;
|
|
|
|
|
2023-10-17 16:09:42 +08:00
|
|
|
public override bool CursorInPlacementArea => drawableRulesetWrapper.Playfield.ReceivePositionalInputAt(InputManager.CurrentState.Mouse.Position);
|
2020-05-29 10:46:08 +08:00
|
|
|
|
|
|
|
/// <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 18:14:28 +08:00
|
|
|
/// <summary>
|
2020-09-25 16:45:19 +08:00
|
|
|
/// A collection of states which will be displayed to the user in the toolbox.
|
2020-09-09 18:14:28 +08:00
|
|
|
/// </summary>
|
2020-09-25 16:45:19 +08:00
|
|
|
public TernaryButton[] TernaryStates { get; private set; }
|
2020-09-25 16:40:43 +08:00
|
|
|
|
2020-09-25 16:45:19 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Create all ternary states required to be displayed to the user.
|
|
|
|
/// </summary>
|
2022-10-19 20:35:08 +08:00
|
|
|
protected virtual IEnumerable<TernaryButton> CreateTernaryButtons() => BlueprintContainer.MainTernaryStates;
|
2020-09-09 18:14:28 +08:00
|
|
|
|
2020-05-29 10:46:08 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Construct a relevant blueprint container. This will manage hitobject selection/placement input handling and display logic.
|
|
|
|
/// </summary>
|
2022-11-30 19:17:58 +08:00
|
|
|
protected virtual ComposeBlueprintContainer CreateBlueprintContainer() => new ComposeBlueprintContainer(this);
|
2020-05-29 10:46:08 +08: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 21:33:10 +08:00
|
|
|
/// <returns>An editor-relevant <see cref="DrawableRuleset{TObject}"/>.</returns>
|
2023-09-20 14:27:50 +08:00
|
|
|
protected virtual DrawableRuleset<TObject> CreateDrawableRuleset(Ruleset ruleset, IBeatmap beatmap, IReadOnlyList<Mod> mods)
|
2020-05-29 10:46:08 +08:00
|
|
|
=> (DrawableRuleset<TObject>)ruleset.CreateDrawableRulesetWith(beatmap, mods);
|
|
|
|
|
|
|
|
#region Tool selection logic
|
|
|
|
|
2020-01-28 14:08:02 +08:00
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
{
|
2023-05-24 13:56:11 +08:00
|
|
|
if (e.ControlPressed || e.AltPressed || e.SuperPressed)
|
2020-09-25 15:56:39 +08:00
|
|
|
return false;
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
if (checkLeftToggleFromKey(e.Key, out int leftIndex))
|
2020-01-28 14:08:02 +08:00
|
|
|
{
|
2020-09-24 15:09:06 +08:00
|
|
|
var item = toolboxCollection.Items.ElementAtOrDefault(leftIndex);
|
2020-01-28 14:08:02 +08:00
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
{
|
2021-07-17 01:30:13 +08:00
|
|
|
if (!item.Selected.Disabled)
|
|
|
|
item.Select();
|
2020-01-28 14:08:02 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
if (checkRightToggleFromKey(e.Key, out int rightIndex))
|
2020-09-24 15:09:06 +08:00
|
|
|
{
|
2022-10-19 20:35:08 +08:00
|
|
|
var item = e.ShiftPressed
|
|
|
|
? sampleBankTogglesCollection.ElementAtOrDefault(rightIndex)
|
|
|
|
: togglesCollection.ElementAtOrDefault(rightIndex);
|
2020-09-24 15:09:06 +08:00
|
|
|
|
2020-09-25 15:33:22 +08:00
|
|
|
if (item is DrawableTernaryButton button)
|
2020-09-24 15:09:06 +08:00
|
|
|
{
|
2020-09-25 15:33:22 +08:00
|
|
|
button.Button.Toggle();
|
2020-09-24 15:09:06 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 14:08:02 +08:00
|
|
|
return base.OnKeyDown(e);
|
|
|
|
}
|
|
|
|
|
2020-09-24 15:09:06 +08: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 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
|
|
|
}
|
|
|
|
|
2020-05-29 10:46:08 +08:00
|
|
|
#endregion
|
2019-08-29 17:02:50 +08:00
|
|
|
|
2020-05-29 10:46:08 +08:00
|
|
|
#region IPlacementHandler
|
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
|
|
|
|
2023-02-19 22:06:40 +08:00
|
|
|
if (autoSeekOnPlacement.Value && EditorClock.CurrentTime < hitObject.StartTime)
|
2021-01-15 15:14:21 +08:00
|
|
|
EditorClock.SeekSmoothlyTo(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-29 10:46:08 +08: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 18:21:53 +08:00
|
|
|
protected virtual Playfield PlayfieldAtScreenSpacePosition(Vector2 screenSpacePosition) => drawableRulesetWrapper.Playfield;
|
|
|
|
|
2022-05-12 14:23:41 +08:00
|
|
|
public override SnapResult FindSnappedPositionAndTime(Vector2 screenSpacePosition, SnapType snapType = SnapType.All)
|
2020-05-25 18:21:53 +08:00
|
|
|
{
|
|
|
|
var playfield = PlayfieldAtScreenSpacePosition(screenSpacePosition);
|
|
|
|
double? targetTime = null;
|
|
|
|
|
2023-05-25 20:41:19 +08:00
|
|
|
if (snapType.HasFlagFast(SnapType.GlobalGrids))
|
2020-05-25 18:21:53 +08:00
|
|
|
{
|
2022-05-12 14:23:41 +08:00
|
|
|
if (playfield is ScrollingPlayfield scrollingPlayfield)
|
|
|
|
{
|
|
|
|
targetTime = scrollingPlayfield.TimeAtScreenSpacePosition(screenSpacePosition);
|
2020-05-25 18:21:53 +08:00
|
|
|
|
2022-05-12 14:23:41 +08:00
|
|
|
// apply beat snapping
|
|
|
|
targetTime = BeatSnapProvider.SnapTime(targetTime.Value);
|
2020-05-25 18:21:53 +08:00
|
|
|
|
2022-05-12 14:23:41 +08:00
|
|
|
// convert back to screen space
|
|
|
|
screenSpacePosition = scrollingPlayfield.ScreenSpacePositionAtTime(targetTime.Value);
|
|
|
|
}
|
2020-05-25 18:21:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return new SnapResult(screenSpacePosition, targetTime, playfield);
|
|
|
|
}
|
2019-10-25 11:34:49 +08:00
|
|
|
|
2020-05-29 10:46:08 +08:00
|
|
|
#endregion
|
2024-06-17 18:11:19 +08:00
|
|
|
|
|
|
|
private partial class ContentContainer : Container
|
|
|
|
{
|
|
|
|
public override bool HandlePositionalInput => true;
|
|
|
|
|
|
|
|
private readonly Bindable<bool> composerFocusMode = new Bindable<bool>();
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
private void load([CanBeNull] Editor editor)
|
|
|
|
{
|
|
|
|
if (editor != null)
|
|
|
|
composerFocusMode.BindTo(editor.ComposerFocusMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
composerFocusMode.Value = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
composerFocusMode.Value = false;
|
|
|
|
}
|
|
|
|
}
|
2018-10-17 17:01:38 +08:00
|
|
|
}
|
2019-08-29 17:02:50 +08:00
|
|
|
|
2020-05-29 10:46:08 +08: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>
|
2022-05-05 15:42:57 +08:00
|
|
|
[Cached]
|
2021-06-17 09:07:52 +08:00
|
|
|
public abstract partial class HitObjectComposer : CompositeDrawable, IPositionSnapProvider
|
2019-08-29 17:02:50 +08:00
|
|
|
{
|
2023-05-02 14:36:01 +08:00
|
|
|
public const float TOOLBOX_CONTRACTED_SIZE_LEFT = 60;
|
2023-07-21 13:39:15 +08:00
|
|
|
public const float TOOLBOX_CONTRACTED_SIZE_RIGHT = 120;
|
2023-05-02 14:36:01 +08:00
|
|
|
|
2022-11-30 19:17:58 +08:00
|
|
|
public readonly Ruleset Ruleset;
|
|
|
|
|
|
|
|
protected HitObjectComposer(Ruleset ruleset)
|
2019-08-29 17:02:50 +08:00
|
|
|
{
|
2022-11-30 19:17:58 +08:00
|
|
|
Ruleset = ruleset;
|
2019-08-29 17:02:50 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
2020-05-29 10:46:08 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The target ruleset's playfield.
|
|
|
|
/// </summary>
|
2020-05-27 22:15:16 +08:00
|
|
|
public abstract Playfield Playfield { get; }
|
|
|
|
|
2019-08-29 17:02:50 +08:00
|
|
|
/// <summary>
|
2020-05-29 10:46:08 +08:00
|
|
|
/// All <see cref="DrawableHitObject"/>s in currently loaded beatmap.
|
2019-08-29 17:02:50 +08: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; }
|
|
|
|
|
2023-11-20 20:37:29 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a string representing the current selection.
|
|
|
|
/// The inverse method to <see cref="SelectFromTimestamp"/>.
|
|
|
|
/// </summary>
|
2021-03-29 17:29:05 +08:00
|
|
|
public virtual string ConvertSelectionToString() => string.Empty;
|
2021-03-26 15:25:20 +08:00
|
|
|
|
2023-11-07 08:36:58 +08:00
|
|
|
/// <summary>
|
2023-11-20 20:37:29 +08:00
|
|
|
/// Selects objects based on the supplied <paramref name="timestamp"/> and <paramref name="objectDescription"/>.
|
|
|
|
/// The inverse method to <see cref="ConvertSelectionToString"/>.
|
2023-11-07 08:36:58 +08:00
|
|
|
/// </summary>
|
2023-11-20 20:37:29 +08:00
|
|
|
/// <param name="timestamp">The time instant to seek to, in milliseconds.</param>
|
|
|
|
/// <param name="objectDescription">The ruleset-specific description of objects to select at the given timestamp.</param>
|
|
|
|
public virtual void SelectFromTimestamp(double timestamp, string objectDescription) { }
|
2023-11-07 08:36:58 +08:00
|
|
|
|
2020-05-29 10:46:08 +08:00
|
|
|
#region IPositionSnapProvider
|
|
|
|
|
2022-05-12 14:23:41 +08:00
|
|
|
public abstract SnapResult FindSnappedPositionAndTime(Vector2 screenSpacePosition, SnapType snapType = SnapType.All);
|
2020-11-24 16:14:39 +08:00
|
|
|
|
2020-05-29 10:46:08 +08:00
|
|
|
#endregion
|
2019-08-29 17:02:50 +08:00
|
|
|
}
|
2017-11-29 15:22:11 +08:00
|
|
|
}
|