From a7306248d162f61c48a343ee892435dba7f87428 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 18 Jun 2019 16:20:35 +0300 Subject: [PATCH 01/14] Implement OverlayTabControl class An abstraction for OverlayHeaderTabControl --- osu.Game/Overlays/OverlayHeaderTabControl.cs | 143 ++--------------- osu.Game/Overlays/OverlayTabControl.cs | 153 +++++++++++++++++++ osu.Game/Overlays/Profile/ProfileHeader.cs | 6 - 3 files changed, 162 insertions(+), 140 deletions(-) create mode 100644 osu.Game/Overlays/OverlayTabControl.cs diff --git a/osu.Game/Overlays/OverlayHeaderTabControl.cs b/osu.Game/Overlays/OverlayHeaderTabControl.cs index dfe7e52420..b2c5fb8f2a 100644 --- a/osu.Game/Overlays/OverlayHeaderTabControl.cs +++ b/osu.Game/Overlays/OverlayHeaderTabControl.cs @@ -1,153 +1,28 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Graphics; -using osu.Framework.Graphics.Shapes; +using osu.Framework.Allocation; using osu.Framework.Graphics.UserInterface; -using osu.Framework.Input.Events; using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; -using osuTK; -using osuTK.Graphics; namespace osu.Game.Overlays { - public class OverlayHeaderTabControl : TabControl + public class OverlayHeaderTabControl : OverlayTabControl { - private readonly Box bar; + protected override TabItem CreateTabItem(string value) => new OverlayHeaderTabItem(value); - private Color4 accentColour = Color4.White; - - public Color4 AccentColour + [BackgroundDependencyLoader] + private void load(OsuColour colours) { - get => accentColour; - set - { - if (accentColour == value) - return; - - accentColour = value; - bar.Colour = value; - - foreach (TabItem tabItem in TabContainer) - { - ((HeaderTabItem)tabItem).AccentColour = value; - } - } + AccentColour = colours.Seafoam; } - public new MarginPadding Padding + private class OverlayHeaderTabItem : OverlayTabItem { - get => TabContainer.Padding; - set => TabContainer.Padding = value; - } - - public OverlayHeaderTabControl() - { - TabContainer.Masking = false; - TabContainer.Spacing = new Vector2(15, 0); - - AddInternal(bar = new Box - { - RelativeSizeAxes = Axes.X, - Height = 2, - Anchor = Anchor.BottomLeft, - Origin = Anchor.CentreLeft - }); - } - - protected override Dropdown CreateDropdown() => null; - - protected override TabItem CreateTabItem(string value) => new HeaderTabItem(value) - { - AccentColour = AccentColour - }; - - private class HeaderTabItem : TabItem - { - private readonly OsuSpriteText text; - private readonly ExpandingBar bar; - - private Color4 accentColour; - - public Color4 AccentColour - { - get => accentColour; - set - { - if (accentColour == value) - return; - - accentColour = value; - bar.Colour = value; - - updateState(); - } - } - - public HeaderTabItem(string value) + public OverlayHeaderTabItem(string value) : base(value) { - AutoSizeAxes = Axes.X; - RelativeSizeAxes = Axes.Y; - - Children = new Drawable[] - { - text = new OsuSpriteText - { - Margin = new MarginPadding { Bottom = 10 }, - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - Text = value, - Font = OsuFont.GetFont() - }, - bar = new ExpandingBar - { - Anchor = Anchor.BottomCentre, - ExpandedSize = 7.5f, - CollapsedSize = 0 - }, - new HoverClickSounds() - }; - } - - protected override bool OnHover(HoverEvent e) - { - base.OnHover(e); - - updateState(); - - return true; - } - - protected override void OnHoverLost(HoverLostEvent e) - { - base.OnHoverLost(e); - - updateState(); - } - - protected override void OnActivated() => updateState(); - - protected override void OnDeactivated() => updateState(); - - private void updateState() - { - if (Active.Value || IsHovered) - { - text.FadeColour(Color4.White, 120, Easing.InQuad); - bar.Expand(); - - if (Active.Value) - text.Font = text.Font.With(weight: FontWeight.Bold); - } - else - { - text.FadeColour(AccentColour, 120, Easing.InQuad); - bar.Collapse(); - text.Font = text.Font.With(weight: FontWeight.Medium); - } + Text.Text = value; } } } diff --git a/osu.Game/Overlays/OverlayTabControl.cs b/osu.Game/Overlays/OverlayTabControl.cs new file mode 100644 index 0000000000..8fd53e0f36 --- /dev/null +++ b/osu.Game/Overlays/OverlayTabControl.cs @@ -0,0 +1,153 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input.Events; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Overlays +{ + public abstract class OverlayTabControl : TabControl + { + private readonly Box bar; + + private Color4 accentColour = Color4.White; + + public Color4 AccentColour + { + get => accentColour; + set + { + if (accentColour == value) + return; + + accentColour = value; + bar.Colour = value; + + foreach (TabItem tabItem in TabContainer) + { + ((OverlayTabItem)tabItem).AccentColour = value; + } + } + } + + public new MarginPadding Padding + { + get => TabContainer.Padding; + set => TabContainer.Padding = value; + } + + protected OverlayTabControl() + { + TabContainer.Masking = false; + TabContainer.Spacing = new Vector2(15, 0); + + AddInternal(bar = new Box + { + RelativeSizeAxes = Axes.X, + Height = 2, + Anchor = Anchor.BottomLeft, + Origin = Anchor.CentreLeft + }); + } + + protected override Dropdown CreateDropdown() => null; + + protected override TabItem CreateTabItem(T value) => new OverlayTabItem(value); + + protected class OverlayTabItem : TabItem + { + private readonly ExpandingBar bar; + + protected readonly OsuSpriteText Text; + + private Color4 accentColour; + + public Color4 AccentColour + { + get => accentColour; + set + { + if (accentColour == value) + return; + + accentColour = value; + bar.Colour = value; + + updateState(); + } + } + + public OverlayTabItem(U value) + : base(value) + { + AutoSizeAxes = Axes.X; + RelativeSizeAxes = Axes.Y; + + Children = new Drawable[] + { + Text = new OsuSpriteText + { + Margin = new MarginPadding { Bottom = 10 }, + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Font = OsuFont.GetFont(), + }, + bar = new ExpandingBar + { + Anchor = Anchor.BottomCentre, + ExpandedSize = 7.5f, + CollapsedSize = 0 + }, + new HoverClickSounds() + }; + } + + protected override bool OnHover(HoverEvent e) + { + base.OnHover(e); + + if (!Active.Value) + OnActivated(); + + return true; + } + + protected override void OnHoverLost(HoverLostEvent e) + { + base.OnHoverLost(e); + + if (!Active.Value) + OnDeactivated(); + } + + protected override void OnActivated() + { + bar.Expand(); + Text.FadeColour(Color4.White, 120, Easing.InQuad); + Text.Font = Text.Font.With(weight: FontWeight.Bold); + } + + protected override void OnDeactivated() + { + bar.Collapse(); + Text.FadeColour(AccentColour, 120, Easing.InQuad); + Text.Font = Text.Font.With(weight: FontWeight.Medium); + } + + private void updateState() + { + if (Active.Value) + OnActivated(); + else + OnDeactivated(); + } + } + } +} diff --git a/osu.Game/Overlays/Profile/ProfileHeader.cs b/osu.Game/Overlays/Profile/ProfileHeader.cs index 76613c156d..90f51a90a6 100644 --- a/osu.Game/Overlays/Profile/ProfileHeader.cs +++ b/osu.Game/Overlays/Profile/ProfileHeader.cs @@ -34,12 +34,6 @@ namespace osu.Game.Overlays.Profile centreHeaderContainer.DetailsVisible.BindValueChanged(visible => detailHeaderContainer.Expanded = visible.NewValue, true); } - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - TabControl.AccentColour = colours.Seafoam; - } - protected override Drawable CreateBackground() => new Container { From 3c3757f12eab580b2709aba027011a3371d40e36 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 18 Jun 2019 16:23:57 +0300 Subject: [PATCH 02/14] Make ProfileTabControl based on OverlayTabControl --- osu.Game/Overlays/UserProfileOverlay.cs | 33 +++++++++---------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/osu.Game/Overlays/UserProfileOverlay.cs b/osu.Game/Overlays/UserProfileOverlay.cs index 8a133a1d1e..6c9b757c13 100644 --- a/osu.Game/Overlays/UserProfileOverlay.cs +++ b/osu.Game/Overlays/UserProfileOverlay.cs @@ -8,12 +8,10 @@ using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics; using osu.Game.Graphics.Containers; -using osu.Game.Graphics.UserInterface; using osu.Game.Online.API.Requests; using osu.Game.Overlays.Profile; using osu.Game.Overlays.Profile.Sections; using osu.Game.Users; -using osuTK; namespace osu.Game.Overlays { @@ -141,31 +139,28 @@ namespace osu.Game.Overlays } } - private class ProfileTabControl : PageTabControl + private class ProfileTabControl : OverlayTabControl { - private readonly Box bottom; - public ProfileTabControl() { TabContainer.RelativeSizeAxes &= ~Axes.X; TabContainer.AutoSizeAxes |= Axes.X; TabContainer.Anchor |= Anchor.x1; TabContainer.Origin |= Anchor.x1; - AddInternal(bottom = new Box - { - RelativeSizeAxes = Axes.X, - Height = 1, - Anchor = Anchor.BottomCentre, - Origin = Anchor.BottomCentre, - EdgeSmoothness = new Vector2(1) - }); } - protected override TabItem CreateTabItem(ProfileSection value) => new ProfileTabItem(value); + protected override TabItem CreateTabItem(ProfileSection value) => new ProfileTabItem(value) + { + AccentColour = AccentColour + }; - protected override Dropdown CreateDropdown() => null; + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + AccentColour = colours.Seafoam; + } - private class ProfileTabItem : PageTabItem + private class ProfileTabItem : OverlayTabItem { public ProfileTabItem(ProfileSection value) : base(value) @@ -173,12 +168,6 @@ namespace osu.Game.Overlays Text.Text = value.Title; } } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - bottom.Colour = colours.Yellow; - } } } } From 1c44fa84fb4939a05ff61c333d0993908a26fec6 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 19 Jun 2019 12:15:32 +0300 Subject: [PATCH 03/14] Fix colour issues --- osu.Game/Overlays/OverlayHeaderTabControl.cs | 11 +++-------- osu.Game/Overlays/Profile/ProfileHeader.cs | 6 ++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/osu.Game/Overlays/OverlayHeaderTabControl.cs b/osu.Game/Overlays/OverlayHeaderTabControl.cs index b2c5fb8f2a..5b56771dc1 100644 --- a/osu.Game/Overlays/OverlayHeaderTabControl.cs +++ b/osu.Game/Overlays/OverlayHeaderTabControl.cs @@ -1,21 +1,16 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Allocation; using osu.Framework.Graphics.UserInterface; -using osu.Game.Graphics; namespace osu.Game.Overlays { public class OverlayHeaderTabControl : OverlayTabControl { - protected override TabItem CreateTabItem(string value) => new OverlayHeaderTabItem(value); - - [BackgroundDependencyLoader] - private void load(OsuColour colours) + protected override TabItem CreateTabItem(string value) => new OverlayHeaderTabItem(value) { - AccentColour = colours.Seafoam; - } + AccentColour = AccentColour, + }; private class OverlayHeaderTabItem : OverlayTabItem { diff --git a/osu.Game/Overlays/Profile/ProfileHeader.cs b/osu.Game/Overlays/Profile/ProfileHeader.cs index 90f51a90a6..76613c156d 100644 --- a/osu.Game/Overlays/Profile/ProfileHeader.cs +++ b/osu.Game/Overlays/Profile/ProfileHeader.cs @@ -34,6 +34,12 @@ namespace osu.Game.Overlays.Profile centreHeaderContainer.DetailsVisible.BindValueChanged(visible => detailHeaderContainer.Expanded = visible.NewValue, true); } + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + TabControl.AccentColour = colours.Seafoam; + } + protected override Drawable CreateBackground() => new Container { From 29305ca0eb2737395178d588873157f0c69b4e34 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 21 Jun 2019 13:24:12 +0300 Subject: [PATCH 04/14] fix broken layout --- osu.Game/Overlays/OverlayTabControl.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/OverlayTabControl.cs b/osu.Game/Overlays/OverlayTabControl.cs index 8fd53e0f36..20649c8a74 100644 --- a/osu.Game/Overlays/OverlayTabControl.cs +++ b/osu.Game/Overlays/OverlayTabControl.cs @@ -114,7 +114,7 @@ namespace osu.Game.Overlays base.OnHover(e); if (!Active.Value) - OnActivated(); + HoverAction(); return true; } @@ -124,20 +124,18 @@ namespace osu.Game.Overlays base.OnHoverLost(e); if (!Active.Value) - OnDeactivated(); + UnhoverAction(); } protected override void OnActivated() { - bar.Expand(); - Text.FadeColour(Color4.White, 120, Easing.InQuad); + HoverAction(); Text.Font = Text.Font.With(weight: FontWeight.Bold); } protected override void OnDeactivated() { - bar.Collapse(); - Text.FadeColour(AccentColour, 120, Easing.InQuad); + UnhoverAction(); Text.Font = Text.Font.With(weight: FontWeight.Medium); } @@ -148,6 +146,18 @@ namespace osu.Game.Overlays else OnDeactivated(); } + + protected virtual void HoverAction() + { + bar.Expand(); + Text.FadeColour(Color4.White, 120, Easing.InQuad); + } + + protected virtual void UnhoverAction() + { + bar.Collapse(); + Text.FadeColour(AccentColour, 120, Easing.InQuad); + } } } } From e2f82ac29b242b6d7621faeb347b2cc9d1704d85 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 22 Jun 2019 17:53:00 +0200 Subject: [PATCH 05/14] Move CatcherSprite to its own file + Make CatcherSprite a SkinReloadableDrawable --- osu.Game.Rulesets.Catch/UI/CatcherArea.cs | 22 +--------- osu.Game.Rulesets.Catch/UI/CatcherSprite.cs | 46 +++++++++++++++++++++ 2 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 osu.Game.Rulesets.Catch/UI/CatcherSprite.cs diff --git a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs index 90052d9b11..18121bba4b 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs @@ -7,7 +7,6 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Textures; using osu.Framework.Input.Bindings; using osu.Framework.MathUtils; using osu.Game.Beatmaps; @@ -141,7 +140,7 @@ namespace osu.Game.Rulesets.Catch.UI [BackgroundDependencyLoader] private void load() { - Children = new Drawable[] + Children = new[] { caughtFruit = new Container { @@ -212,7 +211,7 @@ namespace osu.Game.Rulesets.Catch.UI Scheduler.AddDelayed(beginTrail, HyperDashing ? 25 : 50); } - private Sprite createCatcherSprite() => new CatcherSprite(); + private Drawable createCatcherSprite() => new CatcherSprite(); /// /// Add a caught fruit to the catcher's stack. @@ -444,23 +443,6 @@ namespace osu.Game.Rulesets.Catch.UI fruit.Expire(); } - - private class CatcherSprite : Sprite - { - public CatcherSprite() - { - Size = new Vector2(CATCHER_SIZE); - - // Sets the origin roughly to the centre of the catcher's plate to allow for correct scaling. - OriginPosition = new Vector2(-0.02f, 0.06f) * CATCHER_SIZE; - } - - [BackgroundDependencyLoader] - private void load(TextureStore textures) - { - Texture = textures.Get(@"Play/Catch/fruit-catcher-idle"); - } - } } } } diff --git a/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs b/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs new file mode 100644 index 0000000000..24e5ec500a --- /dev/null +++ b/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs @@ -0,0 +1,46 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Game.Skinning; +using osuTK; + +namespace osu.Game.Rulesets.Catch.UI +{ + public class CatcherSprite : SkinReloadableDrawable + { + private Drawable catcher; + + public CatcherSprite() + { + Size = new Vector2(CatcherArea.CATCHER_SIZE); + + // Sets the origin roughly to the centre of the catcher's plate to allow for correct scaling. + OriginPosition = new Vector2(-0.02f, 0.06f) * CatcherArea.CATCHER_SIZE; + } + + [BackgroundDependencyLoader] + private void load(TextureStore textures) + { + InternalChild = new Container() + { + RelativeSizeAxes = Axes.Both, + Child = catcher = new SkinnableDrawable("fruit-catcher-idle", _ => new Sprite() + { + Texture = textures.Get(@"Play/Catch/fruit-catcher-idle"), + RelativeSizeAxes = Axes.Both, + Size = Vector2.One, + }, restrictSize: true) + { + RelativeSizeAxes = Axes.Both, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + } + }; + } + } +} From b6cae57694b813b1649c5e99efce25003dfce02f Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 22 Jun 2019 18:14:29 +0200 Subject: [PATCH 06/14] Add TestSceneCatcherSkinning --- .../TestSceneCatcherSkinning.cs | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs new file mode 100644 index 0000000000..fa9486b087 --- /dev/null +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs @@ -0,0 +1,99 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics; +using osu.Game.Rulesets.Catch.UI; +using osu.Game.Tests.Visual; +using System; +using System.Collections.Generic; +using osu.Game.Skinning; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osuTK.Graphics; +using osu.Framework.Audio.Sample; +using osu.Framework.Graphics.Textures; + +namespace osu.Game.Rulesets.Catch.Tests +{ + [TestFixture] + public class TestSceneCatcherSkinning : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(CatcherSprite), + }; + + private Container container; + + public TestSceneCatcherSkinning() + { + Child = container = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }; + } + + [BackgroundDependencyLoader] + private void load() + { + AddStep("show default catcher implementation", () => + { + container.Clear(); + container.Child = new CatcherSprite(); + }); + + AddStep("show custom catcher implementation", () => + { + container.Clear(); + container.Child = new CatchCustomSkinSourceContainer + { + Child = new CatcherSprite() + }; + }); + } + + private class CatcherCustomSkin : Container + { + public CatcherCustomSkin() + { + RelativeSizeAxes = Axes.Both; + + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Blue + }, + new SpriteText + { + Text = "custom" + } + }; + } + } + + private class CatchCustomSkinSourceContainer : Container, ISkinSource + { + public event Action SourceChanged; + + public Drawable GetDrawableComponent(string componentName) => new CatcherCustomSkin(); + + public SampleChannel GetSample(string sampleName) => throw new NotImplementedException(); + + public Texture GetTexture(string componentName) => throw new NotImplementedException(); + + public TValue GetValue(Func query) where TConfiguration : SkinConfiguration => throw new NotImplementedException(); + + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + ((DependencyContainer)parent).CacheAs(this); + return base.CreateChildDependencies(parent); + } + } + } +} From 332ac0b82ba974f65ac4fb9d6f6cfa6c6c1bdbd3 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 22 Jun 2019 18:23:20 +0200 Subject: [PATCH 07/14] Fix CI inspections --- osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs | 8 ++++++-- osu.Game.Rulesets.Catch/UI/CatcherArea.cs | 1 - osu.Game.Rulesets.Catch/UI/CatcherSprite.cs | 6 ++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs index fa9486b087..e1ec88d4a9 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs @@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Catch.Tests typeof(CatcherSprite), }; - private Container container; + private readonly Container container; public TestSceneCatcherSkinning() { @@ -79,7 +79,11 @@ namespace osu.Game.Rulesets.Catch.Tests private class CatchCustomSkinSourceContainer : Container, ISkinSource { - public event Action SourceChanged; + public event Action SourceChanged + { + add { } + remove { } + } public Drawable GetDrawableComponent(string componentName) => new CatcherCustomSkin(); diff --git a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs index 18121bba4b..0b06e958e6 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherArea.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherArea.cs @@ -6,7 +6,6 @@ using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Bindings; using osu.Framework.MathUtils; using osu.Game.Beatmaps; diff --git a/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs b/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs index 24e5ec500a..1308a9b7a1 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs @@ -13,8 +13,6 @@ namespace osu.Game.Rulesets.Catch.UI { public class CatcherSprite : SkinReloadableDrawable { - private Drawable catcher; - public CatcherSprite() { Size = new Vector2(CatcherArea.CATCHER_SIZE); @@ -26,10 +24,10 @@ namespace osu.Game.Rulesets.Catch.UI [BackgroundDependencyLoader] private void load(TextureStore textures) { - InternalChild = new Container() + InternalChild = new Container { RelativeSizeAxes = Axes.Both, - Child = catcher = new SkinnableDrawable("fruit-catcher-idle", _ => new Sprite() + Child = new SkinnableDrawable("fruit-catcher-idle", _ => new Sprite { Texture = textures.Get(@"Play/Catch/fruit-catcher-idle"), RelativeSizeAxes = Axes.Both, From 4cd8b6a2bd48d7ffc57a335dae4ec9e4f9bdc2a8 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 24 Jun 2019 13:37:06 +0900 Subject: [PATCH 08/14] Fix unsafe caching of dependencies --- osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs index e1ec88d4a9..a56a1e31c1 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs @@ -77,6 +77,7 @@ namespace osu.Game.Rulesets.Catch.Tests } } + [Cached(typeof(ISkinSource))] private class CatchCustomSkinSourceContainer : Container, ISkinSource { public event Action SourceChanged @@ -92,12 +93,6 @@ namespace osu.Game.Rulesets.Catch.Tests public Texture GetTexture(string componentName) => throw new NotImplementedException(); public TValue GetValue(Func query) where TConfiguration : SkinConfiguration => throw new NotImplementedException(); - - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) - { - ((DependencyContainer)parent).CacheAs(this); - return base.CreateChildDependencies(parent); - } } } } From 2a4bd612d7e31a9a44467d6144f83d24c9c10052 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 24 Jun 2019 13:47:37 +0900 Subject: [PATCH 09/14] Rename test scene --- .../{TestSceneCatcherSkinning.cs => TestSceneCatcher.cs} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename osu.Game.Rulesets.Catch.Tests/{TestSceneCatcherSkinning.cs => TestSceneCatcher.cs} (96%) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs similarity index 96% rename from osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs rename to osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs index a56a1e31c1..e4c01cb668 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcherSkinning.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs @@ -19,7 +19,7 @@ using osu.Framework.Graphics.Textures; namespace osu.Game.Rulesets.Catch.Tests { [TestFixture] - public class TestSceneCatcherSkinning : OsuTestScene + public class TestSceneCatcher : OsuTestScene { public override IReadOnlyList RequiredTypes => new[] { @@ -28,7 +28,7 @@ namespace osu.Game.Rulesets.Catch.Tests private readonly Container container; - public TestSceneCatcherSkinning() + public TestSceneCatcher() { Child = container = new Container { From 06b087db701a97033fa15c678b73265afd1d1f41 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 24 Jun 2019 14:39:20 +0900 Subject: [PATCH 10/14] Add SkinnableSprite implementation --- osu.Game/Skinning/SkinnableDrawable.cs | 26 +++++++++++++++++------- osu.Game/Skinning/SkinnableSprite.cs | 28 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 osu.Game/Skinning/SkinnableSprite.cs diff --git a/osu.Game/Skinning/SkinnableDrawable.cs b/osu.Game/Skinning/SkinnableDrawable.cs index 3ca58dc625..64ef50111c 100644 --- a/osu.Game/Skinning/SkinnableDrawable.cs +++ b/osu.Game/Skinning/SkinnableDrawable.cs @@ -23,6 +23,8 @@ namespace osu.Game.Skinning /// protected Drawable Drawable { get; private set; } + protected virtual T CreateDefault() => createDefault(componentName); + private readonly Func createDefault; private readonly string componentName; @@ -37,34 +39,44 @@ namespace osu.Game.Skinning /// A conditional to decide whether to allow fallback to the default implementation if a skinned element is not present. /// Whether a user-skin drawable should be limited to the size of our parent. public SkinnableDrawable(string name, Func defaultImplementation, Func allowFallback = null, bool restrictSize = true) + : this(name, allowFallback, restrictSize) + { + createDefault = defaultImplementation; + } + + protected SkinnableDrawable(string name, Func allowFallback = null, bool restrictSize = true) : base(allowFallback) { componentName = name; - createDefault = defaultImplementation; this.restrictSize = restrictSize; RelativeSizeAxes = Axes.Both; } + protected virtual bool ApplySizeToDefault => false; + protected override void SkinChanged(ISkinSource skin, bool allowFallback) { Drawable = skin.GetDrawableComponent(componentName); + bool isDefault = false; + + if (Drawable == null && allowFallback) + { + Drawable = CreateDefault(); + isDefault = true; + } + if (Drawable != null) { - if (restrictSize) + if (restrictSize && (!isDefault || ApplySizeToDefault)) { Drawable.RelativeSizeAxes = Axes.Both; Drawable.Size = Vector2.One; Drawable.Scale = Vector2.One; Drawable.FillMode = FillMode.Fit; } - } - else if (allowFallback) - Drawable = createDefault(componentName); - if (Drawable != null) - { Drawable.Origin = Anchor.Centre; Drawable.Anchor = Anchor.Centre; diff --git a/osu.Game/Skinning/SkinnableSprite.cs b/osu.Game/Skinning/SkinnableSprite.cs new file mode 100644 index 0000000000..4cf054b704 --- /dev/null +++ b/osu.Game/Skinning/SkinnableSprite.cs @@ -0,0 +1,28 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Allocation; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; + +namespace osu.Game.Skinning +{ + public class SkinnableSprite : SkinnableDrawable + { + protected override bool ApplySizeToDefault => true; + + private readonly string defaultName; + + protected override Sprite CreateDefault() => new Sprite { Texture = textures.Get(defaultName) }; + + [Resolved] + private TextureStore textures { get; set; } + + public SkinnableSprite(string name, string defaultName, Func allowFallback = null, bool restrictSize = true) + : base(name, allowFallback, restrictSize) + { + this.defaultName = defaultName; + } + } +} From d9f701176995af7b005034438e97b87878bed7f8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 24 Jun 2019 14:39:46 +0900 Subject: [PATCH 11/14] Use SkinnableSprite to reduce complexity of implementation --- osu.Game.Rulesets.Catch/UI/CatcherSprite.cs | 21 +++++---------------- osu.Game/Skinning/SkinnableDrawable.cs | 4 ++-- osu.Game/Skinning/SkinnableSprite.cs | 7 ++----- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs b/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs index 1308a9b7a1..df396279fc 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs @@ -1,11 +1,9 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.Textures; using osu.Game.Skinning; using osuTK; @@ -22,22 +20,13 @@ namespace osu.Game.Rulesets.Catch.UI } [BackgroundDependencyLoader] - private void load(TextureStore textures) + private void load() { - InternalChild = new Container + InternalChild = new SkinnableSprite(@"Play/Catch/fruit-catcher-idle") { RelativeSizeAxes = Axes.Both, - Child = new SkinnableDrawable("fruit-catcher-idle", _ => new Sprite - { - Texture = textures.Get(@"Play/Catch/fruit-catcher-idle"), - RelativeSizeAxes = Axes.Both, - Size = Vector2.One, - }, restrictSize: true) - { - RelativeSizeAxes = Axes.Both, - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - } + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, }; } } diff --git a/osu.Game/Skinning/SkinnableDrawable.cs b/osu.Game/Skinning/SkinnableDrawable.cs index 64ef50111c..dcbb63435a 100644 --- a/osu.Game/Skinning/SkinnableDrawable.cs +++ b/osu.Game/Skinning/SkinnableDrawable.cs @@ -23,7 +23,7 @@ namespace osu.Game.Skinning /// protected Drawable Drawable { get; private set; } - protected virtual T CreateDefault() => createDefault(componentName); + protected virtual T CreateDefault(string name) => createDefault(name); private readonly Func createDefault; @@ -63,7 +63,7 @@ namespace osu.Game.Skinning if (Drawable == null && allowFallback) { - Drawable = CreateDefault(); + Drawable = CreateDefault(componentName); isDefault = true; } diff --git a/osu.Game/Skinning/SkinnableSprite.cs b/osu.Game/Skinning/SkinnableSprite.cs index 4cf054b704..72b5740bd6 100644 --- a/osu.Game/Skinning/SkinnableSprite.cs +++ b/osu.Game/Skinning/SkinnableSprite.cs @@ -12,17 +12,14 @@ namespace osu.Game.Skinning { protected override bool ApplySizeToDefault => true; - private readonly string defaultName; - - protected override Sprite CreateDefault() => new Sprite { Texture = textures.Get(defaultName) }; + protected override Sprite CreateDefault(string name) => new Sprite { Texture = textures.Get(name) }; [Resolved] private TextureStore textures { get; set; } - public SkinnableSprite(string name, string defaultName, Func allowFallback = null, bool restrictSize = true) + public SkinnableSprite(string name, Func allowFallback = null, bool restrictSize = true) : base(name, allowFallback, restrictSize) { - this.defaultName = defaultName; } } } From 9baf8160d1e07256d36fe4ec7daee20f0be3259c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 24 Jun 2019 14:40:08 +0900 Subject: [PATCH 12/14] Remove pointless SkinReloadableDrawable specification --- osu.Game.Rulesets.Catch/UI/CatcherSprite.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs b/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs index df396279fc..c0c1952064 100644 --- a/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs +++ b/osu.Game.Rulesets.Catch/UI/CatcherSprite.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; @@ -9,7 +9,7 @@ using osuTK; namespace osu.Game.Rulesets.Catch.UI { - public class CatcherSprite : SkinReloadableDrawable + public class CatcherSprite : CompositeDrawable { public CatcherSprite() { From 9ab520494773355c523d14f5eb3892c395377675 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 24 Jun 2019 15:09:28 +0900 Subject: [PATCH 13/14] Make test a bit more sane --- .../TestSceneCatcher.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs index e4c01cb668..33f93cdb4a 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs @@ -40,15 +40,10 @@ namespace osu.Game.Rulesets.Catch.Tests [BackgroundDependencyLoader] private void load() { - AddStep("show default catcher implementation", () => - { - container.Clear(); - container.Child = new CatcherSprite(); - }); + AddStep("show default catcher implementation", () => { container.Child = new CatcherSprite(); }); AddStep("show custom catcher implementation", () => { - container.Clear(); container.Child = new CatchCustomSkinSourceContainer { Child = new CatcherSprite() @@ -86,13 +81,25 @@ namespace osu.Game.Rulesets.Catch.Tests remove { } } - public Drawable GetDrawableComponent(string componentName) => new CatcherCustomSkin(); + public Drawable GetDrawableComponent(string componentName) + { + switch (componentName) + { + case "Play/Catch/fruit-catcher-idle": + return new CatcherCustomSkin(); + } - public SampleChannel GetSample(string sampleName) => throw new NotImplementedException(); + return null; + } - public Texture GetTexture(string componentName) => throw new NotImplementedException(); + public SampleChannel GetSample(string sampleName) => + throw new NotImplementedException(); - public TValue GetValue(Func query) where TConfiguration : SkinConfiguration => throw new NotImplementedException(); + public Texture GetTexture(string componentName) => + throw new NotImplementedException(); + + public TValue GetValue(Func query) where TConfiguration : SkinConfiguration => + throw new NotImplementedException(); } } } From 2473a9487a0738c6e405d36caf72bb8da831e792 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 24 Jun 2019 17:38:11 +0900 Subject: [PATCH 14/14] Add missing using --- osu.Game/Overlays/UserProfileOverlay.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Overlays/UserProfileOverlay.cs b/osu.Game/Overlays/UserProfileOverlay.cs index 5b8c2bb357..058d84d32f 100644 --- a/osu.Game/Overlays/UserProfileOverlay.cs +++ b/osu.Game/Overlays/UserProfileOverlay.cs @@ -13,6 +13,7 @@ using osu.Game.Online.API.Requests; using osu.Game.Overlays.Profile; using osu.Game.Overlays.Profile.Sections; using osu.Game.Users; +using osuTK; namespace osu.Game.Overlays {