LUADOC - Farming Simulator 19

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
420function GameInfoDisplay:addActiveWeatherAnimation(animationSequence, isCurrentWeatherIcon, icon)
421 local fullColor = GameInfoDisplay.COLOR.ICON_WEATHER_NEXT
422 if isCurrentWeatherIcon then
423 fullColor = GameInfoDisplay.COLOR.ICON
424 end
425
426 local transparentColor = {fullColor[1], fullColor[2], fullColor[3], 0}
427 local fadeInSequence = TweenSequence.new(icon)
428 local fadeIn = MultiValueTween:new(icon.setColor, transparentColor, fullColor, HUDDisplayElement.MOVE_ANIMATION_DURATION)
429
430 fadeInSequence:insertTween(fadeIn, 0)
431 fadeInSequence:insertCallback(icon.setVisible, true, 0)
432
433 fadeInSequence:start()
434 animationSequence:insertTween(fadeInSequence, 0)
435end

addBecomeCurrentWeatherAnimation

Description
Animate a weather icon becoming the current weather icon.
Definition
addBecomeCurrentWeatherAnimation()
Code
454function GameInfoDisplay:addBecomeCurrentWeatherAnimation(animationSequence, icon)
455 local currentColor = {icon:getColor()}
456 local makeCurrent = MultiValueTween:new(icon.setColor, currentColor, GameInfoDisplay.COLOR.ICON, HUDDisplayElement.MOVE_ANIMATION_DURATION)
457 makeCurrent:setTarget(icon)
458 animationSequence:insertTween(makeCurrent, 0)
459end

addInactiveWeatherAnimation

Description
Animate a weather icon becoming inactive.
Definition
addInactiveWeatherAnimation()
Code
439function GameInfoDisplay:addInactiveWeatherAnimation(animationSequence, icon)
440 local currentColor = {icon:getColor()}
441 local transparentColor = {currentColor[1], currentColor[2], currentColor[3], 0}
442 local fadeOutSequence = TweenSequence.new(icon)
443 local fadeOut = MultiValueTween:new(icon.setColor, currentColor, transparentColor, HUDDisplayElement.MOVE_ANIMATION_DURATION)
444
445 fadeOutSequence:insertTween(fadeOut, 0)
446 fadeOutSequence:addCallback(icon.setVisible, false)
447
448 fadeOutSequence:start()
449 animationSequence:insertTween(fadeOutSequence, 0)
450end

addWeatherPositionAnimation

Description
Animate weather icon position changes.
Definition
addWeatherPositionAnimation()
Code
463function GameInfoDisplay:addWeatherPositionAnimation(animationSequence, isWeatherChanging)
464 local icon = self.weatherTypeIcons[self.currentWeather]
465 local boxPosX, boxPosY = self.weatherBox:getPosition()
466 local centerX, centerY = boxPosX + self.weatherBox:getWidth() * 0.5, boxPosY + (self.weatherBox:getHeight() - icon:getHeight()) * 0.5
467
468 if isWeatherChanging then
469 local moveLeft = MultiValueTween:new(icon.setPosition, {icon:getPosition()}, {centerX - icon:getWidth(), centerY}, HUDDisplayElement.MOVE_ANIMATION_DURATION)
470 moveLeft:setTarget(icon)
471 animationSequence:insertTween(moveLeft, 0)
472
473 local secondIcon = self.weatherTypeIcons[self.nextWeather]
474 if secondIcon:getVisible() then
475 local moveRight = MultiValueTween:new(secondIcon.setPosition, {secondIcon:getPosition()}, {centerX, centerY}, HUDDisplayElement.MOVE_ANIMATION_DURATION)
476 moveRight:setTarget(secondIcon)
477 animationSequence:insertTween(moveRight, 0)
478 else
479 secondIcon:setPosition(centerX, centerY)
480 end
481 else
482 local iconPosX, iconPosY = icon:getPosition()
483 if iconPosX ~= centerX or iconPosY ~= centerY and self.weatherAnimation:getFinished() then
484 local move = MultiValueTween:new(icon.setPosition, {icon:getPosition()}, {centerX, centerY}, HUDDisplayElement.MOVE_ANIMATION_DURATION)
485 move:setTarget(icon)
486 animationSequence:insertTween(move, 0)
487 end
488 end
489end

animateWeatherChange

Description
Make an animation for a weather change.
Definition
animateWeatherChange()
Code
394function GameInfoDisplay:animateWeatherChange()
395 local sequence = TweenSequence.new()
396
397 for weatherType, icon in pairs(self.weatherTypeIcons) do
398 local isCurrent = weatherType == self.currentWeather
399 local isNext = weatherType == self.nextWeather
400 local makeVisible = isCurrent or isNext
401
402 if makeVisible and not icon:getVisible() then
403 self:addActiveWeatherAnimation(sequence, isCurrent, icon)
404 elseif not makeVisible and icon:getVisible() then
405 self:addInactiveWeatherAnimation(sequence, icon)
406 else
407 self:addBecomeCurrentWeatherAnimation(sequence, icon)
408 end
409 end
410
411 local isWeatherChanging = self.currentWeather ~= self.nextWeather
412 self:addWeatherPositionAnimation(sequence, isWeatherChanging)
413
414 sequence:start()
415 self.weatherAnimation = sequence
416end

