/** * Click on the map to pick up loot. We need the camera position to translate * screen coordinates to map locations. */ ItemStack LootManager::checkPickup(Point mouse, FPoint cam, FPoint hero_pos, MenuInventory *inv) { Rect r; ItemStack loot_stack; // check left mouse click if (!NO_MOUSE) { // I'm starting at the end of the loot list so that more recently-dropped // loot is picked up first. If a player drops several loot in the same // location, picking it back up will work like a stack. std::vector<Loot>::iterator it; for (it = loot.end(); it != loot.begin(); ) { --it; // loot close enough to pickup? if (fabs(hero_pos.x - it->pos.x) < INTERACT_RANGE && fabs(hero_pos.y - it->pos.y) < INTERACT_RANGE && !it->isFlying()) { Point p = map_to_screen(it->pos.x, it->pos.y, cam.x, cam.y); r.x = p.x - TILE_W_HALF; r.y = p.y - TILE_H_HALF; r.w = TILE_W; r.h = TILE_H; // clicked in pickup hotspot? if (isWithin(r, mouse)) { curs->setCursor(CURSOR_INTERACT); if (inpt->pressing[MAIN1] && !inpt->lock[MAIN1]) { inpt->lock[MAIN1] = true; if (!it->stack.empty()) { if (!(inv->full(it->stack.item))) { loot_stack = it->stack; it = loot.erase(it); return loot_stack; } else { full_msg = true; } } } } } } } // check pressing Enter/Return if (inpt->pressing[ACCEPT] && !inpt->lock[ACCEPT]) { loot_stack = checkNearestPickup(hero_pos, inv); if (!loot_stack.empty()) { inpt->lock[ACCEPT] = true; } } return loot_stack; }
/** * Click on the map to pick up loot. We need the camera position to translate * screen coordinates to map locations. */ ItemStack LootManager::checkPickup(const Point& mouse, const FPoint& cam, const FPoint& hero_pos) { ItemStack loot_stack; // check left mouse click if (inpt->usingMouse()) { // I'm starting at the end of the loot list so that more recently-dropped // loot is picked up first. If a player drops several loot in the same // location, picking it back up will work like a stack. std::vector<Loot>::iterator it, it_tip, it_hotspot; it_tip = it_hotspot = loot.end(); for (it = loot.end(); it != loot.begin(); ) { --it; // loot close enough to pickup? if (fabs(hero_pos.x - it->pos.x) < eset->misc.interact_range && fabs(hero_pos.y - it->pos.y) < eset->misc.interact_range && !it->isFlying()) { Point p = Utils::mapToScreen(it->pos.x, it->pos.y, cam.x, cam.y); Rect r; r.x = p.x - eset->tileset.tile_w_half; r.y = p.y - eset->tileset.tile_h_half; r.w = eset->tileset.tile_w; r.h = eset->tileset.tile_h; if (it_tip == loot.end() && it->tip_visible && Utils::isWithinRect(it->tip_bounds, mouse)) { // clicked on a tooltip curs->setCursor(CursorManager::CURSOR_INTERACT); if (inpt->pressing[Input::MAIN1] && !inpt->lock[Input::MAIN1] && !it->stack.empty()) { it_tip = it; } } else if (it_hotspot == loot.end() && Utils::isWithinRect(r, mouse)) { // clicked on a hotspot curs->setCursor(CursorManager::CURSOR_INTERACT); if (inpt->pressing[Input::MAIN1] && !inpt->lock[Input::MAIN1] && !it->stack.empty()) { it_hotspot = it; } } // tooltips take priority over hotspots, so we can jump out here if we clicked on a tooltip if (it_tip != loot.end()) break; } } if (it_tip != loot.end()) { inpt->lock[Input::MAIN1] = true; loot_stack = it_tip->stack; loot.erase(it_tip); return loot_stack; } else if (it_hotspot != loot.end()) { inpt->lock[Input::MAIN1] = true; loot_stack = it_hotspot->stack; loot.erase(it_hotspot); return loot_stack; } } // check pressing Enter/Return if (inpt->pressing[Input::ACCEPT] && !inpt->lock[Input::ACCEPT]) { loot_stack = checkNearestPickup(hero_pos); if (!loot_stack.empty()) { inpt->lock[Input::ACCEPT] = true; } } return loot_stack; }