int CmdPutInto::execute() { int turns = 0; ActorPtr target = SingleNeighbourSelector("Select a container to put into...") .select() .firstActor(); if ( target != nullptr && target->hasFeature<Inventory>()) { OpenablePtr openable = target->getFeature<Openable>(); if ( openable && openable->isClosed() ) { gui::msgBox("Cannot put into " + target->getName() + " - it is closed.", gui::MsgType::Warning); } else { auto afterPutIntoAction = [&](const std::string& item, int amount) { target->notify(Event(EventId::Actor_Put,{{"putter","Player"}, {"container",target->getName()}, {"count", std::to_string(amount)}, {"item", tolowers(item)}})); }; auto containerFullAction = [&target](const std::string& item) { gui::msgBox("Cannot put "+item+" into "+tolowers(target->getName())+":#Not enough space!", gui::MsgType::Error); }; Engine::instance().getWindowManager() .getWindow<gui::PickUpWindow>() .setPicker(target) .setSource( [](){ return Engine::instance().getPlayer()->getFeature<Inventory>()->items(); }) .setRemoveAction([&](ActorPtr a){Engine::instance().getPlayer()->getFeature<Inventory>()->remove(a);}) .setAfterPickupAction( afterPutIntoAction ) .setInventoryFullAction( containerFullAction ) .setWindowTitle("Select item to put") .show(); } ++turns; } else if ( target ) { gui::msgBox("You cannot put anything into "+tolowers(target->getName())+".", gui::MsgType::Error); } return turns; }
BagManager::ItemOperation BagManager::chooseItemOperationFromMenu(ActorPtr selected) { MenuWindow& menu = Engine::instance().windowManager().getWindow<MenuWindow>(); menu.setTitle( selected->getName() ); menu.setPosition( gui::AWidget::WINDOW_CENTER ); if ( selected->getFeature<Pickable>()->isEquippable() ) { ALabelMenuItemPtr itemEquip( new ALabelMenuItem ); itemEquip->setValue("Equip"); itemEquip->setProperty<int>("operation", EQUIP); menu.addMenuItem( itemEquip ); } ALabelMenuItemPtr itemDrop( new ALabelMenuItem ); itemDrop->setValue("Drop"); itemDrop->setProperty<int>("operation", DROP); menu.addMenuItem( itemDrop ); ALabelMenuItemPtr itemInfo( new ALabelMenuItem ); itemInfo->setValue("Inspect"); itemInfo->setProperty<int>("operation", INSPECT); menu.addMenuItem( itemInfo ); menu.show(); AMenuItemPtr sItem = menu.getSelectedItem(); return sItem ? static_cast<ItemOperation>(sItem->getProperty<int>("operation")) : INVALID; }
void CmdClose::execute() { Target target = SingleNeighbourSelector("Select object to close...") .select(); auto openableIter = std::find_if(target.actors.begin(), target.actors.end(), [](ActorPtr a) { return a->getFeature<Openable>(); }); ActorPtr toClose = openableIter != target.actors.end() ? *openableIter : nullptr; if ( toClose != nullptr) { if ( target.actors.size() == 1 ) { Actor::Player->performAction( std::make_shared<CloseAction>(toClose) ); } else { gui::msgBox("Cannot close " + tolowers(toClose->getName())+":\n" "It is blocked!", gui::MsgType::Warning); } } else { gui::msgBox("Nothing to close there.", gui::MsgType::Warning); } }
void CmdPutInto::execute() { ActorPtr target = SingleNeighbourSelector("Select a container to put into...") .select() .firstActor(); if ( target != nullptr && target->hasFeature<Container>()) { auto afterPutIntoAction = [&](const std::string& item, int amount) { Messenger::message()->actorPutInto(Actor::Player->getName(), target->getName(), item, amount); }; auto containerFullAction = [&target](const std::string& item) { gui::msgBox("Cannot put "+item+" into "+tolowers(target->getName())+":\nNot enough space!", gui::MsgType::Error); }; Engine::instance().windowManager() .getWindow<gui::PickUpWindow>() .setPicker(target) .setContainer(Actor::Player->getFeature<Container>()) .setAfterPickupAction( afterPutIntoAction ) .setInventoryFullAction( containerFullAction ) .setWindowTitle("Select item to put") .show(); } else if ( target ) { gui::msgBox("You cannot put anything into "+tolowers(target->getName())+".", gui::MsgType::Error); } }
std::string Wearer::debug(const std::string &linebreak) { std::string d = " " + linebreak + "-----WEARER-----"+linebreak; for(auto slot : _itemSlots) { ActorPtr eq = equipped(slot.first); bool blocked = isBlocked(slot.first); PickablePtr p = eq ? eq->getFeature<Pickable>() : nullptr; d += ItemSlotType2Str(slot.first); d += ": " + (eq ? eq->getName() : "<none>") + (p ? " [" + toStr(p->getAmount()) + "]" : "" ) + ( blocked ? " [BLOCKED] " : "" ) + linebreak; } d.append("----------------"+linebreak); return d; }