Crafting window crafting grid shift-click handling
git-svn-id: http://mc-server.googlecode.com/svn/trunk@735 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
da23911dbc
commit
8f79074c42
@ -32,8 +32,19 @@ cCraftingWindow::cCraftingWindow( cWindowOwner* a_Owner, bool a_bInventoryVisibl
|
||||
void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_Player )
|
||||
{
|
||||
bool bDontCook = false;
|
||||
|
||||
cItem * DraggingItem = GetDraggingItem(&a_Player);
|
||||
if (
|
||||
a_ClickPacket->m_IsShiftPressed &&
|
||||
((DraggingItem == NULL) || DraggingItem->IsEmpty())
|
||||
)
|
||||
{
|
||||
ShiftClicked(a_ClickPacket, a_Player);
|
||||
return;
|
||||
}
|
||||
|
||||
// Override for craft result slot
|
||||
if( a_ClickPacket->m_SlotNum == 0 )
|
||||
if (a_ClickPacket->m_SlotNum == 0)
|
||||
{
|
||||
LOG("In craft slot: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount );
|
||||
cItem* DraggingItem = GetDraggingItem( &a_Player );
|
||||
@ -126,3 +137,69 @@ void cCraftingWindow::Close(cPlayer & a_Player)
|
||||
|
||||
|
||||
|
||||
|
||||
void cCraftingWindow::ShiftClicked(cPacket_WindowClick * a_ClickPacket, cPlayer & a_Player)
|
||||
{
|
||||
short Slot = a_ClickPacket->m_SlotNum;
|
||||
if (Slot == SLOT_CRAFTING_RESULT)
|
||||
{
|
||||
ShiftClickedCraftingResult(Slot, a_Player);
|
||||
}
|
||||
else if ((Slot >= SLOT_CRAFTING_MIN) && (Slot <= SLOT_CRAFTING_MAX))
|
||||
{
|
||||
ShiftClickedCraftingGrid(Slot, a_Player);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No need to handle inventory shift-click, it is handled by the underlying cSurvivalInventory, surprise surprise ;)
|
||||
}
|
||||
SendWholeWindow(a_Player.GetClientHandle());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cCraftingWindow::ShiftClickedCraftingResult(short a_Slot, cPlayer & a_Player)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cCraftingWindow::ShiftClickedCraftingGrid(short a_Slot, cPlayer & a_Player)
|
||||
{
|
||||
enum
|
||||
{
|
||||
SLOT_INVENTORY_MIN = 9,
|
||||
SLOT_INVENTORY_MAX = 35,
|
||||
SLOT_HOTBAR_MIN = 36,
|
||||
SLOT_HOTBAR_MAX = 44
|
||||
} ;
|
||||
|
||||
cInventory & Inventory = a_Player.GetInventory();
|
||||
cItem * Item = GetSlot(a_Slot);
|
||||
if ((Item == NULL) || Item->IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// First try the main inventory:
|
||||
Item->m_ItemCount -= Inventory.MoveItem(Item->m_ItemID, Item->m_ItemHealth, Item->m_ItemCount, SLOT_INVENTORY_MIN, SLOT_INVENTORY_MAX);
|
||||
|
||||
// If anything left, try the hotbar:
|
||||
if (Item->m_ItemCount > 0)
|
||||
{
|
||||
Item->m_ItemCount -= Inventory.MoveItem(Item->m_ItemID, Item->m_ItemHealth, Item->m_ItemCount, SLOT_HOTBAR_MIN, SLOT_HOTBAR_MAX);
|
||||
}
|
||||
if (Item->m_ItemCount == 0)
|
||||
{
|
||||
Item->Empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,13 +1,38 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cWindow.h"
|
||||
|
||||
|
||||
|
||||
|
||||
// fwd:
|
||||
class cWindowOwner;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cCraftingWindow : public cWindow
|
||||
{
|
||||
public:
|
||||
cCraftingWindow( cWindowOwner* a_Owner, bool a_bInventoryVisible );
|
||||
enum
|
||||
{
|
||||
SLOT_CRAFTING_RESULT = 0,
|
||||
SLOT_CRAFTING_MIN = 1,
|
||||
SLOT_CRAFTING_MAX = 9,
|
||||
} ;
|
||||
|
||||
cCraftingWindow(cWindowOwner * a_Owner, bool a_bInventoryVisible);
|
||||
|
||||
virtual void Clicked(cPacket_WindowClick * a_ClickPacket, cPlayer & a_Player);
|
||||
virtual void Close(cPlayer & a_Player);
|
||||
|
||||
void ShiftClicked(cPacket_WindowClick * a_ClickPacket, cPlayer & a_Player);
|
||||
void ShiftClickedCraftingResult(short a_Slot, cPlayer & a_Player);
|
||||
void ShiftClickedCraftingGrid (short a_Slot, cPlayer & a_Player);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
virtual void Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_Player );
|
||||
virtual void Close( cPlayer & a_Player );
|
||||
};
|
Loading…
Reference in New Issue
Block a user