diff --git a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs index 8bb206543b..2b6a7c41f4 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs @@ -30,10 +30,10 @@ public CatchPlayfield(BeatmapDifficulty difficulty, Func GetPendingStates() { new ReplayState { - Mouse = new ReplayMouseState(ToScreenSpace(Position ?? Vector2.Zero)), + Mouse = new ReplayMouseState(GamefieldToScreenSpace(Position ?? Vector2.Zero)), PressedActions = CurrentFrame.Actions } }; diff --git a/osu.Game.Tests/Visual/TestCaseScrollingHitObjects.cs b/osu.Game.Tests/Visual/TestCaseScrollingHitObjects.cs index 745ae9ad9d..0742dd68eb 100644 --- a/osu.Game.Tests/Visual/TestCaseScrollingHitObjects.cs +++ b/osu.Game.Tests/Visual/TestCaseScrollingHitObjects.cs @@ -122,7 +122,7 @@ public TestPlayfield(ScrollingDirection direction) Direction = direction; Padding = new MarginPadding(2); - ScaledContent.Masking = true; + Content.Masking = true; AddInternal(new Box { diff --git a/osu.Game/Input/Handlers/ReplayInputHandler.cs b/osu.Game/Input/Handlers/ReplayInputHandler.cs index 8aa3a53cc2..c431af0219 100644 --- a/osu.Game/Input/Handlers/ReplayInputHandler.cs +++ b/osu.Game/Input/Handlers/ReplayInputHandler.cs @@ -13,9 +13,9 @@ namespace osu.Game.Input.Handlers public abstract class ReplayInputHandler : InputHandler { /// - /// A function provided to convert replay coordinates from gamefield to screen space. + /// A function that converts coordinates from gamefield to screen space. /// - public Func ToScreenSpace { protected get; set; } + public Func GamefieldToScreenSpace { protected get; set; } /// /// Update the current frame based on an incoming time value. diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index 2201b6963f..81418fecd4 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -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; } /// diff --git a/osu.Game/Rulesets/UI/ScalableContainer.cs b/osu.Game/Rulesets/UI/ScalableContainer.cs index 9762828e7d..04e6db9578 100644 --- a/osu.Game/Rulesets/UI/ScalableContainer.cs +++ b/osu.Game/Rulesets/UI/ScalableContainer.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // 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 /// public class ScalableContainer : Container { + /// + /// A function that converts coordinates from gamefield to screen space. + /// + public Func GamefieldToScreenSpace => scaledContent.GamefieldToScreenSpace; + /// /// The scaled content. /// - public readonly Container ScaledContent; - - protected override Container Content => content; - private readonly Container content; + private readonly ScaledContainer scaledContent; + protected override Container Content => scaledContent; /// /// A which can have its internal coordinate system scaled to a specific size. @@ -31,17 +35,21 @@ public class ScalableContainer : Container /// 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 { + /// + /// A function that converts coordinates from gamefield to screen space. + /// + public Func GamefieldToScreenSpace => content.ToScreenSpace; + /// /// The value to scale the width of the content to match. /// If null, is used. @@ -54,6 +62,22 @@ private class ScaledContainer : Container /// public float? CustomHeight; + private readonly Container content; + protected override Container 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); + } + /// /// The scale that is required for the size of the content to match and . /// @@ -70,17 +94,6 @@ private Vector2 sizeScale return Vector2.One; } } - - /// - /// Scale the content to the required container size by multiplying by . - /// - 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); - } } } }