From 0e921cb119924c70aad66f762f0c941df1ec29ee Mon Sep 17 00:00:00 2001 From: kmyuhkyuk <72241714+kmyuhkyuk@users.noreply.github.com> Date: Mon, 23 Mar 2026 08:23:23 +0800 Subject: [PATCH] Optimize codes --- .../Components/IPAddressInfoPanel.cs | 203 +++++-------- .../Components/JoinButton.cs | 42 ++- .../Components/LanMultiplayerHostSubmenu.cs | 2 +- .../Patchs/Screens/NJoinFriendScreenPatch.cs | 65 ++--- .../Screens/NMainMenuSubmenuStackPatch.cs | 4 +- .../NMultiplayerPlayerExpandedStatePatch.cs | 64 ++-- .../Screens/NMultiplayerSubmenuPatch.cs | 139 ++++----- .../Patchs/Screens/NRestSiteRoomPatch.cs | 50 ++-- .../Patchs/Screens/NSettingsScreenPatch.cs | 273 ++++++++---------- .../NTreasureRoomRelicCollectionPatch.cs | 71 ++--- .../Patchs/Screens/RunScreenPatchs.cs | 5 +- .../Services/RunScreenService.cs | 4 +- 12 files changed, 401 insertions(+), 521 deletions(-) diff --git a/SlayTheSpire2.LAN.Multiplayer/Components/IPAddressInfoPanel.cs b/SlayTheSpire2.LAN.Multiplayer/Components/IPAddressInfoPanel.cs index 1bcaf14..a9da405 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Components/IPAddressInfoPanel.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Components/IPAddressInfoPanel.cs @@ -47,104 +47,69 @@ namespace SlayTheSpire2.LAN.Multiplayer.Components public static IPAddressInfoPanel Create() { - var ipAddressInfoPanel = new IPAddressInfoPanel(); - - ipAddressInfoPanel.MouseFilter = MouseFilterEnum.Ignore; - + var ipAddressInfoPanel = new IPAddressInfoPanel { MouseFilter = MouseFilterEnum.Ignore }; ipAddressInfoPanel.SetAnchorsAndOffsetsPreset(LayoutPreset.FullRect); - var content = new VBoxContainer { Name = "Content" }; - ipAddressInfoPanel.AddChild(content); + var content = new VBoxContainer { Name = "Content", MouseFilter = MouseFilterEnum.Stop }; + ipAddressInfoPanel.AddChildSafely(content); - content.MouseFilter = MouseFilterEnum.Stop; + var menu = new Control + { Name = "Menu", CustomMinimumSize = new Vector2(300, 24), MouseFilter = MouseFilterEnum.Pass }; + content.AddChildSafely(menu); - var menu = new Control { Name = "Menu" }; - content.AddChild(menu); - - menu.CustomMinimumSize = new Vector2(300, 24); - - menu.MouseFilter = MouseFilterEnum.Pass; - - var background = new NinePatchRect { Name = "Background" }; - menu.AddChild(background); - - background.MouseFilter = MouseFilterEnum.Ignore; + var background = new NinePatchRect + { + Name = "Background", MouseFilter = MouseFilterEnum.Ignore, + Texture = GD.Load("res://images/ui/tiny_nine_patch.png"), PatchMarginLeft = 12, + PatchMarginTop = 12, PatchMarginRight = 12, PatchMarginBottom = 12, + Modulate = new Color(Colors.Black, 0.471f) + }; + menu.AddChildSafely(background); background.SetAnchorsAndOffsetsPreset(LayoutPreset.FullRect); - background.Texture = GD.Load("res://images/ui/tiny_nine_patch.png"); - background.PatchMarginLeft = 12; - background.PatchMarginTop = 12; - background.PatchMarginRight = 12; - background.PatchMarginBottom = 12; + var menuIcon = new TextureRect { Name = "Icon", MouseFilter = MouseFilterEnum.Ignore }; - background.Modulate = new Color(Colors.Black, 0.471f); - - var menuIcon = new TextureRect { Name = "Icon" }; - menu.AddChild(menuIcon); - - menuIcon.MouseFilter = MouseFilterEnum.Ignore; + var menuSvgImage = new Image(); + menuSvgImage.LoadSvgFromString( + ""); + menuIcon.Texture = ImageTexture.CreateFromImage(menuSvgImage); + menu.AddChildSafely(menuIcon); menuIcon.SetAnchorsPreset(LayoutPreset.Center); menuIcon.OffsetLeft = -12; menuIcon.OffsetTop = -12; menuIcon.OffsetRight = 12; menuIcon.OffsetBottom = 12; - var menuSvgImage = new Image(); + var box = new PanelContainer + { Name = "Box", MouseFilter = MouseFilterEnum.Ignore, Modulate = new Color(Colors.White, 0) }; - menuSvgImage.LoadSvgFromString( - ""); - - menuIcon.Texture = ImageTexture.CreateFromImage(menuSvgImage); - - var box = new PanelContainer { Name = "Box" }; - content.AddChild(box); - - box.MouseFilter = MouseFilterEnum.Ignore; - - box.Modulate = new Color(Colors.White, 0); - - var styleBox = new StyleBoxTexture(); - - styleBox.Texture = GD.Load("res://images/ui/tiny_nine_patch.png"); - styleBox.TextureMarginLeft = 12; - styleBox.TextureMarginTop = 12; - styleBox.TextureMarginRight = 12; - styleBox.TextureMarginBottom = 12; - - styleBox.ContentMarginLeft = 12; - styleBox.ContentMarginTop = 12; - styleBox.ContentMarginRight = 12; - styleBox.ContentMarginBottom = 12; - - styleBox.ModulateColor = new Color(Colors.Black, 0.471f); + var styleBox = new StyleBoxTexture + { + Texture = GD.Load("res://images/ui/tiny_nine_patch.png"), TextureMarginLeft = 12, + TextureMarginTop = 12, TextureMarginRight = 12, TextureMarginBottom = 12, ContentMarginLeft = 12, + ContentMarginTop = 12, ContentMarginRight = 12, ContentMarginBottom = 12, + ModulateColor = new Color(Colors.Black, 0.471f) + }; box.AddThemeStyleboxOverride("panel", styleBox); + content.AddChildSafely(box); - var container = new VBoxContainer { Name = "Container" }; - box.AddChild(container); - - container.MouseFilter = MouseFilterEnum.Ignore; - + var container = new VBoxContainer + { + Name = "Container", MouseFilter = MouseFilterEnum.Ignore, Alignment = BoxContainer.AlignmentMode.Center + }; + container.AddThemeConstantOverride("separation", 8); + box.AddChildSafely(container); container.SetAnchorsAndOffsetsPreset(LayoutPreset.FullRect); - container.Alignment = BoxContainer.AlignmentMode.Center; - - container.AddThemeConstantOverride("separation", 8); - - var loading = new Control { Name = "Loading" }; - container.AddChild(loading); - - loading.CustomMinimumSize = new Vector2(64, 64); - - loading.MouseFilter = MouseFilterEnum.Ignore; - - var loadingIcon = new LoadingIcon(); - loading.AddChild(loadingIcon); - - loadingIcon.MouseFilter = MouseFilterEnum.Ignore; + var loading = new Control + { Name = "Loading", CustomMinimumSize = new Vector2(64, 64), MouseFilter = MouseFilterEnum.Ignore }; + container.AddChildSafely(loading); + var loadingIcon = new LoadingIcon { MouseFilter = MouseFilterEnum.Ignore }; + loading.AddChildSafely(loadingIcon); loadingIcon.SetAnchorsPreset(LayoutPreset.Center); loadingIcon.OffsetLeft = -32; loadingIcon.OffsetTop = -32; @@ -157,66 +122,52 @@ namespace SlayTheSpire2.LAN.Multiplayer.Components content.SetAnchorsAndOffsetsPreset(LayoutPreset.CenterTop); - var copiedLabel = new CopiedLabel { Name = "CopiedLabel" }; - ipAddressInfoPanel.AddChild(copiedLabel); - - copiedLabel.MouseFilter = MouseFilterEnum.Ignore; + var copiedLabel = new CopiedLabel { Name = "CopiedLabel", MouseFilter = MouseFilterEnum.Ignore }; + ipAddressInfoPanel.AddChildSafely(copiedLabel); return ipAddressInfoPanel; } private static void AddAddressElement(Node container, string name, string locKeyPrefix, bool isTrim) { - var addressElement = new HBoxContainer { Name = name }; - container.AddChild(addressElement); - - addressElement.CustomMinimumSize = new Vector2(0, 24); - - addressElement.Alignment = BoxContainer.AlignmentMode.Center; - - addressElement.MouseFilter = MouseFilterEnum.Ignore; - - var ipAddressTitleLabel = new IPAddressLabel { Name = "TitleLabel" }; - addressElement.AddChild(ipAddressTitleLabel); - - ipAddressTitleLabel.MouseFilter = MouseFilterEnum.Ignore; + var addressElement = new HBoxContainer + { Name = name, CustomMinimumSize = new Vector2(0, 24), MouseFilter = MouseFilterEnum.Ignore }; + var ipAddressTitleLabel = new IPAddressLabel { Name = "TitleLabel", MouseFilter = MouseFilterEnum.Ignore }; + addressElement.AddChildSafely(ipAddressTitleLabel); ipAddressTitleLabel.SetLocalization(locKeyPrefix); - var ipAddressLabel = new IPAddressLabel { Name = "Label" }; - addressElement.AddChild(ipAddressLabel); - - ipAddressLabel.MouseFilter = MouseFilterEnum.Ignore; + var ipAddressLabel = new IPAddressLabel { Name = "Label", MouseFilter = MouseFilterEnum.Ignore }; if (isTrim) { ipAddressLabel.SizeFlagsHorizontal = SizeFlags.ExpandFill; ipAddressLabel.TextOverrunBehavior = TextServer.OverrunBehavior.TrimEllipsis; } + + addressElement.AddChildSafely(ipAddressLabel); + + container.AddChildSafely(addressElement); } private static void AddAddressContainer(Node container, string name, string locKeyPrefix) { - var addressElement = new VBoxContainer { Name = name }; - container.AddChild(addressElement); - - addressElement.CustomMinimumSize = new Vector2(0, 24); - - addressElement.MouseFilter = MouseFilterEnum.Ignore; - - var ipAddressTitleLabel = new IPAddressLabel { Name = "TitleLabel" }; - addressElement.AddChild(ipAddressTitleLabel); - - ipAddressTitleLabel.HorizontalAlignment = HorizontalAlignment.Center; + var addressElement = new VBoxContainer + { Name = name, CustomMinimumSize = new Vector2(0, 24), MouseFilter = MouseFilterEnum.Ignore }; + var ipAddressTitleLabel = new IPAddressLabel + { Name = "TitleLabel", HorizontalAlignment = HorizontalAlignment.Center }; + addressElement.AddChildSafely(ipAddressTitleLabel); ipAddressTitleLabel.SetLocalization(locKeyPrefix); - var vBoxContainer = new VBoxContainer { Name = "Container" }; - addressElement.AddChild(vBoxContainer); + var vBoxContainer = new VBoxContainer + { + Name = "Container", MouseFilter = MouseFilterEnum.Ignore, Alignment = BoxContainer.AlignmentMode.Center + }; - vBoxContainer.MouseFilter = MouseFilterEnum.Ignore; + addressElement.AddChildSafely(vBoxContainer); - vBoxContainer.Alignment = BoxContainer.AlignmentMode.Center; + container.AddChildSafely(addressElement); } public override void _Ready() @@ -312,7 +263,7 @@ namespace SlayTheSpire2.LAN.Multiplayer.Components foreach (var child in _localIPAddressContainer.GetChildren()) { - child.QueueFree(); + child.QueueFreeSafely(); } _loading.Visible = true; @@ -344,20 +295,14 @@ namespace SlayTheSpire2.LAN.Multiplayer.Components var hasLocalIPAddress = false; - var localIPAddressList = GetLocalIPAddressList(); - - foreach (var localIPAddress in localIPAddressList) + foreach (var localIPAddress in GetLocalIPAddress()) { if (localIPAddress != ipAddress) { - var ipAddressLabel = new IPAddressLabel(); - _localIPAddressContainer.AddChild(ipAddressLabel); + var ipAddressLabel = new IPAddressLabel + { MouseFilter = MouseFilterEnum.Pass, HorizontalAlignment = HorizontalAlignment.Center }; - ipAddressLabel.MouseFilter = MouseFilterEnum.Pass; - - ipAddressLabel.HorizontalAlignment = HorizontalAlignment.Center; - - ipAddressLabel.Text = $"{localIPAddress}:{port}"; + ipAddressLabel.SetTextAutoSize($"{localIPAddress}:{port}"); ipAddressLabel.GuiInput += inputEvent => { @@ -372,6 +317,8 @@ namespace SlayTheSpire2.LAN.Multiplayer.Components } }; + _localIPAddressContainer.AddChildSafely(ipAddressLabel); + hasLocalIPAddress = true; } } @@ -402,10 +349,8 @@ namespace SlayTheSpire2.LAN.Multiplayer.Components _content.SetAnchorsAndOffsetsPreset(LayoutPreset.CenterTop); } - private static List GetLocalIPAddressList() + private static IEnumerable GetLocalIPAddress() { - var list = new List(); - foreach (var networkInterface in NetworkInterface.GetAllNetworkInterfaces()) { if (networkInterface.OperationalStatus == OperationalStatus.Up && @@ -417,14 +362,10 @@ namespace SlayTheSpire2.LAN.Multiplayer.Components foreach (var ip in networkInterface.GetIPProperties().UnicastAddresses) { if (ip.Address.AddressFamily == AddressFamily.InterNetwork) - { - list.Add(ip.Address.ToString()); - } + yield return ip.Address.ToString(); } } } - - return list; } private void OnMouseEntered() diff --git a/SlayTheSpire2.LAN.Multiplayer/Components/JoinButton.cs b/SlayTheSpire2.LAN.Multiplayer/Components/JoinButton.cs index 64b4147..eeac629 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Components/JoinButton.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Components/JoinButton.cs @@ -1,6 +1,7 @@ using Godot; using MegaCrit.Sts2.addons.mega_text; using MegaCrit.Sts2.Core.ControllerInput; +using MegaCrit.Sts2.Core.Helpers; using MegaCrit.Sts2.Core.Localization; using MegaCrit.Sts2.Core.Nodes.Screens.MainMenu; @@ -12,40 +13,33 @@ namespace SlayTheSpire2.LAN.Multiplayer.Components public static JoinButton Create(NJoinFriendRefreshButton joinFriendRefreshButton) { - var joinButton = new JoinButton(); + var joinButton = new JoinButton + { + CustomMinimumSize = new Vector2(150, 50), + SizeFlagsHorizontal = SizeFlags.ShrinkCenter, + MouseFilter = MouseFilterEnum.Stop, + Material = (Material)joinFriendRefreshButton.Material.Duplicate() + }; - joinButton.CustomMinimumSize = new Vector2(150, 50); - joinButton.SizeFlagsHorizontal = SizeFlags.ShrinkCenter; - - joinButton.MouseFilter = MouseFilterEnum.Stop; - - joinButton.Material = joinFriendRefreshButton.Material.Duplicate() as Material; - - var background = new NinePatchRect { Name = "Background" }; - joinButton.AddChild(background); - - background.MouseFilter = MouseFilterEnum.Ignore; + var background = new NinePatchRect + { + Name = "Background", MouseFilter = MouseFilterEnum.Ignore, + Texture = GD.Load("res://images/ui/tiny_nine_patch.png"), PatchMarginLeft = 12, + PatchMarginTop = 12, PatchMarginRight = 12, PatchMarginBottom = 12, + Modulate = joinFriendRefreshButton.SelfModulate, + Material = joinButton.Material + }; + joinButton.AddChildSafely(background); background.SetAnchorsAndOffsetsPreset(LayoutPreset.FullRect); - background.Texture = GD.Load("res://images/ui/tiny_nine_patch.png"); - background.PatchMarginLeft = 12; - background.PatchMarginTop = 12; - background.PatchMarginRight = 12; - background.PatchMarginBottom = 12; - - background.Modulate = joinFriendRefreshButton.SelfModulate; - background.Material = joinButton.Material; - foreach (var child in joinFriendRefreshButton.GetChildren()) { - joinButton.AddChild(child.Duplicate()); + joinButton.AddChildSafely(child.Duplicate()); } var controllerIcon = joinButton.GetNode("ControllerIcon"); - controllerIcon.Owner = joinButton; - controllerIcon.Position = new Vector2(controllerIcon.Position.X - 12, controllerIcon.Position.Y); return joinButton; diff --git a/SlayTheSpire2.LAN.Multiplayer/Components/LanMultiplayerHostSubmenu.cs b/SlayTheSpire2.LAN.Multiplayer/Components/LanMultiplayerHostSubmenu.cs index 1a891c5..faa9d75 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Components/LanMultiplayerHostSubmenu.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Components/LanMultiplayerHostSubmenu.cs @@ -34,7 +34,7 @@ namespace SlayTheSpire2.LAN.Multiplayer.Components child.Reparent(lanMultiplayerHostSubmenu, false); } - multiplayerHostSubmenu.QueueFree(); + multiplayerHostSubmenu.QueueFreeSafely(); return lanMultiplayerHostSubmenu; } diff --git a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NJoinFriendScreenPatch.cs b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NJoinFriendScreenPatch.cs index 28fb581..ecde590 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NJoinFriendScreenPatch.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NJoinFriendScreenPatch.cs @@ -18,13 +18,18 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens { private static void Prefix(NJoinFriendScreen __instance) { - var lanPanel = new NinePatchRect { Name = "LANPanel" }; - __instance.AddChild(lanPanel); + var panel = __instance.GetNode("Panel"); - lanPanel.PatchMarginTop = 12; - lanPanel.PatchMarginBottom = 12; - lanPanel.PatchMarginLeft = 12; - lanPanel.PatchMarginRight = 12; + var lanPanel = new NinePatchRect + { + Name = "LANPanel", + Texture = panel.Texture, + SelfModulate = panel.SelfModulate, + PatchMarginTop = 12, + PatchMarginBottom = 12, + PatchMarginLeft = 12, + PatchMarginRight = 12 + }; lanPanel.SetAnchorsPreset(Control.LayoutPreset.Center); lanPanel.OffsetLeft = 450; @@ -32,43 +37,27 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens lanPanel.OffsetRight = 790; lanPanel.OffsetBottom = 338; - if (__instance.GetNode("Panel") is NinePatchRect panel) + var vBoxContainer = new VBoxContainer { - lanPanel.Texture = panel.Texture; - lanPanel.SelfModulate = panel.SelfModulate; - } + Alignment = BoxContainer.AlignmentMode.Center + }; - var vBoxContainer = new VBoxContainer(); - - lanPanel.AddChild(vBoxContainer); - - vBoxContainer.Alignment = BoxContainer.AlignmentMode.Center; - vBoxContainer.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.FullRect); vBoxContainer.AddThemeConstantOverride("separation", 24); + lanPanel.AddChildSafely(vBoxContainer); + vBoxContainer.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.FullRect); - if (__instance.GetNode("TitleLabel").Duplicate() is MegaLabel ipAddressLabel) + var addressLineEdit = new AddressLineEdit { - lanPanel.AddChild(ipAddressLabel); + Name = "AddressInput", Text = SettingsService.Instance.SettingsModel.IPAddress, + Alignment = HorizontalAlignment.Center, CustomMinimumSize = new Vector2(300, 50), + SizeFlagsHorizontal = Control.SizeFlags.ShrinkCenter + }; - ipAddressLabel.SetTextAutoSize("LAN IP:"); - ipAddressLabel.CustomMinimumSize = new Vector2(300, 0); - ipAddressLabel.SizeFlagsHorizontal = Control.SizeFlags.ShrinkCenter; - } - - var addressLineEdit = new AddressLineEdit { Name = "AddressInput" }; - - vBoxContainer.AddChild(addressLineEdit); - - addressLineEdit.Text = SettingsService.Instance.SettingsModel.IPAddress; - addressLineEdit.Alignment = HorizontalAlignment.Center; - addressLineEdit.CustomMinimumSize = new Vector2(300, 50); - addressLineEdit.SizeFlagsHorizontal = Control.SizeFlags.ShrinkCenter; + vBoxContainer.AddChildSafely(addressLineEdit); var joinButton = JoinButton.Create(__instance.GetNode("RefreshButton")); - joinButton.Name = "JointButton"; - - vBoxContainer.AddChild(joinButton); + vBoxContainer.AddChildSafely(joinButton); joinButton.Connect(NClickableControl.SignalName.Released, Callable.From(_ => { @@ -95,6 +84,14 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens SettingsService.Instance.SettingsModel.NetId, addressInfo.Address, port))); } })); + + var ipAddressLabel = (MegaLabel)__instance.GetNode("TitleLabel").Duplicate(); + ipAddressLabel.CustomMinimumSize = new Vector2(300, 0); + ipAddressLabel.SizeFlagsHorizontal = Control.SizeFlags.ShrinkCenter; + lanPanel.AddChildSafely(ipAddressLabel); + ipAddressLabel.SetTextAutoSize("LAN IP:"); + + __instance.AddChildSafely(lanPanel); } } } \ No newline at end of file diff --git a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMainMenuSubmenuStackPatch.cs b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMainMenuSubmenuStackPatch.cs index fa0e5b0..bec5424 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMainMenuSubmenuStackPatch.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMainMenuSubmenuStackPatch.cs @@ -25,10 +25,8 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens if (lanMultiplayerHostSubmenu != null) { lanMultiplayerHostSubmenu.Name = "LANMultiplayerHostSubmenu"; - - __instance.AddChildSafely(lanMultiplayerHostSubmenu); - lanMultiplayerHostSubmenu.Visible = false; + __instance.AddChildSafely(lanMultiplayerHostSubmenu); __result = lanMultiplayerHostSubmenu; diff --git a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMultiplayerPlayerExpandedStatePatch.cs b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMultiplayerPlayerExpandedStatePatch.cs index 41984df..063b0eb 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMultiplayerPlayerExpandedStatePatch.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMultiplayerPlayerExpandedStatePatch.cs @@ -32,62 +32,54 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens var disableDrawing = PreloadManager.Cache .GetScene(SceneHelper.GetScenePath("screens/card_library/card_library_tickbox")) - .Instantiate(); + .Instantiate(); - if (disableDrawing is NLibraryStatTickbox cardLibraryTickBox && - container.GetNode("MarginContainer") is MarginContainer marginContainer) + disableDrawing.Name = "DisableDrawing"; + disableDrawing.SizeFlagsHorizontal = Control.SizeFlags.ShrinkCenter; + disableDrawing.SetLabel("Disable drawing"); + + var marginContainer = (MarginContainer)container.GetNode("MarginContainer"); + marginContainer.RemoveThemeConstantOverride("margin_top"); + + var lanMapDrawingsService = LanMapDrawingsService.Instance; + + container.AddChildSafely(disableDrawing); + container.MoveChild(disableDrawing, 0); + + disableDrawing.IsTicked = + lanMapDrawingsService.DisableDrawingHashSet.Contains(____player.NetId); + + disableDrawing.Toggled += tickBox => { - disableDrawing.Name = "DisableDrawing"; + if (NMapScreen.Instance == null) + return; - container.AddChild(cardLibraryTickBox); - container.MoveChild(cardLibraryTickBox, 0); + var drawingState = GetDrawingStateForPlayer(NMapScreen.Instance.Drawings, ____player.NetId); - marginContainer.RemoveThemeConstantOverride("margin_top"); + var drawViewport = Traverse.Create(drawingState).Field("drawViewport").GetValue(); - cardLibraryTickBox.SizeFlagsHorizontal = Control.SizeFlags.ShrinkCenter; - - cardLibraryTickBox.SetLabel("Disable drawing"); - - var lanMapDrawingsService = LanMapDrawingsService.Instance; - - cardLibraryTickBox.IsTicked = - lanMapDrawingsService.DisableDrawingHashSet.Contains(____player.NetId); - - cardLibraryTickBox.Toggled += tickBox => + if (drawViewport != null) { - if (NMapScreen.Instance == null) - return; - - var drawingState = GetDrawingStateForPlayer(NMapScreen.Instance.Drawings, ____player.NetId); - - var drawViewport = Traverse.Create(drawingState).Field("drawViewport").GetValue(); - if (tickBox.IsTicked) { - if (drawViewport != null) + foreach (var line2D in drawViewport.GetChildren().OfType()) { - foreach (var line2D in drawViewport.GetChildren().OfType()) - { - line2D.Visible = false; - } + line2D.Visible = false; } lanMapDrawingsService.DisableDrawingHashSet.Add(____player.NetId); } else { - if (drawViewport != null) + foreach (var line2D in drawViewport.GetChildren().OfType()) { - foreach (var line2D in drawViewport.GetChildren().OfType()) - { - line2D.Visible = true; - } + line2D.Visible = true; } lanMapDrawingsService.DisableDrawingHashSet.Remove(____player.NetId); } - }; - } + } + }; } } } diff --git a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMultiplayerSubmenuPatch.cs b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMultiplayerSubmenuPatch.cs index bd07f6b..1302cc4 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMultiplayerSubmenuPatch.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NMultiplayerSubmenuPatch.cs @@ -29,90 +29,93 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens { var buttonContainerNode = __instance.GetNode("ButtonContainer"); - if (buttonContainerNode.GetNode("HostButton").Duplicate() is NSubmenuButton lanHostButton) - { - NSubmenuButtonDuplicateMaterial(lanHostButton); + var lanHostButton = (NSubmenuButton)buttonContainerNode.GetNode("HostButton").Duplicate(); - buttonContainerNode.AddChild(lanHostButton); - buttonContainerNode.MoveChild(lanHostButton, 1); + NSubmenuButtonDuplicateMaterial(lanHostButton); - lanHostButton.Connect(NClickableControl.SignalName.Released, - Callable.From(_ => + buttonContainerNode.AddChildSafely(lanHostButton); + buttonContainerNode.MoveChild(lanHostButton, 1); + + lanHostButton.SetIconAndLocalization("HOST"); + + var lanHostTitle = Traverse.Create(lanHostButton).Field("_title").GetValue(); + lanHostTitle.SetTextAutoSize($"LAN {lanHostTitle.Text}"); + + lanHostButton.Connect(NClickableControl.SignalName.Released, + Callable.From(_ => + { + var traverse = Traverse.Create(__instance); + + var settingsModel = SettingsService.Instance.SettingsModel; + + var stack = traverse.Field("_stack").GetValue(); + + if (SaveManager.Instance.Progress.NumberOfRuns > 0) { - var traverse = Traverse.Create(__instance); - - var settingsModel = SettingsService.Instance.SettingsModel; - - var stack = traverse.Field("_stack").GetValue(); - - if (SaveManager.Instance.Progress.NumberOfRuns > 0) - { - stack.PushSubmenuType(); - } - else - { - LanHostHelper.StartHost(GameMode.Standard, - traverse.Field("_loadingOverlay").GetValue(), stack, settingsModel.HostPort, - settingsModel.HostMaxPlayers); - } - })); - lanHostButton.SetIconAndLocalization("HOST"); - var lanHostTitle = Traverse.Create(lanHostButton).Field("_title").GetValue(); - lanHostTitle.Text = $"LAN {lanHostTitle.Text}"; - - LanMultiplayerSubmenuButtonService.Instance.LanHostButton = lanHostButton; - } - - if (buttonContainerNode.GetNode("LoadButton").Duplicate() is NSubmenuButton lanLoadButton) - { - NSubmenuButtonDuplicateMaterial(lanLoadButton); - - buttonContainerNode.AddChild(lanLoadButton); - buttonContainerNode.MoveChild(lanLoadButton, 2); - - lanLoadButton.Connect(NClickableControl.SignalName.Released, - Callable.From(_ => + stack.PushSubmenuType(); + } + else { - var traverse = Traverse.Create(__instance); + LanHostHelper.StartHost(GameMode.Standard, + traverse.Field("_loadingOverlay").GetValue(), stack, settingsModel.HostPort, + settingsModel.HostMaxPlayers); + } + })); - var settingsModel = SettingsService.Instance.SettingsModel; + LanMultiplayerSubmenuButtonService.Instance.LanHostButton = lanHostButton; - LanHostHelper.StartLoad(lanLoadButton, traverse.Field("_loadingOverlay").GetValue(), - traverse.Field("_stack").GetValue(), - settingsModel.HostPort, settingsModel.HostMaxPlayers); - })); - lanLoadButton.SetIconAndLocalization("MP_LOAD"); - var lanLoadButtonTitle = Traverse.Create(lanLoadButton).Field("_title").GetValue(); - lanLoadButtonTitle.Text = $"LAN {lanLoadButtonTitle.Text}"; + var lanLoadButton = (NSubmenuButton)buttonContainerNode.GetNode("LoadButton").Duplicate(); - LanMultiplayerSubmenuButtonService.Instance.LanLoadButton = lanLoadButton; - } + NSubmenuButtonDuplicateMaterial(lanLoadButton); - if (buttonContainerNode.GetNode("AbandonButton").Duplicate() is NSubmenuButton lanAbandonButton) - { - NSubmenuButtonDuplicateMaterial(lanAbandonButton); + buttonContainerNode.AddChildSafely(lanLoadButton); + buttonContainerNode.MoveChild(lanLoadButton, 2); - buttonContainerNode.AddChild(lanAbandonButton); - buttonContainerNode.MoveChild(lanAbandonButton, 3); + lanLoadButton.SetIconAndLocalization("MP_LOAD"); - lanAbandonButton.Connect(NClickableControl.SignalName.Released, - Callable.From(_ => - { - TaskHelper.RunSafely( - LanHostHelper.TryAbandonMultiplayerRun(() => UpdateButtons(__instance))); - })); - lanAbandonButton.SetIconAndLocalization("MP_ABANDON"); - var lanAbandonButtonTitle = Traverse.Create(lanAbandonButton).Field("_title").GetValue(); - lanAbandonButtonTitle.Text = $"LAN {lanAbandonButtonTitle.Text}"; + var lanLoadButtonTitle = Traverse.Create(lanLoadButton).Field("_title").GetValue(); + lanLoadButtonTitle.SetTextAutoSize($"LAN {lanLoadButtonTitle.Text}"); - LanMultiplayerSubmenuButtonService.Instance.LanAbandonButton = lanAbandonButton; - } + lanLoadButton.Connect(NClickableControl.SignalName.Released, + Callable.From(_ => + { + var traverse = Traverse.Create(__instance); + + var settingsModel = SettingsService.Instance.SettingsModel; + + LanHostHelper.StartLoad(lanLoadButton, traverse.Field("_loadingOverlay").GetValue(), + traverse.Field("_stack").GetValue(), + settingsModel.HostPort, settingsModel.HostMaxPlayers); + })); + + LanMultiplayerSubmenuButtonService.Instance.LanLoadButton = lanLoadButton; + + var lanAbandonButton = (NSubmenuButton)buttonContainerNode.GetNode("AbandonButton").Duplicate(); + + NSubmenuButtonDuplicateMaterial(lanAbandonButton); + + buttonContainerNode.AddChildSafely(lanAbandonButton); + buttonContainerNode.MoveChild(lanAbandonButton, 3); + + lanAbandonButton.SetIconAndLocalization("MP_ABANDON"); + + var lanAbandonButtonTitle = Traverse.Create(lanAbandonButton).Field("_title").GetValue(); + lanAbandonButtonTitle.SetTextAutoSize($"LAN {lanAbandonButtonTitle.Text}"); + + lanAbandonButton.Connect(NClickableControl.SignalName.Released, + Callable.From(_ => + { + TaskHelper.RunSafely( + LanHostHelper.TryAbandonMultiplayerRun(() => UpdateButtons(__instance))); + })); + + LanMultiplayerSubmenuButtonService.Instance.LanAbandonButton = lanAbandonButton; } private static void NSubmenuButtonDuplicateMaterial(NSubmenuButton nSubmenuButton) { var bgPanel = nSubmenuButton.GetNode("BgPanel"); - bgPanel.Material = bgPanel.Material.Duplicate() as Material; + bgPanel.Material = (Material)bgPanel.Material.Duplicate(); } } diff --git a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NRestSiteRoomPatch.cs b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NRestSiteRoomPatch.cs index 3cc8b36..8eac7c5 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NRestSiteRoomPatch.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NRestSiteRoomPatch.cs @@ -1,7 +1,9 @@ using Godot; using HarmonyLib; +using MegaCrit.Sts2.Core.Helpers; using MegaCrit.Sts2.Core.Nodes.Rooms; using MegaCrit.Sts2.Core.Runs; +using Control = Godot.Control; // ReSharper disable UnusedMember.Global // ReSharper disable UnusedType.Global @@ -18,11 +20,11 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens { var bgContainer = __instance.GetNode("BgContainer"); - var lastLeftCharacterUp = bgContainer.GetNode("Character_3"); - var lastLeftCharacterDown = bgContainer.GetNode("Character_1"); + var lastLeftCharacterUp = (Control)bgContainer.GetNode("Character_3"); + var lastLeftCharacterDown = (Control)bgContainer.GetNode("Character_1"); - var lastRightCharacterUp = bgContainer.GetNode("Character_4"); - var lastRightCharacterDown = bgContainer.GetNode("Character_2"); + var lastRightCharacterUp = (Control)bgContainer.GetNode("Character_4"); + var lastRightCharacterDown = (Control)bgContainer.GetNode("Character_2"); for (var i = 4; i < ____runState.Players.Count; i++) { @@ -59,8 +61,8 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens var bgContainer = __instance.GetNode("BgContainer"); var restSiteBackground = bgContainer.GetChild(0); - var lastLeftRestSite = restSiteBackground.GetNode("RestSiteLLog"); - var lastRightRestSite = restSiteBackground.GetNode("RestSiteRLog"); + var lastLeftRestSite = (Control)restSiteBackground.GetNode("RestSiteLLog"); + var lastRightRestSite = (Control)restSiteBackground.GetNode("RestSiteRLog"); for (var i = 4; i < ____runState.Players.Count; i++) { @@ -76,36 +78,32 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens } } - private static void AddRestSite(Node restSiteBackground, ref Node restSite, bool isLeft) + private static void AddRestSite(Node restSiteBackground, ref Control 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); - } + restSite = (Control)restSite.Duplicate(); + + restSite.Position = new Vector2(isLeft ? restSite.Position.X - 200 : restSite.Position.X + 200, + restSite.Position.Y - 50); + + restSiteBackground.AddChildSafely(restSite); + restSite.MoveChild(restSite, nextRestSiteIndex); } - private static void AddCharacter(Node bgContainer, ref Node character, List characterContainers, + private static void AddCharacter(Node bgContainer, ref Control character, List characterContainers, int index, bool isLeft) { var nextCharacterIndex = character.GetIndex() + 1; - character = character.Duplicate(); - bgContainer.AddChild(character); + + character = (Control)character.Duplicate(); + character.Name = $"Character_{index + 1}"; + bgContainer.AddChildSafely(character); bgContainer.MoveChild(character, nextCharacterIndex); + character.Position = new Vector2(isLeft ? character.Position.X - 200 : character.Position.X + 200, + character.Position.Y - 50); - 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); - } + characterContainers.Add(character); } } } \ No newline at end of file diff --git a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NSettingsScreenPatch.cs b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NSettingsScreenPatch.cs index 871de63..fd3943c 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NSettingsScreenPatch.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NSettingsScreenPatch.cs @@ -1,6 +1,7 @@ using Godot; using HarmonyLib; using MegaCrit.Sts2.addons.mega_text; +using MegaCrit.Sts2.Core.Helpers; using MegaCrit.Sts2.Core.Localization; using MegaCrit.Sts2.Core.Nodes.Screens.Settings; using SlayTheSpire2.LAN.Multiplayer.Components; @@ -26,178 +27,150 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens var moddingNode = __instance.GetNode("%Modding"); var vBoxContainerNode = moddingNode.GetParent(); - var generalSettings = vBoxContainerNode.GetParent(); - if (__instance.GetNode("%ModdingDivider").Duplicate() is ColorRect hostPortDivider && - moddingNode.Duplicate() is MarginContainer hostPort && - hostPort.GetNode("Label") is MegaRichTextLabel hostPortLabel) + var hostPortDivider = (ColorRect)__instance.GetNode("%ModdingDivider").Duplicate(); + hostPortDivider.Name = "HostPortDivider"; + hostPortDivider.Visible = true; + vBoxContainerNode.AddChildSafely(hostPortDivider); + vBoxContainerNode.MoveChild(hostPortDivider, moddingNode.GetIndex() + 1); + + var hostPort = (MarginContainer)moddingNode.Duplicate(); + hostPort.Name = "HostPort"; + hostPort.RemoveChildSafely(hostPort.GetNode("ModdingButton")); + hostPort.Visible = true; + + var hostPortLineEdit = new SpinBox { - hostPortDivider.Name = "HostPortDivider"; + Name = "HostPortInput", CustomMinimumSize = new Vector2(324, 64), + SizeFlagsHorizontal = Control.SizeFlags.ShrinkEnd, Step = 1, MinValue = 0, MaxValue = 65535 + }; - vBoxContainerNode.AddChild(hostPortDivider); - vBoxContainerNode.MoveChild(hostPortDivider, moddingNode.GetIndex() + 1); + hostPortLineEdit.GetLineEdit().Alignment = HorizontalAlignment.Center; + hostPort.AddChildSafely(hostPortLineEdit); - hostPortDivider.Show(); + hostPortLineEdit.Value = SettingsService.Instance.SettingsModel.HostPort; + hostPortLineEdit.ValueChanged += value => + { + SettingsService.Instance.SettingsModel.HostPort = (ushort)value; + SettingsService.Instance.WriteSettings(); + }; - hostPort.Name = "HostPort"; + vBoxContainerNode.AddChildSafely(hostPort); + vBoxContainerNode.MoveChild(hostPort, hostPortDivider.GetIndex() + 1); - hostPort.RemoveChild(hostPort.GetNode("ModdingButton")); + var hostPortLabel = (MegaRichTextLabel)hostPort.GetNode("Label"); + hostPortLabel.SetTextAutoSize("Host Port"); - vBoxContainerNode.AddChild(hostPort); - vBoxContainerNode.MoveChild(hostPort, hostPortDivider.GetIndex() + 1); + var hostMaxPlayersDivider = (ColorRect)__instance.GetNode("%ModdingDivider").Duplicate(); + hostMaxPlayersDivider.Name = "HostMaxPlayersDivider"; + hostMaxPlayersDivider.Visible = true; + vBoxContainerNode.AddChildSafely(hostMaxPlayersDivider); + vBoxContainerNode.MoveChild(hostMaxPlayersDivider, moddingNode.GetIndex() + 1); - hostPort.Show(); + var hostMaxPlayers = (MarginContainer)moddingNode.Duplicate(); + hostMaxPlayers.Name = "HostMaxPlayers"; + hostMaxPlayers.RemoveChildSafely(hostMaxPlayers.GetNode("ModdingButton")); + hostMaxPlayers.Visible = true; - var hostPortLineEdit = new SpinBox { Name = "HostPortInput" }; - hostPort.AddChild(hostPortLineEdit); + var hostMaxPlayersInput = new SpinBox + { + Name = "HostMaxPlayersInput", CustomMinimumSize = new Vector2(324, 64), + SizeFlagsHorizontal = Control.SizeFlags.ShrinkEnd, Step = 1, MinValue = 2, + }; - hostPortLineEdit.CustomMinimumSize = new Vector2(324, 64); - hostPortLineEdit.SizeFlagsHorizontal = Control.SizeFlags.ShrinkEnd; - hostPortLineEdit.GetLineEdit().Alignment = HorizontalAlignment.Center; + hostMaxPlayersInput.GetLineEdit().Alignment = HorizontalAlignment.Center; + hostMaxPlayers.AddChildSafely(hostMaxPlayersInput); - hostPortLineEdit.Step = 1; - hostPortLineEdit.MinValue = 0; - hostPortLineEdit.MaxValue = 65535; - hostPortLineEdit.Value = SettingsService.Instance.SettingsModel.HostPort; - hostPortLineEdit.ValueChanged += value => + hostMaxPlayersInput.Value = SettingsService.Instance.SettingsModel.HostMaxPlayers; + hostMaxPlayersInput.ValueChanged += value => + { + SettingsService.Instance.SettingsModel.HostMaxPlayers = (int)value; + SettingsService.Instance.WriteSettings(); + }; + + vBoxContainerNode.AddChildSafely(hostMaxPlayers); + vBoxContainerNode.MoveChild(hostMaxPlayers, hostMaxPlayersDivider.GetIndex() + 1); + + var hostMaxPlayersLabel = (MegaRichTextLabel)hostMaxPlayers.GetNode("Label"); + hostMaxPlayersLabel.SetTextAutoSize("Host Max Players"); + + var playerNameDivider = (ColorRect)__instance.GetNode("%ModdingDivider").Duplicate(); + playerNameDivider.Name = "PlayerNameDivider"; + playerNameDivider.Visible = true; + vBoxContainerNode.AddChildSafely(playerNameDivider); + vBoxContainerNode.MoveChild(playerNameDivider, moddingNode.GetIndex() + 1); + + var playerName = (MarginContainer)moddingNode.Duplicate(); + playerName.Name = "PlayerName"; + playerName.RemoveChildSafely(playerName.GetNode("ModdingButton")); + playerName.Visible = true; + + var marginContainer = new MarginContainer(); + playerName.AddChildSafely(marginContainer); + + marginContainer.AddThemeConstantOverride("margin_right", 18); + + var playerNameInput = new PlayerNameLineEdit + { + Name = "PlayerNameInput", CustomMinimumSize = new Vector2(308, 64), + SizeFlagsHorizontal = Control.SizeFlags.ShrinkEnd, Alignment = HorizontalAlignment.Center, + MaxLength = 16 + }; + + marginContainer.AddChildSafely(playerNameInput); + + playerNameInput.Text = SettingsService.Instance.SettingsModel.PlayerName; + playerNameInput.TextChanged += value => + { + if (playerNameInput.IsEmpty || !playerNameInput.IsInvalid) { - SettingsService.Instance.SettingsModel.HostPort = (ushort)value; + SettingsService.Instance.SettingsModel.PlayerName = value; + LanPlayerNameService.Instance.SetHostPlayerName(); SettingsService.Instance.WriteSettings(); - }; + } + }; - hostPortLabel.Text = "Host Port"; - } + vBoxContainerNode.AddChildSafely(playerName); + vBoxContainerNode.MoveChild(playerName, playerNameDivider.GetIndex() + 1); - if (__instance.GetNode("%ModdingDivider").Duplicate() is ColorRect hostMaxPlayersDivider && - moddingNode.Duplicate() is MarginContainer hostMaxPlayers && - hostMaxPlayers.GetNode("Label") is MegaRichTextLabel hostMaxPlayersLabel) + var playerNameLabel = (MegaRichTextLabel)playerName.GetNode("Label"); + playerNameLabel.SetTextAutoSize("Player Name"); + + var netIdDivider = (ColorRect)__instance.GetNode("%ModdingDivider").Duplicate(); + netIdDivider.Name = "NetIDDivider"; + netIdDivider.Visible = true; + vBoxContainerNode.AddChildSafely(netIdDivider); + vBoxContainerNode.MoveChild(netIdDivider, moddingNode.GetIndex() + 1); + + var netId = (MarginContainer)moddingNode.Duplicate(); + netId.Name = "NetID"; + netId.RemoveChildSafely(netId.GetNode("ModdingButton")); + netId.Visible = true; + + var netIdInput = new SpinBox { - hostMaxPlayersDivider.Name = "HostMaxPlayersDivider"; + Name = "NetIDInput", CustomMinimumSize = new Vector2(324, 64), + SizeFlagsHorizontal = Control.SizeFlags.ShrinkEnd, Step = 1, MinValue = 2, MaxValue = ulong.MaxValue + }; - vBoxContainerNode.AddChild(hostMaxPlayersDivider); - vBoxContainerNode.MoveChild(hostMaxPlayersDivider, moddingNode.GetIndex() + 1); + netIdInput.GetLineEdit().Alignment = HorizontalAlignment.Center; + netId.AddChildSafely(netIdInput); - hostMaxPlayersDivider.Show(); - - hostMaxPlayers.Name = "HostMaxPlayers"; - - hostMaxPlayers.RemoveChild(hostMaxPlayers.GetNode("ModdingButton")); - - vBoxContainerNode.AddChild(hostMaxPlayers); - vBoxContainerNode.MoveChild(hostMaxPlayers, hostMaxPlayersDivider.GetIndex() + 1); - - hostMaxPlayers.Show(); - - var hostMaxPlayersInput = new SpinBox { Name = "HostMaxPlayersInput" }; - hostMaxPlayers.AddChild(hostMaxPlayersInput); - - hostMaxPlayersInput.CustomMinimumSize = new Vector2(324, 64); - hostMaxPlayersInput.SizeFlagsHorizontal = Control.SizeFlags.ShrinkEnd; - hostMaxPlayersInput.GetLineEdit().Alignment = HorizontalAlignment.Center; - - hostMaxPlayersInput.Step = 1; - hostMaxPlayersInput.MinValue = 2; - hostMaxPlayersInput.Value = SettingsService.Instance.SettingsModel.HostMaxPlayers; - hostMaxPlayersInput.ValueChanged += value => - { - SettingsService.Instance.SettingsModel.HostMaxPlayers = (int)value; - SettingsService.Instance.WriteSettings(); - }; - - hostMaxPlayersLabel.Text = "Host Max Players"; - } - - if (__instance.GetNode("%ModdingDivider").Duplicate() is ColorRect playerNameDivider && - moddingNode.Duplicate() is MarginContainer playerName && - playerName.GetNode("Label") is MegaRichTextLabel playerNameLabel) + netIdInput.Value = SettingsService.Instance.SettingsModel.NetId; + netIdInput.ValueChanged += value => { - playerNameDivider.Name = "PlayerNameDivider"; + SettingsService.Instance.SettingsModel.NetId = (ulong)value; + SettingsService.Instance.WriteSettings(); + }; - vBoxContainerNode.AddChild(playerNameDivider); - vBoxContainerNode.MoveChild(playerNameDivider, moddingNode.GetIndex() + 1); + var netIdLabel = (MegaRichTextLabel)netId.GetNode("Label"); + netIdLabel.SetTextAutoSize("NetID"); - playerNameDivider.Show(); + vBoxContainerNode.AddChildSafely(netId); + vBoxContainerNode.MoveChild(netId, netIdDivider.GetIndex() + 1); - playerName.Name = "PlayerName"; - - playerName.RemoveChild(playerName.GetNode("ModdingButton")); - - vBoxContainerNode.AddChild(playerName); - vBoxContainerNode.MoveChild(playerName, playerNameDivider.GetIndex() + 1); - - playerName.Show(); - - var marginContainer = new MarginContainer(); - playerName.AddChild(marginContainer); - - marginContainer.AddThemeConstantOverride("margin_right", 18); - - var playerNameInput = new PlayerNameLineEdit { Name = "PlayerNameInput" }; - marginContainer.AddChild(playerNameInput); - - playerNameInput.CustomMinimumSize = new Vector2(308, 64); - playerNameInput.SizeFlagsHorizontal = Control.SizeFlags.ShrinkEnd; - playerNameInput.Alignment = HorizontalAlignment.Center; - - playerNameInput.MaxLength = 16; - playerNameInput.Text = SettingsService.Instance.SettingsModel.PlayerName; - playerNameInput.TextChanged += value => - { - if (playerNameInput.IsEmpty || !playerNameInput.IsInvalid) - { - SettingsService.Instance.SettingsModel.PlayerName = value; - LanPlayerNameService.Instance.SetHostPlayerName(); - SettingsService.Instance.WriteSettings(); - } - }; - - playerNameLabel.Text = "Player Name"; - } - - if (__instance.GetNode("%ModdingDivider").Duplicate() is ColorRect netIdDivider && - moddingNode.Duplicate() is MarginContainer netId && - netId.GetNode("Label") is MegaRichTextLabel netIdLabel) - { - netIdDivider.Name = "NetIDDivider"; - - vBoxContainerNode.AddChild(netIdDivider); - vBoxContainerNode.MoveChild(netIdDivider, moddingNode.GetIndex() + 1); - - netIdDivider.Show(); - - netId.Name = "NetID"; - - netId.RemoveChild(netId.GetNode("ModdingButton")); - - vBoxContainerNode.AddChild(netId); - vBoxContainerNode.MoveChild(netId, netIdDivider.GetIndex() + 1); - - netId.Show(); - - var netIdInput = new SpinBox { Name = "NetIDInput" }; - netId.AddChild(netIdInput); - - netIdInput.CustomMinimumSize = new Vector2(324, 64); - netIdInput.SizeFlagsHorizontal = Control.SizeFlags.ShrinkEnd; - netIdInput.GetLineEdit().Alignment = HorizontalAlignment.Center; - - netIdInput.Step = 1; - netIdInput.MinValue = 2; - netIdInput.MaxValue = ulong.MaxValue; - netIdInput.Value = SettingsService.Instance.SettingsModel.NetId; - netIdInput.ValueChanged += value => - { - SettingsService.Instance.SettingsModel.NetId = (ulong)value; - SettingsService.Instance.WriteSettings(); - }; - - netIdLabel.Text = "NetID"; - } - - if (generalSettings is NSettingsPanel nSettingsPanel) - { - RefreshSize(nSettingsPanel); - } + var generalSettings = (NSettingsPanel)vBoxContainerNode.GetParent(); + RefreshSize(generalSettings); } } diff --git a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NTreasureRoomRelicCollectionPatch.cs b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NTreasureRoomRelicCollectionPatch.cs index 538d99b..94276a1 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NTreasureRoomRelicCollectionPatch.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/NTreasureRoomRelicCollectionPatch.cs @@ -25,13 +25,9 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens for (var i = 4; i < runState.Players.Count; i++) { - var newMultiplayerRelicHolder = multiplayerRelicHolder.Duplicate(); - container.AddChild(newMultiplayerRelicHolder); - - if (newMultiplayerRelicHolder is NTreasureRoomRelicHolder nTreasureRoomRelicHolder) - { - nTreasureRoomRelicHolder.Name = $"MultiplayerRelicHolder{i + 1}"; - } + var nTreasureRoomRelicHolder = (NTreasureRoomRelicHolder)multiplayerRelicHolder.Duplicate(); + nTreasureRoomRelicHolder.Name = $"MultiplayerRelicHolder{i + 1}"; + container.AddChildSafely(nTreasureRoomRelicHolder); } } } @@ -41,45 +37,31 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens { if (____multiplayerHolders.Count > 4) { - var container = __instance.GetNode("Container"); + var gridContainer = new GridContainer + { Name = "RelicContainer", Columns = 4, CustomMinimumSize = new Vector2(0, 469) }; - var scrollContainer = new NScrollableContainer { Name = "ScrollableContainer" }; - - var mask = new TextureRect { Name = "Mask" }; - scrollContainer.AddChild(mask); - - mask.ClipContents = true; + gridContainer.AddThemeConstantOverride("h_separation", 42); + gridContainer.AddThemeConstantOverride("v_separation", 42); + gridContainer.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.TopWide); var viewport = new Control { Name = "Viewport" }; - mask.AddChild(viewport); - - var gridContainer = new GridContainer { Name = "RelicContainer" }; - viewport.AddChild(gridContainer); - - var scrollbar = PreloadManager.Cache.GetScene(SceneHelper.GetScenePath("ui/scrollbar")) - .Instantiate(); - scrollContainer.AddChild(scrollbar); - - container.AddChild(scrollContainer); - - scrollContainer.SetAnchorsPreset(Control.LayoutPreset.FullRect); - scrollContainer.OffsetLeft = -510; - scrollContainer.OffsetTop = -250; - scrollContainer.OffsetRight = 510; - scrollContainer.OffsetBottom = 250; - - mask.SetAnchorsPreset(Control.LayoutPreset.CenterTop); - mask.OffsetLeft = -450; - mask.OffsetTop = 250; - mask.OffsetRight = 450; - mask.OffsetBottom = 830; - + viewport.AddChildSafely(gridContainer); viewport.SetAnchorsPreset(Control.LayoutPreset.TopWide); viewport.OffsetLeft = 110; viewport.OffsetTop = 110; viewport.OffsetRight = -120; viewport.OffsetBottom = 580; + var mask = new TextureRect { Name = "Mask", ClipContents = true }; + mask.AddChildSafely(viewport); + mask.SetAnchorsPreset(Control.LayoutPreset.CenterTop); + mask.OffsetLeft = -450; + mask.OffsetTop = 250; + mask.OffsetRight = 450; + mask.OffsetBottom = 830; + + var scrollbar = PreloadManager.Cache.GetScene(SceneHelper.GetScenePath("ui/scrollbar")) + .Instantiate(); scrollbar.AnchorLeft = 0.794f; scrollbar.AnchorTop = 0.187f; scrollbar.AnchorRight = 0.818f; @@ -89,13 +71,18 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens scrollbar.OffsetRight = -199; scrollbar.OffsetBottom = -163; - gridContainer.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.TopWide); + var scrollContainer = new NScrollableContainer { Name = "ScrollableContainer" }; + scrollContainer.AddChildSafely(mask); + scrollContainer.AddChildSafely(scrollbar); - gridContainer.Columns = 4; - gridContainer.CustomMinimumSize = new Vector2(0, 469); + scrollContainer.SetAnchorsPreset(Control.LayoutPreset.FullRect); + scrollContainer.OffsetLeft = -510; + scrollContainer.OffsetTop = -250; + scrollContainer.OffsetRight = 510; + scrollContainer.OffsetBottom = 250; - gridContainer.AddThemeConstantOverride("h_separation", 42); - gridContainer.AddThemeConstantOverride("v_separation", 42); + var container = __instance.GetNode("Container"); + container.AddChildSafely(scrollContainer); scrollContainer.SetContent(gridContainer, 20, 30); diff --git a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/RunScreenPatchs.cs b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/RunScreenPatchs.cs index aa265c9..5c168c6 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/RunScreenPatchs.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Patchs/Screens/RunScreenPatchs.cs @@ -1,5 +1,6 @@ using System.Reflection; using HarmonyLib; +using MegaCrit.Sts2.Core.Helpers; using MegaCrit.Sts2.Core.Multiplayer.Game; using MegaCrit.Sts2.Core.Nodes.Screens.CharacterSelect; using MegaCrit.Sts2.Core.Nodes.Screens.CustomRun; @@ -30,10 +31,8 @@ namespace SlayTheSpire2.LAN.Multiplayer.Patchs.Screens { var ipAddressInfoPanel = IPAddressInfoPanel.Create(); ipAddressInfoPanel.Name = "IPAddressPanel"; - - __instance.AddChild(ipAddressInfoPanel); - ipAddressInfoPanel.Visible = false; + __instance.AddChildSafely(ipAddressInfoPanel); } } diff --git a/SlayTheSpire2.LAN.Multiplayer/Services/RunScreenService.cs b/SlayTheSpire2.LAN.Multiplayer/Services/RunScreenService.cs index 2af9c01..f173530 100644 --- a/SlayTheSpire2.LAN.Multiplayer/Services/RunScreenService.cs +++ b/SlayTheSpire2.LAN.Multiplayer/Services/RunScreenService.cs @@ -46,15 +46,13 @@ namespace SlayTheSpire2.LAN.Multiplayer.Services NModalContainer.Instance?.Add(nGenericPopup); var nVerticalPopup = Traverse.Create(nGenericPopup).Field("_verticalPopup").GetValue(); - + nVerticalPopup.YesButton.Visible = false; nVerticalPopup.NoButton.SetAnchorsPreset(Control.LayoutPreset.CenterBottom); nVerticalPopup.NoButton.OffsetLeft = -90; nVerticalPopup.NoButton.OffsetTop = -152; nVerticalPopup.NoButton.OffsetRight = 90; nVerticalPopup.NoButton.OffsetBottom = -80; - nVerticalPopup.YesButton.Visible = false; - await nGenericPopup.WaitForConfirmation(locString, new LocString("gameplay_ui", "CONFIRM_LOAD_SAVE.header"), new LocString("gameplay_ui", "CONFIRM_LOAD_SAVE.cancel"),