1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 19:04:06 +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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Logging;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
@ -23,7 +24,7 @@ namespace osu.Game.Rulesets.Edit
{
public abstract class HitObjectComposer : CompositeDrawable
{
public IEnumerable<DrawableHitObject> HitObjects => RulesetContainer.Playfield.AllHitObjects;
public IEnumerable<DrawableHitObject> HitObjects => rulesetContainer.Playfield.AllHitObjects;
protected readonly Ruleset Ruleset;
@ -33,10 +34,12 @@ namespace osu.Game.Rulesets.Edit
private readonly List<Container> layerContainers = new List<Container>();
public EditRulesetContainer RulesetContainer { get; private set; }
private EditRulesetContainer rulesetContainer;
private BlueprintContainer blueprintContainer;
private InputManager inputManager;
internal HitObjectComposer(Ruleset ruleset)
{
Ruleset = ruleset;
@ -51,8 +54,8 @@ namespace osu.Game.Rulesets.Edit
try
{
RulesetContainer = CreateRulesetContainer();
RulesetContainer.Clock = framedClock;
rulesetContainer = CreateRulesetContainer();
rulesetContainer.Clock = framedClock;
}
catch (Exception e)
{
@ -94,7 +97,7 @@ namespace osu.Game.Rulesets.Edit
Children = new Drawable[]
{
layerBelowRuleset,
RulesetContainer,
rulesetContainer,
layerAboveRuleset
}
}
@ -114,6 +117,13 @@ namespace osu.Game.Rulesets.Edit
toolboxCollection.Items[0].Select();
}
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
}
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
@ -130,20 +140,25 @@ namespace osu.Game.Rulesets.Edit
layerContainers.ForEach(l =>
{
l.Anchor = RulesetContainer.Playfield.Anchor;
l.Origin = RulesetContainer.Playfield.Origin;
l.Position = RulesetContainer.Playfield.Position;
l.Size = RulesetContainer.Playfield.Size;
l.Anchor = rulesetContainer.Playfield.Anchor;
l.Origin = rulesetContainer.Playfield.Origin;
l.Position = rulesetContainer.Playfield.Position;
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>
/// Adds a <see cref="HitObject"/> to the <see cref="Beatmaps.Beatmap"/> and visualises it.
/// </summary>
/// <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();

View File

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