LUADOC - Farming Simulator 19

Script v1.7.1.0

Engine v1.7.1.0

Foundation Reference

ScreenElement

Description
Base screen element. All full-screen GUI views inherit from this. ScreenElement inherits from FrameElement and has no additional configuration, but contains UI logic shared across all full screen views.
Parent
FrameElement
Functions

canReceiveFocus

Description
Definition
canReceiveFocus()
Code
252function ScreenElement:canReceiveFocus()
253 if not self.visible then
254 return false
255 end
256 -- element can only receive focus if all sub elements are ready to receive focus
257 for _, v in ipairs(self.elements) do
258 if (not v:canReceiveFocus()) then
259 return false
260 end
261 end
262 return true
263end

getIsOpen

Description
Definition
getIsOpen()
Code
246function ScreenElement:getIsOpen()
247 return self.isOpen
248end

initializeScreen

Description
Definition
initializeScreen()
Code
65function ScreenElement:initializeScreen()
66 self.isInitialized = true
67
68 if self.pageSelector ~= nil and self.pageSelector.disableButtonSounds ~= nil then
69 -- disable click sounds for page selector buttons, we use the paging sound in separate screen logic
70 self.pageSelector:disableButtonSounds()
71 end
72end

inputEvent

Description
Definition
inputEvent()
Code
171function ScreenElement:inputEvent(action, value, eventUsed)
172 eventUsed = ScreenElement:superClass().inputEvent(self, action, value, eventUsed)
173 if self.inputDisableTime <= 0 then
174 -- handle special case for screen paging controls:
175 if self.pageSelector ~= nil and (action == InputAction.MENU_PAGE_PREV or action == InputAction.MENU_PAGE_NEXT) then
176 if action == InputAction.MENU_PAGE_PREV then
177 self:onPagePrevious()
178 elseif action == InputAction.MENU_PAGE_NEXT then
179 self:onPageNext()
180 end
181 -- always consume event to avoid triggering any other focused elements
182 eventUsed = true
183 end
184
185 if not eventUsed then
186 local sampleToPlay = nil
187
188 -- Directly access screen element subclass events by button presses. The abstract implementation of these
189 -- methods in this class return true, so that we can evaluate if there is no concrete implementation. In
190 -- that case, the event must not be consumed.
191
192 if action == InputAction.MENU then
193 eventUsed = not self:onClickMenu()
194 sampleToPlay = GuiSoundPlayer.SOUND_SAMPLES.BACK -- in the menu, toggling menu means exiting, hence BACK
195 elseif action == InputAction.TOGGLE_STORE then
196 eventUsed = not self:onClickShop()
197 sampleToPlay = GuiSoundPlayer.SOUND_SAMPLES.BACK
198 elseif action == InputAction.MENU_ACTIVATE then
199 eventUsed = not self:onClickActivate()
200 sampleToPlay = GuiSoundPlayer.SOUND_SAMPLES.CLICK
201 elseif action == InputAction.MENU_CANCEL then
202 eventUsed = not self:onClickCancel()
203 sampleToPlay = GuiSoundPlayer.SOUND_SAMPLES.CLICK
204 elseif action == InputAction.MENU_ACCEPT then
205 eventUsed = not self:onClickOk()
206 sampleToPlay = GuiSoundPlayer.SOUND_SAMPLES.CLICK
207 elseif action == InputAction.MENU_BACK then
208 eventUsed = not self:onClickBack(false, false)
209 sampleToPlay = GuiSoundPlayer.SOUND_SAMPLES.BACK
210 elseif action == InputAction.MENU_EXTRA_1 then
211 eventUsed = not self:onClickMenuExtra1()
212 sampleToPlay = GuiSoundPlayer.SOUND_SAMPLES.CLICK
213 elseif action == InputAction.MENU_EXTRA_2 then
214 eventUsed = not self:onClickMenuExtra2()
215 sampleToPlay = GuiSoundPlayer.SOUND_SAMPLES.CLICK
216 end
217
218 if eventUsed and sampleToPlay ~= nil then
219 if not self.nextClickSoundMuted then
220 self:playSample(sampleToPlay)
221 end
222 end
223
224 self.nextClickSoundMuted = false
225 end
226 end
227
228 return eventUsed
229end

invalidateScreen

Description
Definition
invalidateScreen()
Code
166function ScreenElement:invalidateScreen()
167end

new

Description
Definition
new()
Code
24function ScreenElement:new(target, custom_mt)
25 local self = FrameElement:new(target, custom_mt or ScreenElement_mt)
26
27 self.isBackAllowed = true
28 self.handleCursorVisibility = true
29 self.returnScreenName = nil
30 self.returnScreen = nil
31 self.returnScreenClass = nil
32 self.isOpen = false
33 self.lastMouseCursorState = false
34 self.isInitialized = false
35 self.nextClickSoundMuted = false
36
37 self:registerControls(ScreenElement.CONTROLS)
38
39 return self
40end

onClose

Description
Definition
onClose()
Code
76function ScreenElement:onClose()
77 -- Break inheritance here to avoid callback loops
78 local rootElement = self:getRootElement()
79 -- we need to run onClose() only on children of the screen root element because the root usually has the main
80 -- callbacks on itself
81 for _, child in ipairs(rootElement.elements) do
82 child:onClose()
83 end
84
85 if self.handleCursorVisibility then
86 g_inputBinding:setShowMouseCursor(self.lastMouseCursorState)
87 end
88
89 self.isOpen = false
90end

onOpen

Description
Definition
onOpen()
Code
44function ScreenElement:onOpen()
45 -- Break inheritance here to avoid callback loops
46 local rootElement = self:getRootElement()
47 -- we need to run onOpen() only on children of the screen root element because the root usually has the main
48 -- callbacks on itself
49 for _, child in ipairs(rootElement.elements) do
50 child:onOpen()
51 end
52
53 if not self.isInitialized then
54 self:initializeScreen()
55 end
56
57 self.lastMouseCursorState = g_inputBinding:getShowMouseCursor()
58 g_inputBinding:setShowMouseCursor(true)
59
60 self.isOpen = true
61end

setNextScreenClickSoundMuted

Description
Mute the next click sound. Used to override click sounds for the activate/cancel actions
Definition
setNextScreenClickSoundMuted()
Code
267function ScreenElement:setNextScreenClickSoundMuted(value)
268 if value == nil then
269 value = true
270 end
271 self.nextClickSoundMuted = value
272end

setReturnScreen

Description
Definition
setReturnScreen()
Code
233function ScreenElement:setReturnScreen(screenName, screen)
234 self.returnScreenName = screenName
235 self.returnScreen = screen
236end

setReturnScreenClass

Description
Set the class of the return screen which should be opened when the "back" action is triggered on this screen.
Definition
setReturnScreenClass()
Code
240function ScreenElement:setReturnScreenClass(returnScreenClass)
241 self.returnScreenClass = returnScreenClass
242end