-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync UIBeltWindow.OnReverseButtonClick
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace NebulaModel.Packets.Factory.Belt | ||
{ | ||
public class BeltReversePacket | ||
{ | ||
public int BeltId { get; set; } | ||
public int PlanetId { get; set; } | ||
|
||
public BeltReversePacket() { } | ||
public BeltReversePacket(int beltId, int planetId) | ||
{ | ||
BeltId = beltId; | ||
PlanetId = planetId; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
NebulaNetwork/PacketProcessors/Factory/Belt/BeltReverseProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using NebulaAPI; | ||
using NebulaModel.Packets.Factory.Belt; | ||
|
||
namespace NebulaNetwork.PacketProcessors.Factory.Belt | ||
{ | ||
[RegisterPacketProcessor] | ||
internal class BeltReverseProcessor : BasePacketProcessor<BeltReversePacket> | ||
{ | ||
public override void ProcessPacket(BeltReversePacket packet, INebulaConnection conn) | ||
{ | ||
PlanetFactory factory = GameMain.galaxy.PlanetById(packet.PlanetId).factory; | ||
if (factory == null) | ||
return; | ||
|
||
using (NebulaModAPI.MultiplayerSession.Factories.IsIncomingRequest.On()) | ||
{ | ||
NebulaModAPI.MultiplayerSession.Factories.EventFactory = factory; | ||
NebulaModAPI.MultiplayerSession.Factories.TargetPlanet = packet.PlanetId; | ||
if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsHost) | ||
{ | ||
// Load planet model | ||
NebulaModAPI.MultiplayerSession.Factories.AddPlanetTimer(packet.PlanetId); | ||
} | ||
|
||
UIBeltWindow beltWindow = UIRoot.instance.uiGame.beltWindow; | ||
beltWindow._Close(); // close the window first to avoid changing unwant variable when setting beltId | ||
PlanetFactory tmpFactory = beltWindow.factory; | ||
int tmpBeltId = beltWindow.beltId; | ||
beltWindow.factory = factory; | ||
beltWindow.beltId = packet.BeltId; | ||
beltWindow.OnReverseButtonClick(0); | ||
beltWindow.factory = tmpFactory; | ||
beltWindow.beltId = tmpBeltId; | ||
|
||
NebulaModAPI.MultiplayerSession.Factories.EventFactory = null; | ||
NebulaModAPI.MultiplayerSession.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using HarmonyLib; | ||
using NebulaModel.Packets.Factory.Belt; | ||
using NebulaWorld; | ||
|
||
namespace NebulaPatcher.Patches.Dynamic | ||
{ | ||
[HarmonyPatch(typeof(UIBeltWindow))] | ||
internal class UIBeltWindow_Patch | ||
{ | ||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(UIBeltWindow), nameof(UIBeltWindow.OnReverseButtonClick))] | ||
public static void OnReverseButtonClick_Postfix(UIBeltWindow __instance) | ||
{ | ||
// Notify others about belt direction reverse | ||
if (Multiplayer.IsActive && !Multiplayer.Session.Factories.IsIncomingRequest.Value) | ||
{ | ||
Multiplayer.Session.Network.SendPacketToLocalStar(new BeltReversePacket(__instance.beltId, __instance.factory.planetId)); | ||
} | ||
} | ||
} | ||
} |