summaryrefslogtreecommitdiffstats
path: root/source/LuaWindow.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-30 21:34:09 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-30 21:34:09 +0200
commit9684f90f8361fb314a60a387dc9ecf9bc4c3062a (patch)
tree37e595d7f4b6fdd51b18943db2be6b538ea1caea /source/LuaWindow.cpp
parentProtoProxy: Added a note in the documentation about the need to switch off username verification (diff)
downloadcuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar
cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar.gz
cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar.bz2
cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar.lz
cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar.xz
cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.tar.zst
cuberite-9684f90f8361fb314a60a387dc9ecf9bc4c3062a.zip
Diffstat (limited to '')
-rw-r--r--source/LuaWindow.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/source/LuaWindow.cpp b/source/LuaWindow.cpp
new file mode 100644
index 000000000..d7b67d552
--- /dev/null
+++ b/source/LuaWindow.cpp
@@ -0,0 +1,91 @@
+
+// LuaWindow.cpp
+
+// Implements the cLuaWindow class representing a virtual window that plugins may create and open for the player
+
+#include "Globals.h"
+#include "LuaWindow.h"
+#include "UI/SlotArea.h"
+#include "Plugin_NewLua.h"
+#include "lauxlib.h" // Needed for LUA_REFNIL
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cLuaWindow:
+
+cLuaWindow::cLuaWindow(cWindow::WindowType a_WindowType, int a_SlotsX, int a_SlotsY, const AString & a_Title) :
+ super(a_WindowType, a_Title),
+ m_Contents(a_SlotsX, a_SlotsY),
+ m_Plugin(NULL),
+ m_LuaRef(LUA_REFNIL)
+{
+ m_SlotAreas.push_back(new cSlotAreaItemGrid(m_Contents, *this));
+
+ // If appropriate, add an Armor slot area:
+ switch (a_WindowType)
+ {
+ case cWindow::Inventory:
+ case cWindow::Workbench:
+ {
+ m_SlotAreas.push_back(new cSlotAreaArmor(*this));
+ break;
+ }
+ }
+ m_SlotAreas.push_back(new cSlotAreaInventory(*this));
+ m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
+}
+
+
+
+
+
+cLuaWindow::~cLuaWindow()
+{
+ ASSERT(m_OpenedBy.empty());
+}
+
+
+
+
+
+void cLuaWindow::SetLuaRef(cPlugin_NewLua * a_Plugin, int a_LuaRef)
+{
+ ASSERT(m_Plugin == NULL);
+ ASSERT(m_LuaRef == LUA_REFNIL);
+ m_Plugin = a_Plugin;
+ m_LuaRef = a_LuaRef;
+}
+
+
+
+
+
+bool cLuaWindow::IsLuaReferenced(void) const
+{
+ return ((m_Plugin != NULL) && (m_LuaRef != LUA_REFNIL));
+}
+
+
+
+
+
+void cLuaWindow::Destroy(void)
+{
+ super::Destroy();
+
+ if ((m_LuaRef != LUA_REFNIL) && (m_Plugin != NULL))
+ {
+ // The object is referenced by Lua, un-reference it
+ m_Plugin->Unreference(m_LuaRef);
+ }
+
+ // Lua will take care of this object, it will garbage-collect it, so we *must not* delete it!
+ m_IsDestroyed = false;
+}
+
+
+
+