createBackground

Description
Create the background overlay.
Definition
createBackground()
Code
575function GameInfoDisplay.createBackground()
576 local posX, posY = GameInfoDisplay.getBackgroundPosition(1) -- top right corner
577 local width, height = getNormalizedScreenValues(unpack(GameInfoDisplay.SIZE.SELF))
578 return Overlay:new(nil, posX - width, posY - height, width, height)
579end

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
811function GameInfoDisplay:createClockHand(hudAtlasPath, posX, posY, size, uvs, color, pivot)
812 local pivotX, pivotY = self:normalizeUVPivot(pivot, size, uvs)
813 local width, height = self:scalePixelToScreenVector(size)
814 local clockHandOverlay = Overlay:new(hudAtlasPath, posX - pivotX, posY - pivotY, width, height)
815 clockHandOverlay:setUVs(getNormalizedUVs(uvs))
816 clockHandOverlay:setColor(unpack(color))
817
818 local clockHandElement = HUDElement:new(clockHandOverlay)
819 clockHandElement:setRotationPivot(pivotX, pivotY)
820
821 return clockHandElement
822end

createComponents

Description
Create required display components. Also adds a separator HUDElement instance as a field (".separator") to all info boxes.
Definition
createComponents()
Code
584function GameInfoDisplay:createComponents(hudAtlasPath)
585 local topRightX, topRightY = GameInfoDisplay.getBackgroundPosition(1)
586 local bottomY = topRightY - self:getHeight()
587 local marginWidth, marginHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.BOX_MARGIN)
588
589 -- create components from right to left
590 local rightX = self:createMoneyBox(hudAtlasPath, topRightX, bottomY) - marginWidth
591 self.moneyBox.separator = {setVisible=function() end} -- just use a dummy for the money box
592 local sepX = rightX
593 rightX = self:createTimeBox(hudAtlasPath, rightX - marginWidth, bottomY) - marginWidth
594
595 local centerY = bottomY + self:getHeight() * 0.5
596 local separator = self:createVerticalSeparator(hudAtlasPath, sepX, centerY)
597 self.timeBox:addChild(separator)
598 self.timeBox.separator = separator
599
600 sepX = rightX
601 rightX = self:createTemperatureBox(hudAtlasPath, rightX - marginWidth, bottomY) - marginWidth
602
603 separator = self:createVerticalSeparator(hudAtlasPath, sepX, centerY)
604 self.temperatureBox:addChild(separator)
605 self.temperatureBox.separator = separator
606
607 sepX = rightX
608 rightX = self:createWeatherBox(hudAtlasPath, rightX - marginWidth, bottomY) - marginWidth
609
610 separator = self:createVerticalSeparator(hudAtlasPath, sepX, centerY)
611 self.weatherBox:addChild(separator)
612 self.weatherBox.separator = separator
613
614 sepX = rightX
615 rightX = self:createTutorialBox(hudAtlasPath, rightX - marginWidth, bottomY) - marginWidth
616
617 separator = self:createVerticalSeparator(hudAtlasPath, sepX, centerY)
618 self.tutorialBox:addChild(separator)
619 self.tutorialBox.separator = separator
620
621 -- update background size based on components:
622 local width = self:getVisibleWidth()
623 self:setDimension(width, self:getHeight())
624end

createMoneyBox

Description
Create the money display box.
Definition
createMoneyBox()
Code
628function GameInfoDisplay:createMoneyBox(hudAtlasPath, rightX, bottomY)
629 local iconWidth, iconHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.MONEY_ICON)
630 local boxWidth, boxHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.MONEY_BOX)
631 local posX = rightX - boxWidth
632 local posY = bottomY + (boxHeight - iconHeight) * 0.5
633
634 local boxOverlay = Overlay:new(nil, posX, bottomY, boxWidth, boxHeight)
635 local boxElement = HUDElement:new(boxOverlay)
636 self.moneyBox = boxElement
637 self:addChild(boxElement)
638 table.insert(self.infoBoxes, self.moneyBox)
639
640 local iconOverlay = Overlay:new(hudAtlasPath, posX, posY, iconWidth, iconHeight)
641 iconOverlay:setUVs(getNormalizedUVs(GameInfoDisplay.UV.MONEY_ICON[self.moneyUnit]))
642 iconOverlay:setColor(unpack(GameInfoDisplay.COLOR.ICON))
643
644 self.moneyIconOverlay = iconOverlay
645 boxElement:addChild(HUDElement:new(iconOverlay))
646
647 return posX
648end

