From b282d75346ce2b562a97a566a632b52fcfe5f794 Mon Sep 17 00:00:00 2001 From: VisualSj Date: Wed, 22 Jul 2015 16:51:44 +0800 Subject: [PATCH 1/2] Parse Touch/Click callback in JS Studio parser --- .../studio/parsers/timelineParser-2.x.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js b/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js index 49a017e721b9..ff9d31ff1f2e 100644 --- a/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js +++ b/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js @@ -358,6 +358,28 @@ widget.setColor(getColor(color)); setLayoutComponent(widget, json); + bindCallback(widget, json); + }; + + var bindCallback = function(widget, json){ + var callBackType = json["CallBackType"]; + var callBackName = json["CallBackName"]; + if(callBackType === "Click"){ + widget.addClickEventListener(function(){ + if(widget.onLocateClickCallback) + widget.onLocateClickCallback(callBackName); + }); + }else if(callBackType === "Touch"){ + widget.addTouchEventListener(function(){ + if(widget.onLocateTouchCallback) + widget.onLocateTouchCallback(callBackName); + }); + }else if(callBackType === "Event"){ + widget.addCCSEventListener(function(){ + if(widget.onLocateEventCallback) + widget.onLocateEventCallback(callBackName); + }); + } }; var setLayoutComponent = function(widget, json){ @@ -401,6 +423,7 @@ layoutComponent.setPercentHeightEnabled(sizeYPercentEnable); layoutComponent.setPercentWidth(sizeXPercent); layoutComponent.setPercentHeight(sizeYPercent); + layoutComponent.setPercentWidthEnabled(sizeXPercentEnable || sizeYPercentEnable); layoutComponent.setStretchWidthEnabled(stretchHorizontalEnabled); layoutComponent.setStretchHeightEnabled(stretchVerticalEnabled); From d4900493e2d133c6e53f34769d3b4db583fbe576 Mon Sep 17 00:00:00 2001 From: VisualSj Date: Wed, 22 Jul 2015 17:56:35 +0800 Subject: [PATCH 2/2] JS Studio parser (Modify callback method) --- .../studio/parsers/timelineParser-2.x.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js b/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js index ff9d31ff1f2e..c8ab968f4893 100644 --- a/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js +++ b/cocos/scripting/js-bindings/script/studio/parsers/timelineParser-2.x.js @@ -364,21 +364,16 @@ var bindCallback = function(widget, json){ var callBackType = json["CallBackType"]; var callBackName = json["CallBackName"]; + var callBack = function(e){ + if(typeof widget[callBackName] === "function") + widget[callBackName](e); + }; if(callBackType === "Click"){ - widget.addClickEventListener(function(){ - if(widget.onLocateClickCallback) - widget.onLocateClickCallback(callBackName); - }); + widget.addClickEventListener(callBack); }else if(callBackType === "Touch"){ - widget.addTouchEventListener(function(){ - if(widget.onLocateTouchCallback) - widget.onLocateTouchCallback(callBackName); - }); + widget.addTouchEventListener(callBack); }else if(callBackType === "Event"){ - widget.addCCSEventListener(function(){ - if(widget.onLocateEventCallback) - widget.onLocateEventCallback(callBackName); - }); + widget.addCCSEventListener(callBack); } };