From 727facfb90dac06c3eb74b90e0296a097fae79a3 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 2 Jul 2021 17:30:37 -0700 Subject: [PATCH] Fixup None loadouts for aircraft with no loadouts. Aircraft that have no loadouts at all (such as the IL-78M) will have no loadouts and thus no values in the dropdown menu. If the player toggles the custom layout box we reset the flight's loadout to the selected loadout, and with no loadouts in the combo box that is None, and `Flight.loadout` isn't supposed to be optional. Check for that case in the loadout selector and replace with an empty loadout if that happens. Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1402 --- changelog.md | 1 + gen/flights/loadouts.py | 4 ++++ .../mission/flight/payload/QFlightPayloadTab.py | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) 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()