LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

GameInfoDisplay

Description
HUD general game information display. Displays current game information. This includes weather, current account balance and time settings.
Parent
HUDDisplayElement
Functions

addActiveWeatherAnimation

Description
Animate a weather icon becoming active.
Definition
addActiveWeatherAnimation()
Code
475function GameInfoDisplay:addActiveWeatherAnimation(animationSequence, isCurrentWeatherIcon, icon)
476 local fullColor = GameInfoDisplay.COLOR.ICON_WEATHER_NEXT
477 if isCurrentWeatherIcon then
478 fullColor = GameInfoDisplay.COLOR.ICON
479 end
480
481 local transparentColor = {fullColor[1], fullColor[2], fullColor[3], 0}
482 local fadeInSequence = TweenSequence.new(icon)
483 local fadeIn = MultiValueTween.new(icon.setColor, transparentColor, fullColor, HUDDisplayElement.MOVE_ANIMATION_DURATION)
484
485 fadeInSequence:insertTween(fadeIn, 0)
486 fadeInSequence:insertCallback(icon.setVisible, true, 0)
487
488 fadeInSequence:start()
489 animationSequence:insertTween(fadeInSequence, 0)
490end

addBecomeCurrentWeatherAnimation

Description
Animate a weather icon becoming the current weather icon.
Definition
addBecomeCurrentWeatherAnimation()
Code
509function GameInfoDisplay:addBecomeCurrentWeatherAnimation(animationSequence, icon)
510 local currentColor = {icon:getColor()}
511 local makeCurrent = MultiValueTween.new(icon.setColor, currentColor, GameInfoDisplay.COLOR.ICON, HUDDisplayElement.MOVE_ANIMATION_DURATION)
512 makeCurrent:setTarget(icon)
513 animationSequence:insertTween(makeCurrent, 0)
514end

addInactiveWeatherAnimation

Description
Animate a weather icon becoming inactive.
Definition
addInactiveWeatherAnimation()
Code
494function GameInfoDisplay:addInactiveWeatherAnimation(animationSequence, icon)
495 local currentColor = {icon:getColor()}
496 local transparentColor = {currentColor[1], currentColor[2], currentColor[3], 0}
497 local fadeOutSequence = TweenSequence.new(icon)
498 local fadeOut = MultiValueTween.new(icon.setColor, currentColor, transparentColor, HUDDisplayElement.MOVE_ANIMATION_DURATION)
499
500 fadeOutSequence:insertTween(fadeOut, 0)
501 fadeOutSequence:addCallback(icon.setVisible, false)
502
503 fadeOutSequence:start()
504 animationSequence:insertTween(fadeOutSequence, 0)
505end

addWeatherPositionAnimation

Description
Animate weather icon position changes.
Definition
addWeatherPositionAnimation()
Code
518function GameInfoDisplay:addWeatherPositionAnimation(animationSequence, isWeatherChanging)
519 local icon = self.weatherTypeIcons[self.currentWeather]
520 local boxPosX, boxPosY = self.weatherBox:getPosition()
521 local centerX, centerY = boxPosX + self.weatherBox:getWidth() * 0.5, boxPosY + (self.weatherBox:getHeight() - icon:getHeight()) * 0.5
522
523 if isWeatherChanging then
524 local moveLeft = MultiValueTween.new(icon.setPosition, {icon:getPosition()}, {centerX - icon:getWidth(), centerY}, HUDDisplayElement.MOVE_ANIMATION_DURATION)
525 moveLeft:setTarget(icon)
526 animationSequence:insertTween(moveLeft, 0)
527
528 local secondIcon = self.weatherTypeIcons[self.nextWeather]
529 if secondIcon:getVisible() then
530 local moveRight = MultiValueTween.new(secondIcon.setPosition, {secondIcon:getPosition()}, {centerX, centerY}, HUDDisplayElement.MOVE_ANIMATION_DURATION)
531 moveRight:setTarget(secondIcon)
532 animationSequence:insertTween(moveRight, 0)
533 else
534 secondIcon:setPosition(centerX, centerY)
535 end
536 else
537 local iconPosX, iconPosY = icon:getPosition()
538 if iconPosX ~= centerX or iconPosY ~= centerY and self.weatherAnimation:getFinished() then
539 local move = MultiValueTween.new(icon.setPosition, {icon:getPosition()}, {centerX, centerY}, HUDDisplayElement.MOVE_ANIMATION_DURATION)
540 move:setTarget(icon)
541 animationSequence:insertTween(move, 0)
542 end
543 end
544end

animateWeatherChange

Description
Make an animation for a weather change.
Definition
animateWeatherChange()
Code
449function GameInfoDisplay:animateWeatherChange()
450 local sequence = TweenSequence.new()
451
452 for weatherType, icon in pairs(self.weatherTypeIcons) do
453 local isCurrent = weatherType == self.currentWeather
454 local isNext = weatherType == self.nextWeather
455 local makeVisible = isCurrent or isNext
456
457 if makeVisible and not icon:getVisible() then
458 self:addActiveWeatherAnimation(sequence, isCurrent, icon)
459 elseif not makeVisible and icon:getVisible() then
460 self:addInactiveWeatherAnimation(sequence, icon)
461 else
462 self:addBecomeCurrentWeatherAnimation(sequence, icon)
463 end
464 end
465
466 local isWeatherChanging = self.currentWeather ~= self.nextWeather
467 self:addWeatherPositionAnimation(sequence, isWeatherChanging)
468
469 sequence:start()
470 self.weatherAnimation = sequence
471end

createBackground

