From af4a3785e91725d1aae10f141e4113807d879a4b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 13 Nov 2024 14:38:34 +0900 Subject: [PATCH] Fix up code quality and isolate scale better --- osu.Game.Rulesets.Osu/Mods/OsuModBloom.cs | 38 ++++++++------------ osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs | 14 ++++---- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBloom.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBloom.cs index e1b05fa84b..425db55c6e 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBloom.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBloom.cs @@ -2,20 +2,18 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Diagnostics; using osu.Framework.Bindables; using osu.Framework.Localisation; -using osu.Game.Rulesets.Mods; -using osu.Game.Rulesets.Osu.UI; -using osu.Game.Rulesets.UI; +using osu.Framework.Utils; using osu.Game.Configuration; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays.Settings; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Osu.UI.Cursor; using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.UI; using osu.Game.Scoring; using osu.Game.Screens.Play; -using osu.Game.Rulesets.Osu.UI.Cursor; -using osu.Framework.Utils; namespace osu.Game.Rulesets.Osu.Mods { @@ -32,10 +30,11 @@ namespace osu.Game.Rulesets.Osu.Mods protected readonly BindableNumber CurrentCombo = new BindableInt(); protected readonly IBindable IsBreakTime = new Bindable(); - protected float ComboBasedSize; + + private float currentSize; [SettingSource( - "Max Size at Combo", + "Max size at combo", "The combo count at which the cursor reaches its maximum size", SettingControlType = typeof(SettingsSlider>) )] @@ -46,11 +45,11 @@ namespace osu.Game.Rulesets.Osu.Mods }; [SettingSource( - "Final Size Multiplier", + "Final size multiplier", "The multiplier applied to cursor size when combo reaches maximum", SettingControlType = typeof(SettingsSlider>) )] - public BindableFloat MaxMulti { get; } = new BindableFloat(10f) + public BindableFloat MaxCursorSize { get; } = new BindableFloat(10f) { MinValue = 5f, MaxValue = 15f, @@ -69,27 +68,18 @@ namespace osu.Game.Rulesets.Osu.Mods CurrentCombo.BindTo(scoreProcessor.Combo); CurrentCombo.BindValueChanged(combo => { - ComboBasedSize = Math.Clamp(MaxMulti.Value * ((float)combo.NewValue / MaxSizeComboCount.Value), MIN_SIZE, MaxMulti.Value); + currentSize = Math.Clamp(MaxCursorSize.Value * ((float)combo.NewValue / MaxSizeComboCount.Value), MIN_SIZE, MaxCursorSize.Value); }, true); } public void Update(Playfield playfield) { - bool beBaseSize = IsBreakTime.Value; - OsuPlayfield osuPlayfield = (OsuPlayfield)playfield; - Debug.Assert(osuPlayfield.Cursor != null); + OsuCursor cursor = (OsuCursor)(playfield.Cursor!.ActiveCursor); - OsuCursor realCursor = (OsuCursor)osuPlayfield.Cursor.ActiveCursor; - float currentCombSize = (float)Interpolation.Lerp(realCursor.CursorScale.Value, ComboBasedSize, Math.Clamp(osuPlayfield.Time.Elapsed / TRANSITION_DURATION, 0, 1)); - - if (beBaseSize) - { - realCursor.UpdateSize(1); - } + if (IsBreakTime.Value) + cursor.ModScaleAdjust.Value = 1; else - { - realCursor.UpdateSize(currentCombSize); - } + cursor.ModScaleAdjust.Value = (float)Interpolation.Lerp(cursor.ModScaleAdjust.Value, currentSize, Math.Clamp(cursor.Time.Elapsed / TRANSITION_DURATION, 0, 1)); } } } diff --git a/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs b/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs index 545cd15d32..c2f7d84f5e 100644 --- a/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs +++ b/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs @@ -38,6 +38,11 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor public IBindable CursorScale => cursorScale; + /// + /// Mods which want to adjust cursor size should do so via this bindable. + /// + public readonly Bindable ModScaleAdjust = new Bindable(1); + private readonly Bindable cursorScale = new BindableFloat(1); private Bindable userCursorScale = null!; @@ -67,6 +72,8 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor autoCursorScale = config.GetBindable(OsuSetting.AutoCursorSize); autoCursorScale.ValueChanged += _ => cursorScale.Value = CalculateCursorScale(); + ModScaleAdjust.ValueChanged += _ => cursorScale.Value = CalculateCursorScale(); + cursorScale.BindValueChanged(e => cursorScaleContainer.Scale = new Vector2(e.NewValue), true); } @@ -90,7 +97,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor protected virtual float CalculateCursorScale() { - float scale = userCursorScale.Value; + float scale = userCursorScale.Value * ModScaleAdjust.Value; if (autoCursorScale.Value && state != null) { @@ -101,11 +108,6 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor return scale; } - public void UpdateSize(float size) - { - cursorScale.Value = size; - } - protected override void SkinChanged(ISkinSource skin) { cursorExpand = skin.GetConfig(OsuSkinConfiguration.CursorExpand)?.Value ?? true;