/* * This function popups a context sensitive list of actions the user can choose from. * Some actions result in a change of gamestate. * @param item Item the user clicked on (righthand/lefthand) */ void BattlescapeState::handleItemClick(BattleItem *item) { // make sure there is an item, and the battlescape is in an idle state if (item && _states.empty()) { BattleUnit *bu = _battleGame->getSelectedUnit(); // Build up the popup menu int id = 0; std::wstring strAcc = _game->getLanguage()->getString("STR_ACC"); std::wstring strTU = _game->getLanguage()->getString("STR_TUS"); std::wstringstream ss1, ss2; ss1 << strAcc.c_str() << (int)floor(bu->getThrowingAccuracy() * 100) << "%"; ss2 << strTU.c_str() << (int)floor(bu->getUnit()->getTimeUnits() * 0.25); _actionMenu[id]->setAction(BA_THROW, _game->getLanguage()->getString("STR_THROW"), ss1.str(), ss2.str()); _actionMenu[id]->setVisible(true); id++; ss1.str(L""); ss2.str(L""); if (item->getRules()->getAccuracyAuto() != 0) { ss1 << strAcc.c_str() << (int)floor(bu->getFiringAccuracy(item->getRules()->getAccuracyAuto()) * 100) << "%"; ss2 << strTU.c_str() << 0; _actionMenu[id]->setAction(BA_AUTOSHOT, _game->getLanguage()->getString("STR_AUTO_SHOT"), ss1.str(), ss2.str()); _actionMenu[id]->setVisible(true); id++; ss1.str(L""); ss2.str(L""); } if (item->getRules()->getAccuracySnap() != 0) { ss1 << strAcc.c_str() << (int)floor(bu->getFiringAccuracy(item->getRules()->getAccuracySnap()) * 100) << "%"; ss2 << strTU.c_str() << 0; _actionMenu[id]->setAction(BA_SNAPSHOT, _game->getLanguage()->getString("STR_SNAP_SHOT"), ss1.str(), ss2.str()); _actionMenu[id]->setVisible(true); id++; ss1.str(L""); ss2.str(L""); } if (item->getRules()->getAccuracyAimed() != 0) { ss1 << strAcc.c_str() << (int)floor(bu->getFiringAccuracy(item->getRules()->getAccuracyAimed()) * 100) << "%"; ss2 << strTU.c_str() << 0; _actionMenu[id]->setAction(BA_AIMEDSHOT, _game->getLanguage()->getString("STR_AIMED_SHOT"), ss1.str(), ss2.str()); _actionMenu[id]->setVisible(true); id++; ss1.str(L""); ss2.str(L""); } _map->setCursorType(CT_NONE); _popup = true; // TODO other gamestates: scanner/medikit // this should be returned by the popup menu, but is now hardcoded to test without popup menu _selectedItem = item; } }