diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 18265b616b..627e8dbf20 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -1c487d29bdc2d80516e86e2ee93b1664e9f7df2f \ No newline at end of file +486af7c751cc94ff5dc25748cdb4bcb183be5dd2 \ No newline at end of file diff --git a/cocos/2d/CCScriptSupport.h b/cocos/2d/CCScriptSupport.h index 0c7f502a8b..f5803f4cb7 100644 --- a/cocos/2d/CCScriptSupport.h +++ b/cocos/2d/CCScriptSupport.h @@ -211,6 +211,7 @@ enum ScriptEventType kControlEvent, kCommonEvent, kTableViewEvent,//Now it's only used in LuaBinding + kAssetsManagerEvent,//Now it's only used in Lua Binding }; struct BasicScriptData diff --git a/cocos/scripting/lua/bindings/CCLuaEngine.cpp b/cocos/scripting/lua/bindings/CCLuaEngine.cpp index 558b68acb1..dfbf607e84 100644 --- a/cocos/scripting/lua/bindings/CCLuaEngine.cpp +++ b/cocos/scripting/lua/bindings/CCLuaEngine.cpp @@ -252,6 +252,11 @@ int LuaEngine::sendEvent(ScriptEvent* evt) return handleTableViewEvent(evt->data); } break; + case kAssetsManagerEvent: + { + return handleAssetsManagerEvent(evt->data); + } + break; default: break; } @@ -770,4 +775,47 @@ int LuaEngine::handleTableViewEventReturnArray(void* data,int numResults,Array& return ret; } + +int LuaEngine::handleAssetsManagerEvent(void* data) +{ + if (nullptr == data) + return 0; + + BasicScriptData* eventData = static_cast(data); + if (nullptr == eventData->nativeObject || nullptr == eventData->value) + return 0; + + LuaAssetsManagerEventData* assetsManagerEventData = static_cast(eventData->value); + if (assetsManagerEventData->handlerType < ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS || assetsManagerEventData->handlerType > ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR ) + return 0; + + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)eventData->nativeObject, assetsManagerEventData->handlerType); + + if (0 == handler) + return 0; + + int ret = 0; + switch (assetsManagerEventData->handlerType) + { + case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS: + case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR: + { + _stack->pushInt(assetsManagerEventData->value); + ret = _stack->executeFunctionByHandler(handler, 1); + } + break; + + case ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS: + { + ret = _stack->executeFunctionByHandler(handler, 0); + } + break; + + default: + break; + } + + return ret; +} + NS_CC_END diff --git a/cocos/scripting/lua/bindings/CCLuaEngine.h b/cocos/scripting/lua/bindings/CCLuaEngine.h index 0a1442aaaa..e739103080 100644 --- a/cocos/scripting/lua/bindings/CCLuaEngine.h +++ b/cocos/scripting/lua/bindings/CCLuaEngine.h @@ -141,6 +141,7 @@ private: int handlerControlEvent(void* data); int handleTableViewEvent(void* data); int handleTableViewEventReturnArray(void* data,int numResults,Array& resultArray); + int handleAssetsManagerEvent(void* data); void extendWebsocket(lua_State* lua_S); void extendGLNode(lua_State* lua_S); private: diff --git a/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.h b/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.h index 44ea6fa103..d460804cf2 100644 --- a/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.h +++ b/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.h @@ -95,6 +95,10 @@ public: TABLECELL_SIZE_FOR_INDEX, TABLECELL_AT_INDEX, TABLEVIEW_NUMS_OF_CELLS, + + ASSETSMANAGER_PROGRESS, + ASSETSMANAGER_SUCCESS, + ASSETSMANAGER_ERROR, }; typedef int Handler; diff --git a/cocos/scripting/lua/bindings/lua_assetsmanager_test_sample.cpp b/cocos/scripting/lua/bindings/lua_assetsmanager_test_sample.cpp new file mode 100644 index 0000000000..e3d6377f0b --- /dev/null +++ b/cocos/scripting/lua/bindings/lua_assetsmanager_test_sample.cpp @@ -0,0 +1,164 @@ +#include "lua_assetsmanager_test_sample.h" + +#ifdef __cplusplus +extern "C" { +#endif +#include "tolua_fix.h" +#ifdef __cplusplus +} +#endif + +#include "cocos2d.h" +#include "cocos-ext.h" + +#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) +#include +#include +#endif + +USING_NS_CC; +USING_NS_CC_EXT; + + +static int lua_cocos2dx_createDownloadDir(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = lua_gettop(L); +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + if (0 == argc) + { + std::string pathToSave = FileUtils::getInstance()->getWritablePath(); + pathToSave += "tmpdir"; + +#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) + DIR *pDir = NULL; + + pDir = opendir (pathToSave.c_str()); + if (! pDir) + { + mkdir(pathToSave.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); + } +#else + if ((GetFileAttributesA(pathToSave.c_str())) == INVALID_FILE_ATTRIBUTES) + { + CreateDirectoryA(pathToSave.c_str(), 0); + } +#endif + tolua_pushstring(L, pathToSave.c_str()); + CCLOG("the path to save is %s",pathToSave.c_str()); + return 1; + } + + CCLOG("'createDownloadDir' function wrong number of arguments: %d, was expecting %d\n", argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'createDownloadDir'.",&tolua_err); + return 0; +#endif +} + +static int lua_cocos2dx_deleteDownloadDir(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = lua_gettop(L); + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + if (1 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!tolua_isstring(L, 1, 0, &tolua_err)) goto tolua_lerror; +#endif + std::string pathToSave = tolua_tostring(L, 1, ""); + +#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) + std::string command = "rm -r "; + // Path may include space. + command += "\"" + pathToSave + "\""; + system(command.c_str()); +#else + std::string command = "rd /s /q "; + // Path may include space. + command += "\"" + pathToSave + "\""; + system(command.c_str()); +#endif + return 0; + } + + CCLOG("'resetDownloadDir' function wrong number of arguments: %d, was expecting %d\n", argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'resetDownloadDir'.",&tolua_err); + return 0; +#endif +} + +static int lua_cocos2dx_addSearchPath(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = lua_gettop(L); + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + + if (2 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!tolua_isstring(L, 1, 0, &tolua_err) || + !tolua_isboolean(L, 2, 0, &tolua_err)) + goto tolua_lerror; +#endif + std::string pathToSave = tolua_tostring(L, 1, ""); + bool before = tolua_toboolean(L, 2, 0); + std::vector searchPaths = FileUtils::getInstance()->getSearchPaths(); + if (before) + { + searchPaths.insert(searchPaths.begin(), pathToSave); + } + else + { + searchPaths.push_back(pathToSave); + } + + FileUtils::getInstance()->setSearchPaths(searchPaths); + + return 0; + } + CCLOG("'addSearchPath' function wrong number of arguments: %d, was expecting %d\n", argc, 2); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'addSearchPath'.",&tolua_err); + return 0; +#endif +} + +int register_assetsmanager_test_sample(lua_State* L) +{ + tolua_open(L); + tolua_module(L, NULL, 0); + tolua_beginmodule(L, NULL); + tolua_function(L, "createDownloadDir", lua_cocos2dx_createDownloadDir); + tolua_function(L, "deleteDownloadDir", lua_cocos2dx_deleteDownloadDir); + tolua_function(L, "addSearchPath", lua_cocos2dx_addSearchPath); + tolua_endmodule(L); + return 0; +} diff --git a/cocos/scripting/lua/bindings/lua_assetsmanager_test_sample.h b/cocos/scripting/lua/bindings/lua_assetsmanager_test_sample.h new file mode 100644 index 0000000000..967593de71 --- /dev/null +++ b/cocos/scripting/lua/bindings/lua_assetsmanager_test_sample.h @@ -0,0 +1,17 @@ +#ifndef COCOS2DX_COCOS_SCRIPTING_LUA_BINDINGS_LUA_ASSETSMANAGER_TEST_SAMPLE_H +#define COCOS2DX_COCOS_SCRIPTING_LUA_BINDINGS_LUA_ASSETSMANAGER_TEST_SAMPLE_H + +#ifdef __cplusplus +extern "C" { +#endif +#include "tolua++.h" +#ifdef __cplusplus +} +#endif + +/** + * The apis which are bound in this file are temporary for the assetsmanager test sample.After the completion of some systems like fileutils,these apis will be deprecated + */ +TOLUA_API int register_assetsmanager_test_sample(lua_State* tolua_S); + +#endif // #ifndef COCOS2DX_COCOS_SCRIPTING_LUA_BINDINGS_LUA_ASSETSMANAGER_TEST_SAMPLE_H diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp index 0e4582b126..e74dbac377 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp @@ -1426,6 +1426,125 @@ static void extendBone(lua_State* L) } } +class LuaAssetsManagerDelegateProtocol:public Object, public AssetsManagerDelegateProtocol +{ +public: + virtual ~LuaAssetsManagerDelegateProtocol() + {} + + virtual void onProgress(int percent) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS); + if (0 != handler) + { + LuaAssetsManagerEventData eventData(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS,percent); + BasicScriptData data((void*)this,&eventData); + ScriptEvent event(kAssetsManagerEvent,(void*)&data); + LuaEngine::getInstance()->sendEvent(&event); + } + } + + virtual void onSuccess() + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS); + if (0 != handler) + { + LuaAssetsManagerEventData eventData(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_SUCCESS); + BasicScriptData data((void*)this,&eventData); + ScriptEvent event(kAssetsManagerEvent,(void*)&data); + LuaEngine::getInstance()->sendEvent(&event); + } + } + + virtual void onError(AssetsManager::ErrorCode errorCode) + { + int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR); + if (0 != handler) + { + LuaAssetsManagerEventData eventData(ScriptHandlerMgr::HandlerType::ASSETSMANAGER_ERROR, (int)errorCode); + BasicScriptData data((void*)this,&eventData); + ScriptEvent event(kAssetsManagerEvent,(void*)&data); + LuaEngine::getInstance()->sendEvent(&event); + } + } +}; + +static int lua_cocos2dx_AssetsManager_setDelegate(lua_State* L) +{ + if (nullptr == L) + return 0; + + int argc = 0; + AssetsManager* self = nullptr; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; + if (!tolua_isusertype(L,1,"AssetsManager",0,&tolua_err)) goto tolua_lerror; +#endif + + self = (AssetsManager*) tolua_tousertype(L,1,0); + +#if COCOS2D_DEBUG >= 1 + if (nullptr == self) + { + tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_AssetsManager_setDelegate'\n", nullptr); + return 0; + } +#endif + + argc = lua_gettop(L) - 1; + + if (2 == argc) + { + LuaAssetsManagerDelegateProtocol* delegate = dynamic_cast( self->getDelegate()); + if (nullptr == delegate) + { + delegate = new LuaAssetsManagerDelegateProtocol(); + if (nullptr == delegate) + return 0; + + self->setUserObject(delegate); + self->setDelegate(delegate); + delegate->release(); + } + + if (2 == argc) + { +#if COCOS2D_DEBUG >= 1 + if (!toluafix_isfunction(L, 2, "LUA_FUNCTION", 0, &tolua_err) || + !tolua_isnumber(L, 3, 0, &tolua_err) ) + { + goto tolua_lerror; + } +#endif + LUA_FUNCTION handler = toluafix_ref_function(L, 2, 0); + ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType) ((int)tolua_tonumber(L,3,0) + (int)ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS); + + ScriptHandlerMgr::getInstance()->addObjectHandler((void*)delegate, handler, handlerType); + return 0; + } + } + + CCLOG("'setDelegate' function of AssetsManager has wrong number of arguments: %d, was expecting %d\n", argc, 2); + return 0; + +#if COCOS2D_DEBUG >= 1 +tolua_lerror: + tolua_error(L,"#ferror in function 'setDelegate'.",&tolua_err); + return 0; +#endif +} + +static void extendAssetsManager(lua_State* L) +{ + lua_pushstring(L, "AssetsManager"); + lua_rawget(L, LUA_REGISTRYINDEX); + if (lua_istable(L,-1)) + { + tolua_function(L, "setDelegate", lua_cocos2dx_AssetsManager_setDelegate); + } +} + int register_all_cocos2dx_extension_manual(lua_State* tolua_S) { extendScrollView(tolua_S); @@ -1435,5 +1554,6 @@ int register_all_cocos2dx_extension_manual(lua_State* tolua_S) extendCCBAnimationManager(tolua_S); extendTableView(tolua_S); extendBone(tolua_S); + extendAssetsManager(tolua_S); return 0; } diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.h b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.h index dc7dd1d623..2c8b22eddb 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.h +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.h @@ -26,4 +26,15 @@ struct LuaTableViewEventData } }; +struct LuaAssetsManagerEventData +{ + cocos2d::ScriptHandlerMgr::HandlerType handlerType; + int value; + + LuaAssetsManagerEventData(cocos2d::ScriptHandlerMgr::HandlerType _handleType, int _value = 0):handlerType(_handleType),value(_value) + { + } +}; + + #endif // #ifndef COCOS2DX_SCRIPT_LUA_COCOS2DX_SUPPORT_LUA_COCOS2DX_EXTENSION_MANUAL_H diff --git a/cocos/scripting/lua/script/Cocos2dConstants.lua b/cocos/scripting/lua/script/Cocos2dConstants.lua index 5a8ae27e94..e4dc029c55 100644 --- a/cocos/scripting/lua/script/Cocos2dConstants.lua +++ b/cocos/scripting/lua/script/Cocos2dConstants.lua @@ -272,3 +272,13 @@ cc.WEBSOCKET_STATE_CONNECTING = 0 cc.WEBSOCKET_STATE_OPEN = 1 cc.WEBSOCKET_STATE_CLOSING = 2 cc.WEBSOCKET_STATE_CLOSED = 3 + +cc.ASSETSMANAGER_CREATE_FILE = 0 +cc.ASSETSMANAGER_NETWORK = 1 +cc.ASSETSMANAGER_NO_NEW_VERSION = 2 +cc.ASSETSMANAGER_UNCOMPRESS = 3 + +cc.ASSETSMANAGER_PROTOCOL_PROGRESS = 0 +cc.ASSETSMANAGER_PROTOCOL_SUCCESS = 1 +cc.ASSETSMANAGER_PROTOCOL_ERROR = 2 + diff --git a/extensions/assets-manager/AssetsManager.h b/extensions/assets-manager/AssetsManager.h index 23e1a27774..80f0ae5d81 100644 --- a/extensions/assets-manager/AssetsManager.h +++ b/extensions/assets-manager/AssetsManager.h @@ -141,6 +141,12 @@ public: */ void setDelegate(AssetsManagerDelegateProtocol *delegate); + /** + * @js NA + * @lua NA + */ + AssetsManagerDelegateProtocol* getDelegate() { return _delegate ;} + /** @brief Sets connection time out in seconds */ void setConnectionTimeout(unsigned int timeout); diff --git a/samples/Lua/TestLua/Classes/AppDelegate.cpp b/samples/Lua/TestLua/Classes/AppDelegate.cpp index 6f5f6dedfe..025f938b6b 100644 --- a/samples/Lua/TestLua/Classes/AppDelegate.cpp +++ b/samples/Lua/TestLua/Classes/AppDelegate.cpp @@ -3,6 +3,7 @@ #include "AppDelegate.h" #include "CCLuaEngine.h" #include "SimpleAudioEngine.h" +#include "lua_assetsmanager_test_sample.h" using namespace CocosDenshion; @@ -50,7 +51,13 @@ bool AppDelegate::applicationDidFinishLaunching() LuaEngine* pEngine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(pEngine); +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + LuaStack* stack = pEngine->getLuaStack(); + register_assetsmanager_test_sample(stack->getLuaState()); +#endif + std::vector searchPaths = pFileUtils->getSearchPaths(); + searchPaths.insert(searchPaths.begin(), "Images"); searchPaths.insert(searchPaths.begin(), "cocosbuilderRes"); #if CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY diff --git a/samples/Lua/TestLua/Resources/luaScript/AssetsManagerTest/AssetsManagerModule.lua b/samples/Lua/TestLua/Resources/luaScript/AssetsManagerTest/AssetsManagerModule.lua new file mode 100644 index 0000000000..ab9b3874a6 --- /dev/null +++ b/samples/Lua/TestLua/Resources/luaScript/AssetsManagerTest/AssetsManagerModule.lua @@ -0,0 +1,43 @@ +local AssetManagerModule = {} + +function AssetManagerModule.newScene(backfunc) + + local winSize = cc.Director:getInstance():getWinSize() + + local newScene = cc.Scene:create() + local layer = cc.Layer:create() + + local function backToUpdate() + local scene = backfunc() + if scene ~= nil then + cc.Director:getInstance():replaceScene(scene) + end + end + + --Create BackMneu + cc.MenuItemFont:setFontName("Arial") + cc.MenuItemFont:setFontSize(24) + local backMenuItem = cc.MenuItemFont:create("Back") + backMenuItem:setPosition(cc.p(VisibleRect:rightBottom().x - 50, VisibleRect:rightBottom().y + 25)) + backMenuItem:registerScriptTapHandler(backToUpdate) + + local backMenu = cc.Menu:create() + backMenu:setPosition(0, 0) + backMenu:addChild(backMenuItem) + layer:addChild(backMenu,6) + + local helloLabel = cc.LabelTTF:create("Hello World", "Arial", 38) + helloLabel:setPosition(cc.p(winSize.width / 2, winSize.height - 40)) + layer:addChild(helloLabel, 5) + + local sprite = cc.Sprite:create("background.png") + sprite:setAnchorPoint(cc.p(0.5, 0.5)) + sprite:setPosition(cc.p(winSize.width / 2, winSize.height / 2)) + layer:addChild(sprite, 0) + + newScene:addChild(layer) + cc.Director:getInstance():replaceScene(newScene) +end + + +return AssetManagerModule diff --git a/samples/Lua/TestLua/Resources/luaScript/AssetsManagerTest/AssetsManagerTest.lua b/samples/Lua/TestLua/Resources/luaScript/AssetsManagerTest/AssetsManagerTest.lua new file mode 100644 index 0000000000..853342a706 --- /dev/null +++ b/samples/Lua/TestLua/Resources/luaScript/AssetsManagerTest/AssetsManagerTest.lua @@ -0,0 +1,161 @@ +local targetPlatform = cc.Application:getInstance():getTargetPlatform() + +local lineSpace = 40 +local itemTagBasic = 1000 +local menuItemNames = +{ + "enter", + "reset", + "update", +} + +local winSize = cc.Director:getInstance():getWinSize() + +local function updateLayer() + + local support = false + if (cc.PLATFORM_OS_IPHONE == targetPlatform) or (cc.PLATFORM_OS_IPAD == targetPlatform) + or (cc.PLATFORM_OS_WINDOWS == targetPlatform) or (cc.PLATFORM_OS_ANDROID == targetPlatform) + or (cc.PLATFORM_OS_IPHONE == targetPlatform) then + support = true + end + + if not support then + return nil + end + + local isUpdateItemClicked = false + local assetsManager = nil + local pathToSave = "" + + local layer = cc.Layer:create() + local menu = cc.Menu:create() + menu:setPosition(cc.p(0, 0)) + cc.MenuItemFont:setFontName("Arial") + cc.MenuItemFont:setFontSize(24) + + local progressLable = cc.LabelTTF:create("","Arial",30) + progressLable:setPosition(cc.p(140,50)) + layer:addChild(progressLable) + + pathToSave = createDownloadDir() + + local function onError(errorCode) + if errorCode == cc.ASSETSMANAGER_NO_NEW_VERSION then + progressLable:setString("no new version") + elseif errorCode == cc.ASSETSMANAGER_NETWORK then + progressLable:setString("network error") + end + end + + local function onProgress( percent ) + local progress = string.format("downloading %d%%",percent) + progressLable:setString(progress) + end + + local function onSuccess() + progressLable:setString("downloading ok") + end + + local function getAssetsManager() + if nil == assetsManager then + assetsManager = cc.AssetsManager:new("https://raw.github.com/samuele3hu/AssetsManagerTest/master/package.zip", + "https://raw.github.com/samuele3hu/AssetsManagerTest/master/version", + pathToSave) + assetsManager:retain() + assetsManager:setDelegate(onError, cc.ASSETSMANAGER_PROTOCOL_ERROR ) + assetsManager:setDelegate(onProgress, cc.ASSETSMANAGER_PROTOCOL_PROGRESS) + assetsManager:setDelegate(onSuccess, cc.ASSETSMANAGER_PROTOCOL_SUCCESS ) + assetsManager:setConnectionTimeout(3) + end + + return assetsManager + end + + local function update(sender) + + progressLable:setString("") + + getAssetsManager():update() + + --isUpdateItemClicked = true + + end + + local function reset(sender) + progressLable:setString("") + + deleteDownloadDir(pathToSave) + + getAssetsManager():deleteVersion() + + createDownloadDir() + end + + local function reloadModule( moduleName ) + + package.loaded[moduleName] = nil + + return require(moduleName) + end + + local function enter(sender) + + if not isUpdateItemClicked then + addSearchPath(pathToSave,true) + end + + assetsManagerModule = reloadModule("luaScript/AssetsManagerTest/AssetsManagerModule") + + assetsManagerModule.newScene(AssetsManagerTestMain) + end + + local callbackFuncs = + { + enter, + reset, + update, + } + + local function menuCallback(tag, menuItem) + local scene = nil + local nIdx = menuItem:getZOrder() - itemTagBasic + local ExtensionsTestScene = CreateExtensionsTestScene(nIdx) + if nil ~= ExtensionsTestScene then + cc.Director:getInstance():replaceScene(ExtensionsTestScene) + end + end + + for i = 1, table.getn(menuItemNames) do + local item = cc.MenuItemFont:create(menuItemNames[i]) + item:registerScriptTapHandler(callbackFuncs[i]) + item:setPosition(winSize.width / 2, winSize.height - i * lineSpace) + if not support then + item:setEnabled(false) + end + menu:addChild(item, itemTagBasic + i) + end + + local function onNodeEvent(msgName) + if nil ~= assetsManager then + assetsManager:release() + assetsManager = nil + end + end + + layer:registerScriptHandler(onNodeEvent) + + layer:addChild(menu) + + return layer +end + +------------------------------------- +-- AssetsManager Test +------------------------------------- +function AssetsManagerTestMain() + local scene = cc.Scene:create() + scene:addChild(updateLayer()) + scene:addChild(CreateBackMenuItem()) + return scene +end diff --git a/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua b/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua index 73d79855d6..1a534252e1 100644 --- a/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua +++ b/samples/Lua/TestLua/Resources/luaScript/mainMenu.lua @@ -13,6 +13,7 @@ require "luaScript/ActionManagerTest/ActionManagerTest" require "luaScript/ActionsEaseTest/ActionsEaseTest" require "luaScript/ActionsProgressTest/ActionsProgressTest" require "luaScript/ActionsTest/ActionsTest" +require "luaScript/AssetsManagerTest/AssetsManagerTest" require "luaScript/BugsTest/BugsTest" require "luaScript/ClickAndMoveTest/ClickAndMoveTest" require "luaScript/CocosDenshionTest/CocosDenshionTest" @@ -58,6 +59,7 @@ local _allTests = { { isSupported = true, name = "ActionsEaseTest" , create_func = EaseActionsTest }, { isSupported = true, name = "ActionsProgressTest" , create_func = ProgressActionsTest }, { isSupported = true, name = "ActionsTest" , create_func = ActionsTest }, + { isSupported = true, name = "AssetsManagerTest" , create_func = AssetsManagerTestMain }, { isSupported = false, name = "Box2dTest" , create_func= Box2dTestMain }, { isSupported = false, name = "Box2dTestBed" , create_func= Box2dTestBedMain }, { isSupported = true, name = "BugsTest" , create_func= BugsTestMain }, diff --git a/tools/tojs/cocos2dx_extension.ini b/tools/tojs/cocos2dx_extension.ini index 1519b2eb92..c91b2545ea 100644 --- a/tools/tojs/cocos2dx_extension.ini +++ b/tools/tojs/cocos2dx_extension.ini @@ -44,7 +44,7 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV onTouch.* onAcc.* onKey.* onRegisterTouchListener], EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler], TableView::[create (g|s)etDataSource$ (g|s)etDelegate], - AssetsManager::[setDelegate], + AssetsManager::[(g|s)etDelegate], AssetsManagerDelegateProtocol::[*], Control::[removeHandleOfControlEvent addHandleOfControlEvent], ControlUtils::[*], diff --git a/tools/tolua/cocos2dx_extension.ini b/tools/tolua/cocos2dx_extension.ini index 67d87c51d6..dd5aa433aa 100644 --- a/tools/tolua/cocos2dx_extension.ini +++ b/tools/tolua/cocos2dx_extension.ini @@ -13,7 +13,7 @@ android_flags = -D_SIZE_T_DEFINED_ clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include clang_flags = -nostdinc -x c++ -std=c++11 -cocos_headers = -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s +cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT cxxgenerator_headers = @@ -26,7 +26,7 @@ headers = %(cocosdir)s/extensions/cocos-ext.h %(cocosdir)s/cocos/editor-support/ # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = CCBReader.* CCBAnimationManager.* Scale9Sprite Control.* ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$ Armature ArmatureAnimation Skin Bone ArmatureDataManager \w+Data$ +classes = AssetsManager.* CCBReader.* CCBAnimationManager.* Scale9Sprite Control.* ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$ Armature ArmatureAnimation Skin Bone ArmatureDataManager \w+Data$ # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -43,6 +43,8 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType (g|s)etDelegate .*HSV], EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler], TableView::[create (g|s)etDataSource$ (g|s)etDelegate], + AssetsManager::[(g|s)etDelegate], + AssetsManagerDelegateProtocol::[*], Control::[removeHandleOfControlEvent addHandleOfControlEvent], ControlUtils::[*], ControlSwitchSprite::[*],