Clean up aircraft selector.

This commit is contained in:
Dan Albert 2021-05-22 17:05:53 -07:00
parent 16fff8d87a
commit 2df17c32cd
2 changed files with 11 additions and 67 deletions

View File

@ -2,15 +2,12 @@
from typing import Iterable, Type from typing import Iterable, Type
from PySide2.QtWidgets import QComboBox from PySide2.QtWidgets import QComboBox
from dcs.unittype import FlyingType from dcs.unittype import FlyingType
from game import db
from gen.flights.ai_flight_planner_db import aircraft_for_task
from gen.flights.flight import FlightType from gen.flights.flight import FlightType
import gen.flights.ai_flight_planner_db
from game import Game, db
class QAircraftTypeSelector(QComboBox): class QAircraftTypeSelector(QComboBox):
"""Combo box for selecting among the given aircraft types.""" """Combo box for selecting among the given aircraft types."""
@ -19,77 +16,24 @@ class QAircraftTypeSelector(QComboBox):
self, self,
aircraft_types: Iterable[Type[FlyingType]], aircraft_types: Iterable[Type[FlyingType]],
country: str, country: str,
mission_type: str, mission_type: FlightType,
) -> None: ) -> None:
super().__init__() super().__init__()
self.model().sort(0) self.model().sort(0)
self.setSizeAdjustPolicy(self.AdjustToContents) self.setSizeAdjustPolicy(self.AdjustToContents)
self.country = country self.country = country
self.updateItems(mission_type, aircraft_types) self.update_items(mission_type, aircraft_types)
def updateItems(self, mission_type: str, aircraft_types): def update_items(self, mission_type: FlightType, aircraft_types):
current_aircraft = self.currentData() current_aircraft = self.currentData()
self.clear() self.clear()
for aircraft in aircraft_types: for aircraft in aircraft_types:
if mission_type in [ if aircraft in aircraft_for_task(mission_type):
FlightType.BARCAP, self.addItem(
FlightType.ESCORT, f"{db.unit_get_expanded_info(self.country, aircraft, 'name')}",
FlightType.INTERCEPTION, userData=aircraft,
FlightType.SWEEP, )
FlightType.TARCAP,
]:
if aircraft in gen.flights.ai_flight_planner_db.CAP_CAPABLE:
self.addItem(
f"{db.unit_get_expanded_info(self.country, aircraft, 'name')}",
userData=aircraft,
)
elif mission_type in [
FlightType.CAS,
FlightType.BAI,
FlightType.OCA_AIRCRAFT,
]:
if aircraft in gen.flights.ai_flight_planner_db.CAS_CAPABLE:
self.addItem(
f"{db.unit_get_expanded_info(self.country, aircraft, 'name')}",
userData=aircraft,
)
elif mission_type in [FlightType.SEAD]:
if aircraft in gen.flights.ai_flight_planner_db.SEAD_CAPABLE:
self.addItem(
f"{db.unit_get_expanded_info(self.country, aircraft, 'name')}",
userData=aircraft,
)
elif mission_type in [FlightType.DEAD]:
if aircraft in gen.flights.ai_flight_planner_db.DEAD_CAPABLE:
self.addItem(
f"{db.unit_get_expanded_info(self.country, aircraft, 'name')}",
userData=aircraft,
)
elif mission_type in [FlightType.STRIKE]:
if aircraft in gen.flights.ai_flight_planner_db.STRIKE_CAPABLE:
self.addItem(
f"{db.unit_get_expanded_info(self.country, aircraft, 'name')}",
userData=aircraft,
)
elif mission_type in [FlightType.ANTISHIP]:
if aircraft in gen.flights.ai_flight_planner_db.ANTISHIP_CAPABLE:
self.addItem(
f"{db.unit_get_expanded_info(self.country, aircraft, 'name')}",
userData=aircraft,
)
elif mission_type in [FlightType.OCA_RUNWAY]:
if aircraft in gen.flights.ai_flight_planner_db.RUNWAY_ATTACK_CAPABLE:
self.addItem(
f"{db.unit_get_expanded_info(self.country, aircraft, 'name')}",
userData=aircraft,
)
elif mission_type in [FlightType.AEWC]:
if aircraft in gen.flights.ai_flight_planner_db.AEWC_CAPABLE:
self.addItem(
f"{db.unit_get_expanded_info(self.country, aircraft, 'name')}",
userData=aircraft,
)
current_aircraft_index = self.findData(current_aircraft) current_aircraft_index = self.findData(current_aircraft)
if current_aircraft_index != -1: if current_aircraft_index != -1:
self.setCurrentIndex(current_aircraft_index) self.setCurrentIndex(current_aircraft_index)

View File

@ -211,7 +211,7 @@ class QFlightCreator(QDialog):
self.restore_start_type = None self.restore_start_type = None
def on_task_changed(self) -> None: def on_task_changed(self) -> None:
self.aircraft_selector.updateItems( self.aircraft_selector.update_items(
self.task_selector.currentData(), self.task_selector.currentData(),
self.game.aircraft_inventory.available_types_for_player, self.game.aircraft_inventory.available_types_for_player,
) )