bool Inventory::init() { if (!Node::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); relativeLayout = Layout::create(); relativeLayout->setSize(visibleSize); relativeLayout->setClippingEnabled(true); relativeLayout->setLayoutType(LAYOUT_RELATIVE); this->addChild(relativeLayout); simpleLayout = Layout::create(); simpleLayout->setSize(visibleSize); simpleLayout->setClippingEnabled(true); this->addChild(simpleLayout); ImageView *imageViewInList = ImageView::create(); imageViewInList->loadTexture("tool.png"); listView = ListView::create(); listView->setBackGroundColorType(LAYOUT_COLOR_SOLID); listView->setBackGroundColor(Color3B::MAGENTA); listView->setPosition(Point(100, 100)); listView->setSize(Size(500, 80)); listView->setDirection(SCROLLVIEW_DIR_HORIZONTAL); relativeLayout->addChild(listView); RelativeLayoutParameter *rpListView = RelativeLayoutParameter::create(); rpListView->setAlign(RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL); rpListView->setMargin(Margin(0, 20, 0, 0)); listView->setLayoutParameter(rpListView); ImageView *imageView = ImageView::create(); imageView->loadTexture("tool.png"); imageView->setVisible(false); relativeLayout->addChild(imageView); //DataManager::getInstance()->decCraftCount(0); //DataManager::getInstance()->save(); return true; }
void WidgetReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { bool ignoreSizeExsit = DICTOOL->checkObjectExist_json(options, P_IgnoreSize); if (ignoreSizeExsit) { widget->ignoreContentAdaptWithSize(DICTOOL->getBooleanValue_json(options, P_IgnoreSize)); } widget->setSizeType((Widget::SizeType)DICTOOL->getIntValue_json(options, P_SizeType)); widget->setPositionType((Widget::PositionType)DICTOOL->getIntValue_json(options, P_PositionType)); widget->setSizePercent(Vec2(DICTOOL->getFloatValue_json(options, P_SizePercentX), DICTOOL->getFloatValue_json(options, P_SizePercentY))); widget->setPositionPercent(Vec2(DICTOOL->getFloatValue_json(options, P_PositionPercentX), DICTOOL->getFloatValue_json(options, P_PositionPercentY))); /* adapt screen */ float w = 0, h = 0; bool adaptScrenn = DICTOOL->getBooleanValue_json(options, P_AdaptScreen); if (adaptScrenn) { Size screenSize = CCDirector::getInstance()->getWinSize(); w = screenSize.width; h = screenSize.height; } else { w = DICTOOL->getFloatValue_json(options, P_Width); h = DICTOOL->getFloatValue_json(options, P_Height); } widget->setSize(Size(w, h)); widget->setTag(DICTOOL->getIntValue_json(options, P_Tag)); widget->setActionTag(DICTOOL->getIntValue_json(options, P_ActionTag)); widget->setTouchEnabled(DICTOOL->getBooleanValue_json(options, P_TouchAble)); const char* name = DICTOOL->getStringValue_json(options, P_Name); const char* widgetName = name?name:"default"; widget->setName(widgetName); float x = DICTOOL->getFloatValue_json(options, P_X); float y = DICTOOL->getFloatValue_json(options, P_Y); widget->setPosition(Vec2(x,y)); bool sx = DICTOOL->checkObjectExist_json(options, P_ScaleX); if (sx) { widget->setScaleX(DICTOOL->getFloatValue_json(options, P_ScaleX)); } bool sy = DICTOOL->checkObjectExist_json(options, P_ScaleY); if (sy) { widget->setScaleY(DICTOOL->getFloatValue_json(options, P_ScaleY)); } bool rt = DICTOOL->checkObjectExist_json(options, P_Rotation); if (rt) { widget->setRotation(DICTOOL->getFloatValue_json(options, P_Rotation)); } bool vb = DICTOOL->checkObjectExist_json(options, P_Visbile); if (vb) { widget->setVisible(DICTOOL->getBooleanValue_json(options, P_Visbile)); } int z = DICTOOL->getIntValue_json(options, P_ZOrder); widget->setLocalZOrder(z); bool layout = DICTOOL->checkObjectExist_json(options, P_LayoutParameter); if (layout) { const rapidjson::Value& layoutParameterDic = DICTOOL->getSubDictionary_json(options, P_LayoutParameter); int paramType = DICTOOL->getIntValue_json(layoutParameterDic, P_Type); LayoutParameter* parameter = nullptr; switch (paramType) { case 0: break; case 1: { parameter = LinearLayoutParameter::create(); int gravity = DICTOOL->getIntValue_json(layoutParameterDic, P_Gravity); ((LinearLayoutParameter*)parameter)->setGravity((cocos2d::ui::LinearLayoutParameter::LinearGravity)gravity); break; } case 2: { parameter = RelativeLayoutParameter::create(); RelativeLayoutParameter* rParameter = (RelativeLayoutParameter*)parameter; const char* relativeName = DICTOOL->getStringValue_json(layoutParameterDic, P_RelativeName); rParameter->setRelativeName(relativeName); const char* relativeToName = DICTOOL->getStringValue_json(layoutParameterDic, P_RelativeToName); rParameter->setRelativeToWidgetName(relativeToName); int align = DICTOOL->getIntValue_json(layoutParameterDic, P_Align); rParameter->setAlign((cocos2d::ui::RelativeLayoutParameter::RelativeAlign)align); break; } default: break; } if (parameter) { float mgl = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginLeft); float mgt = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginTop); float mgr = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginRight); float mgb = DICTOOL->getFloatValue_json(layoutParameterDic, P_MarginDown); parameter->setMargin(Margin(mgl, mgt, mgr, mgb)); widget->setLayoutParameter(parameter); } } }