|
| 1 | +--- |
| 2 | +-- ExtendedGameInfoDisplay |
| 3 | +-- |
| 4 | +-- Main class to extend the default gameInfoDisplay with year info |
| 5 | +-- and temperature + trend and current/min/max temperatur. |
| 6 | +-- |
| 7 | +-- Copyright (c) Peppie84, 2024 |
| 8 | +-- https://github.com/Peppie84/FS25_ExtendedGameInfoDisplay |
| 9 | +-- |
| 10 | + |
| 11 | +ExtendedGameInfoDisplay = { |
| 12 | + STRECH_GAME_INFO_DISPLAY = 95, |
| 13 | + TEMPERATURE_ICON_SIZE = 40, |
| 14 | + L10N_SYMBOLS = { |
| 15 | + YEAR_TEXT = "yearinfo_current_year" |
| 16 | + }, |
| 17 | + CURRENT_MOD = g_currentModName or 'unknown', |
| 18 | + DIRECTORY_MOD = g_currentModDirectory or '', |
| 19 | + WEATHER_HOURS_FORECAST = 3600000*6, |
| 20 | + HOURS_A_DAY = 3600000*24 |
| 21 | +} |
| 22 | + |
| 23 | +---Overwritten HUD.createDisplayComponents() |
| 24 | +---@param overwrittenFunc function |
| 25 | +---@param uiScale number |
| 26 | +function ExtendedGameInfoDisplay:hud__createDisplayComponents(overwrittenFunc, uiScale) |
| 27 | + overwrittenFunc(self, uiScale) |
| 28 | + -- Set some offsets to move the hud to the left |
| 29 | + self.gameInfoDisplay.calendarTextOffsetY = self.gameInfoDisplay.calendarTextOffsetY + self.gameInfoDisplay:scalePixelToScreenHeight(7) |
| 30 | + self.gameInfoDisplay.infoBgLeft.offsetX = -self.gameInfoDisplay:scalePixelToScreenWidth(ExtendedGameInfoDisplay.STRECH_GAME_INFO_DISPLAY) |
| 31 | + self.gameInfoDisplay.weatherIcon.offsetX = -self.gameInfoDisplay:scalePixelToScreenWidth(ExtendedGameInfoDisplay.STRECH_GAME_INFO_DISPLAY) |
| 32 | + self.gameInfoDisplay.weatherNextIcon.offsetX = -self.gameInfoDisplay:scalePixelToScreenWidth(ExtendedGameInfoDisplay.STRECH_GAME_INFO_DISPLAY) |
| 33 | + |
| 34 | + local posX, posY = self.gameInfoDisplay:getPosition() |
| 35 | + local temperaturePositionY = posY - self.gameInfoDisplay:scalePixelToScreenHeight(ExtendedGameInfoDisplay.TEMPERATURE_ICON_SIZE + 12) |
| 36 | + local temperatureIconWidth = self.gameInfoDisplay:scalePixelToScreenWidth(ExtendedGameInfoDisplay.TEMPERATURE_ICON_SIZE) |
| 37 | + local temperatureIconHeight = self.gameInfoDisplay:scalePixelToScreenHeight(ExtendedGameInfoDisplay.TEMPERATURE_ICON_SIZE) |
| 38 | + |
| 39 | + self.gameInfoDisplay.temperature = g_overlayManager:createOverlay("ui_elements.thermometer", 0, temperaturePositionY, temperatureIconWidth, temperatureIconHeight) |
| 40 | + self.gameInfoDisplay.temperature:setColor(unpack(HUD.COLOR.ACTIVE)) |
| 41 | + self.gameInfoDisplay.temperatureUp = g_overlayManager:createOverlay("ui_elements.thermometerUp", 0, temperaturePositionY, temperatureIconWidth, temperatureIconHeight) |
| 42 | + self.gameInfoDisplay.temperatureUp:setColor(unpack(HUD.COLOR.ACTIVE)) |
| 43 | + self.gameInfoDisplay.temperatureDown = g_overlayManager:createOverlay("ui_elements.thermometerDown", 0, temperaturePositionY, temperatureIconWidth, temperatureIconHeight) |
| 44 | + self.gameInfoDisplay.temperatureDown:setColor(unpack(HUD.COLOR.ACTIVE)) |
| 45 | +end |
| 46 | + |
| 47 | +---Overwrite GameInfoDisplay.draw() |
| 48 | +---@param overwrittenFunc function |
| 49 | +function ExtendedGameInfoDisplay:gameinfodisplay__draw(overwrittenFunc) |
| 50 | + overwrittenFunc(self) |
| 51 | + |
| 52 | + local weatherType = g_currentMission.environment.weather:getCurrentWeatherType() |
| 53 | + local forcastDayTime = math.floor(g_currentMission.environment.dayTime + ExtendedGameInfoDisplay.WEATHER_HOURS_FORECAST ) |
| 54 | + local forcastDay = g_currentMission.environment.currentDay |
| 55 | + if forcastDayTime > ExtendedGameInfoDisplay.HOURS_A_DAY then |
| 56 | + forcastDayTime = forcastDayTime - ExtendedGameInfoDisplay.HOURS_A_DAY |
| 57 | + forcastDay = forcastDay + 1 |
| 58 | + end |
| 59 | + |
| 60 | + local nextWeatherType = g_currentMission.environment.weather:getNextWeatherType(forcastDay, forcastDayTime ) |
| 61 | + |
| 62 | + -- Strech the background and render new! |
| 63 | + self.infoBgScale.width = self:scalePixelToScreenWidth(ExtendedGameInfoDisplay.STRECH_GAME_INFO_DISPLAY) |
| 64 | + self.infoBgScale.offsetX = -self:scalePixelToScreenWidth(ExtendedGameInfoDisplay.STRECH_GAME_INFO_DISPLAY) |
| 65 | + self.infoBgScale:render() |
| 66 | + |
| 67 | + -- ReRender to bring it back to top |
| 68 | + self.weatherIcon:render() |
| 69 | + self.weatherNextIcon:render() |
| 70 | + self.weatherNextIcon:setVisible(weatherType ~= nextWeatherType) |
| 71 | + |
| 72 | + ExtendedGameInfoDisplay:setTemperaturePosition(self) |
| 73 | + ExtendedGameInfoDisplay:setTemperatureTrendAndDraw(self) |
| 74 | + ExtendedGameInfoDisplay:drawYearText(self) |
| 75 | + ExtendedGameInfoDisplay:drawTemperatureText(self) |
| 76 | +end |
| 77 | + |
| 78 | +function ExtendedGameInfoDisplay:setTemperaturePosition(gameInfoDisplay) |
| 79 | + local referencePositionX = gameInfoDisplay.calendarIcon.x - gameInfoDisplay:scalePixelToScreenHeight(65) |
| 80 | + gameInfoDisplay.temperature.x = referencePositionX |
| 81 | + gameInfoDisplay.temperatureUp.x = referencePositionX |
| 82 | + gameInfoDisplay.temperatureDown.x = referencePositionX |
| 83 | +end |
| 84 | + |
| 85 | +function ExtendedGameInfoDisplay:setTemperatureTrendAndDraw(gameInfoDisplay) |
| 86 | + local temperaturTrend = g_currentMission.environment.weather:getCurrentTemperatureTrend() |
| 87 | + |
| 88 | + gameInfoDisplay.temperature:setVisible(temperaturTrend == 0) |
| 89 | + gameInfoDisplay.temperatureUp:setVisible(temperaturTrend > 0) |
| 90 | + gameInfoDisplay.temperatureDown:setVisible(temperaturTrend < 0) |
| 91 | + |
| 92 | + gameInfoDisplay.temperature:draw() |
| 93 | + gameInfoDisplay.temperatureUp:draw() |
| 94 | + gameInfoDisplay.temperatureDown:draw() |
| 95 | + |
| 96 | + local seperatorPosX = gameInfoDisplay.temperature.x - gameInfoDisplay:scalePixelToScreenWidth(5) |
| 97 | + local seperatorPosYStart = gameInfoDisplay.temperature.y + gameInfoDisplay:scalePixelToScreenHeight(ExtendedGameInfoDisplay.TEMPERATURE_ICON_SIZE-1) |
| 98 | + local seperatorPosYEnd = gameInfoDisplay.temperature.y + gameInfoDisplay:scalePixelToScreenHeight(4) |
| 99 | + |
| 100 | + drawLine2D(seperatorPosX, seperatorPosYStart, seperatorPosX, seperatorPosYEnd, gameInfoDisplay.separatorWidth, 1,1,1,0.2) |
| 101 | +end |
| 102 | + |
| 103 | +function ExtendedGameInfoDisplay:drawTemperatureText(gameInfoDisplay) |
| 104 | + local minTemperatureInC, maxTemperatureInC = g_currentMission.environment.weather:getCurrentMinMaxTemperatures() |
| 105 | + local currentTemperatureInC = g_currentMission.environment.weather:getCurrentTemperature() |
| 106 | + |
| 107 | + local minTemperatureExpanded = g_i18n:getTemperature(minTemperatureInC) |
| 108 | + local maxTemperatureExpanded = g_i18n:getTemperature(maxTemperatureInC) |
| 109 | + local currentTemperatureExpanded = g_i18n:getTemperature(currentTemperatureInC) |
| 110 | + |
| 111 | + local scaledTextSizeForCurrentTemperature = gameInfoDisplay:scalePixelToScreenHeight(19) |
| 112 | + local scaledTextSizeForTemperature = gameInfoDisplay:scalePixelToScreenHeight(14) |
| 113 | + |
| 114 | + local temperatureTextX = gameInfoDisplay.temperature.x + gameInfoDisplay.temperature.width + gameInfoDisplay:scalePixelToScreenWidth(40) |
| 115 | + local temperatureTextY = gameInfoDisplay.temperature.y + gameInfoDisplay.temperature.height + gameInfoDisplay:scalePixelToScreenHeight(2) |
| 116 | + |
| 117 | + setTextBold(false) |
| 118 | + setTextAlignment(RenderText.ALIGN_RIGHT) |
| 119 | + |
| 120 | + renderText(temperatureTextX, temperatureTextY - gameInfoDisplay:scalePixelToScreenHeight(22), scaledTextSizeForCurrentTemperature, string.format('%d°', currentTemperatureExpanded)) |
| 121 | + renderText(temperatureTextX, temperatureTextY - gameInfoDisplay:scalePixelToScreenHeight(38), scaledTextSizeForTemperature, string.format('%d°/%d°', maxTemperatureExpanded, minTemperatureExpanded)) |
| 122 | +end |
| 123 | + |
| 124 | +function ExtendedGameInfoDisplay:drawYearText(gameInfoDisplay) |
| 125 | + local monthTextSize = gameInfoDisplay:scalePixelToScreenHeight(10) |
| 126 | + local scaledTextSizeForYear = gameInfoDisplay:scalePixelToScreenHeight(12) |
| 127 | + |
| 128 | + local gameInfoDisplayPosX, gameInfoDisplayPosY = gameInfoDisplay:getPosition() |
| 129 | + local posX = gameInfoDisplay.calendarIcon.x + gameInfoDisplay.calendarIcon.width + gameInfoDisplay:scalePixelToScreenWidth(2) |
| 130 | + local posY = gameInfoDisplayPosY - gameInfoDisplay.calendarTextOffsetY - monthTextSize |
| 131 | + |
| 132 | + local l10nTextYear = g_i18n:getText(ExtendedGameInfoDisplay.L10N_SYMBOLS.YEAR_TEXT, ExtendedGameInfoDisplay.CURRENT_MOD) |
| 133 | + |
| 134 | + setTextBold(false) |
| 135 | + setTextAlignment(RenderText.ALIGN_LEFT) |
| 136 | + |
| 137 | + renderText(posX, posY, scaledTextSizeForYear, string.format('%s %s', l10nTextYear, g_currentMission.environment.currentYear)) |
| 138 | +end |
| 139 | + |
| 140 | +--- Initialize the mod |
| 141 | +local function init() |
| 142 | + --HUD.new = Utils.prependedFunction(HUD.new, newHud) |
| 143 | + HUD.createDisplayComponents = Utils.overwrittenFunction(HUD.createDisplayComponents, ExtendedGameInfoDisplay.hud__createDisplayComponents) |
| 144 | + GameInfoDisplay.draw = Utils.overwrittenFunction(GameInfoDisplay.draw, ExtendedGameInfoDisplay.gameinfodisplay__draw) |
| 145 | +end |
| 146 | + |
| 147 | +init() |
0 commit comments