Cuberite
A lightweight, fast and extensible game server for Minecraft
|
A window that has been created by a Lua plugin and is handled entirely by that plugin This object needs extra care with its lifetime management: More...
#include <LuaWindow.h>
Public Member Functions | |
cLuaWindow (cLuaState &a_LuaState, cWindow::WindowType a_WindowType, int a_SlotsX, int a_SlotsY, const AString &a_Title) | |
Create a window of the specified type, with a slot grid of a_SlotsX * a_SlotsY size. More... | |
cItemGrid & | GetContents (void) |
Returns the internal representation of the contents that are manipulated by Lua. More... | |
void | SetOnClicked (cLuaState::cCallbackPtr &&a_OnClicked) |
Sets the Lua callback to call when the player clicks on the window. More... | |
void | SetOnClosing (cLuaState::cCallbackPtr &&a_OnClosing) |
Sets the Lua callback function to call when the window is about to close. More... | |
void | SetOnSlotChanged (cLuaState::cCallbackPtr &&a_OnSlotChanged) |
Sets the Lua callback function to call when a slot is changed. More... | |
virtual | ~cLuaWindow () override |
Public Member Functions inherited from cWindow | |
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... | |
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) | |
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... | |
cWindowOwner * | GetOwner (void) |
const cItem * | GetSlot (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 AString & | GetWindowTitle () 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... | |
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 () |
Public Member Functions inherited from cItemGrid::cListener | |
virtual | ~cListener () |
Protected Member Functions | |
virtual void | Clicked (cPlayer &a_Player, int a_WindowID, short a_SlotNum, eClickAction a_ClickAction, const cItem &a_ClickedItem) override |
Handles a click event from a player. More... | |
virtual bool | ClosedByPlayer (cPlayer &a_Player, bool a_CanRefuse) override |
Called when a player closes this window; notifies all slot areas. More... | |
virtual void | Destroy (void) override |
Sets the internal flag as "destroyed"; notifies the owner that the window is destroying. More... | |
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 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... | |
virtual void | OnSlotChanged (cItemGrid *a_ItemGrid, int a_SlotNum) override |
Called whenever a slot changes. More... | |
virtual void | OpenedByPlayer (cPlayer &a_Player) override |
Protected Member Functions inherited from cWindow | |
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... | |
cSlotArea * | GetSlotArea (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 cSlotArea * | GetSlotArea (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 | |
cItemGrid | m_Contents |
Contents of the non-inventory part. More... | |
cLuaState::cRef | m_LuaRef |
Reference to self, to keep Lua from GCing the object while a player is still using it. More... | |
cLuaState * | m_LuaState |
The canon Lua state that has opened the window and owns the m_LuaRef. More... | |
cLuaState::cCallbackPtr | m_OnClicked |
The Lua callback to call when the player clicked on a slot. More... | |
cLuaState::cCallbackPtr | m_OnClosing |
The Lua callback to call when the window is closing for any player. More... | |
cLuaState::cCallbackPtr | m_OnSlotChanged |
The Lua callback to call when a slot has changed. More... | |
std::atomic< int > | m_PlayerCount |
Number of players that are currently using the window. More... | |
Protected Attributes inherited from cWindow | |
cCriticalSection | m_CS |
bool | m_IsDestroyed |
cPlayerList | m_OpenedBy |
cWindowOwner * | m_Owner |
cSlotAreas | m_SlotAreas |
char | m_WindowID |
AString | m_WindowTitle |
int | m_WindowType |
Private Types | |
using | Super = cWindow |
Additional Inherited Members | |
Public Types inherited from cWindow | |
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 } |
Static Public Attributes inherited from cWindow | |
static const int | c_NumInventorySlots = 36 |
Static Protected Attributes inherited from cWindow | |
static Byte | m_WindowIDCounter = 0 |
A window that has been created by a Lua plugin and is handled entirely by that plugin This object needs extra care with its lifetime management:
Definition at line 32 of file LuaWindow.h.
|
private |
Definition at line 37 of file LuaWindow.h.
cLuaWindow::cLuaWindow | ( | cLuaState & | a_LuaState, |
cWindow::WindowType | a_WindowType, | ||
int | a_SlotsX, | ||
int | a_SlotsY, | ||
const AString & | a_Title | ||
) |
Create a window of the specified type, with a slot grid of a_SlotsX * a_SlotsY size.
Exported in ManualBindings.cpp
Definition at line 23 of file LuaWindow.cpp.
|
overridevirtual |
Definition at line 55 of file LuaWindow.cpp.
|
overrideprotectedvirtual |
Handles a click event from a player.
Reimplemented from cWindow.
Definition at line 215 of file LuaWindow.cpp.
|
overrideprotectedvirtual |
Called when a player closes this window; notifies all slot areas.
Returns true if close accepted
Reimplemented from cWindow.
Definition at line 140 of file LuaWindow.cpp.
|
overrideprotectedvirtual |
Sets the internal flag as "destroyed"; notifies the owner that the window is destroying.
Reimplemented from cWindow.
Definition at line 170 of file LuaWindow.cpp.
|
overrideprotectedvirtual |
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)
Implements cWindow.
Definition at line 182 of file LuaWindow.cpp.
|
inline |
Returns the internal representation of the contents that are manipulated by Lua.
Definition at line 48 of file LuaWindow.h.
|
overrideprotectedvirtual |
Called whenever a slot changes.
Implements cItemGrid::cListener.
Definition at line 200 of file LuaWindow.cpp.
|
overrideprotectedvirtual |
Reimplemented from cWindow.
Definition at line 124 of file LuaWindow.cpp.
void cLuaWindow::SetOnClicked | ( | cLuaState::cCallbackPtr && | a_OnClicked | ) |
Sets the Lua callback to call when the player clicks on the window.
The window can stop the click from propogating.
Definition at line 85 of file LuaWindow.cpp.
void cLuaWindow::SetOnClosing | ( | cLuaState::cCallbackPtr && | a_OnClosing | ) |
Sets the Lua callback function to call when the window is about to close.
Definition at line 98 of file LuaWindow.cpp.
void cLuaWindow::SetOnSlotChanged | ( | cLuaState::cCallbackPtr && | a_OnSlotChanged | ) |
Sets the Lua callback function to call when a slot is changed.
Definition at line 111 of file LuaWindow.cpp.
|
protected |
Contents of the non-inventory part.
Definition at line 65 of file LuaWindow.h.
|
protected |
Reference to self, to keep Lua from GCing the object while a player is still using it.
Created when the first player opens the window, destroyed when the last player closes the window.
Definition at line 85 of file LuaWindow.h.
|
protected |
The canon Lua state that has opened the window and owns the m_LuaRef.
Definition at line 68 of file LuaWindow.h.
|
protected |
The Lua callback to call when the player clicked on a slot.
Definition at line 71 of file LuaWindow.h.
|
protected |
The Lua callback to call when the window is closing for any player.
Definition at line 74 of file LuaWindow.h.
|
protected |
The Lua callback to call when a slot has changed.
Definition at line 77 of file LuaWindow.h.
|
protected |
Number of players that are currently using the window.
Used to manager the m_LuaRef lifetime.
Definition at line 81 of file LuaWindow.h.