From b72f9222879a5d0dd89ddde3ba174356ad08730f Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 5 Nov 2012 18:43:12 +0800 Subject: [PATCH] issue #1549: Sync jsb_constants_cocos2d.js and jsb_constants_cocosbuilder.js to -iphone version. --- .../bindings/jsb_constants_cocos2d.js | 31 +++++++----- .../bindings/jsb_constants_cocosbuilder.js | 50 +++++++++---------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/samples/TestJavascript/bindings/jsb_constants_cocos2d.js b/samples/TestJavascript/bindings/jsb_constants_cocos2d.js index 06eebf90e8..025d19453b 100644 --- a/samples/TestJavascript/bindings/jsb_constants_cocos2d.js +++ b/samples/TestJavascript/bindings/jsb_constants_cocos2d.js @@ -283,20 +283,26 @@ cc.dumpConfig = function () { // Bindings Overrides // // MenuItemToggle -cc.MenuItemToggle.create = function (/* var args */) { +cc.MenuItemToggle.create = function( /* var args */) { var n = arguments.length; - if (typeof arguments[n - 1] === 'function') { + if (typeof arguments[n-2] === 'function' || typeof arguments[n-1] === 'function') { var args = Array.prototype.slice.call(arguments); + var obj = null; + if( typeof arguments[n-2] === 'function' ) + obj = args.pop(); + var func = args.pop(); - var obj = args.pop(); // create it with arguments, var item = cc.MenuItemToggle._create.apply(this, args); // then set the callback - item.setCallback(obj, func); + if( obj !== null ) + item.setCallback(func, obj); + else + item.setCallback(func); return item; } else { return cc.MenuItemToggle._create.apply(this, arguments); @@ -304,17 +310,16 @@ cc.MenuItemToggle.create = function (/* var args */) { }; // LabelAtlas -// TODO: -// cc.LabelAtlas.create = function (a, b, c, d, e) { +cc.LabelAtlas.create = function( a,b,c,d,e ) { -// var n = arguments.length; + var n = arguments.length; -// if (n == 5) { -// return cc.LabelAtlas._create(a, b, c, d, e.charCodeAt(0)); -// } else { -// return cc.LabelAtlas._create.apply(this, arguments); -// } -// }; + if ( n == 5) { + return cc.LabelAtlas._create(a,b,c,d,e.charCodeAt(0)); + } else { + return cc.LabelAtlas._create.apply(this, arguments); + } +}; /** * Associates a base class with a native superclass diff --git a/samples/TestJavascript/bindings/jsb_constants_cocosbuilder.js b/samples/TestJavascript/bindings/jsb_constants_cocosbuilder.js index a4d33fb89d..306c5e7934 100644 --- a/samples/TestJavascript/bindings/jsb_constants_cocosbuilder.js +++ b/samples/TestJavascript/bindings/jsb_constants_cocosbuilder.js @@ -11,7 +11,7 @@ cc.Reader.load = function(file, owner, parentSize) // Load the node graph using the correct function var reader = cc._Reader.create(); var node; - + if (owner && parentSize) { node = reader.load(file, owner, parentSize); @@ -24,87 +24,87 @@ cc.Reader.load = function(file, owner, parentSize) { node = reader.load(file); } - + // Assign owner callbacks & member variables if (owner) { // Callbacks var ownerCallbackNames = reader.getOwnerCallbackNames(); var ownerCallbackNodes = reader.getOwnerCallbackNodes(); - + for (var i = 0; i < ownerCallbackNames.length; i++) { var callbackName = ownerCallbackNames[i]; var callbackNode = ownerCallbackNodes[i]; - - callbackNode.setCallback(owner, owner[callbackName]); + + callbackNode.setCallback(owner[callbackName], owner); } - + // Variables var ownerOutletNames = reader.getOwnerOutletNames(); var ownerOutletNodes = reader.getOwnerOutletNodes(); - + for (var i = 0; i < ownerOutletNames.length; i++) { var outletName = ownerOutletNames[i]; var outletNode = ownerOutletNodes[i]; - + owner[outletName] = outletNode; } } - + var nodesWithAnimationManagers = reader.getNodesWithAnimationManagers(); var animationManagersForNodes = reader.getAnimationManagersForNodes(); - + // Attach animation managers to nodes and assign root node callbacks and member variables for (var i = 0; i < nodesWithAnimationManagers.length; i++) { var innerNode = nodesWithAnimationManagers[i]; var animationManager = animationManagersForNodes[i]; - + innerNode.animationManager = animationManager; - + var documentControllerName = animationManager.getDocumentControllerName(); if (!documentControllerName) continue; - + // Create a document controller var controller = new _ccbGlobalContext[documentControllerName](); controller.controllerName = documentControllerName; - + innerNode.controller = controller; controller.rootNode = innerNode; - + // Callbacks var documentCallbackNames = animationManager.getDocumentCallbackNames(); var documentCallbackNodes = animationManager.getDocumentCallbackNodes(); - + for (var j = 0; j < documentCallbackNames.length; j++) { var callbackName = documentCallbackNames[j]; var callbackNode = documentCallbackNodes[j]; - - callbackNode.setCallback(controller, controller[callbackName]); + + callbackNode.setCallback(controller[callbackName], controller); } - - + + // Variables var documentOutletNames = animationManager.getDocumentOutletNames(); var documentOutletNodes = animationManager.getDocumentOutletNodes(); - + for (var j = 0; j < documentOutletNames.length; j++) { var outletName = documentOutletNames[j]; var outletNode = documentOutletNodes[j]; - + controller[outletName] = outletNode; } - + if (typeof(controller.onDidLoadFromCCB) == "function") { controller.onDidLoadFromCCB(); } } - + return node; } @@ -113,6 +113,6 @@ cc.Reader.loadAsScene = function(file, owner, parentSize) var node = cc.Reader.load(file, owner, parentSize); var scene = cc.Scene.create(); scene.addChild( node ); - + return scene; }