Fix budget mismatch in the UI.

Much of the UI was using the old budget which wasn't removed from Game
like it should have been when Coaltion was introduced. The UI displayed
(and in some cases pulled from) the starting budget rather than the real
budget.
This commit is contained in:
Dan Albert 2021-07-14 17:33:01 -07:00
parent b1b60f4286
commit 72c181a399
7 changed files with 23 additions and 25 deletions

View File

@ -107,8 +107,6 @@ class Game:
self.__culling_zones: List[Point] = [] self.__culling_zones: List[Point] = []
self.__destroyed_units: list[dict[str, Union[float, str]]] = [] self.__destroyed_units: list[dict[str, Union[float, str]]] = []
self.savepath = "" self.savepath = ""
self.budget = player_budget
self.enemy_budget = enemy_budget
self.current_unit_id = 0 self.current_unit_id = 0
self.current_group_id = 0 self.current_group_id = 0
self.name_generator = naming.namegen self.name_generator = naming.namegen

View File

@ -1,6 +1,7 @@
from PySide2.QtWidgets import QLabel, QHBoxLayout, QGroupBox, QPushButton from PySide2.QtWidgets import QLabel, QHBoxLayout, QGroupBox, QPushButton
import qt_ui.uiconstants as CONST import qt_ui.uiconstants as CONST
from game import Game
from game.income import Income from game.income import Income
from qt_ui.windows.finances.QFinancesMenu import QFinancesMenu from qt_ui.windows.finances.QFinancesMenu import QFinancesMenu
@ -10,7 +11,7 @@ class QBudgetBox(QGroupBox):
UI Component to display current budget and player's money UI Component to display current budget and player's money
""" """
def __init__(self, game): def __init__(self, game: Game):
super(QBudgetBox, self).__init__("Budget") super(QBudgetBox, self).__init__("Budget")
self.game = game self.game = game
@ -40,7 +41,7 @@ class QBudgetBox(QGroupBox):
return return
self.game = game self.game = game
self.setBudget(self.game.budget, Income(self.game, player=True).total) self.setBudget(self.game.blue.budget, Income(self.game, player=True).total)
self.finances.setEnabled(True) self.finances.setEnabled(True)
def openFinances(self): def openFinances(self):

View File

@ -108,7 +108,7 @@ class QBaseMenu2(QDialog):
capture_button.clicked.connect(self.cheat_capture) capture_button.clicked.connect(self.cheat_capture)
self.budget_display = QLabel( self.budget_display = QLabel(
QRecruitBehaviour.BUDGET_FORMAT.format(self.game_model.game.budget) QRecruitBehaviour.BUDGET_FORMAT.format(self.game_model.game.blue.budget)
) )
self.budget_display.setAlignment(Qt.AlignRight | Qt.AlignBottom) self.budget_display.setAlignment(Qt.AlignRight | Qt.AlignBottom)
self.budget_display.setProperty("style", "budget-label") self.budget_display.setProperty("style", "budget-label")
@ -139,7 +139,7 @@ class QBaseMenu2(QDialog):
@property @property
def can_afford_runway_repair(self) -> bool: def can_afford_runway_repair(self) -> bool:
return self.game_model.game.budget >= db.RUNWAY_REPAIR_COST return self.game_model.game.blue.budget >= db.RUNWAY_REPAIR_COST
def begin_runway_repair(self) -> None: def begin_runway_repair(self) -> None:
if not self.can_afford_runway_repair: if not self.can_afford_runway_repair:
@ -147,7 +147,7 @@ class QBaseMenu2(QDialog):
self, self,
"Cannot repair runway", "Cannot repair runway",
f"Runway repair costs ${db.RUNWAY_REPAIR_COST}M but you have " f"Runway repair costs ${db.RUNWAY_REPAIR_COST}M but you have "
f"only ${self.game_model.game.budget}M available.", f"only ${self.game_model.game.blue.budget}M available.",
QMessageBox.Ok, QMessageBox.Ok,
) )
return return
@ -161,7 +161,7 @@ class QBaseMenu2(QDialog):
return return
self.cp.begin_runway_repair() self.cp.begin_runway_repair()
self.game_model.game.budget -= db.RUNWAY_REPAIR_COST self.game_model.game.blue.budget -= db.RUNWAY_REPAIR_COST
self.update_repair_button() self.update_repair_button()
self.update_intel_summary() self.update_intel_summary()
GameUpdateSignal.get_instance().updateGame(self.game_model.game) GameUpdateSignal.get_instance().updateGame(self.game_model.game)
@ -257,4 +257,6 @@ class QBaseMenu2(QDialog):
NewUnitTransferDialog(self.game_model, self.cp, parent=self.window()).show() NewUnitTransferDialog(self.game_model, self.cp, parent=self.window()).show()
def update_budget(self, game: Game) -> None: def update_budget(self, game: Game) -> None:
self.budget_display.setText(QRecruitBehaviour.BUDGET_FORMAT.format(game.budget)) self.budget_display.setText(
QRecruitBehaviour.BUDGET_FORMAT.format(game.blue.budget)
)

