Skip to content

Commit 7d7c36f

Browse files
committed
Use the proper bold font & italicness for miss text
1 parent 4e43bb0 commit 7d7c36f

6 files changed

Lines changed: 60 additions & 37 deletions

File tree

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using HarmonyLib;
22
using SiraLocalizer.UI;
33
using TMPro;
4-
using UnityEngine;
54
using Zenject;
65
using Object = UnityEngine.Object;
76

@@ -10,23 +9,37 @@ namespace SiraLocalizer.HarmonyPatches
109
[HarmonyPatch(typeof(EffectPoolsManualInstaller), nameof(EffectPoolsManualInstaller.ManualInstallBindings))]
1110
internal static class EffectPoolsManualInstaller_ManualInstallBindings
1211
{
12+
private static TMP_FontAsset _fontAsset;
13+
1314
public static void Postfix(DiContainer container, bool shortBeatEffect, FlyingTextEffect ____flyingTextEffectPrefab)
1415
{
1516
container.BindMemoryPool<FlyingTextEffect, FlyingTextEffect.Pool>().WithInitialSize(20).FromComponentInNewPrefab(CreateFlyingTextEffectPrefab(____flyingTextEffectPrefab)).WhenInjectedInto<ItalicizedFlyingTextSpawner>();
1617
}
1718

1819
private static FlyingTextEffect CreateFlyingTextEffectPrefab(FlyingTextEffect original)
1920
{
20-
GameObject gameObject = Object.Instantiate(original.gameObject);
21-
gameObject.SetActive(false);
22-
gameObject.name = "ItalicizedFlyingTextEffect";
21+
FlyingTextEffect flyingTextEffect = Object.Instantiate(original);
22+
flyingTextEffect.name = "ItalicizedFlyingTextEffect";
23+
flyingTextEffect.gameObject.SetActive(false);
2324

24-
TextMeshPro text = gameObject.GetComponentInChildren<TextMeshPro>();
25-
text.fontStyle = FontStyles.Bold | FontStyles.Italic | FontStyles.UpperCase;
25+
TextMeshPro text = flyingTextEffect._text;
26+
text.font = GetFontAsset(text);
27+
text.fontStyle = FontStyles.Italic | FontStyles.UpperCase;
2628
text.alignment = TextAlignmentOptions.Center;
2729
text.fontSize = 3;
2830

29-
return gameObject.GetComponent<FlyingTextEffect>();
31+
return flyingTextEffect;
32+
}
33+
34+
private static TMP_FontAsset GetFontAsset(TextMeshPro text)
35+
{
36+
if (_fontAsset == null)
37+
{
38+
_fontAsset = FontAssetHelper.CopyFontAsset(FontLoader.tekoBoldFontAsset, text.fontMaterial);
39+
_fontAsset.italicStyle = 18;
40+
}
41+
42+
return _fontAsset;
3043
}
3144
}
3245
}

SiraLocalizer/Installers/SiraLocalizerCoreInstaller.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public override void InstallBindings()
3636

3737
Container.Bind(typeof(ILocalizationProvider)).To<ResourceLocalizationProvider>().AsSingle();
3838
Container.Bind(typeof(ILocalizationProvider)).To<UserLocalizationFileProvider>().AsSingle();
39-
Container.Bind<FontAssetHelper>().AsTransient();
4039
Container.Bind<UnityWebRequestHelper>().AsSingle();
4140
}
4241
}

SiraLocalizer/SiraLocalizer.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@
9797
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\System.IO.Compression.FileSystem.dll</HintPath>
9898
<Private>False</Private>
9999
</Reference>
100+
<Reference Include="Unity.Addressables">
101+
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.Addressables.dll</HintPath>
102+
<Private>False</Private>
103+
</Reference>
104+
<Reference Include="Unity.ResourceManager">
105+
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.ResourceManager.dll</HintPath>
106+
<Private>False</Private>
107+
</Reference>
100108
<Reference Include="Unity.TextMeshPro">
101109
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
102110
<Private>False</Private>

