diff --git a/src/Battlescape/BriefingLightState.cpp b/src/Battlescape/BriefingLightState.cpp index ad87acea6d..8ab7f2187d 100644 --- a/src/Battlescape/BriefingLightState.cpp +++ b/src/Battlescape/BriefingLightState.cpp @@ -27,6 +27,7 @@ #include "../Interface/Window.h" #include "../Mod/Mod.h" #include "../Mod/AlienDeployment.h" +#include "../Mod/Armor.h" #include "../Mod/ArticleDefinition.h" #include "../Mod/RuleStartingCondition.h" #include "../Savegame/SavedGame.h" @@ -52,7 +53,7 @@ BriefingLightState::BriefingLightState(AlienDeployment *deployment) _txtTitle = new Text(300, 32, 16, 24); _txtBriefing = new Text(288, 104, 16, 56); _txtArmors = new Text(288, 25, 16, 56); - _lstArmors = new TextList(280, 80, 8, 81); + _lstArmors = new TextList(288, 80, 8, 81); std::string title = deployment->getType(); std::string desc = deployment->getAlertDescription(); @@ -90,13 +91,15 @@ BriefingLightState::BriefingLightState(AlienDeployment *deployment) _txtArmors->setWordWrap(true); _txtArmors->setVisible(false); - _lstArmors->setColumns(2, 148, 116); + _lstArmors->setColumns(2, 148, 132); _lstArmors->setSelectable(true); _lstArmors->setBackground(_window); _lstArmors->setMargin(8); _lstArmors->setVisible(false); checkStartingCondition(deployment); + + _lstArmors->onMouseClick((ActionHandler)&BriefingLightState::lstArmorsClick, SDL_BUTTON_MIDDLE); } /** @@ -114,31 +117,31 @@ void BriefingLightState::checkStartingCondition(AlienDeployment *deployment) _txtArmors->setText(tr(messageCode).arg("")); // passing empty argument, because it is obsolete since a list display was introduced _btnArmors->setVisible(true); - std::vector armorNameList; for (auto& armorType : list) { - ArticleDefinition* article = _game->getMod()->getUfopaediaArticle(armorType, false); + Armor* armor = _game->getMod()->getArmor(armorType, false); + ArticleDefinition* article = _game->getMod()->getUfopaediaArticle(armor ? armor->getUfopediaType() : armorType, false); if (article && Ufopaedia::isArticleAvailable(_game->getSavedGame(), article)) { std::string translation = tr(armorType); - armorNameList.push_back(translation); + _armorNameList.push_back(std::make_pair(armorType, translation)); } } - if (armorNameList.empty()) + if (_armorNameList.empty()) { // no suitable armor yet std::string translation = tr("STR_UNKNOWN"); - armorNameList.push_back(translation); + _armorNameList.push_back(std::make_pair("STR_UNKNOWN", translation)); } - std::sort(armorNameList.begin(), armorNameList.end(), [&](std::string& a, std::string& b) { return Unicode::naturalCompare(a, b); }); - if (armorNameList.size() % 2 != 0) + std::sort(_armorNameList.begin(), _armorNameList.end(), [&](std::pair& a, std::pair& b) { return Unicode::naturalCompare(a.second, b.second); }); + if (_armorNameList.size() % 2 != 0) { - armorNameList.push_back(""); // just padding, we want an even number of items in the list + _armorNameList.push_back(std::make_pair("", "")); // just padding, we want an even number of items in the list } - size_t halfSize = armorNameList.size() / 2; + size_t halfSize = _armorNameList.size() / 2; for (size_t i = 0; i < halfSize; ++i) { - _lstArmors->addRow(2, armorNameList[i].c_str(), armorNameList[i + halfSize].c_str()); + _lstArmors->addRow(2, _armorNameList[i].second.c_str(), _armorNameList[i + halfSize].second.c_str()); } } } @@ -172,4 +175,28 @@ void BriefingLightState::btnArmorsClick(Action *) _txtBriefing->setVisible(!_btnArmors->getPressed()); } +/** + * Shows corresponding Ufopaedia article. + * @param action Pointer to an action. + */ +void BriefingLightState::lstArmorsClick(Action* action) +{ + size_t halfSize = _armorNameList.size() / 2; + + double mx = action->getAbsoluteXMouse(); + if (mx < _btnOk->getX()) + { + halfSize = 0; + } + + auto idx = halfSize + _lstArmors->getSelectedRow(); + const std::string& armorType = _armorNameList[idx].first; + Armor* armor = _game->getMod()->getArmor(armorType, false); + if (armor) + { + std::string articleId = armor->getUfopediaType(); + Ufopaedia::openArticle(_game, articleId); + } +} + } diff --git a/src/Battlescape/BriefingLightState.h b/src/Battlescape/BriefingLightState.h index 682dc266a1..9572cee3ca 100644 --- a/src/Battlescape/BriefingLightState.h +++ b/src/Battlescape/BriefingLightState.h @@ -41,6 +41,7 @@ class BriefingLightState : public State Window *_window; Text *_txtTitle, *_txtBriefing, *_txtArmors; TextList* _lstArmors; + std::vector > _armorNameList; // Checks the starting condition void checkStartingCondition(AlienDeployment *deployment); public: @@ -52,6 +53,8 @@ class BriefingLightState : public State void btnOkClick(Action *action); /// Handler for clicking the Armors button. void btnArmorsClick(Action *action); + /// Handler for clicking the Armors list. + void lstArmorsClick(Action* action); }; } diff --git a/src/version.h b/src/version.h index cfbdb78265..ea124f4b42 100644 --- a/src/version.h +++ b/src/version.h @@ -24,5 +24,5 @@ #define OPENXCOM_VERSION_NUMBER 7,11,2,0 #ifndef OPENXCOM_VERSION_GIT -#define OPENXCOM_VERSION_GIT " (v2024-01-20)" +#define OPENXCOM_VERSION_GIT " (v2024-01-22)" #endif