Enable sell button according to available aircraft

also added a tooltip which gives the user the hint that maybe the aircraft is assigned to mission and therefore the button is disabled
This commit is contained in:
RndName 2021-08-12 18:51:28 +02:00
parent ee8e8d4a9a
commit adeebbc422
No known key found for this signature in database
GPG Key ID: 5EF516FD9537F7C0
3 changed files with 49 additions and 18 deletions

View File

@ -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]** 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. * **[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. * **[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 ## Fixes

View File

@ -80,7 +80,13 @@ class PurchaseGroup(QGroupBox):
def update_state(self) -> None: def update_state(self) -> None:
self.buy_button.setEnabled(self.recruiter.enable_purchase(self.unit_type)) 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.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"<b>{self.pending_units}</b>") self.amount_bought.setText(f"<b>{self.pending_units}</b>")
@ -223,6 +229,18 @@ class QRecruitBehaviour:
def enable_sale(self, unit_type: UnitType) -> bool: def enable_sale(self, unit_type: UnitType) -> bool:
return True 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: def info(self, unit_type: UnitType) -> None:
self.info_window = QUnitInfoWindow(self.game_model.game, unit_type) self.info_window = QUnitInfoWindow(self.game_model.game, unit_type)
self.info_window.show() self.info_window.show()

View File

@ -85,9 +85,13 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
return True return True
def enable_sale(self, unit_type: AircraftType) -> bool: def enable_sale(self, unit_type: AircraftType) -> bool:
if not self.cp.can_operate(unit_type): return self.can_be_sold(unit_type)
return False
return True 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: def buy(self, unit_type: AircraftType) -> bool:
if self.maximum_units > 0: if self.maximum_units > 0:
@ -112,24 +116,32 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
self.hangar_status.update_label() self.hangar_status.update_label()
return True 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: def sell(self, unit_type: AircraftType) -> bool:
# Don't need to remove aircraft from the inventory if we're canceling # Don't need to remove aircraft from the inventory if we're canceling
# orders. # orders.
if self.pending_deliveries.units.get(unit_type, 0) <= 0: if not self.can_be_sold(unit_type):
global_inventory = self.game_model.game.aircraft_inventory QMessageBox.critical(
inventory = global_inventory.for_control_point(self.cp) self,
try: "Could not sell aircraft",
inventory.remove_aircraft(unit_type, 1) f"Attempted to sell one {unit_type} at {self.cp.name} "
except ValueError: "but none are available. Are all aircraft currently "
QMessageBox.critical( "assigned to a mission?",
self, QMessageBox.Ok,
"Could not sell aircraft", )
f"Attempted to sell one {unit_type} at {self.cp.name} " return False
"but none are available. Are all aircraft currently "
"assigned to a mission?", inventory = self.game_model.game.aircraft_inventory.for_control_point(self.cp)
QMessageBox.Ok, pending_deliveries = self.pending_deliveries.units.get(unit_type, 0)
) if pending_deliveries <= 0 < inventory.available(unit_type):
return False inventory.remove_aircraft(unit_type, 1)
super().sell(unit_type) super().sell(unit_type)
self.hangar_status.update_label() self.hangar_status.update_label()