mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 23:59:16 +08:00
Add FormBeatmapFileSelector
for intermediate user-choice step
This commit is contained in:
parent
1468385559
commit
b70fb4b0fe
@ -242,20 +242,26 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
|
|
||||||
Task ICanAcceptFiles.Import(ImportTask[] tasks, ImportParameters parameters) => throw new NotImplementedException();
|
Task ICanAcceptFiles.Import(ImportTask[] tasks, ImportParameters parameters) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
protected virtual FileChooserPopover CreatePopover(string[] handledExtensions, Bindable<FileInfo?> current, string? chooserPath) => new FileChooserPopover(handledExtensions, current, chooserPath);
|
||||||
|
|
||||||
public Popover GetPopover()
|
public Popover GetPopover()
|
||||||
{
|
{
|
||||||
var popover = new FileChooserPopover(handledExtensions, Current, initialChooserPath);
|
var popover = CreatePopover(handledExtensions, Current, initialChooserPath);
|
||||||
popoverState.UnbindBindings();
|
popoverState.UnbindBindings();
|
||||||
popoverState.BindTo(popover.State);
|
popoverState.BindTo(popover.State);
|
||||||
return popover;
|
return popover;
|
||||||
}
|
}
|
||||||
|
|
||||||
private partial class FileChooserPopover : OsuPopover
|
protected partial class FileChooserPopover : OsuPopover
|
||||||
{
|
{
|
||||||
protected override string PopInSampleName => "UI/overlay-big-pop-in";
|
protected override string PopInSampleName => "UI/overlay-big-pop-in";
|
||||||
protected override string PopOutSampleName => "UI/overlay-big-pop-out";
|
protected override string PopOutSampleName => "UI/overlay-big-pop-out";
|
||||||
|
|
||||||
public FileChooserPopover(string[] handledExtensions, Bindable<FileInfo?> currentFile, string? chooserPath)
|
private readonly Bindable<FileInfo?> current = new Bindable<FileInfo?>();
|
||||||
|
|
||||||
|
protected OsuFileSelector FileSelector;
|
||||||
|
|
||||||
|
public FileChooserPopover(string[] handledExtensions, Bindable<FileInfo?> current, string? chooserPath)
|
||||||
: base(false)
|
: base(false)
|
||||||
{
|
{
|
||||||
Child = new Container
|
Child = new Container
|
||||||
@ -264,12 +270,13 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
// simplest solution to avoid underlying text to bleed through the bottom border
|
// simplest solution to avoid underlying text to bleed through the bottom border
|
||||||
// https://github.com/ppy/osu/pull/30005#issuecomment-2378884430
|
// https://github.com/ppy/osu/pull/30005#issuecomment-2378884430
|
||||||
Padding = new MarginPadding { Bottom = 1 },
|
Padding = new MarginPadding { Bottom = 1 },
|
||||||
Child = new OsuFileSelector(chooserPath, handledExtensions)
|
Child = FileSelector = new OsuFileSelector(chooserPath, handledExtensions)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
CurrentFile = { BindTarget = currentFile }
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.current.BindTo(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -292,6 +299,19 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
FileSelector.CurrentFile.ValueChanged += f =>
|
||||||
|
{
|
||||||
|
if (f.NewValue != null)
|
||||||
|
OnFileSelected(f.NewValue);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnFileSelected(FileInfo file) => current.Value = file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
161
osu.Game/Screens/Edit/Setup/FormBeatmapFileSelector.cs
Normal file
161
osu.Game/Screens/Edit/Setup/FormBeatmapFileSelector.cs
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
// 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.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.Edit.Setup
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A type of <see cref="FormFileSelector"/> dedicated to beatmap resources.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This expands on <see cref="FormFileSelector"/> by adding an intermediate step before finalisation
|
||||||
|
/// to choose whether the selected file should be applied to the current difficulty or all difficulties in the set,
|
||||||
|
/// the user's choice is saved in <see cref="ApplyToAllDifficulties"/> before the file selection is finalised and propagated to <see cref="FormFileSelector.Current"/>.
|
||||||
|
/// </remarks>
|
||||||
|
public partial class FormBeatmapFileSelector : FormFileSelector
|
||||||
|
{
|
||||||
|
private readonly bool multipleDifficulties;
|
||||||
|
|
||||||
|
public readonly Bindable<bool> ApplyToAllDifficulties = new Bindable<bool>(true);
|
||||||
|
|
||||||
|
public FormBeatmapFileSelector(bool multipleDifficulties, params string[] handledExtensions)
|
||||||
|
: base(handledExtensions)
|
||||||
|
{
|
||||||
|
this.multipleDifficulties = multipleDifficulties;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override FileChooserPopover CreatePopover(string[] handledExtensions, Bindable<FileInfo?> current, string? chooserPath)
|
||||||
|
{
|
||||||
|
var popover = new BeatmapFileChooserPopover(handledExtensions, current, chooserPath, multipleDifficulties);
|
||||||
|
|
||||||
|
popover.ApplyToAllDifficulties.ValueChanged += v =>
|
||||||
|
{
|
||||||
|
Debug.Assert(v.NewValue != null);
|
||||||
|
ApplyToAllDifficulties.Value = v.NewValue.Value;
|
||||||
|
};
|
||||||
|
|
||||||
|
return popover;
|
||||||
|
}
|
||||||
|
|
||||||
|
private partial class BeatmapFileChooserPopover : FileChooserPopover
|
||||||
|
{
|
||||||
|
private readonly bool multipleDifficulties;
|
||||||
|
|
||||||
|
public readonly Bindable<bool?> ApplyToAllDifficulties = new Bindable<bool?>();
|
||||||
|
|
||||||
|
private Container changeScopeContainer = null!;
|
||||||
|
|
||||||
|
public BeatmapFileChooserPopover(string[] handledExtensions, Bindable<FileInfo?> current, string? chooserPath, bool multipleDifficulties)
|
||||||
|
: base(handledExtensions, current, chooserPath)
|
||||||
|
{
|
||||||
|
this.multipleDifficulties = multipleDifficulties;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OverlayColourProvider colourProvider, OsuColour colours)
|
||||||
|
{
|
||||||
|
Add(changeScopeContainer = new InputBlockingContainer
|
||||||
|
{
|
||||||
|
Alpha = 0f,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
Colour = colourProvider.Background6.Opacity(0.9f),
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
},
|
||||||
|
new Container
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Masking = true,
|
||||||
|
CornerRadius = 10f,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
Colour = colourProvider.Background5,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
},
|
||||||
|
new FillFlowContainer
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Vertical,
|
||||||
|
Spacing = new Vector2(0f, 10f),
|
||||||
|
Margin = new MarginPadding(30),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Text = "Apply this change to all difficulties?",
|
||||||
|
Margin = new MarginPadding { Bottom = 20f },
|
||||||
|
},
|
||||||
|
new RoundedButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Width = 300f,
|
||||||
|
Text = "Apply to all difficulties",
|
||||||
|
Action = () => ApplyToAllDifficulties.Value = true,
|
||||||
|
BackgroundColour = colours.Red2,
|
||||||
|
},
|
||||||
|
new RoundedButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Width = 300f,
|
||||||
|
Text = "Only apply to this difficulty",
|
||||||
|
Action = () => ApplyToAllDifficulties.Value = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
ApplyToAllDifficulties.ValueChanged += onChangeScopeSelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFileSelected(FileInfo file)
|
||||||
|
{
|
||||||
|
if (multipleDifficulties)
|
||||||
|
changeScopeContainer.FadeIn(200, Easing.InQuint);
|
||||||
|
else
|
||||||
|
base.OnFileSelected(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onChangeScopeSelected(ValueChangedEvent<bool?> c)
|
||||||
|
{
|
||||||
|
if (c.NewValue == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Debug.Assert(FileSelector.CurrentFile.Value != null);
|
||||||
|
base.OnFileSelected(FileSelector.CurrentFile.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user