1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:43:21 +08:00

Update background/track file chooser to not display filename

This commit is contained in:
Salman Ahmed 2022-06-15 09:52:12 +03:00
parent f3f0960335
commit 6a8cf514e0
3 changed files with 35 additions and 19 deletions

View File

@ -15,7 +15,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
{ {
} }
public Bindable<TValue> Current public virtual Bindable<TValue> Current
{ {
get => Component.Current; get => Component.Current;
set => Component.Current = value; set => Component.Current = value;

View File

@ -21,10 +21,7 @@ using osuTK;
namespace osu.Game.Screens.Edit.Setup namespace osu.Game.Screens.Edit.Setup
{ {
/// <summary> internal class LabelledFileChooser : LabelledTextBoxWithPopover, ICanAcceptFiles
/// A labelled textbox which reveals an inline file chooser when clicked.
/// </summary>
internal class FileChooserLabelledTextBox : LabelledTextBoxWithPopover, ICanAcceptFiles
{ {
private readonly string[] handledExtensions; private readonly string[] handledExtensions;
@ -35,7 +32,15 @@ namespace osu.Game.Screens.Edit.Setup
[Resolved] [Resolved]
private OsuGameBase game { get; set; } = null!; private OsuGameBase game { get; set; } = null!;
public FileChooserLabelledTextBox(params string[] handledExtensions) private readonly BindableWithCurrent<string> current = new BindableWithCurrent<string>();
public override Bindable<string> Current
{
get => current.Current;
set => current.Current = value;
}
public LabelledFileChooser(params string[] handledExtensions)
{ {
this.handledExtensions = handledExtensions; this.handledExtensions = handledExtensions;
} }

View File

@ -8,15 +8,14 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays; using osu.Game.Overlays;
namespace osu.Game.Screens.Edit.Setup namespace osu.Game.Screens.Edit.Setup
{ {
internal class ResourcesSection : SetupSection internal class ResourcesSection : SetupSection
{ {
private LabelledTextBox audioTrackTextBox; private LabelledFileChooser audioTrackChooser;
private LabelledTextBox backgroundTextBox; private LabelledFileChooser backgroundChooser;
public override LocalisableString Title => "Resources"; public override LocalisableString Title => "Resources";
@ -40,26 +39,24 @@ namespace osu.Game.Screens.Edit.Setup
{ {
Children = new Drawable[] Children = new Drawable[]
{ {
backgroundTextBox = new FileChooserLabelledTextBox(".jpg", ".jpeg", ".png") backgroundChooser = new LabelledFileChooser(".jpg", ".jpeg", ".png")
{ {
Label = "Background", Label = "Background",
FixedLabelWidth = LABEL_WIDTH, FixedLabelWidth = LABEL_WIDTH,
PlaceholderText = "Click to select a background image",
Current = { Value = working.Value.Metadata.BackgroundFile }, Current = { Value = working.Value.Metadata.BackgroundFile },
TabbableContentContainer = this TabbableContentContainer = this
}, },
audioTrackTextBox = new FileChooserLabelledTextBox(".mp3", ".ogg") audioTrackChooser = new LabelledFileChooser(".mp3", ".ogg")
{ {
Label = "Audio Track", Label = "Audio Track",
FixedLabelWidth = LABEL_WIDTH, FixedLabelWidth = LABEL_WIDTH,
PlaceholderText = "Click to select a track",
Current = { Value = working.Value.Metadata.AudioFile }, Current = { Value = working.Value.Metadata.AudioFile },
TabbableContentContainer = this TabbableContentContainer = this
}, },
}; };
backgroundTextBox.Current.BindValueChanged(backgroundChanged); backgroundChooser.Current.BindValueChanged(backgroundChanged, true);
audioTrackTextBox.Current.BindValueChanged(audioTrackChanged); audioTrackChooser.Current.BindValueChanged(audioTrackChanged, true);
} }
public bool ChangeBackgroundImage(string path) public bool ChangeBackgroundImage(string path)
@ -124,14 +121,28 @@ namespace osu.Game.Screens.Edit.Setup
private void backgroundChanged(ValueChangedEvent<string> filePath) private void backgroundChanged(ValueChangedEvent<string> filePath)
{ {
if (!ChangeBackgroundImage(filePath.NewValue)) backgroundChooser.PlaceholderText = string.IsNullOrEmpty(filePath.NewValue)
backgroundTextBox.Current.Value = filePath.OldValue; ? "Click to select a background image"
: "Click to replace the background image";
if (filePath.NewValue != filePath.OldValue)
{
if (!ChangeBackgroundImage(filePath.NewValue))
backgroundChooser.Current.Value = filePath.OldValue;
}
} }
private void audioTrackChanged(ValueChangedEvent<string> filePath) private void audioTrackChanged(ValueChangedEvent<string> filePath)
{ {
if (!ChangeAudioTrack(filePath.NewValue)) audioTrackChooser.PlaceholderText = string.IsNullOrEmpty(filePath.NewValue)
audioTrackTextBox.Current.Value = filePath.OldValue; ? "Click to select a track"
: "Click to replace the track";
if (filePath.NewValue != filePath.OldValue)
{
if (!ChangeAudioTrack(filePath.NewValue))
audioTrackChooser.Current.Value = filePath.OldValue;
}
} }
} }
} }