当前位置: 首页>>代码示例>>C++>>正文


C++ Inventory::getList方法代码示例

本文整理汇总了C++中Inventory::getList方法的典型用法代码示例。如果您正苦于以下问题:C++ Inventory::getList方法的具体用法?C++ Inventory::getList怎么用?C++ Inventory::getList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Inventory的用法示例。


在下文中一共展示了Inventory::getList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getlist

InventoryList* InvRef::getlist(lua_State *L, InvRef *ref,
		const char *listname)
{
	NO_MAP_LOCK_REQUIRED;
	Inventory *inv = getinv(L, ref);
	if(!inv)
		return NULL;
	return inv->getList(listname);
}
开发者ID:4Evergreen4,项目名称:minetest,代码行数:9,代码来源:l_inventory.cpp

示例2: nodeRemovalDisabled

bool FurnaceNodeMetadata::nodeRemovalDisabled()
{
	/*
		Disable removal if furnace is not empty
	*/
	InventoryList *list[3] = {m_inventory->getList("src"),
	m_inventory->getList("dst"), m_inventory->getList("fuel")};
	
	for(int i = 0; i < 3; i++) {
		if(list[i] == NULL)
			continue;
		if(list[i]->getUsedSlots() == 0)
			continue;
		return true;
	}
	return false;
	
}
开发者ID:Anchakor,项目名称:minetest,代码行数:18,代码来源:content_nodemeta.cpp

示例3: drawList

void GUIInventoryMenu::drawList(const ListDrawSpec &s)
{
	video::IVideoDriver* driver = Environment->getVideoDriver();

	// Get font
	gui::IGUIFont *font = NULL;
	gui::IGUISkin* skin = Environment->getSkin();
	if (skin)
		font = skin->getFont();
	
	Inventory *inv = m_invmgr->getInventory(m_c, s.inventoryname);
	assert(inv);
	InventoryList *ilist = inv->getList(s.listname);
	
	core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
	
	for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
	{
		s32 x = (i%s.geom.X) * spacing.X;
		s32 y = (i/s.geom.X) * spacing.Y;
		v2s32 p(x,y);
		core::rect<s32> rect = imgrect + s.pos + p;
		InventoryItem *item = NULL;
		if(ilist)
			item = ilist->getItem(i);

		if(m_selected_item != NULL && m_selected_item->listname == s.listname
				&& m_selected_item->i == i)
		{
			/*s32 border = imgsize.X/12;
			driver->draw2DRectangle(video::SColor(255,192,192,192),
					core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*border,
							rect.LowerRightCorner + v2s32(1,1)*border),
					NULL);
			driver->draw2DRectangle(video::SColor(255,0,0,0),
					core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*((border+1)/2),
							rect.LowerRightCorner + v2s32(1,1)*((border+1)/2)),
					NULL);*/
			s32 border = 2;
			driver->draw2DRectangle(video::SColor(255,255,0,0),
					core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*border,
							rect.LowerRightCorner + v2s32(1,1)*border),
					&AbsoluteClippingRect);
		}

		video::SColor bgcolor(255,128,128,128);
		driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);

		if(item)
		{
			drawInventoryItem(driver, font, item,
					rect, &AbsoluteClippingRect);
		}

	}
}
开发者ID:Jordach,项目名称:Minetest-Classic,代码行数:56,代码来源:guiInventoryMenu.cpp

示例4: setWieldedItem

bool PlayerSAO::setWieldedItem(const ItemStack &item)
{
	Inventory *inv = getInventory();
	if (inv) {
		InventoryList *mlist = inv->getList(getWieldList());
		if (mlist) {
			ItemStack olditem = mlist->getItem(getWieldIndex());
			if (olditem.name.empty()) {
				InventoryList *hlist = inv->getList("hand");
				if (hlist) {
					hlist->changeItem(0, item);
					return true;
				}
			}
			mlist->changeItem(getWieldIndex(), item);
			return true;
		}
	}
	return false;
}
开发者ID:alexxvk,项目名称:freeminer,代码行数:20,代码来源:content_sao.cpp

示例5: setWieldedItem

bool PlayerSAO::setWieldedItem(const ItemStack &item)
{
	Inventory *inv = getInventory();
	if (inv) {
		InventoryList *mlist = inv->getList(getWieldList());
		if (mlist) {
			mlist->changeItem(getWieldIndex(), item);
			return true;
		}
	}
	return false;
}
开发者ID:MultiCraftProject,项目名称:MultiCraft,代码行数:12,代码来源:content_sao.cpp

