From 96d3044e124aedba744c2ad265b15dbb0c97090e Mon Sep 17 00:00:00 2001 From: starfish <50672801+starfi5h@users.noreply.github.com> Date: Thu, 5 Sep 2024 04:15:01 +0800 Subject: [PATCH] Sync OnFillNecessaryButtonClick --- .../UIControlPanelAdvancedMinerEntry_Patch.cs | 60 ++++++++++++++++++- .../UIControlPanelDispenserEntry_Patch.cs | 22 ++++++- .../UIControlPanelStationEntry_Patch.cs | 60 ++++++++++++++++++- 3 files changed, 137 insertions(+), 5 deletions(-) diff --git a/NebulaPatcher/Patches/Dynamic/UIControlPanelAdvancedMinerEntry_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIControlPanelAdvancedMinerEntry_Patch.cs index c8b4cc8b2..467b58afa 100644 --- a/NebulaPatcher/Patches/Dynamic/UIControlPanelAdvancedMinerEntry_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIControlPanelAdvancedMinerEntry_Patch.cs @@ -1,8 +1,10 @@ #region using HarmonyLib; +using NebulaModel.Packets.Logistics; using NebulaModel.Packets.Logistics.ControlPanel; using NebulaWorld; +using UnityEngine; #endregion @@ -61,11 +63,65 @@ public static bool IsLocal_Prefix(UIControlPanelAdvancedMinerEntry __instance, r [HarmonyPrefix] [HarmonyPatch(nameof(UIControlPanelAdvancedMinerEntry.OnFillNecessaryButtonClick))] - public static bool OnFillNecessaryButtonClick_Prefix() + public static bool OnFillNecessaryButtonClick_Prefix(UIControlPanelAdvancedMinerEntry __instance) { if (!Multiplayer.IsActive) return true; + if (__instance.factory == null || __instance.station == null) + { + UIRealtimeTip.Popup("Unavailable".Translate()); + return false; + } + + var packet = new StationUI() + { + PlanetId = __instance.factory.planetId, + StationId = __instance.station.id, + StationGId = __instance.station.gid + }; + var text = ""; + if (__instance.station.isStellar) + { + int shortAge, previousCount; + + previousCount = __instance.station.idleDroneCount; + shortAge = __instance.station.workDroneDatas.Length - (__instance.station.idleDroneCount + __instance.station.workDroneCount); + UIControlPanelObjectEntry.ReplenishItems(5001, shortAge, ref __instance.station.idleDroneCount, ref text); + packet.SettingIndex = StationUI.EUISettings.SetDroneCount; + packet.SettingValue = (__instance.station.idleDroneCount + __instance.station.workDroneCount); + Multiplayer.Session.Network.SendPacket(packet); + if (Multiplayer.Session.IsClient) __instance.station.idleDroneCount = previousCount; // Wait for server to authorize - // Temporarily disable fill item button. We will sync in the future + previousCount = __instance.station.idleShipCount; + shortAge = __instance.station.workShipDatas.Length - (__instance.station.idleShipCount + __instance.station.workShipCount); + UIControlPanelObjectEntry.ReplenishItems(5002, shortAge, ref __instance.station.idleShipCount, ref text); + packet.SettingIndex = StationUI.EUISettings.SetShipCount; + packet.SettingValue = (__instance.station.idleShipCount + __instance.station.workShipCount); + Multiplayer.Session.Network.SendPacket(packet); + if (Multiplayer.Session.IsClient) __instance.station.idleShipCount = previousCount; // Wait for server to authorize + + previousCount = __instance.station.warperCount; + shortAge = __instance.station.warperMaxCount - __instance.station.warperCount; + UIControlPanelObjectEntry.ReplenishItems(1210, shortAge, ref __instance.station.warperCount, ref text); + packet.SettingIndex = StationUI.EUISettings.SetWarperCount; + packet.SettingValue = __instance.station.warperCount; + Multiplayer.Session.Network.SendPacket(packet); + if (Multiplayer.Session.IsClient) __instance.station.warperCount = previousCount; // Wait for server to authorize + } + else + { + var previousCount = __instance.station.idleDroneCount; + var shortAge = __instance.station.workDroneDatas.Length - (__instance.station.idleDroneCount + __instance.station.workDroneCount); + UIControlPanelObjectEntry.ReplenishItems(5001, shortAge, ref __instance.station.idleDroneCount, ref text); + packet.SettingIndex = StationUI.EUISettings.SetDroneCount; + packet.SettingValue = (__instance.station.idleDroneCount + __instance.station.workDroneCount); + Multiplayer.Session.Network.SendPacket(packet); + if (Multiplayer.Session.IsClient) __instance.station.idleDroneCount = previousCount; // Wait for server to authorize + } + if (!string.IsNullOrEmpty(text)) + { + UIRealtimeTip.Popup(text, false, 0); + VFAudio.Create("equip-1", GameMain.mainPlayer.transform, Vector3.zero, true, 4, -1, -1L); + } return false; } } diff --git a/NebulaPatcher/Patches/Dynamic/UIControlPanelDispenserEntry_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIControlPanelDispenserEntry_Patch.cs index 01d32d85f..d46e302fe 100644 --- a/NebulaPatcher/Patches/Dynamic/UIControlPanelDispenserEntry_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIControlPanelDispenserEntry_Patch.cs @@ -1,8 +1,10 @@ #region using HarmonyLib; +using NebulaModel.Packets.Logistics; using NebulaModel.Packets.Logistics.ControlPanel; using NebulaWorld; +using UnityEngine; #endregion @@ -63,8 +65,26 @@ public static bool IsLocal_Prefix(UIControlPanelDispenserEntry __instance, ref b public static bool OnFillNecessaryButtonClick_Prefix(UIControlPanelDispenserEntry __instance) { if (!Multiplayer.IsActive) return true; + if (__instance.factory == null || __instance.dispenser == null) + { + UIRealtimeTip.Popup("Unavailable".Translate()); + return false; + } + + var text = ""; + var num = __instance.dispenser.workCourierDatas.Length - (__instance.dispenser.idleCourierCount + __instance.dispenser.workCourierCount); + UIControlPanelObjectEntry.ReplenishItems(5001, num, ref __instance.dispenser.idleCourierCount, ref text); + if (!string.IsNullOrEmpty(text)) + { + UIRealtimeTip.Popup(text, false, 0); + VFAudio.Create("equip-1", GameMain.mainPlayer.transform, Vector3.zero, true, 4, -1, -1L); + } + Multiplayer.Session.Network.SendPacketToLocalStar( + new DispenserSettingPacket(__instance.factory.planetId, + __instance.id, + EDispenserSettingEvent.SetCourierCount, + __instance.dispenser.workCourierCount + __instance.dispenser.idleCourierCount)); - // Temporarily disable fill item button. We will sync in the future return false; } } diff --git a/NebulaPatcher/Patches/Dynamic/UIControlPanelStationEntry_Patch.cs b/NebulaPatcher/Patches/Dynamic/UIControlPanelStationEntry_Patch.cs index 45137bfb7..7c159913d 100644 --- a/NebulaPatcher/Patches/Dynamic/UIControlPanelStationEntry_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/UIControlPanelStationEntry_Patch.cs @@ -1,8 +1,10 @@ #region using HarmonyLib; +using NebulaModel.Packets.Logistics; using NebulaModel.Packets.Logistics.ControlPanel; using NebulaWorld; +using UnityEngine; #endregion @@ -69,11 +71,65 @@ public static bool IsLocal_Prefix(UIControlPanelAdvancedMinerEntry __instance, r [HarmonyPrefix] [HarmonyPatch(nameof(UIControlPanelStationEntry.OnFillNecessaryButtonClick))] - public static bool OnFillNecessaryButtonClick_Prefix() + public static bool OnFillNecessaryButtonClick_Prefix(UIControlPanelStationEntry __instance) { if (!Multiplayer.IsActive) return true; + if (__instance.factory == null || __instance.station == null) + { + UIRealtimeTip.Popup("Unavailable".Translate()); + return false; + } + + var packet = new StationUI() + { + PlanetId = __instance.factory.planetId, + StationId = __instance.station.id, + StationGId = __instance.station.gid + }; + var text = ""; + if (__instance.station.isStellar) + { + int shortAge, previousCount; + + previousCount = __instance.station.idleDroneCount; + shortAge = __instance.station.workDroneDatas.Length - (__instance.station.idleDroneCount + __instance.station.workDroneCount); + UIControlPanelObjectEntry.ReplenishItems(5001, shortAge, ref __instance.station.idleDroneCount, ref text); + packet.SettingIndex = StationUI.EUISettings.SetDroneCount; + packet.SettingValue = (__instance.station.idleDroneCount + __instance.station.workDroneCount); + Multiplayer.Session.Network.SendPacket(packet); + if (Multiplayer.Session.IsClient) __instance.station.idleDroneCount = previousCount; // Wait for server to authorize - // Temporarily disable fill item button. We will sync in the future + previousCount = __instance.station.idleShipCount; + shortAge = __instance.station.workShipDatas.Length - (__instance.station.idleShipCount + __instance.station.workShipCount); + UIControlPanelObjectEntry.ReplenishItems(5002, shortAge, ref __instance.station.idleShipCount, ref text); + packet.SettingIndex = StationUI.EUISettings.SetShipCount; + packet.SettingValue = (__instance.station.idleShipCount + __instance.station.workShipCount); + Multiplayer.Session.Network.SendPacket(packet); + if (Multiplayer.Session.IsClient) __instance.station.idleShipCount = previousCount; // Wait for server to authorize + + previousCount = __instance.station.warperCount; + shortAge = __instance.station.warperMaxCount - __instance.station.warperCount; + UIControlPanelObjectEntry.ReplenishItems(1210, shortAge, ref __instance.station.warperCount, ref text); + packet.SettingIndex = StationUI.EUISettings.SetWarperCount; + packet.SettingValue = __instance.station.warperCount; + Multiplayer.Session.Network.SendPacket(packet); + if (Multiplayer.Session.IsClient) __instance.station.warperCount = previousCount; // Wait for server to authorize + } + else + { + var previousCount = __instance.station.idleDroneCount; + var shortAge = __instance.station.workDroneDatas.Length - (__instance.station.idleDroneCount + __instance.station.workDroneCount); + UIControlPanelObjectEntry.ReplenishItems(5001, shortAge, ref __instance.station.idleDroneCount, ref text); + packet.SettingIndex = StationUI.EUISettings.SetDroneCount; + packet.SettingValue = (__instance.station.idleDroneCount + __instance.station.workDroneCount); + Multiplayer.Session.Network.SendPacket(packet); + if (Multiplayer.Session.IsClient) __instance.station.idleDroneCount = previousCount; // Wait for server to authorize + } + if (!string.IsNullOrEmpty(text)) + { + UIRealtimeTip.Popup(text, false, 0); + VFAudio.Create("equip-1", GameMain.mainPlayer.transform, Vector3.zero, true, 4, -1, -1L); + } return false; } }