Cuberite
A lightweight, fast and extensible game server for Minecraft
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
cWindow Class Referenceabstract

Represents a UI window. More...

#include <Window.h>

Inheritance diagram for cWindow:
Inheritance graph
[legend]
Collaboration diagram for cWindow:
Collaboration graph
[legend]

Public Types

enum  WindowType {
  wtInventory = -1, wtChest = 0, wtWorkbench = 1, wtFurnace = 2,
  wtDropSpenser = 3, wtEnchantment = 4, wtBrewery = 5, wtNPCTrade = 6,
  wtBeacon = 7, wtAnvil = 8, wtHopper = 9, wtDropper = 10,
  wtAnimalChest = 11
}
 

Public Member Functions

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 an area. More...
 
void BroadcastWholeWindow (void)
 Sends the contents of the whole window to all clients of this window. More...
 
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. More...
 
virtual bool ClosedByPlayer (cPlayer &a_Player, bool a_CanRefuse)
 Called when a player closes this window; notifies all slot areas. More...
 
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. More...
 
 cWindow (WindowType a_WindowType, const AString &a_WindowTitle)
 
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 distributed! if a_ShouldApply is true, the changes are written into the slots; if a_ShouldApply is false, only a_ItemStack is modified to reflect the number of fits (for fit-testing purposes) More...
 
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 is distributed! If a_ShouldApply is true, the changes are written into the slots; if a_ShouldApply is false, only a_ItemStack is modified to reflect the number of fits (for fit-testing purposes) If a_BackFill is true, the areas will be filled from the back (right side). More...
 
bool ForEachClient (cClientHandleCallback a_Callback)
 Calls the callback safely for each client that has this window open; returns true if all clients have been enumerated. More...
 
bool ForEachPlayer (cPlayerListCallback a_Callback)
 Calls the callback safely for each player that has this window open; returns true if all players have been enumerated. More...
 
int GetNumNonInventorySlots (void) const
 Returns the number of slots, excluding the player's inventory (used for network protocols) More...
 
int GetNumSlots (void) const
 Returns the total number of slots. More...
 
cWindowOwnerGetOwner (void)
 
const cItemGetSlot (cPlayer &a_Player, int a_SlotNum) const
 Returns the item at the specified slot for the specified player. More...
 
void GetSlots (cPlayer &a_Player, cItems &a_Slots) const
 Fills a_Slots with the slots read from m_SlotAreas[], for the specified player. More...
 
char GetWindowID (void) const
 
const AStringGetWindowTitle () const
 
int GetWindowType (void) const
 
const AString GetWindowTypeName (void) const
 Returns the textual representation of the window's type, such as "minecraft:chest". More...
 
bool IsSlotInPlayerHotbar (int a_SlotNum) const
 Returns true if the specified slot is in the Player Hotbar slotarea. More...
 
bool IsSlotInPlayerInventory (int a_SlotNum) const
 Returns true if the specified slot is in the Player Main Inventory or Hotbar slotareas. More...
 
bool IsSlotInPlayerMainInventory (int a_SlotNum) const
 Returns true if the specified slot is in the Player Main Inventory slotarea. More...
 
virtual void OpenedByPlayer (cPlayer &a_Player)
 
void OwnerDestroyed (void)
 
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 to a_SlotArea. More...
 
void SendWholeWindow (cClientHandle &a_Client)
 Sends the contents of the whole window to the specified client. More...
 
void SetOwner (cWindowOwner *a_Owner)
 
virtual void SetProperty (size_t a_Property, short a_Value)
 Updates a numerical property associated with the window. More...
 
void SetSlot (cPlayer &a_Player, int a_SlotNum, const cItem &a_Item)
 Sets the item to the specified slot for the specified player. More...
 
void SetWindowTitle (const AString &a_WindowTitle)
 
virtual ~cWindow ()
 

Static Public Attributes

static const int c_NumInventorySlots = 36
 

Protected Member Functions

virtual void Destroy (void)
 Sets the internal flag as "destroyed"; notifies the owner that the window is destroying. More...
 
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 items distributed. More...
 
cSlotAreaGetSlotArea (int a_GlobalSlotNum, int &a_LocalSlotNum)
 Returns the correct slot area for the specified window-global SlotNum Also returns the area-local SlotNum corresponding to the GlobalSlotNum If the global SlotNum is out of range, returns nullptr. More...
 
const cSlotAreaGetSlotArea (int a_GlobalSlotNum, int &a_LocalSlotNum) const
 Returns the correct slot area for the specified window-global SlotNum Also returns the area-local SlotNum corresponding to the GlobalSlotNum If the global SlotNum is out of range, returns nullptr. More...
 
