mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Show aircraft type in the squadron list.
https://github.com/dcs-liberation/dcs_liberation/issues/276
This commit is contained in:
parent
2f8656d54f
commit
57a2457050
@ -38,6 +38,7 @@ class Pilot:
|
||||
class Squadron:
|
||||
name: str
|
||||
nickname: str
|
||||
country: str
|
||||
role: str
|
||||
aircraft: Type[FlyingType]
|
||||
mission_types: Tuple[FlightType, ...]
|
||||
@ -104,6 +105,7 @@ class Squadron:
|
||||
return Squadron(
|
||||
name=data["name"],
|
||||
nickname=data["nickname"],
|
||||
country=game.country_for(player),
|
||||
role=data["role"],
|
||||
aircraft=unit_type,
|
||||
mission_types=tuple(FlightType.from_name(n) for n in data["mission_types"]),
|
||||
@ -127,6 +129,7 @@ class AirWing:
|
||||
Squadron(
|
||||
name=f"Squadron {num + 1:03}",
|
||||
nickname=self.random_nickname(),
|
||||
country=game.country_for(player),
|
||||
role="Flying Squadron",
|
||||
aircraft=aircraft,
|
||||
mission_types=tuple(FlightType),
|
||||
|
||||
@ -398,8 +398,11 @@ class AirWingModel(QAbstractListModel):
|
||||
return squadron.name
|
||||
|
||||
@staticmethod
|
||||
def icon_for_squadron(_squadron: Squadron) -> Optional[QIcon]:
|
||||
def icon_for_squadron(squadron: Squadron) -> Optional[QIcon]:
|
||||
"""Returns the icon that should be displayed for the squadron."""
|
||||
name = db.unit_type_name(squadron.aircraft)
|
||||
if name in AIRCRAFT_ICONS:
|
||||
return QIcon(AIRCRAFT_ICONS[name])
|
||||
return None
|
||||
|
||||
def squadron_at_index(self, index: QModelIndex) -> Squadron:
|
||||
|
||||
@ -4,6 +4,7 @@ from PySide2.QtCore import (
|
||||
QItemSelectionModel,
|
||||
QModelIndex,
|
||||
Qt,
|
||||
QSize,
|
||||
)
|
||||
from PySide2.QtWidgets import (
|
||||
QAbstractItemView,
|
||||
@ -12,6 +13,7 @@ from PySide2.QtWidgets import (
|
||||
QVBoxLayout,
|
||||
)
|
||||
|
||||
from game import db
|
||||
from game.squadrons import Squadron
|
||||
from qt_ui.delegates import TwoColumnRowDelegate
|
||||
from qt_ui.models import GameModel, AirWingModel, SquadronModel
|
||||
@ -20,7 +22,7 @@ from qt_ui.windows.SquadronDialog import SquadronDialog
|
||||
|
||||
class SquadronDelegate(TwoColumnRowDelegate):
|
||||
def __init__(self, air_wing_model: AirWingModel) -> None:
|
||||
super().__init__(rows=2, columns=1, font_size=12)
|
||||
super().__init__(rows=2, columns=2, font_size=12)
|
||||
self.air_wing_model = air_wing_model
|
||||
|
||||
@staticmethod
|
||||
@ -28,9 +30,14 @@ class SquadronDelegate(TwoColumnRowDelegate):
|
||||
return index.data(AirWingModel.SquadronRole)
|
||||
|
||||
def text_for(self, index: QModelIndex, row: int, column: int) -> str:
|
||||
if row == 0:
|
||||
if (row, column) == (0, 0):
|
||||
return self.air_wing_model.data(index, Qt.DisplayRole)
|
||||
elif row == 1:
|
||||
elif (row, column) == (0, 1):
|
||||
squadron = self.air_wing_model.data(index, AirWingModel.SquadronRole)
|
||||
return db.unit_get_expanded_info(
|
||||
squadron.country, squadron.aircraft, "name"
|
||||
)
|
||||
elif (row, column) == (1, 0):
|
||||
return self.squadron(index).nickname
|
||||
return ""
|
||||
|
||||
@ -43,6 +50,7 @@ class SquadronList(QListView):
|
||||
self.air_wing_model = air_wing_model
|
||||
self.dialog: Optional[SquadronDialog] = None
|
||||
|
||||
self.setIconSize(QSize(91, 24))
|
||||
self.setItemDelegate(SquadronDelegate(self.air_wing_model))
|
||||
self.setModel(self.air_wing_model)
|
||||
self.selectionModel().setCurrentIndex(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user