dcs_liberation/qt_ui/windows/QUnitInfoWindow.py
Dan Albert 4a3ef42e67 Wrap the pydcs FlyingType in our own AircraftType.
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.
2021-06-12 20:13:45 -07:00

148 lines
5.8 KiB
Python

from typing import Type, Union
import dcs
from PySide2.QtCore import Qt
from PySide2.QtGui import QIcon
from PySide2.QtWidgets import (
QDialog,
QGridLayout,
QLabel,
QTextBrowser,
QFrame,
)
from dcs.unittype import UnitType
import gen.flights.ai_flight_planner_db
from game import db
from game.dcs.aircrafttype import AircraftType
from game.game import Game
from gen.flights.flight import FlightType
from qt_ui.uiconstants import AIRCRAFT_BANNERS, VEHICLE_BANNERS
class QUnitInfoWindow(QDialog):
def __init__(
self, game: Game, unit_type: Union[AircraftType, Type[UnitType]]
) -> None:
super().__init__()
self.setModal(True)
self.game = game
self.unit_type = unit_type
if isinstance(unit_type, AircraftType):
self.name = unit_type.name
else:
self.name = db.unit_get_expanded_info(
self.game.player_country, self.unit_type, "name"
)
self.setWindowTitle(f"Unit Info: {self.name}")
self.setWindowIcon(QIcon("./resources/icon.png"))
self.setMinimumHeight(570)
self.setMaximumWidth(640)
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.initUi()
def initUi(self):
self.layout = QGridLayout()
header = QLabel(self)
header.setGeometry(0, 0, 720, 360)
pixmap = None
if (
dcs.planes.plane_map.get(self.unit_type.id) is not None
or dcs.helicopters.helicopter_map.get(self.unit_type.id) is not None
):
pixmap = AIRCRAFT_BANNERS.get(self.unit_type.id)
elif dcs.vehicles.vehicle_map.get(self.unit_type.id) is not None:
pixmap = VEHICLE_BANNERS.get(self.unit_type.id)
if pixmap is None:
pixmap = AIRCRAFT_BANNERS.get("Missing")
header.setPixmap(pixmap.scaled(header.width(), header.height()))
self.layout.addWidget(header, 0, 0)
self.gridLayout = QGridLayout()
# Build the topmost details grid.
self.details_grid = QFrame()
self.details_grid_layout = QGridLayout()
self.details_grid_layout.setMargin(0)
self.name_box = QLabel(
f"<b>Name:</b> {db.unit_get_expanded_info(self.game.player_country, self.unit_type, 'manufacturer')} {self.name}"
)
self.name_box.setProperty("style", "info-element")
self.country_box = QLabel(
f"<b>Country of Origin:</b> {db.unit_get_expanded_info(self.game.player_country, self.unit_type, 'country-of-origin')}"
)
self.country_box.setProperty("style", "info-element")
self.role_box = QLabel(
f"<b>Role:</b> {db.unit_get_expanded_info(self.game.player_country, self.unit_type, 'role')}"
)
self.role_box.setProperty("style", "info-element")
self.year_box = QLabel(
f"<b>Variant Introduction:</b> {db.unit_get_expanded_info(self.game.player_country, self.unit_type, 'year-of-variant-introduction')}"
)
self.year_box.setProperty("style", "info-element")
self.details_grid_layout.addWidget(self.name_box, 0, 0)
self.details_grid_layout.addWidget(self.country_box, 0, 1)
self.details_grid_layout.addWidget(self.role_box, 1, 0)
self.details_grid_layout.addWidget(self.year_box, 1, 1)
self.details_grid.setLayout(self.details_grid_layout)
self.gridLayout.addWidget(self.details_grid, 1, 0)
# If it's an aircraft, include the task list.
if (
dcs.planes.plane_map.get(self.unit_type.id) is not None
or dcs.helicopters.helicopter_map.get(self.unit_type.id) is not None
):
self.tasks_box = QLabel(
f"<b>In-Game Tasks:</b> {self.generateAircraftTasks()}"
)
self.tasks_box.setProperty("style", "info-element")
self.gridLayout.addWidget(self.tasks_box, 2, 0)
# Finally, add the description box.
self.details_text = QTextBrowser()
self.details_text.setProperty("style", "info-desc")
self.details_text.setText(
db.unit_get_expanded_info(self.game.player_country, self.unit_type, "text")
)
self.gridLayout.addWidget(self.details_text, 3, 0)
self.layout.addLayout(self.gridLayout, 1, 0)
self.setLayout(self.layout)
def generateAircraftTasks(self) -> str:
aircraft_tasks = ""
if self.unit_type in gen.flights.ai_flight_planner_db.CAP_CAPABLE:
aircraft_tasks = (
aircraft_tasks
+ f"{FlightType.BARCAP}, {FlightType.ESCORT}, {FlightType.INTERCEPTION}, {FlightType.SWEEP}, {FlightType.TARCAP}, "
)
if self.unit_type in gen.flights.ai_flight_planner_db.CAS_CAPABLE:
aircraft_tasks = (
aircraft_tasks
+ f"{FlightType.CAS}, {FlightType.BAI}, {FlightType.OCA_AIRCRAFT}, "
)
if self.unit_type in gen.flights.ai_flight_planner_db.SEAD_CAPABLE:
aircraft_tasks = aircraft_tasks + f"{FlightType.SEAD}, "
if self.unit_type in gen.flights.ai_flight_planner_db.DEAD_CAPABLE:
aircraft_tasks = aircraft_tasks + f"{FlightType.DEAD}, "
if self.unit_type in gen.flights.ai_flight_planner_db.ANTISHIP_CAPABLE:
aircraft_tasks = aircraft_tasks + f"{FlightType.ANTISHIP}, "
if self.unit_type in gen.flights.ai_flight_planner_db.RUNWAY_ATTACK_CAPABLE:
aircraft_tasks = aircraft_tasks + f"{FlightType.OCA_RUNWAY}, "
if self.unit_type in gen.flights.ai_flight_planner_db.STRIKE_CAPABLE:
aircraft_tasks = aircraft_tasks + f"{FlightType.STRIKE}, "
if self.unit_type in gen.flights.ai_flight_planner_db.REFUELING_CAPABALE:
aircraft_tasks = aircraft_tasks + f"{FlightType.REFUELING}, "
return aircraft_tasks[:-2]