Fixed error from campfires with more than 4 players (However, other maxplayers mod already have this feature, so I'm not sure if it's compatible with other mods)
Added Disable drawing feature on PlayerExpandedState
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
// ReSharper disable ClassNeverInstantiated.Global
|
||||||
|
|
||||||
|
namespace SlayTheSpire2.LAN.Multiplayer.Helpers
|
||||||
|
{
|
||||||
|
internal class LanMapDrawingsHelper
|
||||||
|
{
|
||||||
|
public static readonly HashSet<ulong> DisableDrawingHashSet = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs
|
|||||||
{
|
{
|
||||||
private static void Prefix(NJoinFriendScreen __instance)
|
private static void Prefix(NJoinFriendScreen __instance)
|
||||||
{
|
{
|
||||||
var lanPanel = new NinePatchRect { Name = "LanPanel" };
|
var lanPanel = new NinePatchRect { Name = "LANPanel" };
|
||||||
|
|
||||||
__instance.AddChild(lanPanel);
|
__instance.AddChild(lanPanel);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using Godot;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MegaCrit.Sts2.Core.Entities.Players;
|
||||||
|
using MegaCrit.Sts2.Core.Nodes.Screens.Map;
|
||||||
|
using SlayTheSpire2.LAN.Multiplayer.Helpers;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedType.Global
|
||||||
|
|
||||||
|
namespace SlayTheSpire2.LAN.Multiplayer.Patchs
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(NMapDrawings), "CreateLineForPlayer")]
|
||||||
|
internal class NMapDrawingsPatch
|
||||||
|
{
|
||||||
|
private static void Postfix(Player player, Line2D __result)
|
||||||
|
{
|
||||||
|
if (LanMapDrawingsHelper.DisableDrawingHashSet.Contains(player.NetId))
|
||||||
|
{
|
||||||
|
__result.Visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using Godot;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MegaCrit.Sts2.Core.Assets;
|
||||||
|
using MegaCrit.Sts2.Core.Entities.Players;
|
||||||
|
using MegaCrit.Sts2.Core.Helpers;
|
||||||
|
using MegaCrit.Sts2.Core.Nodes.Multiplayer;
|
||||||
|
using MegaCrit.Sts2.Core.Nodes.Screens.CardLibrary;
|
||||||
|
using MegaCrit.Sts2.Core.Nodes.Screens.Map;
|
||||||
|
using MegaCrit.Sts2.Core.Runs;
|
||||||
|
using SlayTheSpire2.LAN.Multiplayer.Helpers;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedType.Global
|
||||||
|
|
||||||
|
namespace SlayTheSpire2.LAN.Multiplayer.Patchs
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(NMultiplayerPlayerExpandedState), "_Ready")]
|
||||||
|
internal class NMultiplayerPlayerExpandedStatePatch
|
||||||
|
{
|
||||||
|
private static void Prefix(NMultiplayerPlayerExpandedState __instance, Player ____player)
|
||||||
|
{
|
||||||
|
if (____player.NetId != RunManager.Instance.NetService.NetId)
|
||||||
|
{
|
||||||
|
var lanPanel = new HBoxContainer { Name = "LANPanel" };
|
||||||
|
__instance.AddChild(lanPanel);
|
||||||
|
|
||||||
|
lanPanel.AnchorLeft = 0.5f;
|
||||||
|
lanPanel.AnchorTop = 0;
|
||||||
|
lanPanel.AnchorRight = 0.5f;
|
||||||
|
lanPanel.AnchorBottom = 0;
|
||||||
|
|
||||||
|
lanPanel.OffsetLeft = -162;
|
||||||
|
lanPanel.OffsetTop = 100;
|
||||||
|
lanPanel.OffsetRight = 162;
|
||||||
|
lanPanel.OffsetBottom = 100;
|
||||||
|
|
||||||
|
var disableDrawing = PreloadManager.Cache
|
||||||
|
.GetScene(SceneHelper.GetScenePath("screens/card_library/card_library_tickbox"))
|
||||||
|
.Instantiate<Control>();
|
||||||
|
|
||||||
|
if (disableDrawing is NLibraryStatTickbox cardLibraryTickBox)
|
||||||
|
{
|
||||||
|
disableDrawing.Name = "DisableDrawing";
|
||||||
|
|
||||||
|
lanPanel.AddChild(cardLibraryTickBox);
|
||||||
|
|
||||||
|
cardLibraryTickBox.SetLabel("Disable drawing");
|
||||||
|
|
||||||
|
cardLibraryTickBox.IsTicked = LanMapDrawingsHelper.DisableDrawingHashSet.Contains(____player.NetId);
|
||||||
|
|
||||||
|
cardLibraryTickBox.Toggled += tickBox =>
|
||||||
|
{
|
||||||
|
var drawingState = Traverse.Create(NMapScreen.Instance?.Drawings)
|
||||||
|
.Method("GetDrawingStateForPlayer", ____player.NetId).GetValue();
|
||||||
|
var drawViewport = Traverse.Create(drawingState).Field("drawViewport").GetValue<SubViewport>();
|
||||||
|
|
||||||
|
if (tickBox.IsTicked)
|
||||||
|
{
|
||||||
|
if (drawViewport != null)
|
||||||
|
{
|
||||||
|
foreach (var line2D in drawViewport.GetChildren().OfType<Line2D>())
|
||||||
|
{
|
||||||
|
line2D.Visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LanMapDrawingsHelper.DisableDrawingHashSet.Add(____player.NetId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (drawViewport != null)
|
||||||
|
{
|
||||||
|
foreach (var line2D in drawViewport.GetChildren().OfType<Line2D>())
|
||||||
|
{
|
||||||
|
line2D.Visible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LanMapDrawingsHelper.DisableDrawingHashSet.Remove(____player.NetId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
using Godot;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MegaCrit.Sts2.Core.Nodes.Rooms;
|
||||||
|
using MegaCrit.Sts2.Core.Runs;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedType.Global
|
||||||
|
|
||||||
|
namespace SlayTheSpire2.LAN.Multiplayer.Patchs
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(NRestSiteRoom), "_Ready")]
|
||||||
|
internal class NRestSiteRoomPatch
|
||||||
|
{
|
||||||
|
private static void Prefix(NRestSiteRoom __instance, IRunState ____runState,
|
||||||
|
List<Control> ____characterContainers)
|
||||||
|
{
|
||||||
|
if (____runState.Players.Count > 4)
|
||||||
|
{
|
||||||
|
var bgContainer = __instance.GetNode("BgContainer");
|
||||||
|
|
||||||
|
var lastLeftCharacterUp = bgContainer.GetNode("Character_3");
|
||||||
|
var lastLeftCharacterDown = bgContainer.GetNode("Character_1");
|
||||||
|
|
||||||
|
var lastRightCharacterUp = bgContainer.GetNode("Character_4");
|
||||||
|
var lastRightCharacterDown = bgContainer.GetNode("Character_2");
|
||||||
|
|
||||||
|
for (var i = 4; i < ____runState.Players.Count; i++)
|
||||||
|
{
|
||||||
|
if (i % 2 == 0)
|
||||||
|
{
|
||||||
|
if (i % 4 == 0)
|
||||||
|
{
|
||||||
|
AddCharacter(bgContainer, ref lastLeftCharacterUp, ____characterContainers, i, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddCharacter(bgContainer, ref lastLeftCharacterDown, ____characterContainers, i, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (i % 4 == 1)
|
||||||
|
{
|
||||||
|
AddCharacter(bgContainer, ref lastRightCharacterUp, ____characterContainers, i, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddCharacter(bgContainer, ref lastRightCharacterDown, ____characterContainers, i, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Postfix(NRestSiteRoom __instance, IRunState ____runState)
|
||||||
|
{
|
||||||
|
if (____runState.Players.Count > 4)
|
||||||
|
{
|
||||||
|
var bgContainer = __instance.GetNode("BgContainer");
|
||||||
|
var restSiteBackground = bgContainer.GetChild(0);
|
||||||
|
|
||||||
|
var lastLeftRestSite = restSiteBackground.GetNode("RestSiteLLog");
|
||||||
|
var lastRightRestSite = restSiteBackground.GetNode("RestSiteRLog");
|
||||||
|
|
||||||
|
for (var i = 4; i < ____runState.Players.Count; i++)
|
||||||
|
{
|
||||||
|
if (i % 2 == 0 && i % 4 == 0)
|
||||||
|
{
|
||||||
|
AddRestSite(restSiteBackground, ref lastLeftRestSite, true);
|
||||||
|
}
|
||||||
|
else if (i % 4 == 1)
|
||||||
|
{
|
||||||
|
AddRestSite(restSiteBackground, ref lastRightRestSite, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddRestSite(Node restSiteBackground, ref Node restSite, bool isLeft)
|
||||||
|
{
|
||||||
|
var nextRestSiteIndex = restSite.GetIndex() + 1;
|
||||||
|
restSite = restSite.Duplicate();
|
||||||
|
restSiteBackground.AddChild(restSite);
|
||||||
|
restSite.MoveChild(restSite, nextRestSiteIndex);
|
||||||
|
|
||||||
|
if (restSite is Control control)
|
||||||
|
{
|
||||||
|
control.Position = new Vector2(isLeft ? control.Position.X - 200 : control.Position.X + 200,
|
||||||
|
control.Position.Y - 50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddCharacter(Node bgContainer, ref Node character, List<Control> characterContainers,
|
||||||
|
int index, bool isLeft)
|
||||||
|
{
|
||||||
|
var nextCharacterIndex = character.GetIndex() + 1;
|
||||||
|
character = character.Duplicate();
|
||||||
|
bgContainer.AddChild(character);
|
||||||
|
bgContainer.MoveChild(character, nextCharacterIndex);
|
||||||
|
|
||||||
|
if (character is Control control)
|
||||||
|
{
|
||||||
|
control.Name = $"Character_{index + 1}";
|
||||||
|
control.Position = new Vector2(isLeft ? control.Position.X - 200 : control.Position.X + 200,
|
||||||
|
control.Position.Y - 50);
|
||||||
|
|
||||||
|
characterContainers.Add(control);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using MegaCrit.Sts2.Core.Runs;
|
||||||
|
using SlayTheSpire2.LAN.Multiplayer.Helpers;
|
||||||
|
|
||||||
|
// ReSharper disable UnusedMember.Global
|
||||||
|
// ReSharper disable UnusedType.Global
|
||||||
|
|
||||||
|
namespace SlayTheSpire2.LAN.Multiplayer.Patchs
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(RunManager), "CleanUp")]
|
||||||
|
internal class RunManagerPatch
|
||||||
|
{
|
||||||
|
private static void Postfix()
|
||||||
|
{
|
||||||
|
LanMapDrawingsHelper.DisableDrawingHashSet.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user