mirror of
https://github.com/ppy/osu.git
synced 2025-02-20 18:43:04 +08:00
Simplify creation of a playfield
This commit is contained in:
parent
826dc6ceb7
commit
368ceec47c
@ -17,9 +17,6 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
{
|
||||
public const float BASE_WIDTH = 512;
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
private readonly Container<Drawable> content;
|
||||
|
||||
private readonly CatcherArea catcherArea;
|
||||
|
||||
protected override bool UserScrollSpeedAdjustment => false;
|
||||
@ -56,10 +53,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.TopLeft,
|
||||
},
|
||||
content = new Container<Drawable>
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
HitObjectContainer
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -30,8 +30,6 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
internal readonly Container TopLevelContainer;
|
||||
private readonly Container explosionContainer;
|
||||
|
||||
protected override Container<Drawable> Content => hitObjectArea;
|
||||
|
||||
public Column()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
@ -54,7 +52,10 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
hitObjectArea = new ColumnHitObjectArea { RelativeSizeAxes = Axes.Both },
|
||||
hitObjectArea = new ColumnHitObjectArea(HitObjectContainer)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
explosionContainer = new Container
|
||||
{
|
||||
Name = "Hit explosions",
|
||||
|
@ -8,28 +8,24 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Rulesets.UI.Scrolling;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.UI.Components
|
||||
{
|
||||
public class ColumnHitObjectArea : Container, IHasAccentColour
|
||||
public class ColumnHitObjectArea : CompositeDrawable, IHasAccentColour
|
||||
{
|
||||
private const float hit_target_height = 10;
|
||||
private const float hit_target_bar_height = 2;
|
||||
|
||||
private Container<Drawable> content;
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
||||
|
||||
private Container hitTargetLine;
|
||||
private readonly Container hitTargetLine;
|
||||
private readonly Drawable hitTargetBar;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IScrollingInfo scrollingInfo)
|
||||
public ColumnHitObjectArea(HitObjectContainer hitObjectContainer)
|
||||
{
|
||||
Drawable hitTargetBar;
|
||||
|
||||
InternalChildren = new[]
|
||||
{
|
||||
hitTargetBar = new Box
|
||||
@ -45,13 +41,13 @@ namespace osu.Game.Rulesets.Mania.UI.Components
|
||||
Masking = true,
|
||||
Child = new Box { RelativeSizeAxes = Axes.Both }
|
||||
},
|
||||
content = new Container
|
||||
{
|
||||
Name = "Hit objects",
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
hitObjectContainer
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IScrollingInfo scrollingInfo)
|
||||
{
|
||||
direction.BindTo(scrollingInfo.Direction);
|
||||
direction.BindValueChanged(direction =>
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ using osu.Game.Rulesets.UI.Scrolling;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.UI
|
||||
{
|
||||
public class ManiaScrollingPlayfield : ScrollingPlayfield
|
||||
public abstract class ManiaScrollingPlayfield : ScrollingPlayfield
|
||||
{
|
||||
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
||||
|
||||
|
@ -30,8 +30,7 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
public IReadOnlyList<Column> Columns => columnFlow.Children;
|
||||
private readonly FillFlowContainer<Column> columnFlow;
|
||||
|
||||
protected override Container<Drawable> Content => barLineContainer;
|
||||
private readonly Container<Drawable> barLineContainer;
|
||||
private readonly Container barLineContainer;
|
||||
|
||||
public Container<DrawableManiaJudgement> Judgements => judgements;
|
||||
private readonly JudgementContainer<DrawableManiaJudgement> judgements;
|
||||
@ -105,6 +104,7 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Child = HitObjectContainer
|
||||
}
|
||||
},
|
||||
judgements = new JudgementContainer<DrawableManiaJudgement>
|
||||
|
@ -20,9 +20,6 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
private readonly JudgementContainer<DrawableOsuJudgement> judgementLayer;
|
||||
private readonly ConnectionRenderer<OsuHitObject> connectionLayer;
|
||||
|
||||
private readonly Container content;
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
public static readonly Vector2 BASE_SIZE = new Vector2(512, 384);
|
||||
|
||||
public OsuPlayfield()
|
||||
@ -37,7 +34,7 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fit,
|
||||
FillAspectRatio = 4f / 3,
|
||||
Child = content = new ScalingContainer(BASE_SIZE.X)
|
||||
Child = new ScalingContainer(BASE_SIZE.X)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
@ -52,6 +49,7 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Depth = 1,
|
||||
},
|
||||
HitObjectContainer,
|
||||
approachCircles = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
|
@ -44,9 +44,6 @@ namespace osu.Game.Rulesets.Taiko.UI
|
||||
private readonly Container<KiaiHitExplosion> kiaiExplosionContainer;
|
||||
private readonly JudgementContainer<DrawableTaikoJudgement> judgementContainer;
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
private readonly Container content;
|
||||
|
||||
private readonly Container topLevelHitContainer;
|
||||
|
||||
private readonly Container barlineContainer;
|
||||
@ -118,12 +115,13 @@ namespace osu.Game.Rulesets.Taiko.UI
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Left = HIT_TARGET_OFFSET }
|
||||
},
|
||||
content = new Container
|
||||
new Container
|
||||
{
|
||||
Name = "Hit objects",
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Left = HIT_TARGET_OFFSET },
|
||||
Masking = true
|
||||
Masking = true,
|
||||
Child = HitObjectContainer
|
||||
},
|
||||
kiaiExplosionContainer = new Container<KiaiHitExplosion>
|
||||
{
|
||||
|
@ -121,14 +121,21 @@ namespace osu.Game.Tests.Visual
|
||||
Direction = direction;
|
||||
|
||||
Padding = new MarginPadding(2);
|
||||
Content.Masking = true;
|
||||
|
||||
AddInternal(new Box
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0.5f,
|
||||
Depth = float.MaxValue
|
||||
});
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
Child = HitObjectContainer
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,11 @@ namespace osu.Game.Rulesets.UI
|
||||
public IEnumerable<DrawableHitObject> Objects => InternalChildren.Cast<DrawableHitObject>().OrderBy(h => h.HitObject.StartTime);
|
||||
public IEnumerable<DrawableHitObject> AliveObjects => AliveInternalChildren.Cast<DrawableHitObject>().OrderBy(h => h.HitObject.StartTime);
|
||||
|
||||
public HitObjectContainer()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
public virtual void Add(DrawableHitObject hitObject) => AddInternal(hitObject);
|
||||
public virtual bool Remove(DrawableHitObject hitObject) => RemoveInternal(hitObject);
|
||||
|
||||
|
@ -16,12 +16,14 @@ using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.UI
|
||||
{
|
||||
public abstract class Playfield : Container
|
||||
public abstract class Playfield : CompositeDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="DrawableHitObject"/> contained in this Playfield.
|
||||
/// </summary>
|
||||
public HitObjectContainer HitObjectContainer { get; private set; }
|
||||
public HitObjectContainer HitObjectContainer => hitObjectContainerLazy.Value;
|
||||
|
||||
private readonly Lazy<HitObjectContainer> hitObjectContainerLazy;
|
||||
|
||||
/// <summary>
|
||||
/// A function that converts gamefield coordinates to screen space.
|
||||
@ -51,6 +53,8 @@ namespace osu.Game.Rulesets.UI
|
||||
protected Playfield()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
hitObjectContainerLazy = new Lazy<HitObjectContainer>(CreateHitObjectContainer);
|
||||
}
|
||||
|
||||
private WorkingBeatmap beatmap;
|
||||
@ -59,11 +63,6 @@ namespace osu.Game.Rulesets.UI
|
||||
private void load(IBindableBeatmap beatmap)
|
||||
{
|
||||
this.beatmap = beatmap.Value;
|
||||
|
||||
HitObjectContainer = CreateHitObjectContainer();
|
||||
HitObjectContainer.RelativeSizeAxes = Axes.Both;
|
||||
|
||||
Add(HitObjectContainer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -94,11 +93,6 @@ namespace osu.Game.Rulesets.UI
|
||||
nestedPlayfields.Value.Add(otherPlayfield);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s.
|
||||
/// </summary>
|
||||
protected virtual HitObjectContainer CreateHitObjectContainer() => new HitObjectContainer();
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
@ -108,5 +102,10 @@ namespace osu.Game.Rulesets.UI
|
||||
if (mod is IUpdatableByPlayfield updatable)
|
||||
updatable.Update(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s.
|
||||
/// </summary>
|
||||
protected virtual HitObjectContainer CreateHitObjectContainer() => new HitObjectContainer();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user