Cuberite
A lightweight, fast and extensible game server for Minecraft
Window.h
Go to the documentation of this file.
1 
2 // Window.h
3 
4 // Interfaces to the cWindow class representing a UI window for a specific block
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "../FunctionRef.h"
13 #include "../ItemGrid.h"
14 
15 
16 
17 
18 
19 class cPlayer;
20 class cWindowOwner;
21 class cClientHandle;
23 class cChestEntity;
24 class cEnderChestEntity;
25 class cFurnaceEntity;
26 class cHopperEntity;
27 class cMinecartWithChest;
28 class cBeaconEntity;
29 class cSlotArea;
30 class cSlotAreaAnvil;
31 class cWorld;
32 
33 typedef std::list<cPlayer *> cPlayerList;
34 typedef std::vector<cSlotArea *> cSlotAreas;
37 
38 
39 
40 
41 // tolua_begin
42 
53 class cWindow
54 {
55 public:
57  {
58  wtInventory = -1, // This value is never actually sent to a client
59  wtChest = 0,
61  wtFurnace = 2,
62  wtDropSpenser = 3, // Dropper or Dispenser
64  wtBrewery = 5,
66  wtBeacon = 7,
67  wtAnvil = 8,
68  wtHopper = 9,
69  wtDropper = 10,
71  };
72 
73  // tolua_end
74 
75  static const int c_NumInventorySlots = 36;
76 
77  cWindow(WindowType a_WindowType, const AString & a_WindowTitle);
78  virtual ~cWindow();
79 
80  char GetWindowID(void) const { return m_WindowID; } // tolua_export
81  int GetWindowType(void) const { return m_WindowType; } // tolua_export
82 
84  const AString GetWindowTypeName(void) const; // tolua_export
85 
86  cWindowOwner * GetOwner(void) { return m_Owner; }
87  void SetOwner( cWindowOwner * a_Owner) { m_Owner = a_Owner; }
88 
90  int GetNumSlots(void) const;
91 
94 
95  // tolua_begin
96 
98  const cItem * GetSlot(cPlayer & a_Player, int a_SlotNum) const;
99 
101  void SetSlot(cPlayer & a_Player, int a_SlotNum, const cItem & a_Item);
102 
104  bool IsSlotInPlayerMainInventory(int a_SlotNum) const;
105 
107  bool IsSlotInPlayerHotbar(int a_SlotNum) const;
108 
110  bool IsSlotInPlayerInventory(int a_SlotNum) const;
111 
112  // tolua_end
113 
115  void GetSlots(cPlayer & a_Player, cItems & a_Slots) const;
116 
118  virtual void Clicked(
119  cPlayer & a_Player, int a_WindowID,
120  short a_SlotNum, eClickAction a_ClickAction,
121  const cItem & a_ClickedItem
122  );
123 
124  virtual void OpenedByPlayer(cPlayer & a_Player);
125 
127  virtual bool ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse);
128 
130  void BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum);
131 
133  void SendWholeWindow(cClientHandle & a_Client);
134 
136  void BroadcastWholeWindow(void);
137 
138  // tolua_begin
139 
140  const AString & GetWindowTitle() const { return m_WindowTitle; }
141  void SetWindowTitle(const AString & a_WindowTitle) { m_WindowTitle = a_WindowTitle; }
142 
145  virtual void SetProperty(size_t a_Property, short a_Value);
146 
147  // tolua_end
148 
149  void OwnerDestroyed(void);
150 
152  bool ForEachPlayer(cPlayerListCallback a_Callback);
153 
155  bool ForEachClient(cClientHandleCallback a_Callback);
156 
160  virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) = 0;
161 
166  void DistributeStackToAreas(cItem & a_ItemStack, cPlayer & a_Player, cSlotAreas & a_AreasInOrder, bool a_ShouldApply, bool a_BackFill);
167 
172  bool CollectItemsToHand(cItem & a_Dragging, cSlotArea & a_Area, cPlayer & a_Player, bool a_CollectFullStacks);
173 
175  void SendSlot(cPlayer & a_Player, cSlotArea * a_SlotArea, int a_RelativeSlotNum);
176 
177 protected:
178 
180 
184 
187 
189 
191 
193 
195  virtual void Destroy(void);
196 
200  cSlotArea * GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum);
201 
206  const cSlotArea * GetSlotArea(int a_GlobalSlotNum, int & a_LocalSlotNum) const;
207 
209  void OnPaintBegin(cPlayer & a_Player);
210 
212  void OnPaintProgress(cPlayer & a_Player, int a_SlotNum);
213 
215  void OnLeftPaintEnd(cPlayer & a_Player);
216 
218  void OnRightPaintEnd(cPlayer & a_Player);
219 
221  void OnMiddlePaintEnd(cPlayer & a_Player);
222 
225  char DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, char a_NumToEachSlot, const cSlotNums & a_SlotNums, bool a_LimitItems = true);
226 } ; // tolua_export
cWindowOwner
Base class for the window owning.
Definition: WindowOwner.h:17
cWindow::wtWorkbench
@ wtWorkbench
Definition: Window.h:60
cWindow::OnPaintProgress
void OnPaintProgress(cPlayer &a_Player, int a_SlotNum)
Adds the slot to the internal structures for inventory painting by the specified player.
Definition: Window.cpp:622
cClientHandle
Definition: ClientHandle.h:49
cWindow::DistributeStackToAreas
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
eClickAction
eClickAction
Individual actions sent in the WindowClick packet.
Definition: Defines.h:81
cWindow::SetWindowTitle
void SetWindowTitle(const AString &a_WindowTitle)
Definition: Window.h:141
cWindow::SendWholeWindow
void SendWholeWindow(cClientHandle &a_Client)
Sends the contents of the whole window to the specified client.
Definition: Window.cpp:384
cWindow::GetWindowTitle
const AString & GetWindowTitle() const
Definition: Window.h:140
cWindow::OwnerDestroyed
void OwnerDestroyed(void)
Definition: Window.cpp:419
cWindow::CollectItemsToHand
bool CollectItemsToHand(cItem &a_Dragging, cSlotArea &a_Area, cPlayer &a_Player, bool a_CollectFullStacks)
Called on DblClicking to collect all stackable items from all areas into hand.
Definition: Window.cpp:490
cWindow::GetWindowType
int GetWindowType(void) const
Definition: Window.h:81
cBeaconEntity
Definition: BeaconEntity.h:19
cWindow::wtBrewery
@ wtBrewery
Definition: Window.h:64
cWindow::BroadcastWholeWindow
void BroadcastWholeWindow(void)
Sends the contents of the whole window to all clients of this window.
Definition: Window.cpp:393
cWindow::GetWindowID
char GetWindowID(void) const
Definition: Window.h:80
cWindow
Represents a UI window.
Definition: Window.h:53
cWindow::GetOwner
cWindowOwner * GetOwner(void)
Definition: Window.h:86
cWindow::m_WindowIDCounter
static Byte m_WindowIDCounter
Definition: Window.h:192
cWindow::ForEachClient
bool ForEachClient(cClientHandleCallback a_Callback)
Calls the callback safely for each client that has this window open; returns true if all clients have...
Definition: Window.cpp:450
cWindow::OnLeftPaintEnd
void OnLeftPaintEnd(cPlayer &a_Player)
Processes the entire action stored in the internal structures for inventory painting; distributes as ...
Definition: Window.cpp:632
cWindow::m_Owner
cWindowOwner * m_Owner
Definition: Window.h:190
cWindow::Destroy
virtual void Destroy(void)
Sets the internal flag as "destroyed"; notifies the owner that the window is destroying.
Definition: Window.cpp:536
cWindow::GetSlot
const cItem * GetSlot(cPlayer &a_Player, int a_SlotNum) const
Returns the item at the specified slot for the specified player.
Definition: Window.cpp:104
cWindow::OnMiddlePaintEnd
void OnMiddlePaintEnd(cPlayer &a_Player)
Processes the entire action stored in the internal structures for inventory painting; distributes a f...
Definition: Window.cpp:689
cWindow::wtFurnace
@ wtFurnace
Definition: Window.h:61
cHopperEntity
Definition: HopperEntity.h:19
cSlotNums
std::vector< int > cSlotNums
List of slot numbers, used for inventory-painting.
Definition: Defines.h:9
cWindow::wtDropSpenser
@ wtDropSpenser
Definition: Window.h:62
cWindow::c_NumInventorySlots
static const int c_NumInventorySlots
Definition: Window.h:75
cWindow::~cWindow
virtual ~cWindow()
Definition: Window.cpp:49
cWindow::Clicked
virtual void Clicked(cPlayer &a_Player, int a_WindowID, short a_SlotNum, eClickAction a_ClickAction, const cItem &a_ClickedItem)
Handles a click event from a player.
Definition: Window.cpp:197
cWindow::m_CS
cCriticalSection m_CS
Definition: Window.h:185
cWindow::wtEnchantment
@ wtEnchantment
Definition: Window.h:63
cWindow::wtAnvil
@ wtAnvil
Definition: Window.h:67
cWindow::wtChest
@ wtChest
Definition: Window.h:59
cWorld
Definition: World.h:47
cWindow::SetSlot
void SetSlot(cPlayer &a_Player, int a_SlotNum, const cItem &a_Item)
Sets the item to the specified slot for the specified player.
Definition: Window.cpp:121
cWindow::BroadcastSlot
void BroadcastSlot(cSlotArea *a_Area, int a_LocalSlotNum)
Sends the specified slot's contents to all clients of this window; the slot is specified as local in ...
Definition: Window.cpp:350
cWindow::OpenedByPlayer
virtual void OpenedByPlayer(cPlayer &a_Player)
Definition: Window.cpp:284
cWindow::WindowType
WindowType
Definition: Window.h:56
cFurnaceEntity
Definition: FurnaceEntity.h:18
cWindow::GetSlotArea
cSlotArea * GetSlotArea(int a_GlobalSlotNum, int &a_LocalSlotNum)
Returns the correct slot area for the specified window-global SlotNum Also returns the area-local Slo...
Definition: Window.cpp:550
cWindow::m_SlotAreas
cSlotAreas m_SlotAreas
Definition: Window.h:179
cWindow::m_WindowID
char m_WindowID
Definition: Window.h:181
cWindow::OnPaintBegin
void OnPaintBegin(cPlayer &a_Player)
Prepares the internal structures for inventory painting from the specified player.
Definition: Window.cpp:612
cItem
Definition: Item.h:36
cWindow::IsSlotInPlayerInventory
bool IsSlotInPlayerInventory(int a_SlotNum) const
Returns true if the specified slot is in the Player Main Inventory or Hotbar slotareas.
Definition: Window.cpp:160
cWindow::SetProperty
virtual void SetProperty(size_t a_Property, short a_Value)
Updates a numerical property associated with the window.
Definition: Window.cpp:406
cWindow::GetSlots
void GetSlots(cPlayer &a_Player, cItems &a_Slots) const
Fills a_Slots with the slots read from m_SlotAreas[], for the specified player.
Definition: Window.cpp:171
cWindow::wtAnimalChest
@ wtAnimalChest
Definition: Window.h:70
cSlotAreaAnvil
Definition: SlotArea.h:315
cWindow::OnRightPaintEnd
void OnRightPaintEnd(cPlayer &a_Player)
Processes the entire action stored in the internal structures for inventory painting; distributes one...
Definition: Window.cpp:661
cWindow::wtNPCTrade
@ wtNPCTrade
Definition: Window.h:65
cWindow::m_IsDestroyed
bool m_IsDestroyed
Definition: Window.h:188
cPlayerList
std::list< cPlayer * > cPlayerList
Definition: Window.h:31
cItems
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:213
Byte
unsigned char Byte
Definition: Globals.h:158
cWindow::SetOwner
void SetOwner(cWindowOwner *a_Owner)
Definition: Window.h:87
cWindow::wtInventory
@ wtInventory
Definition: Window.h:58
cWindow::IsSlotInPlayerMainInventory
bool IsSlotInPlayerMainInventory(int a_SlotNum) const
Returns true if the specified slot is in the Player Main Inventory slotarea.
Definition: Window.cpp:138
cWindow::m_WindowType
int m_WindowType
Definition: Window.h:182
cWindow::GetNumSlots
int GetNumSlots(void) const
Returns the total number of slots.
Definition: Window.cpp:90
cWindow::GetNumNonInventorySlots
int GetNumNonInventorySlots(void) const
Returns the number of slots, excluding the player's inventory (used for network protocols)
Definition: Window.h:93
cWindow::DistributeItemToSlots
char DistributeItemToSlots(cPlayer &a_Player, const cItem &a_Item, char a_NumToEachSlot, const cSlotNums &a_SlotNums, bool a_LimitItems=true)
Distributes a_NumToEachSlot items into the slots specified in a_SlotNums; returns the total number of...
Definition: Window.cpp:713
cChestEntity
Definition: ChestEntity.h:18
cCriticalSection
Definition: CriticalSection.h:8
cPlayer
Definition: Player.h:27
cWindow::m_OpenedBy
cPlayerList m_OpenedBy
Definition: Window.h:186
cWindow::wtBeacon
@ wtBeacon
Definition: Window.h:66
cWindow::DistributeStack
virtual void DistributeStack(cItem &a_ItemStack, int a_Slot, cPlayer &a_Player, cSlotArea *a_ClickedArea, bool a_ShouldApply)=0
Called on shift-clicking to distribute the stack into other areas; Modifies a_ItemStack as it is dist...
cWindow::IsSlotInPlayerHotbar
bool IsSlotInPlayerHotbar(int a_SlotNum) const
Returns true if the specified slot is in the Player Hotbar slotarea.
Definition: Window.cpp:149
cWindow::SendSlot
void SendSlot(cPlayer &a_Player, cSlotArea *a_SlotArea, int a_RelativeSlotNum)
Used by cSlotAreas to send individual slots to clients, a_RelativeSlotNum is the slot number relative...
Definition: Window.cpp:507
cWindow::wtDropper
@ wtDropper
Definition: Window.h:69
cSlotAreas
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
cWindow::wtHopper
@ wtHopper
Definition: Window.h:68
cBrewingstandEntity
Definition: BrewingstandEntity.h:19
cFunctionRef
Definition: FunctionRef.h:6
cSlotArea
Definition: SlotArea.h:33
cWindow::cWindow
cWindow(WindowType a_WindowType, const AString &a_WindowTitle)
Definition: Window.cpp:30
cEnderChestEntity
Definition: EnderChestEntity.h:12
AString
std::string AString
Definition: StringUtils.h:11
cMinecartWithChest
Definition: Minecart.h:127
cWindow::GetWindowTypeName
const AString GetWindowTypeName(void) const
Returns the textual representation of the window's type, such as "minecraft:chest".
Definition: Window.cpp:62
cWindow::ClosedByPlayer
virtual bool ClosedByPlayer(cPlayer &a_Player, bool a_CanRefuse)
Called when a player closes this window; notifies all slot areas.
Definition: Window.cpp:306
cWindow::ForEachPlayer
bool ForEachPlayer(cPlayerListCallback a_Callback)
Calls the callback safely for each player that has this window open; returns true if all players have...
Definition: Window.cpp:433
cWindow::m_WindowTitle
AString m_WindowTitle
Definition: Window.h:183