Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve shift+click experience
- Loading branch information
Showing
6 changed files
with
180 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -782,11 +782,48 @@ ItemStack InventoryList::peekItem(u32 i, u32 peekcount) const | |
return m_items[i].peekItem(peekcount); | ||
} | ||
|
||
void InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, u32 count) | ||
void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count) | ||
{ | ||
if(this == dest && i == dest_i) | ||
// Take item from source list | ||
ItemStack item1; | ||
if (count == 0) | ||
item1 = changeItem(i, ItemStack()); | ||
else | ||
item1 = takeItem(i, count); | ||
|
||
if (item1.empty()) | ||
return; | ||
|
||
// Try to add the item to destination list | ||
u32 oldcount = item1.count; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
est31
Author
Contributor
|
||
u32 dest_size = dest->getSize(); | ||
// First try all the non-empty slots | ||
for (u32 dest_i = 0; dest_i < dest_size; dest_i++) { | ||
if (!m_items[dest_i].empty()) { | ||
item1 = dest->addItem(dest_i, item1); | ||
if (item1.empty()) return; | ||
} | ||
} | ||
|
||
// Then try all the empty ones | ||
for (u32 dest_i = 0; dest_i < dest_size; dest_i++) { | ||
if (m_items[dest_i].empty()) { | ||
item1 = dest->addItem(dest_i, item1); | ||
if (item1.empty()) return; | ||
} | ||
} | ||
|
||
// If we reach this, the item was not fully added | ||
// Add the remaining part back to the source item | ||
addItem(i, item1); | ||
} | ||
|
||
u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, | ||
u32 count, bool swap_if_needed) | ||
{ | ||
if(this == dest && i == dest_i) | ||
return count; | ||
|
||
// Take item from source list | ||
ItemStack item1; | ||
if(count == 0) | ||
|
@@ -795,7 +832,7 @@ void InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, u32 count) | |
item1 = takeItem(i, count); | ||
|
||
if(item1.empty()) | ||
return; | ||
return 0; | ||
|
||
// Try to add the item to destination list | ||
u32 oldcount = item1.count; | ||
|
@@ -813,8 +850,7 @@ void InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, u32 count) | |
|
||
// If olditem is returned, nothing was added. | ||
// Swap the items | ||
if(nothing_added) | ||
{ | ||
if (nothing_added && swap_if_needed) { | ||
// Take item from source list | ||
item1 = changeItem(i, ItemStack()); | ||
// Adding was not possible, swap the items. | ||
|
@@ -823,6 +859,7 @@ void InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i, u32 count) | |
changeItem(i, item2); | ||
} | ||
} | ||
return (oldcount - item1.count); | ||
} | ||
|
||
/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
warning: unused variable ‘oldcount’ [-Wunused-variable]