forked from JakobTischler/BunkerSilosHud
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBunkerSilosHud.lua
1974 lines (1672 loc) · 76.5 KB
/
BunkerSilosHud.lua
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
--
-- BunkerSilosHud
--
-- @description: A hud that shows the contents of all silos (BGA and cow), including the distribution inside each silo, plus the fill levels of all liquid manure tanks and some BGA data.
-- @author: Jakob Tischler
-- @project start: 13 Jan 2014
-- @date: 31 Jan 2015
-- @version: 2.1
-- @history: 0.98 (25 Feb 2014): * initial release
-- 0.99 (02 Mar 2014): * add safety check against impromperly created BunkerSilo triggers (w/o movingPlanes) - you know who you are!
-- * add warning sign if silo is fully fermented but the cover plane hasn't been removed yet
-- * fix scrolling functionality/zooming inhibit for vehicles with 'InteractiveControl' spec
-- 2.0 (14 Jan 2015): * conversion to FS15
-- * GUI update
-- * add BGA data (especially BGAextension): bunker fill level, bunker/fermenter dry matter, current and historic generator power
-- * add MP/DS support
-- 2.1 (31 Jan 2015): * add support for manure heaps
-- * add distinction between pigs and cattle
-- * hud is now draggable via drag+drop
-- @contact: jakobgithub -ätt- gmail -dot- com
-- @note: Modification, upload, distribution or any other change without the author's written permission is not allowed.
-- @thanks: Peter van der Veen and Claus G. Pedersen, for testing the English version
-- upsidedown, for the camera movement function and general testing
-- upsidedown and mor2000 for multiplayer testing
--
-- Copyright (C) 2014-2015 Jakob Tischler
--
--[[
TODO:
1) how to render the effects overlay OVER the rendered text (z-index)? As of right now, the text, even though rendered before, is still rendered above the effects overlay.
2) fix BGA bonus base text width when bonusFillLevel > bonusCapacity bug in BGAextension is fixed
3) setTool(nil) doesn't really work / only works sporadically
]]
-- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
local abs, ceil, floor, max, min, pow = math.abs, math.ceil, math.floor, math.max, math.min, math.pow;
local function round(n, precision)
if precision and precision > 0 then
return floor((n * pow(10, precision)) + 0.5) / pow(10, precision);
end;
return floor(n + 0.5);
end;
local targetAspectRatio = 16/9; -- = 1920/1080;
local aspectRatioRatio = g_screenAspectRatio / targetAspectRatio;
local sizeRatio = 1;
if g_screenWidth > 1920 then
sizeRatio = 1920 / g_screenWidth;
elseif g_screenWidth < 1920 then
sizeRatio = max((1920 / g_screenWidth) * .75, 1);
end;
local function getFullPx(n, dimension)
if dimension == 'x' then
return round(n * g_screenWidth) / g_screenWidth;
else
return round(n * g_screenHeight) / g_screenHeight;
end;
end;
-- px are in targetSize for 1920x1080
local function pxToNormal(px, dimension, fullPixel)
local ret;
if dimension == 'x' then
ret = (px / 1920) * sizeRatio;
else
ret = (px / 1080) * sizeRatio * aspectRatioRatio;
end;
if fullPixel == nil or fullPixel then
ret = getFullPx(ret, dimension);
end;
return ret;
end;
local function getPxToNormalConstant(widthPx, heightPx)
return widthPx/g_screenWidth, heightPx/g_screenHeight;
end;
-- #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
BunkerSilosHud = {
modDir = g_currentModDirectory;
modName = g_currentModName;
imgDir = g_currentModDirectory .. 'res/';
saveAndLoadFunctionsOverwritten = false;
hasMouseCursorActive = false;
canScroll = false;
HUDSTATE_INTERACTIVE = 1;
HUDSTATE_ACTIVE = 2;
HUDSTATE_CLOSED = 3;
TOPSECTION_SILOS = 1;
TOPSECTION_BGA = 2;
version = '0.0';
author = 'Jakob Tischler';
};
local modItem = ModsUtil.findModItemByModName(BunkerSilosHud.modName);
if modItem and modItem.version and modItem.author then
BunkerSilosHud.version, BunkerSilosHud.author = modItem.version, modItem.author;
end;
addModEventListener(BunkerSilosHud);
function BunkerSilosHud:loadMap(name)
if self.initialized then
return;
end;
self.debugActive = false; -- #####
self.complexBgaInstalled = getfenv(0)['ZZZ_complexBGA'] ~= nil;
self:debug('complexBgaInstalled=' .. tostring(self.complexBgaInstalled));
if not BunkerSilosHud.saveAndLoadFunctionsOverwritten then
self:setSaveAndLoadFunctions();
end;
self.inputModifier = self:getKeyIdOfModifier(InputBinding.BUNKERSILOS_HUD);
self.helpButtonText = g_i18n:getText('BUNKERSILOS_SHOWHUD');
local langNumData = {
br = { '.', ',' },
cz = { ' ', ',' },
de = { "'", ',' },
en = { ',', '.' },
es = { '.', ',' },
fr = { ' ', ',' },
it = { '.', ',' },
jp = { ',', '.' },
pl = { ' ', ',' },
ru = { ' ', ',' }
};
self.numberSeparator = '\'';
self.numberDecimalSeparator = '.';
if g_languageShort and langNumData[g_languageShort] then
self.numberSeparator = langNumData[g_languageShort][1];
self.numberDecimalSeparator = langNumData[g_languageShort][2];
end;
self.gui = {
hudState = BunkerSilosHud.HUDSTATE_CLOSED;
width = pxToNormal(500, 'x');
height = pxToNormal(244, 'y');
hPadding = pxToNormal(25, 'x');
fontSizeTitle = pxToNormal(16, 'y');
fontSize = pxToNormal(14, 'y');
fontSizeSmall = pxToNormal(12, 'y');
fontSizeTiny = pxToNormal(10, 'y');
buttonGfxWidth = pxToNormal(16, 'x');
buttonGfxHeight = pxToNormal(16, 'y');
};
local horizontalMargin = pxToNormal(16, 'x');
self.gui.x1 = getFullPx(1 - self.gui.width - horizontalMargin, 'x');
self.gui.y1 = pxToNormal(390, 'y');
self.gui.boxAreaWidth = self.gui.width - (2 * self.gui.hPadding);
self.gui.boxMargin = pxToNormal(3, 'x');
self.gui.boxMaxHeight = pxToNormal(44, 'y');
self.gui.colors = {
default = self:rgba( 33, 48, 24, 1.0),
defaultHover = self:rgba( 33, 48, 24, 2/3),
defaultTransparent = self:rgba( 33, 48, 24, 0.5),
clicked = self:rgba( 33, 48, 24, 1/3),
defaultNonCompacted = self:rgba( 33, 48, 24, 0.5),
text = self:rgba( 0, 5, 0, 1.0),
rotten = self:rgba( 73, 47, 42, 1.0),
rottenNonCompacted = self:rgba( 73, 47, 42, 0.5),
barSpecial = self:rgba(200, 10, 10, 1.0)
};
-- fill bar graph
self.gui.barHeight = pxToNormal(14, 'y');
self.gui.barBorderWidth = pxToNormal(4, 'x');
local imgPath = 'dataS2/menu/white.png';
self.barOverlayId = createImageOverlay(imgPath);
self.barSpecialOverlayId = createImageOverlay(imgPath);
self.barBgOverlayId = createImageOverlay(imgPath);
self:setOverlayIdColor(self.barOverlayId, 'barColor', 'default');
self:setOverlayIdColor(self.barSpecialOverlayId, 'barSpecialColor', 'barSpecial');
self:setOverlayIdColor(self.barBgOverlayId, 'barBgColor', 'defaultTransparent');
self.gui.iconFilePath = Utils.getFilename('bshIcons.png', BunkerSilosHud.imgDir);
self.gui.iconFileSize = { 16, 128 };
self.gui.iconUVs = {
arrowLeft = { 0, 48, 16,32 },
arrowRight = { 0, 32, 16,16 },
closeHud = { 0, 16, 16, 0 },
mouse = { 0, 64, 16,48 },
warning = { 0, 80, 16,64 },
radioDeselected = { 0, 96, 16,80 },
radioSelected = { 0,112, 16,96 }
};
local gfxPath = Utils.getFilename('bshHud.png', BunkerSilosHud.imgDir);
self.gui.background = Overlay:new('bshBackground', gfxPath, 0, 0, self.gui.width, self.gui.height);
self.gui.effects = Overlay:new('bshFx', gfxPath, 0, 0, self.gui.width, self.gui.height);
self:setOverlayUVsPx(self.gui.background, { 6,250, 506, 6 }, 512,512);
self:setOverlayUVsPx(self.gui.effects, { 6,506, 506,262 }, 512,512);
self.gui.buttons = {};
-- mouse wheel icon
self.gui.mouseWheel = Overlay:new('bshMouse', self.gui.iconFilePath, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight);
self:setOverlayUVsPx(self.gui.mouseWheel, self.gui.iconUVs.mouse, self.gui.iconFileSize[1], self.gui.iconFileSize[2]);
-- warning icon
self.gui.warning = Overlay:new('bshWarning', self.gui.iconFilePath, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight);
self:setOverlayUVsPx(self.gui.warning, self.gui.iconUVs.warning, self.gui.iconFileSize[1], self.gui.iconFileSize[2]);
self.displayWarning = false;
self.blinkLength = 500; -- in ms
-- close button
self.gui.closeHudButton = BshButton:new('closeHud', 'setHudState', BunkerSilosHud.HUDSTATE_CLOSED, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight);
-- ################################################################################
self.bunkerStates = {
[0] = g_i18n:getText('BUNKERSILOS_STATE_0'), -- to be filled
[1] = g_i18n:getText('BUNKERSILOS_STATE_1'), -- fermentation
[2] = g_i18n:getText('BUNKERSILOS_STATE_2') -- done/silage
};
local ce = g_currentMission.missionInfo.customEnvironment;
if ce and _G[ce] and _G[ce].g_i18n and _G[ce].g_i18n.getText then
self.mapI18n = _G[ce].g_i18n;
end;
self:debug(('ce=%q, mapI18n=%s'):format(tostring(ce), tostring(self.mapI18n)));
self.bgas = {};
self.bgaToBshData = {};
self.silos = {};
self.tempSiloTriggers = {};
self.siloTriggerIdToIdx = {};
self.tanks = {};
self.tanksIdentifiedById = {};
local bgaIdx = 0;
local bunkerSiloIdx = 0;
local liquidManureIdx = 0;
local manureIdx = 0;
for k,v in pairs(g_currentMission.tipTriggers) do
if g_currentMission.tipTriggers[k] ~= nil then
local t = g_currentMission.tipTriggers[k];
-- Silos
if t.bunkerSilo ~= nil and t.bunkerSilo.movingPlanes ~= nil then
bunkerSiloIdx = bunkerSiloIdx + 1;
self.tempSiloTriggers[bunkerSiloIdx] = v;
local siloTable = {
bunkerSiloIdx = bunkerSiloIdx;
bunkerSiloNum = bunkerSiloIdx;
triggerId = t.triggerId;
state = t.bunkerSilo.state;
stateText = self.bunkerStates[tonumber(t.bunkerSilo.state)];
-- fillLevel = t.bunkerSilo.fillLevel;
-- fillLevelFormatted = self:formatNumber(t.bunkerSilo.fillLevel, 0);
-- fillLevelPct = 0;
-- fillLevelPctFormatted = '0';
capacity = t.bunkerSilo.capacity;
capacityFormatted = self:formatNumber(t.bunkerSilo.capacity, 0);
-- toFillFormatted = '0';
-- compactedFillLevel = t.bunkerSilo.compactedFillLevel;
-- compactPct = 0;
-- compactPctFormatted = '0';
fermentingTime = t.bunkerSilo.fermentingTime;
fermentingDuration = t.bunkerSilo.fermentingDuration;
fermentationPct = 0;
fermentationPctFormatted = '0';
movingPlanesNum = #t.bunkerSilo.movingPlanes;
movingPlanes = {};
rottenFillLevel = 0;
rottenFillLevelPctFormatted = '0';
};
siloTable.boxWidth = (self.gui.boxAreaWidth - (siloTable.movingPlanesNum-1)*self.gui.boxMargin) / siloTable.movingPlanesNum;
for i=1, siloTable.movingPlanesNum do
local movingPlane = {};
movingPlane.boxX = 0;
movingPlane.boxCenterX = movingPlane.boxX + siloTable.boxWidth * 0.5;
table.insert(siloTable.movingPlanes, movingPlane);
end;
local name = getUserAttribute(t.triggerId, 'bshName');
if name ~= nil and self.mapI18n and self.mapI18n:hasText('BSH_' .. name) then
siloTable.name = self.mapI18n:getText('BSH_' .. name);
t.bshName = siloTable.name;
t.bunkerSilo.bshName = siloTable.name;
else
siloTable.name = ('%s %.2d'):format(g_i18n:getText('BUNKERSILOS_SILO'), bunkerSiloIdx);
end;
table.insert(self.silos, siloTable);
self.siloTriggerIdToIdx[t.triggerId] = bunkerSiloIdx;
self:debug(('add silo %d (triggerId %s, #movingPlanes=%d, name %q) / total: %d'):format(bunkerSiloIdx, tostring(t.triggerId), siloTable.movingPlanesNum, tostring(siloTable.name), #self.silos));
end;
end;
end; --END for
for i,onCreateObject in pairs(g_currentMission.onCreateLoadedObjects) do
-- BGAs
if onCreateObject.isa and onCreateObject:isa(Bga) then
bgaIdx = bgaIdx + 1;
local bgaTable = {
bgaIdx = bgaIdx;
bgaNum = bgaIdx;
onCreateIndex = i;
isBga = true;
nodeId = onCreateObject.nodeId;
name = ('%s %.2d'):format(g_i18n:getText('BUNKERSILOS_BGA'), bgaIdx);
};
-- BGA extension (complexBGA, upsidedown)
if onCreateObject.fermenter_TS_clog then
self:debug(' isComplexBga = true');
bgaTable.isComplexBga = true;
bgaTable.tsGraphNumValues = 48; -- 48 hours -- prev: 1 point per hour, 5 days
local posX, posY = 0, 0;
local width = self.gui.boxAreaWidth * ((bgaTable.tsGraphNumValues - 1) / bgaTable.tsGraphNumValues);
local height = self.gui.boxMaxHeight;
local minValue, maxValue = 0, 500;
local showGraphLabels, labelExtraText = false, '';
bgaTable.tsGraph = Graph:new(bgaTable.tsGraphNumValues, posX, posY, width, height, minValue, maxValue, showGraphLabels, labelExtraText);
bgaTable.tsGraph:setColor(unpack(self.gui.colors.default));
bgaTable.powerHistory = {};
if not self.hourChangeListenerAdded then
g_currentMission.environment:addHourChangeListener(self);
self.hourChangeListenerAdded = true;
self.updateBgaPowerHistoryOnce = true;
end;
end;
local name = getUserAttribute(onCreateObject.nodeId, 'bshName');
if name ~= nil and self.mapI18n and self.mapI18n:hasText('BSH_' .. name) then
bgaTable.name = self.mapI18n:getText('BSH_' .. name);
end;
self.bgas[#self.bgas + 1] = bgaTable;
-- reference history directly in BGA so it can be saved to the xml
onCreateObject.bshPowerHistory = self.bgas[#self.bgas].powerHistory;
self.bgaToBshData[onCreateObject] = self.bgas[#self.bgas];
self:debug(('add BGA %d (onCreateIndex %d, name %q) / total: %d'):format(bgaIdx, i, tostring(bgaTable.name), #self.bgas));
-- #####
-- BGA liquid manure tank(s)
if onCreateObject.liquidManureSiloTrigger ~= nil then
local trigger = onCreateObject.liquidManureSiloTrigger;
local triggerId = trigger.triggerId;
if not self.tanksIdentifiedById[triggerId] then
liquidManureIdx = liquidManureIdx + 1;
local tankTable = {
tankNum = liquidManureIdx;
onCreateIndex = i;
triggerId = triggerId;
isBGA = true;
fillLevel = trigger.fillLevel;
fillLevelFormatted = '0';
fillLevelPct = 0;
fillLevelPctFormatted = '0';
capacity = trigger.capacity;
capacityFormatted = self:formatNumber(trigger.capacity, 0);
unit = g_i18n:getText('fluid_unit_short');
name = ('%s %.2d (%s)'):format(g_i18n:getText('BUNKERSILOS_TANK'), liquidManureIdx, g_i18n:getText('BUNKERSILOS_TANKTYPE_BGA'));
};
local name = getUserAttribute(triggerId, 'bshName');
if name ~= nil and self.mapI18n and self.mapI18n:hasText('BSH_' .. name) then
tankTable.name = self.mapI18n:getText('BSH_' .. name);
trigger.bshName = tankTable.name;
end;
tankTable.fillLevelTxtPosX = 0;
table.insert(self.tanks, tankTable);
self.tanksIdentifiedById[triggerId] = true;
self:debug(('add LiquidManureTank %d (triggerId %s, name %q) [BGA] / total: %d'):format(liquidManureIdx, tostring(triggerId), tostring(tankTable.name), #self.tanks));
end;
end;
-- AnimalHusbandry [cows]
elseif onCreateObject.isa and onCreateObject:isa(AnimalHusbandry) then
-- liquid manure tank
if onCreateObject.liquidManureTrigger ~= nil then
local trigger = onCreateObject.liquidManureTrigger;
local triggerId = trigger.triggerId;
if not self.tanksIdentifiedById[triggerId] then
liquidManureIdx = liquidManureIdx + 1;
local tankTable = {
tipTriggersIdx = k;
tankNum = liquidManureIdx;
onCreateIndex = i;
triggerId = triggerId;
isCowsLiquidManure = true;
fillLevel = trigger.fillLevel;
fillLevelFormatted = '0';
fillLevelPct = 0;
fillLevelPctFormatted = '0';
capacity = trigger.capacity;
capacityFormatted = self:formatNumber(trigger.capacity, 0);
unit = g_i18n:getText('fluid_unit_short');
name = ('%s %.2d (%s)'):format(g_i18n:getText('BUNKERSILOS_TANK'), liquidManureIdx, g_i18n:getText('BUNKERSILOS_TANKTYPE_COWS'));
};
local name = getUserAttribute(triggerId, 'bshName');
if name ~= nil and self.mapI18n and self.mapI18n:hasText('BSH_' .. name) then
tankTable.name = self.mapI18n:getText('BSH_' .. name);
end;
tankTable.fillLevelTxtPosX = 0;
table.insert(self.tanks, tankTable);
self.tanksIdentifiedById[triggerId] = true;
self:debug(('add LiquidManureTank %d (triggerId %s, name %q) [cows] / total: %d'):format(liquidManureIdx, tostring(triggerId), tostring(tankTable.name), #self.tanks));
end;
end;
-- manure heap
if onCreateObject.manureHeap ~= nil then
local trigger = onCreateObject.manureHeap;
local triggerId = trigger.triggerId;
if not self.tanksIdentifiedById[triggerId] and trigger.capacity then
manureIdx = manureIdx + 1;
local tankTable = {
tipTriggersIdx = k;
tankNum = manureIdx;
onCreateIndex = i;
triggerId = triggerId;
isCowsManure = true;
isManure = true;
fillLevel = trigger.fillLevel;
fillLevelFormatted = '0';
fillLevelPct = 0;
fillLevelPctFormatted = '0';
capacity = trigger.capacity;
capacityFormatted = self:formatNumber(trigger.capacity * 0.001, 0);
unit = 'm3';
name = ('%s %.2d (%s)'):format(g_i18n:getText('Manure_storage'), manureIdx, g_i18n:getText('BUNKERSILOS_TANKTYPE_COWS'));
};
local name = getUserAttribute(triggerId, 'bshName');
if name ~= nil and self.mapI18n and self.mapI18n:hasText('BSH_' .. name) then
tankTable.name = self.mapI18n:getText('BSH_' .. name);
end;
tankTable.fillLevelTxtPosX = 0;
table.insert(self.tanks, tankTable);
self.tanksIdentifiedById[triggerId] = true;
self:debug(('add ManureHeap %d (triggerId %s, name %q) [cows] / total: %d'):format(manureIdx, tostring(triggerId), tostring(tankTable.name), #self.tanks));
end;
end;
-- ManureLager tanks
elseif onCreateObject.ManureLagerDirtyFlag ~= nil or Utils.endsWith(onCreateObject.className, 'ManureLager') then
local triggerId = onCreateObject.triggerId;
if not self.tanksIdentifiedById[triggerId] then
liquidManureIdx = liquidManureIdx + 1;
local tankTable = {
tankNum = liquidManureIdx;
onCreateIndex = i;
isManureLager = true;
fillLevel = onCreateObject.fillLevel;
fillLevelFormatted = '0';
fillLevelPct = 0;
fillLevelPctFormatted = '0';
capacity = onCreateObject.capacity;
capacityFormatted = self:formatNumber(onCreateObject.capacity, 0);
unit = g_i18n:getText('fluid_unit_short');
name = ('%s %.2d (%s)'):format(g_i18n:getText('BUNKERSILOS_TANK'), liquidManureIdx, g_i18n:getText('BUNKERSILOS_TANKTYPE_MANURESTORAGE'));
};
local name = getUserAttribute(triggerId, 'bshName');
if name ~= nil and self.mapI18n and self.mapI18n:hasText('BSH_' .. name) then
tankTable.name = self.mapI18n:getText('BSH_' .. name);
onCreateObject.bshName = tankTable.name;
end;
tankTable.fillLevelTxtPosX = 0;
self.tanks[#self.tanks + 1] = tankTable;
self.tanksIdentifiedById[triggerId] = true;
self:debug(('add LiquidManureTank %d (triggerId %s, name %q) [ManureLager] / total: %d'):format(liquidManureIdx, tostring(triggerId), tostring(tankTable.name), #self.tanks));
end;
-- Pigs/cattle [Schweinemast by marhu]
elseif onCreateObject.SchweineZuchtDirtyFlag and onCreateObject.numSchweine ~= nil then
-- liquid manure tank
if onCreateObject.liquidManureSiloTrigger ~= nil then
local trigger = onCreateObject.liquidManureSiloTrigger;
local triggerId = trigger.triggerId;
if triggerId and not self.tanksIdentifiedById[triggerId] then
liquidManureIdx = liquidManureIdx + 1;
local tankTable = {
tankNum = liquidManureIdx;
onCreateIndex = i;
isPigsLiquidManure = true;
fillLevel = trigger.fillLevel;
fillLevelFormatted = '0';
fillLevelPct = 0;
fillLevelPctFormatted = '0';
capacity = trigger.capacity;
capacityFormatted = self:formatNumber(trigger.capacity, 0);
unit = g_i18n:getText('fluid_unit_short');
};
local animalType = 'pigs';
local name = getUserAttribute(triggerId, 'bshName');
if name ~= nil and self.mapI18n and self.mapI18n:hasText('BSH_' .. name) then
tankTable.name = self.mapI18n:getText('BSH_' .. name);
onCreateObject.bshName = tankTable.name;
else
if onCreateObject.animal and onCreateObject.animal == 'beef' then
animalType = 'cattle';
end;
if onCreateObject.StationNr then
tankTable.name = ('%s (%s #%d)'):format(g_i18n:getText('BUNKERSILOS_TANK'), g_i18n:getText('BUNKERSILOS_TANKTYPE_' .. animalType:upper()), onCreateObject.StationNr);
else
tankTable.name = ('%s %.2d (%s)'):format(g_i18n:getText('BUNKERSILOS_TANK'), liquidManureIdx, g_i18n:getText('BUNKERSILOS_TANKTYPE_' .. animalType:upper()));
end;
end;
tankTable.fillLevelTxtPosX = 0;
table.insert(self.tanks, tankTable);
self.tanksIdentifiedById[triggerId] = true;
self:debug(('add LiquidManureTank %d (triggerId %s, name %q) [%s] / total: %d'):format(liquidManureIdx, tostring(triggerId), tostring(tankTable.name), animalType, #self.tanks));
end;
end;
-- manure heap [NOTE: SchweineZucht manure heap doesn't have a triggerId! -> no custom naming possible]
if onCreateObject.manureHeap ~= nil then
local trigger = onCreateObject.manureHeap;
if trigger.capacity then
manureIdx = manureIdx + 1;
local tankTable = {
tipTriggersIdx = k;
tankNum = manureIdx;
onCreateIndex = i;
-- triggerId = triggerId;
isPigsManure = true;
isManure = true;
fillLevel = trigger.FillLvl;
fillLevelFormatted = '0';
fillLevelPct = 0;
fillLevelPctFormatted = '0';
capacity = trigger.capacity;
capacityFormatted = self:formatNumber(trigger.capacity * 0.001, 0);
unit = 'm3';
};
local animalType = 'pigs';
if onCreateObject.animal and onCreateObject.animal == 'beef' then
animalType = 'cattle';
end;
if onCreateObject.StationNr then
tankTable.name = ('%s (%s #%d)'):format(g_i18n:getText('Manure_storage'), g_i18n:getText('BUNKERSILOS_TANKTYPE_' .. animalType:upper()), onCreateObject.StationNr);
else
tankTable.name = ('%s %.2d (%s)'):format(g_i18n:getText('Manure_storage'), manureIdx, g_i18n:getText('BUNKERSILOS_TANKTYPE_' .. animalType:upper()));
end;
tankTable.fillLevelTxtPosX = 0;
table.insert(self.tanks, tankTable);
-- self.tanksIdentifiedById[triggerId] = true;
self:debug(('add ManureHeap %d (triggerId %s, name %q) [%s] / total: %d'):format(manureIdx, tostring(triggerId), tostring(tankTable.name), animalType, #self.tanks));
end;
end;
end;
end;
--------------------------------------------------------------------------------------------------------------
local function sortByName(a, b)
return a.name:lower() < b.name:lower();
end;
-- SORT AND REINDEX
-- BGAs
self.numBgas = #self.bgas;
if self.numBgas > 0 then
self.activeBga = 1;
if self.numBgas > 1 then
table.sort(self.bgas, sortByName);
for k,v in ipairs(self.bgas) do
v.bgaNum = k;
end;
self.gui.changeBgaNegButton = BshButton:new('arrowLeft', 'changeBga', -1, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight);
self.gui.changeBgaPosButton = BshButton:new('arrowRight', 'changeBga', 1, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight);
end;
else
self.activeBga = false;
end;
-- silos
self.numSilos = #self.silos;
if self.numSilos > 0 then
self.activeSilo = 1;
local imgPath = 'dataS2/menu/white.png';
self.movingPlanesOverlayId = createImageOverlay(imgPath);
self.movingPlanesNonCompactedOverlayId = createImageOverlay(imgPath);
self:setOverlayIdColor(self.movingPlanesOverlayId, 'movingPlanesColor', 'default');
self:setOverlayIdColor(self.movingPlanesNonCompactedOverlayId, 'movingPlanesNonCompactedColor', 'defaultNonCompacted');
if self.numSilos > 1 then
table.sort(self.silos, sortByName);
for k,v in ipairs(self.silos) do
v.bunkerSiloNum = k;
end;
self.gui.changeSiloNegButton = BshButton:new('arrowLeft', 'changeSilo', -1, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight);
self.gui.changeSiloPosButton = BshButton:new('arrowRight', 'changeSilo', 1, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight);
end;
else
self.activeSilo = false;
end;
-- tanks
self.numTanks = #self.tanks;
if self.numTanks > 0 then
self.activeTank = 1;
if self.numTanks > 1 then
table.sort(self.tanks, sortByName);
for k,v in ipairs(self.tanks) do
v.tankNum = k;
end;
self.gui.changeTankNegButton = BshButton:new('arrowLeft', 'changeTank', -1, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight);
self.gui.changeTankPosButton = BshButton:new('arrowRight', 'changeTank', 1, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight);
end;
else
self.activeTank = false;
end;
-- TOP SECTION SELECTION
-- BGA button
local textWidth = getTextWidth(self.gui.fontSize, g_i18n:getText('BUNKERSILOS_BGA'));
local buttonWidth = self.gui.buttonGfxWidth + textWidth;
self.gui.topSectionButtonBga = BshButton:new('radioDeselected', 'setTopSection', BunkerSilosHud.TOPSECTION_BGA, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight, buttonWidth, self.gui.buttonGfxHeight);
-- Silos button
textWidth = getTextWidth(self.gui.fontSize, g_i18n:getText('BUNKERSILOS_SILOS'));
buttonWidth = self.gui.buttonGfxWidth + textWidth;
self.gui.topSectionButtonSilos = BshButton:new('radioSelected', 'setTopSection', BunkerSilosHud.TOPSECTION_SILOS, 0, 0, self.gui.buttonGfxWidth, self.gui.buttonGfxHeight, buttonWidth, self.gui.buttonGfxHeight);
self:setTopSection(BunkerSilosHud.TOPSECTION_SILOS);
-- ##### SET GRAPHICS POSITION
self:setGuiPositions();
-- stop vehicle/player camera movement if mouse active
if not VehicleCamera.bshMouseInserted then
VehicleCamera.mouseEvent = Utils.overwrittenFunction(VehicleCamera.mouseEvent, BunkerSilosHud.cancelMouseEvent);
VehicleCamera.zoomSmoothly = Utils.overwrittenFunction(VehicleCamera.zoomSmoothly, BunkerSilosHud.cancelZoom);
VehicleCamera.bshMouseInserted = true;
end;
if not Player.bshMouseInserted then
Player.mouseEvent = Utils.overwrittenFunction(Player.mouseEvent, BunkerSilosHud.cancelMouseEvent);
Player.bshMouseInserted = true;
end;
self.initialized = true;
print(('## BunkerSilosHud v%s by %s loaded'):format(BunkerSilosHud.version, BunkerSilosHud.author));
end;
function BunkerSilosHud:setGuiPositions()
self.gui.x2 = self.gui.x1 + self.gui.width;
self.gui.y2 = self.gui.y1 + self.gui.height;
self.gui.contentMinX = self.gui.x1 + self.gui.hPadding;
self.gui.contentMaxX = self.gui.x1 + self.gui.width - self.gui.hPadding;
self.gui.contentCenterX = self.gui.x1 + self.gui.width * 0.5;
self.gui.upperLineY = self.gui.y1 + pxToNormal(210, 'y');
self.gui.lines = {};
-- Main title
self.gui.lines[0] = self.gui.y1 + pxToNormal(212, 'y');
-- Silos / BGA
self.gui.lines[1] = self.gui.lines[0] - pxToNormal(22, 'y');
self.gui.lines[2] = self.gui.lines[1] - pxToNormal(20, 'y');
self.gui.lines[3] = self.gui.lines[2] - pxToNormal(20, 'y');
self.gui.lines[4] = self.gui.lines[3] - pxToNormal(20, 'y');
self.gui.lines[5] = self.gui.lines[4] - pxToNormal(20, 'y');
self.gui.lines[6] = self.gui.y1 + pxToNormal(61, 'y');
-- Liquid manure tanks
self.gui.lines[7] = self.gui.y1 + pxToNormal(42, 'y');
self.gui.lines[8] = self.gui.lines[7] - pxToNormal(20, 'y');
self.gui.barBorderRightPosX = self.gui.contentMaxX - self.gui.barBorderWidth;
self.gui.barMaxX = self.gui.contentMaxX - (self.gui.barBorderWidth * 2);
-- Liquid manure tank bar graph
self.gui.tankBarBorderLeftPosX = self.gui.contentMinX;
self.gui.tankBarMinX = self.gui.tankBarBorderLeftPosX + (self.gui.barBorderWidth * 2);
self.gui.tankBarMaxWidth = self.gui.barMaxX - self.gui.tankBarMinX;
-- BGA bunker fill level bar graph
local text = g_i18n:getText('BUNKERSILOS_BGA_BUNKERFILLLEVEL'):format('00,0', '00,0', '100,0');
if self.complexBgaInstalled then
self.gui.bgaBunkerFillLevelBarBorderLeftPosX, self.gui.bgaBunkerFillLevelBarMinX, self.gui.bgaBunkerFillLevelBarMaxWidth = self:getBarDimensionsFromPrecedingText(text);
else
self.gui.bgaBunkerFillLevelBarBorderLeftPosX, self.gui.bgaBunkerFillLevelBarMinX, self.gui.bgaBunkerFillLevelBarMaxWidth = self.gui.tankBarBorderLeftPosX, self.gui.tankBarMinX, self.gui.tankBarMaxWidth;
end;
-- BGA fermenter TS bar graph
local text = g_i18n:getText('BUNKERSILOS_BGA_FERMENTERTS'):format('00,00');
self.gui.bgaFermenterDrySubstanceBarBorderLeftPosX, self.gui.bgaFermenterDrySubstanceBarMinX, self.gui.bgaFermenterDrySubstanceBarMaxWidth = self:getBarDimensionsFromPrecedingText(text);
local maxDS, optimumDS = 0.16, 0.1;
local optimumRelativePct = optimumDS / maxDS;
self.gui.bgaFermenterDrySubstanceBarOptimumPosX = self.gui.bgaFermenterDrySubstanceBarMinX + (self.gui.bgaFermenterDrySubstanceBarMaxWidth * optimumRelativePct) - (self.gui.barBorderWidth * 0.5);
-- BGA bunker bonus fill level bar graph
local text = ("%s: 100'000/100'000 %s (100.0%%)"):format(g_i18n:getText('BUNKERSILOS_BGA_BUNKERBONUS'), g_i18n:getText('fluid_unit_short'));
self.gui.bgaBunkerBonusFillLevelBarBorderLeftPosX, self.gui.bgaBunkerBonusFillLevelBarMinX, self.gui.bgaBunkerBonusFillLevelBarMaxWidth = self:getBarDimensionsFromPrecedingText(text);
self.gui.background:setPosition(self.gui.x1, self.gui.y1);
self.gui.effects:setPosition(self.gui.x1, self.gui.y1);
-- x1 x2 y1 y2
self.gui.topSectionArea = { self.gui.contentMinX, self.gui.contentMaxX, self.gui.lines[6], self.gui.lines[1] + self.gui.buttonGfxHeight };
self.gui.tankArea = { self.gui.contentMinX, self.gui.contentMaxX, self.gui.lines[8], self.gui.lines[7] + self.gui.buttonGfxHeight };
self.gui.topIconsPosX = {
[1] = self.gui.contentMaxX - self.gui.buttonGfxWidth * 3.2;
[2] = self.gui.contentMaxX - self.gui.buttonGfxWidth * 2.2;
[3] = self.gui.contentMaxX - self.gui.buttonGfxWidth;
};
self.gui.mouseWheel:setPosition(self.gui.topIconsPosX[1], self.gui.upperLineY);
self.gui.warning:setPosition(self.gui.topIconsPosX[2], self.gui.upperLineY);
self.gui.closeHudButton:setPosition(self.gui.topIconsPosX[3], self.gui.upperLineY);
-- set movingPlanes box position
for _,silo in ipairs(self.silos) do
for i,mp in ipairs(silo.movingPlanes) do
mp.boxX = self.gui.contentMinX + (i-1)*(silo.boxWidth + self.gui.boxMargin);
mp.boxCenterX = mp.boxX + silo.boxWidth * 0.5;
end;
end;
-- set BGAs graph position
for _,bga in ipairs(self.bgas) do
if bga.tsGraph then
bga.tsGraph.left = self.gui.contentMinX;
bga.tsGraph.bottom = self.gui.lines[6];
end;
-- reinitialize fill level bars position calculation
bga.bunkerCapacity = nil;
bga.bonusCapacity = nil;
end;
-- set liquid manure tanks bar position
for _,tank in ipairs(self.tanks) do
tank.fillLevelTxtPosX = self.gui.contentMinX + getTextWidth(self.gui.fontSize, tank.name .. ':') + self.gui.buttonGfxWidth;
end;
-- set nav buttons position
if self.numBgas > 1 then
self.gui.changeBgaNegButton:setPosition(self.gui.contentMinX, self.gui.lines[1]);
self.gui.changeBgaPosButton:setPosition(self.gui.contentMaxX - self.gui.buttonGfxWidth, self.gui.lines[1]);
end;
if self.numSilos > 1 then
self.gui.changeSiloNegButton:setPosition(self.gui.contentMinX, self.gui.lines[1]);
self.gui.changeSiloPosButton:setPosition(self.gui.contentMaxX - self.gui.buttonGfxWidth, self.gui.lines[1]);
end;
if self.numTanks > 1 then
self.gui.changeTankNegButton:setPosition(self.gui.contentMinX, self.gui.lines[7]);
self.gui.changeTankPosButton:setPosition(self.gui.contentMaxX - self.gui.buttonGfxWidth, self.gui.lines[7]);
end;
-- set top section selection buttons position
local margin = self.gui.buttonGfxWidth;
-- BGA button
local textWidth = getTextWidth(self.gui.fontSize, g_i18n:getText('BUNKERSILOS_BGA'));
self.gui.topSectionBgaTextX = self.gui.topIconsPosX[1] - margin - textWidth;
local iconX = self.gui.topSectionBgaTextX - self.gui.buttonGfxWidth * 1.25;
local buttonWidth = self.gui.buttonGfxWidth + textWidth;
self.gui.topSectionButtonBga:setPosition(iconX, self.gui.upperLineY);
-- Silos button
textWidth = getTextWidth(self.gui.fontSize, g_i18n:getText('BUNKERSILOS_SILOS'));
self.gui.topSectionSilosTextX = iconX - margin * 0.75 - textWidth;
iconX = self.gui.topSectionSilosTextX - self.gui.buttonGfxWidth * 1.25;
buttonWidth = self.gui.buttonGfxWidth + textWidth;
self.gui.topSectionButtonSilos:setPosition(iconX, self.gui.upperLineY);
end;
function BunkerSilosHud:moveGui(dx, dy)
if dx ~= 0 or dy ~= 0 then
self.gui.x1 = getFullPx(Utils.clamp(self.gui.x1 + dx, 0, 1 - self.gui.width), 'x');
self.gui.y1 = getFullPx(Utils.clamp(self.gui.y1 + dy, 0, 1 - self.gui.height), 'y');
self:setGuiPositions();
end;
self.gui.background:setColor(1, 1, 1, 1);
self.gui.background.hasDragDropColor = false;
self.gui.background.origPos = nil;
self.gui.dragDropMouseDown = nil;
end;
function BunkerSilosHud:dragDropUpdateBackground(dx, dy)
if not self.gui.background.hasDragDropColor then
self.gui.background:setColor(1, 0, 0, 0.6);
self.gui.background.hasDragDropColor = true;
end;
self.gui.background:setPosition(self.gui.background.origPos[1] + dx, self.gui.background.origPos[2] + dy);
end;
function BunkerSilosHud:cancelMouseEvent(superFunc, posX, posY, isDown, isUp, button)
if BunkerSilosHud.hasMouseCursorActive then
local x, y = InputBinding.mouseMovementX, InputBinding.mouseMovementY;
local origIsUp, origIsDown = isUp, isDown;
InputBinding.mouseMovementX, InputBinding.mouseMovementY = 0, 0;
isUp, isDown = false, false;
superFunc(self, posX, posY, isDown, isUp, button);
InputBinding.mouseMovementX, InputBinding.mouseMovementY = x, y;
isUp, isDown = origIsUp, origIsDown;
else
superFunc(self, posX, posY, isDown, isUp, button);
end;
end;
function BunkerSilosHud:cancelZoom(superFunc, offset)
if BunkerSilosHud.hasMouseCursorActive and BunkerSilosHud.canScroll and (abs(offset) == 0.6 or abs(offset) == 0.75) then -- NOTE: make sure user zoomed with the mouse wheel: 0.6 (default), 0.75 (InteractiveControl)
return;
end;
superFunc(self, offset);
end;
function BunkerSilosHud:deleteMap()
-- delete overlays
self:deleteOverlay(self.gui.background);
self:deleteOverlay(self.gui.effects);
self:deleteOverlay(self.gui.mouseWheel);
self:deleteOverlay(self.gui.warning);
-- delete overlayIds
for _,o in ipairs( { 'movingPlanesOverlayId', 'movingPlanesNonCompactedOverlayId', 'barOverlayId', 'barSpecialOverlayId', 'barBgOverlayId' } ) do
if self[o] then
delete(self[o]);
end;
end;
-- delete buttons
for _,button in ipairs(self.gui.buttons) do
button:delete();
end;
self.gui.buttons = {};
-- delete BGA graphs
for _,data in ipairs(self.bgas) do
if data.tsGraph then
data.tsGraph:delete();
end;
data.tsGraph = nil;
end;
-- delete current colors
for _,c in ipairs({ 'barColor', 'barSpecialColor', 'barBgColor', 'movingPlanesColor', 'movingPlanesNonCompactedColor' }) do
self[c] = nil;
end;
self.initialized = false;
end;
function BunkerSilosHud:setHudState(state, dontHideMouseCursor)
self.gui.hudState = state;
BunkerSilosHud.hasMouseCursorActive = state == BunkerSilosHud.HUDSTATE_INTERACTIVE;
-- open
if state == BunkerSilosHud.HUDSTATE_INTERACTIVE then
InputBinding.setShowMouseCursor(true);
self.helpButtonText = g_i18n:getText('BUNKERSILOS_HIDEMOUSE');
-- hide mouse
elseif state == BunkerSilosHud.HUDSTATE_ACTIVE then
BunkerSilosHud.canScroll = false;
InputBinding.setShowMouseCursor(false);
self.helpButtonText = g_i18n:getText('BUNKERSILOS_HIDEHUD');
-- close
elseif state == BunkerSilosHud.HUDSTATE_CLOSED then
for _,button in pairs(self.gui.buttons) do
button.isClicked = false;
button.isHovered = false;
end;
if not dontHideMouseCursor then
InputBinding.setShowMouseCursor(false);
end;
BunkerSilosHud.canScroll = false;
self.gui.warning.curBlinkTime = nil;
self.helpButtonText = g_i18n:getText('BUNKERSILOS_SHOWHUD');
end;
end;
function BunkerSilosHud:setTopSection(sectionRef)
if self.gui.activeTopSection == sectionRef then return; end;
self.gui.activeTopSection = sectionRef;
local isSilosSection = sectionRef == BunkerSilosHud.TOPSECTION_SILOS;
local isBgaSection = sectionRef == BunkerSilosHud.TOPSECTION_BGA;
if isSilosSection then
self:setOverlayUVsPx(self.gui.topSectionButtonBga.overlay, self.gui.iconUVs.radioDeselected, self.gui.iconFileSize[1], self.gui.iconFileSize[2]);
self:setOverlayUVsPx(self.gui.topSectionButtonSilos.overlay, self.gui.iconUVs.radioSelected, self.gui.iconFileSize[1], self.gui.iconFileSize[2]);
elseif isBgaSection then
self:setOverlayUVsPx(self.gui.topSectionButtonBga.overlay, self.gui.iconUVs.radioSelected, self.gui.iconFileSize[1], self.gui.iconFileSize[2]);
self:setOverlayUVsPx(self.gui.topSectionButtonSilos.overlay, self.gui.iconUVs.radioDeselected, self.gui.iconFileSize[1], self.gui.iconFileSize[2]);
end;
if self.gui.changeSiloNegButton and self.gui.changeSiloPosButton then
self.gui.changeSiloNegButton:setVisible(isSilosSection);
self.gui.changeSiloPosButton:setVisible(isSilosSection);
end;
if self.gui.changeBgaNegButton and self.gui.changeBgaPosButton then
self.gui.changeBgaNegButton:setVisible(isBgaSection);
self.gui.changeBgaPosButton:setVisible(isBgaSection);
end;
end;
function BunkerSilosHud:changeBga(move)
self.activeBga = self:loopNumberSequence(self.activeBga + move, 1, self.numBgas);
end;
function BunkerSilosHud:changeSilo(move)
self.activeSilo = self:loopNumberSequence(self.activeSilo + move, 1, self.numSilos);
end;
function BunkerSilosHud:changeTank(move)
self.activeTank = self:loopNumberSequence(self.activeTank + move, 1, self.numTanks);
end;
function BunkerSilosHud:loopNumberSequence(n, minN, maxN)
if n > maxN then
return minN;
elseif n < minN then
return maxN;
end;
return n;
end;
function BunkerSilosHud:update(dt)
if g_currentMission.paused or g_gui.currentGui ~= nil then return; end;
if InputBinding.hasEvent(InputBinding.BUNKERSILOS_HUD) then
self:setHudState(self:loopNumberSequence(self.gui.hudState + 1, BunkerSilosHud.HUDSTATE_INTERACTIVE, BunkerSilosHud.HUDSTATE_CLOSED));
end;
if g_currentMission.showHelpText and (self.inputModifier == nil or Input.isKeyPressed(self.inputModifier)) then
g_currentMission:addHelpButtonText(self.helpButtonText, InputBinding.BUNKERSILOS_HUD);
end;
end;
function BunkerSilosHud:draw()
if self.gui.hudState == BunkerSilosHud.HUDSTATE_CLOSED or g_currentMission.paused or g_gui.currentGui ~= nil or g_currentMission.inGameMessage.currentMessage ~= nil then return; end;
local g = self.gui;
g.background:render();
if g.dragDropMouseDown and g.background.hasDragDropColor then -- drag & drop -> only render background
return;
end;
setTextColor(unpack(g.colors.text));
setTextBold(true);
renderText(g.contentMinX, g.lines[0], g.fontSizeTitle, g_i18n:getText('BUNKERSILOS_TITLE'));
setTextBold(false);
if BunkerSilosHud.canScroll then