Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- |
2 | -- Cover |
3 | -- This is the specialization for Covers |
4 | -- |
5 | -- @author Stefan Geiger |
6 | -- @date 16/07/2014 |
7 | -- |
8 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
9 | |
10 | source("dataS/scripts/vehicles/specializations/SetCoverStateEvent.lua"); |
11 | |
12 | Cover = {}; |
13 | |
14 | function Cover.prerequisitesPresent(specializations) |
15 | return SpecializationUtil.hasSpecialization(AnimatedVehicle, specializations); |
16 | end; |
17 | |
18 | function Cover:preLoad(xmlFile) |
19 | self.getIsToggleCoverAllowed = Cover.getIsToggleCoverAllowed; |
20 | end; |
21 | |
22 | function Cover:load(xmlFile) |
23 | |
24 | self.setCoverState = SpecializationUtil.callSpecializationsFunction("setCoverState"); |
25 | self.allowFillType = Utils.overwrittenFunction(self.allowFillType, Cover.allowFillType); |
26 | self.getAllowFillFromAir = Utils.overwrittenFunction(self.getAllowFillFromAir, Cover.getAllowFillFromAir); |
27 | |
28 | self.coverAnimation = getXMLString(xmlFile, "vehicle.cover#animationName"); |
29 | if self.coverAnimation ~= nil then |
30 | self:setCoverState(true, true); |
31 | else |
32 | self.isCoverOpen = true; |
33 | end; |
34 | end; |
35 | |
36 | function Cover:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) |
37 | if self.coverAnimation ~= nil then |
38 | local isCoverOpen = getXMLBool(xmlFile, key.."#isCoverOpen"); |
39 | self:setCoverState(isCoverOpen, true); |
40 | end |
41 | return BaseMission.VEHICLE_LOAD_OK; |
42 | end; |
43 | |
44 | function Cover:getSaveAttributesAndNodes(nodeIdent) |
45 | if self.coverAnimation ~= nil then |
46 | local attributes = 'isCoverOpen="'..tostring(self.isCoverOpen)..'"'; |
47 | return attributes, nil; |
48 | end |
49 | return nil; |
50 | end; |
51 | |
52 | function Cover:delete() |
53 | end; |
54 | |
55 | function Cover:mouseEvent(posX, posY, isDown, isUp, button) |
56 | end; |
57 | |
58 | function Cover:keyEvent(unicode, sym, modifier, isDown) |
59 | end; |
60 | |
61 | function Cover:readStream(streamId, connection) |
62 | if connection:getIsServer() then |
63 | if self.coverAnimation ~= nil then |
64 | local isOpen = streamReadBool(streamId); |
65 | self:setCoverState(isOpen, true); |
66 | end; |
67 | end; |
68 | end; |
69 | |
70 | function Cover:writeStream(streamId, connection) |
71 | if not connection:getIsServer() then |
72 | if self.coverAnimation ~= nil then |
73 | streamWriteBool(streamId, self.isCoverOpen); |
74 | end; |
75 | end; |
76 | end; |
77 | |
78 | function Cover:update(dt) |
79 | if self:getIsActiveForInput() then |
80 | if self.coverAnimation ~= nil then |
81 | if InputBinding.hasEvent(InputBinding.TOGGLE_COVER) then |
82 | if self:getIsToggleCoverAllowed(not self.isCoverOpen) then |
83 | self:setCoverState(not self.isCoverOpen); |
84 | end; |
85 | end; |
86 | end; |
87 | end; |
88 | end; |
89 | |
90 | function Cover:draw() |
91 | if self.isClient and self:getIsActiveForInput(true) then |
92 | if self.coverAnimation ~= nil and self:getIsToggleCoverAllowed(not self.isCoverOpen) then |
93 | if self.isCoverOpen then |
94 | g_currentMission:addHelpButtonText(g_i18n:getText("CLOSE_COVER"), InputBinding.TOGGLE_COVER); |
95 | else |
96 | g_currentMission:addHelpButtonText(g_i18n:getText("OPEN_COVER"), InputBinding.TOGGLE_COVER); |
97 | end; |
98 | end; |
99 | end; |
100 | end; |
101 | |
102 | function Cover:getIsToggleCoverAllowed(isCoverOpen) |
103 | return true; |
104 | end; |
105 | |
106 | function Cover:allowFillType(superFunc, fillType, allowEmptying) |
107 | if not self.isCoverOpen then |
108 | return false; |
109 | end; |
110 | |
111 | return superFunc(self, fillType, allowEmptying); |
112 | end |
113 | |
114 | function Cover:setCoverState(isOpen, noEventSend) |
115 | if self.coverAnimation ~= nil then |
116 | SetCoverStateEvent.sendEvent(self, isOpen, noEventSend); |
117 | self.isCoverOpen = isOpen; |
118 | |
119 | if isOpen then |
120 | self:playAnimation(self.coverAnimation, -1, self:getAnimationTime(self.coverAnimation), true); |
121 | else |
122 | self:playAnimation(self.coverAnimation, 1, self:getAnimationTime(self.coverAnimation), true); |
123 | end; |
124 | end; |
125 | end; |
126 | |
127 | function Cover:getAllowFillFromAir(superFunc) |
128 | if not self.isCoverOpen then |
129 | return false; |
130 | end |
131 | return superFunc(self); |
132 | end
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de