2021-05-06 02:27:28 +08:00
|
|
|
|
// 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 osu.Framework.Graphics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
|
|
|
using osu.Game.Screens;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-05-17 15:40:42 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2021-05-06 02:27:28 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Screens;
|
2021-05-18 12:40:26 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2021-08-12 12:26:42 +08:00
|
|
|
|
using osu.Game.Localisation;
|
2021-05-06 02:27:28 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|
|
|
|
{
|
|
|
|
|
public abstract class DirectorySelectScreen : OsuScreen
|
|
|
|
|
{
|
|
|
|
|
private TriangleButton selectionButton;
|
|
|
|
|
|
2021-07-06 06:15:17 +08:00
|
|
|
|
private OsuDirectorySelector directorySelector;
|
2021-05-06 02:27:28 +08:00
|
|
|
|
|
2021-09-14 22:37:57 +08:00
|
|
|
|
public override bool? AllowTrackAdjustments => false;
|
2021-09-13 14:00:33 +08:00
|
|
|
|
|
2021-05-17 15:40:42 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Text to display in the header to inform the user of what they are selecting.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract LocalisableString HeaderText { get; }
|
2021-05-06 02:27:28 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called upon selection of a directory by the user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="directory">The selected directory</param>
|
|
|
|
|
protected abstract void OnSelection(DirectoryInfo directory);
|
|
|
|
|
|
2021-05-13 22:28:03 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the current directory is considered to be valid and can be selected.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info">The current directory.</param>
|
|
|
|
|
/// <returns>Whether the selected directory is considered valid.</returns>
|
2021-05-13 17:14:05 +08:00
|
|
|
|
protected virtual bool IsValidDirectory(DirectoryInfo info) => true;
|
2021-05-06 02:27:28 +08:00
|
|
|
|
|
2021-05-13 22:28:03 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The path at which to start selection from.
|
|
|
|
|
/// </summary>
|
2021-05-06 04:13:25 +08:00
|
|
|
|
protected virtual DirectoryInfo InitialPath => null;
|
|
|
|
|
|
2021-05-06 02:27:28 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
InternalChild = new Container
|
|
|
|
|
{
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 10,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(0.5f, 0.8f),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colours.GreySeafoamDark
|
|
|
|
|
},
|
|
|
|
|
new GridContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
RowDimensions = new[]
|
|
|
|
|
{
|
2021-05-18 12:40:26 +08:00
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
2021-05-06 02:27:28 +08:00
|
|
|
|
new Dimension(),
|
2021-05-18 12:40:26 +08:00
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
2021-05-06 02:27:28 +08:00
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
2021-05-18 12:40:26 +08:00
|
|
|
|
new OsuTextFlowContainer(cp =>
|
2021-05-06 02:27:28 +08:00
|
|
|
|
{
|
2021-05-18 12:40:26 +08:00
|
|
|
|
cp.Font = OsuFont.Default.With(size: 24);
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
Text = HeaderText.ToString(),
|
|
|
|
|
TextAnchor = Anchor.TopCentre,
|
|
|
|
|
Margin = new MarginPadding(10),
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2021-05-17 15:40:42 +08:00
|
|
|
|
}
|
2021-05-06 02:27:28 +08:00
|
|
|
|
},
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
2021-07-06 06:15:17 +08:00
|
|
|
|
directorySelector = new OsuDirectorySelector
|
2021-05-06 02:27:28 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
selectionButton = new TriangleButton
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Width = 300,
|
2021-05-18 12:40:26 +08:00
|
|
|
|
Margin = new MarginPadding(10),
|
2021-08-12 12:26:42 +08:00
|
|
|
|
Text = MaintenanceSettingsStrings.SelectDirectory,
|
2021-05-06 17:12:19 +08:00
|
|
|
|
Action = () => OnSelection(directorySelector.CurrentPath.Value)
|
2021-05-06 02:27:28 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2021-05-06 04:13:25 +08:00
|
|
|
|
if (InitialPath != null)
|
2021-05-06 17:12:19 +08:00
|
|
|
|
directorySelector.CurrentPath.Value = InitialPath;
|
2021-05-06 04:13:25 +08:00
|
|
|
|
|
2021-05-14 01:31:10 +08:00
|
|
|
|
directorySelector.CurrentPath.BindValueChanged(e => selectionButton.Enabled.Value = e.NewValue != null && IsValidDirectory(e.NewValue), true);
|
2021-05-06 02:27:28 +08:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnSuspending(IScreen next)
|
|
|
|
|
{
|
|
|
|
|
base.OnSuspending(next);
|
|
|
|
|
|
|
|
|
|
this.FadeOut(250);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|