1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 12:03:20 +08:00
osu-lazer/osu.Game/Graphics/UserInterfaceV2/OsuFileSelector.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

127 lines
4.3 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.IO;
2022-06-06 19:11:43 +08:00
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
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
{
public partial class OsuFileSelector : FileSelector
{
private Box hiddenToggleBackground = null!;
public OsuFileSelector(string? initialPath = null, string[]? validFileExtensions = null)
: base(initialPath, validFileExtensions)
{
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
AddInternal(new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background5,
Depth = float.MaxValue,
});
hiddenToggleBackground.Colour = colourProvider.Background4;
}
protected override ScrollContainer<Drawable> CreateScrollContainer() => new OsuScrollContainer
{
Padding = new MarginPadding
{
Horizontal = 20,
Vertical = 15,
}
};
protected override DirectorySelectorBreadcrumbDisplay CreateBreadcrumb() => new OsuDirectorySelectorBreadcrumbDisplay();
protected override Drawable CreateHiddenToggleButton() => new Container
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Children = new Drawable[]
{
hiddenToggleBackground = new Box
{
RelativeSizeAxes = Axes.Both,
},
new OsuDirectorySelectorHiddenToggle
{
Current = { BindTarget = ShowHiddenItems },
},
}
};
protected override DirectorySelectorDirectory CreateParentDirectoryItem(DirectoryInfo directory) => new OsuDirectorySelectorParentDirectory(directory);
protected override DirectorySelectorDirectory CreateDirectoryItem(DirectoryInfo directory, string? displayName = null) => new OsuDirectorySelectorDirectory(directory, displayName);
protected override DirectoryListingFile CreateFileItem(FileInfo file) => new OsuDirectoryListingFile(file);
protected override void NotifySelectionError() => this.FlashColour(Colour4.Red, 300);
protected partial class OsuDirectoryListingFile : DirectoryListingFile
{
public OsuDirectoryListingFile(FileInfo file)
: base(file)
{
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
Flow.AutoSizeAxes = Axes.X;
Flow.Height = OsuDirectorySelector.ITEM_HEIGHT;
AddRangeInternal(new Drawable[]
{
new HoverClickSounds()
});
Colour = colourProvider.Light3;
}
protected override IconUsage? Icon
{
get
{
2023-04-21 08:35:28 +08:00
if (OsuGameBase.VIDEO_EXTENSIONS.Contains(File.Extension.ToLowerInvariant()))
2022-06-06 19:11:43 +08:00
return FontAwesome.Regular.FileVideo;
switch (File.Extension)
{
case @".ogg":
case @".mp3":
case @".wav":
return FontAwesome.Regular.FileAudio;
case @".jpg":
case @".jpeg":
case @".png":
return FontAwesome.Regular.FileImage;
default:
return FontAwesome.Regular.File;
}
}
}
protected override SpriteText CreateSpriteText() => new OsuSpriteText().With(t => t.Font = OsuFont.Default.With(weight: FontWeight.SemiBold));
}
}
}