Apply reviews

This commit is contained in:
David Zhao 2019-04-08 15:24:09 +09:00
parent 46ecaf3d6c
commit a690302d00
6 changed files with 59 additions and 71 deletions

View File

@ -36,7 +36,7 @@ public TestCaseButtonSystem()
RelativeSizeAxes = Axes.Both,
},
buttons = new ButtonSystem(),
logo = new OsuLogo()
logo = new OsuLogo { RelativePositionAxes = Axes.Both }
};
buttons.SetOsuLogo(logo);

View File

@ -73,7 +73,7 @@ public void MoveFacadeTest()
{
AddToggleStep("Toggle move continuously", b => randomPositions = b);
AddStep("Add tracking containers", addFacadeContainers);
AddStep("Move facade to random position", startTrackingRandom);
AddStep("Move facade to random position", moveLogoFacade);
waitForMove();
AddAssert("Logo is tracking", () => trackingContainer.IsLogoTracking);
}
@ -85,7 +85,7 @@ public void MoveFacadeTest()
public void RemoveFacadeTest()
{
AddStep("Add tracking containers", addFacadeContainers);
AddStep("Move facade to random position", startTrackingRandom);
AddStep("Move facade to random position", moveLogoFacade);
AddStep("Remove facade from FacadeContainer", removeFacade);
waitForMove();
AddAssert("Logo is not tracking", () => !trackingContainer.IsLogoTracking);
@ -98,7 +98,7 @@ public void RemoveFacadeTest()
public void TransferFacadeTest()
{
AddStep("Add tracking containers", addFacadeContainers);
AddStep("Move facade to random position", startTrackingRandom);
AddStep("Move facade to random position", moveLogoFacade);
AddStep("Remove facade from FacadeContainer", removeFacade);
AddStep("Transfer facade to a new container", () =>
{
@ -171,14 +171,14 @@ public void FlowContainerTest()
AddStep("Perform logo movements", () =>
{
trackingContainer.Tracking = false;
trackingContainer.StopTracking();
logo.MoveTo(new Vector2(0.5f), 500, Easing.InOutExpo);
trackingContainer.SetLogo(logo, 1.0f, 1000, Easing.InOutExpo);
visualBox.Colour = Color4.White;
Scheduler.AddDelayed(() =>
{
trackingContainer.Tracking = true;
trackingContainer.StartTracking(logo, 1000, Easing.InOutExpo);
visualBox.Colour = Color4.Tomato;
}, 700);
});
@ -221,14 +221,13 @@ public void SetMultipleContainersTest()
failed = false;
newContainer = new LogoTrackingContainer();
addFacadeContainers();
startTrackingRandom();
newContainer.SetLogo(logo);
moveLogoFacade();
});
AddStep("Try tracking new container", () =>
{
try
{
newContainer.Tracking = true;
newContainer.StartTracking(logo);
}
catch (Exception e)
{
@ -268,7 +267,7 @@ private void addFacadeContainers()
});
trackingContainer.Add(logoFacade = trackingContainer.LogoFacade);
trackingContainer.SetLogo(logo, 1.0f, 1000);
trackingContainer.StartTracking(logo, 1000);
}
private void waitForMove(int count = 5) => AddWaitStep("Wait for transforms to finish", count);
@ -280,12 +279,6 @@ private void removeFacade()
moveLogoFacade();
}
private void startTrackingRandom()
{
trackingContainer.Tracking = true;
moveLogoFacade();
}
private void moveLogoFacade()
{
if (logoFacade?.Transforms.Count == 0 && transferContainer?.Transforms.Count == 0)
@ -304,7 +297,7 @@ private class TestLogoTrackingContainer : LogoTrackingContainer
/// <summary>
/// Check that the logo is tracking the position of the facade, with an acceptable precision lenience.
/// </summary>
public bool IsLogoTracking => Precision.AlmostEquals(Logo.Position, LogoTrackingPosition);
public bool IsLogoTracking => Precision.AlmostEquals(Logo.Position, ComputeLogoTrackingPosition());
}
}
}

View File

