CocoWidget* CCSReader::widgetFromCCDictionary(cocos2d::CCDictionary* data) { CocoWidget* widget = NULL; const char* classname = DICTOOL->getStringValue(data, "classname"); cocos2d::CCDictionary* uiOptions = DICTOOL->getSubDictionary(data, "options"); if (classname && strcmp(classname, "Button") == 0) { widget = CocoButton::create(); this->setPropsForButtonFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "CheckBox") == 0){ widget = CocoCheckBox::create(); this->setPropsForCheckBoxFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "Label") == 0){ widget = CocoLabel::create(); this->setPropsForLabelFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "LabelAtlas") == 0){ widget = CocoLabelAtlas::create(); this->setPropsForLabelAtlasFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "LoadingBar") == 0){ widget = CocoLoadingBar::create(); this->setPropsForLoadingBarFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "ScrollView") == 0){ widget = CocoScrollView::create(); this->setPropsForScrollViewFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "TextArea") == 0){ widget = CocoTextArea::create(); this->setPropsForTextAreaFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "TextButton") == 0){ widget = CocoTextButton::create(); this->setPropsForTextButtonFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "TextField") == 0){ widget = CocoTextField::create(); this->setPropsForTextFieldFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "ImageView") == 0){ widget = CocoImageView::create(); this->setPropsForImageViewFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "Panel") == 0){ widget = CocoPanel::create(); this->setPropsForPanelFromCCDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "Slider") == 0){ widget = CocoSlider::create(); this->setPropsForSliderFromCCDictionary(widget, uiOptions); } cocos2d::CCArray* arr = DICTOOL->getArrayValue(data, "children"); if (arr) { for (int i=0;i<arr->count();i++){ cocos2d::CCDictionary* subData = (cocos2d::CCDictionary*)(arr->objectAtIndex(i)); CocoWidget* child = this->widgetFromCCDictionary(subData); if (child) { widget->addChild(child); } } } return widget; }
CocoWidget* CCSReader::widgetFromJsonDictionary(cs::CSJsonDictionary* data) { CocoWidget* widget = NULL; const char* classname = DICTOOL->getStringValue_json(data, "classname"); cs::CSJsonDictionary* uiOptions = DICTOOL->getSubDictionary_json(data, "options"); if (classname && strcmp(classname, "Button") == 0) { widget = CocoButton::create(); this->setPropsForButtonFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "CheckBox") == 0){ widget = CocoCheckBox::create(); this->setPropsForCheckBoxFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "Label") == 0){ widget = CocoLabel::create(); this->setPropsForLabelFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "LabelAtlas") == 0){ widget = CocoLabelAtlas::create(); this->setPropsForLabelAtlasFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "LoadingBar") == 0){ widget = CocoLoadingBar::create(); this->setPropsForLoadingBarFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "ScrollView") == 0){ widget = CocoScrollView::create(); this->setPropsForScrollViewFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "TextArea") == 0){ widget = CocoTextArea::create(); this->setPropsForTextAreaFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "TextButton") == 0){ widget = CocoTextButton::create(); this->setPropsForTextButtonFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "TextField") == 0){ widget = CocoTextField::create(); this->setPropsForTextFieldFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "ImageView") == 0){ widget = CocoImageView::create(); this->setPropsForImageViewFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "Panel") == 0){ widget = CocoPanel::create(); this->setPropsForPanelFromJsonDictionary(widget, uiOptions); }else if (classname && strcmp(classname, "Slider") == 0){ widget = CocoSlider::create(); this->setPropsForSliderFromJsonDictionary(widget, uiOptions); } int childrenCount = DICTOOL->getArrayCount_json(data, "children"); for (int i=0;i<childrenCount;i++){ cs::CSJsonDictionary* subData = DICTOOL->getDictionaryFromArray_json(data, "children", i); CocoWidget* child = this->widgetFromJsonDictionary(subData); if (child) { widget->addChild(child); } } return widget; }