Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3-gcsplitadapter

This commit is contained in:
Dhilan007 2014-07-01 19:10:15 +08:00
commit 6294a3024f
34 changed files with 2027 additions and 479 deletions

View File

@ -32,6 +32,7 @@ cocos2d-x-3.2 ???
[FIX] UIListView: element position is changed a little when you click and up a list view without move [FIX] UIListView: element position is changed a little when you click and up a list view without move
[FIX] UIListView: element will respond to item_end event when end of scrolling a list view [FIX] UIListView: element will respond to item_end event when end of scrolling a list view
[FIX] UIVideo: crash when try to remove videoView(STATE_PLAYBACK_COMPLETED) on android [FIX] UIVideo: crash when try to remove videoView(STATE_PLAYBACK_COMPLETED) on android
[FIX] WP8: crash of utils::captureScreen()
cocos2d-x-3.2-alpha0 Jun.17 2014 cocos2d-x-3.2-alpha0 Jun.17 2014
[NEW] Console: add a command to show engine version [NEW] Console: add a command to show engine version

View File

@ -180,7 +180,7 @@ void FastTMXLayer::onDraw(int offset, int count)
GL::bindTexture2D(_texture->getName()); GL::bindTexture2D(_texture->getName());
getGLProgramState()->apply(_modelViewTransform); getGLProgramState()->apply(_modelViewTransform);
glBindVertexArray(0); GL::bindVAO(0);
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]); glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);

View File

