diff --git a/game/missiongenerator/kneeboard.py b/game/missiongenerator/kneeboard.py index 1c0a5f96..1834a5e1 100644 --- a/game/missiongenerator/kneeboard.py +++ b/game/missiongenerator/kneeboard.py @@ -336,7 +336,7 @@ class BriefingPage(KneeboardPage): def write(self, path: Path) -> None: writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard) - if self.flight.custom_name is not None: + if self.flight.custom_name: custom_name_title = ' ("{}")'.format(self.flight.custom_name) else: custom_name_title = "" @@ -500,7 +500,7 @@ class SupportPage(KneeboardPage): def write(self, path: Path) -> None: writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard) - if self.flight.custom_name is not None: + if self.flight.custom_name: custom_name_title = ' ("{}")'.format(self.flight.custom_name) else: custom_name_title = "" @@ -611,7 +611,7 @@ class SeadTaskPage(KneeboardPage): def write(self, path: Path) -> None: writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard) - if self.flight.custom_name is not None: + if self.flight.custom_name: custom_name_title = ' ("{}")'.format(self.flight.custom_name) else: custom_name_title = "" @@ -653,7 +653,7 @@ class StrikeTaskPage(KneeboardPage): def write(self, path: Path) -> None: writer = KneeboardPageWriter(dark_theme=self.dark_kneeboard) - if self.flight.custom_name is not None: + if self.flight.custom_name: custom_name_title = ' ("{}")'.format(self.flight.custom_name) else: custom_name_title = "" diff --git a/qt_ui/windows/mission/flight/settings/QCustomName.py b/qt_ui/windows/mission/flight/settings/QCustomName.py index 86da83f0..1258a4b2 100644 --- a/qt_ui/windows/mission/flight/settings/QCustomName.py +++ b/qt_ui/windows/mission/flight/settings/QCustomName.py @@ -1,5 +1,6 @@ -from PySide2.QtWidgets import QGroupBox, QHBoxLayout, QLabel +from typing import Optional +from PySide2.QtWidgets import QGroupBox, QVBoxLayout, QLineEdit, QLabel, QMessageBox from game.ato.flight import Flight @@ -9,7 +10,22 @@ class QFlightCustomName(QGroupBox): self.flight = flight - self.layout = QHBoxLayout() - self.custom_name_label = QLabel(f"Custom Name: {flight.custom_name}") + self.layout = QVBoxLayout() + self.custom_name_label = QLabel(f"Custom Name:") + self.custom_name_input = QLineEdit(flight.custom_name) + self.custom_name_input.textChanged.connect(self.on_change) self.layout.addWidget(self.custom_name_label) + self.layout.addWidget(self.custom_name_input) self.setLayout(self.layout) + + def on_change(self) -> None: + error = self.verify_form() + if error is not None: + QMessageBox.critical(self, "Could not edit flight", error) + return + self.flight.custom_name = self.custom_name_input.text() + + def verify_form(self) -> Optional[str]: + if "|" in self.custom_name_input.text(): + return f"Cannot include | in flight name" + return None