mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
The new class PurchaseGroup coming in with commit 9bb986c was not initiallized correctly. This causes the bug that the update function is not working when you for example open the AircraftRecruitmentMenu press "+" or "-", close the dialog and then open ArmorRecruitmentMenu. If you then want to buy or sell the update function will raise an error "Internal C++ Object Already Deleted".
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
from PySide2.QtCore import Qt
|
|
from PySide2.QtWidgets import (
|
|
QFrame,
|
|
QGridLayout,
|
|
QScrollArea,
|
|
QVBoxLayout,
|
|
QWidget,
|
|
)
|
|
|
|
from game.dcs.groundunittype import GroundUnitType
|
|
from game.theater import ControlPoint
|
|
from qt_ui.models import GameModel
|
|
from qt_ui.windows.basemenu.QRecruitBehaviour import QRecruitBehaviour
|
|
|
|
|
|
class QArmorRecruitmentMenu(QFrame, QRecruitBehaviour):
|
|
def __init__(self, cp: ControlPoint, game_model: GameModel):
|
|
QFrame.__init__(self)
|
|
self.cp = cp
|
|
self.game_model = game_model
|
|
self.purchase_groups = {}
|
|
self.bought_amount_labels = {}
|
|
self.existing_units_labels = {}
|
|
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
main_layout = QVBoxLayout()
|
|
|
|
scroll_content = QWidget()
|
|
task_box_layout = QGridLayout()
|
|
scroll_content.setLayout(task_box_layout)
|
|
row = 0
|
|
|
|
unit_types = list(
|
|
set(self.game_model.game.faction_for(player=True).ground_units)
|
|
)
|
|
unit_types.sort(key=lambda u: u.name)
|
|
for row, unit_type in enumerate(unit_types):
|
|
self.add_purchase_row(unit_type, task_box_layout, row)
|
|
stretch = QVBoxLayout()
|
|
stretch.addStretch()
|
|
task_box_layout.addLayout(stretch, row, 0)
|
|
|
|
scroll_content.setLayout(task_box_layout)
|
|
scroll = QScrollArea()
|
|
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
|
|
scroll.setWidgetResizable(True)
|
|
scroll.setWidget(scroll_content)
|
|
main_layout.addWidget(scroll)
|
|
self.setLayout(main_layout)
|
|
|
|
def enable_purchase(self, unit_type: GroundUnitType) -> bool:
|
|
if not super().enable_purchase(unit_type):
|
|
return False
|
|
return self.cp.has_ground_unit_source(self.game_model.game)
|
|
|
|
def enable_sale(self, unit_type: GroundUnitType) -> bool:
|
|
return self.pending_deliveries.pending_orders(unit_type) > 0
|