Cuberite
A lightweight, fast and extensible game server for Minecraft
EnchantingWindow.cpp
Go to the documentation of this file.
1 
2 // EnchantingWindow.cpp
3 
4 // Representing the UI window for the enchanting block
5 
6 #include "Globals.h"
7 #include "EnchantingWindow.h"
8 #include "SlotArea.h"
9 
10 
11 
12 
13 
14 cEnchantingWindow::cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
15  cWindow(wtEnchantment, "Enchant"),
16  m_SlotArea(),
17  m_BlockX(a_BlockX),
18  m_BlockY(a_BlockY),
19  m_BlockZ(a_BlockZ)
20 {
22  m_SlotAreas.push_back(m_SlotArea);
23  m_SlotAreas.push_back(new cSlotAreaInventory(*this));
24  m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
25 }
26 
27 
28 
29 
30 
31 void cEnchantingWindow::SetProperty(short a_Property, short a_Value, cPlayer & a_Player)
32 {
33  if ((a_Property < 0) || (static_cast<size_t>(a_Property) >= ARRAYCOUNT(m_PropertyValue)))
34  {
35  ASSERT(!"a_Property is invalid");
36  return;
37  }
38 
39  m_PropertyValue[a_Property] = a_Value;
40  super::SetProperty(a_Property, a_Value, a_Player);
41 }
42 
43 
44 
45 
46 
47 void cEnchantingWindow::SetProperty(short a_Property, short a_Value)
48 {
49  if ((a_Property < 0) || (static_cast<size_t>(a_Property) >= ARRAYCOUNT(m_PropertyValue)))
50  {
51  ASSERT(!"a_Property is invalid");
52  return;
53  }
54 
55  m_PropertyValue[a_Property] = a_Value;
56  super::SetProperty(a_Property, a_Value);
57 }
58 
59 
60 
61 
62 
63 short cEnchantingWindow::GetPropertyValue(short a_Property)
64 {
65  if ((a_Property < 0) || (static_cast<size_t>(a_Property) >= ARRAYCOUNT(m_PropertyValue)))
66  {
67  ASSERT(!"a_Property is invalid");
68  return 0;
69  }
70 
71  return m_PropertyValue[a_Property];
72 }
73 
74 
75 
76 
77 
78 void cEnchantingWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
79 {
80  cSlotAreas AreasInOrder;
81 
82  if (a_ClickedArea == m_SlotAreas[0])
83  {
84  // Enchanting Area
85  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
86  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
87  super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true);
88  }
89  else
90  {
91  // Inventory or Hotbar
92  AreasInOrder.push_back(m_SlotAreas[0]); /* Enchanting */
93  super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
94  }
95 }
96 
97 
98 
99 
Handles the main inventory of each player, excluding the armor and hotbar.
Definition: SlotArea.h:117
Definition: Player.h:27
virtual void DistributeStack(cItem &a_ItemStack, int a_Slot, cPlayer &a_Player, cSlotArea *a_ClickedArea, bool a_ShouldApply) override
Called on shift-clicking to distribute the stack into other areas; Modifies a_ItemStack as it is dist...
void DistributeStackToAreas(cItem &a_ItemStack, cPlayer &a_Player, cSlotAreas &a_AreasInOrder, bool a_ShouldApply, bool a_BackFill)
Called from DistributeStack() to distribute the stack into a_AreasInOrder; Modifies a_ItemStack as it...
Definition: Window.cpp:401
cEnchantingWindow(int a_BlockX, int a_BlockY, int a_BlockZ)
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
virtual void SetProperty(short a_Property, short a_Value, cPlayer &a_Player) override
Updates a numerical property associated with the window.
#define ASSERT(x)
Definition: Globals.h:335
short GetPropertyValue(short a_Property)
Return the value of a property.
virtual void SetProperty(short a_Property, short a_Value)
Updates a numerical property associated with the window.
Definition: Window.cpp:751
Represents a UI window.
Definition: Window.h:53
cSlotAreas m_SlotAreas
Definition: Window.h:182
Handles the hotbar of each player.
Definition: SlotArea.h:134
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
Definition: Globals.h:290
Definition: Item.h:36
cSlotArea * m_SlotArea