Description
Create the background overlay.
Definition
createBackground()
Code
636function GameInfoDisplay.createBackground()
637 local posX, posY = GameInfoDisplay.getBackgroundPosition(1) -- top right corner
638 local width, height = getNormalizedScreenValues(unpack(GameInfoDisplay.SIZE.SELF))
639 width = width + g_safeFrameOffsetX
640 local overlay = Overlay.new(nil, posX - width, posY - height, width, height)
641 -- overlay:setUVs(g_colorBgUVs)
642 -- overlay:setColor(0, 0, 0, 0.75)
643 return overlay
644end

createClockHand

Description
Create a rotatable clock hand icon element.
Definition
createClockHand(string hudAtlasPath, float posX, float posY, table size, table uvs, table color, table pivot)
Arguments
stringhudAtlasPathPath to HUD texture atlas
floatposXScreen space X position of the clock hand
floatposYScreen space Y position of the clock hand
tablesizePixel size vector {width, height}
tableuvsUV coordinates of the icon in the HUD texture atlas
tablecolorColor RGBA array
tablepivotUV pixel space rotation pivot coordinates
Return Values
tableClockhand HUDElement instance
Code
943function GameInfoDisplay:createClockHand(hudAtlasPath, posX, posY, size, uvs, color, pivot)
944 local pivotX, pivotY = self:normalizeUVPivot(pivot, size, uvs)
945 local width, height = self:scalePixelToScreenVector(size)
946 local clockHandOverlay = Overlay.new(hudAtlasPath, posX - pivotX, posY - pivotY, width, height)
947 clockHandOverlay:setUVs(GuiUtils.getUVs(uvs))
948 clockHandOverlay:setColor(unpack(color))
949
950 local clockHandElement = HUDElement.new(clockHandOverlay)
951 clockHandElement:setRotationPivot(pivotX, pivotY)
952
953 return clockHandElement
954end

createComponents

Description
Create required display components. Also adds a separator HUDElement instance as a field (".separator") to all info boxes.
Definition
createComponents()
Code
664function GameInfoDisplay:createComponents(hudAtlasPath)
665 local topRightX, topRightY = GameInfoDisplay.getBackgroundPosition(1)
666 local bottomY = topRightY - self:getHeight()
667 local marginWidth, _ = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.BOX_MARGIN)
668
669 self.backgroundOverlay = self:createBackgroundOverlay()
670 self.backgroundBaseX = topRightX
671
672 -- create components from right to left
673 local rightX = self:createMoneyBox(hudAtlasPath, topRightX, bottomY) - marginWidth
674 self.moneyBox.separator = {setVisible=function() end} -- just use a dummy for the money box
675 local sepX = rightX
676 rightX = self:createTimeBox(hudAtlasPath, rightX - marginWidth, bottomY) - marginWidth
677
678 local centerY = bottomY + self:getHeight() * 0.5
679 local separator = self:createVerticalSeparator(hudAtlasPath, sepX, centerY)
680 self.timeBox:addChild(separator)
681 self.timeBox.separator = separator
682
683 sepX = rightX
684 rightX = self:createDateBox(hudAtlasPath, rightX - marginWidth, bottomY) - marginWidth
685
686 separator = self:createVerticalSeparator(hudAtlasPath, sepX, centerY)
687 self.dateBox:addChild(separator)
688 self.dateBox.separator = separator
689
690 sepX = rightX
691 rightX = self:createTemperatureBox(hudAtlasPath, rightX - marginWidth, bottomY) - marginWidth
692
693 separator = self:createVerticalSeparator(hudAtlasPath, sepX, centerY)
694 self.temperatureBox:addChild(separator)
695 self.temperatureBox.separator = separator
696
697 sepX = rightX
698 rightX = self:createWeatherBox(hudAtlasPath, rightX - marginWidth, bottomY) - marginWidth
699
700 separator = self:createVerticalSeparator(hudAtlasPath, sepX, centerY)
701 self.weatherBox:addChild(separator)
702 self.weatherBox.separator = separator
703
704 sepX = rightX
705 self:createTutorialBox(hudAtlasPath, rightX - marginWidth, bottomY)
706
707 separator = self:createVerticalSeparator(hudAtlasPath, sepX, centerY)
708 self.tutorialBox:addChild(separator)
709 self.tutorialBox.separator = separator
710
711 -- update background size based on components:
712 local width = self:getVisibleWidth()
713 self:setDimension(width+g_safeFrameOffsetX, self:getHeight())
714end

createMoneyBox

Description
Create the money display box.
Definition
createMoneyBox()
Code
718function GameInfoDisplay:createMoneyBox(hudAtlasPath, rightX, bottomY)
719 local iconWidth, iconHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.MONEY_ICON)
720 local boxWidth, boxHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.MONEY_BOX)
721 local posX = rightX - boxWidth
722 local posY = bottomY + (boxHeight - iconHeight) * 0.5
723
724 local boxOverlay = Overlay.new(nil, posX, bottomY, boxWidth, boxHeight)
725 local boxElement = HUDElement.new(boxOverlay)
726 self.moneyBox = boxElement
727 self:addChild(boxElement)
728 table.insert(self.infoBoxes, self.moneyBox)
729
730 local iconOverlay = Overlay.new(hudAtlasPath, posX, posY, iconWidth, iconHeight)
731 iconOverlay:setUVs(GuiUtils.getUVs(GameInfoDisplay.UV.MONEY_ICON))
732 iconOverlay:setColor(unpack(GameInfoDisplay.COLOR.ICON))
733
734 self.moneyIconOverlay = iconOverlay
735 boxElement:addChild(HUDElement.new(iconOverlay))
736
737 self.moneyCurrencyText = g_i18n:getCurrencySymbol(true)
738
739 return posX
740end

createTemperatureBox

