mygui与luaplus的绑定

xiaoxiao2021-03-01  16

1.CEGUI里load layout的时候,有关于event的property项,内容一个是event名,另一个是lua脚本里的function name. event事件来后fireEvent,依次调用event里的SlotContainer函数指针容器内的SubscriberSlot,而lua对应的应该是ScriptFunctor模板转换的FunctorCopySlot,ScriptFunctor重载了operator(),operator()调用的就是scriptModule里的executeScriptedEventHandler,   scriptModule可以是luaPlus也可以是tolua++   2.MyGUI如何实现类似的功能,与CEGUI不同,CEGUI所有Window都继承于EventSet,由一个事件名称去索引出Event,MyGUI用的是delegate, 暂时的想法是load layout的时候因为没有event的property项,所以只能用userString项代替了,还好新版的支持eventAddUserString的delegate,读到自定义特定的userStirng事件时,将delegate加到自己的一个luaMgr类似的类函数上,同时将一些delegate回传回来的参数转到lua里   xml: skin="Button" position="25 140 130 30" name="first_btn"> skin="Button" position="170 145 95 25" name="kick_me"> lua: function BtnClick() print(arg0); print("BtnClick\n"); end function KickMe() print(arg0); print("kick me\n"); end c++: void DemoKeeper::onAddUserString(MyGUI::WidgetPtr _sender,const std::string& _key, const std::string& _value) { //printf("%0x_%s_%s", _sender, _key.c_str(), _value.c_str()); if(_key == "Clicked") { _sender->eventMouseButtonClick +=MyGUI::newDelegate(this, &DemoKeeper::lua_doClick); } } void DemoKeeper::lua_doClick(MyGUI::WidgetPtr _sender) { g_luaState->GetGlobals().SetString("arg0", _sender->getName().c_str()); std::string userString = _sender->getUserString("Clicked"); g_luaState->DoString(userString.c_str()); } 相关资源:七夕情人节表白HTML源码(两款)
转载请注明原文地址: https://www.6miu.com/read-4150081.html

最新回复(0)