From 380d6bf47a94d9ce115b855ed8f27db6caf90cc0 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Sun, 29 Aug 2021 02:17:10 -0700 Subject: [PATCH] Fix weird wrong default campaign field bug. I tried fixing this using setField after registering it, but it does nothing. I suspect this is because the page hasn't been registered with the wizard yet so it's setting the field for the wrong wizard. --- changelog.md | 1 + qt_ui/windows/newgame/QNewGameWizard.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index e3a80639..6530da79 100644 --- a/changelog.md +++ b/changelog.md @@ -28,6 +28,7 @@ Saves from 4.x are not compatible with 5.0. * **[Campaign]** Naval control points will no longer claim ground objectives during campaign generation and prevent them from spawning. * **[Mission Generation]** Mission results and other files will now be opened with enforced utf-8 encoding to prevent an issue where destroyed ground units were untracked because of special characters in their names. * **[UI]** Selling of Units is now visible again in the UI dialog and shows the correct amount of sold units +* **[UI]** Fixed bug where an incompatible campaign could be generated if no action is taken on the campaign selection screen. # 4.1.1 diff --git a/qt_ui/windows/newgame/QNewGameWizard.py b/qt_ui/windows/newgame/QNewGameWizard.py index c362d0c6..40a25649 100644 --- a/qt_ui/windows/newgame/QNewGameWizard.py +++ b/qt_ui/windows/newgame/QNewGameWizard.py @@ -65,6 +65,8 @@ class NewGameWizard(QtWidgets.QWizard): logging.info("======================") campaign = self.field("selectedCampaign") + if campaign is None: + campaign = self.theater_page.campaignList.selected_campaign if campaign is None: campaign = self.campaigns[0] @@ -299,13 +301,13 @@ class TheaterConfiguration(QtWidgets.QWizardPage): text="Show incompatible campaigns" ) show_incompatible_campaigns_checkbox.setChecked(False) - campaignList = QCampaignList( + self.campaignList = QCampaignList( campaigns, show_incompatible_campaigns_checkbox.isChecked() ) show_incompatible_campaigns_checkbox.toggled.connect( - lambda checked: campaignList.setup_content(show_incompatible=checked) + lambda checked: self.campaignList.setup_content(show_incompatible=checked) ) - self.registerField("selectedCampaign", campaignList) + self.registerField("selectedCampaign", self.campaignList) # Faction description self.campaignMapDescription = QTextEdit("") @@ -365,7 +367,7 @@ class TheaterConfiguration(QtWidgets.QWizardPage): template_perf = jinja_env.get_template( "campaign_performance_template_EN.j2" ) - campaign = campaignList.selected_campaign + campaign = self.campaignList.selected_campaign self.setField("selectedCampaign", campaign) if campaign is None: self.campaignMapDescription.setText("No campaign selected") @@ -378,11 +380,13 @@ class TheaterConfiguration(QtWidgets.QWizardPage): template_perf.render({"performance": campaign.performance}) ) - campaignList.selectionModel().setCurrentIndex( - campaignList.indexAt(QPoint(1, 1)), QItemSelectionModel.Rows + self.campaignList.selectionModel().setCurrentIndex( + self.campaignList.indexAt(QPoint(1, 1)), QItemSelectionModel.Rows ) - campaignList.selectionModel().selectionChanged.connect(on_campaign_selected) + self.campaignList.selectionModel().selectionChanged.connect( + on_campaign_selected + ) on_campaign_selected() docsText = QtWidgets.QLabel( @@ -409,7 +413,7 @@ class TheaterConfiguration(QtWidgets.QWizardPage): layout = QtWidgets.QGridLayout() layout.setColumnMinimumWidth(0, 20) - layout.addWidget(campaignList, 0, 0, 5, 1) + layout.addWidget(self.campaignList, 0, 0, 5, 1) layout.addWidget(show_incompatible_campaigns_checkbox, 5, 0, 1, 1) layout.addWidget(docsText, 6, 0, 1, 1) layout.addWidget(self.campaignMapDescription, 0, 1, 1, 1)