Description
Create the temperature display box.
Definition
createTemperatureBox()
Code
834function GameInfoDisplay:createTemperatureBox(hudAtlasPath, rightX, bottomY)
835 local boxWidth, boxHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TEMPERATURE_BOX)
836 local posX = rightX - boxWidth
837
838 local boxOverlay = Overlay.new(nil, posX, bottomY, boxWidth, boxHeight)
839 local boxElement = HUDElement.new(boxOverlay)
840 self.temperatureBox = boxElement
841 self:addChild(boxElement)
842 table.insert(self.infoBoxes, self.temperatureBox)
843
844 self.temperatureIconStable = self:createTemperatureIcon(hudAtlasPath, posX, bottomY, boxHeight,
845 GameInfoDisplay.UV.TEMPERATURE_ICON_STABLE, GameInfoDisplay.COLOR.ICON)
846 boxElement:addChild(self.temperatureIconStable)
847
848 self.temperatureIconRising = self:createTemperatureIcon(hudAtlasPath, posX, bottomY, boxHeight,
849 GameInfoDisplay.UV.TEMPERATURE_ICON_RISING, GameInfoDisplay.COLOR.ICON)
850 boxElement:addChild(self.temperatureIconRising)
851
852 self.temperatureIconDropping = self:createTemperatureIcon(hudAtlasPath, posX, bottomY, boxHeight,
853 GameInfoDisplay.UV.TEMPERATURE_ICON_DROPPING, GameInfoDisplay.COLOR.ICON)
854 boxElement:addChild(self.temperatureIconDropping)
855
856 return rightX - boxWidth
857end

createTemperatureIcon

Description
Create a temperature icon to display stable or changing temperatures.
Definition
createTemperatureIcon(string hudAtlasPath, float leftX, float bottomY, float boxHeight, table uvs, table color)
Arguments
stringhudAtlasPathPath to HUD texture atlas
floatleftXScreen space left X position of newly created icon
floatbottomYScreen space bottom Y position of the parent box
floatboxHeightScreen space height of the parent box
tableuvsUV coordinates of the icon in the HUD texture atlas
tablecolorColor RGBA array
Return Values
tableTemperatureicon HUDElement instance
Code
923function GameInfoDisplay:createTemperatureIcon(hudAtlasPath, leftX, bottomY, boxHeight, uvs, color)
924 local iconWidth, iconHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TEMPERATURE_ICON)
925 local posY = bottomY + (boxHeight - iconHeight) * 0.5
926 local overlay = Overlay.new(hudAtlasPath, leftX, posY, iconWidth, iconHeight)
927 overlay:setUVs(GuiUtils.getUVs(uvs))
928 overlay:setColor(unpack(color))
929
930 return HUDElement.new(overlay)
931end

createTimeBox

Description
Create the time display box.
Definition
createTimeBox()
Code
744function GameInfoDisplay:createTimeBox(hudAtlasPath, rightX, bottomY)
745 local boxWidth, boxHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TIME_BOX)
746 local posX = rightX - boxWidth
747
748 local boxOverlay = Overlay.new(nil, posX, bottomY, boxWidth, boxHeight)
749 local boxElement = HUDElement.new(boxOverlay)
750 self.timeBox = boxElement
751 self:addChild(boxElement)
752 table.insert(self.infoBoxes, self.timeBox)
753
754 local clockWidth, clockHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TIME_ICON)
755 local posY = bottomY + (boxHeight - clockHeight) * 0.5
756 local clockOverlay = Overlay.new(hudAtlasPath, posX, posY, clockWidth, clockHeight)
757 clockOverlay:setUVs(GuiUtils.getUVs(GameInfoDisplay.UV.TIME_ICON))
758 clockOverlay:setColor(unpack(GameInfoDisplay.COLOR.ICON))
759 local clockElement = HUDElement.new(clockOverlay)
760 self.clockElement = clockElement
761 boxElement:addChild(clockElement)
762
763 posX, posY = posX + clockWidth * 0.5, posY + clockHeight * 0.5
764
765 self.clockHandSmall = self:createClockHand(hudAtlasPath, posX, posY,
766 GameInfoDisplay.SIZE.CLOCK_HAND_SMALL,
767 GameInfoDisplay.UV.CLOCK_HAND_SMALL,
768 GameInfoDisplay.COLOR.CLOCK_HAND_SMALL,
769 GameInfoDisplay.PIVOT.CLOCK_HAND_SMALL)
770 clockElement:addChild(self.clockHandSmall)
771
772 self.clockHandLarge = self:createClockHand(hudAtlasPath, posX, posY,
773 GameInfoDisplay.SIZE.CLOCK_HAND_LARGE,
774 GameInfoDisplay.UV.CLOCK_HAND_LARGE,
775 GameInfoDisplay.COLOR.CLOCK_HAND_LARGE,
776 GameInfoDisplay.PIVOT.CLOCK_HAND_LARGE)
777 clockElement:addChild(self.clockHandLarge)
778
779 local arrowOffX, arrowOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TIME_SCALE_ARROW)
780 posX, posY = rightX - boxWidth + clockWidth + arrowOffX, bottomY + boxHeight * 0.5 + arrowOffY
781
782 self.timeScaleArrow = self:createTimeScaleArrow(hudAtlasPath, posX, posY,
783 GameInfoDisplay.SIZE.TIME_SCALE_ARROW,
784 GameInfoDisplay.UV.TIME_SCALE_ARROW)
785 boxElement:addChild(self.timeScaleArrow)
786
787 self.timeScaleArrowFast = self:createTimeScaleArrow(hudAtlasPath, posX, posY,
788 GameInfoDisplay.SIZE.TIME_SCALE_ARROW_FAST,
789 GameInfoDisplay.UV.TIME_SCALE_ARROW_FAST)
790 boxElement:addChild(self.timeScaleArrowFast)
791
792 return rightX - boxWidth
793end

createTimeScaleArrow

