summaryrefslogtreecommitdiffstats
path: root/source/LuaWindow.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-31 09:16:14 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-31 09:16:14 +0200
commitbf7c2fe783133cd9f15d96981053ef7ab6aaf49a (patch)
tree3c30a01cd8690a59af2db1ee440bf7e8d2bc61f4 /source/LuaWindow.cpp
parentAdded the OnClosing callback to cLuaWindow API (diff)
downloadcuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar.gz
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar.bz2
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar.lz
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar.xz
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.tar.zst
cuberite-bf7c2fe783133cd9f15d96981053ef7ab6aaf49a.zip
Diffstat (limited to 'source/LuaWindow.cpp')
-rw-r--r--source/LuaWindow.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/source/LuaWindow.cpp b/source/LuaWindow.cpp
index 5ed521793..f6277250c 100644
--- a/source/LuaWindow.cpp
+++ b/source/LuaWindow.cpp
@@ -25,6 +25,7 @@ cLuaWindow::cLuaWindow(cWindow::WindowType a_WindowType, int a_SlotsX, int a_Slo
m_OnClosingFnRef(LUA_REFNIL),
m_OnSlotChangedFnRef(LUA_REFNIL)
{
+ m_Contents.AddListener(*this);
m_SlotAreas.push_back(new cSlotAreaItemGrid(m_Contents, *this));
// If appropriate, add an Armor slot area:
@@ -96,6 +97,26 @@ void cLuaWindow::SetOnClosing(cPlugin_NewLua * a_Plugin, int a_FnRef)
+void cLuaWindow::SetOnSlotChanged(cPlugin_NewLua * a_Plugin, int a_FnRef)
+{
+ // Either m_Plugin is not set or equal to the passed plugin; only one plugin can use one cLuaWindow object
+ ASSERT((m_Plugin == NULL) || (m_Plugin == a_Plugin));
+
+ // If there already was a function, unreference it first
+ if (m_OnSlotChangedFnRef != LUA_REFNIL)
+ {
+ m_Plugin->Unreference(m_OnSlotChangedFnRef);
+ }
+
+ // Store the new reference
+ m_Plugin = a_Plugin;
+ m_OnSlotChangedFnRef = a_FnRef;
+}
+
+
+
+
+
bool cLuaWindow::ClosedByPlayer(cPlayer & a_Player)
{
// First notify the plugin through the registered callback:
@@ -133,3 +154,22 @@ void cLuaWindow::Destroy(void)
+
+void cLuaWindow::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
+{
+ if (a_ItemGrid != &m_Contents)
+ {
+ ASSERT(!"Invalid ItemGrid in callback");
+ return;
+ }
+
+ // If an OnSlotChanged callback has been registered, call it:
+ if (m_OnSlotChangedFnRef != LUA_REFNIL)
+ {
+ m_Plugin->CallbackWindowSlotChanged(m_OnSlotChangedFnRef, *this, a_SlotNum);
+ }
+}
+
+
+
+