GUIInventoryList: Keep item size while moving (#12896)

This commit is contained in:
Jean-Patrick Guerrero 2022-10-24 13:58:56 +02:00 committed by GitHub
parent 02c293ec63
commit 16266397ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

@ -3515,10 +3515,10 @@ GUIInventoryList::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const
s32 item_index = e->getItemIndexAtPos(p);
if (item_index != -1)
return GUIInventoryList::ItemSpec(e->getInventoryloc(), e->getListname(),
item_index);
item_index, e->getSlotSize());
}
return GUIInventoryList::ItemSpec(InventoryLocation(), "", -1);
return GUIInventoryList::ItemSpec(InventoryLocation(), "", -1, {0,0});
}
void GUIFormSpecMenu::drawSelectedItem()
@ -3540,7 +3540,8 @@ void GUIFormSpecMenu::drawSelectedItem()
ItemStack stack = list->getItem(m_selected_item->i);
stack.count = m_selected_amount;
core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
v2s32 slotsize = m_selected_item->slotsize;
core::rect<s32> imgrect(0, 0, slotsize.X, slotsize.Y);
core::rect<s32> rect = imgrect + (m_pointer - imgrect.getCenter());
rect.constrainTo(driver->getViewPort());
drawItemStack(driver, m_font, stack, rect, NULL, m_client, IT_ROT_DRAGGED);
@ -3791,6 +3792,7 @@ void GUIFormSpecMenu::updateSelectedItem()
m_selected_item->inventoryloc = e->getInventoryloc();
m_selected_item->listname = "craftresult";
m_selected_item->i = 0;
m_selected_item->slotsize = e->getSlotSize();
m_selected_amount = item.count;
m_selected_dragging = false;
break;

@ -34,10 +34,12 @@ public:
ItemSpec(const InventoryLocation &a_inventoryloc,
const std::string &a_listname,
s32 a_i) :
s32 a_i,
const v2s32 slotsize) :
inventoryloc(a_inventoryloc),
listname(a_listname),
i(a_i)
i(a_i),
slotsize(slotsize)
{
}
@ -46,6 +48,7 @@ public:
InventoryLocation inventoryloc;
std::string listname;
s32 i = -1;
v2s32 slotsize;
};
// options for inventorylists that are setable with the lua api
@ -99,6 +102,11 @@ public:
m_options.slotbordercolor = slotbordercolor;
}
const v2s32 getSlotSize() const noexcept
{
return m_slot_size;
}
// returns -1 if not item is at pos p
s32 getItemIndexAtPos(v2s32 p) const;