@ -17,29 +17,9 @@ public class LogoTrackingContainer : Container
{
public Facade LogoFacade { get; }
/// <summary>
/// Whether or not the logo assigned to this FacadeContainer should be tracking the position of its facade.
/// </summary>
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");
protected OsuLogo Logo => logo;
Logo.IsTracking = value;
}
tracking = value;
}
}
protected OsuLogo Logo;
private float facadeScale;
private OsuLogo logo;
private Easing easing;
private Vector2? startPosition;
private double? startTime;
@ -58,27 +38,38 @@ public LogoTrackingContainer()
/// <param name="facadeScale">The scale of the facade. Does not actually affect the logo itself.</param>
/// <param name="duration">The duration of the initial transform. Default is instant.</param>
/// <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)
public void StartTracking(OsuLogo logo, double duration = 0, Easing easing = Easing.None)
{
if (Logo != logo && Logo != null)
if (logo == null)
throw new ArgumentNullException(nameof(logo));
if (logo.IsTracking && tracking == false)
throw new InvalidOperationException($"Cannot track an instance of {typeof(OsuLogo)} to multiple {typeof(LogoTrackingContainer)}s");
if (this.logo != logo && this.logo != null)
{
// If we're replacing the logo to be tracked, the old one no longer has a tracking container
Logo.IsTracking = false;
this.logo.IsTracking = false;
}
Logo = logo ?? throw new ArgumentNullException(nameof(logo));
this.logo = logo;
this.logo.IsTracking = true;
if (Tracking)
{
Logo.IsTracking = true;
}
this.facadeScale = facadeScale;
this.duration = duration;
this.easing = easing;
startTime = null;
startPosition = null;
tracking = true;
}
public void StopTracking()
{
if (logo != null)
logo.IsTracking = false;
tracking = false;
}
/// <summary>
@ -86,20 +77,27 @@ public void SetLogo(OsuLogo logo, float facadeScale = 1.0f, double duration = 0,
/// Manually performs a conversion of the Facade's position to the Logo's parent's relative space.
/// </summary>
/// <remarks>Will only be correct if the logo's <see cref="Drawable.RelativePositionAxes"/> are set to Axes.Both</remarks>
protected Vector2 LogoTrackingPosition => new Vector2(Logo.Parent.ToLocalSpace(LogoFacade.ScreenSpaceDrawQuad.Centre).X / Logo.Parent.RelativeToAbsoluteFactor.X,
Logo.Parent.ToLocalSpace(LogoFacade.ScreenSpaceDrawQuad.Centre).Y / Logo.Parent.RelativeToAbsoluteFactor.Y);
protected Vector2 ComputeLogoTrackingPosition()
{
var absolutePos = Logo.Parent.ToLocalSpace(LogoFacade.ScreenSpaceDrawQuad.Centre);
return new Vector2(absolutePos.X / Logo.Parent.RelativeToAbsoluteFactor.X,
absolutePos.Y / Logo.Parent.RelativeToAbsoluteFactor.Y);
}
protected override void Update()
{
base.Update();
if (Logo == null || !Tracking)
if (Logo == null || !tracking)
return;
// Account for the scale of the actual OsuLogo, as SizeForFlow only accounts for the sprite scale.
((ExposedFacade)LogoFacade).SetSize(new Vector2(Logo.SizeForFlow * Logo.Scale.X * facadeScale));
((ExposedFacade)LogoFacade).SetSize(new Vector2(Logo.SizeForFlow * Logo.Scale.X));
if (LogoFacade.Parent != null && Logo.Position != LogoTrackingPosition && Logo.RelativePositionAxes == Axes.Both)
var localPos = ComputeLogoTrackingPosition();
if (LogoFacade.Parent != null && Logo.Position != localPos && Logo.RelativePositionAxes == Axes.Both)
{
// If this is our first update since tracking has started, initialize our starting values for interpolation
if (startTime == null || startPosition == null)
@ -115,11 +113,11 @@ protected override void Update()
var amount = (float)Interpolation.ApplyEasing(easing, Math.Min(elapsedDuration / duration, 1));
// Interpolate the position of the logo, where amount 0 is where the logo was when it first began interpolating, and amount 1 is the target location.
Logo.Position = Vector2.Lerp((Vector2)startPosition, LogoTrackingPosition, amount);
Logo.Position = Vector2.Lerp((Vector2)startPosition, localPos, amount);
}
else
{
Logo.Position = LogoTrackingPosition;
Logo.Position = localPos;
}
}
}
@ -127,7 +125,7 @@ protected override void Update()
protected override void Dispose(bool isDisposing)
{
if (Logo != null)
Tracking = false;
Logo.IsTracking = false;
base.Dispose(isDisposing);
}

