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 
15  cWindow(wtEnchantment, a_Title),
16  m_SlotArea(),
17  m_BlockPos(a_BlockPos)
18 {
20  m_SlotAreas.push_back(m_SlotArea);
21  m_SlotAreas.push_back(new cSlotAreaInventory(*this));
22  m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
23 }
24 
25 
26 
27 
28 
29 void cEnchantingWindow::SetProperty(size_t a_Property, short a_Value)
30 {
31  if (a_Property < m_PropertyValue.size())
32  {
33  m_PropertyValue[a_Property] = a_Value;
34  }
35 
36  Super::SetProperty(a_Property, a_Value);
37 }
38 
39 
40 
41 
42 
43 short cEnchantingWindow::GetProperty(size_t a_Property)
44 {
45  ASSERT(a_Property < m_PropertyValue.size());
46  return m_PropertyValue[a_Property];
47 }
48 
49 
50 
51 
52 
53 void cEnchantingWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
54 {
55  cSlotAreas AreasInOrder;
56 
57  if (a_ClickedArea == m_SlotAreas[0])
58  {
59  // Enchanting Area
60  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
61  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
62  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true);
63  }
64  else
65  {
66  // Inventory or Hotbar
67  AreasInOrder.push_back(m_SlotAreas[0]); /* Enchanting */
68  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
69  }
70 }
71 
72 
73 
74 
#define ASSERT(x)
Definition: Globals.h:276
std::string AString
Definition: StringUtils.h:11
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
Definition: Player.h:29
Definition: Item.h:37
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...
virtual void SetProperty(size_t a_Property, short a_Value) override
Sends enchantment properties to the client.
std::array< short, 3 > m_PropertyValue
cEnchantingWindow(Vector3i a_BlockPos, const AString &a_Title)
short GetProperty(size_t a_Property)
Return the level requirement of the given enchantment slot.
cSlotAreaEnchanting * m_SlotArea
Handles the main inventory of each player, excluding the armor and hotbar.
Definition: SlotArea.h:120
Handles the hotbar of each player.
Definition: SlotArea.h:138
Represents a UI window.
Definition: Window.h:54
virtual void SetProperty(size_t a_Property, short a_Value)
Updates a numerical property associated with the window.
Definition: Window.cpp:406
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:467
cSlotAreas m_SlotAreas
Definition: Window.h:179