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.
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
from collections import defaultdict
|
|
|
|
from PySide2.QtCore import Qt
|
|
from PySide2.QtWidgets import (
|
|
QFrame,
|
|
QGridLayout,
|
|
QGroupBox,
|
|
QLabel,
|
|
QVBoxLayout,
|
|
QScrollArea,
|
|
QWidget,
|
|
)
|
|
|
|
from game import Game, db
|
|
from game.theater import ControlPoint
|
|
|
|
|
|
class QIntelInfo(QFrame):
|
|
def __init__(self, cp: ControlPoint, game: Game):
|
|
super(QIntelInfo, self).__init__()
|
|
self.cp = cp
|
|
self.game = game
|
|
|
|
layout = QVBoxLayout()
|
|
scroll_content = QWidget()
|
|
intel_layout = QVBoxLayout()
|
|
|
|
units_by_task: dict[str, dict[str, int]] = defaultdict(lambda: defaultdict(int))
|
|
for unit_type, count in self.cp.base.aircraft.items():
|
|
if count:
|
|
task_type = unit_type.dcs_unit_type.task_default.name
|
|
units_by_task[task_type][unit_type.name] += count
|
|
|
|
units_by_task = {
|
|
task: units_by_task[task] for task in sorted(units_by_task.keys())
|
|
}
|
|
|
|
front_line_units = defaultdict(int)
|
|
for unit_type, count in self.cp.base.armor.items():
|
|
if count:
|
|
name = db.unit_get_expanded_info(
|
|
self.game.enemy_country, unit_type, "name"
|
|
)
|
|
front_line_units[name] += count
|
|
|
|
units_by_task["Front line units"] = front_line_units
|
|
for task, unit_types in units_by_task.items():
|
|
task_group = QGroupBox(task)
|
|
task_layout = QGridLayout()
|
|
task_group.setLayout(task_layout)
|
|
|
|
for row, (name, count) in enumerate(unit_types.items()):
|
|
task_layout.addWidget(QLabel(f"<b>{name}</b>"), row, 0)
|
|
task_layout.addWidget(QLabel(str(count)), row, 1)
|
|
|
|
intel_layout.addWidget(task_group)
|
|
|
|
scroll_content.setLayout(intel_layout)
|
|
scroll = QScrollArea()
|
|
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
|
|
scroll.setWidgetResizable(True)
|
|
scroll.setWidget(scroll_content)
|
|
|
|
layout.addWidget(scroll)
|
|
|
|
self.setLayout(layout)
|