Skip to content

Commit

Permalink
Sync OnFillNecessaryButtonClick
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Sep 5, 2024
1 parent 99df583 commit 96d3044
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#region

using HarmonyLib;
using NebulaModel.Packets.Logistics;
using NebulaModel.Packets.Logistics.ControlPanel;
using NebulaWorld;
using UnityEngine;

#endregion

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#region

using HarmonyLib;
using NebulaModel.Packets.Logistics;
using NebulaModel.Packets.Logistics.ControlPanel;
using NebulaWorld;
using UnityEngine;

#endregion

Expand Down Expand Up @@ -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;
}
}
60 changes: 58 additions & 2 deletions NebulaPatcher/Patches/Dynamic/UIControlPanelStationEntry_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#region

using HarmonyLib;
using NebulaModel.Packets.Logistics;
using NebulaModel.Packets.Logistics.ControlPanel;
using NebulaWorld;
using UnityEngine;

#endregion

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 96d3044

Please sign in to comment.