Cuberite
A lightweight, fast and extensible game server for Minecraft
AnvilWindow.cpp
Go to the documentation of this file.
1 
2 // AnvilWindow.cpp
3 
4 // Representing the UI window for the anvil block
5 
6 #include "Globals.h"
7 #include "AnvilWindow.h"
8 #include "SlotArea.h"
9 
10 
11 
12 
13 cAnvilWindow::cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
14  cWindow(wtAnvil, "Repair"),
15  m_RepairedItemName(""),
16  m_BlockX(a_BlockX),
17  m_BlockY(a_BlockY),
18  m_BlockZ(a_BlockZ)
19 {
20  m_AnvilSlotArea = new cSlotAreaAnvil(*this);
21  m_SlotAreas.push_back(m_AnvilSlotArea);
22  m_SlotAreas.push_back(new cSlotAreaInventory(*this));
23  m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
24 }
25 
26 
27 
28 
29 
31 {
32  return m_RepairedItemName;
33 }
34 
35 
36 
37 
38 
39 void cAnvilWindow::SetRepairedItemName(const AString & a_Name, cPlayer * a_Player)
40 {
41  m_RepairedItemName = a_Name;
42  if (a_Player != nullptr)
43  {
44  m_AnvilSlotArea->UpdateResult(*a_Player);
45  }
46 }
47 
48 
49 
50 
51 
52 void cAnvilWindow::GetBlockPos(int & a_PosX, int & a_PosY, int & a_PosZ)
53 {
54  a_PosX = m_BlockX;
55  a_PosY = m_BlockY;
56  a_PosZ = m_BlockZ;
57 }
58 
59 
60 
61 
62 
63 void cAnvilWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
64 {
65  cSlotAreas AreasInOrder;
66 
67  if (a_ClickedArea == m_SlotAreas[0])
68  {
69  // Anvil Slot
70  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
71  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
72  }
73  else
74  {
75  // Inventory or Hotbar
76  AreasInOrder.push_back(m_SlotAreas[0]); /* Anvil */
77  }
78  super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
79 }
80 
81 
82 
83 
Handles the main inventory of each player, excluding the armor and hotbar.
Definition: SlotArea.h:117
Definition: Player.h:27
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
cAnvilWindow(int a_BlockX, int a_BlockY, int a_BlockZ)
Definition: AnvilWindow.cpp:13
cSlotAreaAnvil * m_AnvilSlotArea
Definition: AnvilWindow.h:38
void SetRepairedItemName(const AString &a_Name, cPlayer *a_Player)
Set the repaired item name.
Definition: AnvilWindow.cpp:39
void GetBlockPos(int &a_PosX, int &a_PosY, int &a_PosZ)
Gets the Position from the Anvil.
Definition: AnvilWindow.cpp:52
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
AString m_RepairedItemName
Definition: AnvilWindow.h:39
void UpdateResult(cPlayer &a_Player)
Handles a click in the item slot.
Definition: SlotArea.cpp:1062
std::string AString
Definition: StringUtils.h:13
AString GetRepairedItemName(void) const
Gets the repaired item name.
Definition: AnvilWindow.cpp:30
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...
Definition: AnvilWindow.cpp:63
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
Definition: Item.h:36