-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #718 from starfi5h/pr-wip
Sync extra texts in production statistics panel
- Loading branch information
Showing
11 changed files
with
370 additions
and
33 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
NebulaModel/Packets/Statistics/StatisticsExtraDataPacket.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,15 @@ | ||
namespace NebulaModel.Packets.Statistics; | ||
|
||
public class StatisticsExtraDataPacket | ||
{ | ||
public StatisticsExtraDataPacket() { } | ||
|
||
public StatisticsExtraDataPacket(int factoryCount, byte[] binaryData) | ||
{ | ||
FactoryCount = factoryCount; | ||
BinaryData = binaryData; | ||
} | ||
|
||
public int FactoryCount { get; set; } | ||
public byte[] BinaryData { get; set; } | ||
} |
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
61 changes: 61 additions & 0 deletions
61
NebulaNetwork/PacketProcessors/Statistics/StatisticsExtraDataProcessor.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,61 @@ | ||
#region | ||
|
||
using System.IO; | ||
using NebulaAPI.Packets; | ||
using NebulaModel.Networking; | ||
using NebulaModel.Packets; | ||
using NebulaModel.Packets.Statistics; | ||
using NebulaWorld; | ||
|
||
#endregion | ||
|
||
namespace NebulaNetwork.PacketProcessors.Statistics; | ||
|
||
[RegisterPacketProcessor] | ||
internal class StatisticsExtraDataProcessor : PacketProcessor<StatisticsExtraDataPacket> | ||
{ | ||
protected override void ProcessPacket(StatisticsExtraDataPacket packet, NebulaConnection conn) | ||
{ | ||
using var reader = new BinaryUtils.Reader(packet.BinaryData); | ||
ImportExtension(reader.BinaryReader, packet.FactoryCount); | ||
} | ||
|
||
static void ImportExtension(BinaryReader reader, int factoryCount) | ||
{ | ||
var factoryStatPool = GameMain.data.statistics.production.factoryStatPool; | ||
for (var i = 0; i < factoryCount; i++) | ||
{ | ||
var factoryIndex = reader.ReadInt32(); | ||
if (factoryIndex >= factoryStatPool.Length) return; // Abort if factoryProductionStat hasn't imported yet | ||
var factoryProductionStat = factoryStatPool[factoryIndex]; | ||
ImportProductStatExtension(reader, factoryProductionStat); | ||
} | ||
} | ||
|
||
static void ImportProductStatExtension(BinaryReader reader, FactoryProductionStat factoryProductionStat) | ||
{ | ||
var productCursor = reader.ReadInt32(); | ||
for (var i = 1; i < productCursor; i++) | ||
{ | ||
var itemId = reader.ReadInt32(); | ||
var refProductSpeed = reader.ReadSingle(); | ||
var refConsumeSpeed = reader.ReadSingle(); | ||
var storageCount = reader.ReadInt64(); | ||
var trashCount = reader.ReadInt64(); | ||
var importStorageCount = reader.ReadInt64(); | ||
var exportStorageCount = reader.ReadInt64(); | ||
|
||
if (factoryProductionStat == null) continue; | ||
var index = factoryProductionStat.productIndices[itemId]; | ||
if (index == 0) continue; | ||
|
||
var product = factoryProductionStat.productPool[index]; | ||
product.refProductSpeed = refProductSpeed; | ||
product.refConsumeSpeed = refConsumeSpeed; | ||
product.storageCount = storageCount; | ||
product.trashCount = trashCount; | ||
product.importStorageCount = importStorageCount; | ||
product.exportStorageCount = exportStorageCount; | ||
} | ||
} | ||
} |
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
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
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
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,37 @@ | ||
#region | ||
|
||
using HarmonyLib; | ||
using NebulaModel.Packets.Statistics; | ||
using NebulaWorld; | ||
|
||
#endregion | ||
|
||
namespace NebulaPatcher.Patches.Dynamic; | ||
|
||
[HarmonyPatch(typeof(UIProductEntry))] | ||
internal class UIProductEntry_Patch | ||
{ | ||
[HarmonyPrefix] | ||
[HarmonyPatch(nameof(UIProductEntry.OnRefreshRefSpeedClick))] | ||
[HarmonyPatch(nameof(UIProductEntry.OnRefreshStorageCountClick))] | ||
public static void OnRefreshClick_Postfix() | ||
{ | ||
if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) | ||
{ | ||
return; | ||
} | ||
|
||
// When client left-click the refresh button, request the extra data from server | ||
var astroFilter = UIRoot.instance.uiGame.statWindow.astroFilter; | ||
if (astroFilter == 0) | ||
{ | ||
if (GameMain.localPlanet != null) return; | ||
astroFilter = GameMain.localStar?.id ?? 0; | ||
} | ||
else if (GameMain.localPlanet != null && GameMain.localPlanet.astroId == astroFilter) | ||
{ | ||
return; // For local planet, use the local calculation | ||
} | ||
Multiplayer.Session.Network.SendPacket(new StatisticsRequestEvent(StatisticEvent.AstroFilterChanged, astroFilter)); | ||
} | ||
} |
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
Oops, something went wrong.