Description
Create a time scale arrow icon element.
Definition
createTimeScaleArrow(string hudAtlasPath, float posX, float posY, table size, table uvs)
Arguments
stringhudAtlasPathPath to HUD texture atlas
floatposXScreen space X position of the arrow
floatposYScreen space Y position of the arrow
tablesizePixel size vector {width, height}
tableuvsUV coordinates of the icon in the HUD texture atlas
Return Values
tableTimescale arrow icon HUDElement instance
Code
964function GameInfoDisplay:createTimeScaleArrow(hudAtlasPath, posX, posY, size, uvs)
965 local arrowWidth, arrowHeight = self:scalePixelToScreenVector(size)
966 local arrowOverlay = Overlay.new(hudAtlasPath, posX, posY, arrowWidth, arrowHeight)
967 arrowOverlay:setUVs(GuiUtils.getUVs(uvs))
968 arrowOverlay:setColor(unpack(GameInfoDisplay.COLOR.ICON))
969 return HUDElement.new(arrowOverlay)
970end

createTutorialBox

Description
Create the tutorial progress box.
Definition
createTutorialBox()
Code
987function GameInfoDisplay:createTutorialBox(hudAtlasPath, rightX, bottomY)
988 local boxWidth, boxHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TUTORIAL_BOX)
989 local posX = rightX - boxWidth
990 local boxOverlay = Overlay.new(nil, posX, bottomY, boxWidth, boxHeight)
991 local boxElement = HUDElement.new(boxOverlay)
992 self.tutorialBox = boxElement
993 self:addChild(boxElement)
994 table.insert(self.infoBoxes, self.tutorialBox)
995
996 -- create progress bar background frame
997 local offX, offY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TUTORIAL_PROGRESS_BAR)
998 local barWidth, barHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TUTORIAL_PROGRESS_BAR)
999 local barPosX, barPosY = rightX - barWidth + offX, bottomY + (boxHeight - barHeight) * 0.5 + offY
1000
1001 local pixelX, pixelY = 1 / g_screenWidth, 1 / g_screenHeight
1002 local topLine = Overlay.new(hudAtlasPath, barPosX - pixelX, barPosY + barHeight, barWidth + pixelX * 2, pixelY)
1003 local bottomLine = Overlay.new(hudAtlasPath, barPosX - pixelX, barPosY - pixelY, barWidth + pixelX * 2, pixelY)
1004 local leftLine = Overlay.new(hudAtlasPath, barPosX - pixelX, barPosY, pixelX, barHeight)
1005 local rightLine = Overlay.new(hudAtlasPath, barPosX + barWidth, barPosY, pixelX, barHeight)
1006
1007 for _, lineOverlay in pairs{topLine, bottomLine, leftLine, rightLine} do
1008 lineOverlay:setUVs(GuiUtils.getUVs(GameInfoDisplay.UV.SEPARATOR))
1009 lineOverlay:setColor(unpack(GameInfoDisplay.COLOR.SEPARATOR))
1010 local lineElement = HUDElement.new(lineOverlay)
1011 self.tutorialBox:addChild(lineElement)
1012 end
1013
1014 -- create progress bar scalable overlay
1015 local barOverlay = Overlay.new(hudAtlasPath, barPosX, barPosY, barWidth, barHeight)
1016 barOverlay:setUVs(GuiUtils.getUVs(GameInfoDisplay.UV.SEPARATOR))
1017 barOverlay:setColor(unpack(GameInfoDisplay.COLOR.TUTORIAL_PROGRESS_BAR))
1018 local barElement = HUDElement.new(barOverlay)
1019 self.tutorialBox:addChild(barElement)
1020 self.tutorialProgressBar = barElement
1021
1022 return rightX - boxWidth
1023end

createVerticalSeparator

Description
Create and return a vertical separator element.
Definition
createVerticalSeparator()
Code
974function GameInfoDisplay:createVerticalSeparator(hudAtlasPath, posX, centerPosY)
975 local width, height = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.SEPARATOR)
976 width = math.max(width, 1 / g_screenWidth)
977
978 local overlay = Overlay.new(hudAtlasPath, posX - width * 0.5, centerPosY - height * 0.5, width, height)
979 overlay:setUVs(GuiUtils.getUVs(GameInfoDisplay.UV.SEPARATOR))
980 overlay:setColor(unpack(GameInfoDisplay.COLOR.SEPARATOR))
981
982 return HUDElement.new(overlay)
983end

createWeatherBox

Description
Create the weather display box.
Definition
createWeatherBox()
Code
861function GameInfoDisplay:createWeatherBox(hudAtlasPath, rightX, bottomY)
862 local boxWidth, boxHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.WEATHER_BOX)
863 local posX = rightX - boxWidth
864 local boxOverlay = Overlay.new(nil, posX, bottomY, boxWidth, boxHeight)
865 local boxElement = HUDElement.new(boxOverlay)
866 self.weatherBox = boxElement
867 self:addChild(boxElement)
868 table.insert(self.infoBoxes, self.weatherBox)
869
870 self.weatherBoxRight = rightX
871
872 -- Use function so new weather types can be added
873 local weatherUvs = self:getWeatherUVs()
874
875 for weatherId, uvs in pairs(weatherUvs) do
876 local weatherIcon = self:createWeatherIcon(hudAtlasPath, weatherId, boxHeight, uvs, GameInfoDisplay.COLOR.ICON)
877 boxElement:addChild(weatherIcon)
878 self.weatherTypeIcons[weatherId] = weatherIcon
879 end
880
881 return rightX - boxWidth
882end

createWeatherIcon

