Add cLuaWindow OnClicked Callback (#3901)
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include "PluginLua.h"
|
||||
#include "Root.h"
|
||||
#include "lua/src/lauxlib.h" // Needed for LUA_REFNIL
|
||||
|
||||
#include "ClientHandle.h"
|
||||
|
||||
|
||||
|
||||
@@ -86,6 +86,19 @@ cLuaWindow::~cLuaWindow()
|
||||
|
||||
|
||||
|
||||
void cLuaWindow::SetOnClicked(cLuaState::cCallbackPtr && a_OnClicked)
|
||||
{
|
||||
// Only one Lua state can be a cLuaWindow object callback:
|
||||
ASSERT(a_OnClicked->IsSameLuaState(*m_LuaState));
|
||||
|
||||
// Store the new reference, releasing the old one if appropriate:
|
||||
m_OnClicked = std::move(a_OnClicked);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaWindow::SetOnClosing(cLuaState::cCallbackPtr && a_OnClosing)
|
||||
{
|
||||
// Only one Lua state can be a cLuaWindow object callback:
|
||||
@@ -206,3 +219,24 @@ void cLuaWindow::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaWindow::Clicked(cPlayer & a_Player, int a_WindowID, short a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem)
|
||||
{
|
||||
if (m_OnClicked != nullptr)
|
||||
{
|
||||
// Plugin can stop a click
|
||||
if (m_OnClicked->Call(this, &a_Player, a_SlotNum, a_ClickAction, a_ClickedItem))
|
||||
{
|
||||
// Tell the client the actual state of the window
|
||||
a_Player.GetClientHandle()->SendInventorySlot(-1, -1, a_Player.GetDraggingItem());
|
||||
BroadcastWholeWindow();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cWindow::Clicked(a_Player, a_WindowID, a_SlotNum, a_ClickAction, a_ClickedItem);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user