2010-05-06 00:08:41 +00:00
|
|
|
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
|
|
|
// Copyright (C) 2010 Winch Gate Property Limited
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include "stdpch.h"
|
|
|
|
#include "displayer_lua.h"
|
|
|
|
#include "../interface_v3/lua_ihm.h"
|
2012-05-21 01:35:05 +00:00
|
|
|
#include "../interface_v3/lua_ihm_ryzom.h"
|
2010-05-06 00:08:41 +00:00
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
namespace R2
|
|
|
|
{
|
|
|
|
|
2011-02-09 13:42:03 +00:00
|
|
|
// *********************************************************************************************************
|
|
|
|
CDisplayerLua::CDisplayerLua()
|
|
|
|
{
|
|
|
|
_ToLua._Displayer = this;
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
bool CDisplayerLua::init(const CLuaObject ¶meters)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_init)
|
|
|
|
// parameters should be a function that create the lua displayer
|
|
|
|
CLuaStackChecker lsc(parameters.getLuaState());
|
|
|
|
_ToLua._LuaTable.release();
|
|
|
|
if (parameters.isString())
|
|
|
|
{
|
|
|
|
getEditor().getEnv()[parameters.toString()].push(); // get method from the R2 env
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parameters.push();
|
|
|
|
}
|
|
|
|
CLuaState &ls = *parameters.getLuaState();
|
|
|
|
getEditor().getEnv().push(); // this is a method call
|
2012-05-21 01:35:05 +00:00
|
|
|
if (CLuaIHMRyzom::executeFunctionOnStack(ls, 1, 1))
|
2010-05-06 00:08:41 +00:00
|
|
|
{
|
|
|
|
_ToLua._LuaTable.pop(ls);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nlwarning("<CDisplayerLua::init> Error while calling displayer ctor (parameter should be a r2 method, or the *name* of a r2 method) : param is : ");
|
|
|
|
parameters.dump();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return CDisplayerBase::init(parameters);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2011-02-09 13:42:03 +00:00
|
|
|
CDisplayerLua::CToLua::CToLua():_Displayer(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// *********************************************************************************************************
|
|
|
|
CDisplayerLua* CDisplayerLua::CToLua::getEnclosing()
|
2010-05-06 00:08:41 +00:00
|
|
|
{
|
2011-02-09 13:42:03 +00:00
|
|
|
return _Displayer;
|
2010-05-06 00:08:41 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::CToLua::executeHandler(const CLuaString &eventName, int numArgs)
|
|
|
|
{
|
|
|
|
CLuaState &ls = *getLua();
|
|
|
|
CLuaStackRestorer lsr(&ls, ls.getTop() - numArgs);
|
|
|
|
//
|
|
|
|
if (!_LuaTable.isValid()) return; // init failed
|
2012-05-19 22:59:31 +00:00
|
|
|
if (_LuaTable[ eventName.getStr().c_str() ].isNil()) return; // event not handled
|
2010-05-06 00:08:41 +00:00
|
|
|
static volatile bool dumpStackWanted = false;
|
|
|
|
if (dumpStackWanted) ls.dumpStack();
|
2012-05-19 22:59:31 +00:00
|
|
|
_LuaTable[ eventName.getStr().c_str() ].push();
|
2010-05-06 00:08:41 +00:00
|
|
|
if (dumpStackWanted) ls.dumpStack();
|
|
|
|
// put method before its args
|
|
|
|
ls.insert(- numArgs - 1);
|
|
|
|
if (dumpStackWanted) ls.dumpStack();
|
|
|
|
// this is a method call
|
|
|
|
_LuaTable.push();
|
|
|
|
if (dumpStackWanted) ls.dumpStack();
|
|
|
|
ls.insert(- numArgs - 1);
|
|
|
|
if (dumpStackWanted) ls.dumpStack();
|
|
|
|
// First arg always is the instance being displayed
|
2011-02-09 13:42:03 +00:00
|
|
|
if (getEnclosing())
|
|
|
|
getEnclosing()->getDisplayedInstance()->getLuaProjection().push();
|
2010-05-06 00:08:41 +00:00
|
|
|
ls.insert(- numArgs - 1);
|
|
|
|
if (dumpStackWanted) ls.dumpStack();
|
2012-05-21 01:35:05 +00:00
|
|
|
CLuaIHMRyzom::executeFunctionOnStack(*_LuaTable.getLuaState(), numArgs + 2, 0);
|
2010-05-06 00:08:41 +00:00
|
|
|
if (dumpStackWanted) ls.dumpStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::CToLua::pushLuaAccess(CLuaState &ls)
|
|
|
|
{
|
|
|
|
if (_LuaTable.isValid())
|
|
|
|
{
|
|
|
|
nlassert(_LuaTable.getLuaState() == &ls);
|
|
|
|
_LuaTable.push();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ls.pushNil();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::pushLuaAccess(CLuaState &ls)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_pushLuaAccess)
|
|
|
|
_ToLua.pushLuaAccess(ls);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
CLuaState *CDisplayerLua::CToLua::getLua()
|
|
|
|
{
|
|
|
|
if (!_LuaTable.isValid())
|
|
|
|
{
|
|
|
|
nlwarning("Warning: try to access to a corrupted table");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return _LuaTable.getLuaState();
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onActChanged()
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onActChanged)
|
|
|
|
_ToLua.onActChanged();
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onContinentChanged()
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onContinentChanged)
|
|
|
|
_ToLua.onContinentChanged();
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onPostCreate()
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onPostCreate)
|
|
|
|
_ToLua.onPostCreate();
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onCreate()
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onCreate)
|
|
|
|
_ToLua.onCreate();
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onErase()
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onErase)
|
|
|
|
_ToLua.onErase();
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onPreHrcMove()
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onPreHrcMove)
|
|
|
|
_ToLua.onPreHrcMove();
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onPostHrcMove()
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onPostHrcMove)
|
|
|
|
_ToLua.onPostHrcMove();
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onFocus(bool focused)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onFocus)
|
|
|
|
_ToLua.onFocus(focused);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onSelect(bool selected)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onSelect)
|
|
|
|
_ToLua.onSelect(selected);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onAttrModified(const std::string &attrName,sint32 index)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onAttrModified)
|
|
|
|
_ToLua.onAttrModified(attrName, index);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onTargetInstanceCreated(const std::string &refMakerAttr, sint32 refMakerAttrIndex)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onTargetInstanceCreated)
|
|
|
|
_ToLua.onTargetInstanceCreated(refMakerAttr, refMakerAttrIndex);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onTargetInstanceErased(const std::string &refMakerAttr, sint32 refMakerAttrIndex)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onTargetInstanceErased)
|
|
|
|
_ToLua.onTargetInstanceErased(refMakerAttr, refMakerAttrIndex);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onTargetInstanceEraseRequested(const std::string &refMakerAttr, sint32 refMakerAttrIndex)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onTargetInstanceEraseRequested)
|
|
|
|
_ToLua.onTargetInstanceEraseRequested(refMakerAttr, refMakerAttrIndex);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onTargetInstanceAttrModified(const std::string &refMakerAttr,sint32 refMakerAttrIndex,const std::string &targetAttrName,sint32 targetAttrIndex)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onTargetInstanceAttrModified)
|
|
|
|
_ToLua.onTargetInstanceAttrModified(refMakerAttr, refMakerAttrIndex, targetAttrName, targetAttrIndex);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onTargetInstancePreHrcMove(const std::string &refMakerAttr,sint32 refMakerAttrIndex)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onTargetInstancePreHrcMove)
|
|
|
|
_ToLua.onTargetInstancePreHrcMove(refMakerAttr, refMakerAttrIndex);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:50:19 +00:00
|
|
|
// *********************************************************************************************************
|
2010-05-06 00:08:41 +00:00
|
|
|
void CDisplayerLua::onTargetInstancePostHrcMove(const std::string &refMakerAttr,sint32 refMakerAttrIndex)
|
|
|
|
{
|
|
|
|
//H_AUTO(R2_CDisplayerLua_onTargetInstancePostHrcMove)
|
|
|
|
_ToLua.onTargetInstancePostHrcMove(refMakerAttr, refMakerAttrIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // R2
|