createTemperatureBox

Description
Create the temperature display box.
Definition
createTemperatureBox()
Code
705function GameInfoDisplay:createTemperatureBox(hudAtlasPath, rightX, bottomY)
706 local boxWidth, boxHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TEMPERATURE_BOX)
707 local posX = rightX - boxWidth
708
709 local boxOverlay = Overlay:new(nil, posX, bottomY, boxWidth, boxHeight)
710 local boxElement = HUDElement:new(boxOverlay)
711 self.temperatureBox = boxElement
712 self:addChild(boxElement)
713 table.insert(self.infoBoxes, self.temperatureBox)
714
715 self.temperatureIconStable = self:createTemperatureIcon(hudAtlasPath, posX, bottomY, boxHeight,
716 GameInfoDisplay.UV.TEMPERATURE_ICON_STABLE, GameInfoDisplay.COLOR.ICON)
717 boxElement:addChild(self.temperatureIconStable)
718
719 self.temperatureIconRising = self:createTemperatureIcon(hudAtlasPath, posX, bottomY, boxHeight,
720 GameInfoDisplay.UV.TEMPERATURE_ICON_RISING, GameInfoDisplay.COLOR.ICON)
721 boxElement:addChild(self.temperatureIconRising)
722
723 self.temperatureIconDropping = self:createTemperatureIcon(hudAtlasPath, posX, bottomY, boxHeight,
724 GameInfoDisplay.UV.TEMPERATURE_ICON_DROPPING, GameInfoDisplay.COLOR.ICON)
725 boxElement:addChild(self.temperatureIconDropping)
726
727 return rightX - boxWidth
728end

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
791function GameInfoDisplay:createTemperatureIcon(hudAtlasPath, leftX, bottomY, boxHeight, uvs, color)
792 local iconWidth, iconHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TEMPERATURE_ICON)
793 local posY = bottomY + (boxHeight - iconHeight) * 0.5
794 local overlay = Overlay:new(hudAtlasPath, leftX, posY, iconWidth, iconHeight)
795 overlay:setUVs(getNormalizedUVs(uvs))
796 overlay:setColor(unpack(color))
797
798 return HUDElement:new(overlay)
799end

createTimeBox

Description
Create the time display box.
Definition
createTimeBox()
Code
652function GameInfoDisplay:createTimeBox(hudAtlasPath, rightX, bottomY)
653 local boxWidth, boxHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TIME_BOX)
654 local posX = rightX - boxWidth
655
656 local boxOverlay = Overlay:new(nil, posX, bottomY, boxWidth, boxHeight)
657 local boxElement = HUDElement:new(boxOverlay)
658 self.timeBox = boxElement
659 self:addChild(boxElement)
660 table.insert(self.infoBoxes, self.timeBox)
661
662 local clockWidth, clockHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TIME_ICON)
663 local posY = bottomY + (boxHeight - clockHeight) * 0.5
664 local clockOverlay = Overlay:new(hudAtlasPath, posX, posY, clockWidth, clockHeight)
665 clockOverlay:setUVs(getNormalizedUVs(GameInfoDisplay.UV.TIME_ICON))
666 clockOverlay:setColor(unpack(GameInfoDisplay.COLOR.ICON))
667 local clockElement = HUDElement:new(clockOverlay)
668 self.clockElement = clockElement
669 boxElement:addChild(clockElement)
670
671 posX, posY = posX + clockWidth * 0.5, posY + clockHeight * 0.5
672
673 self.clockHandSmall = self:createClockHand(hudAtlasPath, posX, posY,
674 GameInfoDisplay.SIZE.CLOCK_HAND_SMALL,
675 GameInfoDisplay.UV.CLOCK_HAND_SMALL,
676 GameInfoDisplay.COLOR.CLOCK_HAND_SMALL,
677 GameInfoDisplay.PIVOT.CLOCK_HAND_SMALL)
678 clockElement:addChild(self.clockHandSmall)
679
680 self.clockHandLarge = self:createClockHand(hudAtlasPath, posX, posY,
681 GameInfoDisplay.SIZE.CLOCK_HAND_LARGE,
682 GameInfoDisplay.UV.CLOCK_HAND_LARGE,
683 GameInfoDisplay.COLOR.CLOCK_HAND_LARGE,
684 GameInfoDisplay.PIVOT.CLOCK_HAND_LARGE)
685 clockElement:addChild(self.clockHandLarge)
686
687 local arrowOffX, arrowOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TIME_SCALE_ARROW)
688 posX, posY = rightX + arrowOffX, bottomY + arrowOffY
689
690 self.timeScaleArrow = self:createTimeScaleArrow(hudAtlasPath, posX, posY,
691 GameInfoDisplay.SIZE.TIME_SCALE_ARROW,
692 GameInfoDisplay.UV.TIME_SCALE_ARROW)
693 boxElement:addChild(self.timeScaleArrow)
694
695 self.timeScaleArrowFast = self:createTimeScaleArrow(hudAtlasPath, posX, posY,
696 GameInfoDisplay.SIZE.TIME_SCALE_ARROW_FAST,
697 GameInfoDisplay.UV.TIME_SCALE_ARROW_FAST)
698 boxElement:addChild(self.timeScaleArrowFast)
699
700 return rightX - boxWidth
701end

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
832function GameInfoDisplay:createTimeScaleArrow(hudAtlasPath, posX, posY, size, uvs)
833 local arrowWidth, arrowHeight = self:scalePixelToScreenVector(size)
834 local arrowOverlay = Overlay:new(hudAtlasPath, posX, posY, arrowWidth, arrowHeight)
835 arrowOverlay:setUVs(getNormalizedUVs(uvs))
836 arrowOverlay:setColor(unpack(GameInfoDisplay.COLOR.ICON))
837 return HUDElement:new(arrowOverlay)
838end