void OnLeftPaintEnd (cPlayer &a_Player)
 Processes the entire action stored in the internal structures for inventory painting; distributes as many items as possible. More...
 
void OnMiddlePaintEnd (cPlayer &a_Player)
 Processes the entire action stored in the internal structures for inventory painting; distributes a full stack into each slot. More...
 
void OnPaintBegin (cPlayer &a_Player)
 Prepares the internal structures for inventory painting from the specified player. More...
 
void OnPaintProgress (cPlayer &a_Player, int a_SlotNum)
 Adds the slot to the internal structures for inventory painting by the specified player. More...
 
void OnRightPaintEnd (cPlayer &a_Player)
 Processes the entire action stored in the internal structures for inventory painting; distributes one item into each slot. More...
 

Protected Attributes

cCriticalSection m_CS
 
bool m_IsDestroyed
 
cPlayerList m_OpenedBy
 
cWindowOwnerm_Owner
 
cSlotAreas m_SlotAreas
 
char m_WindowID
 
AString m_WindowTitle
 
int m_WindowType
 

Static Protected Attributes

static Byte m_WindowIDCounter = 0
 

Detailed Description

Represents a UI window.

Each window has a list of players that are currently using it When there's no player using a window, it is destroyed. A window consists of several areas of slots with similar functionality - for example the crafting grid area, or the inventory area. Each area knows what its slots are (GetSlot() function) and can handle mouse clicks. The window acts only as a top-level container for those areas, redirecting the click events to the correct areas. Inventory painting, introduced in 1.5, is handled by the window, too

Definition at line 53 of file Window.h.

Member Enumeration Documentation

◆ WindowType

Enumerator
wtInventory 
wtChest 
wtWorkbench 
wtFurnace 
wtDropSpenser 
wtEnchantment 
wtBrewery 
wtNPCTrade 
wtBeacon 
wtAnvil 
wtHopper 
wtDropper 
wtAnimalChest 

Definition at line 56 of file Window.h.

Constructor & Destructor Documentation

◆ cWindow()

cWindow::cWindow ( WindowType  a_WindowType,
const AString a_WindowTitle 
)

Definition at line 30 of file Window.cpp.

◆ ~cWindow()

cWindow::~cWindow ( )
virtual

Definition at line 49 of file Window.cpp.

Member Function Documentation

◆ BroadcastSlot()

void cWindow::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 an area.

Definition at line 350 of file Window.cpp.

◆ BroadcastWholeWindow()

void cWindow::BroadcastWholeWindow ( void  )

Sends the contents of the whole window to all clients of this window.

Definition at line 393 of file Window.cpp.

◆ Clicked()

void cWindow::Clicked ( cPlayer a_Player,
int  a_WindowID,
short  a_SlotNum,
eClickAction  a_ClickAction,
const cItem a_ClickedItem 
)
virtual

Handles a click event from a player.

Reimplemented in cLuaWindow.

Definition at line 197 of file Window.cpp.

◆ ClosedByPlayer()

bool cWindow::ClosedByPlayer ( cPlayer a_Player,
bool  a_CanRefuse 
)
virtual

Called when a player closes this window; notifies all slot areas.

Returns true if close accepted

Reimplemented in cLuaWindow, and cChestWindow.

Definition at line 306 of file Window.cpp.

◆ CollectItemsToHand()

bool cWindow::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.

The items are accumulated in a_Dragging and removed from the SlotAreas immediately. If a_CollectFullStacks is false, slots with full stacks in the area are skipped while collecting. Returns true if full stack has been collected, false if there's space remaining to fill.

Definition at line 490 of file Window.cpp.

◆ Destroy()

void cWindow::Destroy ( void  )
protectedvirtual

Sets the internal flag as "destroyed"; notifies the owner that the window is destroying.

Reimplemented in cLuaWindow.

Definition at line 536 of file Window.cpp.

◆ DistributeItemToSlots()

char cWindow::DistributeItemToSlots ( cPlayer a_Player,
const cItem a_Item,
char  a_NumToEachSlot,
const cSlotNums a_SlotNums,
bool  a_LimitItems = true 
)
protected

Distributes a_NumToEachSlot items into the slots specified in a_SlotNums; returns the total number of items distributed.

Parameters
a_LimitItemsif false, no checks are performed on a_Item.m_ItemCount.

Definition at line 713 of file Window.cpp.

