1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 16:27:43 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Skinning/Default/DefaultBarLine.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.8 KiB
C#
Raw Normal View History

2023-08-15 12:33:49 +08:00
// 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
2023-08-15 12:33:49 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK;
namespace osu.Game.Rulesets.Mania.Skinning.Default
{
public partial class DefaultBarLine : CompositeDrawable
{
private Bindable<bool> major = null!;
private Drawable mainLine = null!;
private Drawable leftAnchor = null!;
private Drawable rightAnchor = null!;
[BackgroundDependencyLoader]
private void load(DrawableHitObject drawableHitObject)
{
RelativeSizeAxes = Axes.Both;
// Avoid flickering due to no anti-aliasing of boxes by default.
var edgeSmoothness = new Vector2(0.3f);
2023-08-15 12:33:49 +08:00
AddInternal(mainLine = new Box
{
Name = "Bar line",
EdgeSmoothness = edgeSmoothness,
2023-08-15 12:33:49 +08:00
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.Both,
});
const float major_extension = 10;
2023-08-15 12:33:49 +08:00
AddInternal(leftAnchor = new Box
2023-08-15 12:33:49 +08:00
{
Name = "Left anchor",
EdgeSmoothness = edgeSmoothness,
Blending = BlendingParameters.Additive,
2023-08-15 12:33:49 +08:00
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreRight,
Width = major_extension,
RelativeSizeAxes = Axes.Y,
Colour = ColourInfo.GradientHorizontal(Colour4.Transparent, Colour4.White),
2023-08-15 12:33:49 +08:00
});
AddInternal(rightAnchor = new Box
2023-08-15 12:33:49 +08:00
{
Name = "Right anchor",
EdgeSmoothness = edgeSmoothness,
Blending = BlendingParameters.Additive,
2023-08-15 12:33:49 +08:00
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreLeft,
Width = major_extension,
RelativeSizeAxes = Axes.Y,
Colour = ColourInfo.GradientHorizontal(Colour4.White, Colour4.Transparent),
2023-08-15 12:33:49 +08:00
});
major = ((DrawableBarLine)drawableHitObject).Major.GetBoundCopy();
}
protected override void LoadComplete()
{
base.LoadComplete();
major.BindValueChanged(updateMajor, true);
}
private void updateMajor(ValueChangedEvent<bool> major)
{
mainLine.Alpha = major.NewValue ? 0.5f : 0.2f;
leftAnchor.Alpha = rightAnchor.Alpha = major.NewValue ? mainLine.Alpha * 0.3f : 0;
2023-08-15 12:33:49 +08:00
}
}
}