createTutorialBox

Description
Create the tutorial progress box.
Definition
createTutorialBox()
Code
855function GameInfoDisplay:createTutorialBox(hudAtlasPath, rightX, bottomY)
856 local boxWidth, boxHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TUTORIAL_BOX)
857 local posX = rightX - boxWidth
858 local boxOverlay = Overlay:new(nil, posX, bottomY, boxWidth, boxHeight)
859 local boxElement = HUDElement:new(boxOverlay)
860 self.tutorialBox = boxElement
861 self:addChild(boxElement)
862 table.insert(self.infoBoxes, self.tutorialBox)
863
864 -- create progress bar background frame
865 local offX, offY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TUTORIAL_PROGRESS_BAR)
866 local barWidth, barHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TUTORIAL_PROGRESS_BAR)
867 local barPosX, barPosY = rightX - barWidth + offX, bottomY + (boxHeight - barHeight) * 0.5 + offY
868
869 local pixelX, pixelY = 1 / g_screenWidth, 1 / g_screenHeight
870 local topLine = Overlay:new(hudAtlasPath, barPosX - pixelX, barPosY + barHeight, barWidth + pixelX * 2, pixelY)
871 local bottomLine = Overlay:new(hudAtlasPath, barPosX - pixelX, barPosY - pixelY, barWidth + pixelX * 2, pixelY)
872 local leftLine = Overlay:new(hudAtlasPath, barPosX - pixelX, barPosY, pixelX, barHeight)
873 local rightLine = Overlay:new(hudAtlasPath, barPosX + barWidth, barPosY, pixelX, barHeight)
874
875 for _, lineOverlay in pairs{topLine, bottomLine, leftLine, rightLine} do
876 lineOverlay:setUVs(getNormalizedUVs(GameInfoDisplay.UV.SEPARATOR))
877 lineOverlay:setColor(unpack(GameInfoDisplay.COLOR.SEPARATOR))
878 local lineElement = HUDElement:new(lineOverlay)
879 self.tutorialBox:addChild(lineElement)
880 end
881
882 -- create progress bar scalable overlay
883 local barOverlay = Overlay:new(hudAtlasPath, barPosX, barPosY, barWidth, barHeight)
884 barOverlay:setUVs(getNormalizedUVs(GameInfoDisplay.UV.SEPARATOR))
885 barOverlay:setColor(unpack(GameInfoDisplay.COLOR.TUTORIAL_PROGRESS_BAR))
886 local barElement = HUDElement:new(barOverlay)
887 self.tutorialBox:addChild(barElement)
888 self.tutorialProgressBar = barElement
889
890 return rightX - boxWidth
891end

createVerticalSeparator

Description
Create and return a vertical separator element.
Definition
createVerticalSeparator()
Code
842function GameInfoDisplay:createVerticalSeparator(hudAtlasPath, posX, centerPosY)
843 local width, height = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.SEPARATOR)
844 width = math.max(width, 1 / g_screenWidth)
845
846 local overlay = Overlay:new(hudAtlasPath, posX - width * 0.5, centerPosY - height * 0.5, width, height)
847 overlay:setUVs(getNormalizedUVs(GameInfoDisplay.UV.SEPARATOR))
848 overlay:setColor(unpack(GameInfoDisplay.COLOR.SEPARATOR))
849
850 return HUDElement:new(overlay)
851end

createWeatherBox

