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


C++ InventoryList类代码示例

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


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

示例1: push_inventory_list

void push_inventory_list(lua_State *L, Inventory *inv, const char *name)
{
	InventoryList *invlist = inv->getList(name);
	if(invlist == NULL){
		lua_pushnil(L);
		return;
	}
	std::vector<ItemStack> items;
	for(u32 i=0; i<invlist->getSize(); i++)
		items.push_back(invlist->getItem(i));
	push_items(L, items);
}
开发者ID:Nate-Devv,项目名称:freeminer,代码行数:12,代码来源:c_content.cpp

示例2: inventory

Player::Player(const std::string & name, IItemDefManager *idef):
	inventory(idef),
	peer_id(PEER_ID_INEXISTENT),
	keyPressed(0),
// protected
	m_speed(0,0,0)
{
	peer_id = PEER_ID_INEXISTENT;
	m_name = name;
	hotbar_image_items = 0;

	inventory.clear();
	inventory.addList("main", PLAYER_INVENTORY_SIZE);
	inventory.addList("hand", 1);
	InventoryList *craft = inventory.addList("craft", 9);
	craft->setWidth(3);
	inventory.addList("craftpreview", 1);
	inventory.addList("craftresult", 1);
	inventory.setModified(false);

	// Can be redefined via Lua
	inventory_formspec = "size[8,7.5]"
		//"image[1,0.6;1,2;player.png]"
		"list[current_player;main;0,3.5;8,4;]"
		"list[current_player;craft;3,0;3,3;]"
		"listring[]"
		"list[current_player;craftpreview;7,1;1,1;]";

	// Initialize movement settings at default values, so movement can work
	// if the server fails to send them
	movement_acceleration_default   = 3    * BS;
	movement_acceleration_air       = 2    * BS;
	movement_acceleration_fast      = 10   * BS;
	movement_speed_walk             = 4    * BS;
	movement_speed_crouch           = 1.35 * BS;
	movement_speed_fast             = 20   * BS;
	movement_speed_climb            = 2    * BS;
	movement_speed_jump             = 6.5  * BS;
	movement_liquid_fluidity        = 1    * BS;
	movement_liquid_fluidity_smooth = 0.5  * BS;
	movement_liquid_sink            = 10   * BS;
	movement_gravity                = 9.81 * BS;
	movement_fall_aerodynamics      = 110;
	local_animation_speed           = 0.0;

	hud_flags =
		HUD_FLAG_HOTBAR_VISIBLE    | HUD_FLAG_HEALTHBAR_VISIBLE |
		HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
		HUD_FLAG_BREATHBAR_VISIBLE | HUD_FLAG_MINIMAP_VISIBLE;

	hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;
}
开发者ID:alexxvk,项目名称:freeminer,代码行数:52,代码来源:player.cpp

示例3: inventory

Player::Player(const char *name, IItemDefManager *idef):
	inventory(idef)
{
	strlcpy(m_name, name, PLAYERNAME_SIZE);

	inventory.clear();
	inventory.addList("main", PLAYER_INVENTORY_SIZE);
	inventory.addList("hand", 1);
	InventoryList *craft = inventory.addList("craft", 9);
	craft->setWidth(3);
	inventory.addList("craftpreview", 1);
	inventory.addList("craftresult", 1);
	inventory.setModified(false);

	// Can be redefined via Lua
	inventory_formspec = "size[8,7.5]"
		//"image[1,0.6;1,2;player.png]"
		"list[current_player;main;0,3.5;8,4;]"
		"list[current_player;craft;3,0;3,3;]"
		"listring[]"
		"list[current_player;craftpreview;7,1;1,1;]";

	// Initialize movement settings at default values, so movement can work
	// if the server fails to send them
	movement_acceleration_default   = 3    * BS;
	movement_acceleration_air       = 2    * BS;
	movement_acceleration_fast      = 10   * BS;
	movement_speed_walk             = 4    * BS;
	movement_speed_crouch           = 1.35 * BS;
	movement_speed_fast             = 20   * BS;
	movement_speed_climb            = 2    * BS;
	movement_speed_jump             = 6.5  * BS;
	movement_liquid_fluidity        = 1    * BS;
	movement_liquid_fluidity_smooth = 0.5  * BS;
	movement_liquid_sink            = 10   * BS;
	movement_gravity                = 9.81 * BS;
	local_animation_speed           = 0.0;

	hud_flags =
		HUD_FLAG_HOTBAR_VISIBLE    | HUD_FLAG_HEALTHBAR_VISIBLE |
		HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
		HUD_FLAG_BREATHBAR_VISIBLE | HUD_FLAG_MINIMAP_VISIBLE   |
		HUD_FLAG_MINIMAP_RADAR_VISIBLE;

	hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;

	m_player_settings.readGlobalSettings();
	// Register player setting callbacks
	for (const std::string &name : m_player_settings.setting_names)
		g_settings->registerChangedCallback(name,
			&Player::settingsChangedCallback, &m_player_settings);
}
开发者ID:GottfriedSp,项目名称:minetest,代码行数:52,代码来源:player.cpp

