add version 300 parsing code in widget reader

This commit is contained in:
andyque 2014-06-05 10:25:08 +08:00
parent b570487bf3
commit 8690122c96
31 changed files with 1189 additions and 33 deletions

View File

@ -39,10 +39,11 @@ THE SOFTWARE.
#include "WidgetReader/PageViewReader/PageViewReader.h"
#include "WidgetReader/ScrollViewReader/ScrollViewReader.h"
#include "WidgetReader/ListViewReader/ListViewReader.h"
#include "cocostudio/CocoLoader.h"
#include "ui/CocosGUI.h"
using namespace cocos2d::ui;
using namespace cocos2d;
using namespace cocos2d::ui;
namespace cocostudio {
@ -129,7 +130,7 @@ int GUIReader::getVersionInteger(const char *str)
int is = atoi(s.c_str());
int iVersion = it*1000+ih*100+ite*10+is;
CCLOG("iversion %d",iVersion);
// CCLOG("iversion %d",iVersion);
return iVersion;
/************************/
}
@ -140,8 +141,8 @@ void GUIReader::storeFileDesignSize(const char *fileName, const cocos2d::Size &s
keyWidth.append("width");
std::string keyHeight = fileName;
keyHeight.append("height");
_fileDesignSizes[keyWidth] = Value(size.width);
_fileDesignSizes[keyHeight] = Value(size.height);
_fileDesignSizes[keyWidth] = cocos2d::Value(size.width);
_fileDesignSizes[keyHeight] = cocos2d::Value(size.height);
}
const cocos2d::Size GUIReader::getFileDesignSize(const char* fileName) const
@ -269,6 +270,104 @@ WidgetReaderProtocol* WidgetPropertiesReader::createWidgetReaderProtocol(const s
Widget* GUIReader::widgetFromBinaryFile(const char *fileName)
{
std::string jsonpath;
rapidjson::Document jsonDict;
jsonpath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
size_t pos = jsonpath.find_last_of('/');
m_strFilePath = jsonpath.substr(0,pos+1);
ssize_t nSize = 0;
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
unsigned char* pBuffer = FileUtils::getInstance()->getFileData(fullPath, "rb", &nSize);
const char* fileVersion = "";
ui::Widget* widget = nullptr;
if (pBuffer != NULL && nSize > 0)
{
CocoLoader tCocoLoader;
if(true == tCocoLoader.ReadCocoBinBuff((char*)pBuffer))
{
stExpCocoNode* tpRootCocoNode = tCocoLoader.GetRootCocoNode();
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType)
{
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray();
//rapidjson::Type tType = tpChildArray[i].GetType(pCocoLoader);
std::string strValue = tpChildArray[7].GetValue();
fileVersion = strValue.c_str();
WidgetPropertiesReader * pReader = nullptr;
if (fileVersion)
{
int versionInteger = getVersionInteger(fileVersion);
if (versionInteger < 250)
{
pReader = new WidgetPropertiesReader0250();
widget = pReader->createWidgetFromBinary(&tCocoLoader, tpRootCocoNode, fileName);
}
else
{
pReader = new WidgetPropertiesReader0300();
widget = pReader->createWidgetFromBinary(&tCocoLoader, tpRootCocoNode, fileName);
}
}
else
{
pReader = new WidgetPropertiesReader0250();
widget = pReader->createWidgetFromBinary(&tCocoLoader, tpRootCocoNode, fileName);
}
CC_SAFE_DELETE(pReader);
}
}
}
CC_SAFE_DELETE_ARRAY(pBuffer);
return widget;
}
std::string WidgetPropertiesReader::getWidgetReaderClassName(const std::string& classname)
{
// create widget reader to parse properties of widget
std::string readerName = classname;
if (readerName == "Panel")
{
readerName = "Layout";
}
else if (readerName == "TextArea")
{
readerName = "Text";
}
else if (readerName == "TextButton")
{
readerName = "Button";
}
else if (readerName == "Label")
{
readerName = "Text";
}
else if (readerName == "LabelAtlas")
{
readerName = "TextAtlas";
}
else if (readerName == "LabelBMFont")
{
readerName = "TextBMFont";
}
readerName.append("Reader");
return readerName;
}
void WidgetPropertiesReader::setAnchorPointForWidget(cocos2d::ui::Widget *widget, const rapidjson::Value &options)
{
@ -334,7 +433,7 @@ Widget* WidgetPropertiesReader0250::createWidget(const rapidjson::Value& data, c
/* *********temp********* */
// ActionManager::getInstance()->releaseActions();
/* ********************** */
CCLOG("file name == [%s]",fileName);
// CCLOG("file name == [%s]",fileName);
Ref* rootWidget = (Ref*) widget;
ActionManagerEx::getInstance()->initWithDictionary(fileName,actions,rootWidget);
return widget;
@ -1043,55 +1142,178 @@ Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, c
/* *********temp********* */
// ActionManager::getInstance()->releaseActions();
/* ********************** */
CCLOG("file name == [%s]",fileName);
// CCLOG("file name == [%s]",fileName);
Ref* rootWidget = (Ref*) widget;
ActionManagerEx::getInstance()->initWithDictionary(fileName,actions,rootWidget);
return widget;
}
Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Value& data)
cocos2d::ui::Widget* WidgetPropertiesReader0300::createWidgetFromBinary(CocoLoader* pCocoLoader,stExpCocoNode* pCocoNode, const char* fileName)
{
const char* classname = DICTOOL->getStringValue_json(data, "classname");
const rapidjson::Value& uiOptions = DICTOOL->getSubDictionary_json(data, "options");
Widget* widget = this->createGUI(classname);
// create widget reader to parse properties of widget
std::string readerName = classname;
if (readerName == "Panel")
stExpCocoNode *tpChildArray = pCocoNode->GetChildArray();
int texturesCount = tpChildArray[6].GetChildNum();
for (int i=0; i<texturesCount; i++)
{
readerName = "Layout";
const char* file = nullptr;
stExpCocoNode *textureCountsArray = tpChildArray[6].GetChildArray();
file = textureCountsArray[i].GetValue();
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(file);
}
else if (readerName == "TextArea")
float fileDesignWidth = atof(tpChildArray[5].GetValue());
float fileDesignHeight = atof(tpChildArray[4].GetValue());
if (fileDesignWidth <= 0 || fileDesignHeight <= 0) {
CCLOGERROR("Read design size error!\n");
Size winSize = Director::getInstance()->getWinSize();
GUIReader::getInstance()->storeFileDesignSize(fileName, winSize);
}
else
{
readerName = "Text";
GUIReader::getInstance()->storeFileDesignSize(fileName, Size(fileDesignWidth, fileDesignHeight));
}
else if (readerName == "TextButton")
stExpCocoNode *widgetTreeNode = &tpChildArray[8];
rapidjson::Type tType = tpChildArray[8].GetType(pCocoLoader);
Widget* widget = nullptr;
if (rapidjson::kObjectType == tType)
{
readerName = "Button";
//convert this function!!!
//widgetFromJsonDictionary(widgetTree);
widget = widgetFromBinary(pCocoLoader, widgetTreeNode);
}
else if (readerName == "Label")
/* *********temp********* */
if (widget->getContentSize().equals(Size::ZERO))
{
readerName = "Text";
Layout* rootWidget = dynamic_cast<Layout*>(widget);
rootWidget->setSize(Size(fileDesignWidth, fileDesignHeight));
}
else if (readerName == "LabelAtlas")
{
readerName = "TextAtlas";
/* ********************** */
// // widget->setFileDesignSize(Size(fileDesignWidth, fileDesignHeight));
// const rapidjson::Value& actions = DICTOOL->getSubDictionary_json(data, "animation");
// /* *********temp********* */
// // ActionManager::getInstance()->releaseActions();
// /* ********************** */
// CCLOG("file name == [%s]",fileName);
// Ref* rootWidget = (Ref*) widget;
// ActionManagerEx::getInstance()->initWithDictionary(fileName,actions,rootWidget);
return widget;
}
Widget* WidgetPropertiesReader0300::widgetFromBinary(CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode)
{
Widget* widget = nullptr;
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
std::string classname;
std::string key = stChildArray[0].GetName(pCocoLoader);
classname = stChildArray[0].GetValue();
if (key == "classname" && !classname.empty()) {
widget = this->createGUI(classname);
}
else if (readerName == "LabelBMFont")
{
readerName = "TextBMFont";
}
readerName.append("Reader");
CCLOG("classname = %s", classname.c_str());
std::string readerName = this->getWidgetReaderClassName(classname);
WidgetReaderProtocol* reader = this->createWidgetReaderProtocol(readerName);
if (reader)
{
// widget parse with widget reader
setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions);
setPropsForAllWidgetFromBinary(reader, widget, pCocoLoader, &stChildArray[3]);
}
else
{
// 1st., custom widget parse properties of parent widget with parent widget reader
readerName = this->getWidgetReaderClassName(widget);
reader = this->createWidgetReaderProtocol(readerName);
setPropsForAllWidgetFromBinary(reader, widget, pCocoLoader, &stChildArray[3]);
//TODO:
// // 2nd., custom widget parse with custom reader
// const char* customProperty = DICTOOL->getStringValue_json(uiOptions, "customProperty");
// rapidjson::Document customJsonDict;
// customJsonDict.Parse<0>(customProperty);
// if (customJsonDict.HasParseError())
// {
// CCLOG("GetParseError %s\n", customJsonDict.GetParseError());
// }
// setPropsForAllCustomWidgetFromJsonDictionary(classname, widget, customJsonDict);
}
//parse children
auto childrenArray = stChildArray[2].GetChildArray();
if (nullptr != childrenArray) {
int childrenCount = childrenArray->GetChildNum();
for (int i=0; i < childrenCount; ++i) {
rapidjson::Type tType = childrenArray[i].GetType(pCocoLoader);
if (tType == rapidjson::kObjectType) {
Widget *child = widgetFromBinary(pCocoLoader, &childrenArray[i]);
if (child)
{
PageView* pageView = dynamic_cast<PageView*>(widget);
if (pageView)
{
pageView->addPage(static_cast<Layout*>(child));
}
else
{
ListView* listView = dynamic_cast<ListView*>(widget);
if (listView)
{
listView->pushBackCustomItem(child);
}
else
{
if (!dynamic_cast<Layout*>(widget))
{
if (child->getPositionType() == ui::Widget::PositionType::PERCENT)
{
child->setPositionPercent(Vec2(child->getPositionPercent().x + widget->getAnchorPoint().x,
child->getPositionPercent().y + widget->getAnchorPoint().y));
}
child->setPosition(Vec2(child->getPositionX() + widget->getAnchorPointInPoints().x,
child->getPositionY() + widget->getAnchorPointInPoints().y));
}
widget->addChild(child);
}
}
}
}
}
}
return widget;
}
void WidgetPropertiesReader0300::setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader,
cocos2d::ui::Widget* widget,
CocoLoader* pCocoLoader,
stExpCocoNode* pCocoNode)
{
reader->setPropsFromBinary(widget, pCocoLoader, pCocoNode);
}
std::string WidgetPropertiesReader::getWidgetReaderClassName(Widget* widget)
{
std::string readerName;
// 1st., custom widget parse properties of parent widget with parent widget reader
if (dynamic_cast<Button*>(widget))
{
@ -1150,6 +1372,28 @@ Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Va
readerName = "WidgetReader";
}
return readerName;
}
Widget* WidgetPropertiesReader0300::widgetFromJsonDictionary(const rapidjson::Value& data)
{
const char* classname = DICTOOL->getStringValue_json(data, "classname");
const rapidjson::Value& uiOptions = DICTOOL->getSubDictionary_json(data, "options");
Widget* widget = this->createGUI(classname);
std::string readerName = this->getWidgetReaderClassName(classname);
WidgetReaderProtocol* reader = this->createWidgetReaderProtocol(readerName);
if (reader)
{
// widget parse with widget reader
setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions);
}
else
{
readerName = this->getWidgetReaderClassName(widget);
reader = dynamic_cast<WidgetReaderProtocol*>(ObjectFactory::getInstance()->createObject(readerName));
setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions);