Description
Create the weather display box.
Definition
createWeatherBox()
Code
732function GameInfoDisplay:createWeatherBox(hudAtlasPath, rightX, bottomY)
733 local boxWidth, boxHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.WEATHER_BOX)
734 local posX = rightX - boxWidth
735 local boxOverlay = Overlay:new(nil, posX, bottomY, boxWidth, boxHeight)
736 local boxElement = HUDElement:new(boxOverlay)
737 self.weatherBox = boxElement
738 self:addChild(boxElement)
739 table.insert(self.infoBoxes, self.weatherBox)
740
741 -- Use function so new weather types can be added
742 local weatherUvs = self:getWeatherUVs()
743
744 for weatherId, uvs in pairs(weatherUvs) do
745 local weatherIcon = self:createWeatherIcon(hudAtlasPath, weatherId, boxHeight, uvs, GameInfoDisplay.COLOR.ICON)
746 boxElement:addChild(weatherIcon)
747 self.weatherTypeIcons[weatherId] = weatherIcon
748 end
749
750 return rightX - boxWidth
751end

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
771function GameInfoDisplay:createWeatherIcon(hudAtlasPath, weatherId, boxHeight, uvs, color)
772 local width, height = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.WEATHER_ICON)
773 local overlay = Overlay:new(hudAtlasPath, 0, 0, width, height) -- position is set on update
774 overlay:setUVs(getNormalizedUVs(uvs))
775
776 local element = HUDElement:new(overlay)
777 element:setVisible(false)
778
779 return element
780end

draw

Description
Draw the game info display.
Definition
draw()
Code
324function GameInfoDisplay:draw()
325 GameInfoDisplay:superClass().draw(self)
326
327 if self.showMoney then
328 self:drawMoneyText()
329 end
330
331 if self.showTime then
332 self:drawTimeText()
333 end
334
335 if self.showTemperature then
336 self:drawTemperatureText()
337 end
338
339 if self.showTutorialProgress then
340 self:drawTutorialText()
341 end
342end

drawMoneyText

Description
Draw the text part of the money display.
Definition
drawMoneyText()
Code
346function GameInfoDisplay:drawMoneyText()
347 setTextBold(false)
348 setTextAlignment(RenderText.ALIGN_RIGHT)
349 setTextColor(unpack(GameInfoDisplay.COLOR.TEXT))
350
351 -- TODO(SR): Optimize?
352 if g_currentMission.player ~= nil then
353 local farm = g_farmManager:getFarmById(g_currentMission.player.farmId)
354
355 local moneyText = g_i18n:formatMoney(farm.money, 0, false, true)
356 renderText(self.moneyTextPositionX, self.moneyTextPositionY, self.moneyTextSize, moneyText)
357 end
358end

drawTemperatureText

Description
Draw the text part of the temperature display.
Definition
drawTemperatureText()
Code
373function GameInfoDisplay:drawTemperatureText()
374 setTextBold(false)
375 setTextAlignment(RenderText.ALIGN_RIGHT)
376 setTextColor(unpack(GameInfoDisplay.COLOR.TEXT))
377
378 renderText(self.temperatureHighTextPositionX, self.temperatureHighTextPositionY, self.temperatureTextSize, self.temperatureDayText)
379 renderText(self.temperatureLowTextPositionX, self.temperatureLowTextPositionY, self.temperatureTextSize, self.temperatureNightText)
380end

drawTimeText

Description
Draw the text part of the time display.
Definition
drawTimeText()
Code
362function GameInfoDisplay:drawTimeText()
363 setTextBold(false)
364 setTextAlignment(RenderText.ALIGN_RIGHT)
365 setTextColor(unpack(GameInfoDisplay.COLOR.TEXT))
366
367 renderText(self.timeTextPositionX, self.timeTextPositionY, self.timeTextSize, self.timeText)
368 renderText(self.timeScaleTextPositionX, self.timeScaleTextPositionY, self.timeScaleTextSize, self.timeScaleText)
369end

drawTutorialText

Description
Draw the text part of the tutorial progress display.
Definition
drawTutorialText()
Code
384function GameInfoDisplay:drawTutorialText()
385 setTextBold(true)
386 setTextAlignment(RenderText.ALIGN_RIGHT)
387 setTextColor(unpack(GameInfoDisplay.COLOR.TEXT))
388
389 renderText(self.tutorialTextPositionX, self.tutorialTextPositionY, self.tutorialTextSize, self.tutorialText)
390end

getBackgroundPosition

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

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
275function GameInfoDisplay:getVisibleWidth()
276 local width = -self.boxMarginWidth -- money box has no right margin
277 for _, box in pairs(self.infoBoxes) do
278 if box:getVisible() then
279 width = width + box:getWidth() + self.boxMarginWidth * 2
280 end
281 end
282
283 return width
284end

getWeatherStates

Description
Definition
getWeatherStates()
Code
238function GameInfoDisplay:getWeatherStates()
239 local sixHours = 6 * 60 * 60 * 1000
240 local env = self.environment
241
242 local dayPlus6h, timePlus6h = env:getDayAndDayTime(env.dayTime + sixHours, env.currentDay)
243
244 local weatherState = env.weather:getWeatherTypeAtTime(env.currentDay, env.dayTime)
245 local nextWeatherState = env.weather:getWeatherTypeAtTime(dayPlus6h, timePlus6h)
246
247 return weatherState, nextWeatherState
248end

