2020-10-06 14:17:15 +08: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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-10-06 14:17:15 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-04-04 01:02:33 +08:00
|
|
|
using osu.Framework.Localisation;
|
2021-06-10 21:38:56 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2020-10-06 14:17:15 +08:00
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2022-01-28 12:53:48 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2022-08-11 01:53:20 +08:00
|
|
|
using osu.Game.Localisation;
|
2020-10-06 14:17:15 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Setup
|
|
|
|
{
|
2021-10-14 21:12:38 +08:00
|
|
|
public partial class MetadataSection : SetupSection
|
2020-10-06 14:17:15 +08:00
|
|
|
{
|
2021-06-11 02:34:52 +08:00
|
|
|
protected LabelledTextBox ArtistTextBox;
|
|
|
|
protected LabelledTextBox RomanisedArtistTextBox;
|
2021-06-10 21:38:56 +08:00
|
|
|
|
2021-06-11 02:34:52 +08:00
|
|
|
protected LabelledTextBox TitleTextBox;
|
|
|
|
protected LabelledTextBox RomanisedTitleTextBox;
|
2021-06-10 20:02:17 +08:00
|
|
|
|
2020-10-06 14:17:15 +08:00
|
|
|
private LabelledTextBox creatorTextBox;
|
|
|
|
private LabelledTextBox difficultyTextBox;
|
2021-06-10 20:02:17 +08:00
|
|
|
private LabelledTextBox sourceTextBox;
|
|
|
|
private LabelledTextBox tagsTextBox;
|
2020-10-06 14:17:15 +08:00
|
|
|
|
2022-08-15 23:14:16 +08:00
|
|
|
public override LocalisableString Title => EditorSetupStrings.MetadataHeader;
|
2021-04-04 01:02:33 +08:00
|
|
|
|
2020-10-06 14:17:15 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-06-10 21:38:56 +08:00
|
|
|
var metadata = Beatmap.Metadata;
|
|
|
|
|
2021-06-10 20:02:17 +08:00
|
|
|
Children = new[]
|
2020-10-06 14:17:15 +08:00
|
|
|
{
|
2022-08-15 23:14:16 +08:00
|
|
|
ArtistTextBox = createTextBox<LabelledTextBox>(EditorSetupStrings.Artist,
|
2021-06-10 21:38:56 +08:00
|
|
|
!string.IsNullOrEmpty(metadata.ArtistUnicode) ? metadata.ArtistUnicode : metadata.Artist),
|
2022-08-15 23:14:16 +08:00
|
|
|
RomanisedArtistTextBox = createTextBox<LabelledRomanisedTextBox>(EditorSetupStrings.RomanisedArtist,
|
2021-06-10 21:38:56 +08:00
|
|
|
!string.IsNullOrEmpty(metadata.Artist) ? metadata.Artist : MetadataUtils.StripNonRomanisedCharacters(metadata.ArtistUnicode)),
|
|
|
|
|
|
|
|
Empty(),
|
|
|
|
|
2022-08-15 23:14:16 +08:00
|
|
|
TitleTextBox = createTextBox<LabelledTextBox>(EditorSetupStrings.Title,
|
2021-06-10 21:38:56 +08:00
|
|
|
!string.IsNullOrEmpty(metadata.TitleUnicode) ? metadata.TitleUnicode : metadata.Title),
|
2022-08-15 23:14:16 +08:00
|
|
|
RomanisedTitleTextBox = createTextBox<LabelledRomanisedTextBox>(EditorSetupStrings.RomanisedTitle,
|
2021-06-10 21:38:56 +08:00
|
|
|
!string.IsNullOrEmpty(metadata.Title) ? metadata.Title : MetadataUtils.StripNonRomanisedCharacters(metadata.ArtistUnicode)),
|
|
|
|
|
2021-06-10 20:02:17 +08:00
|
|
|
Empty(),
|
2021-06-10 21:38:56 +08:00
|
|
|
|
2022-08-15 23:14:16 +08:00
|
|
|
creatorTextBox = createTextBox<LabelledTextBox>(EditorSetupStrings.Creator, metadata.Author.Username),
|
|
|
|
difficultyTextBox = createTextBox<LabelledTextBox>(EditorSetupStrings.DifficultyName, Beatmap.BeatmapInfo.DifficultyName),
|
2022-01-28 12:53:48 +08:00
|
|
|
sourceTextBox = createTextBox<LabelledTextBox>(BeatmapsetsStrings.ShowInfoSource, metadata.Source),
|
|
|
|
tagsTextBox = createTextBox<LabelledTextBox>(BeatmapsetsStrings.ShowInfoTags, metadata.Tags)
|
2020-10-06 14:17:15 +08:00
|
|
|
};
|
|
|
|
|
2020-10-06 18:26:57 +08:00
|
|
|
foreach (var item in Children.OfType<LabelledTextBox>())
|
2020-10-06 14:17:15 +08:00
|
|
|
item.OnCommit += onCommit;
|
|
|
|
}
|
|
|
|
|
2022-01-28 12:53:48 +08:00
|
|
|
private TTextBox createTextBox<TTextBox>(LocalisableString label, string initialValue)
|
2021-06-10 21:38:56 +08:00
|
|
|
where TTextBox : LabelledTextBox, new()
|
|
|
|
=> new TTextBox
|
|
|
|
{
|
|
|
|
Label = label,
|
|
|
|
FixedLabelWidth = LABEL_WIDTH,
|
|
|
|
Current = { Value = initialValue },
|
|
|
|
TabbableContentContainer = this
|
|
|
|
};
|
2021-06-10 19:55:34 +08:00
|
|
|
|
2021-03-17 15:57:14 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-06-11 02:34:52 +08:00
|
|
|
if (string.IsNullOrEmpty(ArtistTextBox.Current.Value))
|
2022-02-15 07:42:37 +08:00
|
|
|
ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(ArtistTextBox));
|
2021-06-10 21:38:56 +08:00
|
|
|
|
2021-06-11 02:34:52 +08:00
|
|
|
ArtistTextBox.Current.BindValueChanged(artist => transferIfRomanised(artist.NewValue, RomanisedArtistTextBox));
|
|
|
|
TitleTextBox.Current.BindValueChanged(title => transferIfRomanised(title.NewValue, RomanisedTitleTextBox));
|
2021-06-10 21:38:56 +08:00
|
|
|
updateReadOnlyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void transferIfRomanised(string value, LabelledTextBox target)
|
|
|
|
{
|
|
|
|
if (MetadataUtils.IsRomanised(value))
|
|
|
|
target.Current.Value = value;
|
|
|
|
|
|
|
|
updateReadOnlyState();
|
2022-08-02 21:02:30 +08:00
|
|
|
Scheduler.AddOnce(updateMetadata);
|
2021-06-10 21:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateReadOnlyState()
|
|
|
|
{
|
2021-06-11 02:34:52 +08:00
|
|
|
RomanisedArtistTextBox.ReadOnly = MetadataUtils.IsRomanised(ArtistTextBox.Current.Value);
|
|
|
|
RomanisedTitleTextBox.ReadOnly = MetadataUtils.IsRomanised(TitleTextBox.Current.Value);
|
2021-03-17 15:57:14 +08:00
|
|
|
}
|
|
|
|
|
2020-10-06 14:17:15 +08:00
|
|
|
private void onCommit(TextBox sender, bool newText)
|
|
|
|
{
|
|
|
|
if (!newText) return;
|
|
|
|
|
2021-06-10 21:38:56 +08:00
|
|
|
// for now, update on commit rather than making BeatmapMetadata bindables.
|
2020-10-06 14:17:15 +08:00
|
|
|
// after switching database engines we can reconsider if switching to bindables is a good direction.
|
2022-08-02 21:02:30 +08:00
|
|
|
Scheduler.AddOnce(updateMetadata);
|
2021-06-10 21:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateMetadata()
|
|
|
|
{
|
2021-06-11 02:34:52 +08:00
|
|
|
Beatmap.Metadata.ArtistUnicode = ArtistTextBox.Current.Value;
|
|
|
|
Beatmap.Metadata.Artist = RomanisedArtistTextBox.Current.Value;
|
2021-06-10 21:38:56 +08:00
|
|
|
|
2021-06-11 02:34:52 +08:00
|
|
|
Beatmap.Metadata.TitleUnicode = TitleTextBox.Current.Value;
|
|
|
|
Beatmap.Metadata.Title = RomanisedTitleTextBox.Current.Value;
|
2021-06-10 20:02:17 +08:00
|
|
|
|
2022-01-18 22:30:40 +08:00
|
|
|
Beatmap.Metadata.Author.Username = creatorTextBox.Current.Value;
|
2021-11-11 16:19:53 +08:00
|
|
|
Beatmap.BeatmapInfo.DifficultyName = difficultyTextBox.Current.Value;
|
2021-06-10 20:02:17 +08:00
|
|
|
Beatmap.Metadata.Source = sourceTextBox.Current.Value;
|
|
|
|
Beatmap.Metadata.Tags = tagsTextBox.Current.Value;
|
2022-08-02 15:35:15 +08:00
|
|
|
|
|
|
|
Beatmap.SaveState();
|
2020-10-06 14:17:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|