SiraLocalizer/UI/FontAssetHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace SiraLocalizer.UI
55
{
6-
internal class FontAssetHelper
6+
internal static class FontAssetHelper
77
{
8-
public TMP_FontAsset CopyFontAsset(TMP_FontAsset original, Material referenceMaterial, string newName = null)
8+
public static TMP_FontAsset CopyFontAsset(TMP_FontAsset original, Material referenceMaterial, string newName = null)
99
{
1010
if (string.IsNullOrEmpty(newName))
1111
{
@@ -31,7 +31,7 @@ public TMP_FontAsset CopyFontAsset(TMP_FontAsset original, Material referenceMat
3131

3232
copy.m_AtlasTexture = newTexture;
3333
copy.name = newName;
34-
copy.atlasTextures = new[] { newTexture };
34+
copy.atlasTextures = [newTexture];
3535
copy.material = material;
3636

3737
return copy;

SiraLocalizer/UI/FontLoader.cs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using SiraUtil.Logging;
99
using TMPro;
1010
using UnityEngine;
11+
using UnityEngine.ResourceManagement.AsyncOperations;
1112
using UnityEngine.SceneManagement;
1213
using Zenject;
1314
using Object = UnityEngine.Object;
@@ -16,28 +17,28 @@ namespace SiraLocalizer.UI
1617
{
1718
internal class FontLoader : IInitializable, IDisposable
1819
{
19-
private static readonly string[] kFontNamesToRemove = { "NotoSansJP-Medium SDF", "NotoSansKR-Medium SDF", "SourceHanSansCN-Bold-SDF-Common-1(2k)", "SourceHanSansCN-Bold-SDF-Common-2(2k)", "SourceHanSansCN-Bold-SDF-Uncommon(2k)" };
20-
private static readonly FontReplacementStrategy[] kFontReplacementStrategies = new[]
21-
{
20+
private static readonly string[] kFontNamesToRemove = ["NotoSansJP-Medium SDF", "NotoSansKR-Medium SDF", "SourceHanSansCN-Bold-SDF-Common-1(2k)", "SourceHanSansCN-Bold-SDF-Common-2(2k)", "SourceHanSansCN-Bold-SDF-Uncommon(2k)"];
21+
private static readonly FontReplacementStrategy[] kFontReplacementStrategies =
22+
[
2223
new FontReplacementStrategy(
23-
new[] { "Teko-Medium SDF" },
24-
new[] { "Teko-Medium SDF Latin-1 Supplement", "Oswald-Medium SDF Cyrillic", "NotoSansHebrew-Medium SDF", "SourceHanSans-Medium SDF" }),
24+
["Teko-Medium SDF"],
25+
["Teko-Medium SDF Latin-1 Supplement", "Oswald-Medium SDF Cyrillic", "NotoSansHebrew-Medium SDF", "SourceHanSans-Medium SDF"]),
2526
new FontReplacementStrategy(
26-
new[] { "Teko-Bold SDF" },
27-
new[] { "Teko-Bold SDF Latin-1 Supplement", "Oswald-Bold SDF Cyrillic", "NotoSansHebrew-Bold SDF", "SourceHanSans-Medium SDF" }),
28-
};
27+
["Teko-Bold SDF"],
28+
["Teko-Bold SDF Latin-1 Supplement", "Oswald-Bold SDF Cyrillic", "NotoSansHebrew-Bold SDF", "SourceHanSans-Medium SDF"]),
29+
];
2930

3031
private readonly SiraLog _logger;
31-
private readonly FontAssetHelper _fontAssetHelper;
3232

33-
private readonly List<TMP_FontAsset> _fallbackFontAssets = new();
34-
private readonly List<TMP_FontAsset> _createdFontAssets = new();
35-
private readonly List<TMP_FontAsset> _processedFontAssets = new();
33+
private readonly List<TMP_FontAsset> _fallbackFontAssets = [];
34+
private readonly List<TMP_FontAsset> _createdFontAssets = [];
35+
private readonly List<TMP_FontAsset> _processedFontAssets = [];
36+
37+
internal static TMP_FontAsset tekoBoldFontAsset { get; private set; }
3638

37-
public FontLoader(SiraLog logger, FontAssetHelper fontAssetHelper)
39+
public FontLoader(SiraLog logger)
3840
{
3941
_logger = logger;
40-
_fontAssetHelper = fontAssetHelper;
4142
}
4243

4344
public async void Initialize()
@@ -104,9 +105,22 @@ private async Task LoadFontAssetsAsync()
104105

105106
await assetBundle.UnloadAsync(false);
106107

108+
tekoBoldFontAsset = await LoadTekoBoldAsync();
109+
107110
ApplyFallbackFonts();
108111
}
109112

113+
private Task<TMP_FontAsset> LoadTekoBoldAsync()
114+
{
115+
TaskCompletionSource<TMP_FontAsset> taskCompletionSource = new();
116+
AsyncOperationHandle<TMP_FontAsset> asyncOperationHandle = UnityEngine.AddressableAssets.Addressables.LoadAssetAsync<TMP_FontAsset>("Assets/Visuals/Fonts/Teko-Bold/Teko-Bold SDF.asset");
117+
asyncOperationHandle.Completed += (aoh) =>
118+
{
119+
taskCompletionSource.SetResult(aoh.Result);
120+
};
121+
return taskCompletionSource.Task;
122+
}
123+
110124
private void LoadFontAsset(AssetBundle assetBundle, string name)
111125
{
112126
TMP_FontAsset fontAsset = assetBundle.LoadAsset<TMP_FontAsset>(name);
@@ -154,7 +168,7 @@ private void AddFallbacksToFont(TMP_FontAsset fontAsset, IEnumerable<TMP_FontAss
154168
foreach (TMP_FontAsset fallback in fallbacks.Reverse())
155169
{
156170
// creating a copy is necessary to prevent fonts from overwriting each others' atlases
157-
TMP_FontAsset fallbackCopy = _fontAssetHelper.CopyFontAsset(fallback, fontAsset.material);
171+
TMP_FontAsset fallbackCopy = FontAssetHelper.CopyFontAsset(fallback, fontAsset.material);
158172
_createdFontAssets.Add(fallbackCopy);
159173

160174
// insert as first possible fallback font

SiraLocalizer/UI/ItalicizedFlyingTextEffect.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)