View File

@ -103,11 +103,11 @@ class QRecruitBehaviour:
@property @property
def budget(self) -> float: def budget(self) -> float:
return self.game_model.game.budget return self.game_model.game.blue.budget
@budget.setter @budget.setter
def budget(self, value: int) -> None: def budget(self, value: int) -> None:
self.game_model.game.budget = value self.game_model.game.blue.budget = value
def add_purchase_row( def add_purchase_row(
self, self,

View File

@ -57,10 +57,7 @@ class FinancesLayout(QGridLayout):
middle=f"Income multiplier: {income.multiplier:.1f}", middle=f"Income multiplier: {income.multiplier:.1f}",
right=f"<b>{income.total}M</b>", right=f"<b>{income.total}M</b>",
) )
if player: budget = game.coalition_for(player).budget
budget = game.budget
else:
budget = game.enemy_budget
self.add_row(middle="Balance", right=f"<b>{budget}M</b>") self.add_row(middle="Balance", right=f"<b>{budget}M</b>")
self.setRowStretch(next(self.row), 1) self.setRowStretch(next(self.row), 1)

View File

@ -237,8 +237,8 @@ class QGroundObjectMenu(QDialog):
self.total_value = total_value self.total_value = total_value
def repair_unit(self, group, unit, price): def repair_unit(self, group, unit, price):
if self.game.budget > price: if self.game.blue.budget > price:
self.game.budget -= price self.game.blue.budget -= price
group.units_losts = [u for u in group.units_losts if u.id != unit.id] group.units_losts = [u for u in group.units_losts if u.id != unit.id]
group.units.append(unit) group.units.append(unit)
GameUpdateSignal.get_instance().updateGame(self.game) GameUpdateSignal.get_instance().updateGame(self.game)
@ -256,7 +256,7 @@ class QGroundObjectMenu(QDialog):
def sell_all(self): def sell_all(self):
self.update_total_value() self.update_total_value()
self.game.budget = self.game.budget + self.total_value self.game.blue.budget = self.game.blue.budget + self.total_value
self.ground_object.groups = [] self.ground_object.groups = []
# Replan if the tgo was a target of the redfor # Replan if the tgo was a target of the redfor
@ -433,12 +433,12 @@ class QBuyGroupForGroundObjectDialog(QDialog):
logging.info("Buying Armor ") logging.info("Buying Armor ")
utype = self.buyArmorCombo.itemData(self.buyArmorCombo.currentIndex()) utype = self.buyArmorCombo.itemData(self.buyArmorCombo.currentIndex())
price = utype.price * self.amount.value() - self.current_group_value price = utype.price * self.amount.value() - self.current_group_value
if price > self.game.budget: if price > self.game.blue.budget:
self.error_money() self.error_money()
self.close() self.close()
return return
else: else:
self.game.budget -= price self.game.blue.budget -= price
# Generate Armor # Generate Armor
group = generate_armor_group_of_type_and_size( group = generate_armor_group_of_type_and_size(
@ -454,11 +454,11 @@ class QBuyGroupForGroundObjectDialog(QDialog):
def buySam(self): def buySam(self):
sam_generator = self.samCombo.itemData(self.samCombo.currentIndex()) sam_generator = self.samCombo.itemData(self.samCombo.currentIndex())
price = sam_generator.price - self.current_group_value price = sam_generator.price - self.current_group_value
if price > self.game.budget: if price > self.game.blue.budget:
self.error_money() self.error_money()
return return
else: else:
self.game.budget -= price self.game.blue.budget -= price
self.ground_object.groups = list(sam_generator.groups) self.ground_object.groups = list(sam_generator.groups)
@ -470,11 +470,11 @@ class QBuyGroupForGroundObjectDialog(QDialog):
def buy_ewr(self): def buy_ewr(self):
ewr_generator = self.ewr_selector.itemData(self.ewr_selector.currentIndex()) ewr_generator = self.ewr_selector.itemData(self.ewr_selector.currentIndex())
price = ewr_generator.price - self.current_group_value price = ewr_generator.price - self.current_group_value
if price > self.game.budget: if price > self.game.blue.budget:
self.error_money() self.error_money()
return return
else: else:
self.game.budget -= price self.game.blue.budget -= price
self.ground_object.groups = [ewr_generator.vg] self.ground_object.groups = [ewr_generator.vg]

View File

@ -873,7 +873,7 @@ class QSettingsWindow(QDialog):
def cheatMoney(self, amount): def cheatMoney(self, amount):
logging.info("CHEATING FOR AMOUNT : " + str(amount) + "M") logging.info("CHEATING FOR AMOUNT : " + str(amount) + "M")
self.game.budget += amount self.game.blue.budget += amount
if amount > 0: if amount > 0:
self.game.informations.append( self.game.informations.append(
Information( Information(