From c1b01308579e057a9748df8f66583f5fe89b3cc4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 Jul 2019 16:17:02 +0900 Subject: [PATCH 1/6] Add legacy cursormiddle support --- osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs | 133 +++++++++++-------- osu.Game/Skinning/LegacySkin.cs | 39 ++++++ 2 files changed, 115 insertions(+), 57 deletions(-) diff --git a/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs b/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs index ea81527fa9..37ac972f41 100644 --- a/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs +++ b/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs @@ -18,6 +18,8 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor { public class OsuCursor : SkinReloadableDrawable { + private const float size = 28; + private bool cursorExpand; private Bindable cursorScale; @@ -30,7 +32,8 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor public OsuCursor() { Origin = Anchor.Centre; - Size = new Vector2(28); + + Size = new Vector2(size); } protected override void SkinChanged(ISkinSource skin, bool allowFallback) @@ -46,62 +49,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor RelativeSizeAxes = Axes.Both, Origin = Anchor.Centre, Anchor = Anchor.Centre, - Child = scaleTarget = new SkinnableDrawable("cursor", _ => new CircularContainer - { - RelativeSizeAxes = Axes.Both, - Masking = true, - BorderThickness = Size.X / 6, - BorderColour = Color4.White, - EdgeEffect = new EdgeEffectParameters - { - Type = EdgeEffectType.Shadow, - Colour = Color4.Pink.Opacity(0.5f), - Radius = 5, - }, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Alpha = 0, - AlwaysPresent = true, - }, - new CircularContainer - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Masking = true, - BorderThickness = Size.X / 3, - BorderColour = Color4.White.Opacity(0.5f), - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Alpha = 0, - AlwaysPresent = true, - }, - }, - }, - new CircularContainer - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Scale = new Vector2(0.1f), - Masking = true, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Color4.White, - }, - }, - }, - } - }, confineMode: ConfineMode.NoScaling) + Child = scaleTarget = new SkinnableDrawable("osu/Game/Rulesets/Osu/UI/Cursor/OsuCursor", _ => new DefaultCursor(), confineMode: ConfineMode.NoScaling) { Origin = Anchor.Centre, Anchor = Anchor.Centre, @@ -144,5 +92,76 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor } public void Contract() => expandTarget.ScaleTo(released_scale, 100, Easing.OutQuad); + + private class DefaultCursor : CompositeDrawable + { + public DefaultCursor() + { + RelativeSizeAxes = Axes.Both; + + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + + InternalChildren = new Drawable[] + { + new CircularContainer + { + RelativeSizeAxes = Axes.Both, + Masking = true, + BorderThickness = size / 6, + BorderColour = Color4.White, + EdgeEffect = new EdgeEffectParameters + { + Type = EdgeEffectType.Shadow, + Colour = Color4.Pink.Opacity(0.5f), + Radius = 5, + }, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0, + AlwaysPresent = true, + }, + new CircularContainer + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Masking = true, + BorderThickness = size / 3, + BorderColour = Color4.White.Opacity(0.5f), + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0, + AlwaysPresent = true, + }, + }, + }, + new CircularContainer + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Scale = new Vector2(0.1f), + Masking = true, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.White, + }, + }, + }, + } + } + }; + } + } } } diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index af9a24df42..905541a592 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -6,9 +6,11 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; @@ -71,6 +73,12 @@ namespace osu.Game.Skinning { switch (componentName) { + case "osu/Game/Rulesets/Osu/UI/Cursor/OsuCursor": + if (GetTexture("cursor") != null) + return new LegacyCursor(); + + break; + case "Play/Miss": componentName = "hit0"; break; @@ -243,5 +251,36 @@ namespace osu.Game.Skinning return texture; } } + + public class LegacyCursor : CompositeDrawable + { + public LegacyCursor() + { + Size = new Vector2(50); + + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + } + + [BackgroundDependencyLoader] + private void load(ISkinSource skin) + { + InternalChildren = new Drawable[] + { + new Sprite + { + Texture = skin.GetTexture("cursormiddle"), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }, + new Sprite + { + Texture = skin.GetTexture("cursor"), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + }; + } + } } } From bfaf9d5f419aef2cd84031e0e0c00aeffc3acf5e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 Jul 2019 16:24:10 +0900 Subject: [PATCH 2/6] Remove unnecessary special cases --- osu.Game/Skinning/LegacySkin.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index 905541a592..48888191e9 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -129,20 +129,8 @@ namespace osu.Game.Skinning } if (texture != null) - { texture.ScaleAdjust = ratio; - switch (componentName) - { - case "cursormiddle": - case "cursortrail": - case "cursor": - // apply inverse of adjustment in OsuPlayfieldAdjustmentContainer for non-gameplay-scale textures. - texture.ScaleAdjust *= 1.6f; - break; - } - } - return texture; } From 1222536f7ac5380b1d217b5f7d69c77bf9e7a1fb Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 30 Jul 2019 19:10:21 +0900 Subject: [PATCH 3/6] Rename resource string --- osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs | 2 +- osu.Game/Skinning/LegacySkin.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs b/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs index 37ac972f41..eb1977a13d 100644 --- a/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs +++ b/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs @@ -49,7 +49,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor RelativeSizeAxes = Axes.Both, Origin = Anchor.Centre, Anchor = Anchor.Centre, - Child = scaleTarget = new SkinnableDrawable("osu/Game/Rulesets/Osu/UI/Cursor/OsuCursor", _ => new DefaultCursor(), confineMode: ConfineMode.NoScaling) + Child = scaleTarget = new SkinnableDrawable("Play/osu/cursor", _ => new DefaultCursor(), confineMode: ConfineMode.NoScaling) { Origin = Anchor.Centre, Anchor = Anchor.Centre, diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index 48888191e9..a567f85a02 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -73,7 +73,7 @@ namespace osu.Game.Skinning { switch (componentName) { - case "osu/Game/Rulesets/Osu/UI/Cursor/OsuCursor": + case "Play/osu/cursor": if (GetTexture("cursor") != null) return new LegacyCursor(); From d12de7dbfa0127ffac637e9736a54fc496d29bd9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 Jul 2019 23:20:35 +0900 Subject: [PATCH 4/6] Add temporary scale hack to make cursors correct size --- osu.Game/Skinning/LegacySkin.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index a567f85a02..bd08de03d5 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -255,13 +255,13 @@ namespace osu.Game.Skinning { InternalChildren = new Drawable[] { - new Sprite + new NonPlayfieldSprite { Texture = skin.GetTexture("cursormiddle"), Anchor = Anchor.Centre, Origin = Anchor.Centre, }, - new Sprite + new NonPlayfieldSprite { Texture = skin.GetTexture("cursor"), Anchor = Anchor.Centre, @@ -270,5 +270,18 @@ namespace osu.Game.Skinning }; } } + + private class NonPlayfieldSprite : Sprite + { + public override Texture Texture + { + get => base.Texture; + set + { + value.ScaleAdjust *= 2f; + base.Texture = value; + } + } + } } } From f6b6fa963393ed2e3130a96e737b33605fc91fcd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 Jul 2019 23:44:47 +0900 Subject: [PATCH 5/6] Add disappeared null check --- osu.Game/Skinning/LegacySkin.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index d6709df646..906a81a007 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -365,7 +365,8 @@ namespace osu.Game.Skinning get => base.Texture; set { - value.ScaleAdjust *= 2f; + if (value != null) + value.ScaleAdjust *= 2f; base.Texture = value; } } From 9335ebeb5592d10a820bdcb5b3edc719294f7593 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 Jul 2019 23:45:55 +0900 Subject: [PATCH 6/6] Fix missing anchor/origin specification --- osu.Game/Skinning/LegacySkin.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Skinning/LegacySkin.cs b/osu.Game/Skinning/LegacySkin.cs index 906a81a007..19f04c9b7a 100644 --- a/osu.Game/Skinning/LegacySkin.cs +++ b/osu.Game/Skinning/LegacySkin.cs @@ -291,6 +291,8 @@ namespace osu.Game.Skinning new NonPlayfieldSprite { Texture = skin.GetTexture("cursor"), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, } }; }