summaryrefslogtreecommitdiffstats
path: root/src/UI
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-09-23 14:39:49 +0200
committerHowaner <franzi.moos@googlemail.com>2014-09-23 14:39:49 +0200
commit4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd (patch)
treecd86062eb50ba870f73b6f29dec0205f87205bf8 /src/UI
parentMerge branch 'master' into EntityCustomName (diff)
parentQtBiomeVisualiser: Fixed confusion about Globals.h. (diff)
downloadcuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar
cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar.gz
cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar.bz2
cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar.lz
cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar.xz
cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar.zst
cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.zip
Diffstat (limited to 'src/UI')
-rw-r--r--src/UI/SlotArea.cpp189
-rw-r--r--src/UI/SlotArea.h7
-rw-r--r--src/UI/Window.cpp61
-rw-r--r--src/UI/Window.h6
4 files changed, 129 insertions, 134 deletions
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp
index 4199bbf56..b4facb2d3 100644
--- a/src/UI/SlotArea.cpp
+++ b/src/UI/SlotArea.cpp
@@ -207,7 +207,7 @@ void cSlotArea::ShiftClicked(cPlayer & a_Player, int a_SlotNum, const cItem & a_
m_ParentWindow.DistributeStack(Slot, a_Player, this, true);
if (Slot.IsEmpty())
{
- // Empty the slot completely, the cilent doesn't like left-over ItemType with zero count
+ // Empty the slot completely, the client doesn't like left-over ItemType with zero count
Slot.Empty();
}
SetSlot(a_SlotNum, a_Player, Slot);
@@ -1389,8 +1389,11 @@ void cSlotAreaBeacon::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
////////////////////////////////////////////////////////////////////////////////
// cSlotAreaEnchanting:
-cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow) :
- cSlotAreaTemporary(1, a_ParentWindow)
+cSlotAreaEnchanting::cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ) :
+ cSlotAreaTemporary(1, a_ParentWindow),
+ m_BlockX(a_BlockX),
+ m_BlockY(a_BlockY),
+ m_BlockZ(a_BlockZ)
{
a_ParentWindow.m_SlotArea = this;
}
@@ -1409,7 +1412,7 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio
LOGWARNING("GetSlot(%d) returned NULL! Ignoring click", a_SlotNum);
return;
}
-
+
switch (a_ClickAction)
{
case caShiftLeftClick:
@@ -1428,6 +1431,25 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio
MiddleClicked(a_Player, a_SlotNum);
return;
}
+ case caDropKey:
+ case caCtrlDropKey:
+ {
+ DropClicked(a_Player, a_SlotNum, false);
+ return;
+ }
+ case caNumber1:
+ case caNumber2:
+ case caNumber3:
+ case caNumber4:
+ case caNumber5:
+ case caNumber6:
+ case caNumber7:
+ case caNumber8:
+ case caNumber9:
+ {
+ NumberClicked(a_Player, a_SlotNum, a_ClickAction);
+ return;
+ }
default:
{
break;
@@ -1443,106 +1465,36 @@ void cSlotAreaEnchanting::Clicked(cPlayer & a_Player, int a_SlotNum, eClickActio
bAsync = true;
}
cItem & DraggingItem = a_Player.GetDraggingItem();
- switch (a_ClickAction)
+
+ if (DraggingItem.IsEmpty())
{
- case caRightClick:
+ // DraggingItem is empty -> Switch draggingitem and slot
+ if (!Slot.IsEmpty())
{
- // 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;
+ std::swap(DraggingItem, Slot);
}
-
- 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:
+ }
+ else if (Slot.IsEmpty())
+ {
+ // DraggingItem isn't empty and slot is empty -> Set one dragging item in the slot
+ Slot = DraggingItem.CopyOne();
+ DraggingItem.m_ItemCount -= 1;
+
+ if (DraggingItem.m_ItemCount <= 0)
{
- LOGWARNING("SlotArea: Unhandled click action: %d (%s)", a_ClickAction, ClickActionToString(a_ClickAction));
- m_ParentWindow.BroadcastWholeWindow();
- return;
+ DraggingItem.Empty();
}
- } // switch (a_ClickAction
-
- SetSlot(a_SlotNum, a_Player, Slot);
- if (bAsync)
- {
- m_ParentWindow.BroadcastWholeWindow();
}
- UpdateResult(a_Player);
-}
-
-
-
-
-
-void cSlotAreaEnchanting::DblClicked(cPlayer & a_Player, int a_SlotNum)
-{
- cItem & Dragging = a_Player.GetDraggingItem();
- if ((!Dragging.IsEmpty()) || (a_SlotNum != 0))
+ else if ((DraggingItem.m_ItemCount == 1) && !DraggingItem.IsEqual(Slot))
{
- return;
+ // DraggingItem and slot aren't empty -> Switch items
+ std::swap(DraggingItem, Slot);
}
-
- cItem Item = *GetSlot(0, a_Player);
- if (!m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, false))
+
+ SetSlot(a_SlotNum, a_Player, Slot);
+ if (bAsync)
{
- m_ParentWindow.CollectItemsToHand(Item, *this, a_Player, true);
+ m_ParentWindow.BroadcastWholeWindow();
}
}
@@ -1567,7 +1519,15 @@ void cSlotAreaEnchanting::DistributeStack(cItem & a_ItemStack, cPlayer & a_Playe
{
a_ItemStack.Empty();
}
+}
+
+
+
+
+void cSlotAreaEnchanting::OnPlayerAdded(cPlayer & a_Player)
+{
+ super::OnPlayerAdded(a_Player);
UpdateResult(a_Player);
}
@@ -1587,29 +1547,33 @@ void cSlotAreaEnchanting::OnPlayerRemoved(cPlayer & a_Player)
+void cSlotAreaEnchanting::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item)
+{
+ super::SetSlot(a_SlotNum, a_Player, a_Item);
+ UpdateResult(a_Player);
+}
+
+
+
+
+
void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
{
cItem Item = *GetSlot(0, a_Player);
- 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)
+ if (cItem::IsEnchantable(Item.m_ItemType) && Item.m_Enchantments.IsEmpty())
{
int Bookshelves = std::min(GetBookshelvesCount(a_Player.GetWorld()), 15);
cFastRandom Random;
- 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);
+ 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);
- m_ParentWindow.SetProperty(0, topSlot, a_Player);
- m_ParentWindow.SetProperty(1, middleSlot, a_Player);
- m_ParentWindow.SetProperty(2, bottomSlot, a_Player);
+ m_ParentWindow.SetProperty(0, TopSlot, a_Player);
+ m_ParentWindow.SetProperty(1, MiddleSlot, a_Player);
+ m_ParentWindow.SetProperty(2, BottomSlot, a_Player);
}
else
{
@@ -1625,12 +1589,9 @@ void cSlotAreaEnchanting::UpdateResult(cPlayer & a_Player)
int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World)
{
- 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);
+ Area.Read(a_World, m_BlockX - 2, m_BlockX + 2, m_BlockY, m_BlockY + 1, m_BlockZ - 2, m_BlockZ + 2);
static const struct
{
@@ -1678,7 +1639,7 @@ int cSlotAreaEnchanting::GetBookshelvesCount(cWorld * a_World)
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
- )
+ )
{
Bookshelves++;
}
diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h
index 9a96f2f3c..6bbc87b76 100644
--- a/src/UI/SlotArea.h
+++ b/src/UI/SlotArea.h
@@ -349,14 +349,15 @@ class cSlotAreaEnchanting :
typedef cSlotAreaTemporary super;
public:
- cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow);
+ cSlotAreaEnchanting(cEnchantingWindow & a_ParentWindow, int a_BlockX, int a_BlockY, int a_BlockZ);
// 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;
+ virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
// cSlotAreaTemporary overrides:
+ virtual void OnPlayerAdded (cPlayer & a_Player) override;
virtual void OnPlayerRemoved(cPlayer & a_Player) override;
/* Get the count of bookshelves who stand in the near of the enchanting table */
@@ -365,6 +366,8 @@ public:
protected:
/** Handles a click in the item slot. */
void UpdateResult(cPlayer & a_Player);
+
+ int m_BlockX, m_BlockY, m_BlockZ;
};
diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp
index 8f4913030..1b7b07f77 100644
--- a/src/UI/Window.cpp
+++ b/src/UI/Window.cpp
@@ -57,6 +57,34 @@ cWindow::~cWindow()
+const AString cWindow::GetWindowTypeName(void) const
+{
+ switch (m_WindowType)
+ {
+ case wtChest: return "minecraft:chest";
+ case wtWorkbench: return "minecraft:crafting_table";
+ case wtFurnace: return "minecraft:furnace";
+ case wtDropSpenser: return "minecraft:dispenser";
+ case wtEnchantment: return "minecraft:enchanting_table";
+ case wtBrewery: return "minecraft:brewing_stand";
+ case wtNPCTrade: return "minecraft:villager";
+ case wtBeacon: return "minecraft:beacon";
+ case wtAnvil: return "minecraft:anvil";
+ case wtHopper: return "minecraft:hopper";
+ case wtDropper: return "minecraft:dropper";
+ case wtAnimalChest: return "EntityHorse";
+ default:
+ {
+ ASSERT(!"Unknown inventory type!");
+ return "";
+ }
+ }
+}
+
+
+
+
+
int cWindow::GetNumSlots(void) const
{
int res = 0;
@@ -881,7 +909,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(*this));
+ m_SlotAreas.push_back(new cSlotAreaEnchanting(*this, m_BlockX, m_BlockY, m_BlockZ));
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
}
@@ -892,8 +920,13 @@ cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
void cEnchantingWindow::SetProperty(int a_Property, int a_Value)
{
- m_PropertyValue[a_Property] = a_Value;
+ if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
+ {
+ ASSERT(!"a_Property is invalid");
+ return;
+ }
+ m_PropertyValue[a_Property] = a_Value;
super::SetProperty(a_Property, a_Value);
}
@@ -903,8 +936,13 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value)
void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player)
{
- m_PropertyValue[a_Property] = a_Value;
+ if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
+ {
+ ASSERT(!"a_Property is invalid");
+ return;
+ }
+ m_PropertyValue[a_Property] = a_Value;
super::SetProperty(a_Property, a_Value, a_Player);
}
@@ -914,18 +952,13 @@ void cEnchantingWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Pla
int cEnchantingWindow::GetPropertyValue(int a_Property)
{
- return m_PropertyValue[a_Property];
-}
-
-
-
-
+ if ((a_Property < 0) || ((size_t)a_Property >= ARRAYCOUNT(m_PropertyValue)))
+ {
+ ASSERT(!"a_Property is invalid");
+ return 0;
+ }
-void cEnchantingWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ)
-{
- a_PosX = m_BlockX;
- a_PosY = m_BlockY;
- a_PosZ = m_BlockZ;
+ return m_PropertyValue[a_Property];
}
diff --git a/src/UI/Window.h b/src/UI/Window.h
index 9fb0e3b38..bc5becf11 100644
--- a/src/UI/Window.h
+++ b/src/UI/Window.h
@@ -63,7 +63,7 @@ public:
wtBeacon = 7,
wtAnvil = 8,
wtHopper = 9,
- // Unknown: 10
+ wtDropper = 10,
wtAnimalChest = 11,
};
@@ -76,6 +76,7 @@ public:
char GetWindowID(void) const { return m_WindowID; } // tolua_export
int GetWindowType(void) const { return m_WindowType; } // tolua_export
+ const AString GetWindowTypeName(void) const; // tolua_export
cWindowOwner * GetOwner(void) { return m_Owner; }
void SetOwner( cWindowOwner * a_Owner) { m_Owner = a_Owner; }
@@ -291,9 +292,6 @@ public:
/** Return the Value of a Property */
int GetPropertyValue(int a_Property);
- /** Get the Position from the Enchantment Table */
- void GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ);
-
cSlotArea * m_SlotArea;
protected: