Skip to content

Commit

Permalink
Merge pull request #134 from andy840119/refector-skin
Browse files Browse the repository at this point in the history
Refector skin
  • Loading branch information
andy840119 authored Jul 5, 2020
2 parents 1d4adcc + ea1f6aa commit 17e1774
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 100 deletions.
15 changes: 3 additions & 12 deletions osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneLyricEditorScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats;
using osu.Game.Rulesets.Karaoke.Edit.LyricEditor;
using osu.Game.Rulesets.Karaoke.Tests.Resources;
using osu.Game.Rulesets.Karaoke.Tests.Beatmaps;
using osu.Game.Screens.Edit;
using osu.Game.Tests.Visual;

namespace osu.Game.Rulesets.Karaoke.Tests.Edit
{
[TestFixture]
[Ignore("Will fail if run muliple tests. No idea how to fix that.")]
public class TestSceneLyricEditorScreen : EditorClockTestScene
{
public TestSceneLyricEditorScreen()
Expand All @@ -25,17 +23,10 @@ public TestSceneLyricEditorScreen()
KaraokeLegacyBeatmapDecoder.Register();
}

private static Beatmap createTestBeatmap()
{
using (var stream = TestResources.OpenBeatmapResource("karaoke-file-samples"))
using (var reader = new LineBufferedReader(stream))
return Decoder.GetDecoder<Beatmap>(reader).Decode(reader);
}

[Cached(typeof(EditorBeatmap))]
[Cached(typeof(IBeatSnapProvider))]
private readonly EditorBeatmap editorBeatmap =
new EditorBeatmap(createTestBeatmap());
new EditorBeatmap(new TestKaraokeBeatmap(null));

[BackgroundDependencyLoader]
private void load()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using osu.Game.Graphics.UserInterface;
using osu.Game.IO;
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats;
using osu.Game.Rulesets.Karaoke.Edit.LyricEditor;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Objects.Drawables;
using osu.Game.Rulesets.Karaoke.Skinning;
Expand Down Expand Up @@ -295,7 +296,7 @@ public TestSceneLyricLineLayout()
RelativeSizeAxes = Axes.Both,
Colour = Color4.WhiteSmoke
},
layoutArea = new SkinProvidingContainer(new KaraokeLegacySkinTransformer(null))
layoutArea = new SkinProvidingContainer(new KaraokeLayoutEditorSkin())
{
RelativeSizeAxes = Axes.Both,
}
Expand Down Expand Up @@ -477,5 +478,10 @@ public EditSection()
Spacing = new Vector2(0, 5);
}
}

public class KaraokeLayoutEditorSkin : KaraokeInternalSkin
{
protected override string ResourceName => @"osu.Game.Rulesets.Karaoke.Resources.Skin.editor.skin";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Karaoke.Edit.LyricEditor;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Objects.Drawables;
using osu.Game.Rulesets.Karaoke.Skinning;
Expand Down Expand Up @@ -278,7 +279,7 @@ public TestSceneLyricLineStyle()
RelativeSizeAxes = Axes.Both,
Colour = Color4.WhiteSmoke
},
layoutArea = new SkinProvidingContainer(new KaraokeLegacySkinTransformer(null))
layoutArea = new SkinProvidingContainer(new KaraokeStyleEditorSkin())
{
RelativeSizeAxes = Axes.Both,
}
Expand Down Expand Up @@ -537,5 +538,10 @@ public enum Font

F003
}

