void SelectMenu::handleMouseUp(int x, int y, int button, const int modKeys) { if (button == 3) { Agent *selected = g_gameCtrl.agents().squadMember(cur_agent_); if (selected == NULL) weapon_dragged_ = NULL; if (weapon_dragged_) { int target = -1; if (x >= 20 && x <= 140) { if (y >= 84 && y <= 150) { if (x >= 82) { target = 1; } else { target = 0; } } if (y >= 162 && y <= 228) { if (x >= 82) { target = 3; } else { target = 2; } } } Agent *reciever = target != -1 ? g_gameCtrl.agents().squadMember(target) : NULL; if (target != cur_agent_ && reciever && reciever->numWeapons() < 8) { selected->removeWeapon(weapon_dragged_); reciever->addWeapon(weapon_dragged_); pSelectedWeap_ = NULL; selectedWInstId_ = 0; showItemList(); } weapon_dragged_ = NULL; } } }
void SelectMenu::handleAction(const int actionId, void *ctx, const int modKeys) { if (actionId == teamButId_) { tab_ = TAB_TEAM; showItemList(); } else if (actionId == modsButId_) { tab_ = TAB_MODS; showItemList(); } else if (actionId == equipButId_) { tab_ = TAB_EQUIPS; showItemList(); } else if (actionId == pTeamLBox_->getId()) { // get the selected agent from the team listbox std::pair<int, void *> * pPair = static_cast<std::pair<int, void *> *> (ctx); Agent *pNewAgent = static_cast<Agent *> (pPair->second); bool found = false; // check if selected agent is already part of the mission squad for (size_t j = 0; j < AgentManager::kMaxSlot; j++) { if (g_Session.agents().squadMember(j) == pNewAgent) { found = true; break; } } // Agent was not part of the squad if (!found) { // adds him to the squad g_Session.agents().setSquadMember(cur_agent_, pNewAgent); // Update current agent name getStatic(txtAgentId_)->setTextFormated("#SELECT_SUBTITLE", pNewAgent->getName()); pTeamLBox_->setSquadLine(cur_agent_, pPair->first); updateAcceptEnabled(); // redraw agent display addDirtyRect(158, 110, 340, 260); // redraw agent buttons dirtyAgentSelector(); } } else if (actionId == pModsLBox_->getId()) { std::pair<int, void *> * pPair = static_cast<std::pair<int, void *> *> (ctx); pSelectedMod_ = static_cast<Mod *> (pPair->second); showModWeaponPanel(); } else if (actionId == pWeaponsLBox_->getId()) { std::pair<int, void *> * pPair = static_cast<std::pair<int, void *> *> (ctx); pSelectedWeap_ = static_cast<Weapon *> (pPair->second); showModWeaponPanel(); } else if (actionId == cancelButId_) { showItemList(); } else if (actionId == reloadButId_) { Agent *selected = g_Session.agents().squadMember(cur_agent_); WeaponInstance *wi = selected->weapon(selectedWInstId_ - 1); int rldCost = (pSelectedWeap_->ammo() - wi->ammoRemaining()) * pSelectedWeap_->ammoCost(); if (g_Session.getMoney() >= rldCost) { g_Session.setMoney(g_Session.getMoney() - rldCost); wi->setAmmoRemaining(pSelectedWeap_->ammo()); getOption(reloadButId_)->setVisible(false); getStatic(moneyTxtId_)->setTextFormated("%d", g_Session.getMoney()); } } else if (actionId == purchaseButId_) { // Buying weapon if (pSelectedWeap_) { if (sel_all_) { for (int n = 0; n < 4; n++) { Agent *selected = g_Session.agents().squadMember(n); if (selected && selected->numWeapons() < 8 && g_Session.getMoney() >= pSelectedWeap_->cost()) { g_Session.setMoney(g_Session.getMoney() - pSelectedWeap_->cost()); selected->addWeapon(pSelectedWeap_->createInstance()); getStatic(moneyTxtId_)->setTextFormated("%d", g_Session.getMoney()); } } } else { Agent *selected = g_Session.agents().squadMember(cur_agent_); if (selected && selected->numWeapons() < 8 && g_Session.getMoney() >= pSelectedWeap_->cost()) { g_Session.setMoney(g_Session.getMoney() - pSelectedWeap_->cost()); selected->addWeapon(pSelectedWeap_->createInstance()); getStatic(moneyTxtId_)->setTextFormated("%d", g_Session.getMoney()); } } needRendering(); } else if (pSelectedMod_) { if (sel_all_) { for (int n = 0; n < 4; n++) { Agent *selected = g_Session.agents().squadMember(n); if (selected && selected->canHaveMod(pSelectedMod_) && g_Session.getMoney() >= pSelectedMod_->cost()) { selected->addMod(pSelectedMod_); g_Session.setMoney(g_Session.getMoney() - pSelectedMod_->cost()); getStatic(moneyTxtId_)->setTextFormated("%d", g_Session.getMoney()); } } } else { Agent *selected = g_Session.agents().squadMember(cur_agent_); if (selected && selected->canHaveMod(pSelectedMod_) && g_Session.getMoney() >= pSelectedMod_->cost()) { selected->addMod(pSelectedMod_); g_Session.setMoney(g_Session.getMoney() - pSelectedMod_->cost()); getStatic(moneyTxtId_)->setTextFormated("%d", g_Session.getMoney()); } } showItemList(); } } else if (actionId == sellButId_ && selectedWInstId_) { addDirtyRect(360, 305, 135, 70); Agent *selected = g_Session.agents().squadMember(cur_agent_); WeaponInstance *pWi = selected->removeWeapon(selectedWInstId_ - 1); g_Session.setMoney(g_Session.getMoney() + pWi->getWeaponClass()->cost()); getStatic(moneyTxtId_)->setTextFormated("%d", g_Session.getMoney()); delete pWi; showItemList(); } }