LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

ListItemElement

Description
List item element to be used and laid out by ListElement and TableElement. Used layers: "image" for a background image.
Parent
BitmapElement
XML Configuration Parameters
GuiElement#allowSelectedbool [optional] If false, this element cannot be selected, only focused or activated.
GuiElement#autoSelectChildrenbool [optional] If true, focus and selection states are propagated with priority to child elements. Only if no child element can be focused or selected will this element receive that state itself.
GuiElement#onFocuscallback [optional] onFocus(element) Called when the cursor enters the borders of this element. Receives this element as an argument.
GuiElement#onLeavecallback [optional] onLeave(element) Called when the cursor leaves the borders of this element. Receives this element as an argument.
GuiElement#onClickcallback [optional] onClick(element) Called then this element is clicked / activated. Receives this element as an argument.

Functions

copyAttributes

Description
Definition
copyAttributes()
Code
73function ListItemElement:copyAttributes(src)
74 ListItemElement:superClass().copyAttributes(self, src)
75
76 self.allowSelected = src.allowSelected
77 self.isSectionHeader = src.isSectionHeader
78 self.autoSelectChildren = src.autoSelectChildren
79 self.hideSelection = src.hideSelection
80
81 self.backgroundColor = src.backgroundColor
82 self.alternateBackgroundColor = src.alternateBackgroundColor
83 self.alternateBackgroundLoaded = src.alternateBackgroundLoaded
84
85 self.onLeaveCallback = src.onLeaveCallback
86 self.onFocusCallback = src.onFocusCallback
87 self.onClickCallback = src.onClickCallback
88end

getFocusTarget

Description
Get the actual focus target, in case a child or parent element needs to be targeted instead. Override from BitmapElement: Only focuses children if #autoSelectChildren is true
Definition
getFocusTarget(incomingDirection (Optional), moveDirection (Optional))
Arguments
incomingDirection(Optional)If specified, may return different targets for different incoming directions.
moveDirection(Optional)Actual movement direction per input. This is the opposing direction of incomingDirection.
Return Values
GuiElementActualelement to focus.
Code
201function ListItemElement:getFocusTarget(incomingDirection, moveDirection)
202 if self.autoSelectChildren then
203 return ListItemElement:superClass().getFocusTarget(self, incomingDirection, moveDirection)
204 else
205 return self
206 end
207end

getIsSelected

Description
Definition
getIsSelected()
Code
92function ListItemElement:getIsSelected()
93 if self:getOverlayState() == GuiOverlay.STATE_SELECTED then
94 return true
95 else
96 return ListItemElement:superClass().getIsSelected(self)
97 end
98end

loadFromXML

Description
Definition
loadFromXML()
Code
42function ListItemElement:loadFromXML(xmlFile, key)
43 ListItemElement:superClass().loadFromXML(self, xmlFile, key)
44
45 self.allowSelected = Utils.getNoNil(getXMLBool(xmlFile, key.."#allowSelected"), self.allowSelected)
46 self.autoSelectChildren = Utils.getNoNil(getXMLBool(xmlFile, key.."#autoSelectChildren"), self.autoSelectChildren)
47 self.hideSelection = Utils.getNoNil(getXMLBool(xmlFile, key.."#hideSelection"), self.hideSelection)
48
49 self:addCallback(xmlFile, key.."#onFocus", "onFocusCallback") -- TODO: change to onHighlight()
50 self:addCallback(xmlFile, key.."#onLeave", "onLeaveCallback")
51 self:addCallback(xmlFile, key.."#onClick", "onClickCallback")
52end

loadProfile

Description
Definition
loadProfile()
Code
56function ListItemElement:loadProfile(profile, applyProfile)
57 ListItemElement:superClass().loadProfile(self, profile, applyProfile)
58
59 self.allowSelected = profile:getBool("allowSelected", self.allowSelected)
60 self.autoSelectChildren = profile:getBool("autoSelectChildren", self.autoSelectChildren)
61 self.hideSelection = profile:getBool("hideSelection", self.hideSelection)
62
63 if not self.alternateBackgroundLoaded then
64 self.backgroundColor = table.copy(GuiOverlay.getOverlayColor(self.overlay, GuiOverlay.STATE_NORMAL))
65 self.alternateBackgroundColor = GuiUtils.getColorArray(profile:getValue("alternateBackgroundColor"))
66 self.alternateBackgroundLoaded = true
67 end
68
69end

mouseEvent

Description
Definition
mouseEvent()
Code
138function ListItemElement:mouseEvent(posX, posY, isDown, isUp, button, eventUsed)
139 if self:getIsVisible() then
140 if ListItemElement:superClass().mouseEvent(self, posX, posY, isDown, isUp, button, eventUsed) then
141 eventUsed = true
142 end
143
144 if not eventUsed and GuiUtils.checkOverlayOverlap(posX, posY, self.absPosition[1], self.absPosition[2], self.absSize[1], self.absSize[2]) then
145 if not isDown and not isUp then
146 if self:getOverlayState() ~= GuiOverlay.STATE_SELECTED and self.handleFocus then
147 FocusManager:setHighlight(self)
148 end
149
150 if not self.mouseEntered then
151 self.mouseEntered = true
152 if self.handleFocus then
153 self:raiseCallback("onFocusCallback", self)
154 end
155 end
156 end
157
158 if isDown then
159 if button == Input.MOUSE_BUTTON_LEFT then
160 self.mouseDown = true
161 end
162 end
163
164 if isUp and button == Input.MOUSE_BUTTON_LEFT and self.mouseDown then
165 self.mouseDown = false
166 self:raiseCallback("onClickCallback", self)
167 end
168 else
169 if self.mouseEntered then
170 self.mouseEntered = false
171 if self.handleFocus then
172 self:raiseCallback("onLeaveCallback", self)
173 end
174 end
175
176 self.mouseDown = false
177 if not self.focusActive and self.handleFocus then
178 if self:getOverlayState() ~= GuiOverlay.STATE_SELECTED then
179 FocusManager:unsetHighlight(self)
180 end
181 end
182 end
183 end
184
185 return eventUsed
186end

new

Description
Definition
new()
Code
24function ListItemElement.new(target, custom_mt)
25 local self = BitmapElement.new(target, custom_mt or ListItemElement_mt)
26
27 self.mouseEntered = false
28 self.allowSelected = true
29 self.autoSelectChildren = false
30 self.handleFocus = false
31 self.hideSelection = false
32
33 self.alternateBackgroundColor = nil
34
35 self.attributes = {}
36
37 return self
38end

onClose

Description
Definition
onClose()
Code
102function ListItemElement:onClose()
103 ListItemElement:superClass().onClose(self)
104 self:reset()
105end

setSelected

Description
Definition
setSelected()
Code
118function ListItemElement:setSelected(selected)
119 if selected and not self.hideSelection then
120 if self.allowSelected then
121 self:setOverlayState(GuiOverlay.STATE_SELECTED)
122 else
123 self:setOverlayState(GuiOverlay.STATE_FOCUSED)
124 end
125 else
126 if self:getOverlayState() ~= GuiOverlay.STATE_HIGHLIGHTED then
127 if self.disabled then
128 self:setOverlayState(GuiOverlay.STATE_DISABLED)
129 else
130 self:setOverlayState(GuiOverlay.STATE_NORMAL)
131 end
132 end
133 end
134end