getWeatherUVs

Description
Get UVs of the icons associated with the weather types
Definition
getWeatherUVs()
Code
755function GameInfoDisplay:getWeatherUVs()
756 return { -- weather type and UV definition for iteration
757 [WeatherType.SUN] = GameInfoDisplay.UV.WEATHER_ICON_CLEAR,
758 [WeatherType.RAIN] = GameInfoDisplay.UV.WEATHER_ICON_RAIN,
759 [WeatherType.CLOUDY] = GameInfoDisplay.UV.WEATHER_ICON_CLOUDY
760 }
761end

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(GameInfoDisplay_mt, backgroundOverlay, nil)
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.showTutorialProgress = false
32
33 self.infoBoxes = {} -- array of created info boxes
34
35 self.moneyBox = nil
36 self.moneyIconOverlay = nil -- Overlay reference of money icon to swap money unit texture UVs when necessary
37
38 self.timeBox = nil
39 self.clockElement = nil
40 self.timeScaleArrow = nil
41 self.timeScaleArrowFast = nil
42 self.clockHandLarge = nil
43 self.clockHandSmall = nil
44
45 self.temperatureBox = nil
46 self.temperatureIconStable = nil
47 self.temperatureIconRising = nil
48 self.temperatureIconDropping = nil
49
50 self.weatherBox = nil
51 self.weatherTypeIcons = {} -- weather type -> HUDElement
52
53 self.tutorialBox = nil
54 self.tutorialProgressBar = nil
55
56 self.boxHeight = 0
57 self.boxMarginWidth, self.boxMarginHeight = 0, 0
58
59 self.moneyBoxWidth = 0
60 self.moneyTextSize = 0
61 self.moneyTextPositionX, self.moneyTextPositionY = 0, 0
62
63 self.timeTextPositionX, self.timeTextPositionY = 0,0
64 self.timeTextSize = 0
65 self.timeScaleTextPositionX, self.timeScaleTextPositionY = 0, 0
66 self.timeScaleTextSize = 0
67 self.timeText = ""
68 self.clockHandLargePivotX, self.clockHandLargePivotY = 0, 0
69 self.clockHandSmallPivotX, self.clockHandSmallPivotY = 0, 0
70
71 self.temperatureHighTextPositionX, self.temperatureHighTextPositionY = 0, 0
72 self.temperatureLowTextPositionX, self.temperatureLowTextPositionY = 0, 0
73 self.temperatureTextSize = 0
74 self.temperatureDayText = ""
75 self.temperatureNightText = ""
76
77 self.tutorialBarWidth, self.tutorialBarHeight = 0, 0
78 self.tutorialTextPositionX, self.tutorialTextPositionX = 0, 0
79 self.tutorialTextSize = 0
80 self.tutorialText = utf8ToUpper(l10n:getText(GameInfoDisplay.L10N_SYMBOL.TUTORIAL))
81
82 self.weatherAnimation = TweenSequence.NO_SEQUENCE
83 self.currentWeather = ""
84 self.nextWeather = ""
85 self.temperatureAnimation = TweenSequence.NO_SEQUENCE
86 self.lastTutorialProgress = 1
87
88 self:createComponents(hudAtlasPath)
89
90 return self
91end

setEnvironment

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

setMissionInfo

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

setMissionStats

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

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
96function GameInfoDisplay:setMoneyUnit(moneyUnit)
97 if moneyUnit ~= GS_MONEY_EURO and moneyUnit ~= GS_MONEY_POUND and moneyUnit ~= GS_MONEY_DOLLAR then
98 moneyUnit = GS_MONEY_DOLLAR
99 end
100
101 self.moneyUnit = moneyUnit
102 self.moneyIconOverlay:setUVs(getNormalizedUVs(GameInfoDisplay.UV.MONEY_ICON[moneyUnit]))
103end

setMoneyVisible

Description
Set visibility of the money display.
Definition
setMoneyVisible()
Code
128function GameInfoDisplay:setMoneyVisible(isVisible)
129 self.showMoney = isVisible
130 self.moneyBox:setVisible(isVisible)
131 self:storeScaledValues()
132 self:updateSizeAndPositions()
133end

setScale

Description
Set this element's UI scale factor.
Definition
setScale(float uiScale)
Arguments
floatuiScaleUI scale factor
Code
506function GameInfoDisplay:setScale(uiScale)
507 GameInfoDisplay:superClass().setScale(self, uiScale, uiScale)
508 self:storeScaledValues()
509 self:updateSizeAndPositions()
510end

setTemperatureVisible

Description
Set visibility of temperature display.
Definition
setTemperatureVisible()
Code
146function GameInfoDisplay:setTemperatureVisible(isVisible)
147 self.showTemperature = isVisible
148 self.temperatureBox:setVisible(isVisible)
149 self:storeScaledValues()
150 self:updateSizeAndPositions()
151end

