diff --git a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs index 102ec7fb3b..ecd1142b52 100644 --- a/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs +++ b/osu.Game.Rulesets.Catch/UI/CatchPlayfield.cs @@ -25,7 +25,6 @@ namespace osu.Game.Rulesets.Catch.UI protected override bool UserScrollSpeedAdjustment => false; public CatchPlayfield(BeatmapDifficulty difficulty, Func> getVisualRepresentation) - : base(BASE_WIDTH) { Direction.Value = ScrollingDirection.Down; @@ -34,27 +33,36 @@ namespace osu.Game.Rulesets.Catch.UI Anchor = Anchor.TopCentre; Origin = Anchor.TopCentre; - base.Content.Anchor = Anchor.BottomLeft; - base.Content.Origin = Anchor.BottomLeft; - - base.Content.AddRange(new Drawable[] + InternalChild = new Container { - explodingFruitContainer = new Container + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + FillMode = FillMode.Fit, + FillAspectRatio = 4f / 3, + Child = new ScalingContainer(BASE_WIDTH) { RelativeSizeAxes = Axes.Both, - }, - catcherArea = new CatcherArea(difficulty) - { - GetVisualRepresentation = getVisualRepresentation, - ExplodingFruitTarget = explodingFruitContainer, - Anchor = Anchor.BottomLeft, - Origin = Anchor.TopLeft, - }, - content = new Container - { - RelativeSizeAxes = Axes.Both, - }, - }); + Children = new Drawable[] + { + explodingFruitContainer = new Container + { + RelativeSizeAxes = Axes.Both, + }, + catcherArea = new CatcherArea(difficulty) + { + GetVisualRepresentation = getVisualRepresentation, + ExplodingFruitTarget = explodingFruitContainer, + Anchor = Anchor.BottomLeft, + Origin = Anchor.TopLeft, + }, + content = new Container + { + RelativeSizeAxes = Axes.Both, + }, + } + } + }; } public bool CheckIfWeCanCatch(CatchHitObject obj) => catcherArea.AttemptCatch(obj); diff --git a/osu.Game.Rulesets.Catch/UI/ScalingContainer.cs b/osu.Game.Rulesets.Catch/UI/ScalingContainer.cs new file mode 100644 index 0000000000..a2011dcc6f --- /dev/null +++ b/osu.Game.Rulesets.Catch/UI/ScalingContainer.cs @@ -0,0 +1,29 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics.Containers; +using OpenTK; + +namespace osu.Game.Rulesets.Catch.UI +{ + /// + /// A which scales its content relative to a target width. + /// + public class ScalingContainer : Container + { + private readonly float targetWidth; + + public ScalingContainer(float targetWidth) + { + this.targetWidth = targetWidth; + } + + protected override void Update() + { + base.Update(); + + Scale = new Vector2(Parent.ChildSize.X / targetWidth); + Size = Vector2.Divide(Vector2.One, Scale); + } + } +} diff --git a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs index dce1fc2851..bec7d1fe26 100644 --- a/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs +++ b/osu.Game.Rulesets.Osu/Edit/OsuHitObjectComposer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Tools; @@ -31,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.Edit new HitObjectCompositionTool() }; - protected override ScalableContainer CreateLayerContainer() => new ScalableContainer(OsuPlayfield.BASE_SIZE.X) { RelativeSizeAxes = Axes.Both }; + protected override Container CreateLayerContainer() => new LayerContainer(); public override HitObjectMask CreateMaskFor(DrawableHitObject hitObject) { @@ -45,5 +46,20 @@ namespace osu.Game.Rulesets.Osu.Edit return base.CreateMaskFor(hitObject); } + + private class LayerContainer : Container + { + protected override Container Content => content; + private readonly Container content; + + public LayerContainer() + { + RelativeSizeAxes = Axes.Both; + FillMode = FillMode.Fit; + FillAspectRatio = 4f / 3; + + Child = content = new ScalingContainer(OsuPlayfield.BASE_SIZE.X) { RelativeSizeAxes = Axes.Both }; + } + } } } diff --git a/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs b/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs index 61937a535c..b6e4ae62a9 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuPlayfield.cs @@ -20,32 +20,46 @@ namespace osu.Game.Rulesets.Osu.UI private readonly JudgementContainer judgementLayer; private readonly ConnectionRenderer connectionLayer; + private readonly Container content; + protected override Container Content => content; + public static readonly Vector2 BASE_SIZE = new Vector2(512, 384); public OsuPlayfield() - : base(BASE_SIZE.X) { Anchor = Anchor.Centre; Origin = Anchor.Centre; - AddRange(new Drawable[] + InternalChild = new Container { - connectionLayer = new FollowPointRenderer + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + FillMode = FillMode.Fit, + FillAspectRatio = 4f / 3, + Child = content = new ScalingContainer(BASE_SIZE.X) { RelativeSizeAxes = Axes.Both, - Depth = 2, - }, - judgementLayer = new JudgementContainer - { - RelativeSizeAxes = Axes.Both, - Depth = 1, - }, - approachCircles = new Container - { - RelativeSizeAxes = Axes.Both, - Depth = -1, - }, - }); + Children = new Drawable[] + { + connectionLayer = new FollowPointRenderer + { + RelativeSizeAxes = Axes.Both, + Depth = 2, + }, + judgementLayer = new JudgementContainer + { + RelativeSizeAxes = Axes.Both, + Depth = 1, + }, + approachCircles = new Container + { + RelativeSizeAxes = Axes.Both, + Depth = -1, + }, + } + } + }; } public override void Add(DrawableHitObject h) diff --git a/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs b/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs index 4bc6992445..0ea8d3ede8 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs @@ -4,7 +4,6 @@ using System.Linq; using osu.Framework.Graphics.Cursor; using osu.Framework.Input; -using OpenTK; using osu.Game.Beatmaps; using osu.Game.Input.Handlers; using osu.Game.Rulesets.Objects.Drawables; @@ -58,12 +57,6 @@ namespace osu.Game.Rulesets.Osu.UI } } - protected override Vector2 GetAspectAdjustedSize() - { - var aspectSize = DrawSize.X * 0.75f < DrawSize.Y ? new Vector2(DrawSize.X, DrawSize.X * 0.75f) : new Vector2(DrawSize.Y * 4f / 3f, DrawSize.Y); - return new Vector2(aspectSize.X / DrawSize.X, aspectSize.Y / DrawSize.Y); - } - protected override CursorContainer CreateCursor() => new GameplayCursor(); } } diff --git a/osu.Game.Rulesets.Osu/UI/ScalingContainer.cs b/osu.Game.Rulesets.Osu/UI/ScalingContainer.cs new file mode 100644 index 0000000000..0a9bec67fb --- /dev/null +++ b/osu.Game.Rulesets.Osu/UI/ScalingContainer.cs @@ -0,0 +1,29 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics.Containers; +using OpenTK; + +namespace osu.Game.Rulesets.Osu.UI +{ + /// + /// A which scales its content relative to a target width. + /// + public class ScalingContainer : Container + { + private readonly float targetWidth; + + public ScalingContainer(float targetWidth) + { + this.targetWidth = targetWidth; + } + + protected override void Update() + { + base.Update(); + + Scale = new Vector2(Parent.ChildSize.X / targetWidth); + Size = Vector2.Divide(Vector2.One, Scale); + } + } +} diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index a3253250f2..8060ac742a 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -165,6 +165,6 @@ namespace osu.Game.Rulesets.Edit /// /// Creates a which provides a layer above or below the . /// - protected virtual ScalableContainer CreateLayerContainer() => new ScalableContainer { RelativeSizeAxes = Axes.Both }; + protected virtual Container CreateLayerContainer() => new Container { RelativeSizeAxes = Axes.Both }; } } diff --git a/osu.Game/Rulesets/UI/Playfield.cs b/osu.Game/Rulesets/UI/Playfield.cs index e090a18eda..a8dc096a1d 100644 --- a/osu.Game/Rulesets/UI/Playfield.cs +++ b/osu.Game/Rulesets/UI/Playfield.cs @@ -9,18 +9,25 @@ using osu.Game.Rulesets.Objects.Drawables; using osu.Framework.Allocation; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Configuration; +using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Rulesets.Mods; +using OpenTK; namespace osu.Game.Rulesets.UI { - public abstract class Playfield : ScalableContainer + public abstract class Playfield : Container { /// /// The contained in this Playfield. /// public HitObjectContainer HitObjectContainer { get; private set; } + /// + /// A function that converts gamefield coordinates to screen space. + /// + public Func GamefieldToScreenSpace => HitObjectContainer.ToScreenSpace; + /// /// All the s contained in this and all . /// @@ -39,16 +46,9 @@ namespace osu.Game.Rulesets.UI public readonly BindableBool DisplayJudgements = new BindableBool(true); /// - /// A container for keeping track of DrawableHitObjects. + /// Creates a new . /// - /// The width to scale the internal coordinate space to. - /// May be null if scaling based on is desired. If is also null, no scaling will occur. - /// - /// The height to scale the internal coordinate space to. - /// May be null if scaling based on is desired. If is also null, no scaling will occur. - /// - protected Playfield(float? customWidth = null, float? customHeight = null) - : base(customWidth, customHeight) + protected Playfield() { RelativeSizeAxes = Axes.Both; } diff --git a/osu.Game/Rulesets/UI/ScalableContainer.cs b/osu.Game/Rulesets/UI/ScalableContainer.cs deleted file mode 100644 index 5ee03be7ee..0000000000 --- a/osu.Game/Rulesets/UI/ScalableContainer.cs +++ /dev/null @@ -1,99 +0,0 @@ -// 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; - -namespace osu.Game.Rulesets.UI -{ - /// - /// A which can have its internal coordinate system scaled to a specific size. - /// - public class ScalableContainer : Container - { - /// - /// A function that converts coordinates from gamefield to screen space. - /// - public Func GamefieldToScreenSpace => scaledContent.GamefieldToScreenSpace; - - /// - /// The scaled content. - /// - private readonly ScaledContainer scaledContent; - protected override Container Content => scaledContent; - - /// - /// A which can have its internal coordinate system scaled to a specific size. - /// - /// The width to scale the internal coordinate space to. - /// May be null if scaling based on is desired. If is also null, no scaling will occur. - /// - /// The height to scale the internal coordinate space to. - /// May be null if scaling based on is desired. If is also null, no scaling will occur. - /// - public ScalableContainer(float? customWidth = null, float? customHeight = null) - { - AddInternal(scaledContent = new ScaledContainer - { - CustomWidth = customWidth, - CustomHeight = customHeight, - 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. - /// - public float? CustomWidth; - - /// - /// The value to scale the height of the content to match. - /// if null, is used. - /// - 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 . - /// - private Vector2 sizeScale - { - get - { - if (CustomWidth.HasValue && CustomHeight.HasValue) - return Vector2.Divide(DrawSize, new Vector2(CustomWidth.Value, CustomHeight.Value)); - if (CustomWidth.HasValue) - return new Vector2(DrawSize.X / CustomWidth.Value); - if (CustomHeight.HasValue) - return new Vector2(DrawSize.Y / CustomHeight.Value); - return Vector2.One; - } - } - } - } -} diff --git a/osu.Game/Rulesets/UI/Scrolling/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/Scrolling/ScrollingPlayfield.cs index ec73c0fb14..b555b6616a 100644 --- a/osu.Game/Rulesets/UI/Scrolling/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/Scrolling/ScrollingPlayfield.cs @@ -62,20 +62,6 @@ namespace osu.Game.Rulesets.UI.Scrolling /// protected readonly Bindable Direction = new Bindable(); - /// - /// Creates a new . - /// - /// The width to scale the internal coordinate space to. - /// May be null if scaling based on is desired. If is also null, no scaling will occur. - /// - /// The height to scale the internal coordinate space to. - /// May be null if scaling based on is desired. If is also null, no scaling will occur. - /// - protected ScrollingPlayfield(float? customWidth = null, float? customHeight = null) - : base(customWidth, customHeight) - { - } - [BackgroundDependencyLoader] private void load() {