public class KaraokeStyleEditorSkin : KaraokeInternalSkin
{
protected override string ResourceName => @"osu.Game.Rulesets.Karaoke.Resources.Skin.editor.skin";
}
}
}
15 changes: 12 additions & 3 deletions osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneSinger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Karaoke.Edit.LyricEditor;
using osu.Game.Rulesets.Karaoke.Skinning;
using osu.Game.Rulesets.Karaoke.Skinning.Components;
using osu.Game.Tests.Visual;
Expand All @@ -23,15 +24,15 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Edit
[TestFixture]
public class TestSceneSinger : OsuTestScene
{
private readonly KaraokeLegacySkinTransformer skinTransformer;
private readonly KaraokeSingerEditorSkin skinTransformer;

private readonly Box background;
private readonly SingerTableContainer singerTableContainer;
private readonly SingerInfoContainer singerInfoContainer;

public TestSceneSinger()
{
skinTransformer = new KaraokeLegacySkinTransformer(null);
skinTransformer = new KaraokeSingerEditorSkin();

Child = new Container
{
Expand Down Expand Up @@ -78,7 +79,7 @@ public TestSceneSinger()
}
};

var bindableSinger = skinTransformer.GetConfig<KaraokeIndexLookup, Dictionary<int, string>>(KaraokeIndexLookup.Singer);
var bindableSinger = skinTransformer.GetConfig<KaraokeIndexLookup, IDictionary<int, string>>(KaraokeIndexLookup.Singer);
bindableSinger.BindValueChanged(x =>
{
var singers = x.NewValue.ToDictionary(i => i.Key, v =>
Expand Down Expand Up @@ -245,5 +246,13 @@ public Singer Singer
}
}
}

public class KaraokeSingerEditorSkin : KaraokeLegacySkinTransformer
{
public KaraokeSingerEditorSkin()
: base(null)
{
}
}
}
}
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/Edit/KaraokeSelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private MenuItem createCombineNoteMenuItem(IEnumerable<Note> selectedObject)

