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

(cherry picked from commit 727facfb90)
This commit is contained in:
Dan Albert
2021-07-02 17:30:37 -07:00
parent 355ea9f9be
commit 3415525e2c
3 changed files with 19 additions and 2 deletions

View File

@@ -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()