Skip to content

Commit 0367930

Browse files
committed
Always repopulate faction comboboxes when Activity config GUI is enabled since modules can now be loaded/unloaded from the mod manager
1 parent b3da7d8 commit 0367930

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

Menus/ScenarioActivityConfigGUI.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,35 @@ namespace RTE {
6363
m_CPULockLabel = dynamic_cast<GUILabel *>(m_GUIControlManager->GetControl("LabelCPUTeamLock"));
6464
m_StartErrorLabel = dynamic_cast<GUILabel *>(m_GUIControlManager->GetControl("LabelStartError"));
6565
m_StartGameButton = dynamic_cast<GUIButton *>(m_GUIControlManager->GetControl("ButtonStartGame"));
66-
67-
m_TechListFetched = false;
6866
}
6967

7068
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7169

7270
void ScenarioActivityConfigGUI::PopulateTechComboBoxes() {
71+
static constexpr int allTechIndex = -2;
72+
static constexpr int randomTechIndex = -1;
73+
74+
std::array<int, Activity::Teams::MaxTeamCount> lastSelectedIndices = {};
75+
lastSelectedIndices.fill(allTechIndex);
76+
7377
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
74-
m_TeamTechComboBoxes[team]->GetListPanel()->AddItem("-All-", "", nullptr, nullptr, -2);
75-
m_TeamTechComboBoxes[team]->GetListPanel()->AddItem("-Random-", "", nullptr, nullptr, -1);
78+
lastSelectedIndices[team] = m_TeamTechComboBoxes[team]->GetSelectedIndex();
79+
m_TeamTechComboBoxes[team]->ClearList();
80+
m_TeamTechComboBoxes[team]->GetListPanel()->AddItem("-All-", "", nullptr, nullptr, allTechIndex);
81+
m_TeamTechComboBoxes[team]->GetListPanel()->AddItem("-Random-", "", nullptr, nullptr, randomTechIndex);
7682
}
77-
for (int moduleID = 0; moduleID < g_ModuleMan.GetTotalModuleCount(); ++moduleID) {
78-
if (const DataModule *dataModule = g_ModuleMan.GetDataModule(moduleID)) {
79-
if (dataModule->IsFaction()) {
80-
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
81-
m_TeamTechComboBoxes[team]->GetListPanel()->AddItem(dataModule->GetFriendlyName(), "", nullptr, nullptr, moduleID);
82-
m_TeamTechComboBoxes[team]->GetListPanel()->ScrollToTop();
83-
m_TeamTechComboBoxes[team]->SetSelectedIndex(0);
84-
}
83+
for (const auto &[moduleID, dataModule] : g_ModuleMan.GetLoadedDataModules()) {
84+
if (dataModule->IsFaction()) {
85+
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
86+
m_TeamTechComboBoxes[team]->GetListPanel()->AddItem(dataModule->GetFriendlyName(), "", nullptr, nullptr, moduleID);
87+
m_TeamTechComboBoxes[team]->GetListPanel()->ScrollToTop();
88+
m_TeamTechComboBoxes[team]->SetSelectedIndex(0);
8589
}
8690
}
8791
}
88-
m_TechListFetched = true;
92+
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
93+
m_TeamTechComboBoxes[team]->SetSelectedIndex(lastSelectedIndices[team] < m_TeamTechComboBoxes[team]->GetCount() ? lastSelectedIndices[team] : allTechIndex);
94+
}
8995
}
9096

9197
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -115,7 +121,7 @@ namespace RTE {
115121
m_TeamTechComboBoxes[team]->SetVisible(enable);
116122
}
117123
if (enable && m_SelectedActivity && m_SelectedScene) {
118-
if (!m_TechListFetched) { PopulateTechComboBoxes(); }
124+
PopulateTechComboBoxes();
119125

120126
int startingGoldOverride = selectingPreviousActivityWithManuallyAdjustedGold ? m_StartingGoldSlider->GetValue() : -1;
121127
ResetActivityConfigBox();

Menus/ScenarioActivityConfigGUI.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ namespace RTE {
8585

8686
Timer m_StartGameButtonBlinkTimer; //!< Timer for blinking the start game button.
8787

88-
bool m_TechListFetched; //!< Whether the tech list was fetched and each team's ComboBox was populated with it, even if no valid tech modules were added.
89-
9088
/// <summary>
9189
/// GUI elements that compose the Activity setup box.
9290
/// </summary>

0 commit comments

Comments
 (0)