Merge branch 'master' into update-section-selection-childcount

This commit is contained in:
Salman Ahmed 2021-08-23 20:43:46 +03:00 committed by GitHub
commit 13a24ed36f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 68 deletions

View File

@ -8,28 +8,28 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
using osuTK;
namespace osu.Game.Screens.Edit.Setup namespace osu.Game.Screens.Edit.Setup
{ {
/// <summary> /// <summary>
/// A labelled textbox which reveals an inline file chooser when clicked. /// A labelled textbox which reveals an inline file chooser when clicked.
/// </summary> /// </summary>
internal class FileChooserLabelledTextBox : LabelledTextBox, ICanAcceptFiles internal class FileChooserLabelledTextBox : LabelledTextBox, ICanAcceptFiles, IHasPopover
{ {
private readonly string[] handledExtensions; private readonly string[] handledExtensions;
public IEnumerable<string> HandledExtensions => handledExtensions;
/// <summary> public IEnumerable<string> HandledExtensions => handledExtensions;
/// The target container to display the file chooser in.
/// </summary>
public Container Target;
private readonly Bindable<FileInfo> currentFile = new Bindable<FileInfo>(); private readonly Bindable<FileInfo> currentFile = new Bindable<FileInfo>();
@ -51,23 +51,9 @@ namespace osu.Game.Screens.Edit.Setup
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
CornerRadius = CORNER_RADIUS, CornerRadius = CORNER_RADIUS,
OnFocused = DisplayFileChooser OnFocused = this.ShowPopover
}; };
public void DisplayFileChooser()
{
OsuFileSelector fileSelector;
Target.Child = fileSelector = new OsuFileSelector(currentFile.Value?.DirectoryName, handledExtensions)
{
RelativeSizeAxes = Axes.X,
Height = 400,
CurrentFile = { BindTarget = currentFile }
};
sectionsContainer.ScrollTo(fileSelector);
}
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -81,7 +67,7 @@ namespace osu.Game.Screens.Edit.Setup
if (file.NewValue == null) if (file.NewValue == null)
return; return;
Target.Clear(); this.HidePopover();
Current.Value = file.NewValue.FullName; Current.Value = file.NewValue.FullName;
} }
@ -111,5 +97,23 @@ namespace osu.Game.Screens.Edit.Setup
GetContainingInputManager().TriggerFocusContention(this); GetContainingInputManager().TriggerFocusContention(this);
} }
} }
public Popover GetPopover() => new FileChooserPopover(handledExtensions, currentFile);
private class FileChooserPopover : OsuPopover
{
public FileChooserPopover(string[] handledExtensions, Bindable<FileInfo> currentFile)
{
Child = new Container
{
Size = new Vector2(600, 400),
Child = new OsuFileSelector(currentFile.Value?.DirectoryName, handledExtensions)
{
RelativeSizeAxes = Axes.Both,
CurrentFile = { BindTarget = currentFile }
},
};
}
}
} }
} }

View File

@ -6,7 +6,6 @@ using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
@ -39,62 +38,30 @@ namespace osu.Game.Screens.Edit.Setup
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Container audioTrackFileChooserContainer = createFileChooserContainer();
Container backgroundFileChooserContainer = createFileChooserContainer();
Children = new Drawable[] Children = new Drawable[]
{ {
new FillFlowContainer backgroundTextBox = new FileChooserLabelledTextBox(".jpg", ".jpeg", ".png")
{ {
RelativeSizeAxes = Axes.X, Label = "Background",
AutoSizeAxes = Axes.Y, FixedLabelWidth = LABEL_WIDTH,
Direction = FillDirection.Vertical, PlaceholderText = "Click to select a background image",
Children = new Drawable[] Current = { Value = working.Value.Metadata.BackgroundFile },
{ TabbableContentContainer = this
backgroundTextBox = new FileChooserLabelledTextBox(".jpg", ".jpeg", ".png")
{
Label = "Background",
FixedLabelWidth = LABEL_WIDTH,
PlaceholderText = "Click to select a background image",
Current = { Value = working.Value.Metadata.BackgroundFile },
Target = backgroundFileChooserContainer,
TabbableContentContainer = this
},
backgroundFileChooserContainer,
}
}, },
new FillFlowContainer audioTrackTextBox = new FileChooserLabelledTextBox(".mp3", ".ogg")
{ {
RelativeSizeAxes = Axes.X, Label = "Audio Track",
AutoSizeAxes = Axes.Y, FixedLabelWidth = LABEL_WIDTH,
Direction = FillDirection.Vertical, PlaceholderText = "Click to select a track",
Children = new Drawable[] Current = { Value = working.Value.Metadata.AudioFile },
{ TabbableContentContainer = this
audioTrackTextBox = new FileChooserLabelledTextBox(".mp3", ".ogg") },
{
Label = "Audio Track",
FixedLabelWidth = LABEL_WIDTH,
PlaceholderText = "Click to select a track",
Current = { Value = working.Value.Metadata.AudioFile },
Target = audioTrackFileChooserContainer,
TabbableContentContainer = this
},
audioTrackFileChooserContainer,
}
}
}; };
backgroundTextBox.Current.BindValueChanged(backgroundChanged); backgroundTextBox.Current.BindValueChanged(backgroundChanged);
audioTrackTextBox.Current.BindValueChanged(audioTrackChanged); audioTrackTextBox.Current.BindValueChanged(audioTrackChanged);
} }
private static Container createFileChooserContainer() =>
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
};
public bool ChangeBackgroundImage(string path) public bool ChangeBackgroundImage(string path)
{ {
var info = new FileInfo(path); var info = new FileInfo(path);