mirror of https://github.com/ppy/osu
Fix ScalableContainer irrepairably altering content size
This commit is contained in:
parent
cc70f7182a
commit
551ba6ac4b
|
@ -30,10 +30,10 @@ public CatchPlayfield(BeatmapDifficulty difficulty, Func<CatchHitObject, Drawabl
|
|||
Anchor = Anchor.TopCentre;
|
||||
Origin = Anchor.TopCentre;
|
||||
|
||||
ScaledContent.Anchor = Anchor.BottomLeft;
|
||||
ScaledContent.Origin = Anchor.BottomLeft;
|
||||
base.Content.Anchor = Anchor.BottomLeft;
|
||||
base.Content.Origin = Anchor.BottomLeft;
|
||||
|
||||
ScaledContent.AddRange(new Drawable[]
|
||||
base.Content.AddRange(new Drawable[]
|
||||
{
|
||||
explodingFruitContainer = new Container
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ public override List<InputState> GetPendingStates()
|
|||
{
|
||||
new ReplayState<OsuAction>
|
||||
{
|
||||
Mouse = new ReplayMouseState(ToScreenSpace(Position ?? Vector2.Zero)),
|
||||
Mouse = new ReplayMouseState(GamefieldToScreenSpace(Position ?? Vector2.Zero)),
|
||||
PressedActions = CurrentFrame.Actions
|
||||
}
|
||||
};
|
||||
|
|
|
@ -122,7 +122,7 @@ public TestPlayfield(ScrollingDirection direction)
|
|||
Direction = direction;
|
||||
|
||||
Padding = new MarginPadding(2);
|
||||
ScaledContent.Masking = true;
|
||||
Content.Masking = true;
|
||||
|
||||
AddInternal(new Box
|
||||
{
|
||||
|
|
|
@ -13,9 +13,9 @@ namespace osu.Game.Input.Handlers
|
|||
public abstract class ReplayInputHandler : InputHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// A function provided to convert replay coordinates from gamefield to screen space.
|
||||
/// A function that converts coordinates from gamefield to screen space.
|
||||
/// </summary>
|
||||
public Func<Vector2, Vector2> ToScreenSpace { protected get; set; }
|
||||
public Func<Vector2, Vector2> GamefieldToScreenSpace { protected get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Update the current frame based on an incoming time value.
|
||||
|
|
|
@ -290,7 +290,7 @@ public override void SetReplay(Replay replay)
|
|||
base.SetReplay(replay);
|
||||
|
||||
if (ReplayInputManager?.ReplayInputHandler != null)
|
||||
ReplayInputManager.ReplayInputHandler.ToScreenSpace = input => Playfield.ScaledContent.ToScreenSpace(input);
|
||||
ReplayInputManager.ReplayInputHandler.GamefieldToScreenSpace = Playfield.GamefieldToScreenSpace;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using OpenTK;
|
||||
|
@ -12,13 +13,16 @@ namespace osu.Game.Rulesets.UI
|
|||
/// </summary>
|
||||
public class ScalableContainer : Container
|
||||
{
|
||||
/// <summary>
|
||||
/// A function that converts coordinates from gamefield to screen space.
|
||||
/// </summary>
|
||||
public Func<Vector2, Vector2> GamefieldToScreenSpace => scaledContent.GamefieldToScreenSpace;
|
||||
|
||||
/// <summary>
|
||||
/// The scaled content.
|
||||
/// </summary>
|
||||
public readonly Container ScaledContent;
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
private readonly Container content;
|
||||
private readonly ScaledContainer scaledContent;
|
||||
protected override Container<Drawable> Content => scaledContent;
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Container"/> which can have its internal coordinate system scaled to a specific size.
|
||||
|
@ -31,17 +35,21 @@ public class ScalableContainer : Container
|
|||
/// </param>
|
||||
public ScalableContainer(float? customWidth = null, float? customHeight = null)
|
||||
{
|
||||
AddInternal(ScaledContent = new ScaledContainer
|
||||
AddInternal(scaledContent = new ScaledContainer
|
||||
{
|
||||
CustomWidth = customWidth,
|
||||
CustomHeight = customHeight,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = content = new Container { RelativeSizeAxes = Axes.Both }
|
||||
});
|
||||
}
|
||||
|
||||
private class ScaledContainer : Container
|
||||
{
|
||||
/// <summary>
|
||||
/// A function that converts coordinates from gamefield to screen space.
|
||||
/// </summary>
|
||||
public Func<Vector2, Vector2> GamefieldToScreenSpace => content.ToScreenSpace;
|
||||
|
||||
/// <summary>
|
||||
/// The value to scale the width of the content to match.
|
||||
/// If null, <see cref="CustomHeight"/> is used.
|
||||
|
@ -54,6 +62,22 @@ private class ScaledContainer : Container
|
|||
/// </summary>
|
||||
public float? CustomHeight;
|
||||
|
||||
private readonly Container content;
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
public ScaledContainer()
|
||||
{
|
||||
AddInternal(content = new Container { RelativeSizeAxes = Axes.Both });
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
content.Scale = sizeScale;
|
||||
content.Size = Vector2.Divide(Vector2.One, sizeScale);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The scale that is required for the size of the content to match <see cref="CustomWidth"/> and <see cref="CustomHeight"/>.
|
||||
/// </summary>
|
||||
|
@ -70,17 +94,6 @@ private Vector2 sizeScale
|
|||
return Vector2.One;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scale the content to the required container size by multiplying by <see cref="sizeScale"/>.
|
||||
/// </summary>
|
||||
protected override Vector2 DrawScale => sizeScale * base.DrawScale;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
RelativeChildSize = new Vector2(CustomWidth.HasValue ? sizeScale.X : RelativeChildSize.X, CustomHeight.HasValue ? sizeScale.Y : RelativeChildSize.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue