Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- |
2 | -- MixerWagon |
3 | -- Class for all sprayers |
4 | -- |
5 | -- @author Stefan Geiger |
6 | -- @date 24/02/08 |
7 | -- |
8 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
9 | |
10 | source("dataS/scripts/vehicles/specializations/SetTurnedOnEvent.lua"); |
11 | |
12 | MixerWagon = {}; |
13 | |
14 | function MixerWagon.prerequisitesPresent(specializations) |
15 | return SpecializationUtil.hasSpecialization(Fillable, specializations) and SpecializationUtil.hasSpecialization(TurnOnVehicle, specializations); |
16 | end; |
17 | |
18 | function MixerWagon:load(xmlFile) |
19 | |
20 | self.mixerWagonSuperAllowFillType = self.allowFillType; |
21 | self.allowFillType = Utils.overwrittenFunction(self.allowFillType, MixerWagon.allowFillType); |
22 | self.getFillLevel = Utils.overwrittenFunction(self.getFillLevel, MixerWagon.getFillLevel); |
23 | self.setFillLevel = Utils.overwrittenFunction(self.setFillLevel, MixerWagon.setFillLevel); |
24 | self.resetFillLevelIfNeeded = Utils.overwrittenFunction(self.resetFillLevelIfNeeded, MixerWagon.resetFillLevelIfNeeded); |
25 | self.fillShovelFromGroundValue = Utils.overwrittenFunction(self.fillShovelFromGroundValue, MixerWagon.fillShovelFromGroundValue); |
26 | self.fillShovelFromTrigger = Utils.overwrittenFunction(self.fillShovelFromTrigger, MixerWagon.fillShovelFromTrigger); |
27 | self.mixerWagonBaleTriggerCallback = MixerWagon.mixerWagonBaleTriggerCallback; |
28 | self.getCanBeTurnedOn = Utils.overwrittenFunction(self.getCanBeTurnedOn, MixerWagon.getCanBeTurnedOn); |
29 | self.getIsTurnedOnAllowed = Utils.overwrittenFunction(self.getIsTurnedOnAllowed, MixerWagon.getIsTurnedOnAllowed); |
30 | self.drawMixerWagonHelp = SpecializationUtil.callSpecializationsFunction("drawMixerWagonHelp"); |
31 | |
32 | self.getAllowFillShovel = Utils.overwrittenFunction(self.getAllowFillShovel, MixerWagon.getAllowFillShovel); |
33 | |
34 | self.mixerWagonNeedsTurnOn = false; |
35 | if self.shovelNodes ~= nil then |
36 | self.mixerWagonNeedsTurnOn = true; |
37 | end |
38 | |
39 | self.mixerWagonPickupSoundEnabled = false; |
40 | if self.isClient then |
41 | self.sampleMixerWagonPickup = Utils.loadSample(xmlFile, {}, "vehicle.mixerWagonPickupSound", nil, self.baseDirectory, self.components[1].node); |
42 | self.sampleMixerWagonStart = Utils.loadSample(xmlFile, {}, "vehicle.mixerWagonPickupStartSound", nil, self.baseDirectory); |
43 | self.sampleMixerWagonStop = Utils.loadSample(xmlFile, {}, "vehicle.mixerWagonPickupStopSound", nil, self.baseDirectory); |
44 | self.mixerWagonPickupSoundPitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.mixerWagonPickupSound#pitchOffset"), 1); |
45 | self.mixerWagonPickupSoundPickupPitchOffset = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.mixerWagonPickupSound#pickupPitchOffset"), 0.8*self.mixerWagonPickupSoundPitchOffset); |
46 | |
47 | self.mixerWagonMixRotatingParts = Utils.loadRotationNodes(xmlFile, {}, "vehicle.mixerWagonRotatingParts.mixerWagonRotatingPart", "mixerWagonMix", self.components); |
48 | self.mixerWagonPickupRotatingParts = Utils.loadRotationNodes(xmlFile, {}, "vehicle.mixerWagonRotatingParts.mixerWagonRotatingPart", "mixerWagonPickup", self.components); |
49 | end |
50 | |
51 | |
52 | self.mixerWagonFillTypes = {}; |
53 | self.fillTypeToMixerWagonFillType = {}; |
54 | local i=0; |
55 | while true do |
56 | local baseName = string.format("vehicle.mixerWagonFillTypes.mixerWagonFillType(%d)", i); |
57 | if not hasXMLProperty(xmlFile, baseName) then |
58 | break; |
59 | end; |
60 | local entry = {}; |
61 | entry.fillTypes = {}; |
62 | |
63 | local j=0; |
64 | while true do |
65 | local fillTypeKey = baseName..string.format(".fillType(%d)", j); |
66 | if not hasXMLProperty(xmlFile, fillTypeKey) then |
67 | break; |
68 | end; |
69 | local fillType = getXMLString(xmlFile, fillTypeKey.."#fillType"); |
70 | if fillType ~= nil then |
71 | local fillTypeInt = Fillable.fillTypeNameToInt[fillType]; |
72 | if fillTypeInt ~= nil then |
73 | if self.fillTypeToMixerWagonFillType[fillTypeInt] == nil then |
74 | entry.fillTypes[fillTypeInt] = true; |
75 | self.fillTypeToMixerWagonFillType[fillTypeInt] = entry; |
76 | else |
77 | print("Warning: Invalid mixerWagonFillType '"..fillType.."' used multiple times in '"..self.configFileName.."'."); |
78 | end |
79 | else |
80 | print("Warning: Invalid mixerWagonFillType '"..fillType.."' in '"..self.configFileName.. "'."); |
81 | end |
82 | end |
83 | |
84 | j = j+1; |
85 | end |
86 | entry.minPercentage = Utils.getNoNil(getXMLFloat(xmlFile, baseName.."#minPercentage"), 0)*0.01; |
87 | entry.maxPercentage = Utils.getNoNil(getXMLFloat(xmlFile, baseName.."#maxPercentage"), 100)*0.01; |
88 | entry.fillLevel = 0; |
89 | |
90 | local name = Utils.getNoNil(getXMLString(xmlFile, baseName.."#name"), "unknown"); |
91 | entry.name = name; |
92 | local i18n = g_i18n; |
93 | if self.customEnvironment ~= nil then |
94 | i18n = _G[self.customEnvironment].g_i18n; |
95 | end; |
96 | entry.nameI18N = i18n:getText(name); |
97 | if next(entry.fillTypes) ~= nil then |
98 | local width, height = getNormalizedScreenValues(350*g_currentMission.vehicleHudScale, 3*g_currentMission.vehicleHudScale) |
99 | entry.statusBarColor = {0.0232, 0.4508, 0.8388, 1}; |
100 | entry.statusBarColor2 = {1, 0, 0, 1} |
101 | entry.statusBar = StatusBar:new("dataS2/menu/white.png", nil, entry.statusBarColor, {0.04, 0.04, 0.04, 1}, nil, 0, 0, width, height); |
102 | table.insert(self.mixerWagonFillTypes, entry); |
103 | end |
104 | i = i+1; |
105 | end; |
106 | |
107 | |
108 | if self.isServer then |
109 | self.mixerWagonBaleTriggerId = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.mixerWagonBaleTrigger#index")); |
110 | if self.mixerWagonBaleTriggerId ~= nil then |
111 | addTrigger(self.mixerWagonBaleTriggerId, "mixerWagonBaleTriggerCallback", self); |
112 | end |
113 | end |
114 | |
115 | self.mixingActiveTimerMax = 5000; |
116 | self.mixingActiveTimer = 0; |
117 | |
118 | fillTypeOverlayWidth, fillTypeOverlayHeight = getNormalizedScreenValues(7*g_currentMission.vehicleHudScale, 30*g_currentMission.vehicleHudScale); |
119 | _, self.fillTypeOverlayLineSpacing = getNormalizedScreenValues(0, 35*g_currentMission.vehicleHudScale); |
120 | self.mixerWagonFillTypeRangeMarkerLeftOverlay = Overlay:new("", "dataS2/menu/hud/mixerWagonHUD_rangeMarkerLeft.png", 0, 0, fillTypeOverlayWidth, fillTypeOverlayHeight); |
121 | self.mixerWagonFillTypeRangeMarkerRightOverlay = Overlay:new("", "dataS2/menu/hud/mixerWagonHUD_rangeMarkerLeft.png", 0, 0, fillTypeOverlayWidth, fillTypeOverlayHeight); |
122 | self.mixerWagonFillTypeRangeMarkerRightOverlay:setInvertX(true); |
123 | _, self.mixerFillLevelTextOffsetY = getNormalizedScreenValues(0, 5*g_currentMission.vehicleHudScale); |
124 | _, self.mixerStatusbarOffsetY = getNormalizedScreenValues(0, 14*g_currentMission.vehicleHudScale); |
125 | |
126 | |
127 | self.mixerWagonLastPickupTime = -10000; |
128 | |
129 | -- disable fill level sync and save of Fillable |
130 | self.synchronizeFillLevel = false; |
131 | |
132 | |
133 | self.mixerWagonDirtyFlag = self:getNextDirtyFlag(); |
134 | end; |
135 | |
136 | function MixerWagon:delete() |
137 | if self.isServer then |
138 | if self.mixerWagonBaleTriggerId ~= nil then |
139 | removeTrigger(self.mixerWagonBaleTriggerId); |
140 | end |
141 | end |
142 | |
143 | for _,entry in pairs(self.mixerWagonFillTypes) do |
144 | entry.statusBar:delete(); |
145 | end |
146 | if self.isClient then |
147 | Utils.deleteSample(self.sampleMixerWagonPickup); |
148 | Utils.deleteSample(self.sampleMixerWagonStart); |
149 | Utils.deleteSample(self.sampleMixerWagonStop); |
150 | end; |
151 | |
152 | self.mixerWagonFillTypeRangeMarkerLeftOverlay:delete(); |
153 | self.mixerWagonFillTypeRangeMarkerRightOverlay:delete(); |
154 | end; |
155 | |
156 | function MixerWagon:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) |
157 | self.fillLevel = 0; |
158 | for i=1, table.getn(self.mixerWagonFillTypes) do |
159 | local fillTypeKey = key..string.format(".mixerWagonFillType%d#fillLevel", i); |
160 | local fillLevel = getXMLFloat(xmlFile, fillTypeKey); |
161 | if fillLevel == nil then |
162 | fillLevel = 0; |
163 | end |
164 | self:setFillLevel(fillLevel, next(self.mixerWagonFillTypes[i].fillTypes)); |
165 | end |
166 | return BaseMission.VEHICLE_LOAD_OK; |
167 | end; |
168 | |
169 | function MixerWagon:getSaveAttributesAndNodes(nodeIdent) |
170 | local nodes = ""; |
171 | for i=1, table.getn(self.mixerWagonFillTypes) do |
172 | if i>1 then |
173 | nodes = nodes.."\n"; |
174 | end; |
175 | local fillLevel = self.mixerWagonFillTypes[i].fillLevel; |
176 | nodes = nodes.. nodeIdent..string.format('<mixerWagonFillType%d', i)..' fillLevel="'..fillLevel..'" />'; |
177 | end; |
178 | return "", nodes; |
179 | end; |
180 | |
181 | function MixerWagon:readStream(streamId, connection) |
182 | self.fillLevel = 0; |
183 | for i=1,table.getn(self.mixerWagonFillTypes) do |
184 | local fillLevel = streamReadFloat32(streamId); |
185 | self:setFillLevel(fillLevel, next(self.mixerWagonFillTypes[i].fillTypes)); |
186 | end |
187 | end |
188 | |
189 | function MixerWagon:writeStream(streamId, connection) |
190 | for i=1,table.getn(self.mixerWagonFillTypes) do |
191 | streamWriteFloat32(streamId, self.mixerWagonFillTypes[i].fillLevel); |
192 | end |
193 | end |
194 | |
195 | function MixerWagon:readUpdateStream(streamId, timestamp, connection) |
196 | if connection:getIsServer() then |
197 | if streamReadBool(streamId) then |
198 | self.mixingActiveTimer = streamReadUIntN(streamId, 4)/15 * self.mixingActiveTimerMax; |
199 | for i=1,table.getn(self.mixerWagonFillTypes) do |
200 | local fillLevel = streamReadUInt8(streamId)/255*self:getCapacity(); |
201 | self:setFillLevel(fillLevel, next(self.mixerWagonFillTypes[i].fillTypes)); |
202 | end |
203 | end; |
204 | end |
205 | end |
206 | |
207 | function MixerWagon:writeUpdateStream(streamId, connection, dirtyMask) |
208 | if not connection:getIsServer() then |
209 | if streamWriteBool(streamId, bitAND(dirtyMask, self.mixerWagonDirtyFlag) ~= 0) then |
210 | streamWriteUIntN(streamId, math.floor(self.mixingActiveTimer/self.mixingActiveTimerMax*15), 4); |
211 | for i=1,table.getn(self.mixerWagonFillTypes) do |
212 | local percent = 0; |
213 | if self:getCapacity() ~= 0 then |
214 | percent = Utils.clamp(self.mixerWagonFillTypes[i].fillLevel / self:getCapacity(), 0, 1); |
215 | end; |
216 | streamWriteUInt8(streamId, math.floor(percent*255)); |
217 | end |
218 | end |
219 | end |
220 | end; |
221 | |
222 | function MixerWagon:mouseEvent(posX, posY, isDown, isUp, button) |
223 | end; |
224 | |
225 | function MixerWagon:keyEvent(unicode, sym, modifier, isDown) |
226 | end; |
227 | |
228 | function MixerWagon:update(dt) |
229 | if self.isClient then |
230 | if self:getIsActive() then |
231 | if self.mixingActiveTimer > 0 or self:getIsTurnedOn() or self.tipState == Trailer.TIPSTATE_OPENING or self.tipState == Trailer.TIPSTATE_OPEN then |
232 | if self:getIsActiveForSound() then |
233 | if not Utils.isSamplePlaying(self.sampleMixerWagonStart, 1.8*dt) then |
234 | Utils.playSample(self.sampleMixerWagonPickup, 0, 0, nil); |
235 | end |
236 | else |
237 | Utils.play3DSample(self.sampleMixerWagonPickup); |
238 | end |
239 | if Utils.isSamplePlaying(self.sampleMixerWagonPickup) then |
240 | if self.mixerWagonLastPickupTime >= g_currentMission.time-200 then |
241 | Utils.setSamplePitch(self.sampleMixerWagonPickup, self.mixerWagonPickupSoundPickupPitchOffset); |
242 | else |
243 | Utils.setSamplePitch(self.sampleMixerWagonPickup, self.mixerWagonPickupSoundPitchOffset); |
244 | end; |
245 | end |
246 | else |
247 | if self:getIsActiveForSound() then |
248 | Utils.stopSample(self.sampleMixerWagonPickup); |
249 | else |
250 | Utils.stop3DSample(self.sampleMixerWagonPickup); |
251 | end; |
252 | end |
253 | end |
254 | |
255 | -- update pickup rotating parts |
256 | Utils.updateRotationNodes(self, self.mixerWagonPickupRotatingParts, dt, self:getIsActive() and self:getIsTurnedOn()); |
257 | Utils.updateRotationNodes(self, self.mixerWagonMixRotatingParts, dt, self.mixingActiveTimer > 0 or self:getIsTurnedOn() or self.tipState == Trailer.TIPSTATE_OPENING or self.tipState == Trailer.TIPSTATE_OPEN); |
258 | end; |
259 | |
260 | if self.mixingActiveTimer > 0 or self:getIsTurnedOn() or self.tipState == Trailer.TIPSTATE_OPENING or self.tipState == Trailer.TIPSTATE_OPEN then |
261 | self.mixingActiveTimer = self.mixingActiveTimer - dt; |
262 | end |
263 | end; |
264 | |
265 | function MixerWagon:updateTick(dt) |
266 | end; |
267 | |
268 | function MixerWagon:draw() |
269 | if self:getIsActiveForInput(true) then |
270 | local numFillTypes = table.getn(self.mixerWagonFillTypes); |
271 | if numFillTypes > 0 then |
272 | local helpHeight = g_currentMission.hudHelpTextSize + 2*g_currentMission.hudHelpTextLineSpacing; |
273 | helpHeight = helpHeight + numFillTypes*self.fillTypeOverlayLineSpacing; |
274 | g_currentMission:addHelpTextFunction(self.drawMixerWagonHelp, self, helpHeight, nil); |
275 | end |
276 | end |
277 | end; |
278 | |
279 | function MixerWagon:onDetach() |
280 | end; |
281 | |
282 | function MixerWagon:onLeave() |
283 | end; |
284 | |
285 | function MixerWagon:onDeactivateSounds() |
286 | if self.isClient then |
287 | Utils.stopSample(self.sampleMixerWagonPickup, true); |
288 | Utils.stopSample(self.sampleMixerWagonStart, true); |
289 | Utils.stop3DSample(self.sampleMixerWagonPickup); |
290 | end; |
291 | end; |
292 | |
293 | -- overwrite Fillable.resetFillLevelIfNeeded |
294 | function MixerWagon:resetFillLevelIfNeeded(superFunc, fillType) |
295 | local mixerWagonFillType = self.fillTypeToMixerWagonFillType[fillType]; |
296 | if mixerWagonFillType ~= nil then |
297 | -- nothing to do |
298 | return; |
299 | end |
300 | superFunc(self, fillType); |
301 | end; |
302 | |
303 | function MixerWagon:allowFillType(superFunc, fillType, allowEmptying) |
304 | local mixerWagonFillType = self.fillTypeToMixerWagonFillType[fillType]; |
305 | if mixerWagonFillType ~= nil then |
306 | return true; |
307 | end |
308 | |
309 | return superFunc(self, fillType, allowEmptying); |
310 | end |
311 | |
312 | function MixerWagon:getFillLevel(superFunc, fillType) |
313 | local mixerWagonFillType = self.fillTypeToMixerWagonFillType[fillType]; |
314 | if mixerWagonFillType ~= nil then |
315 | return mixerWagonFillType.fillLevel; |
316 | end |
317 | return superFunc(self, fillType); |
318 | end |
319 | |
320 | function MixerWagon:setFillLevel(superFunc, fillLevel, fillType, force, fillSourceStruct) |
321 | |
322 | local mixerWagonFillType = self.fillTypeToMixerWagonFillType[fillType]; |
323 | if mixerWagonFillType == nil then |
324 | |
325 | if self:allowFillType(fillType) and fillLevel < self.fillLevel and self.fillLevel > 0 then |
326 | -- remove values from all fill types such that the ratio doesn't change |
327 | fillLevel = Utils.clamp(fillLevel, 0, self:getCapacity()); |
328 | local delta = fillLevel - self.fillLevel; |
329 | local newFillLevel = 0; |
330 | for _, entry in pairs(self.mixerWagonFillTypes) do |
331 | entry.fillLevel = math.max(entry.fillLevel + delta * entry.fillLevel / self.fillLevel, 0); |
332 | newFillLevel = newFillLevel + entry.fillLevel; |
333 | end |
334 | |
335 | self:raiseDirtyFlags(self.mixerWagonDirtyFlag); |
336 | |
337 | superFunc(self, newFillLevel, self.currentFillType, force, fillSourceStruct); |
338 | end |
339 | |
340 | return; |
341 | |
342 | end |
343 | |
344 | local isSingleFilled = (self.fillLevel == mixerWagonFillType.fillLevel) and self:mixerWagonSuperAllowFillType(fillType); |
345 | |
346 | local limitedFillLevel = fillLevel; |
347 | limitedFillLevel = math.min(limitedFillLevel, self:getCapacity() - self.fillLevel + mixerWagonFillType.fillLevel); |
348 | -- dont check for validity any more. player can always empty a bit of the forage mixing at the feeding trough and fill up later |
349 | --[[if not isSingleFilled then |
350 | -- make sure that we are not above the max percentage |
351 | limitedFillLevel = math.min(limitedFillLevel, mixerWagonFillType.maxPercentage * self:getCapacity()); |
352 | -- check that all other minPercentages can still be fullfilled |
353 | local othersMinPercentagesFillLevel = 0; |
354 | for _, entry in pairs(self.mixerWagonFillTypes) do |
355 | if entry ~= mixerWagonFillType then |
356 | othersMinPercentagesFillLevel = othersMinPercentagesFillLevel + entry.minPercentage * self:getCapacity() |
357 | end |
358 | end |
359 | limitedFillLevel = math.min(limitedFillLevel, self:getCapacity()-othersMinPercentagesFillLevel); |
360 | end]] |
361 | limitedFillLevel = Utils.clamp(limitedFillLevel, 0, self:getCapacity()); |
362 | |
363 | if limitedFillLevel ~= mixerWagonFillType.fillLevel then |
364 | mixerWagonFillType.fillLevel = limitedFillLevel; |
365 | self:raiseDirtyFlags(self.mixerWagonDirtyFlag); |
366 | end |
367 | |
368 | -- calculate new fill level and forage is ok |
369 | local newFillLevel = 0; |
370 | local isForageOk = true; |
371 | for _, entry in pairs(self.mixerWagonFillTypes) do |
372 | newFillLevel = newFillLevel + entry.fillLevel; |
373 | end |
374 | for _, entry in pairs(self.mixerWagonFillTypes) do |
375 | if entry.fillLevel < entry.minPercentage * newFillLevel-0.01 or entry.fillLevel > entry.maxPercentage * newFillLevel + 0.01 then |
376 | isForageOk = false; |
377 | break; |
378 | end |
379 | end |
380 | |
381 | local newFillType = Fillable.FILLTYPE_FORAGE_MIXING; |
382 | if isForageOk then |
383 | newFillType = Fillable.FILLTYPE_FORAGE; |
384 | else |
385 | if isSingleFilled then |
386 | newFillType = fillType; |
387 | else |
388 | -- maybe we are single filled now |
389 | local singleFilledFillType; |
390 | for _, entry in pairs(self.mixerWagonFillTypes) do |
391 | if entry.fillLevel == newFillLevel then |
392 | isSingleFilled = true; |
393 | newFillType = next(entry.fillTypes); |
394 | break; |
395 | end |
396 | end |
397 | end |
398 | end |
399 | |
400 | superFunc(self, newFillLevel, newFillType, true, fillSourceStruct); |
401 | end |
402 | |
403 | function MixerWagon:mixerWagonBaleTriggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) |
404 | if onEnter then |
405 | -- this happens if a compound child of a deleted compound is entering |
406 | if otherActorId ~= 0 then |
407 | local object = g_currentMission:getNodeObject(otherActorId); |
408 | if object ~= nil then |
409 | if object:isa(Bale) then |
410 | local fillLevel = object:getFillLevel(); |
411 | local fillType = object:getFillType(); |
412 | if self:allowFillType(fillType, false) then |
413 | self:setFillLevel(self:getFillLevel(fillType)+fillLevel, fillType, false); |
414 | end |
415 | object:delete(); |
416 | |
417 | self.mixingActiveTimer = self.mixingActiveTimerMax; |
418 | self:raiseDirtyFlags(self.mixerWagonDirtyFlag); |
419 | end; |
420 | end; |
421 | end; |
422 | end; |
423 | end; |
424 | |
425 | function MixerWagon:drawMixerWagonHelp(posY, param) |
426 | -- do not draw mixer wagon help when in game message is visible |
427 | if g_currentMission.inGameMessage:getIsVisible() then return; end; |
428 | |
429 | local posX = g_currentMission.hudHelpTextPosX1; |
430 | local posX2 = g_currentMission.hudHelpTextPosX2; |
431 | |
432 | posY = posY - g_currentMission.hudHelpTextSize - 2*g_currentMission.hudHelpTextLineSpacing; |
433 | setTextBold(true); |
434 | renderText(posX, posY, g_currentMission.hudHelpTextSize, g_i18n:getText("mixing_ratio")); |
435 | setTextBold(false); |
436 | |
437 | |
438 | for _, mixerWagonFillType in pairs(self.mixerWagonFillTypes) do |
439 | posY = posY - self.fillTypeOverlayLineSpacing; |
440 | |
441 | local percentage = 0; |
442 | if self.fillLevel > 0 then |
443 | percentage = mixerWagonFillType.fillLevel / self.fillLevel; |
444 | end |
445 | |
446 | if mixerWagonFillType.fillLevel > 0 then |
447 | if self.currentFillType ~= Fillable.FILLTYPE_FORAGE_MIXING or (percentage >= mixerWagonFillType.minPercentage and percentage <= mixerWagonFillType.maxPercentage) then |
448 | mixerWagonFillType.statusBar:setColor(unpack(mixerWagonFillType.statusBarColor)); |
449 | else |
450 | mixerWagonFillType.statusBar:setColor(unpack(mixerWagonFillType.statusBarColor2)); |
451 | end |
452 | end |
453 | mixerWagonFillType.statusBar:setPosition(posX2 - mixerWagonFillType.statusBar.width, posY+self.mixerStatusbarOffsetY); |
454 | mixerWagonFillType.statusBar:setValue(percentage); |
455 | mixerWagonFillType.statusBar:render(); |
456 | |
457 | |
458 | |
459 | renderText(posX, posY + (self.fillTypeOverlayLineSpacing-g_currentMission.hudHelpTextSize)/2, g_currentMission.hudHelpTextSize, mixerWagonFillType.nameI18N); |
460 | |
461 | setTextAlignment(RenderText.ALIGN_CENTER); |
462 | renderText(mixerWagonFillType.statusBar.x + mixerWagonFillType.statusBar.width/2, mixerWagonFillType.statusBar.y + mixerWagonFillType.statusBar.height + self.mixerFillLevelTextOffsetY, getCorrectTextSize(0.02*g_currentMission.vehicleHudScale), string.format("%1.2f%%", percentage * 100)); |
463 | setTextAlignment(RenderText.ALIGN_LEFT); |
464 | |
465 | |
466 | -- draw range markers |
467 | local y = mixerWagonFillType.statusBar.y + mixerWagonFillType.statusBar.height /2 + (mixerWagonFillType.statusBar.height - self.mixerWagonFillTypeRangeMarkerRightOverlay.height)/2; |
468 | local maxLeft = mixerWagonFillType.statusBar.x + mixerWagonFillType.statusBar.width; |
469 | self.mixerWagonFillTypeRangeMarkerLeftOverlay.x = math.min(mixerWagonFillType.statusBar.x + mixerWagonFillType.statusBar.width*mixerWagonFillType.minPercentage, maxLeft); |
470 | self.mixerWagonFillTypeRangeMarkerRightOverlay.x = math.min(mixerWagonFillType.statusBar.x + mixerWagonFillType.statusBar.width*mixerWagonFillType.maxPercentage, maxLeft); |
471 | self.mixerWagonFillTypeRangeMarkerLeftOverlay.y = y; |
472 | self.mixerWagonFillTypeRangeMarkerRightOverlay.y = y; |
473 | self.mixerWagonFillTypeRangeMarkerLeftOverlay:render(); |
474 | self.mixerWagonFillTypeRangeMarkerRightOverlay:render(); |
475 | end |
476 | end |
477 | |
478 | function MixerWagon:onTurnedOn(noEventSend) |
479 | if self.isClient then |
480 | Utils.stopSample(self.sampleMixerWagonStop); |
481 | if self:getIsActiveForSound() then |
482 | Utils.playSample(self.sampleMixerWagonStart, 1, 0, nil); |
483 | end; |
484 | end; |
485 | end; |
486 | |
487 | function MixerWagon:onTurnedOff(noEventSend) |
488 | if self.isClient then |
489 | Utils.stopSample(self.sampleMixerWagonStart); |
490 | if self:getIsActiveForSound() then |
491 | Utils.playSample(self.sampleMixerWagonStop, 1, 0, nil); |
492 | end; |
493 | end; |
494 | end; |
495 | |
496 | function MixerWagon:getCanBeTurnedOn(superFunc) |
497 | if not self.mixerWagonNeedsTurnOn then |
498 | return false; |
499 | end; |
500 | |
501 | if superFunc ~= nil then |
502 | return superFunc(self, isTurnedOn); |
503 | end |
504 | return true; |
505 | end; |
506 | |
507 | function MixerWagon:getIsTurnedOnAllowed(superFunc, isTurnedOn) |
508 | if not self.mixerWagonNeedsTurnOn then |
509 | return false; |
510 | end; |
511 | |
512 | if superFunc ~= nil then |
513 | return superFunc(self, isTurnedOn); |
514 | end |
515 | return true; |
516 | end; |
517 | |
518 | function MixerWagon:getAllowFillShovel(superFunc, fillType) |
519 | if self:getIsTurnedOn() then |
520 | if superFunc ~= nil then |
521 | return superFunc(self, fillType); |
522 | end |
523 | end |
524 | return false; |
525 | end; |
526 | |
527 | function MixerWagon:fillShovelFromGroundValue(superFunc, areas, fillType) |
528 | local value = false; |
529 | if superFunc ~= nil then |
530 | value = superFunc(self, areas, fillType) |
531 | end |
532 | if value then |
533 | self.mixerWagonLastPickupTime = g_currentMission.time; |
534 | end |
535 | return value; |
536 | end |
537 | |
538 | function MixerWagon:fillShovelFromTrigger(superFunc, shovelTrigger, deltaFillLevel, fillType, dt) |
539 | local value = 0; |
540 | if superFunc ~= nil then |
541 | value = superFunc(self, shovelTrigger, deltaFillLevel, fillType, dt) |
542 | end |
543 | if value > 0 then |
544 | self.mixerWagonLastPickupTime = g_currentMission.time; |
545 | end |
546 | return value; |
547 | end
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de