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]** 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

View File

@ -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"<b>{self.pending_units}</b>")
@ -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()

View File

@ -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,15 +116,17 @@ 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:
if not self.can_be_sold(unit_type):
QMessageBox.critical(
self,
"Could not sell aircraft",
@ -130,6 +136,12 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
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()