2020-10-06 15:17:15 +09:00
|
|
|
// 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.IO;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2021-04-03 19:02:33 +02:00
|
|
|
using osu.Framework.Localisation;
|
2020-10-06 15:17:15 +09:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Overlays;
|
2022-08-11 03:53:20 +10:00
|
|
|
using osu.Game.Localisation;
|
2020-10-06 15:17:15 +09:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Setup
|
|
|
|
{
|
2022-11-24 14:32:20 +09:00
|
|
|
internal partial class ResourcesSection : SetupSection
|
2020-10-06 15:17:15 +09:00
|
|
|
{
|
2023-01-07 03:08:02 +03:00
|
|
|
private LabelledFileChooser audioTrackChooser = null!;
|
|
|
|
private LabelledFileChooser backgroundChooser = null!;
|
2020-10-06 15:17:15 +09:00
|
|
|
|
2022-08-16 01:14:16 +10:00
|
|
|
public override LocalisableString Title => EditorSetupStrings.ResourcesHeader;
|
2021-04-03 19:02:33 +02:00
|
|
|
|
2020-10-06 15:17:15 +09:00
|
|
|
[Resolved]
|
2023-01-07 03:08:02 +03:00
|
|
|
private MusicController music { get; set; } = null!;
|
2020-10-06 15:17:15 +09:00
|
|
|
|
|
|
|
[Resolved]
|
2023-01-07 03:08:02 +03:00
|
|
|
private BeatmapManager beatmaps { get; set; } = null!;
|
2020-10-06 15:17:15 +09:00
|
|
|
|
2021-01-04 16:47:08 +09:00
|
|
|
[Resolved]
|
2023-01-07 03:08:02 +03:00
|
|
|
private IBindable<WorkingBeatmap> working { get; set; } = null!;
|
2021-01-04 16:47:08 +09:00
|
|
|
|
2022-08-01 16:36:12 +09:00
|
|
|
[Resolved]
|
2023-01-07 03:08:02 +03:00
|
|
|
private EditorBeatmap editorBeatmap { get; set; } = null!;
|
2020-10-06 15:17:15 +09:00
|
|
|
|
2023-01-06 19:26:30 +03:00
|
|
|
[Resolved]
|
2023-01-07 03:03:52 +03:00
|
|
|
private Editor? editor { get; set; }
|
2023-01-06 19:26:30 +03:00
|
|
|
|
2021-04-04 12:50:50 +02:00
|
|
|
[Resolved]
|
2023-01-07 03:08:02 +03:00
|
|
|
private SetupScreenHeader header { get; set; } = null!;
|
2021-04-04 12:50:50 +02:00
|
|
|
|
2020-10-06 15:17:15 +09:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2020-10-06 19:26:57 +09:00
|
|
|
Children = new Drawable[]
|
2020-10-06 15:17:15 +09:00
|
|
|
{
|
2022-06-15 09:52:12 +03:00
|
|
|
backgroundChooser = new LabelledFileChooser(".jpg", ".jpeg", ".png")
|
2021-04-04 12:50:50 +02:00
|
|
|
{
|
2022-08-11 03:53:20 +10:00
|
|
|
Label = GameplaySettingsStrings.BackgroundHeader,
|
2021-08-23 18:01:01 +03:00
|
|
|
FixedLabelWidth = LABEL_WIDTH,
|
|
|
|
TabbableContentContainer = this
|
2021-04-04 12:50:50 +02:00
|
|
|
},
|
2022-06-15 09:52:12 +03:00
|
|
|
audioTrackChooser = new LabelledFileChooser(".mp3", ".ogg")
|
2020-10-06 15:17:15 +09:00
|
|
|
{
|
2022-08-16 01:14:16 +10:00
|
|
|
Label = EditorSetupStrings.AudioTrack,
|
2021-08-23 18:01:01 +03:00
|
|
|
FixedLabelWidth = LABEL_WIDTH,
|
|
|
|
TabbableContentContainer = this
|
|
|
|
},
|
2020-10-06 15:17:15 +09:00
|
|
|
};
|
|
|
|
|
2022-06-15 19:29:09 +03:00
|
|
|
if (!string.IsNullOrEmpty(working.Value.Metadata.BackgroundFile))
|
|
|
|
backgroundChooser.Current.Value = new FileInfo(working.Value.Metadata.BackgroundFile);
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(working.Value.Metadata.AudioFile))
|
|
|
|
audioTrackChooser.Current.Value = new FileInfo(working.Value.Metadata.AudioFile);
|
|
|
|
|
2022-06-16 18:48:32 +03:00
|
|
|
backgroundChooser.Current.BindValueChanged(backgroundChanged);
|
|
|
|
audioTrackChooser.Current.BindValueChanged(audioTrackChanged);
|
|
|
|
|
|
|
|
updatePlaceholderText();
|
2020-10-06 15:17:15 +09:00
|
|
|
}
|
|
|
|
|
2022-06-15 19:29:09 +03:00
|
|
|
public bool ChangeBackgroundImage(FileInfo source)
|
2020-10-06 15:17:15 +09:00
|
|
|
{
|
2022-06-15 09:02:48 +03:00
|
|
|
if (!source.Exists)
|
2020-10-06 15:17:15 +09:00
|
|
|
return false;
|
|
|
|
|
2021-01-04 16:47:08 +09:00
|
|
|
var set = working.Value.BeatmapSetInfo;
|
2020-10-06 15:17:15 +09:00
|
|
|
|
2022-06-15 09:02:48 +03:00
|
|
|
var destination = new FileInfo($@"bg{source.Extension}");
|
|
|
|
|
2021-04-04 13:10:12 +02:00
|
|
|
// remove the previous background for now.
|
2020-10-06 15:17:15 +09:00
|
|
|
// in the future we probably want to check if this is being used elsewhere (other difficulties?)
|
2022-08-10 15:48:38 +09:00
|
|
|
var oldFile = set.GetFile(working.Value.Metadata.BackgroundFile);
|
2020-10-06 15:17:15 +09:00
|
|
|
|
2022-06-15 09:02:48 +03:00
|
|
|
using (var stream = source.OpenRead())
|
2020-10-06 15:17:15 +09:00
|
|
|
{
|
|
|
|
if (oldFile != null)
|
2021-11-29 18:08:02 +09:00
|
|
|
beatmaps.DeleteFile(set, oldFile);
|
|
|
|
|
2022-06-15 09:02:48 +03:00
|
|
|
beatmaps.AddFile(set, stream, destination.Name);
|
2020-10-06 15:17:15 +09:00
|
|
|
}
|
|
|
|
|
2022-08-01 16:36:12 +09:00
|
|
|
editorBeatmap.SaveState();
|
|
|
|
|
2022-06-15 09:02:48 +03:00
|
|
|
working.Value.Metadata.BackgroundFile = destination.Name;
|
2021-04-04 13:10:12 +02:00
|
|
|
header.Background.UpdateBackground();
|
2020-10-06 15:17:15 +09:00
|
|
|
|
2023-01-07 03:03:52 +03:00
|
|
|
editor?.ApplyToBackground(bg => bg.RefreshBackground());
|
2023-01-06 19:26:30 +03:00
|
|
|
|
2020-10-06 15:17:15 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-06-15 19:29:09 +03:00
|
|
|
public bool ChangeAudioTrack(FileInfo source)
|
2021-04-04 12:50:50 +02:00
|
|
|
{
|
2022-06-15 09:02:48 +03:00
|
|
|
if (!source.Exists)
|
2021-04-04 12:50:50 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
var set = working.Value.BeatmapSetInfo;
|
|
|
|
|
2022-06-15 09:02:48 +03:00
|
|
|
var destination = new FileInfo($@"audio{source.Extension}");
|
|
|
|
|
2021-04-04 13:10:12 +02:00
|
|
|
// remove the previous audio track for now.
|
2021-04-04 12:50:50 +02:00
|
|
|
// in the future we probably want to check if this is being used elsewhere (other difficulties?)
|
2022-08-10 15:48:38 +09:00
|
|
|
var oldFile = set.GetFile(working.Value.Metadata.AudioFile);
|
2021-04-04 12:50:50 +02:00
|
|
|
|
2022-06-15 09:02:48 +03:00
|
|
|
using (var stream = source.OpenRead())
|
2021-04-04 12:50:50 +02:00
|
|
|
{
|
|
|
|
if (oldFile != null)
|
2021-11-29 18:08:02 +09:00
|
|
|
beatmaps.DeleteFile(set, oldFile);
|
2022-06-15 09:02:48 +03:00
|
|
|
|
|
|
|
beatmaps.AddFile(set, stream, destination.Name);
|
2021-04-04 12:50:50 +02:00
|
|
|
}
|
|
|
|
|
2022-06-15 09:02:48 +03:00
|
|
|
working.Value.Metadata.AudioFile = destination.Name;
|
2021-04-04 12:50:50 +02:00
|
|
|
|
2022-08-01 16:36:12 +09:00
|
|
|
editorBeatmap.SaveState();
|
2021-04-04 13:10:12 +02:00
|
|
|
music.ReloadCurrentTrack();
|
2022-08-01 16:36:12 +09:00
|
|
|
|
2021-04-04 12:50:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-07 03:08:02 +03:00
|
|
|
private void backgroundChanged(ValueChangedEvent<FileInfo?> file)
|
2021-04-04 12:50:50 +02:00
|
|
|
{
|
2023-01-07 18:15:57 +03:00
|
|
|
if (file.NewValue == null || !ChangeBackgroundImage(file.NewValue))
|
2022-06-16 18:48:32 +03:00
|
|
|
backgroundChooser.Current.Value = file.OldValue;
|
2022-06-15 09:52:12 +03:00
|
|
|
|
2022-06-16 18:48:32 +03:00
|
|
|
updatePlaceholderText();
|
2021-04-04 12:50:50 +02:00
|
|
|
}
|
|
|
|
|
2023-01-07 03:08:02 +03:00
|
|
|
private void audioTrackChanged(ValueChangedEvent<FileInfo?> file)
|
2020-10-06 15:17:15 +09:00
|
|
|
{
|
2023-01-07 18:15:57 +03:00
|
|
|
if (file.NewValue == null || !ChangeAudioTrack(file.NewValue))
|
2022-06-16 18:48:32 +03:00
|
|
|
audioTrackChooser.Current.Value = file.OldValue;
|
|
|
|
|
|
|
|
updatePlaceholderText();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updatePlaceholderText()
|
|
|
|
{
|
|
|
|
audioTrackChooser.Text = audioTrackChooser.Current.Value == null
|
2022-08-16 01:14:16 +10:00
|
|
|
? EditorSetupStrings.ClickToSelectTrack
|
|
|
|
: EditorSetupStrings.ClickToReplaceTrack;
|
2022-06-15 09:52:12 +03:00
|
|
|
|
2022-06-16 18:48:32 +03:00
|
|
|
backgroundChooser.Text = backgroundChooser.Current.Value == null
|
2022-08-16 01:14:16 +10:00
|
|
|
? EditorSetupStrings.ClickToSelectBackground
|
|
|
|
: EditorSetupStrings.ClickToReplaceBackground;
|
2020-10-06 15:17:15 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|