Repository navigation
Expand file tree
/
Copy pathFunctions.lua
More file actions
617 lines (530 loc) · 20 KB
/
Copy pathFunctions.lua
File metadata and controls
617 lines (530 loc) · 20 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
-- Vehicle Info
-- FUNCTIONS --
-- Toggle mouse true/false
function VInfo:toggleMouse(show)
if (g_gui:getIsGuiVisible()) then return; end;
if (type(show) == "boolean") then
g_inputBinding:setShowMouseCursor(show);
else
g_inputBinding:setShowMouseCursor(not g_inputBinding:getShowMouseCursor());
end
VInfo.isMouseActive = g_inputBinding:getShowMouseCursor();
end;
-- Switch to selected vehicle
function VInfo:SwitchToVehicle(vehicle)
if (g_currentMission.controlledVehicle == vehicle) then return; end;
g_currentMission:requestToEnterVehicle(vehicle);
VInfo:toggleMouse(false);
end;
-- Sort vehicle in the list
function VInfo:SortVehicle(targetVehicle)
table.remove(VInfo.vehicleList, VInfo.selectedVehicle.vi.id);
table.insert(VInfo.vehicleList, targetVehicle.vi.id, VInfo.selectedVehicle);
-- Set vehicle id's back to the current list order
for key, veh in ipairs(VInfo.vehicleList) do
veh.vi.id = key;
end;
-- Clear the selectedVehicle
VInfo.selectedVehicle = nil;
end;
-- Overwrite default TAB binding
function VInfo:overwriteDefaultTabBinding()
if not (string.len(g_gui.currentGuiName) > 0) then
local state = false;
if g_inputBinding.nameActions.SWITCH_VEHICLE.bindings[1] ~= nil and g_inputBinding.nameActions.SWITCH_VEHICLE.bindings[1].isActive ~= state then
local eventsTab = InputBinding.getEventsForActionName(g_inputBinding, "SWITCH_VEHICLE");
if eventsTab[1] ~= nil then
g_inputBinding:setActionEventActive(eventsTab[1].id, state);
end;
end;
if g_inputBinding.nameActions.SWITCH_VEHICLE_BACK.bindings[1] ~= nil and g_inputBinding.nameActions.SWITCH_VEHICLE_BACK.bindings[1].isActive ~= state then
local eventsShiftTab = InputBinding.getEventsForActionName(g_inputBinding, "SWITCH_VEHICLE_BACK");
if eventsShiftTab[1] ~= nil then
g_inputBinding:setActionEventActive(eventsShiftTab[1].id, state);
end;
end;
end;
end;
-- Draws Object on same line
function VInfo:updateObjectText(info, lineNumber)
local posX = VInfo.text.posX;
local posY = VInfo.text.posY;
local size = VInfo.settings.textSize[VInfo.text.size];
local lineWidth = 0;
-- Draw every object after eachother with seperator inbetween
for index, obj in pairs(info) do
if (type(obj) == "table") then
if (obj.text ~= nil) then
setTextAlignment(0);
local line = posY - (size * lineNumber);
local text = '';
local objWidth = 0;
-- [1] speed
if (index == 1) then
text = obj.text;
objWidth = (string.len(text) < 8) and size*2 or getTextWidth(size, text);
else
text = obj.text;
if (string.len(text) > VInfo.settings.maxTextLength) then
text = string.sub(text, 0, VInfo.settings.maxTextLength);
text = text.."..";
end;
objWidth = getTextWidth(size, text);
end;
-- Draw text
if (obj.bold) then setTextBold(true); else setTextBold(false); end;
if (VInfo.settings.canMoveText) then setTextColor(unpack(VInfo.colors.blocked));
elseif (obj.color) then setTextColor(unpack(obj.color));
else setTextColor(unpack(VInfo.colors.default)); end;
renderText(posX, line, size, text);
-- Add the textWidth to draw after 1st draw
posX = posX + objWidth;
lineWidth = lineWidth + objWidth;
-- Set text to original state
setTextBold(false);
setTextColor(unpack(VInfo.colors.default));
-- Render the seperator if not last item
if (index ~= #info) then
text = VInfo.text.seperator;
objWidth = getTextWidth(size, text);
renderText(posX, line, size, text);
posX = posX + objWidth;
lineWidth = lineWidth + objWidth;
end
end;
end;
end;
local bg = Overlay.new(VInfo.images["BG_VInfo"], VInfo.text.posX-0.001, VInfo.text.posY - (size * lineNumber) - (size/4.5), lineWidth+0.001, (size));
bg:setColor(1,1,1, VInfo.settings.backgroundTransparency[VInfo.text.bgAlpha]);
bg:render();
end;
-- Logging function
function VInfo:log(...)
print(" [VI]: " .. string.format(...));
end;
-- Logging warning function
function VInfo:warning(...)
print(" [VI][Warning!]: " .. string.format(...));
end;
-- Returns current vehicle/implement fruit and filllevel
function VInfo:getFillUnitInfo(vehicle, fillUnitNum)
local fillUnit = nil;
local fillPercent = 0;
local color;
local fruitID = vehicle:getFillUnitFillType(fillUnitNum);
if math.floor(vehicle:getFillUnitFillLevel(fillUnitNum)) > 0 then
local fruit = nil;
if vehicle.spec_fillUnit.fillUnits[fillUnitNum] ~= nil then
if vehicle.spec_fillUnit.fillUnits[fillUnitNum].fillTypeToDisplay ~= 1 then
fruit = g_fillTypeManager:getFillTypeByIndex(vehicle.spec_fillUnit.fillUnits[fillUnitNum].fillTypeToDisplay).title;
else
fruit = g_fillTypeManager:getFillTypeByIndex(fruitID).title;
end;
fillPercent = math.floor(vehicle:getFillUnitFillLevelPercentage(fillUnitNum) * 100);
fillUnit = string.format("%s(%s%%), %s", math.floor(vehicle:getFillUnitFillLevel(fillUnitNum)), fillPercent, fruit);
end;
end;
-- Set the color for the amount (need to check if seeder e.a ... seeder is ok when full, trailer is ok when empty)
if (fillUnit ~= nil) then color = self:setFillColor(vehicle, fillPercent) end;
return fillUnit, color;
end;
-- Set the text color of fillunits
function VInfo:setFillColor(vehicle, fillPercent)
local color;
if (not vehicle.spec_sowingMachine and not vehicle.spec_sprayer) then
if (vehicle.brand.title == "Hardi") then
-- its a Hardi extra tank for the sprayer
if (fillPercent > 75) then
color = VInfo.colors.tankLow;
elseif (fillPercent > 10) then
color = VInfo.colors.tankMid;
elseif (fillPercent <= 10) then
color = VInfo.colors.tankFull;
end;
else-- Probably a trailer or harvester
if (fillPercent > 90) then
color = VInfo.colors.tankFull;
elseif (fillPercent > 25) then
color = VInfo.colors.tankMid;
elseif (fillPercent > 5) then
color = VInfo.colors.tankLow;
end;
end;
elseif (vehicle.spec_sowingMachine or vehicle.spec_sprayer) then
-- its a sowing machine or a sprayer (reversing colors)
if (fillPercent > 75) then
color = VInfo.colors.tankLow;
elseif (fillPercent > 10) then
color = VInfo.colors.tankMid;
elseif (fillPercent <= 10) then
color = VInfo.colors.tankFull;
end;
end;
return color;
end;
-- Check if vehicle has trailers or tools with fillunits
function VInfo:getAttachedInfo(vehicle, obj)
if VInfo:getAllAttachedImplements(vehicle) ~= nil then
local allImp = VInfo:getAllAttachedImplements(vehicle);
local maxImp = 0;
-- Need to reverse the table, last item is 1st attached inserted
for i = #allImp, 1, -1 do
if (maxImp >= VInfo.settings.maxImp) then goto skipToNext; end;
-- We dont want to display weights e.a.
if not (allImp[i].spec_workArea or allImp[i].spec_fillUnit) then goto skipToNext; end; --
maxImp = maxImp + 1;
obj[#obj+1] = {};
obj[#obj].text = allImp[i]:getName();
if (allImp[i].spec_fillUnit) then
if (allImp[i]:getFillUnitFillLevel(1) ~= nil) then
obj[#obj+1] = {};
obj[#obj].text, obj[#obj].color = self:getFillUnitInfo(allImp[i], 1);
end;
if (allImp[i]:getFillUnitFillLevel(2) ~= nil) then
obj[#obj+1] = {};
obj[#obj].text, obj[#obj].color = self:getFillUnitInfo(allImp[i], 2);
end;
end;
::skipToNext::
end;
end;
end;
-- Returns 'all' attached implements on given vehicle
function VInfo:getAllAttachedImplements(vehicle)
if vehicle ~= nil and vehicle.getAttachedImplements and #vehicle:getAttachedImplements() > 0 then
local allImp = {};
local function addAllAttached(obj)
for _, imp in pairs(obj:getAttachedImplements()) do
addAllAttached(imp.object);
table.insert(allImp, imp.object);
end;
end;
addAllAttached(vehicle);
return allImp;
end;
end;
-- Check if the vehicle blocked
function VInfo:isVehicleBlocked(vehicle)
if g_server ~= nil and g_client ~= nil and g_dedicatedServerInfo ~= nil then return false; end;
if (vehicle.vi.moveTimer == nil) then vehicle.vi.moveTimer = 5000; end;
if vehicle.spec_aiVehicle.isActive then
if (vehicle:getLastSpeed() < 2 and not VInfo:getIsWaiting(vehicle)) then
vehicle.vi.moveTimer = vehicle.vi.moveTimer-10;
else
vehicle.vi.moveTimer = 5000;
end;
if (vehicle.vi.moveTimer < 0) then return true; end;
else
vehicle.vi.moveTimer = nil;
end;
return false;
end;
-- Change object colors
function VInfo:changeObjColor(obj, color)
for k,v in pairs(obj) do
if (type(v) == "table") then
if obj[k].color == self.colors.entered then
elseif obj[k].color == self.colors.lowFuel then
else obj[k].color = color;
end
end;
end;
end;
-- Check if the mouse is over text
function VInfo:isMouseOverText(text, size, posX, posY)
if (VInfo.isMouseActive) then
local txtWidth = getTextWidth(size, text);
local txtHeight = getTextHeight(size, text);
local areaX1 = posX;
local areaX2 = areaX1 + txtWidth;
local areaY1 = posY;
local areaY2 = areaY1 + txtHeight;
return VInfo.mousePosX >= areaX1 and VInfo.mousePosX <= areaX2 and VInfo.mousePosY >= areaY1 and VInfo.mousePosY <= areaY2;
end;
end;
function VInfo:isMouseOverArea(posX, posY, width, height)
if (VInfo.isMouseActive) then
local areaX1 = posX;
local areaX2 = areaX1 + width;
local areaY1 = posY;
local areaY2 = areaY1 + height;
return VInfo.mousePosX >= areaX1 and VInfo.mousePosX <= areaX2 and VInfo.mousePosY >= areaY1 and VInfo.mousePosY <= areaY2;
end;
end;
function VInfo:getIsWaiting(vehicle)
if (vehicle == nil) then return false; end;
if (vehicle:getLastSpeed() > 2) then return false; end;
if vehicle.ad ~= nil then
if vehicle.ad.stateModule:getCurrentTaskInfo() == "$l10n_AD_task_wait_for_call;" or
string.find(vehicle.ad.stateModule:getCurrentTaskInfo(), "AD_task_drive_to") and vehicle.ad.drivePathModule:isTargetReached() or
vehicle.ad.trailerModule:isActiveAtTrigger() then
return true
end
end
if VInfo:getIsCpFieldWorker(vehicle) then return false; end; -- then its not a cp ai combine unloader
if VInfo:getIsCpUnloader(vehicle) then return true; end;
return false;
end
-- Returns if Courseplay is active
function VInfo:getIsCPActive(vehicle)
if (vehicle.getIsCpActive and vehicle:getIsCpActive()) then return true; end;
return false;
end
-- Returns if Courseplay fieldwork is active or not
function VInfo:getIsCpFieldWorker(vehicle)
if (vehicle.spec_cpAIFieldWorker) then
if (vehicle:getIsCpFieldWorkActive()) then return true; end;
end;
return false;
end
-- Returns if Courseplay AI Unloader is active or not
function VInfo:getIsCpUnloader(vehicle)
if not (vehicle.spec_cpAIFieldWorker) then return false; end;
if not (vehicle.spec_cpAIFieldWorker.driveStrategy) then return false; end;
if (vehicle.spec_cpAIFieldWorker.driveStrategy.isACombineUnloadAIDriver) then return true; end;
return false;
end
function VInfo:getIsLowFuel()
if self ~= nil and self.spec_motorized then
local lowLevel = 0.20 -- percent
local fuel = self:getConsumerFillUnitIndex(FillType.DIESEL)
local level = self:getFillUnitFillLevel(fuel)
local cap = self:getFillUnitCapacity(fuel)
if type(level) =="number" and type(cap) == "number" and level/cap < lowLevel then
return true
end
end
return false
end
-- returns speed of vehicle in string format
function VInfo:getSpeedText(vehicle)
if vehicle.getLastSpeed ~= nil then
local unit = nil;
local speed = nil;
if g_i18n.useMiles then
speed = vehicle:getLastSpeed() * 0.621371;
unit = g_i18n.texts.unit_mph;
else
speed = vehicle:getLastSpeed();
unit = g_i18n.texts.unit_kmh;
end;
return string.format("%1.0f %s", speed, unit);
end;
end;
function VInfo:getActiveName(vehicle, isEntered, isHelper, name, Obj)
if (isEntered) then
local txt = vehicle:getControllerName() or "Player";
table.insert(Obj, name, {text = txt});
Obj[name].bold = true;
elseif (isHelper) then
local txt;
if (VInfo:getIsCPActive(vehicle)) then txt = VInfo.text.cpHelper;
elseif (vehicle.ad ~= nil and vehicle.ad.stateModule:isActive()) then txt = VInfo.text.adHelper; end;
txt = txt or VInfo.text.helper;
table.insert(Obj, name, {text = txt});
Obj[name].bold = true;
if (self.settings.showHelperName) then
if (vehicle:getCurrentHelper().name ~= nil) then
txt = vehicle:getCurrentHelper().name;
table.insert(Obj, name+1, {text = txt});
end;
end;
end;
end;
function VInfo:getIsLeasedIsMission(vehicle, Obj)
if (vehicle.propertyState == 2) then -- Leased vehicle
local index = #Obj+1;
Obj[index] = {};
Obj[index].text = VInfo.text.isLeased;
Obj[index].color = VInfo.colors.isLeased;
Obj[index].bold = true;
elseif (vehicle.propertyState == 3) then -- Mission vehicle
local index = #Obj+1;
Obj[index] = {};
Obj[index].text = VInfo.text.isMission;
Obj[index].color = VInfo.colors.isLeased;
Obj[index].bold = true;
end;
end;
--------------------------------------
-- MENU FUNCTIONS
--------------------------------------
-- Returns Yes/No from boolean
function VInfo:getYesNo(value)
if (value == true) then return "Yes"; end;
if (value == false) then return "No"; end;
end;
-- Toggle CanVehicleTabWhenParked
function VInfo.toggleCanVehicleTabWhenParked()
VInfo.settings.canVehicleTabWhenParked = not VInfo.settings.canVehicleTabWhenParked;
end;
-- Toggle CanVehicleTabWhenInActive
function VInfo.toggleCanVehicleTabWhenInActive()
VInfo.settings.canVehicleTabWhenInActive = not VInfo.settings.canVehicleTabWhenInActive;
end;
-- Toggle ShowParkedVehicles
function VInfo.toggleShowParkedVehicles()
VInfo.settings.showParkedVehicles = not VInfo.settings.showParkedVehicles;
end;
-- Toggle ShowInActiveVehicles
function VInfo.toggleShowInActiveVehicles()
VInfo.settings.showInActiveVehicles = not VInfo.settings.showInActiveVehicles;
end;
-- Toggle TextSize
function VInfo.toggleTextSize()
local size = VInfo.text.size;
for i, v in ipairs(VInfo.settings.textSize) do
if (size >= #VInfo.settings.textSize) then
VInfo.text.size = 1;
elseif (i > size) then
VInfo.text.size = i;
return;
end;
end;
end;
-- Toggle BackgroundTransparency
function VInfo.toggleBackgroundTransparency()
local bgAlpha = VInfo.text.bgAlpha;
for i, v in ipairs(VInfo.settings.backgroundTransparency) do
if (bgAlpha >= #VInfo.settings.backgroundTransparency) then
VInfo.text.bgAlpha = 1;
elseif (i > bgAlpha) then
VInfo.text.bgAlpha = i;
return;
end;
end;
end;
-- Toggle ShowIcon
function VInfo.toggleShowIcon()
VInfo.settings.showIcon = not VInfo.settings.showIcon;
end;
-- Toggle ShowAll
function VInfo.toggleShowAll()
VInfo.settings.showAll = not VInfo.settings.showAll;
end;
-- Open SettingsMenu
function VInfo:openSettingsMenu()
VInfo.settings.showSettings = true;
VInfo:toggleMouse(true);
VInfo:lockContext(true);
end;
-- Close SettingsMenu
function VInfo:closeSettingsMenu()
VInfo.settings.showSettings = false;
VInfo:toggleMouse(false);
VInfo:lockContext(false);
end;
-- Create a interactive text line (for settings menu)
function VInfo:activeMenuLine(line, text, textSize, posX, value, func)
local textToRender;
if (type(value) == "boolean") then
textToRender = string.format("%s: %s", text, VInfo:getYesNo(value));
elseif (value ~= nil) then
textToRender = string.format("%s: %s", text, value);
else textToRender = text;
end;
if (VInfo:isMouseOverText(textToRender, textSize, posX, line)) then
setTextColor(unpack(VInfo.colors.default)); -- text hover color
VInfo.button1 = func;
elseif (VInfo.button1 == func) then
VInfo.button1 = nil;
else setTextColor(unpack(VInfo.colors.lightBlue)); -- text color
end;
renderText(posX, line, textSize, textToRender);
end;
-- Render interactive Icon
function VInfo:renderIcon(posX, posY, width, height, img1, img2, func)
local iconImg;
if (VInfo:isMouseOverArea(posX, posY, width, height)) then
iconImg = img2;
VInfo.button1 = func;
elseif (VInfo.button1 == func) then
VInfo.button1 = nil;
else iconImg = img1;
end;
local icon = Overlay.new(iconImg, posX, posY, width, height);
icon:setColor(1,1,1,1);
icon:render();
end;
-- Helper function for table
function table.contains(table, element)
for _, value in pairs(table) do
if value == element then
return true;
end;
end;
return false;
end;
--- Lock/Unlock mouse and keyboard from any interaction outside the menu
function VInfo:lockContext(lockIt)
local lockIt = lockIt ~= false;
if lockIt and g_inputBinding:getContextName() ~= VInfo.hudName then
g_inputBinding:setContext(VInfo.hudName, true, false);
elseif not lockIt and g_inputBinding:getContextName() == VInfo.hudName then
g_inputBinding:revertContext(true);
end;
end;
-----------------------------------------------------
------------------------ XML ------------------------
-----------------------------------------------------
-- Calls saveToXML
function VInfo.saveSavegame()
if (g_server ~= nil) then VInfo.saveToXML(); end;
end;
-- Save to xml file (global script)
function VInfo.saveToXML()
local xmlFilePath = VInfo.getXMLPath();
local xmlFile = createXMLFile(VInfo.name, xmlFilePath, VInfo.name);
setXMLString(xmlFile, "VInfo.author", VInfo.author);
setXMLString(xmlFile, "VInfo.version", VInfo.version);
setXMLFloat(xmlFile, "VInfo.text.posX", VInfo.text.posX);
setXMLFloat(xmlFile, "VInfo.text.posY", VInfo.text.posY);
setXMLFloat(xmlFile, "VInfo.text.size", VInfo.text.size);
setXMLFloat(xmlFile, "VInfo.text.bgAlpha", VInfo.text.bgAlpha);
setXMLBool(xmlFile, "VInfo.settings.canVehicleTabWhenParked", VInfo.settings.canVehicleTabWhenParked);
setXMLBool(xmlFile, "VInfo.settings.canVehicleTabWhenNotActive", VInfo.settings.canVehicleTabWhenInActive);
setXMLBool(xmlFile, "VInfo.settings.showParkedVehicles", VInfo.settings.showParkedVehicles);
setXMLBool(xmlFile, "VInfo.settings.showNotActiveVehicles", VInfo.settings.showInActiveVehicles);
setXMLInt (xmlFile, "VInfo.settings.maxImp", VInfo.settings.maxImp);
setXMLBool(xmlFile, "VInfo.settings.showIcon", VInfo.settings.showIcon);
setXMLBool(xmlFile, "VInfo.settings.showAll", VInfo.settings.showAll);
saveXMLFile(xmlFile);
VInfo:log("Saved to xml file");
end;
-- Read from xml file (global script)
function VInfo.readFromXML(xmlFile)
if (xmlFile == nil) then return; end;
VInfo.text.posX = Utils.getNoNil(getXMLFloat(xmlFile, "VInfo.text.posX"), VInfo.text.posX);
VInfo.text.posY = Utils.getNoNil(getXMLFloat(xmlFile, "VInfo.text.posY"), VInfo.text.posY);
VInfo.text.size = Utils.getNoNil(getXMLFloat(xmlFile, "VInfo.text.size"), VInfo.text.size);
VInfo.text.bgAlpha = Utils.getNoNil(getXMLFloat(xmlFile, "VInfo.text.bgAlpha"), VInfo.text.bgAlpha);
VInfo.settings.canVehicleTabWhenParked = Utils.getNoNil(getXMLBool(xmlFile, "VInfo.settings.canVehicleTabWhenParked"), VInfo.settings.canVehicleTabWhenParked);
VInfo.settings.canVehicleTabWhenInActive = Utils.getNoNil(getXMLBool(xmlFile, "VInfo.settings.canVehicleTabWhenNotActive"), VInfo.settings.canVehicleTabWhenInActive);
VInfo.settings.showParkedVehicles = Utils.getNoNil(getXMLBool(xmlFile, "VInfo.settings.showParkedVehicles"), VInfo.settings.showParkedVehicles);
VInfo.settings.showInActiveVehicles = Utils.getNoNil(getXMLBool(xmlFile, "VInfo.settings.showNotActiveVehicles"), VInfo.settings.showInActiveVehicles);
VInfo.settings.maxImp = Utils.getNoNil(getXMLInt (xmlFile, "VInfo.settings.maxImp"), VInfo.settings.maxImp);
VInfo.settings.showOpenMenuIcon = Utils.getNoNil(getXMLBool(xmlFile, "VInfo.settings.showIcon"), VInfo.settings.showIcon);
VInfo.settings.showAll = Utils.getNoNil(getXMLBool(xmlFile, "VInfo.settings.showAll"), VInfo.settings.showAll);
end;
-- Load xml file
function VInfo.loadStoredXML()
if (g_server == nil) then return; end;
local xmlFilePath = VInfo.getXMLPath();
if fileExists(xmlFilePath) then
local xmlFile = loadXMLFile(VInfo.name, xmlFilePath);
VInfo:log("Loaded xmlFile");
VInfo.readFromXML(xmlFile);
delete(xmlFile);
else
VInfo:warning("xmlFile not found or other error!");
end;
end;
-- Returns the xml file path stored in savegame directory. Creates new if not exists
function VInfo.getXMLPath()
local path = g_currentMission.missionInfo.savegameDirectory;
if path ~= nil then
return path .. "/VInfo_config.xml";
else
return getUserProfileAppPath() .. "savegame" .. g_currentMission.missionInfo.savegameIndex .. "/VInfo_config.xml";
end;
end;