summaryrefslogtreecommitdiffstats
path: root/source/cWindow.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-11 21:54:57 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-11 21:54:57 +0200
commit18b04ab93f31e4701351dc35f847f2763d75c5e0 (patch)
tree577ee0332b3ae8778443dc6af4ee0f24c7ca1011 /source/cWindow.cpp
parentUpdated Bindings to match the new armor categories and torch metas (diff)
downloadcuberite-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 '')
-rw-r--r--source/cWindow.cpp72
1 files changed, 56 insertions, 16 deletions
diff --git a/source/cWindow.cpp b/source/cWindow.cpp
index f2c66420e..a7eceac27 100644
--- a/source/cWindow.cpp
+++ b/source/cWindow.cpp
@@ -86,36 +86,42 @@ cItem* cWindow::GetDraggingItem( cPlayer * a_Player /* = 0 */ )
void cWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_Player )
{
- if( a_ClickPacket->m_WindowID != m_WindowID )
+ if (a_ClickPacket->m_WindowID != m_WindowID)
{
LOG("WRONG WINDOW ID! (exp %d, got %d)", m_WindowID, a_ClickPacket->m_WindowID);
return;
}
- if( m_bInventoryVisible )
+ if (m_bInventoryVisible)
{
- cWindow* Window = a_Player.GetInventory().GetWindow();
- if( Window )
+ cWindow * Window = a_Player.GetInventory().GetWindow();
+ if (Window != NULL)
{
m_DraggingItem = Window->GetDraggingItem();
}
}
bool bAsync = false;
- if( a_ClickPacket->m_SlotNum == -999 ) // Outside window click
+ if (a_ClickPacket->m_SlotNum == -999) // Outside window click
{
- if( a_ClickPacket->m_RightMouse )
+ if (a_ClickPacket->m_RightMouse)
+ {
a_Player.TossItem( true );
+ }
else
+ {
a_Player.TossItem( true, m_DraggingItem->m_ItemCount );
+ }
}
- else if( GetSlot( a_ClickPacket->m_SlotNum ) != 0 )
+ else if (GetSlot(a_ClickPacket->m_SlotNum) != NULL)
{
- cItem* Item = GetSlot( a_ClickPacket->m_SlotNum );
- if( a_ClickPacket->m_ItemID != Item->m_ItemID
- || a_ClickPacket->m_ItemCount != Item->m_ItemCount
- || a_ClickPacket->m_ItemUses != Item->m_ItemHealth )
+ cItem * Item = GetSlot(a_ClickPacket->m_SlotNum);
+ if (
+ (a_ClickPacket->m_ItemID != Item->m_ItemID) ||
+ (a_ClickPacket->m_ItemCount != Item->m_ItemCount) ||
+ (a_ClickPacket->m_ItemUses != Item->m_ItemHealth)
+ )
{
- if( !((a_ClickPacket->m_ItemID == -1 || a_ClickPacket->m_ItemID == 0) && (Item->m_ItemID == -1 || Item->m_ItemID == 0 )) )
+ if (!((a_ClickPacket->m_ItemID == -1 || a_ClickPacket->m_ItemID == 0) && (Item->m_ItemID == -1 || Item->m_ItemID == 0 )) )
{
LOGD("My ID: %i Their ID: %i", Item->m_ItemID, a_ClickPacket->m_ItemID );
LOGD("My Count: %i Their Count: %i", Item->m_ItemCount, a_ClickPacket->m_ItemCount );
@@ -124,13 +130,13 @@ void cWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_Player )
}
}
}
- if( m_DraggingItem && a_ClickPacket->m_SlotNum > -1 && a_ClickPacket->m_SlotNum < m_NumSlots )
+ if (m_DraggingItem && (a_ClickPacket->m_SlotNum > -1) && (a_ClickPacket->m_SlotNum < m_NumSlots))
{
- if( a_ClickPacket->m_RightMouse == 0 )
+ if (a_ClickPacket->m_RightMouse == 0)
{
- if( !m_DraggingItem->Equals( m_Slots[a_ClickPacket->m_SlotNum] ) )
+ if (!m_DraggingItem->Equals(m_Slots[a_ClickPacket->m_SlotNum]))
{
- cItem tmp( *m_DraggingItem );
+ cItem tmp(*m_DraggingItem);
*m_DraggingItem = m_Slots[a_ClickPacket->m_SlotNum];
m_Slots[a_ClickPacket->m_SlotNum] = tmp; // Switch contents
}
@@ -283,6 +289,40 @@ void cWindow::OwnerDestroyed()
+bool cWindow::ForEachPlayer(cItemCallback<cPlayer> & a_Callback)
+{
+ cCSLock Lock(m_CS);
+ for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr)
+ {
+ if (a_Callback.Item(*itr))
+ {
+ return false;
+ }
+ } // for itr - m_OpenedBy[]
+ return true;
+}
+
+
+
+
+
+bool cWindow::ForEachClient(cItemCallback<cClientHandle> & a_Callback)
+{
+ cCSLock Lock(m_CS);
+ for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr)
+ {
+ if (a_Callback.Item((*itr)->GetClientHandle()))
+ {
+ return false;
+ }
+ } // for itr - m_OpenedBy[]
+ return true;
+}
+
+
+
+
+
void cWindow::Destroy()
{
LOGD("Destroying window %p (type %d)", this, m_WindowType);