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).
67 lines
2.5 KiB
Python
67 lines
2.5 KiB
Python
"""Time panel: clock, day, season, timescale. Mirrors `renderTime`."""
|
||
from __future__ import annotations
|
||
|
||
from typing import Optional
|
||
|
||
from PySide6.QtWidgets import QHBoxLayout, QLabel
|
||
|
||
from formatting import is_number
|
||
from widgets.common import CollapsiblePanel, style_role
|
||
|
||
|
||
class TimePanel(CollapsiblePanel):
|
||
def __init__(self, parent=None) -> None:
|
||
super().__init__("time", "Zeit", parent)
|
||
|
||
self.clock_label = QLabel("--:--")
|
||
self.clock_label.setStyleSheet("font-size: 34px; font-weight: 700;")
|
||
self.body_layout.addWidget(self.clock_label)
|
||
|
||
sub_row = QHBoxLayout()
|
||
self.day_label = QLabel("Tag –")
|
||
self.season_label = QLabel("")
|
||
self.period_label = QLabel("")
|
||
self.scale_label = QLabel("")
|
||
for lbl in (self.day_label, self.season_label, self.period_label, self.scale_label):
|
||
style_role(lbl, "stat-label")
|
||
sub_row.addWidget(lbl)
|
||
sub_row.addStretch(1)
|
||
self.body_layout.addLayout(sub_row)
|
||
|
||
def render_time(self, time_data: Optional[dict]) -> None:
|
||
if not time_data:
|
||
self.clock_label.setText("--:--")
|
||
self.day_label.setText("Tag –")
|
||
self.season_label.setText("")
|
||
self.period_label.setText("")
|
||
self.scale_label.setText("")
|
||
return
|
||
|
||
minutes = None
|
||
day_time_minutes = time_data.get("dayTimeMinutes")
|
||
current_hour = time_data.get("currentHour")
|
||
if is_number(day_time_minutes):
|
||
minutes = day_time_minutes / 60000 if day_time_minutes > 1440 else day_time_minutes
|
||
elif is_number(current_hour):
|
||
minutes = current_hour * 60
|
||
|
||
if minutes is not None:
|
||
minutes = ((minutes % 1440) + 1440) % 1440
|
||
hh = int(minutes // 60)
|
||
mm = int(minutes % 60)
|
||
self.clock_label.setText(f"{hh:02d}:{mm:02d}")
|
||
else:
|
||
self.clock_label.setText("--:--")
|
||
|
||
current_day = time_data.get("currentDay")
|
||
self.day_label.setText(f"Tag {current_day}" if is_number(current_day) else "Tag –")
|
||
|
||
season = time_data.get("currentSeason")
|
||
self.season_label.setText(f"Saison {season}" if season is not None else "")
|
||
|
||
days_per_period = time_data.get("daysPerPeriod")
|
||
self.period_label.setText(f"({days_per_period} Tage/Saison)" if is_number(days_per_period) else "")
|
||
|
||
time_scale = time_data.get("timeScale")
|
||
self.scale_label.setText(f"{time_scale}× Zeitraffer" if is_number(time_scale) else "")
|