Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor StationUIManager (0.9.24) #513

Merged
merged 8 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions NebulaModel/Packets/Logistics/RemoteOrderUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace NebulaModel.Packets.Logistics
{
public class RemoteOrderUpdate
{
public int StationGId { get; set; }
public int[] RemoteOrder { get; set; }

public RemoteOrderUpdate() { }
public RemoteOrderUpdate(int stationGid, int[] remoteOrder)
{
StationGId = stationGid;
RemoteOrder = remoteOrder;
}
}
}
18 changes: 0 additions & 18 deletions NebulaModel/Packets/Logistics/StationSubscribeUIUpdates.cs

This file was deleted.

42 changes: 4 additions & 38 deletions NebulaModel/Packets/Logistics/StationUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class StationUI
{
public enum EUISettings
{
None,
MaxChargePower,
MaxTripDrones,
MaxTripVessel,
Expand All @@ -15,62 +16,27 @@ public enum EUISettings
SetDroneCount,
SetShipCount,
SetWarperCount,
AddOrRemoveItemFromStorageRequest,
AddOrRemoveItemFromStorageResponse
PilerCount,
MaxMiningSpeed
}

public int PlanetId { get; set; }
public int StationId { get; set; }
public int StationGId { get; set; }
public bool IsStorageUI { get; set; }
public StationUI.EUISettings SettingIndex { get; set; }
public float SettingValue { get; set; }
public int StorageIdx { get; set; }
public int ItemId { get; set; }
public int ItemCountMax { get; set; }
public ELogisticStorage LocalLogic { get; set; }
public ELogisticStorage RemoteLogic { get; set; }
public bool ShouldMimic { get; set; }
public bool WarperShouldTakeFromStorage { get; set; }
public bool ShouldRefund { get; set; }

public StationUI() { }
public StationUI(int planetId, int stationId, int stationGId, int storageIdx, int itemId, int itemCountMax, ELogisticStorage localLogic, ELogisticStorage remoteLogic)
{
IsStorageUI = true;
ShouldMimic = false;
WarperShouldTakeFromStorage = false;

PlanetId = planetId;
StationId = stationId;
StationGId = stationGId;
StorageIdx = storageIdx;
ItemId = itemId;
ItemCountMax = itemCountMax;
LocalLogic = localLogic;
RemoteLogic = remoteLogic;
}
public StationUI(int planetId, int stationId, int stationGId, StationUI.EUISettings settingIndex, float value, bool warperShouldTakeFromStorage = false)
{
IsStorageUI = false;

PlanetId = planetId;
StationId = stationId;
StationGId = stationGId;
SettingIndex = settingIndex;
SettingValue = value;
WarperShouldTakeFromStorage = warperShouldTakeFromStorage;
}
public StationUI(int planetId, int stationId, int stationGId, int storageIdx, StationUI.EUISettings settingIndex, int itemId, int settingValue)
{
WarperShouldTakeFromStorage = false;

PlanetId = planetId;
StationId = stationId;
StationGId = stationGId;
StorageIdx = storageIdx;
SettingIndex = settingIndex;
ItemId = itemId;
SettingValue = settingValue;
}
}
}
6 changes: 6 additions & 0 deletions NebulaModel/Packets/Logistics/StationUIInitialSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public class StationUIInitialSync
public bool IncludeOrbitCollector { get; set; }
public long Energy { get; set; }
public long EnergyPerTick { get; set; }
public int PilerCount { get; set; }
public int[] ItemId { get; set; }
public int[] ItemCountMax { get; set; }
public int[] ItemCount { get; set; }
public int[] ItemInc { get; set; }
public int[] LocalLogic { get; set; }
public int[] RemoteLogic { get; set; }
public int[] RemoteOrder { get; set; }
Expand All @@ -35,9 +37,11 @@ public StationUIInitialSync(
bool includeOrbitCollector,
long energy,
long energyPerTick,
int pilerCount,
int[] itemId,
int[] itemCountMax,
int[] itemCount,
int[] itemInc,
int[] localLogic,
int[] remoteLogic,
int[] remoteOrder
Expand All @@ -55,10 +59,12 @@ int[] remoteOrder
IncludeOrbitCollector = includeOrbitCollector;
Energy = energy;
EnergyPerTick = energyPerTick;
PilerCount = pilerCount;

ItemId = itemId;
ItemCountMax = itemCountMax;
ItemCount = itemCount;
ItemInc = itemInc;
LocalLogic = localLogic;
RemoteLogic = remoteLogic;
RemoteOrder = remoteOrder;
Expand Down
43 changes: 43 additions & 0 deletions NebulaModel/Packets/Logistics/StorageUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace NebulaModel.Packets.Logistics
{
public class StorageUI
{
public int PlanetId { get; set; }
public int StationId { get; set; }
public int StationGId { get; set; }
public int StorageIdx { get; set; }
public int ItemId { get; set; }
public int ItemCountMax { get; set; }
public ELogisticStorage LocalLogic { get; set; }
public ELogisticStorage RemoteLogic { get; set; }
public int ItemCount { get; set; }
public int ItemInc { get; set; }
public bool ShouldRefund { get; set; }

public StorageUI() { }
public StorageUI(int planetId, int stationId, int stationGId, int storageIdx, int itemId, int itemCountMax, ELogisticStorage localLogic, ELogisticStorage remoteLogic)
{
ItemCount = -1; //Indicate it is SetStationStorage()

PlanetId = planetId;
StationId = stationId;
StationGId = stationGId;
StorageIdx = storageIdx;
ItemId = itemId;
ItemCountMax = itemCountMax;
LocalLogic = localLogic;
RemoteLogic = remoteLogic;
}
public StorageUI(int planetId, int stationId, int stationGId, int storageIdx, int itemCount, int itemInc)
{
ShouldRefund = false;

PlanetId = planetId;
StationId = stationId;
StationGId = stationGId;
StorageIdx = storageIdx;
ItemCount = itemCount;
ItemInc = itemInc;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using NebulaAPI;
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.Logistics;
using NebulaWorld;

namespace NebulaNetwork.PacketProcessors.Logistics
{
[RegisterPacketProcessor]
public class RemoteOrderUpdateProcessor : PacketProcessor<RemoteOrderUpdate>
{
public override void ProcessPacket(RemoteOrderUpdate packet, NebulaConnection conn)
{
if (IsHost)
{
StationComponent stationComponent = GameMain.data.galacticTransport.stationPool[packet.StationGId];
StationStore[] storage = stationComponent?.storage;
if (stationComponent == null || storage == null)
{
return;
}
int[] remoteOrder = new int[storage.Length];
for (int i = 0; i < stationComponent.storage.Length; i++)
{
remoteOrder[i] = storage[i].remoteOrder;
}
packet.RemoteOrder = remoteOrder;
conn.SendPacket(packet);
}
if (IsClient)
{
StationComponent stationComponent = GameMain.data.galacticTransport.stationPool[packet.StationGId];
StationStore[] storage = stationComponent?.storage;
if (stationComponent == null || storage == null)
{
return;
}
for (int i = 0; i < storage.Length; i++)
{
storage[i].remoteOrder = packet.RemoteOrder[i];
}
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
/*
* When the client opens the UI of a station (ILS/PLS/Collector) the contents gets updated and shown to
* the player once this packet is received. He will see a loading text before that.
* This will also subscribe to live updates syncing changes made by other players to the station while the UI is opened
*/
namespace NebulaNetwork.PacketProcessors.Logistics
{
Expand All @@ -29,47 +28,38 @@ public override void ProcessPacket(StationUIInitialSync packet, NebulaConnection
return;
}

if (Multiplayer.Session.StationsUI.UIIsSyncedStage == 1)
{
UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;

stationComponent.tripRangeDrones = packet.TripRangeDrones;
stationComponent.tripRangeShips = packet.TripRangeShips;
stationComponent.deliveryDrones = packet.DeliveryDrones;
stationComponent.deliveryShips = packet.DeliveryShips;
stationComponent.warpEnableDist = packet.WarperEnableDistance;
stationComponent.warperNecessary = packet.WarperNecessary;
stationComponent.includeOrbitCollector = packet.IncludeOrbitCollector;
stationComponent.energy = packet.Energy;
stationComponent.energyPerTick = packet.EnergyPerTick;
stationComponent.tripRangeDrones = packet.TripRangeDrones;
stationComponent.tripRangeShips = packet.TripRangeShips;
stationComponent.deliveryDrones = packet.DeliveryDrones;
stationComponent.deliveryShips = packet.DeliveryShips;
stationComponent.warpEnableDist = packet.WarperEnableDistance;
stationComponent.warperNecessary = packet.WarperNecessary;
stationComponent.includeOrbitCollector = packet.IncludeOrbitCollector;
stationComponent.energy = packet.Energy;
stationComponent.energyPerTick = packet.EnergyPerTick;
stationComponent.pilerCount = packet.PilerCount;

for (int i = 0; i < packet.ItemId.Length; i++)
for (int i = 0; i < packet.ItemId.Length; i++)
{
if (stationComponent.storage == null)
{
if (stationComponent.storage == null)
{
stationComponent.storage = new StationStore[packet.ItemId.Length];
}

stationComponent.storage[i].itemId = packet.ItemId[i];
stationComponent.storage[i].max = packet.ItemCountMax[i];
stationComponent.storage[i].count = packet.ItemCount[i];
stationComponent.storage[i].remoteOrder = packet.RemoteOrder[i];
stationComponent.storage[i].localLogic = (ELogisticStorage)packet.LocalLogic[i];
stationComponent.storage[i].remoteLogic = (ELogisticStorage)packet.RemoteLogic[i];
stationComponent.storage = new StationStore[packet.ItemId.Length];
}

if (stationWindow != null && stationWindow.active)
{
conn.SendPacket(new StationSubscribeUIUpdates(true, stationComponent.planetId, stationComponent.id, stationComponent.gid));
Multiplayer.Session.StationsUI.UIIsSyncedStage++;
stationWindow._Free();
stationWindow._Init(stationComponent);
stationWindow._stationId = stationComponent.id;
stationWindow._Open();
stationWindow._Update();
}
stationComponent.storage[i].itemId = packet.ItemId[i];
stationComponent.storage[i].max = packet.ItemCountMax[i];
stationComponent.storage[i].count = packet.ItemCount[i];
stationComponent.storage[i].inc = packet.ItemInc[i];
stationComponent.storage[i].remoteOrder = packet.RemoteOrder[i];
stationComponent.storage[i].localLogic = (ELogisticStorage)packet.LocalLogic[i];
stationComponent.storage[i].remoteLogic = (ELogisticStorage)packet.RemoteLogic[i];
}

Multiplayer.Session.StationsUI.UIStationId = stationComponent.id;
UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;
if (stationWindow.active && stationWindow.factory?.planetId == packet.PlanetId && stationWindow.stationId == packet.StationId)
{
//Trigger OnStationIdChange() to refresh window
stationWindow.OnStationIdChange();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void ProcessPacket(StationUIInitialSyncRequest packet, NebulaCon
return;
}

StationComponent stationComponent = null;
StationComponent stationComponent;
StationComponent[] gStationPool = GameMain.data.galacticTransport.stationPool;
StationComponent[] stationPool = GameMain.data.galaxy?.PlanetById(packet.PlanetId)?.factory?.transport?.stationPool;

Expand All @@ -37,6 +37,7 @@ public override void ProcessPacket(StationUIInitialSyncRequest packet, NebulaCon
int[] itemId = new int[storage.Length];
int[] itemCountMax = new int[storage.Length];
int[] itemCount = new int[storage.Length];
int[] itemInc = new int[storage.Length];
int[] localLogic = new int[storage.Length];
int[] remoteLogic = new int[storage.Length];
int[] remoteOrder = new int[storage.Length];
Expand All @@ -46,6 +47,7 @@ public override void ProcessPacket(StationUIInitialSyncRequest packet, NebulaCon
itemId[i] = storage[i].itemId;
itemCountMax[i] = storage[i].max;
itemCount[i] = storage[i].count;
itemInc[i] = storage[i].inc;
localLogic[i] = (int)storage[i].localLogic;
remoteLogic[i] = (int)storage[i].remoteLogic;
remoteOrder[i] = storage[i].remoteOrder;
Expand All @@ -64,9 +66,11 @@ public override void ProcessPacket(StationUIInitialSyncRequest packet, NebulaCon
stationComponent.includeOrbitCollector,
stationComponent.energy,
stationComponent.energyPerTick,
stationComponent.pilerCount,
itemId,
itemCountMax,
itemCount,
itemInc,
localLogic,
remoteLogic,
remoteOrder
Expand Down
Loading