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, QPushButton,
) )
from game.armedforces.armedforces import ArmedForces
from game.ato.flight import Flight from game.ato.flight import Flight
from game.factions import Faction
from game.server import EventStream from game.server import EventStream
from game.sim import GameUpdateEvents from game.sim import GameUpdateEvents
from game.squadrons import Squadron from game.squadrons import Squadron
@ -270,20 +272,24 @@ class AirWingTabs(QTabWidget):
w = QWidget(layout=layout) w = QWidget(layout=layout)
self.addTab(w, "Cheats") 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( self.addTab(
QFactionUnits( qfu_ownfor,
game_model.game.coalition_for(True).faction,
self,
show_jtac=True,
),
"Faction 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( self.addTab(
QFactionUnits( qfu_opfor,
game_model.game.coalition_for(False).faction,
self,
show_jtac=False,
),
"Faction OPFOR", "Faction OPFOR",
) )
@ -293,6 +299,15 @@ class AirWingTabs(QTabWidget):
EventStream.put_nowait(events) EventStream.put_nowait(events)
self.game_model.ato_model.on_sim_update(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): class AirWingDialog(QDialog):
"""Dialog window showing the player's air wing.""" """Dialog window showing the player's air wing."""

View File

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