-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
2383 lines (2005 loc) · 105 KB
/
Program.cs
File metadata and controls
2383 lines (2005 loc) · 105 KB
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
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Sandbox.ModAPI.Ingame;
using System;
using System.Collections.Generic;
using System.Text;
using VRage.Game.GUI.TextPanel;
using VRage.Game.ModAPI.Ingame;
using VRage.Game.ModAPI.Ingame.Utilities;
using VRageMath;
using System.Linq;
using VRage;
using System.IO;
namespace IngameScript
{
partial class Program : MyGridProgram
{
/*
* R e a d m e
* -----------
* Base Graphical inventory display for LCD by Space Engineers Script.
* 太空工程师,基地图形化显示库存脚本。
*
* @version 1.0.0
* @see <https://github.com/se-scripts/mybase>
* @author [Hi.James](https://space.bilibili.com/368005035)
* @author [chivehao](https://github.com/chivehao)
*/
MyIni _ini = new MyIni();
List<IMyCargoContainer> cargoContainers = new List<IMyCargoContainer>();
IMyTextPanel statisticsPanel = null;
IMyTextPanel farmPlotStatusPanel = null;
IMyTextPanel testPanel = null;
List<IMyTextPanel> statisticsPanels = new List<IMyTextPanel>();
List<IMyTextPanel> panels = new List<IMyTextPanel>();
List<IMyTextPanel> panels_Items_All = new List<IMyTextPanel>();
List<IMyTextPanel> panels_Items_Ore = new List<IMyTextPanel>();
List<IMyTextPanel> panels_Items_Ingot = new List<IMyTextPanel>();
List<IMyTextPanel> panels_Items_Component = new List<IMyTextPanel>();
List<IMyTextPanel> panels_Items_AmmoMagazine = new List<IMyTextPanel>();
List<IMyTextPanel> panels_Refineries = new List<IMyTextPanel>();
List<IMyTextPanel> panels_Assemblers = new List<IMyTextPanel>();
List<IMyTextPanel> panels_Overall = new List<IMyTextPanel>();
List<IMyGasTank> oxygenTanks = new List<IMyGasTank>();
List<IMyGasTank> hydrogenTanks = new List<IMyGasTank>();
List<IMyAssembler> assemblers = new List<IMyAssembler>();
List<IMyRefinery> refineries = new List<IMyRefinery>();
List<IMyPowerProducer> powerProducers = new List<IMyPowerProducer>();
List<IMyReactor> reactors = new List<IMyReactor>();
List<IMyGasGenerator> gasGenerators = new List<IMyGasGenerator>();
List<IMyFarmPlotLogic> farmPlotLogics = new List<IMyFarmPlotLogic>();
List<string> spritesList = new List<string>();
Dictionary<string, string> translator = new Dictionary<string, string>();
Dictionary<string, double> productionList = new Dictionary<string, double>();
const int itemAmountInEachScreen = 35, facilityAmountInEachScreen = 20;
const float itemBox_ColumnInterval_Float = 73, itemBox_RowInterval_Float = 102, amountBox_Height_Float = 24, facilityBox_RowInterval_Float = 25.5f;
const string translateList_Section = "Translate_List", length_Key = "Length";
const string statsSection = "Stats", statsLengthKey = "Length", statsTimeIntervalKey = "StatsTimeInterval", defaultStatsTimeInterval = "5";
int counter_ProgramRefresh = 0, counter_ShowItems = 0, counter_ShowFacilities = 0, counter_InventoryManagement = 0, counter_AssemblerManagement = 0, counter_RefineryManagement = 0, counter_Panel = 0;
double counter_Logo = 0;
const string basicConfigSelection = "BasicConfig"
, isCargoSameConstructAsKey = "IsCargoSameConstructAs", defaultIsCargoSameConstructAsValue = "true"
, isAssemblerSameConstructAsKey = "IsAssemblerSameConstructAs", defaultIsAssemblerSameConstructAsValue = "true"
, isRefinerySameConstructAsKey = "IsRefinerySameConstructAs", defaultIsRefinerySameConstructAsValue = "true"
, isPowerProducerSameConstructAsKey = "IsPowerProducerSameConstructAs", defaultIsPowerProducerSameConstructAsValue = "true"
, isReactorSameConstructAsKey = "IsReactorSameConstructAs", defaultIsReactorSameConstructAsValue = "true"
, isCargoAutoManagerSameConstructAsKey = "IsCargoAutoManagerSameConstructAs", defaultIsCargoAutoManagerSameConstructAsValue = "true";
const string overallConfigSeletion = "OverallConfig", displayAssemblerCustomName = "DisplayAssemblerName";
const string modBlueprintSubtypeIdResultMapSelection = "ModBlueprintSubtypeIdResultMap", enableKey = "enable", modBlueprintSubtypeIdResultMapLengthKey = "Length";
Dictionary<string, string> modBlueprintSubtypeIdResultMap = new Dictionary<string, string>();
Color background_Color = new Color(0, 35, 45);
Color border_Color = new Color(0, 130, 255);
public struct ItemStats
{
public string Name; // type id str
public DateTime StartTime;
public long LastCount;
public long Count;
public double Difference; // 差额
}
List<ItemStats> itemStatsList = new List<ItemStats>();
HashSet<string> statsItemTyps = new HashSet<string>();
public struct ItemList
{
public string Name;
public double Amount;
}
ItemList[] itemList_All;
ItemList[] itemList_Ore;
ItemList[] itemList_Ingot;
ItemList[] itemList_Component;
ItemList[] itemList_AmmoMagazine;
public struct Facility_Struct
{
public bool IsEnabled_Bool;
public string Name;
public bool IsProducing_Bool;
public bool IsCooperativeMode_Bool;
public bool IsRepeatMode_Bool;
public string Picture;
public double ItemAmount;
public string InputInventory;
public string OutputInventory;
public string Productivity;
}
Facility_Struct[] refineryList;
Facility_Struct[] assemblerList;
// 农场相关,从农场方块的面板信息里解析出来对应的状态值
// 当前作物类型:蔬菜
// 生长进度:100.00%
// 生长时间:00:20:00
// 作物健康状况:100.00%
// 水位:高
// 当前用水量:1.5升/分钟
public struct FarmBlockInfo
{
// 方块ID
public string id;
// 方块名称
public string name;
// 自定义数据
public string customData;
// 当前作物类型
public string cropType;
// 生长进度
public string growthProgress;
// 生长时间
public string growthTime;
// 作物健康状况
public string healthProgress;
// 水位
public string waterLevel;
// 当前分钟用水量
public string waterUseInMin;
}
List<IMyTerminalBlock> farmTerminalBlocks = new List<IMyTerminalBlock>();
List<FarmBlockInfo> farmBlockInfos = new List<FarmBlockInfo>();
public void SetUpdateFrequency()
{
Runtime.UpdateFrequency = UpdateFrequency.Once | UpdateFrequency.Update10;
string refreshRate = "FF", refreshRateKey = "RefreshRate";
if (!_ini.ContainsKey(basicConfigSelection, refreshRateKey))
{
_ini.Set(basicConfigSelection, refreshRateKey, refreshRate);
Me.CustomData = _ini.ToString();
}
GetConfiguration_from_CustomData(basicConfigSelection, refreshRateKey, out refreshRate);
if ("F".Equals(refreshRate))
{
Runtime.UpdateFrequency = UpdateFrequency.Update100;
}
else if ("FFF".Equals(refreshRate))
{
Runtime.UpdateFrequency = UpdateFrequency.Update1;
}
else
{
Runtime.UpdateFrequency = UpdateFrequency.Update10;
}
}
public Program()
{
SetDefultConfiguration();
SetUpdateFrequency();
BuildTranslateDic();
BuildStatsItemTyps();
GetBlocksFromGridTerminalSystem();
// incase no screen
if (panels.Count < 1)
{
if (Me.SurfaceCount > 0)
{
Me.GetSurface(0).GetSprites(spritesList);
}
}
else
{
panels[0].GetSprites(spritesList);
}
}
public void Save(){}
public void DebugLCD(string text)
{
List<IMyTextPanel> debugPanel = new List<IMyTextPanel>();
GridTerminalSystem.GetBlocksOfType(debugPanel, b => b.IsSameConstructAs(Me) && b.CustomName == "DEBUGLCD");
if (debugPanel.Count == 0) return;
string temp = "";
foreach (var panel in debugPanel)
{
temp = "";
temp = panel.GetText();
}
foreach (var panel in debugPanel)
{
if (panel.ContentType != ContentType.TEXT_AND_IMAGE) panel.ContentType = ContentType.TEXT_AND_IMAGE;
panel.FontSize = 0.55f;
panel.Font = "LoadingScreen";
panel.WriteText(DateTime.Now.ToString(), false);
panel.WriteText("\n", true);
panel.WriteText(text, true);
panel.WriteText("\n", true);
panel.WriteText(temp, true);
}
}
public void WriteConfiguration_to_CustomData(string section, string key, string value)
{
_ini.Set(section, key, value);
Me.CustomData = _ini.ToString();
}
public void GetConfiguration_from_CustomData(string section, string key, out string value)
{
GetConfiguration_from_CustomData(Me.CustomData, section, key, out value);
}
public void GetConfiguration_from_CustomData(string customData, string section, string key, out string value)
{
// This time we _must_ check for failure since the user may have written invalid ini.
MyIniParseResult result;
if (!_ini.TryParse(customData, out result))
throw new Exception(result.ToString());
string DefaultValue = "";
// Read the integer value. If it does not exist, return the default for this value.
value = _ini.Get(section, key).ToString(DefaultValue);
}
public void SetDefultConfiguration()
{
// This time we _must_ check for failure since the user may have written invalid ini.
MyIniParseResult result;
if (!_ini.TryParse(Me.CustomData, out result))
throw new Exception(result.ToString());
// Initialize CustomData
string dataTemp;
dataTemp = Me.CustomData;
if (dataTemp == "" || dataTemp == null)
{
_ini.Set(basicConfigSelection, isCargoSameConstructAsKey, defaultIsCargoSameConstructAsValue);
_ini.Set(basicConfigSelection, isAssemblerSameConstructAsKey, defaultIsAssemblerSameConstructAsValue);
_ini.Set(basicConfigSelection, isRefinerySameConstructAsKey, defaultIsRefinerySameConstructAsValue);
_ini.Set(basicConfigSelection, isPowerProducerSameConstructAsKey, defaultIsPowerProducerSameConstructAsValue);
_ini.Set(basicConfigSelection, isReactorSameConstructAsKey, defaultIsReactorSameConstructAsValue);
_ini.Set(overallConfigSeletion, displayAssemblerCustomName, "");
_ini.Set(translateList_Section, length_Key, "1");
_ini.Set(translateList_Section, "1", "AH_BoreSight:More");
Me.CustomData = _ini.ToString();
}// End if
if (!_ini.ContainsSection(statsSection)) {
_ini.Set(statsSection, statsTimeIntervalKey, defaultStatsTimeInterval);
_ini.Set(statsSection, statsLengthKey, 0);
Me.CustomData = _ini.ToString();
}
string value;
GetConfiguration_from_CustomData(statsSection, statsTimeIntervalKey, out value);
statsTimeInterval = Convert.ToInt32(value);
if (!_ini.ContainsSection(modBlueprintSubtypeIdResultMapSelection)) {
_ini.Set(modBlueprintSubtypeIdResultMapSelection, enableKey, "false");
_ini.Set(modBlueprintSubtypeIdResultMapSelection, modBlueprintSubtypeIdResultMapLengthKey, 0);
Me.CustomData = _ini.ToString();
}
if (_ini.Get(modBlueprintSubtypeIdResultMapSelection, enableKey).ToBoolean())
{
var length = _ini.Get(modBlueprintSubtypeIdResultMapSelection, modBlueprintSubtypeIdResultMapLengthKey).ToInt64();
for (var i = 1; i <= length; i++)
{
var str = _ini.Get(modBlueprintSubtypeIdResultMapSelection, i.ToString()).ToString();
var strs = str.Split(':');
modBlueprintSubtypeIdResultMap.Add(strs[0], strs[1]);
}
}
}
/*############### Overall ###############*/
public void OverallDisplay()
{
foreach (var panel in panels_Overall)
{
if (panel.CustomData != "0") panel.CustomData = "0";
else panel.CustomData = "0.001";
if (panel.ContentType != ContentType.SCRIPT) panel.ContentType = ContentType.SCRIPT;
MySpriteDrawFrame frame = panel.DrawFrame();
DrawContentBox(panel, frame);
frame.Dispose();
}
}
public void DrawContentBox(IMyTextPanel panel, MySpriteDrawFrame frame)
{
float x_Left = itemBox_ColumnInterval_Float / 2 + 1.5f, x_Right = itemBox_ColumnInterval_Float + 2 + (512 - itemBox_ColumnInterval_Float - 4) / 2, x_Title = 70, y_Title = itemBox_ColumnInterval_Float + 2 + Convert.ToSingle(panel.CustomData);
float progressBar_YCorrect = 0f, progressBarWidth = 512 - itemBox_ColumnInterval_Float - 6, progressBarHeight = itemBox_ColumnInterval_Float - 3;
// Title
DrawBox(frame, x_Left, x_Left + Convert.ToSingle(panel.CustomData), itemBox_ColumnInterval_Float, itemBox_ColumnInterval_Float, background_Color);
DrawBox(frame, 512 - x_Left, x_Left + Convert.ToSingle(panel.CustomData), itemBox_ColumnInterval_Float, itemBox_ColumnInterval_Float, background_Color);
DrawBox(frame, 512 / 2, x_Left + Convert.ToSingle(panel.CustomData), 512 - itemBox_ColumnInterval_Float * 2 - 4, itemBox_ColumnInterval_Float, background_Color);
PanelWriteText(frame, panels_Overall[0].GetOwnerFactionTag(), 512 / 2, 2 + Convert.ToSingle(panel.CustomData), 2.3f, TextAlignment.CENTER);
DrawLogo(frame, x_Left, x_Left + Convert.ToSingle(panel.CustomData), itemBox_ColumnInterval_Float);
DrawLogo(frame, 512 - x_Left, x_Left + Convert.ToSingle(panel.CustomData), itemBox_ColumnInterval_Float);
for (int i = 1; i <= 6; i++)
{
float y = i * itemBox_ColumnInterval_Float + itemBox_ColumnInterval_Float / 2 + 1.5f + Convert.ToSingle(panel.CustomData);
DrawBox(frame, x_Left, y, itemBox_ColumnInterval_Float, itemBox_ColumnInterval_Float, background_Color);
DrawBox(frame, x_Right, y, (512 - itemBox_ColumnInterval_Float - 4), itemBox_ColumnInterval_Float, background_Color);
}
// All Cargo
float y1 = itemBox_ColumnInterval_Float + itemBox_ColumnInterval_Float / 2 + 1.5f + Convert.ToSingle(panel.CustomData);
MySprite sprite = MySprite.CreateSprite("Textures\\FactionLogo\\Builders\\BuilderIcon_1.dds", new Vector2(x_Left, y1), new Vector2(itemBox_ColumnInterval_Float - 2, itemBox_ColumnInterval_Float - 2));
frame.Add(sprite);
string percentage_String, finalValue_String;
CalculateAll(out percentage_String, out finalValue_String);
ProgressBar(frame, x_Right, y1 + progressBar_YCorrect, progressBarWidth, progressBarHeight, percentage_String);
PanelWriteText(frame, cargoContainers.Count.ToString(), x_Title, y_Title, 0.55f, TextAlignment.RIGHT);
PanelWriteText(frame, percentage_String, x_Right, y_Title, 1.2f, TextAlignment.CENTER);
PanelWriteText(frame, finalValue_String, x_Right, y_Title + itemBox_ColumnInterval_Float / 2, 1.2f, TextAlignment.CENTER);
// H2
float y2 = y1 + itemBox_ColumnInterval_Float;
sprite = MySprite.CreateSprite("IconHydrogen", new Vector2(x_Left, y2), new Vector2(itemBox_ColumnInterval_Float - 2, itemBox_ColumnInterval_Float - 2));
frame.Add(sprite);
CalcualateGasTank(hydrogenTanks, out percentage_String, out finalValue_String);
PanelWriteText(frame, hydrogenTanks.Count.ToString(), x_Title, y_Title + itemBox_ColumnInterval_Float, 0.55f, TextAlignment.RIGHT);
ProgressBar(frame, x_Right, y2 + progressBar_YCorrect, progressBarWidth, progressBarHeight, percentage_String);
PanelWriteText(frame, percentage_String, x_Right, y_Title + itemBox_ColumnInterval_Float, 1.2f, TextAlignment.CENTER);
PanelWriteText(frame, finalValue_String, x_Right, y_Title + itemBox_ColumnInterval_Float + itemBox_ColumnInterval_Float / 2, 1.2f, TextAlignment.CENTER);
// O2
float y3 = y2 + itemBox_ColumnInterval_Float;
sprite = MySprite.CreateSprite("IconOxygen", new Vector2(x_Left, y3), new Vector2(itemBox_ColumnInterval_Float - 2, itemBox_ColumnInterval_Float - 2));
frame.Add(sprite);
CalcualateGasTank(oxygenTanks, out percentage_String, out finalValue_String);
PanelWriteText(frame, oxygenTanks.Count.ToString(), x_Title, y_Title + itemBox_ColumnInterval_Float * 2, 0.55f, TextAlignment.RIGHT);
ProgressBar(frame, x_Right, y3 + progressBar_YCorrect, progressBarWidth, progressBarHeight, percentage_String);
PanelWriteText(frame, percentage_String, x_Right, y_Title + itemBox_ColumnInterval_Float * 2, 1.2f, TextAlignment.CENTER);
PanelWriteText(frame, finalValue_String, x_Right, y_Title + itemBox_ColumnInterval_Float * 2 + itemBox_ColumnInterval_Float / 2, 1.2f, TextAlignment.CENTER);
// Power
float y4 = y3 + itemBox_ColumnInterval_Float;
sprite = MySprite.CreateSprite("IconEnergy", new Vector2(x_Left, y4), new Vector2(itemBox_ColumnInterval_Float - 2, itemBox_ColumnInterval_Float - 2));
frame.Add(sprite);
CalculatePowerProducer(out percentage_String, out finalValue_String);
PanelWriteText(frame, powerProducers.Count.ToString(), x_Title, y_Title + itemBox_ColumnInterval_Float * 3, 0.55f, TextAlignment.RIGHT);
ProgressBar(frame, x_Right, y4 + progressBar_YCorrect, progressBarWidth, progressBarHeight, percentage_String);
PanelWriteText(frame, percentage_String, x_Right, y_Title + itemBox_ColumnInterval_Float * 3, 1.2f, TextAlignment.CENTER);
PanelWriteText(frame, finalValue_String, x_Right, y_Title + itemBox_ColumnInterval_Float * 3 + itemBox_ColumnInterval_Float / 2, 1.2f, TextAlignment.CENTER);
// 特殊生产设备的生产进度
float y5 = y4 + itemBox_ColumnInterval_Float;
sprite = MySprite.CreateSprite("Textures\\FactionLogo\\Builders\\BuilderIcon_16.dds", new Vector2(x_Left, y5), new Vector2(itemBox_ColumnInterval_Float - 2, itemBox_ColumnInterval_Float - 2));
frame.Add(sprite);
string itemName;
CalculateSpProducerProgress(out itemName, out percentage_String, out finalValue_String);
PanelWriteText(frame, "", x_Title, y_Title + itemBox_ColumnInterval_Float * 4, 0.55f, TextAlignment.RIGHT);
ProgressBar(frame, x_Right, y5 + progressBar_YCorrect, progressBarWidth, progressBarHeight, percentage_String);
PanelWriteText(frame, itemName, x_Right, y_Title + itemBox_ColumnInterval_Float * 4, 1.2f, TextAlignment.CENTER);
PanelWriteText(frame, finalValue_String, x_Right, y_Title + itemBox_ColumnInterval_Float * 4 + itemBox_ColumnInterval_Float / 2, 1.2f, TextAlignment.CENTER);
}
public void ProgressBar(MySpriteDrawFrame frame, float x, float y, float width, float height, string ratio)
{
string[] ratiogroup = ratio.Split('%');
float ratio_Float = Convert.ToSingle(ratiogroup[0]);
float currentWidth = width * ratio_Float / 100;
float currentX = x - width / 2 + currentWidth / 2;
Color co = new Color(0, 0, 256);
if (ratio_Float == 0) return;
DrawBox(frame, currentX, y, currentWidth, height, co, co);
}
public void DrawLogo(MySpriteDrawFrame frame, float x, float y, float width)
{
MySprite sprite = new MySprite()
{
Type = SpriteType.TEXTURE,
Data = "Screen_LoadingBar",
Position = new Vector2(x, y),
Size = new Vector2(width - 6, width - 6),
RotationOrScale = Convert.ToSingle(counter_Logo / 360 * 2 * Math.PI),
Alignment = TextAlignment.CENTER,
};
frame.Add(sprite);
sprite = new MySprite()
{
Type = SpriteType.TEXTURE,
Data = "Screen_LoadingBar",
Position = new Vector2(x, y),
Size = new Vector2(width / 2, width / 2),
RotationOrScale = Convert.ToSingle(2 * Math.PI - counter_Logo / 360 * 2 * Math.PI),
Alignment = TextAlignment.CENTER,
};
frame.Add(sprite);
sprite = new MySprite()
{
Type = SpriteType.TEXTURE,
Data = "Screen_LoadingBar",
Position = new Vector2(x, y),
Size = new Vector2(width / 4, width / 4),
RotationOrScale = Convert.ToSingle(Math.PI + counter_Logo / 360 * 2 * Math.PI),
Alignment = TextAlignment.CENTER,
};
frame.Add(sprite);
}
public void CalculateAll(out string percentage_String, out string finalValue_String)
{
double currentVolume_Double = 0, totalVolume_Double = 0;
foreach (var cargoContainer in cargoContainers)
{
currentVolume_Double += ((double)cargoContainer.GetInventory().CurrentVolume);
totalVolume_Double += ((double)cargoContainer.GetInventory().MaxVolume);
}
percentage_String = Math.Round(currentVolume_Double / totalVolume_Double * 100, 1).ToString() + "%";
finalValue_String = AmountUnitConversion(currentVolume_Double * 1000) + " L / " + AmountUnitConversion(totalVolume_Double * 1000) + " L";
}
public void CalcualateGasTank(List<IMyGasTank> tanks, out string percentage_String, out string finalValue_String)
{
double currentVolume_Double = 0, totalVolume_Double = 0;
foreach (var tank in tanks)
{
currentVolume_Double += tank.Capacity * tank.FilledRatio;
totalVolume_Double += tank.Capacity;
}
percentage_String = Math.Round(currentVolume_Double / totalVolume_Double * 100, 1).ToString() + "%";
finalValue_String = AmountUnitConversion(currentVolume_Double) + " L / " + AmountUnitConversion(totalVolume_Double) + " L";
}
public void CalculatePowerProducer(out string percentage_String, out string finalValue_String)
{
double currentOutput = 0, totalOutput = 0;
foreach (var powerProducer in powerProducers)
{
currentOutput += powerProducer.CurrentOutput;
totalOutput += powerProducer.MaxOutput;
}
percentage_String = Math.Round(currentOutput / totalOutput * 100, 1).ToString() + "%";
finalValue_String = AmountUnitConversion(currentOutput * 1000000) + " W / " + AmountUnitConversion(totalOutput * 1000000) + " W";
}
public void CalculateSpProducerProgress(out string producer_Name, out string percentage_String, out string finalValue_String)
{
producer_Name = "";
percentage_String = 0 + "%";
finalValue_String = 0 + " % / " + 100 + " W";
GetConfiguration_from_CustomData(overallConfigSeletion, displayAssemblerCustomName, out producer_Name);
if (producer_Name != "")
{
string name = producer_Name;
List<IMyAssembler> asses = assemblers.Where((ass) => ass.CustomName.Contains(name)).ToList();
if (asses.Count > 0)
{
IMyAssembler ass = asses[0];
producer_Name = ass.CustomName;
percentage_String = Math.Round(ass.CurrentProgress * 100, 4) + "%";
finalValue_String = Math.Round(ass.CurrentProgress * 100, 4) + " / 100%";
}
}
}
//############### Overall ###############
/*############### ShowItems ###############*/
public void ShowItems()
{
//GetAllItems();
if (counter_ShowItems >= 7) counter_ShowItems = 1;
switch (counter_ShowItems.ToString())
{
case "1":
GetAllItems();
break;
case "2":
ItemDivideInGroups(itemList_All, panels_Items_All);
break;
case "3":
ItemDivideInGroups(itemList_Ore, panels_Items_Ore);
break;
case "4":
ItemDivideInGroups(itemList_Ingot, panels_Items_Ingot);
break;
case "5":
ItemDivideInGroups(itemList_Component, panels_Items_Component);
break;
case "6":
ItemDivideInGroups(itemList_AmmoMagazine, panels_Items_AmmoMagazine);
break;
}
counter_ShowItems++;
}
public void BuildTranslateDic()
{
string value;
GetConfiguration_from_CustomData(translateList_Section, length_Key, out value);
int length = Convert.ToInt16(value);
for (int i = 1; i <= length; i++)
{
GetConfiguration_from_CustomData(translateList_Section, i.ToString(), out value);
string[] result = value.Split(':');
translator.Add(result[0], result[1]);
}
}
public void BuildStatsItemTyps() {
string value;
GetConfiguration_from_CustomData(statsSection, statsLengthKey, out value);
int length = Convert.ToInt16(value);
for (int i = 1; i <= length; i++)
{
GetConfiguration_from_CustomData(statsSection, i.ToString(), out value);
statsItemTyps.Add(value);
}
}
public void GetBlocksFromGridTerminalSystem()
{
string isCargoSameConstructAsStr = defaultIsCargoSameConstructAsValue;
GetConfiguration_from_CustomData(basicConfigSelection, isCargoSameConstructAsKey, out isCargoSameConstructAsStr);
bool isCargoSameConstructAs = (isCargoSameConstructAsStr == "true");
cargoContainers.Clear();
statisticsPanels.Clear();
panels.Clear();
panels_Overall.Clear();
panels_Items_All.Clear();
panels_Items_Ore.Clear();
panels_Items_Ingot.Clear();
panels_Items_Component.Clear();
panels_Items_AmmoMagazine.Clear();
panels_Assemblers.Clear();
panels_Refineries.Clear();
oxygenTanks.Clear();
hydrogenTanks.Clear();
assemblers.Clear();
refineries.Clear();
powerProducers.Clear();
reactors.Clear();
gasGenerators.Clear();
farmPlotLogics.Clear();
GridTerminalSystem.GetBlocksOfType(cargoContainers, b => (isCargoSameConstructAs ? b.IsSameConstructAs(Me) : true));
GridTerminalSystem.GetBlocksOfType(panels, b => b.IsSameConstructAs(Me));
var sPanRes = GridTerminalSystem.GetBlockWithName("LCD_Statistics");
if (sPanRes != null) statisticsPanel = (IMyTextPanel)sPanRes;
var tPanRes = GridTerminalSystem.GetBlockWithName("TEST");
if (tPanRes != null) testPanel = (IMyTextPanel)tPanRes;
var fPlotsStatusPanRes = GridTerminalSystem.GetBlockWithName("LCD_FARM_PLOT_STATUS");
if (fPlotsStatusPanRes != null) farmPlotStatusPanel = (IMyTextPanel)fPlotsStatusPanRes;
GridTerminalSystem.GetBlocksOfType(statisticsPanels, b => b.IsSameConstructAs(Me) && b.CustomName.Contains("LCD_Statistics_Display:"));
GridTerminalSystem.GetBlocksOfType(panels_Overall, b => b.IsSameConstructAs(Me) && b.CustomName.Contains("LCD_Overall_Display"));
GridTerminalSystem.GetBlocksOfType(panels_Items_All, b => b.IsSameConstructAs(Me) && b.CustomName.Contains("LCD_Inventory_Display:"));
GridTerminalSystem.GetBlocksOfType(panels_Items_Ore, b => b.IsSameConstructAs(Me) && b.CustomName.Contains("LCD_Ore_Inventory_Display:"));
GridTerminalSystem.GetBlocksOfType(panels_Items_Ingot, b => b.IsSameConstructAs(Me) && b.CustomName.Contains("LCD_Ingot_Inventory_Display:"));
GridTerminalSystem.GetBlocksOfType(panels_Items_Component, b => b.IsSameConstructAs(Me) && b.CustomName.Contains("LCD_Component_Inventory_Display:"));
GridTerminalSystem.GetBlocksOfType(panels_Items_AmmoMagazine, b => b.IsSameConstructAs(Me) && b.CustomName.Contains("LCD_AmmoMagazine_Inventory_Display:"));
GridTerminalSystem.GetBlocksOfType(panels_Assemblers, b => b.IsSameConstructAs(Me) && b.CustomName.Contains("LCD_Assembler_Inventory_Display:"));
GridTerminalSystem.GetBlocksOfType(panels_Refineries, b => b.IsSameConstructAs(Me) && b.CustomName.Contains("LCD_Refinery_Inventory_Display:"));
GridTerminalSystem.GetBlocksOfType(oxygenTanks, b => b.IsSameConstructAs(Me) && !b.DefinitionDisplayNameText.ToString().Contains("Hydrogen") && !b.DefinitionDisplayNameText.ToString().Contains("氢气"));
GridTerminalSystem.GetBlocksOfType(hydrogenTanks, b => b.IsSameConstructAs(Me) && !b.DefinitionDisplayNameText.ToString().Contains("Oxygen") && !b.DefinitionDisplayNameText.ToString().Contains("氧气"));
string isAssemblerSameConstructAsStr = defaultIsAssemblerSameConstructAsValue;
GetConfiguration_from_CustomData(basicConfigSelection, isAssemblerSameConstructAsKey, out isAssemblerSameConstructAsStr);
bool isAssemblerSameConstructAs = (isAssemblerSameConstructAsStr == "true");
GridTerminalSystem.GetBlocksOfType(assemblers, b => (isAssemblerSameConstructAs ? b.IsSameConstructAs(Me) : true));
assemblers = assemblers.OrderBy(e => e.CustomName).ToList();
string isRefinerySameConstructAsStr = defaultIsRefinerySameConstructAsValue;
GetConfiguration_from_CustomData(basicConfigSelection, isRefinerySameConstructAsKey, out isRefinerySameConstructAsStr);
bool isRefinerySameConstructAs = (isRefinerySameConstructAsStr == "true");
GridTerminalSystem.GetBlocksOfType(refineries, b => !b.BlockDefinition.ToString().Contains("Shield") && (isRefinerySameConstructAs ? b.IsSameConstructAs(Me) : true));
refineries = refineries.OrderBy(e => e.CustomName).ToList();
string isPowerProducerSameConstructAsStr = defaultIsPowerProducerSameConstructAsValue;
GetConfiguration_from_CustomData(basicConfigSelection, isPowerProducerSameConstructAsKey, out isPowerProducerSameConstructAsStr);
bool isPowerProducerSameConstructAs = (isPowerProducerSameConstructAsStr == "true");
GridTerminalSystem.GetBlocksOfType(powerProducers, b => (isPowerProducerSameConstructAs ? b.IsSameConstructAs(Me) : true));
string isReactorSameConstructAsStr = defaultIsReactorSameConstructAsValue;
GetConfiguration_from_CustomData(basicConfigSelection, isReactorSameConstructAsKey, out isReactorSameConstructAsStr);
bool isReactorSameConstructAs = (isReactorSameConstructAsStr == "true");
GridTerminalSystem.GetBlocksOfType(reactors, b => (isReactorSameConstructAs ? b.IsSameConstructAs(Me) : true));
GridTerminalSystem.GetBlocksOfType(gasGenerators, b => b.IsSameConstructAs(Me));
// 目前脚本无法获取到对应的实体对象,预估是因为官方并没有给LargeBlockFarmPlot实现IMyFarmPlotLogic接口。
GridTerminalSystem.GetBlocksOfType(farmPlotLogics);
// 获取农场方块,并转化成对应的信息对象
farmTerminalBlocks.Clear();
GridTerminalSystem.GetBlocksOfType(farmTerminalBlocks, b => b.IsSameConstructAs(Me) && b.CustomName.Contains("[LCD]"));
reloadFarmInfos();
}
private void reloadFarmInfos()
{
if (farmTerminalBlocks.Count > 0)
{
farmBlockInfos.Clear();
foreach(var farmTerminalBlock in farmTerminalBlocks)
{
farmBlockInfos.Add(parseTerminal2BlockInfo(farmTerminalBlock));
}
}
}
private FarmBlockInfo parseTerminal2BlockInfo(IMyTerminalBlock farmTerminalBlock)
{
FarmBlockInfo farmBlockInfo = new FarmBlockInfo();
farmBlockInfo.id = farmTerminalBlock.EntityId.ToString();
farmBlockInfo.name = farmTerminalBlock.CustomName;
farmBlockInfo.customData = farmTerminalBlock.CustomData;
string DetailedInfo = farmTerminalBlock.DetailedInfo;
Dictionary<string, string> dict = new Dictionary<string, string>();
// 按换行符拆分, 按冒号分KV。
string[] lines = DetailedInfo.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string line in lines)
{
if (string.IsNullOrWhiteSpace(line))
continue;
int colonIndex = line.IndexOf(':'); // 中文冒号
if (colonIndex == -1)
colonIndex = line.IndexOf(':'); // 英文冒号
if (colonIndex > 0)
{
string key = line.Substring(0, colonIndex).Trim();
string value = line.Substring(colonIndex + 1).Trim();
dict[key] = value;
}
}
// PS: 当前只在中文的时候有效
if (dict.Keys.Contains("当前作物类型"))
{
farmBlockInfo.cropType = dict["当前作物类型"];
}
if (dict.Keys.Contains("生长进度"))
{
farmBlockInfo.growthProgress = dict["生长进度"];
if (farmBlockInfo.growthProgress == "100.00%")
{
// todo 更新为绿灯
} else
{
// todo 更新为在闪的红灯
}
}
if (dict.Keys.Contains("生长时间"))
{
farmBlockInfo.growthTime = dict["生长时间"];
}
if (dict.Keys.Contains("作物健康状况"))
{
farmBlockInfo.healthProgress = dict["作物健康状况"];
}
if (dict.Keys.Contains("水位"))
{
farmBlockInfo.waterLevel = dict["水位"];
}
if (dict.Keys.Contains("当前用水量"))
{
farmBlockInfo.waterUseInMin = dict["当前用水量"];
}
return farmBlockInfo;
}
public void GetAllItems()
{
Dictionary<string, double> allItems = new Dictionary<string, double>();
foreach (var cargoContainer in cargoContainers)
{
var items = new List<MyInventoryItem>();
cargoContainer.GetInventory().GetItems(items);
foreach (var item in items)
{
if (allItems.ContainsKey(item.Type.ToString())) allItems[item.Type.ToString()] += (double)item.Amount.RawValue;
else allItems.Add(item.Type.ToString(), (double)item.Amount.RawValue);
}
}
foreach (var cargoContainer in oxygenTanks)
{
var items = new List<MyInventoryItem>();
cargoContainer.GetInventory().GetItems(items);
foreach (var item in items)
{
if (allItems.ContainsKey(item.Type.ToString())) allItems[item.Type.ToString()] += (double)item.Amount.RawValue;
else allItems.Add(item.Type.ToString(), (double)item.Amount.RawValue);
}
}
foreach (var cargoContainer in hydrogenTanks)
{
var items = new List<MyInventoryItem>();
cargoContainer.GetInventory().GetItems(items);
foreach (var item in items)
{
if (allItems.ContainsKey(item.Type.ToString())) allItems[item.Type.ToString()] += (double)item.Amount.RawValue;
else allItems.Add(item.Type.ToString(), (double)item.Amount.RawValue);
}
}
foreach (var reactor in reactors)
{
var items = new List<MyInventoryItem>();
reactor.GetInventory().GetItems(items);
foreach (var item in items)
{
if (allItems.ContainsKey(item.Type.ToString())) allItems[item.Type.ToString()] += (double)item.Amount.RawValue;
else allItems.Add(item.Type.ToString(), (double)item.Amount.RawValue);
}
}
foreach (var cargoContainer in assemblers)
{
var items = new List<MyInventoryItem>();
cargoContainer.OutputInventory.GetItems(items);
foreach (var item in items)
{
if (allItems.ContainsKey(item.Type.ToString())) allItems[item.Type.ToString()] += (double)item.Amount.RawValue;
else allItems.Add(item.Type.ToString(), (double)item.Amount.RawValue);
}
}
foreach (var cargoContainer in refineries)
{
var items = new List<MyInventoryItem>();
cargoContainer.InputInventory.GetItems(items);
foreach (var item in items)
{
if (allItems.ContainsKey(item.Type.ToString())) allItems[item.Type.ToString()] += (double)item.Amount.RawValue;
else allItems.Add(item.Type.ToString(), (double)item.Amount.RawValue);
}
}
foreach (var gasGenerator in gasGenerators)
{
var items = new List<MyInventoryItem>();
gasGenerator.GetInventory().GetItems(items);
foreach (var item in items)
{
if (allItems.ContainsKey(item.Type.ToString())) allItems[item.Type.ToString()] += (double)item.Amount.RawValue;
else allItems.Add(item.Type.ToString(), (double)item.Amount.RawValue);
}
}
itemList_All = new ItemList[allItems.Count];
int k = 0;
foreach (var key in allItems.Keys)
{
itemList_All[k].Name = key;
itemList_All[k].Amount = allItems[key];
k++;
}
itemList_Ore = new ItemList[LengthOfEachCategory("MyObjectBuilder_Ore")];
itemList_Ingot = new ItemList[LengthOfEachCategory("MyObjectBuilder_Ingot")];
itemList_AmmoMagazine = new ItemList[LengthOfEachCategory("MyObjectBuilder_AmmoMagazine")];
transferItemsList(itemList_Ore, "MyObjectBuilder_Ore");
transferItemsList(itemList_Ingot, "MyObjectBuilder_Ingot");
transferItemsList(itemList_AmmoMagazine, "MyObjectBuilder_AmmoMagazine");
itemList_Component = new ItemList[itemList_All.Length - itemList_Ore.Length - itemList_Ingot.Length - itemList_AmmoMagazine.Length];
k = 0;
foreach (var item in itemList_All)
{
if (item.Name.IndexOf("MyObjectBuilder_Ore") == -1 && item.Name.IndexOf("MyObjectBuilder_Ingot") == -1 && item.Name.IndexOf("MyObjectBuilder_AmmoMagazine") == -1)
{
itemList_Component[k].Name = item.Name;
itemList_Component[k].Amount = item.Amount;
k++;
}
}
}
public int LengthOfEachCategory(string tag)
{
Dictionary<string, double> keyValuePairs = new Dictionary<string, double>();
foreach (var item in itemList_All)
{
if (item.Name.IndexOf(tag) != -1)
{
keyValuePairs.Add(item.Name, item.Amount);
}
}
return keyValuePairs.Count;
}
public void transferItemsList(ItemList[] itemList, string tag)
{
int k = 0;
foreach (var item in itemList_All)
{
if (item.Name.IndexOf(tag) != -1)
{
itemList[k].Name = item.Name;
itemList[k].Amount = item.Amount;
k++;
}
}
}
public void ItemDivideInGroups(ItemList[] itemList, List<IMyTextPanel> panels_Items)
{
if (itemList.Length == 0 || panels_Items.Count == 0) return;
// get all panel numbers
int[] findMax = new int[panels_Items.Count];
int k = 0;
foreach (var panel in panels_Items)
{
// get current panel number
string[] arry = panel.CustomName.Split(':');
findMax[k] = Convert.ToInt16(arry[1]);
k++;
}
if (itemList.Length > FindMax(findMax) * itemAmountInEachScreen)
{
foreach (var panel in panels_Items)
{
if (panel.CustomData != "0") panel.CustomData = "0";
else panel.CustomData = "1";
panel.ContentType = ContentType.SCRIPT;
panel.BackgroundColor = Color.Black;
MySpriteDrawFrame frame = panel.DrawFrame();
string[] arry = panel.CustomName.Split(':');
if (Convert.ToInt16(arry[1]) < FindMax(findMax))
{
DrawFullItemScreen(panel, frame, arry[1], true, itemList);
}
else
{
DrawFullItemScreen(panel, frame, arry[1], false, itemList);
}
frame.Dispose();
}
}
else
{
foreach (var panel in panels_Items)
{
if (panel.CustomData != "0") panel.CustomData = "0";
else panel.CustomData = "1";
panel.ContentType = ContentType.SCRIPT;
panel.BackgroundColor = Color.Black;
MySpriteDrawFrame frame = panel.DrawFrame();
string[] arry = panel.CustomName.Split(':');
DrawFullItemScreen(panel, frame, arry[1], true, itemList);
frame.Dispose();
}
}
}
public int FindMax(int[] arry)
{
int p = 0;
for (int i = 0; i < arry.Length; i++)
{
if (i == 0) p = arry[i];
else if (arry[i] > p) p = arry[i];
}
return p;
}
public void DrawFullItemScreen(IMyTextPanel panel, MySpriteDrawFrame frame, string groupNumber, bool isEnoughScreen, ItemList[] itemList)
{
panel.WriteText("", false);
DrawBox(frame, 512 / 2, 512 / 2 + Convert.ToSingle(panel.CustomData), 520, 520, new Color(0, 0, 0));
for (int i = 0; i < itemAmountInEachScreen; i++)
{
int k = (Convert.ToInt16(groupNumber) - 1) * itemAmountInEachScreen + i;
int x = (i + 1) % 7;
if (x == 0) x = 7;
int y = Convert.ToInt16(Math.Ceiling(Convert.ToDecimal(Convert.ToDouble(i + 1) / 7)));
if (k > itemList.Length - 1)
{
return;
}
else
{
if (x == 7 && y == 5)
{
if (isEnoughScreen)
{
DrawSingleItemUnit(panel, frame, itemList[k].Name, itemList[k].Amount / 1000000, x, y);