From dbfa23e7f85750a6ab7c94021ebe4f27e53b7583 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Fri, 6 Dec 2024 23:24:05 +0800 Subject: [PATCH] Remove the drawable layout preview because layout arrangement will be controlled by stage info, not skin. --- .../Editor/TestSceneLayoutToolTip.cs | 101 -------------- .../Edit/Components/Cursor/LayoutToolTip.cs | 47 ------- .../Sprites/DrawableLayoutPreview.cs | 127 ------------------ 3 files changed, 275 deletions(-) delete mode 100644 osu.Game.Rulesets.Karaoke.Tests/Editor/TestSceneLayoutToolTip.cs delete mode 100644 osu.Game.Rulesets.Karaoke/Edit/Components/Cursor/LayoutToolTip.cs delete mode 100644 osu.Game.Rulesets.Karaoke/Edit/Components/Sprites/DrawableLayoutPreview.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/TestSceneLayoutToolTip.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/TestSceneLayoutToolTip.cs deleted file mode 100644 index e3f04358d..000000000 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/TestSceneLayoutToolTip.cs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.Collections.Generic; -using JetBrains.Annotations; -using NUnit.Framework; -using osu.Framework.Graphics; -using osu.Game.IO; -using osu.Game.Rulesets.Karaoke.Edit.Components.Cursor; -using osu.Game.Rulesets.Karaoke.Extensions; -using osu.Game.Rulesets.Karaoke.Objects; -using osu.Game.Rulesets.Karaoke.Skinning; -using osu.Game.Rulesets.Karaoke.Skinning.Elements; -using osu.Game.Skinning; -using osu.Game.Tests.Visual; - -namespace osu.Game.Rulesets.Karaoke.Tests.Editor; - -[TestFixture] -public partial class TestSceneLayoutToolTip : OsuTestScene -{ - private readonly ISkin skin = new TestingSkin(null); - private LayoutToolTip toolTip = null!; - - [SetUp] - public void SetUp() => Schedule(() => - { - Child = new SkinProvidingContainer(skin) - { - RelativeSizeAxes = Axes.Both, - Child = toolTip = new LayoutToolTip - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }, - }; - toolTip.Show(); - }); - - [Test] - public void TestDisplayToolTip() - { - var layouts = skin.GetConfig>(KaraokeIndexLookup.Layout)?.Value; - if (layouts == null) - return; - - foreach ((int key, string value) in layouts) - { - setTooltip($"Test lyric with layout {value}", lyric => - { - // todo: should change mapping group id from the lyric. - }); - } - } - - private void setTooltip(string testName, Action callBack) - { - AddStep(testName, () => - { - var singer = new Lyric - { - Text = "karaoke!", - }; - callBack(singer); - toolTip.SetContent(singer); - }); - } - - /// - /// todo: it's a tricky way to create ruleset's own skin class. - /// should use generic skin like eventually. - /// - public class TestingSkin : KaraokeSkin - { - internal static readonly Guid DEFAULT_SKIN = new("FEC5A291-5709-11EC-9F10-0800200C9A66"); - - public static SkinInfo CreateInfo() => new() - { - ID = DEFAULT_SKIN, - Name = "karaoke! (default skin)", - Creator = "team karaoke!", - Protected = true, - InstantiationInfo = typeof(TestingSkin).GetInvariantInstantiationInfo(), - }; - - public TestingSkin(IStorageResourceProvider? resources) - : this(CreateInfo(), resources) - { - } - - [UsedImplicitly(ImplicitUseKindFlags.InstantiatedWithFixedConstructorSignature)] - public TestingSkin(SkinInfo skin, IStorageResourceProvider? resources) - : base(skin, resources) - { - DefaultElement[ElementType.LyricFontInfo] = LyricFontInfo.CreateDefault(); - DefaultElement[ElementType.LyricStyle] = LyricStyle.CreateDefault(); - DefaultElement[ElementType.NoteStyle] = NoteStyle.CreateDefault(); - } - } -} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Components/Cursor/LayoutToolTip.cs b/osu.Game.Rulesets.Karaoke/Edit/Components/Cursor/LayoutToolTip.cs deleted file mode 100644 index aa7dc007b..000000000 --- a/osu.Game.Rulesets.Karaoke/Edit/Components/Cursor/LayoutToolTip.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Allocation; -using osu.Game.Rulesets.Karaoke.Edit.Components.Sprites; -using osu.Game.Rulesets.Karaoke.Graphics.Cursor; -using osu.Game.Rulesets.Karaoke.Objects; -using osu.Game.Rulesets.Karaoke.Skinning.Elements; -using osu.Game.Skinning; -using osuTK; - -namespace osu.Game.Rulesets.Karaoke.Edit.Components.Cursor; - -public partial class LayoutToolTip : BackgroundToolTip -{ - private const float scale = 0.4f; - - private readonly DrawableLayoutPreview preview; - - [Resolved] - private ISkinSource? skinSource { get; set; } - - public LayoutToolTip() - { - Child = preview = new DrawableLayoutPreview - { - Size = new Vector2(512 * scale, 384 * scale), - }; - } - - private Lyric? lastLyric; - - public override void SetContent(Lyric lyric) - { - if (lyric == lastLyric) - return; - - lastLyric = lyric; - - // Get layout - var layout = skinSource?.GetConfig(lyric)?.Value; - - // Display in content - preview.Layout = layout; - preview.Lyric = lyric; - } -} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Components/Sprites/DrawableLayoutPreview.cs b/osu.Game.Rulesets.Karaoke/Edit/Components/Sprites/DrawableLayoutPreview.cs deleted file mode 100644 index 74662970c..000000000 --- a/osu.Game.Rulesets.Karaoke/Edit/Components/Sprites/DrawableLayoutPreview.cs +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Allocation; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; -using osu.Game.Rulesets.Karaoke.Objects; -using osu.Game.Rulesets.Karaoke.Skinning.Elements; -using osu.Game.Skinning; - -namespace osu.Game.Rulesets.Karaoke.Edit.Components.Sprites; - -public partial class DrawableLayoutPreview : CompositeDrawable -{ - private const float scale = 0.4f; - - private readonly Box background; - private readonly Box previewLyric; - private readonly OsuSpriteText notSupportText; - - [Resolved] - private ISkinSource? skinSource { get; set; } - - public DrawableLayoutPreview() - { - InternalChildren = new Drawable[] - { - background = new Box - { - RelativeSizeAxes = Axes.Both, - }, - previewLyric = new Box - { - Height = 15, - }, - notSupportText = new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }, - }; - - previewLyric.Hide(); - notSupportText.Hide(); - } - - private LyricLayout? layout; - - public LyricLayout? Layout - { - get => layout; - set - { - if (layout == value) - return; - - layout = value; - updateLayout(); - } - } - - private Lyric? lyric; - - public Lyric? Lyric - { - get => lyric; - set - { - if (lyric == value) - return; - - lyric = value; - updateLayout(); - } - } - - private void updateLayout() - { - // Display in content - if (Layout == null) - { - // mark layout as not supported, or skin is not loaded - notSupportText.Show(); - - if (skinSource == null) - notSupportText.Text = "Sorry, skin is not exist."; - else - notSupportText.Text = "Sorry, layout is not exist."; - } - else - { - // Display box preview position - previewLyric.Show(); - - // Set preview width - const float text_size = 20; - previewLyric.Width = (Lyric?.Text.Length ?? 10) * text_size * scale; - previewLyric.Height = text_size * 1.5f * scale; - - // Set relative position - previewLyric.Anchor = Layout.Alignment; - previewLyric.Origin = Layout.Alignment; - - // Set margin - const float padding = 30 * scale; - float horizontalMargin = Layout.HorizontalMargin * scale + padding; - float verticalMargin = Layout.VerticalMargin * scale + padding; - previewLyric.Margin = new MarginPadding - { - Left = Layout.Alignment.HasFlag(Anchor.x0) ? horizontalMargin : 0, - Right = Layout.Alignment.HasFlag(Anchor.x2) ? horizontalMargin : 0, - Top = Layout.Alignment.HasFlag(Anchor.y0) ? verticalMargin : 0, - Bottom = Layout.Alignment.HasFlag(Anchor.y2) ? verticalMargin : 0, - }; - } - } - - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - background.Colour = colours.Gray2; - previewLyric.Colour = colours.Yellow; - } -}