Skip to content

Commit

Permalink
Move judgement to other caller
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahoyomu committed Aug 13, 2024
1 parent da77c04 commit f3a32c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 11 additions & 1 deletion src/gui/guiFormSpecMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3555,7 +3555,17 @@ void GUIFormSpecMenu::getAndroidUIInput()
GUIInventoryList::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const
{
for (const GUIInventoryList *e : m_inventorylists) {
s32 item_index = e->getItemIndexAtPos(p);
Inventory *inv = m_invmgr->getInventory(e->getInventoryloc());
InventoryList *ilist = nullptr;
s32 item_index = -1;
if (inv)
ilist = inv->getList(e->getListname());
if (ilist)
{
s32 i = e->getItemIndexAtPos(p);
if (i < (s32)ilist->getSize())
item_index = i;
}
if (item_index != -1)
return GUIInventoryList::ItemSpec(e->getInventoryloc(), e->getListname(),
item_index, e->getSlotSize());
Expand Down
11 changes: 1 addition & 10 deletions src/gui/guiInventoryList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,6 @@ s32 GUIInventoryList::getItemIndexAtPos(v2s32 p) const
!AbsoluteClippingRect.isPointInside(p))
return -1;

// there cannot be an item if the inventory or the inventorylist does not exist
Inventory *inv = m_invmgr->getInventory(m_inventoryloc);
if (!inv)
return -1;
// todo : delete this and related code, move judgement to other callers
InventoryList *ilist = inv->getList(m_listname);
if (!ilist)
return -1;

core::rect<s32> imgrect(0, 0, m_slot_size.X, m_slot_size.Y);
v2s32 base_pos = AbsoluteRect.UpperLeftCorner;
Expand All @@ -238,8 +230,7 @@ s32 GUIInventoryList::getItemIndexAtPos(v2s32 p) const

rect.clipAgainst(AbsoluteClippingRect);

if (rect.getArea() > 0 && rect.isPointInside(p) &&
i + m_start_item_i < (s32)ilist->getSize())
if (rect.getArea() > 0 && rect.isPointInside(p))
return i + m_start_item_i;

return -1;
Expand Down

0 comments on commit f3a32c2

Please sign in to comment.