420 | function 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) |
435 | end |
439 | function 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) |
450 | end |
463 | function 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 |
489 | end |
394 | function 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 |
416 | end |
811 | function 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 |
822 | end |
584 | function 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()) |
624 | end |
628 | function 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 |
648 | end |
705 | function 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 |
728 | end |
652 | function 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 |
701 | end |
855 | function 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 |
891 | end |
732 | function 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 |
751 | end |
18 | function 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 |
91 | end |
514 | function 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 |
567 | end |
288 | function 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() |
316 | end |
204 | function 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) |
221 | end |