1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-29 16:07:52 +08:00
osu-lazer/osu.Game.Rulesets.Mania/UI/Components/ColumnHitObjectArea.cs

79 lines
2.8 KiB
C#
Raw Normal View History

// 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;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-09-11 17:21:29 +08:00
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
2018-09-21 13:35:50 +08:00
using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.UI.Scrolling;
2020-03-31 11:17:44 +08:00
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Mania.UI.Components
{
2020-03-31 11:17:44 +08:00
public class ColumnHitObjectArea : SkinReloadableDrawable
{
2020-03-31 11:17:44 +08:00
public readonly Container<HitExplosion> Explosions;
[Resolved(CanBeNull = true)]
private ManiaStage stage { get; set; }
2020-03-31 11:17:44 +08:00
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
2019-12-29 23:37:28 +08:00
private readonly Drawable hitTarget;
2018-09-21 13:35:50 +08:00
public ColumnHitObjectArea(HitObjectContainer hitObjectContainer)
{
2019-12-29 23:18:50 +08:00
InternalChildren = new[]
{
2020-03-31 11:17:44 +08:00
hitTarget = new SkinnableDrawable(new ManiaSkinComponent(ManiaSkinComponents.HitTarget), _ => new DefaultHitTarget())
{
RelativeSizeAxes = Axes.X,
},
2020-03-31 11:17:44 +08:00
hitObjectContainer,
Explosions = new Container<HitExplosion> { RelativeSizeAxes = Axes.Both }
};
2018-09-21 13:35:50 +08:00
}
2018-09-21 13:35:50 +08:00
[BackgroundDependencyLoader]
private void load(IScrollingInfo scrollingInfo)
{
direction.BindTo(scrollingInfo.Direction);
2020-03-31 11:17:44 +08:00
direction.BindValueChanged(onDirectionChanged, true);
}
2020-03-31 11:17:44 +08:00
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
{
2020-03-31 11:17:44 +08:00
base.SkinChanged(skin, allowFallback);
updateHitPosition();
}
2020-03-31 11:17:44 +08:00
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
{
2020-03-31 11:17:44 +08:00
updateHitPosition();
}
2019-12-28 13:48:10 +08:00
2020-03-31 11:17:44 +08:00
private void updateHitPosition()
{
float hitPosition = CurrentSkin.GetConfig<LegacyManiaSkinConfigurationLookup, float>(
new LegacyManiaSkinConfigurationLookup(stage?.Columns.Count ?? 4, LegacyManiaSkinConfigurationLookups.HitPosition))?.Value
?? ManiaStage.HIT_TARGET_POSITION;
2019-12-28 13:48:10 +08:00
2020-03-31 11:17:44 +08:00
if (direction.Value == ScrollingDirection.Up)
2019-12-28 13:48:10 +08:00
{
2020-03-31 11:17:44 +08:00
hitTarget.Anchor = hitTarget.Origin = Anchor.TopLeft;
2019-12-28 13:48:10 +08:00
2020-03-31 11:17:44 +08:00
Padding = new MarginPadding { Top = hitPosition };
2020-03-31 14:29:25 +08:00
Explosions.Padding = new MarginPadding { Top = DefaultNotePiece.NOTE_HEIGHT };
2019-12-28 13:48:10 +08:00
}
2020-03-31 11:17:44 +08:00
else
2019-12-28 13:48:10 +08:00
{
2020-03-31 11:17:44 +08:00
hitTarget.Anchor = hitTarget.Origin = Anchor.BottomLeft;
2019-12-28 13:48:10 +08:00
2020-03-31 11:17:44 +08:00
Padding = new MarginPadding { Bottom = hitPosition };
2020-03-31 14:29:25 +08:00
Explosions.Padding = new MarginPadding { Bottom = DefaultNotePiece.NOTE_HEIGHT };
2019-12-28 13:48:10 +08:00
}
}
}
}