diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-11 21:54:57 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-11 21:54:57 +0200 |
commit | 18b04ab93f31e4701351dc35f847f2763d75c5e0 (patch) | |
tree | 577ee0332b3ae8778443dc6af4ee0f24c7ca1011 /source/cSurvivalInventory.cpp | |
parent | Updated Bindings to match the new armor categories and torch metas (diff) | |
download | cuberite-18b04ab93f31e4701351dc35f847f2763d75c5e0.tar cuberite-18b04ab93f31e4701351dc35f847f2763d75c5e0.tar.gz cuberite-18b04ab93f31e4701351dc35f847f2763d75c5e0.tar.bz2 cuberite-18b04ab93f31e4701351dc35f847f2763d75c5e0.tar.lz cuberite-18b04ab93f31e4701351dc35f847f2763d75c5e0.tar.xz cuberite-18b04ab93f31e4701351dc35f847f2763d75c5e0.tar.zst cuberite-18b04ab93f31e4701351dc35f847f2763d75c5e0.zip |
Diffstat (limited to 'source/cSurvivalInventory.cpp')
-rw-r--r-- | source/cSurvivalInventory.cpp | 177 |
1 files changed, 162 insertions, 15 deletions
diff --git a/source/cSurvivalInventory.cpp b/source/cSurvivalInventory.cpp index 5ed91cf70..62808a17d 100644 --- a/source/cSurvivalInventory.cpp +++ b/source/cSurvivalInventory.cpp @@ -14,36 +14,53 @@ -cSurvivalInventory::~cSurvivalInventory() +cSurvivalInventory::cSurvivalInventory(cPlayer* a_Owner) + : cInventory(a_Owner) { - } -cSurvivalInventory::cSurvivalInventory(cPlayer* a_Owner) - : cInventory(a_Owner) + + + + +cSurvivalInventory::~cSurvivalInventory() { - } + + + + void cSurvivalInventory::Clicked( cPacket* a_ClickPacket ) { - cPacket_WindowClick *Packet = reinterpret_cast<cPacket_WindowClick *>(a_ClickPacket); + cPacket_WindowClick * Packet = reinterpret_cast<cPacket_WindowClick *>(a_ClickPacket); + + if ( + Packet->m_IsShiftPressed && // Shift pressed + (GetWindow() != NULL) && // Window is valid + (GetWindow()->GetDraggingItem()->IsEmpty()) // Not dragging anything + ) + { + ShiftClicked(Packet); + return; + } + bool bDontCook = false; - if( GetWindow() ) + if (GetWindow()) { // Override for craft result slot - if( Packet->m_SlotNum == (short)c_CraftOffset ) + if (Packet->m_SlotNum == (short)c_CraftOffset) { - LOG("In craft slot: %i x %i !!", m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount ); - cItem* DraggingItem = GetWindow()->GetDraggingItem(); - if( DraggingItem->IsEmpty() ) + LOGD("In craft slot: %i x %i !!", m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount ); + cItem * DraggingItem = GetWindow()->GetDraggingItem(); + if (DraggingItem->IsEmpty()) { *DraggingItem = m_Slots[c_CraftOffset]; m_Slots[c_CraftOffset].Empty(); } - else if( DraggingItem->Equals( m_Slots[c_CraftOffset] ) ) + else if (DraggingItem->Equals(m_Slots[c_CraftOffset])) { - if( DraggingItem->m_ItemCount + m_Slots[c_CraftOffset].m_ItemCount <= 64 ) + if (DraggingItem->m_ItemCount + m_Slots[c_CraftOffset].m_ItemCount <= 64) { DraggingItem->m_ItemCount += m_Slots[c_CraftOffset].m_ItemCount; m_Slots[0].Empty(); @@ -57,7 +74,7 @@ void cSurvivalInventory::Clicked( cPacket* a_ClickPacket ) { bDontCook = true; } - LOG("Dragging Dish %i", DraggingItem->m_ItemCount ); + LOGD("Dragging Dish %i", DraggingItem->m_ItemCount ); } else { @@ -66,6 +83,7 @@ void cSurvivalInventory::Clicked( cPacket* a_ClickPacket ) } else { + ASSERT(!"No inventory window! WTF?"); LOG("No Inventory window! WTF"); } @@ -91,5 +109,134 @@ void cSurvivalInventory::Clicked( cPacket* a_ClickPacket ) LOGD("%s cooked: %i x %i !!", m_Owner->GetName().c_str(), m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount ); SendWholeInventory( m_Owner->GetClientHandle() ); } - SendSlot( 0 ); + SendSlot(0); } + + + + + +void cSurvivalInventory::ShiftClicked(cPacket_WindowClick * a_ClickPacket) +{ + ASSERT((GetWindow() == NULL) || (GetWindow()->GetDraggingItem()->IsEmpty())); // Cannot handle shift-click if dragging something + + short Slot = a_ClickPacket->m_SlotNum; + if (Slot == SLOT_CRAFTING_RESULT) + { + ShiftClickedCraftingResult(Slot); + } + else if ((Slot >= SLOT_CRAFTING_MIN) && (Slot <= SLOT_CRAFTING_MAX)) + { + ShiftClickedCraftingGrid(Slot); + } + else if ((Slot >= SLOT_ARMOR_MIN) && (Slot <= SLOT_ARMOR_MAX)) + { + ShiftClickedArmor(Slot); + } + else if ((Slot >= SLOT_HOTBAR_MIN) && (Slot <= SLOT_HOTBAR_MAX)) + { + ShiftClickedHotbar(Slot); + } + else + { + ShiftClickedInventory(Slot); + } + // Because the client tries to guess our actions, not always right, send the whole inventory: + SendWholeInventoryToAll(); +} + + + + + +void cSurvivalInventory::ShiftClickedCraftingResult(short a_Slot) +{ + // TODO +} + + + + + +void cSurvivalInventory::ShiftClickedCraftingGrid(short a_Slot) +{ + // Move the item from the crafting grid into the main inventory: + cItem * Item = GetSlot(a_Slot); + if ((Item == NULL) || Item->IsEmpty()) + { + return; + } + Item->m_ItemCount -= MoveItem(Item->m_ItemID, Item->m_ItemHealth, Item->m_ItemCount, SLOT_INVENTORY_MIN, SLOT_INVENTORY_MAX); + SendSlot(a_Slot); +} + + + + + +void cSurvivalInventory::ShiftClickedArmor(short a_Slot) +{ + // Move the item from the armor slot into the main inventory: + cItem * Item = GetSlot(a_Slot); + if ((Item == NULL) || Item->IsEmpty()) + { + return; + } + Item->m_ItemCount -= MoveItem(Item->m_ItemID, Item->m_ItemHealth, Item->m_ItemCount, SLOT_INVENTORY_MIN, SLOT_INVENTORY_MAX); + SendSlot(a_Slot); +} + + + + + +void cSurvivalInventory::ShiftClickedHotbar(short a_Slot) +{ + // Move the item from the hotbar into the main inventory: + cItem * Item = GetSlot(a_Slot); + if ((Item == NULL) || Item->IsEmpty()) + { + return; + } + Item->m_ItemCount -= MoveItem(Item->m_ItemID, Item->m_ItemHealth, Item->m_ItemCount, SLOT_INVENTORY_MIN, SLOT_INVENTORY_MAX); + SendSlot(a_Slot); +} + + + + + +void cSurvivalInventory::ShiftClickedInventory(short a_Slot) +{ + // Move the item from the main inventory into armor slot if it is armor, or the hotbar otherwise: + cItem * Item = GetSlot(a_Slot); + if ((Item == NULL) || Item->IsEmpty()) + { + return; + } + if (ItemCategory::IsHelmet(Item->m_ItemID)) + { + Item->m_ItemCount -= MoveItem(Item->m_ItemID, Item->m_ItemHealth, Item->m_ItemCount, SLOT_ARMOR_HELMET, SLOT_ARMOR_HELMET); + } + else if (ItemCategory::IsChestPlate(Item->m_ItemID)) + { + Item->m_ItemCount -= MoveItem(Item->m_ItemID, Item->m_ItemHealth, Item->m_ItemCount, SLOT_ARMOR_CHESTPLATE, SLOT_ARMOR_CHESTPLATE); + } + else if (ItemCategory::IsLeggings(Item->m_ItemID)) + { + Item->m_ItemCount -= MoveItem(Item->m_ItemID, Item->m_ItemHealth, Item->m_ItemCount, SLOT_ARMOR_LEGGINGS, SLOT_ARMOR_LEGGINGS); + } + else if (ItemCategory::IsBoots(Item->m_ItemID)) + { + Item->m_ItemCount -= MoveItem(Item->m_ItemID, Item->m_ItemHealth, Item->m_ItemCount, SLOT_ARMOR_BOOTS, SLOT_ARMOR_BOOTS); + } + else + { + Item->m_ItemCount -= MoveItem(Item->m_ItemID, Item->m_ItemHealth, Item->m_ItemCount, SLOT_HOTBAR_MIN, SLOT_HOTBAR_MAX); + } + SendSlot(a_Slot); +} + + + + |