setTimeVisible

Description
Set visibility of time display.
Definition
setTimeVisible()
Code
137function GameInfoDisplay:setTimeVisible(isVisible)
138 self.showTime = isVisible
139 self.timeBox:setVisible(isVisible)
140 self:storeScaledValues()
141 self:updateSizeAndPositions()
142end

setTutorialProgress

Description
Set the current tutorial progress values.
Definition
setTutorialProgress(float progress)
Arguments
floatprogressProgress expressed as a number between 0 and 1
Code
174function GameInfoDisplay:setTutorialProgress(progress)
175 if self.showTutorialProgress and progress ~= self.lastTutorialProgress then
176 progress = MathUtil.clamp(progress, 0, 1)
177 self.lastTutorialProgress = progress
178 self.tutorialProgressBar:setDimension(self.tutorialBarWidth * progress)
179 end
180end

setTutorialVisible

Description
Set visibility of tutorial progress display.
Definition
setTutorialVisible()
Code
164function GameInfoDisplay:setTutorialVisible(isVisible)
165 self.showTutorialProgress = isVisible
166 self.tutorialBox:setVisible(isVisible)
167 self:storeScaledValues()
168 self:updateSizeAndPositions()
169end

setWeatherVisible

Description
Set visibility of weather display.
Definition
setWeatherVisible()
Code
155function GameInfoDisplay:setWeatherVisible(isVisible)
156 self.showWeather = isVisible
157 self.weatherBox:setVisible(isVisible)
158 self:storeScaledValues()
159 self:updateSizeAndPositions()
160end

storeScaledValues

Description
Store scaled positioning, size and offset values.
Definition
storeScaledValues()
Code
514function GameInfoDisplay:storeScaledValues()
515 local baseX, baseY = self:getPosition()
516 local width, height = self:getWidth(), self:getHeight()
517 local rightX, bottomY = baseX + width, baseY - height
518
519 self.boxHeight = self:scalePixelToScreenHeight(GameInfoDisplay.BOX_HEIGHT)
520 self.boxMarginWidth, self.boxMarginHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.BOX_MARGIN)
521 self.moneyBoxWidth = self:scalePixelToScreenWidth(GameInfoDisplay.SIZE.MONEY_BOX[1])
522 self.moneyTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.MONEY)
523
524 local moneyBoxPosX, moneyBoxPosY = self.moneyBox:getPosition()
525 local textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.MONEY_TEXT)
526 self.moneyTextPositionX = moneyBoxPosX + self.moneyBox:getWidth() + textOffX
527 self.moneyTextPositionY = moneyBoxPosY + self.moneyBox:getHeight() * 0.5 + textOffY
528
529 local timeBoxPosX, timeBoxPosY = self.timeBox:getPosition()
530 local timeBoxWidth, timeBoxHeight = self.timeBox:getWidth(), self.timeBox:getHeight()
531 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TIME_TEXT)
532 self.timeTextPositionX = timeBoxPosX + timeBoxWidth + textOffX
533 self.timeTextPositionY = timeBoxPosY + textOffY
534 self.timeTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.TIME)
535
536 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TIME_SCALE_TEXT)
537 self.timeScaleTextPositionX = timeBoxPosX + timeBoxWidth + textOffX
538 self.timeScaleTextPositionY = timeBoxPosY + textOffY
539 self.timeScaleTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.TIME_SCALE)
540
541 self.clockHandLargePivotX, self.clockHandLargePivotY = self:normalizeUVPivot(
542 GameInfoDisplay.PIVOT.CLOCK_HAND_LARGE,
543 GameInfoDisplay.SIZE.CLOCK_HAND_LARGE,
544 GameInfoDisplay.UV.CLOCK_HAND_LARGE)
545 self.clockHandSmallPivotX, self.clockHandSmallPivotY = self:normalizeUVPivot(
546 GameInfoDisplay.PIVOT.CLOCK_HAND_SMALL,
547 GameInfoDisplay.SIZE.CLOCK_HAND_SMALL,
548 GameInfoDisplay.UV.CLOCK_HAND_SMALL)
549
550 self.temperatureTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.TEMPERATURE)
551 local tempBoxPosX, tempBoxPosY = self.temperatureBox:getPosition()
552 local tempBoxWidth, tempBoxHeight = self.temperatureBox:getWidth(), self.temperatureBox:getHeight()
553 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TEMPERATURE_HIGH)
554 self.temperatureHighTextPositionX = tempBoxPosX + tempBoxWidth + textOffX
555 self.temperatureHighTextPositionY = tempBoxPosY + tempBoxHeight * 0.5 + textOffY
556
557 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TEMPERATURE_LOW)
558 self.temperatureLowTextPositionX = tempBoxPosX + tempBoxWidth + textOffX
559 self.temperatureLowTextPositionY = tempBoxPosY + tempBoxHeight * 0.5 + textOffY
560
561 local tutorialBarX, tutorialBarY = self.tutorialProgressBar:getPosition()
562 self.tutorialBarWidth, self.tutorialBarHeight = self:scalePixelToScreenVector(GameInfoDisplay.SIZE.TUTORIAL_PROGRESS_BAR)
563 textOffX, textOffY = self:scalePixelToScreenVector(GameInfoDisplay.POSITION.TUTORIAL_TEXT)
564 self.tutorialTextSize = self:scalePixelToScreenHeight(GameInfoDisplay.TEXT_SIZE.TUTORIAL)
565 self.tutorialTextPositionX = tutorialBarX + textOffX
566 self.tutorialTextPositionY = tutorialBarY + (self.tutorialBarHeight - self.tutorialTextSize) * 0.5 + textOffY
567end

