Skip to content

Commit

Permalink
fully working TTF/OTF support, and handling something i cba to explai…
Browse files Browse the repository at this point in the history
…n (less errors tho!)
  • Loading branch information
headassbtw committed Jul 4, 2021
1 parent 577fe83 commit 28cbb15
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CustomMenuText/CustomMenuText.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UI.dll</HintPath>
Expand Down
19 changes: 5 additions & 14 deletions CustomMenuText/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class FontManager
public static GameObject Prefab;
public static TMP_FontAsset Font;
public static List<TMP_FontAsset> Fonts;
public static OldFont[] FontList;

public static GameObject loadPrefab(string fontName)
{
Expand All @@ -31,7 +30,7 @@ public static GameObject loadPrefab(string fontName)

public static Font embeddedFont(string fileName)
{
string FontPath = Path.Combine(Application.temporaryCachePath, "CMT", fileName);
string FontPath = Path.Combine(UnityGame.UserDataPath, "CustomMenuText", "Cache", fileName);
Plugin.Log.Info($"Cache path is: {FontPath}");
using (Stream ntf = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("CustomMenuText.Fonts." + fileName))
Expand All @@ -48,14 +47,11 @@ public static Font embeddedFont(string fileName)
}
ntf.Close();
}
return new Font(FontPath);
}

internal static void LoadTTFFiles(string dir)
{

Font tf = new Font(FontPath);
return tf;
}

public static TMP_FontAsset LoadFromTTF(string path)
{
var fnt = new Font(path);
Expand Down Expand Up @@ -84,17 +80,12 @@ public static void FirstTimeFontLoad()
TTFs.Add(file);
}
}

foreach (var ttf in TTFs)
{
fonts.Add(LoadFromTTF(ttf));
}

Fonts = fonts;





Plugin.Log.Info("FontManager) Font loading complete, ");
}
}
Expand Down
50 changes: 23 additions & 27 deletions CustomMenuText/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ public class Plugin
/// </summary>
public void Init(IPALogger logger)
{

if(!Directory.Exists(Path.Combine(Application.temporaryCachePath, "CMT")))
Directory.CreateDirectory(Path.Combine(Application.temporaryCachePath, "CMT"));
Instance = this;
Log = logger;
harmony = new Harmony("com.headassbtw.custommenutext");
Log.Info("CustomMenuText initialized.");

}

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

// Logo Top Pos : 0.63, 18.61, 26.1
// Logo Bottom Pos : 0, 14, 26.1
if (mainText != null)
{
GameObject.Destroy(GameObject.Find("CustomMenuText"));
GameObject.Destroy(mainText);
mainText = null;
}
if (bottomText != null)
{
GameObject.Destroy(GameObject.Find("CustomMenuText-Bot"));
GameObject.Destroy(bottomText);
bottomText = null;
}

textPrefab = FontManager.loadPrefab("NeonTubes");
//if (mainText == null) mainText = GameObject.Find("CustomMenuText")?.GetComponent<TextMeshPro>();
//if (mainText == null)
if(!textPrefab)
textPrefab = FontManager.loadPrefab("NeonTubes");
if (mainText == null) mainText = GameObject.Find("CustomMenuText")?.GetComponent<TextMeshPro>();
if (mainText == null)
{
GameObject textObj = GameObject.Instantiate(textPrefab);
textObj.name = "CustomMenuText";
Expand All @@ -306,10 +292,10 @@ public static void replaceLogo()
mainText.color = MainColor;

mainText.text = "BEAT";
mainText.font = FontManager.Font;
mainText.font = FontManager.Fonts[Configuration.PluginConfig.Instance.Font];

//if (bottomText == null) bottomText = GameObject.Find("CustomMenuText-Bot")?.GetComponent<TextMeshPro>();
//if (bottomText == null)
if (bottomText == null) bottomText = GameObject.Find("CustomMenuText-Bot")?.GetComponent<TextMeshPro>();
if (bottomText == null)
{
GameObject textObj2 = GameObject.Instantiate(textPrefab);
textObj2.name = "CustomMenuText-Bot";
Expand All @@ -330,8 +316,8 @@ public static void replaceLogo()
bottomText.rectTransform.position = DefBotPos;
bottomText.color = BottomColor;
bottomText.text = "SABER";
bottomText.font = FontManager.Font;

bottomText.font = FontManager.Fonts[Configuration.PluginConfig.Instance.Font];

// Destroy Default Logo

Expand Down Expand Up @@ -400,10 +386,20 @@ public void OnApplicationQuit()
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged;
}
catch (Exception) { }
if(Directory.Exists(Path.Combine(Application.temporaryCachePath, "CMT")))
Directory.Delete(Path.Combine(Application.temporaryCachePath, "CMT"));

string cachePath = Path.Combine(UnityGame.UserDataPath, "CustomMenuText", "Cache");
if (Directory.Exists(cachePath))
{
foreach (var st in Directory.GetFiles(cachePath))
{
File.Delete(st);
}
Directory.Delete(cachePath);
}

}





Expand Down
19 changes: 14 additions & 5 deletions CustomMenuText/Views/TextSelector/TextSelectorViewController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -237,7 +238,8 @@ public void fontSelect(TableView _, int row)
{
//int row = fontListData.data.IndexOf(cell);
Configuration.PluginConfig.Instance.Font = row;
Plugin.instance.ApplyFont();
Plugin.mainText.font = FontManager.Fonts[row];
Plugin.bottomText.font = FontManager.Fonts[row];
}
/*[UIAction("imgSelect")]
public void imgSelect(TableView _, int row)
Expand Down Expand Up @@ -343,23 +345,30 @@ public void SetupTextList()
}
public void SetupFontList()
{
if (Configuration.PluginConfig.Instance.Font > FontManager.Fonts.Count)
Configuration.PluginConfig.Instance.Font = FontManager.Fonts.Count;
fontListData.data.Clear();
foreach (var font in FontManager.FontList)
foreach (var font in FontManager.Fonts)
{
string name = Path.GetFileNameWithoutExtension(font.sourceFontFile.name);
Plugin.Log.Notice($"adding font\"{name}\" to table");

CustomListTableData.CustomCellInfo fontCell;
if (font.builtin)
if (name.ToLower().Equals("neontubes2") || name.ToLower().Equals("beon") || name.ToLower().Equals("teko"))
{
fontCell = new CustomListTableData.CustomCellInfo(font.name, "Built-In");
fontCell = new CustomListTableData.CustomCellInfo(name, "Built-In");
fontListData.data.Add(fontCell);
}
else
{
fontCell = new CustomListTableData.CustomCellInfo(font.name);
fontCell = new CustomListTableData.CustomCellInfo(name);
fontListData.data.Add(fontCell);
}
}
fontListData.tableView.ReloadData();
fontListData.tableView.SelectCellWithIdx(Configuration.PluginConfig.Instance.Font);
Plugin.mainText.font = FontManager.Fonts[Configuration.PluginConfig.Instance.Font];
Plugin.bottomText.font = FontManager.Fonts[Configuration.PluginConfig.Instance.Font];
}
/*public void SetupImageList()
{
Expand Down

0 comments on commit 28cbb15

Please sign in to comment.