DI the scrolling info rather than pass by ctor

This commit is contained in:
smoogipoo
2018-06-08 20:13:24 +09:00
parent 0fb4e6b41b
commit ca5103615d
14 changed files with 146 additions and 118 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
@ -9,6 +10,7 @@ using OpenTK.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Mania.Judgements;
using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI.Scrolling;
@ -36,6 +38,8 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
/// </summary>
private bool hasBroken;
private ScrollingInfo scrollingInfo;
private readonly Container<DrawableHoldNoteTick> tickContainer;
public DrawableHoldNote(HoldNote hitObject, ManiaAction action)
@ -76,17 +80,13 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
AddNested(tail);
}
private ScrollingDirection direction;
public override ScrollingDirection Direction
[BackgroundDependencyLoader]
private void load(ScrollingInfo scrollingInfo)
{
set
{
base.Direction = value;
direction = value;
this.scrollingInfo = scrollingInfo;
bodyPiece.Anchor = value == ScrollingDirection.Up ? Anchor.TopLeft : Anchor.BottomLeft;
bodyPiece.Origin = bodyPiece.Anchor;
}
bodyPiece.Anchor = scrollingInfo.Direction == ScrollingDirection.Up ? Anchor.TopLeft : Anchor.BottomLeft;
bodyPiece.Origin = bodyPiece.Anchor;
}
public override Color4 AccentColour
@ -114,7 +114,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
base.Update();
// Make the body piece not lie under the head note
bodyPiece.Y = (direction == ScrollingDirection.Up ? 1 : -1) * head.Height / 2;
bodyPiece.Y = (scrollingInfo.Direction == ScrollingDirection.Up ? 1 : -1) * head.Height / 2;
bodyPiece.Height = DrawHeight - head.Height / 2 + tail.Height / 2;
}

View File

@ -1,40 +1,15 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling;
namespace osu.Game.Rulesets.Mania.Objects.Drawables
{
public abstract class DrawableManiaHitObject : DrawableHitObject<ManiaHitObject>
{
protected DrawableManiaHitObject(ManiaHitObject hitObject)
: base(hitObject)
{
}
/// <summary>
/// Sets the scrolling direction.
/// </summary>
public virtual ScrollingDirection Direction
{
set
{
Anchor = value == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre;
Origin = Anchor;
if (!HasNestedHitObjects)
return;
foreach (var obj in NestedHitObjects.OfType<DrawableManiaHitObject>())
obj.Direction = value;
}
}
}
public abstract class DrawableManiaHitObject<TObject> : DrawableManiaHitObject
public abstract class DrawableManiaHitObject<TObject> : DrawableHitObject<ManiaHitObject>
where TObject : ManiaHitObject
{
/// <summary>
@ -47,15 +22,19 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
protected DrawableManiaHitObject(TObject hitObject, ManiaAction? action = null)
: base(hitObject)
{
Anchor = Anchor.TopCentre;
Origin = Anchor.TopCentre;
HitObject = hitObject;
if (action != null)
Action = action.Value;
}
[BackgroundDependencyLoader]
private void load(ScrollingInfo scrollingInfo)
{
Anchor = scrollingInfo.Direction == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre;
Origin = Anchor;
}
protected override void UpdateState(ArmedState state)
{
switch (state)

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using OpenTK.Graphics;
using osu.Framework.Graphics;
@ -8,6 +9,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Mania.Judgements;
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI.Scrolling;
@ -29,26 +31,14 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
CornerRadius = 5;
Masking = true;
InternalChildren = new Drawable[]
{
headPiece = new NotePiece
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre
}
};
InternalChild = headPiece = new NotePiece();
}
public override ScrollingDirection Direction
[BackgroundDependencyLoader]
private void load(ScrollingInfo scrollingInfo)
{
set
{
base.Direction = value;
headPiece.Direction = value;
headPiece.Anchor = Anchor;
headPiece.Origin = Origin;
}
headPiece.Anchor = scrollingInfo.Direction == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre;
headPiece.Origin = headPiece.Anchor;
}
public override Color4 AccentColour

View File

@ -1,12 +1,14 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using OpenTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.UI.Scrolling;
namespace osu.Game.Rulesets.Mania.Objects.Drawables.Pieces
@ -43,13 +45,11 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables.Pieces
};
}
public ScrollingDirection Direction
[BackgroundDependencyLoader]
private void load(ScrollingInfo scrollingInfo)
{
set
{
colouredBox.Anchor = value == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre;
colouredBox.Origin = colouredBox.Anchor;
}
colouredBox.Anchor = scrollingInfo.Direction == ScrollingDirection.Up ? Anchor.TopCentre : Anchor.BottomCentre;
colouredBox.Origin = colouredBox.Anchor;
}
private Color4 accentColour;