private MenuItem createLayoutMenuItem()
{
var layoutDictionary = source.GetConfig<KaraokeIndexLookup, Dictionary<int, string>>(KaraokeIndexLookup.Layout)?.Value;
var layoutDictionary = source.GetConfig<KaraokeIndexLookup, IDictionary<int, string>>(KaraokeIndexLookup.Layout)?.Value;
return new OsuMenuItem("Layout")
{
Items = layoutDictionary.Select(x => new TernaryStateMenuItem(x.Value, MenuItemType.Standard, state =>
Expand All @@ -109,7 +109,7 @@ private MenuItem createLayoutMenuItem()

private MenuItem createFontMenuItem()
{
var fontDictionary = source.GetConfig<KaraokeIndexLookup, Dictionary<int, string>>(KaraokeIndexLookup.Style)?.Value;
var fontDictionary = source.GetConfig<KaraokeIndexLookup, IDictionary<int, string>>(KaraokeIndexLookup.Style)?.Value;
return new OsuMenuItem("Font")
{
Items = fontDictionary.Select(x => new TernaryStateMenuItem(x.Value, MenuItemType.Standard, state =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,87 +1,33 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osu.Game.IO;
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats;
using osu.Game.Rulesets.Karaoke.Skinning;
using osu.Game.Rulesets.Karaoke.Skinning.Components;
using osu.Game.Skinning;
using System;
using System.Linq;
using System.Reflection;

namespace osu.Game.Rulesets.Karaoke.Edit.LyricEditor
{
/// <summary>
/// This karaoke skin is using in lyric editor only.
/// </summary>
public class KaraokeLyricEditorSkin : ISkin
public class KaraokeLyricEditorSkin : KaraokeInternalSkin
{
public const int MIN_FONT_SIZE = 10;
public const int MAX_FONT_SIZE = 45;

private readonly Bindable<KaraokeFont> bindableFont;
private readonly Bindable<KaraokeLayout> bindableLayout;

public KaraokeLyricEditorSkin()
{
// TODO : need a better way to load resource
var assembly = Assembly.GetExecutingAssembly();
const string resource_name = @"osu.Game.Rulesets.Karaoke.Resources.Skin.lyric-editor.skin";

using (var stream = assembly.GetManifestResourceStream(resource_name))
using (var reader = new LineBufferedReader(stream))
{
var skin = new KaraokeSkinDecoder().Decode(reader);

bindableFont = new Bindable<KaraokeFont>(skin.Fonts.FirstOrDefault());
bindableLayout = new Bindable<KaraokeLayout>(skin.Layouts.FirstOrDefault());
}
}
protected override string ResourceName => @"osu.Game.Rulesets.Karaoke.Resources.Skin.editor.skin";

public float FontSize
{
get => bindableFont.Value.LyricTextFontInfo.LyricTextFontInfo.CharSize;
get => BindableFont.Value.LyricTextFontInfo.LyricTextFontInfo.CharSize;
set
{
var textSize = Math.Max(Math.Min(value, MAX_FONT_SIZE), MIN_FONT_SIZE);
var changePercentage = textSize / FontSize;
bindableFont.Value.LyricTextFontInfo.LyricTextFontInfo.CharSize *= changePercentage;
bindableFont.Value.RubyTextFontInfo.LyricTextFontInfo.CharSize *= changePercentage;
bindableFont.Value.RomajiTextFontInfo.LyricTextFontInfo.CharSize *= changePercentage;
bindableFont.Value.ShadowOffset *= changePercentage;
bindableFont.TriggerChange();
}
}

public Drawable GetDrawableComponent(ISkinComponent component) => null;

public SampleChannel GetSample(ISampleInfo sampleInfo) => null;

public Texture GetTexture(string componentName) => null;

public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
if (!(lookup is KaraokeSkinLookup skinLookup))
throw new NotSupportedException();

var config = skinLookup.Config;

switch (config)
{
case KaraokeSkinConfiguration.LyricStyle:
return SkinUtils.As<TValue>(bindableFont);

case KaraokeSkinConfiguration.LyricLayout:
return SkinUtils.As<TValue>(bindableLayout);

default:
throw new NotSupportedException();
BindableFont.Value.LyricTextFontInfo.LyricTextFontInfo.CharSize *= changePercentage;
BindableFont.Value.RubyTextFontInfo.LyricTextFontInfo.CharSize *= changePercentage;
BindableFont.Value.RomajiTextFontInfo.LyricTextFontInfo.CharSize *= changePercentage;
BindableFont.Value.ShadowOffset *= changePercentage;
BindableFont.TriggerChange();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,9 @@ private void addHitObject(HitObject hitObject)
// see how `DrawableEditRulesetWrapper` do
if (hitObject is LyricLine lyric)
{
Schedule(() =>
container.Add(new LyricControl(lyric)
{
container.Add(new LyricControl(lyric)
{
RelativeSizeAxes = Axes.X,
});
RelativeSizeAxes = Axes.X,
});
}
}
Expand Down
70 changes: 70 additions & 0 deletions osu.Game.Rulesets.Karaoke/Skinning/KaraokeInternalSkin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osu.Game.IO;
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats;
using osu.Game.Rulesets.Karaoke.Skinning.Components;
using osu.Game.Skinning;
using System;
using System.Linq;
using System.Reflection;

namespace osu.Game.Rulesets.Karaoke.Skinning
{
/// <summary>
/// Use as internal skin and prevent user to asjust
/// </summary>
public abstract class KaraokeInternalSkin : ISkin
{
protected readonly Bindable<KaraokeFont> BindableFont;
protected readonly Bindable<KaraokeLayout> BindableLayout;

protected abstract string ResourceName { get; }

public KaraokeInternalSkin()
{
// TODO : need a better way to load resource
var assembly = Assembly.GetExecutingAssembly();

using (var stream = assembly.GetManifestResourceStream(ResourceName))
using (var reader = new LineBufferedReader(stream))
{
var skin = new KaraokeSkinDecoder().Decode(reader);

BindableFont = new Bindable<KaraokeFont>(skin.Fonts.FirstOrDefault());
BindableLayout = new Bindable<KaraokeLayout>(skin.Layouts.FirstOrDefault());
}
}

public Drawable GetDrawableComponent(ISkinComponent component) => null;

public SampleChannel GetSample(ISampleInfo sampleInfo) => null;

public Texture GetTexture(string componentName) => null;

public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
if (!(lookup is KaraokeSkinLookup skinLookup))
throw new NotSupportedException();

var config = skinLookup.Config;

switch (config)
{
case KaraokeSkinConfiguration.LyricStyle:
return SkinUtils.As<TValue>(BindableFont);

case KaraokeSkinConfiguration.LyricLayout:
return SkinUtils.As<TValue>(BindableLayout);

default:
throw new NotSupportedException();
}
}
}
}
Loading

0 comments on commit 17e1774

Please sign in to comment.