CheckBoxReader.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. #include "editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.h"
  2. #include "ui/UICheckBox.h"
  3. #include "platform/CCFileUtils.h"
  4. #include "2d/CCSpriteFrameCache.h"
  5. #include "editor-support/cocostudio/CocoLoader.h"
  6. #include "editor-support/cocostudio/CSParseBinary_generated.h"
  7. #include "editor-support/cocostudio/FlatBuffersSerialize.h"
  8. #include "tinyxml2.h"
  9. #include "flatbuffers/flatbuffers.h"
  10. USING_NS_CC;
  11. using namespace ui;
  12. using namespace flatbuffers;
  13. namespace cocostudio
  14. {
  15. static const char* P_BackGroundBoxData = "backGroundBoxData";
  16. static const char* P_BackGroundBoxSelectedData = "backGroundBoxSelectedData";
  17. static const char* P_FrontCrossData = "frontCrossData";
  18. static const char* P_BackGroundBoxDisabledData = "backGroundBoxDisabledData";
  19. static const char* P_FrontCrossDisabledData = "frontCrossDisabledData";
  20. static CheckBoxReader* instanceCheckBoxReader = nullptr;
  21. IMPLEMENT_CLASS_NODE_READER_INFO(CheckBoxReader)
  22. CheckBoxReader::CheckBoxReader()
  23. {
  24. }
  25. CheckBoxReader::~CheckBoxReader()
  26. {
  27. }
  28. CheckBoxReader* CheckBoxReader::getInstance()
  29. {
  30. if (!instanceCheckBoxReader)
  31. {
  32. instanceCheckBoxReader = new (std::nothrow) CheckBoxReader();
  33. }
  34. return instanceCheckBoxReader;
  35. }
  36. void CheckBoxReader::destroyInstance()
  37. {
  38. CC_SAFE_DELETE(instanceCheckBoxReader);
  39. }
  40. void CheckBoxReader::setPropsFromBinary(cocos2d::ui::Widget *widget, CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
  41. {
  42. CheckBox *checkBox = static_cast<CheckBox*>(widget);
  43. this->beginSetBasicProperties(widget);
  44. stExpCocoNode *stChildArray = cocoNode->GetChildArray(cocoLoader);
  45. for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
  46. std::string key = stChildArray[i].GetName(cocoLoader);
  47. std::string value = stChildArray[i].GetValue(cocoLoader);
  48. //read all basic properties of widget
  49. CC_BASIC_PROPERTY_BINARY_READER
  50. //read all color related properties of widget
  51. CC_COLOR_PROPERTY_BINARY_READER
  52. else if (key == P_BackGroundBoxData){
  53. stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
  54. std::string resType = backGroundChildren[2].GetValue(cocoLoader);
  55. Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
  56. std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
  57. checkBox->loadTextureBackGround(backgroundValue, imageFileNameType);
  58. }else if(key == P_BackGroundBoxSelectedData){
  59. stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
  60. std::string resType = backGroundChildren[2].GetValue(cocoLoader);
  61. Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
  62. std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
  63. checkBox->loadTextureBackGroundSelected(backgroundValue, imageFileNameType);
  64. }else if(key == P_FrontCrossData){
  65. stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
  66. std::string resType = backGroundChildren[2].GetValue(cocoLoader);
  67. Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
  68. std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
  69. checkBox->loadTextureFrontCross(backgroundValue, imageFileNameType);
  70. }else if(key == P_BackGroundBoxDisabledData){
  71. stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
  72. std::string resType = backGroundChildren[2].GetValue(cocoLoader);
  73. Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
  74. std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
  75. checkBox->loadTextureBackGroundDisabled(backgroundValue, imageFileNameType);
  76. }else if (key == P_FrontCrossDisabledData){
  77. stExpCocoNode *backGroundChildren = stChildArray[i].GetChildArray(cocoLoader);
  78. std::string resType = backGroundChildren[2].GetValue(cocoLoader);
  79. Widget::TextureResType imageFileNameType = (Widget::TextureResType)valueToInt(resType);
  80. std::string backgroundValue = this->getResourcePath(cocoLoader, &stChildArray[i], imageFileNameType);
  81. checkBox->loadTextureFrontCrossDisabled(backgroundValue, imageFileNameType);
  82. }
  83. // else if (key == "selectedState"){
  84. // checkBox->setSelectedState(valueToBool(value));
  85. // }
  86. }
  87. this->endSetBasicProperties(widget);
  88. }
  89. void CheckBoxReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options)
  90. {
  91. WidgetReader::setPropsFromJsonDictionary(widget, options);
  92. CheckBox* checkBox = static_cast<CheckBox*>(widget);
  93. //load background image
  94. const rapidjson::Value& backGroundDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxData);
  95. int backGroundType = DICTOOL->getIntValue_json(backGroundDic,P_ResourceType);
  96. std::string backGroundTexturePath = this->getResourcePath(backGroundDic, P_Path, (Widget::TextureResType)backGroundType);
  97. checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType);
  98. //load background selected image
  99. const rapidjson::Value& backGroundSelectedDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxSelectedData);
  100. int backGroundSelectedType = DICTOOL->getIntValue_json(backGroundSelectedDic, P_ResourceType);
  101. std::string backGroundSelectedTexturePath = this->getResourcePath(backGroundSelectedDic, P_Path, (Widget::TextureResType)backGroundSelectedType);
  102. checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType);
  103. //load frontCross image
  104. const rapidjson::Value& frontCrossDic = DICTOOL->getSubDictionary_json(options, P_FrontCrossData);
  105. int frontCrossType = DICTOOL->getIntValue_json(frontCrossDic, P_ResourceType);
  106. std::string frontCrossFileName = this->getResourcePath(frontCrossDic, P_Path, (Widget::TextureResType)frontCrossType);
  107. checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
  108. //load backGroundBoxDisabledData
  109. const rapidjson::Value& backGroundDisabledDic = DICTOOL->getSubDictionary_json(options, P_BackGroundBoxDisabledData);
  110. int backGroundDisabledType = DICTOOL->getIntValue_json(backGroundDisabledDic, P_ResourceType);
  111. std::string backGroundDisabledFileName = this->getResourcePath(backGroundDisabledDic, P_Path, (Widget::TextureResType)backGroundDisabledType);
  112. checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType);
  113. ///load frontCrossDisabledData
  114. const rapidjson::Value& frontCrossDisabledDic = DICTOOL->getSubDictionary_json(options, P_FrontCrossDisabledData);
  115. int frontCrossDisabledType = DICTOOL->getIntValue_json(frontCrossDisabledDic, P_ResourceType);
  116. std::string frontCrossDisabledFileName = this->getResourcePath(frontCrossDisabledDic, P_Path, (Widget::TextureResType)frontCrossDisabledType);
  117. checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType);
  118. WidgetReader::setColorPropsFromJsonDictionary(widget, options);
  119. }
  120. Offset<Table> CheckBoxReader::createOptionsWithFlatBuffers(const tinyxml2::XMLElement *objectData,
  121. flatbuffers::FlatBufferBuilder *builder)
  122. {
  123. auto temp = WidgetReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
  124. auto widgetOptions = *(Offset<WidgetOptions>*)(&temp);
  125. bool selectedState = false;
  126. bool displaystate = true;
  127. int backgroundboxResourceType = 0;
  128. std::string backgroundboxPath = "";
  129. std::string backgroundboxPlistFile = "";
  130. int backGroundBoxSelectedResourceType = 0;
  131. std::string backGroundBoxSelectedPath = "";
  132. std::string backGroundBoxSelectedPlistFile = "";
  133. int frontCrossResourceType = 0;
  134. std::string frontCrossPath = "";
  135. std::string frontCrossPlistFile = "";
  136. int backGroundBoxDisabledResourceType = 0;
  137. std::string backGroundBoxDisabledPath = "";
  138. std::string backGroundBoxDisabledPlistFile = "";
  139. int frontCrossDisabledResourceType = 0;
  140. std::string frontCrossDisabledPath = "";
  141. std::string frontCrossDisabledPlistFile = "";
  142. // attributes
  143. const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
  144. while (attribute)
  145. {
  146. std::string name = attribute->Name();
  147. std::string value = attribute->Value();
  148. if (name == "CheckedState")
  149. {
  150. selectedState = (value == "True") ? true : false;
  151. }
  152. else if (name == "DisplayState")
  153. {
  154. displaystate = (value == "True") ? true : false;
  155. }
  156. attribute = attribute->Next();
  157. }
  158. // child elements
  159. const tinyxml2::XMLElement* child = objectData->FirstChildElement();
  160. while (child)
  161. {
  162. std::string name = child->Name();
  163. if (name == "NormalBackFileData")
  164. {
  165. std::string texture = "";
  166. std::string texturePng = "";
  167. attribute = child->FirstAttribute();
  168. while (attribute)
  169. {
  170. name = attribute->Name();
  171. std::string value = attribute->Value();
  172. if (name == "Path")
  173. {
  174. backgroundboxPath = value;
  175. }
  176. else if (name == "Type")
  177. {
  178. backgroundboxResourceType = getResourceType(value);
  179. }
  180. else if (name == "Plist")
  181. {
  182. backgroundboxPlistFile = value;
  183. texture = value;
  184. }
  185. attribute = attribute->Next();
  186. }
  187. if (backgroundboxResourceType == 1)
  188. {
  189. FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
  190. fbs->_textures.push_back(builder->CreateString(texture));
  191. }
  192. }
  193. else if (name == "PressedBackFileData")
  194. {
  195. std::string texture = "";
  196. std::string texturePng = "";
  197. attribute = child->FirstAttribute();
  198. while (attribute)
  199. {
  200. name = attribute->Name();
  201. std::string value = attribute->Value();
  202. if (name == "Path")
  203. {
  204. backGroundBoxSelectedPath = value;
  205. }
  206. else if (name == "Type")
  207. {
  208. backGroundBoxSelectedResourceType = getResourceType(value);
  209. }
  210. else if (name == "Plist")
  211. {
  212. backGroundBoxSelectedPlistFile = value;
  213. texture = value;
  214. }
  215. attribute = attribute->Next();
  216. }
  217. if (backGroundBoxSelectedResourceType == 1)
  218. {
  219. FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
  220. fbs->_textures.push_back(builder->CreateString(texture));
  221. }
  222. }
  223. else if (name == "NodeNormalFileData")
  224. {
  225. std::string texture = "";
  226. std::string texturePng = "";
  227. attribute = child->FirstAttribute();
  228. while (attribute)
  229. {
  230. name = attribute->Name();
  231. std::string value = attribute->Value();
  232. if (name == "Path")
  233. {
  234. frontCrossPath = value;
  235. }
  236. else if (name == "Type")
  237. {
  238. frontCrossResourceType = getResourceType(value);
  239. }
  240. else if (name == "Plist")
  241. {
  242. frontCrossPlistFile = value;
  243. texture = value;
  244. }
  245. attribute = attribute->Next();
  246. }
  247. if (frontCrossResourceType == 1)
  248. {
  249. FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
  250. fbs->_textures.push_back(builder->CreateString(texture));
  251. }
  252. }
  253. else if (name == "DisableBackFileData")
  254. {
  255. std::string texture = "";
  256. std::string texturePng = "";
  257. attribute = child->FirstAttribute();
  258. while (attribute)
  259. {
  260. name = attribute->Name();
  261. std::string value = attribute->Value();
  262. if (name == "Path")
  263. {
  264. backGroundBoxDisabledPath = value;
  265. }
  266. else if (name == "Type")
  267. {
  268. backGroundBoxDisabledResourceType = getResourceType(value);
  269. }
  270. else if (name == "Plist")
  271. {
  272. backGroundBoxDisabledPlistFile = value;
  273. texture = value;
  274. }
  275. attribute = attribute->Next();
  276. }
  277. if (backGroundBoxDisabledResourceType == 1)
  278. {
  279. FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
  280. fbs->_textures.push_back(builder->CreateString(texture));
  281. }
  282. }
  283. else if (name == "NodeDisableFileData")
  284. {
  285. std::string texture = "";
  286. std::string texturePng = "";
  287. attribute = child->FirstAttribute();
  288. while (attribute)
  289. {
  290. name = attribute->Name();
  291. std::string value = attribute->Value();
  292. if (name == "Path")
  293. {
  294. frontCrossDisabledPath = value;
  295. }
  296. else if (name == "Type")
  297. {
  298. frontCrossDisabledResourceType = getResourceType(value);
  299. }
  300. else if (name == "Plist")
  301. {
  302. frontCrossDisabledPlistFile = value;
  303. texture = value;
  304. }
  305. attribute = attribute->Next();
  306. }
  307. if (frontCrossDisabledResourceType == 1)
  308. {
  309. FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
  310. fbs->_textures.push_back(builder->CreateString(texture));
  311. }
  312. }
  313. child = child->NextSiblingElement();
  314. }
  315. auto options = CreateCheckBoxOptions(*builder,
  316. widgetOptions,
  317. CreateResourceData(*builder,
  318. builder->CreateString(backgroundboxPath),
  319. builder->CreateString(backgroundboxPlistFile),
  320. backgroundboxResourceType),
  321. CreateResourceData(*builder,
  322. builder->CreateString(backGroundBoxSelectedPath),
  323. builder->CreateString(backGroundBoxSelectedPlistFile),
  324. backGroundBoxSelectedResourceType),
  325. CreateResourceData(*builder,
  326. builder->CreateString(frontCrossPath),
  327. builder->CreateString(frontCrossPlistFile),
  328. frontCrossResourceType),
  329. CreateResourceData(*builder,
  330. builder->CreateString(backGroundBoxDisabledPath),
  331. builder->CreateString(backGroundBoxDisabledPlistFile),
  332. backGroundBoxDisabledResourceType),
  333. CreateResourceData(*builder,
  334. builder->CreateString(frontCrossDisabledPath),
  335. builder->CreateString(frontCrossDisabledPlistFile),
  336. frontCrossDisabledResourceType),
  337. selectedState,
  338. displaystate
  339. );
  340. return *(Offset<Table>*)&options;
  341. }
  342. void CheckBoxReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *checkBoxOptions)
  343. {
  344. auto options = (CheckBoxOptions*)checkBoxOptions;
  345. CheckBox* checkBox = static_cast<CheckBox*>(node);
  346. //load background image
  347. bool backGroundFileExist = false;
  348. std::string backGroundErrorFilePath = "";
  349. auto backGroundDic = options->backGroundBoxData();
  350. int backGroundType = backGroundDic->resourceType();
  351. std::string backGroundTexturePath = backGroundDic->path()->c_str();
  352. switch (backGroundType)
  353. {
  354. case 0:
  355. {
  356. if (FileUtils::getInstance()->isFileExist(backGroundTexturePath))
  357. {
  358. backGroundFileExist = true;
  359. }
  360. else
  361. {
  362. backGroundErrorFilePath = backGroundTexturePath;
  363. backGroundFileExist = false;
  364. }
  365. break;
  366. }
  367. case 1:
  368. {
  369. std::string plist = backGroundDic->plistFile()->c_str();
  370. SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundTexturePath);
  371. if (spriteFrame)
  372. {
  373. backGroundFileExist = true;
  374. }
  375. else
  376. {
  377. if (FileUtils::getInstance()->isFileExist(plist))
  378. {
  379. ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
  380. ValueMap metadata = value["metadata"].asValueMap();
  381. std::string textureFileName = metadata["textureFileName"].asString();
  382. if (!FileUtils::getInstance()->isFileExist(textureFileName))
  383. {
  384. backGroundErrorFilePath = textureFileName;
  385. }
  386. }
  387. else
  388. {
  389. backGroundErrorFilePath = plist;
  390. }
  391. backGroundFileExist = false;
  392. }
  393. break;
  394. }
  395. default:
  396. break;
  397. }
  398. if (backGroundFileExist)
  399. {
  400. checkBox->loadTextureBackGround(backGroundTexturePath, (Widget::TextureResType)backGroundType);
  401. }
  402. //load background selected image
  403. bool backGroundSelectedfileExist = false;
  404. std::string backGroundSelectedErrorFilePath = "";
  405. auto backGroundSelectedDic = options->backGroundBoxSelectedData();
  406. int backGroundSelectedType = backGroundSelectedDic->resourceType();
  407. std::string backGroundSelectedTexturePath = backGroundSelectedDic->path()->c_str();
  408. switch (backGroundSelectedType)
  409. {
  410. case 0:
  411. {
  412. if (FileUtils::getInstance()->isFileExist(backGroundSelectedTexturePath))
  413. {
  414. backGroundSelectedfileExist = true;
  415. }
  416. else
  417. {
  418. backGroundSelectedErrorFilePath = backGroundSelectedTexturePath;
  419. backGroundSelectedfileExist = false;
  420. }
  421. break;
  422. }
  423. case 1:
  424. {
  425. std::string plist = backGroundSelectedDic->plistFile()->c_str();
  426. SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundSelectedTexturePath);
  427. if (spriteFrame)
  428. {
  429. backGroundSelectedfileExist = true;
  430. }
  431. else
  432. {
  433. if (FileUtils::getInstance()->isFileExist(plist))
  434. {
  435. ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
  436. ValueMap metadata = value["metadata"].asValueMap();
  437. std::string textureFileName = metadata["textureFileName"].asString();
  438. if (!FileUtils::getInstance()->isFileExist(textureFileName))
  439. {
  440. backGroundSelectedErrorFilePath = textureFileName;
  441. }
  442. }
  443. else
  444. {
  445. backGroundSelectedErrorFilePath = plist;
  446. }
  447. backGroundSelectedfileExist = false;
  448. }
  449. break;
  450. }
  451. default:
  452. break;
  453. }
  454. if (backGroundSelectedfileExist)
  455. {
  456. checkBox->loadTextureBackGroundSelected(backGroundSelectedTexturePath, (Widget::TextureResType)backGroundSelectedType);
  457. }
  458. //load frontCross image
  459. bool frontCrossFileExist = false;
  460. std::string frontCrossErrorFilePath = "";
  461. auto frontCrossDic = options->frontCrossData();
  462. int frontCrossType = frontCrossDic->resourceType();
  463. std::string frontCrossFileName = frontCrossDic->path()->c_str();
  464. switch (frontCrossType)
  465. {
  466. case 0:
  467. {
  468. if (FileUtils::getInstance()->isFileExist(frontCrossFileName))
  469. {
  470. frontCrossFileExist = true;
  471. }
  472. else
  473. {
  474. frontCrossErrorFilePath = frontCrossFileName;
  475. frontCrossFileExist = false;
  476. }
  477. break;
  478. }
  479. case 1:
  480. {
  481. std::string plist = frontCrossDic->plistFile()->c_str();
  482. SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(frontCrossFileName);
  483. if (spriteFrame)
  484. {
  485. frontCrossFileExist = true;
  486. }
  487. else
  488. {
  489. if (FileUtils::getInstance()->isFileExist(plist))
  490. {
  491. ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
  492. ValueMap metadata = value["metadata"].asValueMap();
  493. std::string textureFileName = metadata["textureFileName"].asString();
  494. if (!FileUtils::getInstance()->isFileExist(textureFileName))
  495. {
  496. frontCrossErrorFilePath = textureFileName;
  497. }
  498. }
  499. else
  500. {
  501. frontCrossErrorFilePath = plist;
  502. }
  503. frontCrossFileExist = false;
  504. }
  505. break;
  506. }
  507. default:
  508. break;
  509. }
  510. if (frontCrossFileExist)
  511. {
  512. checkBox->loadTextureFrontCross(frontCrossFileName, (Widget::TextureResType)frontCrossType);
  513. }
  514. //load backGroundBoxDisabledData
  515. bool backGroundBoxDisabledFileExist = false;
  516. std::string backGroundBoxDisabledErrorFilePath = "";
  517. auto backGroundDisabledDic = options->backGroundBoxDisabledData();
  518. int backGroundDisabledType = backGroundDisabledDic->resourceType();
  519. std::string backGroundDisabledFileName = backGroundDisabledDic->path()->c_str();
  520. switch (backGroundDisabledType)
  521. {
  522. case 0:
  523. {
  524. if (FileUtils::getInstance()->isFileExist(backGroundDisabledFileName))
  525. {
  526. backGroundBoxDisabledFileExist = true;
  527. }
  528. else
  529. {
  530. backGroundBoxDisabledErrorFilePath = backGroundDisabledFileName;
  531. backGroundBoxDisabledFileExist = false;
  532. }
  533. break;
  534. }
  535. case 1:
  536. {
  537. std::string plist = backGroundDisabledDic->plistFile()->c_str();
  538. SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(backGroundDisabledFileName);
  539. if (spriteFrame)
  540. {
  541. backGroundBoxDisabledFileExist = true;
  542. }
  543. else
  544. {
  545. if (FileUtils::getInstance()->isFileExist(plist))
  546. {
  547. ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
  548. ValueMap metadata = value["metadata"].asValueMap();
  549. std::string textureFileName = metadata["textureFileName"].asString();
  550. if (!FileUtils::getInstance()->isFileExist(textureFileName))
  551. {
  552. backGroundBoxDisabledErrorFilePath = textureFileName;
  553. }
  554. }
  555. else
  556. {
  557. backGroundBoxDisabledErrorFilePath = plist;
  558. }
  559. backGroundBoxDisabledFileExist = false;
  560. }
  561. break;
  562. }
  563. default:
  564. break;
  565. }
  566. if (backGroundBoxDisabledFileExist)
  567. {
  568. checkBox->loadTextureBackGroundDisabled(backGroundDisabledFileName, (Widget::TextureResType)backGroundDisabledType);
  569. }
  570. ///load frontCrossDisabledData
  571. bool frontCrossDisabledFileExist = false;
  572. std::string frontCrossDisabledErrorFilePath = "";
  573. auto frontCrossDisabledDic = options->frontCrossDisabledData();
  574. int frontCrossDisabledType = frontCrossDisabledDic->resourceType();
  575. std::string frontCrossDisabledFileName = frontCrossDisabledDic->path()->c_str();
  576. switch (frontCrossDisabledType)
  577. {
  578. case 0:
  579. {
  580. if (FileUtils::getInstance()->isFileExist(frontCrossDisabledFileName))
  581. {
  582. frontCrossDisabledFileExist = true;
  583. }
  584. else
  585. {
  586. frontCrossDisabledErrorFilePath = frontCrossDisabledFileName;
  587. frontCrossDisabledFileExist = false;
  588. }
  589. break;
  590. }
  591. case 1:
  592. {
  593. std::string plist = frontCrossDisabledDic->plistFile()->c_str();
  594. SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(frontCrossDisabledFileName);
  595. if (spriteFrame)
  596. {
  597. frontCrossDisabledFileExist = true;
  598. }
  599. else
  600. {
  601. if (FileUtils::getInstance()->isFileExist(plist))
  602. {
  603. ValueMap value = FileUtils::getInstance()->getValueMapFromFile(plist);
  604. ValueMap metadata = value["metadata"].asValueMap();
  605. std::string textureFileName = metadata["textureFileName"].asString();
  606. if (!FileUtils::getInstance()->isFileExist(textureFileName))
  607. {
  608. frontCrossDisabledErrorFilePath = textureFileName;
  609. }
  610. }
  611. else
  612. {
  613. frontCrossDisabledErrorFilePath = plist;
  614. }
  615. frontCrossDisabledFileExist = false;
  616. }
  617. break;
  618. }
  619. default:
  620. break;
  621. }
  622. if (frontCrossDisabledFileExist)
  623. {
  624. checkBox->loadTextureFrontCrossDisabled(frontCrossDisabledFileName, (Widget::TextureResType)frontCrossDisabledType);
  625. }
  626. bool selectedstate = options->selectedState() != 0;
  627. checkBox->setSelected(selectedstate);
  628. bool displaystate = options->displaystate() != 0;
  629. checkBox->setBright(displaystate);
  630. checkBox->setEnabled(displaystate);
  631. auto widgetReader = WidgetReader::getInstance();
  632. widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
  633. }
  634. Node* CheckBoxReader::createNodeWithFlatBuffers(const flatbuffers::Table *checkBoxOptions)
  635. {
  636. CheckBox* checkBox = CheckBox::create();
  637. setPropsWithFlatBuffers(checkBox, (Table*)checkBoxOptions);
  638. return checkBox;
  639. }
  640. int CheckBoxReader::getResourceType(std::string key)
  641. {
  642. if(key == "Normal" || key == "Default")
  643. {
  644. return 0;
  645. }
  646. FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
  647. if(fbs->_isSimulator)
  648. {
  649. if(key == "MarkedSubImage")
  650. {
  651. return 0;
  652. }
  653. }
  654. return 1;
  655. }
  656. }