diff --git a/qt_ui/windows/AirWingConfigurationDialog.py b/qt_ui/windows/AirWingConfigurationDialog.py index 4d6f6988..38f29ee2 100644 --- a/qt_ui/windows/AirWingConfigurationDialog.py +++ b/qt_ui/windows/AirWingConfigurationDialog.py @@ -154,11 +154,13 @@ class SquadronSizeSpinner(QSpinBox): class AirWingConfigParkingTracker(QWidget): allocation_changed = Signal() - def __init__(self, squadrons: Iterable[Squadron]) -> None: + def __init__(self, game: Game) -> None: super().__init__() + self.theater = game.theater self.by_cp: dict[ControlPoint, set[Squadron]] = defaultdict(set) - for squadron in squadrons: - self.add_squadron(squadron) + for coalition in game.coalitions: + for squadron in coalition.air_wing.iter_squadrons(): + self.add_squadron(squadron) def add_squadron(self, squadron: Squadron) -> None: self.by_cp[squadron.location].add(squadron) @@ -182,6 +184,12 @@ class AirWingConfigParkingTracker(QWidget): def used_parking_at(self, control_point: ControlPoint) -> int: return sum(s.max_size for s in self.by_cp[control_point]) + def iter_overfull(self) -> Iterator[tuple[ControlPoint, int, list[Squadron]]]: + for control_point in self.theater.controlpoints: + used = self.used_parking_at(control_point) + if used > control_point.total_aircraft_parking: + yield control_point, used, list(self.by_cp[control_point]) + def signal_change(self) -> None: self.allocation_changed.emit() @@ -622,17 +630,62 @@ class AircraftTypeList(QListView): self.update(self.selectionModel().currentIndex()) +class OverfullAirbasesDisplay(QGroupBox): + def __init__( + self, + parking_tracker: AirWingConfigParkingTracker, + parent: QWidget | None = None, + ) -> None: + super().__init__("Overfull airbases", parent) + self.parking_tracker = parking_tracker + self.parking_tracker.allocation_changed.connect(self.on_allocation_changed) + + layout = QVBoxLayout() + self.setLayout(layout) + + self.label = QLabel() + layout.addWidget(self.label) + + self.on_allocation_changed() + + def on_allocation_changed(self) -> None: + string_builder = [] + for ( + control_point, + used_parking, + squadrons, + ) in self.parking_tracker.iter_overfull(): + capacity = control_point.total_aircraft_parking + base_description = f"{control_point.name} {used_parking}/{capacity}" + string_builder.append(f"
{base_description}
") + squadron_descriptions = [] + for squadron in squadrons: + squadron_details = ( + f"{squadron.aircraft} {squadron.name} {squadron.max_size} aircraft" + ) + squadron_descriptions.append(f"