7 #include "../Entities/Player.h" 8 #include "../UI/SlotArea.h" 10 #include "lua/src/lauxlib.h" 12 #include "../ClientHandle.h" 21 Super(a_WindowType, a_Title),
22 m_Contents(a_SlotsX, a_SlotsY),
23 m_LuaState(a_LuaState.QueryCanonLuaState())
184 if (Area != a_ClickedArea)
186 Areas.push_back(Area);
201 ASSERT(!
"Invalid ItemGrid in callback");
231 cWindow::Clicked(a_Player, a_WindowID, a_SlotNum, a_ClickAction, a_ClickedItem);
Handles the main inventory of each player, excluding the armor and hotbar.
void CreateFromObject(cLuaState &a_LuaState, T &&a_Object)
Creates a Lua reference to the specified object instance in the specified Lua state.
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.
virtual ~cLuaWindow() override
cWindow * GetWindow(void)
virtual bool ClosedByPlayer(cPlayer &a_Player, bool a_CanRefuse) override
Called when a player closes this window; notifies all slot areas.
void SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem &a_Item)
cItem & GetDraggingItem(void)
In UI windows, get the item that the player is dragging.
cLuaState::cCallbackPtr m_OnClicked
The Lua callback to call when the player clicked on a slot.
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...
void UnRef(void)
Removes the bound reference, resets the object to Unbound state.
virtual void OpenedByPlayer(cPlayer &a_Player) override
Encapsulates a Lua state and provides some syntactic sugar for common operations. ...
Handles the armor area of the player's inventory.
void SetOnClosing(cLuaState::cCallbackPtr &&a_OnClosing)
Sets the Lua callback function to call when the window is about to close.
void AddListener(cListener &a_Listener)
Adds a callback that gets called whenever a slot changes.
virtual void OnSlotChanged(cItemGrid *a_ItemGrid, int a_SlotNum) override
Called whenever a slot changes.
eClickAction
Individual actions sent in the WindowClick packet.
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...
bool ForEachPlayer(cPlayerListCallback a_Callback)
Calls the callback for each player in all worlds.
cLuaState::cCallbackPtr m_OnSlotChanged
The Lua callback to call when a slot has changed.
void RemoveListener(cListener &a_Listener)
Removes a slot-change-callback.
Handles any slot area that is representing a cItemGrid; same items for all the players.
cItemGrid m_Contents
Contents of the non-inventory part.
std::vector< cSlotArea * > cSlotAreas
void SetOnClicked(cLuaState::cCallbackPtr &&a_OnClicked)
Sets the Lua callback to call when the player clicks on the window.
virtual void OpenedByPlayer(cPlayer &a_Player)
std::unique_ptr< cCallback > cCallbackPtr
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.
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.
void CloseWindow(bool a_CanRefuse=true)
Closes the current window, resets current window to m_InventoryWindow.
std::atomic< int > m_PlayerCount
Number of players that are currently using the window.
virtual bool ClosedByPlayer(cPlayer &a_Player, bool a_CanRefuse)
Called when a player closes this window; notifies all slot areas.
cLuaState * m_LuaState
The canon Lua state that has opened the window and owns the m_LuaRef.
cLuaState::cRef m_LuaRef
Reference to self, to keep Lua from GCing the object while a player is still using it...
virtual void Destroy(void) override
Sets the internal flag as "destroyed"; notifies the owner that the window is destroying.
virtual void Destroy(void)
Sets the internal flag as "destroyed"; notifies the owner that the window is destroying.
Handles the hotbar of each player.
void SetOnSlotChanged(cLuaState::cCallbackPtr &&a_OnSlotChanged)
Sets the Lua callback function to call when a slot is changed.
cLuaState::cCallbackPtr m_OnClosing
The Lua callback to call when the window is closing for any player.
cClientHandle * GetClientHandle(void) const
Returns the raw client handle associated with the player.
void BroadcastWholeWindow(void)
Sends the contents of the whole window to all clients of this window.