From cbeeb4a2b4b5cc7485f3f44012a14103ad8f2987 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 27 Sep 2024 13:43:57 +0900 Subject: [PATCH 1/2] Add basic hover states for file selector elements --- .../UserInterfaceV2/FormFileSelector.cs | 19 +++++- .../OsuDirectorySelectorBreadcrumbDisplay.cs | 20 +------ .../OsuDirectorySelectorDirectory.cs | 6 +- .../UserInterfaceV2/OsuFileSelector.cs | 6 +- .../OsuFileSelectorBackgroundLayer.cs | 59 +++++++++++++++++++ 5 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 osu.Game/Graphics/UserInterfaceV2/OsuFileSelectorBackgroundLayer.cs diff --git a/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs b/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs index 66f68f3e3b..55cc026d7c 100644 --- a/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FormFileSelector.cs @@ -24,6 +24,7 @@ using osu.Game.Database; using osu.Game.Graphics.Sprites; using osu.Game.Overlays; using osuTK; +using osuTK.Graphics; namespace osu.Game.Graphics.UserInterfaceV2 { @@ -254,8 +255,22 @@ namespace osu.Game.Graphics.UserInterfaceV2 [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { - Body.BorderThickness = 2; - Body.BorderColour = colourProvider.Highlight1; + Add(new Container + { + RelativeSizeAxes = Axes.Both, + Masking = true, + BorderThickness = 2, + CornerRadius = 10, + BorderColour = colourProvider.Highlight1, + Children = new Drawable[] + { + new Box + { + Colour = Color4.Transparent, + RelativeSizeAxes = Axes.Both, + }, + } + }); } } } diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorBreadcrumbDisplay.cs b/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorBreadcrumbDisplay.cs index e91076498c..3fd1fa998f 100644 --- a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorBreadcrumbDisplay.cs +++ b/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorBreadcrumbDisplay.cs @@ -80,7 +80,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 AddRangeInternal(new Drawable[] { - new Background + new OsuFileSelectorBackgroundLayer(0.5f) { Depth = 1 }, @@ -101,24 +101,6 @@ namespace osu.Game.Graphics.UserInterfaceV2 protected override SpriteText CreateSpriteText() => new OsuSpriteText().With(t => t.Font = OsuFont.Default.With(weight: FontWeight.SemiBold)); protected override IconUsage? Icon => Directory.Name.Contains(Path.DirectorySeparatorChar) ? FontAwesome.Solid.Database : null; - - internal partial class Background : CompositeDrawable - { - [BackgroundDependencyLoader] - private void load(OverlayColourProvider overlayColourProvider) - { - RelativeSizeAxes = Axes.Both; - - Masking = true; - CornerRadius = 5; - - InternalChild = new Box - { - Colour = overlayColourProvider.Background3, - RelativeSizeAxes = Axes.Both, - }; - } - } } } } diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorDirectory.cs b/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorDirectory.cs index a36804658a..4240eb73a4 100644 --- a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorDirectory.cs +++ b/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorDirectory.cs @@ -7,7 +7,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; namespace osu.Game.Graphics.UserInterfaceV2 { @@ -24,10 +23,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 Flow.AutoSizeAxes = Axes.X; Flow.Height = OsuDirectorySelector.ITEM_HEIGHT; - AddRangeInternal(new Drawable[] - { - new HoverClickSounds() - }); + AddInternal(new OsuFileSelectorBackgroundLayer()); Colour = colours.Orange1; } diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs b/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs index 7ce5f63656..f54bfeebba 100644 --- a/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs +++ b/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs @@ -11,7 +11,6 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; namespace osu.Game.Graphics.UserInterfaceV2 @@ -87,10 +86,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 Flow.AutoSizeAxes = Axes.X; Flow.Height = OsuDirectorySelector.ITEM_HEIGHT; - AddRangeInternal(new Drawable[] - { - new HoverClickSounds() - }); + AddInternal(new OsuFileSelectorBackgroundLayer()); Colour = colourProvider.Light3; } diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuFileSelectorBackgroundLayer.cs b/osu.Game/Graphics/UserInterfaceV2/OsuFileSelectorBackgroundLayer.cs new file mode 100644 index 0000000000..ee5e7f014d --- /dev/null +++ b/osu.Game/Graphics/UserInterfaceV2/OsuFileSelectorBackgroundLayer.cs @@ -0,0 +1,59 @@ +// 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.Shapes; +using osu.Framework.Input.Events; +using osu.Game.Graphics.UserInterface; +using osu.Game.Overlays; + +namespace osu.Game.Graphics.UserInterfaceV2 +{ + internal partial class OsuFileSelectorBackgroundLayer : CompositeDrawable + { + private Box background = null!; + + private readonly float defaultAlpha; + + public OsuFileSelectorBackgroundLayer(float defaultAlpha = 0f) + { + Depth = float.MaxValue; + + this.defaultAlpha = defaultAlpha; + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider overlayColourProvider) + { + RelativeSizeAxes = Axes.Both; + + Masking = true; + CornerRadius = 5; + + InternalChildren = new Drawable[] + { + new HoverClickSounds(), + background = new Box + { + Alpha = defaultAlpha, + Colour = overlayColourProvider.Background3, + RelativeSizeAxes = Axes.Both, + }, + }; + } + + protected override bool OnHover(HoverEvent e) + { + background.FadeTo(1, 200, Easing.OutQuint); + return base.OnHover(e); + } + + protected override void OnHoverLost(HoverLostEvent e) + { + base.OnHoverLost(e); + background.FadeTo(defaultAlpha, 500, Easing.OutQuint); + } + } +} From eacd9b9756583950a78b91affcccd92f74d2162c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 27 Sep 2024 13:57:05 +0900 Subject: [PATCH 2/2] Move dependent files to namespace --- .../BackgroundLayer.cs} | 6 +++--- .../HiddenFilesToggleCheckbox.cs} | 6 +++--- .../OsuDirectorySelectorBreadcrumbDisplay.cs | 4 ++-- .../{ => FileSelection}/OsuDirectorySelectorDirectory.cs | 4 ++-- .../OsuDirectorySelectorParentDirectory.cs | 2 +- osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelector.cs | 3 ++- osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs | 5 +++-- 7 files changed, 16 insertions(+), 14 deletions(-) rename osu.Game/Graphics/UserInterfaceV2/{OsuFileSelectorBackgroundLayer.cs => FileSelection/BackgroundLayer.cs} (88%) rename osu.Game/Graphics/UserInterfaceV2/{OsuDirectorySelectorHiddenToggle.cs => FileSelection/HiddenFilesToggleCheckbox.cs} (88%) rename osu.Game/Graphics/UserInterfaceV2/{ => FileSelection}/OsuDirectorySelectorBreadcrumbDisplay.cs (97%) rename osu.Game/Graphics/UserInterfaceV2/{ => FileSelection}/OsuDirectorySelectorDirectory.cs (91%) rename osu.Game/Graphics/UserInterfaceV2/{ => FileSelection}/OsuDirectorySelectorParentDirectory.cs (92%) diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuFileSelectorBackgroundLayer.cs b/osu.Game/Graphics/UserInterfaceV2/FileSelection/BackgroundLayer.cs similarity index 88% rename from osu.Game/Graphics/UserInterfaceV2/OsuFileSelectorBackgroundLayer.cs rename to osu.Game/Graphics/UserInterfaceV2/FileSelection/BackgroundLayer.cs index ee5e7f014d..cd3199c6f5 100644 --- a/osu.Game/Graphics/UserInterfaceV2/OsuFileSelectorBackgroundLayer.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FileSelection/BackgroundLayer.cs @@ -9,15 +9,15 @@ using osu.Framework.Input.Events; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; -namespace osu.Game.Graphics.UserInterfaceV2 +namespace osu.Game.Graphics.UserInterfaceV2.FileSelection { - internal partial class OsuFileSelectorBackgroundLayer : CompositeDrawable + internal partial class BackgroundLayer : CompositeDrawable { private Box background = null!; private readonly float defaultAlpha; - public OsuFileSelectorBackgroundLayer(float defaultAlpha = 0f) + public BackgroundLayer(float defaultAlpha = 0f) { Depth = float.MaxValue; diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorHiddenToggle.cs b/osu.Game/Graphics/UserInterfaceV2/FileSelection/HiddenFilesToggleCheckbox.cs similarity index 88% rename from osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorHiddenToggle.cs rename to osu.Game/Graphics/UserInterfaceV2/FileSelection/HiddenFilesToggleCheckbox.cs index 521ebebf91..07d84a0095 100644 --- a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorHiddenToggle.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FileSelection/HiddenFilesToggleCheckbox.cs @@ -8,11 +8,11 @@ using osu.Game.Overlays; using osuTK; using osuTK.Graphics; -namespace osu.Game.Graphics.UserInterfaceV2 +namespace osu.Game.Graphics.UserInterfaceV2.FileSelection { - internal partial class OsuDirectorySelectorHiddenToggle : OsuCheckbox + internal partial class HiddenFilesToggleCheckbox : OsuCheckbox { - public OsuDirectorySelectorHiddenToggle() + public HiddenFilesToggleCheckbox() { RelativeSizeAxes = Axes.None; AutoSizeAxes = Axes.None; diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorBreadcrumbDisplay.cs b/osu.Game/Graphics/UserInterfaceV2/FileSelection/OsuDirectorySelectorBreadcrumbDisplay.cs similarity index 97% rename from osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorBreadcrumbDisplay.cs rename to osu.Game/Graphics/UserInterfaceV2/FileSelection/OsuDirectorySelectorBreadcrumbDisplay.cs index 3fd1fa998f..aeeda82bfb 100644 --- a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorBreadcrumbDisplay.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FileSelection/OsuDirectorySelectorBreadcrumbDisplay.cs @@ -13,7 +13,7 @@ using osu.Game.Graphics.UserInterface; using osu.Game.Overlays; using osuTK; -namespace osu.Game.Graphics.UserInterfaceV2 +namespace osu.Game.Graphics.UserInterfaceV2.FileSelection { internal partial class OsuDirectorySelectorBreadcrumbDisplay : DirectorySelectorBreadcrumbDisplay { @@ -80,7 +80,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 AddRangeInternal(new Drawable[] { - new OsuFileSelectorBackgroundLayer(0.5f) + new BackgroundLayer(0.5f) { Depth = 1 }, diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorDirectory.cs b/osu.Game/Graphics/UserInterfaceV2/FileSelection/OsuDirectorySelectorDirectory.cs similarity index 91% rename from osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorDirectory.cs rename to osu.Game/Graphics/UserInterfaceV2/FileSelection/OsuDirectorySelectorDirectory.cs index 4240eb73a4..0da4e1929f 100644 --- a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorDirectory.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FileSelection/OsuDirectorySelectorDirectory.cs @@ -8,7 +8,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.Sprites; -namespace osu.Game.Graphics.UserInterfaceV2 +namespace osu.Game.Graphics.UserInterfaceV2.FileSelection { internal partial class OsuDirectorySelectorDirectory : DirectorySelectorDirectory { @@ -23,7 +23,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 Flow.AutoSizeAxes = Axes.X; Flow.Height = OsuDirectorySelector.ITEM_HEIGHT; - AddInternal(new OsuFileSelectorBackgroundLayer()); + AddInternal(new BackgroundLayer()); Colour = colours.Orange1; } diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorParentDirectory.cs b/osu.Game/Graphics/UserInterfaceV2/FileSelection/OsuDirectorySelectorParentDirectory.cs similarity index 92% rename from osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorParentDirectory.cs rename to osu.Game/Graphics/UserInterfaceV2/FileSelection/OsuDirectorySelectorParentDirectory.cs index d274a0ecfe..e5e1e0b7f3 100644 --- a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelectorParentDirectory.cs +++ b/osu.Game/Graphics/UserInterfaceV2/FileSelection/OsuDirectorySelectorParentDirectory.cs @@ -6,7 +6,7 @@ using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; using osu.Game.Overlays; -namespace osu.Game.Graphics.UserInterfaceV2 +namespace osu.Game.Graphics.UserInterfaceV2.FileSelection { internal partial class OsuDirectorySelectorParentDirectory : OsuDirectorySelectorDirectory { diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelector.cs b/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelector.cs index 85599a5d45..65ffdcaa5b 100644 --- a/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelector.cs +++ b/osu.Game/Graphics/UserInterfaceV2/OsuDirectorySelector.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.Containers; +using osu.Game.Graphics.UserInterfaceV2.FileSelection; using osu.Game.Overlays; namespace osu.Game.Graphics.UserInterfaceV2 @@ -57,7 +58,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 { RelativeSizeAxes = Axes.Both, }, - new OsuDirectorySelectorHiddenToggle + new HiddenFilesToggleCheckbox { Current = { BindTarget = ShowHiddenItems }, }, diff --git a/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs b/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs index f54bfeebba..c7b559d9ed 100644 --- a/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs +++ b/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs @@ -11,6 +11,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterfaceV2.FileSelection; using osu.Game.Overlays; namespace osu.Game.Graphics.UserInterfaceV2 @@ -58,7 +59,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 { RelativeSizeAxes = Axes.Both, }, - new OsuDirectorySelectorHiddenToggle + new HiddenFilesToggleCheckbox { Current = { BindTarget = ShowHiddenItems }, }, @@ -86,7 +87,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 Flow.AutoSizeAxes = Axes.X; Flow.Height = OsuDirectorySelector.ITEM_HEIGHT; - AddInternal(new OsuFileSelectorBackgroundLayer()); + AddInternal(new BackgroundLayer()); Colour = colourProvider.Light3; }