forked from JumpyDuke/UniversalProcessKit_FS15
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUPK_DisplayTrigger.lua
133 lines (112 loc) · 5.33 KB
/
UPK_DisplayTrigger.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
-- by mor2000
--------------------
-- DisplayTrigger (shows sth in the top left hud)
local UPK_DisplayTrigger_mt = ClassUPK(UPK_DisplayTrigger,UniversalProcessKit)
InitObjectClass(UPK_DisplayTrigger, "UPK_DisplayTrigger")
UniversalProcessKit.addModule("displaytrigger",UPK_DisplayTrigger)
local countriesUsingCommas={"al", "ad", "ao", "ar", "am", "at", "az", "by", "be", "bo", "ba", "br", "bg", "cm", "cl", "cr", "hr", "cu", "cy", "cz", "dk", "ec", "ee", "fo", "fi", "fr", "de", "ge", "gr", "gl", "hu", "is", "in", "it", "kz", "kg", "lv", "lb", "lt", "lu", "mo", "mk", "md", "mn", "ma", "mz", "nl", "no", "py", "pe", "pl", "pt", "ro", "ru", "cs", "sk", "sm", "za", "es", "ch", "se", "tn", "tr", "ua", "uy", "uz", "ve", "vn"}
local isCountryUsingComma=isInTable(countriesUsingCommas,g_languageShort)
function UPK_DisplayTrigger:new(nodeId, parent)
printFn('UPK_DisplayTrigger:new(',nodeId,', ',parent,')')
local self = UniversalProcessKit:new(nodeId, parent, UPK_DisplayTrigger_mt)
registerObjectClassName(self, "UPK_DisplayTrigger")
self.onlyFilled = getBoolFromUserAttribute(nodeId, "onlyFilled", true)
self.showFillLevel = getBoolFromUserAttribute(nodeId, "showFillLevel", true)
self.showFillLevelDecimals = getNumberFromUserAttribute(nodeId, "showFillLevelDecimals", 0, 0, 6)
self.showCapacity = getBoolFromUserAttribute(nodeId, "showCapacity", false)
self.showCapacityDecimals = getNumberFromUserAttribute(nodeId, "showCapacityDecimals", self.showFillLevelDecimals, 0, 6)
self.showPercentage = getBoolFromUserAttribute(nodeId, "showPercentage", true)
self.showPercentageDecimals = getNumberFromUserAttribute(nodeId, "showPercentageDecimals", 0, 0, 6)
local heading = getArrayFromUserAttribute(nodeId, "heading")
if #heading>0 then
self.heading=heading
self.headingLength=#heading
end
useLongUnitNames = getBoolFromUserAttribute(nodeId, "useLongUnitNames", false)
self.useUnitNames = "_unit_short"
if useLongUnitNames then
self.useUnitNames = "_unit_long"
end
self.displayFillTypes={}
self.displayFillTypesOrder={}
local displayFillTypesArr = UniversalProcessKit.fillTypeNameToInt(getArrayFromUserAttribute(nodeId, "displayFillTypes"))
for i=1,length(displayFillTypesArr) do
self.displayFillTypes[displayFillTypesArr[i]] = true
table.insert(self.displayFillTypesOrder,displayFillTypesArr[i])
end
self.displayFillTypesOrderLength = length(self.displayFillTypesOrder)
self:addTrigger()
self:printFn('UPK_DisplayTrigger:new done')
return self
end
function UPK_DisplayTrigger:delete()
self:printFn('UPK_DisplayTrigger:delete()')
UPK_DisplayTrigger:superClass().delete(self)
end
function UPK_DisplayTrigger:triggerUpdate(vehicle,isInTrigger)
self:printFn('UPK_DisplayTrigger:triggerUpdate(',vehicle,',',isInTrigger,')')
--self:print('entitiesInTrigger = '..tostring(self.entitiesInTrigger))
if self.entitiesInTrigger>0 then
--self:print('UniversalProcessKitListener.addUpdateable()')
UniversalProcessKitListener.addUpdateable(self)
else
--self:print('UniversalProcessKitListener.removeUpdateable()')
UniversalProcessKitListener.removeUpdateable(self)
end
end
function UPK_DisplayTrigger:update(dt)
self:printAll('UPK_DisplayTrigger:update(',dt,')')
if self.isEnabled and self:getShowInfo() then
--self:print('enable printing')
if self.heading~=nil then
for i=1,self.headingLength do
g_currentMission:addExtraPrintText(self.i18n[self.heading[i]])
end
end
for i=1,self.displayFillTypesOrderLength do
fillType = self.displayFillTypesOrder[i]
display = self.displayFillTypes[fillType]
--self:print('want to display '..tostring(fillType)..': '..tostring(display))
if display then
local fillLevel=self:getFillLevel(fillType) or 0
--self:print('fillLevel = '..tostring(fillLevel)..', self.onlyFilled = '..tostring(self.onlyFilled))
if fillLevel>0 or not self.onlyFilled then
local text=(returnNilIfEmptyString(self.i18n[UniversalProcessKit.fillTypeIntToName[fillType]]) or ("["..UniversalProcessKit.fillTypeIntToName[fillType].."]"))..": "
local capacity
if self.showFillLevel then
local nrStr=string.format('%.'..tostring(self.showFillLevelDecimals)..'f',fillLevel)
if isCountryUsingComma then
nrStr=string.gsub(nrStr,"%.",",")
end
if self.showCapacity then
capacity = self:getCapacity(fillType)
if capacity<math.huge then
local nrStr2=string.format('%.'..tostring(self.showCapacityDecimals)..'f',capacity)
if isCountryUsingComma then
nrStr2=string.gsub(nrStr2,"%.",",")
end
nrStr=nrStr.." / "..nrStr2
end
end
text=text.. nrStr .. " [" .. (returnNilIfEmptyString(self.i18n[UniversalProcessKit.fillTypeIntToName[fillType]..self.useUnitNames]) or self.i18n["fluid"..self.useUnitNames]) .. "]"
end
if self.showPercentage then
capacity = capacity or self:getCapacity(fillType)
if capacity<math.huge then
local ratio = round(fillLevel/capacity*100, self.showPercentageDecimals)
if ratio==100 and round(fillLevel,1)<capacity then
ratio = 99
end
local nrStr = string.format('%.'..tostring(self.showPercentageDecimals)..'f',ratio)
if isCountryUsingComma then
nrStr=string.gsub(nrStr,"%.",",")
end
text=text.." ".. nrStr .. "%"
end
end
g_currentMission:addExtraPrintText(text)
end
end
end
end
end