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 013da806ec20b62a742aded9a9d2b8131193f30d Mon Sep 17 00:00:00 2001 From: jfhumann Date: Fri, 18 Apr 2014 21:09:44 +0200 Subject: Did some static analysis, fixed some bugs and optimized a lot of code --- src/UI/SlotArea.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 88977e005..419d919bd 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -483,6 +483,7 @@ void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player) // Get the current recipe: cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player); + const cItem & Result = Recipe.GetResult(); cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1; cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize); @@ -490,16 +491,16 @@ void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player) // If possible, craft: if (DraggingItem.IsEmpty()) { - DraggingItem = Recipe.GetResult(); + DraggingItem = Result; Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); } - else if (DraggingItem.IsEqual(Recipe.GetResult())) + else if (DraggingItem.IsEqual(Result)) { - cItemHandler * Handler = ItemHandler(Recipe.GetResult().m_ItemType); - if (DraggingItem.m_ItemCount + Recipe.GetResult().m_ItemCount <= Handler->GetMaxStackSize()) + cItemHandler * Handler = ItemHandler(Result.m_ItemType); + if (DraggingItem.m_ItemCount + Result.m_ItemCount <= Handler->GetMaxStackSize()) { - DraggingItem.m_ItemCount += Recipe.GetResult().m_ItemCount; + DraggingItem.m_ItemCount += Result.m_ItemCount; Recipe.ConsumeIngredients(Grid); Grid.CopyToItems(PlayerSlots); } -- 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 From 7b246d9a8dae22937171a753072d72b4732986d7 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 20 Apr 2014 13:50:37 +0200 Subject: Fixed MSVC compilation. --- 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 5f74b4fa3..e062598c8 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -806,7 +806,7 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player) int Bookshelves = std::min(GetBookshelvesCount(a_Player.GetWorld()), 15); cFastRandom Random; - int base = (Random.GenerateRandomInteger(1, 8) + floor(Bookshelves / 2) + Random.GenerateRandomInteger(0, Bookshelves)); + int base = (Random.GenerateRandomInteger(1, 8) + (int)floor((float)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); -- cgit v1.2.3 From 9cbb3a339f98f1737ea78af7f40e1ae7d25027e8 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 24 Apr 2014 20:41:25 +0200 Subject: Fix armor in survival mode. --- src/UI/SlotArea.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/UI/SlotArea.h | 7 ++++- 2 files changed, 80 insertions(+), 1 deletion(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 2d58388b1..ef4cf17cd 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); } ; -- cgit v1.2.3 From 376dc880b37e1b104c86efebef0f294c34ca3c42 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 24 Apr 2014 23:03:04 +0200 Subject: Add armor to switch() in ItemHandler.cpp --- 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 ef4cf17cd..87b4032e0 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -1108,7 +1108,7 @@ void cSlotAreaArmor::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C return; } - //Armors haven't a dbl click + // Armors haven't a dbl click if (a_ClickAction == caDblClick) { return; -- cgit v1.2.3 From e47dab84f3f6606d6d6e95774b16d7d4e8d7daa6 Mon Sep 17 00:00:00 2001 From: archshift Date: Fri, 25 Apr 2014 09:56:15 -0700 Subject: Cmake generated projects for IDEs include headers in project files. --- src/UI/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'src/UI') 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}) -- cgit v1.2.3 From 3c102870f600178b7cabf6714f83e06fc05b42fd Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 1 May 2014 00:47:57 +0200 Subject: Add anvil window and slot area. --- src/UI/SlotArea.cpp | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/UI/SlotArea.h | 29 +++++++++ src/UI/Window.cpp | 15 +++++ src/UI/Window.h | 12 ++++ 4 files changed, 229 insertions(+) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 87b4032e0..eac8257ec 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -595,6 +595,179 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSlotAreaAnvil: + +cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) : + cSlotAreaTemporary(3, a_ParentWindow), + m_MaximumCost(0), + m_RepairedItemName("") +{ +} + + + + + +void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) +{ + super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); + UpdateResult(a_Player); +} + + + + + +void cSlotAreaAnvil::OnPlayerRemoved(cPlayer & a_Player) +{ + TossItems(a_Player, 0, 3); + super::OnPlayerRemoved(a_Player); +} + + + + + +void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) +{ + cItem Input(*GetSlot(0, a_Player)); + cItem SecondInput(*GetSlot(1, a_Player)); + cItem Output(*GetSlot(2, a_Player)); + + if (Input.IsEmpty() && !Output.IsEmpty()) + { + Output.Empty(); + SetSlot(2, a_Player, Output); + m_ParentWindow.SetProperty(0, 0, a_Player); + return; + } + + int RepairCost = cItemHandler::GetItemHandler(Input)->GetRepairCost(); + int NeedExp = 0; + if (!SecondInput.IsEmpty()) + { + RepairCost += cItemHandler::GetItemHandler(SecondInput)->GetRepairCost(); + + if (Input.IsDamageable() && cItemHandler::GetItemHandler(Input)->CanRepairWithItem(SecondInput)) + { + // Tool and armor repair with special item (iron / gold / diamond / ...) + int DamageDiff = std::min((int)Input.m_ItemDamage, (int)Input.GetMaxDamage() / 4); + if (DamageDiff < 0) + { + // No enchantment + Output.Empty(); + SetSlot(2, a_Player, Output); + m_ParentWindow.SetProperty(0, 0, a_Player); + return; + } + + int x = 0; + while ((DamageDiff > 0) && (x < SecondInput.m_ItemCount)) + { + Input.m_ItemDamage -= DamageDiff; + NeedExp += std::max(1, DamageDiff / 100) + Input.m_Enchantments.Size(); + DamageDiff = std::min((int)Input.m_ItemDamage, (int)Input.GetMaxDamage() / 4); + + ++x; + } + } + else + { + // Tool and armor repair with two tools / armors + if (!Input.IsSameType(SecondInput) || !Input.IsDamageable()) + { + // No enchantment + Output.Empty(); + SetSlot(2, a_Player, Output); + m_ParentWindow.SetProperty(0, 0, a_Player); + return; + } + + int FirstDamageDiff = Input.GetMaxDamage() - Input.m_ItemDamage; + int SecondDamageDiff = SecondInput.GetMaxDamage() - SecondInput.m_ItemDamage; + int Damage = SecondDamageDiff + Input.GetMaxDamage() * 12 / 100; + + int NewItemDamage = Input.GetMaxDamage() - (FirstDamageDiff + Damage); + if (NewItemDamage > 0) + { + NewItemDamage = 0; + } + + if (NewItemDamage < Input.m_ItemDamage) + { + Input.m_ItemDamage = NewItemDamage; + NeedExp += std::max(1, Damage / 100); + } + + // TODO: Add enchantments. + } + } + + int NameChangeExp = 0; + if (m_RepairedItemName.empty()) + { + // Remove custom name + if (!Input.m_CustomName.empty()) + { + NameChangeExp = (Input.IsDamageable()) ? 4 : (Input.m_ItemCount * 5); + NeedExp += NameChangeExp; + Input.m_CustomName = ""; + } + } + else if (m_RepairedItemName != Input.m_CustomName) + { + // Change custom name + NameChangeExp = (Input.IsDamageable()) ? 4 : (Input.m_ItemCount * 5); + NeedExp += NameChangeExp; + + if (!Input.m_CustomName.empty()) + { + RepairCost += NameChangeExp / 2; + } + + Input.m_CustomName = m_RepairedItemName; + } + + // TODO: Add enchantment exp cost. + + int MaximumCost = RepairCost + NeedExp; + + if (NeedExp < 0) + { + Input.Empty(); + } + + if (NameChangeExp == NeedExp && NameChangeExp > 0 && MaximumCost >= 40) + { + MaximumCost = 39; + } + if (MaximumCost >= 40 && !a_Player.IsGameModeCreative()) + { + Input.Empty(); + } + + /* TODO: Add repair cost to cItem and not ItemHandler. This is required for this function! + if (!Input.IsEmpty()) + { + RepairCost = max(cItemHandler::GetItemHandler(Input)->GetRepairCost(), cItemHandler::GetItemHandler(SecondInput)->GetRepairCost()); + if (!Input.m_CustomName.empty()) + { + RepairCost -= 9; + } + RepairCost = max(RepairCost, 0); + RepairCost += 2; + }*/ + + SetSlot(2, a_Player, Input); + m_ParentWindow.SetProperty(0, MaximumCost, a_Player); +} + + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaEnchanting: diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 254722822..a316480c6 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -9,6 +9,7 @@ #pragma once #include "../Inventory.h" +#include "Window.h" @@ -259,6 +260,34 @@ protected: +class cSlotAreaAnvil : + public cSlotAreaTemporary +{ + typedef cSlotAreaTemporary super; + +public: + cSlotAreaAnvil(cAnvilWindow & a_ParentWindow); + + // cSlotArea overrides: + virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; + + // cSlotAreaTemporary overrides: + virtual void OnPlayerRemoved(cPlayer & a_Player) override; + +protected: + /** Handles a click in the item slot. */ + void UpdateResult(cPlayer & a_Player); + + /** The maximum cost of repairing/renaming in the anvil. */ + int m_MaximumCost; + + AString m_RepairedItemName; +} ; + + + + + class cSlotAreaEnchanting : public cSlotAreaTemporary { diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 0a78578fc..eb105f8ab 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -804,6 +804,21 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cAnvilWindow: + +cAnvilWindow::cAnvilWindow() : + cWindow(wtAnvil, "Repair") +{ + m_SlotAreas.push_back(new cSlotAreaAnvil(*this)); + m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cEnchantingWindow: diff --git a/src/UI/Window.h b/src/UI/Window.h index 1ca67bfd8..c08b36f9b 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -231,6 +231,18 @@ public: +class cAnvilWindow : + public cWindow +{ + typedef cWindow super; +public: + cAnvilWindow(); +} ; + + + + + class cEnchantingWindow : public cWindow { -- cgit v1.2.3 From 6ac332cd0662f49e30f60ae0b5a3b7f85df8cfb3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 1 May 2014 01:25:04 +0200 Subject: Add MC|ItemName plugin message. --- src/UI/SlotArea.cpp | 10 +++++----- src/UI/SlotArea.h | 2 -- src/UI/Window.cpp | 3 ++- src/UI/Window.h | 9 +++++++++ 4 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index eac8257ec..2941982a7 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -600,8 +600,7 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) : cSlotAreaTemporary(3, a_ParentWindow), - m_MaximumCost(0), - m_RepairedItemName("") + m_MaximumCost(0) { } @@ -705,7 +704,8 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) } int NameChangeExp = 0; - if (m_RepairedItemName.empty()) + const AString & RepairedItemName = ((cAnvilWindow*)&m_ParentWindow)->GetRepairedItemName(); + if (RepairedItemName.empty()) { // Remove custom name if (!Input.m_CustomName.empty()) @@ -715,7 +715,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) Input.m_CustomName = ""; } } - else if (m_RepairedItemName != Input.m_CustomName) + else if (RepairedItemName != Input.m_CustomName) { // Change custom name NameChangeExp = (Input.IsDamageable()) ? 4 : (Input.m_ItemCount * 5); @@ -726,7 +726,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) RepairCost += NameChangeExp / 2; } - Input.m_CustomName = m_RepairedItemName; + Input.m_CustomName = RepairedItemName; } // TODO: Add enchantment exp cost. diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index a316480c6..01dcb88ab 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -280,8 +280,6 @@ protected: /** The maximum cost of repairing/renaming in the anvil. */ int m_MaximumCost; - - AString m_RepairedItemName; } ; diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index eb105f8ab..d6adbef8f 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -808,7 +808,8 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : // cAnvilWindow: cAnvilWindow::cAnvilWindow() : - cWindow(wtAnvil, "Repair") + cWindow(wtAnvil, "Repair"), + m_RepairedItemName("") { m_SlotAreas.push_back(new cSlotAreaAnvil(*this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); diff --git a/src/UI/Window.h b/src/UI/Window.h index c08b36f9b..8f6f80a41 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -237,6 +237,15 @@ class cAnvilWindow : typedef cWindow super; public: cAnvilWindow(); + + /** Gets the repaired item name. */ + AString GetRepairedItemName(void) const { return m_RepairedItemName; } + + /** Set the repaired item name. */ + void SetRepairedItemName(const AString & a_Name) { m_RepairedItemName = a_Name; } + +protected: + AString m_RepairedItemName; } ; -- cgit v1.2.3 From 7fe6e40bf7d40347f7f452ea2b7c353a5bc8073f Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 3 May 2014 23:42:26 +0200 Subject: Add clicks, exp subtraction, item check, ... --- src/UI/SlotArea.cpp | 164 +++++++++++++++++++++++++++++++++++++++++++++++++--- src/UI/SlotArea.h | 9 ++- src/UI/Window.cpp | 35 ++++++++++- src/UI/Window.h | 12 +++- 4 files changed, 204 insertions(+), 16 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 2941982a7..1e488de62 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -610,8 +610,151 @@ cSlotAreaAnvil::cSlotAreaAnvil(cAnvilWindow & a_ParentWindow) : void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); - UpdateResult(a_Player); + ASSERT((a_SlotNum >= 0) && (a_SlotNum < GetNumSlots())); + if (a_SlotNum != 2) + { + super::Clicked(a_Player, a_SlotNum, a_ClickAction, a_ClickedItem); + UpdateResult(a_Player); + return; + } + + bool bAsync = false; + if (GetSlot(a_SlotNum, a_Player) == NULL) + { + LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum); + return; + } + + 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 (Slot.IsEmpty()) + { + return; + } + if (!DraggingItem.IsEmpty()) + { + if (!(DraggingItem.IsEqual(Slot) && ((DraggingItem.m_ItemCount + Slot.m_ItemCount) <= cItemHandler::GetItemHandler(Slot)->GetMaxStackSize()))) + { + return; + } + } + + if (!CanTakeResultItem(a_Player)) + { + return; + } + + cItem NewItem = cItem(Slot); + NewItem.m_ItemCount += DraggingItem.m_ItemCount; + + Slot.Empty(); + DraggingItem.Empty(); + SetSlot(a_SlotNum, a_Player, Slot); + + DraggingItem = NewItem; + OnTakeResult(a_Player, NewItem); + + if (bAsync) + { + m_ParentWindow.BroadcastWholeWindow(); + } +} + + + + + +void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player, cItem a_ResultItem) +{ + if (!a_Player.IsGameModeCreative()) + { + a_Player.DeltaExperience(cPlayer::XpForLevel(m_MaximumCost)); + } + SetSlot(0, a_Player, cItem()); + + if (m_StackSizeToBeUsedInRepair > 0) + { + const cItem * Item = GetSlot(1, a_Player); + if (!Item->IsEmpty() && (Item->m_ItemCount > m_StackSizeToBeUsedInRepair)) + { + cItem NewSecondItem(*Item); + NewSecondItem.m_ItemCount -= m_StackSizeToBeUsedInRepair; + SetSlot(1, a_Player, NewSecondItem); + } + else + { + SetSlot(1, a_Player, cItem()); + } + } + else + { + SetSlot(1, a_Player, cItem()); + } + m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player); + + m_MaximumCost = 0; + ((cAnvilWindow*)&m_ParentWindow)->SetRepairedItemName("", false); + + int PosX, PosY, PosZ; + ((cAnvilWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ); + + BLOCKTYPE Block; + NIBBLETYPE BlockMeta; + a_Player.GetWorld()->GetBlockTypeMeta(PosX, PosY, PosZ, Block, BlockMeta); + + cFastRandom Random; + if (!a_Player.IsGameModeCreative() && (Block == E_BLOCK_ANVIL) && (Random.NextFloat(1.0F) < 0.12F)) + { + NIBBLETYPE var4 = BlockMeta & 0x3; + NIBBLETYPE AnvilDamage = BlockMeta >> 2; + ++AnvilDamage; + + if (AnvilDamage > 2) + { + // Anvil will break + a_Player.GetWorld()->SetBlock(PosX, PosY, PosZ, E_BLOCK_AIR, (NIBBLETYPE)0); + a_Player.GetWorld()->BroadcastSoundParticleEffect(1020, PosX, PosY, PosZ, 0); + a_Player.CloseWindow(false); + } + else + { + a_Player.GetWorld()->SetBlockMeta(PosX, PosY, PosZ, var4 | AnvilDamage << 2); + a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0); + } + } + else + { + a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0); + } +} + + + + + +bool cSlotAreaAnvil::CanTakeResultItem(cPlayer & a_Player) +{ + return ( + ( + a_Player.IsGameModeCreative() + || a_Player.GetXpLevel() >= m_MaximumCost + ) + && !GetSlot(2, a_Player)->IsEmpty() + && m_MaximumCost > 0 + ); } @@ -620,7 +763,7 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C void cSlotAreaAnvil::OnPlayerRemoved(cPlayer & a_Player) { - TossItems(a_Player, 0, 3); + TossItems(a_Player, 0, 2); super::OnPlayerRemoved(a_Player); } @@ -641,7 +784,9 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) m_ParentWindow.SetProperty(0, 0, a_Player); return; } - + + m_MaximumCost = 0; + m_StackSizeToBeUsedInRepair = 0; int RepairCost = cItemHandler::GetItemHandler(Input)->GetRepairCost(); int NeedExp = 0; if (!SecondInput.IsEmpty()) @@ -670,6 +815,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) ++x; } + m_StackSizeToBeUsedInRepair = x; } else { @@ -731,18 +877,18 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) // TODO: Add enchantment exp cost. - int MaximumCost = RepairCost + NeedExp; + m_MaximumCost = RepairCost + NeedExp; if (NeedExp < 0) { Input.Empty(); } - if (NameChangeExp == NeedExp && NameChangeExp > 0 && MaximumCost >= 40) + if (NameChangeExp == NeedExp && NameChangeExp > 0 && m_MaximumCost >= 40) { - MaximumCost = 39; + m_MaximumCost = 39; } - if (MaximumCost >= 40 && !a_Player.IsGameModeCreative()) + if (m_MaximumCost >= 40 && !a_Player.IsGameModeCreative()) { Input.Empty(); } @@ -760,7 +906,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) }*/ SetSlot(2, a_Player, Input); - m_ParentWindow.SetProperty(0, MaximumCost, a_Player); + m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player); } diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 01dcb88ab..4f273ec65 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -274,12 +274,19 @@ public: // cSlotAreaTemporary overrides: virtual void OnPlayerRemoved(cPlayer & a_Player) override; -protected: + bool CanTakeResultItem(cPlayer & a_Player); + + void OnTakeResult(cPlayer & a_Player, cItem a_ResultItem); + /** Handles a click in the item slot. */ void UpdateResult(cPlayer & a_Player); +protected: /** The maximum cost of repairing/renaming in the anvil. */ int m_MaximumCost; + + /** The stack size of the second item where was used for repair */ + char m_StackSizeToBeUsedInRepair; } ; diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index d6adbef8f..4991f0147 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -807,11 +807,15 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cAnvilWindow: -cAnvilWindow::cAnvilWindow() : +cAnvilWindow::cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : cWindow(wtAnvil, "Repair"), - m_RepairedItemName("") + m_RepairedItemName(""), + m_BlockX(a_BlockX), + m_BlockY(a_BlockY), + m_BlockZ(a_BlockZ) { - m_SlotAreas.push_back(new cSlotAreaAnvil(*this)); + m_AnvilSlotArea = new cSlotAreaAnvil(*this); + m_SlotAreas.push_back(m_AnvilSlotArea); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); } @@ -820,6 +824,31 @@ cAnvilWindow::cAnvilWindow() : +void cAnvilWindow::SetRepairedItemName(const AString & a_Name, cPlayer * a_Player) +{ + m_RepairedItemName = a_Name; + + if (a_Player != NULL) + { + m_AnvilSlotArea->UpdateResult(*a_Player); + } +} + + + + + +void cAnvilWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ) +{ + a_PosX = m_BlockX; + a_PosY = m_BlockY; + a_PosZ = m_BlockZ; +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cEnchantingWindow: diff --git a/src/UI/Window.h b/src/UI/Window.h index 8f6f80a41..c87d9b174 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -24,6 +24,7 @@ class cEnderChestEntity; class cFurnaceEntity; class cHopperEntity; class cSlotArea; +class cSlotAreaAnvil; class cWorld; typedef std::list cPlayerList; @@ -236,16 +237,21 @@ class cAnvilWindow : { typedef cWindow super; public: - cAnvilWindow(); + cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ); /** Gets the repaired item name. */ AString GetRepairedItemName(void) const { return m_RepairedItemName; } /** Set the repaired item name. */ - void SetRepairedItemName(const AString & a_Name) { m_RepairedItemName = a_Name; } + void SetRepairedItemName(const AString & a_Name, cPlayer * a_Player); + + /** Get the Position from the Enchantment Table */ + void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); protected: + cSlotAreaAnvil * m_AnvilSlotArea; AString m_RepairedItemName; + int m_BlockX, m_BlockY, m_BlockZ; } ; @@ -264,7 +270,7 @@ public: /** Return the Value of a Property */ int GetPropertyValue(int a_Property); - /** Set the Position Values to the Position of the Enchantment Table */ + /** Get the Position from the Enchantment Table */ void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); cSlotArea * m_SlotArea; -- cgit v1.2.3 From ca3c9ce84d50426631bf49124ad5e822c8ef9e94 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 4 May 2014 01:20:16 +0200 Subject: This isn't a enchantment table :D --- src/UI/Window.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/UI') diff --git a/src/UI/Window.h b/src/UI/Window.h index c87d9b174..542dccb88 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -245,7 +245,7 @@ public: /** Set the repaired item name. */ void SetRepairedItemName(const AString & a_Name, cPlayer * a_Player); - /** Get the Position from the Enchantment Table */ + /** Gets the Position from the Anvil */ void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ); protected: -- cgit v1.2.3 From ecc62dbb9c8d7fcce7e385285ff701a002462137 Mon Sep 17 00:00:00 2001 From: Howaner Date: Sun, 4 May 2014 11:11:07 +0200 Subject: Add anvil shift click. --- src/UI/SlotArea.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++--- src/UI/SlotArea.h | 4 ++- 2 files changed, 86 insertions(+), 5 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 1e488de62..7b9f4e628 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -244,7 +244,7 @@ void cSlotArea::OnPlayerRemoved(cPlayer & a_Player) -void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_Apply, bool a_KeepEmptySlots) +void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) { for (int i = 0; i < m_NumSlots; i++) { @@ -264,7 +264,7 @@ void cSlotArea::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ { NumFit = a_ItemStack.m_ItemCount; } - if (a_Apply) + if (a_ShouldApply) { cItem NewSlot(a_ItemStack); NewSlot.m_ItemCount = Slot->m_ItemCount + NumFit; @@ -630,6 +630,12 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C return; } + if ((a_ClickAction == caShiftLeftClick) || (a_ClickAction == caShiftRightClick)) + { + ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + return; + } + cItem Slot(*GetSlot(a_SlotNum, a_Player)); if (!Slot.IsSameType(a_ClickedItem)) { @@ -665,7 +671,7 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C SetSlot(a_SlotNum, a_Player, Slot); DraggingItem = NewItem; - OnTakeResult(a_Player, NewItem); + OnTakeResult(a_Player); if (bAsync) { @@ -677,7 +683,80 @@ void cSlotAreaAnvil::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_C -void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player, cItem a_ResultItem) +void cSlotAreaAnvil::ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem) +{ + if (a_SlotNum != 2) + { + super::ShiftClicked(a_Player, a_SlotNum, a_ClickedItem); + UpdateResult(a_Player); + return; + } + + // Make a copy of the slot, distribute it among the other areas, then update the slot to contain the leftover: + cItem Slot(*GetSlot(a_SlotNum, a_Player)); + + if (Slot.IsEmpty() || !CanTakeResultItem(a_Player)) + { + return; + } + + m_ParentWindow.DistributeStack(Slot, a_Player, this, true); + if (Slot.IsEmpty()) + { + Slot.Empty(); + OnTakeResult(a_Player); + } + SetSlot(a_SlotNum, a_Player, Slot); + + // Some clients try to guess our actions and not always right (armor slots in 1.2.5), so we fix them: + m_ParentWindow.BroadcastWholeWindow(); +} + + + + + +void cSlotAreaAnvil::DistributeStack(cItem & a_ItemStack, cPlayer & a_Player, bool a_ShouldApply, bool a_KeepEmptySlots) +{ + for (int i = 0; i < 2; i++) + { + const cItem * Slot = GetSlot(i, a_Player); + if (!Slot->IsEqual(a_ItemStack) && (!Slot->IsEmpty() || a_KeepEmptySlots)) + { + // Different items + continue; + } + int NumFit = ItemHandler(Slot->m_ItemType)->GetMaxStackSize() - Slot->m_ItemCount; + if (NumFit <= 0) + { + // Full stack already + continue; + } + if (NumFit > a_ItemStack.m_ItemCount) + { + NumFit = a_ItemStack.m_ItemCount; + } + if (a_ShouldApply) + { + cItem NewSlot(a_ItemStack); + NewSlot.m_ItemCount = Slot->m_ItemCount + NumFit; + SetSlot(i, a_Player, NewSlot); + } + a_ItemStack.m_ItemCount -= NumFit; + if (a_ItemStack.IsEmpty()) + { + UpdateResult(a_Player); + return; + } + } // for i - Slots + UpdateResult(a_Player); +} + + + + + +void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player) { if (!a_Player.IsGameModeCreative()) { diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index 4f273ec65..e7a2acd47 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -270,13 +270,15 @@ public: // cSlotArea overrides: virtual void Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) override; + virtual void ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_ClickedItem) 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; bool CanTakeResultItem(cPlayer & a_Player); - void OnTakeResult(cPlayer & a_Player, cItem a_ResultItem); + void OnTakeResult(cPlayer & a_Player); /** Handles a click in the item slot. */ void UpdateResult(cPlayer & a_Player); -- cgit v1.2.3 From c162d69e7bb48221b9eacbd378b41129cfb35ebd Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 5 May 2014 15:45:03 +0200 Subject: Add doxycomments to cSlotAreaAnvil functions. --- src/UI/SlotArea.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/UI') diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index e7a2acd47..4da6a672f 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -276,8 +276,10 @@ public: // cSlotAreaTemporary overrides: virtual void OnPlayerRemoved(cPlayer & a_Player) override; + /** Can the player take the item from the slot? */ bool CanTakeResultItem(cPlayer & a_Player); + /** This function will call, when the player take the item from the slot. */ void OnTakeResult(cPlayer & a_Player); /** Handles a click in the item slot. */ -- cgit v1.2.3 From f2617d06830c649c5d13d1daf4f3e70e7ee487b0 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 5 May 2014 15:49:56 +0200 Subject: Add comments to CanTakeResultItem() --- src/UI/SlotArea.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 7b9f4e628..0f5e292d0 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -828,11 +828,11 @@ bool cSlotAreaAnvil::CanTakeResultItem(cPlayer & a_Player) { return ( ( - a_Player.IsGameModeCreative() - || a_Player.GetXpLevel() >= m_MaximumCost - ) - && !GetSlot(2, a_Player)->IsEmpty() - && m_MaximumCost > 0 + a_Player.IsGameModeCreative() || // Is the player in gamemode? + (a_Player.GetXpLevel() >= m_MaximumCost) // or the player have enough exp? + ) && + (!GetSlot(2, a_Player)->IsEmpty()) && // Is a item in the result slot? + (m_MaximumCost > 0) // And: Is m_MaximumCost higher than 0? ); } -- cgit v1.2.3 From a138671e0e38cd452b001c87d42b7eccd1e447e9 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 5 May 2014 17:36:22 +0200 Subject: Fix SetRepairedItemName() in SlotArea.cpp --- 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 0f5e292d0..0e3e293aa 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -785,7 +785,7 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player) m_ParentWindow.SetProperty(0, m_MaximumCost, a_Player); m_MaximumCost = 0; - ((cAnvilWindow*)&m_ParentWindow)->SetRepairedItemName("", false); + ((cAnvilWindow*)&m_ParentWindow)->SetRepairedItemName("", NULL); int PosX, PosY, PosZ; ((cAnvilWindow*)&m_ParentWindow)->GetBlockPos(PosX, PosY, PosZ); -- cgit v1.2.3 From 954b59d6f460106e93efab39c8666d4692db25b6 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 6 May 2014 19:38:09 +0200 Subject: Rename CanRepairWithItem to CanRepairWithRawMaterial and rename Size() to Count() --- src/UI/SlotArea.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/UI') diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 0e3e293aa..fcf5f6f6b 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -797,7 +797,7 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player) cFastRandom Random; if (!a_Player.IsGameModeCreative() && (Block == E_BLOCK_ANVIL) && (Random.NextFloat(1.0F) < 0.12F)) { - NIBBLETYPE var4 = BlockMeta & 0x3; + NIBBLETYPE Orientation = BlockMeta & 0x3; NIBBLETYPE AnvilDamage = BlockMeta >> 2; ++AnvilDamage; @@ -810,7 +810,7 @@ void cSlotAreaAnvil::OnTakeResult(cPlayer & a_Player) } else { - a_Player.GetWorld()->SetBlockMeta(PosX, PosY, PosZ, var4 | AnvilDamage << 2); + a_Player.GetWorld()->SetBlockMeta(PosX, PosY, PosZ, Orientation | (AnvilDamage << 2)); a_Player.GetWorld()->BroadcastSoundParticleEffect(1021, PosX, PosY, PosZ, 0); } } @@ -832,7 +832,7 @@ bool cSlotAreaAnvil::CanTakeResultItem(cPlayer & a_Player) (a_Player.GetXpLevel() >= m_MaximumCost) // or the player have enough exp? ) && (!GetSlot(2, a_Player)->IsEmpty()) && // Is a item in the result slot? - (m_MaximumCost > 0) // And: Is m_MaximumCost higher than 0? + (m_MaximumCost > 0) // When no maximum cost is set, the item isn't set from the UpdateResult() method and can't be a valid enchanting result. ); } @@ -871,8 +871,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) if (!SecondInput.IsEmpty()) { RepairCost += cItemHandler::GetItemHandler(SecondInput)->GetRepairCost(); - - if (Input.IsDamageable() && cItemHandler::GetItemHandler(Input)->CanRepairWithItem(SecondInput)) + if (Input.IsDamageable() && cItemHandler::GetItemHandler(Input)->CanRepairWithRawMaterial(SecondInput.m_ItemType)) { // Tool and armor repair with special item (iron / gold / diamond / ...) int DamageDiff = std::min((int)Input.m_ItemDamage, (int)Input.GetMaxDamage() / 4); @@ -889,7 +888,7 @@ void cSlotAreaAnvil::UpdateResult(cPlayer & a_Player) while ((DamageDiff > 0) && (x < SecondInput.m_ItemCount)) { Input.m_ItemDamage -= DamageDiff; - NeedExp += std::max(1, DamageDiff / 100) + Input.m_Enchantments.Size(); + NeedExp += std::max(1, DamageDiff / 100) + Input.m_Enchantments.Count(); DamageDiff = std::min((int)Input.m_ItemDamage, (int)Input.GetMaxDamage() / 4); ++x; -- cgit v1.2.3