1
0

Add cLuaWindow OnClicked Callback (#3901)

This commit is contained in:
Lane Kolbly
2017-08-17 09:27:43 -05:00
committed by Mattes D
parent 238f5bb338
commit 1ec85a2b2c
15 changed files with 156 additions and 3 deletions

View File

@@ -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);
}