Description
Create a weather icon for current and upcoming weather conditions.
Definition
createWeatherIcon(string hudAtlasPath, int weatherId, float boxHeight, table uvs, table color)
Arguments
stringhudAtlasPathPath to HUD texture atlas
intweatherIdWeather condition ID, as defined in WeatherType... constants
floatboxHeightScreen space height of the box which will hold this icon
tableuvsUV coordinates of the weather icon in the HUD texture atlas
tablecolorColor RGBA array
Return Values
tableWeathericon HUDElement instance
Code
903function GameInfoDisplay:createWeatherIcon(hudAtlasPath, weatherId, boxHeight, uvs, color)
904 local width, height = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.WEATHER_ICON)
905 local overlay = Overlay.new(hudAtlasPath, 0, 0, width, height) -- position is set on update
906 overlay:setUVs(GuiUtils.getUVs(uvs))
907
908 local element = HUDElement.new(overlay)
909 element:setVisible(false)
910
911 return element
912end

draw

Description
Draw the game info display.
Definition
draw()
Code
363function GameInfoDisplay:draw()
364 GameInfoDisplay:superClass().draw(self)
365
366 if self.showMoney then
367 self:drawMoneyText()
368 end
369
370 if self.showTime then
371 self:drawTimeText()
372 end
373
374 if self.showDate then
375 self:drawDateText()
376 end
377
378 if self.showTemperature then
379 self:drawTemperatureText()
380 end
381
382 if self.showTutorialProgress then
383 self:drawTutorialText()
384 end
385end

drawMoneyText

Description
Draw the text part of the money display.
Definition
drawMoneyText()
Code
389function GameInfoDisplay:drawMoneyText()
390 setTextBold(false)
391 setTextAlignment(RenderText.ALIGN_RIGHT)
392 setTextColor(unpack(GameInfoDisplay.COLOR.TEXT))
393
394 -- TODO(SR): Optimize?
395 if g_currentMission.player ~= nil then
396 local farm = g_farmManager:getFarmById(g_currentMission.player.farmId)
397
398 local moneyText = g_i18n:formatMoney(farm.money, 0, false, true)
399 renderText(self.moneyTextPositionX, self.moneyTextPositionY, self.moneyTextSize, moneyText)
400 end
401
402 setTextAlignment(RenderText.ALIGN_CENTER)
403 setTextColor(unpack(GameInfoDisplay.COLOR.ICON))
404 renderText(self.moneyCurrencyPositionX, self.moneyCurrencyPositionY, self.moneyTextSize, self.moneyCurrencyText)
405end

drawTemperatureText

Description
Draw the text part of the temperature display.
Definition
drawTemperatureText()
Code
428function GameInfoDisplay:drawTemperatureText()
429 setTextBold(false)
430 setTextAlignment(RenderText.ALIGN_RIGHT)
431 setTextColor(unpack(GameInfoDisplay.COLOR.TEXT))
432
433 renderText(self.temperatureHighTextPositionX, self.temperatureHighTextPositionY, self.temperatureTextSize, self.temperatureDayText)
434 renderText(self.temperatureLowTextPositionX, self.temperatureLowTextPositionY, self.temperatureTextSize, self.temperatureNightText)
435end

drawTimeText

Description
Draw the text part of the time display.
Definition
drawTimeText()
Code
409function GameInfoDisplay:drawTimeText()
410 setTextBold(false)
411 setTextAlignment(RenderText.ALIGN_LEFT)
412 setTextColor(unpack(GameInfoDisplay.COLOR.TEXT))
413
414 renderText(self.timeTextPositionX, self.timeTextPositionY, self.timeTextSize, self.timeText)
415 renderText(self.timeScaleTextPositionX, self.timeScaleTextPositionY, self.timeScaleTextSize, self.timeScaleText)
416end

drawTutorialText

Description
Draw the text part of the tutorial progress display.
Definition
drawTutorialText()
Code
439function GameInfoDisplay:drawTutorialText()
440 setTextBold(true)
441 setTextAlignment(RenderText.ALIGN_RIGHT)
442 setTextColor(unpack(GameInfoDisplay.COLOR.TEXT))
443
444 renderText(self.tutorialTextPositionX, self.tutorialTextPositionY, self.tutorialTextSize, self.tutorialText)
445end

getBackgroundPosition

Description
Get this element's base background position.
Definition
getBackgroundPosition(float uiScale)
Arguments
floatuiScaleCurrent UI scale factor
Code
553function GameInfoDisplay.getBackgroundPosition(uiScale)
554 local offX, offY = getNormalizedScreenValues(unpack(GameInfoDisplay.POSITION.SELF))
555 return 1 + offX * uiScale - g_safeFrameOffsetX, 1 - g_safeFrameOffsetY + offY * uiScale -- top right corner plus offset
556end

getVisibleWidth

Description
Get the game info display's width based on its visible info boxes.
Definition
getVisibleWidth()
Return Values
floatGameinfo display width of visible elements in screen space
Code
309function GameInfoDisplay:getVisibleWidth()
310 local width = -self.boxMarginWidth -- money box has no right margin
311 for _, box in pairs(self.infoBoxes) do
312 if box:getVisible() then
313 width = width + box:getWidth() + self.boxMarginWidth * 2
314 end
315 end
316
317 if self.currentWeather == self.nextWeather then
318 local boxWidth, _ = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.WEATHER_BOX)
319 width = width - boxWidth / 2
320 end
321
322 return width
323end

getWeatherStates

Description
Definition
getWeatherStates()
Code
269function GameInfoDisplay:getWeatherStates()
270 local sixHours = 6 * 60 * 60 * 1000
271 local env = self.environment
272
273 local dayPlus6h, timePlus6h = env:getDayAndDayTime(env.dayTime + sixHours, env.currentMonotonicDay)
274
275 local weatherState = env.weather:getCurrentWeatherType()
276 local nextWeatherState = env.weather:getNextWeatherType(dayPlus6h, timePlus6h)
277
278 return weatherState, nextWeatherState
279end

