diff --git a/Source/Client/Session/PlayerInfo.cs b/Source/Client/Session/PlayerInfo.cs index 5eac5470..60c4d219 100644 --- a/Source/Client/Session/PlayerInfo.cs +++ b/Source/Client/Session/PlayerInfo.cs @@ -20,6 +20,7 @@ public class PlayerInfo : IPlayerInfo public PlayerType type; public PlayerStatus status; public Color color; + public Material selectionBracketMaterial; public int factionId; public ulong steamId; @@ -83,6 +84,7 @@ public static PlayerInfo Read(ByteReader data) steamId = steamId, steamPersonaName = steamName, color = color, + selectionBracketMaterial = MaterialPool.MatFrom("UI/Overlays/SelectionBracket", ShaderDatabase.MetaOverlay, color * new Color(1, 1, 1, 0.5f)), ticksBehind = ticksBehind, simulating = simulating, factionId = factionId diff --git a/Source/Client/UI/CursorPatches.cs b/Source/Client/UI/CursorPatches.cs index 49fd2081..397edb84 100644 --- a/Source/Client/UI/CursorPatches.cs +++ b/Source/Client/UI/CursorPatches.cs @@ -64,8 +64,6 @@ static void Postfix() [StaticConstructorOnStartup] static class SelectionBoxPatch { - static Material graySelection = MaterialPool.MatFrom("UI/Overlays/SelectionBracket", ShaderDatabase.MetaOverlay); - static MaterialPropertyBlock propBlock = new MaterialPropertyBlock(); static HashSet drawnThisUpdate = new HashSet(); static Dictionary selTimes = new Dictionary(); @@ -76,28 +74,31 @@ static void Postfix() foreach (var t in Find.Selector.SelectedObjects.OfType()) drawnThisUpdate.Add(t.thingIDNumber); - foreach (var player in Multiplayer.session.players) + var tempTimes = SelectionDrawer.selectTimes; + try { - if (player.factionId != Multiplayer.RealPlayerFaction.loadID) continue; + SelectionDrawer.selectTimes = selTimes; - foreach (var sel in player.selectedThings) + foreach (var player in Multiplayer.session.players) { - if (!drawnThisUpdate.Add(sel.Key)) continue; - if (!ThingsById.thingsById.TryGetValue(sel.Key, out Thing thing)) continue; - if (thing.Map != Find.CurrentMap) continue; + if (player.factionId != Multiplayer.RealPlayerFaction.loadID) continue; - selTimes[thing] = sel.Value; - SelectionDrawerUtility.CalculateSelectionBracketPositionsWorld(SelectionDrawer.bracketLocs, thing, thing.DrawPos, thing.RotatedSize.ToVector2(), selTimes, Vector2.one, 1f); - selTimes.Clear(); - - for (int i = 0; i < 4; i++) + foreach (var sel in player.selectedThings) { - Quaternion rotation = Quaternion.AngleAxis(-i * 90, Vector3.up); - propBlock.SetColor("_Color", player.color * new Color(1, 1, 1, 0.5f)); - Graphics.DrawMesh(MeshPool.plane10, SelectionDrawer.bracketLocs[i], rotation, graySelection, 0, null, 0, propBlock); + if (!drawnThisUpdate.Add(sel.Key)) continue; + if (!ThingsById.thingsById.TryGetValue(sel.Key, out Thing thing)) continue; + if (thing.MapHeld != Find.CurrentMap) continue; + + selTimes[thing] = sel.Value; + SelectionDrawer.DrawSelectionBracketFor(thing, player.selectionBracketMaterial); + selTimes.Clear(); } } } + finally + { + SelectionDrawer.selectTimes = tempTimes; + } drawnThisUpdate.Clear(); } @@ -130,5 +131,4 @@ static void Prefix(ref string str) str += $"\nSelected by: {players.Join()}"; } } - }