Fix budget update for non-base SAMs.

Just emit the signal to update the budget rather than trying to figure
out the heirarchy of the UI.

Fixes https://github.com/Khopa/dcs_liberation/issues/581

(cherry picked from commit 7d907aac0f644f55bda42ec916eb2be054aefcf5)
This commit is contained in:
Dan Albert 2020-12-14 17:00:56 -08:00
parent 4b0d2f7abc
commit edba923f2f
3 changed files with 22 additions and 24 deletions

View File

@ -10,7 +10,7 @@ from PySide2.QtWidgets import (
QWidget,
)
from game import db
from game import Game, db
from game.theater import ControlPoint, ControlPointType
from gen.flights.flight import FlightType
from qt_ui.dialogs import Dialog
@ -89,13 +89,14 @@ class QBaseMenu2(QDialog):
runway_attack_button.setProperty("style", "btn-danger")
runway_attack_button.clicked.connect(self.new_package)
budget_display = QLabel(
self.budget_display = QLabel(
QRecruitBehaviour.BUDGET_FORMAT.format(self.game_model.game.budget)
)
budget_display.setObjectName("budgetField")
budget_display.setAlignment(Qt.AlignRight | Qt.AlignBottom)
budget_display.setProperty("style", "budget-label")
bottom_row.addWidget(budget_display)
self.budget_display.setAlignment(Qt.AlignRight | Qt.AlignBottom)
self.budget_display.setProperty("style", "budget-label")
bottom_row.addWidget(self.budget_display)
GameUpdateSignal.get_instance().budgetupdated.connect(
self.update_budget)
self.setLayout(main_layout)
@property
@ -171,9 +172,6 @@ class QBaseMenu2(QDialog):
def new_package(self) -> None:
Dialog.open_new_package_dialog(self.cp, parent=self.window())
def update_dialogue_budget(self, budget: int):
GameUpdateSignal.get_instance().updateBudget(self.game_model.game)
for child in self.children():
if child.objectName() == "budgetField":
child.setText(
QRecruitBehaviour.BUDGET_FORMAT.format(budget))
def update_budget(self, game: Game) -> None:
self.budget_display.setText(
QRecruitBehaviour.BUDGET_FORMAT.format(game.budget))

View File

@ -16,6 +16,7 @@ from game import db
from game.event import UnitsDeliveryEvent
from game.theater import ControlPoint
from qt_ui.models import GameModel
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
class QRecruitBehaviour:
@ -121,11 +122,8 @@ class QRecruitBehaviour:
self.cp.base.total_units_of_type(unit_type)
))
def update_available_budget(self):
parent = self.parent()
while parent.objectName != "menuDialogue":
parent = parent.parent()
parent.update_dialogue_budget(self.budget)
def update_available_budget(self) -> None:
GameUpdateSignal.get_instance().updateBudget(self.game_model.game)
def buy(self, unit_type: Type[UnitType]):
price = db.PRICES[unit_type]

View File

@ -1,4 +1,5 @@
import logging
from typing import List, Optional
from PySide2 import QtCore
from PySide2.QtGui import Qt
@ -33,11 +34,16 @@ class QGroundObjectMenu(QDialog):
changed = QtCore.Signal()
def __init__(self, parent, ground_object: TheaterGroundObject, buildings:[], cp: ControlPoint, game: Game):
super(QGroundObjectMenu, self).__init__(parent)
def __init__(self, parent, ground_object: TheaterGroundObject,
buildings: Optional[List[TheaterGroundObject]],
cp: ControlPoint, game: Game):
super().__init__(parent)
self.setMinimumWidth(350)
self.ground_object = ground_object
self.buildings = buildings
if buildings is None:
self.buildings = []
else:
self.buildings = buildings
self.cp = cp
self.game = game
self.setWindowTitle("Location " + self.ground_object.obj_name)
@ -190,7 +196,6 @@ class QGroundObjectMenu(QDialog):
group.units_losts = [u for u in group.units_losts if u.id != unit.id]
group.units.append(unit)
GameUpdateSignal.get_instance().updateGame(self.game)
self.parent().update_dialogue_budget(self.game.budget)
# Remove destroyed units in the vicinity
destroyed_units = self.game.get_destroyed_units()
@ -210,7 +215,6 @@ class QGroundObjectMenu(QDialog):
self.ground_object.groups = []
self.do_refresh_layout()
GameUpdateSignal.get_instance().updateBudget(self.game)
self.parent().update_dialogue_budget(self.game.budget)
def buy_group(self):
self.subwindow = QBuyGroupForGroundObjectDialog(self, self.ground_object, self.cp, self.game, self.total_value)
@ -335,7 +339,6 @@ class QBuyGroupForGroundObjectDialog(QDialog):
self.ground_object.groups = [group]
GameUpdateSignal.get_instance().updateBudget(self.game)
self.parent().parent().update_dialogue_budget(self.game.budget)
self.changed.emit()
self.close()
@ -356,7 +359,6 @@ class QBuyGroupForGroundObjectDialog(QDialog):
self.ground_object.groups = [generated_group]
GameUpdateSignal.get_instance().updateBudget(self.game)
self.parent().parent().update_dialogue_budget(self.game.budget)
self.changed.emit()
self.close()