diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-05-30 22:40:43 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-05-30 22:40:43 +0200 |
commit | 2eb1240e14986e1cccc02a96713133a003347f8b (patch) | |
tree | 28c58a677423d507ab57e421b9fcb8df8b31c5e0 /source/LuaWindow.cpp | |
parent | Window contents are sent whenever the window is opened by a player. (diff) | |
download | cuberite-2eb1240e14986e1cccc02a96713133a003347f8b.tar cuberite-2eb1240e14986e1cccc02a96713133a003347f8b.tar.gz cuberite-2eb1240e14986e1cccc02a96713133a003347f8b.tar.bz2 cuberite-2eb1240e14986e1cccc02a96713133a003347f8b.tar.lz cuberite-2eb1240e14986e1cccc02a96713133a003347f8b.tar.xz cuberite-2eb1240e14986e1cccc02a96713133a003347f8b.tar.zst cuberite-2eb1240e14986e1cccc02a96713133a003347f8b.zip |
Diffstat (limited to 'source/LuaWindow.cpp')
-rw-r--r-- | source/LuaWindow.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/source/LuaWindow.cpp b/source/LuaWindow.cpp index d7b67d552..5ed521793 100644 --- a/source/LuaWindow.cpp +++ b/source/LuaWindow.cpp @@ -7,6 +7,7 @@ #include "LuaWindow.h"
#include "UI/SlotArea.h"
#include "Plugin_NewLua.h"
+#include "Player.h"
#include "lauxlib.h" // Needed for LUA_REFNIL
@@ -20,7 +21,9 @@ cLuaWindow::cLuaWindow(cWindow::WindowType a_WindowType, int a_SlotsX, int a_Slo super(a_WindowType, a_Title),
m_Contents(a_SlotsX, a_SlotsY),
m_Plugin(NULL),
- m_LuaRef(LUA_REFNIL)
+ m_LuaRef(LUA_REFNIL),
+ m_OnClosingFnRef(LUA_REFNIL),
+ m_OnSlotChangedFnRef(LUA_REFNIL)
{
m_SlotAreas.push_back(new cSlotAreaItemGrid(m_Contents, *this));
@@ -53,7 +56,8 @@ cLuaWindow::~cLuaWindow() void cLuaWindow::SetLuaRef(cPlugin_NewLua * a_Plugin, int a_LuaRef)
{
- ASSERT(m_Plugin == NULL);
+ // 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));
ASSERT(m_LuaRef == LUA_REFNIL);
m_Plugin = a_Plugin;
m_LuaRef = a_LuaRef;
@@ -72,6 +76,46 @@ bool cLuaWindow::IsLuaReferenced(void) const +void cLuaWindow::SetOnClosing(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_OnClosingFnRef != LUA_REFNIL)
+ {
+ m_Plugin->Unreference(m_OnClosingFnRef);
+ }
+
+ // Store the new reference
+ m_Plugin = a_Plugin;
+ m_OnClosingFnRef = a_FnRef;
+}
+
+
+
+
+
+bool cLuaWindow::ClosedByPlayer(cPlayer & a_Player)
+{
+ // First notify the plugin through the registered callback:
+ if (m_OnClosingFnRef != LUA_REFNIL)
+ {
+ ASSERT(m_Plugin != NULL);
+ if (m_Plugin->CallbackWindowClosing(m_OnClosingFnRef, *this, a_Player))
+ {
+ // The callback disagrees
+ return false;
+ }
+ }
+
+ return super::ClosedByPlayer(a_Player);
+}
+
+
+
+
+
void cLuaWindow::Destroy(void)
{
super::Destroy();
|