mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
77 lines
2.9 KiB
Python
77 lines
2.9 KiB
Python
from PySide2.QtCore import QSortFilterProxyModel, Qt, QModelIndex
|
|
from PySide2.QtGui import QStandardItem, QStandardItemModel
|
|
from PySide2.QtWidgets import QComboBox, QCompleter
|
|
from game import Game
|
|
from gen import Conflict, FlightWaypointType, db
|
|
from gen.flights.flight import FlightWaypoint, PredefinedWaypointCategory
|
|
from qt_ui.widgets.combos.QFilteredComboBox import QFilteredComboBox
|
|
from theater import ControlPointType
|
|
|
|
|
|
class SEADTargetInfo:
|
|
|
|
def __init__(self):
|
|
self.name = ""
|
|
self.location = None
|
|
self.radars = []
|
|
self.threat_range = 0
|
|
self.detection_range = 0
|
|
|
|
class QSEADTargetSelectionComboBox(QFilteredComboBox):
|
|
|
|
def __init__(self, game: Game, parent=None):
|
|
super(QSEADTargetSelectionComboBox, self).__init__(parent)
|
|
self.game = game
|
|
self.find_possible_sead_targets()
|
|
|
|
def get_selected_target(self):
|
|
n = self.currentText()
|
|
for target in self.targets:
|
|
if target.name == n:
|
|
return target
|
|
|
|
def find_possible_sead_targets(self):
|
|
|
|
self.targets = []
|
|
i = 0
|
|
model = QStandardItemModel()
|
|
|
|
def add_model_item(i, model, target):
|
|
item = QStandardItem(target.name)
|
|
model.setItem(i, 0, item)
|
|
self.targets.append(target)
|
|
return i + 1
|
|
|
|
for cp in self.game.theater.controlpoints:
|
|
if cp.captured: continue
|
|
for g in cp.ground_objects:
|
|
|
|
radars = []
|
|
detection_range = 0
|
|
threat_range = 0
|
|
if g.dcs_identifier == "AA":
|
|
for group in g.groups:
|
|
for u in group.units:
|
|
utype = db.unit_type_from_name(u.type)
|
|
if hasattr(utype, "detection_range") and utype.detection_range > 1000:
|
|
if utype.detection_range > detection_range:
|
|
detection_range = utype.detection_range
|
|
radars.append(u)
|
|
if hasattr(utype, "threat_range"):
|
|
if utype.threat_range > threat_range:
|
|
threat_range = utype.threat_range
|
|
if len(radars) > 0:
|
|
tgt_info = SEADTargetInfo()
|
|
tgt_info.name = g.obj_name + " [" + ",".join([db.unit_type_from_name(u.type).id for u in radars]) + " ]"
|
|
if len(tgt_info.name) > 25:
|
|
tgt_info.name = g.obj_name + " [" + str(len(radars)) + " units]"
|
|
tgt_info.radars = radars
|
|
tgt_info.location = g
|
|
tgt_info.threat_range = threat_range
|
|
tgt_info.detection_range = detection_range
|
|
i = add_model_item(i, model, tgt_info)
|
|
|
|
self.setModel(model)
|
|
|
|
|