dcs_liberation/qt_ui/widgets/map/QMapGroundObject.py
Dan Albert ff083942e8 Replace mission planning UI.
Mission planning has been completely redone. Missions are now planned
by right clicking the target area and choosing "New package".

A package can include multiple flights for the same objective. Right
now the automatic flight planner is only fragging single-flight
packages in the same manner that it used to, but that can be improved
now.

The air tasking order (ATO) is now the left bar of the main UI. This
shows every fragged package, and the flights in the selected package.
The info bar that was previously on the left is now a smaller bar at
the bottom of the screen. The old "Mission Planning" button is now
just the "Take Off" button.

The flight plan display no longer shows enemy flight plans. That could
be re-added if needed, probably with a difficulty/cheat option.

Aircraft inventories have been disassociated from the Planner class.
Aircraft inventories are now stored globally in the Game object.

Save games made prior to this update will not be compatible do to the
changes in how aircraft inventories and planned flights are stored.
2020-09-27 13:44:58 -07:00

115 lines
4.3 KiB
Python

from typing import List, Optional
from PySide2.QtCore import QRect
from PySide2.QtGui import QBrush
from PySide2.QtWidgets import QGraphicsItem
import qt_ui.uiconstants as const
from game import Game
from game.data.building_data import FORTIFICATION_BUILDINGS
from qt_ui.windows.groundobject.QGroundObjectMenu import QGroundObjectMenu
from theater import TheaterGroundObject, ControlPoint
from .QMapObject import QMapObject
class QMapGroundObject(QMapObject):
def __init__(self, parent, x: float, y: float, w: float, h: float,
control_point: ControlPoint,
ground_object: TheaterGroundObject, game: Game,
buildings: Optional[List[TheaterGroundObject]] = None) -> None:
super().__init__(x, y, w, h, mission_target=ground_object)
self.ground_object = ground_object
self.control_point = control_point
self.parent = parent
self.game = game
self.setZValue(2)
self.buildings = buildings if buildings is not None else []
self.setFlag(QGraphicsItem.ItemIgnoresTransformations, False)
self.ground_object_dialog: Optional[QGroundObjectMenu] = None
if self.ground_object.groups:
units = {}
for g in self.ground_object.groups:
for u in g.units:
if u.type in units:
units[u.type] = units[u.type]+1
else:
units[u.type] = 1
tooltip = "[" + self.ground_object.obj_name + "]" + "\n"
for unit in units.keys():
tooltip = tooltip + str(unit) + "x" + str(units[unit]) + "\n"
self.setToolTip(tooltip[:-1])
else:
tooltip = "[" + self.ground_object.obj_name + "]" + "\n"
for building in buildings:
if not building.is_dead:
tooltip = tooltip + str(building.dcs_identifier) + "\n"
self.setToolTip(tooltip[:-1])
def paint(self, painter, option, widget=None) -> None:
player_icons = "_blue"
enemy_icons = ""
if self.parent.get_display_rule("go"):
painter.save()
cat = self.ground_object.category
if cat == "aa" and self.ground_object.sea_object:
cat = "ship"
rect = QRect(option.rect.x() + 2, option.rect.y(),
option.rect.width() - 2, option.rect.height())
is_dead = self.ground_object.is_dead
for building in self.buildings:
if not building.is_dead:
is_dead = False
break
if not is_dead and not self.control_point.captured:
painter.drawPixmap(rect, const.ICONS[cat + enemy_icons])
elif not is_dead:
painter.drawPixmap(rect, const.ICONS[cat + player_icons])
else:
painter.drawPixmap(rect, const.ICONS["destroyed"])
self.draw_health_gauge(painter, option)
painter.restore()
def draw_health_gauge(self, painter, option) -> None:
units_alive = 0
units_dead = 0
if len(self.ground_object.groups) == 0:
for building in self.buildings:
if building.dcs_identifier in FORTIFICATION_BUILDINGS:
continue
if building.is_dead:
units_dead += 1
else:
units_alive += 1
for g in self.ground_object.groups:
units_alive += len(g.units)
if hasattr(g, "units_losts"):
units_dead += len(g.units_losts)
if units_dead + units_alive > 0:
ratio = float(units_alive)/(float(units_dead) + float(units_alive))
bar_height = ratio * option.rect.height()
painter.fillRect(option.rect.x(), option.rect.y(), 2,
option.rect.height(),
QBrush(const.COLORS["dark_red"]))
painter.fillRect(option.rect.x(), option.rect.y(), 2, bar_height,
QBrush(const.COLORS["green"]))
def on_click(self) -> None:
self.ground_object_dialog = QGroundObjectMenu(
self.window(),
self.ground_object,
self.buildings,
self.control_point,
self.game
)
self.ground_object_dialog.show()