Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto best fit to labels in custom controls menu #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<AssemblyName>BepInEx5Plugins.Ash.Alisa.ResizeTextForBestFit</AssemblyName>
<Description>ResizeTextForBestFit</Description>
<Version>1.0.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
<PackageReference Include="UnityEngine.Modules" Version="5.6.7" IncludeAssets="compile" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\lib\SteamRelease\Assembly-CSharp.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\lib\UnityEngine\UnityEngine.UI.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy /Y /Q /C /I &quot;$(OutDir)&quot; &quot;..\$(OutDir)\$(TargetName)\&quot;" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using HarmonyLib;
using UnityEngine.UI;

namespace BepInEx5Plugins.Ash.Alisa.ResizeTextForBestFit.HarmonyPatches
{
[HarmonyPatch(typeof(KeyBindScript), "Start")]
public class KeyBindScript_Start
{
public static int maxSize = 18;

public static bool singleOutline = true;

// Set every text child components to fit automatically.
public static void Postfix(KeyBindScript __instance)
{
foreach (var text in __instance.GetComponentsInChildren<Text>())
{
text.resizeTextForBestFit = true;
text.resizeTextMaxSize = maxSize;

if (singleOutline)
{
var outlines = text.GetComponents<Outline>();

for (var i = 1; i < outlines.Length; ++i)
{
var outline = outlines[i];

outline.enabled = false;
}
}
}
}
}
}
6 changes: 6 additions & 0 deletions BepInEx5Plugins.Ash.Alisa.ResizeTextForBestFit/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
</packageSources>
</configuration>
52 changes: 52 additions & 0 deletions BepInEx5Plugins.Ash.Alisa.ResizeTextForBestFit/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using System;

namespace BepInEx5Plugins.Ash.Alisa.ResizeTextForBestFit
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
private readonly ConfigEntry<int> maxSize;

private readonly ConfigEntry<bool> singleOutline;

private Plugin()
{
maxSize = Config.Bind("ResizeTextForBestFit", "Max Size", 18);
singleOutline = Config.Bind("ResizeTextForBestFit", "Single Outline", true);

Config.SettingChanged += Config_SettingChanged;

ApplySettings();
}

private void Config_SettingChanged(object sender, EventArgs e)
{
ApplySettings();
}

private void ApplySettings()
{
HarmonyPatches.KeyBindScript_Start.maxSize = maxSize.Value;
HarmonyPatches.KeyBindScript_Start.singleOutline = singleOutline.Value;
}

private void Awake()
{
try
{
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");

var harmony = new Harmony(Info.Metadata.GUID);

harmony.PatchAll();
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
}
}
}