mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Cleanups in map object UI.
* Fix the context menu * Remove unnecessary overrides * Clean up formatting/naming * Factor out base class for shared behavior
This commit is contained in:
@@ -1,33 +1,37 @@
|
||||
from PySide2.QtCore import QPoint, QRect, QPointF, Qt
|
||||
from PySide2.QtGui import QPainter, QBrush
|
||||
from PySide2.QtWidgets import QGraphicsRectItem, QGraphicsItem, QGraphicsSceneHoverEvent, QGraphicsSceneMouseEvent
|
||||
from typing import List, Optional
|
||||
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game import db, Game
|
||||
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(QGraphicsRectItem):
|
||||
|
||||
def __init__(self, parent, x: float, y: float, w: float, h: float, cp: ControlPoint, model: TheaterGroundObject, game:Game, buildings=[]):
|
||||
super(QMapGroundObject, self).__init__(x, y, w, h)
|
||||
class QMapGroundObject(QMapObject):
|
||||
def __init__(self, parent, x: float, y: float, w: float, h: float,
|
||||
cp: ControlPoint, model: TheaterGroundObject, game: Game,
|
||||
buildings: Optional[List[TheaterGroundObject]] = None) -> None:
|
||||
super().__init__(x, y, w, h)
|
||||
self.model = model
|
||||
self.cp = cp
|
||||
self.parent = parent
|
||||
self.game = game
|
||||
self.setAcceptHoverEvents(True)
|
||||
self.setZValue(2)
|
||||
self.buildings = buildings
|
||||
self.buildings = buildings if buildings is not None else []
|
||||
self.setFlag(QGraphicsItem.ItemIgnoresTransformations, False)
|
||||
self.ground_object_dialog: Optional[QGroundObjectMenu] = None
|
||||
|
||||
if len(self.model.groups) > 0:
|
||||
units = {}
|
||||
for g in self.model.groups:
|
||||
print(g)
|
||||
for u in g.units:
|
||||
if u.type in units.keys():
|
||||
if u.type in units:
|
||||
units[u.type] = units[u.type]+1
|
||||
else:
|
||||
units[u.type] = 1
|
||||
@@ -42,14 +46,9 @@ class QMapGroundObject(QGraphicsRectItem):
|
||||
tooltip = tooltip + str(building.dcs_identifier) + "\n"
|
||||
self.setToolTip(tooltip[:-1])
|
||||
|
||||
def mousePressEvent(self, event:QGraphicsSceneMouseEvent):
|
||||
self.openEditionMenu()
|
||||
|
||||
def paint(self, painter, option, widget=None):
|
||||
#super(QMapControlPoint, self).paint(painter, option, widget)
|
||||
|
||||
playerIcons = "_blue"
|
||||
enemyIcons = ""
|
||||
def paint(self, painter, option, widget=None) -> None:
|
||||
player_icons = "_blue"
|
||||
enemy_icons = ""
|
||||
|
||||
if self.parent.get_display_rule("go"):
|
||||
painter.save()
|
||||
@@ -58,7 +57,8 @@ class QMapGroundObject(QGraphicsRectItem):
|
||||
if cat == "aa" and self.model.sea_object:
|
||||
cat = "ship"
|
||||
|
||||
rect = QRect(option.rect.x()+2,option.rect.y(),option.rect.width()-2,option.rect.height())
|
||||
rect = QRect(option.rect.x() + 2, option.rect.y(),
|
||||
option.rect.width() - 2, option.rect.height())
|
||||
|
||||
is_dead = self.model.is_dead
|
||||
for building in self.buildings:
|
||||
@@ -67,16 +67,16 @@ class QMapGroundObject(QGraphicsRectItem):
|
||||
break
|
||||
|
||||
if not is_dead and not self.cp.captured:
|
||||
painter.drawPixmap(rect, CONST.ICONS[cat + enemyIcons])
|
||||
painter.drawPixmap(rect, const.ICONS[cat + enemy_icons])
|
||||
elif not is_dead:
|
||||
painter.drawPixmap(rect, CONST.ICONS[cat + playerIcons])
|
||||
painter.drawPixmap(rect, const.ICONS[cat + player_icons])
|
||||
else:
|
||||
painter.drawPixmap(rect, CONST.ICONS["destroyed"])
|
||||
painter.drawPixmap(rect, const.ICONS["destroyed"])
|
||||
|
||||
self.drawHealthGauge(painter, option)
|
||||
self.draw_health_gauge(painter, option)
|
||||
painter.restore()
|
||||
|
||||
def drawHealthGauge(self, painter, option):
|
||||
def draw_health_gauge(self, painter, option) -> None:
|
||||
units_alive = 0
|
||||
units_dead = 0
|
||||
|
||||
@@ -97,22 +97,18 @@ class QMapGroundObject(QGraphicsRectItem):
|
||||
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 hoverEnterEvent(self, event: QGraphicsSceneHoverEvent):
|
||||
self.update()
|
||||
self.setCursor(Qt.PointingHandCursor)
|
||||
|
||||
def mouseMoveEvent(self, event:QGraphicsSceneMouseEvent):
|
||||
self.update()
|
||||
self.setCursor(Qt.PointingHandCursor)
|
||||
|
||||
def hoverLeaveEvent(self, event: QGraphicsSceneHoverEvent):
|
||||
self.update()
|
||||
|
||||
def openEditionMenu(self):
|
||||
self.editionMenu = QGroundObjectMenu(self.window(), self.model, self.buildings, self.cp, self.game)
|
||||
self.editionMenu.show()
|
||||
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.model,
|
||||
self.buildings,
|
||||
self.cp,
|
||||
self.game
|
||||
)
|
||||
self.ground_object_dialog.show()
|
||||
|
||||
Reference in New Issue
Block a user