Skip to content

Commit 28cbb15

Browse files
committed
fully working TTF/OTF support, and handling something i cba to explain (less errors tho!)
1 parent 577fe83 commit 28cbb15

File tree

4 files changed

+43
-47
lines changed

4 files changed

+43
-47
lines changed

CustomMenuText/CustomMenuText.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<Private>False</Private>
102102
</Reference>
103103
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
104-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
104+
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
105105
</Reference>
106106
<Reference Include="UnityEngine.UI">
107107
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UI.dll</HintPath>

CustomMenuText/FontManager.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class FontManager
1717
public static GameObject Prefab;
1818
public static TMP_FontAsset Font;
1919
public static List<TMP_FontAsset> Fonts;
20-
public static OldFont[] FontList;
2120

2221
public static GameObject loadPrefab(string fontName)
2322
{
@@ -31,7 +30,7 @@ public static GameObject loadPrefab(string fontName)
3130

3231
public static Font embeddedFont(string fileName)
3332
{
34-
string FontPath = Path.Combine(Application.temporaryCachePath, "CMT", fileName);
33+
string FontPath = Path.Combine(UnityGame.UserDataPath, "CustomMenuText", "Cache", fileName);
3534
Plugin.Log.Info($"Cache path is: {FontPath}");
3635
using (Stream ntf = Assembly.GetExecutingAssembly()
3736
.GetManifestResourceStream("CustomMenuText.Fonts." + fileName))
@@ -48,14 +47,11 @@ public static Font embeddedFont(string fileName)
4847
}
4948
ntf.Close();
5049
}
51-
return new Font(FontPath);
52-
}
5350

54-
internal static void LoadTTFFiles(string dir)
55-
{
56-
51+
Font tf = new Font(FontPath);
52+
return tf;
5753
}
58-
54+
5955
public static TMP_FontAsset LoadFromTTF(string path)
6056
{
6157
var fnt = new Font(path);
@@ -84,17 +80,12 @@ public static void FirstTimeFontLoad()
8480
TTFs.Add(file);
8581
}
8682
}
87-
8883
foreach (var ttf in TTFs)
8984
{
9085
fonts.Add(LoadFromTTF(ttf));
9186
}
92-
9387
Fonts = fonts;
94-
95-
96-
97-
88+
9889
Plugin.Log.Info("FontManager) Font loading complete, ");
9990
}
10091
}

CustomMenuText/Plugin.cs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,10 @@ public class Plugin
4343
/// </summary>
4444
public void Init(IPALogger logger)
4545
{
46-
47-
if(!Directory.Exists(Path.Combine(Application.temporaryCachePath, "CMT")))
48-
Directory.CreateDirectory(Path.Combine(Application.temporaryCachePath, "CMT"));
4946
Instance = this;
5047
Log = logger;
5148
harmony = new Harmony("com.headassbtw.custommenutext");
5249
Log.Info("CustomMenuText initialized.");
53-
5450
}
5551

