mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 04:22:54 +08:00
74 lines
2.1 KiB
C#
74 lines
2.1 KiB
C#
// 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;
|
|
using System.IO;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Input.Events;
|
|
using osu.Game.Graphics.UserInterface;
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
|
|
namespace osu.Game.Screens.Edit.Setup
|
|
{
|
|
/// <summary>
|
|
/// A labelled textbox which reveals an inline file chooser when clicked.
|
|
/// </summary>
|
|
internal class FileChooserLabelledTextBox : LabelledTextBox
|
|
{
|
|
public Container Target;
|
|
|
|
private readonly IBindable<FileInfo> currentFile = new Bindable<FileInfo>();
|
|
|
|
public FileChooserLabelledTextBox()
|
|
{
|
|
currentFile.BindValueChanged(onFileSelected);
|
|
}
|
|
|
|
private void onFileSelected(ValueChangedEvent<FileInfo> file)
|
|
{
|
|
if (file.NewValue == null)
|
|
return;
|
|
|
|
Target.Clear();
|
|
Current.Value = file.NewValue.FullName;
|
|
}
|
|
|
|
protected override OsuTextBox CreateTextBox() =>
|
|
new FileChooserOsuTextBox
|
|
{
|
|
Anchor = Anchor.Centre,
|
|
Origin = Anchor.Centre,
|
|
RelativeSizeAxes = Axes.X,
|
|
CornerRadius = CORNER_RADIUS,
|
|
OnFocused = DisplayFileChooser
|
|
};
|
|
|
|
public void DisplayFileChooser()
|
|
{
|
|
Target.Child = new FileSelector(validFileExtensions: ResourcesSection.AudioExtensions)
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
Height = 400,
|
|
Anchor = Anchor.Centre,
|
|
Origin = Anchor.Centre,
|
|
CurrentFile = { BindTarget = currentFile }
|
|
};
|
|
}
|
|
|
|
internal class FileChooserOsuTextBox : OsuTextBox
|
|
{
|
|
public Action OnFocused;
|
|
|
|
protected override void OnFocus(FocusEvent e)
|
|
{
|
|
OnFocused?.Invoke();
|
|
base.OnFocus(e);
|
|
|
|
GetContainingInputManager().TriggerFocusContention(this);
|
|
}
|
|
}
|
|
}
|
|
}
|