Merge pull request #3413 from dumganhar/iss2521-js-ccb-owner

Adding more ExtensionTest like CocosBuilderTest and ControlButtonTest and bug fix in CCBReader.
This commit is contained in:
James Chen 2013-08-15 04:19:17 -07:00
commit 9dbd74d2a8
13 changed files with 173 additions and 71 deletions

View File

@ -636,7 +636,7 @@ std::string FileUtils::fullPathForFilename(const char* filename)
for (auto resOrderIter = _searchResolutionsOrderArray.begin();
resOrderIter != _searchResolutionsOrderArray.end(); ++resOrderIter) {
// CCLOG("\n\nSEARCHING: %s, %s, %s", newFilename.c_str(), resOrderIter->c_str(), searchPathsIter->c_str());
// CCLOG("SEARCHING: %s\n", std::string(*searchPathsIter + *resOrderIter + newFilename).c_str() );
fullpath = this->getPathForFilename(newFilename, *resOrderIter, *searchPathsIter);
@ -644,7 +644,7 @@ std::string FileUtils::fullPathForFilename(const char* filename)
{
// Using the filename passed in as key.
_fullPathCache.insert(std::pair<std::string, std::string>(filename, fullpath));
// CCLOG("Returning path: %s", fullpath.c_str());
// CCLOG("Returning path: %s\n", fullpath.c_str());
return fullpath;
}
}

View File

@ -42,6 +42,7 @@ bool CCBAnimationManager::init()
_documentOutletNodes = new Array();
_documentCallbackNames = new Array();
_documentCallbackNodes = new Array();
_documentCallbackControlEvents = new Array();
_keyframeCallbacks = new Array();
_keyframeCallFuncs = new Dictionary();
@ -76,6 +77,7 @@ CCBAnimationManager::~CCBAnimationManager()
CC_SAFE_RELEASE(_documentOutletNodes);
CC_SAFE_RELEASE(_documentCallbackNames);
CC_SAFE_RELEASE(_documentCallbackNodes);
CC_SAFE_RELEASE(_documentCallbackControlEvents);
CC_SAFE_RELEASE(_keyframeCallFuncs);
CC_SAFE_RELEASE(_keyframeCallbacks);
@ -130,6 +132,11 @@ void CCBAnimationManager::addDocumentCallbackName(std::string name) {
_documentCallbackNames->addObject(tmpName);
}
void CCBAnimationManager::addDocumentCallbackControlEvents(Control::EventType eventType)
{
_documentCallbackControlEvents->addObject(Integer::create((int)eventType));
}
Array* CCBAnimationManager::getDocumentCallbackNames() {
return _documentCallbackNames;
}
@ -138,6 +145,11 @@ Array* CCBAnimationManager::getDocumentCallbackNodes() {
return _documentCallbackNodes;
}
Array* CCBAnimationManager::getDocumentCallbackControlEvents()
{
return _documentCallbackControlEvents;
}
void CCBAnimationManager::addDocumentOutletNode(Node *node) {
_documentOutletNodes->addObject(node);
}

View File

@ -6,6 +6,7 @@
#include "CCBSequence.h"
#include "CCBValue.h"
#include "CCBSequenceProperty.h"
#include "GUI/CCControlExtension/CCControl.h"
NS_CC_EXT_BEGIN
@ -40,6 +41,8 @@ public:
void addDocumentCallbackNode(Node *node);
void addDocumentCallbackName(std::string name);
void addDocumentCallbackControlEvents(Control::EventType eventType);
void addDocumentOutletNode(Node *node);
void addDocumentOutletName(std::string name);
@ -48,6 +51,8 @@ public:
std::string getDocumentControllerName();
Array* getDocumentCallbackNames();
Array* getDocumentCallbackNodes();
Array* getDocumentCallbackControlEvents();
Array* getDocumentOutletNames();
Array* getDocumentOutletNodes();
std::string getLastCompletedSequenceName();
@ -121,6 +126,7 @@ private:
Array *_documentOutletNodes;
Array *_documentCallbackNames;
Array *_documentCallbackNodes;
Array *_documentCallbackControlEvents;
Array *_keyframeCallbacks;
Dictionary *_keyframeCallFuncs;

