Skip to content

Commit

Permalink
MMB to open Pedia on "What can I wear?" UI
Browse files Browse the repository at this point in the history
  • Loading branch information
MeridianOXC committed Jan 22, 2024
1 parent af6052f commit fed1595
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
51 changes: 39 additions & 12 deletions src/Battlescape/BriefingLightState.cpp
Expand Up @@ -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"
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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<std::string> 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<std::string, std::string>& a, std::pair<std::string, std::string>& 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());
}
}
}
Expand Down Expand Up @@ -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);
}
}

}
3 changes: 3 additions & 0 deletions src/Battlescape/BriefingLightState.h
Expand Up @@ -41,6 +41,7 @@ class BriefingLightState : public State
Window *_window;
Text *_txtTitle, *_txtBriefing, *_txtArmors;
TextList* _lstArmors;
std::vector<std::pair<std::string, std::string> > _armorNameList;
// Checks the starting condition
void checkStartingCondition(AlienDeployment *deployment);
public:
Expand All @@ -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);
};

}
2 changes: 1 addition & 1 deletion src/version.h
Expand Up @@ -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

0 comments on commit fed1595

Please sign in to comment.