From f0a3fd1e3a6621f70f69ee2e07249f31215c348d Mon Sep 17 00:00:00 2001 From: RndName Date: Tue, 22 Mar 2022 15:19:36 +0100 Subject: [PATCH] Merge forcegroups with the same task --- game/armedforces/armedforces.py | 12 +++++------- game/armedforces/forcegroup.py | 5 +++-- qt_ui/windows/groundobject/QGroundObjectBuyMenu.py | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/game/armedforces/armedforces.py b/game/armedforces/armedforces.py index ecc11876..177cffcf 100644 --- a/game/armedforces/armedforces.py +++ b/game/armedforces/armedforces.py @@ -22,14 +22,12 @@ class ArmedForces: self._load_forces(faction) def add_or_update_force_group(self, new_group: ForceGroup) -> None: - """TODO Description""" - # Check if a force group with the same units exists + """Adds or update a forcegroup depending if a forcegroup with the exact same + tasking already exists""" + # Check if a force group with the same tasking already exists for force_group in self.forces: - if ( - force_group.units == new_group.units - and force_group.tasks == new_group.tasks - ): - # Update existing group if units and tasks are equal + if force_group.tasks == new_group.tasks: + # Update existing group if tasks are equal force_group.update_group(new_group) return # Add a new force group diff --git a/game/armedforces/forcegroup.py b/game/armedforces/forcegroup.py index 4f09b738..7410e509 100644 --- a/game/armedforces/forcegroup.py +++ b/game/armedforces/forcegroup.py @@ -160,8 +160,9 @@ class ForceGroup: return random.choice(self.dcs_unit_types_for_group(group)) def update_group(self, new_group: ForceGroup) -> None: - """Update the group from another group. This will merge statics and layouts.""" - # Merge layouts and statics + """Update the group from another group. + This will merge units, statics and layouts.""" + self.units = list(set(self.units + new_group.units)) self.statics = list(set(self.statics + new_group.statics)) self.layouts = list(set(self.layouts + new_group.layouts)) diff --git a/qt_ui/windows/groundobject/QGroundObjectBuyMenu.py b/qt_ui/windows/groundobject/QGroundObjectBuyMenu.py index b173cf63..d22ab1b8 100644 --- a/qt_ui/windows/groundobject/QGroundObjectBuyMenu.py +++ b/qt_ui/windows/groundobject/QGroundObjectBuyMenu.py @@ -248,7 +248,6 @@ class QGroundObjectBuyMenu(QDialog): self.force_group_selector.setMinimumWidth(250) self.layout_selector = QComboBox() self.layout_selector.setMinimumWidth(250) - self.layout_selector.setEnabled(False) # Get the layouts and fill the combobox tasks = [] @@ -276,6 +275,7 @@ class QGroundObjectBuyMenu(QDialog): for layout in force_group.layouts: self.layout_selector.addItem(layout.name, userData=layout) self.layout_selector.adjustSize() + self.layout_selector.setEnabled(len(force_group.layouts) > 1) selected_template = self.layout_selector.itemData( self.layout_selector.currentIndex() )