mirror of
https://github.com/osukey/osukey.git
synced 2025-05-19 20:47:24 +09:00
Add romanised author & title fields
This commit is contained in:
parent
252fe0a6cc
commit
e41a5a0fcd
47
osu.Game/Beatmaps/MetadataUtils.cs
Normal file
47
osu.Game/Beatmaps/MetadataUtils.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace osu.Game.Beatmaps
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Groups utility methods used to handle beatmap metadata.
|
||||||
|
/// </summary>
|
||||||
|
public static class MetadataUtils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns <see langword="true"/> if the character <paramref name="c"/> can be used in <see cref="BeatmapMetadata.Artist"/> and <see cref="BeatmapMetadata.Title"/> fields.
|
||||||
|
/// Characters not matched by this method can be placed in <see cref="BeatmapMetadata.ArtistUnicode"/> and <see cref="BeatmapMetadata.TitleUnicode"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsRomanised(char c) => c <= 0xFF;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns <see langword="true"/> if the string <paramref name="str"/> can be used in <see cref="BeatmapMetadata.Artist"/> and <see cref="BeatmapMetadata.Title"/> fields.
|
||||||
|
/// Strings not matched by this method can be placed in <see cref="BeatmapMetadata.ArtistUnicode"/> and <see cref="BeatmapMetadata.TitleUnicode"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsRomanised(string? str) => str == null || str.All(IsRomanised);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a copy of <paramref name="str"/> with all characters that do not match <see cref="IsRomanised(char)"/> removed.
|
||||||
|
/// </summary>
|
||||||
|
public static string StripNonRomanisedCharacters(string? str)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(str))
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
var stringBuilder = new StringBuilder(str.Length);
|
||||||
|
|
||||||
|
foreach (var c in str)
|
||||||
|
{
|
||||||
|
if (IsRomanised(c))
|
||||||
|
stringBuilder.Append(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringBuilder.ToString().Trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -45,14 +45,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
Component.BorderColour = colours.Blue;
|
Component.BorderColour = colours.Blue;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual OsuTextBox CreateTextBox() => new OsuTextBox
|
protected virtual OsuTextBox CreateTextBox() => new OsuTextBox();
|
||||||
{
|
|
||||||
CommitOnFocusLost = true,
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
CornerRadius = CORNER_RADIUS,
|
|
||||||
};
|
|
||||||
|
|
||||||
public override bool AcceptsFocus => true;
|
public override bool AcceptsFocus => true;
|
||||||
|
|
||||||
@ -64,6 +57,12 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
|||||||
|
|
||||||
protected override OsuTextBox CreateComponent() => CreateTextBox().With(t =>
|
protected override OsuTextBox CreateComponent() => CreateTextBox().With(t =>
|
||||||
{
|
{
|
||||||
|
t.CommitOnFocusLost = true;
|
||||||
|
t.Anchor = Anchor.Centre;
|
||||||
|
t.Origin = Anchor.Centre;
|
||||||
|
t.RelativeSizeAxes = Axes.X;
|
||||||
|
t.CornerRadius = CORNER_RADIUS;
|
||||||
|
|
||||||
t.OnCommit += (sender, newText) => OnCommit?.Invoke(sender, newText);
|
t.OnCommit += (sender, newText) => OnCommit?.Invoke(sender, newText);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
20
osu.Game/Screens/Edit/Setup/LabelledRomanisedTextBox.cs
Normal file
20
osu.Game/Screens/Edit/Setup/LabelledRomanisedTextBox.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// 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 osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.Edit.Setup
|
||||||
|
{
|
||||||
|
internal class LabelledRomanisedTextBox : LabelledTextBox
|
||||||
|
{
|
||||||
|
protected override OsuTextBox CreateTextBox() => new RomanisedTextBox();
|
||||||
|
|
||||||
|
private class RomanisedTextBox : OsuTextBox
|
||||||
|
{
|
||||||
|
protected override bool CanAddCharacter(char character)
|
||||||
|
=> MetadataUtils.IsRomanised(character);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Edit.Setup
|
namespace osu.Game.Screens.Edit.Setup
|
||||||
@ -12,7 +13,10 @@ namespace osu.Game.Screens.Edit.Setup
|
|||||||
internal class MetadataSection : SetupSection
|
internal class MetadataSection : SetupSection
|
||||||
{
|
{
|
||||||
private LabelledTextBox artistTextBox;
|
private LabelledTextBox artistTextBox;
|
||||||
|
private LabelledTextBox romanisedArtistTextBox;
|
||||||
|
|
||||||
private LabelledTextBox titleTextBox;
|
private LabelledTextBox titleTextBox;
|
||||||
|
private LabelledTextBox romanisedTitleTextBox;
|
||||||
|
|
||||||
private LabelledTextBox creatorTextBox;
|
private LabelledTextBox creatorTextBox;
|
||||||
private LabelledTextBox difficultyTextBox;
|
private LabelledTextBox difficultyTextBox;
|
||||||
@ -24,28 +28,43 @@ namespace osu.Game.Screens.Edit.Setup
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
|
var metadata = Beatmap.Metadata;
|
||||||
|
|
||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
artistTextBox = createTextBox("Artist", Beatmap.Metadata.Artist),
|
artistTextBox = createTextBox<LabelledTextBox>("Artist",
|
||||||
titleTextBox = createTextBox("Title", Beatmap.Metadata.Title),
|
!string.IsNullOrEmpty(metadata.ArtistUnicode) ? metadata.ArtistUnicode : metadata.Artist),
|
||||||
|
romanisedArtistTextBox = createTextBox<LabelledRomanisedTextBox>("Romanised Artist",
|
||||||
|
!string.IsNullOrEmpty(metadata.Artist) ? metadata.Artist : MetadataUtils.StripNonRomanisedCharacters(metadata.ArtistUnicode)),
|
||||||
|
|
||||||
Empty(),
|
Empty(),
|
||||||
creatorTextBox = createTextBox("Creator", Beatmap.Metadata.AuthorString),
|
|
||||||
difficultyTextBox = createTextBox("Difficulty Name", Beatmap.BeatmapInfo.Version),
|
titleTextBox = createTextBox<LabelledTextBox>("Title",
|
||||||
sourceTextBox = createTextBox("Source", Beatmap.Metadata.Source),
|
!string.IsNullOrEmpty(metadata.TitleUnicode) ? metadata.TitleUnicode : metadata.Title),
|
||||||
tagsTextBox = createTextBox("Tags", Beatmap.Metadata.Tags)
|
romanisedTitleTextBox = createTextBox<LabelledRomanisedTextBox>("Romanised Title",
|
||||||
|
!string.IsNullOrEmpty(metadata.Title) ? metadata.Title : MetadataUtils.StripNonRomanisedCharacters(metadata.ArtistUnicode)),
|
||||||
|
|
||||||
|
Empty(),
|
||||||
|
|
||||||
|
creatorTextBox = createTextBox<LabelledTextBox>("Creator", metadata.AuthorString),
|
||||||
|
difficultyTextBox = createTextBox<LabelledTextBox>("Difficulty Name", Beatmap.BeatmapInfo.Version),
|
||||||
|
sourceTextBox = createTextBox<LabelledTextBox>("Source", metadata.Source),
|
||||||
|
tagsTextBox = createTextBox<LabelledTextBox>("Tags", metadata.Tags)
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var item in Children.OfType<LabelledTextBox>())
|
foreach (var item in Children.OfType<LabelledTextBox>())
|
||||||
item.OnCommit += onCommit;
|
item.OnCommit += onCommit;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LabelledTextBox createTextBox(string label, string initialValue) => new LabelledTextBox
|
private TTextBox createTextBox<TTextBox>(string label, string initialValue)
|
||||||
{
|
where TTextBox : LabelledTextBox, new()
|
||||||
Label = label,
|
=> new TTextBox
|
||||||
FixedLabelWidth = LABEL_WIDTH,
|
{
|
||||||
Current = { Value = initialValue },
|
Label = label,
|
||||||
TabbableContentContainer = this
|
FixedLabelWidth = LABEL_WIDTH,
|
||||||
};
|
Current = { Value = initialValue },
|
||||||
|
TabbableContentContainer = this
|
||||||
|
};
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
@ -53,16 +72,43 @@ namespace osu.Game.Screens.Edit.Setup
|
|||||||
|
|
||||||
if (string.IsNullOrEmpty(artistTextBox.Current.Value))
|
if (string.IsNullOrEmpty(artistTextBox.Current.Value))
|
||||||
GetContainingInputManager().ChangeFocus(artistTextBox);
|
GetContainingInputManager().ChangeFocus(artistTextBox);
|
||||||
|
|
||||||
|
artistTextBox.Current.BindValueChanged(artist => transferIfRomanised(artist.NewValue, romanisedArtistTextBox));
|
||||||
|
titleTextBox.Current.BindValueChanged(title => transferIfRomanised(title.NewValue, romanisedTitleTextBox));
|
||||||
|
updateReadOnlyState();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transferIfRomanised(string value, LabelledTextBox target)
|
||||||
|
{
|
||||||
|
if (MetadataUtils.IsRomanised(value))
|
||||||
|
target.Current.Value = value;
|
||||||
|
|
||||||
|
updateReadOnlyState();
|
||||||
|
updateMetadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateReadOnlyState()
|
||||||
|
{
|
||||||
|
romanisedArtistTextBox.ReadOnly = MetadataUtils.IsRomanised(artistTextBox.Current.Value);
|
||||||
|
romanisedTitleTextBox.ReadOnly = MetadataUtils.IsRomanised(titleTextBox.Current.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onCommit(TextBox sender, bool newText)
|
private void onCommit(TextBox sender, bool newText)
|
||||||
{
|
{
|
||||||
if (!newText) return;
|
if (!newText) return;
|
||||||
|
|
||||||
// for now, update these on commit rather than making BeatmapMetadata bindables.
|
// for now, update on commit rather than making BeatmapMetadata bindables.
|
||||||
// after switching database engines we can reconsider if switching to bindables is a good direction.
|
// after switching database engines we can reconsider if switching to bindables is a good direction.
|
||||||
Beatmap.Metadata.Artist = artistTextBox.Current.Value;
|
updateMetadata();
|
||||||
Beatmap.Metadata.Title = titleTextBox.Current.Value;
|
}
|
||||||
|
|
||||||
|
private void updateMetadata()
|
||||||
|
{
|
||||||
|
Beatmap.Metadata.ArtistUnicode = artistTextBox.Current.Value;
|
||||||
|
Beatmap.Metadata.Artist = romanisedArtistTextBox.Current.Value;
|
||||||
|
|
||||||
|
Beatmap.Metadata.TitleUnicode = titleTextBox.Current.Value;
|
||||||
|
Beatmap.Metadata.Title = romanisedTitleTextBox.Current.Value;
|
||||||
|
|
||||||
Beatmap.Metadata.AuthorString = creatorTextBox.Current.Value;
|
Beatmap.Metadata.AuthorString = creatorTextBox.Current.Value;
|
||||||
Beatmap.BeatmapInfo.Version = difficultyTextBox.Current.Value;
|
Beatmap.BeatmapInfo.Version = difficultyTextBox.Current.Value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user