示例4: Contents

InventoryList Inventory::Contents() const
{
	InventoryList list;
	
	for (InventoryMap::const_iterator itr = inventory.begin();
		itr != inventory.end();
		itr++)
	{
		list.push_back((*(itr)).first);
	}

	return list;
}
开发者ID:khariq,项目名称:Survive,代码行数:13,代码来源:Inventory.cpp

示例5: checkobject

// get_stack(self, listname, i) -> itemstack
int InvRef::l_get_stack(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	InvRef *ref = checkobject(L, 1);
	const char *listname = luaL_checkstring(L, 2);
	int i = luaL_checknumber(L, 3) - 1;
	InventoryList *list = getlist(L, ref, listname);
	ItemStack item;
	if(list != NULL && i >= 0 && i < (int) list->getSize())
		item = list->getItem(i);
	LuaItemStack::create(L, item);
	return 1;
}
开发者ID:4Evergreen4,项目名称:minetest,代码行数:14,代码来源:l_inventory.cpp

示例6: verifyDatabase

bool PlayerDatabaseSQLite3::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
{
	verifyDatabase();

	str_to_sqlite(m_stmt_player_load, 1, player->getName());
	if (sqlite3_step(m_stmt_player_load) != SQLITE_ROW) {
		sqlite3_reset(m_stmt_player_load);
		return false;
	}
	sao->setPitch(sqlite_to_float(m_stmt_player_load, 0));
	sao->setYaw(sqlite_to_float(m_stmt_player_load, 1));
	sao->setBasePosition(sqlite_to_v3f(m_stmt_player_load, 2));
	sao->setHPRaw((s16) MYMIN(sqlite_to_int(m_stmt_player_load, 5), S16_MAX));
	sao->setBreath((u16) MYMIN(sqlite_to_int(m_stmt_player_load, 6), U16_MAX), false);
	sqlite3_reset(m_stmt_player_load);

	// Load inventory
	str_to_sqlite(m_stmt_player_load_inventory, 1, player->getName());
	while (sqlite3_step(m_stmt_player_load_inventory) == SQLITE_ROW) {
		InventoryList *invList = player->inventory.addList(
			sqlite_to_string(m_stmt_player_load_inventory, 2),
			sqlite_to_uint(m_stmt_player_load_inventory, 3));
		invList->setWidth(sqlite_to_uint(m_stmt_player_load_inventory, 1));

		u32 invId = sqlite_to_uint(m_stmt_player_load_inventory, 0);

		str_to_sqlite(m_stmt_player_load_inventory_items, 1, player->getName());
		int_to_sqlite(m_stmt_player_load_inventory_items, 2, invId);
		while (sqlite3_step(m_stmt_player_load_inventory_items) == SQLITE_ROW) {
			const std::string itemStr = sqlite_to_string(m_stmt_player_load_inventory_items, 1);
			if (itemStr.length() > 0) {
				ItemStack stack;
				stack.deSerialize(itemStr);
				invList->addItem(sqlite_to_uint(m_stmt_player_load_inventory_items, 0), stack);
			}
		}
		sqlite3_reset(m_stmt_player_load_inventory_items);
	}

	sqlite3_reset(m_stmt_player_load_inventory);

	str_to_sqlite(m_stmt_player_metadata_load, 1, sao->getPlayer()->getName());
	while (sqlite3_step(m_stmt_player_metadata_load) == SQLITE_ROW) {
		std::string attr = sqlite_to_string(m_stmt_player_metadata_load, 0);
		std::string value = sqlite_to_string(m_stmt_player_metadata_load, 1);

		sao->setExtendedAttribute(attr, value);
	}
	sqlite3_reset(m_stmt_player_metadata_load);
	return true;
}
开发者ID:MultiCraftProject,项目名称:MultiCraft,代码行数:51,代码来源:database-sqlite3.cpp

示例7: checkobject

