LUADOC - Farming Simulator 19

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#allowFocusbool [optional] If false, this element cannot be focused
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
67function ListItemElement:copyAttributes(src)
68 ListItemElement:superClass().copyAttributes(self, src)
69
70 self.allowSelected = src.allowSelected
71 self.allowFocus = src.allowFocus
72 self.autoSelectChildren = src.autoSelectChildren
73 self.onLeaveCallback = src.onLeaveCallback
74 self.onFocusCallback = src.onFocusCallback
75 self.onClickCallback = src.onClickCallback
76end

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
169function ListItemElement:getFocusTarget(incomingDirection, moveDirection)
170 if self.autoSelectChildren then
171 return ListItemElement:superClass().getFocusTarget(self, incomingDirection, moveDirection)
172 else
173 return self
174 end
175end

getIsSelected

Description
Definition
getIsSelected()
Code
80function ListItemElement:getIsSelected()
81 if self:getOverlayState() == GuiOverlay.STATE_SELECTED then
82 return true
83 else
84 return ListItemElement:superClass().getIsSelected(self)
85 end
86end

loadFromXML

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

loadProfile

Description
Definition
loadProfile()
Code
57function ListItemElement:loadProfile(profile, applyProfile)
58 ListItemElement:superClass().loadProfile(self, profile, applyProfile)
59
60 self.allowSelected = profile:getBool("allowSelected", self.allowSelected)
61 self.allowFocus = profile:getBool("allowFocus", self.allowFocus)
62 self.autoSelectChildren = profile:getBool("autoSelectChildren", self.autoSelectChildren)
63end

mouseEvent

Description
Definition
mouseEvent()
Code
113function ListItemElement:mouseEvent(posX, posY, isDown, isUp, button, eventUsed)
114 if self:getIsVisible() then
115 if ListItemElement:superClass().mouseEvent(self, posX, posY, isDown, isUp, button, eventUsed) then
116 eventUsed = true
117 end
118
119 if not eventUsed and GuiUtils.checkOverlayOverlap(posX, posY, self.absPosition[1], self.absPosition[2], self.size[1], self.size[2]) then
120 if not isDown and not isUp then
121 if self:getOverlayState() ~= GuiOverlay.STATE_SELECTED and self.handleFocus then
122 FocusManager:setHighlight(self)
123 end
124
125 if not self.mouseEntered then
126 self.mouseEntered = true
127 if self.handleFocus then
128 self:raiseCallback("onFocusCallback", self)
129 end
130 end
131 end
132
133 if isDown then
134 if button == Input.MOUSE_BUTTON_LEFT then
135 self.mouseDown = true
136 end
137 end
138
139 if isUp and button == Input.MOUSE_BUTTON_LEFT and self.mouseDown then
140 self.mouseDown = false
141 self:raiseCallback("onClickCallback", self)
142 end
143 else
144 if self.mouseEntered then
145 self.mouseEntered = false
146 if self.handleFocus then
147 self:raiseCallback("onLeaveCallback", self)
148 end
149 end
150
151 self.mouseDown = false
152 if not self.focusActive and self.handleFocus then
153 if self:getOverlayState() ~= GuiOverlay.STATE_SELECTED then
154 FocusManager:unsetHighlight(self)
155 end
156 end
157 end
158 end
159
160 return eventUsed
161end

new

Description
Definition
new()
Code
25function ListItemElement:new(target, custom_mt)
26 if custom_mt == nil then
27 custom_mt = ListItemElement_mt
28 end
29
30 local self = BitmapElement:new(target, custom_mt)
31
32 self.mouseEntered = false
33 self.allowSelected = true
34 self.allowFocus = true
35 self.autoSelectChildren = false
36 self.handleFocus = false
37
38 return self
39end

onClose

Description
Definition
onClose()
Code
90function ListItemElement:onClose()
91 ListItemElement:superClass().onClose(self)
92 self:reset()
93end

setSelected

Description
Definition
setSelected()
Code
97function ListItemElement:setSelected(selected)
98 if selected then
99 if self.allowSelected then
100 self:setOverlayState(GuiOverlay.STATE_SELECTED)
101 else
102 self:setOverlayState(GuiOverlay.STATE_FOCUSED)
103 end
104 else
105 if self:getOverlayState() ~= GuiOverlay.STATE_HIGHLIGHTED then
106 self:setOverlayState(GuiOverlay.STATE_NORMAL)
107 end
108 end
109end