mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
This is an attempt to remove a lot of our supposedly unnecessary error handling. Every aircraft should have a price, a description, a name, etc; and none of those should require carrying around the faction's country as context. This moves all the data for aircraft into yaml files (only one converted here as an example). Most of the "extended unit info" isn't actually being read yet. To replace the renaming of units based on the county, we instead generate multiple types of each unit when necessary. The CF-18 is just as much a first-class type as the F/A-18 is. This doesn't work in its current state because it does break all the existing names for aircraft that are used in the faction and squadron files, and we no longer let those errors go as a warning. It will be an annoying one time switch, but it allows us to define the names that get used in these files instead of being sensitive to changes as they happen in pydcs, and allows faction designers to specifically choose, for example, the Su-22 instead of the Su-17. One thing not handled by this is aircraft task capability. This is because the lists in ai_flight_planner_db.py are a priority list, and to move it out to a yaml file we'd need to assign a weight to it that would be used to stack rank each aircraft. That's doable, but it makes it much more difficult to see the ordering of aircraft at a glance, and much more annoying to move aircraft around in the priority list. I don't think this is worth doing, and the priority lists will remain in their own separate lists. This includes the converted I used to convert all the old unit info and factions to the new format. This doesn't need to live long, but we may want to reuse it in the future so we want it in the version history.
95 lines
2.9 KiB
Python
95 lines
2.9 KiB
Python
import logging
|
|
from typing import Callable, Dict, TypeVar
|
|
|
|
from PySide2.QtGui import QIcon, QPixmap
|
|
from PySide2.QtWidgets import (
|
|
QDialog,
|
|
QGridLayout,
|
|
QGroupBox,
|
|
QLabel,
|
|
QPushButton,
|
|
QVBoxLayout,
|
|
)
|
|
|
|
from game import db
|
|
from game.debriefing import Debriefing
|
|
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
class LossGrid(QGridLayout):
|
|
def __init__(self, debriefing: Debriefing, player: bool) -> None:
|
|
super().__init__()
|
|
|
|
self.add_loss_rows(debriefing.air_losses.by_type(player), lambda u: u.name)
|
|
self.add_loss_rows(
|
|
debriefing.front_line_losses_by_type(player),
|
|
lambda u: db.unit_type_name(u),
|
|
)
|
|
self.add_loss_rows(
|
|
debriefing.convoy_losses_by_type(player),
|
|
lambda u: f"{db.unit_type_name(u)} from convoy",
|
|
)
|
|
self.add_loss_rows(
|
|
debriefing.cargo_ship_losses_by_type(player),
|
|
lambda u: f"{db.unit_type_name(u)} from cargo ship",
|
|
)
|
|
self.add_loss_rows(
|
|
debriefing.airlift_losses_by_type(player),
|
|
lambda u: f"{db.unit_type_name(u)} from airlift",
|
|
)
|
|
self.add_loss_rows(
|
|
debriefing.building_losses_by_type(player),
|
|
lambda u: u,
|
|
)
|
|
|
|
# TODO: Display dead ground object units and runways.
|
|
|
|
def add_loss_rows(self, losses: Dict[T, int], make_name: Callable[[T], str]):
|
|
for unit_type, count in losses.items():
|
|
row = self.rowCount()
|
|
try:
|
|
name = make_name(unit_type)
|
|
except AttributeError:
|
|
logging.exception(f"Could not make unit name for {unit_type}")
|
|
name = unit_type.id
|
|
self.addWidget(QLabel(name), row, 0)
|
|
self.addWidget(QLabel(str(count)), row, 1)
|
|
|
|
|
|
class QDebriefingWindow(QDialog):
|
|
def __init__(self, debriefing: Debriefing):
|
|
super(QDebriefingWindow, self).__init__()
|
|
self.debriefing = debriefing
|
|
|
|
self.setModal(True)
|
|
self.setWindowTitle("Debriefing")
|
|
self.setMinimumSize(300, 200)
|
|
self.setWindowIcon(QIcon("./resources/icon.png"))
|
|
|
|
layout = QVBoxLayout()
|
|
self.setLayout(layout)
|
|
|
|
header = QLabel(self)
|
|
header.setGeometry(0, 0, 655, 106)
|
|
pixmap = QPixmap("./resources/ui/debriefing.png")
|
|
header.setPixmap(pixmap)
|
|
layout.addWidget(header)
|
|
layout.addStretch()
|
|
|
|
title = QLabel("<b>Casualty report</b>")
|
|
layout.addWidget(title)
|
|
|
|
player_lost_units = QGroupBox(f"{self.debriefing.player_country}'s lost units:")
|
|
player_lost_units.setLayout(LossGrid(debriefing, player=True))
|
|
layout.addWidget(player_lost_units)
|
|
|
|
enemy_lost_units = QGroupBox(f"{self.debriefing.enemy_country}'s lost units:")
|
|
enemy_lost_units.setLayout(LossGrid(debriefing, player=False))
|
|
layout.addWidget(enemy_lost_units)
|
|
|
|
okay = QPushButton("Okay")
|
|
okay.clicked.connect(self.close)
|
|
layout.addWidget(okay)
|