本文整理汇总了C++中InventoryList::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ InventoryList::getSize方法的具体用法?C++ InventoryList::getSize怎么用?C++ InventoryList::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InventoryList
的用法示例。
在下文中一共展示了InventoryList::getSize方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: l_get_size
// get_size(self, listname)
int InvRef::l_get_size(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
InvRef *ref = checkobject(L, 1);
const char *listname = luaL_checkstring(L, 2);
InventoryList *list = getlist(L, ref, listname);
if(list){
lua_pushinteger(L, list->getSize());
} else {
lua_pushinteger(L, 0);
}
return 1;
}
示例3: l_get_stack
// 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;
}
示例4: 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;
}
示例5: l_get_wielded_item
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;
}
示例6: l_set_stack
// set_stack(self, listname, i, stack) -> true/false
int InvRef::l_set_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;
ItemStack newitem = read_item(L, 4, getServer(L)->idef());
InventoryList *list = getlist(L, ref, listname);
if(list != NULL && i >= 0 && i < (int) list->getSize()){
list->changeItem(i, newitem);
reportInventoryChange(L, ref);
lua_pushboolean(L, true);
} else {
lua_pushboolean(L, false);
}
return 1;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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);
//.........这里部分代码省略.........
示例10: OnEvent
bool GUIFormSpecMenu::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.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
{
acceptInput();
quitMenu();
return true;
}
}
if(event.EventType==EET_MOUSE_INPUT_EVENT
&& event.MouseInput.Event == EMIE_MOUSE_MOVED)
{
// Mouse moved
m_pointer = v2s32(event.MouseInput.X, event.MouseInput.Y);
}
if(event.EventType==EET_MOUSE_INPUT_EVENT
&& event.MouseInput.Event != EMIE_MOUSE_MOVED)
{
// Mouse event other than movement
v2s32 p(event.MouseInput.X, event.MouseInput.Y);
m_pointer = p;
// Get selected item and hovered/clicked item (s)
updateSelectedItem();
ItemSpec s = getItemAtPos(p);
Inventory *inv_selected = NULL;
Inventory *inv_s = NULL;
if(m_selected_item)
{
inv_selected = m_invmgr->getInventory(m_selected_item->inventoryloc);
assert(inv_selected);
assert(inv_selected->getList(m_selected_item->listname) != NULL);
}
u32 s_count = 0;
if(s.isValid())
do{ // breakable
inv_s = m_invmgr->getInventory(s.inventoryloc);
if(!inv_s){
errorstream<<"InventoryMenu: The selected inventory location "
<<"\""<<s.inventoryloc.dump()<<"\" doesn't exist"
<<std::endl;
s.i = -1; // make it invalid again
break;
}
InventoryList *list = inv_s->getList(s.listname);
if(list == NULL){
verbosestream<<"InventoryMenu: The selected inventory list \""
<<s.listname<<"\" does not exist"<<std::endl;
s.i = -1; // make it invalid again
break;
}
if((u32)s.i >= list->getSize()){
infostream<<"InventoryMenu: The selected inventory list \""
<<s.listname<<"\" is too small (i="<<s.i<<", size="
<<list->getSize()<<")"<<std::endl;
s.i = -1; // make it invalid again
break;
}
s_count = list->getItem(s.i).count;
}while(0);
bool identical = (m_selected_item != NULL) && s.isValid() &&
(inv_selected == inv_s) &&
(m_selected_item->listname == s.listname) &&
(m_selected_item->i == s.i);
// buttons: 0 = left, 1 = right, 2 = middle
// up/down: 0 = down (press), 1 = up (release), 2 = unknown event
int button = 0;
int updown = 2;
if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{ button = 0; updown = 0; }
else if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
{ button = 1; updown = 0; }
else if(event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN)
{ button = 2; updown = 0; }
else if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
{ button = 0; updown = 1; }
else if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP)
{ button = 1; updown = 1; }
else if(event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP)
//.........这里部分代码省略.........
示例11: updateSelectedItem
void GUIFormSpecMenu::updateSelectedItem()
{
// WARNING: BLACK MAGIC
// See if there is a stack suited for our current guess.
// If such stack does not exist, clear the guess.
if(m_selected_content_guess.name != "")
{
bool found = false;
for(u32 i=0; i<m_inventorylists.size() && !found; i++){
const ListDrawSpec &s = m_inventorylists[i];
Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
if(!inv)
continue;
InventoryList *list = inv->getList(s.listname);
if(!list)
continue;
for(s32 i=0; i<s.geom.X*s.geom.Y && !found; i++){
u32 item_i = i + s.start_item_i;
if(item_i >= list->getSize())
continue;
ItemStack stack = list->getItem(item_i);
if(stack.name == m_selected_content_guess.name &&
stack.count == m_selected_content_guess.count){
found = true;
if(m_selected_item){
// If guessed stack is already selected, all is fine
if(m_selected_item->inventoryloc == s.inventoryloc &&
m_selected_item->listname == s.listname &&
m_selected_item->i == (s32)item_i &&
m_selected_amount == stack.count){
break;
}
delete m_selected_item;
m_selected_item = NULL;
}
infostream<<"Client: Changing selected content guess to "
<<s.inventoryloc.dump()<<" "<<s.listname
<<" "<<item_i<<std::endl;
m_selected_item = new ItemSpec(s.inventoryloc, s.listname, item_i);
m_selected_amount = stack.count;
break;
}
}
}
if(!found){
infostream<<"Client: Discarding selected content guess: "
<<m_selected_content_guess.getItemString()<<std::endl;
m_selected_content_guess.name = "";
}
}
// If the selected stack has become empty for some reason, deselect it.
// If the selected stack has become smaller, adjust m_selected_amount.
if(m_selected_item)
{
bool selection_valid = false;
if(m_selected_item->isValid())
{
Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc);
if(inv)
{
InventoryList *list = inv->getList(m_selected_item->listname);
if(list && (u32) m_selected_item->i < list->getSize())
{
ItemStack stack = list->getItem(m_selected_item->i);
if(m_selected_amount > stack.count)
m_selected_amount = stack.count;
if(!stack.empty())
selection_valid = true;
}
}
}
if(!selection_valid)
{
delete m_selected_item;
m_selected_item = NULL;
m_selected_amount = 0;
m_selected_dragging = false;
}
}
// If craftresult is nonempty and nothing else is selected, select it now.
if(!m_selected_item)
{
for(u32 i=0; i<m_inventorylists.size(); i++)
{
const ListDrawSpec &s = m_inventorylists[i];
if(s.listname == "craftpreview")
{
Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
InventoryList *list = inv->getList("craftresult");
if(list && list->getSize() >= 1 && !list->getItem(0).empty())
{
m_selected_item = new ItemSpec;
m_selected_item->inventoryloc = s.inventoryloc;
m_selected_item->listname = "craftresult";
m_selected_item->i = 0;
m_selected_amount = 0;
m_selected_dragging = false;
break;
}
//.........这里部分代码省略.........
示例12: drawList
void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase)
{
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(s.inventoryloc);
if(!inv){
infostream<<"GUIFormSpecMenu::drawList(): WARNING: "
<<"The inventory location "
<<"\""<<s.inventoryloc.dump()<<"\" doesn't exist"
<<std::endl;
return;
}
InventoryList *ilist = inv->getList(s.listname);
if(!ilist){
infostream<<"GUIFormSpecMenu::drawList(): WARNING: "
<<"The inventory list \""<<s.listname<<"\" @ \""
<<s.inventoryloc.dump()<<"\" doesn't exist"
<<std::endl;
return;
}
core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
{
u32 item_i = i + s.start_item_i;
if(item_i >= ilist->getSize())
break;
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;
ItemStack item;
if(ilist)
item = ilist->getItem(item_i);
bool selected = m_selected_item
&& m_invmgr->getInventory(m_selected_item->inventoryloc) == inv
&& m_selected_item->listname == s.listname
&& m_selected_item->i == i;
bool hovering = rect.isPointInside(m_pointer);
if(phase == 0)
{
if(hovering && m_selected_item)
{
video::SColor bgcolor(255,192,192,192);
driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
}
else
{
video::SColor bgcolor(255,128,128,128);
driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
}
}
if(phase == 1)
{
// Draw item stack
if(selected)
{
item.takeItem(m_selected_amount);
}
if(!item.empty())
{
drawItemStack(driver, font, item,
rect, &AbsoluteClippingRect, m_gamedef);
}
// Draw tooltip
std::string tooltip_text = "";
if(hovering && !m_selected_item)
tooltip_text = item.getDefinition(m_gamedef->idef()).description;
if(tooltip_text != "")
{
m_tooltip_element->setVisible(true);
this->bringToFront(m_tooltip_element);
m_tooltip_element->setText(narrow_to_wide(tooltip_text).c_str());
s32 tooltip_x = m_pointer.X + 15;
s32 tooltip_y = m_pointer.Y + 15;
s32 tooltip_width = m_tooltip_element->getTextWidth() + 15;
s32 tooltip_height = m_tooltip_element->getTextHeight() + 5;
m_tooltip_element->setRelativePosition(core::rect<s32>(
core::position2d<s32>(tooltip_x, tooltip_y),
core::dimension2d<s32>(tooltip_width, tooltip_height)));
}
}
}
}