Skip to content

Commit a5517b0

Browse files
authored
Merge pull request #101 from MageKing17/bugfix/metagame-tech-list-repopulation
Gate populating metagame tech dropdown and team icons behind flag.
2 parents a0d0538 + 285e666 commit a5517b0

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6060

6161
- Fixed Decision Day camera potentially getting stuck at the start if player 1 wasn't present.
6262

63+
- Fixed Conquest tech selection dropdown getting repeatedly repopulated with duplicated entries, which could cause a crash.
64+
6365
</details>
6466

6567
<details><summary><b>Removed</b></summary>

Source/Menus/MetagameGUI.cpp

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ int MetagameGUI::Create(Controller* pController) {
582582

583583
// Hide all screens, the appropriate screen will reappear on next update
584584
HideAllScreens();
585+
m_TechAndFlagListFetched = false;
585586
return 0;
586587
}
587588

@@ -717,33 +718,43 @@ void MetagameGUI::SetEnabled(bool enable) {
717718
g_GUISound.ExitMenuSound()->Play();
718719
}
719720

720-
// Populate the tech comboboxes with the available tech modules
721-
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
722-
m_apPlayerTechSelect[team]->GetListPanel()->AddItem("-Random-", "", nullptr, nullptr, -1);
723-
m_apPlayerTechSelect[team]->SetSelectedIndex(0);
724-
}
725-
for (int moduleID = 0; moduleID < g_PresetMan.GetTotalModuleCount(); ++moduleID) {
726-
if (const DataModule* dataModule = g_PresetMan.GetDataModule(moduleID)) {
727-
if (dataModule->IsFaction()) {
728-
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
729-
m_apPlayerTechSelect[team]->GetListPanel()->AddItem(dataModule->GetFriendlyName(), "", nullptr, nullptr, moduleID);
730-
m_apPlayerTechSelect[team]->GetListPanel()->ScrollToTop();
721+
if (!m_TechAndFlagListFetched) {
722+
m_TechAndFlagListFetched = true;
723+
// Populate the tech comboboxes with the available tech modules
724+
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; ++player) {
725+
m_apPlayerTechSelect[player]->GetListPanel()->AddItem("-Random-", "", nullptr, nullptr, -1);
726+
m_apPlayerTechSelect[player]->SetSelectedIndex(0);
727+
}
728+
for (int moduleID = 0; moduleID < g_PresetMan.GetTotalModuleCount(); ++moduleID) {
729+
if (const DataModule* dataModule = g_PresetMan.GetDataModule(moduleID)) {
730+
if (dataModule->IsFaction()) {
731+
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; ++player) {
732+
m_apPlayerTechSelect[player]->GetListPanel()->AddItem(dataModule->GetFriendlyName(), "", nullptr, nullptr, moduleID);
733+
}
731734
}
732735
}
733736
}
734-
}
737+
// Start scrolled to the top.
738+
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; ++player) {
739+
m_apPlayerTechSelect[player]->GetListPanel()->ScrollToTop();
740+
}
735741

736-
std::list<Entity*> flagList;
737-
g_PresetMan.GetAllOfGroup(flagList, "Flags", "Icon");
738-
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; ++player) {
739-
for (std::list<Entity*>::iterator itr = flagList.begin(); itr != flagList.end(); ++itr) {
740-
if (const Icon* pIcon = dynamic_cast<Icon*>(*itr)) {
741-
m_apPlayerTeamSelect[player]->AddItem("", "", new AllegroBitmap(pIcon->GetBitmaps32()[0]), pIcon);
742+
// Populate team selection flags.
743+
std::list<Entity*> flagList;
744+
g_PresetMan.GetAllOfGroup(flagList, "Flags", "Icon");
745+
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; ++player) {
746+
for (std::list<Entity*>::iterator itr = flagList.begin(); itr != flagList.end(); ++itr) {
747+
if (const Icon* pIcon = dynamic_cast<Icon*>(*itr)) {
748+
m_apPlayerTeamSelect[player]->AddItem("", "", new AllegroBitmap(pIcon->GetBitmaps32()[0]), pIcon);
749+
}
742750
}
743751
}
744752
}
745-
if (m_apPlayerTeamSelect[Players::PlayerOne]->GetSelectedIndex() < 0) {
746-
m_apPlayerTeamSelect[Players::PlayerOne]->SetSelectedIndex(0);
753+
// If a player has no team selected, default to the same team as their player index.
754+
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; ++player) {
755+
if (m_apPlayerTeamSelect[player]->GetSelectedIndex() < 0) {
756+
m_apPlayerTeamSelect[player]->SetSelectedIndex(player);
757+
}
747758
}
748759

749760
m_ScreenChange = true;

Source/Menus/MetagameGUI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ namespace RTE {
772772
// The scene currently being played, NOT OWNED
773773
Scene* m_pPlayingScene;
774774

775+
bool m_TechAndFlagListFetched; //!< Whether the tech list was fetched and each team's ComboBox was populated with it, even if no valid tech modules were added. The team flags are also populated at the same time.
776+
775777
// NEW GAME DIALOG
776778
// Game size label and slider
777779
GUILabel* m_pSizeLabel;

Source/Menus/ScenarioActivityConfigGUI.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,20 @@ void ScenarioActivityConfigGUI::PopulateTechComboBoxes() {
7373
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
7474
m_TeamTechComboBoxes[team]->GetListPanel()->AddItem("-All-", "", nullptr, nullptr, -2);
7575
m_TeamTechComboBoxes[team]->GetListPanel()->AddItem("-Random-", "", nullptr, nullptr, -1);
76+
m_TeamTechComboBoxes[team]->SetSelectedIndex(0);
7677
}
7778
for (int moduleID = 0; moduleID < g_PresetMan.GetTotalModuleCount(); ++moduleID) {
7879
if (const DataModule* dataModule = g_PresetMan.GetDataModule(moduleID)) {
7980
if (dataModule->IsFaction()) {
8081
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
8182
m_TeamTechComboBoxes[team]->GetListPanel()->AddItem(dataModule->GetFriendlyName(), "", nullptr, nullptr, moduleID);
82-
m_TeamTechComboBoxes[team]->GetListPanel()->ScrollToTop();
83-
m_TeamTechComboBoxes[team]->SetSelectedIndex(0);
8483
}
8584
}
8685
}
8786
}
87+
for (int team = Activity::Teams::TeamOne; team < Activity::Teams::MaxTeamCount; ++team) {
88+
m_TeamTechComboBoxes[team]->GetListPanel()->ScrollToTop();
89+
}
8890
m_TechListFetched = true;
8991
}
9092

0 commit comments

Comments
 (0)