-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from andy840119/refector-skin
Refector skin
- Loading branch information
Showing
10 changed files
with
145 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 8 additions & 62 deletions
70
osu.Game.Rulesets.Karaoke/Edit/LyricEditor/KaraokeLyricEditorSkin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.