View File

@ -65,7 +65,6 @@ CCBReader::CCBReader(NodeLoaderLibrary * pNodeLoaderLibrary, CCBMemberVariableAs
, _nodesWithAnimationManagers(NULL)
, _animationManagersForNodes(NULL)
, _ownerCallbackNodes(NULL)
, _hasScriptingOwner(false)
{
this->_nodeLoaderLibrary = pNodeLoaderLibrary;
this->_nodeLoaderLibrary->retain();
@ -88,7 +87,6 @@ CCBReader::CCBReader(CCBReader * ccbReader)
, _nodesWithAnimationManagers(NULL)
, _animationManagersForNodes(NULL)
, _ownerCallbackNodes(NULL)
, _hasScriptingOwner(false)
{
this->_loadedSpriteSheets = ccbReader->_loadedSpriteSheets;
this->_nodeLoaderLibrary = ccbReader->_nodeLoaderLibrary;
@ -97,13 +95,6 @@ CCBReader::CCBReader(CCBReader * ccbReader)
this->_CCBMemberVariableAssigner = ccbReader->_CCBMemberVariableAssigner;
this->_CCBSelectorResolver = ccbReader->_CCBSelectorResolver;
this->_nodeLoaderListener = ccbReader->_nodeLoaderListener;
this->_ownerCallbackNames = ccbReader->_ownerCallbackNames;
this->_ownerCallbackNodes = ccbReader->_ownerCallbackNodes;
this->_ownerCallbackNodes->retain();
this->_ownerOutletNames = ccbReader->_ownerOutletNames;
this->_ownerOutletNodes = ccbReader->_ownerOutletNodes;
this->_ownerOutletNodes->retain();
this->_CCBRootPath = ccbReader->getCCBRootPath();
@ -124,12 +115,12 @@ CCBReader::CCBReader()
, _CCBSelectorResolver(NULL)
, _nodesWithAnimationManagers(NULL)
, _animationManagersForNodes(NULL)
, _hasScriptingOwner(false)
{
init();
}
CCBReader::~CCBReader() {
CCBReader::~CCBReader()
{
CC_SAFE_RELEASE_NULL(_owner);
CC_SAFE_RELEASE_NULL(_data);
@ -139,9 +130,9 @@ CCBReader::~CCBReader() {
_ownerOutletNames.clear();
CC_SAFE_RELEASE(_ownerCallbackNodes);
_ownerCallbackNames.clear();
CC_SAFE_RELEASE(_ownerOwnerCallbackControlEvents);
// Clear string cache.
this->_stringCache.clear();
CC_SAFE_RELEASE(_nodesWithAnimationManagers);
CC_SAFE_RELEASE(_animationManagersForNodes);
@ -162,6 +153,10 @@ const std::string& CCBReader::getCCBRootPath() const
bool CCBReader::init()
{
_ownerOutletNodes = new Array();
_ownerCallbackNodes = new Array();
_ownerOwnerCallbackControlEvents = new Array();
// Setup action manager
CCBAnimationManager *pActionManager = new CCBAnimationManager();
setAnimationManager(pActionManager);
@ -269,8 +264,6 @@ Node* CCBReader::readNodeGraphFromData(Data *pData, Object *pOwner, const Size &
_actionManager->setRootContainerSize(parentSize);
_actionManager->_owner = _owner;
_ownerOutletNodes = new Array();
_ownerCallbackNodes = new Array();
Dictionary* animationManagers = Dictionary::create();
Node *pNodeGraph = readFileWithCleanUp(true, animationManagers);
@ -280,8 +273,10 @@ Node* CCBReader::readNodeGraphFromData(Data *pData, Object *pOwner, const Size &
// Auto play animations
_actionManager->runAnimationsForSequenceIdTweenDuration(_actionManager->getAutoPlaySequenceId(), 0);
}
// Assign actionManagers to userObject
if(_jsControlled) {
if(_jsControlled)
{
_nodesWithAnimationManagers = new Array();
_animationManagersForNodes = new Array();
}
@ -716,8 +711,8 @@ Node * CCBReader::readNodeGraph(Node * pParent)
if(target != NULL)
{
CCBMemberVariableAssigner * targetAsCCBMemberVariableAssigner = dynamic_cast<CCBMemberVariableAssigner *>(target);
if(targetAsCCBMemberVariableAssigner != NULL) {
if(targetAsCCBMemberVariableAssigner != NULL)
{
Dictionary* pCustomPropeties = ccNodeLoader->getCustomProperties();
DictElement* pElement;
CCDICT_FOREACH(pCustomPropeties, pElement)
@ -741,7 +736,8 @@ Node * CCBReader::readNodeGraph(Node * pParent)
/* Read and add children. */
int numChildren = this->readInt(false);
for(int i = 0; i < numChildren; i++) {
for(int i = 0; i < numChildren; i++)
{
Node * child = this->readNodeGraph(node);
node->addChild(child);
}
@ -749,12 +745,16 @@ Node * CCBReader::readNodeGraph(Node * pParent)
// FIX ISSUE #1860: "onNodeLoaded will be called twice if ccb was added as a CCBFile".
// If it's a sub-ccb node, skip notification to NodeLoaderListener since it will be
// notified at LINE #734: Node * child = this->readNodeGraph(node);
if (!isCCBFileNode) {
if (!isCCBFileNode)
{
// Call onNodeLoaded
NodeLoaderListener * nodeAsNodeLoaderListener = dynamic_cast<NodeLoaderListener *>(node);
if(nodeAsNodeLoaderListener != NULL) {
if(nodeAsNodeLoaderListener != NULL)
{
nodeAsNodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
} else if(this->_nodeLoaderListener != NULL) {
}
else if(this->_nodeLoaderListener != NULL)
{
this->_nodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
}
}
@ -991,29 +991,43 @@ bool CCBReader::endsWith(const char* pString, const char* pEnding) {
}
}
bool CCBReader::isJSControlled() {
bool CCBReader::isJSControlled()
{
return _jsControlled;
}
void CCBReader::addOwnerCallbackName(std::string name) {
void CCBReader::addOwnerCallbackName(const std::string& name)
{
_ownerCallbackNames.push_back(name);
}
void CCBReader::addOwnerCallbackNode(Node *node) {
void CCBReader::addOwnerCallbackNode(Node *node)
{
_ownerCallbackNodes->addObject(node);
}
void CCBReader::addOwnerCallbackControlEvents(Control::EventType type)
{
_ownerOwnerCallbackControlEvents->addObject(Integer::create((int)type));
}
void CCBReader::addDocumentCallbackName(std::string name) {
void CCBReader::addDocumentCallbackName(const std::string& name)
{
_actionManager->addDocumentCallbackName(name);
}
void CCBReader::addDocumentCallbackNode(Node *node) {
void CCBReader::addDocumentCallbackNode(Node *node)
{
_actionManager->addDocumentCallbackNode(node);
}
void CCBReader::addDocumentCallbackControlEvents(Control::EventType eventType)
{
_actionManager->addDocumentCallbackControlEvents(eventType);
}
Array* CCBReader::getOwnerCallbackNames() {
Array* CCBReader::getOwnerCallbackNames()
{
Array* pRet = Array::createWithCapacity(_ownerCallbackNames.size());
std::vector<std::string>::iterator it = _ownerCallbackNames.begin();
for (; it != _ownerCallbackNames.end(); ++it)
@ -1024,11 +1038,18 @@ Array* CCBReader::getOwnerCallbackNames() {
return pRet;
}
Array* CCBReader::getOwnerCallbackNodes() {
Array* CCBReader::getOwnerCallbackNodes()
{
return _ownerCallbackNodes;
}
Array* CCBReader::getOwnerOutletNames() {
Array* CCBReader::getOwnerCallbackControlEvents()
{
return _ownerOwnerCallbackControlEvents;
}
Array* CCBReader::getOwnerOutletNames()
{
Array* pRet = Array::createWithCapacity(_ownerOutletNames.size());
std::vector<std::string>::iterator it = _ownerOutletNames.begin();
for (; it != _ownerOutletNames.end(); ++it)
@ -1038,26 +1059,29 @@ Array* CCBReader::getOwnerOutletNames() {
return pRet;
}
Array* CCBReader::getOwnerOutletNodes() {
Array* CCBReader::getOwnerOutletNodes()
{
return _ownerOutletNodes;
}
Array* CCBReader::getNodesWithAnimationManagers() {
Array* CCBReader::getNodesWithAnimationManagers()
{
return _nodesWithAnimationManagers;
}
Array* CCBReader::getAnimationManagersForNodes() {
Array* CCBReader::getAnimationManagersForNodes()
{
return _animationManagersForNodes;
}
void CCBReader::addOwnerOutletName(std::string name)
{
_ownerOutletNames.push_back(name);
}
void CCBReader::addOwnerOutletNode(Node *node)
{
if (NULL != node)
if (NULL == node)
return;
_ownerOutletNodes->addObject(node);

View File

@ -6,7 +6,7 @@
#include <string>
#include <vector>
#include "CCBSequence.h"
#include "GUI/CCControlExtension/CCControl.h"
#define CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(T, METHOD) static T * METHOD() { \
T * ptr = new T(); \
@ -187,28 +187,29 @@ public:
float readFloat();
std::string readCachedString();
bool isJSControlled();
bool readCallbackKeyframesForSeq(CCBSequence* seq);
bool readSoundKeyframesForSeq(CCBSequence* seq);
Array* getOwnerCallbackNames();
Array* getOwnerCallbackNodes();
Array* getOwnerCallbackControlEvents();
Array* getOwnerOutletNames();
Array* getOwnerOutletNodes();
Array* getNodesWithAnimationManagers();
Array* getAnimationManagersForNodes();
Dictionary* getAnimationManagers();
void setAnimationManagers(Dictionary* x); // weak reference
void addOwnerCallbackName(std::string name);
void addOwnerCallbackName(const std::string& name);
void addOwnerCallbackNode(Node *node);
void addOwnerCallbackControlEvents(Control::EventType type);
void addDocumentCallbackName(std::string name);
void addDocumentCallbackName(const std::string& name);
void addDocumentCallbackNode(Node *node);
void addDocumentCallbackControlEvents(Control::EventType eventType);
static float getResolutionScale();
static void setResolutionScale(float scale);
@ -232,6 +233,8 @@ private:
bool getBit();
void alignBits();
bool init();
friend class NodeLoader;
private:
@ -262,12 +265,10 @@ private:
std::vector<std::string> _ownerCallbackNames;
Array* _ownerCallbackNodes;
Array* _ownerOwnerCallbackControlEvents;
std::string _CCBRootPath;
bool _jsControlled;
bool _hasScriptingOwner;
bool init();
};
// end of effects group

View File

@ -800,14 +800,22 @@ BlockData * NodeLoader::parsePropTypeBlock(Node * pNode, Node * pParent, CCBRead
} else {
CCLOG("Unexpected NULL target for selector.");
}
} else {
if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT) {
}
else
{
if (selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
{
ccbReader->addDocumentCallbackNode(pNode);
ccbReader->addDocumentCallbackName(selectorName);
} else {
// Since there isn't a Control::EventType::NONE, add a TOUCH_DOWN type as a placeholder.
ccbReader->addDocumentCallbackControlEvents(Control::EventType::TOUCH_DOWN);
}
else if (selectorTarget == CCBReader::TargetType::OWNER)
{
ccbReader->addOwnerCallbackNode(pNode);
ccbReader->addOwnerCallbackName(selectorName);
// Since there isn't a Control::EventType::NONE, add a TOUCH_DOWN type as a placeholder.
ccbReader->addOwnerCallbackControlEvents(Control::EventType::TOUCH_DOWN);
}
}
}
@ -884,12 +892,13 @@ BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * pP
{
ccbReader->addDocumentCallbackNode(pNode);
ccbReader->addDocumentCallbackName(selectorName);
ccbReader->addDocumentCallbackControlEvents((Control::EventType)controlEvents);
}
else
{
ccbReader->addOwnerCallbackNode(pNode);
ccbReader->addOwnerCallbackName(selectorName);
ccbReader->addOwnerCallbackControlEvents((Control::EventType)controlEvents);
}
}
}
@ -953,11 +962,13 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
if (NULL != ownerCallbackNames && ownerCallbackNames->count() > 0 &&
NULL != ownerCallbackNodes && ownerCallbackNodes->count() > 0)
{
assert(ownerCallbackNames->count() == ownerCallbackNodes->count());
CCASSERT(ownerCallbackNames->count() == ownerCallbackNodes->count(), "");
int nCount = ownerCallbackNames->count();
for (int i = 0 ; i < nCount; i++) {
for (int i = 0 ; i < nCount; i++)
{
pCCBReader->addOwnerCallbackName((dynamic_cast<String*>(ownerCallbackNames->objectAtIndex(i)))->getCString());
pCCBReader->addOwnerCallbackNode(dynamic_cast<Node*>(ownerCallbackNames->objectAtIndex(i)) );
pCCBReader->addOwnerCallbackNode(dynamic_cast<Node*>(ownerCallbackNodes->objectAtIndex(i)) );
}
}
//set variables
@ -966,11 +977,13 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
if (NULL != ownerOutletNames && ownerOutletNames->count() > 0 &&
NULL != ownerOutletNodes && ownerOutletNodes->count() > 0)
{
assert(ownerOutletNames->count() == ownerOutletNodes->count());
CCASSERT(ownerOutletNames->count() == ownerOutletNodes->count(), "");
int nCount = ownerOutletNames->count();
for (int i = 0 ; i < nCount; i++) {
pCCBReader->addOwnerOutletName((dynamic_cast<String*>(ownerOutletNames->objectAtIndex(i)))->getCString());
pCCBReader->addOwnerOutletNode(dynamic_cast<Node*>(ownerOutletNodes->objectAtIndex(i)) );
for (int i = 0 ; i < nCount; i++)
{
pCCBReader->addOwnerOutletName((static_cast<String*>(ownerOutletNames->objectAtIndex(i)))->getCString());
pCCBReader->addOwnerOutletNode(static_cast<Node*>(ownerOutletNodes->objectAtIndex(i)));
}
}
}

View File

@ -63,6 +63,7 @@ public:
virtual double getValue() const;
virtual void setStepValue(double stepValue);
/** Set the numeric value of the stepper. If send is true, the Control::EventType::VALUE_CHANGED is sent. */
virtual void setValueWithSendingEvent(double value, bool send);
virtual bool isContinuous() const;
@ -75,9 +76,6 @@ public:
/** Update the layout of the stepper with the given touch location. */
void updateLayoutUsingTouchLocation(Point location);
/** Set the numeric value of the stepper. If send is true, the Control::EventType::VALUE_CHANGED is sent. */
void setValue(double value, bool send);
/** Start the autorepeat increment/decrement. */
void startAutorepeat();

@ -1 +1 @@
Subproject commit dddaff578b31436a0a18c7420428e91e7d9d2df4
Subproject commit 4a4179ed52d2236a3c2780456b77c24a600bfe3e

View File

@ -12,6 +12,7 @@
#include "jsb_opengl_registration.h"
#include "XMLHTTPRequest.h"
#include "jsb_websocket.h"
#include "js_bindings_ccbreader.h"
USING_NS_CC;
USING_NS_CC_EXT;
@ -50,7 +51,8 @@ bool AppDelegate::applicationDidFinishLaunching()
sc->addRegisterCallback(jsb_register_system);
sc->addRegisterCallback(MinXmlHttpRequest::_js_register);
sc->addRegisterCallback(register_jsb_websocket);
sc->addRegisterCallback(register_CCBuilderReader);
sc->start();
ScriptEngineProtocol *pEngine = ScriptingCore::getInstance();

View File

@ -1 +1 @@
a9b4d7898c51c7cc4c1e53fde4695cf85e32d796
d17c1939227c62cebcc30a071cf81b12bfa08db3

View File

@ -133,6 +133,20 @@ cc._c4b = function( r, g, b, a )
cc.c4 = cc.c4b;
cc._c4 = cc._c4b;
/**
* convert Color3B to a string of color for style.
* e.g. Color3B(255,6,255) to : "#ff06ff"
* @param clr
* @return {String}
*/
cc.convertColor3BtoHexString = function (clr) {
var hR = clr.r.toString(16);
var hG = clr.g.toString(16);
var hB = clr.b.toString(16);
var stClr = "#" + (clr.r < 16 ? ("0" + hR) : hR) + (clr.g < 16 ? ("0" + hG) : hG) + (clr.b < 16 ? ("0" + hB) : hB);
return stClr;
};
//
// Color 4F
//

View File

@ -40,7 +40,22 @@ cc.BuilderReader.load = function(file, owner, parentSize)
var callbackName = ownerCallbackNames[i];
var callbackNode = ownerCallbackNodes[i];
callbackNode.setCallback(owner[callbackName], owner);
if (owner[callbackName] === undefined)
{
cc.log("Warning: " + "owner." + callbackName + " is undefined.");
}
else
{
if(callbackNode instanceof cc.ControlButton)
{
var ownerCallbackControlEvents = reader.getOwnerCallbackControlEvents();
callbackNode.addTargetWithActionForControlEvents(owner, owner[callbackName], ownerCallbackControlEvents[i]);
}
else
{
callbackNode.setCallback(owner[callbackName], owner);
}
}
}
// Variables
@ -86,7 +101,22 @@ cc.BuilderReader.load = function(file, owner, parentSize)
var callbackName = documentCallbackNames[j];
var callbackNode = documentCallbackNodes[j];
callbackNode.setCallback(controller[callbackName], controller);
if (controller[callbackName] === undefined)
{
cc.log("Warning: " + documentControllerName + "." + callbackName + " is undefined.");
}
else
{
if(callbackNode instanceof cc.ControlButton)
{
var documentCallbackControlEvents = animationManager.getDocumentCallbackControlEvents();
callbackNode.addTargetWithActionForControlEvents(controller, controller[callbackName], documentCallbackControlEvents[j]);
}
else
{
callbackNode.setCallback(controller[callbackName], controller);
}
}
}
@ -145,4 +175,4 @@ cc.BuilderReader.loadAsScene = function(file, owner, parentSize)
scene.addChild( node );
return scene;
};
};

View File

@ -26,7 +26,7 @@ headers = %(cocosdir)s/extensions/cocos-ext.h
# 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$
classes = CCBReader.* CCBAnimationManager.* Scale9Sprite Control.* ControlButton.* ScrollView$ TableView$ TableViewCell$ EditBox$
# 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
@ -40,10 +40,12 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC
ScrollView::[(g|s)etDelegate$],
.*Delegate::[*],
.*Loader.*::[*],
*::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType],
*::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*HSV],
EditBox::[(g|s)etDelegate ^keyboard.* touchDownAction getScriptEditBoxHandler registerScriptEditBoxHandler unregisterScriptEditBoxHandler],
TableView::[create (g|s)etDataSource$ (g|s)etDelegate],
Control::[removeHandleOfControlEvent addHandleOfControlEvent]
Control::[removeHandleOfControlEvent addHandleOfControlEvent],
ControlUtils::[*],
ControlSwitchSprite::[*]
rename_functions = CCBReader::[getAnimationManager=getActionManager setAnimationManager=setActionManager],
CCBAnimationManager::[setCallFunc=setCallFuncForJSCallbackNamed]