summaryrefslogtreecommitdiffstats
path: root/src/UI
diff options
context:
space:
mode:
Diffstat (limited to 'src/UI')
-rw-r--r--src/UI/SlotArea.cpp96
-rw-r--r--src/UI/SlotArea.h28
-rw-r--r--src/UI/Window.cpp15
-rw-r--r--src/UI/Window.h12
4 files changed, 151 insertions, 0 deletions
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index 88977e005..9463bc593 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"
@@ -593,6 +595,100 @@ 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)
+{
+ LOGWARN("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)
+{
+ LOGWARN("Click!");
+
+ if (a_Player.GetDraggingItem().IsEmpty())
+ {
+ LOGWARN("EMPTY");
+ 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");
+ m_ParentWindow.SetProperty(0, topSlot);
+ m_ParentWindow.SetProperty(1, middleSlot);
+ m_ParentWindow.SetProperty(2, bottomSlot);
+ }
+ else
+ {
+ LOGWARN("Not Enchantable");
+ m_ParentWindow.SetProperty(0, 0);
+ m_ParentWindow.SetProperty(1, 0);
+ m_ParentWindow.SetProperty(2, 0);
+ }
+}
+
+
+
+
+
+void cSlotAreaEnchanting::ShiftClickedResult(cPlayer & a_Player)
+{
+ LOGWARN("Shift Click!");
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cSlotAreaEnderChest:
cSlotAreaEnderChest::cSlotAreaEnderChest(cEnderChestEntity * a_EnderChest, cWindow & a_ParentWindow) :
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index 25b367cff..82360ffbe 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 aae7b99a3..5d89534dd 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -805,6 +805,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, "Enchant")
+{
+ m_SlotAreas.push_back(new cSlotAreaEnchanting(1, *this));
+ m_SlotAreas.push_back(new cSlotAreaInventory(*this));
+ m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cChestWindow:
cChestWindow::cChestWindow(cChestEntity * a_Chest) :
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
{