Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUIInventoryList: Keep item size while moving #12896

Merged
merged 1 commit into from Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/gui/guiFormSpecMenu.cpp
Expand Up @@ -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()
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions src/gui/guiInventoryList.h
Expand Up @@ -34,10 +34,12 @@ class GUIInventoryList : public gui::IGUIElement

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)
{
}

Expand All @@ -46,6 +48,7 @@ class GUIInventoryList : public gui::IGUIElement
InventoryLocation inventoryloc;
std::string listname;
s32 i = -1;
v2s32 slotsize;
};

// options for inventorylists that are setable with the lua api
Expand Down Expand Up @@ -99,6 +102,11 @@ class GUIInventoryList : public gui::IGUIElement
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;

Expand Down