From bf7c2fe783133cd9f15d96981053ef7ab6aaf49a Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Fri, 31 May 2013 07:16:14 +0000 Subject: Added cLuaWindow:SetOnSlotChanged(); the callback is called only for non-inventory slots git-svn-id: http://mc-server.googlecode.com/svn/trunk@1535 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/LuaWindow.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'source/LuaWindow.cpp') 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); + } +} + + + + -- cgit v1.2.3