update

Description
Update the game info display state.
Definition
update()
Code
188function GameInfoDisplay:update(dt)
189 if self.showTime then
190 self:updateTime()
191 end
192
193 if self.showTemperature then
194 self:updateTemperature()
195 end
196
197 if self.showWeather then
198 self:updateWeather(dt)
199 end
200end

updateSizeAndPositions

Description
Update sizes and positions of this elements and its children.
Definition
updateSizeAndPositions()
Code
288function GameInfoDisplay:updateSizeAndPositions()
289 local width = self:getVisibleWidth()
290 self:setDimension(width, self:getHeight())
291
292 local topRightX, topRightY = GameInfoDisplay.getBackgroundPosition(self:getScale())
293 local bottomY = topRightY - self:getHeight()
294 self:setPosition(topRightX - width, bottomY)
295
296 -- update positions of info elements based on visibility
297 local posX = topRightX
298 local isRightMostBox = true
299 for i, box in ipairs(self.infoBoxes) do -- iterate in order, info boxes stored from right to left
300 if box:getVisible() then
301 local leftMargin = self.boxMarginWidth
302 local rightMargin = 0
303 if i > 1 then
304 rightMargin = self.boxMarginWidth
305 end
306
307 box:setPosition(posX - box:getWidth() - rightMargin, bottomY)
308 posX = posX - box:getWidth() - leftMargin - rightMargin
309
310 box.separator:setVisible(not isRightMostBox) -- all info boxes have their separators assigned as a field, see createComponents()
311 isRightMostBox = false
312 end
313 end
314
315 self:storeScaledValues()
316end

updateTemperature

Description
Update temperature display.
Definition
updateTemperature()
Code
225function GameInfoDisplay:updateTemperature()
226 local minTemp, maxTemp = self.environment.weather:getCurrentMinMaxTemperatures()
227 self.temperatureDayText = string.format("%d?", maxTemp)
228 self.temperatureNightText = string.format("%d?", minTemp)
229
230 local trend = self.environment.weather:getCurrentTemperatureTrend()
231 self.temperatureIconStable:setVisible(trend == 0)
232 self.temperatureIconRising:setVisible(trend > 0)
233 self.temperatureIconDropping:setVisible(trend < 0)
234end

updateTime

Description
Update time display.
Definition
updateTime()
Code
204function GameInfoDisplay:updateTime()
205 local currentTime = self.environment.dayTime / (1000 * 60 * 60)
206 local timeHours = math.floor(currentTime)
207 local timeMinutes = math.floor((currentTime - timeHours) * 60)
208
209 self.timeText = string.format("%02d:%02d", timeHours, timeMinutes)
210 self.timeScaleText = string.format("%d", self.missionInfo.timeScale)
211
212 local hourRotation = -((currentTime % 12) / 12) * math.pi * 2
213 local minutesRotation = -(currentTime - timeHours) * math.pi * 2
214
215 self.clockHandSmall:setRotation(hourRotation)
216 self.clockHandLarge:setRotation(minutesRotation)
217
218 local isTimeScaleFast = self.missionInfo.timeScale > 1
219 self.timeScaleArrow:setVisible(not isTimeScaleFast)
220 self.timeScaleArrowFast:setVisible(isTimeScaleFast)
221end

updateWeather

Description
Update weather display
Definition
updateWeather()
Code
252function GameInfoDisplay:updateWeather(dt)
253 local weatherState, nextWeatherState = self:getWeatherStates()
254 local weatherChanging = weatherState ~= nextWeatherState
255
256 weatherState = weatherState or WeatherType.SUN
257 nextWeatherState = nextWeatherState or WeatherType.SUN
258
259 local hasChange = self.currentWeather ~= weatherState or self.nextWeather ~= nextWeatherState
260 if hasChange then
261 self.currentWeather = weatherState
262 self.nextWeather = nextWeatherState
263
264 self:animateWeatherChange()
265 end
266
267 if not self.weatherAnimation:getFinished() then
268 self.weatherAnimation:update(dt)
269 end
270end