From 0e2a449553c50873840385f8723c65a66de1432a Mon Sep 17 00:00:00 2001 From: Khopa Date: Wed, 23 Sep 2020 00:39:01 +0200 Subject: [PATCH] Fixes to Buy/Sell sam UI --- .../base_defenses/QBaseDefenseGroupInfo.py | 51 +++++++++++++------ .../base_defenses/QBaseInformation.py | 1 - .../windows/groundobject/QGroundObjectMenu.py | 11 ++-- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/qt_ui/windows/basemenu/base_defenses/QBaseDefenseGroupInfo.py b/qt_ui/windows/basemenu/base_defenses/QBaseDefenseGroupInfo.py index 4ace3577..bafd70ee 100644 --- a/qt_ui/windows/basemenu/base_defenses/QBaseDefenseGroupInfo.py +++ b/qt_ui/windows/basemenu/base_defenses/QBaseDefenseGroupInfo.py @@ -1,5 +1,5 @@ from PySide2.QtCore import Qt -from PySide2.QtWidgets import QGridLayout, QLabel, QGroupBox, QPushButton +from PySide2.QtWidgets import QGridLayout, QLabel, QGroupBox, QPushButton, QVBoxLayout from qt_ui.uiconstants import VEHICLES_ICONS from qt_ui.windows.groundobject.QGroundObjectMenu import QGroundObjectMenu @@ -8,18 +8,40 @@ from theater import ControlPoint, TheaterGroundObject class QBaseDefenseGroupInfo(QGroupBox): - def __init__(self, cp:ControlPoint, ground_object: TheaterGroundObject, game): + def __init__(self, cp: ControlPoint, ground_object: TheaterGroundObject, game): super(QBaseDefenseGroupInfo, self).__init__("Group : " + ground_object.obj_name) self.ground_object = ground_object self.cp = cp self.game = game self.buildings = game.theater.find_ground_objects_by_obj_name(self.ground_object.obj_name) + + self.main_layout = QVBoxLayout() + self.unit_layout = QGridLayout() + self.init_ui() - def init_ui(self): + + self.buildLayout() + manage_button = QPushButton("Manage") + manage_button.setProperty("style", "btn-success") + manage_button.setMaximumWidth(180) + manage_button.clicked.connect(self.onManage) + + self.main_layout.addLayout(self.unit_layout) + self.main_layout.addWidget(manage_button, 0, Qt.AlignLeft) + + self.setLayout(self.main_layout) + + def buildLayout(self): unit_dict = {} - layout = QGridLayout() + for i in range(self.unit_layout.count()): + item = self.unit_layout.itemAt(i) + if item is not None and item.widget() is not None: + self.unit_layout.removeItem(item) + item.widget().setParent(None) + item.widget().deleteLater() + for g in self.ground_object.groups: for u in g.units: if u.type in unit_dict.keys(): @@ -32,21 +54,18 @@ class QBaseDefenseGroupInfo(QGroupBox): if k in VEHICLES_ICONS.keys(): icon.setPixmap(VEHICLES_ICONS[k]) else: - icon.setText("" + k[:9] + "") + icon.setText("" + k[:8] + "") icon.setProperty("style", "icon-armor") - layout.addWidget(icon, i, 0) - layout.addWidget(QLabel(str(v) + " x " + "" + k + ""), i, 1) + self.unit_layout.addWidget(icon, i, 0) + self.unit_layout.addWidget(QLabel(str(v) + " x " + "" + k + ""), i, 1) i = i + 1 - manage_button = QPushButton("Manage") - manage_button.setProperty("style", "btn-success") - manage_button.setMaximumWidth(180) - manage_button.clicked.connect(self.onManage) - layout.addWidget(manage_button, i, 0, Qt.AlignLeft) - self.setLayout(layout) + self.setLayout(self.main_layout) def onManage(self): - self.editionMenu = QGroundObjectMenu(self.window(), self.ground_object, self.buildings, self.cp, self.game) - self.editionMenu.show() - + self.edition_menu = QGroundObjectMenu(self.window(), self.ground_object, self.buildings, self.cp, self.game) + self.edition_menu.show() + self.edition_menu.changed.connect(self.onEdition) + def onEdition(self): + self.buildLayout() \ No newline at end of file diff --git a/qt_ui/windows/basemenu/base_defenses/QBaseInformation.py b/qt_ui/windows/basemenu/base_defenses/QBaseInformation.py index c98113b6..f5325887 100644 --- a/qt_ui/windows/basemenu/base_defenses/QBaseInformation.py +++ b/qt_ui/windows/basemenu/base_defenses/QBaseInformation.py @@ -23,7 +23,6 @@ class QBaseInformation(QFrame): scroll_content = QWidget() task_box_layout = QGridLayout() scroll_content.setLayout(task_box_layout) - row = 0 for g in self.cp.ground_objects: if g.airbase_group: diff --git a/qt_ui/windows/groundobject/QGroundObjectMenu.py b/qt_ui/windows/groundobject/QGroundObjectMenu.py index 6b8c9ed1..6d28c357 100644 --- a/qt_ui/windows/groundobject/QGroundObjectMenu.py +++ b/qt_ui/windows/groundobject/QGroundObjectMenu.py @@ -20,6 +20,8 @@ from theater import ControlPoint, TheaterGroundObject class QGroundObjectMenu(QDialog): + changed = QtCore.Signal() + def __init__(self, parent, ground_object: TheaterGroundObject, buildings:[], cp: ControlPoint, game: Game): super(QGroundObjectMenu, self).__init__(parent) self.setMinimumWidth(350) @@ -64,7 +66,7 @@ class QGroundObjectMenu(QDialog): self.actionLayout.addWidget(self.sell_all_button) self.actionLayout.addWidget(self.buy_replace) - if self.cp.captured: + if self.cp.captured and self.ground_object.dcs_identifier == "AA": self.mainLayout.addLayout(self.actionLayout) self.setLayout(self.mainLayout) @@ -132,12 +134,13 @@ class QGroundObjectMenu(QDialog): self.actionLayout.addWidget(self.sell_all_button) self.actionLayout.addWidget(self.buy_replace) - if self.cp.captured: + if self.cp.captured and self.ground_object.dcs_identifier == "AA": self.mainLayout.addLayout(self.actionLayout) except Exception as e: print(e) self.update_total_value() + self.changed.emit() def update_total_value(self): total_value = 0 @@ -169,6 +172,7 @@ class QGroundObjectMenu(QDialog): logging.info("Repaired unit : " + str(unit.id) + " " + str(unit.type)) self.do_refresh_layout() + self.changed.emit() def sell_all(self): self.update_total_value() @@ -183,9 +187,6 @@ class QGroundObjectMenu(QDialog): self.subwindow.show() - def closeEvent(self, closeEvent: QCloseEvent): - pass - class QBuyGroupForGroundObjectDialog(QDialog):