diff options
author | Lane Kolbly <lane@rscheme.org> | 2017-08-17 16:27:43 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-08-17 16:27:43 +0200 |
commit | 1ec85a2b2cb285bcc019258c8fddcddfcda84fa8 (patch) | |
tree | b6511b8d1ecae466815dc7376322f1bd617dbc6d /src/Bindings/LuaWindow.cpp | |
parent | Add support for 1.12.1 (#3908) (diff) | |
download | cuberite-1ec85a2b2cb285bcc019258c8fddcddfcda84fa8.tar cuberite-1ec85a2b2cb285bcc019258c8fddcddfcda84fa8.tar.gz cuberite-1ec85a2b2cb285bcc019258c8fddcddfcda84fa8.tar.bz2 cuberite-1ec85a2b2cb285bcc019258c8fddcddfcda84fa8.tar.lz cuberite-1ec85a2b2cb285bcc019258c8fddcddfcda84fa8.tar.xz cuberite-1ec85a2b2cb285bcc019258c8fddcddfcda84fa8.tar.zst cuberite-1ec85a2b2cb285bcc019258c8fddcddfcda84fa8.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/LuaWindow.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/Bindings/LuaWindow.cpp b/src/Bindings/LuaWindow.cpp index fd714390e..2802c69db 100644 --- a/src/Bindings/LuaWindow.cpp +++ b/src/Bindings/LuaWindow.cpp @@ -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); +} + + + + |