diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-01-08 06:01:06 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-01-08 06:01:06 +0100 |
commit | 71d71410fdeb4b47e543758186cdbee19a2baf6b (patch) | |
tree | 24c00994262179d2d658d637ef45beceafdd5d6b /source | |
parent | Fixed disappearing pickups - wrong physics simulation. (diff) | |
download | cuberite-71d71410fdeb4b47e543758186cdbee19a2baf6b.tar cuberite-71d71410fdeb4b47e543758186cdbee19a2baf6b.tar.gz cuberite-71d71410fdeb4b47e543758186cdbee19a2baf6b.tar.bz2 cuberite-71d71410fdeb4b47e543758186cdbee19a2baf6b.tar.lz cuberite-71d71410fdeb4b47e543758186cdbee19a2baf6b.tar.xz cuberite-71d71410fdeb4b47e543758186cdbee19a2baf6b.tar.zst cuberite-71d71410fdeb4b47e543758186cdbee19a2baf6b.zip |
Diffstat (limited to 'source')
-rw-r--r-- | source/UI/SlotArea.cpp | 49 | ||||
-rw-r--r-- | source/UI/SlotArea.h | 18 | ||||
-rw-r--r-- | source/UI/Window.cpp | 25 | ||||
-rw-r--r-- | source/UI/Window.h | 4 |
4 files changed, 84 insertions, 12 deletions
diff --git a/source/UI/SlotArea.cpp b/source/UI/SlotArea.cpp index 01f77d74a..dfcb753f3 100644 --- a/source/UI/SlotArea.cpp +++ b/source/UI/SlotArea.cpp @@ -211,7 +211,7 @@ void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cSlotAreaChest:
-cSlotAreaChest::cSlotAreaChest(cChestEntity *a_Chest, cWindow &a_ParentWindow) :
+cSlotAreaChest::cSlotAreaChest(cChestEntity * a_Chest, cWindow & a_ParentWindow) :
cSlotArea(27, a_ParentWindow),
m_Chest(a_Chest)
{
@@ -241,6 +241,53 @@ void cSlotAreaChest::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cSlotAreaDoubleChest:
+
+cSlotAreaDoubleChest::cSlotAreaDoubleChest(cChestEntity * a_TopChest, cChestEntity * a_BottomChest, cWindow & a_ParentWindow) :
+ cSlotArea(54, a_ParentWindow),
+ m_TopChest(a_TopChest),
+ m_BottomChest(a_BottomChest)
+{
+}
+
+
+
+
+
+const cItem * cSlotAreaDoubleChest::GetSlot(int a_SlotNum, cPlayer & a_Player)
+{
+ // a_SlotNum ranges from 0 to 53, use that to index the correct chest's inventory:
+ if (a_SlotNum < 27)
+ {
+ return m_TopChest->GetSlot(a_SlotNum);
+ }
+ else
+ {
+ return m_BottomChest->GetSlot(a_SlotNum - 27);
+ }
+}
+
+
+
+
+
+void cSlotAreaDoubleChest::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item)
+{
+ if (a_SlotNum < 27)
+ {
+ m_TopChest->SetSlot(a_SlotNum, a_Item);
+ }
+ else
+ {
+ m_BottomChest->SetSlot(a_SlotNum - 27, a_Item);
+ }
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cSlotAreaCrafting:
cSlotAreaCrafting::cSlotAreaCrafting(int a_GridSize, cWindow & a_ParentWindow) :
diff --git a/source/UI/SlotArea.h b/source/UI/SlotArea.h index 50c7e0c28..fff9f46cc 100644 --- a/source/UI/SlotArea.h +++ b/source/UI/SlotArea.h @@ -232,6 +232,24 @@ protected: +class cSlotAreaDoubleChest :
+ public cSlotArea
+{
+public:
+ cSlotAreaDoubleChest(cChestEntity * a_TopChest, cChestEntity * a_BottomChest, cWindow & a_ParentWindow);
+
+ virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) override;
+ virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
+
+protected:
+ cChestEntity * m_TopChest;
+ cChestEntity * m_BottomChest;
+} ;
+
+
+
+
+
class cSlotAreaDispenser :
public cSlotArea
{
diff --git a/source/UI/Window.cpp b/source/UI/Window.cpp index 7ad7b1a58..d22255105 100644 --- a/source/UI/Window.cpp +++ b/source/UI/Window.cpp @@ -28,6 +28,7 @@ cWindow::cWindow(cWindow::WindowType a_WindowType, const AString & a_WindowTitle , m_WindowTitle(a_WindowTitle) , m_Owner(NULL) , m_IsDestroyed(false) + , m_ShouldDistributeToHotbarFirst(true) { if (a_WindowType == Inventory) { @@ -259,18 +260,23 @@ void cWindow::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, cSlotArea // Then ask any remaining slots for (int Pass = 0; Pass < 2; ++Pass) { - // First distribute into the hotbar: - if (a_ExcludeArea != m_SlotAreas.back()) + if (m_ShouldDistributeToHotbarFirst) { - m_SlotAreas.back()->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (Pass == 0)); - if (a_ItemStack.IsEmpty()) + // First distribute into the hotbar: + if (a_ExcludeArea != m_SlotAreas.back()) { - // Distributed it all - return; + m_SlotAreas.back()->DistributeStack(a_ItemStack, a_Player, a_ShouldApply, (Pass == 0)); + if (a_ItemStack.IsEmpty()) + { + // Distributed it all + return; + } } } + // The distribute to all other areas: - for (cSlotAreas::iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end() - 1; itr != end; ++itr) + cSlotAreas::iterator end = m_ShouldDistributeToHotbarFirst ? (m_SlotAreas.end() - 1) : m_SlotAreas.end(); + for (cSlotAreas::iterator itr = m_SlotAreas.begin(); itr != end; ++itr) { if (*itr == a_ExcludeArea) { @@ -432,11 +438,12 @@ cChestWindow::cChestWindow(cChestEntity * a_PrimaryChest, cChestEntity * a_Secon m_BlockY(a_PrimaryChest->GetPosY()), m_BlockZ(a_PrimaryChest->GetPosZ()) { - m_SlotAreas.push_back(new cSlotAreaChest(a_PrimaryChest, *this)); - m_SlotAreas.push_back(new cSlotAreaChest(a_SecondaryChest, *this)); + m_SlotAreas.push_back(new cSlotAreaDoubleChest(a_PrimaryChest, a_SecondaryChest, *this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); + m_ShouldDistributeToHotbarFirst = false; + // Play the opening sound: m_World->BroadcastSoundEffect("random.chestopen", m_BlockX * 8, m_BlockY * 8, m_BlockZ * 8, 1, 1); diff --git a/source/UI/Window.h b/source/UI/Window.h index f939727c9..1c5fe4084 100644 --- a/source/UI/Window.h +++ b/source/UI/Window.h @@ -106,7 +106,6 @@ public: protected: cSlotAreas m_SlotAreas; -private: char m_WindowID; int m_WindowType; AString m_WindowTitle; @@ -114,7 +113,8 @@ private: cCriticalSection m_CS; cPlayerList m_OpenedBy; - bool m_IsDestroyed; + bool m_IsDestroyed; + bool m_ShouldDistributeToHotbarFirst; ///< If set (default), shift+click tries to distribute to hotbar first, then other areas. False for doublechests cWindowOwner * m_Owner; |