feat: add FS25_FarmHUD mod and FarmHUD desktop companion app
Initial commit: the FS25 Lua mod (live.json data export), the FS25-WebDashboard project (Node/web dashboard + PySide6 desktop variant), and FarmHUD (standalone PySide6 companion app with Discord Rich Presence, settings, and installer).
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
"""Weather panel: current weather, badges, forecast strip. Mirrors
|
||||
`renderWeather`."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from PySide6.QtWidgets import QFrame, QHBoxLayout, QLabel, QVBoxLayout
|
||||
|
||||
from formatting import WEATHER_ICONS, WEATHER_LABELS_DE, is_number
|
||||
from widgets.common import CollapsiblePanel, clear_layout, style_role
|
||||
|
||||
|
||||
class WeatherPanel(CollapsiblePanel):
|
||||
def __init__(self, parent=None) -> None:
|
||||
super().__init__("weather", "Wetter", parent)
|
||||
|
||||
now_row = QHBoxLayout()
|
||||
self.icon_label = QLabel("❓")
|
||||
self.icon_label.setStyleSheet("font-size: 30px;")
|
||||
now_row.addWidget(self.icon_label)
|
||||
|
||||
text_col = QVBoxLayout()
|
||||
self.type_label = QLabel("Unbekannt")
|
||||
self.type_label.setStyleSheet("font-weight: 600;")
|
||||
text_col.addWidget(self.type_label)
|
||||
self.temp_label = QLabel("")
|
||||
style_role(self.temp_label, "stat-label")
|
||||
text_col.addWidget(self.temp_label)
|
||||
now_row.addLayout(text_col)
|
||||
|
||||
now_row.addStretch(1)
|
||||
self.badges_row = QHBoxLayout()
|
||||
now_row.addLayout(self.badges_row)
|
||||
self.body_layout.addLayout(now_row)
|
||||
|
||||
self.extra_row = QHBoxLayout()
|
||||
self.body_layout.addLayout(self.extra_row)
|
||||
|
||||
self.forecast_row = QHBoxLayout()
|
||||
self.forecast_row.setSpacing(8)
|
||||
self.body_layout.addLayout(self.forecast_row)
|
||||
|
||||
def render_weather(self, weather: Optional[dict], time_data: Optional[dict]) -> None:
|
||||
clear_layout(self.badges_row)
|
||||
clear_layout(self.extra_row)
|
||||
clear_layout(self.forecast_row)
|
||||
|
||||
if not weather:
|
||||
self.icon_label.setText("❓")
|
||||
self.type_label.setText("Unbekannt")
|
||||
self.temp_label.setText("")
|
||||
self.forecast_row.addWidget(self._muted("Keine Wetterdaten vom Spiel verfügbar."))
|
||||
return
|
||||
|
||||
name = weather.get("currentTypeName")
|
||||
self.icon_label.setText(WEATHER_ICONS.get(name, "❓"))
|
||||
self.type_label.setText(WEATHER_LABELS_DE.get(name, "Unbekannt"))
|
||||
temp = weather.get("temperatureCelsius")
|
||||
self.temp_label.setText(f"{round(temp)} °C" if is_number(temp) else "")
|
||||
|
||||
badges = []
|
||||
if weather.get("isRaining"):
|
||||
badges.append("🌧️ Regen")
|
||||
if weather.get("isSnowing"):
|
||||
badges.append("❄️ Schnee")
|
||||
if time_data and time_data.get("isNight"):
|
||||
badges.append("🌙 Nacht")
|
||||
for text in badges:
|
||||
badge = QFrame()
|
||||
style_role(badge, "stat-chip")
|
||||
layout = QHBoxLayout(badge)
|
||||
layout.setContentsMargins(8, 3, 8, 3)
|
||||
lbl = QLabel(text)
|
||||
layout.addWidget(lbl)
|
||||
self.badges_row.addWidget(badge)
|
||||
|
||||
rain_scale = weather.get("rainFallScale")
|
||||
if weather.get("isRaining") and is_number(rain_scale):
|
||||
self.extra_row.addWidget(self._muted(f"Regenintensität: {round(rain_scale * 100)}%"))
|
||||
snow_height = weather.get("snowHeight")
|
||||
if is_number(snow_height) and snow_height > 0.001:
|
||||
self.extra_row.addWidget(self._muted(f"Schneehöhe: {snow_height:.2f} m"))
|
||||
self.extra_row.addStretch(1)
|
||||
|
||||
forecast = weather.get("forecast") or []
|
||||
if not forecast:
|
||||
self.forecast_row.addWidget(self._muted("Keine Vorhersagedaten vom Spiel verfügbar."))
|
||||
return
|
||||
|
||||
for f in forecast:
|
||||
day = QFrame()
|
||||
style_role(day, "stat-chip")
|
||||
col = QVBoxLayout(day)
|
||||
col.setContentsMargins(8, 6, 8, 6)
|
||||
col.setSpacing(2)
|
||||
|
||||
label = QLabel(f"+{f.get('dayOffset')} Tag")
|
||||
style_role(label, "stat-label")
|
||||
col.addWidget(label)
|
||||
|
||||
icon = QLabel(WEATHER_ICONS.get(f.get("typeName"), "❓"))
|
||||
icon.setStyleSheet("font-size: 20px;")
|
||||
col.addWidget(icon)
|
||||
|
||||
min_t = f.get("minTemperatureCelsius")
|
||||
max_t = f.get("maxTemperatureCelsius")
|
||||
temp_text = f"{round(min_t)}° / {round(max_t)}°" if is_number(min_t) and is_number(max_t) else ""
|
||||
temp_lbl = QLabel(temp_text)
|
||||
col.addWidget(temp_lbl)
|
||||
|
||||
self.forecast_row.addWidget(day)
|
||||
self.forecast_row.addStretch(1)
|
||||
|
||||
@staticmethod
|
||||
def _muted(text: str) -> QLabel:
|
||||
lbl = QLabel(text)
|
||||
style_role(lbl, "stat-label")
|
||||
return lbl
|
||||
Reference in New Issue
Block a user