View File

@ -30,6 +30,9 @@ THE SOFTWARE.
#include "WidgetReader/WidgetReaderProtocol.h"
#include "base/ObjectFactory.h"
class CocoLoader;
class stExpCocoNode;
namespace cocostudio {
@ -49,6 +52,9 @@ public:
static void destroyInstance();
cocos2d::ui::Widget* widgetFromJsonFile(const char* fileName);
cocos2d::ui::Widget* widgetFromBinaryFile(const char* fileName);
int getVersionInteger(const char* str);
/**
* @js NA
@ -64,8 +70,6 @@ public:
cocos2d::ObjectFactory::Instance ins,
Ref* object,
SEL_ParseEvent callBack);
protected:
GUIReader();
~GUIReader();
@ -88,13 +92,24 @@ class WidgetPropertiesReader : public cocos2d::Ref
{
public:
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName)=0;
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& data) = 0;
virtual void setPropsForAllWidgetFromJsonDictionary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, const rapidjson::Value& options) = 0;
virtual void setPropsForAllCustomWidgetFromJsonDictionary(const std::string& classType,
cocos2d::ui::Widget* widget,
const rapidjson::Value& customOptions) = 0;
//add binary parsing
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* pCocoLoader,stExpCocoNode* pCocoNode, const char* fileName)=0;
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) = 0;
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) = 0;
protected:
void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value&options);
std::string getWidgetReaderClassName(const std::string& classname);
std::string getWidgetReaderClassName(cocos2d::ui::Widget *widget);
std::string getGUIClassName(const std::string& name);
cocos2d::ui::Widget *createGUI(const std::string& classname);
@ -114,7 +129,14 @@ public:
virtual ~WidgetPropertiesReader0250(){};
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName);
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic);
//added for binary parsing
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* pCocoLoader,stExpCocoNode* pCocoNode, const char* fileName)override{return nullptr;}
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode){return nullptr;}
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) {}
virtual void setPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
virtual void setColorPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
@ -136,7 +158,7 @@ public:
cocos2d::ui::Widget* widget,
const rapidjson::Value& customOptions);
};
class WidgetPropertiesReader0300 : public WidgetPropertiesReader
{
@ -146,7 +168,17 @@ public:
virtual ~WidgetPropertiesReader0300(){};
virtual cocos2d::ui::Widget* createWidget(const rapidjson::Value& dic, const char* fullPath, const char* fileName);
//add bin parse support
virtual cocos2d::ui::Widget* createWidgetFromBinary(CocoLoader* pCocoLoader,stExpCocoNode* pCocoNode, const char* fileName)override;
virtual cocos2d::ui::Widget* widgetFromBinary(CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode);
virtual void setPropsForAllWidgetFromBinary(WidgetReaderProtocol* reader, cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode);
virtual cocos2d::ui::Widget* widgetFromJsonDictionary(const rapidjson::Value& dic);
virtual void setPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget*,const rapidjson::Value& options);
virtual void setColorPropsForWidgetFromJsonDictionary(cocos2d::ui::Widget* widget,const rapidjson::Value& options);
@ -170,6 +202,9 @@ public:
cocos2d::ui::Widget* widget,
const rapidjson::Value& customOptions);
};

View File

@ -2,6 +2,7 @@
#include "ButtonReader.h"
#include "ui/UIButton.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -36,6 +37,97 @@ namespace cocostudio
CC_SAFE_DELETE(instanceButtonReader);
}
void ButtonReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
Button *button = static_cast<Button*>(widget);
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
int cri = 255, cgi = 255, cbi = 255;
float scale9Width = 0.0f, scale9Height = 0.0f;
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "scale9Enable") {
button->setScale9Enabled(valueToBool(value));
}
else if (key == "normalData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
button->loadTextureNormal(backgroundValue, imageFileNameType);
}
else if (key == "pressedData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
button->loadTexturePressed(backgroundValue, imageFileNameType);
}
else if (key == "disabledData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
button->loadTextureDisabled(backgroundValue, imageFileNameType);
}else if (key == "text"){
button->setTitleText(value);
}
else if(key == "capInsetsX"){
capsx = valueToFloat(value);
}else if(key == "capInsetsY"){
capsy = valueToFloat(value);
}else if(key == "capInsetsWidth"){
capsWidth = valueToFloat(value);
}else if(key == "capInsetsHeight"){
capsHeight = valueToFloat(value);
}else if(key == "scale9Width"){
scale9Width = valueToFloat(value);
}else if(key == "scale9Height"){
scale9Height = valueToFloat(value);
}else if(key == "textColorR"){
cri = valueToInt(value);
}else if(key == "textColorG"){
cgi = valueToInt(value);
}else if(key == "textColorB"){
cbi = valueToInt(value);
}else if(key == "fontSize"){
button->setTitleFontSize(valueToFloat(value));
}else if(key == "fontName"){
button->setTitleFontName(value);
}
} //end of for loop
if (button->isScale9Enabled()) {
button->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
button->setSize(Size(scale9Width, scale9Height));
}
button->setTitleColor(Color3B(cri, cgi, cbi));
}
void ButtonReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);

View File

@ -42,6 +42,7 @@ namespace cocostudio
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget,
const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode);
};
}

View File

@ -2,6 +2,7 @@
#include "CheckBoxReader.h"
#include "ui/UICheckBox.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -31,6 +32,70 @@ namespace cocostudio
return instanceCheckBoxReader;
}
void CheckBoxReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
CheckBox *checkBox = static_cast<CheckBox*>(widget);
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "backGroundBoxData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGround(backgroundValue, imageFileNameType);
}else if(key == "backGroundBoxSelectedData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGroundSelected(backgroundValue, imageFileNameType);
}else if(key == "frontCrossData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureFrontCross(backgroundValue, imageFileNameType);
}else if(key == "backGroundBoxDisabledData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureBackGroundDisabled(backgroundValue, imageFileNameType);
}else if (key == "frontCrossDisabledData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
checkBox->loadTextureFrontCrossDisabled(backgroundValue, imageFileNameType);
}
}
}
void CheckBoxReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,7 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode);
};
}

View File

@ -2,6 +2,7 @@
#include "ImageViewReader.h"
#include "ui/UIImageView.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -31,6 +32,58 @@ namespace cocostudio
return instanceImageViewReader;
}
void ImageViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
ImageView* imageView = static_cast<ImageView*>(widget);
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "scale9Enable") {
imageView->setScale9Enabled(valueToBool(value));
}
else if (key == "fileNameData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
imageView->loadTexture(backgroundValue, imageFileNameType);
}
else if(key == "scale9Width"){
imageView->setSize(Size(valueToFloat(value), imageView->getSize().height));
}else if(key == "scale9Height"){
imageView->setSize(Size(imageView->getSize().width, valueToFloat(value)));
}
else if(key == "capInsetsX"){
capsx = valueToFloat(value);
}else if(key == "capInsetsY"){
capsy = valueToFloat(value);
}else if(key == "capInsetsWidth"){
capsWidth = valueToFloat(value);
}else if(key == "capInsetsHeight"){
capsHeight = valueToFloat(value);
}
} //end of for loop
if (imageView->isScale9Enabled()) {
imageView->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
}
}
void ImageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,7 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode);
};
}

View File

@ -2,6 +2,7 @@
#include "LayoutReader.h"
#include "ui/UILayout.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -31,6 +32,111 @@ namespace cocostudio
return instanceLayoutReader;
}
void LayoutReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
Layout* panel = static_cast<Layout*>(widget);
float w = 0, h= 0;
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
int cr=0, cg = 0, cb = 0;
int scr=0, scg=0, scb=0;
int ecr=0, ecg=0, ecb= 0;
float bgcv1 = 0.0f, bgcv2= 0.0f;
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
Layout::Type layoutType;
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "adaptScreen") {
bool adptScreen = valueToBool(value);
if (adptScreen) {
Size screenSize = CCDirector::getInstance()->getWinSize();
w = screenSize.width;
h = screenSize.height;
}else{
w = widget->getSize().width;
h = widget->getSize().height;
}
panel->setSize(Size(w,h));
}else if( key == "clipAble"){
panel->setClippingEnabled(valueToBool(value));
}else if(key == "backGroundScale9Enable"){
panel->setBackGroundImageScale9Enabled(valueToBool(value));
}else if(key == "bgColorR"){
cr = valueToInt(value);
}else if(key == "bgColorG"){
cg = valueToInt(value);
}else if(key == "bgColorB")
{
cb = valueToInt(value);
}else if(key == "bgStartColorR"){
scr = valueToInt(value);
}else if(key == "bgStartColorG"){
scg = valueToInt(value);
}else if(key == "bgStartColorB")
{
scb = valueToInt(value);
}
else if(key == "bgEndColorR"){
ecr = valueToInt(value);
}else if(key == "bgEndColorG"){
ecg = valueToInt(value);
}else if(key == "bgEndColorB")
{
ecb = valueToInt(value);
}else if (key == "vectorX"){
bgcv1 = valueToFloat(value);
}else if(key == "vectorY"){
bgcv2 = valueToFloat(value);
}else if(key == "bgColorOpacity"){
panel->setBackGroundColorOpacity(valueToInt(value));
}else if( key == "colorType"){
panel->setBackGroundColorType(Layout::BackGroundColorType(valueToInt(value)));
}else if (key == "backGroundImageData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
if (backGroundChildren) {
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
panel->setBackGroundImage(backgroundValue,imageFileNameType);
}
}else if(key == "capInsetsX"){
capsx = valueToFloat(value);
}else if(key == "capInsetsY"){
capsy = valueToFloat(value);
}else if(key == "capInsetsWidth"){
capsWidth = valueToFloat(value);
}else if(key == "capInsetsHeight"){
capsHeight = valueToFloat(value);
}else if (key == "layoutType"){
layoutType = (Layout::Type)valueToInt(value);
}
}
panel->setBackGroundColor(Color3B(scr, scg, scb),Color3B(ecr, ecg, ecb));
panel->setBackGroundColor(Color3B(cr, cg, cb));
panel->setBackGroundColorVector(Vec2(bgcv1, bgcv2));
if (panel->isBackGroundImageScale9Enabled()) {
panel->setBackGroundImageCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
}
panel->setLayoutType(layoutType);
}
void LayoutReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,7 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,6 +2,7 @@
#include "ListViewReader.h"
#include "ui/UIListView.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -31,6 +32,30 @@ namespace cocostudio
return instanceListViewReader;
}
void ListViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
ScrollViewReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
ListView* listView = static_cast<ListView*>(widget);
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "direction") {
listView->setDirection((ScrollView::Direction)valueToInt(value));
}
else if(key == "gravity"){
listView->setGravity((ListView::Gravity)valueToInt(value));
}else if(key == "itemMargin"){
listView->setItemsMargin(valueToFloat(value));
}
} //end of for loop
}
void ListViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
ScrollViewReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,7 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,9 +2,11 @@
#include "LoadingBarReader.h"
#include "ui/UILoadingBar.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
using namespace cocostudio;
namespace cocostudio
{
@ -31,6 +33,56 @@ namespace cocostudio
return instanceLoadingBar;
}
void LoadingBarReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
LoadingBar* loadingBar = static_cast<LoadingBar*>(widget);
float capsx = 0.0f, capsy = 0.0, capsWidth = 0.0, capsHeight = 0.0f;
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "scale9Enable") {
loadingBar->setScale9Enabled(valueToBool(value));
}
else if (key == "textureData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
loadingBar->loadTexture(backgroundValue, imageFileNameType);
}
else if(key == "capInsetsX"){
capsx = valueToFloat(value);
}else if(key == "capInsetsY"){
capsy = valueToFloat(value);
}else if(key == "capInsetsWidth"){
capsWidth = valueToFloat(value);
}else if(key == "capInsetsHeight"){
capsHeight = valueToFloat(value);
}else if(key == "direction"){
loadingBar->setDirection((LoadingBar::Direction)valueToInt(value));
}else if(key == "percent"){
loadingBar->setPercent(valueToInt(value));
}
} //end of for loop
if (loadingBar->isScale9Enabled()) {
loadingBar->setCapInsets(Rect(capsx, capsy, capsWidth, capsHeight));
}
}
void LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,7 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -31,6 +31,11 @@ namespace cocostudio
return instancePageViewReader;
}
void PageViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
LayoutReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
}
void PageViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
LayoutReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,6 +2,7 @@
#include "ScrollViewReader.h"
#include "ui/UIScrollView.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -31,6 +32,34 @@ namespace cocostudio
return instanceScrollViewReader;
}
void ScrollViewReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
LayoutReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
ScrollView* scrollView = static_cast<ScrollView*>(widget);
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "innerWidth") {
scrollView->setInnerContainerSize(Size(valueToFloat(value), scrollView->getInnerContainerSize().height));
}
else if(key == "innerHeight"){
scrollView->setInnerContainerSize(Size(scrollView->getInnerContainerSize().height, valueToFloat(value) ));
}else if(key == "direction"){
scrollView->setDirection((ScrollView::Direction)valueToInt(value));
}else if(key == "bounceEnable"){
scrollView->setBounceEnabled(valueToBool(value));
}
} //end of for loop
}
void ScrollViewReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
LayoutReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,6 +2,7 @@
#include "SliderReader.h"
#include "ui/UISlider.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -31,6 +32,85 @@ namespace cocostudio
return instanceSliderReader;
}
void SliderReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
Slider* slider = static_cast<Slider*>(widget);
float barLength = 0.0f;
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "scale9Enable") {
slider->setScale9Enabled(valueToBool(value));
}
else if(key == "percent"){
slider->setPercent(valueToInt(value));
}else if(key == "barFileNameData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
slider->loadBarTexture(backgroundValue, imageFileNameType);
}else if(key == "length"){
barLength = valueToFloat(value);
}else if(key == "ballNormalData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
slider->loadSlidBallTextureNormal(backgroundValue, imageFileNameType);
}else if(key == "ballPressedData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
slider->loadSlidBallTexturePressed(backgroundValue, imageFileNameType);
}else if(key == "ballDisabledData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
slider->loadSlidBallTextureDisabled(backgroundValue, imageFileNameType);
}else if(key == "progressBarData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
slider->loadProgressBarTexture(backgroundValue, imageFileNameType);
}
} //end of for loop
if (slider->isScale9Enabled()) {
slider->setSize(Size(barLength, slider->getContentSize().height));
}
}
void SliderReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,6 +2,7 @@
#include "TextAtlasReader.h"
#include "ui/UITextAtlas.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -31,6 +32,52 @@ namespace cocostudio
return instanceTextAtalsReader;
}
void TextAtlasReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
TextAtlas* labelAtlas = static_cast<TextAtlas*>(widget);
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
Widget::TextureResType type;
std::string charMapFileName;
std::string stringValue;
std::string startCharMap;
float itemWidth;
float itemHeight;
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "stringValue") {
stringValue = value;
}
else if(key == "charMapFileData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
charMapFileName = backgroundValue;
type = imageFileNameType;
}else if(key == "itemWidth"){
itemWidth = valueToFloat(value);
}else if(key == "itemHeight"){
itemHeight = valueToFloat(value);
}else if(key == "startCharMap"){
startCharMap = value;
}
} //end of for loop
if (type == (Widget::TextureResType)0) {
labelAtlas->setProperty(stringValue, charMapFileName, itemWidth, itemHeight, startCharMap);
}
}
void TextAtlasReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);

View File

@ -40,6 +40,8 @@ namespace cocostudio
static TextAtlasReader* getInstance();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,6 +2,7 @@
#include "TextBMFontReader.h"
#include "ui/UITextBMFont.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -31,6 +32,37 @@ namespace cocostudio
return instanceTextBMFontReader;
}
void TextBMFontReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
TextBMFont* labelBMFont = static_cast<TextBMFont*>(widget);
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if(key == "fileNameData"){
stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray();
std::string resType = backGroundChildren[2].GetValue();;
Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
std::string backgroundValue = this->getResourcePath(pCocoLoader, &stChildArray[i], imageFileNameType);
if (imageFileNameType == (Widget::TextureResType)0) {
labelBMFont->setFntFile(backgroundValue);
}
}else if(key == "text"){
labelBMFont->setString(value);
}
} //end of for loop
}
void TextBMFontReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,6 +2,7 @@
#include "TextFieldReader.h"
#include "ui/UITextField.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -31,6 +32,42 @@ namespace cocostudio
return instanceTextFieldReader;
}
void TextFieldReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
TextField* textField = static_cast<TextField*>(widget);
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if(key == "placeHolder"){
textField->setPlaceHolder(value);
}else if(key == "text"){
textField->setText(value);
}else if(key == "fontSize"){
textField->setFontSize(valueToInt(value));
}else if(key == "fontName"){
textField->setFontName(value);
}else if(key == "touchSizeWidth"){
textField->setTouchSize(Size(valueToFloat(value), textField->getTouchSize().height));
}else if(key == "touchSizeHeight"){
textField->setTouchSize(Size(textField->getTouchSize().width, valueToFloat(value)));
}else if (key == "maxLengthEnable"){
textField->setMaxLengthEnabled(valueToBool(value));
}else if(key == "maxLength"){
textField->setMaxLength(valueToInt(value));
}else if(key == "passwordEnable"){
textField->setPasswordEnabled(valueToBool(value));
}else if(key == "passwordStyleText"){
textField->setPasswordStyleText(value.c_str());
}
} //end of for loop
}
void TextFieldReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) ;
};
}

View File

@ -2,6 +2,7 @@
#include "TextReader.h"
#include "ui/UIText.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -31,6 +32,42 @@ namespace cocostudio
return instanceTextReader;
}
void TextReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
WidgetReader::setPropsFromBinary(widget, pCocoLoader, pCocoNode);
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
Text* label = static_cast<Text*>(widget);
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "touchScaleEnable") {
label->setTouchScaleChangeEnabled(valueToBool(value));
}
else if(key == "text"){
label->setString(value);
}else if(key == "fontSize"){
label->setFontSize(valueToInt(value));
}else if(key == "fontName"){
label->setFontName(value);
}else if(key == "areaWidth"){
label->setTextAreaSize(Size(valueToFloat(value), label->getTextAreaSize().height));
}else if(key == "areaHeight"){
label->setTextAreaSize(Size(label->getTextAreaSize().width, valueToFloat(value)));
}else if(key == "hAlignment"){
label->setTextHorizontalAlignment((TextHAlignment)valueToInt(value));
}else if(key == "vAlignment"){
label->setTextVerticalAlignment((TextVAlignment)valueToInt(value));
}
} //end of for loop
}
void TextReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
WidgetReader::setPropsFromJsonDictionary(widget, options);

View File

@ -41,6 +41,8 @@ namespace cocostudio
static void purge();
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode);
};
}

View File

@ -1,6 +1,7 @@
#include "WidgetReader.h"
#include "cocostudio/CocoLoader.h"
USING_NS_CC;
using namespace ui;
@ -13,7 +14,22 @@ namespace cocostudio
WidgetReader::WidgetReader()
{
valueToInt = [=](std::string str) -> int{
return atoi(str.c_str());
};
valueToBool = [=](std::string str) -> bool{
int intValue = valueToInt(str);
if (1 == intValue) {
return true;
}else{
return false;
}
};
valueToFloat = [=](std::string str) -> float{
return atof(str.c_str());
};
}
WidgetReader::~WidgetReader()
@ -148,6 +164,139 @@ namespace cocostudio
}
}
void WidgetReader::setBasicPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "ignoreSize") {
widget->ignoreContentAdaptWithSize(valueToBool(value));
}else if(key == "sizeType"){
widget->setSizeType((Widget::SizeType)valueToInt(value));
}else if(key == "positionType"){
widget->setPositionType((Widget::PositionType)valueToInt(value));
}else if(key == "sizePercentX"){
widget->setSizePercent(Vec2(valueToFloat(value), widget->getSizePercent().y));
}else if(key == "sizePercentY"){
widget->setSizePercent(Vec2(widget->getSizePercent().x, valueToFloat(value)));
}else if(key == "positionPercentX"){
widget->setPositionPercent(Vec2(valueToFloat(value), widget->getPositionPercent().y));
}else if(key == "positionPercentY"){
widget->setPositionPercent(Vec2(widget->getPositionPercent().x, valueToFloat(value)));
}else if (key == "width"){
widget->setSize(Size(valueToFloat(value), widget->getSize().height));
}else if(key == "height"){
widget->setSize(Size(widget->getSize().width, valueToFloat(value)));
}else if(key == "tag"){
widget->setTag(valueToInt(value));
}else if(key == "actiontag"){
widget->setActionTag(valueToInt(value));
}else if(key == "touchAble"){
widget->setTouchEnabled(valueToBool(value));
}else if(key == "name"){
std::string widgetName = value.empty() ? "default" : value;
CCLOG("%s", widgetName.c_str());
widget->setName(widgetName);
}else if(key == "x"){
widget->setPosition(Vec2(valueToFloat(value), widget->getPosition().y));
}else if(key == "y"){
widget->setPosition(Vec2(widget->getPosition().x, valueToFloat(value)));
}else if(key == "scaleX"){
widget->setScaleX(valueToFloat(value));
}else if(key == "scaleY"){
widget->setScaleY(valueToFloat(value));
}else if(key == "rotation"){
widget->setRotation(valueToFloat(value));
}else if(key == "visible"){
widget->setVisible(valueToBool(value));
}else if(key == "ZOrder"){
widget->setZOrder(valueToInt(value));
}else if(key == "layoutParameter"){
stExpCocoNode *layoutCocosNode = stChildArray[i].GetChildArray();
LinearLayoutParameter *linearParameter = LinearLayoutParameter::create();
RelativeLayoutParameter *relativeParameter = RelativeLayoutParameter::create();
Margin mg;
int paramType = -1;
for (int j = 0; j < stChildArray[i].GetChildNum(); ++j) {
std::string innerKey = layoutCocosNode[j].GetName(pCocoLoader);
std::string innerValue = layoutCocosNode[j].GetValue();
if (innerKey == "type") {
paramType = valueToInt(innerValue);
}else if(innerKey == "gravity"){
linearParameter->setGravity((cocos2d::ui::LinearLayoutParameter::LinearGravity)valueToInt(innerValue));
}else if(innerKey == "relativeName"){
relativeParameter->setRelativeName(innerValue);
}else if(innerKey == "relativeToName"){
relativeParameter->setRelativeToWidgetName(innerValue);
}else if(innerKey == "align"){
relativeParameter->setAlign((cocos2d::ui::RelativeLayoutParameter::RelativeAlign)valueToInt(innerValue));
}else if(innerKey == "marginLeft"){
mg.left = valueToFloat(innerValue);
}else if(innerKey == "marginTop"){
mg.top = valueToFloat(innerValue);
}else if(innerKey == "marginRight"){
mg.right = valueToFloat(innerValue);
}else if(innerKey == "marginDown"){
mg.bottom = valueToFloat(innerValue);
}
}
linearParameter->setMargin(mg);
relativeParameter->setMargin(mg);
switch (paramType) {
case 1:
widget->setLayoutParameter(linearParameter);
break;
case 2:
widget->setLayoutParameter(relativeParameter);
default:
break;
}
}
}
}
void WidgetReader::setColorPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode)
{
stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
//set default color
widget->setColor(Color3B(255,255,255));
for (int i = 0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "opacity") {
widget->setOpacity(valueToInt(value));
}else if(key == "colorR"){
Color3B color = widget->getColor();
widget->setColor(Color3B(valueToInt(value), color.g, color.b));
}else if(key == "colorG"){
Color3B color = widget->getColor();
widget->setColor(Color3B( color.r, valueToInt(value), color.b));
}else if(key == "colorB")
{
Color3B color = widget->getColor();
widget->setColor(Color3B( color.r, color.g , valueToInt(value)));
}else if(key == "flipX"){
widget->setFlippedX(valueToBool(value));
}else if(key == "flipY"){
widget->setFlippedY(valueToBool(value));
}
}
}
void WidgetReader::setColorPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
{
bool op = DICTOOL->checkObjectExist_json(options, "opacity");
@ -193,6 +342,30 @@ namespace cocostudio
return imageFileName_tp;
}
std::string WidgetReader::getResourcePath(CocoLoader *pCocoLoader, stExpCocoNode *pCocoNode, cocos2d::ui::Widget::TextureResType texType)
{
stExpCocoNode *backGroundChildren = pCocoNode->GetChildArray();
std::string backgroundValue = backGroundChildren[0].GetValue();
std::string binaryPath = GUIReader::getInstance()->getFilePath();
std::string imageFileName_tp;
if (!backgroundValue.empty())
{
if (texType == ui::Widget::TextureResType::LOCAL) {
imageFileName_tp = binaryPath + backgroundValue;
}
else if(texType == ui::Widget::TextureResType::PLIST){
imageFileName_tp = backgroundValue;
}
else{
CCASSERT(0, "invalid TextureResType!!!");
}
}
return imageFileName_tp;
}
void WidgetReader::setAnchorPointForWidget(cocos2d::ui::Widget *widget, const rapidjson::Value &options)
{
bool isAnchorPointXExists = DICTOOL->checkObjectExist_json(options, "anchorPointX");

View File

@ -30,8 +30,13 @@
#include "ui/GUIDefine.h"
#include "ui/UIWidget.h"
namespace cocostudio
{
class CocoLoader;
class stExpCocoNode;
class WidgetReader : public cocos2d::Ref, public WidgetReaderProtocol
{
public:
@ -49,11 +54,24 @@ namespace cocostudio
virtual void setColorPropsFromJsonDictionary(cocos2d::ui::Widget* widget,
const rapidjson::Value& options);
virtual void setBasicPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode);
virtual void setColorPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode);
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode)
{
this->setBasicPropsFromBinary(widget, pCocoLoader, pCocoNode);
this->setColorPropsFromBinary(widget, pCocoLoader, pCocoNode);
};
protected:
std::string getResourcePath(const rapidjson::Value& dict,
const std::string& key,
cocos2d::ui::Widget::TextureResType texType);
std::string getResourcePath(CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode, cocos2d::ui::Widget::TextureResType texType);
void setAnchorPointForWidget(cocos2d::ui::Widget* widget, const rapidjson::Value&options);
std::function<int(std::string)> valueToInt;
std::function<bool(std::string)> valueToBool;
std::function<float(std::string)> valueToFloat;
};
}

View File

@ -28,6 +28,8 @@
#include "cocos2d.h"
#include "cocostudio/DictionaryHelper.h"
namespace cocos2d
{
namespace ui
@ -38,11 +40,15 @@ namespace cocos2d
namespace cocostudio
{
class CocoLoader;
class stExpCocoNode;
class WidgetReaderProtocol
{
public:
virtual ~WidgetReaderProtocol() {};
virtual void setPropsFromJsonDictionary(cocos2d::ui::Widget* widget, const rapidjson::Value& options) = 0;
virtual void setPropsFromBinary(cocos2d::ui::Widget* widget, CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode) = 0;
};
}