475 | function 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) |
490 | end |
518 | function 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 |
544 | end |
449 | function 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 |
471 | end |
943 | function 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 |
954 | end |
664 | function 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()) |
714 | end |
718 | function 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 |
740 | end |
834 | function 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 |
857 | end |
744 | function 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 |
793 | end |
987 | function 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 |
1023 | end |
861 | function 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 |
882 | end |
389 | function 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) |
405 | end |
18 | function 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 |
99 | end |
569 | function 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 |
628 | end |
327 | function 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() |
355 | end |
227 | function 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) |
252 | end |