Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- |
2 | -- TurnOnVehicle |
3 | -- Class for all TurnOnVehicles |
4 | -- |
5 | -- @author Manuel Leithner |
6 | -- @date 19/05/14 |
7 | -- |
8 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
9 | |
10 | TurnOnVehicle = {}; |
11 | source("dataS/scripts/vehicles/specializations/SetTurnedOnEvent.lua"); |
12 | |
13 | function TurnOnVehicle.prerequisitesPresent(specializations) |
14 | return true; |
15 | end; |
16 | |
17 | function TurnOnVehicle:preLoad(xmlFile) |
18 | assert(self.setIsTurnedOn == nil, "TurnOnVehicle needs to be the first specialization which implements setIsTurnedOn"); |
19 | self.setIsTurnedOn = TurnOnVehicle.setIsTurnedOn; |
20 | assert(self.getIsTurnedOnAllowed == nil, "TurnOnVehicle needs to be the first specialization which implements getIsTurnedOnAllowed"); |
21 | self.getIsTurnedOnAllowed = TurnOnVehicle.getIsTurnedOnAllowed; |
22 | assert(self.getIsTurnedOn == nil, "TurnOnVehicle needs to be the first specialization which implements getIsTurnedOn"); |
23 | self.getIsTurnedOn = TurnOnVehicle.getIsTurnedOn; |
24 | assert(self.getTurnedOnNotAllowedWarning == nil, "TurnOnVehicle needs to be the first specialization which implements getTurnedOnNotAllowedWarning"); |
25 | self.getTurnedOnNotAllowedWarning = TurnOnVehicle.getTurnedOnNotAllowedWarning; |
26 | assert(self.getCanBeTurnedOn == nil, "TurnOnVehicle needs to be the first specialization which implements getCanBeTurnedOn"); |
27 | self.getCanBeTurnedOn = TurnOnVehicle.getCanBeTurnedOn; |
28 | |
29 | self.loadInputAttacherJoint = Utils.overwrittenFunction(self.loadInputAttacherJoint, TurnOnVehicle.loadInputAttacherJoint); |
30 | self.loadWorkAreaFromXML = Utils.overwrittenFunction(self.loadWorkAreaFromXML, TurnOnVehicle.loadWorkAreaFromXML); |
31 | end |
32 | |
33 | function TurnOnVehicle:load(xmlFile) |
34 | |
35 | self.onTurnedOn = SpecializationUtil.callSpecializationsFunction("onTurnedOn"); |
36 | self.onTurnedOff = SpecializationUtil.callSpecializationsFunction("onTurnedOff"); |
37 | self.getIsWorkAreaActive = Utils.overwrittenFunction(self.getIsWorkAreaActive, TurnOnVehicle.getIsWorkAreaActive); |
38 | |
39 | local turnOnButtonStr = getXMLString(xmlFile, "vehicle.turnOnSettings#toggleButton"); |
40 | if turnOnButtonStr ~= nil then |
41 | self.toggleTurnOnInputBinding = InputBinding[turnOnButtonStr]; |
42 | end |
43 | |
44 | self.toggleTurnOnInputBinding = Utils.getNoNil(self.toggleTurnOnInputBinding, InputBinding.IMPLEMENT_EXTRA); |
45 | self.turnOffText = Utils.getNoNil(getXMLString(xmlFile, "vehicle.turnOnSettings#turnOffText"), "turn_off_OBJECT"); |
46 | self.turnOnText = Utils.getNoNil(getXMLString(xmlFile, "vehicle.turnOnSettings#turnOnText"), "turn_on_OBJECT"); |
47 | self.needsSelection = Utils.getNoNil(getXMLBool(xmlFile, "vehicle.turnOnSettings#needsSelection"), true); |
48 | self.isTurnedOn = false; |
49 | self.isSelectable = true; |
50 | self.isAlwaysTurnedOn = Utils.getNoNil(getXMLBool(xmlFile, "vehicle.turnOnSettings#isAlwaysTurnedOn"), false); |
51 | |
52 | self:addConflictCheckedInput(self.toggleTurnOnInputBinding); |
53 | end; |
54 | |
55 | function TurnOnVehicle:loadInputAttacherJoint(superFunc, xmlFile, key, inputAttacherJoint) |
56 | if superFunc ~= nil then |
57 | if not superFunc(self, xmlFile, key, inputAttacherJoint) then |
58 | return false; |
59 | end |
60 | end; |
61 | |
62 | inputAttacherJoint.canBeTurnedOn = Utils.getNoNil(getXMLBool(xmlFile, key.. "#canBeTurnedOn"), true); |
63 | |
64 | return true; |
65 | end |
66 | |
67 | function TurnOnVehicle:loadWorkAreaFromXML(superFunc, workArea, xmlFile, key) |
68 | local retValue = true; |
69 | if superFunc ~= nil then |
70 | retValue = superFunc(self, workArea, xmlFile, key) |
71 | end |
72 | |
73 | workArea.needsSetIsTurnedOn = Utils.getNoNil( getXMLBool(xmlFile, key.."#needsSetIsTurnedOn"), true ); |
74 | |
75 | return retValue; |
76 | end; |
77 | |
78 | function TurnOnVehicle:delete() |
79 | end; |
80 | |
81 | function TurnOnVehicle:readStream(streamId, connection) |
82 | local turnedOn = streamReadBool(streamId); |
83 | self:setIsTurnedOn(turnedOn, true); |
84 | end; |
85 | |
86 | function TurnOnVehicle:writeStream(streamId, connection) |
87 | streamWriteBool(streamId, self.isTurnedOn); |
88 | end; |
89 | |
90 | function TurnOnVehicle:mouseEvent(posX, posY, isDown, isUp, button) |
91 | end; |
92 | |
93 | function TurnOnVehicle:keyEvent(unicode, sym, modifier, isDown) |
94 | end; |
95 | |
96 | function TurnOnVehicle:update(dt) |
97 | if self:getIsActive() then |
98 | if self:getCanBeTurnedOn() then |
99 | if InputBinding.hasEvent(self.toggleTurnOnInputBinding) then |
100 | if self:getIsActiveForInput(self.needsSelection) and not self:hasInputConflictWithSelection() then |
101 | if self:getIsTurnedOnAllowed(not self.isTurnedOn) then |
102 | self:setIsTurnedOn(not self.isTurnedOn); |
103 | else |
104 | if not self.isTurnedOn then |
105 | local warning = self:getTurnedOnNotAllowedWarning(); |
106 | if warning ~= nil then |
107 | g_currentMission:showBlinkingWarning(warning, 2000); |
108 | end; |
109 | end; |
110 | end; |
111 | end; |
112 | end; |
113 | end; |
114 | end; |
115 | end; |
116 | |
117 | function TurnOnVehicle:updateTick(dt) |
118 | end; |
119 | |
120 | function TurnOnVehicle:draw() |
121 | if self.isClient then |
122 | if self:getCanBeTurnedOn() then |
123 | if self:getIsActiveForInput(self.needsSelection) and not self:hasInputConflictWithSelection() then |
124 | if self:getIsTurnedOnAllowed(not self.isTurnedOn) then |
125 | if self.isTurnedOn then |
126 | g_currentMission:addHelpButtonText(string.format(g_i18n:getText(self.turnOffText), self.typeDesc), self.toggleTurnOnInputBinding); |
127 | else |
128 | g_currentMission:addHelpButtonText(string.format(g_i18n:getText(self.turnOnText), self.typeDesc), self.toggleTurnOnInputBinding); |
129 | end; |
130 | end; |
131 | end; |
132 | end; |
133 | end; |
134 | end; |
135 | |
136 | function TurnOnVehicle:onLeave() |
137 | if self.deactivateOnLeave then |
138 | self:setIsTurnedOn(false, true); |
139 | end; |
140 | end; |
141 | |
142 | function TurnOnVehicle:onDeactivate() |
143 | self:setIsTurnedOn(false, true); |
144 | end; |
145 | |
146 | function TurnOnVehicle:onDetach() |
147 | if self.deactivateOnDetach then |
148 | self:setIsTurnedOn(false, true); |
149 | end; |
150 | end; |
151 | |
152 | function TurnOnVehicle:setIsTurnedOn(isTurnedOn, noEventSend) |
153 | if isTurnedOn ~= self.isTurnedOn then |
154 | SetTurnedOnEvent.sendEvent(self, isTurnedOn, noEventSend) |
155 | self.isTurnedOn = isTurnedOn; |
156 | if self.isTurnedOn then |
157 | self:onTurnedOn(noEventSend); |
158 | else |
159 | self:onTurnedOff(noEventSend); |
160 | end; |
161 | end; |
162 | end; |
163 | |
164 | function TurnOnVehicle:onTurnedOff(noEventSend) |
165 | end; |
166 | |
167 | function TurnOnVehicle:onTurnedOn(noEventSend) |
168 | end; |
169 | |
170 | function TurnOnVehicle:getIsTurnedOn() |
171 | return self.isAlwaysTurnedOn or self.isTurnedOn; |
172 | end; |
173 | |
174 | function TurnOnVehicle:getCanBeTurnedOn() |
175 | if self.isAlwaysTurnedOn then |
176 | return false; |
177 | end; |
178 | if self.attacherJoint ~= nil and self.attacherJoint.canBeTurnedOn ~= nil and not self.attacherJoint.canBeTurnedOn then |
179 | return false; |
180 | end; |
181 | |
182 | return true; |
183 | end; |
184 | |
185 | function TurnOnVehicle:getIsTurnedOnAllowed(isTurnedOn) |
186 | if self.isAlwaysTurnedOn then |
187 | return false; |
188 | end; |
189 | return true; |
190 | end; |
191 | |
192 | function TurnOnVehicle:getTurnedOnNotAllowedWarning() |
193 | return nil; |
194 | end; |
195 | |
196 | function TurnOnVehicle:getIsWorkAreaActive(superFunc, workArea) |
197 | if not self:getIsTurnedOn() and workArea.needsSetIsTurnedOn then |
198 | return false; |
199 | end; |
200 | |
201 | if superFunc ~= nil then |
202 | return superFunc(self, workArea); |
203 | end |
204 | return true; |
205 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de