2021-06-11 02:34:52 +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
|
|
|
|
|
2024-01-26 12:36:50 +08:00
|
|
|
using System.Linq;
|
2021-06-11 02:34:52 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2024-01-26 12:36:50 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Input;
|
|
|
|
using osu.Framework.Testing;
|
2021-06-11 02:34:52 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2022-01-12 22:17:35 +08:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2021-06-11 02:34:52 +08:00
|
|
|
using osu.Game.Screens.Edit;
|
|
|
|
using osu.Game.Screens.Edit.Setup;
|
2024-01-26 12:36:50 +08:00
|
|
|
using osuTK.Input;
|
2021-06-11 02:34:52 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Editing
|
|
|
|
{
|
2024-01-26 12:36:50 +08:00
|
|
|
public partial class TestSceneMetadataSection : OsuManualInputManagerTestScene
|
2021-06-11 02:34:52 +08:00
|
|
|
{
|
|
|
|
[Cached]
|
2022-01-12 22:17:35 +08:00
|
|
|
private EditorBeatmap editorBeatmap = new EditorBeatmap(new Beatmap
|
|
|
|
{
|
|
|
|
BeatmapInfo =
|
|
|
|
{
|
|
|
|
Ruleset = new OsuRuleset().RulesetInfo
|
|
|
|
},
|
|
|
|
});
|
2021-06-11 02:34:52 +08:00
|
|
|
|
|
|
|
private TestMetadataSection metadataSection;
|
|
|
|
|
2024-01-26 12:36:50 +08:00
|
|
|
[Test]
|
|
|
|
public void TestUpdateViaTextBoxOnFocusLoss()
|
|
|
|
{
|
|
|
|
AddStep("set metadata", () =>
|
|
|
|
{
|
|
|
|
editorBeatmap.Metadata.Artist = "Example Artist";
|
|
|
|
editorBeatmap.Metadata.ArtistUnicode = string.Empty;
|
|
|
|
});
|
|
|
|
|
|
|
|
createSection();
|
|
|
|
|
2024-02-02 20:24:59 +08:00
|
|
|
TextBox textbox;
|
2024-01-26 12:36:50 +08:00
|
|
|
|
|
|
|
AddStep("focus first textbox", () =>
|
|
|
|
{
|
|
|
|
textbox = metadataSection.ChildrenOfType<TextBox>().First();
|
|
|
|
InputManager.MoveMouseTo(textbox);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("simulate changing textbox", () =>
|
|
|
|
{
|
|
|
|
// Can't simulate text input but this should work.
|
|
|
|
InputManager.Keys(PlatformAction.SelectAll);
|
|
|
|
InputManager.Keys(PlatformAction.Copy);
|
|
|
|
InputManager.Keys(PlatformAction.Paste);
|
|
|
|
InputManager.Keys(PlatformAction.Paste);
|
|
|
|
});
|
|
|
|
|
|
|
|
assertArtistMetadata("Example Artist");
|
|
|
|
|
|
|
|
// It's important values are committed immediately on focus loss so the editor exit sequence detects them.
|
|
|
|
AddAssert("value immediately changed on focus loss", () =>
|
|
|
|
{
|
2024-05-24 16:21:40 +08:00
|
|
|
((IFocusManager)InputManager).TriggerFocusContention(metadataSection);
|
2024-01-26 12:36:50 +08:00
|
|
|
return editorBeatmap.Metadata.Artist;
|
|
|
|
}, () => Is.EqualTo("Example ArtistExample Artist"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestUpdateViaTextBoxOnCommit()
|
|
|
|
{
|
|
|
|
AddStep("set metadata", () =>
|
|
|
|
{
|
|
|
|
editorBeatmap.Metadata.Artist = "Example Artist";
|
|
|
|
editorBeatmap.Metadata.ArtistUnicode = string.Empty;
|
|
|
|
});
|
|
|
|
|
|
|
|
createSection();
|
|
|
|
|
2024-02-02 20:24:59 +08:00
|
|
|
TextBox textbox;
|
2024-01-26 12:36:50 +08:00
|
|
|
|
|
|
|
AddStep("focus first textbox", () =>
|
|
|
|
{
|
|
|
|
textbox = metadataSection.ChildrenOfType<TextBox>().First();
|
|
|
|
InputManager.MoveMouseTo(textbox);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("simulate changing textbox", () =>
|
|
|
|
{
|
|
|
|
// Can't simulate text input but this should work.
|
|
|
|
InputManager.Keys(PlatformAction.SelectAll);
|
|
|
|
InputManager.Keys(PlatformAction.Copy);
|
|
|
|
InputManager.Keys(PlatformAction.Paste);
|
|
|
|
InputManager.Keys(PlatformAction.Paste);
|
|
|
|
});
|
|
|
|
|
|
|
|
assertArtistMetadata("Example Artist");
|
|
|
|
|
|
|
|
AddStep("commit", () => InputManager.Key(Key.Enter));
|
|
|
|
|
|
|
|
assertArtistMetadata("Example ArtistExample Artist");
|
|
|
|
}
|
|
|
|
|
2021-06-11 02:34:52 +08:00
|
|
|
[Test]
|
|
|
|
public void TestMinimalMetadata()
|
|
|
|
{
|
|
|
|
AddStep("set metadata", () =>
|
|
|
|
{
|
|
|
|
editorBeatmap.Metadata.Artist = "Example Artist";
|
2021-11-04 13:50:39 +08:00
|
|
|
editorBeatmap.Metadata.ArtistUnicode = string.Empty;
|
2021-06-11 02:34:52 +08:00
|
|
|
|
|
|
|
editorBeatmap.Metadata.Title = "Example Title";
|
2021-11-04 13:50:39 +08:00
|
|
|
editorBeatmap.Metadata.TitleUnicode = string.Empty;
|
2021-06-11 02:34:52 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
createSection();
|
|
|
|
|
2024-01-26 12:36:50 +08:00
|
|
|
assertArtistTextBox("Example Artist");
|
2021-06-11 02:34:52 +08:00
|
|
|
assertRomanisedArtist("Example Artist", false);
|
|
|
|
|
|
|
|
assertTitle("Example Title");
|
|
|
|
assertRomanisedTitle("Example Title", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestInitialisationFromNonRomanisedVariant()
|
|
|
|
{
|
|
|
|
AddStep("set metadata", () =>
|
|
|
|
{
|
|
|
|
editorBeatmap.Metadata.ArtistUnicode = "*なみりん";
|
2021-11-04 13:50:39 +08:00
|
|
|
editorBeatmap.Metadata.Artist = string.Empty;
|
2021-06-11 02:34:52 +08:00
|
|
|
|
|
|
|
editorBeatmap.Metadata.TitleUnicode = "コイシテイク・プラネット";
|
2021-11-04 13:50:39 +08:00
|
|
|
editorBeatmap.Metadata.Title = string.Empty;
|
2021-06-11 02:34:52 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
createSection();
|
|
|
|
|
2024-01-26 12:36:50 +08:00
|
|
|
assertArtistTextBox("*なみりん");
|
2021-06-11 02:34:52 +08:00
|
|
|
assertRomanisedArtist(string.Empty, true);
|
|
|
|
|
|
|
|
assertTitle("コイシテイク・プラネット");
|
|
|
|
assertRomanisedTitle(string.Empty, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestInitialisationPreservesOriginalValues()
|
|
|
|
{
|
|
|
|
AddStep("set metadata", () =>
|
|
|
|
{
|
|
|
|
editorBeatmap.Metadata.ArtistUnicode = "*なみりん";
|
|
|
|
editorBeatmap.Metadata.Artist = "*namirin";
|
|
|
|
|
|
|
|
editorBeatmap.Metadata.TitleUnicode = "コイシテイク・プラネット";
|
|
|
|
editorBeatmap.Metadata.Title = "Koishiteiku Planet";
|
|
|
|
});
|
|
|
|
|
|
|
|
createSection();
|
|
|
|
|
2024-01-26 12:36:50 +08:00
|
|
|
assertArtistTextBox("*なみりん");
|
2021-06-11 02:34:52 +08:00
|
|
|
assertRomanisedArtist("*namirin", true);
|
|
|
|
|
|
|
|
assertTitle("コイシテイク・プラネット");
|
|
|
|
assertRomanisedTitle("Koishiteiku Planet", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestValueTransfer()
|
|
|
|
{
|
|
|
|
AddStep("set metadata", () =>
|
|
|
|
{
|
|
|
|
editorBeatmap.Metadata.ArtistUnicode = "*なみりん";
|
2021-11-04 13:50:39 +08:00
|
|
|
editorBeatmap.Metadata.Artist = string.Empty;
|
2021-06-11 02:34:52 +08:00
|
|
|
|
|
|
|
editorBeatmap.Metadata.TitleUnicode = "コイシテイク・プラネット";
|
2021-11-04 13:50:39 +08:00
|
|
|
editorBeatmap.Metadata.Title = string.Empty;
|
2021-06-11 02:34:52 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
createSection();
|
|
|
|
|
|
|
|
AddStep("set romanised artist name", () => metadataSection.ArtistTextBox.Current.Value = "*namirin");
|
2024-01-26 12:36:50 +08:00
|
|
|
assertArtistTextBox("*namirin");
|
2021-06-11 02:34:52 +08:00
|
|
|
assertRomanisedArtist("*namirin", false);
|
|
|
|
|
|
|
|
AddStep("set native artist name", () => metadataSection.ArtistTextBox.Current.Value = "*なみりん");
|
2024-01-26 12:36:50 +08:00
|
|
|
assertArtistTextBox("*なみりん");
|
2021-06-11 02:34:52 +08:00
|
|
|
assertRomanisedArtist("*namirin", true);
|
|
|
|
|
|
|
|
AddStep("set romanised title", () => metadataSection.TitleTextBox.Current.Value = "Hitokoto no kyori");
|
|
|
|
assertTitle("Hitokoto no kyori");
|
|
|
|
assertRomanisedTitle("Hitokoto no kyori", false);
|
|
|
|
|
|
|
|
AddStep("set native title", () => metadataSection.TitleTextBox.Current.Value = "ヒトコトの距離");
|
|
|
|
assertTitle("ヒトコトの距離");
|
|
|
|
assertRomanisedTitle("Hitokoto no kyori", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createSection()
|
|
|
|
=> AddStep("create metadata section", () => Child = metadataSection = new TestMetadataSection());
|
|
|
|
|
2024-01-26 12:36:50 +08:00
|
|
|
private void assertArtistMetadata(string expected)
|
|
|
|
=> AddAssert($"artist metadata is {expected}", () => editorBeatmap.Metadata.Artist, () => Is.EqualTo(expected));
|
|
|
|
|
|
|
|
private void assertArtistTextBox(string expected)
|
|
|
|
=> AddAssert($"artist textbox is {expected}", () => metadataSection.ArtistTextBox.Current.Value, () => Is.EqualTo(expected));
|
2021-06-11 02:34:52 +08:00
|
|
|
|
|
|
|
private void assertRomanisedArtist(string expected, bool editable)
|
|
|
|
{
|
2024-01-26 12:36:50 +08:00
|
|
|
AddAssert($"romanised artist is {expected}", () => metadataSection.RomanisedArtistTextBox.Current.Value, () => Is.EqualTo(expected));
|
2024-08-28 18:17:39 +08:00
|
|
|
AddAssert($"romanised artist is {(editable ? "" : "not ")}editable", () => metadataSection.RomanisedArtistTextBox.Current.Disabled == !editable);
|
2021-06-11 02:34:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assertTitle(string expected)
|
2024-01-26 12:36:50 +08:00
|
|
|
=> AddAssert($"title is {expected}", () => metadataSection.TitleTextBox.Current.Value, () => Is.EqualTo(expected));
|
2021-06-11 02:34:52 +08:00
|
|
|
|
|
|
|
private void assertRomanisedTitle(string expected, bool editable)
|
|
|
|
{
|
2024-01-26 12:36:50 +08:00
|
|
|
AddAssert($"romanised title is {expected}", () => metadataSection.RomanisedTitleTextBox.Current.Value, () => Is.EqualTo(expected));
|
2024-08-28 18:17:39 +08:00
|
|
|
AddAssert($"romanised title is {(editable ? "" : "not ")}editable", () => metadataSection.RomanisedTitleTextBox.Current.Disabled == !editable);
|
2021-06-11 02:34:52 +08:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
private partial class TestMetadataSection : MetadataSection
|
2021-06-11 02:34:52 +08:00
|
|
|
{
|
2024-08-28 18:17:39 +08:00
|
|
|
public new FormTextBox ArtistTextBox => base.ArtistTextBox;
|
|
|
|
public new FormTextBox RomanisedArtistTextBox => base.RomanisedArtistTextBox;
|
2021-06-11 02:34:52 +08:00
|
|
|
|
2024-08-28 18:17:39 +08:00
|
|
|
public new FormTextBox TitleTextBox => base.TitleTextBox;
|
|
|
|
public new FormTextBox RomanisedTitleTextBox => base.RomanisedTitleTextBox;
|
2021-06-11 02:34:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|