@ -861,24 +861,25 @@ void Node::enumerateChildren(const std::string &name, std::function<bool (Node *
} }
} }
// TODO: support ends with '/..'
// End with '/..'? // End with '/..'?
bool searchFromParent = false; // bool searchFromParent = false;
if (length > 3 && // if (length > 3 &&
name[length-3] == '/' && // name[length-3] == '/' &&
name[length-2] == '.' && // name[length-2] == '.' &&
name[length-1] == '.') // name[length-1] == '.')
{ // {
searchFromParent = true; // searchFromParent = true;
subStrlength -= 3; // subStrlength -= 3;
} // }
// Remove '/', '//' and '/..' if exist // Remove '/', '//' if exist
std::string newName = name.substr(subStrStartPos, subStrlength); std::string newName = name.substr(subStrStartPos, subStrlength);
// If search from parent, then add * at first to make it match its children, which will do make // If search from parent, then add * at first to make it match its children, which will do make
if (searchFromParent) // if (searchFromParent)
{ // {
newName.insert(0, "[[:alnum:]]+/"); // newName.insert(0, "[[:alnum:]]+/");
} // }
if (searchFromRoot) if (searchFromRoot)
{ {
@ -943,10 +944,14 @@ bool Node::doEnumerate(std::string name, std::function<bool (Node *)> callback)
needRecursive = true; needRecursive = true;
} }
std::hash<std::string> h;
size_t hashOfName = h(searchName);
bool ret = false; bool ret = false;
for (const auto& child : _children) for (const auto& child : _children)
{ {
if(std::regex_match(child->_name, std::regex(searchName))) // TODO: regular expression support
// Android doesn't support c++ 11 regular expression well, may use external lib
if (hashOfName == child->_hashOfName && searchName.compare(child->_name) == 0)
{ {
if (!needRecursive) if (!needRecursive)
{ {

View File

@ -714,20 +714,17 @@ public:
virtual Node* getChildByName(const std::string& name) const; virtual Node* getChildByName(const std::string& name) const;
/** Search the children of the receiving node to perform processing for nodes which share a name. /** Search the children of the receiving node to perform processing for nodes which share a name.
* *
* @param name The name to search for, support c++11 regular expression * @param name The name to search for
* Search syntax options: * Search syntax options:
* `/` : When placed at the start of the search string, this indicates that the search should be performed on the tree's node. * `/` : When placed at the start of the search string, this indicates that the search should be performed on the tree's node.
* `//`: Can only be placed at the begin of the search string. This indicates that the search should be performed on the tree's node * `//`: Can only be placed at the begin of the search string. This indicates that the search should be performed on the tree's node
* and be performed recursively across the entire node tree. * and be performed recursively across the entire node tree.
* `..`: The search should move up to the node's parent. Can only be placed at the end of string
* `/` : When placed anywhere but the start of the search string, this indicates that the search should move to the node's children * `/` : When placed anywhere but the start of the search string, this indicates that the search should move to the node's children
* *
* @code * @code
* enumerateChildren("/MyName", ...): This searches the root's children and matches any node with the name `MyName`. * enumerateChildren("/MyName", ...): This searches the root's children and matches any node with the name `MyName`.
* enumerateChildren("//MyName", ...): This searches the root's children recursively and matches any node with the name `MyName`. * enumerateChildren("//MyName", ...): This searches the root's children recursively and matches any node with the name `MyName`.
* enumerateChildren("[[:alnum:]]+", ...): This search string matches every node of its children.
* enumerateChildren("/MyName", ...): This searches the node tree and matches the parent node of every node named `MyName`. * enumerateChildren("/MyName", ...): This searches the node tree and matches the parent node of every node named `MyName`.
* enumerateChildren("A[[:digit:]]", ...): This searches the node's children and returns any child named `A0`, `A1`, ..., `A9`
* enumerateChildren("Abby/Normal", ...): This searches the node's grandchildren and returns any node whose name is `Normal` * enumerateChildren("Abby/Normal", ...): This searches the node's grandchildren and returns any node whose name is `Normal`
* and whose parent is named `Abby`. * and whose parent is named `Abby`.
* enumerateChildren("//Abby/Normal", ...): This searches the node tree and returns any node whose name is `Normal` and whose * enumerateChildren("//Abby/Normal", ...): This searches the node tree and returns any node whose name is `Normal` and whose

View File

@ -72,19 +72,50 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
} }
glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
// The frame buffer is always created with portrait orientation on WP8.
// So if the current device orientation is landscape, we need to rotate the frame buffer.
auto renderTargetSize = glView->getRenerTargetSize();
CCASSERT(width * height == static_cast<int>(renderTargetSize.width * renderTargetSize.height), "The frame size is not matched");
glReadPixels(0, 0, (int)renderTargetSize.width, (int)renderTargetSize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
#else
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get()); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
#endif
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); }); std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
if (!flippedBuffer) if (!flippedBuffer)
{ {
break; break;
} }
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
if (width == static_cast<int>(renderTargetSize.width))
{
// The current device orientation is portrait.
for (int row = 0; row < height; ++row)
{
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
}
}
else
{
// The current device orientation is landscape.
for (int row = 0; row < width; ++row)
{
for (int col = 0; col < height; ++col)
{
*(int*)(flippedBuffer.get() + (height - col - 1) * width * 4 + row * 4) = *(int*)(buffer.get() + row * height * 4 + col * 4);
}
}
}
#else
for (int row = 0; row < height; ++row) for (int row = 0; row < height; ++row)
{ {
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4); memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
} }
#endif
std::shared_ptr<Image> image(new Image); std::shared_ptr<Image> image(new Image);
if (image) if (image)
{ {

View File

@ -144,14 +144,42 @@ ComAttribute* ComAttribute::create(void)
bool ComAttribute::serialize(void* r) bool ComAttribute::serialize(void* r)
{ {
bool bRet = false; bool ret = false;
do do
{ {
CC_BREAK_IF(r == nullptr); CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r; SerData *serData = (SerData *)(r);
const char *className = DICTOOL->getStringValue_json(*v, "classname"); const rapidjson::Value *v = serData->_rData;
CC_BREAK_IF(className == nullptr); stExpCocoNode *cocoNode = serData->_cocoNode;
const char *comName = DICTOOL->getStringValue_json(*v, "name"); const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
std::string filePath;
int resType = 0;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
}
else if (cocoNode != nullptr)
{
className = cocoNode[1].GetValue();
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue();
stExpCocoNode *fileData = cocoNode[3].GetChildArray();
CC_BREAK_IF(!fileData);
file = fileData[0].GetValue();
CC_BREAK_IF(file == nullptr);
resType = atoi(fileData[2].GetValue());
CC_BREAK_IF(resType != 0);
}
if (comName != nullptr) if (comName != nullptr)
{ {
setName(comName); setName(comName);
@ -160,22 +188,17 @@ bool ComAttribute::serialize(void* r)
{ {
setName(className); setName(className);
} }
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
std::string filePath;
if (file != nullptr) if (file != nullptr)
{ {
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file)); filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
} }
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1); if (parse(filePath.c_str()))
CC_BREAK_IF(resType != 0); {
parse(filePath.c_str()); ret = true;
bRet = true; }
} while (0);
}while (0);
return bRet; return ret;
} }
bool ComAttribute::parse(const std::string &jsonFile) bool ComAttribute::parse(const std::string &jsonFile)

View File

@ -69,14 +69,46 @@ void ComAudio::setEnabled(bool b)
bool ComAudio::serialize(void* r) bool ComAudio::serialize(void* r)
{ {
bool bRet = false; bool ret = false;
do do
{ {
CC_BREAK_IF(r == nullptr); CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r; SerData *serData = (SerData *)(r);
const char *className = DICTOOL->getStringValue_json(*v, "classname"); const rapidjson::Value *v = serData->_rData;
CC_BREAK_IF(className == nullptr); stExpCocoNode *cocoNode = serData->_cocoNode;
const char *comName = DICTOOL->getStringValue_json(*v, "name"); const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
std::string filePath;
int resType = 0;
bool loop = false;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
loop = DICTOOL->getIntValue_json(*v, "loop") != 0? true:false;
}
else if (cocoNode != nullptr)
{
className = cocoNode[1].GetValue();
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue();
stExpCocoNode *pfileData = cocoNode[4].GetChildArray();
CC_BREAK_IF(!pfileData);
file = pfileData[0].GetValue();
CC_BREAK_IF(file == nullptr);
resType = atoi(pfileData[2].GetValue());
CC_BREAK_IF(resType != 0);
loop = atoi(cocoNode[5].GetValue()) != 0? true:false;
ret = true;
}
if (comName != nullptr) if (comName != nullptr)
{ {
setName(comName); setName(comName);
@ -85,17 +117,14 @@ bool ComAudio::serialize(void* r)
{ {
setName(className); setName(className);
} }
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
std::string filePath;
if (file != nullptr) if (file != nullptr)
{ {
if (strcmp(file, "") == 0)
{
continue;
}
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file)); filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
} }
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
if (strcmp(className, "CCBackgroundAudio") == 0) if (strcmp(className, "CCBackgroundAudio") == 0)
{ {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
@ -108,9 +137,8 @@ bool ComAudio::serialize(void* r)
filePath.replace(pos, filePath.length(), ".wav"); filePath.replace(pos, filePath.length(), ".wav");
#endif #endif
preloadBackgroundMusic(filePath.c_str()); preloadBackgroundMusic(filePath.c_str());
bool loop = DICTOOL->getIntValue_json(*v, "loop") != 0? true:false;
setLoop(loop); setLoop(loop);
playBackgroundMusic(filePath.c_str(), loop); playBackgroundMusic(filePath.c_str(), loop);
} }
else if(strcmp(className, "CCComAudio") == 0) else if(strcmp(className, "CCComAudio") == 0)
{ {
@ -120,10 +148,9 @@ bool ComAudio::serialize(void* r)
{ {
CC_BREAK_IF(true); CC_BREAK_IF(true);
} }
bRet = true; ret = true;
} while (0); }while (0);
return ret;
return bRet;
} }
ComAudio* ComAudio::create(void) ComAudio* ComAudio::create(void)

View File

@ -28,6 +28,7 @@ THE SOFTWARE.
#include <string> #include <string>
#include "DictionaryHelper.h" #include "DictionaryHelper.h"
#include "base/ObjectFactory.h" #include "base/ObjectFactory.h"
#include "CocoLoader.h"
#define DECLARE_CLASS_COMPONENT_INFO \ #define DECLARE_CLASS_COMPONENT_INFO \
@ -45,5 +46,16 @@ THE SOFTWARE.
#define CREATE_CLASS_COMPONENT_INFO(className) \ #define CREATE_CLASS_COMPONENT_INFO(className) \
cocos2d::ObjectFactory::TInfo(#className, &className::createInstance) cocos2d::ObjectFactory::TInfo(#className, &className::createInstance)
struct SerData
{
const rapidjson::Value *_rData;
cocostudio::stExpCocoNode *_cocoNode;
SerData()
{
_rData = NULL;
_cocoNode = NULL;
}
};
#endif #endif

View File

@ -90,14 +90,44 @@ void ComRender::setNode(cocos2d::Node *node)
bool ComRender::serialize(void* r) bool ComRender::serialize(void* r)
{ {
bool bRet = false; bool ret = false;
do do
{ {
CC_BREAK_IF(r == nullptr); CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r; SerData *serData = (SerData *)(r);
const char *className = DICTOOL->getStringValue_json(*v, "classname"); const rapidjson::Value *v = serData->_rData;
CC_BREAK_IF(className == nullptr); stExpCocoNode *cocoNode = serData->_cocoNode;
const char *comName = DICTOOL->getStringValue_json(*v, "name"); const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
const char *plist = nullptr;
std::string filePath;
std::string plistPath;
int resType = 0;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
plist = DICTOOL->getStringValue_json(fileData, "plistFile");
CC_BREAK_IF(file == nullptr && plist == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
}
else if(cocoNode != nullptr)
{
className = cocoNode[1].GetValue();
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue();
stExpCocoNode *pfileData = cocoNode[4].GetChildArray();
CC_BREAK_IF(!pfileData);
file = pfileData[0].GetValue();
plist = pfileData[1].GetValue();
CC_BREAK_IF(file == nullptr && plist == nullptr);
resType = atoi(pfileData[2].GetValue());
}
if (comName != nullptr) if (comName != nullptr)
{ {
setName(comName); setName(comName);
@ -106,72 +136,175 @@ bool ComRender::serialize(void* r)
{ {
setName(className); setName(className);
} }
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
const char *plist = DICTOOL->getStringValue_json(fileData, "plistFile");
CC_BREAK_IF(file == nullptr && plist == nullptr);
std::string filePath;
std::string plistPath;
if (file != nullptr) if (file != nullptr)
{ {
filePath.assign(cocos2d::CCFileUtils::getInstance()->fullPathForFilename(file)); filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
} }
if (plist != nullptr) if (plist != nullptr)
{ {
plistPath.assign(cocos2d::CCFileUtils::getInstance()->fullPathForFilename(plist)); plistPath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(plist));
} }
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
if (resType == 0) if (resType == 0)
{ {
if (strcmp(className, "CCSprite") == 0 && filePath.find(".png") != std::string::npos) if (strcmp(className, "CCSprite") == 0 && (filePath.find(".png") != filePath.npos || filePath.find(".pvr.ccz") != filePath.npos))
{ {
_render = Sprite::create(filePath.c_str()); _render = CCSprite::create(filePath.c_str());
_render->retain(); _render->retain();
ret = true;
} }
else if(strcmp(className, "CCTMXTiledMap") == 0 && filePath.find(".tmx") != std::string::npos) else if(strcmp(className, "CCTMXTiledMap") == 0 && filePath.find(".tmx") != filePath.npos)
{ {
_render = TMXTiledMap::create(filePath.c_str()); _render = CCTMXTiledMap::create(filePath.c_str());
_render->retain(); _render->retain();
ret = true;
} }
else if(strcmp(className, "CCParticleSystemQuad") == 0 && filePath.find(".plist") != std::string::npos) else if(strcmp(className, "CCParticleSystemQuad") == 0 && filePath.find(".plist") != filePath.npos)
{ {
_render = ParticleSystemQuad::create(filePath.c_str()); _render = CCParticleSystemQuad::create(filePath.c_str());
_render->setPosition(Vec2(0.0f, 0.0f)); _render->setPosition(Point(0.0f, 0.0f));
_render->retain(); _render->retain();
ret = true;
} }
else if(strcmp(className, "CCArmature") == 0) else if(strcmp(className, "CCArmature") == 0)
{ {
std::string reDir = filePath; std::string file_extension = filePath;
std::string file_path = ""; size_t pos = filePath.find_last_of('.');
size_t pos = reDir.find_last_of('/');
if (pos != std::string::npos) if (pos != std::string::npos)
{ {
file_path = reDir.substr(0, pos+1); file_extension = filePath.substr(pos, filePath.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
} }
rapidjson::Document doc; if (file_extension == ".JSON" || file_extension == ".EXPORTJSON")
if(!readJson(filePath.c_str(), doc))
{ {
log("read json file[%s] error!\n", filePath.c_str()); rapidjson::Document doc;
continue; if(!readJson(filePath.c_str(), doc))
{
log("read json file[%s] error!\n", filePath.c_str());
continue;
}
const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0);
const char *name = DICTOOL->getStringValue_json(subData, "name");
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = Armature::create(name);
_render = pAr;
_render->retain();
const char *actionName = nullptr;
if (cocoNode != nullptr)
{
actionName = cocoNode[6].GetValue();//DICTOOL->getStringValue_json(*v, "selectedactionname");
}
else
{
actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
}
if (actionName != nullptr && pAr->getAnimation() != nullptr)
{
pAr->getAnimation()->play(actionName);
}
ret = true;
} }
const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0); else if (file_extension == ".CSB")
const char *name = DICTOOL->getStringValue_json(subData, "name");
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = Armature::create(name);
_render = pAr;
_render->retain();
const char *actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
if (actionName != nullptr && pAr->getAnimation() != nullptr)
{ {
pAr->getAnimation()->play(actionName); ssize_t size = 0;
unsigned char *pBytes = nullptr;
std::string binaryFilePath = FileUtils::getInstance()->fullPathForFilename(filePath.c_str());
pBytes = cocos2d::FileUtils::getInstance()->getFileData(binaryFilePath.c_str(), "rb", &size);
CC_BREAK_IF(pBytes == nullptr || strcmp((char*)pBytes, "") == 0);
CocoLoader tCocoLoader;
if (tCocoLoader.ReadCocoBinBuff((char*)pBytes))
{
stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode();
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType)
{
int count = tpRootCocoNode->GetChildNum();
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray();
for (int i = 0; i < count; ++i)
{
std::string key = tpChildArray[i].GetName(&tCocoLoader);
if (key.compare("armature_data") == 0)
{
int length = tpChildArray[i].GetChildNum();
stExpCocoNode *armature_dataArray = tpChildArray[i].GetChildArray();
if (length < 1)
{
continue;
}
length = armature_dataArray[0].GetChildNum();
stExpCocoNode *armature_data = armature_dataArray[0].GetChildArray();
for (int j = 0; j < length; ++j)
{
std::string key1 = armature_data[j].GetName(&tCocoLoader);
const char *str1 = armature_data[j].GetValue();
if (key.compare("name") == 0)
{
if (str1 != nullptr)
{
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = CCArmature::create(str1);
_render = pAr;
_render->retain();
const char *actionName = nullptr;
if (cocoNode != nullptr)
{
actionName = cocoNode[6].GetValue();
}
else
{
actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
}
if (actionName != nullptr && pAr->getAnimation() != nullptr)
{
pAr->getAnimation()->play(actionName);
}
ret = true;
}
}
}
}
}
}
}
else
{
continue;
}
} }
else
{
continue;
}
} }
else if(strcmp(className, "GUIComponent") == 0) else if(strcmp(className, "GUIComponent") == 0)
{ {
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromJsonFile(filePath.c_str()); std::string file_extension = filePath;
_render = widget; size_t pos = filePath.find_last_of('.');
_render->retain(); if (pos != std::string::npos)
{
file_extension = filePath.substr(pos, filePath.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
if (file_extension == ".JSON" || file_extension == ".EXPORTJSON")
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromJsonFile(filePath.c_str());
_render = widget;
_render->retain();
ret = true;
}
else if (file_extension == ".CSB")
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromBinaryFile(filePath.c_str());
_render = widget;
_render->retain();
ret = true;
}
} }
else else
{ {
@ -190,8 +323,10 @@ bool ComRender::serialize(void* r)
} }
strPngFile.replace(pos, strPngFile.length(), ".png"); strPngFile.replace(pos, strPngFile.length(), ".png");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath.c_str(), strPngFile.c_str()); SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath.c_str(), strPngFile.c_str());
_render = Sprite::createWithSpriteFrameName(filePath.c_str()); _render = CCSprite::createWithSpriteFrameName(filePath.c_str());
_render->retain(); _render->retain();
ret = true;
} }
else else
{ {
@ -202,10 +337,9 @@ bool ComRender::serialize(void* r)
{ {
CC_BREAK_IF(true); CC_BREAK_IF(true);
} }
bRet = true; } while (0);
} while (0);
return ret;
return bRet;
} }
ComRender* ComRender::create(void) ComRender* ComRender::create(void)

View File

@ -56,28 +56,133 @@ const char* SceneReader::sceneReaderVersion()
cocos2d::Node* SceneReader::createNodeWithSceneFile(const std::string &fileName, AttachComponentType attachComponent /*= AttachComponentType::EMPTY_NODE*/) cocos2d::Node* SceneReader::createNodeWithSceneFile(const std::string &fileName, AttachComponentType attachComponent /*= AttachComponentType::EMPTY_NODE*/)
{ {
_node = nullptr; std::string reDir = fileName;
rapidjson::Document jsonDict; std::string file_extension = "";
do { size_t pos = reDir.find_last_of('.');
CC_BREAK_IF(!readJson(fileName, jsonDict)); if (pos != std::string::npos)
_node = createObject(jsonDict, nullptr, attachComponent); {
TriggerMng::getInstance()->parse(jsonDict); file_extension = reDir.substr(pos, reDir.length());
} while (0); std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
return _node; if (file_extension == ".JSON")
{
_node = nullptr;
rapidjson::Document jsonDict;
do {
CC_BREAK_IF(!readJson(fileName, jsonDict));
_node = createObject(jsonDict, nullptr, attachComponent);
TriggerMng::getInstance()->parse(jsonDict);
} while (0);
return _node;
}
else if(file_extension == ".CSB")
{
ssize_t size = 0;
unsigned char *pBytes = nullptr;
do {
std::string binaryFilePath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
pBytes = cocos2d::FileUtils::getInstance()->getFileData(binaryFilePath.c_str(), "rb", &size);
CC_BREAK_IF(pBytes == nullptr || strcmp((char*)pBytes, "") == 0);
CocoLoader tCocoLoader;
if (tCocoLoader.ReadCocoBinBuff((char*)pBytes))
{
stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode();
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType)
{
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray();
CC_BREAK_IF(tpRootCocoNode->GetChildNum() == 0);
_node = Node::create();
int nCount = 0;
std::vector<Component*> _vecComs;
ComRender *pRender = nullptr;
std::string key = tpChildArray[15].GetName(&tCocoLoader);
if (key == "components")
{
nCount = tpChildArray[15].GetChildNum();
}
stExpCocoNode *pComponents = tpChildArray[15].GetChildArray();
SerData *data = new SerData();
for (int i = 0; i < nCount; i++)
{
stExpCocoNode *subDict = pComponents[i].GetChildArray();
if (subDict == nullptr)
{
continue;
}
std::string key = subDict[1].GetName(&tCocoLoader);
const char *comName = subDict[1].GetValue();
Component *pCom = nullptr;
if (key == "classname" && comName != nullptr)
{
pCom = createComponent(comName);
}
CCLOG("classname = %s", comName);
if (pCom != nullptr)
{
data->_rData = nullptr;
data->_cocoNode = subDict;
if (pCom->serialize(data))
{
ComRender *pTRender = dynamic_cast<ComRender*>(pCom);
if (pTRender != nullptr)
{
pRender = pTRender;
}
else
{
_vecComs.push_back(pCom);
}
}
else
{
CC_SAFE_RELEASE_NULL(pCom);
}
}
if(_fnSelector != nullptr)
{
_fnSelector(pCom, (void*)(data));
}
}
setPropertyFromJsonDict(&tCocoLoader, tpRootCocoNode, _node);
for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter)
{
_node->addComponent(*iter);
}
stExpCocoNode *pGameObjects = tpChildArray[11].GetChildArray();
int length = tpChildArray[11].GetChildNum();
for (int i = 0; i < length; ++i)
{
createObject(&tCocoLoader, &pGameObjects[i], _node, attachComponent);
}
TriggerMng::getInstance()->parse(&tCocoLoader, tpChildArray);
}
}
}while (0);
return _node;
}
else
{
log("read file [%s] error!\n", fileName.c_str());
}
return nullptr;
} }
bool SceneReader::readJson(const std::string &fileName, rapidjson::Document &doc) bool SceneReader::readJson(const std::string &fileName, rapidjson::Document &doc)
{ {
bool bRet = false; bool ret = false;
do { do {
std::string jsonpath = FileUtils::getInstance()->fullPathForFilename(fileName); std::string jsonpath = FileUtils::getInstance()->fullPathForFilename(fileName);
std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath); std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath);
doc.Parse<0>(contentStr.c_str()); doc.Parse<0>(contentStr.c_str());
CC_BREAK_IF(doc.HasParseError()); CC_BREAK_IF(doc.HasParseError());
bRet = true; ret = true;
} while (0); } while (0);
return bRet; return ret;
} }
Node* SceneReader::nodeByTag(Node *parent, int tag) Node* SceneReader::nodeByTag(Node *parent, int tag)
@ -172,9 +277,13 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
} }
const char *comName = DICTOOL->getStringValue_json(subDict, "classname"); const char *comName = DICTOOL->getStringValue_json(subDict, "classname");
Component *com = this->createComponent(comName); Component *com = this->createComponent(comName);
CCLOG("classname = %s", comName);
SerData *data = new SerData();
if (com != nullptr) if (com != nullptr)
{ {
if (com->serialize((void*)(&subDict))) data->_rData = &subDict;
data->_cocoNode = nullptr;
if (com->serialize(data))
{ {
ComRender *tRender = dynamic_cast<ComRender*>(com); ComRender *tRender = dynamic_cast<ComRender*>(com);
if (tRender == nullptr) if (tRender == nullptr)
@ -187,9 +296,10 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
} }
} }
} }
CC_SAFE_DELETE(data);
if(_fnSelector != nullptr) if(_fnSelector != nullptr)
{ {
_fnSelector(com, (void*)(&subDict)); _fnSelector(com, data);
} }
} }
@ -234,6 +344,111 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
return nullptr; return nullptr;
} }
cocos2d::Node* SceneReader::createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent)
{
const char *className = nullptr;
stExpCocoNode *pNodeArray = cocoNode->GetChildArray();
std::string Key = pNodeArray[1].GetName(cocoLoader);
if (Key == "classname")
{
className = pNodeArray[1].GetValue();
}
if(strcmp(className, "CCNode") == 0)
{
Node* gb = nullptr;
std::vector<Component*> _vecComs;
ComRender *pRender = nullptr;
int count = 0;
std::string key = pNodeArray[13].GetName(cocoLoader);
if (key == "components")
{
count = pNodeArray[13].GetChildNum();
}
stExpCocoNode *pComponents = pNodeArray[13].GetChildArray();
SerData *data = new SerData();
for (int i = 0; i < count; ++i)
{
stExpCocoNode *subDict = pComponents[i].GetChildArray();
if (subDict == nullptr)
{
continue;
}
std::string key = subDict[1].GetName(cocoLoader);
const char *comName = subDict[1].GetValue();//DICTOOL->getStringValue_json(subDict, "classname");
Component *pCom = nullptr;
if (key == "classname" && comName != nullptr)
{
pCom = createComponent(comName);
}
CCLOG("classname = %s", comName);
if (pCom != nullptr)
{
data->_rData = nullptr;
data->_cocoNode = subDict;
if (pCom->serialize(data))
{
ComRender *pTRender = dynamic_cast<ComRender*>(pCom);
if (pTRender != nullptr)
{
pRender = pTRender;
}
else
{
_vecComs.push_back(pCom);
}
}
else
{
CC_SAFE_RELEASE_NULL(pCom);
}
}
if(_fnSelector != nullptr)
{
_fnSelector(pCom, (void*)(data));
}
}
CC_SAFE_DELETE(data);
if (parent != nullptr)
{
if (pRender == nullptr || attachComponent == AttachComponentType::EMPTY_NODE)
{
gb = CCNode::create();
if (pRender != nullptr)
{
_vecComs.push_back(pRender);
}
}
else
{
gb = pRender->getNode();
gb->retain();
pRender->setNode(nullptr);
CC_SAFE_RELEASE_NULL(pRender);
}
parent->addChild(gb);
}
setPropertyFromJsonDict(cocoLoader, cocoNode, gb);
for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter)
{
gb->addComponent(*iter);
}
stExpCocoNode *pGameObjects = pNodeArray[12].GetChildArray();
if (pGameObjects != nullptr)
{
int length = pNodeArray[12].GetChildNum();
for (int i = 0; i < length; ++i)
{
createObject(cocoLoader, &pGameObjects[i], gb, attachComponent);
}
}
return gb;
}
return nullptr;
}
void SceneReader::setTarget(const std::function<void(cocos2d::Ref* obj, void* doc)>& selector) void SceneReader::setTarget(const std::function<void(cocos2d::Ref* obj, void* doc)>& selector)
{ {
@ -276,6 +491,62 @@ void SceneReader::setPropertyFromJsonDict(const rapidjson::Value &root, cocos2d:
float fRotationZ = DICTOOL->getFloatValue_json(root, "rotation"); float fRotationZ = DICTOOL->getFloatValue_json(root, "rotation");
node->setRotation(fRotationZ); node->setRotation(fRotationZ);
} }
void SceneReader::setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node *node)
{
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
float x = 0.0f, y = 0.0f, fScaleX = 1.0f, fScaleY = 1.0f, fRotationZ = 1.0f;
bool bVisible = false;
int nTag = 0, nZorder = -1;
for (int i = 0; i < cocoNode->GetChildNum(); ++i)
{
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "x")
{
x = atof(value.c_str());
node->setPositionX(x);
}
else if (key == "y")
{
y = atof(value.c_str());
node->setPositionY(y);
}
else if (key == "visible")
{
bVisible = (bool)atoi(value.c_str());
node->setVisible(bVisible);
}
else if (key == "objecttag")
{
nTag = atoi(value.c_str());
node->setTag(nTag);
}
else if (key == "zorder")
{
nZorder = atoi(value.c_str());
node->setZOrder(nZorder);
}
else if(key == "scalex")
{
fScaleX = atof(value.c_str());
node->setScaleX(fScaleX);
}
else if(key == "scaley")
{
fScaleY = atof(value.c_str());
node->setScaleY(fScaleY);
}
else if(key == "rotation")
{
fRotationZ = atof(value.c_str());
node->setRotation(fRotationZ);
}
}
}
SceneReader* SceneReader::getInstance() SceneReader* SceneReader::getInstance()
{ {

View File

@ -76,6 +76,10 @@ private:
cocos2d::Node* createObject(const rapidjson::Value& dict, cocos2d::Node* parent, AttachComponentType attachComponent); cocos2d::Node* createObject(const rapidjson::Value& dict, cocos2d::Node* parent, AttachComponentType attachComponent);
void setPropertyFromJsonDict(const rapidjson::Value& dict, cocos2d::Node *node); void setPropertyFromJsonDict(const rapidjson::Value& dict, cocos2d::Node *node);
bool readJson(const std::string &fileName, rapidjson::Document& doc); bool readJson(const std::string &fileName, rapidjson::Document& doc);
cocos2d::Node* createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent);
void setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node *node);
cocos2d::Node* nodeByTag(cocos2d::Node *parent, int tag); cocos2d::Node* nodeByTag(cocos2d::Node *parent, int tag);
private: private:
static SceneReader* s_sharedReader; static SceneReader* s_sharedReader;

