Merge pull request #72 from root0fall/add_budget_update

add budget preview to purchase dialogue
This commit is contained in:
C. Perreau 2020-08-17 11:46:23 +02:00 committed by GitHub
commit fb7ed19f7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 3 deletions

View File

@ -7,6 +7,7 @@ from game.event import ControlPointType
from qt_ui.uiconstants import EVENT_ICONS from qt_ui.uiconstants import EVENT_ICONS
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
from qt_ui.windows.basemenu.QBaseMenuTabs import QBaseMenuTabs from qt_ui.windows.basemenu.QBaseMenuTabs import QBaseMenuTabs
from qt_ui.windows.basemenu.QRecruitBehaviour import QRecruitBehaviour
from theater import ControlPoint from theater import ControlPoint
@ -19,6 +20,7 @@ class QBaseMenu2(QDialog):
self.cp = cp self.cp = cp
self.game = game self.game = game
self.is_carrier = self.cp.cptype in [ControlPointType.AIRCRAFT_CARRIER_GROUP, ControlPointType.LHA_GROUP] self.is_carrier = self.cp.cptype in [ControlPointType.AIRCRAFT_CARRIER_GROUP, ControlPointType.LHA_GROUP]
self.objectName = "menuDialogue"
# Widgets # Widgets
self.qbase_menu_tab = QBaseMenuTabs(cp, game) self.qbase_menu_tab = QBaseMenuTabs(cp, game)
@ -58,7 +60,6 @@ class QBaseMenu2(QDialog):
title.setProperty("style", "base-title") title.setProperty("style", "base-title")
unitsPower = QLabel("{} / {} / Runway : {}".format(self.cp.base.total_planes, self.cp.base.total_armor, unitsPower = QLabel("{} / {} / Runway : {}".format(self.cp.base.total_planes, self.cp.base.total_armor,
"Available" if self.cp.has_runway() else "Unavailable")) "Available" if self.cp.has_runway() else "Unavailable"))
self.topLayout.addWidget(title) self.topLayout.addWidget(title)
self.topLayout.addWidget(unitsPower) self.topLayout.addWidget(unitsPower)
self.topLayout.setAlignment(Qt.AlignTop) self.topLayout.setAlignment(Qt.AlignTop)
@ -69,7 +70,11 @@ class QBaseMenu2(QDialog):
self.mainLayout.addWidget(header, 0, 0) self.mainLayout.addWidget(header, 0, 0)
self.mainLayout.addWidget(self.topLayoutWidget, 1, 0) self.mainLayout.addWidget(self.topLayoutWidget, 1, 0)
self.mainLayout.addWidget(self.qbase_menu_tab, 2, 0) self.mainLayout.addWidget(self.qbase_menu_tab, 2, 0)
totalBudget = QLabel(QRecruitBehaviour.BUDGET_FORMAT.format(self.game.budget))
totalBudget.setObjectName("budgetField")
totalBudget.setAlignment(Qt.AlignRight | Qt.AlignBottom)
totalBudget.setProperty("style", "budget-label")
self.mainLayout.addWidget(totalBudget)
self.setLayout(self.mainLayout) self.setLayout(self.mainLayout)
def closeEvent(self, closeEvent:QCloseEvent): def closeEvent(self, closeEvent:QCloseEvent):
@ -81,4 +86,4 @@ class QBaseMenu2(QDialog):
elif self.cp.cptype == ControlPointType.LHA_GROUP: elif self.cp.cptype == ControlPointType.LHA_GROUP:
return "./resources/ui/lha.png" return "./resources/ui/lha.png"
else: else:
return "./resources/ui/airbase.png" return "./resources/ui/airbase.png"

View File

@ -5,6 +5,7 @@ from dcs.unittype import UnitType
from theater import db from theater import db
class QRecruitBehaviour: class QRecruitBehaviour:
game = None game = None
@ -12,10 +13,12 @@ class QRecruitBehaviour:
deliveryEvent = None deliveryEvent = None
existing_units_labels = None existing_units_labels = None
bought_amount_labels = None bought_amount_labels = None
BUDGET_FORMAT = "Available Budget: <b>${}M</b>"
def __init__(self): def __init__(self):
self.bought_amount_labels = {} self.bought_amount_labels = {}
self.existing_units_labels = {} self.existing_units_labels = {}
self.update_available_budget()
def add_purchase_row(self, unit_type, layout, row): def add_purchase_row(self, unit_type, layout, row):
@ -91,12 +94,22 @@ class QRecruitBehaviour:
self.cp.base.total_units_of_type(unit_type) self.cp.base.total_units_of_type(unit_type)
)) ))
def update_available_budget(self):
parent = self.parent()
while parent.objectName != "menuDialogue":
parent = parent.parent()
for child in parent.children():
if child.objectName() == "budgetField":
child.setText(QRecruitBehaviour.BUDGET_FORMAT.format(self.game.budget))
def buy(self, unit_type): def buy(self, unit_type):
price = db.PRICES[unit_type] price = db.PRICES[unit_type]
if self.game.budget >= price: if self.game.budget >= price:
self.deliveryEvent.deliver({unit_type: 1}) self.deliveryEvent.deliver({unit_type: 1})
self.game.budget -= price self.game.budget -= price
self._update_count_label(unit_type) self._update_count_label(unit_type)
self.update_available_budget()
def sell(self, unit_type): def sell(self, unit_type):
if self.deliveryEvent.units.get(unit_type, 0) > 0: if self.deliveryEvent.units.get(unit_type, 0) > 0:
@ -111,3 +124,4 @@ class QRecruitBehaviour:
self.cp.base.commit_losses({unit_type: 1}) self.cp.base.commit_losses({unit_type: 1})
self._update_count_label(unit_type) self._update_count_label(unit_type)
self.update_available_budget()

View File

@ -184,6 +184,11 @@ QLabel[style="base-title"]{
font-size: 24px; font-size: 24px;
} }
QLabel[style="budget-label"]{
font-size: 16px;
margin-right: 20px;
}
QLabel[style="icon-plane"]{ QLabel[style="icon-plane"]{
background-color:#48719D; background-color:#48719D;
min-height:24px; min-height:24px;