// room_for_item(self, listname, itemstack or itemstring or table or nil) -> true/false
// Returns true if the item completely fits into the list
int InvRef::l_room_for_item(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	InvRef *ref = checkobject(L, 1);
	const char *listname = luaL_checkstring(L, 2);
	ItemStack item = read_item(L, 3,STACK_TO_SERVER(L));
	InventoryList *list = getlist(L, ref, listname);
	if(list){
		lua_pushboolean(L, list->roomForItem(item));
	} else {
		lua_pushboolean(L, false);
	}
	return 1;
}
开发者ID:EcoleKeine,项目名称:minetest,代码行数:16,代码来源:l_inventory.cpp

示例8: getInventory

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

示例9: getClient

int ModApiClient::l_get_wielded_item(lua_State *L)
{
	Client *client = getClient(L);

	Inventory local_inventory(client->idef());
	client->getLocalInventory(local_inventory);

	InventoryList *mlist = local_inventory.getList("main");

	if (mlist && client->getPlayerItem() < mlist->getSize()) {
		LuaItemStack::create(L, mlist->getItem(client->getPlayerItem()));
	} else {
		LuaItemStack::create(L, ItemStack());
	}
	return 1;
}
开发者ID:juhdanad,项目名称:minetest,代码行数:16,代码来源:l_client.cpp

示例10: assert

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 = 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:ray8888,项目名称:MINETEST-Minetest-classic-remoboray,代码行数:47,代码来源:guiInventoryMenu.cpp

示例11: touching_ground

Player::Player(IGameDef *gamedef):
    touching_ground(false),
    in_liquid(false),
    in_liquid_stable(false),
    liquid_viscosity(0),
    is_climbing(false),
    swimming_vertical(false),
    camera_barely_in_ceiling(false),
    inventory(gamedef->idef()),
    hp(PLAYER_MAX_HP),
    peer_id(PEER_ID_INEXISTENT),
// protected
    m_gamedef(gamedef),
    m_pitch(0),
    m_yaw(0),
    m_speed(0,0,0),
    m_position(0,0,0)
{
    updateName("<not set>");
    inventory.clear();
    inventory.addList("main", PLAYER_INVENTORY_SIZE);
    InventoryList *craft = inventory.addList("craft", 9);
    craft->setWidth(3);
    inventory.addList("craftpreview", 1);
    inventory.addList("craftresult", 1);

    // Can be redefined via Lua
    inventory_formspec =  "size[8,7.5]"
                          //"image[1,0.6;1,2;player.png]"
                          "list[current_player;main;0,3.5;8,4;]"
                          "list[current_player;craft;3,0;3,3;]"
                          "list[current_player;craftpreview;7,1;1,1;]";

    // Initialize movement settings at default values, so movement can work if the server fails to send them
    movement_acceleration_default = 3 * BS;
    movement_acceleration_air = 2 * BS;
    movement_acceleration_fast = 10 * BS;
    movement_speed_walk = 4 * BS;
    movement_speed_crouch = 1.35 * BS;
    movement_speed_fast = 20 * BS;
    movement_speed_climb = 2 * BS;
    movement_speed_jump = 6.5 * BS;
    movement_liquid_fluidity = 1 * BS;
    movement_liquid_fluidity_smooth = 0.5 * BS;
    movement_liquid_sink = 10 * BS;
    movement_gravity = 9.81 * BS;
}
开发者ID:ChicoTeam,项目名称:minetest,代码行数:47,代码来源:player.cpp

示例12: getInventory

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

示例13: checkobject

// 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

示例14: assert

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

示例15: getCraftingResult

// Crafting helper
bool getCraftingResult(Inventory *inv, ItemStack& result,
		std::vector<ItemStack> &output_replacements,
		bool decrementInput, IGameDef *gamedef)
{
	DSTACK(__FUNCTION_NAME);
	
	result.clear();

	// Get the InventoryList in which we will operate
	InventoryList *clist = inv->getList("craft");
	if(!clist)
		return false;

	// Mangle crafting grid to an another format
	CraftInput ci;
	ci.method = CRAFT_METHOD_NORMAL;
	ci.width = clist->getWidth() ? clist->getWidth() : 3;
	for(u16 i=0; i<clist->getSize(); i++)
		ci.items.push_back(clist->getItem(i));

	// Find out what is crafted and add it to result item slot
	CraftOutput co;
	bool found = gamedef->getCraftDefManager()->getCraftResult(
			ci, co, output_replacements, decrementInput, gamedef);
	if(found)
		result.deSerialize(co.item, gamedef->getItemDefManager());

	if(found && decrementInput)
	{
		// CraftInput has been changed, apply changes in clist
		for(u16 i=0; i<clist->getSize(); i++)
		{
			clist->changeItem(i, ci.items[i]);
		}
	}

	return found;
}
开发者ID:BlazingGamer,项目名称:InfinityCraft,代码行数:39,代码来源:inventorymanager.cpp


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