1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 14:32:55 +08:00

Support absolute-sized health bar and use it for default layout

This commit is contained in:
Salman Ahmed 2023-11-07 02:03:16 +03:00
parent 0dbba13686
commit cbea2db4be
2 changed files with 23 additions and 10 deletions

View File

@ -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)

View File

@ -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);