getWeatherUVs

Description
Get UVs of the icons associated with the weather types
Definition
getWeatherUVs()
Code
886function GameInfoDisplay:getWeatherUVs()
887 return { -- weather type and UV definition for iteration
888 [WeatherType.SUN] = GameInfoDisplay.UV.WEATHER_ICON_CLEAR,
889 [WeatherType.RAIN] = GameInfoDisplay.UV.WEATHER_ICON_RAIN,
890 [WeatherType.CLOUDY] = GameInfoDisplay.UV.WEATHER_ICON_CLOUDY,
891 [WeatherType.SNOW] = GameInfoDisplay.UV.WEATHER_ICON_SNOW
892 }
893end

new

Description
Create a new instance of GameInfoDisplay.
Definition
new(string hudAtlasPath)
Arguments
stringhudAtlasPathPath to the HUD texture atlas
Code
18function GameInfoDisplay.new(hudAtlasPath, moneyUnit, l10n)
19 local backgroundOverlay = GameInfoDisplay.createBackground()
20 local self = GameInfoDisplay:superClass().new(backgroundOverlay, nil, GameInfoDisplay_mt)
21
22 self.moneyUnit = moneyUnit
23 self.l10n = l10n
24 self.missionStats = nil -- MissionStats reference, set on loading
25 self.environment = nil -- Environment reference, set on loading
26
27 self.showMoney = true
28 self.showWeather = true
29 self.showTemperature = true
30 self.showTime = true
31 self.showDate = true
32 self.showTutorialProgress = false
33
34 self.infoBoxes = {} -- array of created info boxes
35
36 self.moneyBox = nil
37 self.moneyIconOverlay = nil -- Overlay reference of money icon to swap money unit texture UVs when necessary
38
39 self.timeBox = nil
40 self.clockElement = nil
41 self.timeScaleArrow = nil
42 self.timeScaleArrowFast = nil
43 self.clockHandLarge = nil
44 self.clockHandSmall = nil
45
46 self.dateBox = nil
47 self.seasonElement = nil
48 self.monthMaxSize = 0
49
50 self.temperatureBox = nil
51 self.temperatureIconStable = nil
52 self.temperatureIconRising = nil
53 self.temperatureIconDropping = nil
54
55 self.weatherBox = nil
56 self.weatherTypeIcons = {} -- weather type -> HUDElement
57
58 self.tutorialBox = nil
59 self.tutorialProgressBar = nil
60
61 self.boxHeight = 0
62 self.boxMarginWidth, self.boxMarginHeight = 0, 0
63
64 self.moneyBoxWidth = 0
65 self.moneyTextSize = 0
66 self.moneyTextPositionX, self.moneyTextPositionY = 0, 0
67 self.monthText = ""
68
69 self.timeTextPositionX, self.timeTextPositionY = 0,0
70 self.timeTextSize = 0
71 self.timeScaleTextPositionX, self.timeScaleTextPositionY = 0, 0
72 self.timeScaleTextSize = 0
73 self.timeText = ""
74 self.clockHandLargePivotX, self.clockHandLargePivotY = 0, 0
75 self.clockHandSmallPivotX, self.clockHandSmallPivotY = 0, 0
76
77 self.dateTextPositionX, self.dateTextPositionY = 0,0
78
79 self.temperatureHighTextPositionX, self.temperatureHighTextPositionY = 0, 0
80 self.temperatureLowTextPositionX, self.temperatureLowTextPositionY = 0, 0
81 self.temperatureTextSize = 0
82 self.temperatureDayText = ""
83 self.temperatureNightText = ""
84
85 self.tutorialBarWidth, self.tutorialBarHeight = 0, 0
86 self.tutorialTextPositionX, self.tutorialTextPositionX = 0, 0
87 self.tutorialTextSize = 0
88 self.tutorialText = utf8ToUpper(l10n:getText(GameInfoDisplay.L10N_SYMBOL.TUTORIAL))
89
90 self.weatherAnimation = TweenSequence.NO_SEQUENCE
91 self.currentWeather = ""
92 self.nextWeather = ""
93 self.temperatureAnimation = TweenSequence.NO_SEQUENCE
94 self.lastTutorialProgress = 1
95
96 self:createComponents(hudAtlasPath)
97
98 return self
99end

setEnvironment

Description
Set the environment reference to use for weather information display.
Definition
setEnvironment(table environment)
Arguments
tableenvironmentEnvironment reference, do not change
Code
130function GameInfoDisplay:setEnvironment(environment)
131 self.environment = environment
132end

setMissionInfo

Description
Set the mission information reference for base information display.
Definition
setMissionInfo(table missionInfo)
Arguments
tablemissionInfoMissionInfo reference, do not change
Code
123function GameInfoDisplay:setMissionInfo(missionInfo)
124 self.missionInfo = missionInfo
125end

setMissionStats

Description
Set the MissionStats reference for displaying information.
Definition
setMissionStats(table missionStats)
Arguments
tablemissionStatsMissionStats reference, do not change
Code
116function GameInfoDisplay:setMissionStats(missionStats)
117 self.missionStats = missionStats
118end

setMoneyUnit

Description
Set the money unit for displaying the account balance.
Definition
setMoneyUnit(int moneyUnit)
Arguments
intmoneyUnitMoney unit ID, any of [GS_MONEY_EURO | GS_MONEY_POUND | GS_MONEY_DOLLAR]. Invalid values are substituted by GS_MONEY_DOLLAR.
Code
104function GameInfoDisplay:setMoneyUnit(moneyUnit)
105 if moneyUnit ~= GS_MONEY_EURO and moneyUnit ~= GS_MONEY_POUND and moneyUnit ~= GS_MONEY_DOLLAR then
106 moneyUnit = GS_MONEY_DOLLAR
107 end
108
109 self.moneyUnit = moneyUnit
110 self.moneyCurrencyText = g_i18n:getCurrencySymbol(true)
111end

