1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 21:17:33 +08:00
osu-lazer/osu.Game/Overlays/Settings/Sections/Maintenance/DirectorySelectScreen.cs

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

135 lines
5.0 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 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;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Screens;
2021-05-18 12:40:26 +08:00
using osu.Game.Graphics.Containers;
using osu.Game.Localisation;
namespace osu.Game.Overlays.Settings.Sections.Maintenance
{
public abstract class DirectorySelectScreen : OsuScreen
{
private TriangleButton selectionButton;
private OsuDirectorySelector directorySelector;
/// <summary>
/// Text to display in the header to inform the user of what they are selecting.
/// </summary>
public abstract LocalisableString HeaderText { get; }
/// <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>
protected virtual bool IsValidDirectory(DirectoryInfo info) => true;
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;
[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),
new Dimension(),
2021-05-18 12:40:26 +08:00
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
{
new Drawable[]
{
2021-05-18 12:40:26 +08:00
new OsuTextFlowContainer(cp =>
{
2021-05-18 12:40:26 +08:00
cp.Font = OsuFont.Default.With(size: 24);
})
{
Text = HeaderText,
2021-05-18 12:40:26 +08:00
TextAnchor = Anchor.TopCentre,
Margin = new MarginPadding(10),
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}
},
new Drawable[]
{
directorySelector = new OsuDirectorySelector
{
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),
Text = MaintenanceSettingsStrings.SelectDirectory,
2021-05-06 17:12:19 +08:00
Action = () => OnSelection(directorySelector.CurrentPath.Value)
},
}
}
}
}
};
}
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);
base.LoadComplete();
}
public override void OnSuspending(ScreenTransitionEvent e)
{
base.OnSuspending(e);
this.FadeOut(250);
}
}
}