1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 07:43:00 +08:00

Simplify flashlight parameter passing flow

This commit is contained in:
Bartłomiej Dach 2022-01-24 20:55:24 +01:00
parent 5874475dff
commit a227af75ed
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
5 changed files with 37 additions and 40 deletions

View File

@ -35,7 +35,7 @@ namespace osu.Game.Rulesets.Catch.Mods
public override float DefaultFlashlightSize => 350;
public override Flashlight CreateFlashlight() => new CatchFlashlight(playfield, ComboBasedSize.Value, SizeMultiplier.Value, DefaultFlashlightSize);
protected override Flashlight CreateFlashlight() => new CatchFlashlight(this, playfield);
private CatchPlayfield playfield;
@ -49,11 +49,11 @@ namespace osu.Game.Rulesets.Catch.Mods
{
private readonly CatchPlayfield playfield;
public CatchFlashlight(CatchPlayfield playfield, bool isRadiusBasedOnCombo, float initialRadius, float defaultFlashlightSize)
: base(isRadiusBasedOnCombo, initialRadius, defaultFlashlightSize)
public CatchFlashlight(CatchModFlashlight modFlashlight, CatchPlayfield playfield)
: base(modFlashlight)
{
this.playfield = playfield;
FlashlightSize = new Vector2(0, GetRadiusFor(0));
FlashlightSize = new Vector2(0, GetSizeFor(0));
}
protected override void Update()
@ -65,7 +65,7 @@ namespace osu.Game.Rulesets.Catch.Mods
protected override void OnComboChange(ValueChangedEvent<int> e)
{
this.TransformTo(nameof(FlashlightSize), new Vector2(0, GetRadiusFor(e.NewValue)), FLASHLIGHT_FADE_DURATION);
this.TransformTo(nameof(FlashlightSize), new Vector2(0, GetSizeFor(e.NewValue)), FLASHLIGHT_FADE_DURATION);
}
protected override string FragmentShader => "CircularFlashlight";

View File

@ -36,16 +36,16 @@ namespace osu.Game.Rulesets.Mania.Mods
public override float DefaultFlashlightSize => 50;
public override Flashlight CreateFlashlight() => new ManiaFlashlight(ComboBasedSize.Value, SizeMultiplier.Value, DefaultFlashlightSize);
protected override Flashlight CreateFlashlight() => new ManiaFlashlight(this);
private class ManiaFlashlight : Flashlight
{
private readonly LayoutValue flashlightProperties = new LayoutValue(Invalidation.DrawSize);
public ManiaFlashlight(bool isRadiusBasedOnCombo, float initialRadius, float defaultFlashlightSize)
: base(isRadiusBasedOnCombo, initialRadius, defaultFlashlightSize)
public ManiaFlashlight(ManiaModFlashlight modFlashlight)
: base(modFlashlight)
{
FlashlightSize = new Vector2(DrawWidth, GetRadiusFor(0));
FlashlightSize = new Vector2(DrawWidth, GetSizeFor(0));
AddLayout(flashlightProperties);
}
@ -65,7 +65,7 @@ namespace osu.Game.Rulesets.Mania.Mods
protected override void OnComboChange(ValueChangedEvent<int> e)
{
this.TransformTo(nameof(FlashlightSize), new Vector2(DrawWidth, GetRadiusFor(e.NewValue)), FLASHLIGHT_FADE_DURATION);
this.TransformTo(nameof(FlashlightSize), new Vector2(DrawWidth, GetSizeFor(e.NewValue)), FLASHLIGHT_FADE_DURATION);
}
protected override string FragmentShader => "RectangularFlashlight";

View File

@ -51,7 +51,7 @@ namespace osu.Game.Rulesets.Osu.Mods
private OsuFlashlight flashlight;
public override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight(ComboBasedSize.Value, SizeMultiplier.Value, FollowDelay.Value, DefaultFlashlightSize);
protected override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight(this);
public void ApplyToDrawableHitObject(DrawableHitObject drawable)
{
@ -61,17 +61,14 @@ namespace osu.Game.Rulesets.Osu.Mods
private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition
{
public double FollowDelay { private get; set; }
private readonly double followDelay;
//public float InitialRadius { private get; set; }
public bool ChangeRadius { private get; set; }
public OsuFlashlight(bool isRadiusBasedOnCombo, float initialRadius, double followDelay, float defaultFlashlightSize)
: base(isRadiusBasedOnCombo, initialRadius, defaultFlashlightSize)
public OsuFlashlight(OsuModFlashlight modFlashlight)
: base(modFlashlight)
{
FollowDelay = followDelay;
followDelay = modFlashlight.FollowDelay.Value;
FlashlightSize = new Vector2(0, GetRadiusFor(0));
FlashlightSize = new Vector2(0, GetSizeFor(0));
}
public void OnSliderTrackingChange(ValueChangedEvent<bool> e)
@ -86,14 +83,14 @@ namespace osu.Game.Rulesets.Osu.Mods
var destination = e.MousePosition;
FlashlightPosition = Interpolation.ValueAt(
Math.Min(Math.Abs(Clock.ElapsedFrameTime), FollowDelay), position, destination, 0, FollowDelay, Easing.Out);
Math.Min(Math.Abs(Clock.ElapsedFrameTime), followDelay), position, destination, 0, followDelay, Easing.Out);
return base.OnMouseMove(e);
}
protected override void OnComboChange(ValueChangedEvent<int> e)
{
this.TransformTo(nameof(FlashlightSize), new Vector2(0, GetRadiusFor(e.NewValue)), FLASHLIGHT_FADE_DURATION);
this.TransformTo(nameof(FlashlightSize), new Vector2(0, GetSizeFor(e.NewValue)), FLASHLIGHT_FADE_DURATION);
}
protected override string FragmentShader => "CircularFlashlight";

View File

@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
public override float DefaultFlashlightSize => 250;
public override Flashlight CreateFlashlight() => new TaikoFlashlight(playfield, ComboBasedSize.Value, SizeMultiplier.Value, DefaultFlashlightSize);
protected override Flashlight CreateFlashlight() => new TaikoFlashlight(this, playfield);
private TaikoPlayfield playfield;
@ -51,8 +51,8 @@ namespace osu.Game.Rulesets.Taiko.Mods
private readonly LayoutValue flashlightProperties = new LayoutValue(Invalidation.DrawSize);
private readonly TaikoPlayfield taikoPlayfield;
public TaikoFlashlight(TaikoPlayfield taikoPlayfield, bool isRadiusBasedOnCombo, float initialRadius, float defaultFlashlightSize)
: base(isRadiusBasedOnCombo, initialRadius, defaultFlashlightSize)
public TaikoFlashlight(TaikoModFlashlight modFlashlight, TaikoPlayfield taikoPlayfield)
: base(modFlashlight)
{
this.taikoPlayfield = taikoPlayfield;
FlashlightSize = getSizeFor(0);
@ -63,7 +63,7 @@ namespace osu.Game.Rulesets.Taiko.Mods
private Vector2 getSizeFor(int combo)
{
// Preserve flashlight size through the playfield's aspect adjustment.
return new Vector2(0, GetRadiusFor(combo) * taikoPlayfield.DrawHeight / TaikoPlayfield.DEFAULT_HEIGHT);
return new Vector2(0, GetSizeFor(combo) * taikoPlayfield.DrawHeight / TaikoPlayfield.DEFAULT_HEIGHT);
}
protected override void OnComboChange(ValueChangedEvent<int> e)

View File

@ -88,7 +88,7 @@ namespace osu.Game.Rulesets.Mods
flashlight.Breaks = drawableRuleset.Beatmap.Breaks;
}
public abstract Flashlight CreateFlashlight();
protected abstract Flashlight CreateFlashlight();
public abstract class Flashlight : Drawable
{
@ -102,17 +102,15 @@ namespace osu.Game.Rulesets.Mods
public List<BreakPeriod> Breaks;
public readonly bool IsRadiusBasedOnCombo;
private readonly float defaultFlashlightSize;
private readonly float sizeMultiplier;
private readonly bool comboBasedSize;
public readonly float InitialRadius;
public readonly float DefaultFlashlightSize;
protected Flashlight(bool isRadiusBasedOnCombo, float initialRadius, float defaultFlashlightSize)
protected Flashlight(ModFlashlight modFlashlight)
{
IsRadiusBasedOnCombo = isRadiusBasedOnCombo;
InitialRadius = initialRadius;
DefaultFlashlightSize = defaultFlashlightSize;
defaultFlashlightSize = modFlashlight.DefaultFlashlightSize;
sizeMultiplier = modFlashlight.SizeMultiplier.Value;
comboBasedSize = modFlashlight.ComboBasedSize.Value;
}
[BackgroundDependencyLoader]
@ -146,17 +144,19 @@ namespace osu.Game.Rulesets.Mods
protected abstract string FragmentShader { get; }
protected float GetRadiusFor(int combo)
protected float GetSizeFor(int combo)
{
if (IsRadiusBasedOnCombo)
float size = defaultFlashlightSize * sizeMultiplier;
if (comboBasedSize)
{
if (combo > 200)
return InitialRadius * 0.8f * DefaultFlashlightSize;
size *= 0.8f;
else if (combo > 100)
return InitialRadius * 0.9f * DefaultFlashlightSize;
size *= 0.9f;
}
return InitialRadius * DefaultFlashlightSize;
return size;
}
private Vector2 flashlightPosition;