5652
public static Color defaultMainColor = Color.red;
@@ -115,6 +111,8 @@ public void OnDisable()
115111
[OnStart]
116112
public void OnApplicationStart()
117113
{
114+
if (!Directory.Exists(Path.Combine(UnityGame.UserDataPath, "CustomMenuText", "Cache")))
115+
Directory.CreateDirectory(Path.Combine(UnityGame.UserDataPath, "CustomMenuText", "Cache"));
118116
IMG_PATH = Path.Combine(UnityGame.UserDataPath, "CustomMenuText", "Images") + "\\";
119117
FONT_PATH = Path.Combine(UnityGame.UserDataPath, "CustomMenuText", "Fonts") + "\\";
120118
InitializeImageFolder();
@@ -269,22 +267,10 @@ public static void replaceLogo()
269267

270268
// Logo Top Pos : 0.63, 18.61, 26.1
271269
// Logo Bottom Pos : 0, 14, 26.1
272-
if (mainText != null)
273-
{
274-
GameObject.Destroy(GameObject.Find("CustomMenuText"));
275-
GameObject.Destroy(mainText);
276-
mainText = null;
277-
}
278-
if (bottomText != null)
279-
{
280-
GameObject.Destroy(GameObject.Find("CustomMenuText-Bot"));
281-
GameObject.Destroy(bottomText);
282-
bottomText = null;
283-
}
284-
285-
textPrefab = FontManager.loadPrefab("NeonTubes");
286-
//if (mainText == null) mainText = GameObject.Find("CustomMenuText")?.GetComponent<TextMeshPro>();
287-
//if (mainText == null)
270+
if(!textPrefab)
271+
textPrefab = FontManager.loadPrefab("NeonTubes");
272+
if (mainText == null) mainText = GameObject.Find("CustomMenuText")?.GetComponent<TextMeshPro>();
273+
if (mainText == null)
288274
{
289275
GameObject textObj = GameObject.Instantiate(textPrefab);
290276
textObj.name = "CustomMenuText";
@@ -306,10 +292,10 @@ public static void replaceLogo()
306292
mainText.color = MainColor;
307293

308294
mainText.text = "BEAT";
309-
mainText.font = FontManager.Font;
295+
mainText.font = FontManager.Fonts[Configuration.PluginConfig.Instance.Font];
310296

311-
//if (bottomText == null) bottomText = GameObject.Find("CustomMenuText-Bot")?.GetComponent<TextMeshPro>();
312-
//if (bottomText == null)
297+
if (bottomText == null) bottomText = GameObject.Find("CustomMenuText-Bot")?.GetComponent<TextMeshPro>();
298+
if (bottomText == null)
313299
{
314300
GameObject textObj2 = GameObject.Instantiate(textPrefab);
315301
textObj2.name = "CustomMenuText-Bot";
@@ -330,8 +316,8 @@ public static void replaceLogo()
330316
bottomText.rectTransform.position = DefBotPos;
331317
bottomText.color = BottomColor;
332318
bottomText.text = "SABER";
333-
bottomText.font = FontManager.Font;
334-
319+
bottomText.font = FontManager.Fonts[Configuration.PluginConfig.Instance.Font];
320+
335321

336322
// Destroy Default Logo
337323

@@ -400,10 +386,20 @@ public void OnApplicationQuit()
400386
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
401387
}
402388
catch (Exception) { }
403-
if(Directory.Exists(Path.Combine(Application.temporaryCachePath, "CMT")))
404-
Directory.Delete(Path.Combine(Application.temporaryCachePath, "CMT"));
389+
390+
string cachePath = Path.Combine(UnityGame.UserDataPath, "CustomMenuText", "Cache");
391+
if (Directory.Exists(cachePath))
392+
{
393+
foreach (var st in Directory.GetFiles(cachePath))
394+
{
395+
File.Delete(st);
396+
}
397+
Directory.Delete(cachePath);
398+
}
399+
405400
}
406401

402+
407403

408404

409405

CustomMenuText/Views/TextSelector/TextSelectorViewController.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
@@ -237,7 +238,8 @@ public void fontSelect(TableView _, int row)
237238
{
238239
//int row = fontListData.data.IndexOf(cell);
239240
Configuration.PluginConfig.Instance.Font = row;
240-
Plugin.instance.ApplyFont();
241+
Plugin.mainText.font = FontManager.Fonts[row];
242+
Plugin.bottomText.font = FontManager.Fonts[row];
241243
}
242244
/*[UIAction("imgSelect")]
243245
public void imgSelect(TableView _, int row)
@@ -343,23 +345,30 @@ public void SetupTextList()
343345
}
344346
public void SetupFontList()
345347
{
348+
if (Configuration.PluginConfig.Instance.Font > FontManager.Fonts.Count)
349+
Configuration.PluginConfig.Instance.Font = FontManager.Fonts.Count;
346350
fontListData.data.Clear();
347-
foreach (var font in FontManager.FontList)
351+
foreach (var font in FontManager.Fonts)
348352
{
353+
string name = Path.GetFileNameWithoutExtension(font.sourceFontFile.name);
354+
Plugin.Log.Notice($"adding font\"{name}\" to table");
355+
349356
CustomListTableData.CustomCellInfo fontCell;
350-
if (font.builtin)
357+
if (name.ToLower().Equals("neontubes2") || name.ToLower().Equals("beon") || name.ToLower().Equals("teko"))
351358
{
352-
fontCell = new CustomListTableData.CustomCellInfo(font.name, "Built-In");
359+
fontCell = new CustomListTableData.CustomCellInfo(name, "Built-In");
353360
fontListData.data.Add(fontCell);
354361
}
355362
else
356363
{
357-
fontCell = new CustomListTableData.CustomCellInfo(font.name);
364+
fontCell = new CustomListTableData.CustomCellInfo(name);
358365
fontListData.data.Add(fontCell);
359366
}
360367
}
361368
fontListData.tableView.ReloadData();
362369
fontListData.tableView.SelectCellWithIdx(Configuration.PluginConfig.Instance.Font);
370+
Plugin.mainText.font = FontManager.Fonts[Configuration.PluginConfig.Instance.Font];
371+
Plugin.bottomText.font = FontManager.Fonts[Configuration.PluginConfig.Instance.Font];
363372
}
364373
/*public void SetupImageList()
365374
{

0 commit comments

Comments
 (0)