mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Refactor the sell unit changes as requested.
It works more simply now, and also doesn't immediately sell the unit. Also adds a matching UI dialog popup for selling too many ground units.
This commit is contained in:
@@ -61,13 +61,7 @@ class QRecruitBehaviour:
|
||||
unitName = QLabel("<b>" + db.unit_type_name_2(unit_type) + "</b>")
|
||||
unitName.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
|
||||
|
||||
sold_count = self.cp.base.sold_units.get(unit_type)
|
||||
if sold_count is None:
|
||||
sold_count = 0
|
||||
if sold_count > 0:
|
||||
existing_units = QLabel("<b>{} (-{})</b>".format(existing_units, sold_count))
|
||||
else:
|
||||
existing_units = QLabel(str(existing_units))
|
||||
existing_units = QLabel(str(existing_units))
|
||||
existing_units.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
|
||||
|
||||
amount_bought = QLabel("<b>{}</b>".format(str(scheduled_units)))
|
||||
@@ -123,17 +117,9 @@ class QRecruitBehaviour:
|
||||
unit_type in self.pending_deliveries.units and "{}".format(self.pending_deliveries.units[unit_type]) or "0"
|
||||
))
|
||||
|
||||
sold_count = self.cp.base.sold_units.get(unit_type)
|
||||
if sold_count is None:
|
||||
sold_count = 0
|
||||
if sold_count > 0:
|
||||
self.existing_units_labels[unit_type].setText("<b>{} (-{})</b>".format(
|
||||
self.cp.base.total_units_of_type(unit_type), self.cp.base.sold_units[unit_type]
|
||||
))
|
||||
else:
|
||||
self.existing_units_labels[unit_type].setText("<b>{}</b>".format(
|
||||
self.cp.base.total_units_of_type(unit_type)
|
||||
))
|
||||
self.existing_units_labels[unit_type].setText("<b>{}</b>".format(
|
||||
self.cp.base.total_units_of_type(unit_type)
|
||||
))
|
||||
|
||||
def update_available_budget(self) -> None:
|
||||
GameUpdateSignal.get_instance().updateBudget(self.game_model.game)
|
||||
@@ -141,16 +127,8 @@ class QRecruitBehaviour:
|
||||
def buy(self, unit_type: Type[UnitType]):
|
||||
price = db.PRICES[unit_type]
|
||||
if self.budget >= price:
|
||||
sold_count = self.cp.base.sold_units.get(unit_type)
|
||||
if sold_count is None:
|
||||
sold_count = 0
|
||||
if sold_count > 0:
|
||||
self.cp.base.sold_units[unit_type] -= 1
|
||||
self.cp.base.commision_units({unit_type: 1})
|
||||
self.budget -= price
|
||||
else:
|
||||
self.pending_deliveries.order({unit_type: 1})
|
||||
self.budget -= price
|
||||
self.pending_deliveries.order({unit_type: 1})
|
||||
self.budget -= price
|
||||
else:
|
||||
# TODO : display modal warning
|
||||
logging.info("Not enough money !")
|
||||
@@ -158,18 +136,12 @@ class QRecruitBehaviour:
|
||||
self.update_available_budget()
|
||||
|
||||
def sell(self, unit_type):
|
||||
if self.pending_deliveries.units.get(unit_type, 0) > 0:
|
||||
if self.pending_deliveries.units.get(unit_type, 0) > 0 or self.cp.base.total_units_of_type(unit_type) > 0:
|
||||
price = db.PRICES[unit_type]
|
||||
self.budget += price
|
||||
self.pending_deliveries.units[unit_type] = self.pending_deliveries.units[unit_type] - 1
|
||||
self.pending_deliveries.sell({unit_type: 1})
|
||||
if self.pending_deliveries.units[unit_type] == 0:
|
||||
del self.pending_deliveries.units[unit_type]
|
||||
elif self.cp.base.total_units_of_type(unit_type) > 0:
|
||||
price = db.PRICES[unit_type]
|
||||
self.budget += price
|
||||
self.cp.base.commit_losses({unit_type: 1})
|
||||
self.cp.base.sold_units[unit_type] += 1
|
||||
|
||||
self._update_count_label(unit_type)
|
||||
self.update_available_budget()
|
||||
|
||||
|
||||
@@ -85,8 +85,6 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
||||
self.setLayout(main_layout)
|
||||
|
||||
def buy(self, unit_type):
|
||||
global_inventory = self.game_model.game.aircraft_inventory
|
||||
inventory = global_inventory.for_control_point(self.cp)
|
||||
if self.maximum_units > 0:
|
||||
if self.cp.unclaimed_parking(self.game_model.game) <= 0:
|
||||
logging.debug(f"No space for additional aircraft at {self.cp}.")
|
||||
@@ -94,29 +92,19 @@ class QAircraftRecruitmentMenu(QFrame, QRecruitBehaviour):
|
||||
self, "No space for additional aircraft",
|
||||
f"There is no parking space left at {self.cp.name} to accommodate another plane.", QMessageBox.Ok)
|
||||
return
|
||||
sold_count = self.cp.base.sold_units.get(unit_type)
|
||||
if sold_count is None:
|
||||
sold_count = 0
|
||||
if sold_count > 0:
|
||||
inventory.add_aircraft(unit_type, 1)
|
||||
super().buy(unit_type)
|
||||
self.hangar_status.update_label()
|
||||
|
||||
def sell(self, unit_type: UnitType):
|
||||
# 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.id} at {self.cp.name} "
|
||||
"but none are available. Are all aircraft currently "
|
||||
"assigned to a mission?", QMessageBox.Ok)
|
||||
return
|
||||
if self.pending_deliveries.units.get(unit_type, 0) <= 0 - self.cp.base.total_units_of_type(unit_type):
|
||||
QMessageBox.critical(
|
||||
self, "Could not sell aircraft",
|
||||
f"Attempted to sell one {unit_type.id} at {self.cp.name} "
|
||||
"but none are available. Are all aircraft currently "
|
||||
"assigned to a mission?", QMessageBox.Ok)
|
||||
return
|
||||
super().sell(unit_type)
|
||||
self.hangar_status.update_label()
|
||||
|
||||
|
||||
@@ -5,8 +5,10 @@ from PySide2.QtWidgets import (
|
||||
QScrollArea,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
QMessageBox,
|
||||
)
|
||||
from dcs.task import PinpointStrike
|
||||
from dcs.unittype import FlyingType, UnitType
|
||||
|
||||
from game import db
|
||||
from game.theater import ControlPoint
|
||||
@@ -57,3 +59,15 @@ class QArmorRecruitmentMenu(QFrame, QRecruitBehaviour):
|
||||
scroll.setWidget(scroll_content)
|
||||
main_layout.addWidget(scroll)
|
||||
self.setLayout(main_layout)
|
||||
|
||||
def sell(self, unit_type: UnitType):
|
||||
# Don't need to remove aircraft from the inventory if we're canceling
|
||||
# orders.
|
||||
if self.pending_deliveries.units.get(unit_type, 0) <= 0 - self.cp.base.total_units_of_type(unit_type):
|
||||
QMessageBox.critical(
|
||||
self, "Could not sell ground unit",
|
||||
f"Attempted to sell one {unit_type.id} at {self.cp.name} "
|
||||
"but none are available.", QMessageBox.Ok)
|
||||
return
|
||||
super().sell(unit_type)
|
||||
self.hangar_status.update_label()
|
||||
Reference in New Issue
Block a user