Add checks guarding against setting tracking on multiple trackingcongtainers and setting facade size

This commit is contained in:
David Zhao 2019-04-05 13:56:08 +09:00
parent 7047f305a1
commit b1d74e57e5
2 changed files with 27 additions and 23 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Reflection.Metadata.Ecma335;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.MathUtils;
@ -20,7 +21,24 @@ public class LogoTrackingContainer : Container
/// <summary>
/// Whether or not the logo assigned to this FacadeContainer should be tracking the position of its facade.
/// </summary>
public bool Tracking { get; set; }
public bool Tracking
{
get => tracking;
set
{
if (Logo != null)
{
if (value && !tracking && Logo.IsTracking)
throw new InvalidOperationException($"Cannot track an instance of {typeof(OsuLogo)} to multiple {typeof(LogoTrackingContainer)}s");
Logo.IsTracking = value;
}
tracking = value;
}
}
private bool tracking;
protected OsuLogo Logo;
@ -44,23 +62,15 @@ public LogoTrackingContainer()
/// <param name="easing">The easing type of the initial transform.</param>
public void SetLogo(OsuLogo logo, float facadeScale = 1.0f, double duration = 0, Easing easing = Easing.None)
{
if (Logo != logo)
if (Logo != logo && Logo != null)
{
if (logo?.HasTrackingContainer ?? throw new ArgumentNullException(nameof(logo)))
{
// Prevent the same logo from being added to multiple LogoTrackingContainers.
throw new InvalidOperationException($"Cannot add an instance of {typeof(OsuLogo)} to multiple {typeof(LogoTrackingContainer)}s");
}
if (Logo != null)
{
// If we're replacing the logo to be tracked, the old one no longer has a tracking container
Logo.HasTrackingContainer = false;
}
// If we're replacing the logo to be tracked, the old one no longer has a tracking container
Logo.IsTracking = false;
}
Logo = logo;
Logo.HasTrackingContainer = true;
Logo = logo ?? throw new ArgumentNullException(nameof(logo));
Logo.IsTracking = Tracking;
this.facadeScale = facadeScale;
this.duration = duration;
this.easing = easing;
@ -115,7 +125,7 @@ protected override void Update()
protected override void Dispose(bool isDisposing)
{
if (Logo != null)
Logo.HasTrackingContainer = false;
Tracking = false;
base.Dispose(isDisposing);
}
@ -124,12 +134,6 @@ protected override void Dispose(bool isDisposing)
private class ExposedFacade : Facade
{
public override Vector2 Size
{
get => base.Size;
set => throw new InvalidOperationException($"Cannot set the Size of a {typeof(Facade)} outside of a {typeof(LogoTrackingContainer)}");
}
public void SetSize(Vector2 size)
{
base.SetSize(size);

View File

@ -60,7 +60,7 @@ public class OsuLogo : BeatSyncedContainer
/// <remarks>Does not account for the scale of this <see cref="OsuLogo"/></remarks>
public float SizeForFlow => logo == null ? 0 : logo.DrawSize.X * logo.Scale.X * logoBounceContainer.Scale.X * logoHoverContainer.Scale.X;
public bool HasTrackingContainer { get; set; }
public bool IsTracking { get; set; }
private readonly Sprite ripple;