LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

HUDFrameElement

Description
FrameElement HUD background frame element. Displays a transparent frame with a thick bottom bar for use as a background in HUD elements.
Parent
HUDElement
Functions

createComponents

Description
Create display components.
Definition
createComponents()
Code
45function HUDFrameElement:createComponents(hudAtlasPath, baseX, baseY, width, height)
46 -- get pixel sizes so that frame lines are always at least a screen pixel thick
47 local refPixelX, refPixelY = 1 / g_referenceScreenWidth, 1 / g_referenceScreenHeight
48 local screenPixelX, screenPixelY = 1 / g_screenWidth, 1 / g_screenHeight
49 local onePixelX, onePixelY = math.max(refPixelX, screenPixelX), math.max(refPixelY, screenPixelY)
50
51 -- top line
52 local posX, posY = baseX, baseY + self:getHeight()
53 local frameWidth, frameHeight = getNormalizedScreenValues(self.frameThickness, self.frameThickness)
54 local pixelsX, pixelsY = math.ceil(frameWidth / onePixelX), math.ceil(frameHeight / onePixelY)
55 self.frameWidth, self.frameHeight = pixelsX * onePixelX, pixelsY * onePixelY
56
57 local lineOverlay = Overlay.new(hudAtlasPath, posX, posY - self.frameHeight, width, self.frameHeight)
58 lineOverlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL))
59 lineOverlay:setColor(unpack(HUDFrameElement.COLOR.FRAME))
60
61 local lineElement = HUDElement.new(lineOverlay)
62 self.topLine = lineElement
63 self:addChild(lineElement)
64
65 -- side lines
66 posX, posY = baseX, baseY + self.frameHeight
67 lineOverlay = Overlay.new(hudAtlasPath, posX, posY, self.frameWidth, height - self.frameHeight * 2)
68 lineOverlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL))
69 lineOverlay:setColor(unpack(HUDFrameElement.COLOR.FRAME))
70
71 lineElement = HUDElement.new(lineOverlay)
72 self.leftLine = lineElement
73 self:addChild(lineElement)
74
75 posX, posY = baseX + width - self.frameWidth, baseY + self.frameHeight
76 lineOverlay = Overlay.new(hudAtlasPath, posX, posY, self.frameWidth, height - self.frameHeight * 2)
77 lineOverlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL))
78 lineOverlay:setColor(unpack(HUDFrameElement.COLOR.FRAME))
79
80 lineElement = HUDElement.new(lineOverlay)
81 self.rightLine = lineElement
82 self:addChild(lineElement)
83
84 -- bottom bar
85 local barSize = self.barThickness
86 local barColor = HUDFrameElement.COLOR.BAR
87 if not self.showBar then
88 barSize = self.frameThickness
89 barColor = HUDFrameElement.COLOR.FRAME
90 end
91
92 local _, barHeight = getNormalizedScreenValues(0, barSize)
93 pixelsY = math.ceil(barHeight / onePixelY)
94 local barOverlay = Overlay.new(hudAtlasPath, baseX, baseY, width, pixelsY * onePixelY)
95 barOverlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL))
96 barOverlay:setColor(unpack(barColor))
97
98 local barElement = HUDElement.new(barOverlay)
99 self.bottomBar = barElement
100 self:addChild(barElement)
101end

new

Description
Create a new instance of FrameElement.
Definition
new(string hudAtlasPath, float posX, float posY, float width, float height, table parent)
Arguments
stringhudAtlasPathPath to the HUD atlas texture
floatposXInitial X position in screen space
floatposYInitial Y position in screen space
floatwidthFrame width in screen space
floatheightFrame height in screen space
tableparent[optional] Parent HUDElement which will receive this frame as its child element
Code
23function HUDFrameElement.new(hudAtlasPath, posX, posY, width, height, parent, showBar, frameThickness, barThickness)
24 local backgroundOverlay = Overlay.new(hudAtlasPath, posX, posY, width, height)
25 backgroundOverlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL))
26 backgroundOverlay:setColor(0, 0, 0, 0) -- default invisible
27 local self = HUDElement.new(backgroundOverlay, parent, HUDFrameElement_mt)
28
29 self.topLine = nil
30 self.leftLine = nil
31 self.rightLine = nil
32 self.bottomBar = nil
33 self.frameWidth, self.frameHeight = 0, 0
34 self.showBar = Utils.getNoNil(showBar, true)
35 self.frameThickness = frameThickness or HUDFrameElement.THICKNESS.FRAME
36 self.barThickness = barThickness or HUDFrameElement.THICKNESS.BAR
37
38 self:createComponents(hudAtlasPath, posX, posY, width, height)
39
40 return self
41end

setBottomBarColor

Description
Set frame bottom bar height.
Definition
setBottomBarColor()
Code
132function HUDFrameElement:setBottomBarColor(r, g, b, a)
133 self.bottomBar:setColor(r, g, b, a)
134end

setBottomBarHeight

Description
Set frame bottom bar height.
Definition
setBottomBarHeight()
Code
126function HUDFrameElement:setBottomBarHeight(height)
127 self.bottomBar:setDimension(nil, height)
128end

setDimension

Description
Set frame element dimensions. Override from HUDElement to preserve border positioning and sizes.
Definition
setDimension()
Code
106function HUDFrameElement:setDimension(width, height)
107 HUDFrameElement:superClass().setDimension(self, width, height)
108
109 local lineHeight = nil
110 if height ~= nil then
111 lineHeight = height - self.frameHeight * 2
112 end
113
114 self.topLine:setDimension(width, nil)
115 self.leftLine:setDimension(nil, lineHeight)
116 self.rightLine:setDimension(nil, lineHeight)
117 self.bottomBar:setDimension(width, nil)
118
119 local x, y = self:getPosition()
120 self.topLine:setPosition(nil, y + self:getHeight() - self.frameHeight)
121 self.rightLine:setPosition(x + self:getWidth() - self.frameWidth, nil)
122end

setFrameColor

Description
Sets color of the frame
Definition
setFrameColor()
Code
150function HUDFrameElement:setFrameColor(r, g, b, a)
151 self.topLine:setColor(r, g, b, a)
152 self.leftLine:setColor(r, g, b, a)
153 self.rightLine:setColor(r, g, b, a)
154 self.bottomBar:setColor(r, g, b, a)
155end

setLeftLineVisible

Description
Set visibility of left line
Definition
setLeftLineVisible()
Code
138function HUDFrameElement:setLeftLineVisible(visible)
139 self.leftLine:setVisible(visible)
140end

setRightLineVisible

Description
Set visibility of right line
Definition
setRightLineVisible()
Code
144function HUDFrameElement:setRightLineVisible(visible)
145 self.rightLine:setVisible(visible)
146end