400 | function LicensePlateManager.createLicensePlateXMLSchema() |
401 | if LicensePlateManager.xmlSchema == nil then |
402 | local schema = XMLSchema.new("mapLicensePlates") |
403 | |
404 | LicensePlate.registerXMLPaths(schema, "licensePlates.licensePlate(?)") |
405 | |
406 | schema:register(XMLValueType.STRING, "licensePlates.font#name", "License plate font name", "GENERIC") |
407 | |
408 | schema:register(XMLValueType.STRING, "licensePlates.colorConfigurations#shaderParameter", "Color shader parameter", "colorMat0") |
409 | schema:register(XMLValueType.STRING, "licensePlates.colorConfigurations#shaderParameterCharacters", "Color shader parameter of characters", "colorSale") |
410 | schema:register(XMLValueType.BOOL, "licensePlates.colorConfigurations#useDefaultColors", "License plate can be colored with all available default colors", false) |
411 | schema:register(XMLValueType.INT, "licensePlates.colorConfigurations#defaultColorIndex", "Default selected color") |
412 | schema:register(XMLValueType.FLOAT, "licensePlates.colorConfigurations#defaultColorMaxBrightness", "Default colors with higher brightness will be skipped", 0.55) |
413 | schema:register(XMLValueType.L10N_STRING, "licensePlates.colorConfigurations.colorConfiguration(?)#name", "Name of color to display") |
414 | schema:register(XMLValueType.COLOR, "licensePlates.colorConfigurations.colorConfiguration(?)#color", "Color values") |
415 | schema:register(XMLValueType.BOOL, "licensePlates.colorConfigurations.colorConfiguration(?)#isDefault", "Color is default selected") |
416 | |
417 | schema:register(XMLValueType.STRING, "licensePlates.placement#defaultType", "Default type of placement (none/both/back_only)", "both") |
418 | |
419 | LicensePlateManager.xmlSchema = schema |
420 | end |
421 | end |
198 | function LicensePlateManager:licensePlateI3DFileLoaded(i3dNode, failedReason, args) |
199 | local filename = args.filename |
200 | local xmlFile = args.xmlFile |
201 | local plateKey = args.plateKey |
202 | local customEnvironment = args.customEnvironment |
203 | |
204 | if i3dNode ~= nil and i3dNode ~= 0 then |
205 | local node = xmlFile:getValue(plateKey .. "#node", nil, i3dNode) |
206 | if node ~= nil then |
207 | unlink(node) |
208 | |
209 | local licensePlate = LicensePlate.new() |
210 | if licensePlate:loadFromXML(node, filename, customEnvironment, xmlFile, plateKey) then |
211 | table.insert(self.licensePlates, licensePlate) |
212 | end |
213 | end |
214 | |
215 | delete(i3dNode) |
216 | end |
217 | |
218 | self.xmlReferences = self.xmlReferences - 1 |
219 | if self.xmlReferences == 0 then |
220 | xmlFile:delete() |
221 | self.licensePlatesAvailable = #self.licensePlates > 0 |
222 | if xmlFile == self.licensePlateXML then |
223 | self.licensePlateXML = nil |
224 | end |
225 | end |
226 | end |
352 | function LicensePlateManager.loadLicensePlateDataFromXML(xmlFile, key, useAbsolutePaths) |
353 | local valid = xmlFile:hasProperty(key .. "#variation") |
354 | if valid then |
355 | local licensePlateData = {} |
356 | if useAbsolutePaths then |
357 | licensePlateData.xmlFilename = xmlFile:getString(key .. "#configuration") |
358 | else |
359 | licensePlateData.xmlFilename = NetworkUtil.convertFromNetworkFilename(xmlFile:getString(key .. "#configuration")) |
360 | end |
361 | licensePlateData.variation = xmlFile:getInt(key .. "#variation") |
362 | licensePlateData.colorIndex = xmlFile:getInt(key .. "#color") |
363 | licensePlateData.placementIndex = xmlFile:getInt(key .. "#placement") |
364 | |
365 | local font = g_licensePlateManager:getFont() |
366 | |
367 | licensePlateData.characters = {} |
368 | local characters = xmlFile:getString(key .. "#characters") |
369 | local characterLength = characters:len() |
370 | for i=1, characterLength do |
371 | table.insert(licensePlateData.characters, characters:sub(i, i)) |
372 | end |
373 | |
374 | return licensePlateData |
375 | else |
376 | return nil |
377 | end |
378 | end |
114 | function LicensePlateManager:loadLicensePlatesFromXML(xmlFile, baseDirectory) |
115 | local customEnvironment, _ = Utils.getModNameAndBaseDirectory(baseDirectory) |
116 | |
117 | self.fontName = xmlFile:getValue("licensePlates.font#name", "GENERIC") |
118 | self.customEnvironment = customEnvironment |
119 | |
120 | xmlFile:iterate("licensePlates.licensePlate", function(_, plateKey) |
121 | local filename = xmlFile:getValue(plateKey .. "#filename") |
122 | if filename ~= nil then |
123 | self.xmlReferences = self.xmlReferences + 1 |
124 | filename = Utils.getFilename(filename, baseDirectory) |
125 | local arguments = { |
126 | filename = filename, |
127 | xmlFile = xmlFile, |
128 | plateKey = plateKey, |
129 | customEnvironment = customEnvironment |
130 | } |
131 | local sharedLoadRequestId = g_i3DManager:loadSharedI3DFileAsync(filename, false, false, self.licensePlateI3DFileLoaded, self, arguments) |
132 | table.insert(self.sharedLoadRequestIds, sharedLoadRequestId) |
133 | else |
134 | Logging.xmlError(xmlFile, "Missing filename for license plate '%s'", plateKey) |
135 | end |
136 | end) |
137 | |
138 | self.shaderParameterPlate = xmlFile:getValue("licensePlates.colorConfigurations#shaderParameter", "colorMat0") |
139 | self.shaderParameterCharacters = xmlFile:getValue("licensePlates.colorConfigurations#shaderParameterCharacters", "colorScale") |
140 | self.useDefaultColors = xmlFile:getValue("licensePlates.colorConfigurations#useDefaultColors", false) |
141 | self.defaultColorIndex = xmlFile:getValue("licensePlates.colorConfigurations#defaultColorIndex") |
142 | self.defaultColorMaxBrightness = xmlFile:getValue("licensePlates.colorConfigurations#defaultColorMaxBrightness", 0.55) |
143 | |
144 | local defaultConfiguration = 1 |
145 | xmlFile:iterate("licensePlates.colorConfigurations.colorConfiguration", function(index, baseKey) |
146 | local name = xmlFile:getValue(baseKey .. "#name", "", self.customEnvironment, false) |
147 | local color = xmlFile:getValue(baseKey .. "#color", nil, true) |
148 | local isDefault = xmlFile:getValue(baseKey .. "#isDefault", false) |
149 | if color ~= nil then |
150 | if isDefault then |
151 | defaultConfiguration = index |
152 | end |
153 | |
154 | table.insert(self.colorConfigurations, {name=name, color=color, isDefault=isDefault}) |
155 | end |
156 | end) |
157 | |
158 | if self.defaultColorIndex ~= nil then |
159 | self.defaultColorIndex = self.defaultColorIndex + #self.colorConfigurations |
160 | else |
161 | self.defaultColorIndex = defaultConfiguration |
162 | end |
163 | |
164 | self.colors = {} |
165 | for j=1, #self.colorConfigurations do |
166 | table.insert(self.colors, self.colorConfigurations[j]) |
167 | end |
168 | |
169 | if self.useDefaultColors then |
170 | for j=1, #g_vehicleColors do |
171 | local color = g_vehicleColors[j] |
172 | |
173 | local colorData = {name=g_i18n:convertText(color.name), color={1, 1, 1, 1}} |
174 | if color.r ~= nil and color.g ~= nil and color.b ~= nil then |
175 | colorData.color = {color.r, color.g, color.b, 1} |
176 | elseif color.brandColor ~= nil then |
177 | colorData.color = g_brandColorManager:getBrandColorByName(color.brandColor) |
178 | end |
179 | |
180 | local brightness = MathUtil.getBrightnessFromColor(colorData.color[1], colorData.color[2], colorData.color[3]) |
181 | if brightness < self.defaultColorMaxBrightness then |
182 | table.insert(self.colors, colorData) |
183 | end |
184 | end |
185 | end |
186 | |
187 | self.defaultPlacementIndex = LicensePlateManager.PLACEMENT_OPTION.BOTH |
188 | local placementStr = xmlFile:getValue("licensePlates.placement#defaultType") |
189 | if placementStr ~= nil then |
190 | self.defaultPlacementIndex = LicensePlateManager.PLACEMENT_OPTION[placementStr:upper()] or self.defaultPlacementIndex |
191 | end |
192 | end |
64 | function LicensePlateManager:loadMapData(xmlFile, missionInfo, baseDirectory) |
65 | LicensePlateManager:superClass().loadMapData(self) |
66 | self.baseDirectory = baseDirectory |
67 | |
68 | LicensePlateManager.createLicensePlateXMLSchema() |
69 | |
70 | local filename = getXMLString(xmlFile, "map.licensePlates#filename") |
71 | if filename ~= nil then |
72 | self.xmlFilename = Utils.getFilename(filename, baseDirectory) |
73 | self.licensePlateXML = XMLFile.load("mapLicensePlates", self.xmlFilename, LicensePlateManager.xmlSchema) |
74 | if self.licensePlateXML ~= nil then |
75 | self.xmlReferences = 0 |
76 | self:loadLicensePlatesFromXML(self.licensePlateXML, baseDirectory) |
77 | |
78 | if self.licensePlateXML ~= nil and self.xmlReferences == 0 then |
79 | self.licensePlateXML:delete() |
80 | self.licensePlateXML = nil |
81 | end |
82 | end |
83 | end |
84 | |
85 | return true |
86 | end |
307 | function LicensePlateManager.readLicensePlateData(streamId, connection) |
308 | local licensePlateData = {variation=1, characters=nil, colorIndex=nil, placementIndex=1} |
309 | |
310 | local valid = streamReadBool(streamId) |
311 | if valid then |
312 | licensePlateData.variation = streamReadUIntN(streamId, LicensePlateManager.SEND_NUM_BITS_VARIATION) |
313 | licensePlateData.colorIndex = streamReadUIntN(streamId, LicensePlateManager.SEND_NUM_BITS_COLOR) |
314 | licensePlateData.placementIndex = streamReadUIntN(streamId, LicensePlateManager.SEND_NUM_BITS_PLACEMENT) |
315 | |
316 | local font = g_licensePlateManager:getFont() |
317 | |
318 | licensePlateData.characters = {} |
319 | local numCharacters = streamReadUIntN(streamId, LicensePlateManager.SEND_NUM_BITS_CHARACTER) |
320 | for i=1, numCharacters do |
321 | local index = streamReadUIntN(streamId, LicensePlateManager.SEND_NUM_BITS_CHARACTER) |
322 | local character = font:getCharacterByCharacterIndex(index) |
323 | table.insert(licensePlateData.characters, character) |
324 | end |
325 | end |
326 | |
327 | return licensePlateData |
328 | end |
382 | function LicensePlateManager.saveLicensePlateDataToXML(xmlFile, key, licensePlateData, useAbsolutePaths) |
383 | local valid = licensePlateData ~= nil and licensePlateData.variation ~= nil and licensePlateData.characters ~= nil and licensePlateData.colorIndex ~= nil and licensePlateData.placementIndex ~= nil |
384 | if valid then |
385 | xmlFile:setInt(key .. "#variation", licensePlateData.variation) |
386 | xmlFile:setInt(key .. "#color", licensePlateData.colorIndex) |
387 | xmlFile:setInt(key .. "#placement", licensePlateData.placementIndex) |
388 | xmlFile:setString(key .. "#characters", table.concat(licensePlateData.characters, "")) |
389 | |
390 | if useAbsolutePaths then |
391 | xmlFile:setString(key .. "#configuration", licensePlateData.xmlFilename) |
392 | else |
393 | xmlFile:setString(key .. "#configuration", NetworkUtil.convertToNetworkFilename(licensePlateData.xmlFilename)) |
394 | end |
395 | end |
396 | end |
334 | function LicensePlateManager.writeLicensePlateData(streamId, connection, licensePlateData) |
335 | if streamWriteBool(streamId, licensePlateData ~= nil and licensePlateData.variation ~= nil and licensePlateData.characters ~= nil and licensePlateData.colorIndex ~= nil and licensePlateData.placementIndex ~= nil) then |
336 | streamWriteUIntN(streamId, licensePlateData.variation, LicensePlateManager.SEND_NUM_BITS_VARIATION) |
337 | streamWriteUIntN(streamId, licensePlateData.colorIndex, LicensePlateManager.SEND_NUM_BITS_COLOR) |
338 | streamWriteUIntN(streamId, licensePlateData.placementIndex, LicensePlateManager.SEND_NUM_BITS_PLACEMENT) |
339 | |
340 | local font = g_licensePlateManager:getFont() |
341 | |
342 | streamWriteUIntN(streamId, #licensePlateData.characters, LicensePlateManager.SEND_NUM_BITS_CHARACTER) |
343 | for i=1, #licensePlateData.characters do |
344 | local index = font:getCharacterIndexByCharacter(licensePlateData.characters[i]) |
345 | streamWriteUIntN(streamId, index, LicensePlateManager.SEND_NUM_BITS_CHARACTER) |
346 | end |
347 | end |
348 | end |