From c2ebf61fd36f28f65da399bb39607635708cc728 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 20 Apr 2021 23:20:08 -0700 Subject: [PATCH] Disable cancel actions on enemy transfers. Decided to leave these in the menu as intel for the player, but the player can no longer cancel them. Fixes https://github.com/Khopa/dcs_liberation/issues/995 --- qt_ui/windows/PendingTransfersDialog.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/qt_ui/windows/PendingTransfersDialog.py b/qt_ui/windows/PendingTransfersDialog.py index 447f6437..ac671c86 100644 --- a/qt_ui/windows/PendingTransfersDialog.py +++ b/qt_ui/windows/PendingTransfersDialog.py @@ -139,6 +139,10 @@ class PendingTransfersList(QListView): def contextMenuEvent(self, event: QContextMenuEvent) -> None: index = self.indexAt(event.pos()) + if not index.isValid(): + return + if not self.transfer_model.transfer_at_index(index).player: + return menu = QMenu("Menu") @@ -181,15 +185,23 @@ class PendingTransfersDialog(QDialog): self.cancel_button = QPushButton("Cancel Transfer") self.cancel_button.setProperty("style", "btn-danger") self.cancel_button.clicked.connect(self.on_cancel_transfer) - self.cancel_button.setEnabled(self.transfer_model.rowCount() > 0) + self.cancel_button.setEnabled( + self.can_cancel(self.transfer_list.currentIndex()) + ) button_layout.addWidget(self.cancel_button) def on_cancel_transfer(self) -> None: """Cancels the selected transfer order.""" self.transfer_model.cancel_transfer_at_index(self.transfer_list.currentIndex()) + def can_cancel(self, index: QModelIndex) -> bool: + return self.transfer_model.transfer_at_index(index).player + def on_selection_changed( self, selected: QItemSelection, _deselected: QItemSelection ) -> None: """Updates the state of the delete button.""" - self.cancel_button.setEnabled(not selected.empty()) + if selected.empty(): + self.cancel_button.setEnabled(False) + return + self.cancel_button.setEnabled(self.can_cancel(selected.indexes()[0]))