◆ DistributeStack()

virtual void cWindow::DistributeStack ( cItem a_ItemStack,
int  a_Slot,
cPlayer a_Player,
cSlotArea a_ClickedArea,
bool  a_ShouldApply 
)
pure virtual

Called on shift-clicking to distribute the stack into other areas; Modifies a_ItemStack as it is distributed! if a_ShouldApply is true, the changes are written into the slots; if a_ShouldApply is false, only a_ItemStack is modified to reflect the number of fits (for fit-testing purposes)

Implemented in cLuaWindow, cEnchantingWindow, cMinecartWithChestWindow, cAnvilWindow, cChestWindow, cEnderChestWindow, cBeaconWindow, cBrewingstandWindow, cCraftingWindow, cDropSpenserWindow, cHopperWindow, cInventoryWindow, cFurnaceWindow, and cHorseWindow.

◆ DistributeStackToAreas()

void cWindow::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 is distributed! If a_ShouldApply is true, the changes are written into the slots; if a_ShouldApply is false, only a_ItemStack is modified to reflect the number of fits (for fit-testing purposes) If a_BackFill is true, the areas will be filled from the back (right side).

(Example: Empty Hotbar -> Item get in slot 8, not slot 0)

Definition at line 467 of file Window.cpp.

◆ ForEachClient()

bool cWindow::ForEachClient ( cClientHandleCallback  a_Callback)

Calls the callback safely for each client that has this window open; returns true if all clients have been enumerated.

Definition at line 450 of file Window.cpp.

◆ ForEachPlayer()

bool cWindow::ForEachPlayer ( cPlayerListCallback  a_Callback)

Calls the callback safely for each player that has this window open; returns true if all players have been enumerated.

Definition at line 433 of file Window.cpp.

◆ GetNumNonInventorySlots()

int cWindow::GetNumNonInventorySlots ( void  ) const
inline

Returns the number of slots, excluding the player's inventory (used for network protocols)

Definition at line 93 of file Window.h.

◆ GetNumSlots()

int cWindow::GetNumSlots ( void  ) const

Returns the total number of slots.

Definition at line 90 of file Window.cpp.

◆ GetOwner()

cWindowOwner* cWindow::GetOwner ( void  )
inline

Definition at line 86 of file Window.h.

◆ GetSlot()

const cItem * cWindow::GetSlot ( cPlayer a_Player,
int  a_SlotNum 
) const

Returns the item at the specified slot for the specified player.

Returns nullptr if invalid SlotNum requested

Definition at line 104 of file Window.cpp.

◆ GetSlotArea() [1/2]

cSlotArea * cWindow::GetSlotArea ( int  a_GlobalSlotNum,
int &  a_LocalSlotNum 
)
protected

Returns the correct slot area for the specified window-global SlotNum Also returns the area-local SlotNum corresponding to the GlobalSlotNum If the global SlotNum is out of range, returns nullptr.

Definition at line 550 of file Window.cpp.

◆ GetSlotArea() [2/2]

const cSlotArea * cWindow::GetSlotArea ( int  a_GlobalSlotNum,
int &  a_LocalSlotNum 
) const
protected

Returns the correct slot area for the specified window-global SlotNum Also returns the area-local SlotNum corresponding to the GlobalSlotNum If the global SlotNum is out of range, returns nullptr.

Const version.

Definition at line 581 of file Window.cpp.

◆ GetSlots()

void cWindow::GetSlots ( cPlayer a_Player,
cItems a_Slots 
) const

Fills a_Slots with the slots read from m_SlotAreas[], for the specified player.

Definition at line 171 of file Window.cpp.

◆ GetWindowID()

char cWindow::GetWindowID ( void  ) const
inline

Definition at line 80 of file Window.h.

◆ GetWindowTitle()

const AString& cWindow::GetWindowTitle ( ) const
inline

Definition at line 140 of file Window.h.

◆ GetWindowType()

int cWindow::GetWindowType ( void  ) const
inline

Definition at line 81 of file Window.h.

◆ GetWindowTypeName()

const AString cWindow::GetWindowTypeName ( void  ) const

Returns the textual representation of the window's type, such as "minecraft:chest".

Definition at line 62 of file Window.cpp.

◆ IsSlotInPlayerHotbar()

bool cWindow::IsSlotInPlayerHotbar ( int  a_SlotNum) const

Returns true if the specified slot is in the Player Hotbar slotarea.

Definition at line 149 of file Window.cpp.

◆ IsSlotInPlayerInventory()

