From d1c7146a472e6d9b4b4c83b390ddd8a1dada6e28 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sun, 30 May 2021 20:16:54 -0700 Subject: [PATCH] Add cheat options back to front lines. Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1108. --- .../ground_forces/QGroundForcesStrategy.py | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/qt_ui/windows/basemenu/ground_forces/QGroundForcesStrategy.py b/qt_ui/windows/basemenu/ground_forces/QGroundForcesStrategy.py index c903413b..ec467b92 100644 --- a/qt_ui/windows/basemenu/ground_forces/QGroundForcesStrategy.py +++ b/qt_ui/windows/basemenu/ground_forces/QGroundForcesStrategy.py @@ -1,7 +1,10 @@ -from PySide2.QtWidgets import QGroupBox, QLabel, QVBoxLayout +from collections import Callable + +from PySide2.QtWidgets import QGroupBox, QLabel, QVBoxLayout, QPushButton from game import Game from game.theater import ControlPoint +from qt_ui.windows.GameUpdateSignal import GameUpdateSignal from qt_ui.windows.basemenu.ground_forces.QGroundForcesStrategySelector import ( QGroundForcesStrategySelector, ) @@ -15,10 +18,44 @@ class QGroundForcesStrategy(QGroupBox): self.init_ui() def init_ui(self): + def make_cheat_callback( + enemy_point: ControlPoint, advance: bool + ) -> Callable[[], None]: + def cheat() -> None: + self.cheat_alter_front_line(enemy_point, advance) + + return cheat + layout = QVBoxLayout() for enemy_cp in self.cp.connected_points: if not enemy_cp.captured: layout.addWidget(QLabel(enemy_cp.name)) layout.addWidget(QGroundForcesStrategySelector(self.cp, enemy_cp)) + if self.game.settings.enable_frontline_cheats: + advance_button = QPushButton("CHEAT: Advance") + advance_button.setProperty("style", "btn-danger") + layout.addWidget(advance_button) + advance_button.clicked.connect( + make_cheat_callback(enemy_cp, advance=True) + ) + + retreat_button = QPushButton("CHEAT: Retreat") + retreat_button.setProperty("style", "btn-danger") + layout.addWidget(retreat_button) + retreat_button.clicked.connect( + make_cheat_callback(enemy_cp, advance=False) + ) + layout.addStretch() self.setLayout(layout) + + def cheat_alter_front_line(self, enemy_point: ControlPoint, advance: bool) -> None: + amount = 0.2 + if not advance: + amount *= -1 + self.cp.base.affect_strength(amount) + enemy_point.base.affect_strength(-amount) + # Clear the ATO to replan missions affected by the front line. + self.game.reset_ato() + self.game.initialize_turn() + GameUpdateSignal.get_instance().updateGame(self.game)