1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 06:42:54 +08:00

Reduce chaining

This commit is contained in:
smoogipoo 2018-11-14 18:34:13 +09:00
parent 84d16ee71b
commit c963fc7cd2
2 changed files with 27 additions and 24 deletions

View File

@ -8,6 +8,7 @@ using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -23,7 +24,7 @@ namespace osu.Game.Rulesets.Edit
{ {
public abstract class HitObjectComposer : CompositeDrawable public abstract class HitObjectComposer : CompositeDrawable
{ {
public IEnumerable<DrawableHitObject> HitObjects => RulesetContainer.Playfield.AllHitObjects; public IEnumerable<DrawableHitObject> HitObjects => rulesetContainer.Playfield.AllHitObjects;
protected readonly Ruleset Ruleset; protected readonly Ruleset Ruleset;
@ -33,10 +34,12 @@ namespace osu.Game.Rulesets.Edit
private readonly List<Container> layerContainers = new List<Container>(); private readonly List<Container> layerContainers = new List<Container>();
public EditRulesetContainer RulesetContainer { get; private set; } private EditRulesetContainer rulesetContainer;
private BlueprintContainer blueprintContainer; private BlueprintContainer blueprintContainer;
private InputManager inputManager;
internal HitObjectComposer(Ruleset ruleset) internal HitObjectComposer(Ruleset ruleset)
{ {
Ruleset = ruleset; Ruleset = ruleset;
@ -51,8 +54,8 @@ namespace osu.Game.Rulesets.Edit
try try
{ {
RulesetContainer = CreateRulesetContainer(); rulesetContainer = CreateRulesetContainer();
RulesetContainer.Clock = framedClock; rulesetContainer.Clock = framedClock;
} }
catch (Exception e) catch (Exception e)
{ {
@ -94,7 +97,7 @@ namespace osu.Game.Rulesets.Edit
Children = new Drawable[] Children = new Drawable[]
{ {
layerBelowRuleset, layerBelowRuleset,
RulesetContainer, rulesetContainer,
layerAboveRuleset layerAboveRuleset
} }
} }
@ -114,6 +117,13 @@ namespace osu.Game.Rulesets.Edit
toolboxCollection.Items[0].Select(); toolboxCollection.Items[0].Select();
} }
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ {
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
@ -130,20 +140,25 @@ namespace osu.Game.Rulesets.Edit
layerContainers.ForEach(l => layerContainers.ForEach(l =>
{ {
l.Anchor = RulesetContainer.Playfield.Anchor; l.Anchor = rulesetContainer.Playfield.Anchor;
l.Origin = RulesetContainer.Playfield.Origin; l.Origin = rulesetContainer.Playfield.Origin;
l.Position = RulesetContainer.Playfield.Position; l.Position = rulesetContainer.Playfield.Position;
l.Size = RulesetContainer.Playfield.Size; l.Size = rulesetContainer.Playfield.Size;
}); });
} }
/// <summary>
/// Whether the user's cursor is currently in an area of the <see cref="HitObjectComposer"/> that is valid for placement.
/// </summary>
public virtual bool CursorInPlacementArea => rulesetContainer.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position);
/// <summary> /// <summary>
/// Adds a <see cref="HitObject"/> to the <see cref="Beatmaps.Beatmap"/> and visualises it. /// Adds a <see cref="HitObject"/> to the <see cref="Beatmaps.Beatmap"/> and visualises it.
/// </summary> /// </summary>
/// <param name="hitObject">The <see cref="HitObject"/> to add.</param> /// <param name="hitObject">The <see cref="HitObject"/> to add.</param>
public void Add(HitObject hitObject) => blueprintContainer.AddBlueprintFor(RulesetContainer.Add(hitObject)); public void Add(HitObject hitObject) => blueprintContainer.AddBlueprintFor(rulesetContainer.Add(hitObject));
public void Remove(HitObject hitObject) => blueprintContainer.RemoveBlueprintFor(RulesetContainer.Remove(hitObject)); public void Remove(HitObject hitObject) => blueprintContainer.RemoveBlueprintFor(rulesetContainer.Remove(hitObject));
internal abstract EditRulesetContainer CreateRulesetContainer(); internal abstract EditRulesetContainer CreateRulesetContainer();

View File

@ -7,7 +7,6 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Input;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Input.States; using osu.Framework.Input.States;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
@ -30,8 +29,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
[Resolved] [Resolved]
private HitObjectComposer composer { get; set; } private HitObjectComposer composer { get; set; }
private InputManager inputManager;
public BlueprintContainer() public BlueprintContainer()
{ {
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -59,13 +56,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
AddBlueprintFor(obj); AddBlueprintFor(obj);
} }
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
}
private HitObjectCompositionTool currentTool; private HitObjectCompositionTool currentTool;
/// <summary> /// <summary>
@ -136,9 +126,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (currentPlacement != null) if (currentPlacement != null)
{ {
bool cursorInPlayfield = composer.RulesetContainer.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position); if (composer.CursorInPlacementArea)
if (cursorInPlayfield)
currentPlacement.State = PlacementState.Shown; currentPlacement.State = PlacementState.Shown;
else if (currentPlacement?.PlacementBegun == false) else if (currentPlacement?.PlacementBegun == false)
currentPlacement.State = PlacementState.Hidden; currentPlacement.State = PlacementState.Hidden;