mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Fix artifact on map when drawing events & improved base menu
This commit is contained in:
parent
1776452964
commit
c621e822dc
@ -21,4 +21,9 @@ QPushButton[style="btn-primary"]{
|
||||
QBaseMenu{
|
||||
background-color:#699245;
|
||||
color:white;
|
||||
}
|
||||
|
||||
QWidgte[style="baseMenuHeader"]{
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
}
|
||||
@ -27,6 +27,7 @@ class QLiberationMap(QGraphicsView):
|
||||
"cp": True,
|
||||
"go": True,
|
||||
"lines": True,
|
||||
"events": True,
|
||||
"ennemy_sam_ranges": True,
|
||||
"ally_sam_ranges": True
|
||||
}
|
||||
@ -200,6 +201,7 @@ class QLiberationMap(QGraphicsView):
|
||||
nonlocal occupied_rects
|
||||
point = self._transform_point(location)
|
||||
rect = QRect(point[0] - 16, point[1] - 16, 32, 32)
|
||||
print(rect)
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
@ -236,7 +238,7 @@ class QLiberationMap(QGraphicsView):
|
||||
location = self._frontline_center(event.from_cp, event.to_cp)
|
||||
|
||||
rect = _location_to_rect(location)
|
||||
scene.addItem(QMapEvent(self, rect.x(), rect.y(), rect.width(), rect.height(), event))
|
||||
scene.addItem(QMapEvent(self, rect.x(), rect.y(), 32, 32, event))
|
||||
|
||||
@staticmethod
|
||||
def set_display_rule(rule: str, value: bool):
|
||||
|
||||
@ -52,14 +52,10 @@ class QMapControlPoint(QGraphicsRectItem):
|
||||
self.update()
|
||||
|
||||
def contextMenuEvent(self, event: QGraphicsSceneContextMenuEvent):
|
||||
# TODO : improve this and add contextual actions (just a placholder for now)
|
||||
|
||||
openBaseMenu = QAction("Open base menu")
|
||||
openBaseMenu.triggered.connect(self.openBaseMenu)
|
||||
|
||||
menu = QMenu("Menu", self.parent)
|
||||
menu.addAction("Plan a strike on " + self.model.name + " airbase")
|
||||
menu.addAction("See available intel")
|
||||
menu.addAction(openBaseMenu)
|
||||
menu.exec_(event.screenPos())
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
from PySide2.QtGui import QPen
|
||||
from PySide2.QtWidgets import QGraphicsRectItem
|
||||
from PySide2.QtWidgets import QGraphicsRectItem, QGraphicsSceneMouseEvent
|
||||
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game.event import Event
|
||||
from qt_ui.windows.QBriefingWindow import QBriefingWindow
|
||||
from theater import TheaterGroundObject, ControlPoint
|
||||
|
||||
|
||||
@ -14,22 +15,29 @@ class QMapEvent(QGraphicsRectItem):
|
||||
self.parent = parent
|
||||
self.setAcceptHoverEvents(True)
|
||||
self.setZValue(2)
|
||||
print(x,y,w,h)
|
||||
self.setToolTip(str(self.gameEvent))
|
||||
|
||||
|
||||
def paint(self, painter, option, widget=None):
|
||||
|
||||
painter.save()
|
||||
if self.parent.get_display_rule("events"):
|
||||
painter.save()
|
||||
|
||||
if self.gameEvent.is_player_attacking:
|
||||
painter.setPen(QPen(brush=CONST.COLORS["blue"]))
|
||||
painter.setBrush(CONST.COLORS["blue"])
|
||||
else:
|
||||
painter.setPen(QPen(brush=CONST.COLORS["red"]))
|
||||
painter.setBrush(CONST.COLORS["red"])
|
||||
if self.gameEvent.is_player_attacking:
|
||||
painter.setPen(QPen(brush=CONST.COLORS["blue"]))
|
||||
painter.setBrush(CONST.COLORS["blue"])
|
||||
else:
|
||||
painter.setPen(QPen(brush=CONST.COLORS["red"]))
|
||||
painter.setBrush(CONST.COLORS["red"])
|
||||
|
||||
painter.drawRect(option.rect)
|
||||
painter.drawRect(option.rect)
|
||||
print(option.rect)
|
||||
painter.drawPixmap(option.rect, CONST.EVENT_ICONS[self.gameEvent.__class__])
|
||||
painter.restore()
|
||||
|
||||
painter.drawPixmap(option.rect, CONST.EVENT_ICONS[self.gameEvent.__class__])
|
||||
def mousePressEvent(self, event:QGraphicsSceneMouseEvent):
|
||||
self.openBriefing()
|
||||
|
||||
painter.restore()
|
||||
def openBriefing(self):
|
||||
self.briefing = QBriefingWindow(self.window(), self.gameEvent)
|
||||
self.briefing.show()
|
||||
@ -1,8 +1,10 @@
|
||||
from PySide2.QtCore import Qt
|
||||
from PySide2.QtGui import QWindow
|
||||
from PySide2.QtGui import QWindow, QCloseEvent
|
||||
from PySide2.QtWidgets import QHBoxLayout, QLabel, QWidget, QFrame, QDialog, QVBoxLayout, QGridLayout, QPushButton
|
||||
from dcs.unittype import UnitType
|
||||
|
||||
from game.event import UnitsDeliveryEvent
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
from theater import ControlPoint, CAP, Embarking, AirDefence, CAS, PinpointStrike, db
|
||||
from game import Game
|
||||
|
||||
@ -13,20 +15,42 @@ class QBaseMenu(QDialog):
|
||||
super(QBaseMenu, self).__init__(parent)
|
||||
self.cp = controlPoint
|
||||
self.game = game
|
||||
self.deliveryEvent = self.game.units_delivery_event(self.cp)
|
||||
|
||||
|
||||
if self.cp.captured:
|
||||
self.deliveryEvent = None
|
||||
for event in self.game.events:
|
||||
print(event.__class__)
|
||||
print(UnitsDeliveryEvent.__class__)
|
||||
if event.__class__ == UnitsDeliveryEvent and event.from_cp == self.cp:
|
||||
self.deliveryEvent = event
|
||||
break
|
||||
if not self.deliveryEvent:
|
||||
print("Rebuild event")
|
||||
self.deliveryEvent = self.game.units_delivery_event(self.cp)
|
||||
|
||||
self.setWindowFlags(Qt.WindowStaysOnTopHint)
|
||||
self.setMinimumSize(200,200)
|
||||
self.setMinimumSize(200, 200)
|
||||
self.setModal(True)
|
||||
self.initUi()
|
||||
|
||||
def initUi(self):
|
||||
|
||||
self.setWindowTitle(self.cp.name)
|
||||
|
||||
self.topLayoutWidget = QWidget()
|
||||
self.topLayout = QHBoxLayout()
|
||||
self.topLayout.setProperty("style", "baseMenuHeader")
|
||||
self.topLayout.addWidget(QLabel("<b>" + self.cp.name + "</b>"))
|
||||
self.topLayout.addWidget(
|
||||
QLabel("{} / {} / {}".format(self.cp.base.total_planes, self.cp.base.total_armor, self.cp.base.total_aa)))
|
||||
|
||||
title = QLabel("<b>" + self.cp.name + "</b>")
|
||||
title.setAlignment(Qt.AlignLeft | Qt.AlignTop)
|
||||
unitsPower = QLabel("{} / {} / {}".format(self.cp.base.total_planes, self.cp.base.total_armor, self.cp.base.total_aa))
|
||||
unitsPower.setAlignment(Qt.AlignLeft |Qt.AlignTop)
|
||||
|
||||
self.topLayout.addWidget(title)
|
||||
self.topLayout.addWidget(unitsPower)
|
||||
self.topLayout.setAlignment(Qt.AlignTop)
|
||||
self.topLayoutWidget.setProperty("style", "baseMenuHeader")
|
||||
self.topLayoutWidget.setLayout(self.topLayout)
|
||||
|
||||
units = {
|
||||
CAP: db.find_unittype(CAP, self.game.player_name),
|
||||
@ -37,65 +61,65 @@ class QBaseMenu(QDialog):
|
||||
}
|
||||
|
||||
self.mainLayout = QVBoxLayout()
|
||||
self.mainLayout.addLayout(self.topLayout)
|
||||
self.mainLayout.addWidget(self.topLayoutWidget)
|
||||
|
||||
print(units)
|
||||
tasks = list(units.keys())
|
||||
tasks_per_column = 3
|
||||
|
||||
self.unitLayout = QGridLayout()
|
||||
self.bought_amount_labels = {}
|
||||
|
||||
row = 0
|
||||
|
||||
def add_purchase_row(unit_type):
|
||||
|
||||
nonlocal row
|
||||
existing_units = self.cp.base.total_units_of_type(unit_type)
|
||||
scheduled_units = self.deliveryEvent.units.get(unit_type, 0)
|
||||
|
||||
unitName = QLabel("<b>" + db.unit_type_name(unit_type) + "</b>")
|
||||
amountBought = QLabel("{} ({})".format(existing_units, scheduled_units))
|
||||
self.bought_amount_labels[unit_type] = amountBought
|
||||
|
||||
price = QLabel("{}m".format(db.PRICES[unit_type]))
|
||||
|
||||
buy = QPushButton("+")
|
||||
buy.clicked.connect(lambda: self.buy(unit_type))
|
||||
|
||||
sell = QPushButton("-")
|
||||
sell.clicked.connect(lambda: self.sell(unit_type))
|
||||
|
||||
self.unitLayout.addWidget(unitName, row, 0)
|
||||
self.unitLayout.addWidget(amountBought, row, 1)
|
||||
self.unitLayout.addWidget(price, row, 2)
|
||||
self.unitLayout.addWidget(buy, row, 3)
|
||||
self.unitLayout.addWidget(sell, row, 4)
|
||||
|
||||
row = row + 1
|
||||
|
||||
if self.cp.captured:
|
||||
column = 0
|
||||
for i, tasks_column in [(i, tasks[idx:idx+tasks_per_column]) for i, idx in enumerate(range(0, len(tasks), tasks_per_column))]:
|
||||
row = 2
|
||||
|
||||
def purchase_row(unit_type, unit_price):
|
||||
layout = QHBoxLayout()
|
||||
existing_units = self.cp.base.total_units_of_type(unit_type)
|
||||
scheduled_units = self.deliveryEvent.units.get(unit_type, 0)
|
||||
for task_type in units.keys():
|
||||
|
||||
unitName = QLabel(db.unit_type_name(unit_type))
|
||||
amountBought = QLabel("{} ({})".format(existing_units, scheduled_units))
|
||||
self.bought_amount_labels[unit_type] = amountBought
|
||||
units_column = list(set(units[task_type]))
|
||||
if len(units_column) == 0: continue
|
||||
units_column.sort(key=lambda x: db.PRICES[x])
|
||||
|
||||
price = QLabel("{}m".format(unit_price))
|
||||
|
||||
buy = QPushButton("+")
|
||||
buy.clicked.connect(lambda: self.buy(unit_type))
|
||||
|
||||
sell = QPushButton("-")
|
||||
sell.clicked.connect(lambda: self.sell(unit_type))
|
||||
|
||||
layout.addWidget(unitName)
|
||||
layout.addWidget(amountBought)
|
||||
layout.addWidget(price)
|
||||
|
||||
layout.addWidget(buy)
|
||||
layout.addWidget(sell)
|
||||
|
||||
return layout
|
||||
|
||||
for task_type in tasks_column:
|
||||
QLabel("<b>{}</b>".format(db.task_name(task_type)))
|
||||
row += 1
|
||||
|
||||
units_column = list(set(units[task_type]))
|
||||
units_column.sort(key=lambda x: db.PRICES[x])
|
||||
for unit_type in units_column:
|
||||
layout = purchase_row(unit_type, db.PRICES[unit_type])
|
||||
self.mainLayout.addLayout(layout)
|
||||
|
||||
column += 5
|
||||
taskTypeLabel = QLabel("<b>{}</b>".format(db.task_name(task_type)))
|
||||
self.unitLayout.addWidget(taskTypeLabel, row, 0)
|
||||
row = row + 1
|
||||
|
||||
for unit_type in units_column:
|
||||
add_purchase_row(unit_type)
|
||||
|
||||
self.mainLayout.addLayout(self.unitLayout)
|
||||
self.setLayout(self.mainLayout)
|
||||
|
||||
|
||||
def _update_count_label(self, unit_type: UnitType):
|
||||
self.bought_amount_labels[unit_type].setText("({}{})".format(
|
||||
self.bought_amount_labels[unit_type].setText("{}{}".format(
|
||||
self.cp.base.total_units_of_type(unit_type),
|
||||
unit_type in self.deliveryEvent.units and ", bought {}".format(self.deliveryEvent.units[unit_type]) or ""
|
||||
unit_type in self.deliveryEvent.units and " ({})".format(self.deliveryEvent.units[unit_type]) or ""
|
||||
))
|
||||
|
||||
def buy(self, unit_type):
|
||||
@ -118,4 +142,7 @@ class QBaseMenu(QDialog):
|
||||
self.game.budget += price
|
||||
self.cp.base.commit_losses({unit_type: 1})
|
||||
|
||||
self._update_count_label(unit_type)
|
||||
self._update_count_label(unit_type)
|
||||
|
||||
def closeEvent(self, closeEvent:QCloseEvent):
|
||||
GameUpdateSignal.get_instance().updateGame(self.game)
|
||||
@ -1,17 +1,20 @@
|
||||
from PySide2.QtGui import QWindow
|
||||
from PySide2.QtWidgets import QHBoxLayout, QLabel, QWidget
|
||||
from PySide2.QtWidgets import QHBoxLayout, QLabel, QWidget, QDialog
|
||||
|
||||
|
||||
class QBriefingWindow(QWindow):
|
||||
class QBriefingWindow(QDialog):
|
||||
|
||||
def __init__(self, parent):
|
||||
def __init__(self, parent, event):
|
||||
super(QBriefingWindow, self).__init__(parent)
|
||||
self.gameEvent = event
|
||||
self.setWindowTitle("Briefing : " + str(event))
|
||||
self.setMinimumSize(200,200)
|
||||
self.setModal(True)
|
||||
self.initUi()
|
||||
|
||||
def initUi(self):
|
||||
|
||||
layout = QHBoxLayout()
|
||||
layout.addWidget(QLabel("TODO : This will be the briefing window"))
|
||||
|
||||
central_widget = QWidget()
|
||||
central_widget.setLayout(layout)
|
||||
self.setCentralWidget(central_widget)
|
||||
self.setLayout(layout)
|
||||
@ -110,9 +110,16 @@ class QLiberationWindow(QMainWindow):
|
||||
tg_line_visibility.toggled.connect(
|
||||
lambda: QLiberationMap.set_display_rule("lines", tg_line_visibility.isChecked()))
|
||||
|
||||
tg_event_visibility = QAction('Events', displayMenu)
|
||||
tg_event_visibility.setCheckable(True)
|
||||
tg_event_visibility.setChecked(True)
|
||||
tg_event_visibility.toggled.connect(
|
||||
lambda: QLiberationMap.set_display_rule("events", tg_event_visibility.isChecked()))
|
||||
|
||||
displayMenu.addAction(tg_go_visibility)
|
||||
displayMenu.addAction(tg_cp_visibility)
|
||||
displayMenu.addAction(tg_line_visibility)
|
||||
displayMenu.addAction(tg_event_visibility)
|
||||
|
||||
def newGame(self):
|
||||
wizard = NewGameWizard(self)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user