LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

VariableWorkWidthHUDExtension

Description
Custom HUD drawing extension for VariableWorkWidth Displays the active partial sections
Parent
VehicleHUDExtension
Functions

canDraw

Description
Determine if the HUD extension should be drawn.
Definition
canDraw()
Code
70function VariableWorkWidthHUDExtension:canDraw()
71 return self.vehicle:getIsActiveForInput(true) and self.variableWorkWidth.drawInputHelp
72end

draw

Description
Draw mixing ratio information for a mixing wagon when it is active.
Definition
draw(float leftPosX, float rightPosX, float posY)
Arguments
floatleftPosXLeft input help panel column start position
floatrightPosXRight input help panel column start position
floatposYCurrent input help panel drawing vertical offset
Return Values
floatModifiedinput help panel drawing vertical offset
Code
94function VariableWorkWidthHUDExtension:draw(leftPosX, rightPosX, posY)
95 setTextColor(unpack(self.uiTextColor))
96 setTextBold(true)
97 setTextAlignment(RenderText.ALIGN_LEFT)
98 renderText(leftPosX, posY + self.displayHeight - self.uiTextSize * 1.7, self.uiTextSize, g_i18n:getText("info_partialWorkingWidth"))
99 setTextBold(false)
100
101 setTextAlignment(RenderText.ALIGN_RIGHT)
102 local usage = self.vehicle:getVariableWorkWidthUsage()
103 if usage ~= nil then
104 usage = MathUtil.round(usage)
105 renderText(rightPosX, posY + self.displayHeight - self.uiTextSize * 1.7, self.uiTextSize, string.format(g_i18n:getText("info_workWidthAndUsage"), usage, self.vehicle:getWorkAreaWidth(self.variableWorkWidth.widthReferenceWorkArea)))
106 else
107 renderText(rightPosX, posY + self.displayHeight - self.uiTextSize * 1.7, self.uiTextSize, string.format(g_i18n:getText("info_workWidth"), self.vehicle:getWorkAreaWidth(self.variableWorkWidth.widthReferenceWorkArea)))
108 end
109
110 local numSections = #self.sectionOverlays
111 local _, yOffset = getNormalizedScreenValues(0, 25 * self.uiScale)
112 local fullWidth = (rightPosX - leftPosX)
113 local sectionWidth = fullWidth / numSections
114 local sideOffset = sectionWidth * 0.1
115 for i=1, numSections do
116 local overlay = self.sectionOverlays[i].overlay
117
118 local color = VariableWorkWidthHUDExtension.COLOR.SECTION_ACTIVE
119 if not self.sectionOverlays[i].section.isActive then
120 color = VariableWorkWidthHUDExtension.COLOR.SECTION_INACTIVE
121 end
122 local posX = leftPosX + sectionWidth * (i - 1) * (1 + (sectionWidth * 0.2) / fullWidth)
123 local width = sectionWidth * 0.8
124 overlay:setPosition(posX, posY + yOffset)
125 overlay:setDimension(width)
126 overlay:setColor(unpack(color))
127 overlay:render()
128
129 local separator = self.sectionOverlays[i].separator
130 if separator ~= nil then
131 separator:setPosition(posX + width + sideOffset - separator.width * 0.5, posY + yOffset)
132 separator:render()
133 end
134 end
135
136 return posY
137end

getDisplayHeight

Description
Get this HUD extension's display height.
Definition
getDisplayHeight()
Return Values
floatDisplayheight in screen space
Code
77function VariableWorkWidthHUDExtension:getDisplayHeight()
78 return self:canDraw() and self.displayHeight or 0
79end

getHelpEntryCountReduction

Description
Returns how many help entry slots should be removed for display of the hud extension
Definition
getHelpEntryCountReduction()
Return Values
integernumSLotsnumSLots
Code
84function VariableWorkWidthHUDExtension:getHelpEntryCountReduction()
85 return self:canDraw() and 1 or 0
86end

new

Description
Create a new instance of VariableWorkWidthHUDExtension.
Definition
new(table vehicle, float uiScale, table uiTextColor, float uiTextSize)
Arguments
tablevehicleVehicle which has the specialization required by a sub-class
floatuiScaleCurrent UI scale
tableuiTextColorHUD text drawing color as an RGBA array
floatuiTextSizeHUD text size
Code
24function VariableWorkWidthHUDExtension.new(vehicle, uiScale, uiTextColor, uiTextSize)
25 local self = VehicleHUDExtension.new(VariableWorkWidthHUDExtension_mt, vehicle, uiScale, uiTextColor, uiTextSize)
26
27 self.variableWorkWidth = vehicle.spec_variableWorkWidth
28
29 local _, sectionHeight = getNormalizedScreenValues(0, 15 * uiScale)
30 self.sectionOverlays = {}
31 local numSections = #self.variableWorkWidth.sections
32 for i=1, numSections do
33 local section = self.variableWorkWidth.sections[i]
34
35 local sectionOverlay = {}
36
37 local overlay = Overlay.new(g_baseHUDFilename, 0, 0, 0, sectionHeight)
38 overlay:setAlignment(Overlay.ALIGN_VERTICAL_MIDDLE, Overlay.ALIGN_HORIZONTAL_LEFT)
39 overlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL))
40 overlay:setColor(unpack(uiTextColor))
41 self:addComponentForCleanup(overlay)
42
43 sectionOverlay.overlay = overlay
44 sectionOverlay.section = section
45
46 if (i < numSections and self.variableWorkWidth.sections[i+1].isCenter) or section.isCenter or (not self.variableWorkWidth.hasCenter and i == numSections / 2)then
47 local separatorWidth, separatorHeight = getNormalizedScreenValues(1, 35 * uiScale)
48 separatorWidth = math.max(separatorWidth, 1 / g_screenWidth)
49 local separator = Overlay.new(g_baseHUDFilename, 0, 0, separatorWidth, separatorHeight)
50 separator:setAlignment(Overlay.ALIGN_VERTICAL_MIDDLE, Overlay.ALIGN_HORIZONTAL_LEFT)
51 separator:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL))
52 separator:setColor(unpack(VariableWorkWidthHUDExtension.COLOR.SEPARATOR))
53 self:addComponentForCleanup(separator)
54
55 sectionOverlay.separator = separator
56 end
57
58 table.insert(self.sectionOverlays, sectionOverlay)
59 end
60
61 local _, helpHeight = getNormalizedScreenValues(0, 75 * uiScale)
62
63 self.displayHeight = helpHeight
64
65 return self
66end