Skip to content

Commit

Permalink
Update to 0.13.0; add custom font support(!)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiswkearney committed Mar 15, 2019
1 parent f08185c commit 0613b2f
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 33 deletions.
Binary file added Custom Menu Text/Beon
Binary file not shown.
23 changes: 20 additions & 3 deletions Custom Menu Text/CustomMenuText.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="TextMeshPro-1.0.55.2017.1.0b12, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\TextMeshPro-1.0.55.2017.1.0b12.dll</HintPath>
<Reference Include="Unity.TextMeshPro">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
Expand All @@ -65,6 +68,20 @@
<ItemGroup>
<Compile Include="CustomMenuTextPlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Beon" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down
74 changes: 46 additions & 28 deletions Custom Menu Text/CustomMenuTextPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
using System;
using IllusionPlugin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Linq;
using System.Text;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using IllusionPlugin;
using TMPro;
using System.Text;

namespace TestBSPlugin
namespace CustomMenuText
{
public class CustomMenuTextPlugin : IPlugin
{
// path to the file to load text from
private const string FILE_PATH = "/UserData/CustomMenuText.txt";
public static TMP_FontAsset beon;
// path to load the font prefab from
private const string FONT_PATH = "UserData/CustomMenuFont";
// prefab to instantiate when creating the TextMeshPros
public static GameObject textPrefab;
// used if we can't load any custom entries
public static readonly string[] DEFAULT_TEXT = { "BEAT", "SABER" };
public static readonly Color defaultMainColor = new Color(0, 0.5019608f, 1);
public static readonly Color defaultBottomColor = Color.red;

public const string DEFAULT_CONFIG =
@"# Custom Menu Text v2.2.0
@"# Custom Menu Text v3.0.0
# by Arti
# Special Thanks: Kyle1413
#
Expand All @@ -42,7 +45,7 @@ public class CustomMenuTextPlugin : IPlugin
# You can override the colors even when the text is 2 lines, plus do a lot of other stuff!
# (contributed by @Rolo)
<size=+5><#ffffff>SBU<#ffff00>BBY
<size=-15><#1E5142>eef freef.
<size=-5><#1E5142>eef freef.
# Some more random messages:
BEAT
Expand Down Expand Up @@ -159,7 +162,7 @@ Ask in <#7289DA>#support
public static List<string[]> allEntries = null;

public string Name => "Custom Menu Text";
public string Version => "2.2.0";
public string Version => "3.0.0";

// Store the text objects so when we leave the menu and come back, we aren't creating a bunch of them
public static TextMeshPro mainText;
Expand All @@ -173,7 +176,7 @@ public void OnApplicationStart()

private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene arg1)
{
if (arg1.name == "Menu") // Only run in menu scene
if (arg1.name == "MenuCore") // Only run in menu scene
{
if (allEntries == null)
{
Expand Down Expand Up @@ -204,6 +207,25 @@ private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)

}

public static GameObject loadTextPrefab(string path)
{
GameObject prefab;
string fontPath = Path.Combine(Environment.CurrentDirectory, path);
if (!File.Exists(fontPath))
{
File.WriteAllBytes(fontPath, Properties.Resources.Beon);
}
AssetBundle fontBundle = AssetBundle.LoadFromFile(fontPath);
prefab = fontBundle.LoadAsset<GameObject>("Text");
if (prefab == null)
{
Console.WriteLine("[CustomMenuText] No text prefab found in the provided AssetBundle! Using Beon.");
AssetBundle beonBundle = AssetBundle.LoadFromMemory(Properties.Resources.Beon);
prefab = beonBundle.LoadAsset<GameObject>("Text");
}
return prefab;
}

public static List<string[]> readFromFile(string relPath)
{
List<string[]> entriesInFile = new List<string[]>();
Expand Down Expand Up @@ -279,33 +301,27 @@ public static List<string[]> readFromFile(string relPath)
/// </summary>
public static void replaceLogo()
{
if (beon == null)
{
var fonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
foreach (TMP_FontAsset font in fonts)
{
if (font.name == "Beon SDF")
beon = font;
}
}
// Since 0.13.0, we have to create our TextMeshPros differently! You can't change the font at runtime, so we load a prefab with the right font from an AssetBundle. This has the side effect of allowing for custom fonts, an oft-requested feature.
if (textPrefab == null) textPrefab = loadTextPrefab(FONT_PATH);

// Logo Top Pos : 0.63, 21.61, 24.82
// Logo Bottom Pos : 0, 17.38, 24.82

if (mainText == null) mainText = GameObject.Find("CustomMenuText")?.GetComponent<TextMeshPro>();
if (mainText == null)
{
GameObject textObj = new GameObject("CustomMenuText");
mainText = textObj.AddComponent<TextMeshPro>();
GameObject textObj = GameObject.Instantiate(textPrefab);
textObj.name = "CustomMenuText";
textObj.SetActive(false);
mainText = textObj.GetComponent<TextMeshPro>();
mainText.alignment = TextAlignmentOptions.Center;
mainText.fontSize = 12;
mainText.font = beon;
mainText.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 2f);
mainText.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 2f);
mainText.richText = true;
textObj.transform.localScale *= 3.7f;
mainText.overflowMode = TextOverflowModes.Overflow;
mainText.enableWordWrapping = false;
textObj.SetActive(true);
}
mainText.rectTransform.position = new Vector3(0f, 21.61f, 24.82f);
mainText.color = defaultMainColor;
Expand All @@ -314,24 +330,26 @@ public static void replaceLogo()
if (bottomText == null) bottomText = GameObject.Find("CustomMenuText-Bot")?.GetComponent<TextMeshPro>();
if (bottomText == null)
{
GameObject textObj2 = new GameObject("CustomMenuText-Bot");
bottomText = textObj2.AddComponent<TextMeshPro>();
GameObject textObj2 = GameObject.Instantiate(textPrefab);
textObj2.name = "CustomMenuText-Bot";
textObj2.SetActive(false);
bottomText = textObj2.GetComponent<TextMeshPro>();
bottomText.alignment = TextAlignmentOptions.Center;
bottomText.fontSize = 12;
bottomText.font = beon;
bottomText.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 2f);
bottomText.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 2f);
bottomText.richText = true;
textObj2.transform.localScale *= 3.7f;
bottomText.overflowMode = TextOverflowModes.Overflow;
bottomText.enableWordWrapping = false;
textObj2.SetActive(true);
}
bottomText.rectTransform.position = new Vector3(0f, 17f, 24.82f);
bottomText.color = defaultBottomColor;
mainText.text = "SABER";

// Destroy Default Logo
GameObject defaultLogo = GameObject.Find("Logo");
GameObject defaultLogo = FindUnityObjectsHelper.GetAllGameObjectsInLoadedScenes().Where(go => go.name == "Logo").FirstOrDefault();
if (defaultLogo != null) GameObject.Destroy(defaultLogo);
}

Expand Down
4 changes: 2 additions & 2 deletions Custom Menu Text/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.0.0.0")]
73 changes: 73 additions & 0 deletions Custom Menu Text/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0613b2f

Please sign in to comment.