示例6: setWieldedItem

bool ServerActiveObject::setWieldedItem(const ItemStack &item)
{
	Inventory *inv = getInventory();
	if(inv)
	{
		InventoryList *list = inv->getList(getWieldList());
		if (list)
		{
			list->changeItem(getWieldIndex(), item);
			setInventoryModified();
			return true;
		}
	}
	return false;
}
开发者ID:Oblomov,项目名称:minetest,代码行数:15,代码来源:serverobject.cpp

示例7: getBurnResult

bool FurnaceNodeMetadata::getBurnResult(bool remove, float &burntime)
{
	std::vector<ItemStack> items;
	InventoryList *fuel_list = m_inventory->getList("fuel");
	assert(fuel_list);
	items.push_back(fuel_list->getItem(0));

	CraftInput ci(CRAFT_METHOD_FUEL, 1, items);
	CraftOutput co;
	bool found = m_gamedef->getCraftDefManager()->getCraftResult(
			ci, co, remove, m_gamedef);
	if(remove)
		fuel_list->changeItem(0, ci.items[0]);

	burntime = co.time;
	return found;
}
开发者ID:Anchakor,项目名称:minetest,代码行数:17,代码来源:content_nodemeta.cpp

示例8: l_set_list

// set_list(self, listname, list)
int InvRef::l_set_list(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	InvRef *ref = checkobject(L, 1);
	const char *listname = luaL_checkstring(L, 2);
	Inventory *inv = getinv(L, ref);
	if(inv == NULL){
		return 0;
	}
	InventoryList *list = inv->getList(listname);
	if(list)
		read_inventory_list(L, 3, inv, listname,
				getServer(L), list->getSize());
	else
		read_inventory_list(L, 3, inv, listname, getServer(L));
	reportInventoryChange(L, ref);
	return 0;
}
开发者ID:4Evergreen4,项目名称:minetest,代码行数:19,代码来源:l_inventory.cpp

示例9: l_set_width

// set_width(self, listname, size)
int InvRef::l_set_width(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	InvRef *ref = checkobject(L, 1);
	const char *listname = luaL_checkstring(L, 2);
	int newwidth = luaL_checknumber(L, 3);
	Inventory *inv = getinv(L, ref);
	if(inv == NULL){
		return 0;
	}
	InventoryList *list = inv->getList(listname);
	if(list){
		list->setWidth(newwidth);
	} else {
		return 0;
	}
	reportInventoryChange(L, ref);
	return 0;
}
开发者ID:4Evergreen4,项目名称:minetest,代码行数:20,代码来源:l_inventory.cpp

示例10: getCookResult

bool FurnaceNodeMetadata::getCookResult(bool remove,
		std::string &cookresult, float &cooktime)
{
	std::vector<ItemStack> items;
	InventoryList *src_list = m_inventory->getList("src");
	assert(src_list);
	items.push_back(src_list->getItem(0));

	CraftInput ci(CRAFT_METHOD_COOKING, 1, items);
	CraftOutput co;
	bool found = m_gamedef->getCraftDefManager()->getCraftResult(
			ci, co, remove, m_gamedef);
	if(remove)
		src_list->changeItem(0, ci.items[0]);

	cookresult = co.item;
	cooktime = co.time;
	return found;
}
开发者ID:Anchakor,项目名称:minetest,代码行数:19,代码来源:content_nodemeta.cpp

示例11: l_set_size

// set_size(self, listname, size)
int InvRef::l_set_size(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	InvRef *ref = checkobject(L, 1);
	const char *listname = luaL_checkstring(L, 2);

	int newsize = luaL_checknumber(L, 3);
	if (newsize < 0) {
		lua_pushboolean(L, false);
		return 1;
	}

	Inventory *inv = getinv(L, ref);
	if(inv == NULL){
		lua_pushboolean(L, false);
		return 1;
	}
	if(newsize == 0){
		inv->deleteList(listname);
		reportInventoryChange(L, ref);
		lua_pushboolean(L, true);
		return 1;
	}
	InventoryList *list = inv->getList(listname);
	if(list){
		list->setSize(newsize);
	} else {
		list = inv->addList(listname, newsize);
		if (!list)
		{
			lua_pushboolean(L, false);
			return 1;
		}
	}
	reportInventoryChange(L, ref);
	lua_pushboolean(L, true);
	return 1;
}
开发者ID:4Evergreen4,项目名称:minetest,代码行数:39,代码来源:l_inventory.cpp

