diff --git a/changelog.md b/changelog.md index d85f0b7e..06e98544 100644 --- a/changelog.md +++ b/changelog.md @@ -29,6 +29,7 @@ Saves from 4.0.0 are compatible with 4.1.0. * **[Mission Generation]** The lua data for other plugins is now generated correctly * **[Mission Generation]** The legacy always-available tanker option no longer prevents mission creation. * **[UI]** Statistics window tick marks are now always integers. +* **[UI]** Toggling custom loadout for an aircraft with no preset loadouts no longer breaks the flight. # 4.0.0 diff --git a/gen/flights/loadouts.py b/gen/flights/loadouts.py index 0a51245a..5906315e 100644 --- a/gen/flights/loadouts.py +++ b/gen/flights/loadouts.py @@ -133,4 +133,8 @@ class Loadout: ) # TODO: Try group.load_task_default_loadout(loadout_for_task) + return cls.empty_loadout() + + @classmethod + def empty_loadout(cls) -> Loadout: return Loadout("Empty", {}, date=None) diff --git a/qt_ui/windows/mission/flight/payload/QFlightPayloadTab.py b/qt_ui/windows/mission/flight/payload/QFlightPayloadTab.py index 5cf5b370..b1eb809e 100644 --- a/qt_ui/windows/mission/flight/payload/QFlightPayloadTab.py +++ b/qt_ui/windows/mission/flight/payload/QFlightPayloadTab.py @@ -47,8 +47,20 @@ class QFlightPayloadTab(QFrame): def reload_from_flight(self) -> None: self.loadout_selector.setCurrentText(self.flight.loadout.name) + def loadout_at(self, index: int) -> Loadout: + loadout = self.loadout_selector.itemData(index) + if loadout is None: + return Loadout.empty_loadout() + return loadout + + def current_loadout(self) -> Loadout: + loadout = self.loadout_selector.currentData() + if loadout is None: + return Loadout.empty_loadout() + return loadout + def on_new_loadout(self, index: int) -> None: - self.flight.loadout = self.loadout_selector.itemData(index) + self.flight.loadout = self.loadout_at(index) self.payload_editor.reset_pylons() def on_custom_toggled(self, use_custom: bool) -> None: @@ -56,5 +68,5 @@ class QFlightPayloadTab(QFrame): if use_custom: self.flight.loadout = self.flight.loadout.derive_custom("Custom") else: - self.flight.loadout = self.loadout_selector.currentData() + self.flight.loadout = self.current_loadout() self.payload_editor.reset_pylons()