本文整理汇总了C++中InventoryList::getItem方法的典型用法代码示例。如果您正苦于以下问题:C++ InventoryList::getItem方法的具体用法?C++ InventoryList::getItem怎么用?C++ InventoryList::getItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InventoryList
的用法示例。
在下文中一共展示了InventoryList::getItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clickActiveObject
void Client::clickActiveObject(u8 button, u16 id, u16 item_i)
{
if(connectedAndInitialized() == false){
infostream<<"Client::clickActiveObject() "
"cancelled (not connected)"
<<std::endl;
return;
}
Player *player = m_env.getLocalPlayer();
if(player == NULL)
return;
ClientActiveObject *obj = m_env.getActiveObject(id);
if(obj){
if(button == 0){
ToolItem *titem = NULL;
std::string toolname = "";
InventoryList *mlist = player->inventory.getList("main");
if(mlist != NULL)
{
InventoryItem *item = mlist->getItem(item_i);
if(item && (std::string)item->getName() == "ToolItem")
{
titem = (ToolItem*)item;
toolname = titem->getToolName();
}
}
v3f playerpos = player->getPosition();
v3f objpos = obj->getPosition();
v3f dir = (objpos - playerpos).normalize();
bool disable_send = obj->directReportPunch(toolname, dir);
if(disable_send)
return;
}
}
/*
length: 7
[0] u16 command
[2] u8 button (0=left, 1=right)
[3] u16 id
[5] u16 item
*/
u8 datasize = 2 + 1 + 6 + 2 + 2;
SharedBuffer<u8> data(datasize);
writeU16(&data[0], TOSERVER_CLICK_ACTIVEOBJECT);
writeU8(&data[2], button);
writeU16(&data[3], id);
writeU16(&data[5], item_i);
Send(0, data, true);
}
示例2: 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);
}
}
}
示例3: 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);
}
示例4: 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;
}
示例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: 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;
}
示例7: 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;
}
示例8: 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);
}
示例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 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;
}
}
}
//.........这里部分代码省略.........
示例11: ProcessData
//.........这里部分代码省略.........
// Only digging of nodes
if(pointed.type == POINTEDTHING_NODE)
{
bool pos_ok;
MapNode n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
if (!pos_ok) {
infostream << "Server: Not finishing digging: Node not found."
<< " Adding block to emerge queue."
<< std::endl;
m_emerge->enqueueBlockEmerge(peer_id, getNodeBlockPos(p_above), false);
}
/* Cheat prevention */
bool is_valid_dig = true;
if(!isSingleplayer() && !g_settings->getBool("disable_anticheat"))
{
v3s16 nocheat_p = playersao->getNoCheatDigPos();
float nocheat_t = playersao->getNoCheatDigTime();
playersao->noCheatDigEnd();
// If player didn't start digging this, ignore dig
if(nocheat_p != p_under){
infostream<<"Server: NoCheat: "<<player->getName()
<<" started digging "
<<PP(nocheat_p)<<" and completed digging "
<<PP(p_under)<<"; not digging."<<std::endl;
is_valid_dig = false;
// Call callbacks
m_script->on_cheat(playersao, "finished_unknown_dig");
}
// Get player's wielded item
ItemStack playeritem;
InventoryList *mlist = playersao->getInventory()->getList("main");
if(mlist != NULL)
playeritem = mlist->getItem(playersao->getWieldIndex());
ToolCapabilities playeritem_toolcap =
playeritem.getToolCapabilities(m_itemdef);
// Get diggability and expected digging time
DigParams params = getDigParams(m_nodedef->get(n).groups,
&playeritem_toolcap);
// If can't dig, try hand
if(!params.diggable){
const ItemDefinition &hand = m_itemdef->get("");
const ToolCapabilities *tp = hand.tool_capabilities;
if(tp)
params = getDigParams(m_nodedef->get(n).groups, tp);
}
// If can't dig, ignore dig
if(!params.diggable){
infostream<<"Server: NoCheat: "<<player->getName()
<<" completed digging "<<PP(p_under)
<<", which is not diggable with tool. not digging."
<<std::endl;
is_valid_dig = false;
// Call callbacks
m_script->on_cheat(playersao, "dug_unbreakable");
}
// Check digging time
// If already invalidated, we don't have to
if(!is_valid_dig){
// Well not our problem then
}
// Clean and long dig
else if(params.time > 2.0 && nocheat_t * 1.2 > params.time){
// All is good, but grab time from pool; don't care if
// it's actually available
playersao->getDigPool().grab(params.time);
示例12: handleCommand_Interact
//.........这里部分代码省略.........
2: Digging completed
*/
else if(action == 2) {
// Only digging of nodes
if(pointed.type == POINTEDTHING_NODE) {
MapNode n = m_env->getMap().getNode(p_under);
if (!n) {
infostream << "Server: Not finishing digging: Node not found."
<< " Adding block to emerge queue."
<< std::endl;
m_emerge->enqueueBlockEmerge(peer_id, getNodeBlockPos(p_above), false);
}
/* Cheat prevention */
bool is_valid_dig = true;
if (enable_anticheat && !isSingleplayer()) {
v3s16 nocheat_p = playersao->getNoCheatDigPos();
float nocheat_t = playersao->getNoCheatDigTime();
playersao->noCheatDigEnd();
// If player didn't start digging this, ignore dig
if(nocheat_p != p_under) {
infostream << "Server: NoCheat: " << player->getName()
<< " started digging "
<< PP(nocheat_p) << " and completed digging "
<< PP(p_under) << "; not digging." << std::endl;
is_valid_dig = false;
// Call callbacks
m_script->on_cheat(playersao, "finished_unknown_dig");
}
// Get player's wielded item
ItemStack playeritem;
InventoryList *mlist = playersao->getInventory()->getList("main");
if(mlist != NULL)
playeritem = mlist->getItem(playersao->getWieldIndex());
ToolCapabilities playeritem_toolcap =
playeritem.getToolCapabilities(m_itemdef);
// Get diggability and expected digging time
DigParams params = getDigParams(m_nodedef->get(n).groups,
&playeritem_toolcap);
// If can't dig, try hand
if(!params.diggable) {
const ItemDefinition &hand = m_itemdef->get("");
const ToolCapabilities *tp = hand.tool_capabilities;
if(tp)
params = getDigParams(m_nodedef->get(n).groups, tp);
}
// If can't dig, ignore dig
if(!params.diggable) {
infostream << "Server: NoCheat: " << player->getName()
<< " completed digging " << PP(p_under)
<< ", which is not diggable with tool. not digging."
<< std::endl;
is_valid_dig = false;
// Call callbacks
m_script->on_cheat(playersao, "dug_unbreakable");
}
// Check digging time
// If already invalidated, we don't have to
if(!is_valid_dig) {
// Well not our problem then
}
// Clean and long dig
else if(params.time > 2.0 && nocheat_t * 1.2 > params.time) {
// All is good, but grab time from pool; don't care if
// it's actually available
playersao->getDigPool().grab(params.time);
示例13: 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)
//.........这里部分代码省略.........
示例14: 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;
}
//.........这里部分代码省略.........
示例15: 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)));
}
}
}
}