Skip to content

Commit

Permalink
Ingame menu, and fixed a bug that would happen if you didn't have the…
Browse files Browse the repository at this point in the history
… font
  • Loading branch information
headassbtw committed Feb 20, 2021
1 parent f015c24 commit 3b40e3a
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 88 deletions.
6 changes: 3 additions & 3 deletions CustomMenuText/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

using System.Runtime.CompilerServices;
using IPA.Config.Stores;

Expand All @@ -8,7 +8,8 @@ namespace CustomMenuText.Configuration
internal class PluginConfig
{
public static PluginConfig Instance { get; set; }
public virtual int IntValue { get; set; } = 42; // Must be 'virtual' if you want BSIPA to detect a value change and save the config automatically.
public virtual int SelectionType { get; set; } = 0;
public virtual int SelectedEntry { get; set; } = 0;

/// <summary>
/// This is called whenever BSIPA reads the config from disk (including when file changes are detected).
Expand All @@ -35,4 +36,3 @@ public virtual void CopyFrom(PluginConfig other)
}
}
}
*/
18 changes: 18 additions & 0 deletions CustomMenuText/CustomMenuText.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<DisableZipRelease>True</DisableZipRelease>
</PropertyGroup>
<ItemGroup>
<Reference Include="BSML, Version=1.4.5.0, Culture=neutral, processorArchitecture=MSIL">
<Private>False</Private>
<HintPath>$(BeatSaberDir)\Plugins\BSML.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -101,6 +106,14 @@
<Compile Include="Configuration\PluginConfig.cs" />
<Compile Include="CustomMenuTextController.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources1.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Views\MenuTextFlowCoordinator.cs" />
<Compile Include="Views\TextSelector\TextSelectorViewController.cs" />
<Compile Include="Views\UICreator.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="manifest.json" />
Expand All @@ -110,6 +123,11 @@
<None Include="Directory.Build.targets" Condition="Exists('Directory.Build.targets')" />
<None Include="CustomMenuText.csproj.user" Condition="Exists('CustomMenuText.csproj.user')" />
<EmbeddedResource Include="NeonTubes" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources1.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Views\TextSelector\TextSelector.bsml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BeatSaberModdingTools.Tasks">
Expand Down
138 changes: 57 additions & 81 deletions CustomMenuText/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,89 +11,16 @@
using TMPro;
using System.IO;
using System.Text;

namespace CustomMenuText.Properties
{
using System;


/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{

private static global::System.Resources.ResourceManager resourceMan;

private static global::System.Globalization.CultureInfo resourceCulture;

[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}

/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if (object.ReferenceEquals(resourceMan, null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CustomMenuText.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}

/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}

/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] NeonTubes
{
get
{
object obj = ResourceManager.GetObject("NeonTubes", resourceCulture);
return ((byte[])(obj));
}
}
}
}


using System.Reflection;

namespace CustomMenuText
{
[Plugin(RuntimeOptions.SingleStartInit)]
public class Plugin
{
public static int selection_type = 0;
public static int choice = 0;

internal static Plugin Instance { get; private set; }
internal static IPALogger Log { get; private set; }

Expand All @@ -110,6 +37,23 @@ public void Init(IPALogger logger)
Log.Info("CustomMenuText initialized.");
}

#region BSIPA Config
//Uncomment to use BSIPA's config
[Init]
public void InitWithConfig(Config conf)
{
Configuration.PluginConfig.Instance = conf.Generated<Configuration.PluginConfig>();

Log.Debug("Config loaded");
selection_type = Configuration.PluginConfig.Instance.SelectionType;
choice = Configuration.PluginConfig.Instance.SelectedEntry;
}
#endregion





public static Plugin instance;

// path to the file to load text from
Expand All @@ -124,7 +68,7 @@ public void Init(IPALogger logger)
public static readonly Color defaultBottomColor = new Color(0, 0.5019608f, 1);

public const string DEFAULT_CONFIG =
@"# Custom Menu Text v3.1.1
@"# Custom Menu Text v3.1.3
# by Arti
# Special Thanks: Kyle1413, Alphie
#
Expand Down Expand Up @@ -258,6 +202,9 @@ Ask in <#7289DA>#pc-help
DON'T
PANIC
STAN
AUROS
<line-height=75%><#cf7100>ARTI
<#FF0000><size=+4><</size>3
<#0080FF>JADE
Expand All @@ -284,6 +231,7 @@ public void OnApplicationStart()
instance = this;
SceneManager.activeSceneChanged += SceneManagerOnActiveSceneChanged;
SceneManager.sceneLoaded += SceneManager_sceneLoaded;
Views.UICreator.CreateMenu();
}

private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene arg1)
Expand All @@ -300,7 +248,23 @@ private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene arg1)
}
else
{
pickRandomEntry();
switch (Configuration.PluginConfig.Instance.SelectionType)
{
case 0:
//default
setText(DEFAULT_TEXT);
break;
case 1:
//random
pickRandomEntry();
break;
case 2:
//pre-chosen
setText(allEntries[choice]);
break;
}


}
}
}
Expand Down Expand Up @@ -334,10 +298,21 @@ public static GameObject loadTextPrefab(string path)
string fontPath = Path.Combine(Environment.CurrentDirectory, path);
if (!File.Exists(fontPath))
{
File.WriteAllBytes(fontPath, CustomMenuText.Properties.Resources.NeonTubes);
Log.Critical("Font Not Found, will be taken care of soon");
}
AssetBundle fontBundle = AssetBundle.LoadFromFile(fontPath);
prefab = fontBundle.LoadAsset<GameObject>("Text");
try { prefab = fontBundle.LoadAsset<GameObject>("Text"); }
catch (NullReferenceException) {
prefab = null;
string gameDirectory = Environment.CurrentDirectory;
string joe = "/" + FONT_PATH;
FileStream fs = File.Create(gameDirectory + joe);

Stream mrs = Assembly.GetExecutingAssembly().GetManifestResourceStream("CustomMenuText.NeonTubes");
fs.Seek(0, SeekOrigin.Begin);
mrs.CopyTo(fs);
fs.Close();}

if (prefab == null)
{
Console.WriteLine("[CustomMenuText] No text prefab found in the provided AssetBundle! Using NeonTubes.");
Expand Down Expand Up @@ -424,6 +399,7 @@ public static List<string[]> readFromFile(string relPath)
public static void replaceLogo()
{
// 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(FONT_PATH == null) { Plugin.Log.Critical("font file not found!"); }
if (textPrefab == null) textPrefab = loadTextPrefab(FONT_PATH);

// Logo Top Pos : 0.63, 21.61, 24.82
Expand Down
4 changes: 2 additions & 2 deletions CustomMenuText/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("3.1.2")]
[assembly: AssemblyFileVersion("3.1.2")]
[assembly: AssemblyVersion("3.2.0")]
[assembly: AssemblyFileVersion("3.2.0")]
101 changes: 101 additions & 0 deletions CustomMenuText/Properties/Resources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Loading

0 comments on commit 3b40e3a

Please sign in to comment.