setMoneyVisible

Description
Set visibility of the money display.
Definition
setMoneyVisible()
Code
136function GameInfoDisplay:setMoneyVisible(isVisible)
137 self.showMoney = isVisible
138 self.moneyBox:setVisible(isVisible)
139 self:storeScaledValues()
140 self:updateSizeAndPositions()
141end

setScale

Description
Set this element's UI scale factor.
Definition
setScale(float uiScale)
Arguments
floatuiScaleUI scale factor
Code
561function GameInfoDisplay:setScale(uiScale)
562 GameInfoDisplay:superClass().setScale(self, uiScale, uiScale)
563 self:storeScaledValues()
564 self:updateSizeAndPositions()
565end

setTemperatureVisible

Description
Set visibility of temperature display.
Definition
setTemperatureVisible()
Code
154function GameInfoDisplay:setTemperatureVisible(isVisible)
155 self.showTemperature = isVisible
156 self.temperatureBox:setVisible(isVisible)
157 self:storeScaledValues()
158 self:updateSizeAndPositions()
159end

setTimeVisible

Description
Set visibility of time display.
Definition
setTimeVisible()
Code
145function GameInfoDisplay:setTimeVisible(isVisible)
146 self.showTime = isVisible
147 self.timeBox:setVisible(isVisible)
148 self:storeScaledValues()
149 self:updateSizeAndPositions()
150end

setTutorialProgress

Description
Set the current tutorial progress values.
Definition
setTutorialProgress(float progress)
Arguments
floatprogressProgress expressed as a number between 0 and 1
Code
189function GameInfoDisplay:setTutorialProgress(progress)
190 if self.showTutorialProgress and progress ~= self.lastTutorialProgress then
191 progress = MathUtil.clamp(progress, 0, 1)
192 self.lastTutorialProgress = progress
193 self.tutorialProgressBar:setDimension(self.tutorialBarWidth * progress)
194 end
195end

setTutorialVisible

Description
Set visibility of tutorial progress display.
Definition
setTutorialVisible()
Code
172function GameInfoDisplay:setTutorialVisible(isVisible)
173 self.showTutorialProgress = isVisible
174 self.tutorialBox:setVisible(isVisible)
175 self:storeScaledValues()
176 self:updateSizeAndPositions()
177end

setWeatherVisible

Description
Set visibility of weather display.
Definition
setWeatherVisible()
Code
163function GameInfoDisplay:setWeatherVisible(isVisible)
164 self.showWeather = isVisible
165 self.weatherBox:setVisible(isVisible)
166 self:storeScaledValues()
167 self:updateSizeAndPositions()
168end

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()
Code
569function GameInfoDisplay:storeScaledValues()
570 self.boxHeight = self:scalePixelToScreenHeight(GameInfoDisplay.BOX_HEIGHT)
571 self.boxMarginWidth, self.boxMarginHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.BOX_MARGIN)
572 self.moneyBoxWidth = self:scalePixelToScreenWidth(GameInfoDisplay.SIZE.MONEY_BOX[1])
573 self.moneyTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.MONEY)
574
575 local moneyBoxPosX, moneyBoxPosY = self.moneyBox:getPosition()
576 local textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.MONEY_TEXT)
577 self.moneyTextPositionX = moneyBoxPosX + self.moneyBox:getWidth() + textOffX
578 self.moneyTextPositionY = moneyBoxPosY + self.moneyBox:getHeight() * 0.5 - self.moneyTextSize * 0.5 + textOffY
579
580 local x, y = self.moneyIconOverlay:getPosition()
581 self.moneyCurrencyPositionX = self.moneyIconOverlay.width * 0.5 + x
582 self.moneyCurrencyPositionY = self.moneyIconOverlay.height * 0.5 + y - self.moneyTextSize * 0.5 + textOffY
583
584 local timeBoxPosX, timeBoxPosY = self.timeBox:getPosition()
585 local _, timeBoxHeight = self.timeBox:getWidth(), self.timeBox:getHeight()
586 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TIME_TEXT)
587 self.timeTextPositionX = timeBoxPosX + textOffX
588 self.timeTextPositionY = timeBoxPosY + timeBoxHeight * 0.5 + textOffY
589 self.timeTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.TIME)
590
591 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TIME_SCALE_TEXT)
592 self.timeScaleTextPositionX = timeBoxPosX + textOffX
593 self.timeScaleTextPositionY = timeBoxPosY + timeBoxHeight * 0.5 + textOffY
594 self.timeScaleTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.TIME_SCALE)
595
596 self.clockHandLargePivotX, self.clockHandLargePivotY = self:normalizeUVPivot(
597 GameInfoDisplay.PIVOT.CLOCK_HAND_LARGE,
598 GameInfoDisplay.SIZE.CLOCK_HAND_LARGE,
599 GameInfoDisplay.UV.CLOCK_HAND_LARGE)
600 self.clockHandSmallPivotX, self.clockHandSmallPivotY = self:normalizeUVPivot(
601 GameInfoDisplay.PIVOT.CLOCK_HAND_SMALL,
602 GameInfoDisplay.SIZE.CLOCK_HAND_SMALL,
603 GameInfoDisplay.UV.CLOCK_HAND_SMALL)
604
605 self.monthTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.MONTH)
606 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.MONTH_TEXT)
607 local dateBoxX, dateBoxY = self.dateBox:getPosition()
608 self.monthTextPositionX = dateBoxX + self.seasonOverlay.width + textOffX
609 self.monthTextPositionY = dateBoxY + textOffY + (self.dateBox:getHeight() - self.monthTextSize) * 0.5
610
611 self.temperatureTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.TEMPERATURE)
612 local tempBoxPosX, tempBoxPosY = self.temperatureBox:getPosition()
613 local tempBoxWidth, tempBoxHeight = self.temperatureBox:getWidth(), self.temperatureBox:getHeight()
614 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TEMPERATURE_HIGH)
615 self.temperatureHighTextPositionX = tempBoxPosX + tempBoxWidth + textOffX
616 self.temperatureHighTextPositionY = tempBoxPosY + tempBoxHeight * 0.5 + textOffY
617
618 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TEMPERATURE_LOW)
619 self.temperatureLowTextPositionX = tempBoxPosX + tempBoxWidth + textOffX
620 self.temperatureLowTextPositionY = tempBoxPosY + tempBoxHeight * 0.5 + textOffY
621
622 local tutorialBarX, tutorialBarY = self.tutorialProgressBar:getPosition()
623 self.tutorialBarWidth, self.tutorialBarHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TUTORIAL_PROGRESS_BAR)
624 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TUTORIAL_TEXT)
625 self.tutorialTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.TUTORIAL)
626 self.tutorialTextPositionX = tutorialBarX + textOffX
627 self.tutorialTextPositionY = tutorialBarY + (self.tutorialBarHeight - self.tutorialTextSize) * 0.5 + textOffY
628end

