Fix GroundObjectBuy Menu after buy or sell

- Close the Buy Menu after complete buy
- Update the Ground Object Dialog with the changes
- Update the Game & map correctly
This commit is contained in:
RndName 2022-03-22 15:20:42 +01:00
parent f0a3fd1e3a
commit e93639e1ab
2 changed files with 26 additions and 19 deletions

View File

@ -96,11 +96,13 @@ class QTgoLayoutGroupRow(QWidget):
self.grid_layout.addWidget(self.unit_selector, 0, 0, alignment=Qt.AlignRight) self.grid_layout.addWidget(self.unit_selector, 0, 0, alignment=Qt.AlignRight)
self.grid_layout.addWidget(self.amount_selector, 0, 1, alignment=Qt.AlignRight) self.grid_layout.addWidget(self.amount_selector, 0, 1, alignment=Qt.AlignRight)
unit_type, price = self.unit_selector.itemData( dcs_unit_type, price = self.unit_selector.itemData(
self.unit_selector.currentIndex() self.unit_selector.currentIndex()
) )
self.group_layout = QTgoLayoutGroup(group, unit_type, group.group_size, price) self.group_layout = QTgoLayoutGroup(
group, dcs_unit_type, group.group_size, price
)
self.group_selector.setChecked(self.group_layout.enabled) self.group_selector.setChecked(self.group_layout.enabled)
self.group_selector.setEnabled(self.group_layout.layout.optional) self.group_selector.setEnabled(self.group_layout.layout.optional)
@ -128,6 +130,8 @@ class QTgoLayoutGroupRow(QWidget):
class QGroundObjectTemplateLayout(QGroupBox): class QGroundObjectTemplateLayout(QGroupBox):
close_dialog_signal = Signal()
def __init__( def __init__(
self, self,
game: Game, game: Game,
@ -216,12 +220,7 @@ class QGroundObjectTemplateLayout(QGroupBox):
group.dcs_unit_type, # Forced Type group.dcs_unit_type, # Forced Type
group.amount, # Forced Amount group.amount, # Forced Amount
) )
self.close_dialog_signal.emit()
# Replan redfor missions
events = GameUpdateEvents()
self.game.initialize_turn(events, for_red=True, for_blue=False)
EventStream.put_nowait(events)
GameUpdateSignal.get_instance().updateGame(self.game)
class QGroundObjectBuyMenu(QDialog): class QGroundObjectBuyMenu(QDialog):
@ -305,6 +304,7 @@ class QGroundObjectBuyMenu(QDialog):
self.layout_changed_signal, self.layout_changed_signal,
current_group_value, current_group_value,
) )
self.template_layout.close_dialog_signal.connect(self.close_dialog)
self.mainLayout.addWidget(self.template_layout, 1, 0) self.mainLayout.addWidget(self.template_layout, 1, 0)
self.setLayout(self.mainLayout) self.setLayout(self.mainLayout)
@ -333,3 +333,6 @@ class QGroundObjectBuyMenu(QDialog):
self.force_group_selector.currentIndex() self.force_group_selector.currentIndex()
) )
self.layout_changed_signal.emit(self.theater_layout) self.layout_changed_signal.emit(self.theater_layout)
def close_dialog(self) -> None:
self.accept()

View File

@ -202,21 +202,25 @@ class QGroundObjectMenu(QDialog):
self.update_total_value() self.update_total_value()
self.game.blue.budget = self.game.blue.budget + self.total_value self.game.blue.budget = self.game.blue.budget + self.total_value
self.ground_object.groups = [] self.ground_object.groups = []
self.update_game()
# Replan if the tgo was a target of the redfor def buy_group(self) -> None:
self.subwindow = QGroundObjectBuyMenu(
self, self.ground_object, self.game, self.total_value
)
if self.subwindow.exec_():
self.update_game()
def update_game(self) -> None:
events = GameUpdateEvents()
events.update_tgo(self.ground_object)
if any( if any(
package.target == self.ground_object package.target == self.ground_object
for package in self.game.ato_for(player=False).packages for package in self.game.ato_for(player=False).packages
): ):
events = GameUpdateEvents() # Replan if the tgo was a target of the redfor
self.game.initialize_turn(events, for_red=True, for_blue=False) self.game.initialize_turn(events, for_red=True, for_blue=False)
EventStream.put_nowait(events) EventStream.put_nowait(events)
self.do_refresh_layout()
GameUpdateSignal.get_instance().updateGame(self.game) GameUpdateSignal.get_instance().updateGame(self.game)
# Refresh the dialog
def buy_group(self): self.do_refresh_layout()
self.subwindow = QGroundObjectBuyMenu(
self, self.ground_object, self.game, self.total_value
)
self.subwindow.show()