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 
14  cWindow(wtAnvil, "Repair"),
15  m_RepairedItemName(),
16  m_BlockPos(a_BlockPos)
17 {
18  m_AnvilSlotArea = new cSlotAreaAnvil(*this);
19  m_SlotAreas.push_back(m_AnvilSlotArea);
20  m_SlotAreas.push_back(new cSlotAreaInventory(*this));
21  m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
22 }
23 
24 
25 
26 
27 
29 {
30  return m_RepairedItemName;
31 }
32 
33 
34 
35 
36 
37 void cAnvilWindow::SetRepairedItemName(const AString & a_Name, cPlayer * a_Player)
38 {
39  m_RepairedItemName = a_Name;
40  if (a_Player != nullptr)
41  {
42  m_AnvilSlotArea->UpdateResult(*a_Player);
43  }
44 }
45 
46 
47 
48 
49 
50 void cAnvilWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
51 {
52  cSlotAreas AreasInOrder;
53 
54  if (a_ClickedArea == m_SlotAreas[0])
55  {
56  // Anvil Slot
57  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
58  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
59  }
60  else
61  {
62  // Inventory or Hotbar
63  AreasInOrder.push_back(m_SlotAreas[0]); /* Anvil */
64  }
65  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
66 }
67 
68 
69 
70 
std::string AString
Definition: StringUtils.h:11
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
Definition: Player.h:29
Definition: Item.h:37
AString m_RepairedItemName
Definition: AnvilWindow.h:40
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:50
void SetRepairedItemName(const AString &a_Name, cPlayer *a_Player)
Set the repaired item name.
Definition: AnvilWindow.cpp:37
AString GetRepairedItemName(void) const
Gets the repaired item name.
Definition: AnvilWindow.cpp:28
cAnvilWindow(Vector3i a_BlockPos)
Definition: AnvilWindow.cpp:13
cSlotAreaAnvil * m_AnvilSlotArea
Definition: AnvilWindow.h:39
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
void UpdateResult(cPlayer &a_Player)
Handles a click in the item slot.
Definition: SlotArea.cpp:1125
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