2019-10-08 05:23:13 +00: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.
|
|
|
|
|
|
2020-09-24 09:18:50 +00:00
|
|
|
|
using System;
|
2020-09-25 04:11:34 +00:00
|
|
|
|
using System.IO;
|
2020-09-08 10:28:20 +00:00
|
|
|
|
using System.Linq;
|
2020-09-07 10:21:35 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-09-24 09:18:50 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-09-07 10:21:35 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-09-08 10:28:20 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-09-24 09:18:50 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2020-09-24 09:30:02 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-09-07 10:21:35 +00:00
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-09-24 09:18:50 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-09-07 10:21:35 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2020-09-24 09:55:49 +00:00
|
|
|
|
using osu.Game.Overlays;
|
2020-09-07 10:21:35 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
|
2019-10-08 05:23:13 +00:00
|
|
|
|
namespace osu.Game.Screens.Edit.Setup
|
|
|
|
|
{
|
|
|
|
|
public class SetupScreen : EditorScreen
|
|
|
|
|
{
|
2020-09-08 10:28:20 +00:00
|
|
|
|
private FillFlowContainer flow;
|
|
|
|
|
private LabelledTextBox artistTextBox;
|
|
|
|
|
private LabelledTextBox titleTextBox;
|
|
|
|
|
private LabelledTextBox creatorTextBox;
|
|
|
|
|
private LabelledTextBox difficultyTextBox;
|
2020-09-24 09:18:50 +00:00
|
|
|
|
private LabelledTextBox audioTrackTextBox;
|
2020-09-08 10:28:20 +00:00
|
|
|
|
|
2020-09-24 13:00:13 +00:00
|
|
|
|
[Resolved]
|
2020-09-25 04:11:34 +00:00
|
|
|
|
private MusicController music { get; set; }
|
2020-09-24 13:00:13 +00:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
2020-09-25 04:11:34 +00:00
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
2020-09-24 13:00:13 +00:00
|
|
|
|
|
|
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
|
private Editor editor { get; set; }
|
|
|
|
|
|
2020-09-24 08:03:54 +00:00
|
|
|
|
public SetupScreen()
|
|
|
|
|
: base(EditorScreenMode.SongSetup)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 10:21:35 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
2019-10-08 05:23:13 +00:00
|
|
|
|
{
|
2020-09-24 09:18:50 +00:00
|
|
|
|
Container audioTrackFileChooserContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-08 10:50:44 +00:00
|
|
|
|
Child = new Container
|
2020-09-07 10:21:35 +00:00
|
|
|
|
{
|
2020-09-08 10:50:44 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding(50),
|
|
|
|
|
Child = new Container
|
2020-09-07 10:21:35 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-09-08 10:50:44 +00:00
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 10,
|
|
|
|
|
Children = new Drawable[]
|
2020-09-07 10:21:35 +00:00
|
|
|
|
{
|
2020-09-08 10:50:44 +00:00
|
|
|
|
new Box
|
2020-09-07 10:21:35 +00:00
|
|
|
|
{
|
2020-09-08 10:50:44 +00:00
|
|
|
|
Colour = colours.GreySeafoamDark,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
new OsuScrollContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
|
Child = flow = new FillFlowContainer
|
2020-09-07 10:21:35 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2020-09-08 10:50:44 +00:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Spacing = new Vector2(20),
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
2020-09-07 10:21:35 +00:00
|
|
|
|
{
|
2020-09-08 10:50:44 +00:00
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 250,
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = 10,
|
|
|
|
|
Child = new BeatmapBackgroundSprite(Beatmap.Value)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
2020-09-24 09:18:50 +00:00
|
|
|
|
{
|
|
|
|
|
Text = "Resources"
|
|
|
|
|
},
|
|
|
|
|
audioTrackTextBox = new FileChooserLabelledTextBox
|
|
|
|
|
{
|
|
|
|
|
Label = "Audio Track",
|
|
|
|
|
Current = { Value = Beatmap.Value.Metadata.AudioFile ?? "Click to select a track" },
|
|
|
|
|
Target = audioTrackFileChooserContainer,
|
|
|
|
|
TabbableContentContainer = this
|
|
|
|
|
},
|
|
|
|
|
audioTrackFileChooserContainer,
|
|
|
|
|
new OsuSpriteText
|
2020-09-08 10:50:44 +00:00
|
|
|
|
{
|
|
|
|
|
Text = "Beatmap metadata"
|
|
|
|
|
},
|
|
|
|
|
artistTextBox = new LabelledTextBox
|
|
|
|
|
{
|
|
|
|
|
Label = "Artist",
|
2020-09-08 10:51:31 +00:00
|
|
|
|
Current = { Value = Beatmap.Value.Metadata.Artist },
|
|
|
|
|
TabbableContentContainer = this
|
2020-09-08 10:50:44 +00:00
|
|
|
|
},
|
|
|
|
|
titleTextBox = new LabelledTextBox
|
|
|
|
|
{
|
|
|
|
|
Label = "Title",
|
2020-09-08 10:51:31 +00:00
|
|
|
|
Current = { Value = Beatmap.Value.Metadata.Title },
|
|
|
|
|
TabbableContentContainer = this
|
2020-09-08 10:50:44 +00:00
|
|
|
|
},
|
|
|
|
|
creatorTextBox = new LabelledTextBox
|
|
|
|
|
{
|
|
|
|
|
Label = "Creator",
|
2020-09-08 10:51:31 +00:00
|
|
|
|
Current = { Value = Beatmap.Value.Metadata.AuthorString },
|
|
|
|
|
TabbableContentContainer = this
|
2020-09-08 10:50:44 +00:00
|
|
|
|
},
|
|
|
|
|
difficultyTextBox = new LabelledTextBox
|
|
|
|
|
{
|
|
|
|
|
Label = "Difficulty Name",
|
2020-09-08 10:51:31 +00:00
|
|
|
|
Current = { Value = Beatmap.Value.BeatmapInfo.Version },
|
|
|
|
|
TabbableContentContainer = this
|
2020-09-08 10:50:44 +00:00
|
|
|
|
},
|
|
|
|
|
}
|
2020-09-07 10:21:35 +00:00
|
|
|
|
},
|
2020-09-08 10:50:44 +00:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-07 10:21:35 +00:00
|
|
|
|
};
|
2020-09-08 10:28:20 +00:00
|
|
|
|
|
2020-09-24 09:30:02 +00:00
|
|
|
|
audioTrackTextBox.Current.BindValueChanged(audioTrackChanged);
|
|
|
|
|
|
2020-09-08 10:28:20 +00:00
|
|
|
|
foreach (var item in flow.OfType<LabelledTextBox>())
|
|
|
|
|
item.OnCommit += onCommit;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 13:00:13 +00:00
|
|
|
|
public bool ChangeAudioTrack(string path)
|
2020-09-24 09:30:02 +00:00
|
|
|
|
{
|
2020-09-24 13:00:13 +00:00
|
|
|
|
var info = new FileInfo(path);
|
2020-09-24 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
if (!info.Exists)
|
2020-09-24 13:00:13 +00:00
|
|
|
|
return false;
|
2020-09-24 09:34:17 +00:00
|
|
|
|
|
2020-09-25 04:11:34 +00:00
|
|
|
|
var set = Beatmap.Value.BeatmapSetInfo;
|
2020-09-24 09:30:02 +00:00
|
|
|
|
|
2020-09-25 04:11:34 +00:00
|
|
|
|
// remove the previous audio track for now.
|
|
|
|
|
// in the future we probably want to check if this is being used elsewhere (other difficulties?)
|
|
|
|
|
var oldFile = set.Files.FirstOrDefault(f => f.Filename == Beatmap.Value.Metadata.AudioFile);
|
2020-09-24 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
using (var stream = info.OpenRead())
|
|
|
|
|
{
|
2020-09-25 04:11:34 +00:00
|
|
|
|
if (oldFile != null)
|
|
|
|
|
beatmaps.ReplaceFile(set, oldFile, stream, info.Name);
|
|
|
|
|
else
|
|
|
|
|
beatmaps.AddFile(set, stream, info.Name);
|
|
|
|
|
}
|
2020-09-24 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
Beatmap.Value.Metadata.AudioFile = info.Name;
|
2020-09-24 09:55:49 +00:00
|
|
|
|
|
2020-09-25 03:27:08 +00:00
|
|
|
|
music.ReloadCurrentTrack();
|
2020-09-24 09:55:49 +00:00
|
|
|
|
|
2020-09-25 03:28:41 +00:00
|
|
|
|
editor?.UpdateClockSource();
|
2020-09-24 13:00:13 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void audioTrackChanged(ValueChangedEvent<string> filePath)
|
|
|
|
|
{
|
|
|
|
|
if (!ChangeAudioTrack(filePath.NewValue))
|
|
|
|
|
audioTrackTextBox.Current.Value = filePath.OldValue;
|
2020-09-24 09:30:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-08 10:28:20 +00:00
|
|
|
|
private void onCommit(TextBox sender, bool newText)
|
|
|
|
|
{
|
|
|
|
|
if (!newText) return;
|
|
|
|
|
|
|
|
|
|
// for now, update these on commit rather than making BeatmapMetadata bindables.
|
|
|
|
|
// after switching database engines we can reconsider if switching to bindables is a good direction.
|
|
|
|
|
Beatmap.Value.Metadata.Artist = artistTextBox.Current.Value;
|
|
|
|
|
Beatmap.Value.Metadata.Title = titleTextBox.Current.Value;
|
|
|
|
|
Beatmap.Value.Metadata.AuthorString = creatorTextBox.Current.Value;
|
|
|
|
|
Beatmap.Value.BeatmapInfo.Version = difficultyTextBox.Current.Value;
|
2019-10-08 05:23:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-24 09:18:50 +00:00
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2020-09-25 03:30:05 +00:00
|
|
|
|
Target.Child = new FileSelector(validFileExtensions: new[] { ".mp3", ".ogg" })
|
2020-09-24 09:18:50 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-08 05:23:13 +00:00
|
|
|
|
}
|