View File

@ -96,8 +96,8 @@ public:
stExpCocoNode* GetChildArray(); stExpCocoNode* GetChildArray();
public: public:
inline void ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr); inline void ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr);
void WriteJson(CocoLoader* pCoco, void* pFileName = NULL, int vLayer = 0, bool bEndNode = false, bool bParentNodeIsArray = false); void WriteJson(CocoLoader* pCoco, void* pFileName = NULL, int vLayer = 0, bool bEndNode = false, bool bParentNodeIsArray = false);
}; };

View File

@ -104,6 +104,44 @@ void TriggerMng::parse(const rapidjson::Value &root)
} }
} }
} }
void TriggerMng::parse(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
CCLOG("%s", triggerMngVersion());
int count = pCocoNode[13].GetChildNum();
stExpCocoNode *pTriggersArray = pCocoNode[13].GetChildArray();
#if CC_ENABLE_SCRIPT_BINDING
ScriptEngineProtocol* engine = ScriptEngineManager::getInstance()->getScriptEngine();
bool useBindings = engine != NULL;
if (useBindings)
{
if (count > 0 )
{
rapidjson::Document document;
buildJson(document, pCocoLoader, pCocoNode);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
document.Accept(writer);
engine->parseConfig(ScriptEngineProtocol::ConfigType::COCOSTUDIO, buffer.GetString());
}
}
else
#endif // #if CC_ENABLE_SCRIPT_BINDING
{
for (int i = 0; i < count; ++i)
{
TriggerObj *obj = TriggerObj::create();
obj->serialize(pCocoLoader, &pTriggersArray[i]);
_triggerObjs.insert(std::pair<unsigned int, TriggerObj*>(obj->getId(), obj));
obj->retain();
}
}
}
TriggerObj* TriggerMng::getTriggerObj(unsigned int id) const TriggerObj* TriggerMng::getTriggerObj(unsigned int id) const
{ {
@ -152,6 +190,217 @@ bool TriggerMng::isEmpty(void) const
return _triggerObjs.empty(); return _triggerObjs.empty();
} }
void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int count = pCocoNode[13].GetChildNum();
int length = 0;
int num = 0;
int size = 0;
int extent = 0;
int border = 0;
std::string key;
stExpCocoNode *pTriggersArray = pCocoNode[13].GetChildArray();
document.SetArray();
rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
for (int i = 0; i < count; ++i)
{
rapidjson::Value vElemItem(rapidjson::kObjectType);
border = pTriggersArray[i].GetChildNum();
stExpCocoNode *pTriggerArray = pTriggersArray[i].GetChildArray();
for (int i = 0; i < border; ++i)
{
std::string key = pTriggerArray[i].GetName(pCocoLoader);
const char *str = pTriggerArray[i].GetValue();
rapidjson::Type type = pTriggerArray[i].GetType(pCocoLoader);
if (key.compare("actions") == 0)
{
rapidjson::Value actionsItem(rapidjson::kArrayType);
length = pTriggerArray[i].GetChildNum();
stExpCocoNode *pActionsArray = pTriggerArray[i].GetChildArray();
for (int i = 0; i < length; ++i)
{
rapidjson::Value action(rapidjson::kObjectType);
num = pActionsArray[i].GetChildNum();
stExpCocoNode *pActionArray = pActionsArray[i].GetChildArray();
for (int i = 0; i < num; ++i)
{
std::string key = pActionArray[i].GetName(pCocoLoader);
const char *str = pActionArray[i].GetValue();
if (key.compare("classname") == 0)
{
if (str != NULL)
{
action.AddMember("classname", str, allocator);
}
}
else if (key.compare("dataitems") == 0)
{
rapidjson::Value dataitems(rapidjson::kArrayType);
size = pActionArray[i].GetChildNum();
stExpCocoNode *pDataItemsArray = pActionArray[i].GetChildArray();
for (int i = 0; i < size; ++i)
{
rapidjson::Value dataitem(rapidjson::kObjectType);
extent = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
for (int i = 0; i < extent; ++i)
{
std::string key = pDataItemArray[i].GetName(pCocoLoader);
const char *str = pDataItemArray[i].GetValue();
if (key.compare("key") == 0)
{
if (str != NULL)
{
dataitem.AddMember("key", str, allocator);
}
}
else
{
rapidjson::Type type = pDataItemArray[i].GetType(pCocoLoader);
if (type == rapidjson::kStringType)
{
dataitem.AddMember("value", str, allocator);
}
else if(type == rapidjson::kNumberType)
{
int nV = atoi(str);
float fV = atof(str);
if (fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
else
{
dataitem.AddMember("value", fV, allocator);
}
}
}
}
dataitems.PushBack(dataitem, allocator);
}
action.AddMember("dataitems", dataitems, allocator);
}
}
actionsItem.PushBack(action, allocator);
}
vElemItem.AddMember("actions", actionsItem, allocator);
}
else if (key.compare("conditions") == 0)
{
rapidjson::Value condsItem(rapidjson::kArrayType);
length = pTriggerArray[i].GetChildNum();
stExpCocoNode *pConditionsArray = pTriggerArray[i].GetChildArray();
for (int i = 0; i < length; ++i)
{
rapidjson::Value cond(rapidjson::kObjectType);
num = pConditionsArray[i].GetChildNum();
stExpCocoNode *pConditionArray = pConditionsArray[i].GetChildArray();
for (int i = 0; i < num; ++i)
{
std::string key = pConditionArray[i].GetName(pCocoLoader);
const char *str = pConditionArray[i].GetValue();
if (key.compare("classname") == 0)
{
if (str != NULL)
{
cond.AddMember("classname", str, allocator);
}
}
else if (key.compare("dataitems") == 0)
{
rapidjson::Value dataitems(rapidjson::kArrayType);
size = pConditionArray[i].GetChildNum();
stExpCocoNode *pDataItemsArray = pConditionArray[i].GetChildArray();
for (int i = 0; i < size; ++i)
{
rapidjson::Value dataitem(rapidjson::kObjectType);
extent = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
for (int i = 0; i < extent; ++i)
{
std::string key = pDataItemArray[i].GetName(pCocoLoader);
const char *str = pDataItemArray[i].GetValue();
if (key.compare("key") == 0)
{
if (str != NULL)
{
dataitem.AddMember("key", str, allocator);
}
}
else
{
rapidjson::Type type = pDataItemArray[i].GetType(pCocoLoader);
if (type == rapidjson::kStringType)
{
dataitem.AddMember("value", str, allocator);
}
else if(type == rapidjson::kNumberType)
{
int nV = atoi(str);
float fV = atof(str);
if (fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
else
{
dataitem.AddMember("value", fV, allocator);
}
}
}
}
dataitems.PushBack(dataitem, allocator);
}
cond.AddMember("dataitems", dataitems, allocator);
}
}
condsItem.PushBack(cond, allocator);
}
vElemItem.AddMember("conditions", condsItem, allocator);
}
else if (key.compare("events") == 0)
{
rapidjson::Value eventsItem(rapidjson::kArrayType);
length = pTriggerArray[i].GetChildNum();
stExpCocoNode *pEventsArray = pTriggerArray[i].GetChildArray();
for (int i = 0; i < length; ++i)
{
rapidjson::Value event(rapidjson::kObjectType);
stExpCocoNode *pEventArray = pEventsArray->GetChildArray();
std::string key = pEventArray[0].GetName(pCocoLoader);
const char *str = pEventArray[0].GetValue();
if (key.compare("id") == 0 && str != NULL)
{
event.AddMember("id", atoi(str), allocator);
eventsItem.PushBack(event, allocator);
}
}
vElemItem.AddMember("events", eventsItem, allocator);
}
else if (key.compare("id") == 0)
{
if (str != NULL)
{
vElemItem.AddMember("id", atoi(str), allocator);
}
}
}
document.PushBack(vElemItem, allocator);
}
}
void TriggerMng::addArmatureMovementCallBack(Armature *pAr, Ref *pTarget, SEL_MovementEventCallFunc mecf) void TriggerMng::addArmatureMovementCallBack(Armature *pAr, Ref *pTarget, SEL_MovementEventCallFunc mecf)
{ {
if (pAr == nullptr || _movementDispatches == nullptr || pTarget == nullptr || mecf == nullptr) if (pAr == nullptr || _movementDispatches == nullptr || pTarget == nullptr || mecf == nullptr)

View File

@ -64,6 +64,7 @@ public:
public: public:
void parse(const rapidjson::Value &root); void parse(const rapidjson::Value &root);
void parse(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
void removeAll(void); void removeAll(void);
cocos2d::Vector<TriggerObj*>* get(unsigned int event) const; cocos2d::Vector<TriggerObj*>* get(unsigned int event) const;
TriggerObj* getTriggerObj(unsigned int id) const; TriggerObj* getTriggerObj(unsigned int id) const;
@ -78,6 +79,8 @@ public:
void dispatchEvent(cocos2d::EventCustom* tEvent); void dispatchEvent(cocos2d::EventCustom* tEvent);
void removeEventListener(cocos2d::EventListener* listener); void removeEventListener(cocos2d::EventListener* listener);
void addEventListenerWithFixedPriority(cocos2d::EventListener* listener, int fixedPriority); void addEventListenerWithFixedPriority(cocos2d::EventListener* listener, int fixedPriority);
private:
void buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
private: private:
static TriggerMng *_sharedTriggerMng; static TriggerMng *_sharedTriggerMng;

View File

@ -48,6 +48,11 @@ bool BaseTriggerCondition::detect()
void BaseTriggerCondition::serialize(const rapidjson::Value &val) void BaseTriggerCondition::serialize(const rapidjson::Value &val)
{ {
} }
void BaseTriggerCondition::serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode)
{
}
void BaseTriggerCondition::removeAll() void BaseTriggerCondition::removeAll()
{ {
@ -75,6 +80,10 @@ void BaseTriggerAction::serialize(const rapidjson::Value &val)
{ {
} }
void BaseTriggerAction::serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode)
{
}
void BaseTriggerAction::removeAll() void BaseTriggerAction::removeAll()
{ {
} }
@ -231,6 +240,102 @@ void TriggerObj::serialize(const rapidjson::Value &val)
} }
} }
void TriggerObj::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
int num = 0;
stExpCocoNode *pTriggerObjArray = pCocoNode->GetChildArray();
for (int i = 0; i < length; ++i)
{
std::string key = pTriggerObjArray[i].GetName(pCocoLoader);
const char* str = pTriggerObjArray[i].GetValue();
if (key.compare("id") == 0)
{
if (str != NULL)
{
_id = atoi(str); //(unsigned int)(DICTOOL->getIntValue_json(val, "id"));
}
}
else if (key.compare("conditions") == 0)
{
count = pTriggerObjArray[i].GetChildNum();
stExpCocoNode *pConditionsArray = pTriggerObjArray[i].GetChildArray();
for (int i = 0; i < count; ++i)
{
num = pConditionsArray[i].GetChildNum();
stExpCocoNode *pConditionArray = pConditionsArray[i].GetChildArray();
const char *classname = pConditionArray[0].GetValue();
if (classname == NULL)
{
continue;
}
BaseTriggerCondition *con = dynamic_cast<BaseTriggerCondition*>(ObjectFactory::getInstance()->createObject(classname));
CCAssert(con != NULL, "class named classname can not implement!");
con->serialize(pCocoLoader, &pConditionArray[1]);
con->init();
_cons.pushBack(con);
}
}
else if (key.compare("actions") == 0)
{
count = pTriggerObjArray[i].GetChildNum();
stExpCocoNode *pActionsArray = pTriggerObjArray[i].GetChildArray();
for (int i = 0; i < count; ++i)
{
num = pActionsArray[i].GetChildNum();
stExpCocoNode *pActionArray = pActionsArray[i].GetChildArray();
const char *classname = pActionArray[0].GetValue();
if (classname == NULL)
{
continue;
}
BaseTriggerAction *act = dynamic_cast<BaseTriggerAction*>(ObjectFactory::getInstance()->createObject(classname));
CCAssert(act != NULL, "class named classname can not implement!");
act->serialize(pCocoLoader, &pActionArray[1]);
act->init();
_acts.pushBack(act);
}
}
else if (key.compare("events") == 0)
{
count = pTriggerObjArray[i].GetChildNum();
stExpCocoNode *pEventsArray = pTriggerObjArray[i].GetChildArray();
for (int i = 0; i < count; ++i)
{
num = pEventsArray[i].GetChildNum();
stExpCocoNode *pEventArray = pEventsArray[i].GetChildArray();
const char *str = pEventArray[0].GetValue();
if (str == NULL)
{
continue;
}
int event = atoi(str);
if (event < 0)
{
continue;
}
char* buf = new char[10];
sprintf(buf, "%d", event);
std::string custom_event_name(buf);
CC_SAFE_DELETE_ARRAY(buf);
EventListenerCustom* listener = EventListenerCustom::create(custom_event_name, [=](EventCustom* evt){
if (detect())
{
done();
}
});
_listeners.pushBack(listener);
TriggerMng::getInstance()->addEventListenerWithFixedPriority(listener, 1);
}
}
}
}
unsigned int TriggerObj::getId() unsigned int TriggerObj::getId()
{ {
return _id; return _id;

View File

@ -44,6 +44,7 @@ public:
virtual bool init(); virtual bool init();
virtual bool detect(); virtual bool detect();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode);
virtual void removeAll(); virtual void removeAll();
}; };
@ -56,6 +57,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode);
virtual void removeAll(); virtual void removeAll();
}; };
@ -72,6 +74,7 @@ public:
virtual void done(); virtual void done();
virtual void removeAll(); virtual void removeAll();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode);
unsigned int getId(); unsigned int getId();
void setEnabled(bool enabled); void setEnabled(bool enabled);

