Use vent group colors for highlighting, add modded flags

This commit is contained in:
D1GQ committed 2026-02-26 06:15:40 -06:00
1 parent 08cee7e2fc
commit fea6fa4847
5 files changed
+151 -91

No files matched your search

@@ -163,6 +163,18 @@ public static class BAUModdedSupportFlags
/// </summary>
public static string Disable_EndGameSummary = "gameplay.disable.endgamesummary";
/// <summary>
/// Disables custom icon on mini map.
/// When enabled by another mod, custom icons on the mini map will not be generated.
/// </summary>
public static string Disable_MinimapIcons = "gameplay.disable.minimapicons";
/// <summary>
/// Disables custom vent color highlights.
/// When enabled by another mod, vent colors when highlighted will not use vent groups.
/// </summary>
public static string Disable_VentColorGroups = "gameplay.disable.ventcolorgroups";
private static readonly HashSet<string> _flags = [];
private static bool _initialized = false;
+94
View File
@@ -0,0 +1,94 @@
using UnityEngine;
namespace BetterAmongUs.Modules;
internal static class VentGroups
{
private static readonly Dictionary<int, int> ventToLowestId = [];
private static readonly Dictionary<int, Color> groupColors = [];
internal static void CalculateAllVentGroups(Vent[] vents)
{
ventToLowestId.Clear();
groupColors.Clear();
HashSet<Vent> unprocessedVents = [.. vents];
HashSet<int> groupLowestIds = [];
Dictionary<int, List<Vent>> groups = [];
while (unprocessedVents.Count > 0)
{
Vent startVent = unprocessedVents.First();
HashSet<Vent> group = [];
Queue<Vent> toVisit = new();
int lowestId = startVent.Id;
toVisit.Enqueue(startVent);
while (toVisit.Count > 0)
{
Vent current = toVisit.Dequeue();
if (group.Contains(current)) continue;
group.Add(current);
unprocessedVents.Remove(current);
if (current.Id < lowestId)
{
lowestId = current.Id;
}
Vent[] connections = { current.Left, current.Right, current.Center };
foreach (var connection in connections)
{
if (connection != null && !group.Contains(connection) && !toVisit.Contains(connection))
{
toVisit.Enqueue(connection);
}
}
}
groupLowestIds.Add(lowestId);
groups[lowestId] = [.. group];
}
Color[] colorGroups =
[
Color.red,
Color.green,
Color.blue,
Color.gray,
Color.magenta,
Color.cyan,
Color.white
];
for (int i = 0; i < groupLowestIds.Count; i++)
{
int lowestId = groupLowestIds.ElementAt(i);
int colorIndex = i % colorGroups.Length;
groupColors[lowestId] = colorGroups[colorIndex] + (new Color(1f, 1f, 1f, 0f) * 0.2f);
}
foreach (var kvp in groups)
{
int lowestId = kvp.Key;
foreach (var vent in kvp.Value)
{
ventToLowestId[vent.Id] = lowestId;
}
}
}
internal static Color GetVentGroupColor(Vent vent)
{
if (ventToLowestId.TryGetValue(vent.Id, out int lowestId))
{
return groupColors[lowestId];
}
return Color.black;
}
}
@@ -0,0 +1,15 @@
using BetterAmongUs.Modules;
using HarmonyLib;
namespace BetterAmongUs.Patches.Gameplay.Ship;
[HarmonyPatch]
internal static class ShipStatusPatch
{
[HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.Awake))]
[HarmonyPostfix]
private static void ShipStatus_Awake_Postfix(ShipStatus __instance)
{
VentGroups.CalculateAllVentGroups(__instance.AllVents);
}
}
+24
View File
@@ -0,0 +1,24 @@
using BetterAmongUs.Modules;
using BetterAmongUs.Modules.Support;
using HarmonyLib;
using UnityEngine;
namespace BetterAmongUs.Patches.Gameplay.Ship;
[HarmonyPatch]
internal static class VentPatch
{
[HarmonyPatch(typeof(Vent), nameof(Vent.SetOutline))]
[HarmonyPrefix]
private static bool Vent_SetOutline_Prefix(Vent __instance, bool on, bool mainTarget)
{
if (BAUModdedSupportFlags.HasFlag(BAUModdedSupportFlags.Disable_VentColorGroups)) return true;
Color color = VentGroups.GetVentGroupColor(__instance);
__instance.myRend.material.SetFloat("_Outline", on ? 1f : 0f);
__instance.myRend.material.SetColor("_OutlineColor", color);
__instance.myRend.material.SetColor("_AddColor", mainTarget ? color : Color.clear);
return false;
}
}
@@ -1,4 +1,6 @@
using BetterAmongUs.Helpers;
using BetterAmongUs.Modules;
using BetterAmongUs.Modules.Support;
using HarmonyLib;
using UnityEngine;
@@ -42,6 +44,8 @@ internal static class MiniMapBehaviourPatch
[HarmonyPostfix]
private static void MapBehaviour_Show_Postfix(MapBehaviour __instance)
{
if (BAUModdedSupportFlags.HasFlag(BAUModdedSupportFlags.Disable_MinimapIcons)) return;
if (_icons == null)
{
var icons = new GameObject("Icons")
@@ -53,7 +57,6 @@ internal static class MiniMapBehaviourPatch
icons.transform.localScale = Vector3.one;
_icons = icons.transform;
CalculateAllVentGroups();
foreach (var vent in BAUPlugin.AllVents)
{
CreateVentIcon(vent);
@@ -82,7 +85,7 @@ internal static class MiniMapBehaviourPatch
private static void CreateVentIcon(Vent vent)
{
var icon = CreateIcon(Utils.LoadSprite("BetterAmongUs.Resources.Images.Icons.Vent.png", 280), "VentIcon");
icon.color = GetVentGroupColor(vent) * 0.8f;
icon.color = VentGroups.GetVentGroupColor(vent) * 0.8f;
SetPosFromShip(vent.transform.position, icon.transform, new Vector3(0f, 0f, VentLayerOffset));
@@ -97,7 +100,7 @@ internal static class MiniMapBehaviourPatch
if (neighborVent)
{
var arrowIcon = CreateIcon(Utils.LoadSprite("BetterAmongUs.Resources.Images.Icons.Arrow.png", 500), "VentArrowIcon");
arrowIcon.color = GetVentGroupColor(neighborVent);
arrowIcon.color = VentGroups.GetVentGroupColor(neighborVent);
arrowIcon.transform.SetParent(icon.transform);
Vector3 directionToNeighbor = neighborVent.transform.position - vent.transform.position;
@@ -178,94 +181,6 @@ internal static class MiniMapBehaviourPatch
}
}
private static Dictionary<int, int> ventToLowestId = [];
private static Dictionary<int, Color> groupColors = [];
private static void CalculateAllVentGroups()
{
ventToLowestId.Clear();
groupColors.Clear();
HashSet<Vent> unprocessedVents = [.. BAUPlugin.AllVents];
HashSet<int> groupLowestIds = [];
Dictionary<int, List<Vent>> groups = [];
while (unprocessedVents.Count > 0)
{
Vent startVent = unprocessedVents.First();
HashSet<Vent> group = [];
Queue<Vent> toVisit = new();
int lowestId = startVent.Id;
toVisit.Enqueue(startVent);
while (toVisit.Count > 0)
{
Vent current = toVisit.Dequeue();
if (group.Contains(current)) continue;
group.Add(current);
unprocessedVents.Remove(current);
if (current.Id < lowestId)
{
lowestId = current.Id;
}
Vent[] connections = { current.Left, current.Right, current.Center };
foreach (var connection in connections)
{
if (connection != null && !group.Contains(connection) && !toVisit.Contains(connection))
{
toVisit.Enqueue(connection);
}
}
}
groupLowestIds.Add(lowestId);
groups[lowestId] = [.. group];
}
Color[] colorGroups =
[
Color.red,
Color.green,
Color.blue,
Color.gray,
Color.magenta,
Color.cyan,
Color.white
];
for (int i = 0; i < groupLowestIds.Count; i++)
{
int lowestId = groupLowestIds.ElementAt(i);
int colorIndex = i % colorGroups.Length;
groupColors[lowestId] = colorGroups[colorIndex] + (new Color(1f, 1f, 1f, 0f) * 0.2f);
}
foreach (var kvp in groups)
{
int lowestId = kvp.Key;
foreach (var vent in kvp.Value)
{
ventToLowestId[vent.Id] = lowestId;
}
}
}
private static Color GetVentGroupColor(Vent vent)
{
if (ventToLowestId.TryGetValue(vent.Id, out int lowestId))
{
return groupColors[lowestId];
}
return Color.black;
}
private static SpriteRenderer CreateIcon(Sprite sprite, string name = "Icon")
{
var go = new GameObject(name)