update

Description
Update the game info display state.
Definition
update()
Code
203function GameInfoDisplay:update(dt)
204 if self.showTime then
205 self:updateTime()
206 end
207
208 if self.showTemperature then
209 self:updateTemperature()
210 end
211
212 if self.showWeather then
213 self:updateWeather(dt)
214 end
215
216 self:updateBackground()
217end

updateSizeAndPositions

Description
Update sizes and positions of this elements and its children.
Definition
updateSizeAndPositions()
Code
327function GameInfoDisplay:updateSizeAndPositions()
328 local width = self:getVisibleWidth()
329 self:setDimension(width+g_safeFrameOffsetX, self:getHeight())
330
331 local topRightX, topRightY = GameInfoDisplay.getBackgroundPosition(self:getScale())
332 local bottomY = topRightY - self:getHeight()
333 self:setPosition(topRightX - width, bottomY)
334
335 -- update positions of info elements based on visibility
336 local posX = topRightX
337 local isRightMostBox = true
338 for i, box in ipairs(self.infoBoxes) do -- iterate in order, info boxes stored from right to left
339 if box:getVisible() then
340 local leftMargin = self.boxMarginWidth
341 local rightMargin = 0
342 if i > 1 then
343 rightMargin = self.boxMarginWidth
344 end
345
346 box:setPosition(posX - box:getWidth() - rightMargin, bottomY)
347 posX = posX - box:getWidth() - leftMargin - rightMargin
348
349 box.separator:setVisible(not isRightMostBox) -- all info boxes have their separators assigned as a field, see createComponents()
350 isRightMostBox = false
351 end
352 end
353
354 self:storeScaledValues()
355end

updateTemperature

Description
Update temperature display.
Definition
updateTemperature()
Code
256function GameInfoDisplay:updateTemperature()
257 local minTemp, maxTemp = self.environment.weather:getCurrentMinMaxTemperatures()
258 self.temperatureDayText = string.format("%d?", maxTemp)
259 self.temperatureNightText = string.format("%d?", minTemp)
260
261 local trend = self.environment.weather:getCurrentTemperatureTrend()
262 self.temperatureIconStable:setVisible(trend == 0)
263 self.temperatureIconRising:setVisible(trend > 0)
264 self.temperatureIconDropping:setVisible(trend < 0)
265end

updateTime

Description
Update time display.
Definition
updateTime()
Code
227function GameInfoDisplay:updateTime()
228 local currentTime = self.environment.dayTime / (1000 * 60 * 60)
229 local timeHours = math.floor(currentTime)
230 local timeMinutes = math.floor((currentTime - timeHours) * 60)
231
232 self.timeText = string.format("%02d:%02d", timeHours, timeMinutes)
233
234 if self.missionInfo.timeScale < 1 then
235 self.timeScaleText = string.format("%0.1f", self.missionInfo.timeScale)
236 else
237 self.timeScaleText = string.format("%d", self.missionInfo.timeScale)
238 end
239
240 self.monthText = g_i18n:formatDayInPeriod(nil, nil, true)
241 self.seasonOverlay:setUVs(self.seasonOverlayUVs[self.environment.currentSeason])
242
243 local hourRotation = -((currentTime % 12) / 12) * math.pi * 2
244 local minutesRotation = -(currentTime - timeHours) * math.pi * 2
245
246 self.clockHandSmall:setRotation(hourRotation)
247 self.clockHandLarge:setRotation(minutesRotation)
248
249 local isTimeScaleFast = self.missionInfo.timeScale > 1
250 self.timeScaleArrow:setVisible(not isTimeScaleFast)
251 self.timeScaleArrowFast:setVisible(isTimeScaleFast)
252end

updateWeather

Description
Update weather display
Definition
updateWeather()
Code
283function GameInfoDisplay:updateWeather(dt)
284 if not self.environment.weather:getIsReady() then
285 return
286 end
287
288 local weatherState, nextWeatherState = self:getWeatherStates()
289
290 weatherState = weatherState or WeatherType.SUN
291 nextWeatherState = nextWeatherState or WeatherType.SUN
292
293 local hasChange = self.currentWeather ~= weatherState or self.nextWeather ~= nextWeatherState
294 if hasChange then
295 self.currentWeather = weatherState
296 self.nextWeather = nextWeatherState
297
298 self:animateWeatherChange()
299 end
300
301 if not self.weatherAnimation:getFinished() then
302 self.weatherAnimation:update(dt)
303 end
304end