View File

@ -60,17 +60,17 @@ public void SetOsuLogo(OsuLogo logo)
if (this.logo != null)
{
this.logo.Action = onOsuLogo;
logoTrackingContainer.SetLogo(logo, 0.74f);
// osuLogo.SizeForFlow relies on loading to be complete.
buttonArea.Flow.Position = new Vector2(WEDGE_WIDTH * 2 - (BUTTON_WIDTH + this.logo.SizeForFlow / 4), 0);
logoTrackingContainer.LogoFacade.Scale = new Vector2(0.74f);
updateLogoState();
}
else
{
// We should stop tracking as the facade is now out of scope.
logoTrackingContainer.Tracking = false;
logoTrackingContainer.StopTracking();
}
}
@ -271,7 +271,7 @@ private void updateLogoState(ButtonSystemState lastState = ButtonSystemState.Ini
logoDelayedAction?.Cancel();
logoDelayedAction = Scheduler.AddDelayed(() =>
{
logoTrackingContainer.Tracking = false;
logoTrackingContainer.StopTracking();
game?.Toolbar.Hide();
@ -294,8 +294,7 @@ private void updateLogoState(ButtonSystemState lastState = ButtonSystemState.Ini
if (lastState == ButtonSystemState.Initial)
logo.ScaleTo(0.5f, 200, Easing.In);
logoTrackingContainer.SetLogo(logo, 0.74f, lastState == ButtonSystemState.EnteringMode ? 0 : 200, Easing.In);
logoTrackingContainer.Tracking = true;
logoTrackingContainer.StartTracking(logo, lastState == ButtonSystemState.EnteringMode ? 0 : 200, Easing.In);
logoDelayedAction?.Cancel();
logoDelayedAction = Scheduler.AddDelayed(() =>
@ -308,14 +307,14 @@ private void updateLogoState(ButtonSystemState lastState = ButtonSystemState.Ini
break;
default:
logo.ClearTransforms(targetMember: nameof(Position));
logoTrackingContainer.Tracking = true;
logoTrackingContainer.StartTracking(logo, 0, Easing.In);
logo.ScaleTo(0.5f, 200, Easing.OutQuint);
break;
}
break;
case ButtonSystemState.EnteringMode:
logoTrackingContainer.Tracking = true;
logoTrackingContainer.StartTracking(logo, 0, Easing.In);
break;
}
}

View File

@ -29,7 +29,7 @@ public override Vector2 OriginPosition
if (CentreTarget == null)
return base.OriginPosition;
return CentreTarget.DrawPosition + CentreTarget.DrawSize / 2;
return CentreTarget.DrawPosition + CentreTarget.DrawSize / 2 * CentreTarget.Scale;
}
}
}

View File

@ -128,7 +128,7 @@ private void contentIn()
private void contentOut()
{
// Ensure the logo is no longer tracking before we scale the content
content.Tracking = false;
content.StopTracking();
content.ScaleTo(0.7f, 300, Easing.InQuint);
content.FadeOut(250);
@ -161,15 +161,13 @@ protected override void LogoArriving(OsuLogo logo, bool resuming)
logo.ScaleTo(new Vector2(0.15f), duration, Easing.In);
logo.FadeIn(350);
content.SetLogo(logo, 1.0f, resuming ? 0 : 500, Easing.InOutExpo);
Scheduler.AddDelayed(() => { content.Tracking = true; }, resuming ? 0 : 500);
Scheduler.AddDelayed(() => { content.StartTracking(logo, resuming ? 0 : 500, Easing.InOutExpo); }, resuming ? 0 : 500);
}
protected override void LogoExiting(OsuLogo logo)
{
base.LogoExiting(logo);
content.Tracking = false;
content.StopTracking();
}
protected override void LoadComplete()