2024-12-30 12:33:32 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2020-04-01 17:00:17 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2025-01-29 17:16:04 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2020-04-01 17:00:17 +08:00
|
|
|
using osu.Framework.Graphics;
|
2025-01-26 07:21:20 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-04-02 17:39:49 +08:00
|
|
|
using osu.Game.Rulesets.Mania.Skinning;
|
2020-04-01 17:00:17 +08:00
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.UI.Components
|
|
|
|
{
|
2025-01-26 07:21:20 +08:00
|
|
|
public partial class HitPositionPaddedContainer : Container
|
2020-04-01 17:00:17 +08:00
|
|
|
{
|
|
|
|
protected readonly IBindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();
|
|
|
|
|
2025-01-26 07:21:20 +08:00
|
|
|
[Resolved]
|
|
|
|
private ISkinSource skin { get; set; } = null!;
|
2025-01-13 11:56:28 +08:00
|
|
|
|
2020-04-01 17:00:17 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(IScrollingInfo scrollingInfo)
|
|
|
|
{
|
|
|
|
Direction.BindTo(scrollingInfo.Direction);
|
2025-01-29 17:16:04 +08:00
|
|
|
Direction.BindValueChanged(_ => UpdateHitPosition(), true);
|
2020-04-01 17:00:17 +08:00
|
|
|
|
2025-01-26 07:21:20 +08:00
|
|
|
skin.SourceChanged += onSkinChanged;
|
2020-04-01 17:00:17 +08:00
|
|
|
}
|
|
|
|
|
2025-01-26 07:21:20 +08:00
|
|
|
private void onSkinChanged() => UpdateHitPosition();
|
|
|
|
|
2020-04-01 17:00:17 +08:00
|
|
|
protected virtual void UpdateHitPosition()
|
|
|
|
{
|
2025-01-26 07:21:20 +08:00
|
|
|
float hitPosition = skin.GetConfig<ManiaSkinConfigurationLookup, float>(
|
2020-04-02 17:39:49 +08:00
|
|
|
new ManiaSkinConfigurationLookup(LegacyManiaSkinConfigurationLookups.HitPosition))?.Value
|
2020-04-08 13:08:34 +08:00
|
|
|
?? Stage.HIT_TARGET_POSITION;
|
2020-04-01 17:00:17 +08:00
|
|
|
|
|
|
|
Padding = Direction.Value == ScrollingDirection.Up
|
|
|
|
? new MarginPadding { Top = hitPosition }
|
|
|
|
: new MarginPadding { Bottom = hitPosition };
|
|
|
|
}
|
2025-01-29 17:16:04 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (skin.IsNotNull())
|
|
|
|
skin.SourceChanged -= onSkinChanged;
|
|
|
|
}
|
2020-04-01 17:00:17 +08:00
|
|
|
}
|
|
|
|
}
|