Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- |
2 | -- IndoorHud |
3 | -- Class for all IndoorHuds |
4 | -- |
5 | -- @author Manuel Leithner |
6 | -- @date 23/07/14 |
7 | -- |
8 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
9 | |
10 | IndoorHud = {}; |
11 | |
12 | function IndoorHud.prerequisitesPresent(specializations) |
13 | return SpecializationUtil.hasSpecialization(AnimatedVehicle, specializations) and SpecializationUtil.hasSpecialization(Motorized, specializations); |
14 | end; |
15 | |
16 | function IndoorHud:load(xmlFile) |
17 | |
18 | self.setHudValue = IndoorHud.setHudValue; |
19 | |
20 | self.indoorHud = {}; |
21 | self.indoorHud.speed = IndoorHud.loadValue(self, xmlFile, "speed"); |
22 | self.indoorHud.rpm = IndoorHud.loadValue(self, xmlFile, "rpm"); |
23 | self.indoorHud.fuel = IndoorHud.loadValue(self, xmlFile, "fuel"); |
24 | self.indoorHud.fillLevel = IndoorHud.loadValue(self, xmlFile, "fillLevel"); |
25 | self.indoorHud.operatingTime = IndoorHud.loadValue(self, xmlFile, "operatingTime"); |
26 | self.indoorHud.workedHectars = IndoorHud.loadValue(self, xmlFile, "workedHectars"); |
27 | self.indoorHud.diameter = IndoorHud.loadValue(self, xmlFile, "diameter"); |
28 | self.indoorHud.cutLength = IndoorHud.loadValue(self, xmlFile, "cutLength"); |
29 | self.indoorHud.time = IndoorHud.loadValue(self, xmlFile, "time"); |
30 | self.indoorHud.cruiseControl = IndoorHud.loadValue(self, xmlFile, "cruiseControl"); |
31 | end; |
32 | |
33 | function IndoorHud:loadValue(xmlFile, name) |
34 | local numbers = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.indoorHud."..name.."#numbers")); |
35 | local animName = getXMLString(xmlFile, "vehicle.indoorHud."..name.."#animName"); |
36 | |
37 | if numbers ~= nil or animName ~= nil then |
38 | local precision = nil; |
39 | local numChilds = nil; |
40 | local maxValue = nil; |
41 | if numbers ~= nil then |
42 | precision = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.indoorHud."..name.."#precision"), 1); |
43 | numChilds = getNumOfChildren(numbers); |
44 | if numChilds-precision <= 0 then |
45 | print("Warning: Not enough number meshes in '"..self.configFileName.."'"); |
46 | end; |
47 | numChilds = numChilds - precision; |
48 | maxValue = (10 ^ (numChilds)) - 1/(10^precision); -- e.g. max with 2 childs and 1 float -> 10^2 - 1/10 -> 99.9 -> makes sure that display doesn't show 00.0 if value is 100 |
49 | end; |
50 | |
51 | local hud = {numbers=numbers, animName=animName, lastNormValue=0, lastValue=-1, precision=precision, maxValue=maxValue, numChilds=numChilds}; |
52 | |
53 | self:setHudValue(hud, 0, 0); |
54 | |
55 | return hud; |
56 | end; |
57 | |
58 | return nil; |
59 | end; |
60 | |
61 | function IndoorHud:delete() |
62 | end; |
63 | |
64 | function IndoorHud:mouseEvent(posX, posY, isDown, isUp, button) |
65 | end; |
66 | |
67 | function IndoorHud:keyEvent(unicode, sym, modifier, isDown) |
68 | end; |
69 | |
70 | function IndoorHud:update(dt) |
71 | end; |
72 | |
73 | function IndoorHud:updateTick(dt) |
74 | if self:getIsActive() then |
75 | if self.indoorHud.speed ~= nil then |
76 | local maxSpeed = 30; |
77 | if self.cruiseControl ~= nil then |
78 | maxSpeed = self.cruiseControl.maxSpeed; |
79 | end; |
80 | self:setHudValue(self.indoorHud.speed, g_i18n:getSpeed(self:getLastSpeed() * self.speedDisplayScale), g_i18n:getSpeed(maxSpeed)); |
81 | end; |
82 | if self.indoorHud.rpm ~= nil then |
83 | self:setHudValue(self.indoorHud.rpm, self.motor.lastMotorRpm, self.motor.maxRpm); |
84 | end; |
85 | if self.indoorHud.fuel ~= nil then |
86 | self:setHudValue(self.indoorHud.fuel, self.fuelFillLevel, self.fuelCapacity); |
87 | end; |
88 | if self.indoorHud.fillLevel ~= nil and self.fillLevel ~= nil and self.getCapacity ~= nil and self:getCapacity() ~= 0 then |
89 | self:setHudValue(self.indoorHud.fillLevel, self.fillLevel, self:getCapacity()); |
90 | end; |
91 | if self.indoorHud.operatingTime ~= nil and self.operatingTime ~= nil then |
92 | local minutes = self.operatingTime / (1000 * 60); |
93 | local hours = math.floor(minutes / 60); |
94 | minutes = math.floor(minutes - hours * 60); |
95 | |
96 | local minutesString = string.format("%02d", minutes); |
97 | self:setHudValue(self.indoorHud.operatingTime, tonumber(hours.."."..minutesString), self.maxOperatingTime); |
98 | |
99 | end; |
100 | if self.indoorHud.workedHectars ~= nil and self.workedHectars ~= nil then |
101 | self:setHudValue(self.indoorHud.workedHectars, self.workedHectars, 9999); |
102 | end; |
103 | if self.indoorHud.diameter ~= nil and self.lastDiameter ~= nil then |
104 | self:setHudValue(self.indoorHud.diameter, self.lastDiameter*1000, 9999); |
105 | end; |
106 | if self.indoorHud.cutLength ~= nil and self.currentCutLength ~= nil then |
107 | self:setHudValue(self.indoorHud.cutLength, self.currentCutLength*100, 9999); |
108 | end; |
109 | if self.indoorHud.time ~= nil then |
110 | local minutes = g_currentMission.environment.currentMinute; |
111 | local hours = g_currentMission.environment.currentHour; |
112 | local minutesString = string.format("%02d", minutes); |
113 | self:setHudValue(self.indoorHud.time, tonumber(hours.."."..minutesString), 9999); |
114 | end; |
115 | if self.indoorHud.cruiseControl ~= nil and self.cruiseControl ~= nil then |
116 | self:setHudValue(self.indoorHud.cruiseControl, self.cruiseControl.speed, 9999); |
117 | end; |
118 | end; |
119 | end; |
120 | |
121 | function IndoorHud:draw() |
122 | end; |
123 | |
124 | function IndoorHud:setHudValue(hud, value, maxValue) |
125 | if hud.numbers ~= nil then |
126 | if math.abs(hud.lastValue-value) > 1/(10^(hud.precision+1)) then |
127 | local displayedValue = math.min(hud.maxValue, math.max(0, value)); |
128 | local speed = tonumber(string.format("%."..hud.precision.."f", displayedValue)); |
129 | Utils.setNumberShaderByValue(hud.numbers, speed, hud.precision, true); |
130 | hud.lastValue = value; |
131 | end; |
132 | end; |
133 | if hud.animName ~= nil then |
134 | local normValue = Utils.round(value/maxValue, 3); |
135 | if maxValue == 0 then |
136 | normValue = 0; |
137 | end; |
138 | if math.abs(hud.lastNormValue - normValue) > 0.01 then |
139 | self:setAnimationTime(hud.animName, normValue, true); |
140 | hud.lastNormValue = normValue; |
141 | end; |
142 | end; |
143 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de