31 | function AttacherJointControl:load(savegame) |
32 | |
33 | self.updateAttacherJoint = AttacherJointControl.updateAttacherJoint; |
34 | |
35 | self.attacherJointControl = {}; |
36 | |
37 | local uiScale = g_gameSettings:getValue("uiScale") |
38 | |
39 | self.attacherJointControl.controls = {}; |
40 | for i=1,2 do |
41 | local key = string.format("vehicle.attacherJointControl.control%d", i); |
42 | if not hasXMLProperty(self.xmlFile, key) then |
43 | break; |
44 | end |
45 | local control = {}; |
46 | |
47 | control.controlAxis = getXMLString(self.xmlFile, key .. "#controlAxis"); |
48 | |
49 | if control.controlAxis ~= nil then |
50 | control.controlActionIndex = InputBinding[control.controlAxis]; |
51 | if control.controlActionIndex ~= nil then |
52 | self:addConflictCheckedInput(control.controlActionIndex); |
53 | end |
54 | end |
55 | |
56 | control.invertControlAxis = Utils.getNoNil( getXMLString(self.xmlFile, key .. "#invertControlAxis"), false ); |
57 | control.mouseSpeedFactor = Utils.getNoNil( getXMLFloat(self.xmlFile, key .. "#mouseSpeedFactor"), 1.0 ); |
58 | |
59 | control.iconFilename = getXMLString(self.xmlFile, key .. "#controlAxisIcon"); |
60 | if control.iconFilename ~= nil then |
61 | local iconFilename = Utils.getFilename(control.iconFilename, self.baseDirectory); |
62 | local iconWidth, iconHeight = getNormalizedScreenValues(40*uiScale, 40*uiScale); |
63 | control.controlAxisIcon = Overlay:new("axisIcon", iconFilename, 0, 0, iconWidth, iconHeight); |
64 | control.controlAxisIcon:setAlignment(Overlay.ALIGN_VERTICAL_MIDDLE, Overlay.ALIGN_HORIZONTAL_LEFT); |
65 | end |
66 | |
67 | control.moveAlpha = 0; |
68 | control.moveAlphaSend = 0; |
69 | |
70 | table.insert(self.attacherJointControl.controls, control); |
71 | end |
72 | |
73 | self.lastDirtyTime = -10000; |
74 | |
75 | self.attacherJointControl.dirtyFlag = self:getNextDirtyFlag(); |
76 | |
77 | end; |
164 | function AttacherJointControl:update(dt) |
165 | |
166 | if self.attacherJointControl ~= nil and self.attacherJointControl.controls ~= nil and self.attacherJointControl.jointDesc ~= nil then |
167 | |
168 | if self.isClient and self:getIsActiveForInput(false) and not self:hasInputConflictWithSelection() and self.attacherJoint.isControllable then |
169 | |
170 | for i=1,2 do |
171 | local control = self.attacherJointControl.controls[i]; |
172 | |
173 | if control.controlActionIndex ~= nil then |
174 | if control.controlAxisIcon ~= nil then |
175 | g_currentMission:addHelpAxis(control.controlActionIndex, control.controlAxisIcon) |
176 | end |
177 | |
178 | local move, axisType = InputBinding.getInputAxis(control.controlActionIndex); |
179 | if control.invertControlAxis then |
180 | move = -move; |
181 | end |
182 | if axisType == InputBinding.INPUTTYPE_MOUSE_AXIS then |
183 | move = move * control.mouseSpeedFactor; |
184 | else |
185 | move = move * g_gameSettings:getValue("vehicleArmSensitivity") |
186 | end |
187 | |
188 | local isAxisZero = InputBinding.isAxisZero(move); |
189 | |
190 | if not isAxisZero then |
191 | local jointDesc = self.attacherJointControl.jointDesc; |
192 | |
193 | local moveAlpha = control.moveAlpha + (0.001 * dt * move); |
194 | control.moveAlpha = Utils.clamp(moveAlpha, jointDesc.upperAlpha, jointDesc.lowerAlpha); |
195 | end |
196 | end |
197 | end |
198 | |
199 | local isDirty = false; |
200 | for i=1,2 do |
201 | local control = self.attacherJointControl.controls[i]; |
202 | if control.moveAlphaSend ~= control.moveAlpha then |
203 | control.moveAlphaSend = control.moveAlpha; |
204 | isDirty = true; |
205 | end |
206 | end |
207 | if isDirty then |
208 | self:raiseDirtyFlags(self.attacherJointControl.dirtyFlag); |
209 | self:updateAttacherJoint(self.attacherJointControl.controls[1].moveAlpha, self.attacherJointControl.controls[2].moveAlpha); |
210 | self.lastDirtyTime = g_currentMission.time; |
211 | end |
212 | |
213 | if self:getIsActiveForSound() and self.attacherVehicle ~= nil and self.attacherVehicle.sampleHydraulic ~= nil and self.attacherVehicle.sampleHydraulic.sample ~= nil then |
214 | if math.abs(self.lastDirtyTime - g_currentMission.time) <= 125 then |
215 | if self.startedSample == nil then |
216 | SoundUtil.playSample(self.attacherVehicle.sampleHydraulic, 0, 0, nil); |
217 | self.attacherVehicle.sampleHydraulic.isPlaying = false; |
218 | self.startedSample = self.attacherVehicle.sampleHydraulic; |
219 | end |
220 | elseif self.startedSample ~= nil then |
221 | SoundUtil.stopSample(self.startedSample, true); |
222 | self.startedSample = nil; |
223 | end |
224 | end |
225 | |
226 | end |
227 | end; |
228 | end; |
240 | function AttacherJointControl:onAttach(attacherVehicle, jointDescIndex) |
241 | if attacherVehicle.attacherJoints[jointDescIndex] ~= nil then |
242 | for i=1,2 do |
243 | local control = self.attacherJointControl.controls[i]; |
244 | if control.controlActionIndex ~= nil then |
245 | if not self.attacherJoint.isControllable then |
246 | self:removeConflictCheckedInput(control.controlActionIndex); |
247 | else |
248 | self:addConflictCheckedInput(control.controlActionIndex); |
249 | end; |
250 | end |
251 | end |
252 | end |
253 | local jointDesc = attacherVehicle.attacherJoints[jointDescIndex] |
254 | jointDesc.allowsLoweringBackup = jointDesc.allowsLowering; |
255 | jointDesc.allowsLowering = false; |
256 | |
257 | self.attacherJointControl.jointDesc = jointDesc; |
258 | |
259 | --jnself.applyInitialRotation = true; |
260 | self.attacherJointControl.controls[1].moveAlpha = 0.5; |
261 | self.attacherJointControl.controls[2].moveAlpha = 0.5; |
262 | end |
277 | function AttacherJointControl:updateAttacherJoint(moveAlpha1, moveAlpha2) |
278 | local jointDesc = self.attacherJointControl.jointDesc; |
279 | |
280 | self.attacherJointControl.controls[1].moveAlpha = moveAlpha1; |
281 | self.attacherJointControl.controls[2].moveAlpha = moveAlpha2; |
282 | self.attacherJointControl.controls[1].moveAlphaSend = moveAlpha1; |
283 | self.attacherJointControl.controls[2].moveAlphaSend = moveAlpha2; |
284 | |
285 | if jointDesc ~= nil then |
286 | if jointDesc.rotationNode ~= nil then |
287 | setRotation(jointDesc.rotationNode, Utils.vector3ArrayLerp(jointDesc.upperRotation, jointDesc.lowerRotation, moveAlpha1)); |
288 | end |
289 | if jointDesc.rotationNode2 ~= nil then |
290 | setRotation(jointDesc.rotationNode2, Utils.vector3ArrayLerp(jointDesc.upperRotation2, jointDesc.lowerRotation2, moveAlpha2)); |
291 | end |
292 | self.attacherVehicle:updateAttacherJointRotation(jointDesc, self); |
293 | |
294 | if self.isServer and jointDesc.jointIndex ~= 0 then |
295 | setJointFrame(jointDesc.jointIndex, 0, jointDesc.jointTransform) |
296 | end |
297 | end |
298 | end |