1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 16:12:57 +08:00

Tidy up naming and structure

This commit is contained in:
Dean Herbert 2020-05-13 18:52:10 +09:00
parent 246812e0b1
commit e9e03d038d

View File

@ -34,10 +34,9 @@ namespace osu.Game.Graphics.UserInterfaceV2
currentDirectory.Value = new DirectoryInfo(initialPath ??= Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); currentDirectory.Value = new DirectoryInfo(initialPath ??= Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
} }
protected override void LoadComplete() [BackgroundDependencyLoader]
private void load()
{ {
base.LoadComplete();
Padding = new MarginPadding(10); Padding = new MarginPadding(10);
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
@ -80,30 +79,30 @@ namespace osu.Game.Graphics.UserInterfaceV2
var drives = DriveInfo.GetDrives(); var drives = DriveInfo.GetDrives();
foreach (var drive in drives) foreach (var drive in drives)
directoryFlow.Add(new DirectoryRow(drive.RootDirectory)); directoryFlow.Add(new DirectoryPiece(drive.RootDirectory));
} }
else 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)) foreach (var dir in currentDirectory.Value.GetDirectories().OrderBy(d => d.Name))
{ {
if ((dir.Attributes & FileAttributes.Hidden) == 0) 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] [Resolved]
private Bindable<DirectoryInfo> currentDirectory { get; set; } private Bindable<DirectoryInfo> currentDirectory { get; set; }
private FillFlowContainer flow;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
FillFlowContainer flow;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
flow = new FillFlowContainer flow = new FillFlowContainer
@ -112,50 +111,48 @@ namespace osu.Game.Graphics.UserInterfaceV2
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Spacing = new Vector2(5), Spacing = new Vector2(5),
Height = DirectoryRow.HEIGHT, Height = DirectoryPiece.HEIGHT,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
}, },
}; };
currentDirectory.BindValueChanged(dir => currentDirectory.BindValueChanged(updateDisplay, true);
}
private void updateDisplay(ValueChangedEvent<DirectoryInfo> dir)
{ {
flow.Clear(); flow.Clear();
flow.Add(new OsuSpriteText List<DirectoryPiece> pathPieces = new List<DirectoryPiece>();
DirectoryInfo ptr = dir.NewValue;
while (ptr != null)
{ {
Text = "Current Directory: ", pathPieces.Insert(0, new CurrentDisplayPiece(ptr));
Font = OsuFont.Default.With(size: DirectoryRow.HEIGHT), ptr = ptr.Parent;
});
flow.Add(new ComputerRow());
List<DirectoryRow> traversalRows = new List<DirectoryRow>();
DirectoryInfo traverse = dir.NewValue;
while (traverse != null)
{
traversalRows.Insert(0, new CurrentDisplayRow(traverse));
traverse = traverse.Parent;
} }
flow.AddRange(traversalRows); flow.ChildrenEnumerable = new Drawable[]
}, true); {
new OsuSpriteText { Text = "Current Directory: ", Font = OsuFont.Default.With(size: DirectoryPiece.HEIGHT), },
new ComputerPiece(),
}.Concat(pathPieces);
} }
private class ComputerRow : CurrentDisplayRow private class ComputerPiece : CurrentDisplayPiece
{ {
protected override IconUsage? Icon => null; protected override IconUsage? Icon => null;
public ComputerRow() public ComputerPiece()
: base(null, "Computer") : 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) : 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; protected override IconUsage? Icon => FontAwesome.Solid.Folder;
public ParentDirectoryRow(DirectoryInfo directory) public ParentDirectoryPiece(DirectoryInfo directory)
: base(directory, "..") : base(directory, "..")
{ {
} }
} }
private class DirectoryRow : CompositeDrawable private class DirectoryPiece : CompositeDrawable
{ {
public const float HEIGHT = 20; public const float HEIGHT = 20;
@ -201,7 +198,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
[Resolved] [Resolved]
private Bindable<DirectoryInfo> currentDirectory { get; set; } private Bindable<DirectoryInfo> currentDirectory { get; set; }
public DirectoryRow(DirectoryInfo directory, string displayName = null) public DirectoryPiece(DirectoryInfo directory, string displayName = null)
{ {
Directory = directory; Directory = directory;
this.displayName = displayName; this.displayName = displayName;
@ -258,7 +255,9 @@ namespace osu.Game.Graphics.UserInterfaceV2
return true; 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;
} }
} }
} }