61 | function PlaceableWeighingStation:onLoad(savegame) |
62 | local spec = self.spec_weighingStation |
63 | |
64 | local key = "placeable.weighingStation" |
65 | |
66 | spec.trigger = self.xmlFile:getValue(key .. "#triggerNode", nil, self.components, self.i3dMappings) |
67 | if spec.trigger == nil then |
68 | Logging.xmlError(self.xmlFile, "Missing vehicle triggerNode for weighing station") |
69 | return |
70 | end |
71 | |
72 | addTrigger(spec.trigger, "onWeighingTriggerCallback", self) |
73 | spec.triggerVehicleNodes = {} |
74 | spec.vehicles = {} |
75 | |
76 | spec.displays = {} |
77 | self.xmlFile:iterate(key .. ".display", function(_, displayKey) |
78 | local displayNode = self.xmlFile:getValue(displayKey .. "#node", nil, self.components, self.i3dMappings) |
79 | if displayNode ~= nil then |
80 | local fontName = self.xmlFile:getValue(displayKey .. "#font", "DIGIT"):upper() |
81 | local fontMaterial = g_materialManager:getFontMaterial(fontName, self.customEnvironment) |
82 | |
83 | if fontMaterial ~= nil then |
84 | local display = {} |
85 | |
86 | local alignmentStr = self.xmlFile:getValue(displayKey .. "#alignment", "RIGHT") |
87 | local alignment = RenderText["ALIGN_" .. alignmentStr:upper()] or RenderText.ALIGN_RIGHT |
88 | |
89 | local size = self.xmlFile:getValue(displayKey .. "#size", 0.03) |
90 | local scaleX = self.xmlFile:getValue(displayKey .. "#scaleX", 1) |
91 | local scaleY = self.xmlFile:getValue(displayKey .. "#scaleY", 1) |
92 | local mask = self.xmlFile:getValue(displayKey .. "#mask", "00.0") |
93 | local emissiveScale = self.xmlFile:getValue(displayKey .. "#emissiveScale", 0.2) |
94 | local color = self.xmlFile:getValue(displayKey .. "#color", {0.9, 0.9, 0.9, 1}, true) |
95 | local hiddenColor = self.xmlFile:getValue(displayKey .. "#hiddenColor", nil, true) |
96 | |
97 | display.displayNode = displayNode |
98 | display.formatStr, display.formatPrecision = string.maskToFormat(mask) |
99 | display.fontMaterial = fontMaterial |
100 | display.characterLine = fontMaterial:createCharacterLine(display.displayNode, mask:len(), size, color, hiddenColor, emissiveScale, scaleX, scaleY, alignment) |
101 | |
102 | table.insert(spec.displays, display) |
103 | end |
104 | end |
105 | end) |
106 | |
107 | self:setWeightDisplay(0) |
108 | end |
39 | function PlaceableWeighingStation.registerXMLPaths(schema, basePath) |
40 | schema:setXMLSpecializationType("WeighingStation") |
41 | |
42 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".weighingStation#triggerNode", "Vehicle trigger") |
43 | |
44 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".weighingStation.display(?)#node", "Display start node") |
45 | schema:register(XMLValueType.STRING, basePath .. ".weighingStation.display(?)#font", "Display font name") |
46 | schema:register(XMLValueType.STRING, basePath .. ".weighingStation.display(?)#alignment", "Display text alignment") |
47 | schema:register(XMLValueType.FLOAT, basePath .. ".weighingStation.display(?)#size", "Display text size") |
48 | schema:register(XMLValueType.FLOAT, basePath .. ".weighingStation.display(?)#scaleX", "Display text x scale") |
49 | schema:register(XMLValueType.FLOAT, basePath .. ".weighingStation.display(?)#scaleY", "Display text y scale") |
50 | schema:register(XMLValueType.STRING, basePath .. ".weighingStation.display(?)#mask", "Display text mask") |
51 | schema:register(XMLValueType.FLOAT, basePath .. ".weighingStation.display(?)#emissiveScale", "Display emissive scale") |
52 | schema:register(XMLValueType.COLOR, basePath .. ".weighingStation.display(?)#color", "Display text color") |
53 | schema:register(XMLValueType.COLOR, basePath .. ".weighingStation.display(?)#hiddenColor", "Display text hidden color") |
54 | |
55 | schema:setXMLSpecializationType() |
56 | end |
123 | function PlaceableWeighingStation:updateWeightDisplay() |
124 | local spec = self.spec_weighingStation |
125 | |
126 | -- resolve nodes to vehicles, add to table to eliminate duplicates |
127 | for node, _ in pairs(spec.triggerVehicleNodes) do |
128 | if entityExists(node) then |
129 | local vehicle = g_currentMission:getNodeObject(node) |
130 | if vehicle ~= nil and vehicle.getTotalMass ~= nil then |
131 | spec.vehicles[vehicle] = true |
132 | end |
133 | else |
134 | -- vehicle does not exist anymore |
135 | spec.triggerVehicleNodes[node] = nil |
136 | end |
137 | end |
138 | |
139 | local mass = 0 |
140 | for vehicle in pairs(spec.vehicles) do |
141 | mass = mass + vehicle:getTotalMass(true) |
142 | end |
143 | table.clear(spec.vehicles) |
144 | |
145 | self:setWeightDisplay(mass*1000) |
146 | end |