From 79acf80fb16f24e507d3cbfa8759917b0305d99a Mon Sep 17 00:00:00 2001 From: pipu Date: Wed, 17 Dec 2014 19:00:24 +0800 Subject: [PATCH] Update that avoid crash during load resource which serialize by flat buffers --- .../ButtonReader/ButtonReader.cpp | 212 +++++++++++- .../CheckBoxReader/CheckBoxReader.cpp | 315 +++++++++++++++++- .../GameMapReader/GameMapReader.cpp | 33 +- .../ImageViewReader/ImageViewReader.cpp | 63 +++- .../LayoutReader/LayoutReader.cpp | 67 +++- .../ListViewReader/ListViewReader.cpp | 77 ++++- .../LoadingBarReader/LoadingBarReader.cpp | 63 +++- .../PageViewReader/PageViewReader.cpp | 67 +++- .../ParticleReader/ParticleReader.cpp | 31 +- .../ScrollViewReader/ScrollViewReader.cpp | 66 +++- .../SliderReader/SliderReader.cpp | 315 +++++++++++++++++- .../SpriteReader/SpriteReader.cpp | 46 ++- .../TextBMFontReader/TextBMFontReader.cpp | 40 ++- .../TextFieldReader/TextFieldReader.cpp | 24 +- .../WidgetReader/TextReader/TextReader.cpp | 24 +- 15 files changed, 1371 insertions(+), 72 deletions(-) diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index 15dfbeaf1d..e4136795a5 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -547,21 +547,195 @@ namespace cocostudio bool scale9Enabled = options->scale9Enabled(); button->setScale9Enabled(scale9Enabled); - + bool normalFileExist = false; + std::string normalErrorFilePath = ""; auto normalDic = options->normalData(); int normalType = normalDic->resourceType(); - std::string normalTexturePath = normalDic->path()->c_str(); - button->loadTextureNormal(normalTexturePath, (Widget::TextureResType)normalType); + std::string normalTexturePath = this->getResourcePath(normalDic->path()->c_str(), (Widget::TextureResType)normalType); + switch (normalType) + { + case 0: + if (FileUtils::getInstance()->isFileExist(normalTexturePath)) + { + normalFileExist = true; + } + else + { + normalErrorFilePath = normalTexturePath; + normalFileExist = false; + } + break; + + case 1: + { + std::string plist = normalDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(normalTexturePath); + if (spriteFrame) + { + normalFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + normalErrorFilePath = textureFileName; + } + } + else + { + normalErrorFilePath = plist; + } + normalFileExist = false; + } + break; + } + + default: + break; + } + if (normalFileExist) + { + button->loadTextureNormal(normalTexturePath, (Widget::TextureResType)normalType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", normalErrorFilePath.c_str())->getCString()); + button->addChild(label); + } + bool pressedFileExist = false; + std::string pressedErrorFilePath = ""; auto pressedDic = options->pressedData(); int pressedType = pressedDic->resourceType(); - std::string pressedTexturePath = pressedDic->path()->c_str(); - button->loadTexturePressed(pressedTexturePath, (Widget::TextureResType)pressedType); + std::string pressedTexturePath = this->getResourcePath(pressedDic->path()->c_str(), (Widget::TextureResType)pressedType); + switch (pressedType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(pressedTexturePath)) + { + pressedFileExist = true; + } + else + { + pressedErrorFilePath = pressedTexturePath; + pressedFileExist = false; + } + break; + } + + case 1: + { + std::string plist = pressedDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(pressedTexturePath); + if (spriteFrame) + { + pressedFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + pressedErrorFilePath = textureFileName; + } + } + else + { + pressedErrorFilePath = plist; + } + pressedFileExist = false; + } + break; + } + + default: + break; + } + if (pressedFileExist) + { + button->loadTexturePressed(pressedTexturePath, (Widget::TextureResType)pressedType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", pressedErrorFilePath.c_str())->getCString()); + button->addChild(label); + } + bool disabledFileExist = false; + std::string disabledErrorFilePath = ""; auto disabledDic = options->disabledData(); int disabledType = disabledDic->resourceType(); - std::string disabledTexturePath = disabledDic->path()->c_str(); - button->loadTextureDisabled(disabledTexturePath, (Widget::TextureResType)disabledType); + std::string disabledTexturePath = this->getResourcePath(disabledDic->path()->c_str(), (Widget::TextureResType)disabledType); + switch (disabledType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(disabledTexturePath)) + { + disabledFileExist = true; + } + else + { + disabledErrorFilePath = disabledTexturePath; + disabledFileExist = false; + } + break; + } + + case 1: + { + std::string plist = disabledDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(disabledTexturePath); + if (spriteFrame) + { + disabledFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + disabledErrorFilePath = textureFileName; + } + } + else + { + disabledErrorFilePath = plist; + } + disabledFileExist = false; + } + break; + } + + default: + break; + } + if (disabledFileExist) + { + button->loadTextureDisabled(disabledTexturePath, (Widget::TextureResType)disabledType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", disabledErrorFilePath.c_str())->getCString()); + button->addChild(label); + } std::string titleText = options->text()->c_str(); button->setTitleText(titleText); @@ -577,16 +751,36 @@ namespace cocostudio button->setTitleFontName(titleFontName); auto resourceData = options->fontResource(); + bool fileExist = false; + std::string errorFilePath = ""; std::string path = resourceData->path()->c_str(); if (path != "") { - button->setTitleFontName(path); + if (FileUtils::getInstance()->isFileExist(path)) + { + fileExist = true; + } + else + { + errorFilePath = path; + fileExist = false; + } + if (fileExist) + { + button->setTitleFontName(path); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + button->addChild(label); + } } bool displaystate = options->displaystate(); button->setBright(displaystate); button->setEnabled(displaystate); - + auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); diff --git a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp index c251648135..8d5fdfc592 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp @@ -429,34 +429,329 @@ namespace cocostudio CheckBox* checkBox = static_cast(node); //load background image + bool backGroundFileExist = false; + std::string backGroundErrorFilePath = ""; auto backGroundDic = options->backGroundBoxData(); int backGroundType = backGroundDic->resourceType(); - std::string backGroundTexturePath = backGroundDic->path()->c_str(); - checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType); + std::string backGroundTexturePath = this->getResourcePath(backGroundDic->path()->c_str(), (Widget::TextureResType)backGroundType); + switch (backGroundType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(backGroundTexturePath)) + { + backGroundFileExist = true; + } + else + { + backGroundErrorFilePath = backGroundTexturePath; + backGroundFileExist = false; + } + break; + } + + case 1: + { + std::string plist = backGroundDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundTexturePath); + if (spriteFrame) + { + backGroundFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + backGroundErrorFilePath = textureFileName; + } + } + else + { + backGroundErrorFilePath = plist; + } + backGroundFileExist = false; + } + break; + } + + default: + break; + } + if (backGroundFileExist) + { + checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", backGroundErrorFilePath.c_str())->getCString()); + checkBox->addChild(label); + } //load background selected image + bool backGroundSelectedfileExist = false; + std::string backGroundSelectedErrorFilePath = ""; auto backGroundSelectedDic = options->backGroundBoxSelectedData(); int backGroundSelectedType = backGroundSelectedDic->resourceType(); - std::string backGroundSelectedTexturePath = backGroundSelectedDic->path()->c_str(); - checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType); + std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic->path()->c_str(), (Widget::TextureResType)backGroundSelectedType); + switch (backGroundSelectedType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(backGroundSelectedTexturePath)) + { + backGroundSelectedfileExist = true; + } + else + { + backGroundSelectedErrorFilePath = backGroundSelectedTexturePath; + backGroundSelectedfileExist = false; + } + break; + } + + case 1: + { + std::string plist = backGroundSelectedDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundSelectedTexturePath); + if (spriteFrame) + { + backGroundSelectedfileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + backGroundSelectedErrorFilePath = textureFileName; + } + } + else + { + backGroundSelectedErrorFilePath = plist; + } + backGroundSelectedfileExist = false; + } + break; + } + + default: + break; + } + if (backGroundSelectedfileExist) + { + checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", backGroundSelectedErrorFilePath.c_str())->getCString()); + checkBox->addChild(label); + } //load frontCross image + bool frontCrossFileExist = false; + std::string frontCrossErrorFilePath = ""; auto frontCrossDic = options->frontCrossData(); int frontCrossType = frontCrossDic->resourceType(); - std::string frontCrossFileName = frontCrossDic->path()->c_str(); - checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType); + std::string frontCrossFileName = this->getResourcePath(frontCrossDic->path()->c_str(), (Widget::TextureResType)frontCrossType); + switch (frontCrossType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(frontCrossFileName)) + { + frontCrossFileExist = true; + } + else + { + frontCrossErrorFilePath = frontCrossFileName; + frontCrossFileExist = false; + } + break; + } + + case 1: + { + std::string plist = frontCrossDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(frontCrossFileName); + if (spriteFrame) + { + frontCrossFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + frontCrossErrorFilePath = textureFileName; + } + } + else + { + frontCrossErrorFilePath = plist; + } + frontCrossFileExist = false; + } + break; + } + + default: + break; + } + if (frontCrossFileExist) + { + checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", frontCrossErrorFilePath.c_str())->getCString()); + checkBox->addChild(label); + } //load backGroundBoxDisabledData + bool backGroundBoxDisabledFileExist = false; + std::string backGroundBoxDisabledErrorFilePath = ""; auto backGroundDisabledDic = options->backGroundBoxDisabledData(); int backGroundDisabledType = backGroundDisabledDic->resourceType(); - std::string backGroundDisabledFileName = backGroundDisabledDic->path()->c_str(); - checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType); + std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic->path()->c_str(), (Widget::TextureResType)backGroundDisabledType); + switch (backGroundDisabledType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(backGroundDisabledFileName)) + { + backGroundBoxDisabledFileExist = true; + } + else + { + backGroundBoxDisabledErrorFilePath = backGroundDisabledFileName; + backGroundBoxDisabledFileExist = false; + } + break; + } + + case 1: + { + std::string plist = backGroundDisabledDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundDisabledFileName); + if (spriteFrame) + { + backGroundBoxDisabledFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + backGroundBoxDisabledErrorFilePath = textureFileName; + } + } + else + { + backGroundBoxDisabledErrorFilePath = plist; + } + backGroundBoxDisabledFileExist = false; + } + break; + } + + default: + break; + } + if (backGroundBoxDisabledFileExist) + { + checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", backGroundBoxDisabledErrorFilePath.c_str())->getCString()); + checkBox->addChild(label); + } ///load frontCrossDisabledData + bool frontCrossDisabledFileExist = false; + std::string frontCrossDisabledErrorFilePath = ""; auto frontCrossDisabledDic = options->frontCrossDisabledData(); int frontCrossDisabledType = frontCrossDisabledDic->resourceType(); - std::string frontCrossDisabledFileName = frontCrossDisabledDic->path()->c_str(); - checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType); + std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic->path()->c_str(), (Widget::TextureResType)frontCrossDisabledType); + switch (frontCrossDisabledType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(frontCrossDisabledFileName)) + { + frontCrossDisabledFileExist = true; + } + else + { + frontCrossDisabledErrorFilePath = frontCrossDisabledFileName; + frontCrossDisabledFileExist = false; + } + break; + } + + case 1: + { + std::string plist = frontCrossDisabledDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(frontCrossDisabledFileName); + if (spriteFrame) + { + frontCrossDisabledFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + frontCrossDisabledErrorFilePath = textureFileName; + } + } + else + { + frontCrossDisabledErrorFilePath = plist; + } + frontCrossDisabledFileExist = false; + } + break; + } + + default: + break; + } + if (frontCrossDisabledFileExist) + { + checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", frontCrossDisabledErrorFilePath.c_str())->getCString()); + checkBox->addChild(label); + } bool selectedstate = options->selectedState(); checkBox->setSelected(selectedstate); diff --git a/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp index 6963d73377..8f4a642f3d 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp @@ -134,17 +134,22 @@ namespace cocostudio auto options = (GameMapOptions*)gameMapOptions; auto fileNameData = options->fileNameData(); + bool fileExist = false; + std::string errorFilePath = ""; + std::string path = fileNameData->path()->c_str(); int resourceType = fileNameData->resourceType(); switch (resourceType) { case 0: { - std::string path = fileNameData->path()->c_str(); - const char* tmxFile = path.c_str(); - - if (tmxFile && strcmp("", tmxFile) != 0) + if (FileUtils::getInstance()->isFileExist(path)) { - tmx = TMXTiledMap::create(tmxFile); + fileExist = true; + } + else + { + errorFilePath = path; + fileExist = false; } break; } @@ -152,10 +157,22 @@ namespace cocostudio default: break; } - - if (tmx) + if (fileExist) { - setPropsWithFlatBuffers(tmx, (Table*)gameMapOptions); + tmx = TMXTiledMap::create(path); + if (tmx) + { + setPropsWithFlatBuffers(tmx, (Table*)gameMapOptions); + } + } + else + { + Node* node = Node::create(); + setPropsWithFlatBuffers(node, (Table*)gameMapOptions); + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + node->addChild(label); + return node; } return tmx; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp index ff73358b02..1fbd8da0ac 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -291,10 +291,69 @@ namespace cocostudio auto options = (ImageViewOptions*)imageViewOptions; + bool fileExist = false; + std::string errorFilePath = ""; auto imageFileNameDic = options->fileNameData(); int imageFileNameType = imageFileNameDic->resourceType(); - std::string imageFileName = imageFileNameDic->path()->c_str(); - imageView->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType); + std::string imageFileName = this->getResourcePath(imageFileNameDic->path()->c_str(), (Widget::TextureResType)imageFileNameType); + switch (imageFileNameType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(imageFileName)) + { + fileExist = true; + } + else + { + errorFilePath = imageFileName; + fileExist = false; + } + break; + } + + case 1: + { + std::string plist = imageFileNameDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(imageFileName); + if (spriteFrame) + { + fileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + errorFilePath = textureFileName; + } + } + else + { + errorFilePath = plist; + } + fileExist = false; + } + break; + } + + default: + break; + } + if (fileExist) + { + imageView->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + imageView->addChild(label); + } bool scale9Enabled = options->scale9Enabled(); imageView->setScale9Enabled(scale9Enabled); diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp index 96aef6aa96..1d840e3fbd 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -598,10 +598,72 @@ namespace cocostudio panel->setBackGroundColorOpacity(bgColorOpacity); + bool fileExist = false; + std::string errorFilePath = ""; auto imageFileNameDic = options->backGroundImageData(); int imageFileNameType = imageFileNameDic->resourceType(); - std::string imageFileName = imageFileNameDic->path()->c_str(); - panel->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType); + std::string imageFileName = this->getResourcePath(imageFileNameDic->path()->c_str(), (Widget::TextureResType)imageFileNameType); + if (imageFileName != "") + { + switch (imageFileNameType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(imageFileName)) + { + fileExist = true; + } + else + { + errorFilePath = imageFileName; + fileExist = false; + } + break; + } + + case 1: + { + std::string plist = imageFileNameDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(imageFileName); + if (spriteFrame) + { + fileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + errorFilePath = textureFileName; + } + } + else + { + errorFilePath = plist; + } + fileExist = false; + } + break; + } + + default: + break; + } + if (fileExist) + { + panel->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + panel->addChild(label); + } + } auto widgetOptions = options->widgetOptions(); auto f_color = widgetOptions->color(); @@ -614,6 +676,7 @@ namespace cocostudio auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); + if (backGroundScale9Enabled) { auto f_capInsets = options->capInsets(); diff --git a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp index d67d9acbca..4272f4b14a 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp @@ -426,10 +426,72 @@ namespace cocostudio listView->setBackGroundColorOpacity(bgColorOpacity); + bool fileExist = false; + std::string errorFilePath = ""; auto imageFileNameDic = options->backGroundImageData(); int imageFileNameType = imageFileNameDic->resourceType(); std::string imageFileName = imageFileNameDic->path()->c_str(); - listView->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType); + if (imageFileName != "") + { + switch (imageFileNameType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(imageFileName)) + { + fileExist = true; + } + else + { + errorFilePath = imageFileName; + fileExist = false; + } + break; + } + + case 1: + { + std::string plist = imageFileNameDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(imageFileName); + if (spriteFrame) + { + fileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + errorFilePath = textureFileName; + } + } + else + { + errorFilePath = plist; + } + fileExist = false; + } + break; + } + + default: + break; + } + if (fileExist) + { + listView->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + listView->addChild(label); + } + } auto widgetOptions = options->widgetOptions(); auto f_color = widgetOptions->color(); @@ -442,9 +504,15 @@ namespace cocostudio auto f_innerSize = options->innerSize(); Size innerSize(f_innerSize->width(), f_innerSize->height()); listView->setInnerContainerSize(innerSize); + // int direction = options->direction(); + // listView->setDirection((ScrollView::Direction)direction); bool bounceEnabled = options->bounceEnabled(); listView->setBounceEnabled(bounceEnabled); + // int gravityValue = options->gravity(); + // ListView::Gravity gravity = (ListView::Gravity)gravityValue; + // listView->setGravity(gravity); + std::string directionType = options->directionType()->c_str(); if (directionType == "") { @@ -453,7 +521,7 @@ namespace cocostudio if (verticalType == "") { listView->setGravity(ListView::Gravity::TOP); - } + } else if (verticalType == "Align_Bottom") { listView->setGravity(ListView::Gravity::BOTTOM); @@ -462,7 +530,7 @@ namespace cocostudio { listView->setGravity(ListView::Gravity::CENTER_VERTICAL); } - } + } else if (directionType == "Vertical") { listView->setDirection(ListView::Direction::VERTICAL); @@ -483,7 +551,7 @@ namespace cocostudio float itemMargin = options->itemMargin(); listView->setItemsMargin(itemMargin); - + auto widgetReader = WidgetReader::getInstance(); widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions()); @@ -499,7 +567,6 @@ namespace cocostudio } else { - auto widgetOptions = options->widgetOptions(); if (!listView->isIgnoreContentAdaptWithSize()) { Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp index 20d20e393d..76d198e1d7 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -241,10 +241,69 @@ namespace cocostudio LoadingBar* loadingBar = static_cast(node); auto options = (LoadingBarOptions*)loadingBarOptions; + bool fileExist = false; + std::string errorFilePath = ""; auto imageFileNameDic = options->textureData(); int imageFileNameType = imageFileNameDic->resourceType(); - std::string imageFileName = imageFileNameDic->path()->c_str(); - loadingBar->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType); + std::string imageFileName = this->getResourcePath(imageFileNameDic->path()->c_str(), (Widget::TextureResType)imageFileNameType); + switch (imageFileNameType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(imageFileName)) + { + fileExist = true; + } + else + { + errorFilePath = imageFileName; + fileExist = false; + } + break; + } + + case 1: + { + std::string plist = imageFileNameDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(imageFileName); + if (spriteFrame) + { + fileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + errorFilePath = textureFileName; + } + } + else + { + errorFilePath = plist; + } + fileExist = false; + } + break; + } + + default: + break; + } + if (fileExist) + { + loadingBar->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + loadingBar->addChild(label); + } int direction = options->direction(); loadingBar->setDirection(LoadingBar::Direction(direction)); diff --git a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp index 9737d6d4db..0285bf55ff 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp @@ -339,11 +339,72 @@ namespace cocostudio pageView->setBackGroundColorOpacity(bgColorOpacity); + bool fileExist = false; + std::string errorFilePath = ""; auto imageFileNameDic = options->backGroundImageData(); int imageFileNameType = imageFileNameDic->resourceType(); - std::string imageFileName = imageFileNameDic->path()->c_str(); - pageView->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType); - + std::string imageFileName = this->getResourcePath(imageFileNameDic->path()->c_str(), (Widget::TextureResType)imageFileNameType); + if (imageFileName != "") + { + switch (imageFileNameType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(imageFileName)) + { + fileExist = true; + } + else + { + errorFilePath = imageFileName; + fileExist = false; + } + break; + } + + case 1: + { + std::string plist = imageFileNameDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(imageFileName); + if (spriteFrame) + { + fileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + errorFilePath = textureFileName; + } + } + else + { + errorFilePath = plist; + } + fileExist = false; + } + break; + } + + default: + break; + } + if (fileExist) + { + pageView->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + pageView->addChild(label); + } + } auto widgetOptions = options->widgetOptions(); auto f_color = widgetOptions->color(); diff --git a/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp index 321d3b6c40..dc7f7a7d63 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp @@ -134,15 +134,22 @@ namespace cocostudio auto options = (ParticleSystemOptions*)particleOptions; auto fileNameData = options->fileNameData(); + bool fileExist = false; + std::string errorFilePath = ""; + std::string path = fileNameData->path()->c_str(); int resourceType = fileNameData->resourceType(); switch (resourceType) { case 0: { - std::string path = fileNameData->path()->c_str(); - if (path != "") + if (FileUtils::getInstance()->isFileExist(path)) { - particle = ParticleSystemQuad::create(path); + fileExist = true; + } + else + { + errorFilePath = path; + fileExist = false; } break; } @@ -150,10 +157,22 @@ namespace cocostudio default: break; } - - if (particle) + if (fileExist) { - setPropsWithFlatBuffers(particle, (Table*)particleOptions); + particle = ParticleSystemQuad::create(path); + if (particle) + { + setPropsWithFlatBuffers(particle, (Table*)particleOptions); + } + } + else + { + Node* node = Node::create(); + setPropsWithFlatBuffers(node, (Table*)particleOptions); + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + node->addChild(label); + return node; } return particle; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp index 96d6eb1870..9dd10412bf 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp @@ -425,10 +425,72 @@ namespace cocostudio scrollView->setBackGroundColorOpacity(bgColorOpacity); + bool fileExist = false; + std::string errorFilePath = ""; auto imageFileNameDic = options->backGroundImageData(); int imageFileNameType = imageFileNameDic->resourceType(); - std::string imageFileName = imageFileNameDic->path()->c_str(); - scrollView->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType); + std::string imageFileName = this->getResourcePath(imageFileNameDic->path()->c_str(), (Widget::TextureResType)imageFileNameType); + if (imageFileName != "") + { + switch (imageFileNameType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(imageFileName)) + { + fileExist = true; + } + else + { + errorFilePath = imageFileName; + fileExist = false; + } + break; + } + + case 1: + { + std::string plist = imageFileNameDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(imageFileName); + if (spriteFrame) + { + fileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + errorFilePath = textureFileName; + } + } + else + { + errorFilePath = plist; + } + fileExist = false; + } + break; + } + + default: + break; + } + if (fileExist) + { + scrollView->setBackGroundImage(imageFileName, (Widget::TextureResType)imageFileNameType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + scrollView->addChild(label); + } + } auto widgetOptions = options->widgetOptions(); auto f_color = widgetOptions->color(); diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp index b63fde3cd8..4c45a2f1cc 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp @@ -463,34 +463,329 @@ namespace cocostudio int percent = options->percent(); slider->setPercent(percent); + bool imageFileExist = false; + std::string imageErrorFilePath = ""; auto imageFileNameDic = options->barFileNameData(); int imageFileNameType = imageFileNameDic->resourceType(); - std::string imageFileName = imageFileNameDic->path()->c_str(); - slider->loadBarTexture(imageFileName, (Widget::TextureResType)imageFileNameType); + std::string imageFileName = this->getResourcePath(imageFileNameDic->path()->c_str(), (Widget::TextureResType)imageFileNameType); + switch (imageFileNameType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(imageFileName)) + { + imageFileExist = true; + } + else + { + imageErrorFilePath = imageFileName; + imageFileExist = false; + } + break; + } + + case 1: + { + std::string plist = imageFileNameDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(imageFileName); + if (spriteFrame) + { + imageFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + imageErrorFilePath = textureFileName; + } + } + else + { + imageErrorFilePath = plist; + } + imageFileExist = false; + } + break; + } + + default: + break; + } + if (imageFileExist) + { + slider->loadBarTexture(imageFileName, (Widget::TextureResType)imageFileNameType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", imageErrorFilePath.c_str())->getCString()); + slider->addChild(label); + } //loading normal slider ball texture + bool normalFileExist = false; + std::string normalErrorFilePath = ""; auto normalDic = options->ballNormalData(); int normalType = normalDic->resourceType(); - std::string normalFileName = normalDic->path()->c_str(); - slider->loadSlidBallTextureNormal(normalFileName, (Widget::TextureResType)normalType); + std::string normalFileName = this->getResourcePath(normalDic->path()->c_str(), (Widget::TextureResType)normalType); + switch (normalType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(normalFileName)) + { + normalFileExist = true; + } + else + { + normalErrorFilePath = normalFileName; + normalFileExist = false; + } + break; + } + + case 1: + { + std::string plist = normalDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(normalFileName); + if (spriteFrame) + { + normalFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + normalErrorFilePath = textureFileName; + } + } + else + { + normalErrorFilePath = plist; + } + normalFileExist = false; + } + break; + } + + default: + break; + } + if (normalFileExist) + { + slider->loadSlidBallTextureNormal(normalFileName, (Widget::TextureResType)normalType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", normalErrorFilePath.c_str())->getCString()); + slider->addChild(label); + } //loading slider ball press texture + bool pressedFileExist = false; + std::string pressedErrorFilePath = ""; auto pressedDic = options->ballPressedData(); int pressedType = pressedDic->resourceType(); - std::string pressedFileName = pressedDic->path()->c_str(); - slider->loadSlidBallTexturePressed(pressedFileName, (Widget::TextureResType)pressedType); + std::string pressedFileName = this->getResourcePath(pressedDic->path()->c_str(), (Widget::TextureResType)pressedType); + switch (pressedType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(pressedFileName)) + { + pressedFileExist = true; + } + else + { + pressedErrorFilePath = pressedFileName; + pressedFileExist = false; + } + break; + } + + case 1: + { + std::string plist = pressedDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(pressedFileName); + if (spriteFrame) + { + pressedFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + pressedErrorFilePath = textureFileName; + } + } + else + { + pressedErrorFilePath = plist; + } + pressedFileExist = false; + } + break; + } + + default: + break; + } + if (pressedFileExist) + { + slider->loadSlidBallTexturePressed(pressedFileName, (Widget::TextureResType)pressedType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", pressedErrorFilePath.c_str())->getCString()); + slider->addChild(label); + } //loading silder ball disable texture + bool disabledFileExist = false; + std::string disabledErrorFilePath = ""; auto disabledDic = options->ballDisabledData(); int disabledType = disabledDic->resourceType(); - std::string disabledFileName = disabledDic->path()->c_str(); - slider->loadSlidBallTextureDisabled(disabledFileName, (Widget::TextureResType)disabledType); + std::string disabledFileName = this->getResourcePath(disabledDic->path()->c_str(), (Widget::TextureResType)disabledType); + switch (disabledType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(disabledFileName)) + { + disabledFileExist = true; + } + else + { + disabledErrorFilePath = disabledFileName; + disabledFileExist = false; + } + break; + } + + case 1: + { + std::string plist = disabledDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(disabledFileName); + if (spriteFrame) + { + disabledFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + disabledErrorFilePath = textureFileName; + } + } + else + { + disabledErrorFilePath = plist; + } + disabledFileExist = false; + } + break; + } + + default: + break; + } + if (disabledFileExist) + { + slider->loadSlidBallTextureDisabled(disabledFileName, (Widget::TextureResType)disabledType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", disabledErrorFilePath.c_str())->getCString()); + slider->addChild(label); + } //load slider progress texture + bool progressFileExist = false; + std::string progressErrorFilePath = ""; auto progressBarDic = options->progressBarData(); int progressBarType = progressBarDic->resourceType(); - std::string progressBarFileName = progressBarDic->path()->c_str(); - slider->loadProgressBarTexture(progressBarFileName, (Widget::TextureResType)progressBarType); + std::string progressBarFileName = this->getResourcePath(progressBarDic->path()->c_str(), (Widget::TextureResType)progressBarType); + switch (progressBarType) + { + case 0: + { + if (FileUtils::getInstance()->isFileExist(progressBarFileName)) + { + progressFileExist = true; + } + else + { + progressErrorFilePath = progressBarFileName; + progressFileExist = false; + } + break; + } + + case 1: + { + std::string plist = progressBarDic->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(progressBarFileName); + if (spriteFrame) + { + progressFileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + progressErrorFilePath = textureFileName; + } + } + else + { + progressErrorFilePath = plist; + } + progressFileExist = false; + } + break; + } + + default: + break; + } + if (progressFileExist) + { + slider->loadProgressBarTexture(progressBarFileName, (Widget::TextureResType)progressBarType); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", progressErrorFilePath.c_str())->getCString()); + slider->addChild(label); + } bool displaystate = options->displaystate(); slider->setBright(displaystate); diff --git a/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp index 9327aedf7e..645829263d 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp @@ -141,24 +141,54 @@ namespace cocostudio auto fileNameData = options->fileNameData(); int resourceType = fileNameData->resourceType(); + std::string path = fileNameData->path()->c_str(); + + bool fileExist = false; + std::string errorFilePath = ""; + switch (resourceType) { case 0: { - std::string path = fileNameData->path()->c_str(); - if (path != "") + if (FileUtils::getInstance()->isFileExist(path)) { sprite->setTexture(path); + fileExist = true; + } + else + { + errorFilePath = path; + fileExist = false; } break; } case 1: { - std::string path = fileNameData->path()->c_str(); - if (path != "") + std::string plist = fileNameData->plistFile()->c_str(); + SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(path); + if (spriteFrame) { - sprite->setSpriteFrame(path); + sprite->setSpriteFrame(spriteFrame); + fileExist = true; + } + else + { + if (FileUtils::getInstance()->isFileExist(plist)) + { + ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist); + ValueMap metadata = value["metadata"].asValueMap(); + std::string textureFileName = metadata["textureFileName"].asString(); + if (!FileUtils::getInstance()->isFileExist(textureFileName)) + { + errorFilePath = textureFileName; + } + } + else + { + errorFilePath = plist; + } + fileExist = false; } break; } @@ -166,6 +196,12 @@ namespace cocostudio default: break; } + if (!fileExist) + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + sprite->addChild(label); + } auto nodeReader = NodeReader::getInstance(); diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index e9fb8295a1..39502292ca 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -2,6 +2,7 @@ #include "TextBMFontReader.h" +#include "2d/CCFontAtlasCache.h" #include "ui/UITextBMFont.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary_generated.h" @@ -190,23 +191,50 @@ namespace cocostudio auto options = (TextBMFontOptions*)textBMFontOptions; auto cmftDic = options->fileNameData(); + bool fileExist = false; + std::string errorFilePath = ""; + std::string errorContent = ""; + std::string path = cmftDic->path()->c_str(); int cmfType = cmftDic->resourceType(); switch (cmfType) { case 0: { - const char* cmfPath = cmftDic->path()->c_str(); - labelBMFont->setFntFile(cmfPath); + if (FileUtils::getInstance()->isFileExist(path)) + { + FontAtlas* newAtlas = FontAtlasCache::getFontAtlasFNT(path); + if (newAtlas) + { + fileExist = true; + } + else + { + errorContent = "has problem"; + fileExist = false; + } + } + else + { + errorContent = "missed"; + fileExist = false; + } break; } - case 1: - CCLOG("Wrong res type of LabelAtlas!"); - break; - default: break; } + if (fileExist) + { + labelBMFont->setFntFile(path); + } + else + { + errorFilePath = path; + auto label = Label::create(); + label->setString(__String::createWithFormat("%s %s", errorFilePath.c_str(), errorContent.c_str())->getCString()); + labelBMFont->addChild(label); + } std::string text = options->text()->c_str(); labelBMFont->setString(text); diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 7cae65573b..1bf4e66b8d 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -303,11 +303,31 @@ namespace cocostudio } + bool fileExist = false; + std::string errorFilePath = ""; auto resourceData = options->fontResource(); std::string path = resourceData->path()->c_str(); if (path != "") { - textField->setFontName(path); + if (FileUtils::getInstance()->isFileExist(path)) + { + fileExist = true; + } + else + { + errorFilePath = path; + fileExist = false; + } + if (fileExist) + { + textField->setFontName(path); + } + else + { + auto label = Label::create(); + label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + textField->addChild(label); + } } auto widgetReader = WidgetReader::getInstance(); @@ -323,6 +343,8 @@ namespace cocostudio Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); textField->setContentSize(contentSize); } + + } Node* TextFieldReader::createNodeWithFlatBuffers(const flatbuffers::Table *textFieldOptions) diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index 403fecf0d3..f352e03821 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -294,6 +294,7 @@ namespace cocostudio bool touchScaleEnabled = options->touchScaleEnable(); label->setTouchScaleChangeEnabled(touchScaleEnabled); + std::string text = options->text()->c_str(); label->setString(text); @@ -315,11 +316,31 @@ namespace cocostudio TextVAlignment v_alignment = (TextVAlignment)options->vAlignment(); label->setTextVerticalAlignment((TextVAlignment)v_alignment); + bool fileExist = false; + std::string errorFilePath = ""; auto resourceData = options->fontResource(); std::string path = resourceData->path()->c_str(); if (path != "") { - label->setFontName(path); + if (FileUtils::getInstance()->isFileExist(path)) + { + fileExist = true; + } + else + { + errorFilePath = path; + fileExist = false; + } + if (fileExist) + { + label->setFontName(path); + } + else + { + auto alert = Label::create(); + alert->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString()); + label->addChild(alert); + } } auto widgetReader = WidgetReader::getInstance(); @@ -336,6 +357,7 @@ namespace cocostudio Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height()); label->setContentSize(contentSize); } + } Node* TextReader::createNodeWithFlatBuffers(const flatbuffers::Table *textOptions)