View File

@ -0,0 +1,16 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-16
android.library.reference.1=../java
android.library=true

View File

@ -65,6 +65,7 @@ public:
const Mat4& getReverseOrientationMatrix () const {return m_reverseOrientationMatrix;}; const Mat4& getReverseOrientationMatrix () const {return m_reverseOrientationMatrix;};
Windows::Graphics::Display::DisplayOrientations getDeviceOrientation() {return m_orientation;}; Windows::Graphics::Display::DisplayOrientations getDeviceOrientation() {return m_orientation;};
Size getRenerTargetSize() const { return Size(m_width, m_height); }
virtual void setIMEKeyboardState(bool bOpen); virtual void setIMEKeyboardState(bool bOpen);
void ShowKeyboard(Windows::Foundation::Rect r); void ShowKeyboard(Windows::Foundation::Rect r);

View File

@ -61,7 +61,7 @@ namespace {
typedef Texture2D::PixelFormatInfoMap::value_type PixelFormatInfoMapValue; typedef Texture2D::PixelFormatInfoMap::value_type PixelFormatInfoMapValue;
static const PixelFormatInfoMapValue TexturePixelFormatInfoTablesValue[] = static const PixelFormatInfoMapValue TexturePixelFormatInfoTablesValue[] =
{ {
PixelFormatInfoMapValue(Texture2D::PixelFormat::BGRA8888, Texture2D::PixelFormatInfo(GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE, 32, false, true)), PixelFormatInfoMapValue(Texture2D::PixelFormat::BGRA8888, Texture2D::PixelFormatInfo(GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE, 32, false, true)),
PixelFormatInfoMapValue(Texture2D::PixelFormat::RGBA8888, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 32, false, true)), PixelFormatInfoMapValue(Texture2D::PixelFormat::RGBA8888, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 32, false, true)),
PixelFormatInfoMapValue(Texture2D::PixelFormat::RGBA4444, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, false, true)), PixelFormatInfoMapValue(Texture2D::PixelFormat::RGBA4444, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, false, true)),
PixelFormatInfoMapValue(Texture2D::PixelFormat::RGB5A1, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, false, true)), PixelFormatInfoMapValue(Texture2D::PixelFormat::RGB5A1, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, false, true)),
@ -1032,6 +1032,14 @@ rgba(1) -> 12345678
*/ */
Texture2D::PixelFormat Texture2D::convertDataToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, ssize_t* outDataLen) Texture2D::PixelFormat Texture2D::convertDataToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, ssize_t* outDataLen)
{ {
// don't need to convert
if (format == originFormat || format == PixelFormat::AUTO)
{
*outData = (unsigned char*)data;
*outDataLen = dataLen;
return originFormat;
}
switch (originFormat) switch (originFormat)
{ {
case PixelFormat::I8: case PixelFormat::I8:

View File

@ -1104,7 +1104,7 @@ Vec2 Layout::getWorldCenterPoint(Widget* widget)const
return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2)); return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2));
} }
float Layout::caculateNearestDistance(Widget* baseWidget) float Layout::calculateNearestDistance(Widget* baseWidget)
{ {
float distance = FLT_MAX; float distance = FLT_MAX;
@ -1114,7 +1114,7 @@ float Layout::caculateNearestDistance(Widget* baseWidget)
Layout *layout = dynamic_cast<Layout*>(node); Layout *layout = dynamic_cast<Layout*>(node);
int length; int length;
if (layout) { if (layout) {
length = layout->caculateNearestDistance(baseWidget); length = layout->calculateNearestDistance(baseWidget);
} }
else else
{ {
@ -1137,7 +1137,7 @@ float Layout::caculateNearestDistance(Widget* baseWidget)
return distance; return distance;
} }
float Layout::caculateFarestDistance(cocos2d::ui::Widget *baseWidget) float Layout::calculateFarestDistance(cocos2d::ui::Widget *baseWidget)
{ {
float distance = -FLT_MAX; float distance = -FLT_MAX;
@ -1147,7 +1147,7 @@ float Layout::caculateFarestDistance(cocos2d::ui::Widget *baseWidget)
Layout *layout = dynamic_cast<Layout*>(node); Layout *layout = dynamic_cast<Layout*>(node);
int length; int length;
if (layout) { if (layout) {
length = layout->caculateFarestDistance(baseWidget); length = layout->calculateFarestDistance(baseWidget);
} }
else else
{ {
@ -1194,7 +1194,8 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
float distance = FLT_MAX; float distance = FLT_MAX;
int found = 0; int found = 0;
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT) if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT ||
direction == FocusDirection::DOWN || direction == FocusDirection::UP)
{ {
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget); Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
while (index < count) while (index < count)
@ -1207,7 +1208,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
Layout *layout = dynamic_cast<Layout*>(w); Layout *layout = dynamic_cast<Layout*>(w);
if (layout) if (layout)
{ {
length = layout->caculateNearestDistance(baseWidget); length = layout->calculateNearestDistance(baseWidget);
} }
else else
{ {
@ -1225,39 +1226,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
return found; return found;
} }
index = 0;
found = 0;
distance = FLT_MAX;
if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) {
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
while (index < count)
{
Widget *w = dynamic_cast<Widget*>(this->getChildren().at(index));
if (w && w->isFocusEnabled())
{
Vec2 wPosition = this->getWorldCenterPoint(w);
float length;
Layout *layout = dynamic_cast<Layout*>(w);
if (layout)
{
length = layout->caculateNearestDistance(baseWidget);
}
else
{
length = (wPosition - widgetPosition).getLength();
}
if (length < distance)
{
found = index;
distance = length;
}
}
index++;
}
return found;
}
CCASSERT(0, "invalid focus direction!!!"); CCASSERT(0, "invalid focus direction!!!");
return 0; return 0;
} }
@ -1273,7 +1242,8 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi
float distance = -FLT_MAX; float distance = -FLT_MAX;
int found = 0; int found = 0;
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT) if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT
|| direction == FocusDirection::DOWN || direction == FocusDirection::UP)
{ {
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget); Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
while (index < count) while (index < count)
@ -1286,7 +1256,7 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi
Layout *layout = dynamic_cast<Layout*>(w); Layout *layout = dynamic_cast<Layout*>(w);
if (layout) if (layout)
{ {
length = layout->caculateFarestDistance(baseWidget); length = layout->calculateFarestDistance(baseWidget);
} }
else else
{ {
@ -1304,39 +1274,6 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi
return found; return found;
} }
index = 0;
found = 0;
distance = -FLT_MAX;
if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) {
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
while (index < count)
{
Widget *w = dynamic_cast<Widget*>(this->getChildren().at(index));
if (w && w->isFocusEnabled())
{
Vec2 wPosition = this->getWorldCenterPoint(w);
float length;
Layout *layout = dynamic_cast<Layout*>(w);
if (layout)
{
length = layout->caculateFarestDistance(baseWidget);
}
else
{
length = (wPosition - widgetPosition).getLength();
}
if (length > distance)
{
found = index;
distance = length;
}
}
index++;
}
return found;
}
CCASSERT(0, "invalid focus direction!!!"); CCASSERT(0, "invalid focus direction!!!");
return 0; return 0;
} }
@ -1368,6 +1305,9 @@ Widget *Layout::findFirstNonLayoutWidget()
Layout* layout = dynamic_cast<Layout*>(node); Layout* layout = dynamic_cast<Layout*>(node);
if (layout) { if (layout) {
widget = layout->findFirstNonLayoutWidget(); widget = layout->findFirstNonLayoutWidget();
if (widget != nullptr) {
return widget;
}
} }
else{ else{
Widget *w = dynamic_cast<Widget*>(node); Widget *w = dynamic_cast<Widget*>(node);

View File

@ -376,7 +376,7 @@ protected:
*@param the base widget which will be used to caculate the distance between the layout's children and itself *@param the base widget which will be used to caculate the distance between the layout's children and itself
*@return return the nearest distance between the baseWidget and the layout's children *@return return the nearest distance between the baseWidget and the layout's children
*/ */
float caculateNearestDistance(Widget* baseWidget); float calculateNearestDistance(Widget* baseWidget);
/** /**
* caculate the farest distance between the baseWidget and the children of the layout * caculate the farest distance between the baseWidget and the children of the layout
@ -384,7 +384,7 @@ protected:
*@return return the farest distance between the baseWidget and the layout's children *@return return the farest distance between the baseWidget and the layout's children
*/ */
float caculateFarestDistance(Widget* baseWidget); float calculateFarestDistance(Widget* baseWidget);
/** /**
* when a layout pass the focus to it's child, use this method to determine which algorithm to use, nearest or farest distance algorithm or not * when a layout pass the focus to it's child, use this method to determine which algorithm to use, nearest or farest distance algorithm or not

View File

@ -747,38 +747,37 @@
"cocos/platform/android/CCGLView.h", "cocos/platform/android/CCGLView.h",
"cocos/platform/android/CCPlatformDefine.h", "cocos/platform/android/CCPlatformDefine.h",
"cocos/platform/android/CCStdC.h", "cocos/platform/android/CCStdC.h",
"cocos/platform/android/ControllerDelegate/.classpath", "cocos/platform/android/ControllerAutoAdapter/.classpath",
"cocos/platform/android/ControllerDelegate/.project", "cocos/platform/android/ControllerAutoAdapter/.project",
"cocos/platform/android/ControllerDelegate/.settings/org.eclipse.jdt.core.prefs", "cocos/platform/android/ControllerAutoAdapter/.settings/org.eclipse.jdt.core.prefs",
"cocos/platform/android/ControllerDelegate/AndroidManifest.xml", "cocos/platform/android/ControllerAutoAdapter/AndroidManifest.xml",
"cocos/platform/android/ControllerDelegate/ant.properties", "cocos/platform/android/ControllerAutoAdapter/ant.properties",
"cocos/platform/android/ControllerDelegate/build.xml", "cocos/platform/android/ControllerAutoAdapter/build.xml",
"cocos/platform/android/ControllerDelegate/proguard-project.txt", "cocos/platform/android/ControllerAutoAdapter/lint.xml",
"cocos/platform/android/ControllerDelegate/src/org/cocos2dx/lib/GameControllerDelegate.java", "cocos/platform/android/ControllerAutoAdapter/proguard-project.txt",
"cocos/platform/android/ControllerMoga/.classpath", "cocos/platform/android/ControllerAutoAdapter/project.properties",
"cocos/platform/android/ControllerMoga/.project", "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/GameControllerActivity.java",
"cocos/platform/android/ControllerMoga/.settings/org.eclipse.jdt.core.prefs", "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/GameControllerHelper.java",
"cocos/platform/android/ControllerMoga/AndroidManifest.xml", "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java",
"cocos/platform/android/ControllerMoga/ant.properties", "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java",
"cocos/platform/android/ControllerMoga/build.xml", "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java",
"cocos/platform/android/ControllerMoga/proguard-project.txt", "cocos/platform/android/ControllerManualAdapter/.classpath",
"cocos/platform/android/ControllerMoga/src/org/cocos2dx/lib/GameControllerMoga.java", "cocos/platform/android/ControllerManualAdapter/.project",
"cocos/platform/android/ControllerNibiru/.classpath", "cocos/platform/android/ControllerManualAdapter/.settings/org.eclipse.jdt.core.prefs",
"cocos/platform/android/ControllerNibiru/.project", "cocos/platform/android/ControllerManualAdapter/AndroidManifest.xml",
"cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs", "cocos/platform/android/ControllerManualAdapter/ant.properties",
"cocos/platform/android/ControllerNibiru/AndroidManifest.xml", "cocos/platform/android/ControllerManualAdapter/build.xml",
"cocos/platform/android/ControllerNibiru/ant.properties", "cocos/platform/android/ControllerManualAdapter/lint.xml",
"cocos/platform/android/ControllerNibiru/build.xml", "cocos/platform/android/ControllerManualAdapter/proguard-project.txt",
"cocos/platform/android/ControllerNibiru/proguard-project.txt", "cocos/platform/android/ControllerManualAdapter/project.properties",
"cocos/platform/android/ControllerNibiru/src/org/cocos2dx/lib/GameControllerNibiru.java", "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java",
"cocos/platform/android/ControllerOuya/.classpath", "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java",
"cocos/platform/android/ControllerOuya/.project", "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerMoga.java",
"cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs", "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java",
"cocos/platform/android/ControllerOuya/AndroidManifest.xml", "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java",
"cocos/platform/android/ControllerOuya/ant.properties", "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java",
"cocos/platform/android/ControllerOuya/build.xml", "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java",
"cocos/platform/android/ControllerOuya/proguard-project.txt", "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java",
"cocos/platform/android/ControllerOuya/src/org/cocos2dx/lib/GameControllerOuya.java",
"cocos/platform/android/java/.classpath", "cocos/platform/android/java/.classpath",
"cocos/platform/android/java/.project", "cocos/platform/android/java/.project",
"cocos/platform/android/java/.settings/org.eclipse.jdt.core.prefs", "cocos/platform/android/java/.settings/org.eclipse.jdt.core.prefs",
@ -807,11 +806,8 @@
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java", "cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java", "cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerAdapter.java", "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerAdapter.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerHelper.java", "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerUtils.java", "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerUtils.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java",
"cocos/platform/android/javaactivity.cpp", "cocos/platform/android/javaactivity.cpp",
"cocos/platform/android/jni/DPIJni.cpp", "cocos/platform/android/jni/DPIJni.cpp",
"cocos/platform/android/jni/DPIJni.h", "cocos/platform/android/jni/DPIJni.h",

View File

@ -106,7 +106,7 @@ void SceneEditorTestScene::MainMenuCallback(Ref *pSender)
removeAllChildren(); removeAllChildren();
} }
const char* SceneEditorTestLayer::_loadtypeStr[2] = {"change to load \nwith binary file","change to load \nwith json file"};
void SceneEditorTestLayer::onEnter() void SceneEditorTestLayer::onEnter()
{ {
CCLayer::onEnter(); CCLayer::onEnter();
@ -127,6 +127,13 @@ void SceneEditorTestLayer::onEnter()
addChild(l, 1, 10001); addChild(l, 1, 10001);
l->setPosition(Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) ); l->setPosition(Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) );
} }
_isCsbLoad = false;
_loadtypelb = cocos2d::Label::createWithSystemFont(_loadtypeStr[0], "Arial", 12);
// #endif
MenuItemLabel* itemlb = CCMenuItemLabel::create(_loadtypelb, CC_CALLBACK_1(SceneEditorTestLayer::changeLoadTypeCallback, this));
Menu* loadtypemenu = CCMenu::create(itemlb, NULL);
loadtypemenu->setPosition(Point(VisibleRect::rightTop().x -50,VisibleRect::rightTop().y -20));
addChild(loadtypemenu,100);
// add menu // add menu
backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(SceneEditorTestLayer::backCallback, this) ); backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(SceneEditorTestLayer::backCallback, this) );
@ -199,6 +206,36 @@ void SceneEditorTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint3
Layer::draw(renderer, transform, flags); Layer::draw(renderer, transform, flags);
} }
void SceneEditorTestLayer::changeLoadTypeCallback(cocos2d::Ref *pSender)
{
_isCsbLoad = !_isCsbLoad;
_loadtypelb->setString(_loadtypeStr[(int)_isCsbLoad]);
loadFileChangeHelper(_filePath);
if(_rootNode != NULL)
{
this->removeChild(_rootNode);
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return ;
}
defaultPlay();
this->addChild(_rootNode);
}
}
void SceneEditorTestLayer::loadFileChangeHelper(std::string& filePathName)
{
std::string::size_type n = filePathName.find_last_of(".");
if(n == std::string::npos)
return;
filePathName = filePathName.substr(0,n);
if(_isCsbLoad)
filePathName.append(".csb");
else
filePathName.append(".json");
}
LoadSceneEdtiorFileTest::LoadSceneEdtiorFileTest() LoadSceneEdtiorFileTest::LoadSceneEdtiorFileTest()
{ {
@ -238,12 +275,19 @@ void LoadSceneEdtiorFileTest::onExit()
cocos2d::Node* LoadSceneEdtiorFileTest::createGameScene() cocos2d::Node* LoadSceneEdtiorFileTest::createGameScene()
{ {
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/LoadSceneEdtiorFileTest/FishJoy2.json"); _filePath = "scenetest/LoadSceneEdtiorFileTest/FishJoy2.json"; //default is json
if (node == nullptr) _rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{ {
return nullptr; return NULL;
} }
return node; defaultPlay();
return _rootNode;
}
void LoadSceneEdtiorFileTest::defaultPlay()
{
} }
SpriteComponentTest::SpriteComponentTest() SpriteComponentTest::SpriteComponentTest()
@ -283,22 +327,29 @@ void SpriteComponentTest::onExit()
cocos2d::Node* SpriteComponentTest::createGameScene() cocos2d::Node* SpriteComponentTest::createGameScene()
{ {
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/SpriteComponentTest/SpriteComponentTest.json"); _filePath = "scenetest/SpriteComponentTest/SpriteComponentTest.json";
if (node == nullptr) _rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{ {
return nullptr; return NULL;
} }
defaultPlay();
return _rootNode;
}
void SpriteComponentTest::defaultPlay()
{
ActionInterval* action1 = CCBlink::create(2, 10); ActionInterval* action1 = CCBlink::create(2, 10);
ActionInterval* action2 = CCBlink::create(2, 5); ActionInterval* action2 = CCBlink::create(2, 5);
ComRender *pSister1 = static_cast<ComRender*>(node->getChildByTag(10003)->getComponent("CCSprite")); ComRender *pSister1 = static_cast<ComRender*>(_rootNode->getChildByTag(10003)->getComponent("CCSprite"));
pSister1->getNode()->runAction(action1); pSister1->getNode()->runAction(action1);
ComRender *pSister2 = static_cast<ComRender*>(node->getChildByTag(10004)->getComponent("CCSprite")); ComRender *pSister2 = static_cast<ComRender*>(_rootNode->getChildByTag(10004)->getComponent("CCSprite"));
pSister2->getNode()->runAction(action2); pSister2->getNode()->runAction(action2);
return node;
} }
ArmatureComponentTest::ArmatureComponentTest() ArmatureComponentTest::ArmatureComponentTest()
@ -338,22 +389,27 @@ void ArmatureComponentTest::onExit()
cocos2d::Node* ArmatureComponentTest::createGameScene() cocos2d::Node* ArmatureComponentTest::createGameScene()
{ {
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ArmatureComponentTest/ArmatureComponentTest.json"); _filePath = "scenetest/ArmatureComponentTest/ArmatureComponentTest.json";
if (node == nullptr) _rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{ {
return nullptr; return NULL;
} }
ComRender *pBlowFish = static_cast<ComRender*>(node->getChildByTag(10007)->getComponent("CCArmature")); defaultPlay();
pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0))); return _rootNode;
}
ComRender *pButterflyfish = static_cast<ComRender*>(node->getChildByTag(10008)->getComponent("CCArmature")); void ArmatureComponentTest::defaultPlay()
pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0))); {
ComRender *pBlowFish = static_cast<ComRender*>(_rootNode->getChildByTag(10007)->getComponent("CCArmature"));
pBlowFish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0)));
ComRender *pButterflyfish = static_cast<ComRender*>(_rootNode->getChildByTag(10008)->getComponent("CCArmature"));
pButterflyfish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0)));
return node;
} }
UIComponentTest::UIComponentTest() UIComponentTest::UIComponentTest()
: _node(nullptr)
{ {
} }
@ -389,20 +445,15 @@ void UIComponentTest::onExit()
cocos2d::Node* UIComponentTest::createGameScene() cocos2d::Node* UIComponentTest::createGameScene()
{ {
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/UIComponentTest/UIComponentTest.json"); _filePath = "scenetest/UIComponentTest/UIComponentTest.json";
if (node == nullptr) _rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{ {
return nullptr; return NULL;
} }
_node = node; defaultPlay();
ComRender *render = static_cast<ComRender*>(_node->getChildByTag(10025)->getComponent("GUIComponent")); return _rootNode;
Widget* widget = static_cast<cocos2d::ui::Widget*>(render->getNode());
Button* button = static_cast<Button*>(widget->getChildByName("Button_156"));
// button->addTouchEventListener(this, toucheventselector(UIComponentTest::touchEvent));
button->addTouchEventListener(CC_CALLBACK_2(UIComponentTest::touchEvent, this));
return node;
} }
void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type) void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type)
@ -411,10 +462,10 @@ void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type)
{ {
case ui::Widget::TouchEventType::BEGAN: case ui::Widget::TouchEventType::BEGAN:
{ {
ComRender *pBlowFish = static_cast<ComRender*>(_node->getChildByTag(10010)->getComponent("CCArmature")); ComRender *pBlowFish = static_cast<ComRender*>(_rootNode->getChildByTag(10010)->getComponent("CCArmature"));
pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0))); pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
ComRender *pButterflyfish = static_cast<ComRender*>(_node->getChildByTag(10011)->getComponent("CCArmature")); ComRender *pButterflyfish = static_cast<ComRender*>(_rootNode->getChildByTag(10011)->getComponent("CCArmature"));
pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0))); pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
} }
break; break;
@ -423,6 +474,15 @@ void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type)
} }
} }
void UIComponentTest::defaultPlay()
{
ComRender *render = static_cast<ComRender*>(_rootNode->getChildByTag(10025)->getComponent("GUIComponent"));
Widget* widget = static_cast<cocos2d::ui::Widget*>(render->getNode());
Button* button = static_cast<Button*>(widget->getChildByName("Button_156"));
button->addTouchEventListener(CC_CALLBACK_2(UIComponentTest::touchEvent, this));
}
TmxMapComponentTest::TmxMapComponentTest() TmxMapComponentTest::TmxMapComponentTest()
{ {
@ -460,24 +520,30 @@ void TmxMapComponentTest::onExit()
cocos2d::Node* TmxMapComponentTest::createGameScene() cocos2d::Node* TmxMapComponentTest::createGameScene()
{ {
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/TmxMapComponentTest/TmxMapComponentTest.json"); _filePath = "scenetest/TmxMapComponentTest/TmxMapComponentTest.json";
if (node == nullptr) _rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{ {
return nullptr; return NULL;
} }
ComRender *tmxMap = static_cast<ComRender*>(node->getChildByTag(10015)->getComponent("CCTMXTiledMap")); defaultPlay();
ActionInterval *actionTo = SkewTo::create(2, 0.f, 2.f); return _rootNode;
ActionInterval *rotateTo = RotateTo::create(2, 61.0f); }
ActionInterval *actionScaleTo = ScaleTo::create(2, -0.44f, 0.47f);
ActionInterval *actionScaleToBack = ScaleTo::create(2, 1.0f, 1.0f); void TmxMapComponentTest::defaultPlay()
ActionInterval *rotateToBack = RotateTo::create(2, 0); {
ActionInterval *actionToBack = SkewTo::create(2, 0, 0); ComRender *tmxMap = static_cast<ComRender*>(_rootNode->getChildByTag(10015)->getComponent("CCTMXTiledMap"));
ActionInterval *actionTo = CCSkewTo::create(2, 0.f, 2.f);
ActionInterval *rotateTo = CCRotateTo::create(2, 61.0f);
ActionInterval *actionScaleTo = CCScaleTo::create(2, -0.44f, 0.47f);
tmxMap->getNode()->runAction(Sequence::create(actionTo, actionToBack, nullptr)); ActionInterval *actionScaleToBack = CCScaleTo::create(2, 1.0f, 1.0f);
tmxMap->getNode()->runAction(Sequence::create(rotateTo, rotateToBack, nullptr)); ActionInterval *rotateToBack = CCRotateTo::create(2, 0);
tmxMap->getNode()->runAction(Sequence::create(actionScaleTo, actionScaleToBack, nullptr)); ActionInterval *actionToBack = CCSkewTo::create(2, 0, 0);
return node;
tmxMap->getNode()->runAction(CCSequence::create(actionTo, actionToBack, NULL));
tmxMap->getNode()->runAction(CCSequence::create(rotateTo, rotateToBack, NULL));
tmxMap->getNode()->runAction(CCSequence::create(actionScaleTo, actionScaleToBack, NULL));
} }
ParticleComponentTest::ParticleComponentTest() ParticleComponentTest::ParticleComponentTest()
@ -516,22 +582,26 @@ void ParticleComponentTest::onExit()
cocos2d::Node* ParticleComponentTest::createGameScene() cocos2d::Node* ParticleComponentTest::createGameScene()
{ {
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ParticleComponentTest/ParticleComponentTest.json"); _filePath = "scenetest/ParticleComponentTest/ParticleComponentTest.json";
if (node == nullptr) _rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{ {
return nullptr; return NULL;
} }
defaultPlay();
return _rootNode;
}
ComRender* Particle = static_cast<ComRender*>(node->getChildByTag(10020)->getComponent("CCParticleSystemQuad")); void ParticleComponentTest::defaultPlay()
ActionInterval* jump = JumpBy::create(5, Vec2(-500,0), 50, 4); {
FiniteTimeAction* action = Sequence::create( jump, jump->reverse(), nullptr); ComRender* Particle = static_cast<ComRender*>(_rootNode->getChildByTag(10020)->getComponent("CCParticleSystemQuad"));
ActionInterval* jump = CCJumpBy::create(5, Point(-500,0), 50, 4);
FiniteTimeAction* action = CCSequence::create( jump, jump->reverse(), NULL);
Particle->getNode()->runAction(action); Particle->getNode()->runAction(action);
return node;
} }
EffectComponentTest::EffectComponentTest() EffectComponentTest::EffectComponentTest()
: _node(nullptr)
{ {
} }
@ -567,16 +637,14 @@ void EffectComponentTest::onExit()
cocos2d::Node* EffectComponentTest::createGameScene() cocos2d::Node* EffectComponentTest::createGameScene()
{ {
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/EffectComponentTest/EffectComponentTest.json"); _filePath = "scenetest/EffectComponentTest/EffectComponentTest.json";
if (node == nullptr) _rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{ {
return nullptr; return NULL;
} }
_node = node; defaultPlay();
ComRender *render = static_cast<ComRender*>(_node->getChildByTag(10015)->getComponent("CCArmature")); return _rootNode;
Armature *pAr = static_cast<Armature*>(render->getNode());
pAr->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(EffectComponentTest::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
return node;
} }
void EffectComponentTest::animationEvent(Armature *armature, MovementEventType movementType, const std::string& movementID) void EffectComponentTest::animationEvent(Armature *armature, MovementEventType movementType, const std::string& movementID)
@ -587,12 +655,19 @@ void EffectComponentTest::animationEvent(Armature *armature, MovementEventType m
{ {
if (id.compare("Fire") == 0) if (id.compare("Fire") == 0)
{ {
ComAudio *pAudio = static_cast<ComAudio*>(_node->getChildByTag(10015)->getComponent("CCComAudio")); ComAudio *pAudio = static_cast<ComAudio*>(_rootNode->getChildByTag(10015)->getComponent("CCComAudio"));
pAudio->playEffect(); pAudio->playEffect();
} }
} }
} }
void EffectComponentTest::defaultPlay()
{
ComRender *render = static_cast<ComRender*>(_rootNode->getChildByTag(10015)->getComponent("CCArmature"));
Armature *pAr = static_cast<Armature*>(render->getNode());
pAr->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(EffectComponentTest::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}
BackgroundComponentTest::BackgroundComponentTest() BackgroundComponentTest::BackgroundComponentTest()
{ {
@ -629,20 +704,24 @@ void BackgroundComponentTest::onExit()
cocos2d::Node* BackgroundComponentTest::createGameScene() cocos2d::Node* BackgroundComponentTest::createGameScene()
{ {
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/BackgroundComponentTest/BackgroundComponentTest.json"); _filePath = "scenetest/BackgroundComponentTest/BackgroundComponentTest.json";
if (node == nullptr) _rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{ {
return nullptr; return NULL;
} }
defaultPlay();
return _rootNode;
}
ComAudio *Audio = static_cast<ComAudio*>(node->getComponent("CCBackgroundAudio")); void BackgroundComponentTest::defaultPlay()
{
ComAudio *Audio = static_cast<ComAudio*>(_rootNode->getComponent("CCBackgroundAudio"));
Audio->playBackgroundMusic(); Audio->playBackgroundMusic();
return node;
} }
AttributeComponentTest::AttributeComponentTest() AttributeComponentTest::AttributeComponentTest()
: _node(nullptr)
{ {
} }
@ -663,7 +742,7 @@ void AttributeComponentTest::onEnter()
{ {
Node *root = createGameScene(); Node *root = createGameScene();
CC_BREAK_IF(!root); CC_BREAK_IF(!root);
initData(); defaultPlay();
this->addChild(root, 0, 1); this->addChild(root, 0, 1);
} while (0); } while (0);
} }
@ -682,8 +761,8 @@ bool AttributeComponentTest::initData()
bool bRet = false; bool bRet = false;
rapidjson::Document doc; rapidjson::Document doc;
do { do {
CC_BREAK_IF(_node == nullptr); CC_BREAK_IF(_rootNode == nullptr);
ComAttribute *attribute = static_cast<ComAttribute*>(_node->getChildByTag(10015)->getComponent("CCComAttribute")); ComAttribute *attribute = static_cast<ComAttribute*>(_rootNode->getChildByTag(10015)->getComponent("CCComAttribute"));
CC_BREAK_IF(attribute == nullptr); CC_BREAK_IF(attribute == nullptr);
log("Name: %s, HP: %f, MP: %f", attribute->getString("name").c_str(), attribute->getFloat("maxHP"), attribute->getFloat("maxMP")); log("Name: %s, HP: %f, MP: %f", attribute->getString("name").c_str(), attribute->getFloat("maxHP"), attribute->getFloat("maxMP"));
@ -694,13 +773,18 @@ bool AttributeComponentTest::initData()
cocos2d::Node* AttributeComponentTest::createGameScene() cocos2d::Node* AttributeComponentTest::createGameScene()
{ {
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/AttributeComponentTest/AttributeComponentTest.json"); _filePath = "scenetest/AttributeComponentTest/AttributeComponentTest.json";
if (node == nullptr) _rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{ {
return nullptr; return NULL;
} }
_node = node; return _rootNode;
return node; }
void AttributeComponentTest::defaultPlay()
{
initData();
} }
TriggerTest::TriggerTest() TriggerTest::TriggerTest()
@ -783,12 +867,16 @@ void TriggerTest::gameLogic(float dt)
cocos2d::Node* TriggerTest::createGameScene() cocos2d::Node* TriggerTest::createGameScene()
{ {
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/TriggerTest/TriggerTest.json"); _filePath = "scenetest/TriggerTest/TriggerTest.json";
if (node == nullptr) _rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{ {
return nullptr; return NULL;
} }
_node = node;
defaultPlay();
return node; return _rootNode;
}
void TriggerTest::defaultPlay()
{
} }

View File

@ -49,6 +49,20 @@ protected:
MenuItemImage *restartItem; MenuItemImage *restartItem;
MenuItemImage *nextItem; MenuItemImage *nextItem;
MenuItemImage *backItem; MenuItemImage *backItem;
protected:
virtual void changeLoadTypeCallback(cocos2d::Ref *pSender);
virtual void defaultPlay() = 0; // must to be overrided
void loadFileChangeHelper(std::string& filePathName ); // switch json& csb
private:
bool _isCsbLoad; // default is false
cocos2d::Label* _loadtypelb;
static const char* _loadtypeStr[2];
protected:
cocos2d::Node* _rootNode;
std::string _filePath;
}; };
class LoadSceneEdtiorFileTest : public SceneEditorTestLayer class LoadSceneEdtiorFileTest : public SceneEditorTestLayer
@ -61,6 +75,8 @@ public:
virtual void onEnter() override; virtual void onEnter() override;
virtual void onExit() override; virtual void onExit() override;
cocos2d::Node* createGameScene(); cocos2d::Node* createGameScene();
private:
void defaultPlay();
}; };
@ -75,6 +91,8 @@ public:
virtual void onExit() override; virtual void onExit() override;
cocos2d::Node* createGameScene(); cocos2d::Node* createGameScene();
private:
void defaultPlay();
}; };
class ArmatureComponentTest : public SceneEditorTestLayer class ArmatureComponentTest : public SceneEditorTestLayer
@ -88,6 +106,8 @@ public:
virtual void onExit() override; virtual void onExit() override;
cocos2d::Node* createGameScene(); cocos2d::Node* createGameScene();
private:
void defaultPlay();
}; };
class UIComponentTest : public SceneEditorTestLayer class UIComponentTest : public SceneEditorTestLayer
@ -102,7 +122,7 @@ public:
cocos2d::Node* createGameScene(); cocos2d::Node* createGameScene();
void touchEvent(cocos2d::Ref *pSender, ui::Widget::TouchEventType type); void touchEvent(cocos2d::Ref *pSender, ui::Widget::TouchEventType type);
private: private:
cocos2d::Node* _node; void defaultPlay();
}; };
class TmxMapComponentTest : public SceneEditorTestLayer class TmxMapComponentTest : public SceneEditorTestLayer
@ -115,6 +135,8 @@ public:
virtual void onEnter() override; virtual void onEnter() override;
virtual void onExit() override; virtual void onExit() override;
cocos2d::Node* createGameScene(); cocos2d::Node* createGameScene();
private:
void defaultPlay();
}; };
@ -128,6 +150,8 @@ public:
virtual void onEnter() override; virtual void onEnter() override;
virtual void onExit() override; virtual void onExit() override;
cocos2d::Node* createGameScene(); cocos2d::Node* createGameScene();
protected:
void defaultPlay();
}; };
class EffectComponentTest : public SceneEditorTestLayer class EffectComponentTest : public SceneEditorTestLayer
@ -142,7 +166,8 @@ public:
cocos2d::Node* createGameScene(); cocos2d::Node* createGameScene();
void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID); void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID);
private: private:
cocos2d::Node* _node; void defaultPlay();
}; };
class BackgroundComponentTest : public SceneEditorTestLayer class BackgroundComponentTest : public SceneEditorTestLayer
@ -155,6 +180,8 @@ public:
virtual void onEnter() override; virtual void onEnter() override;
virtual void onExit() override; virtual void onExit() override;
cocos2d::Node* createGameScene(); cocos2d::Node* createGameScene();
private:
void defaultPlay();
}; };
class AttributeComponentTest : public SceneEditorTestLayer class AttributeComponentTest : public SceneEditorTestLayer
@ -168,8 +195,9 @@ public:
virtual void onExit() override; virtual void onExit() override;
bool initData(); bool initData();
cocos2d::Node* createGameScene(); cocos2d::Node* createGameScene();
private: private:
cocos2d::Node* _node; void defaultPlay();
}; };
class TriggerTest : public SceneEditorTestLayer class TriggerTest : public SceneEditorTestLayer
@ -197,6 +225,8 @@ public:
private: private:
cocos2d::Node *_node; cocos2d::Node *_node;
cocos2d::EventListener* _touchListener; cocos2d::EventListener* _touchListener;
private:
void defaultPlay();
}; };
#endif // __HELLOWORLD_SCENE_H__ #endif // __HELLOWORLD_SCENE_H__

View File

@ -65,6 +65,44 @@ void PlayMusic::serialize(const rapidjson::Value &val)
} }
} }
void PlayMusic::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);//DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "componentName")
{
if (str != NULL)
{
_comName = str; //DICTOOL->getStringValue_json(subDict, "value");
}
}
else if (key == "type")
{
if (str != NULL)
{
_type = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
}
}
void PlayMusic::removeAll() void PlayMusic::removeAll()
{ {
} }
@ -127,6 +165,50 @@ void TMoveTo::serialize(const rapidjson::Value &val)
} }
} }
void TMoveTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "x")
{
if (str != NULL)
{
_pos.x = atof(str);
}
}
else if (key == "y")
{
if (str != NULL)
{
_pos.y = atoi(str);
}
}
}
}
void TMoveTo::removeAll() void TMoveTo::removeAll()
{ {
Node *node = SceneReader::getInstance()->getNodeByTag(_tag); Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -205,6 +287,57 @@ void TMoveBy::serialize(const rapidjson::Value &val)
} }
} }
void TMoveBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "x")
{
if (str != NULL)
{
_pos.x = atof(str);
}
}
else if (key == "y")
{
if (str != NULL)
{
_pos.y = atof(str);
}
}
else if (key == "IsReverse")
{
if (str != NULL)
{
_reverse = atoi(str)!=0?true:false; //DICTOOL->getIntValue_json(subDict, "value") != 0? true: false;
}
}
}
}
void TMoveBy::removeAll() void TMoveBy::removeAll()
{ {
Node *node = SceneReader::getInstance()->getNodeByTag(_tag); Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -267,6 +400,43 @@ void TRotateTo::serialize(const rapidjson::Value &val)
} }
} }
void TRotateTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "DeltaAngle")
{
if (str != NULL)
{
_deltaAngle = atof(str);
}
}
}
}
void TRotateTo::removeAll() void TRotateTo::removeAll()
{ {
Node *node = SceneReader::getInstance()->getNodeByTag(_tag); Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -343,6 +513,50 @@ void TRotateBy::serialize(const rapidjson::Value &val)
} }
} }
void TRotateBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "DeltaAngle")
{
if (str != NULL)
{
_deltaAngle = atof(str);
}
}
else if (key == "IsReverse")
{
if (str != NULL)
{
_reverse = atoi(str)!=0?true:false;
}
}
}
}
void TRotateBy::removeAll() void TRotateBy::removeAll()
{ {
Node *node = SceneReader::getInstance()->getNodeByTag(_tag); Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -409,6 +623,50 @@ void TScaleTo::serialize(const rapidjson::Value &val)
} }
} }
void TScaleTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "ScaleX")
{
if (str != NULL)
{
_scale.x = atof(str);
}
}
else if (key == "ScaleY")
{
if (str != NULL)
{
_scale.y = atof(str);
}
}
}
}
void TScaleTo::removeAll() void TScaleTo::removeAll()
{ {
Node *node = SceneReader::getInstance()->getNodeByTag(_tag); Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -489,6 +747,58 @@ void TScaleBy::serialize(const rapidjson::Value &val)
} }
} }
void TScaleBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "ScaleX")
{
if (str != NULL)
{
_scale.x = atof(str);
}
}
else if (key == "ScaleY")
{
if (str != NULL)
{
_scale.y = atof(str);
}
}
else if (key == "IsReverse")
{
if (str != NULL)
{
_reverse = atoi(str)!=0?true:false; //DICTOOL->getIntValue_json(subDict, "value")!= 0? true:false;
}
continue;
}
}
}
void TScaleBy::removeAll() void TScaleBy::removeAll()
{ {
Node *node = SceneReader::getInstance()->getNodeByTag(_tag); Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -555,6 +865,50 @@ void TSkewTo::serialize(const rapidjson::Value &val)
} }
} }
void TSkewTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "SkewX")
{
if (str != NULL)
{
_skew.x = atof(str);
}
}
else if (key == "SkewY")
{
if (str != NULL)
{
_skew.y = atof(str);
}
}
}
}
void TSkewTo::removeAll() void TSkewTo::removeAll()
{ {
Node *node = SceneReader::getInstance()->getNodeByTag(_tag); Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -634,6 +988,54 @@ void TSkewBy::serialize(const rapidjson::Value &val)
} }
} }
void TSkewBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "SkewX")
{
if (str != NULL)
{
_skew.x = atof(str);
}
}
else if (key == "SkewY")
{
if (str != NULL)
{
_skew.y = atof(str);
}
}
else if (key == "IsReverse")
{
_reverse = atoi(str)!=0?true:false; //DICTOOL->getIntValue_json(subDict, "value")!= 0? true:false;
}
}
}
void TSkewBy::removeAll() void TSkewBy::removeAll()
{ {
Node *node = SceneReader::getInstance()->getNodeByTag(_tag); Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -700,6 +1102,36 @@ void TriggerState::serialize(const rapidjson::Value &val)
} }
} }
void TriggerState::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "ID")
{
if (str != NULL)
{
_id = atoi(str);
}
}
else if (key == "State")
{
if (str != NULL)
{
_state = atoi(str);
}
}
}
}
void TriggerState::removeAll() void TriggerState::removeAll()
{ {
CCLOG("TriggerState::removeAll"); CCLOG("TriggerState::removeAll");
@ -726,7 +1158,7 @@ void ArmaturePlayAction::done()
{ {
Node *node = SceneReader::getInstance()->getNodeByTag(_tag); Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(node == nullptr); CC_BREAK_IF(node == nullptr);
ComRender *pRender = (ComRender*)(node->getComponent(_ComName.c_str())); ComRender *pRender = (ComRender*)(node->getComponent(_comName.c_str()));
CC_BREAK_IF(pRender == nullptr); CC_BREAK_IF(pRender == nullptr);
Armature *pAr = (Armature *)(pRender->getNode()); Armature *pAr = (Armature *)(pRender->getNode());
CC_BREAK_IF(pAr == nullptr); CC_BREAK_IF(pAr == nullptr);
@ -748,7 +1180,7 @@ void ArmaturePlayAction::serialize(const rapidjson::Value &val)
} }
else if (key == "componentName") else if (key == "componentName")
{ {
_ComName = DICTOOL->getStringValue_json(subDict, "value"); _comName = DICTOOL->getStringValue_json(subDict, "value");
continue; continue;
} }
else if (key == "AnimationName") else if (key == "AnimationName")
@ -759,6 +1191,43 @@ void ArmaturePlayAction::serialize(const rapidjson::Value &val)
} }
} }
void ArmaturePlayAction::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);//DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "componentName")
{
if (str != NULL)
{
_comName = str; //DICTOOL->getStringValue_json(subDict, "value");
}
}
else if (key == "AnimationName")
{
if (str != NULL)
{
_aniname = str; //DICTOOL->getStringValue_json(subDict, "value");
}
}
}
}
void ArmaturePlayAction::removeAll() void ArmaturePlayAction::removeAll()
{ {
CCLOG("ArmaturePlayAction::removeAll"); CCLOG("ArmaturePlayAction::removeAll");

View File

@ -15,6 +15,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
@ -32,6 +33,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
@ -50,6 +52,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
@ -69,6 +72,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
@ -87,6 +91,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
@ -106,6 +111,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
@ -124,6 +130,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
@ -144,6 +151,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
@ -162,6 +170,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
@ -181,6 +190,7 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _id; int _id;
@ -197,10 +207,11 @@ public:
virtual bool init(); virtual bool init();
virtual void done(); virtual void done();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
std::string _ComName; std::string _comName;
std::string _aniname; std::string _aniname;
}; };

View File

@ -47,6 +47,28 @@ void TimeElapsed::serialize(const rapidjson::Value &val)
} }
} }
void TimeElapsed::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "TotalTime")
{
if (str != NULL)
{
_totalTime = atof(str); //DICTOOL->getFloatValue_json(subDict, "value");
}
}
}
}
void TimeElapsed::removeAll() void TimeElapsed::removeAll()
{ {
_scheduler->unschedule(schedule_selector(TimeElapsed::update), this); _scheduler->unschedule(schedule_selector(TimeElapsed::update), this);
@ -125,6 +147,50 @@ void ArmatureActionState::serialize(const rapidjson::Value &val)
} }
} }
void ArmatureActionState::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);//DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "componentName")
{
if (str != NULL)
{
_comName = str; //DICTOOL->getStringValue_json(subDict, "value");
}
}
else if (key == "AnimationName")
{
if (str != NULL)
{
_aniname = str; //DICTOOL->getStringValue_json(subDict, "value");
}
}
else if (key == "ActionType")
{
if (str != NULL)
{
_state = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
}
}
void ArmatureActionState::removeAll() void ArmatureActionState::removeAll()
{ {
do do
@ -209,6 +275,56 @@ void NodeInRect::serialize(const rapidjson::Value &val)
} }
} }
void NodeInRect::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);//DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "originX")
{
if (str != NULL)
{
_origin.x = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "originY")
{
if (str != NULL)
{
_origin.y = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "sizeWidth")
{
if (str != NULL)
{
_size.width = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "sizeHeight")
{
if (str != NULL)
{
_size.height = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
}
}
void NodeInRect::removeAll() void NodeInRect::removeAll()
{ {
CCLOG("NodeInRect::removeAll"); CCLOG("NodeInRect::removeAll");
@ -261,6 +377,35 @@ void NodeVisible::serialize(const rapidjson::Value &val)
} }
} }
void NodeVisible::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);//DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "Visible")
{
if (str != NULL)
{
_visible = atoi(str) != 0? true:false;//DICTOOL->getIntValue_json(subDict, "value") != 0? true:false;
}
}
}
}
void NodeVisible::removeAll() void NodeVisible::removeAll()
{ {
CCLOG("NodeVisible::removeAll"); CCLOG("NodeVisible::removeAll");

View File

@ -15,6 +15,7 @@ public:
virtual bool init(); virtual bool init();
virtual bool detect(); virtual bool detect();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
virtual void update(float dt); virtual void update(float dt);
private: private:
@ -35,6 +36,7 @@ public:
virtual bool init(); virtual bool init();
virtual bool detect(); virtual bool detect();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID); void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID);
private: private:
@ -56,6 +58,7 @@ public:
virtual bool init(); virtual bool init();
virtual bool detect(); virtual bool detect();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;
@ -73,6 +76,7 @@ public:
virtual bool init(); virtual bool init();
virtual bool detect(); virtual bool detect();
virtual void serialize(const rapidjson::Value &val); virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll(); virtual void removeAll();
private: private:
int _tag; int _tag;

View File

@ -1274,28 +1274,28 @@ void NodeNameTest::test(float dt)
// enumerateChildren() // enumerateChildren()
// name = regular expression // name = regular expression
int i = 0; int i = 0;
parent = Node::create(); // parent = Node::create();
for (int i = 0; i < 100; ++i) // for (int i = 0; i < 100; ++i)
{ // {
auto node = Node::create(); // auto node = Node::create();
sprintf(name, "node%d", i); // sprintf(name, "node%d", i);
node->setName(name); // node->setName(name);
parent->addChild(node); // parent->addChild(node);
} // }
//
i = 0; // i = 0;
parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool { // parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool {
++i; // ++i;
return false; // return false;
}); // });
CCAssert(i == 100, ""); // CCAssert(i == 100, "");
//
i = 0; // i = 0;
parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool { // parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool {
++i; // ++i;
return true; // return true;
}); // });
CCAssert(i == 1, ""); // CCAssert(i == 1, "");
// enumerateChildren // enumerateChildren
@ -1331,89 +1331,119 @@ void NodeNameTest::test(float dt)
}); });
CCAssert(i == 1, ""); CCAssert(i == 1, "");
i = 0; // search from root
parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
++i;
return false;
});
CCAssert(i == 10000, "");
i = 0;
parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
++i;
return true;
});
CCAssert(i == 1, "");
// search from parent
// name is xxx/..
i = 0;
parent->enumerateChildren("node/..", [&i](Node* node) -> bool {
++i;
return true;
});
CCAssert(i == 1, "");
i = 0;
parent->enumerateChildren("node/..", [&i](Node* node) -> bool {
++i;
return false;
});
CCAssert(i == 10000, "");
// name = /xxx : search from root
parent = getScene(); parent = getScene();
for (int j = 0; j < 100; j++) for (int i = 0; i < 100; ++i)
{ {
auto node = Node::create(); auto node = Node::create();
sprintf(name, "node%d", j); node->setName("node");
node->setName(name);
parent->addChild(node); parent->addChild(node);
for (int k = 0; k < 100; ++k) for (int j = 0; j < 100; ++j)
{ {
auto child = Node::create(); auto child = Node::create();
sprintf(name, "node%d", k); child->setName("child");
child->setName(name);
node->addChild(child); node->addChild(child);
} }
} }
i = 0; i = 0;
enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool { parent->enumerateChildren("/node", [&i](Node* node) -> bool {
++i; ++i;
return false; return false;
}); });
CCAssert(i == 100, ""); CCAssert(i == 100, "");
i = 0; i = 0;
enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool { parent->enumerateChildren("//child", [&i](Node* node) -> bool {
++i;
return true;
});
CCAssert(i == 1, "");
i = 0;
enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
++i;
return false;
});
CCAssert(i == 10100, ""); // 10000(children) + 100(parent)
i = 0;
enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
++i;
return true;
});
CCAssert(i == 1, "");
i = 0;
enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool {
++i; ++i;
return false; return false;
}); });
CCAssert(i == 10000, ""); CCAssert(i == 10000, "");
// i = 0;
// parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
// ++i;
// return false;
// });
// CCAssert(i == 10000, "");
//
// i = 0;
// parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool {
// ++i;
// return true;
// });
// CCAssert(i == 1, "");
// search from parent
// name is xxx/..
// i = 0;
// parent->enumerateChildren("node/..", [&i](Node* node) -> bool {
// ++i;
// return true;
// });
// CCAssert(i == 1, "");
//
// i = 0;
// parent->enumerateChildren("node/..", [&i](Node* node) -> bool {
// ++i;
// return false;
// });
// CCAssert(i == 10000, "");
// name = /xxx : search from root
// parent = getScene();
// for (int j = 0; j < 100; j++)
// {
// auto node = Node::create();
// sprintf(name, "node%d", j);
// node->setName(name);
// parent->addChild(node);
//
// for (int k = 0; k < 100; ++k)
// {
// auto child = Node::create();
// sprintf(name, "node%d", k);
// child->setName(name);
// node->addChild(child);
// }
// }
//
// i = 0;
// enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool {
// ++i;
// return false;
// });
// CCAssert(i == 100, "");
// i = 0;
// enumerateChildren("/node[[:digit:]]+", [&i](Node* node) -> bool {
// ++i;
// return true;
// });
// CCAssert(i == 1, "");
//
// i = 0;
// enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
// ++i;
// return false;
// });
// CCAssert(i == 10100, ""); // 10000(children) + 100(parent)
//
// i = 0;
// enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool {
// ++i;
// return true;
// });
// CCAssert(i == 1, "");
//
// i = 0;
// enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool {
// ++i;
// return false;
// });
// CCAssert(i == 10000, "");
// utils::findChildren() // utils::findChildren()
parent = Node::create(); parent = Node::create();

View File

@ -341,7 +341,6 @@ Effect3DOutline::Effect3DOutline()
Effect3DOutline::~Effect3DOutline() Effect3DOutline::~Effect3DOutline()
{ {
CC_SAFE_RELEASE_NULL(_sprite);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener); Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener);
#endif #endif
@ -371,8 +370,6 @@ void Effect3DOutline::setTarget(EffectSprite3D *sprite)
if(sprite != _sprite) if(sprite != _sprite)
{ {
CC_SAFE_RETAIN(sprite);
CC_SAFE_RELEASE_NULL(_sprite);
_sprite = sprite; _sprite = sprite;
auto mesh = sprite->getMesh(); auto mesh = sprite->getMesh();

View File

@ -103,6 +103,7 @@ protected:
Vec3 _outlineColor; Vec3 _outlineColor;
float _outlineWidth; float _outlineWidth;
//weak reference
EffectSprite3D* _sprite; EffectSprite3D* _sprite;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
EventListenerCustom* _backToForegroundListener; EventListenerCustom* _backToForegroundListener;

View File

@ -10,4 +10,4 @@
# Project target. # Project target.
target=android-10 target=android-10
android.library.reference.1=../../../cocos/platform/android/ControllerDelegate android.library.reference.1=../../../cocos/platform/android/ControllerAutoAdapter

View File

@ -23,14 +23,10 @@ THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
package org.cocos2dx.game_controller_test; package org.cocos2dx.game_controller_test;
import java.util.ArrayList;
import org.cocos2dx.lib.GameControllerActivity; import org.cocos2dx.lib.GameControllerActivity;
import org.cocos2dx.lib.GameControllerHelper.ControllerListener; //import org.cocos2dx.lib.GameControllerHelper.ControllerListener;
import android.bluetooth.BluetoothDevice;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
public class AppActivity extends GameControllerActivity { public class AppActivity extends GameControllerActivity {
@ -42,61 +38,12 @@ public class AppActivity extends GameControllerActivity {
//Automatic adaptation for connect controller. //Automatic adaptation for connect controller.
//Supported Platform: Nibiru / Moga / Ouya TV //Supported Platform: Nibiru / Moga / Ouya TV
//mControllerHelper.setControllerListener(controllerListener); this.connectController();
mControllerHelper.connectController();
//Manually specify an adapter. //Manually specify an adapter.
//setGameControllerInstance(new GameControllerNibiru()); //Requirements: using libControllerDriveAdapter project
//setGameControllerInstance(new GameControllerMoga()); //this.connectController(DRIVERTYPE_NIBIRU);
//setGameControllerInstance(new GameControllerOuya()); //this.connectController(DRIVERTYPE_MOGA);
//this.connectController(DRIVERTYPE_OUYA);
} }
ControllerListener controllerListener = new ControllerListener() {
@Override
public void onDownloadConfigStarted() {
Log.w("controllerListener", "onDownloadDepsFinished");
}
@Override
public void onDownloadConfigFinished(boolean isSuccess) {
//If download failed
Log.w("controllerListener", "onDownloadConfigFinished:" + isSuccess);
}
@Override
public void onControllerDiscoveryStarted() {
Log.w("controllerListener", "onControllerDiscoveryStarted");
}
@Override
public void onControllerDiscoveryFinish(ArrayList<BluetoothDevice> devices) {
Log.w("controllerListener", "onControllerDiscoveryFinish");
}
@Override
public void onDownloadDepsStarted() {
Log.w("controllerListener", "onDownloadDepsStarted");
}
@Override
public void onDownloadDepsProgress(int bytesWritten, int totalSize) {
Log.w("controllerListener", "onDownloadDepsProgress");
}
@Override
public void onDownloadDepsFinished(boolean isSuccess) {
Log.w("controllerListener", "");
}
@Override
public void onInstallDriver(String filePath) {
Log.w("controllerListener", "onInstallDriver");
}
@Override
public void onConnectController() {
Log.w("controllerListener", "onConnectController");
}
};
} }