Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ContextActionDisplay
- DialogElement
- FieldInfoDisplay
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputHelpDisplay
- ListElement
- ListItemElement
- MapHotspot
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- SettingsModel
- SideNotification
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- StableListElement
- StatusBar
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TextElement
- TextInputElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
FieldInfoDisplay
DescriptionHUD field information display element. Displays dynamic information about the field which the player is currently standing in (or close by).Parent
HUDDisplayElementFunctions
- addCustomText
- clearCustomText
- clearFieldData
- clearInfoRow
- createBackground
- createComponents
- createFrame
- createRowListContainer
- createSeparators
- draw
- drawText
- getBackgroundPosition
- new
- onFieldDataUpdateFinished
- reset
- setEnabled
- setFarmlandOwnerFarmId
- setFertilization
- setFruitType
- setLimeRequired
- setPlayer
- setPlowingRequired
- setScale
- setupRows
- setWeed
- storeScaledValues
- update
- updateSize
addCustomText
DescriptionAdd a custom text row. The custom text will be added in order of calls to this function after the default information.Definition
addCustomText(string leftText, string rightText, table leftColor)Arguments
string | leftText | Text to be displayed on the left side in bold print |
string | rightText | [optional] Text to be displayed on the right side in regular print |
table | leftColor | [optional, default= |
int | Display | row index of the newly added custom text or 0 if it could not be added |
279 | function FieldInfoDisplay:addCustomText(leftText, rightText, leftColor) |
280 | local customRowIndex = 0 |
281 | local row = nil |
282 | for i = 1, FieldInfoDisplay.MAX_ROW_COUNT do |
283 | row = self.rows[i] |
284 | if row.infoType == FieldInfoDisplay.INFO_TYPE.CUSTOM and row.leftText == "" and row.rightText == "" then |
285 | customRowIndex = i |
286 | break |
287 | end |
288 | end |
289 | |
290 | if customRowIndex > 0 and customRowIndex <= FieldInfoDisplay.MAX_ROW_COUNT then |
291 | row.leftText = leftText |
292 | row.rightText = rightText or "" |
293 | local color = leftColor or FieldInfoDisplay.COLOR.TEXT_DEFAULT |
294 | for i = 1, 4 do |
295 | row.leftColor[i] = color[i] |
296 | end |
297 | |
298 | self.needResize = true |
299 | end |
300 | |
301 | return customRowIndex |
302 | end |
clearCustomText
DescriptionClear a custom text row previously added by FieldInfoDisplay:addCustomText().Definition
clearCustomText(int rowIndex)Arguments
int | rowIndex | [optional] Custom text row index as returned by FieldInfoDisplay:addCustomText(). If no value is provided, all custom text is cleared. |
307 | function FieldInfoDisplay:clearCustomText(rowIndex) |
308 | if rowIndex ~= nil then -- clear one by index |
309 | if rowIndex > 0 and rowIndex <= FieldInfoDisplay.MAX_ROW_COUNT and self.rows[rowIndex].infoType == FieldInfoDisplay.INFO_TYPE.CUSTOM then |
310 | self:clearInfoRow(self.rows[rowIndex]) |
311 | self.needResize = true |
312 | end |
313 | else -- clear all |
314 | for i = 1, FieldInfoDisplay.MAX_ROW_COUNT do |
315 | local row = self.rows[i] |
316 | if row.infoType == FieldInfoDisplay.INFO_TYPE.CUSTOM then |
317 | self:clearInfoRow(row) |
318 | end |
319 | end |
320 | |
321 | self.needResize = true |
322 | end |
323 | end |
clearFieldData
DescriptionClear all previously set field data. This does not clear custom text rows, which need to be cleared specifically using clearCustomText().Definition
clearFieldData()Code
340 | function FieldInfoDisplay:clearFieldData() |
341 | for _, row in pairs(self.rows) do |
342 | if row.infoType ~= FieldInfoDisplay.INFO_TYPE.CUSTOM then |
343 | self:clearInfoRow(row) |
344 | end |
345 | end |
346 | |
347 | self.needResize = true |
348 | end |
clearInfoRow
DescriptionClear a single info row's data.Definition
clearInfoRow()Code
327 | function FieldInfoDisplay:clearInfoRow(row) |
328 | row.leftText = "" |
329 | row.rightText = "" |
330 | |
331 | local defaultColor = FieldInfoDisplay.COLOR.TEXT_DEFAULT |
332 | for i = 1, 4 do -- r, g, b, a |
333 | row.leftColor[i] = defaultColor[i] |
334 | end |
335 | end |
createBackground
DescriptionCreate the background overlay.Definition
createBackground()Code
562 | function FieldInfoDisplay.createBackground() |
563 | local posX, posY = FieldInfoDisplay.getBackgroundPosition(1) |
564 | local width, height = getNormalizedScreenValues(unpack(FieldInfoDisplay.SIZE.SELF)) |
565 | |
566 | return Overlay:new(nil, posX, posY, width, height) |
567 | end |
createComponents
DescriptionCreate required display components.Definition
createComponents()Code
571 | function FieldInfoDisplay:createComponents(hudAtlasPath) |
572 | local posX, posY = self:getPosition() |
573 | |
574 | self.frameElement = self:createFrame(hudAtlasPath, posX, posY) |
575 | self.rowListElement = self:createRowListContainer(posX, posY) |
576 | self:createSeparators(hudAtlasPath) |
577 | end |
createFrame
DescriptionCreate the background frame element.Definition
createFrame()Code
581 | function FieldInfoDisplay:createFrame(hudAtlasPath, baseX, baseY) |
582 | local width, height = self:getWidth(), self:getHeight() |
583 | local frame = HUDFrameElement:new(hudAtlasPath, baseX, baseY, width, height) |
584 | frame:setColor(unpack(HUD.COLOR.FRAME_BACKGROUND)) |
585 | self:addChild(frame) |
586 | |
587 | return frame |
588 | end |
createRowListContainer
DescriptionCreate row list container.Definition
createRowListContainer()Code
592 | function FieldInfoDisplay:createRowListContainer(baseX, baseY) |
593 | local listOffX, listOffY = self:scalePixelToScreenVector(FieldInfoDisplay.SIZE.ROW_LIST_MARGIN) |
594 | local listWidth, listHeight = self:scalePixelToScreenVector(FieldInfoDisplay.SIZE.ROW_LIST) |
595 | local listOverlay = Overlay:new(nil, baseX + listOffX, baseY + listOffY, listWidth, listHeight) |
596 | local listElement = HUDElement:new(listOverlay) |
597 | self:addChild(listElement) |
598 | |
599 | return listElement |
600 | end |
createSeparators
DescriptionCreate row separators.Definition
createSeparators()Code
604 | function FieldInfoDisplay:createSeparators(hudAtlasPath) |
605 | local listPosX, listPosY = self.rowListElement:getPosition() |
606 | local sepWidth, sepHeight = self:scalePixelToScreenVector(FieldInfoDisplay.SIZE.SEPARATOR) |
607 | sepHeight = math.max(sepHeight, 1 / g_screenHeight) -- make sure it's at least 1 pixel |
608 | local rowHeight = self:scalePixelToScreenHeight(FieldInfoDisplay.SIZE.ROW[2]) |
609 | for i = 1, FieldInfoDisplay.MAX_ROW_COUNT do |
610 | local separatorElement = nil |
611 | if i == 1 or i == FieldInfoDisplay.MAX_ROW_COUNT then -- use dummy separators for top and bottom |
612 | separatorElement = NULL_SEPARATOR |
613 | else |
614 | local overlay = Overlay:new(hudAtlasPath, listPosX, listPosY, sepWidth, sepHeight) |
615 | overlay:setUVs(getNormalizedUVs(HUDElement.UV.FILL)) |
616 | overlay:setColor(unpack(InputHelpDisplay.COLOR.SEPARATOR)) |
617 | separatorElement = HUDElement:new(overlay) |
618 | separatorElement:setVisible(false) |
619 | |
620 | self.rowListElement:addChild(separatorElement) |
621 | end |
622 | |
623 | self.separators[i] = separatorElement |
624 | listPosY = listPosY + rowHeight |
625 | end |
626 | end |
draw
DescriptionDraw the display.Definition
draw()Code
467 | function FieldInfoDisplay:draw() |
468 | if self.isEnabled and self:getVisible() then |
469 | FieldInfoDisplay:superClass().draw(self) |
470 | self:drawText() |
471 | end |
472 | end |
drawText
DescriptionDraw text parts of this display element.Definition
drawText()Code
476 | function FieldInfoDisplay:drawText() |
477 | -- top label |
478 | local posX, posY = self:getPosition() |
479 | local labelPosX, labelPosY = posX + self.labelTextOffsetX, posY + self:getHeight() + self.labelTextOffsetY |
480 | |
481 | setTextBold(true) |
482 | setTextAlignment(RenderText.ALIGN_LEFT) |
483 | setTextColor(unpack(FieldInfoDisplay.COLOR.TEXT_DEFAULT)) |
484 | |
485 | renderText(labelPosX, labelPosY, self.labelTextSize, self.displayLabelText) |
486 | |
487 | -- rows |
488 | local listPosX, listPosY = self.rowListElement:getPosition() |
489 | local listWidth, listHeight = self.rowListElement:getWidth(), self.rowListElement:getHeight() |
490 | |
491 | local rowPosY = listPosY + listHeight - self.rowHeight |
492 | for i = 1, FieldInfoDisplay.MAX_ROW_COUNT do |
493 | local row = self.rows[i] |
494 | if row.leftText ~= "" or row.rightText ~= "" then |
495 | local centerY = rowPosY + (self.rowHeight - self.rowTextSize) * 0.5 |
496 | local leftTextY = centerY + self.leftTextOffsetY |
497 | local leftTextX = listPosX + self.leftTextOffsetX |
498 | |
499 | local rightTextY = centerY + self.rightTextOffsetY |
500 | local rightTextX = listPosX + listWidth + self.rightTextOffsetX |
501 | |
502 | setTextBold(true) |
503 | setTextAlignment(RenderText.ALIGN_LEFT) |
504 | setTextColor(unpack(row.leftColor)) |
505 | |
506 | renderText(leftTextX, leftTextY, self.rowTextSize, row.leftText) |
507 | |
508 | setTextBold(false) |
509 | setTextAlignment(RenderText.ALIGN_RIGHT) |
510 | setTextColor(unpack(FieldInfoDisplay.COLOR.TEXT_DEFAULT)) |
511 | |
512 | renderText(rightTextX, rightTextY, self.rowTextSize, row.rightText) |
513 | |
514 | rowPosY = rowPosY - self.rowHeight |
515 | end |
516 | end |
517 | end |
getBackgroundPosition
DescriptionGet the scaled background position.Definition
getBackgroundPosition()Code
525 | function FieldInfoDisplay.getBackgroundPosition(uiScale) |
526 | local width, _ = getNormalizedScreenValues(unpack(FieldInfoDisplay.SIZE.SELF)) |
527 | local posX = 1 - g_safeFrameOffsetX - width * uiScale |
528 | local posY = g_safeFrameOffsetY |
529 | |
530 | return posX, posY |
531 | end |
new
DescriptionCreate a new instance of FieldInfoDisplay.Definition
new(string hudAtlasPath)Arguments
string | hudAtlasPath | Path to the HUD texture atlas |
46 | function FieldInfoDisplay.new(hudAtlasPath, l10n, fruitTypeManager, currentMission, farmManager, farmlandManager) |
47 | local backgroundOverlay = FieldInfoDisplay.createBackground(hudAtlasPath) |
48 | local self = FieldInfoDisplay:superClass().new(FieldInfoDisplay_mt, backgroundOverlay, nil) |
49 | |
50 | self.isEnabled = true |
51 | |
52 | self.l10n = l10n |
53 | self.fruitTypeManager = fruitTypeManager |
54 | self.currentMission = currentMission |
55 | self.farmManager = farmManager |
56 | self.farmlandManager = farmlandManager |
57 | |
58 | self.requestedFieldData = false -- asynchronous field data request flag (if true, do not request again) |
59 | |
60 | self.rows = {} -- {i={infoType=<int>, leftText="<text>", rightText="<text>", leftColor={r, g, b, a}}} |
61 | self.needResize = false |
62 | |
63 | self.displayLabelText = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.DISPLAY_LABEL):upper() |
64 | self.labelTextSize = 0 |
65 | self.rowTextSize = 0 |
66 | self.labelTextOffsetX, self.labelTextOffsetY = 0, 0 |
67 | self.leftTextOffsetX, self.leftTextOffsetY = 0, 0 |
68 | self.rightTextOffsetX, self.rightTextOffsetY = 0, 0 |
69 | self.rowWidth, self.rowHeight = 0, 0 |
70 | self.listMarginWidth, self.listMarginHeight = 0, 0 |
71 | |
72 | self.frameElement = nil |
73 | self.rowListElement = nil |
74 | |
75 | self.separators = {} -- {i=HUDElement}, ordered top to bottom |
76 | self:createComponents(hudAtlasPath) |
77 | self:setupRows() |
78 | |
79 | return self |
80 | end |
onFieldDataUpdateFinished
DescriptionCalled when FSDensityMapUtil.getFieldStatusAsync() in update() has finished.Definition
onFieldDataUpdateFinished(table data)Arguments
table | data | Field information data as provided by processing in FSDensityMapUtil.getFieldStatusAsync() |
353 | function FieldInfoDisplay:onFieldDataUpdateFinished(data) |
354 | if not self.requestedFieldData then |
355 | return -- discard results of update in some cases, e.g. reset |
356 | end |
357 | |
358 | local hasData = data ~= nil |
359 | |
360 | if hasData then |
361 | self:clearFieldData() |
362 | self:setFarmlandOwnerFarmId(data.farmlandId, data.ownerFarmId) |
363 | self:setLimeRequired(data.needsLimeFactor > FieldInfoDisplay.LIME_REQUIRED_THRESHOLD) |
364 | self:setPlowingRequired(data.needsPlowFactor > FieldInfoDisplay.PLOWING_REQUIRED_THRESHOLD) |
365 | self:setFertilization(data.fertilizerFactor) |
366 | self:setWeed(data.weedFactor) |
367 | |
368 | local fruitIndex = 0 |
369 | local fruitState = 0 |
370 | local maxPixels = 0 |
371 | for fruitDescIndex, state in pairs(data.fruits) do |
372 | if data.fruitPixels[fruitDescIndex] > maxPixels then |
373 | maxPixels = data.fruitPixels[fruitDescIndex] |
374 | fruitIndex = fruitDescIndex |
375 | fruitState = state |
376 | end |
377 | end |
378 | |
379 | self:setFruitType(fruitIndex, fruitState) -- fruitIndex 0 will just remove type and growth state rows |
380 | end |
381 | |
382 | self.requestedFieldData = false |
383 | |
384 | self:setVisible(hasData and self.player.isEntered) |
385 | end |
reset
DescriptionReset the field info display.Definition
reset()Code
455 | function FieldInfoDisplay:reset() |
456 | self.requestedFieldData = false -- causes any current asynchronous field data update results to be discarded |
457 | self:setVisible(false) |
458 | self:clearFieldData() |
459 | end |
setEnabled
DescriptionDefinitionsetEnabled()Code
105 | function FieldInfoDisplay:setEnabled(isEnabled) |
106 | self.isEnabled = isEnabled |
107 | if not isEnabled then |
108 | self:clearFieldData() |
109 | end |
110 | end |
setFarmlandOwnerFarmId
DescriptionSet the field ownerDefinition
setFarmlandOwnerFarmId(int farmlandId, int ownerFarmId)Arguments
int | farmlandId | Current farmland id |
int | ownerFarmId | Current owner farm id |
173 | function FieldInfoDisplay:setFarmlandOwnerFarmId(farmlandId, ownerFarmId) |
174 | local ownerRow = self.rows[FieldInfoDisplay.INFO_TYPE.OWNER] |
175 | |
176 | ownerRow.leftText = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.OWNED_BY) |
177 | local farmName |
178 | if ownerFarmId == self.currentMission:getFarmId() and ownerFarmId ~= FarmManager.SPECTATOR_FARM_ID then |
179 | farmName = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.OWNER_YOU) |
180 | elseif ownerFarmId == AccessHandler.EVERYONE or ownerFarmId == AccessHandler.NOBODY then |
181 | local farmland = self.farmlandManager:getFarmlandById(farmlandId) |
182 | if farmland == nil then |
183 | farmName = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.OWNER_NOBODY) |
184 | else |
185 | local npc = farmland:getNPC() |
186 | farmName = npc.title |
187 | end |
188 | else |
189 | local farm = self.farmManager:getFarmById(ownerFarmId) |
190 | if farm ~= nil then |
191 | farmName = farm.name |
192 | else |
193 | farmName = "Unkown" |
194 | end |
195 | end |
196 | |
197 | ownerRow.rightText = farmName |
198 | |
199 | self.needResize = true |
200 | end |
setFertilization
DescriptionSet the fertilization factor info to display.Definition
setFertilization(float fertilizationFactor)Arguments
float | fertilizationFactor | Current fertilization factor to display, this will be converted to a percentage. Values < 0 clear this info. |
205 | function FieldInfoDisplay:setFertilization(fertilizationFactor) |
206 | local fertRow = self.rows[FieldInfoDisplay.INFO_TYPE.FERTILIZATION] |
207 | |
208 | if fertilizationFactor >= 0 then |
209 | fertRow.leftText = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.FERTILIZATION) |
210 | fertRow.rightText = string.format("%d %%", fertilizationFactor * 100) |
211 | else -- clear |
212 | self:clearInfoRow(fertRow) |
213 | end |
214 | |
215 | self.needResize = true |
216 | end |
setFruitType
DescriptionSet the current fruit type to display.Definition
setFruitType(int fruitTypeIndex, int fruitGrowthState)Arguments
int | fruitTypeIndex | Index of the field fruit type or a number <= 0 to clear the fruit type. |
int | fruitGrowthState | Current growth state of the given fruit type |
122 | function FieldInfoDisplay:setFruitType(fruitTypeIndex, fruitGrowthState) |
123 | local fruitTypeRow = self.rows[FieldInfoDisplay.INFO_TYPE.FRUIT_TYPE] |
124 | local fieldStateRow = self.rows[FieldInfoDisplay.INFO_TYPE.FIELD_STATE] |
125 | |
126 | if fruitTypeIndex > 0 then |
127 | local fruitType = self.fruitTypeManager:getFruitTypeByIndex(fruitTypeIndex) |
128 | |
129 | fruitTypeRow.leftText = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.FRUIT_TYPE) |
130 | fruitTypeRow.rightText = fruitType.fillType.title |
131 | |
132 | local witheredState = fruitType.maxHarvestingGrowthState + 1 |
133 | if fruitType.maxPreparingGrowthState >= 0 then |
134 | witheredState = fruitType.maxPreparingGrowthState + 1 |
135 | end |
136 | |
137 | local maxGrowingState = fruitType.minHarvestingGrowthState - 1 |
138 | if fruitType.minPreparingGrowthState >= 0 then |
139 | maxGrowingState = math.min(maxGrowingState, fruitType.minPreparingGrowthState - 1) |
140 | end |
141 | |
142 | local text = "" |
143 | if fruitGrowthState == fruitType.cutState + 1 then |
144 | text = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.GROWTH_STATE_CUT) |
145 | elseif fruitGrowthState == witheredState+1 then |
146 | text = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.GROWTH_STATE_WITHERED) |
147 | elseif fruitGrowthState > 0 and fruitGrowthState <= maxGrowingState + 1 then |
148 | text = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.GROWTH_STATE_GROWING) |
149 | elseif fruitType.minPreparingGrowthState >= 0 and fruitGrowthState >= fruitType.minPreparingGrowthState and fruitGrowthState <= fruitType.maxPreparingGrowthState + 1 then |
150 | text = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.GROWTH_STATE_NEED_PREP) |
151 | elseif fruitGrowthState >= fruitType.minHarvestingGrowthState + 1 and fruitGrowthState <= fruitType.maxHarvestingGrowthState + 1 then |
152 | text = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.GROWTH_STATE_CAN_HARVEST) |
153 | end |
154 | |
155 | if text ~= "" then |
156 | fieldStateRow.leftText = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.FIELD_STATE) |
157 | fieldStateRow.rightText = text |
158 | else |
159 | self:clearInfoRow(fieldStateRow) |
160 | end |
161 | else -- clear |
162 | self:clearInfoRow(fruitTypeRow) |
163 | self:clearInfoRow(fieldStateRow) |
164 | end |
165 | |
166 | self.needResize = true |
167 | end |
setLimeRequired
DescriptionSet the lime required display.Definition
setLimeRequired(bool isRequired)Arguments
bool | isRequired | If true, will display that the current field needs lime. Otherwise, the info is hidden. |
256 | function FieldInfoDisplay:setLimeRequired(isRequired) |
257 | local limeRow = self.rows[FieldInfoDisplay.INFO_TYPE.LIME_STATE] |
258 | |
259 | if isRequired and g_currentMission.missionInfo.limeRequired then |
260 | limeRow.leftText = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.NEED_LIME) |
261 | local highlightColor = FieldInfoDisplay.COLOR.TEXT_HIGHLIGHT |
262 | for i = 1, 4 do |
263 | limeRow.leftColor[i] = highlightColor[i] |
264 | end |
265 | else |
266 | self:clearInfoRow(limeRow) |
267 | end |
268 | |
269 | self.needResize = true |
270 | end |
setPlayer
DescriptionSet the local player reference.Definition
setPlayer()Code
114 | function FieldInfoDisplay:setPlayer(player) |
115 | self.player = player |
116 | end |
setPlowingRequired
DescriptionSet the plowing required display.Definition
setPlowingRequired(bool isRequired)Arguments
bool | isRequired | If true, will display that the current field needs to be plowed. Otherwise, the info is hidden. |
237 | function FieldInfoDisplay:setPlowingRequired(isRequired) |
238 | local plowRow = self.rows[FieldInfoDisplay.INFO_TYPE.PLOWING_STATE] |
239 | |
240 | if isRequired and g_currentMission.missionInfo.plowingRequiredEnabled then |
241 | plowRow.leftText = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.NEED_PLOWING) |
242 | local highlightColor = FieldInfoDisplay.COLOR.TEXT_HIGHLIGHT |
243 | for i = 1, 4 do |
244 | plowRow.leftColor[i] = highlightColor[i] |
245 | end |
246 | else |
247 | self:clearInfoRow(plowRow) |
248 | end |
249 | |
250 | self.needResize = true |
251 | end |
setScale
DescriptionSet this element's UI scale factor.Definition
setScale(float uiScale)Arguments
float | uiScale | UI scale factor |
536 | function FieldInfoDisplay:setScale(uiScale) |
537 | FieldInfoDisplay:superClass().setScale(self, uiScale, uiScale) |
538 | self.uiScale = uiScale |
539 | self:storeScaledValues() |
540 | end |
setupRows
DescriptionSet up rows data structures.Definition
setupRows()Code
84 | function FieldInfoDisplay:setupRows() |
85 | for i = 1, FieldInfoDisplay.MAX_ROW_COUNT do |
86 | table.insert(self.rows, { |
87 | infoType = FieldInfoDisplay.INFO_TYPE.CUSTOM, |
88 | leftText = "", |
89 | rightText = "", |
90 | leftColor = {unpack(FieldInfoDisplay.COLOR.TEXT_DEFAULT)} -- copy color array so we can change it in place |
91 | }) |
92 | end |
93 | |
94 | -- assign specific info types to rows of the defined indices |
95 | for _, infoType in pairs(FieldInfoDisplay.INFO_TYPE) do |
96 | local infoTypeRow = self.rows[infoType] |
97 | if infoTypeRow ~= nil then |
98 | infoTypeRow.infoType = infoType |
99 | end |
100 | end |
101 | end |
setWeed
DescriptionSet the weed factor info to display.Definition
setWeed(float fertilizationFactor)Arguments
float | fertilizationFactor | Current weed factor to display, this will be converted to a percentage. Values < 0 clear this info. |
221 | function FieldInfoDisplay:setWeed(weedFactor) |
222 | local weedRow = self.rows[FieldInfoDisplay.INFO_TYPE.WEED] |
223 | |
224 | if weedFactor >= 0 and g_currentMission.missionInfo.weedsEnabled then |
225 | weedRow.leftText = self.l10n:getText(FieldInfoDisplay.L10N_SYMBOL.WEED) |
226 | weedRow.rightText = string.format("%d %%", weedFactor * 100) |
227 | else -- clear |
228 | self:clearInfoRow(weedRow) |
229 | end |
230 | |
231 | self.needResize = true |
232 | end |
storeScaledValues
DescriptionStore scaled position and size values.Definition
storeScaledValues()Code
544 | function FieldInfoDisplay:storeScaledValues() |
545 | self.labelTextSize = self:scalePixelToScreenHeight(HUDElement.TEXT_SIZE.DEFAULT_TITLE) |
546 | self.rowTextSize = self:scalePixelToScreenHeight(HUDElement.TEXT_SIZE.DEFAULT_TEXT) |
547 | |
548 | self.labelTextOffsetX, self.labelTextOffsetY = self:scalePixelToScreenVector(FieldInfoDisplay.POSITION.DISPLAY_LABEL) |
549 | self.leftTextOffsetX, self.leftTextOffsetY = self:scalePixelToScreenVector(FieldInfoDisplay.POSITION.TEXT_LEFT) |
550 | self.rightTextOffsetX, self.rightTextOffsetY = self:scalePixelToScreenVector(FieldInfoDisplay.POSITION.TEXT_RIGHT) |
551 | |
552 | self.rowWidth, self.rowHeight = self:scalePixelToScreenVector(FieldInfoDisplay.SIZE.ROW) |
553 | self.listMarginWidth, self.listMarginHeight = self:scalePixelToScreenVector(FieldInfoDisplay.SIZE.ROW_LIST_MARGIN) |
554 | end |
update
DescriptionDefinitionupdate()Code
393 | function FieldInfoDisplay:update(dt) |
394 | FieldInfoDisplay:superClass().update(self, dt) |
395 | |
396 | if self.isEnabled and self.player ~= nil and self.player.isEntered and not self.requestedFieldData then |
397 | local posX, posY, posZ, rotY = self.player:getPositionData() |
398 | |
399 | local sizeX, sizeZ = 5, 5 |
400 | local distance = 2 |
401 | |
402 | local dirX, dirZ = MathUtil.getDirectionFromYRotation(rotY) |
403 | local sideX,_,sideZ = MathUtil.crossProduct(dirX, 0, dirZ, 0, 1, 0) |
404 | |
405 | local startWorldX, startWorldZ = posX - sideX*sizeX*0.5 - dirX*distance, posZ - sideZ*sizeX*0.5 - dirZ*distance |
406 | local widthWorldX, widthWorldZ = posX + sideX*sizeX*0.5 - dirX*distance, posZ + sideZ*sizeX*0.5 - dirZ*distance |
407 | local heightWorldX, heightWorldZ = posX - sideX*sizeX*0.5 - dirX*(distance+sizeZ), posZ - sideZ*sizeX*0.5 - dirZ*(distance+sizeZ) |
408 | |
409 | self.requestedFieldData = true |
410 | FSDensityMapUtil.getFieldStatusAsync(startWorldX, startWorldZ, widthWorldX, widthWorldZ, heightWorldX, heightWorldZ, self.onFieldDataUpdateFinished, self) |
411 | end |
412 | |
413 | if self.needResize then |
414 | self:updateSize() |
415 | end |
416 | end |
updateSize
DescriptionUpdate the info display size depending on used rows.Definition
updateSize()Code
420 | function FieldInfoDisplay:updateSize() |
421 | for _, sep in pairs(self.separators) do |
422 | sep:setVisible(false) |
423 | end |
424 | |
425 | local rowCount = 0 |
426 | for i = 1, FieldInfoDisplay.MAX_ROW_COUNT do |
427 | local row = self.rows[i] |
428 | if row.leftText ~= "" or row.rightText ~= "" then |
429 | rowCount = rowCount + 1 |
430 | if rowCount > 1 and rowCount < FieldInfoDisplay.MAX_ROW_COUNT then |
431 | self.separators[rowCount]:setVisible(true) |
432 | end |
433 | end |
434 | end |
435 | |
436 | -- set new dimensions |
437 | local newListHeight = rowCount * self.rowHeight |
438 | self.rowListElement:setDimension(self.rowListElement:getWidth(), newListHeight) |
439 | |
440 | local listWidth, listHeight = self.rowListElement:getWidth(), self.rowListElement:getHeight() |
441 | local width, height = listWidth + self.listMarginWidth * 2, listHeight + self.listMarginHeight * 2 |
442 | self:setDimension(width, height) |
443 | self.frameElement:setDimension(width, height) |
444 | |
445 | -- re-position |
446 | local posX, posY = FieldInfoDisplay.getBackgroundPosition(self.uiScale) |
447 | self:setPosition(posX, posY) |
448 | self.rowListElement:setPosition(posX + self.listMarginWidth, posY + self.listMarginHeight) |
449 | |
450 | self.needResize = false |
451 | end |