mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 18:23:04 +08:00
Unify bar line types & prepare for pooling
This commit is contained in:
parent
f83c5fa81d
commit
a8e86a20e1
@ -71,7 +71,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
hoc.Add(new DrawableBarLineMajor(createBarLineAtCurrentTime(true))
|
hoc.Add(new DrawableBarLine(createBarLineAtCurrentTime(true))
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
|
@ -145,9 +145,13 @@ namespace osu.Game.Rulesets.Taiko.Tests
|
|||||||
|
|
||||||
private void addBarLine(bool major, double delay = scroll_time)
|
private void addBarLine(bool major, double delay = scroll_time)
|
||||||
{
|
{
|
||||||
BarLine bl = new BarLine { StartTime = DrawableRuleset.Playfield.Time.Current + delay };
|
BarLine bl = new BarLine
|
||||||
|
{
|
||||||
|
StartTime = DrawableRuleset.Playfield.Time.Current + delay,
|
||||||
|
Major = major
|
||||||
|
};
|
||||||
|
|
||||||
DrawableRuleset.Playfield.Add(major ? new DrawableBarLineMajor(bl) : new DrawableBarLine(bl));
|
DrawableRuleset.Playfield.Add(new DrawableBarLine(bl));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSwell(double duration = default_duration)
|
private void addSwell(double duration = default_duration)
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -15,49 +19,123 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DrawableBarLine : DrawableHitObject<HitObject>
|
public class DrawableBarLine : DrawableHitObject<HitObject>
|
||||||
{
|
{
|
||||||
|
public new BarLine HitObject => (BarLine)base.HitObject;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The width of the line tracker.
|
/// The width of the line tracker.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const float tracker_width = 2f;
|
private const float tracker_width = 2f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fade out time calibrated to a pre-empt of 1000ms.
|
/// The vertical offset of the triangles from the line tracker.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const float base_fadeout_time = 100f;
|
private const float triangle_offset = 10f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The size of the triangles.
|
||||||
|
/// </summary>
|
||||||
|
private const float triangle_size = 20f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The visual line tracker.
|
/// The visual line tracker.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected SkinnableDrawable Line;
|
private SkinnableDrawable line;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The bar line.
|
/// Container with triangles. Only visible for major lines.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly BarLine BarLine;
|
private Container triangleContainer;
|
||||||
|
|
||||||
public DrawableBarLine(BarLine barLine)
|
private readonly Bindable<bool> major = new Bindable<bool>();
|
||||||
|
|
||||||
|
public DrawableBarLine()
|
||||||
|
: this(null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawableBarLine([CanBeNull] BarLine barLine)
|
||||||
: base(barLine)
|
: base(barLine)
|
||||||
{
|
{
|
||||||
BarLine = barLine;
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
Anchor = Anchor.CentreLeft;
|
Anchor = Anchor.CentreLeft;
|
||||||
Origin = Anchor.Centre;
|
Origin = Anchor.Centre;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Y;
|
RelativeSizeAxes = Axes.Y;
|
||||||
Width = tracker_width;
|
Width = tracker_width;
|
||||||
|
|
||||||
AddInternal(Line = new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.BarLine), _ => new Box
|
AddRangeInternal(new Drawable[]
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
line = new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.BarLine), _ => new Box
|
||||||
EdgeSmoothness = new Vector2(0.5f, 0),
|
{
|
||||||
})
|
RelativeSizeAxes = Axes.Both,
|
||||||
{
|
EdgeSmoothness = new Vector2(0.5f, 0),
|
||||||
Anchor = Anchor.Centre,
|
})
|
||||||
Origin = Anchor.Centre,
|
{
|
||||||
Alpha = 0.75f,
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
},
|
||||||
|
triangleContainer = new Container
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Children = new[]
|
||||||
|
{
|
||||||
|
new EquilateralTriangle
|
||||||
|
{
|
||||||
|
Name = "Top",
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Position = new Vector2(0, -triangle_offset),
|
||||||
|
Size = new Vector2(-triangle_size),
|
||||||
|
EdgeSmoothness = new Vector2(1),
|
||||||
|
},
|
||||||
|
new EquilateralTriangle
|
||||||
|
{
|
||||||
|
Name = "Bottom",
|
||||||
|
Anchor = Anchor.BottomCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Position = new Vector2(0, triangle_offset),
|
||||||
|
Size = new Vector2(triangle_size),
|
||||||
|
EdgeSmoothness = new Vector2(1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateHitStateTransforms(ArmedState state) => this.FadeOut(150);
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
major.BindValueChanged(majorChanged => updateMajor(majorChanged.NewValue), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateMajor(bool major)
|
||||||
|
{
|
||||||
|
line.Alpha = major ? 1f : 0.75f;
|
||||||
|
triangleContainer.Alpha = major ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnApply()
|
||||||
|
{
|
||||||
|
base.OnApply();
|
||||||
|
major.BindTo(HitObject.MajorBindable);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFree()
|
||||||
|
{
|
||||||
|
base.OnFree();
|
||||||
|
major.UnbindFrom(HitObject.MajorBindable);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateHitStateTransforms(ArmedState state)
|
||||||
|
{
|
||||||
|
using (BeginAbsoluteSequence(HitObject.StartTime))
|
||||||
|
this.FadeOutFromOne(150).Expire();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osuTK;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|
||||||
{
|
|
||||||
public class DrawableBarLineMajor : DrawableBarLine
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The vertical offset of the triangles from the line tracker.
|
|
||||||
/// </summary>
|
|
||||||
private const float triangle_offfset = 10f;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The size of the triangles.
|
|
||||||
/// </summary>
|
|
||||||
private const float triangle_size = 20f;
|
|
||||||
|
|
||||||
private readonly Container triangleContainer;
|
|
||||||
|
|
||||||
public DrawableBarLineMajor(BarLine barLine)
|
|
||||||
: base(barLine)
|
|
||||||
{
|
|
||||||
AddInternal(triangleContainer = new Container
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Children = new[]
|
|
||||||
{
|
|
||||||
new EquilateralTriangle
|
|
||||||
{
|
|
||||||
Name = "Top",
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
Position = new Vector2(0, -triangle_offfset),
|
|
||||||
Size = new Vector2(-triangle_size),
|
|
||||||
EdgeSmoothness = new Vector2(1),
|
|
||||||
},
|
|
||||||
new EquilateralTriangle
|
|
||||||
{
|
|
||||||
Name = "Bottom",
|
|
||||||
Anchor = Anchor.BottomCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
Position = new Vector2(0, triangle_offfset),
|
|
||||||
Size = new Vector2(triangle_size),
|
|
||||||
EdgeSmoothness = new Vector2(1),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Line.Alpha = 1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
using (triangleContainer.BeginAbsoluteSequence(HitObject.StartTime))
|
|
||||||
triangleContainer.FadeOut(150);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -40,7 +40,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
new BarLineGenerator<BarLine>(Beatmap).BarLines.ForEach(bar => Playfield.Add(bar.Major ? new DrawableBarLineMajor(bar) : new DrawableBarLine(bar)));
|
new BarLineGenerator<BarLine>(Beatmap).BarLines.ForEach(bar => Playfield.Add(new DrawableBarLine(bar)));
|
||||||
|
|
||||||
FrameStableComponents.Add(scroller = new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.Scroller), _ => Empty())
|
FrameStableComponents.Add(scroller = new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.Scroller), _ => Empty())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user