Skip to content

Commit c2fc749

Browse files
committed
add resizing in-game buttons
1 parent 95c05e4 commit c2fc749

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
- Be able to send URLs and Email addresses
3838
- Increase the character limit from 100 to 120
3939
- ✨ Other Features
40-
- Remove the 60 FPS cap
40+
- Remove the 60 FPS cap
41+
- Resize the in-game buttons (Use, Kill, Report, etc.)
4142
- Prevent the game from collecting analytics and sending them to Innersloth
4243
- Be able to activate the April Fools Mode (Long Boi and Horse Mode)
4344
- Show more information when finding a game: host name, lobby code, host platform, and lobby age

src/AUnlocker.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public partial class AUnlocker : BasePlugin
1616

1717
// General
1818
public static ConfigEntry<KeyCode> ReloadConfigKeybind;
19+
public static ConfigEntry<float> ButtonSize;
1920

2021
// Account
2122
public static ConfigEntry<bool> UnlockGuest;
@@ -50,6 +51,7 @@ public override void Load()
5051
{
5152
// General
5253
ReloadConfigKeybind = Config.Bind("General", "ReloadConfigKeybind", KeyCode.F6, "The keyboard key used to reload the configuration file");
54+
ButtonSize = Config.Bind("General", "ButtonSize", 1f, "Resize the in-game buttons (Use, Kill, Report, etc.)\nSet to 1.0 to disable scaling");
5355
// Account
5456
UnlockGuest = Config.Bind("Account", "RemoveGuestStatus", false, "Remove guest restrictions (no custom name, no free chat, no friend list)");
5557
UnlockMinor = Config.Bind("Account", "RemoveMinorStatus", false, "Remove minor status and restrictions (no online play)");
@@ -89,6 +91,7 @@ public override void Load()
8991
// More Info: https://discussions.unity.com/t/iap-privacy-issue/881743
9092

9193
AddComponent<KeybindListener>().Plugin = this;
94+
HudManager_Start_Patch.Plugin = this;
9295
}
9396
}
9497

@@ -103,3 +106,46 @@ public void Update()
103106
Plugin.Log.LogInfo("Configuration reloaded.");
104107
}
105108
}
109+
110+
// https://github.com/AU-Avengers/TOU-Mira/blob/main/TownOfUs/Patches/HudManagerPatches.cs#L57
111+
public static class Resize
112+
{
113+
/// <summary>
114+
/// Resize the in-game buttons (Use, Kill, Report, etc.) based on the given scale factor.
115+
/// </summary>
116+
/// <param name="scaleFactor">The scale factor to apply to the buttons.</param>
117+
public static void ResizeUI(float scaleFactor)
118+
{
119+
// Resize the buttons by scaleFactor
120+
foreach (var button in HudManager.Instance.GetComponentsInChildren<ActionButton>(true))
121+
button.gameObject.transform.localScale *= scaleFactor;
122+
123+
// Make sure the buttons have fitting distance between them
124+
foreach (var arrange in HudManager.Instance.transform.FindChild("Buttons")
125+
.GetComponentsInChildren<GridArrange>(true))
126+
arrange.CellSize *= new Vector2(scaleFactor, scaleFactor);
127+
128+
// Change DistanceFromEdge for the buttons depending on scaleFactor
129+
// (closer to the edge for smaller scale factor, further from the edge for larger scale factor)
130+
foreach (var aspect in HudManager.Instance.transform.FindChild("Buttons")
131+
.GetComponentsInChildren<AspectPosition>(true))
132+
{
133+
if (aspect.gameObject.transform.parent.name == "TopRight") { continue; }
134+
if (aspect.gameObject.transform.parent.transform.parent.name == "TopRight") { continue; }
135+
aspect.gameObject.SetActive(!aspect.isActiveAndEnabled);
136+
aspect.DistanceFromEdge *= new Vector2(scaleFactor, scaleFactor);
137+
aspect.gameObject.SetActive(!aspect.isActiveAndEnabled);
138+
}
139+
}
140+
}
141+
142+
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Start))]
143+
public static class HudManager_Start_Patch
144+
{
145+
public static AUnlocker Plugin { get; internal set; }
146+
public static void Postfix()
147+
{
148+
Resize.ResizeUI(AUnlocker.ButtonSize.Value);
149+
Plugin.Log.LogInfo("UI resized to " + AUnlocker.ButtonSize.Value * 100 + "%");
150+
}
151+
}

0 commit comments

Comments
 (0)