2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "TextFieldReader.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/UITextField.h"
|
2014-06-05 10:25:08 +08:00
|
|
|
#include "cocostudio/CocoLoader.h"
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2014-03-06 16:15:03 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace ui;
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
static TextFieldReader* instanceTextFieldReader = NULL;
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
static const char* P_PlaceHolder = "placeHolder";
|
|
|
|
static const char* P_Text = "text";
|
|
|
|
static const char* P_FontSize = "fontSize";
|
|
|
|
static const char* P_FontName = "fontName";
|
|
|
|
static const char* P_TouchSizeWidth = "touchSizeWidth";
|
|
|
|
static const char* P_TouchSizeHeight = "touchSizeHeight";
|
|
|
|
static const char* P_MaxLengthEnable = "maxLengthEnable";
|
|
|
|
static const char* P_MaxLength = "maxLength";
|
|
|
|
static const char* P_PasswordEnable = "passwordEnable";
|
|
|
|
static const char* P_PasswordStyleText = "passwordStyleText";
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
IMPLEMENT_CLASS_WIDGET_READER_INFO(TextFieldReader)
|
|
|
|
|
|
|
|
TextFieldReader::TextFieldReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TextFieldReader::~TextFieldReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TextFieldReader* TextFieldReader::getInstance()
|
|
|
|
{
|
|
|
|
if (!instanceTextFieldReader)
|
|
|
|
{
|
|
|
|
instanceTextFieldReader = new TextFieldReader();
|
|
|
|
}
|
|
|
|
return instanceTextFieldReader;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
void TextFieldReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode* cocoNode)
|
2014-06-05 10:25:08 +08:00
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
this->beginSetBasicProperties(widget);
|
2014-06-05 10:25:08 +08:00
|
|
|
|
|
|
|
TextField* textField = static_cast<TextField*>(widget);
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
|
2014-06-05 10:25:08 +08:00
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
|
|
|
|
std::string key = stChildArray[i].GetName(cocoLoader);
|
2014-06-05 10:25:08 +08:00
|
|
|
std::string value = stChildArray[i].GetValue();
|
|
|
|
|
2014-06-19 15:16:56 +08:00
|
|
|
//read all basic properties of widget
|
|
|
|
CC_BASIC_PROPERTY_BINARY_READER
|
|
|
|
//read all color related properties of widget
|
|
|
|
CC_COLOR_PROPERTY_BINARY_READER
|
2014-06-11 09:35:24 +08:00
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
else if(key == P_PlaceHolder){
|
2014-06-05 10:25:08 +08:00
|
|
|
textField->setPlaceHolder(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_Text){
|
2014-06-05 10:25:08 +08:00
|
|
|
textField->setText(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_FontSize){
|
2014-06-05 10:25:08 +08:00
|
|
|
textField->setFontSize(valueToInt(value));
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_FontName){
|
2014-06-05 10:25:08 +08:00
|
|
|
textField->setFontName(value);
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_TouchSizeWidth){
|
2014-06-05 10:25:08 +08:00
|
|
|
textField->setTouchSize(Size(valueToFloat(value), textField->getTouchSize().height));
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_TouchSizeHeight){
|
2014-06-05 10:25:08 +08:00
|
|
|
textField->setTouchSize(Size(textField->getTouchSize().width, valueToFloat(value)));
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if (key == P_MaxLengthEnable){
|
2014-06-05 10:25:08 +08:00
|
|
|
textField->setMaxLengthEnabled(valueToBool(value));
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_MaxLength){
|
2014-06-05 10:25:08 +08:00
|
|
|
textField->setMaxLength(valueToInt(value));
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_PasswordEnable){
|
2014-06-05 10:25:08 +08:00
|
|
|
textField->setPasswordEnabled(valueToBool(value));
|
2014-06-19 17:04:14 +08:00
|
|
|
}else if(key == P_PasswordStyleText){
|
2014-06-05 10:25:08 +08:00
|
|
|
textField->setPasswordStyleText(value.c_str());
|
|
|
|
}
|
|
|
|
} //end of for loop
|
2014-06-11 09:35:24 +08:00
|
|
|
this->endSetBasicProperties(widget);
|
2014-06-05 10:25:08 +08:00
|
|
|
}
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
void TextFieldReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
|
|
|
|
{
|
|
|
|
WidgetReader::setPropsFromJsonDictionary(widget, options);
|
|
|
|
|
|
|
|
|
2014-03-06 16:15:03 +08:00
|
|
|
TextField* textField = static_cast<TextField*>(widget);
|
2014-06-19 17:04:14 +08:00
|
|
|
bool ph = DICTOOL->checkObjectExist_json(options, P_PlaceHolder);
|
2014-03-04 16:51:35 +08:00
|
|
|
if (ph)
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
textField->setPlaceHolder(DICTOOL->getStringValue_json(options, P_PlaceHolder));
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
textField->setText(DICTOOL->getStringValue_json(options, P_Text));
|
|
|
|
bool fs = DICTOOL->checkObjectExist_json(options, P_FontSize);
|
2014-03-04 16:51:35 +08:00
|
|
|
if (fs)
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
textField->setFontSize(DICTOOL->getIntValue_json(options, P_FontSize));
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
bool fn = DICTOOL->checkObjectExist_json(options, P_FontName);
|
2014-03-04 16:51:35 +08:00
|
|
|
if (fn)
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
textField->setFontName(DICTOOL->getStringValue_json(options, P_FontName));
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
bool tsw = DICTOOL->checkObjectExist_json(options, P_TouchSizeWidth);
|
|
|
|
bool tsh = DICTOOL->checkObjectExist_json(options, P_TouchSizeHeight);
|
2014-03-04 16:51:35 +08:00
|
|
|
if (tsw && tsh)
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
textField->setTouchSize(Size(DICTOOL->getFloatValue_json(options, P_TouchSizeWidth), DICTOOL->getFloatValue_json(options,P_TouchSizeHeight)));
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
|
2014-06-19 17:04:14 +08:00
|
|
|
// float dw = DICTOOL->getFloatValue_json(options, "width");
|
|
|
|
// float dh = DICTOOL->getFloatValue_json(options, "height");
|
|
|
|
// if (dw > 0.0f || dh > 0.0f)
|
|
|
|
// {
|
|
|
|
// //textField->setSize(Size(dw, dh));
|
|
|
|
// }
|
|
|
|
bool maxLengthEnable = DICTOOL->getBooleanValue_json(options, P_MaxLengthEnable);
|
2014-03-04 16:51:35 +08:00
|
|
|
textField->setMaxLengthEnabled(maxLengthEnable);
|
|
|
|
|
|
|
|
if (maxLengthEnable)
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
int maxLength = DICTOOL->getIntValue_json(options, P_MaxLength);
|
2014-03-04 16:51:35 +08:00
|
|
|
textField->setMaxLength(maxLength);
|
|
|
|
}
|
2014-06-19 17:04:14 +08:00
|
|
|
bool passwordEnable = DICTOOL->getBooleanValue_json(options, P_PasswordEnable);
|
2014-03-04 16:51:35 +08:00
|
|
|
textField->setPasswordEnabled(passwordEnable);
|
|
|
|
if (passwordEnable)
|
|
|
|
{
|
2014-06-19 17:04:14 +08:00
|
|
|
textField->setPasswordStyleText(DICTOOL->getStringValue_json(options, P_PasswordStyleText));
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WidgetReader::setColorPropsFromJsonDictionary(widget, options);
|
|
|
|
}
|
|
|
|
}
|