summaryrefslogtreecommitdiffstats
path: root/src/UI
diff options
context:
space:
mode:
authorarchshift <admin@archshift.com>2014-04-25 19:50:10 +0200
committerarchshift <admin@archshift.com>2014-04-25 19:50:10 +0200
commitd64e46186f21a024da3cedff1a8bab24e8d51b3f (patch)
tree441377b44418bce1a7d97b5cc2b09135e668aa40 /src/UI
parentSmall changes; warning fixing. (diff)
parentMerge pull request #937 from archshift/xcode-headers (diff)
downloadcuberite-d64e46186f21a024da3cedff1a8bab24e8d51b3f.tar
cuberite-d64e46186f21a024da3cedff1a8bab24e8d51b3f.tar.gz
cuberite-d64e46186f21a024da3cedff1a8bab24e8d51b3f.tar.bz2
cuberite-d64e46186f21a024da3cedff1a8bab24e8d51b3f.tar.lz
cuberite-d64e46186f21a024da3cedff1a8bab24e8d51b3f.tar.xz
cuberite-d64e46186f21a024da3cedff1a8bab24e8d51b3f.tar.zst
cuberite-d64e46186f21a024da3cedff1a8bab24e8d51b3f.zip
Diffstat (limited to '')
-rw-r--r--src/UI/CMakeLists.txt1
-rw-r--r--src/UI/SlotArea.cpp74
-rw-r--r--src/UI/SlotArea.h7
3 files changed, 81 insertions, 1 deletions
diff --git a/src/UI/CMakeLists.txt b/src/UI/CMakeLists.txt
index cef2a9f35..5b5b8cc18 100644
--- a/src/UI/CMakeLists.txt
+++ b/src/UI/CMakeLists.txt
@@ -6,6 +6,7 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
file(GLOB SOURCE
"*.cpp"
+ "*.h"
)
add_library(UI ${SOURCE})
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index 2d58388b1..87b4032e0 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -1091,6 +1091,80 @@ void cSlotAreaArmor::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bo
+void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem)
+{
+ ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots()));
+
+ bool bAsync = false;
+ if (GetSlot(a_SlotNum, a_Player) == NULL)
+ {
+ LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum);
+ return;
+ }
+
+ if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick))
+ {
+ ShiftClicked(a_Player, a_SlotNum, a_ClickedItem);
+ return;
+ }
+
+ // Armors haven't a dbl click
+ if (a_ClickAction == caDblClick)
+ {
+ return;
+ }
+
+ cItem Slot(*GetSlot(a_SlotNum, a_Player));
+ if (!Slot.IsSameType(a_ClickedItem))
+ {
+ LOGWARNING("*** Window lost sync at item %d in SlotArea with %d items ***", a_SlotNum, m_NumSlots);
+ LOGWARNING("My item: %s", ItemToFullString(Slot).c_str());
+ LOGWARNING("Their item: %s", ItemToFullString(a_ClickedItem).c_str());
+ bAsync = true;
+ }
+ cItem & DraggingItem = a_Player.GetDraggingItem();
+ if ((a_ClickAction != caRightClick) && (a_ClickAction != caLeftClick))
+ {
+ LOGWARNING("SlotArea: Unhandled click action: %d (%s)", a_ClickAction, ClickActionToString(a_ClickAction));
+ m_ParentWindow.BroadcastWholeWindow();
+ return;
+ }
+
+ if (DraggingItem.IsEmpty() || CanPlaceInSlot(a_SlotNum, DraggingItem))
+ {
+ // Swap contents
+ cItem tmp(DraggingItem);
+ DraggingItem = Slot;
+ Slot = tmp;
+ }
+
+ SetSlot(a_SlotNum, a_Player, Slot);
+ if (bAsync)
+ {
+ m_ParentWindow.BroadcastWholeWindow();
+ }
+}
+
+
+
+
+
+bool cSlotAreaArmor::CanPlaceInSlot(int a_SlotNum, const cItem & a_Item)
+{
+ switch (a_SlotNum)
+ {
+ case 0: return ItemCategory::IsHelmet (a_Item.m_ItemType);
+ case 1: return ItemCategory::IsChestPlate(a_Item.m_ItemType);
+ case 2: return ItemCategory::IsLeggings (a_Item.m_ItemType);
+ case 3: return ItemCategory::IsBoots (a_Item.m_ItemType);
+ }
+ return false;
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cSlotAreaItemGrid:
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index bab1098bb..254722822 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -145,8 +145,13 @@ public:
{
}
- // Distributing the stack is allowed only for compatible items (helmets into helmet slot etc.)
+ /** Distributing the stack is allowed only for compatible items (helmets into helmet slot etc.) */
virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override;
+
+ /** Called when a player clicks in the window. Parameters taken from the click packet. */
+ virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override;
+
+ bool CanPlaceInSlot(int a_SlotNum, const cItem & a_Item);
} ;