From cbea2db4bef9322b8dcbe9619d95cb918dcc3b55 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Tue, 7 Nov 2023 02:03:16 +0300 Subject: [PATCH] Support absolute-sized health bar and use it for default layout --- .../Screens/Play/HUD/ArgonHealthDisplay.cs | 30 +++++++++++++------ osu.Game/Skinning/ArgonSkin.cs | 3 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/ArgonHealthDisplay.cs b/osu.Game/Screens/Play/HUD/ArgonHealthDisplay.cs index 793d43f7ef..2ae6bdcb15 100644 --- a/osu.Game/Screens/Play/HUD/ArgonHealthDisplay.cs +++ b/osu.Game/Screens/Play/HUD/ArgonHealthDisplay.cs @@ -36,12 +36,10 @@ namespace osu.Game.Screens.Play.HUD }; [SettingSource("Bar length")] - public BindableFloat BarLength { get; } = new BindableFloat(0.98f) - { - MinValue = 0.2f, - MaxValue = 1, - Precision = 0.01f, - }; + public BindableFloat BarLength { get; } = new BindableFloat(0.98f); + + [SettingSource("Use relative size")] + public BindableBool UseRelativeSize { get; } = new BindableBool(true); private BarPath mainBar = null!; @@ -140,9 +138,23 @@ namespace osu.Game.Screens.Play.HUD Current.BindValueChanged(_ => Scheduler.AddOnce(updateCurrent), true); - BarLength.BindValueChanged(l => Width = l.NewValue, true); - BarHeight.BindValueChanged(_ => updatePath()); - updatePath(); + // update relative axes first before reading width from bar length. + RelativeSizeAxes = UseRelativeSize.Value ? Axes.X : Axes.None; + Width = BarLength.Value; + + UseRelativeSize.BindValueChanged(v => + { + RelativeSizeAxes = v.NewValue ? Axes.X : Axes.None; + float newWidth = Width; + + BarLength.MinValue = v.NewValue ? 0.2f : 200f; + BarLength.MaxValue = v.NewValue ? 1f : 1000f; + BarLength.Precision = v.NewValue ? 0.01f : 1f; + BarLength.Value = newWidth; + }, true); + + BarLength.ValueChanged += l => Width = l.NewValue; + BarHeight.BindValueChanged(_ => updatePath(), true); } protected override bool OnInvalidate(Invalidation invalidation, InvalidationSource source) diff --git a/osu.Game/Skinning/ArgonSkin.cs b/osu.Game/Skinning/ArgonSkin.cs index 82c150ced7..95e1820059 100644 --- a/osu.Game/Skinning/ArgonSkin.cs +++ b/osu.Game/Skinning/ArgonSkin.cs @@ -129,7 +129,8 @@ namespace osu.Game.Skinning health.Anchor = Anchor.TopLeft; health.Origin = Anchor.TopLeft; - health.BarLength.Value = 0.22f; + health.UseRelativeSize.Value = false; + health.BarLength.Value = 300; health.BarHeight.Value = 30f; health.Position = new Vector2(components_x_offset, 20f);