LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

InfoDisplay

Description
HUD player information
Parent
HUDDisplayElement
Functions

createBackground

Description
Create the background overlay.
Definition
createBackground()
Code
152function InfoDisplay.createBackground()
153 local posX, posY = InfoDisplay.getBackgroundPosition(1)
154 local width, height = getNormalizedScreenValues(unpack(InfoDisplay.SIZE.SELF))
155
156 local overlay = Overlay.new(g_baseUIFilename, posX, posY, width, height)
157 overlay:setUVs(g_colorBgUVs)
158 overlay:setColor(1, 0, 0, 0.75)
159
160 return overlay
161end

draw

Description
Definition
draw()
Code
97function InfoDisplay:draw()
98 if not self.isEnabled then
99 return
100 end
101
102 InfoDisplay:superClass().draw(self)
103
104 local posX, posY = 1 - g_safeFrameOffsetX, g_safeFrameOffsetY
105
106 for i = #self.boxes, 1, -1 do
107 local box = self.boxes[i]
108
109 if box:canDraw() then
110 box:draw(posX, posY)
111
112 posY = posY + box:getDisplayHeight() + self.boxMarginY
113 end
114 end
115end

getBackgroundPosition

Description
Get the scaled background position.
Definition
getBackgroundPosition()
Code
123function InfoDisplay.getBackgroundPosition(uiScale)
124 local width, _ = getNormalizedScreenValues(unpack(InfoDisplay.SIZE.SELF))
125 local posX = 1 - g_safeFrameOffsetX - width * uiScale
126 local posY = g_safeFrameOffsetY
127
128 return posX, posY
129end

getDisplayHeight

Description
Definition
getDisplayHeight()
Code
87function InfoDisplay:getDisplayHeight()
88 if self.isEnabled then
89 return self.totalHeight
90 else
91 return 0
92 end
93end

setEnabled

Description
Definition
setEnabled()
Code
32function InfoDisplay:setEnabled(isEnabled)
33 self.isEnabled = isEnabled
34end

setScale

Description
Set this element's UI scale factor.
Definition
setScale(float uiScale)
Arguments
floatuiScaleUI scale factor
Code
134function InfoDisplay:setScale(uiScale)
135 InfoDisplay:superClass().setScale(self, uiScale, uiScale)
136 self.uiScale = uiScale
137 self:storeScaledValues()
138
139 for _, box in ipairs(self.boxes) do
140 self:setScale(uiScale)
141 end
142end

storeScaledValues

Description
Store scaled position and size values.
Definition
storeScaledValues()
Code
146function InfoDisplay:storeScaledValues()
147 self.boxMarginY = self:scalePixelToScreenHeight(InfoDisplay.SIZE.BOX_MARGIN)
148end

update

Description
Definition
update()
Code
61function InfoDisplay:update(dt)
62 InfoDisplay:superClass().update(self, dt)
63
64 if self.isEnabled then
65 self:updateSize()
66 end
67end

updateSize

Description
Update the info display size depending on used rows.
Definition
updateSize()
Code
71function InfoDisplay:updateSize()
72 local height = 0
73
74 for i = 1, #self.boxes do
75 local box = self.boxes[i]
76
77 if box:canDraw() then
78 height = height + box:getDisplayHeight() + self.boxMarginY
79 end
80 end
81
82 self.totalHeight = height
83end