From 5352da277d3cf46b3997d426b92ad8cb2510e4de Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 3 Aug 2017 08:16:19 +0930 Subject: [PATCH] Remove ScaleFixContainer. --- osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs | 214 +++++++------------ 1 file changed, 78 insertions(+), 136 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs index b0fb9d7f28..1f83e36c14 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs @@ -56,111 +56,104 @@ namespace osu.Game.Rulesets.Taiko.UI { AddRangeInternal(new Drawable[] { - new ScaleFixContainer + backgroundContainer = new Container { - RelativeSizeAxes = Axes.X, - Height = DEFAULT_PLAYFIELD_HEIGHT, - Children = new[] + Name = "Transparent playfield background", + RelativeSizeAxes = Axes.Both, + BorderThickness = 2, + Masking = true, + EdgeEffect = new EdgeEffectParameters { - backgroundContainer = new Container + Type = EdgeEffectType.Shadow, + Colour = Color4.Black.Opacity(0.2f), + Radius = 5, + }, + Children = new Drawable[] + { + background = new Box { - Name = "Transparent playfield background", RelativeSizeAxes = Axes.Both, - BorderThickness = 2, - Masking = true, - EdgeEffect = new EdgeEffectParameters - { - Type = EdgeEffectType.Shadow, - Colour = Color4.Black.Opacity(0.2f), - Radius = 5, - }, - Children = new Drawable[] - { - background = new Box - { - RelativeSizeAxes = Axes.Both, - Alpha = 0.6f - }, - } + Alpha = 0.6f }, + } + }, + new Container + { + Name = "Right area", + RelativeSizeAxes = Axes.Both, + Margin = new MarginPadding { Left = left_area_size }, + Children = new Drawable[] + { new Container { - Name = "Right area", + Name = "Masked elements", RelativeSizeAxes = Axes.Both, - Margin = new MarginPadding { Left = left_area_size }, + Padding = new MarginPadding { Left = HIT_TARGET_OFFSET }, + Masking = true, Children = new Drawable[] { - new Container + hitExplosionContainer = new Container + { + RelativeSizeAxes = Axes.Y, + BlendingMode = BlendingMode.Additive, + }, + barLineContainer = new Container { - Name = "Masked elements", RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding { Left = HIT_TARGET_OFFSET }, - Masking = true, - Children = new Drawable[] - { - hitExplosionContainer = new Container - { - RelativeSizeAxes = Axes.Y, - BlendingMode = BlendingMode.Additive, - }, - barLineContainer = new Container - { - RelativeSizeAxes = Axes.Both, - }, - new HitTarget - { - Anchor = Anchor.CentreLeft, - Origin = Anchor.Centre, - }, - hitObjectContainer = new Container - { - RelativeSizeAxes = Axes.Both, - }, - } }, - kiaiExplosionContainer = new Container + new HitTarget { - Name = "Kiai hit explosions", - RelativeSizeAxes = Axes.Y, - Margin = new MarginPadding { Left = HIT_TARGET_OFFSET }, - BlendingMode = BlendingMode.Additive + Anchor = Anchor.CentreLeft, + Origin = Anchor.Centre, }, - judgementContainer = new Container + hitObjectContainer = new Container { - Name = "Judgements", - RelativeSizeAxes = Axes.Y, - Margin = new MarginPadding { Left = HIT_TARGET_OFFSET }, - BlendingMode = BlendingMode.Additive + RelativeSizeAxes = Axes.Both, }, } }, - overlayBackgroundContainer = new Container + kiaiExplosionContainer = new Container { - Name = "Left overlay", - Size = new Vector2(left_area_size, DEFAULT_PLAYFIELD_HEIGHT), - BorderThickness = 1, - Children = new Drawable[] - { - overlayBackground = new Box - { - RelativeSizeAxes = Axes.Both, - }, - new InputDrum - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativePositionAxes = Axes.X, - Position = new Vector2(0.10f, 0), - Scale = new Vector2(0.9f) - }, - new Box - { - Anchor = Anchor.TopRight, - RelativeSizeAxes = Axes.Y, - Width = 10, - Colour = Framework.Graphics.Colour.ColourInfo.GradientHorizontal(Color4.Black.Opacity(0.6f), Color4.Black.Opacity(0)), - }, - } + Name = "Kiai hit explosions", + RelativeSizeAxes = Axes.Y, + Margin = new MarginPadding { Left = HIT_TARGET_OFFSET }, + BlendingMode = BlendingMode.Additive + }, + judgementContainer = new Container + { + Name = "Judgements", + RelativeSizeAxes = Axes.Y, + Margin = new MarginPadding { Left = HIT_TARGET_OFFSET }, + BlendingMode = BlendingMode.Additive + }, + } + }, + overlayBackgroundContainer = new Container + { + Name = "Left overlay", + RelativeSizeAxes = Axes.Y, + Size = new Vector2(left_area_size, 1), + BorderThickness = 1, + Children = new Drawable[] + { + overlayBackground = new Box + { + RelativeSizeAxes = Axes.Both, + }, + new InputDrum + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativePositionAxes = Axes.X, + Position = new Vector2(0.10f, 0), + Scale = new Vector2(0.9f) + }, + new Box + { + Anchor = Anchor.TopRight, + RelativeSizeAxes = Axes.Y, + Width = 10, + Colour = Framework.Graphics.Colour.ColourInfo.GradientHorizontal(Color4.Black.Opacity(0.6f), Color4.Black.Opacity(0)), }, } }, @@ -233,56 +226,5 @@ namespace osu.Game.Rulesets.Taiko.UI else hitExplosionContainer.Children.FirstOrDefault(e => e.Judgement == judgedObject.Judgement)?.VisualiseSecondHit(); } - - /// - /// This is a very special type of container. It serves a similar purpose to , however unlike , - /// this will only adjust the scale relative to the height of its parent and will maintain the original width relative to its parent. - /// - /// - /// By adjusting the scale relative to the height of its parent, the aspect ratio of this container's children is maintained, however this is undesirable - /// in the case where the hit object container should not have its width adjusted by scale. To counteract this, another container is nested inside this - /// container which takes care of reversing the width adjustment while appearing transparent to the user. - /// - /// - private class ScaleFixContainer : Container - { - protected override Container Content => widthAdjustmentContainer; - private readonly WidthAdjustmentContainer widthAdjustmentContainer; - - /// - /// We only want to apply DrawScale in the Y-axis to preserve aspect ratio and doesn't care about having its width adjusted. - /// - protected override Vector2 DrawScale => Scale * RelativeToAbsoluteFactor.Y / DrawHeight; - - public ScaleFixContainer() - { - AddInternal(widthAdjustmentContainer = new WidthAdjustmentContainer { ParentDrawScaleReference = () => DrawScale.X }); - } - - /// - /// The container type that reverses the width adjustment. - /// - private class WidthAdjustmentContainer : Container - { - /// - /// This container needs to know its parent's so it can reverse the width adjustment caused by . - /// - public Func ParentDrawScaleReference; - - public WidthAdjustmentContainer() - { - // This container doesn't care about height, it should always fill its parent - RelativeSizeAxes = Axes.Y; - } - - protected override void Update() - { - base.Update(); - - // Reverse the DrawScale adjustment - Width = Parent.DrawSize.X / ParentDrawScaleReference(); - } - } - } } } \ No newline at end of file