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,153 @@
|
||||
"""Storage panel: silos, husbandries, productions. Mirrors `renderStorage`."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from PySide6.QtWidgets import QFrame, QHBoxLayout, QLabel, QVBoxLayout
|
||||
|
||||
from formatting import (
|
||||
PRODUCTION_STATUS_LABELS,
|
||||
farm_suffix,
|
||||
format_liters,
|
||||
is_number,
|
||||
production_status_ok,
|
||||
)
|
||||
from widgets.common import CollapsiblePanel, clear_layout, style_role
|
||||
|
||||
|
||||
class StoragePanel(CollapsiblePanel):
|
||||
def __init__(self, parent=None) -> None:
|
||||
super().__init__("storage", "Lager, Tierhaltung & Produktion", parent)
|
||||
|
||||
self.body_layout.addWidget(self._head("Silos"))
|
||||
self.silo_list = QVBoxLayout()
|
||||
self.silo_list.setSpacing(6)
|
||||
self.body_layout.addLayout(self.silo_list)
|
||||
|
||||
self.body_layout.addWidget(self._head("Ställe"))
|
||||
self.husbandry_list = QVBoxLayout()
|
||||
self.husbandry_list.setSpacing(6)
|
||||
self.body_layout.addLayout(self.husbandry_list)
|
||||
|
||||
self.body_layout.addWidget(self._head("Produktionen"))
|
||||
self.production_list = QVBoxLayout()
|
||||
self.production_list.setSpacing(6)
|
||||
self.body_layout.addLayout(self.production_list)
|
||||
|
||||
@staticmethod
|
||||
def _head(text: str) -> QLabel:
|
||||
lbl = QLabel(text)
|
||||
lbl.setStyleSheet("font-weight: 600; margin-top: 4px;")
|
||||
return lbl
|
||||
|
||||
@staticmethod
|
||||
def _muted(text: str) -> QLabel:
|
||||
lbl = QLabel(text)
|
||||
style_role(lbl, "stat-label")
|
||||
return lbl
|
||||
|
||||
@staticmethod
|
||||
def _card() -> tuple[QFrame, QVBoxLayout]:
|
||||
card = QFrame()
|
||||
style_role(card, "stat-chip")
|
||||
layout = QVBoxLayout(card)
|
||||
layout.setContentsMargins(10, 8, 10, 8)
|
||||
layout.setSpacing(3)
|
||||
return card, layout
|
||||
|
||||
@staticmethod
|
||||
def _fill_row(name: str, value: str):
|
||||
row = QHBoxLayout()
|
||||
row.addWidget(QLabel(name))
|
||||
row.addStretch(1)
|
||||
row.addWidget(QLabel(value))
|
||||
return row
|
||||
|
||||
def render_storage(
|
||||
self,
|
||||
silos: Optional[list],
|
||||
husbandries: Optional[list],
|
||||
productions: Optional[list],
|
||||
farms: Optional[list],
|
||||
) -> None:
|
||||
show_farm_badge = bool(farms) and len(farms) > 1
|
||||
|
||||
clear_layout(self.silo_list)
|
||||
filled_silos = [s for s in (silos or []) if s.get("fillTypes")]
|
||||
if not filled_silos:
|
||||
self.silo_list.addWidget(self._muted("– keine befüllten Silos –"))
|
||||
else:
|
||||
for silo in filled_silos:
|
||||
card, layout = self._card()
|
||||
name_lbl = QLabel((silo.get("name") or "Unbenannt") + farm_suffix(silo.get("ownerFarmId"), show_farm_badge))
|
||||
name_lbl.setStyleSheet("font-weight: 600;")
|
||||
layout.addWidget(name_lbl)
|
||||
for ft in silo.get("fillTypes") or []:
|
||||
level = ft.get("fillLevel") if is_number(ft.get("fillLevel")) else 0
|
||||
layout.addLayout(self._fill_row(ft.get("fillTypeName") or "Unbekannt", f"{format_liters(level)} l"))
|
||||
self.silo_list.addWidget(card)
|
||||
|
||||
clear_layout(self.husbandry_list)
|
||||
husbandry_arr = husbandries or []
|
||||
if not husbandry_arr:
|
||||
self.husbandry_list.addWidget(self._muted("– keine –"))
|
||||
else:
|
||||
for h in husbandry_arr:
|
||||
card, layout = self._card()
|
||||
name_lbl = QLabel((h.get("name") or "Unbenannt") + farm_suffix(h.get("ownerFarmId"), show_farm_badge))
|
||||
name_lbl.setStyleSheet("font-weight: 600;")
|
||||
layout.addWidget(name_lbl)
|
||||
count = h.get("numAnimals") if is_number(h.get("numAnimals")) else "–"
|
||||
max_n = f" / {h.get('maxNumAnimals')}" if is_number(h.get("maxNumAnimals")) else ""
|
||||
count_lbl = QLabel(f"{count}{max_n}")
|
||||
count_lbl.setStyleSheet("font-size: 18px; font-weight: 700;")
|
||||
layout.addWidget(count_lbl)
|
||||
layout.addWidget(self._muted("Tiere"))
|
||||
self.husbandry_list.addWidget(card)
|
||||
|
||||
clear_layout(self.production_list)
|
||||
production_arr = productions or []
|
||||
if not production_arr:
|
||||
self.production_list.addWidget(self._muted("– keine –"))
|
||||
else:
|
||||
for p in production_arr:
|
||||
card, layout = self._card()
|
||||
name_lbl = QLabel((p.get("name") or "Unbenannt") + farm_suffix(p.get("ownerFarmId"), show_farm_badge))
|
||||
name_lbl.setStyleSheet("font-weight: 600;")
|
||||
layout.addWidget(name_lbl)
|
||||
|
||||
for r in p.get("recipes") or []:
|
||||
head_row = QHBoxLayout()
|
||||
head_row.addWidget(QLabel(r.get("name") or "Rezept"))
|
||||
head_row.addStretch(1)
|
||||
status_name = r.get("statusName")
|
||||
status_label = PRODUCTION_STATUS_LABELS.get(status_name, status_name or "")
|
||||
if status_label:
|
||||
status_lbl = QLabel(status_label)
|
||||
ok = production_status_ok(status_name)
|
||||
if ok is True:
|
||||
status_lbl.setStyleSheet("color: #3ecf7a; font-weight: 600;")
|
||||
elif ok is False:
|
||||
status_lbl.setStyleSheet("color: #e8b93f; font-weight: 600;")
|
||||
head_row.addWidget(status_lbl)
|
||||
layout.addLayout(head_row)
|
||||
|
||||
inputs_text = " + ".join(
|
||||
(i.get("fillTypeName") or "?") + (f" ({i.get('amount')})" if is_number(i.get("amount")) else "")
|
||||
for i in (r.get("inputs") or [])
|
||||
) or "–"
|
||||
outputs_text = " + ".join(
|
||||
(o.get("fillTypeName") or "?") + (f" ({o.get('amount')})" if is_number(o.get("amount")) else "")
|
||||
for o in (r.get("outputs") or [])
|
||||
) or "–"
|
||||
flow_lbl = self._muted(f"{inputs_text} → {outputs_text}")
|
||||
layout.addWidget(flow_lbl)
|
||||
|
||||
contents = p.get("contents") or []
|
||||
if contents:
|
||||
layout.addWidget(self._head("Lagerbestand"))
|
||||
for c in contents:
|
||||
level = c.get("fillLevel") if is_number(c.get("fillLevel")) else 0
|
||||
layout.addLayout(self._fill_row(c.get("fillTypeName") or "Unbekannt", f"{format_liters(level)} l"))
|
||||
|
||||
self.production_list.addWidget(card)
|
||||
Reference in New Issue
Block a user