Cuberite
A lightweight, fast and extensible game server for Minecraft
InventoryWindow.cpp
Go to the documentation of this file.
1 
2 // InventoryWindow.cpp
3 
4 // Representing the UI window for the player inventory
5 
6 #include "Globals.h"
7 #include "InventoryWindow.h"
8 #include "SlotArea.h"
9 
10 
11 
12 
13 
15  cWindow(wtInventory, "Inventory"),
16  m_Player(a_Player)
17 {
18  m_SlotAreas.push_back(new cSlotAreaCrafting(2, *this)); // The creative inventory doesn't display it, but it's still counted into slot numbers
19  m_SlotAreas.push_back(new cSlotAreaArmor(*this));
20  m_SlotAreas.push_back(new cSlotAreaInventory(*this));
21  m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
22  m_SlotAreas.push_back(new cSlotAreaShield(*this));
23 }
24 
25 
26 
27 
28 
29 void cInventoryWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
30 {
31  cSlotAreas AreasInOrder;
32 
33  if (a_ClickedArea == m_SlotAreas[0])
34  {
35  // Crafting Area
36  if (a_Slot == 0)
37  {
38  // Result Slot
39  AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */
40  AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */
41  }
42  else
43  {
44  AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */
45  AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */
46  }
47  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, (a_Slot == 0));
48  }
49  else if (a_ClickedArea == m_SlotAreas[1])
50  {
51  // Armor Area
52  AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */
53  AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */
54  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
55  }
56  else if (a_ClickedArea == m_SlotAreas[2])
57  {
58  // Inventory Area
59  AreasInOrder.push_back(m_SlotAreas[1]); /* Armor */
60  AreasInOrder.push_back(m_SlotAreas[3]); /* Hotbar */
61  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
62  }
63  else
64  {
65  // Hotbar
66  AreasInOrder.push_back(m_SlotAreas[1]); /* Armor */
67  AreasInOrder.push_back(m_SlotAreas[2]); /* Inventory */
68  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
69  }
70 }
71 
72 
73 
74 
75 
76 void cInventoryWindow::LoadRecipe(cPlayer & a_Player, UInt32 a_RecipeId)
77 {
78  auto slotAreaCrafting = static_cast<cSlotAreaCrafting *>(m_SlotAreas[0]);
79  slotAreaCrafting->LoadRecipe(a_Player, a_RecipeId);
80 }
unsigned int UInt32
Definition: Globals.h:157
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
Definition: Player.h:29
Definition: Item.h:37
cInventoryWindow(cPlayer &a_Player)
void LoadRecipe(cPlayer &a_Player, UInt32 a_RecipeId)
Loads the given Recipe into the crafting grid.
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...
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
Handles the shield of each player.
Definition: SlotArea.h:155
Handles the armor area of the player's inventory.
Definition: SlotArea.h:173
void LoadRecipe(cPlayer &a_Player, UInt32 a_RecipeId)
Loads the given Recipe into the crafting grid.
Definition: SlotArea.cpp:784
Represents a UI window.
Definition: Window.h:54
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