示例12: l_set_lists

// set_lists(self, lists)
int InvRef::l_set_lists(lua_State *L)
{
    NO_MAP_LOCK_REQUIRED;
    InvRef *ref = checkobject(L, 1);
    Inventory *inv = getinv(L, ref);
    if (!inv) {
        return 0;
    }
    lua_pushnil(L);
    while (lua_next(L, 2)) {
        const char* listname = lua_tostring(L, -2);
        InventoryList *list = inv->getList(listname);
        if (list) {
            read_inventory_list(L, -1, inv, listname,
                                getServer(L), list->getSize());
        } else {
            read_inventory_list(L, -1, inv, listname,
                                getServer(L));
        }
        lua_pop(L, 1);
    }
    return 0;
}
开发者ID:hdastwb,项目名称:freeminer,代码行数:24,代码来源:l_inventory.cpp

示例13: drawSelectedItem

void GUIFormSpecMenu::drawSelectedItem()
{
	if(!m_selected_item)
		return;

	video::IVideoDriver* driver = Environment->getVideoDriver();

	// Get font
	gui::IGUIFont *font = NULL;
	gui::IGUISkin* skin = Environment->getSkin();
	if (skin)
		font = skin->getFont();
	
	Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc);
	assert(inv);
	InventoryList *list = inv->getList(m_selected_item->listname);
	assert(list);
	ItemStack stack = list->getItem(m_selected_item->i);
	stack.count = m_selected_amount;

	core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
	core::rect<s32> rect = imgrect + (m_pointer - imgrect.getCenter());
	drawItemStack(driver, font, stack, rect, NULL, m_gamedef);
}
开发者ID:Jeija,项目名称:minetest-ingame-modmanager,代码行数:24,代码来源:guiFormSpecMenu.cpp

示例14: applyRevert

bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const
{
	try {
		switch (type) {
		case TYPE_NOTHING:
			return true;
		case TYPE_SET_NODE: {
			INodeDefManager *ndef = gamedef->ndef();
			// Make sure position is loaded from disk
			map->emergeBlock(getContainerPos(p, MAP_BLOCKSIZE), false);
			// Check current node
			MapNode current_node = map->getNodeNoEx(p);
			std::string current_name = ndef->get(current_node).name;
			// If current node not the new node, it's bad
			if (current_name != n_new.name) {
				return false;
			}
			// Create rollback node
			MapNode n(ndef, n_old.name, n_old.param1, n_old.param2);
			// Set rollback node
			try {
				if (!map->addNodeWithEvent(p, n)) {
					infostream << "RollbackAction::applyRevert(): "
						<< "AddNodeWithEvent failed at "
						<< PP(p) << " for " << n_old.name
						<< std::endl;
					return false;
				}
				if (n_old.meta.empty()) {
					map->removeNodeMetadata(p);
				} else {
					NodeMetadata *meta = map->getNodeMetadata(p);
					if (!meta) {
						meta = new NodeMetadata(gamedef);
						if (!map->setNodeMetadata(p, meta)) {
							delete meta;
							infostream << "RollbackAction::applyRevert(): "
								<< "setNodeMetadata failed at "
								<< PP(p) << " for " << n_old.name
								<< std::endl;
							return false;
						}
					}
					std::istringstream is(n_old.meta, std::ios::binary);
					meta->deSerialize(is);
				}
				// Inform other things that the meta data has changed
				v3s16 blockpos = getContainerPos(p, MAP_BLOCKSIZE);
				MapEditEvent event;
				event.type = MEET_BLOCK_NODE_METADATA_CHANGED;
				event.p = blockpos;
				map->dispatchEvent(&event);
				// Set the block to be saved
				MapBlock *block = map->getBlockNoCreateNoEx(blockpos);
				if (block) {
					block->raiseModified(MOD_STATE_WRITE_NEEDED,
						MOD_REASON_REPORT_META_CHANGE);
				}
			} catch (InvalidPositionException &e) {
				infostream << "RollbackAction::applyRevert(): "
					<< "InvalidPositionException: " << e.what()
					<< std::endl;
				return false;
			}
			// Success
			return true; }
		case TYPE_MODIFY_INVENTORY_STACK: {
			InventoryLocation loc;
			loc.deSerialize(inventory_location);
			std::string real_name = gamedef->idef()->getAlias(inventory_stack.name);
			Inventory *inv = imgr->getInventory(loc);
			if (!inv) {
				infostream << "RollbackAction::applyRevert(): Could not get "
					"inventory at " << inventory_location << std::endl;
				return false;
			}
			InventoryList *list = inv->getList(inventory_list);
			if (!list) {
				infostream << "RollbackAction::applyRevert(): Could not get "
					"inventory list \"" << inventory_list << "\" in "
					<< inventory_location << std::endl;
				return false;
			}
			if (list->getSize() <= inventory_index) {
				infostream << "RollbackAction::applyRevert(): List index "
					<< inventory_index << " too large in "
					<< "inventory list \"" << inventory_list << "\" in "
					<< inventory_location << std::endl;
			}
			// If item was added, take away item, otherwise add removed item
			if (inventory_add) {
				// Silently ignore different current item
				if (list->getItem(inventory_index).name != real_name)
					return false;
				list->takeItem(inventory_index, inventory_stack.count);
			} else {
				list->addItem(inventory_index, inventory_stack);
			}
			// Inventory was modified; send to clients
			imgr->setInventoryModified(loc);
//.........这里部分代码省略.........
开发者ID:4aiman,项目名称:MultiCraft,代码行数:101,代码来源:rollback_interface.cpp

示例15: OnEvent

bool GUIInventoryMenu::OnEvent(const SEvent& event)
{
	if(event.EventType==EET_KEY_INPUT_EVENT)
	{
		KeyPress kp(event.KeyInput);
		if (event.KeyInput.PressedDown && (kp == EscapeKey ||
			kp == getKeySetting("keymap_inventory")))
		{
			quitMenu();
			return true;
		}
	}
	if(event.EventType==EET_MOUSE_INPUT_EVENT)
	{
		char amount = -1;

		if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
			amount = 0;
		else if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
			amount = 1;
		else if(event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN)
			amount = 10;

		if(amount >= 0)
		{
			v2s32 p(event.MouseInput.X, event.MouseInput.Y);
			//infostream<<"Mouse down at p=("<<p.X<<","<<p.Y<<")"<<std::endl;
			ItemSpec s = getItemAtPos(p);
			if(s.isValid())
			{
				infostream<<"Mouse down on "<<s.inventoryname
						<<"/"<<s.listname<<" "<<s.i<<std::endl;
				if(m_selected_item)
				{
					Inventory *inv_from = m_invmgr->getInventory(m_c,
							m_selected_item->inventoryname);
					Inventory *inv_to = m_invmgr->getInventory(m_c,
							s.inventoryname);
					assert(inv_from);
					assert(inv_to);
					InventoryList *list_from =
							inv_from->getList(m_selected_item->listname);
					InventoryList *list_to =
							inv_to->getList(s.listname);
					if(list_from == NULL)
						infostream<<"from list doesn't exist"<<std::endl;
					if(list_to == NULL)
						infostream<<"to list doesn't exist"<<std::endl;
					// Indicates whether source slot completely empties
					bool source_empties = false;
					if(list_from && list_to
							&& list_from->getItem(m_selected_item->i) != NULL)
					{
						infostream<<"Handing IACTION_MOVE to manager"<<std::endl;
						IMoveAction *a = new IMoveAction();
						a->count = amount;
						a->from_inv = m_selected_item->inventoryname;
						a->from_list = m_selected_item->listname;
						a->from_i = m_selected_item->i;
						a->to_inv = s.inventoryname;
						a->to_list = s.listname;
						a->to_i = s.i;
						//ispec.actions->push_back(a);
						m_invmgr->inventoryAction(a);

						if(list_from->getItem(m_selected_item->i)->getCount()==1)
							source_empties = true;
					}
					// Remove selection if target was left-clicked or source
					// slot was emptied
					if(amount == 0 || source_empties)
					{
						delete m_selected_item;
						m_selected_item = NULL;
					}
				}
				else
				{
					/*
						Select if non-NULL
					*/
					Inventory *inv = m_invmgr->getInventory(m_c,
							s.inventoryname);
					assert(inv);
					InventoryList *list = inv->getList(s.listname);
					if(list->getItem(s.i) != NULL)
					{
						m_selected_item = new ItemSpec(s);
					}
				}
			}
			else
			{
				if(m_selected_item)
				{
					delete m_selected_item;
					m_selected_item = NULL;
				}
			}
		}
//.........这里部分代码省略.........
开发者ID:ray8888,项目名称:MINETEST-Minetest-classic-remoboray,代码行数:101,代码来源:guiInventoryMenu.cpp


注:本文中的Inventory::getList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。