From 0c2b307eab67b7f37d82a7862a6acbcd96b45adb Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 20 Jan 2014 18:22:08 +0100 Subject: first changes for enchanting (not finished) - added enchanting table block handler and added it to the blockhandler - added enchanting window - drop item in the slot 0 when the player close the window - added enchanting packet (1.7 only) - some more... --- src/UI/SlotArea.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/UI/SlotArea.h | 28 +++++++++++++++++ src/UI/Window.cpp | 15 ++++++++++ src/UI/Window.h | 12 ++++++++ 4 files changed, 141 insertions(+) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index bfcad3d92..ae6bfccb5 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -562,6 +562,92 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSlotAreaEnchanting: + +cSlotAreaEnchanting::cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow) : +cSlotAreaTemporary(a_NumSlots, a_ParentWindow) +{ +} + + + + + +void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) +{ + LOG("Clicked"); + // Check if Slot is in the Enchantment Table + if (a_SlotNum == 0) + { + if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) + { + ShiftClickedResult(a_Player); + } + else + { + ClickedResult(a_Player); + } + return; + } + super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); +} + + + + + +void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +{ + // Toss the item in the enchanting slot + TossItems(a_Player, 0, 0); + // Player not found - that is acceptable +} + + + + + +void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) +{ + LOG("Click!"); + + if (a_Player.GetDraggingItem().IsEmpty()) + { + LOG("EMPTY"); + this->m_ParentWindow.SetProperty(0, NULL); + this->m_ParentWindow.SetProperty(1, NULL); + this->m_ParentWindow.SetProperty(2, NULL); + } + else if (a_Player.GetDraggingItem().IsEnchantable) + { + LOG("Enchantable"); + this->m_ParentWindow.SetProperty(0, 30); + this->m_ParentWindow.SetProperty(1, 20); + this->m_ParentWindow.SetProperty(2, 10); + } + else + { + LOG("Not Enchantable"); + this->m_ParentWindow.SetProperty(0, NULL); + this->m_ParentWindow.SetProperty(1, NULL); + this->m_ParentWindow.SetProperty(2, NULL); + } +} + + + + + +void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player) +{ + LOG("Shift Click!"); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnderChest: diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index d31c87e0c..bd5c66c77 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -252,6 +252,34 @@ protected: +class cSlotAreaEnchanting : + public cSlotAreaTemporary +{ + typedef cSlotAreaTemporary super; + +public: + /// a_GridSize is allowed to be only 2 or 3 + cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow); + + // cSlotAreaTemporary overrides: + virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; + virtual void OnPlayerRemoved(cPlayer & a_Player) override; + + // Distributing items into this area is completely disabled + virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override {} + +protected: + /// Handles a click in the result slot. Crafts using the current recipe, if possible + void ClickedResult(cPlayer & a_Player); + + /// Handles a shift-click in the result slot. Crafts using the current recipe until it changes or no more space for result. + void ShiftClickedResult(cPlayer & a_Player); +}; + + + + + class cSlotAreaChest : public cSlotArea { diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 3ffeff7a0..fcfe6faf3 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -781,6 +781,21 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cEnchantingWindow: + +cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : +cWindow(wtEnchantment, "Enchantment Table") +{ + m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this)); + m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cChestWindow: diff --git a/src/UI/Window.h b/src/UI/Window.h index 030182888..cdaec5aaa 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -231,6 +231,18 @@ public: +class cEnchantingWindow : + public cWindow +{ + typedef cWindow super; +public: + cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ); +}; + + + + + class cFurnaceWindow : public cWindow { -- cgit v1.2.3 From bfac00f2807a6740e876adebd689cc3ae6e075ed Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Fri, 24 Jan 2014 20:01:21 +0100 Subject: Some updates for enchanting --- src/UI/SlotArea.cpp | 24 ++++++++++++------------ src/UI/Window.cpp | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index ae6bfccb5..a226d027b 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -576,7 +576,7 @@ cSlotAreaTemporary(a_NumSlots, a_ParentWindow) void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - LOG("Clicked"); + LOGWARN("Clicked"); // Check if Slot is in the Enchantment Table if (a_SlotNum == 0) { @@ -610,28 +610,28 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) { - LOG("Click!"); + LOGWARN("Click!"); if (a_Player.GetDraggingItem().IsEmpty()) { - LOG("EMPTY"); - this->m_ParentWindow.SetProperty(0, NULL); - this->m_ParentWindow.SetProperty(1, NULL); - this->m_ParentWindow.SetProperty(2, NULL); + LOGWARN("EMPTY"); + this->m_ParentWindow.SetProperty(0, 0); + this->m_ParentWindow.SetProperty(1, 0); + this->m_ParentWindow.SetProperty(2, 0); } else if (a_Player.GetDraggingItem().IsEnchantable) { - LOG("Enchantable"); + LOGWARN("Enchantable"); this->m_ParentWindow.SetProperty(0, 30); this->m_ParentWindow.SetProperty(1, 20); this->m_ParentWindow.SetProperty(2, 10); } else { - LOG("Not Enchantable"); - this->m_ParentWindow.SetProperty(0, NULL); - this->m_ParentWindow.SetProperty(1, NULL); - this->m_ParentWindow.SetProperty(2, NULL); + LOGWARN("Not Enchantable"); + this->m_ParentWindow.SetProperty(0, 0); + this->m_ParentWindow.SetProperty(1, 0); + this->m_ParentWindow.SetProperty(2, 0); } } @@ -641,7 +641,7 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player) { - LOG("Shift Click!"); + LOGWARN("Shift Click!"); } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index fcfe6faf3..9188b47a7 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -785,7 +785,7 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : // cEnchantingWindow: cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : -cWindow(wtEnchantment, "Enchantment Table") +cWindow(wtEnchantment, "Enchant") { m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); -- cgit v1.2.3 From af566d5a79134842854bea78de577676d507949f Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 7 Apr 2014 19:52:35 +0200 Subject: Added Enchantment-Slot-Level generating --- src/UI/SlotArea.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index a226d027b..03bfd275a 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -13,6 +13,8 @@ #include "Window.h" #include "../CraftingRecipes.h" #include "../Root.h" +#include "../FastRandom.h" +#include "../BlockArea.h" @@ -615,23 +617,31 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) if (a_Player.GetDraggingItem().IsEmpty()) { LOGWARN("EMPTY"); - this->m_ParentWindow.SetProperty(0, 0); - this->m_ParentWindow.SetProperty(1, 0); - this->m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0); + m_ParentWindow.SetProperty(1, 0); + m_ParentWindow.SetProperty(2, 0); } else if (a_Player.GetDraggingItem().IsEnchantable) { + int bookshelves = 15; // TODO: Check Bookshelves + + cFastRandom Random; + int base = (Random.GenerateRandomInteger(1, 8) + floor(bookshelves / 2) + Random.GenerateRandomInteger(0, bookshelves)); + int topSlot = std::max(base / 3, 1); + int middleSlot = (base * 2) / 3 + 1; + int bottomSlot = std::max(base, bookshelves * 2); + LOGWARN("Enchantable"); - this->m_ParentWindow.SetProperty(0, 30); - this->m_ParentWindow.SetProperty(1, 20); - this->m_ParentWindow.SetProperty(2, 10); + m_ParentWindow.SetProperty(0, topSlot); + m_ParentWindow.SetProperty(1, middleSlot); + m_ParentWindow.SetProperty(2, bottomSlot); } else { LOGWARN("Not Enchantable"); - this->m_ParentWindow.SetProperty(0, 0); - this->m_ParentWindow.SetProperty(1, 0); - this->m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0); + m_ParentWindow.SetProperty(1, 0); + m_ParentWindow.SetProperty(2, 0); } } -- cgit v1.2.3 From e6e702e7fdbc8b7475d3dbecc0f81a08304997ae Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 12 Apr 2014 14:58:46 +0200 Subject: Added complete Enchanting System http://minecraft.gamepedia.com/Enchantment_mechanics --- src/UI/SlotArea.cpp | 49 ++++++++++++++++++++---------- src/UI/Window.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++- src/UI/Window.h | 20 ++++++++++--- 3 files changed, 135 insertions(+), 20 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 9463bc593..f76b11380 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -608,7 +608,6 @@ cSlotAreaTemporary(a_NumSlots, a_ParentWindow) void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - LOGWARN("Clicked"); // Check if Slot is in the Enchantment Table if (a_SlotNum == 0) { @@ -642,17 +641,39 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) { - LOGWARN("Click!"); - if (a_Player.GetDraggingItem().IsEmpty()) { - LOGWARN("EMPTY"); - m_ParentWindow.SetProperty(0, 0); - m_ParentWindow.SetProperty(1, 0); - m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); } else if (a_Player.GetDraggingItem().IsEnchantable) { + int PosX = 0; + int PosY = 0; + int PosZ = 0; + cEnchantingWindow * Window = (cEnchantingWindow*)&m_ParentWindow; + Window->GetBlockPos(PosX, PosY, PosZ); + + cBlockArea Area; + Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); + + for (int x = 0; x < 7; x++) + { + for (int y = 0; y < 2; y++) + { + for (int z = 0; z < 7; z++) + { + LOG(Printf("%i", Area.GetBlockType(x, y, z)).c_str()); + + if (Area.GetBlockType(x, y, z) == E_BLOCK_BOOKCASE) + { + LOG("BookShelf"); + } + } + } + } + int bookshelves = 15; // TODO: Check Bookshelves cFastRandom Random; @@ -661,17 +682,15 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) int middleSlot = (base * 2) / 3 + 1; int bottomSlot = std::max(base, bookshelves * 2); - LOGWARN("Enchantable"); - m_ParentWindow.SetProperty(0, topSlot); - m_ParentWindow.SetProperty(1, middleSlot); - m_ParentWindow.SetProperty(2, bottomSlot); + m_ParentWindow.SetProperty(0, topSlot, a_Player); + m_ParentWindow.SetProperty(1, middleSlot, a_Player); + m_ParentWindow.SetProperty(2, bottomSlot, a_Player); } else { - LOGWARN("Not Enchantable"); - m_ParentWindow.SetProperty(0, 0); - m_ParentWindow.SetProperty(1, 0); - m_ParentWindow.SetProperty(2, 0); + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); } } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 5d89534dd..c514e76e7 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -808,7 +808,10 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : // cEnchantingWindow: cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : -cWindow(wtEnchantment, "Enchant") + cWindow(wtEnchantment, "Enchant"), + m_BlockX(a_BlockX), + m_BlockY(a_BlockY), + m_BlockZ(a_BlockZ) { m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); @@ -819,6 +822,87 @@ cWindow(wtEnchantment, "Enchant") +void cEnchantingWindow::SetProperty(int a_Property, int a_Value) +{ + if (a_Property == 0) + { + m_PropertyValue0 = a_Value; + } + else if (a_Property == 1) + { + m_PropertyValue1 = a_Value; + } + else if (a_Property == 2) + { + m_PropertyValue2 = a_Value; + } + + cCSLock Lock(m_CS); + for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr) + { + (*itr)->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); + } // for itr - m_OpenedBy[] +} + + + + + +void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player) +{ + if (a_Property == 0) + { + m_PropertyValue0 = a_Value; + } + else if (a_Property == 1) + { + m_PropertyValue1 = a_Value; + } + else if (a_Property == 2) + { + m_PropertyValue2 = a_Value; + } + + a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); +} + + + + + +int cEnchantingWindow::GetPropertyValue(int a_Property) +{ + if (a_Property == 0) + { + return m_PropertyValue0; + } + else if (a_Property == 1) + { + return m_PropertyValue1; + } + else if (a_Property == 2) + { + return m_PropertyValue2; + } + + return -1; +} + + + + + +void cEnchantingWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ) +{ + a_PosX = m_BlockX; + a_PosY = m_BlockY; + a_PosZ = m_BlockZ; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cChestWindow: diff --git a/src/UI/Window.h b/src/UI/Window.h index cdaec5aaa..52ab6c3ae 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -136,11 +136,11 @@ public: void SetWindowTitle(const AString & a_WindowTitle ) { m_WindowTitle = a_WindowTitle; } /// Sends the UpdateWindowProperty (0x69) packet to all clients of the window - void SetProperty(int a_Property, int a_Value); + virtual void SetProperty(int a_Property, int a_Value); /// Sends the UpdateWindowPropert(0x69) packet to the specified player - void SetProperty(int a_Property, int a_Value, cPlayer & a_Player); - + virtual void SetProperty(int a_Property, int a_Value, cPlayer & a_Player); + // tolua_end void OwnerDestroyed(void); @@ -165,7 +165,7 @@ public: /// Used by cSlotAreas to send individual slots to clients, a_RelativeSlotNum is the slot number relative to a_SlotArea void SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_RelativeSlotNum); - + protected: cSlotAreas m_SlotAreas; @@ -237,6 +237,18 @@ class cEnchantingWindow : typedef cWindow super; public: cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ); + virtual void SetProperty(int a_Property, int a_Value, cPlayer & a_Player) override; + virtual void SetProperty(int a_Property, int a_Value) override; + + /** Return the Value of a Property */ + int GetPropertyValue(int a_Property); + + /** Set the Position Values to the Position of the Enchantment Table */ + void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); + +protected: + int m_PropertyValue0, m_PropertyValue1, m_PropertyValue2; + int m_BlockX, m_BlockY, m_BlockZ; }; -- cgit v1.2.3 From dd1f8fb1f5640d9f9d58098c8aefbc1c1ad308ab Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 12 Apr 2014 18:52:17 +0200 Subject: Fixed Bookshelves Checking (not completly) --- src/UI/SlotArea.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index f76b11380..d43b91700 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -658,17 +658,20 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) cBlockArea Area; Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - for (int x = 0; x < 7; x++) + for (int x = 0; x < 6; x++) { - for (int y = 0; y < 2; y++) + for (int y = 0; y < 3; y++) { - for (int z = 0; z < 7; z++) + for (int z = 0; z < 6; z++) { - LOG(Printf("%i", Area.GetBlockType(x, y, z)).c_str()); - - if (Area.GetBlockType(x, y, z) == E_BLOCK_BOOKCASE) + if ((((x == 0) || (x == 5)) || ((z == 0) || (z == 5))) && ((y == 0) || y == 1)) { - LOG("BookShelf"); + LOG("%i", Area.GetRelBlockType(x, y, z)); + + if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) + { + LOG("BookShelf"); + } } } } -- cgit v1.2.3 From 1429d2f1b1802e1be5f5551df890562b4a014342 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 13:33:47 +0200 Subject: Some Fixes --- src/UI/SlotArea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index d43b91700..352558d9e 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -647,7 +647,7 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (a_Player.GetDraggingItem().IsEnchantable) + else if (cItem::IsEnchantable(a_Player.GetDraggingItem().m_ItemType)) { int PosX = 0; int PosY = 0; -- cgit v1.2.3 From fce9ea65c35ab7f94c23bb361386b5ce223279eb Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sun, 13 Apr 2014 22:15:10 +0200 Subject: Fixed invisibility enchantments --- src/UI/SlotArea.cpp | 2 ++ src/UI/Window.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 352558d9e..35230cffb 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -600,6 +600,8 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) cSlotAreaEnchanting::cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow) : cSlotAreaTemporary(a_NumSlots, a_ParentWindow) { + cEnchantingWindow * Window = (cEnchantingWindow *)&m_ParentWindow; + Window->m_SlotArea = this; } diff --git a/src/UI/Window.h b/src/UI/Window.h index 52ab6c3ae..5e799248c 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -246,6 +246,8 @@ public: /** Set the Position Values to the Position of the Enchantment Table */ void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); + cSlotArea * m_SlotArea; + protected: int m_PropertyValue0, m_PropertyValue1, m_PropertyValue2; int m_BlockX, m_BlockY, m_BlockZ; -- cgit v1.2.3 From 856e900bf8e74cb478904d6322dcb6310ff7a3b2 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 11:48:12 +0200 Subject: Bug fixes --- src/UI/SlotArea.cpp | 32 +++++++++++++++++--------------- src/UI/SlotArea.h | 8 ++------ 2 files changed, 19 insertions(+), 21 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 35230cffb..673c036b6 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -608,8 +608,21 @@ cSlotAreaTemporary(a_NumSlots, a_ParentWindow) +void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +{ + // Toss the item in the enchanting slot + TossItems(a_Player, 0, 1); + // Player not found - that is acceptable +} + + + + + void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { + super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); + // Check if Slot is in the Enchantment Table if (a_SlotNum == 0) { @@ -621,20 +634,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio { ClickedResult(a_Player); } - return; } - super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); -} - - - - - -void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) -{ - // Toss the item in the enchanting slot - TossItems(a_Player, 0, 0); - // Player not found - that is acceptable } @@ -643,13 +643,15 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) { - if (a_Player.GetDraggingItem().IsEmpty()) + cItem Item = *GetSlot(0, a_Player); + + if (Item.IsEmpty()) { m_ParentWindow.SetProperty(0, 0, a_Player); m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(a_Player.GetDraggingItem().m_ItemType)) + else if (cItem::IsEnchantable(Item.m_ItemType)) { int PosX = 0; int PosY = 0; diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 82360ffbe..7feb74aa1 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -258,21 +258,17 @@ class cSlotAreaEnchanting : typedef cSlotAreaTemporary super; public: - /// a_GridSize is allowed to be only 2 or 3 cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow); // cSlotAreaTemporary overrides: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; virtual void OnPlayerRemoved(cPlayer & a_Player) override; - // Distributing items into this area is completely disabled - virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override {} - protected: - /// Handles a click in the result slot. Crafts using the current recipe, if possible + /// Handles a click in the item slot. void ClickedResult(cPlayer & a_Player); - /// Handles a shift-click in the result slot. Crafts using the current recipe until it changes or no more space for result. + /// Handles a shift-click in the item slot. void ShiftClickedResult(cPlayer & a_Player); }; -- cgit v1.2.3 From fb26d2ba870f63deb5515521ecf5ce0c35780a2b Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 11:56:50 +0200 Subject: Fixed Bookshelf Checking Code by LO1ZB --- src/UI/SlotArea.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 673c036b6..23108c256 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -659,29 +659,31 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) cEnchantingWindow * Window = (cEnchantingWindow*)&m_ParentWindow; Window->GetBlockPos(PosX, PosY, PosZ); + int bookshelves = 0; cBlockArea Area; Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - for (int x = 0; x < 6; x++) + for (int y = 0; y <= 2; y++) { - for (int y = 0; y < 3; y++) + for (int x = 0; x <= 4; x++) { - for (int z = 0; z < 6; z++) + for (int z = 0; z <= 4; z++) { - if ((((x == 0) || (x == 5)) || ((z == 0) || (z == 5))) && ((y == 0) || y == 1)) + if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) { - LOG("%i", Area.GetRelBlockType(x, y, z)); - if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) { - LOG("BookShelf"); + bookshelves++; } } } } } - int bookshelves = 15; // TODO: Check Bookshelves + if (bookshelves > 15) + { + bookshelves = 15; + } cFastRandom Random; int base = (Random.GenerateRandomInteger(1, 8) + floor(bookshelves / 2) + Random.GenerateRandomInteger(0, bookshelves)); -- cgit v1.2.3 From a51a099c81f34f875c76d560e6729889b2fdd4fa Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 13:39:44 +0200 Subject: Blocked enchanting a item twice --- src/UI/SlotArea.cpp | 14 ++++++++------ src/UI/SlotArea.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 23108c256..eb528d7ca 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -628,11 +628,11 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio { if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) { - ShiftClickedResult(a_Player); + ShiftClickedSlot(a_Player); } else { - ClickedResult(a_Player); + ClickedSlot(a_Player); } } } @@ -641,7 +641,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio -void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) +void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) { cItem Item = *GetSlot(0, a_Player); @@ -651,7 +651,7 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(Item.m_ItemType)) + else if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty()) { int PosX = 0; int PosY = 0; @@ -707,9 +707,11 @@ void cSlotAreaEnchanting::ClickedResult(cPlayer & a_Player) -void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player) +void cSlotAreaEnchanting::ShiftClickedSlot(cPlayer & a_Player) { - LOGWARN("Shift Click!"); + m_ParentWindow.SetProperty(0, 0, a_Player); + m_ParentWindow.SetProperty(1, 0, a_Player); + m_ParentWindow.SetProperty(2, 0, a_Player); } diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 7feb74aa1..a6af72273 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -266,10 +266,10 @@ public: protected: /// Handles a click in the item slot. - void ClickedResult(cPlayer & a_Player); + void ClickedSlot(cPlayer & a_Player); /// Handles a shift-click in the item slot. - void ShiftClickedResult(cPlayer & a_Player); + void ShiftClickedSlot(cPlayer & a_Player); }; -- cgit v1.2.3 From b5401ec03ad74782129e6a68eac3e9c0ccb573e2 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Mon, 14 Apr 2014 22:05:04 +0200 Subject: Added ItemPlaceCount in SlotArea Thanks to Howaner for helping --- src/UI/SlotArea.cpp | 32 ++++++++++++++++++++++++++++++++ src/UI/SlotArea.h | 3 +++ 2 files changed, 35 insertions(+) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index eb528d7ca..9ea2e0021 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -135,6 +135,12 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA cItem tmp(DraggingItem); DraggingItem = Slot; Slot = tmp; + int ItemPlaceCount = GetItemPlaceCount(Slot); + if (Slot.m_ItemCount > ItemPlaceCount) + { + DraggingItem.m_ItemCount += Slot.m_ItemCount - ItemPlaceCount; + Slot.m_ItemCount = ItemPlaceCount; + } } else { @@ -147,6 +153,13 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA FreeSlots = 0; } int Filling = (FreeSlots > DraggingItem.m_ItemCount) ? DraggingItem.m_ItemCount : FreeSlots; + + int ItemPlaceCount = GetItemPlaceCount(DraggingItem); + if (Filling > ItemPlaceCount) + { + Filling = ItemPlaceCount; + } + Slot.m_ItemCount += (char)Filling; DraggingItem.m_ItemCount -= (char)Filling; if (DraggingItem.m_ItemCount <= 0) @@ -315,6 +328,16 @@ bool cSlotArea::CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool +int cSlotArea::GetItemPlaceCount(cItem & a_Item) +{ + cItemHandler * Handler = ItemHandler(a_Item.m_ItemType); + return Handler->GetMaxStackSize(); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaChest: @@ -718,6 +741,15 @@ void cSlotAreaEnchanting::ShiftClickedSlot(cPlayer & a_Player) +int cSlotAreaEnchanting::GetItemPlaceCount(cItem & a_Item) +{ + return 1; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnderChest: diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index a6af72273..431ad753c 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -66,6 +66,8 @@ public: /// If a_CollectFullStacks is false, slots with full stacks are skipped while collecting. /// Returns true if full stack has been collected in a_Dragging, false if there's space remaining to fill. virtual bool CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool a_CollectFullStacks); + + virtual int GetItemPlaceCount(cItem & a_Item); protected: int m_NumSlots; @@ -263,6 +265,7 @@ public: // cSlotAreaTemporary overrides: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; virtual void OnPlayerRemoved(cPlayer & a_Player) override; + virtual int GetItemPlaceCount(cItem & a_Item) override; protected: /// Handles a click in the item slot. -- cgit v1.2.3 From e81fc2779e4b9a8ce847d63864537259033c9cb9 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 15 Apr 2014 21:10:44 +0200 Subject: Add more checks to cSlotAreaEnchanting --- src/UI/SlotArea.cpp | 286 ++++++++++++++++++++++++++++++++++++---------------- src/UI/SlotArea.h | 23 +++-- src/UI/Window.cpp | 2 +- 3 files changed, 212 insertions(+), 99 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 9ea2e0021..46ed493d8 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -135,12 +135,6 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA cItem tmp(DraggingItem); DraggingItem = Slot; Slot = tmp; - int ItemPlaceCount = GetItemPlaceCount(Slot); - if (Slot.m_ItemCount > ItemPlaceCount) - { - DraggingItem.m_ItemCount += Slot.m_ItemCount - ItemPlaceCount; - Slot.m_ItemCount = ItemPlaceCount; - } } else { @@ -154,12 +148,6 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA } int Filling = (FreeSlots > DraggingItem.m_ItemCount) ? DraggingItem.m_ItemCount : FreeSlots; - int ItemPlaceCount = GetItemPlaceCount(DraggingItem); - if (Filling > ItemPlaceCount) - { - Filling = ItemPlaceCount; - } - Slot.m_ItemCount += (char)Filling; DraggingItem.m_ItemCount -= (char)Filling; if (DraggingItem.m_ItemCount <= 0) @@ -182,7 +170,6 @@ void cSlotArea::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickA { m_ParentWindow.BroadcastWholeWindow(); } - } @@ -328,16 +315,6 @@ bool cSlotArea::CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool -int cSlotArea::GetItemPlaceCount(cItem & a_Item) -{ - cItemHandler * Handler = ItemHandler(a_Item.m_ItemType); - return Handler->GetMaxStackSize(); -} - - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaChest: @@ -620,51 +597,200 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnchanting: -cSlotAreaEnchanting::cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow) : -cSlotAreaTemporary(a_NumSlots, a_ParentWindow) +cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow) : + cSlotAreaTemporary(1, a_ParentWindow) { - cEnchantingWindow * Window = (cEnchantingWindow *)&m_ParentWindow; - Window->m_SlotArea = this; + a_ParentWindow.m_SlotArea = this; } -void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - // Toss the item in the enchanting slot - TossItems(a_Player, 0, 1); - // Player not found - that is acceptable + 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; + } + + switch (a_ClickAction) + { + case caShiftLeftClick: + case caShiftRightClick: + { + ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + return; + } + + case caDblClick: + { + DblClicked(a_Player, a_SlotNum); + return; + } + default: + { + break; + } + } + + 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(); + switch (a_ClickAction) + { + case caRightClick: + { + // Right-clicked + if (DraggingItem.IsEmpty()) + { + DraggingItem = Slot.CopyOne(); + Slot.Empty(); + break; + } + + if (Slot.IsEmpty()) + { + Slot = DraggingItem.CopyOne(); + DraggingItem.m_ItemCount -= 1; + if (DraggingItem.m_ItemCount <= 0) + { + DraggingItem.Empty(); + } + } + else if ((!DraggingItem.IsEqual(Slot)) && (DraggingItem.m_ItemCount == 1)) + { + // Swap contents + cItem tmp(DraggingItem); + DraggingItem = Slot; + Slot = tmp; + } + break; + } + + case caLeftClick: + { + // Left-clicked + if (DraggingItem.IsEmpty()) + { + DraggingItem = Slot.CopyOne(); + Slot.Empty(); + break; + } + + if (DraggingItem.IsEqual(Slot)) + { + // Do nothing + break; + } + + if (!Slot.IsEmpty()) + { + if (DraggingItem.m_ItemCount == 1) + { + // Swap contents + cItem tmp(DraggingItem); + DraggingItem = Slot; + Slot = tmp; + } + } + else + { + Slot = DraggingItem.CopyOne(); + DraggingItem.m_ItemCount -= 1; + if (DraggingItem.m_ItemCount <= 0) + { + DraggingItem.Empty(); + } + } + break; + } + default: + { + LOGWARNING("SlotArea: Unhandled click action: %d (%s)", a_ClickAction, ClickActionToString(a_ClickAction)); + m_ParentWindow.BroadcastWholeWindow(); + return; + } + } // switch (a_ClickAction + + SetSlot(a_SlotNum, a_Player, Slot); + if (bAsync) + { + m_ParentWindow.BroadcastWholeWindow(); + } + UpdateResult(a_Player); } -void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) +void cSlotAreaEnchanting::DblClicked(cPlayer & a_Player, int a_SlotNum) { - super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); + cItem & Dragging = a_Player.GetDraggingItem(); + if ((!Dragging.IsEmpty()) || (a_SlotNum != 0)) + { + return; + } + + cItem Item = *GetSlot(0, a_Player); + if (!m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, false)) + { + m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, true); + } +} - // Check if Slot is in the Enchantment Table - if (a_SlotNum == 0) + + + + +void cSlotAreaEnchanting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots) +{ + const cItem * Slot = GetSlot(0, a_Player); + if (!Slot->IsEmpty()) { - if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) - { - ShiftClickedSlot(a_Player); - } - else - { - ClickedSlot(a_Player); - } + return; } + + if (a_Apply) + { + SetSlot(0, a_Player, a_ItemStack.CopyOne()); + } + a_ItemStack.m_ItemCount -= 1; + if (a_ItemStack.m_ItemCount <= 0) + { + a_ItemStack.Empty(); + } + + UpdateResult(a_Player); +} + + + + + +void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) +{ + // Toss the item in the enchanting slot + TossItems(a_Player, 0, 1); + // Player not found - that is acceptable } -void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) +void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) { cItem Item = *GetSlot(0, a_Player); @@ -676,43 +802,13 @@ void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) } else if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty()) { - int PosX = 0; - int PosY = 0; - int PosZ = 0; - cEnchantingWindow * Window = (cEnchantingWindow*)&m_ParentWindow; - Window->GetBlockPos(PosX, PosY, PosZ); - - int bookshelves = 0; - cBlockArea Area; - Area.Read(a_Player.GetWorld(), PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - - for (int y = 0; y <= 2; y++) - { - for (int x = 0; x <= 4; x++) - { - for (int z = 0; z <= 4; z++) - { - if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) - { - if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) - { - bookshelves++; - } - } - } - } - } - - if (bookshelves > 15) - { - bookshelves = 15; - } + int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); cFastRandom Random; - int base = (Random.GenerateRandomInteger(1, 8) + floor(bookshelves / 2) + Random.GenerateRandomInteger(0, bookshelves)); + int base = (Random.GenerateRandomInteger(1, 8) + floor(Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves)); int topSlot = std::max(base / 3, 1); int middleSlot = (base * 2) / 3 + 1; - int bottomSlot = std::max(base, bookshelves * 2); + int bottomSlot = std::max(base, Bookshelves * 2); m_ParentWindow.SetProperty(0, topSlot, a_Player); m_ParentWindow.SetProperty(1, middleSlot, a_Player); @@ -730,20 +826,34 @@ void cSlotAreaEnchanting::ClickedSlot(cPlayer & a_Player) -void cSlotAreaEnchanting::ShiftClickedSlot(cPlayer & a_Player) +int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) { - m_ParentWindow.SetProperty(0, 0, a_Player); - m_ParentWindow.SetProperty(1, 0, a_Player); - m_ParentWindow.SetProperty(2, 0, a_Player); -} - - + int PosX, PosY, PosZ; + ((cEnchantingWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ); + int Bookshelves = 0; + cBlockArea Area; + Area.Read(a_World, PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - -int cSlotAreaEnchanting::GetItemPlaceCount(cItem & a_Item) -{ - return 1; + for (int y = 0; y <= 2; y++) + { + for (int x = 0; x <= 4; x++) + { + for (int z = 0; z <= 4; z++) + { + if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) + { + if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) + { + Bookshelves++; + } + } + } + } + } + + Bookshelves = std::min(Bookshelves, 15); + return Bookshelves; } diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 431ad753c..bab1098bb 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -19,6 +19,8 @@ class cDropSpenserEntity; class cEnderChestEntity; class cFurnaceEntity; class cCraftingRecipe; +class cEnchantingWindow; +class cWorld; @@ -67,8 +69,6 @@ public: /// Returns true if full stack has been collected in a_Dragging, false if there's space remaining to fill. virtual bool CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool a_CollectFullStacks); - virtual int GetItemPlaceCount(cItem & a_Item); - protected: int m_NumSlots; cWindow & m_ParentWindow; @@ -260,19 +260,22 @@ class cSlotAreaEnchanting : typedef cSlotAreaTemporary super; public: - cSlotAreaEnchanting(int a_NumSlots, cWindow & a_ParentWindow); + cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow); - // cSlotAreaTemporary overrides: + // cSlotArea overrides: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; + virtual void DblClicked(cPlayer & a_Player, int a_SlotNum) override; + virtual void DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) override; + + // cSlotAreaTemporary overrides: virtual void OnPlayerRemoved(cPlayer & a_Player) override; - virtual int GetItemPlaceCount(cItem & a_Item) override; -protected: - /// Handles a click in the item slot. - void ClickedSlot(cPlayer & a_Player); + /* Get the count of bookshelves who stand in the near of the enchanting table */ + int GetBookshelvesCount(cWorld * a_World); - /// Handles a shift-click in the item slot. - void ShiftClickedSlot(cPlayer & a_Player); +protected: + /** Handles a click in the item slot. */ + void UpdateResult(cPlayer & a_Player); }; diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index c514e76e7..c7b9b6aaf 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -813,7 +813,7 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : m_BlockY(a_BlockY), m_BlockZ(a_BlockZ) { - m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this)); + m_SlotAreas.push_back(new cSlotAreaEnchanting(*this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); } -- cgit v1.2.3 From 36f747d6746b32c4352354933b25ae7ead6f1b7f Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Tue, 15 Apr 2014 21:43:52 +0200 Subject: Added Book Enchanting --- src/UI/SlotArea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 46ed493d8..d8d02f458 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -800,7 +800,7 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty()) + else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK && Item.m_Enchantments.IsEmpty()) { int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); -- cgit v1.2.3 From 8c33b3c4155b030e2174a453ca067be969473736 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Wed, 16 Apr 2014 13:31:37 +0200 Subject: Fixed double enchanting items --- src/UI/SlotArea.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index d8d02f458..621854518 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -794,13 +794,13 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) { cItem Item = *GetSlot(0, a_Player); - if (Item.IsEmpty()) + if (Item.IsEmpty() || !Item.m_Enchantments.IsEmpty()) { m_ParentWindow.SetProperty(0, 0, a_Player); m_ParentWindow.SetProperty(1, 0, a_Player); m_ParentWindow.SetProperty(2, 0, a_Player); } - else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK && Item.m_Enchantments.IsEmpty()) + else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK) { int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); -- cgit v1.2.3 From f9343a8490b50cb28a62c7327c0013da48ca2745 Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Thu, 17 Apr 2014 13:15:35 +0200 Subject: Modified many things --- src/UI/SlotArea.cpp | 66 ++++++++++++++++++++++++++++++++++++++++------------- src/UI/Window.cpp | 41 +++------------------------------ src/UI/Window.h | 2 +- 3 files changed, 54 insertions(+), 55 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 621854518..26fdfe928 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -802,7 +802,7 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) } else if (cItem::IsEnchantable(Item.m_ItemType) || Item.m_ItemType == E_ITEM_BOOK) { - int Bookshelves = GetBookshelvesCount(a_Player.GetWorld()); + int Bookshelves = std::min(GetBookshelvesCount(a_Player.GetWorld()), 15); cFastRandom Random; int base = (Random.GenerateRandomInteger(1, 8) + floor(Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves)); @@ -835,24 +835,58 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) cBlockArea Area; Area.Read(a_World, PosX - 2, PosX + 2, PosY, PosY + 1, PosZ - 2, PosZ + 2); - for (int y = 0; y <= 2; y++) + static const struct { - for (int x = 0; x <= 4; x++) + int m_BookX, m_BookY, m_BookZ; // Coords to check for bookcases + int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won\'t be counted + } CheckCoords[] = + { + { 0, 0, 0, 1, 0, 1 }, // Bookcase at {0, 0, 0}, air at {1, 0, 1} + { 0, 0, 1, 1, 0, 1 }, // Bookcase at {0, 0, 1}, air at {1, 0, 1} + { 0, 0, 2, 1, 0, 2 }, // Bookcase at {0, 0, 2}, air at {1, 0, 2} + { 0, 0, 3, 1, 0, 3 }, // Bookcase at {0, 0, 3}, air at {1, 0, 3} + { 0, 0, 4, 1, 0, 3 }, // Bookcase at {0, 0, 4}, air at {1, 0, 3} + { 1, 0, 4, 1, 0, 3 }, // Bookcase at {1, 0, 4}, air at {1, 0, 3} + { 2, 0, 4, 2, 0, 3 }, // Bookcase at {2, 0, 4}, air at {2, 0, 3} + { 3, 0, 4, 3, 0, 3 }, // Bookcase at {3, 0, 4}, air at {3, 0, 3} + { 4, 0, 4, 3, 0, 3 }, // Bookcase at {4, 0, 4}, air at {3, 0, 3} + { 4, 0, 3, 3, 0, 3 }, // Bookcase at {4, 0, 3}, air at {3, 0, 3} + { 4, 0, 2, 3, 0, 2 }, // Bookcase at {4, 0, 2}, air at {3, 0, 2} + { 4, 0, 1, 3, 0, 1 }, // Bookcase at {4, 0, 1}, air at {3, 0, 1} + { 4, 0, 0, 3, 0, 1 }, // Bookcase at {4, 0, 0}, air at {3, 0, 1} + { 3, 0, 0, 3, 0, 1 }, // Bookcase at {3, 0, 0}, air at {3, 0, 1} + { 2, 0, 0, 2, 0, 1 }, // Bookcase at {2, 0, 0}, air at {2, 0, 1} + { 1, 0, 0, 1, 0, 1 }, // Bookcase at {1, 0, 0}, air at {1, 0, 1} + + { 0, 1, 0, 1, 1, 1 }, // Bookcase at {0, 1, 0}, air at {1, 1, 1} + { 0, 1, 1, 1, 1, 1 }, // Bookcase at {0, 1, 1}, air at {1, 1, 1} + { 0, 1, 2, 1, 1, 2 }, // Bookcase at {0, 1, 2}, air at {1, 1, 2} + { 0, 1, 3, 1, 1, 3 }, // Bookcase at {0, 1, 3}, air at {1, 1, 3} + { 0, 1, 4, 1, 1, 3 }, // Bookcase at {0, 1, 4}, air at {1, 1, 3} + { 1, 1, 4, 1, 1, 3 }, // Bookcase at {1, 1, 4}, air at {1, 1, 3} + { 2, 1, 4, 2, 1, 3 }, // Bookcase at {2, 1, 4}, air at {2, 1, 3} + { 3, 1, 4, 3, 1, 3 }, // Bookcase at {3, 1, 4}, air at {3, 1, 3} + { 4, 1, 4, 3, 1, 3 }, // Bookcase at {4, 1, 4}, air at {3, 1, 3} + { 4, 1, 3, 3, 1, 3 }, // Bookcase at {4, 1, 3}, air at {3, 1, 3} + { 4, 1, 2, 3, 1, 2 }, // Bookcase at {4, 1, 2}, air at {3, 1, 2} + { 4, 1, 1, 3, 1, 1 }, // Bookcase at {4, 1, 1}, air at {3, 1, 1} + { 4, 1, 0, 3, 1, 1 }, // Bookcase at {4, 1, 0}, air at {3, 1, 1} + { 3, 1, 0, 3, 1, 1 }, // Bookcase at {3, 1, 0}, air at {3, 1, 1} + { 2, 1, 0, 2, 1, 1 }, // Bookcase at {2, 1, 0}, air at {2, 1, 1} + { 1, 1, 0, 1, 1, 1 }, // Bookcase at {1, 1, 0}, air at {1, 1, 1} + }; + + for (size_t i = 0; i < ARRAYCOUNT(CheckCoords); i++) + { + if ( + (Area.GetRelBlockType(CheckCoords[i].m_AirX, CheckCoords[i].m_AirY, CheckCoords[i].m_AirZ) == E_BLOCK_AIR) && // There's air in the checkspot + (Area.GetRelBlockType(CheckCoords[i].m_BookX, CheckCoords[i].m_BookY, CheckCoords[i].m_BookZ) == E_BLOCK_BOOKCASE) // There's bookcase in the wanted place + ) { - for (int z = 0; z <= 4; z++) - { - if ((((x == 0) || (x == 4)) || ((z == 0) || (z == 4))) && ((y == 0) || y == 1)) - { - if (Area.GetRelBlockType(x, y, z) == E_BLOCK_BOOKCASE) - { - Bookshelves++; - } - } - } + Bookshelves++; } - } - - Bookshelves = std::min(Bookshelves, 15); + } // for i - CheckCoords + return Bookshelves; } diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index c7b9b6aaf..fffe0e3fd 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -824,18 +824,7 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : void cEnchantingWindow::SetProperty(int a_Property, int a_Value) { - if (a_Property == 0) - { - m_PropertyValue0 = a_Value; - } - else if (a_Property == 1) - { - m_PropertyValue1 = a_Value; - } - else if (a_Property == 2) - { - m_PropertyValue2 = a_Value; - } + m_PropertyValue[a_Property] = a_Value; cCSLock Lock(m_CS); for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr) @@ -850,18 +839,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value) void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player) { - if (a_Property == 0) - { - m_PropertyValue0 = a_Value; - } - else if (a_Property == 1) - { - m_PropertyValue1 = a_Value; - } - else if (a_Property == 2) - { - m_PropertyValue2 = a_Value; - } + m_PropertyValue[a_Property] = a_Value; a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); } @@ -872,20 +850,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Pla int cEnchantingWindow::GetPropertyValue(int a_Property) { - if (a_Property == 0) - { - return m_PropertyValue0; - } - else if (a_Property == 1) - { - return m_PropertyValue1; - } - else if (a_Property == 2) - { - return m_PropertyValue2; - } - - return -1; + return m_PropertyValue[a_Property]; } diff --git a/src/UI/Window.h b/src/UI/Window.h index 5e799248c..1ca67bfd8 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -249,7 +249,7 @@ public: cSlotArea * m_SlotArea; protected: - int m_PropertyValue0, m_PropertyValue1, m_PropertyValue2; + int m_PropertyValue[3]; int m_BlockX, m_BlockY, m_BlockZ; }; -- cgit v1.2.3 From a6de7bf1cd80847abed22e3b962a5b8650b2911c Mon Sep 17 00:00:00 2001 From: daniel0916 Date: Sat, 19 Apr 2014 15:10:50 +0200 Subject: Fixed Code --- src/UI/SlotArea.cpp | 5 +++-- src/UI/Window.cpp | 8 ++------ 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 26fdfe928..5f74b4fa3 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -783,7 +783,8 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player) { // Toss the item in the enchanting slot TossItems(a_Player, 0, 1); - // Player not found - that is acceptable + + super::OnPlayerRemoved(a_Player); } @@ -838,7 +839,7 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World) static const struct { int m_BookX, m_BookY, m_BookZ; // Coords to check for bookcases - int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won\'t be counted + int m_AirX, m_AirY, m_AirZ; // Coords to check for air; if not air, the bookcase won't be counted } CheckCoords[] = { { 0, 0, 0, 1, 0, 1 }, // Bookcase at {0, 0, 0}, air at {1, 0, 1} diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index fffe0e3fd..0a78578fc 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -826,11 +826,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value) { m_PropertyValue[a_Property] = a_Value; - cCSLock Lock(m_CS); - for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr) - { - (*itr)->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); - } // for itr - m_OpenedBy[] + super::SetProperty(a_Property, a_Value); } @@ -841,7 +837,7 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Pla { m_PropertyValue[a_Property] = a_Value; - a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); + super::SetProperty(a_Property, a_Value, a_Player); } -- cgit v1.2.3