-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSystemMonitorWindow.cs
935 lines (847 loc) · 45 KB
/
SystemMonitorWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using FortressCraft.Community.Utilities;
using System.Text;
public class SystemMonitorWindow : BaseMachineWindow
{
public const string InterfaceName = "steveman0.SystemMonitorWindow";
public const string InterfaceNetStatus = "RequestNetStatus";
public const string InterfaceTrackSystems = "RequestTrackSystems";
private bool dirty;
public static bool networkredraw;
private WindowTypes CurrentWindow;
private int SelectedNetwork = 0;
private int SelectedStorage = 0;
private int TrackNetworkDisplay = -1;
private int StationDisplay = -1;
private int CartDisplay = -1;
private int InventoryCount;
private FreightCartStation CurrentStation;
private List<FreightRegistry> Registries;
public static FreightCartManager fcm = FreightCartManager.instance;
private Dictionary<ItemBase, int> FullInventory;
//private int RefreshCounter; //Use this someday to refresh the stock window?
private Vector3 StartPos;
private bool firstopen;
private bool OrderByName = true;
private bool CompactLayout = true;
//Window position offsets
const int globalxoffset = 75; //For window scaling adjustments
const int buttonoffset = 95;
const int buttonspacing = 140;
const int buttonx1 = globalxoffset + buttonoffset - 25;
const int buttonx2 = globalxoffset + buttonoffset + buttonspacing;
const int buttonx3 = globalxoffset + buttonoffset + 2 * buttonspacing;
const int buttonx4 = globalxoffset + buttonoffset + 3 * buttonspacing;
const int buttonx5 = globalxoffset + buttonoffset + 4 * buttonspacing;
const int buttonx6 = globalxoffset + buttonoffset + 5 * buttonspacing + 25;
private enum WindowTypes
{
NetworkStatus,
NetworkSelection,
TrackNetworks,
GlobalInventory,
StorageInventory,
}
#region SpawnWindow
public override void SpawnWindow(SegmentEntity targetEntity)
{
FreightSystemMonitor monitor = targetEntity as FreightSystemMonitor;
//Catch for when the window is called on an inappropriate machine
if (monitor == null)
{
//GenericMachinePanelScript.instance.Hide();
UIManager.RemoveUIRules("Machine");
return;
}
//Debug.LogWarning("first area test fsm");
if (fcm == null)
Debug.LogWarning("Freight cart manager instance is null in System Monitor Window SpawnWindow!!");
if (fcm != null && this.SelectedNetwork >= fcm.Networks.Count)
this.SelectedNetwork = 0;
if (!firstopen)
this.InitializeWindow();
switch (this.CurrentWindow)
{
case WindowTypes.NetworkStatus:
this.SpawnNetworkStatus(monitor);
break;
case WindowTypes.NetworkSelection:
this.SpawnNetworkSelection();
break;
case WindowTypes.TrackNetworks:
this.SpawnTrackNetworks(monitor);
break;
case WindowTypes.GlobalInventory:
this.SpawnGlobalInventory();
break;
case WindowTypes.StorageInventory:
this.SpawnStorageInventory();
break;
}
this.dirty = true;
networkredraw = false;
}
private void InitializeWindow()
{
this.StartPos = GenericMachinePanelScript.instance.gameObject.transform.localPosition;
GenericMachinePanelScript.instance.gameObject.transform.localScale = new Vector3(3.0f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.gameObject.transform.localPosition = this.StartPos + new Vector3(-420f, 0f, 0f);
GenericMachinePanelScript.instance.Background_Panel.transform.localScale = new Vector3(3.0f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Label_Holder.transform.localScale = new Vector3(0.33f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Icon_Holder.transform.localScale = new Vector3(0.33f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Content_Holder.transform.localScale = new Vector3(0.33f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Content_Icon_Holder.transform.localScale = new Vector3(0.33f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Scroll_Bar.transform.localScale = new Vector3(0.33f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Source_Holder.transform.localScale = new Vector3(0.33f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Generic_Machine_Title_Label.transform.localScale = new Vector3(0.33f, 1.0f, 1.0f);
//Bring labels in front of icons
float x = GenericMachinePanelScript.instance.Label_Holder.transform.position.x;
float y = GenericMachinePanelScript.instance.Label_Holder.transform.position.y;
GenericMachinePanelScript.instance.Label_Holder.transform.position = new Vector3(x, y, 69.3f);
GenericMachinePanelScript.instance.Scroll_Bar.GetComponent<UIScrollBar>().scrollValue = 0.0f;
this.firstopen = true;
}
private void SpawnNetworkStatus(FreightSystemMonitor monitor)
{
this.manager.SetTitle("Freight System Status");
this.manager.AddButton("prevnetwork", "Previous Network", buttonx1, 0);
this.manager.AddButton("allnetworks", "Global Inventory", buttonx2, 0);
this.manager.AddButton("selnetwork", "Select Network", buttonx3, 0);
this.manager.AddButton("tracknetworks", "Track Systems", buttonx4, 0);
this.manager.AddButton("viewinventory", "View Inventory", buttonx5, 0);
this.manager.AddButton("nextnetwork", "Next Network", buttonx6, 0);
if (NetworkSync.NetworkStatus == null)
SystemMonitorWindow.RequestNetworkStatus(this.SelectedNetwork, WorldScript.mLocalPlayer, monitor);
if (NetworkSync.NetworkStatus != null)
{
int spacing = 60; //Spacing between each registry line
int count = 0;
int yoffset = 100; //Offset below button row
int col2xoffset = 350 + globalxoffset; //Col 2 offset from the left
int col3xoffset = 125 + col2xoffset; //Col 3 offset from the left
int col4xoffset = 125 + col3xoffset; //Col 3 offset from the left
int col5xoffset = 125 + col4xoffset; //Col 4 offset from the left
//this.Registries = new List<FreightRegistry>();
//this.FullInventory = new Dictionary<ItemBase, int>(new ItemBaseComparer());
//this.Registries = fcm.GetNetworkRegistries(this.SelectedNetwork);
count = NetworkSync.NetworkStatus.Registries.Count;
//Debug.Log("After registeries counting " + count);
this.manager.AddBigLabel("nameofnetworktitle", "Viewing status of freight network: ", Color.cyan, 350, 50);
this.manager.AddBigLabel("nameofnetwork", NetworkSync.NetworkStatus.NetworkID, Color.cyan, 650, 50);
//Debug.Log("Spawning window with network: " + fcm.Networks[this.SelectedNetwork]);
for (int n = 0; n < count; n++)
{
//Debug.Log("Catch error at n = " + n);
this.manager.AddIcon("item" + n, "empty", Color.white, globalxoffset + 40, yoffset + (spacing * n));
this.manager.AddBigLabel("registrytitle" + n, "Registry Item", Color.white, 100 + globalxoffset, yoffset + (spacing * n));
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "deficittitle" + n, "Network Deficit", Color.white, false, col2xoffset, yoffset + (spacing * n));
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "surptitle" + n, "Network Surplus", Color.white, false, col3xoffset, yoffset + (spacing * n));
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "stocktitle" + n, "In Transit", Color.white, false, col4xoffset, yoffset + (spacing * n));
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "invtitle" + n, "Network Inventory", Color.white, false, col5xoffset, yoffset + (spacing * n));
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "deficit" + n, "0", Color.white, false, col2xoffset, yoffset + (spacing * n + 20));
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "surplus" + n, "0", Color.white, false, col3xoffset, yoffset + (spacing * n + 20));
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "stock" + n, "0", Color.white, false, col4xoffset, yoffset + (spacing * n + 20));
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "totalinv" + n, "0", Color.white, false, col5xoffset, yoffset + (spacing * n + 20));
}
}
else if (WorldScript.mbIsServer)
{
this.manager.AddBigLabel("loadingnetworks", "No Freight Networks found...", Color.red, 225, 150);
}
else
{
this.manager.AddBigLabel("loadingnetworks", "Waiting for server...", Color.red, 225, 150);
}
}
private void SpawnNetworkSelection()
{
this.manager.SetTitle("Select Network");
this.manager.AddButton("allnetworks", "Global Inventory", buttonx2, 0);
this.manager.AddButton("selnetwork", "Network Status", buttonx3, 0);
this.manager.AddButton("tracknetworks", "Track Systems", buttonx4, 0);
this.manager.AddButton("viewinventory", "View Inventory", buttonx5, 0);
int spacing = 50; //Spacing between each registry line
int yoffset = 65; //Offset below button row
for (int n = 0; n < fcm.Networks.Count; n++)
{
this.manager.AddButton("networknum" + n, fcm.Networks[n], buttonx3 + 70, yoffset + (n * spacing));
}
}
private void SpawnTrackNetworks(FreightSystemMonitor monitor)
{
this.manager.SetTitle("Track Systems");
this.manager.AddButton("allnetworks", "Global Inventory", buttonx2, 0);
this.manager.AddButton("selnetwork", "Select Network", buttonx3, 0);
this.manager.AddButton("tracknetworks", "Network Status", buttonx4, 0);
this.manager.AddButton("viewinventory", "View Inventory", buttonx5, 0);
int ycursor = 65;
int trackiconx = globalxoffset + 175;
int trackxoffset = trackiconx + 65;
int tracklabel = trackxoffset + 250;
int stationxicon = trackiconx + 50;
int stationlabel = stationxicon + 65;
int cartxicon = stationxicon + 50;
int cartlabel = cartxicon + 65;
int invxicon = cartxicon + 50;
int invlabel = invxicon + 65;
if (NetworkSync.TrackNetworks == null)
SystemMonitorWindow.RequestTrackNetworks(this.TrackNetworkDisplay, this.StationDisplay, this.CartDisplay, WorldScript.mLocalPlayer, monitor);
//int networkcount = FreightCartManager.instance.GlobalTrackNetworks.Count;
if (NetworkSync.TrackNetworks != null && NetworkSync.TrackNetworks.NetworkCount > 0)
{
for (int n = 0; n < NetworkSync.TrackNetworks.NetworkCount; n++)
{
TrackNetworkStats network = NetworkSync.TrackNetworks.NetworkStats[n];
if (network == null)
continue;
this.DisplayTrackNetworks(network, n, ref ycursor, trackiconx, trackxoffset, tracklabel);
if (this.TrackNetworkDisplay == n)
{
List<StationStats> stations = NetworkSync.TrackNetworks.Stations;
for (int m = 0; m < NetworkSync.TrackNetworks.StationCount; m++)
{
StationStats station = NetworkSync.TrackNetworks.Stations[m];
this.DisplayStation(station, m, ref ycursor, stationxicon, stationlabel);
if (this.StationDisplay == m)
{
// How do I network this? ...
//this.manager.AddButton("addcart", "Add Cart", stationlabel + 475, ycursor - 60);
//this.manager.AddButton("removecart", "Remove Cart", stationlabel + 475, ycursor - 10);
//this.CurrentStation = station;
//List<FreightRegistry> LocalDeficits = new List<FreightRegistry>();
//List<FreightRegistry> LocalSurplus = new List<FreightRegistry>();
//if (station.massStorageCrate != null)
//{
// LocalDeficits = FreightCartManager.instance.GetLocalDeficit(station.NetworkID, station.massStorageCrate);
// LocalSurplus = FreightCartManager.instance.GetLocalSurplus(station.NetworkID, station.massStorageCrate);
//}
//else if (station.HopperInterface != null)
//{
// LocalDeficits = this.FreightListingConversion(station.HopperInterface.FreightRequests.OrderByDescending(x => x.Quantity).Take(3).ToList());
// LocalSurplus = this.FreightListingConversion(station.HopperInterface.FreightOfferings.OrderByDescending(x => x.Quantity).Take(3).ToList());
//}
//else if (station.AttachedInterface != null)
//{
// LocalDeficits = this.FreightListingConversion(station.AttachedInterface.FreightRequests.OrderByDescending(x => x.Quantity).Take(3).ToList());
// LocalSurplus = this.FreightListingConversion(station.AttachedInterface.FreightOfferings.OrderByDescending(x => x.Quantity).Take(3).ToList());
//}
this.DisplayDefSur(ref ycursor, stationlabel);
for (int p = 0; p < NetworkSync.TrackNetworks.CartCount; p++)
{
CartStats cart = NetworkSync.TrackNetworks.Carts[p];
this.DisplayCart(cart, p, ref ycursor, cartlabel, cartxicon);
if (p == CartDisplay)
{
this.DisplayCartInventory(cart, ref ycursor, invxicon, invlabel);
}
}
}
}
//Insert Tour cart staion listing here
}
}
}
else if (WorldScript.mbIsServer || (NetworkSync.TrackNetworks != null && NetworkSync.TrackNetworks.NetworkCount == 0))
{
this.manager.AddBigLabel("notracknetworks", "No track networks found...", Color.red, 225, 150);
}
else
{
this.manager.AddBigLabel("notracknetworks", "Waiting for server...", Color.red, 225, 150);
}
}
private void DisplayTrackNetworks(TrackNetworkStats network, int n, ref int ycursor, int trackiconx, int trackxoffset, int tracklabel)
{
this.manager.AddIcon("trackicon" + n, "Track Straight", Color.white, trackiconx, ycursor);
this.manager.AddBigLabel("trackjunctions" + n, "ID: " + network.NetworkID.ToString() + " " + network.JunctionCount.ToString() + " Junctions Carts: ", network.NetworkClosed ? Color.white : Color.red, trackxoffset, ycursor);
this.manager.AddBigLabel("trackcarts" + n, network.AvailableCarts.ToString() + " / " + network.AssignedCarts.ToString(), network.AvailableCarts > network.AssignedCarts ? Color.green : network.AvailableCarts == network.AssignedCarts ? Color.white : Color.red, tracklabel, ycursor);
ycursor += 60;
}
private void DisplayStation(StationStats station, int m, ref int ycursor, int stationxicon, int stationlabel)
{
int stationavail = station.AvailableCarts;
int stationassigned = station.AssignedCarts;
this.manager.AddIcon("stationicon" + m, "Minecart Load", Color.white, stationxicon, ycursor);
this.manager.AddBigLabel("stationnetwork" + m, (!string.IsNullOrEmpty(station.StationName) ? station.StationName : "UNNAMED") + " - " + station.NetworkID, station.StationFull <= 0 ? Color.white : Color.red, stationlabel, ycursor);
this.manager.AddBigLabel("stationcarts" + m, "Carts: " + stationavail.ToString() + " / " + stationassigned.ToString(), stationavail > stationassigned ? Color.green : stationavail == stationassigned ? Color.white : Color.red, stationlabel + 350, ycursor);
ycursor += 60;
}
private void DisplayDefSur(ref int ycursor, int stationlabel)
{
ycursor -= 20;
string str = "";
int shifter = 1;
int ind2 = 0;
if (NetworkSync.TrackNetworks.StationDeficits.Count <= 0)
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localdef", "This storage is fully stocked!", Color.white, false, stationlabel, ycursor);
else
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localdef", "Top requests for this storage:", Color.white, false, stationlabel, ycursor);
ycursor += 20;
for (int index = 0; index < NetworkSync.TrackNetworks.StationDeficits.Count; index++)
{
if (NetworkSync.TrackNetworks.StationDeficits[index].Deficit != 0)
{
str = (index + 1).ToString() + ") " + NetworkSync.TrackNetworks.StationDeficits[index].Deficit.ToString("N0") + "x " + ItemManager.GetItemName(NetworkSync.TrackNetworks.StationDeficits[index].FreightItem) + "\n";
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localdef" + index, str, Color.white, false, stationlabel, ycursor);
ycursor += 20;
}
shifter++;
}
ycursor -= 20 * shifter;
if (NetworkSync.TrackNetworks.StationSurplus.Count <= 0)
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localsur", "This storage has nothing to offer!", Color.white, false, stationlabel + 250, ycursor);
else
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localsur", "Top offerings for this storage:", Color.white, false, stationlabel + 250, ycursor);
ycursor += 20;
for (int index = 0; index < NetworkSync.TrackNetworks.StationSurplus.Count; index++)
{
if (NetworkSync.TrackNetworks.StationSurplus[index].Surplus != 0)
{
str = (index + 1).ToString() + ") " + NetworkSync.TrackNetworks.StationSurplus[index].Surplus.ToString("N0") + "x " + ItemManager.GetItemName(NetworkSync.TrackNetworks.StationSurplus[index].FreightItem) + "\n";
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localsur" + index, str, Color.white, false, stationlabel + 250, ycursor);
ycursor += 20;
}
ind2 = index;
}
if (ind2 > (shifter - 2))
ycursor += 20;
else
ycursor += (shifter - 1 - ind2) * 20 + 20;
}
private void DisplayCart(CartStats cart, int p, ref int ycursor, int cartlabel, int cartxicon)
{
int itemID = ItemEntries.MineCartT1;
if (cart.CartType == FreightCartMob.eMinecartType.FreightCartMK1)
itemID = ModManager.mModMappings.ItemsByKey["steveman0.FreightCartMK1"].ItemId;
else if (cart.CartType == FreightCartMob.eMinecartType.FreightCart_T1 || cart.CartType == FreightCartMob.eMinecartType.OreFreighter_T1)
itemID = ItemEntries.MineCartT1;
else if (cart.CartType == FreightCartMob.eMinecartType.FreightCart_T2 || cart.CartType == FreightCartMob.eMinecartType.OreFreighter_T2)
itemID = ItemEntries.MineCartT2;
else if (cart.CartType == FreightCartMob.eMinecartType.FreightCart_T3 || cart.CartType == FreightCartMob.eMinecartType.OreFreighter_T3)
itemID = ItemEntries.MineCartT3;
else if (cart.CartType == FreightCartMob.eMinecartType.FreightCart_T4 || cart.CartType == FreightCartMob.eMinecartType.OreFreighter_T4)
itemID = ItemEntries.MineCartT4;
else if (cart.CartType == FreightCartMob.eMinecartType.FreightCartTour)
itemID = ItemEntries.TourCart;
string carticon = ItemManager.GetItemIcon(itemID);
this.manager.AddIcon("carticon" + p, carticon, Color.white, cartxicon, ycursor);
this.manager.AddBigLabel("cartlabel" + p, "Inventory: " + cart.UsedStorage.ToString() + "/" + cart.MaxStorage.ToString(), Color.white, cartlabel, ycursor);
ycursor += 60;
}
private void DisplayCartInventory(CartStats cart, ref int ycursor, int invxicon, int invlabel)
{
List<ItemBase> inv = NetworkSync.TrackNetworks.CartInventory;
if (inv == null || inv.Count == 0)
{
this.manager.AddBigLabel("invlabelempty", "No goods from this station", Color.white, invxicon + 15, ycursor);
ycursor += 60;
}
else
{
int invcount = inv.Count;
for (int q = 0; q < invcount; q++)
{
ItemBase item = inv[q];
string invicon = ItemManager.GetItemIcon(item);
this.manager.AddIcon("invicon" + q, invicon, Color.white, invxicon, ycursor);
this.manager.AddBigLabel("invlabel" + q, item.ToString(), Color.white, invlabel, ycursor);
ycursor += 60;
}
}
}
private void SpawnGlobalInventory()
{
this.manager.SetTitle("Global Inventory");
if (this.OrderByName)
this.manager.AddButton("ordercount", "Order by Count", buttonx1, 0);
else
this.manager.AddButton("ordername", "Order by Name", buttonx1, 0);
this.manager.AddButton("allnetworks", "Network Status", buttonx2, 0);
this.manager.AddButton("selnetwork", "Select Network", buttonx3, 0);
this.manager.AddButton("tracknetworks", "Track Systems", buttonx4, 0);
this.manager.AddButton("viewinventory", "View Inventory", buttonx5, 0);
//Need to restore the buttons for different layout and ordering here!
fcm.CalculateGlobalInventory();
int count = fcm.GlobalInventory.Count;
if (CompactLayout)
{
int ItemRowSpacing = 60;
int ItemColSpacing = 60;
int yoffset = 60;
for (int n = 0; n < count; n++)
{
int row = n / 15;
int col = n % 15;
this.manager.AddIcon("itemicon" + n, "empty", Color.white, globalxoffset + col * ItemColSpacing + 35, row * ItemRowSpacing + yoffset);
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "StackSize" + n, "", Color.white, false, globalxoffset + col * ItemColSpacing + 27 + 25, row * ItemRowSpacing + 22 + yoffset);
}
}
else
{
int spacing = 60; //Spacing between each registry line
int yoffset = 60; //Offset below button row
int labeloffset = 50 + globalxoffset; //x offset for label from icon
//int count1offset = 120 + globalxoffset; //Inventory count offset
int col2xoffset = 300 + labeloffset; //Col 3 offset from the left
for (int n = 0; n < count; n++)
{
//Debug.Log("Catch error at n = " + n);
int height = n / 2; // int division rounds down
int shift = n % 2 == 1 ? col2xoffset : 0; // add shift for odd entries
int shift2 = n % 2 == 1 ? 50 : 0; // extra shift required for icons due to different scaling
this.manager.AddIcon("itemicon" + n, "empty", Color.white, globalxoffset + shift + 35, yoffset + (spacing * height));
this.manager.AddBigLabel("iteminfo" + n, "Inventory Item", Color.white, labeloffset + shift + 35, yoffset + (spacing * height));
}
}
}
private void SpawnStorageInventory()
{
this.manager.SetTitle("Mass Storage Inventory");
this.manager.AddButton("prevstorage", "Previous Inventory", buttonx1, 0);
this.manager.AddButton("allnetworks", "Global Inventory", buttonx2, 0);
this.manager.AddButton("selnetwork", "Select Network", buttonx3, 0);
this.manager.AddButton("tracknetworks", "Track Systems", buttonx4, 0);
this.manager.AddButton("viewinventory", "Network Status", buttonx5, 0);
this.manager.AddButton("nextstorage", "Next Inventory", buttonx6, 0);
if (fcm.StationInventories != null && fcm.StationInventories.Count > this.SelectedStorage && fcm.StationInventories.Count > 0)
{
this.InventoryCount = fcm.StationInventories[this.SelectedStorage].Inventory.Count;
int ItemRowSpacing = 60;
int ItemColSpacing = 60;
int yoffset = 100;
this.manager.AddBigLabel("nameofnetworktitle", "Viewing inventory of mass storage: ", Color.cyan, 335, 50);
this.manager.AddBigLabel("nameofnetwork", fcm.StationInventories[this.SelectedStorage].Name, Color.cyan, 650, 50);
for (int n = 0; n < this.InventoryCount; n++)
{
int row = n / 15;
int col = n % 15;
this.manager.AddIcon("itemicon" + n, "empty", Color.white, globalxoffset + col * ItemColSpacing + 35, row * ItemRowSpacing + yoffset);
this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "StackSize" + n, "", Color.white, false, globalxoffset + col * ItemColSpacing + 27 + 25, row * ItemRowSpacing + 22 + yoffset);
}
}
}
#endregion
#region UpdateMachine
public override void UpdateMachine(SegmentEntity targetEntity)
{
FreightSystemMonitor monitor = targetEntity as FreightSystemMonitor;
//Catch for when the window is called on an inappropriate machine
if (monitor == null)
{
GenericMachinePanelScript.instance.Hide();
UIManager.RemoveUIRules("Machine");
return;
}
if (networkredraw)
this.manager.RedrawWindow();
GenericMachinePanelScript.instance.Scroll_Bar.GetComponent<UIScrollBar>().scrollValue -= Input.GetAxis("Mouse ScrollWheel");
switch (this.CurrentWindow)
{
case WindowTypes.NetworkStatus:
this.UpdateNetworkStatus();
break;
case WindowTypes.GlobalInventory:
this.UpdateGlobalInventory();
break;
case WindowTypes.StorageInventory:
this.UpdateStorageInventory();
break;
}
}
private void UpdateNetworkStatus()
{
if (NetworkSync.NetworkStatus != null)
{
//string networkid = fcm.Networks[this.SelectedNetwork];
int count;
count = NetworkSync.NetworkStatus.Registries.Count;
for (int n = 0; n < count; n++)
{
ItemBase item = NetworkSync.NetworkStatus.Registries[n].FreightItem;
string iconname = ItemManager.GetItemIcon(item);
string itemname = ItemManager.GetItemName(item);
int def = NetworkSync.NetworkStatus.Registries[n].Deficit;
int stock = NetworkSync.NetworkStatus.Registries[n].Stock;
int inventory = NetworkSync.NetworkStatus.Registries[n].Inventory;
int surplus = NetworkSync.NetworkStatus.Registries[n].Surplus;
this.manager.UpdateIcon("item" + n, iconname, Color.white);
this.manager.UpdateLabel("registrytitle" + n, itemname, Color.white);
this.manager.UpdateLabel("deficit" + n, def.ToString("N0"), def <= surplus ? Color.white : Color.red);
this.manager.UpdateLabel("surplus" + n, surplus.ToString("N0"), surplus > def ? Color.green : Color.white);
this.manager.UpdateLabel("stock" + n, stock.ToString("N0"), stock < def ? Color.red : Color.green);
this.manager.UpdateLabel("totalinv" + n, inventory.ToString("N0"), Color.white);
}
// The server references update regularly but clients only get a snapshot
if (!WorldScript.mbIsServer)
dirty = false;
}
}
private void UpdateGlobalInventory()
{
int count = fcm.GlobalInventory.Count;
if (this.OrderByName)
fcm.OrderyInvByName();
else
fcm.OrderInvByCount();
for (int n = 0; n < count; n++)
{
ItemBase item = fcm.GlobalInventory[n].Key;
string iconname = ItemManager.GetItemIcon(item);
string itemname = ItemManager.GetItemName(item);
int itemcount = fcm.GlobalInventory[n].Value;
string iteminfo = (itemcount.ToString("N0") + "x " + itemname);
iteminfo = iteminfo.Substring(0, 35 > iteminfo.Length ? iteminfo.Length : 35);
this.manager.UpdateIcon("itemicon" + n, iconname, Color.white);
if (this.CompactLayout)
this.manager.UpdateLabel("StackSize" + n, FormatStackText(itemcount), Color.white);
else
this.manager.UpdateLabel("iteminfo" + n, iteminfo, Color.white);
}
}
private void UpdateStorageInventory()
{
if (fcm.StationInventories != null && fcm.StationInventories.Count > this.SelectedStorage)
{
int count = fcm.StationInventories[this.SelectedStorage].Inventory.Count;
if (count != this.InventoryCount)
this.manager.RedrawWindow();
for (int n = 0; n < this.InventoryCount; n++)
{
ItemBase item = fcm.StationInventories[this.SelectedStorage].Inventory[n].Key;
string iconname = ItemManager.GetItemIcon(item);
string itemname = ItemManager.GetItemName(item);
int itemcount = fcm.StationInventories[this.SelectedStorage].Inventory[n].Value;
string iteminfo = (itemcount.ToString("N0") + "x " + itemname);
iteminfo = iteminfo.Substring(0, 35 > iteminfo.Length ? iteminfo.Length : 35);
this.manager.UpdateIcon("itemicon" + n, iconname, Color.white);
if (this.CompactLayout)
this.manager.UpdateLabel("StackSize" + n, FormatStackText(itemcount), Color.white);
else
this.manager.UpdateLabel("iteminfo" + n, iteminfo, Color.white);
}
}
else
this.manager.RedrawWindow();
}
#endregion
private List<FreightRegistry> FreightListingConversion(List<FreightListing> items)
{
List<FreightRegistry> regs = new List<FreightRegistry>();
foreach (FreightListing item in items)
{
FreightRegistry reg = new FreightRegistry(null, null, item.Item, 0, 0, FreightRegistry.RegistryType.Registry);
reg.Deficit = item.Quantity;
reg.Surplus = item.Quantity;
regs.Add(reg);
}
return regs;
}
private string FormatStackText(int count)
{
string label = "";
if (count < 10)
label = " " + count.ToString();
else if (count < 100)
label = " " + count.ToString();
else if (count < 1000)
label = " " + count.ToString();
else if (count < 10000)
label = " " + ((double)count / 1000f).ToString("N1") + "k";
else if (count < 100000)
label = ((double)count / 1000f).ToString("N1") + "k";
else if (count < 1000000)
label = " "+ (count / 1000).ToString() + "k";
return label;
}
private void CountInventory(List<MassInventory> inv)
{
for (int index = 0; index < inv.Count; index++)
{
this.FullInventory = (from e in inv[index].Inventory.Concat(this.FullInventory)
group e by e.Key into g
select new { Name = g.Key, Count = g.Sum(kvp => kvp.Value) })
.ToDictionary(item => item.Name, item => item.Count);
}
}
public override bool ButtonClicked(string name, SegmentEntity targetEntity)
{
if (name == "nextnetwork") // Increment network count
{
this.SelectedNetwork++;
if (this.SelectedNetwork >= fcm.Networks.Count)
this.SelectedNetwork = 0;
NetworkSync.NetworkStatus = null;
this.manager.RedrawWindow();
return true;
}
else if (name == "prevnetwork") // Decrement network count
{
this.SelectedNetwork--;
if (this.SelectedNetwork < 0)
this.SelectedNetwork = fcm.Networks.Count - 1;
NetworkSync.NetworkStatus = null;
this.manager.RedrawWindow();
return true;
}
else if (name == "nextstorage") // Increment storage count
{
this.SelectedStorage++;
if (this.SelectedStorage >= fcm.StationInventories.Count)
this.SelectedStorage = 0;
this.manager.RedrawWindow();
return true;
}
else if (name == "prevstorage") // Decrement storage count
{
this.SelectedStorage--;
if (this.SelectedStorage < 0)
this.SelectedStorage = fcm.StationInventories.Count - 1;
this.manager.RedrawWindow();
return true;
}
else if (name == "allnetworks")
{
if (this.CurrentWindow == WindowTypes.GlobalInventory)
this.CurrentWindow = WindowTypes.NetworkStatus;
else
this.CurrentWindow = WindowTypes.GlobalInventory;
this.manager.RedrawWindow();
return true;
}
else if (name == "tracknetworks")
{
if (this.CurrentWindow == WindowTypes.TrackNetworks)
this.CurrentWindow = WindowTypes.NetworkStatus;
else
this.CurrentWindow = WindowTypes.TrackNetworks;
this.manager.RedrawWindow();
return true;
}
else if (name == "selnetwork")
{
if (this.CurrentWindow == WindowTypes.NetworkSelection)
this.CurrentWindow = WindowTypes.NetworkStatus;
else
this.CurrentWindow = WindowTypes.NetworkSelection;
this.manager.RedrawWindow();
return true;
}
else if (name == "viewinventory")
{
if (this.CurrentWindow == WindowTypes.StorageInventory)
this.CurrentWindow = WindowTypes.NetworkStatus;
else
this.CurrentWindow = WindowTypes.StorageInventory;
this.manager.RedrawWindow();
return true;
}
else if (name.Contains("networknum"))
{
int slotNum = -1;
int.TryParse(name.Replace("networknum", ""), out slotNum); //Get slot name as number
if (slotNum > -1) // valid slot
{
this.SelectedNetwork = slotNum;
NetworkSync.NetworkStatus = null;
this.CurrentWindow = WindowTypes.NetworkStatus;
this.manager.RedrawWindow();
return true;
}
}
else if (name.Contains("trackicon"))
{
int slotNum = -1;
int.TryParse(name.Replace("trackicon", ""), out slotNum); //Get slot name as number
if (slotNum > -1) // valid slot
{
if (this.TrackNetworkDisplay == slotNum)
this.TrackNetworkDisplay = -1;
else
this.TrackNetworkDisplay = slotNum;
this.StationDisplay = -1;
this.CartDisplay = -1;
NetworkSync.TrackNetworks = null;
this.manager.RedrawWindow();
return true;
}
}
else if (name.Contains("stationicon"))
{
int slotNum = -1;
int.TryParse(name.Replace("stationicon", ""), out slotNum); //Get slot name as number
if (slotNum > -1) // valid slot
{
if (this.StationDisplay == slotNum)
this.StationDisplay = -1;
else
this.StationDisplay = slotNum;
this.CartDisplay = -1;
this.manager.ClearWindow();
NetworkSync.TrackNetworks = null;
this.manager.RedrawWindow();
return true;
}
}
else if (name.Contains("carticon"))
{
int slotNum = -1;
int.TryParse(name.Replace("carticon", ""), out slotNum); //Get slot name as number
if (slotNum > -1) // valid slot
{
if (this.CartDisplay == slotNum)
this.CartDisplay = -1;
else
this.CartDisplay = slotNum;
NetworkSync.TrackNetworks = null;
this.manager.RedrawWindow();
return true;
}
}
else if (name == "addcart")
{
int amount = 1;
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
amount = 10;
FreightCartWindow.SetCartAssignment(this.CurrentStation, this.CurrentStation.AssignedCarts + amount);
this.manager.UpdateLabel("stationcarts" + this.StationDisplay.ToString(), "Carts: " + this.CurrentStation.AvailableCarts.ToString() + " / " + this.CurrentStation.AssignedCarts.ToString(), this.CurrentStation.AvailableCarts > this.CurrentStation.AssignedCarts ? Color.green : this.CurrentStation.AvailableCarts == this.CurrentStation.AssignedCarts ? Color.white : Color.red);
return true;
}
else if (name == "removecart")
{
int amount = 1;
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
amount = 10;
FreightCartWindow.SetCartAssignment(this.CurrentStation, this.CurrentStation.AssignedCarts - amount < 0 ? 0 : this.CurrentStation.AssignedCarts - amount);
this.manager.UpdateLabel("stationcarts" + this.StationDisplay.ToString(), "Carts: " + this.CurrentStation.AvailableCarts.ToString() + " / " + this.CurrentStation.AssignedCarts.ToString(), this.CurrentStation.AvailableCarts > this.CurrentStation.AssignedCarts ? Color.green : this.CurrentStation.AvailableCarts == this.CurrentStation.AssignedCarts ? Color.white : Color.red);
return true;
}
else if (name == "ordername")
{
this.OrderByName = true;
this.manager.RedrawWindow();
}
else if (name == "ordercount")
{
this.OrderByName = false;
this.manager.RedrawWindow();
}
else if (name == "togglelayout")
{
this.CompactLayout = !this.CompactLayout;
this.manager.RedrawWindow();
}
return false;
}
public override void ButtonEnter(string name, SegmentEntity targetEntity)
{
FreightSystemMonitor monitor = targetEntity as FreightSystemMonitor;
if (this.CurrentWindow != WindowTypes.GlobalInventory)
return;
string str = string.Empty;
int count;
ItemBase itemForSlot = this.GetItemForSlot(name, out count);
if (itemForSlot == null)
return;
if (HotBarManager.mbInited)
{
HotBarManager.SetCurrentBlockLabel(ItemManager.GetItemName(itemForSlot));
}
else
{
if (!SurvivalHotBarManager.mbInited)
return;
string name1 = !WorldScript.mLocalPlayer.mResearch.IsKnown(itemForSlot) ? "Unknown Material" : ItemManager.GetItemName(itemForSlot);
if (count > 1)
SurvivalHotBarManager.SetCurrentBlockLabel(string.Format("{0} {1}", count, name1));
else
SurvivalHotBarManager.SetCurrentBlockLabel(name1);
}
}
private ItemBase GetItemForSlot(string name, out int count)
{
ItemBase itemForSlot = null;
count = 0;
int slotNum = -1;
int.TryParse(name.Replace("itemicon", ""), out slotNum); //Get slot name as number
if (slotNum > -1 && slotNum < fcm.GlobalInventory.Count)
{
itemForSlot = fcm.GlobalInventory[slotNum].Key;
count = fcm.GlobalInventory[slotNum].Value;
}
return itemForSlot;
}
public override void OnClose(SegmentEntity targetEntity)
{
GenericMachinePanelScript.instance.gameObject.transform.localPosition = this.StartPos;
GenericMachinePanelScript.instance.gameObject.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Background_Panel.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Label_Holder.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Icon_Holder.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Content_Holder.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Content_Icon_Holder.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Scroll_Bar.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Source_Holder.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
GenericMachinePanelScript.instance.Generic_Machine_Title_Label.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
this.firstopen = false;
this.TrackNetworkDisplay = -1;
this.StationDisplay = -1;
this.CartDisplay = -1;
NetworkSync.TrackNetworks = null;
base.OnClose(targetEntity);
}
public override void HandleItemDrag(string name, ItemBase draggedItem, DragAndDropManager.DragRemoveItem dragDelegate, SegmentEntity targetEntity)
{
//FreightSystemMonitor monitor = targetEntity as FreightSystemMonitor;
return;
}
public static void RequestNetworkStatus(int netindex, Player player, FreightSystemMonitor monitor)
{
if (WorldScript.mbIsServer)
NetworkSync.GetNetworkStatus(netindex, player);
else
NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceNetStatus, netindex.ToString(), null, monitor, 0f);
}
public static void RequestTrackNetworks(int tracknetwork, int station, int cart, Player player, FreightSystemMonitor monitor)
{
if (WorldScript.mbIsServer)
NetworkSync.GetTrackNetworks(tracknetwork, station, cart, player);
else
NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceTrackSystems, tracknetwork.ToString() + "," + station.ToString() + "," + cart.ToString(), null, monitor, 0f);
}
public static NetworkInterfaceResponse HandleNetworkCommand(Player player, NetworkInterfaceCommand nic)
{
FreightSystemMonitor monitor = nic.target as FreightSystemMonitor;
string command = nic.command;
if (command != null)
{
if (command == InterfaceNetStatus)
{
int Netindex = 0;
int.TryParse(nic.payload ?? "-1", out Netindex);
SystemMonitorWindow.RequestNetworkStatus(Netindex, player, monitor);
}
else if (command == InterfaceTrackSystems)
{
int tracknetwork = -1;
int station = -1;
int cart = -1;
string[] output = nic.payload.Split(',');
if (output.Length > 2)
{
int.TryParse(output[0] ?? "-1", out tracknetwork);
int.TryParse(output[1] ?? "-1", out station);
int.TryParse(output[2] ?? "-1", out cart);
}
SystemMonitorWindow.RequestTrackNetworks(tracknetwork, station, cart, player, monitor);
}
}
return new NetworkInterfaceResponse
{
entity = monitor,
inventory = player.mInventory
};
}
}