完整开源的CocoStuido gui for lua

  • 本帖最后由 rrobin 于 2013-9-10 14:43 编辑 *

注意:此代码只针对此网站发布的cocos2dx_v2.1.5b
所有testcpp里的widget示例都已实现,实现了一个GuiExample,其他的就留给大家去熟悉.其实无非就是讲c代码拷贝到lua里然后修改一点…
http://pan.baidu.com/share/link?shareid=2377009888&uk=2956369506 代码,pkg和示例的包
使用步骤:
1.解压下载包
2.将extensions下的CocoGUILIB文件夹备份下,然后用解压的CocoGUILIB覆盖原文件夹
3.将tools/tolua++文件夹备份,将pkg.zip解压到tools/tolua++下,然后运行命令行编译出LuaCocos2d.cpp(这步编译不会的…去百度)
4.编译cocos2d-x工程,就可以在lua里使用cocosguilib里的类了

使用Hellolua工程跑示例程序:
将bin下面的所有文件夹和lua拷贝到samples\Lua\HelloLua\Resources下
将hellolua项目里的AppDelegate.cpp的函数applicationDidFinishLaunching()修改一下.

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionNoBorder);

    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // register lua engine
    CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
    CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);

    std::string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("hellogui.lua");
    pEngine->executeScriptFile(path.c_str());

    return true;
}

然后run

lua中UIWidget注册回调函数的方法
UIWidget :registerEventScript

lua回调示例这样

function eventHandler(eventType)
     if eventType == "pushDown" then
        -- do something
     end
end
UIWidget: registerEventScript(eventHandler)

现有eventType为
“pushDown”
“move”
“releaseUp”
“cancelUp”
“longClick” (这个studio还未实现)
“selected”
“unSelected”
“percentChanged”
“attachWithIME”
“detachWithIME”
“insertText”
“deleteBackward”
“berthToLeftBottom”
“berthToLeftTop”
“berthToRightBottom”
“berthToRightTop”
“berthToLeft”
“berthToTop”
“berthToRight”
“berthToBottom”
“bounceOver”
“bounceToLeftBottom”
“bounceToLeftTop”
“bounceToRightBottom”
“bounceToRightTop”
“bounceToLeft”
“bounceToTop”
“bounceToRight”
“bounceToBottom”
“initChild”
“updateChild”
“scrollToTop”
“scrollToBottom”
“scrollToLeft”
“scrollToRight”

好了,各位苦逼的程序员,老衲只能帮你们到这里了

111:14::14::14::14::14::14:

好帖子 强力支持:)

强力支持楼主~

修改CocosGUIExamplesRegisterScene.lua里的82行
将UIActionManager:shareManger():purgeUIActionManager()修改为UIActionManager:purgeUIActionManager().
这是一个官方写的代码问题…调用static的purgeUIActionManager函数之前还调用了shareManger.估计vs把代码优化了所以官方给的示例没有问题,一旦誊抄到lua里就出问题了.

— Begin quote from ____

%url%dengqianyi 发表于 2013-9-18 09:23
收到,回头改下,thanks。你这边的CocoGUILIB库有把论坛里的2.1.5b的补丁打上嘛? …

— End quote

必须打啊…2.1.5b修改了好多…

嗯,这个bug是腾代码导致的,将退出那里的资源释放修改成这样:

    local function onEnterOrExit(tag)
            if tag == "enter" then
                  Scene:addChild(RegisterLayer())
            elseif tag == "exit" then
                 UIHelper:purgeUIHelper()
                 UIActionManager:purgeUIActionManager()
            end
    end

thanks for your shared

楼主,请问uiwidget是如何绑定点击事件的呢?uiwidget没有registerEventScript的窝好像,谢谢