LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

VideoElement

Description
Plays back a video.
Parent
GuiElement
XML Configuration Parameters
GuiElement#videoFileNamestring File path to video file. If the path contains the special string "$l10nSuffix", it will be substituted by the current language code to allow automatically selecting the proper language video in the file system.
GuiElement#volumefloat [optional] Playback volume, defaults to 1 (maximum).
GuiElement#allowStopbool [optional] If false, does not allow skipping the video by mouse click. Keyboard inputs will always skip the video.
GuiElement#isLoopingbool [optional] If true, the video is restarted when playback is finished until an input stops playback entirely.
GuiElement#onEndVideocallback [optional] onEndVideo() Called when the video is finished.

Functions

changeVideo

Description
Definition
changeVideo()
Code
190function VideoElement:changeVideo(newVideoFilename, volume)
191 self:disposeVideo()
192
193 self.videoFilename = newVideoFilename
194 if self.videoFilename ~= nil then
195 local videoFilename = string.gsub(self.videoFilename, "$l10nSuffix", g_gui.languageSuffix)
196 self.overlay = createVideoOverlay(videoFilename, self.isLooping, volume or self.volume)
197 end
198end

copyAttributes

Description
Definition
copyAttributes()
Code
62function VideoElement:copyAttributes(src)
63 VideoElement:superClass().copyAttributes(self, src)
64
65 self:changeVideo(src.videoFilename)
66 self.volume = src.volume
67 self.allowStop = src.allowStop
68 self.isLooping = src.isLooping
69 self.onEndVideoCallback = src.onEndVideoCallback
70end

delete

Description
Definition
delete()
Code
74function VideoElement:delete()
75 self:disposeVideo()
76 VideoElement:superClass().delete(self)
77end

disposeVideo

Description
Definition
disposeVideo()
Code
158function VideoElement:disposeVideo()
159 if self.overlay ~= nil then
160 self:stopVideo()
161 delete(self.overlay)
162 self.overlay = nil
163 end
164end

draw

Description
Definition
draw()
Code
137function VideoElement:draw(clipX1, clipY1, clipX2, clipY2)
138 if self.overlay ~= nil and isVideoOverlayPlaying(self.overlay) then
139 renderOverlay(self.overlay, self.absPosition[1], self.absPosition[2], self.size[1], self.size[2])
140 end
141 VideoElement:superClass().draw(self, clipX1, clipY1, clipX2, clipY2)
142end

getIsActive

Description
Definition
getIsActive()
Code
168function VideoElement:getIsActive()
169 return self:getIsVisible()
170end

keyEvent

Description
Definition
keyEvent()
Code
106function VideoElement:keyEvent(unicode, sym, modifier, isDown, eventUsed)
107 if self:getIsActive() then
108 VideoElement:superClass().keyEvent(self, unicode, sym, modifier, isDown, eventUsed)
109
110 if isDown then
111 if self.overlay ~= nil then
112 self:disposeVideo()
113 self:onEndVideo()
114 end
115 end
116
117 return true
118 end
119
120 return eventUsed
121end

loadFromXML

Description
Definition
loadFromXML()
Code
36function VideoElement:loadFromXML(xmlFile, key)
37 VideoElement:superClass().loadFromXML(self, xmlFile, key)
38
39 self.videoFilename = Utils.getNoNil(getXMLString(xmlFile, key.."#videoFilename"), self.videoFilename)
40 self.volume = Utils.getNoNil(getXMLFloat(xmlFile, key.."#volume"), self.volume)
41 self.allowStop = Utils.getNoNil(getXMLBool(xmlFile, key.."#allowStop"), self.allowStop)
42 self.isLooping = Utils.getNoNil(getXMLBool(xmlFile, key.."#isLooping"), self.isLooping)
43
44 self:addCallback(xmlFile, key.."#onEndVideo", "onEndVideoCallback")
45
46 self:changeVideo(self.videoFilename)
47end

loadProfile

Description
Definition
loadProfile()
Code
51function VideoElement:loadProfile(profile, applyProfile)
52 VideoElement:superClass().loadProfile(self, profile, applyProfile)
53
54 self.videoFilename = profile:getValue("videoFilename", self.videoFilename)
55 self.volume = profile:getNumber("volume", self.volume)
56 self.allowStop = profile:getBool("allowStop", self.allowStop)
57 self.isLooping = profile:getBool("isLooping", self.isLooping)
58end

mouseEvent

Description
Definition
mouseEvent()
Code
81function VideoElement:mouseEvent(posX, posY, isDown, isUp, button, eventUsed)
82 if self:getIsActive() then
83 if VideoElement:superClass().mouseEvent(self, posX, posY, isDown, isUp, button, eventUsed) then
84 eventUsed = true
85 end
86
87 if not eventUsed and self.allowStop then
88 local ret = true
89
90 if isDown then
91 if self.overlay ~= nil then
92 self:disposeVideo()
93 self:onEndVideo()
94 end
95 end
96
97 return ret
98 end
99 end
100
101 return eventUsed
102end

new

Description
Definition
new()
Code
23function VideoElement.new(target, custom_mt)
24 local self = VideoElement:superClass().new(target, custom_mt or VideoElement_mt)
25
26 self.videoFilename = nil
27 self.allowStop = true
28 self.isLooping = false
29 self.volume = 1.0
30
31 return self
32end

onEndVideo

Description
Definition
onEndVideo()
Code
146function VideoElement:onEndVideo()
147 if self.onEndVideoCallback ~= nil then
148 if self.target ~= nil then
149 self.onEndVideoCallback(self.target)
150 else
151 self.onEndVideoCallback()
152 end
153 end
154end

playVideo

Description
Definition
playVideo()
Code
174function VideoElement:playVideo()
175 if self.overlay ~= nil then
176 playVideoOverlay(self.overlay)
177 end
178end

stopVideo

Description
Definition
stopVideo()
Code
182function VideoElement:stopVideo()
183 if self.overlay ~= nil and isVideoOverlayPlaying(self.overlay) then
184 stopVideoOverlay(self.overlay)
185 end
186end

update

Description
Definition
update()
Code
125function VideoElement:update(dt)
126 VideoElement:superClass().update(self, dt)
127 if self.overlay ~= nil and isVideoOverlayPlaying(self.overlay) then
128 updateVideoOverlay(self.overlay)
129 elseif self.overlay ~= nil then
130 self:disposeVideo()
131 self:onEndVideo()
132 end
133end