Update armed forces when preset-group is added

This commit is contained in:
Raffson 2025-01-05 14:46:20 +01:00
parent 807bb16ddf
commit f112f227cc
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99
2 changed files with 29 additions and 12 deletions

View File

@ -18,7 +18,9 @@ from PySide6.QtWidgets import (
QPushButton,
)
from game.armedforces.armedforces import ArmedForces
from game.ato.flight import Flight
from game.factions import Faction
from game.server import EventStream
from game.sim import GameUpdateEvents
from game.squadrons import Squadron
@ -270,20 +272,24 @@ class AirWingTabs(QTabWidget):
w = QWidget(layout=layout)
self.addTab(w, "Cheats")
qfu_ownfor = QFactionUnits(
game_model.game.coalition_for(True).faction,
self,
show_jtac=True,
)
qfu_ownfor.preset_groups_changed.connect(self.preset_group_updated_ownfor)
self.addTab(
QFactionUnits(
game_model.game.coalition_for(True).faction,
self,
show_jtac=True,
),
qfu_ownfor,
"Faction OWNFOR",
)
qfu_opfor = QFactionUnits(
game_model.game.coalition_for(False).faction,
self,
show_jtac=True,
)
qfu_opfor.preset_groups_changed.connect(self.preset_group_updated_opfor)
self.addTab(
QFactionUnits(
game_model.game.coalition_for(False).faction,
self,
show_jtac=False,
),
qfu_opfor,
"Faction OPFOR",
)
@ -293,6 +299,15 @@ class AirWingTabs(QTabWidget):
EventStream.put_nowait(events)
self.game_model.ato_model.on_sim_update(events)
def preset_group_updated_ownfor(self, f: Faction) -> None:
self.preset_group_updated(f, player=True)
def preset_group_updated_opfor(self, f: Faction) -> None:
self.preset_group_updated(f, player=False)
def preset_group_updated(self, f: Faction, player: bool) -> None:
self.game_model.game.coalition_for(player).armed_forces = ArmedForces(f)
class AirWingDialog(QDialog):
"""Dialog window showing the player's air wing."""

View File

@ -1,12 +1,11 @@
from __future__ import unicode_literals
import json
from copy import deepcopy
from typing import Union, Callable, Set, Optional, List
from PySide6 import QtWidgets, QtGui
from PySide6.QtCore import Qt
from PySide6.QtCore import Qt, Signal
from PySide6.QtWidgets import (
QScrollArea,
QWidget,
@ -37,6 +36,8 @@ from qt_ui.windows.newgame.jinja_env import jinja_env
class QFactionUnits(QScrollArea):
preset_groups_changed = Signal(Faction)
def __init__(self, faction: Faction, parent=None, show_jtac: bool = False):
super().__init__()
self.setWidgetResizable(True)
@ -302,6 +303,7 @@ class QFactionUnits(QScrollArea):
# invalidate the cached property
del self.faction.__dict__["accessible_units"]
self.updateFaction(self.faction)
self.preset_groups_changed.emit(self.faction)
def updateFaction(self, faction: Faction):
self.faction = faction