Adds WIP handling for default payload display with restricted date feature enabled.

This commit is contained in:
Simon Clark 2021-01-30 01:00:40 +00:00
parent e4cc749180
commit 883f233c09
2 changed files with 22 additions and 6 deletions

View File

@ -39,7 +39,7 @@ class QLoadoutEditor(QGroupBox):
if not self.isChecked(): if not self.isChecked():
for i in self.findChildren(QPylonEditor): for i in self.findChildren(QPylonEditor):
i.default_loadout(i.pylon.number) i.default_loadout()
def on_toggle(self): def on_toggle(self):
self.flight.use_custom_loadout = self.isChecked() self.flight.use_custom_loadout = self.isChecked()

View File

@ -16,12 +16,13 @@ class QPylonEditor(QComboBox):
super().__init__() super().__init__()
self.flight = flight self.flight = flight
self.pylon = pylon self.pylon = pylon
self.game = game
current = self.flight.loadout.get(self.pylon.number) current = self.flight.loadout.get(self.pylon.number)
self.addItem("None", None) self.addItem("None", None)
if game.settings.restrict_weapons_by_date: if self.game.settings.restrict_weapons_by_date:
weapons = pylon.available_on(game.date) weapons = pylon.available_on(self.game.date)
else: else:
weapons = pylon.allowed weapons = pylon.allowed
allowed = sorted(weapons, key=operator.attrgetter("name")) allowed = sorted(weapons, key=operator.attrgetter("name"))
@ -42,10 +43,11 @@ class QPylonEditor(QComboBox):
logging.debug( logging.debug(
f"Pylon {self.pylon.number} changed to {selected.name}") f"Pylon {self.pylon.number} changed to {selected.name}")
def default_loadout(self, pylon: Pylon) -> None: def default_loadout(self) -> None:
self.flight.unit_type.load_payloads() self.flight.unit_type.load_payloads()
self.setCurrentText("None") self.setCurrentText("None")
pylon_default_weapon = None pylon_default_weapon = None
historical_weapon = None
loadout = None loadout = None
# Iterate through each possible payload type for a given aircraft. # Iterate through each possible payload type for a given aircraft.
# Some aircraft have custom loadouts that in aren't the standard set. # Some aircraft have custom loadouts that in aren't the standard set.
@ -60,5 +62,19 @@ class QPylonEditor(QComboBox):
if pylon_default_weapon == "<CLEAN>": if pylon_default_weapon == "<CLEAN>":
pylon_default_weapon = None pylon_default_weapon = None
if pylon_default_weapon is not None: if pylon_default_weapon is not None:
#self.setCurrentIndex(self.findText(weapons_data.weapon_ids.get(pylon_default_weapon).get("name"))) if self.game.settings.restrict_weapons_by_date:
orig_weapon = Weapon.from_clsid(pylon_default_weapon)
if not orig_weapon.available_on(self.game.date):
for fallback in orig_weapon.fallbacks:
if historical_weapon is None:
if not self.pylon.can_equip(fallback):
continue
if not fallback.available_on(self.game.date):
continue
historical_weapon = fallback
else:
historical_weapon = orig_weapon
if historical_weapon is not None:
self.setCurrentText(weapons_data.weapon_ids.get(historical_weapon.cls_id).get("name"))
else:
self.setCurrentText(weapons_data.weapon_ids.get(pylon_default_weapon).get("name")) self.setCurrentText(weapons_data.weapon_ids.get(pylon_default_weapon).get("name"))