-
Notifications
You must be signed in to change notification settings - Fork 25
/
UniversalAutoloadInstaller.lua
2294 lines (1948 loc) · 86.6 KB
/
UniversalAutoloadInstaller.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
-- ============================================================= --
-- Universal Autoload MOD - MANAGER
-- ============================================================= --
-- manager
UniversalAutoloadManager = {}
addModEventListener(UniversalAutoloadManager)
UniversalAutoloadManager.DEBUG_STEPS = nil
-- specialisation
g_specializationManager:addSpecialization('universalAutoload', 'UniversalAutoload', Utils.getFilename('UniversalAutoload.lua', g_currentModDirectory), "")
TypeManager.validateTypes = Utils.appendedFunction(TypeManager.validateTypes, function(self)
if self.typeName == "vehicle" then
print("UAL - VALIDATE TYPES")
UniversalAutoloadManager.injectSpecialisation()
end
end)
local ROOT = getmetatable(_G).__index
-- DETECT SOLD LOGS
ROOT.delete = Utils.appendedFunction(ROOT.delete, function(nodeId)
if UniversalAutoload.SPLITSHAPES_LOOKUP[nodeId] then
local object = UniversalAutoload.SPLITSHAPES_LOOKUP[nodeId]
UniversalAutoload.clearPalletFromAllVehicles(nil, object)
UniversalAutoload.SPLITSHAPES_LOOKUP[nodeId] = nil
end
end)
-- DETECT SPAWNED LOGS
ROOT.addToPhysics = Utils.appendedFunction(ROOT.addToPhysics, function(nodeId)
if nodeId ~= 0 and nodeId ~= nil then
if getRigidBodyType(nodeId) == RigidBodyType.DYNAMIC and getSplitType(nodeId) ~= 0 then
if not UniversalAutoload.createdLogId and UniversalAutoload.createdTreeId and nodeId > UniversalAutoload.createdTreeId then
UniversalAutoload.createdLogId = nodeId
end
end
end
end)
-- DETECT CUT LOGS
SplitShapeUtil.splitShape = Utils.appendedFunction(SplitShapeUtil.splitShape, function(nodeId)
if UniversalAutoload.SPLITSHAPES_LOOKUP[nodeId] then
local object = UniversalAutoload.SPLITSHAPES_LOOKUP[nodeId]
UniversalAutoload.clearPalletFromAllVehicles(nil, object)
UniversalAutoload.SPLITSHAPES_LOOKUP[nodeId] = nil
end
end)
-- Create a new store pack to group all UAL supported vehicles
g_storeManager:addModStorePack("UNIVERSALAUTOLOAD", g_i18n:getText("configuration_universalAutoload", g_currentModName), "icons/storePack_ual.dds", g_currentModDirectory)
-- external classes
source(UniversalAutoload.path .. "scripts/BoundingBox.lua")
source(UniversalAutoload.path .. "scripts/LoadingVolume.lua")
source(UniversalAutoload.path .. "gui/ModSettingsMenu.lua")
source(UniversalAutoload.path .. "gui/ShopConfigMenuUALSettings.lua")
-- class variables
UniversalAutoload.userSettingsFile = "modSettings/UniversalAutoload.xml"
UniversalAutoload.SHOP_ICON = UniversalAutoload.path .. "icons/shop_icon.dds"
-- class tables
UniversalAutoload.ACTIONS = {
["TOGGLE_LOADING"] = "UNIVERSALAUTOLOAD_TOGGLE_LOADING",
["UNLOAD_ALL"] = "UNIVERSALAUTOLOAD_UNLOAD_ALL",
["TOGGLE_TIPSIDE"] = "UNIVERSALAUTOLOAD_TOGGLE_TIPSIDE",
["TOGGLE_FILTER"] = "UNIVERSALAUTOLOAD_TOGGLE_FILTER",
["TOGGLE_HORIZONTAL"] = "UNIVERSALAUTOLOAD_TOGGLE_HORIZONTAL",
["CYCLE_MATERIAL_FW"] = "UNIVERSALAUTOLOAD_CYCLE_MATERIAL_FW",
["CYCLE_MATERIAL_BW"] = "UNIVERSALAUTOLOAD_CYCLE_MATERIAL_BW",
["SELECT_ALL_MATERIALS"] = "UNIVERSALAUTOLOAD_SELECT_ALL_MATERIALS",
["CYCLE_CONTAINER_FW"] = "UNIVERSALAUTOLOAD_CYCLE_CONTAINER_FW",
["CYCLE_CONTAINER_BW"] = "UNIVERSALAUTOLOAD_CYCLE_CONTAINER_BW",
["SELECT_ALL_CONTAINERS"] = "UNIVERSALAUTOLOAD_SELECT_ALL_CONTAINERS",
-- ["TOGGLE_BELTS"] = "UNIVERSALAUTOLOAD_TOGGLE_BELTS",
-- ["TOGGLE_DOOR"] = "UNIVERSALAUTOLOAD_TOGGLE_DOOR",
-- ["TOGGLE_CURTAIN"] = "UNIVERSALAUTOLOAD_TOGGLE_CURTAIN",
["TOGGLE_SHOW_DEBUG"] = "UNIVERSALAUTOLOAD_TOGGLE_SHOW_DEBUG",
["TOGGLE_SHOW_LOADING"] = "UNIVERSALAUTOLOAD_TOGGLE_SHOW_LOADING",
["TOGGLE_BALE_COLLECTION"] = "UNIVERSALAUTOLOAD_TOGGLE_BALE_COLLECTION",
}
UniversalAutoload.WARNINGS = {
[1] = "warning_UNIVERSALAUTOLOAD_CLEAR_UNLOADING_AREA",
[2] = "warning_UNIVERSALAUTOLOAD_NO_OBJECTS_FOUND",
[3] = "warning_UNIVERSALAUTOLOAD_UNABLE_TO_LOAD_OBJECT_FULL",
[4] = "warning_UNIVERSALAUTOLOAD_UNABLE_TO_LOAD_OBJECT_EMPTY",
[5] = "warning_UNIVERSALAUTOLOAD_NO_LOADING_UNLESS_STATIONARY",
}
UniversalAutoload.WARNINGS_BY_NAME = {
["CLEAR_UNLOADING_AREA"] = 1,
["NO_OBJECTS_FOUND"] = 2,
["UNABLE_TO_LOAD_FULL"] = 3,
["UNABLE_TO_LOAD_EMPTY"] = 4,
["NO_LOADING_UNLESS_STATIONARY"] = 5,
}
UniversalAutoload.CONTAINERS = {
[1] = "ALL",
[2] = "EURO_PALLET",
[3] = "BIGBAG_PALLET",
[4] = "LIQUID_TANK",
[5] = "BIGBAG",
[6] = "BALE",
[7] = "LOGS",
}
-- DEFINE DEFAULTS FOR CONTAINER TYPES
-- UniversalAutoload.ALL = { sizeX = 1.250, sizeY = 0.850, sizeZ = 0.850 }
-- UniversalAutoload.EURO_PALLET = { sizeX = 1.250, sizeY = 0.790, sizeZ = 0.850 }
-- UniversalAutoload.BIGBAG_PALLET = { sizeX = 1.525, sizeY = 1.075, sizeZ = 1.200 }
-- UniversalAutoload.LIQUID_TANK = { sizeX = 1.433, sizeY = 1.500, sizeZ = 1.415 }
-- UniversalAutoload.BIGBAG = { sizeX = 1.050, sizeY = 1.666, sizeZ = 0.866, neverStack=true }
-- UniversalAutoload.BALE = { isBale=true }
UniversalAutoload.VEHICLES = {} -- actual vehicles currently in game
UniversalAutoload.VEHICLE_TYPES = {} -- vehicleTypes with autoload spec
UniversalAutoload.LOADING_TYPES = {} -- known container object types
UniversalAutoload.GLOBAL_DEFAULTS = {
{id="showDebug", default=false, valueType="BOOL", key="#showDebug"}, --Show the full graphical debugging display for all vehicles in game
{id="highPriority", default=true, valueType="BOOL", key="#highPriority"}, --Apply high priority to all UAL key bindings in the F1 menu
{id="disableAutoStrap", default=false, valueType="BOOL", key="#disableAutoStrap"}, --Disable the automatic application of tension belts
{id="pricePerLog", default=0, valueType="FLOAT", key="#pricePerLog"}, --The price charged for each auto-loaded log (default is zero)
{id="pricePerBale", default=0, valueType="FLOAT", key="#pricePerBale"}, --The price charged for each auto-loaded bale (default is zero)
{id="pricePerPallet", default=0, valueType="FLOAT", key="#pricePerPallet"}, --The price charged for each auto-loaded pallet (default is zero)
{id="minLogLength", default=0, valueType="FLOAT", key="#minLogLength"}, --The global minimum length for logs that will be autoloaded (default is zero)
}
UniversalAutoload.OPTIONS_DEFAULTS = {
{id="autoloadDisabled", default=false, valueType="BOOL", key="#autoloadDisabled"}, --If autoload features are disabled for this trailer
{id="isBoxTrailer", default=false, valueType="BOOL", key="#isBoxTrailer"}, --If trailer is enclosed with a rear door
{id="isLogTrailer", default=false, valueType="BOOL", key="#isLogTrailer"}, --If trailer is a logging trailer - will load only logs, dropped from above
{id="isBaleTrailer", default=false, valueType="BOOL", key="#isBaleTrailer"}, --If trailer should use an automatic bale collection mode
{id="isBaleProcessor", default=false, valueType="BOOL", key="#isBaleProcessor"}, --If trailer should consume bales (e.g. TMR Mixer or Straw Blower)
{id="isCurtainTrailer", default=false, valueType="BOOL", key="#isCurtainTrailer"}, --Automatically detect the available load side (if the trailer has curtain sides)
{id="enableRearLoading", default=false, valueType="BOOL", key="#enableRearLoading"}, --Use the automatic rear loading trigger
{id="enableSideLoading", default=false, valueType="BOOL", key="#enableSideLoading"}, --Use the automatic side loading triggers
{id="noLoadingIfFolded", default=false, valueType="BOOL", key="#noLoadingIfFolded"}, --Prevent loading when folded
{id="noLoadingIfUnfolded", default=false, valueType="BOOL", key="#noLoadingIfUnfolded"}, --Prevent loading when unfolded
{id="noLoadingIfCovered", default=false, valueType="BOOL", key="#noLoadingIfCovered"}, --Prevent loading when covered
{id="noLoadingIfUncovered", default=false, valueType="BOOL", key="#noLoadingIfUncovered"}, --Prevent loading when uncovered
{id="rearUnloadingOnly", default=false, valueType="BOOL", key="#rearUnloadingOnly"}, --Use rear unloading zone only (not side zones)
{id="frontUnloadingOnly", default=false, valueType="BOOL", key="#frontUnloadingOnly"}, --Use front unloading zone only (not side zones)
{id="horizontalLoading", default=false, valueType="BOOL", key="#horizontalLoading"}, --Start with horizontal loading enabled (can be toggled if key is bound)
{id="disableAutoStrap", default=false, valueType="BOOL", key="#disableAutoStrap"}, --Disable the automatic application of tension belts
{id="disableHeightLimit", default=false, valueType="BOOL", key="#disableHeightLimit"}, --Disable the density based stacking height limit
{id="zonesOverlap", default=false, valueType="BOOL", key="#zonesOverlap"}, --Flag to identify when the loading areas overlap each other
{id="offsetRoot", default=nil, valueType="STRING", key="#offsetRoot"}, --Vehicle i3d node that area offsets are relative to
{id="minLogLength", default=0, valueType="FLOAT", key="#minLogLength"}, --The minimum length for logs that will be autoloaded (default is zero)
}
UniversalAutoload.LOADING_AREA_DEFAULTS = {
{id="offset", default="0 0 0", valueType="VECTOR_TRANS", key="#offset"}, --Offset to the centre of the loading area
{id="offsetRoot", default=nil, valueType="STRING", key="#offsetRoot"}, --Vehicle i3d node that this area offset is relative to
{id="width", default=0, valueType="FLOAT", key="#width"}, --Width of the loading area
{id="length", default=0, valueType="FLOAT", key="#length"}, --Length of the loading area
{id="height", default=0, valueType="FLOAT", key="#height"}, --Height of the loading area
{id="baleHeight", default=nil, valueType="FLOAT", key="#baleHeight"}, --Height of the loading area for BALES only
{id="widthAxis", default=nil, valueType="STRING", key="#widthAxis"}, --Axis name to extend width of the loading area
{id="lengthAxis", default=nil, valueType="STRING", key="#lengthAxis"}, --Axis name to extend length of the loading area
{id="heightAxis", default=nil, valueType="STRING", key="#heightAxis"}, --Axis name to extend height of the loading area
{id="offsetFrontAxis", default=nil, valueType="STRING", key="#offsetFrontAxis"}, --Axis name to adjust the front position of the loading area
{id="offsetRearAxis", default=nil, valueType="STRING", key="#offsetRearAxis"}, --Axis name to adjust the rear position of the loading area
{id="reverseWidthAxis", default=false, valueType="BOOL", key="#reverseWidthAxis"}, --Reverses direction of width extension if true
{id="reverseLengthAxis", default=false, valueType="BOOL", key="#reverseLengthAxis"}, --Reverses direction of length extension if true
{id="reverseHeightAxis", default=false, valueType="BOOL", key="#reverseHeightAxis"}, --Reverses direction of height extension if true
{id="noLoadingIfFolded", default=false, valueType="BOOL", key="#noLoadingIfFolded"}, --Prevent loading when folded (for this area only)
{id="noLoadingIfUnfolded", default=false, valueType="BOOL", key="#noLoadingIfUnfolded"}, --Prevent loading when unfolded (for this area only)
{id="noLoadingIfCovered", default=false, valueType="BOOL", key="#noLoadingIfCovered"}, --Prevent loading when covered (for this area only)
{id="noLoadingIfUncovered", default=false, valueType="BOOL", key="#noLoadingIfUncovered"}, --Prevent loading when uncovered (for this area only)
}
UniversalAutoload.CONFIG_DEFAULTS = {
{id="selectedConfigs", default="ALL", valueType="STRING", key="#selectedConfigs"}, --Selected Configuration Names
{id="useConfigName", default=nil, valueType="STRING", key="#useConfigName"}, --Specific configuration to be used for selected configs
{
key = ".loadingArea(?)",
name = "loadingArea",
data = UniversalAutoload.LOADING_AREA_DEFAULTS,
},
{
key = ".options",
name = "options",
data = UniversalAutoload.OPTIONS_DEFAULTS,
},
}
UniversalAutoload.VEHICLE_DEFAULTS = {
{id="configFileName", default=nil, valueType="STRING", key="#configFileName"}, --Vehicle config file xml full path - used to identify supported vehicles
{
key = ".configuration(?)",
name = "spec",
data = UniversalAutoload.CONFIG_DEFAULTS,
},
}
UniversalAutoload.SAVEGAME_STATE_DEFAULTS = {
{id="tipside", default="none", valueType="STRING", key="#tipside"}, --Last used tip side
{id="loadside", default="both", valueType="STRING", key="#loadside"}, --Last used load side
{id="loadWidth", default=0, valueType="FLOAT", key="#loadWidth"}, --Last used load width
{id="loadLength", default=0, valueType="FLOAT", key="#loadLength"}, --Last used load length
{id="loadHeight", default=0, valueType="FLOAT", key="#loadHeight"}, --Last used load height
{id="actualWidth", default=0, valueType="FLOAT", key="#actualWidth"}, --Last used expected load width
{id="actualLength", default=0, valueType="FLOAT", key="#actualLength"}, --Last used complete load length
{id="layerCount", default=0, valueType="INT", key="#layerCount"}, --Number of layers that are currently loaded
{id="layerHeight", default=0, valueType="FLOAT", key="#layerHeight"}, --Total height of the currently loaded layers
{id="nextLayerHeight", default=0, valueType="FLOAT", key="#nextLayerHeight"}, --Height for the next layer (highest point in previous layer)
{id="lastLoadLength", default=0, valueType="FLOAT", key="#lastLoadLength"}, --Length of the last loaded object
{id="loadAreaIndex", default=1, valueType="INT", key="#loadAreaIndex"}, --Last used load area
{id="materialIndex", default=1, valueType="INT", key="#materialIndex"}, --Last used material type
{id="containerIndex", default=1, valueType="INT", key="#containerIndex"}, --Last used container type
{id="loadingFilter", default=false, valueType="BOOL", key="#loadingFilter"}, --TRUE=Load full pallets only; FALSE=Load any pallets
{id="useHorizontalLoading", default=false, valueType="BOOL", key="#useHorizontalLoading"}, --Last used horizontal loading state
{id="baleCollectionMode", default=false, valueType="BOOL", key="#baleCollectionMode"}, --Enable manual toggling of the automatic bale collection mode
}
function iterateDefaultsTable(tbl, parentKey, currentKey, currentValue, action)
parentKey = parentKey or ""
currentKey = currentKey or ""
action = action or function(k, v, parentKey, currentKey, currentValue, finalValue)
if debugSchema then print(" " .. currentKey .. ": " .. tostring(finalValue)) end
end
for k, v in pairs(tbl) do
if type(v) == "table" then
local newCurrentKey = currentKey
if v.key then
newCurrentKey = newCurrentKey .. v.key
end
local newCurrentValue = currentValue
if v.id ~= nil then
local finalValue = newCurrentValue and newCurrentValue[v.id] or v.default
action(k, v, parentKey, newCurrentKey, newCurrentValue, finalValue)
end
if v.data then
iterateDefaultsTable(v.data, parentKey, newCurrentKey, newCurrentValue, action)
end
end
end
end
print("GLOBAL_DEFAULTS") iterateDefaultsTable(UniversalAutoload.GLOBAL_DEFAULTS)
print("VEHICLE_DEFAULTS") iterateDefaultsTable(UniversalAutoload.VEHICLE_DEFAULTS)
print("SAVEGAME_STATE_DEFAULTS") iterateDefaultsTable(UniversalAutoload.SAVEGAME_STATE_DEFAULTS)
function UniversalAutoloadManager.openUserSettingsXMLFile(xmlFilename)
local xmlFilename = xmlFilename or Utils.getFilename(UniversalAutoload.userSettingsFile, getUserProfileAppPath())
local xmlFile = XMLFile.loadIfExists("settings", xmlFilename, UniversalAutoload.xmlSchema)
if not xmlFile then
print("Creating NEW settings file " .. xmlFilename)
xmlFile = XMLFile.create("settings", xmlFilename, "universalAutoload", UniversalAutoload.xmlSchema)
end
return xmlFile
end
--
function UniversalAutoloadManager.getVehicleConfigFromSettingsXML(configKey, xmlFile)
if not configKey then
print("configuration key required for getVehicleConfigFromSettingsXML")
return
end
local shouldCloseFile = not xmlFile and true
local xmlFile = xmlFile or UniversalAutoloadManager.openUserSettingsXMLFile()
if xmlFile then
local function readSettingFromFile(k, v, parentKey, currentKey, currentValue, finalValue)
if currentKey and currentValue and v.id then
if v.valueType == "VECTOR_TRANS" then
currentValue[v.id] = xmlFile:getValue(currentKey, v.default, true)
else
currentValue[v.id] = xmlFile:getValue(currentKey, v.default)
end
-- print(" << " .. tostring(currentKey) .. " = " .. tostring(currentValue[v.id]))
end
end
local config = {}
config.selectedConfigs = xmlFile:getValue(configKey.."#selectedConfigs", "ALL")
config.useConfigName = xmlFile:getValue(configKey.."#useConfigName", nil)
iterateDefaultsTable(UniversalAutoload.OPTIONS_DEFAULTS, "", configKey..".options", config, readSettingFromFile)
local j = 1
local hasBaleHeight = false
local loadingArea = {}
while true do
local loadAreaKey = string.format("%s.loadingArea(%d)", configKey, j-1)
if not xmlFile:hasProperty(loadAreaKey) then
break
end
loadingArea[j] = {}
iterateDefaultsTable(UniversalAutoload.LOADING_AREA_DEFAULTS, "", loadAreaKey, loadingArea[j], readSettingFromFile)
hasBaleHeight = hasBaleHeight or type(loadingArea[j].baleHeight) == 'number'
j = j + 1
end
config['loadArea'] = loadingArea
local isBaleTrailer = config.isBaleTrailer
local isBaleProcessor = config.isBaleProcessor
local horizontalLoading = config.horizontalLoading
config.horizontalLoading = horizontalLoading or isBaleTrailer or isBaleProcessor or false
config.isBaleTrailer = isBaleTrailer or hasBaleHeight
if shouldCloseFile then
xmlFile:delete()
end
return config
else
print("ERROR: no settings file " .. tostring(xmlFile))
end
end
--
function UniversalAutoloadManager.countConfigsInSettingsXML(xmlFile)
local shouldCloseFile = not xmlFile and true
local xmlFile = xmlFile or UniversalAutoloadManager.openUserSettingsXMLFile()
if xmlFile then
local i = 0
local counts = {}
while true do
local vehicleKey = string.format(UniversalAutoload.vehicleKey, i)
if not xmlFile:hasProperty(vehicleKey) then
break
end
local j = 0
while true do
local configKey = string.format(UniversalAutoload.vehicleConfigKey, i, j)
if not xmlFile:hasProperty(configKey) then
break
end
j = j + 1
end
i = i + 1
counts[i] = j
end
if shouldCloseFile then
xmlFile:delete()
end
return i, counts
end
end
--
function UniversalAutoloadManager.getConfigSettingsPosition(targetFileName, targetConfigId, xmlFile)
local targetConfigId = targetConfigId or UniversalAutoload.ALL
local shouldCloseFile = not xmlFile and true
local xmlFile = xmlFile or UniversalAutoloadManager.openUserSettingsXMLFile()
if xmlFile then
local i = 0
while true do
local vehicleKey = string.format(UniversalAutoload.vehicleKey, i)
if not xmlFile:hasProperty(vehicleKey) then
break
end
local configFileName = xmlFile:getValue(vehicleKey .. "#configFileName", "MISSING")
configFileName = UniversalAutoloadManager.cleanConfigFileName(configFileName)
targetFileName = UniversalAutoloadManager.cleanConfigFileName(targetFileName)
if tostring(configFileName):lower() == tostring(targetFileName):lower() then
print("targetConfigId: " .. tostring(targetConfigId))
local j = 0
while true do
local configKey = string.format(UniversalAutoload.vehicleConfigKey, i, j)
if not xmlFile:hasProperty(configKey) then
break
end
local selectedConfigs = xmlFile:getValue(configKey .. "#selectedConfigs", "MISSING")
print("selectedConfigs: " .. selectedConfigs)
local isMatchAny = selectedConfigs == UniversalAutoload.ALL
-- local hasPipeChar = tostring(targetConfigId):find("|")
-- local isMatchFull = hasPipeChar and targetConfigId == selectedConfigs
-- local isMatchPart = not hasPipeChar and tostring(targetConfigId):find(selectedConfigs)
if isMatchAny then
print("FOUND 'ALL' CONFIG AT #" .. j+1)
break
elseif selectedConfigs:find(tostring(targetConfigId)) then
print("FOUND SELECTED CONFIG AT #" .. j+1)
break
end
j = j + 1
end
return i, j
end
i = i + 1
end
if shouldCloseFile then
xmlFile:delete()
end
return nil, nil, i
end
end
--
function UniversalAutoloadManager.getVehicleConfigIndexesForSaving(exportSpec, configFileName, configId, xmlFile)
local index, subIndex, size = UniversalAutoloadManager.getConfigSettingsPosition(configFileName, configId, xmlFile)
if index then
local key = string.format(UniversalAutoload.vehicleKey, index)
local configKey = string.format(UniversalAutoload.vehicleConfigKey, index, subIndex)
local fileSelectedConfigs = xmlFile:getValue(configKey .. "#selectedConfigs")
if fileSelectedConfigs == UniversalAutoload.ALL and exportSpec.useConfigName then
print("SETTINGS FILE using: " .. fileSelectedConfigs)
print(" configId: " .. configId)
print(" useConfigName: " .. exportSpec.useConfigName)
end
print("UPDATE CONFIG #" .. index + 1 .. " == " .. configId .. " (#" ..subIndex + 1 .. ")")
while true do
local loadAreaKey = string.format("%s.loadingArea(%d)", configKey, 0)
if not xmlFile:hasProperty(loadAreaKey) then
break
end
xmlFile:removeProperty(loadAreaKey)
end
else
index = size or 0
subIndex = 0
print("INSERT CONFIG INDEX #" .. index)
local key = string.format(UniversalAutoload.vehicleKey, index)
xmlFile:setValue(key.."#configFileName", configFileName)
end
if exportSpec.useConfigName then
local key = string.format(UniversalAutoload.vehicleConfigKey, index, subIndex)
xmlFile:setValue(key.."#useConfigName", exportSpec.useConfigName)
end
print("USING CONFIG SUB-INDEX: #" .. subIndex .. " (" .. configId .. ")")
local key = string.format(UniversalAutoload.vehicleConfigKey, index, subIndex)
xmlFile:setValue(key.."#selectedConfigs", tostring(configId))
if exportSpec.useConfigName then
print("useConfigName: " .. tostring(exportSpec.useConfigName))
xmlFile:setValue(key.."#useConfigName", tostring(exportSpec.useConfigName))
end
if not UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName] then
UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName] = {}
end
if not UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName][configId] then
UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName][configId] = {}
end
return index, subIndex
end
--
function UniversalAutoloadManager.getVehicleConfigNames(vehicle)
local spec = vehicle and vehicle.spec_universalAutoload
if not spec or not vehicle.configFileName then
print("Invalid vehicle supplied: " .. tostring(vehicle))
return
end
local configFileName, selectedConfigs
local didReplaceUseConfigId = false
if spec.selectedConfigs and spec.configFileName then
print("WAS ALREADY SET WITH:")
selectedConfigs = spec.selectedConfigs
configFileName = spec.configFileName
if spec.replaceConfigId and spec.replaceConfigId ~= spec.selectedConfigs then
local CONFIGS = UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName]
CONFIGS[spec.replaceConfigId] = deepCopy(CONFIGS[spec.selectedConfigs])
CONFIGS[spec.selectedConfigs] = nil
selectedConfigs = spec.replaceConfigId
didReplaceUseConfigId = true
end
end
if not selectedConfigs or not configFileName then
print("FIND CORRECT SETTINGS FILE POSITION:")
configFileName = UniversalAutoloadManager.cleanConfigFileName(vehicle.configFileName)
selectedConfigs = UniversalAutoloadManager.getValidConfigurationId(vehicle)
spec.configFileName = configFileName
spec.selectedConfigs = selectedConfigs
end
print(" configFileName = " .. tostring(configFileName))
print(" selectedConfig = " .. tostring(selectedConfigs))
print(" useConfigName = " .. tostring(spec.useConfigName))
if didReplaceUseConfigId then
print(" *** REPLACED " .. spec.selectedConfigs .. " with " .. spec.replaceConfigId .. " for saving ***")
end
return configFileName, selectedConfigs
end
--
function UniversalAutoloadManager.saveVehicleConfigToSettingsXML(exportSpec, configFileName, configId)
if not exportSpec or not configFileName then
print("Invalid vehicle spec supplied: " .. tostring(configFileName))
return
end
local xmlFile = UniversalAutoloadManager.openUserSettingsXMLFile()
if xmlFile then
local function writeSettingToFile(k, v, parentKey, currentKey, currentValue, finalValue)
if currentKey and finalValue ~= nil then
if v.valueType == "VECTOR_TRANS" then
if type(finalValue) == "string" then
local vector = {}
for num in finalValue:gmatch("%S+") do
table.insert(vector, tonumber(num))
end
finalValue = vector
elseif type(finalValue) ~= "table" then
error("Unexpected type for VECTOR_TRANS: " .. tostring(finalValue))
end
end
if finalValue == v.default then
xmlFile:removeProperty(parentKey..currentKey)
else
print(" >> " .. tostring(currentKey) .. " = " .. tostring(finalValue))
if type(finalValue) == "table" and v.valueType == "VECTOR_TRANS" then
xmlFile:setValue(parentKey..currentKey, unpack(finalValue))
else
xmlFile:setValue(parentKey..currentKey, finalValue)
end
end
end
end
if exportSpec.loadArea and #exportSpec.loadArea > 0 then
print("SAVE TO SETTINGS FILE")
local index, subIndex = UniversalAutoloadManager.getVehicleConfigIndexesForSaving(exportSpec, configFileName, configId, xmlFile)
print("options:")
local configKey = string.format(UniversalAutoload.vehicleConfigKey, index, subIndex)
iterateDefaultsTable(UniversalAutoload.OPTIONS_DEFAULTS, configKey, ".options", exportSpec, writeSettingToFile)
print("loadingAreas:")
for j, loadArea in pairs(exportSpec.loadArea or {}) do
local loadAreaKey = string.format(".loadingArea(%d)", j-1)
iterateDefaultsTable(UniversalAutoload.LOADING_AREA_DEFAULTS, configKey, loadAreaKey, loadArea, writeSettingToFile)
end
xmlFile:save()
print("UPDATE CONFIG IN MEMORY - " .. configId)
local CONFIGS = UniversalAutoload.VEHICLE_CONFIGURATIONS
local config = CONFIGS[configFileName][configId]
for k, v in pairs(UniversalAutoload.OPTIONS_DEFAULTS) do
local id = v.id
config[id] = exportSpec[id] or v.default
end
config.loadArea = {}
for i, loadArea in (exportSpec.loadArea) do
config.loadArea[i] = deepCopy(exportSpec.loadArea[i])
end
config.configFileName = configFileName
config.selectedConfigs = configId
else
print("DID NOT SAVE SETTINGS - loading area was missing")
end
xmlFile:delete()
end
end
function UniversalAutoloadManager.importLocalConfigurations(forceOverwrite)
-- print("UAL - IMPORT CONFIGS")
local forceOverwrite = forceOverwrite or false
local userSettingsFile = Utils.getFilename(UniversalAutoload.userSettingsFile, getUserProfileAppPath())
if not fileExists(userSettingsFile) or forceOverwrite then
print("CREATING default settings file")
local defaultSettingsFile = Utils.getFilename("xml/UniversalAutoloadDefaults.xml", UniversalAutoload.path)
copyFile(defaultSettingsFile, userSettingsFile, forceOverwrite)
end
UniversalAutoloadManager.importGlobalSettings(userSettingsFile)
UniversalAutoloadManager.importVehicleConfigurations(userSettingsFile)
end
function UniversalAutoloadManager.consoleResetConfigurations()
-- print("UAL - RESET CONFIGS")
UniversalAutoloadManager.importLocalConfigurations(true)
print("UNIVERSAL AUTOLOAD: Configurations were RESET to defaults")
print("New configurations will be used for new vehicles, please restart game to apply to all vehicles")
end
--
function UniversalAutoloadManager.importGlobalSettings(xmlFilename)
-- print("UAL - IMPORT GLOBAL SETTINGS")
if g_currentMission:getIsServer() then
local xmlFile = UniversalAutoloadManager.openUserSettingsXMLFile(xmlFilename)
if xmlFile ~= 0 and xmlFile ~= nil then
print("IMPORT Universal Autoload global settings")
iterateDefaultsTable(UniversalAutoload.GLOBAL_DEFAULTS, UniversalAutoload.globalKey, "", UniversalAutoload,
function(k, v, parentKey, currentKey, currentValue, finalValue)
UniversalAutoload[v.id] = xmlFile:getValue(parentKey..currentKey, v.default)
print(" >> " .. tostring(v.id) .. ": " .. tostring(v.default))
end)
xmlFile:delete()
else
print("Universal Autoload - could not open global settings file")
end
else
print("Universal Autoload - global settings are only loaded for the server")
end
end
--
function UniversalAutoloadManager.importVehicleConfigurations(xmlFilename)
print("UAL - IMPORT VEHICLE CONFIGS")
UniversalAutoload.VEHICLE_CONFIGURATIONS = {}
local xmlFile = UniversalAutoloadManager.openUserSettingsXMLFile(xmlFilename)
if xmlFile then
local xmlWasCleaned = false
local i = 0
while true do
local vehicleKey = string.format(UniversalAutoload.vehicleKey, i)
if not xmlFile:hasProperty(vehicleKey) then
break
end
local configFileName = xmlFile:getValue(vehicleKey .. "#configFileName")
configFileName, removedPart = UniversalAutoloadManager.cleanConfigFileName(configFileName)
if removedPart ~= nil then
print("CLEANING CONFIG FILE NAME: " .. configFileName .. removedPart)
xmlFile:setValue(vehicleKey .. "#configFileName", configFileName)
print("... replaced with: " .. configFileName)
xmlWasCleaned = true
end
if UniversalAutoloadManager.getValidXmlName(configFileName) then
print(" [" .. i + 1 .. "] " .. configFileName)
local j = 0
while true do
local configKey = vehicleKey .. string.format(".configuration(%d)", j)
if not xmlFile:hasProperty(configKey) then
break
end
local configuration = UniversalAutoloadManager.getVehicleConfigFromSettingsXML(configKey, xmlFile)
if not configuration then
print("could not load UAL configuration for: " .. configKey)
end
if not UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName] then
-- print("ADDING SHOP ITEM " .. configFileName)
UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName] = {}
table.addElement(g_storeManager:getPackItems("UNIVERSALAUTOLOAD"), configFileName)
end
local configGroup = UniversalAutoload.VEHICLE_CONFIGURATIONS[configFileName]
local selectedConfigs = xmlFile:getValue(configKey.."#selectedConfigs", UniversalAutoload.ALL)
local useConfigName = xmlFile:getValue(configKey.."#useConfigName", nil)
if useConfigName == nil and tostring(selectedConfigs):find("|") then
configuration.originalSelectedConfigs = selectedConfigs
selectedConfigs = tostring(selectedConfigs):match("^(.-)|")
print(" *** SUGGEST REPAIRING CONFIG: '" .. configuration.originalSelectedConfigs
.. "' - using '" .. selectedConfigs .. "' OR specify useConfigName='design' ***")
end
if not configGroup[selectedConfigs] then
configuration.useConfigName = useConfigName
configuration.configFileName = configFileName
configuration.selectedConfigs = selectedConfigs
configGroup[selectedConfigs] = configuration
else
if UniversalAutoload.showDebug then print(" ALREADY EXISTS: "..configFileName.." ["..selectedConfigs.."]") end
end
print(" >> "..configFileName.." ["..selectedConfigs.."] ".. (useConfigName and ("(" .. useConfigName .. ")") or ""))
j = j + 1
end
else
if UniversalAutoload.showDebug then print(" NOT FOUND: " .. tostring(configFileName)) end
end
i = i + 1
end
if xmlWasCleaned then
xmlFile:save()
end
xmlFile:delete()
return i
end
end
function UniversalAutoloadManager.getValidConfigurationId(vehicle)
-- returns: configId, description
local spec = vehicle and vehicle.spec_universalAutoload
if not spec then return end
local item = g_storeManager:getItemByXMLFilename(vehicle.configFileName)
if not item then
print("could not get store item for " .. tostring(vehicle.configFileName))
return
end
local useConfigName = spec.useConfigName
local configName = useConfigName and vehicle.configurations[useConfigName] and tostring(vehicle.configurations[useConfigName]) or nil
local configurationSets = item.configurationSets or {}
if #configurationSets == 0 then
local fullConfigId = UniversalAutoload.ALL .. (configName and ("|" .. configName) or "")
return fullConfigId, "UNIQUE" .. (useConfigName and ("|" .. useConfigName) or "")
end
local bestMatch = { index = nil, count = 0, name = nil }
for i, config in ipairs(configurationSets) do
local count, match = 0, true
for k, v in pairs(config.configurations or {}) do
if vehicle.configurations[k] == v then
count = count + 1
else
match = false
end
end
if match then
local fullConfigId = i .. (configName and ("|" .. configName) or "")
return fullConfigId, config.name
elseif count > bestMatch.count then
bestMatch = { index = i, count = count, name = config.name }
end
end
if bestMatch.index then
local fullConfigId = bestMatch.index .. (configName and ("|" .. configName) or "")
return fullConfigId, bestMatch.name
end
end
function UniversalAutoloadManager.saveConfigurationToSettings(exportSpec, configFileName, configId, noEventSend)
print("UAL - SAVE CONFIGURATION TO SETTINGS")
if not exportSpec or not configFileName then
print("valid UAL spec is required to save settings")
return
end
if g_currentMission:getIsServer() then
print("EXPORT VEHICLE SETTINGS: " .. configFileName)
UniversalAutoloadManager.saveVehicleConfigToSettingsXML(exportSpec, configFileName, configId)
end
UniversalAutoload.UpdateDefaultSettingsEvent.sendEvent(exportSpec, configFileName, configId, noEventSend)
end
function UniversalAutoloadManager.exportVehicleConfigToServer()
if g_localPlayer and g_localPlayer.isClient then
print("SAVE SETTINGS FROM SHOP VEHICLE")
local shopVolume = UniversalAutoloadManager.shopConfig and UniversalAutoloadManager.shopConfig.loadingVolume
if not shopVolume or not shopVolume.bbs then
print("NOTHING TO SAVE: shopVolume or shopVolume.bbs is nil")
return
end
local exportVehicle = nil
if UniversalAutoloadManager.shopVehicle then
print("SHOP VEHICLE STILL EXISTS " .. UniversalAutoloadManager.shopVehicle.rootNode )
exportVehicle = UniversalAutoloadManager.shopVehicle
elseif UniversalAutoloadManager.lastShopVehicle then
print("WORKSHOP VEHICLE STILL EXISTS " .. UniversalAutoloadManager.lastShopVehicle.rootNode )
exportVehicle = UniversalAutoloadManager.lastShopVehicle
UniversalAutoloadManager.lastShopVehicle = nil
end
if exportVehicle and exportVehicle.configFileName then
if exportVehicle.spec_universalAutoload.autoloadDisabled then
print("Autoload is DISABLED for this vehicle")
end
print("..convert shop volume to loading area")
local exportSpec = exportVehicle.spec_universalAutoload
exportSpec.loadArea = {}
for i, boundingBox in (shopVolume.bbs) do
local s = boundingBox:getSize()
local o = boundingBox:getOffset()
exportSpec.loadArea[i] = {
width = s.x,
height = s.y,
length = s.z,
offset = {o.x, o.y-s.y/2, o.z},
}
end
local configFileName, configId = UniversalAutoloadManager.getVehicleConfigNames(exportVehicle)
UniversalAutoloadManager.saveConfigurationToSettings(exportSpec, configFileName, configId)
end
end
end
function UniversalAutoloadManager:onVehicleBuyEvent(errorCode, leaseVehicle, price)
if errorCode == BuyVehicleEvent.STATE_SUCCESS then
print("UAL - ON VEHICLE BUY EVENT " .. (leaseVehicle and "(leased)" or "(owned)"))
-- do nothing here for now..
-- UniversalAutoloadManager.saveShopConfiguration()
end
end
function UniversalAutoloadManager.getValidXmlName(ualConfigName)
if ualConfigName == nil then
return
end
local xmlFilename = ualConfigName
if g_storeManager:getItemByXMLFilename(xmlFilename) then
return xmlFilename
end
xmlFilename = g_modsDirectory .. ualConfigName
if g_storeManager:getItemByXMLFilename(xmlFilename) then
return xmlFilename
end
for i = 1, #g_dlcsDirectories do
local dlcsDir = g_dlcsDirectories[i].path
xmlFilename = dlcsDir .. ualConfigName
if g_storeManager:getItemByXMLFilename(xmlFilename) then
return xmlFilename
end
end
end
function UniversalAutoloadManager.cleanConfigFileName(configFileName)
if configFileName == nil then
return
end
if configFileName:find(g_modsDirectory) then
-- print("CLEANED MOD FILE NAME")
return configFileName:gsub(g_modsDirectory, ""), g_modsDirectory
end
for i = 1, #g_dlcsDirectories do
local dlcsDir = g_dlcsDirectories[i].path
if configFileName:find(dlcsDir) then
-- print("CLEANED DLC FILE NAME")
return configFileName:gsub(dlcsDir, ""), dlcsDir
end
end
return configFileName
end
function UniversalAutoloadManager.injectSpecialisation()
-- print("UAL - injectSpecialisation")
for typeName, vehicleType in pairs(g_vehicleTypeManager.types) do
if SpecializationUtil.hasSpecialization(TensionBelts, vehicleType.specializations)
and not SpecializationUtil.hasSpecialization(UniversalAutoload, vehicleType.specializations) then
g_vehicleTypeManager:addSpecialization(typeName, UniversalAutoload.name .. '.universalAutoload')
UniversalAutoload.VEHICLE_TYPES[typeName] = true
end
end
end
function UniversalAutoloadManager:ualInputCallback(target)
print("UAL SHOP INPUT CALLBACK")
UniversalAutoloadManager:onOpenSettingsEvent('UNIVERSALAUTOLOAD_SHOP_CONFIG', 1)
end
ShopConfigScreen.ualInputCallback = UniversalAutoloadManager.ualInputCallback
function UniversalAutoloadManager:onOpenSettingsEvent(actionName, inputValue, callbackState, isAnalog)
-- print("onOpenSettingsEvent")
if UniversalAutoloadManager.shopCongfigMenu then
g_gui:showDialog("ShopConfigMenuUALSettings")
end
end
function UniversalAutoloadManager:onEditLoadingAreaEvent(actionName, inputValue, callbackState, isAnalog)
-- print("onEditLoadingAreaEvent")
if UniversalAutoloadManager.shopVehicle then
local spec = UniversalAutoloadManager.shopVehicle.spec_universalAutoload
if spec and spec.isInsideShop then
local shopConfig = UniversalAutoloadManager.shopConfig or {}
UniversalAutoloadManager.pauseOnNextStep = nil
local ctrl = UniversalAutoloadManager.ctrlHeld
local shift = UniversalAutoloadManager.shiftHeld
if shift and ctrl then
spec.resetToDefault = true
else
shopConfig.enableEditing = shopConfig.enableEditing or false
shopConfig.enableEditing = not shopConfig.enableEditing
end
end
end
end
function UniversalAutoloadManager.onSetStoreItem()
if UniversalAutoloadManager.configButton then
UniversalAutoloadManager.configButton:setVisible(false)
end
if UniversalAutoloadManager.shopCongfigMenu then
UniversalAutoloadManager.shopCongfigMenu:setNewVehicle(nil)
end
end
ShopConfigScreen.setStoreItem = Utils.prependedFunction(ShopConfigScreen.setStoreItem, UniversalAutoloadManager.onSetStoreItem)
function UniversalAutoloadManager.onInputEvent(self, action, value, eventUsed)
if not eventUsed and action == InputAction.UNIVERSALAUTOLOAD_SHOP_CONFIG then
UniversalAutoloadManager:ualInputCallback(target)
eventUsed = true
end
return eventUsed
end
ShopConfigScreen.inputEvent = Utils.appendedFunction(ShopConfigScreen.inputEvent, UniversalAutoloadManager.onInputEvent)
function UniversalAutoloadManager.onBuyEvent(self, yes)
if yes == true then
UniversalAutoloadManager.exportVehicleConfigToServer()
end
end
ShopConfigScreen.onYesNoBuy = Utils.prependedFunction(ShopConfigScreen.onYesNoBuy, UniversalAutoloadManager.onBuyEvent)
ShopConfigScreen.onYesNoLease = Utils.prependedFunction(ShopConfigScreen.onYesNoLease, UniversalAutoloadManager.onBuyEvent)
-- ENABLE WORKSHOP CONFIG BUTTON FOR AUTOLOAD VEHICLES
ShopConfigScreen.getConfigurationCostsAndChanges = Utils.overwrittenFunction(ShopConfigScreen.getConfigurationCostsAndChanges,
function(self, superFunc, storeItem, vehicle, saleItem)
local basePrice, upgradePrice, hasChanges = superFunc(self, storeItem, vehicle, saleItem)
local spec = vehicle and vehicle.spec_universalAutoload
if spec and spec.isAutoloadAvailable then
hasChanges = true
end
return basePrice, upgradePrice, hasChanges
end)
function UniversalAutoloadManager.injectGlobalMenu()
print("UAL - injectGlobalMenu")
local function fixInGameMenu(frame, pageName, position, predicateFunc)
local inGameMenu = g_gui.screenControllers[InGameMenu] --g_inGameMenu
local aboveSettings = nil;
--DebugUtil.printTableRecursively(inGameMenu.pagingElement)
-- remove all to avoid warnings
for k, v in pairs({pageName}) do
inGameMenu.controlIDs[v] = nil
end
for i = 1, #inGameMenu.pagingElement.elements do
local child = inGameMenu.pagingElement.elements[i]
if child == inGameMenu["pageSettings"] then
aboveSettings = i;
print("--- found Settings position - "..tostring(i))
end
end
aboveSettings = aboveSettings or position
inGameMenu[pageName] = frame
inGameMenu.pagingElement:addElement(inGameMenu[pageName])
inGameMenu:exposeControlsAsFields(pageName)
for i = 1, #inGameMenu.pagingElement.elements do
local child = inGameMenu.pagingElement.elements[i]
if child == inGameMenu[pageName] then
table.remove(inGameMenu.pagingElement.elements, i)
table.insert(inGameMenu.pagingElement.elements, aboveSettings, child)
break
end
end
for i = 1, #inGameMenu.pagingElement.pages do
local child = inGameMenu.pagingElement.pages[i]
if child.element == inGameMenu[pageName] then