diff --git a/changelog.md b/changelog.md index 7a105b53..d138bf04 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,7 @@ Saves from 4.x are not compatible with 5.0. * **[Kneeboard]** Minimum required fuel estimates have been added to the kneeboard for aircraft with supporting data (currently only the Hornet). * **[Kneeboard]** QNH (pressure MSL) and temperature have been added to the kneeboard. * **[New Game Wizard]** Can now customize the player's air wing before campaign start to disable or rename squadrons. +* **[UI]** Sell Button for aircraft will be disabled if there are no units available to be sold or all are already assigned to a mission ## Fixes diff --git a/qt_ui/windows/basemenu/QRecruitBehaviour.py b/qt_ui/windows/basemenu/QRecruitBehaviour.py index 77b0258b..21684682 100644 --- a/qt_ui/windows/basemenu/QRecruitBehaviour.py +++ b/qt_ui/windows/basemenu/QRecruitBehaviour.py @@ -80,7 +80,13 @@ class PurchaseGroup(QGroupBox): def update_state(self) -> None: self.buy_button.setEnabled(self.recruiter.enable_purchase(self.unit_type)) + self.buy_button.setToolTip( + self.recruiter.purchase_tooltip(self.buy_button.isEnabled()) + ) self.sell_button.setEnabled(self.recruiter.enable_sale(self.unit_type)) + self.sell_button.setToolTip( + self.recruiter.sell_tooltip(self.sell_button.isEnabled()) + ) self.amount_bought.setText(f"{self.pending_units}") @@ -223,6 +229,18 @@ class QRecruitBehaviour: def enable_sale(self, unit_type: UnitType) -> bool: return True + def purchase_tooltip(self, is_enabled: bool) -> str: + if is_enabled: + return "Buy unit. Use Shift or Ctrl key to buy multiple units at once." + else: + return "Unit can not be bought." + + def sell_tooltip(self, is_enabled: bool) -> str: + if is_enabled: + return "Sell unit. Use Shift or Ctrl key to buy multiple units at once." + else: + return "Unit can not be sold." + def info(self, unit_type: UnitType) -> None: self.info_window = QUnitInfoWindow(self.game_model.game, unit_type) self.info_window.show() diff --git a/qt_ui/windows/basemenu/airfield/QAircraftRecruitmentMenu.py b/qt_ui/windows/basemenu/airfield/QAircraftRecruitmentMenu.py index e435fd75..88ddbffd 100644 --- a/qt_ui/windows/basemenu/airfield/QAircraftRecruitmentMenu.py +++ b/qt_ui/windows/basemenu/airfield/QAircraftRecruitmentMenu.py @@ -85,9 +85,13 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour): return True def enable_sale(self, unit_type: AircraftType) -> bool: - if not self.cp.can_operate(unit_type): - return False - return True + return self.can_be_sold(unit_type) + + def sell_tooltip(self, is_enabled: bool) -> str: + if is_enabled: + return "Sell unit. Use Shift or Ctrl key to sell multiple units at once." + else: + return "Can not be sold because either no aircraft are available or are already assigned to a mission." def buy(self, unit_type: AircraftType) -> bool: if self.maximum_units > 0: @@ -112,24 +116,32 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour): self.hangar_status.update_label() return True + def can_be_sold(self, unit_type: AircraftType) -> bool: + inventory = self.game_model.game.aircraft_inventory.for_control_point(self.cp) + pending_deliveries = self.pending_deliveries.units.get(unit_type, 0) + return self.cp.can_operate(unit_type) and ( + pending_deliveries > 0 or inventory.available(unit_type) > 0 + ) + def sell(self, unit_type: AircraftType) -> bool: # Don't need to remove aircraft from the inventory if we're canceling # orders. - if self.pending_deliveries.units.get(unit_type, 0) <= 0: - global_inventory = self.game_model.game.aircraft_inventory - inventory = global_inventory.for_control_point(self.cp) - try: - inventory.remove_aircraft(unit_type, 1) - except ValueError: - QMessageBox.critical( - self, - "Could not sell aircraft", - f"Attempted to sell one {unit_type} at {self.cp.name} " - "but none are available. Are all aircraft currently " - "assigned to a mission?", - QMessageBox.Ok, - ) - return False + if not self.can_be_sold(unit_type): + QMessageBox.critical( + self, + "Could not sell aircraft", + f"Attempted to sell one {unit_type} at {self.cp.name} " + "but none are available. Are all aircraft currently " + "assigned to a mission?", + QMessageBox.Ok, + ) + return False + + inventory = self.game_model.game.aircraft_inventory.for_control_point(self.cp) + pending_deliveries = self.pending_deliveries.units.get(unit_type, 0) + if pending_deliveries <= 0 < inventory.available(unit_type): + inventory.remove_aircraft(unit_type, 1) + super().sell(unit_type) self.hangar_status.update_label()