From 8500f8fe767c4f7362cf4c6c38685de270cdf77a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 12 May 2020 18:12:58 +0900 Subject: [PATCH 1/7] Add basic implementation --- .../Settings/TestSceneDirectorySelector.cs | 195 ++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs diff --git a/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs b/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs new file mode 100644 index 0000000000..416d978c69 --- /dev/null +++ b/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs @@ -0,0 +1,195 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.IO; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Platform; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using osuTK; + +namespace osu.Game.Tests.Visual.Settings +{ + public class TestSceneDirectorySelector : OsuTestScene + { + [BackgroundDependencyLoader] + private void load(GameHost host) + { + Add(new DirectorySelector { RelativeSizeAxes = Axes.Both }); + } + } + + public class DirectorySelector : CompositeDrawable + { + private Storage root; + private FillFlowContainer directoryFlow; + private CurrentDirectoryDisplay current; + + [Resolved] + private GameHost host { get; set; } + + private readonly Bindable currentDirectory = new Bindable(); + + public DirectorySelector(Storage root = null) + { + this.root = root; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + Padding = new MarginPadding(10); + + if (root == null) + root = host.GetStorage("/Users/"); + + InternalChildren = new Drawable[] + { + new FillFlowContainer + { + RelativeSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Children = new Drawable[] + { + current = new CurrentDirectoryDisplay + { + CurrentDirectory = { BindTarget = currentDirectory }, + RelativeSizeAxes = Axes.X, + Height = 50, + }, + new OsuScrollContainer + { + RelativeSizeAxes = Axes.Both, + Child = directoryFlow = new FillFlowContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FillDirection.Vertical, + } + } + } + }, + }; + + currentDirectory.BindValueChanged(updateDisplay); + currentDirectory.Value = root.GetFullPath(string.Empty); + } + + private void updateDisplay(ValueChangedEvent directory) + { + root = host.GetStorage(directory.NewValue); + + directoryFlow.Clear(); + + directoryFlow.Add(new ParentDirectoryRow(getParentPath()) { CurrentDirectory = { BindTarget = currentDirectory }, }); + + foreach (var dir in root.GetDirectories(string.Empty)) + directoryFlow.Add(new DirectoryRow(dir, root.GetFullPath(dir)) { CurrentDirectory = { BindTarget = currentDirectory }, }); + } + + private string getParentPath() => Path.GetFullPath(Path.Combine(root.GetFullPath(string.Empty), "..")); + + public class CurrentDirectoryDisplay : CompositeDrawable + { + public readonly Bindable CurrentDirectory = new Bindable(); + + public CurrentDirectoryDisplay() + { + FillFlowContainer flow; + + InternalChildren = new Drawable[] + { + flow = new FillFlowContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + Spacing = new Vector2(10), + Height = 20, + Direction = FillDirection.Horizontal, + }, + }; + + CurrentDirectory.BindValueChanged(dir => + { + flow.Clear(); + + flow.Add(new OsuSpriteText { Text = "Current Directory: " }); + + var pieces = dir.NewValue.Split(Path.DirectorySeparatorChar); + + pieces[0] = "/"; + + for (int i = 0; i < pieces.Length; i++) + { + flow.Add(new DirectoryRow(pieces[i], Path.Combine(pieces.Take(i + 1).ToArray())) + { + CurrentDirectory = { BindTarget = CurrentDirectory }, + RelativeSizeAxes = Axes.Y, + Size = new Vector2(100, 1) + }); + } + }); + } + } + + private class ParentDirectoryRow : DirectoryRow + { + public override IconUsage Icon => FontAwesome.Solid.Folder; + + public ParentDirectoryRow(string fullPath) + : base("..", fullPath) + { + } + } + + private class DirectoryRow : OsuButton + { + private readonly string fullPath; + + public readonly Bindable CurrentDirectory = new Bindable(); + + public DirectoryRow(string display, string fullPath) + { + this.fullPath = fullPath; + + RelativeSizeAxes = Axes.X; + Height = 20; + + BackgroundColour = OsuColour.Gray(0.1f); + + AddRange(new Drawable[] + { + new SpriteIcon + { + Icon = Icon, + Size = new Vector2(20) + }, + new OsuSpriteText + { + X = 25, + Text = display, + Font = OsuFont.Default.With(size: 20) + } + }); + + Action = PerformDirectoryTraversal; + } + + protected virtual void PerformDirectoryTraversal() + { + CurrentDirectory.Value = fullPath; + } + + public virtual IconUsage Icon => FontAwesome.Regular.Folder; + } + } +} From 2c83417c41e29be9a5e474df65a7806dbf747577 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 13 May 2020 18:08:43 +0900 Subject: [PATCH 2/7] Switch to using DirectoryInfo/DriveInfo --- .../Settings/TestSceneDirectorySelector.cs | 122 +++++++++--------- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs b/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs index 416d978c69..beb5353115 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs @@ -1,6 +1,7 @@ // 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 System.IO; using System.Linq; using osu.Framework.Allocation; @@ -8,11 +9,11 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; +using osu.Framework.Input.Events; using osu.Framework.Platform; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; -using osu.Game.Graphics.UserInterface; using osuTK; namespace osu.Game.Tests.Visual.Settings @@ -28,18 +29,17 @@ namespace osu.Game.Tests.Visual.Settings public class DirectorySelector : CompositeDrawable { - private Storage root; private FillFlowContainer directoryFlow; - private CurrentDirectoryDisplay current; [Resolved] private GameHost host { get; set; } - private readonly Bindable currentDirectory = new Bindable(); + [Cached] + private readonly Bindable currentDirectory = new Bindable(); - public DirectorySelector(Storage root = null) + public DirectorySelector(string initialPath = null) { - this.root = root; + currentDirectory.Value = new DirectoryInfo(initialPath ??= Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); } protected override void LoadComplete() @@ -48,9 +48,6 @@ namespace osu.Game.Tests.Visual.Settings Padding = new MarginPadding(10); - if (root == null) - root = host.GetStorage("/Users/"); - InternalChildren = new Drawable[] { new FillFlowContainer @@ -59,9 +56,8 @@ namespace osu.Game.Tests.Visual.Settings Direction = FillDirection.Vertical, Children = new Drawable[] { - current = new CurrentDirectoryDisplay + new CurrentDirectoryDisplay { - CurrentDirectory = { BindTarget = currentDirectory }, RelativeSizeAxes = Axes.X, Height = 50, }, @@ -79,29 +75,39 @@ namespace osu.Game.Tests.Visual.Settings }, }; - currentDirectory.BindValueChanged(updateDisplay); - currentDirectory.Value = root.GetFullPath(string.Empty); + currentDirectory.BindValueChanged(updateDisplay, true); } - private void updateDisplay(ValueChangedEvent directory) + private void updateDisplay(ValueChangedEvent directory) { - root = host.GetStorage(directory.NewValue); - directoryFlow.Clear(); - directoryFlow.Add(new ParentDirectoryRow(getParentPath()) { CurrentDirectory = { BindTarget = currentDirectory }, }); + if (directory.NewValue == null) + { + // var drives = DriveInfo.GetDrives(); + // + // foreach (var drive in drives) + // directoryFlow.Add(new DirectoryRow(drive.RootDirectory)); + } + else + { + directoryFlow.Add(new ParentDirectoryRow(currentDirectory.Value.Parent)); - foreach (var dir in root.GetDirectories(string.Empty)) - directoryFlow.Add(new DirectoryRow(dir, root.GetFullPath(dir)) { CurrentDirectory = { BindTarget = currentDirectory }, }); + foreach (var dir in currentDirectory.Value.GetDirectories().OrderBy(d => d.Name)) + { + if ((dir.Attributes & FileAttributes.Hidden) == 0) + directoryFlow.Add(new DirectoryRow(dir)); + } + } } - private string getParentPath() => Path.GetFullPath(Path.Combine(root.GetFullPath(string.Empty), "..")); - public class CurrentDirectoryDisplay : CompositeDrawable { - public readonly Bindable CurrentDirectory = new Bindable(); + [Resolved] + private Bindable currentDirectory { get; set; } - public CurrentDirectoryDisplay() + [BackgroundDependencyLoader] + private void load() { FillFlowContainer flow; @@ -118,26 +124,26 @@ namespace osu.Game.Tests.Visual.Settings }, }; - CurrentDirectory.BindValueChanged(dir => + currentDirectory.BindValueChanged(dir => { flow.Clear(); - flow.Add(new OsuSpriteText { Text = "Current Directory: " }); - - var pieces = dir.NewValue.Split(Path.DirectorySeparatorChar); - - pieces[0] = "/"; - - for (int i = 0; i < pieces.Length; i++) + flow.Add(new OsuSpriteText { - flow.Add(new DirectoryRow(pieces[i], Path.Combine(pieces.Take(i + 1).ToArray())) - { - CurrentDirectory = { BindTarget = CurrentDirectory }, - RelativeSizeAxes = Axes.Y, - Size = new Vector2(100, 1) - }); + Text = "Current Directory: ", + Font = OsuFont.Default.With(size: DirectoryRow.HEIGHT), + }); + + flow.Add(new DirectoryRow(null, "Computer")); + + DirectoryInfo traverse = dir.NewValue; + + while (traverse != null) + { + flow.Add(new DirectoryRow(traverse)); + traverse = traverse.Parent; } - }); + }, true); } } @@ -145,48 +151,48 @@ namespace osu.Game.Tests.Visual.Settings { public override IconUsage Icon => FontAwesome.Solid.Folder; - public ParentDirectoryRow(string fullPath) - : base("..", fullPath) + public ParentDirectoryRow(DirectoryInfo directory) + : base(directory, "..") { } } - private class DirectoryRow : OsuButton + private class DirectoryRow : CompositeDrawable { - private readonly string fullPath; + public const float HEIGHT = 20; - public readonly Bindable CurrentDirectory = new Bindable(); + private readonly DirectoryInfo directory; - public DirectoryRow(string display, string fullPath) + [Resolved] + private Bindable currentDirectory { get; set; } + + public DirectoryRow(DirectoryInfo directory, string display = null) { - this.fullPath = fullPath; + this.directory = directory; - RelativeSizeAxes = Axes.X; - Height = 20; + AutoSizeAxes = Axes.X; + Height = HEIGHT; - BackgroundColour = OsuColour.Gray(0.1f); - - AddRange(new Drawable[] + AddRangeInternal(new Drawable[] { new SpriteIcon { Icon = Icon, - Size = new Vector2(20) + Size = new Vector2(HEIGHT) }, new OsuSpriteText { - X = 25, - Text = display, - Font = OsuFont.Default.With(size: 20) + X = HEIGHT + 5, + Text = display ?? directory.Name, + Font = OsuFont.Default.With(size: HEIGHT) } }); - - Action = PerformDirectoryTraversal; } - protected virtual void PerformDirectoryTraversal() + protected override bool OnClick(ClickEvent e) { - CurrentDirectory.Value = fullPath; + currentDirectory.Value = directory; + return true; } public virtual IconUsage Icon => FontAwesome.Regular.Folder; From 49e4fc6cba39028b5be157b975a26ae85e2e2161 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 13 May 2020 18:37:14 +0900 Subject: [PATCH 3/7] Move to better namespace --- .../Settings/TestSceneDirectorySelector.cs | 184 +----------- .../UserInterfaceV2/DirectorySelector.cs | 261 ++++++++++++++++++ 2 files changed, 262 insertions(+), 183 deletions(-) create mode 100644 osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs diff --git a/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs b/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs index beb5353115..0cd0f13b5f 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneDirectorySelector.cs @@ -1,20 +1,10 @@ // 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 System.IO; -using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Input.Events; using osu.Framework.Platform; -using osu.Game.Graphics; -using osu.Game.Graphics.Containers; -using osu.Game.Graphics.Sprites; -using osuTK; +using osu.Game.Graphics.UserInterfaceV2; namespace osu.Game.Tests.Visual.Settings { @@ -26,176 +16,4 @@ namespace osu.Game.Tests.Visual.Settings Add(new DirectorySelector { RelativeSizeAxes = Axes.Both }); } } - - public class DirectorySelector : CompositeDrawable - { - private FillFlowContainer directoryFlow; - - [Resolved] - private GameHost host { get; set; } - - [Cached] - private readonly Bindable currentDirectory = new Bindable(); - - public DirectorySelector(string initialPath = null) - { - currentDirectory.Value = new DirectoryInfo(initialPath ??= Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - Padding = new MarginPadding(10); - - InternalChildren = new Drawable[] - { - new FillFlowContainer - { - RelativeSizeAxes = Axes.Both, - Direction = FillDirection.Vertical, - Children = new Drawable[] - { - new CurrentDirectoryDisplay - { - RelativeSizeAxes = Axes.X, - Height = 50, - }, - new OsuScrollContainer - { - RelativeSizeAxes = Axes.Both, - Child = directoryFlow = new FillFlowContainer - { - AutoSizeAxes = Axes.Y, - RelativeSizeAxes = Axes.X, - Direction = FillDirection.Vertical, - } - } - } - }, - }; - - currentDirectory.BindValueChanged(updateDisplay, true); - } - - private void updateDisplay(ValueChangedEvent directory) - { - directoryFlow.Clear(); - - if (directory.NewValue == null) - { - // var drives = DriveInfo.GetDrives(); - // - // foreach (var drive in drives) - // directoryFlow.Add(new DirectoryRow(drive.RootDirectory)); - } - else - { - directoryFlow.Add(new ParentDirectoryRow(currentDirectory.Value.Parent)); - - foreach (var dir in currentDirectory.Value.GetDirectories().OrderBy(d => d.Name)) - { - if ((dir.Attributes & FileAttributes.Hidden) == 0) - directoryFlow.Add(new DirectoryRow(dir)); - } - } - } - - public class CurrentDirectoryDisplay : CompositeDrawable - { - [Resolved] - private Bindable currentDirectory { get; set; } - - [BackgroundDependencyLoader] - private void load() - { - FillFlowContainer flow; - - InternalChildren = new Drawable[] - { - flow = new FillFlowContainer - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.X, - Spacing = new Vector2(10), - Height = 20, - Direction = FillDirection.Horizontal, - }, - }; - - currentDirectory.BindValueChanged(dir => - { - flow.Clear(); - - flow.Add(new OsuSpriteText - { - Text = "Current Directory: ", - Font = OsuFont.Default.With(size: DirectoryRow.HEIGHT), - }); - - flow.Add(new DirectoryRow(null, "Computer")); - - DirectoryInfo traverse = dir.NewValue; - - while (traverse != null) - { - flow.Add(new DirectoryRow(traverse)); - traverse = traverse.Parent; - } - }, true); - } - } - - private class ParentDirectoryRow : DirectoryRow - { - public override IconUsage Icon => FontAwesome.Solid.Folder; - - public ParentDirectoryRow(DirectoryInfo directory) - : base(directory, "..") - { - } - } - - private class DirectoryRow : CompositeDrawable - { - public const float HEIGHT = 20; - - private readonly DirectoryInfo directory; - - [Resolved] - private Bindable currentDirectory { get; set; } - - public DirectoryRow(DirectoryInfo directory, string display = null) - { - this.directory = directory; - - AutoSizeAxes = Axes.X; - Height = HEIGHT; - - AddRangeInternal(new Drawable[] - { - new SpriteIcon - { - Icon = Icon, - Size = new Vector2(HEIGHT) - }, - new OsuSpriteText - { - X = HEIGHT + 5, - Text = display ?? directory.Name, - Font = OsuFont.Default.With(size: HEIGHT) - } - }); - } - - protected override bool OnClick(ClickEvent e) - { - currentDirectory.Value = directory; - return true; - } - - public virtual IconUsage Icon => FontAwesome.Regular.Folder; - } - } } diff --git a/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs b/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs new file mode 100644 index 0000000000..5dcaacf0a4 --- /dev/null +++ b/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs @@ -0,0 +1,261 @@ +// 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 System.Collections.Generic; +using System.IO; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input.Events; +using osu.Framework.Platform; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osuTK; + +namespace osu.Game.Graphics.UserInterfaceV2 +{ + public class DirectorySelector : CompositeDrawable + { + private FillFlowContainer directoryFlow; + + [Resolved] + private GameHost host { get; set; } + + [Cached] + private readonly Bindable currentDirectory = new Bindable(); + + public DirectorySelector(string initialPath = null) + { + currentDirectory.Value = new DirectoryInfo(initialPath ??= Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + Padding = new MarginPadding(10); + + InternalChildren = new Drawable[] + { + new FillFlowContainer + { + RelativeSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Children = new Drawable[] + { + new CurrentDirectoryDisplay + { + RelativeSizeAxes = Axes.X, + Height = 50, + }, + new OsuScrollContainer + { + RelativeSizeAxes = Axes.Both, + Child = directoryFlow = new FillFlowContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FillDirection.Vertical, + Spacing = new Vector2(2), + } + } + } + }, + }; + + currentDirectory.BindValueChanged(updateDisplay, true); + } + + private void updateDisplay(ValueChangedEvent directory) + { + directoryFlow.Clear(); + + if (directory.NewValue == null) + { + var drives = DriveInfo.GetDrives(); + + foreach (var drive in drives) + directoryFlow.Add(new DirectoryRow(drive.RootDirectory)); + } + else + { + directoryFlow.Add(new ParentDirectoryRow(currentDirectory.Value.Parent)); + + foreach (var dir in currentDirectory.Value.GetDirectories().OrderBy(d => d.Name)) + { + if ((dir.Attributes & FileAttributes.Hidden) == 0) + directoryFlow.Add(new DirectoryRow(dir)); + } + } + } + + public class CurrentDirectoryDisplay : CompositeDrawable + { + [Resolved] + private Bindable currentDirectory { get; set; } + + [BackgroundDependencyLoader] + private void load() + { + FillFlowContainer flow; + + InternalChildren = new Drawable[] + { + flow = new FillFlowContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.X, + Spacing = new Vector2(5), + Height = DirectoryRow.HEIGHT, + Direction = FillDirection.Horizontal, + }, + }; + + currentDirectory.BindValueChanged(dir => + { + flow.Clear(); + + flow.Add(new OsuSpriteText + { + Text = "Current Directory: ", + Font = OsuFont.Default.With(size: DirectoryRow.HEIGHT), + }); + + flow.Add(new ComputerRow()); + + List traversalRows = new List(); + + DirectoryInfo traverse = dir.NewValue; + + while (traverse != null) + { + traversalRows.Insert(0, new CurrentDisplayRow(traverse)); + traverse = traverse.Parent; + } + + flow.AddRange(traversalRows); + }, true); + } + + private class ComputerRow : CurrentDisplayRow + { + public override IconUsage? Icon => null; + + public ComputerRow() + : base(null, "Computer") + { + } + } + + private class CurrentDisplayRow : DirectoryRow + { + public CurrentDisplayRow(DirectoryInfo directory, string displayName = null) + : base(directory, displayName) + { + } + + [BackgroundDependencyLoader] + private void load() + { + Flow.Add(new SpriteIcon + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Icon = FontAwesome.Solid.ChevronRight, + Size = new Vector2(FONT_SIZE / 2) + }); + } + } + } + + private class ParentDirectoryRow : DirectoryRow + { + public override IconUsage? Icon => FontAwesome.Solid.Folder; + + public ParentDirectoryRow(DirectoryInfo directory) + : base(directory, "..") + { + } + } + + private class DirectoryRow : CompositeDrawable + { + public const float HEIGHT = 20; + + protected const float FONT_SIZE = 16; + + private readonly DirectoryInfo directory; + private readonly string displayName; + + protected FillFlowContainer Flow; + + [Resolved] + private Bindable currentDirectory { get; set; } + + public DirectoryRow(DirectoryInfo directory, string displayName = null) + { + this.directory = directory; + this.displayName = displayName; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + AutoSizeAxes = Axes.Both; + + Masking = true; + CornerRadius = 5; + + InternalChildren = new Drawable[] + { + new Box + { + Colour = colours.GreySeafoamDarker, + RelativeSizeAxes = Axes.Both, + }, + Flow = new FillFlowContainer + { + AutoSizeAxes = Axes.X, + Height = 20, + Margin = new MarginPadding { Vertical = 2, Horizontal = 5 }, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(5), + } + }; + + if (Icon.HasValue) + { + Flow.Add(new SpriteIcon + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Icon = Icon.Value, + Size = new Vector2(FONT_SIZE) + }); + } + + Flow.Add(new OsuSpriteText + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Text = displayName ?? directory.Name, + Font = OsuFont.Default.With(size: FONT_SIZE) + }); + } + + protected override bool OnClick(ClickEvent e) + { + currentDirectory.Value = directory; + return true; + } + + public virtual IconUsage? Icon => FontAwesome.Regular.Folder; + } + } +} From 246812e0b1b550c0bebb63739ad67a4b45f0f124 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 13 May 2020 18:42:20 +0900 Subject: [PATCH 4/7] Change breadcrumb display icons to match design --- .../UserInterfaceV2/DirectorySelector.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs b/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs index 5dcaacf0a4..1cd4ab6f01 100644 --- a/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs +++ b/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs @@ -145,7 +145,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 private class ComputerRow : CurrentDisplayRow { - public override IconUsage? Icon => null; + protected override IconUsage? Icon => null; public ComputerRow() : base(null, "Computer") @@ -171,12 +171,14 @@ namespace osu.Game.Graphics.UserInterfaceV2 Size = new Vector2(FONT_SIZE / 2) }); } + + protected override IconUsage? Icon => Directory.Name.Contains("/") ? base.Icon : null; } } private class ParentDirectoryRow : DirectoryRow { - public override IconUsage? Icon => FontAwesome.Solid.Folder; + protected override IconUsage? Icon => FontAwesome.Solid.Folder; public ParentDirectoryRow(DirectoryInfo directory) : base(directory, "..") @@ -190,7 +192,8 @@ namespace osu.Game.Graphics.UserInterfaceV2 protected const float FONT_SIZE = 16; - private readonly DirectoryInfo directory; + protected readonly DirectoryInfo Directory; + private readonly string displayName; protected FillFlowContainer Flow; @@ -200,7 +203,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 public DirectoryRow(DirectoryInfo directory, string displayName = null) { - this.directory = directory; + Directory = directory; this.displayName = displayName; } @@ -244,18 +247,18 @@ namespace osu.Game.Graphics.UserInterfaceV2 { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Text = displayName ?? directory.Name, + Text = displayName ?? Directory.Name, Font = OsuFont.Default.With(size: FONT_SIZE) }); } protected override bool OnClick(ClickEvent e) { - currentDirectory.Value = directory; + currentDirectory.Value = Directory; return true; } - public virtual IconUsage? Icon => FontAwesome.Regular.Folder; + protected virtual IconUsage? Icon => Directory.Name.Contains("/") ? FontAwesome.Solid.Database : FontAwesome.Regular.Folder; } } } From e9e03d038d780f13d62a3b29e9c6243148f10ebc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 13 May 2020 18:52:10 +0900 Subject: [PATCH 5/7] Tidy up naming and structure --- .../UserInterfaceV2/DirectorySelector.cs | 87 +++++++++---------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs b/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs index 1cd4ab6f01..427b9a1eff 100644 --- a/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs +++ b/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs @@ -34,10 +34,9 @@ namespace osu.Game.Graphics.UserInterfaceV2 currentDirectory.Value = new DirectoryInfo(initialPath ??= Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); } - protected override void LoadComplete() + [BackgroundDependencyLoader] + private void load() { - base.LoadComplete(); - Padding = new MarginPadding(10); InternalChildren = new Drawable[] @@ -80,30 +79,30 @@ namespace osu.Game.Graphics.UserInterfaceV2 var drives = DriveInfo.GetDrives(); foreach (var drive in drives) - directoryFlow.Add(new DirectoryRow(drive.RootDirectory)); + directoryFlow.Add(new DirectoryPiece(drive.RootDirectory)); } else { - directoryFlow.Add(new ParentDirectoryRow(currentDirectory.Value.Parent)); + directoryFlow.Add(new ParentDirectoryPiece(currentDirectory.Value.Parent)); foreach (var dir in currentDirectory.Value.GetDirectories().OrderBy(d => d.Name)) { if ((dir.Attributes & FileAttributes.Hidden) == 0) - directoryFlow.Add(new DirectoryRow(dir)); + directoryFlow.Add(new DirectoryPiece(dir)); } } } - public class CurrentDirectoryDisplay : CompositeDrawable + private class CurrentDirectoryDisplay : CompositeDrawable { [Resolved] private Bindable currentDirectory { get; set; } + private FillFlowContainer flow; + [BackgroundDependencyLoader] private void load() { - FillFlowContainer flow; - InternalChildren = new Drawable[] { flow = new FillFlowContainer @@ -112,50 +111,48 @@ namespace osu.Game.Graphics.UserInterfaceV2 Origin = Anchor.Centre, RelativeSizeAxes = Axes.X, Spacing = new Vector2(5), - Height = DirectoryRow.HEIGHT, + Height = DirectoryPiece.HEIGHT, Direction = FillDirection.Horizontal, }, }; - currentDirectory.BindValueChanged(dir => - { - flow.Clear(); - - flow.Add(new OsuSpriteText - { - Text = "Current Directory: ", - Font = OsuFont.Default.With(size: DirectoryRow.HEIGHT), - }); - - flow.Add(new ComputerRow()); - - List traversalRows = new List(); - - DirectoryInfo traverse = dir.NewValue; - - while (traverse != null) - { - traversalRows.Insert(0, new CurrentDisplayRow(traverse)); - traverse = traverse.Parent; - } - - flow.AddRange(traversalRows); - }, true); + currentDirectory.BindValueChanged(updateDisplay, true); } - private class ComputerRow : CurrentDisplayRow + private void updateDisplay(ValueChangedEvent dir) + { + flow.Clear(); + + List pathPieces = new List(); + + DirectoryInfo ptr = dir.NewValue; + + while (ptr != null) + { + pathPieces.Insert(0, new CurrentDisplayPiece(ptr)); + ptr = ptr.Parent; + } + + flow.ChildrenEnumerable = new Drawable[] + { + new OsuSpriteText { Text = "Current Directory: ", Font = OsuFont.Default.With(size: DirectoryPiece.HEIGHT), }, + new ComputerPiece(), + }.Concat(pathPieces); + } + + private class ComputerPiece : CurrentDisplayPiece { protected override IconUsage? Icon => null; - public ComputerRow() + public ComputerPiece() : base(null, "Computer") { } } - private class CurrentDisplayRow : DirectoryRow + private class CurrentDisplayPiece : DirectoryPiece { - public CurrentDisplayRow(DirectoryInfo directory, string displayName = null) + public CurrentDisplayPiece(DirectoryInfo directory, string displayName = null) : base(directory, displayName) { } @@ -172,21 +169,21 @@ namespace osu.Game.Graphics.UserInterfaceV2 }); } - protected override IconUsage? Icon => Directory.Name.Contains("/") ? base.Icon : null; + protected override IconUsage? Icon => Directory.Name.Contains(Path.DirectorySeparatorChar) ? base.Icon : null; } } - private class ParentDirectoryRow : DirectoryRow + private class ParentDirectoryPiece : DirectoryPiece { protected override IconUsage? Icon => FontAwesome.Solid.Folder; - public ParentDirectoryRow(DirectoryInfo directory) + public ParentDirectoryPiece(DirectoryInfo directory) : base(directory, "..") { } } - private class DirectoryRow : CompositeDrawable + private class DirectoryPiece : CompositeDrawable { public const float HEIGHT = 20; @@ -201,7 +198,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 [Resolved] private Bindable currentDirectory { get; set; } - public DirectoryRow(DirectoryInfo directory, string displayName = null) + public DirectoryPiece(DirectoryInfo directory, string displayName = null) { Directory = directory; this.displayName = displayName; @@ -258,7 +255,9 @@ namespace osu.Game.Graphics.UserInterfaceV2 return true; } - protected virtual IconUsage? Icon => Directory.Name.Contains("/") ? FontAwesome.Solid.Database : FontAwesome.Regular.Folder; + protected virtual IconUsage? Icon => Directory.Name.Contains(Path.DirectorySeparatorChar) + ? FontAwesome.Solid.Database + : FontAwesome.Regular.Folder; } } } From c048d9b6ae215eb0923ba39d060e5ae1adb0ace7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 13 May 2020 18:55:06 +0900 Subject: [PATCH 6/7] Fix incorrect assignment --- osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs b/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs index 427b9a1eff..59de931df5 100644 --- a/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs +++ b/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs @@ -31,7 +31,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 public DirectorySelector(string initialPath = null) { - currentDirectory.Value = new DirectoryInfo(initialPath ??= Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); + currentDirectory.Value = new DirectoryInfo(initialPath ?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); } [BackgroundDependencyLoader] From 149cb93e8cb314a87c7a0f7a97293ebac98372cf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 14 May 2020 13:18:37 +0900 Subject: [PATCH 7/7] Add very basic error handling when a directory cannot be enumerated --- .../UserInterfaceV2/DirectorySelector.cs | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs b/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs index 59de931df5..ee428c0047 100644 --- a/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs +++ b/osu.Game/Graphics/UserInterfaceV2/DirectorySelector.cs @@ -16,6 +16,7 @@ using osu.Framework.Platform; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osuTK; +using osuTK.Graphics; namespace osu.Game.Graphics.UserInterfaceV2 { @@ -74,22 +75,31 @@ namespace osu.Game.Graphics.UserInterfaceV2 { directoryFlow.Clear(); - if (directory.NewValue == null) + try { - var drives = DriveInfo.GetDrives(); - - foreach (var drive in drives) - directoryFlow.Add(new DirectoryPiece(drive.RootDirectory)); - } - else - { - directoryFlow.Add(new ParentDirectoryPiece(currentDirectory.Value.Parent)); - - foreach (var dir in currentDirectory.Value.GetDirectories().OrderBy(d => d.Name)) + if (directory.NewValue == null) { - if ((dir.Attributes & FileAttributes.Hidden) == 0) - directoryFlow.Add(new DirectoryPiece(dir)); + var drives = DriveInfo.GetDrives(); + + foreach (var drive in drives) + directoryFlow.Add(new DirectoryPiece(drive.RootDirectory)); } + else + { + directoryFlow.Add(new ParentDirectoryPiece(currentDirectory.Value.Parent)); + + foreach (var dir in currentDirectory.Value.GetDirectories().OrderBy(d => d.Name)) + { + if ((dir.Attributes & FileAttributes.Hidden) == 0) + directoryFlow.Add(new DirectoryPiece(dir)); + } + } + } + catch (Exception) + { + currentDirectory.Value = directory.OldValue; + + this.FlashColour(Color4.Red, 300); } }