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,56 @@
|
||||
"""A collapsed-by-default group at the very bottom of the HUD for the
|
||||
low-glance-value / technical data (session settings, savegame metadata,
|
||||
per-vehicle technical flags, ...) - keeps the main view focused on what's
|
||||
actually useful while the app + and toggle keeps everything accessible."""
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtCore import QSettings, Signal
|
||||
from PySide6.QtWidgets import QFrame, QHBoxLayout, QLabel, QPushButton, QVBoxLayout
|
||||
|
||||
from version import APP_NAME, APP_ORG
|
||||
from widgets.common import style_role
|
||||
|
||||
SETTINGS_KEY = "ui/technical_section_expanded"
|
||||
|
||||
|
||||
class CollapsibleGroup(QFrame):
|
||||
toggled = Signal(bool)
|
||||
|
||||
def __init__(self, title: str, parent=None) -> None:
|
||||
super().__init__(parent)
|
||||
self.setProperty("role", "tile")
|
||||
outer = QVBoxLayout(self)
|
||||
outer.setContentsMargins(14, 10, 14, 10)
|
||||
outer.setSpacing(8)
|
||||
|
||||
header = QHBoxLayout()
|
||||
title_label = QLabel(title)
|
||||
style_role(title_label, "section-title")
|
||||
header.addWidget(title_label)
|
||||
header.addStretch(1)
|
||||
self._settings = QSettings(APP_ORG, APP_NAME)
|
||||
self._expanded = self._settings.value(SETTINGS_KEY, False, type=bool)
|
||||
|
||||
self.toggle_btn = QPushButton()
|
||||
self.toggle_btn.setProperty("flat", "true")
|
||||
self.toggle_btn.clicked.connect(self._on_toggle)
|
||||
header.addWidget(self.toggle_btn)
|
||||
outer.addLayout(header)
|
||||
|
||||
self.body = QFrame()
|
||||
self.body_layout = QVBoxLayout(self.body)
|
||||
self.body_layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.body_layout.setSpacing(8)
|
||||
outer.addWidget(self.body)
|
||||
|
||||
self._apply_state()
|
||||
|
||||
def _on_toggle(self) -> None:
|
||||
self._expanded = not self._expanded
|
||||
self._settings.setValue(SETTINGS_KEY, self._expanded)
|
||||
self._apply_state()
|
||||
self.toggled.emit(self._expanded)
|
||||
|
||||
def _apply_state(self) -> None:
|
||||
self.body.setVisible(self._expanded)
|
||||
self.toggle_btn.setText("▾ ausblenden" if self._expanded else "▸ mehr anzeigen")
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Small shared helpers used across FarmHUD's widgets."""
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtWidgets import QWidget
|
||||
|
||||
|
||||
def style_role(widget: QWidget, role: str) -> QWidget:
|
||||
widget.setProperty("role", role)
|
||||
return widget
|
||||
|
||||
|
||||
def clear_layout(layout) -> None:
|
||||
"""Empties a layout so it can be rebuilt on the next poll tick.
|
||||
|
||||
Removing a widget from a layout with takeAt() does NOT hide it - it
|
||||
keeps painting at its last geometry until deleteLater()'s deferred
|
||||
deletion actually runs on a later event-loop pass. Every dynamic list
|
||||
here (storage, missions, players, ...) gets rebuilt on every ~500ms
|
||||
poll tick, so that lag would show up as visible flicker/ghosting.
|
||||
Hiding immediately (synchronous, cheap) avoids that; deleteLater()
|
||||
still runs afterwards to actually free it.
|
||||
"""
|
||||
while layout.count():
|
||||
item = layout.takeAt(0)
|
||||
w = item.widget()
|
||||
if w is not None:
|
||||
w.hide()
|
||||
w.deleteLater()
|
||||
@@ -0,0 +1,53 @@
|
||||
"""A tile-styled card with a title row and a dynamic list of label:value
|
||||
rows underneath - the one component nearly every new "useful vs. less
|
||||
useful" section is built from (weather, attached implement, missions,
|
||||
storage, husbandry, prices, players, session settings, ...)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtWidgets import QFrame, QHBoxLayout, QLabel, QVBoxLayout, QWidget
|
||||
|
||||
from widgets.common import clear_layout, style_role
|
||||
|
||||
|
||||
class InfoCard(QFrame):
|
||||
def __init__(self, icon: str, title: str, parent=None) -> None:
|
||||
super().__init__(parent)
|
||||
self.setProperty("role", "tile")
|
||||
outer = QVBoxLayout(self)
|
||||
outer.setContentsMargins(14, 10, 14, 10)
|
||||
outer.setSpacing(6)
|
||||
|
||||
head = QHBoxLayout()
|
||||
head.setSpacing(8)
|
||||
icon_label = QLabel(icon)
|
||||
icon_label.setStyleSheet("font-size: 15px;")
|
||||
head.addWidget(icon_label)
|
||||
title_label = QLabel(title)
|
||||
style_role(title_label, "section-title")
|
||||
head.addWidget(title_label)
|
||||
head.addStretch(1)
|
||||
outer.addLayout(head)
|
||||
|
||||
self.rows_layout = QVBoxLayout()
|
||||
self.rows_layout.setSpacing(3)
|
||||
outer.addLayout(self.rows_layout)
|
||||
|
||||
def set_rows(self, rows: list[tuple[str, str]], empty_text: str = "Keine Daten") -> None:
|
||||
clear_layout(self.rows_layout)
|
||||
if not rows:
|
||||
lbl = QLabel(empty_text)
|
||||
style_role(lbl, "dim")
|
||||
self.rows_layout.addWidget(lbl)
|
||||
return
|
||||
for name, value in rows:
|
||||
row = QWidget()
|
||||
row_layout = QHBoxLayout(row)
|
||||
row_layout.setContentsMargins(0, 0, 0, 0)
|
||||
name_lbl = QLabel(name)
|
||||
style_role(name_lbl, "dim")
|
||||
row_layout.addWidget(name_lbl)
|
||||
row_layout.addStretch(1)
|
||||
value_lbl = QLabel(value)
|
||||
style_role(value_lbl, "row-value")
|
||||
row_layout.addWidget(value_lbl)
|
||||
self.rows_layout.addWidget(row)
|
||||
@@ -0,0 +1,146 @@
|
||||
"""Settings dialog: Discord Rich Presence config + manual update check.
|
||||
Both features live here on purpose (not on the main HUD) - they're
|
||||
configure-once, not something you watch continuously."""
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtWidgets import (
|
||||
QCheckBox,
|
||||
QDialog,
|
||||
QFormLayout,
|
||||
QGroupBox,
|
||||
QHBoxLayout,
|
||||
QLabel,
|
||||
QLineEdit,
|
||||
QPushButton,
|
||||
QSpinBox,
|
||||
QVBoxLayout,
|
||||
)
|
||||
|
||||
from settings_store import ROTATION_KEYS, ROTATION_LABELS, SettingsStore
|
||||
from update_checker import check_for_update
|
||||
from version import APP_VERSION
|
||||
|
||||
|
||||
class SettingsDialog(QDialog):
|
||||
def __init__(self, settings: SettingsStore, parent=None) -> None:
|
||||
super().__init__(parent)
|
||||
self.settings = settings
|
||||
self.setWindowTitle("Einstellungen")
|
||||
self.setMinimumWidth(420)
|
||||
|
||||
root = QVBoxLayout(self)
|
||||
root.setSpacing(14)
|
||||
|
||||
# -- Discord RPC ---------------------------------------------------
|
||||
discord_box = QGroupBox("Discord Rich Presence")
|
||||
discord_layout = QVBoxLayout(discord_box)
|
||||
|
||||
self.discord_enabled_cb = QCheckBox("Discord-Status anzeigen")
|
||||
self.discord_enabled_cb.setChecked(settings.discord_enabled)
|
||||
discord_layout.addWidget(self.discord_enabled_cb)
|
||||
|
||||
form = QFormLayout()
|
||||
self.client_id_edit = QLineEdit(settings.discord_client_id)
|
||||
self.client_id_edit.setPlaceholderText("Discord Application Client ID")
|
||||
form.addRow("Client ID:", self.client_id_edit)
|
||||
|
||||
self.interval_spin = QSpinBox()
|
||||
self.interval_spin.setRange(5, 120)
|
||||
self.interval_spin.setSuffix(" s")
|
||||
self.interval_spin.setValue(settings.discord_rotation_interval_s)
|
||||
form.addRow("Wechsel alle:", self.interval_spin)
|
||||
discord_layout.addLayout(form)
|
||||
|
||||
hint = QLabel(
|
||||
"Client ID kommt aus dem Discord Developer Portal "
|
||||
"(discord.com/developers/applications → deine App → General Information)."
|
||||
)
|
||||
hint.setProperty("role", "dim")
|
||||
hint.setWordWrap(True)
|
||||
discord_layout.addWidget(hint)
|
||||
|
||||
discord_layout.addWidget(QLabel("In der Rotation zeigen:"))
|
||||
self.rotation_checkboxes: dict[str, QCheckBox] = {}
|
||||
for key in ROTATION_KEYS:
|
||||
cb = QCheckBox(ROTATION_LABELS[key])
|
||||
cb.setChecked(settings.rotation_enabled(key))
|
||||
discord_layout.addWidget(cb)
|
||||
self.rotation_checkboxes[key] = cb
|
||||
|
||||
root.addWidget(discord_box)
|
||||
|
||||
# -- Updates ---------------------------------------------------------
|
||||
update_box = QGroupBox("Updates")
|
||||
update_layout = QVBoxLayout(update_box)
|
||||
|
||||
version_label = QLabel(f"Installierte Version: {APP_VERSION}")
|
||||
version_label.setProperty("role", "dim")
|
||||
update_layout.addWidget(version_label)
|
||||
|
||||
url_form = QFormLayout()
|
||||
self.manifest_url_edit = QLineEdit(settings.update_manifest_url)
|
||||
self.manifest_url_edit.setPlaceholderText("https://.../fhud-version.json")
|
||||
url_form.addRow("Update-Quelle:", self.manifest_url_edit)
|
||||
update_layout.addLayout(url_form)
|
||||
|
||||
check_row = QHBoxLayout()
|
||||
self.check_button = QPushButton("Auf Updates prüfen")
|
||||
self.check_button.setProperty("role", "primary")
|
||||
self.check_button.clicked.connect(self._on_check_updates)
|
||||
check_row.addWidget(self.check_button)
|
||||
check_row.addStretch(1)
|
||||
update_layout.addLayout(check_row)
|
||||
|
||||
self.update_result_label = QLabel("")
|
||||
self.update_result_label.setWordWrap(True)
|
||||
self.update_result_label.setProperty("role", "dim")
|
||||
update_layout.addWidget(self.update_result_label)
|
||||
|
||||
self.download_button = QPushButton("Download öffnen")
|
||||
self.download_button.hide()
|
||||
self.download_button.clicked.connect(self._open_download)
|
||||
update_layout.addWidget(self.download_button)
|
||||
|
||||
root.addWidget(update_box)
|
||||
|
||||
# -- Save/Close --------------------------------------------------------
|
||||
button_row = QHBoxLayout()
|
||||
button_row.addStretch(1)
|
||||
save_btn = QPushButton("Speichern")
|
||||
save_btn.setProperty("role", "primary")
|
||||
save_btn.clicked.connect(self._save_and_close)
|
||||
button_row.addWidget(save_btn)
|
||||
root.addLayout(button_row)
|
||||
|
||||
self._pending_download_url = None
|
||||
|
||||
def _on_check_updates(self) -> None:
|
||||
self.check_button.setEnabled(False)
|
||||
self.update_result_label.setText("Prüfe…")
|
||||
self.download_button.hide()
|
||||
from PySide6.QtWidgets import QApplication
|
||||
|
||||
QApplication.instance().processEvents()
|
||||
|
||||
result = check_for_update(self.manifest_url_edit.text().strip())
|
||||
self.update_result_label.setText(result.message)
|
||||
if result.ok and result.update_available and result.download_url:
|
||||
self._pending_download_url = result.download_url
|
||||
self.download_button.show()
|
||||
self.check_button.setEnabled(True)
|
||||
|
||||
def _open_download(self) -> None:
|
||||
if self._pending_download_url:
|
||||
from PySide6.QtGui import QDesktopServices
|
||||
from PySide6.QtCore import QUrl
|
||||
|
||||
QDesktopServices.openUrl(QUrl(self._pending_download_url))
|
||||
|
||||
def _save_and_close(self) -> None:
|
||||
self.settings.discord_enabled = self.discord_enabled_cb.isChecked()
|
||||
self.settings.discord_client_id = self.client_id_edit.text()
|
||||
self.settings.discord_rotation_interval_s = self.interval_spin.value()
|
||||
for key, cb in self.rotation_checkboxes.items():
|
||||
self.settings.set_rotation_enabled(key, cb.isChecked())
|
||||
self.settings.update_manifest_url = self.manifest_url_edit.text()
|
||||
self.accept()
|
||||
@@ -0,0 +1,75 @@
|
||||
"""HUD tiles - the two shapes the "gauge cluster" hero section is built
|
||||
from: one wide masthead reading (current vehicle) and several compact
|
||||
gauges side by side (money, farm value, time), the way a tractor's dash
|
||||
has one big central display flanked by smaller round gauges."""
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QFrame, QHBoxLayout, QLabel, QVBoxLayout
|
||||
|
||||
|
||||
class StatTile(QFrame):
|
||||
def __init__(self, icon: str, label: str, variant: str = "hero", parent=None) -> None:
|
||||
super().__init__(parent)
|
||||
self.variant = variant
|
||||
self.setProperty("role", "tile-hero" if variant == "hero" else "tile")
|
||||
|
||||
if variant == "hero":
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(16, 14, 16, 14)
|
||||
layout.setSpacing(14)
|
||||
|
||||
icon_label = QLabel(icon)
|
||||
icon_label.setStyleSheet("font-size: 30px;")
|
||||
icon_label.setFixedWidth(38)
|
||||
layout.addWidget(icon_label)
|
||||
|
||||
text_col = QVBoxLayout()
|
||||
text_col.setSpacing(2)
|
||||
self.label = QLabel(label)
|
||||
self.label.setProperty("role", "tile-label")
|
||||
text_col.addWidget(self.label)
|
||||
|
||||
self.value = QLabel("–")
|
||||
self.value.setProperty("role", "tile-value-lg")
|
||||
self.value.setWordWrap(True)
|
||||
text_col.addWidget(self.value)
|
||||
|
||||
layout.addLayout(text_col, 1)
|
||||
else:
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(10, 12, 10, 12)
|
||||
layout.setSpacing(4)
|
||||
layout.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||||
|
||||
icon_label = QLabel(icon)
|
||||
icon_label.setStyleSheet("font-size: 20px;")
|
||||
icon_label.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||||
layout.addWidget(icon_label)
|
||||
|
||||
self.label = QLabel(label)
|
||||
self.label.setProperty("role", "tile-label")
|
||||
self.label.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||||
layout.addWidget(self.label)
|
||||
|
||||
self.value = QLabel("–")
|
||||
self.value.setProperty("role", "tile-value")
|
||||
self.value.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||||
self.value.setWordWrap(True)
|
||||
layout.addWidget(self.value)
|
||||
|
||||
self.sub_value = QLabel("")
|
||||
self.sub_value.setProperty("role", "dim")
|
||||
self.sub_value.setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||||
self.sub_value.hide()
|
||||
layout.addWidget(self.sub_value)
|
||||
|
||||
def set_value(self, text: str) -> None:
|
||||
self.value.setText(text)
|
||||
|
||||
def set_sub_value(self, text: str) -> None:
|
||||
"""Compact tiles only: a small line under the value (e.g. the day
|
||||
number under the clock) - keeps the big value short enough to
|
||||
never wrap in a narrow gauge tile."""
|
||||
self.sub_value.setText(text)
|
||||
self.sub_value.setVisible(bool(text))
|
||||
Reference in New Issue
Block a user