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-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,
|
2021-12-10 13:15:00 +08:00
|
|
|
|
Colour = colours.GreySeaFoamDark
|
2021-05-06 02:27:28 +08:00
|
|
|
|
},
|
|
|
|
|
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);
|
|
|
|
|
})
|
|
|
|
|
{
|
2021-10-31 00:50:34 +08:00
|
|
|
|
Text = HeaderText,
|
2021-05-18 12:40:26 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
|
public override void OnSuspending(ScreenTransitionEvent e)
|
2021-05-06 02:27:28 +08:00
|
|
|
|
{
|
2022-04-21 23:52:44 +08:00
|
|
|
|
base.OnSuspending(e);
|
2021-05-06 02:27:28 +08:00
|
|
|
|
|
|
|
|
|
this.FadeOut(250);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|