bool cWindow::IsSlotInPlayerInventory ( int  a_SlotNum) const

Returns true if the specified slot is in the Player Main Inventory or Hotbar slotareas.

Note that returns false for Armor.

Definition at line 160 of file Window.cpp.

◆ IsSlotInPlayerMainInventory()

bool cWindow::IsSlotInPlayerMainInventory ( int  a_SlotNum) const

Returns true if the specified slot is in the Player Main Inventory slotarea.

Definition at line 138 of file Window.cpp.

◆ OnLeftPaintEnd()

void cWindow::OnLeftPaintEnd ( cPlayer a_Player)
protected

Processes the entire action stored in the internal structures for inventory painting; distributes as many items as possible.

Definition at line 632 of file Window.cpp.

◆ OnMiddlePaintEnd()

void cWindow::OnMiddlePaintEnd ( cPlayer a_Player)
protected

Processes the entire action stored in the internal structures for inventory painting; distributes a full stack into each slot.

Definition at line 689 of file Window.cpp.

◆ OnPaintBegin()

void cWindow::OnPaintBegin ( cPlayer a_Player)
protected

Prepares the internal structures for inventory painting from the specified player.

Definition at line 612 of file Window.cpp.

◆ OnPaintProgress()

void cWindow::OnPaintProgress ( cPlayer a_Player,
int  a_SlotNum 
)
protected

Adds the slot to the internal structures for inventory painting by the specified player.

Definition at line 622 of file Window.cpp.

◆ OnRightPaintEnd()

void cWindow::OnRightPaintEnd ( cPlayer a_Player)
protected

Processes the entire action stored in the internal structures for inventory painting; distributes one item into each slot.

Definition at line 661 of file Window.cpp.

◆ OpenedByPlayer()

void cWindow::OpenedByPlayer ( cPlayer a_Player)
virtual

Reimplemented in cLuaWindow, cChestWindow, and cBeaconWindow.

Definition at line 284 of file Window.cpp.

◆ OwnerDestroyed()

void cWindow::OwnerDestroyed ( void  )

Definition at line 419 of file Window.cpp.

◆ SendSlot()

void cWindow::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 to a_SlotArea.

Definition at line 507 of file Window.cpp.

◆ SendWholeWindow()

void cWindow::SendWholeWindow ( cClientHandle a_Client)

Sends the contents of the whole window to the specified client.

Definition at line 384 of file Window.cpp.

◆ SetOwner()

void cWindow::SetOwner ( cWindowOwner a_Owner)
inline

Definition at line 87 of file Window.h.

◆ SetProperty()

void cWindow::SetProperty ( size_t  a_Property,
short  a_Value 
)
virtual

Updates a numerical property associated with the window.

Typically used for furnace progressbars. Sends the UpdateWindowProperty packet to all clients of the window

Reimplemented in cEnchantingWindow.

Definition at line 406 of file Window.cpp.

◆ SetSlot()

void cWindow::SetSlot ( cPlayer a_Player,
int  a_SlotNum,
const cItem a_Item 
)

Sets the item to the specified slot for the specified player.

Definition at line 121 of file Window.cpp.

◆ SetWindowTitle()

void cWindow::SetWindowTitle ( const AString a_WindowTitle)
inline

Definition at line 141 of file Window.h.

Member Data Documentation

◆ c_NumInventorySlots

const int cWindow::c_NumInventorySlots = 36
static

Definition at line 75 of file Window.h.

◆ m_CS

cCriticalSection cWindow::m_CS
protected

Definition at line 185 of file Window.h.

◆ m_IsDestroyed

bool cWindow::m_IsDestroyed
protected

Definition at line 188 of file Window.h.

◆ m_OpenedBy

cPlayerList cWindow::m_OpenedBy
protected

Definition at line 186 of file Window.h.

◆ m_Owner

cWindowOwner* cWindow::m_Owner
protected

Definition at line 190 of file Window.h.

◆ m_SlotAreas

cSlotAreas cWindow::m_SlotAreas
protected

Definition at line 179 of file Window.h.

◆ m_WindowID

char cWindow::m_WindowID
protected

Definition at line 181 of file Window.h.

◆ m_WindowIDCounter

Byte cWindow::m_WindowIDCounter = 0
staticprotected

Definition at line 192 of file Window.h.

◆ m_WindowTitle

AString cWindow::m_WindowTitle
protected

Definition at line 183 of file Window.h.

◆ m_WindowType

int cWindow::m_WindowType
protected

Definition at line 182 of file Window.h.


The documentation for this class was generated from the following files: