// // load file // void CCConfiguration::loadConfigFile( const char *filename ) { CCDictionary *dict = CCDictionary::createWithContentsOfFile(filename); CCAssert(dict, "cannot create dictionary"); // search for metadata bool metadata_ok = false; CCObject *metadata = dict->objectForKey("metadata"); if( metadata && dynamic_cast<CCDictionary*>(metadata) ) { CCObject *format_o = static_cast<CCDictionary*>(metadata)->objectForKey("format"); // XXX: cocos2d-x returns CCStrings when importing from .plist. This bug will be addressed in cocos2d-x v3.x if( format_o && dynamic_cast<CCString*>(format_o) ) { int format = static_cast<CCString*>(format_o)->intValue(); // Support format: 1 if( format == 1 ) { metadata_ok = true; } } // XXX: cocos2d-x returns CCStrings when importing from .plist. This bug will be addressed in cocos2d-x v3.x if( format_o && dynamic_cast<CCInteger*>(format_o) ) { int format = dynamic_cast<CCInteger*>(format_o)->getValue(); // Support format: 1 if( format == 1 ) { metadata_ok = true; } } } if( ! metadata_ok ) { CCLOG("Invalid config format for file: %s", filename); return; } CCObject *data = dict->objectForKey("data"); if( !data || !dynamic_cast<CCDictionary*>(data) ) { CCLOG("Expected 'data' dict, but not found. Config file: %s", filename); return; } // Add all keys in the existing dictionary CCDictionary *data_dict = static_cast<CCDictionary*>(data); CCDictElement* element; CCDICT_FOREACH(data_dict, element) { if( ! m_pValueDict->objectForKey( element->getStrKey() ) ) m_pValueDict->setObject(element->getObject(), element->getStrKey() ); else CCLOG("Key already present. Ignoring '%s'", element->getStrKey() ); } }
// // load file // void CCConfiguration::loadConfigFile( const char *filename ) { CCDictionary *dict = CCDictionary::createWithContentsOfFile(filename); CCAssert(dict, "cannot create dictionary"); // Add all keys in the existing dictionary CCDictElement* element; CCDICT_FOREACH(dict, element) { if( ! m_pDefaults->objectForKey( element->getStrKey() ) ) m_pDefaults->setObject(element->getObject(), element->getStrKey() ); else CCLOG("Key already present. Ignoring '%s'", element->getStrKey() ); } }
void CCPrettyPrinter::visit(const CCDictionary *p) { _result += "\n"; _result += _indentStr; _result += "<dict>\n"; setIndentLevel(_indentLevel+1); CCDictElement* element; bool bFirstElement = true; char buf[1000] = {0}; CCDICT_FOREACH(p, element) { if (!bFirstElement) { _result += "\n"; } sprintf(buf, "%s%s: ", _indentStr.c_str(),element->getStrKey()); _result += buf; CCPrettyPrinter v(_indentLevel); element->getObject()->acceptVisitor(v); _result += v.getResult(); bFirstElement = false; } setIndentLevel(_indentLevel-1); _result += "\n"; _result += _indentStr; _result += "</dict>"; }
bool CCDictionarySaver::saveDictionary(CCDictionary* pDict, xmlNodePtr node) { do { xmlNodePtr dict_node = xmlNewNode(NULL, DICT_NODE_DICT); CC_BREAK_IF(!dict_node); CC_BREAK_IF(!xmlAddChild(node, dict_node)); CCDictElement* pElem; CCDICT_FOREACH(pDict, pElem) { saveKey(pElem->getStrKey(), dict_node); CCObject* obj = pElem->getObject(); if (dynamic_cast<CCString*>(obj)) { CCString* s = dynamic_cast<CCString*>(obj); CC_BREAK_IF(!saveString(s->getCString(), dict_node)); } else if (dynamic_cast<CCDictionary*>(obj)) { CC_BREAK_IF(!saveDictionary(dynamic_cast<CCDictionary*>(obj), dict_node)); } else if (dynamic_cast<CCArray*>(obj)) { CC_BREAK_IF(!saveArray(dynamic_cast<CCArray*>(obj), dict_node)); } } return true; } while (false);
void YHLanguageManager::addTexts(cocos2d::CCDictionary * dict) { CCDictElement * e = nullptr; CCDICT_FOREACH(dict, e) { m_dict->setObject(e->getObject(), e->getStrKey()); }
void StatusPush::handleResponse(__Dictionary* dict) { if (!dict) { return; } __Dictionary* params = _dict(dict->objectForKey("params")); if (params->objectForKey("oldStatus")) {//删除该状态的作用 int reStatusId = params->valueForKey("oldStatus")->intValue(); if (GlobalData::shared()->statusMap.find(reStatusId) != GlobalData::shared()->statusMap.end()) { GlobalData::shared()->statusMap[reStatusId] = 0; } } // int tempTime = 0; if (params->objectForKey("effectState")) { auto stateDict = _dict(params->objectForKey("effectState")); CCDictElement* element; CCDICT_FOREACH(stateDict, element) { string key = element->getStrKey(); // int effectId = atoi(key.c_str()); double time = stateDict->valueForKey(key)->doubleValue()/1000; if (time>0) { time = GlobalData::shared()->changeTime(time); } if (key!="startTime") { GlobalData::shared()->statusMap[atoi(key.c_str())] = -1;//time; // tempTime = time; } map<int, CCDictionary* >::iterator it = ToolController::getInstance()->m_statusItems.find(100); CCObject* obj = element->getObject(); CCString* str = (CCString*)obj; if(it!=ToolController::getInstance()->m_statusItems.end()){ auto dic = it->second; if(!dic->objectForKey("startTime")){ dic->setObject(CCString::create(CC_ITOA(WorldController::getInstance()->getTime())), "startTime"); }else if(key!="" && key!="startTime"){ dic->setObject(CCString::create(str->getCString()), "endTime"); }else if(key=="startTime"){ dic->setObject(CCString::create(str->getCString()), "startTime"); } ToolController::getInstance()->m_statusItems[100] = dic; }else{ auto infoDic = CCDictionary::create(); infoDic->retain(); if(key!="" && key!="startTime"){ infoDic->setObject(CCString::create(str->getCString()), "endTime"); }else if(key=="startTime"){ infoDic->setObject(CCString::create(str->getCString()), "startTime"); } ToolController::getInstance()->m_statusItems[100] = infoDic; } ToolController::getInstance()->checkMaincityCustom(); }
CCDictionary* CCTextureCache::snapshotTextures() { CCDictionary* pRet = new CCDictionary(); CCDictElement* pElement = NULL; CCDICT_FOREACH(m_pTextures, pElement) { pRet->setObject(pElement->getObject(), pElement->getStrKey()); }
void CCJSONConverter::convertDictionaryToJson(CCDictionary *dictionary, cJSON *json) { CCDictElement * pElement = NULL; CCDICT_FOREACH(dictionary, pElement){ CCObject * obj = pElement->getObject(); cJSON * jsonItem = getObjJson(obj); cJSON_AddItemToObject(json, pElement->getStrKey(), jsonItem); }
void YHEffectFactory::addEffectDefiner(CCDictionary * dict) { CCDictElement * e = NULL; CCDICT_FOREACH(dict, e) { YHEffectDefiner * definer = new YHEffectDefiner((CCDictionary *)e->getObject()); definer->autorelease(); addEffectDefiner(e->getStrKey(), definer); }
bool Cartoon::ccTouchBegan(cocos2d::CCTouch *touch, cocos2d::CCEvent *event) { CCPoint touchLocation = touch->getLocationInView(); touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); touchLocation = convertToNodeSpace(touchLocation); // from left-bottom point to from left-top point touchLocation.y = getContentSize().height - touchLocation.y; if (m_pListener && m_pfnSelector) { CCDictElement* pElement = NULL; CCDICT_FOREACH(m_pBoxConfigs, pElement) { CCString *psBox = (CCString*)pElement->getObject(); CCRect rectOfTouched = CCRectFromString(psBox->m_sString.c_str()); if (rectOfTouched.containsPoint(touchLocation) && getBoxEnabled(pElement->getStrKey())) { (m_pListener->*m_pfnSelector)(this, pElement->getStrKey()); } }
// initialize NPC names void NPCManager::initNpcNames() { // read NpcName.plist const char* pszPath = GameResourceManager::sharedManager()->storedFullPathFromRelativePath(NPC_NAME_PLIST); CCDictionary *pNameDict = CCFileUtils::dictionaryWithContentsOfFile(pszPath); CCDictElement* pElement = NULL; CCDICT_FOREACH(pNameDict, pElement) { if (pNameDict->objectForKey(pElement->getStrKey())) { string strNpcID = pElement->getStrKey(); string strName = ((CCString*)pElement->getObject())->toStdString(); uint8 npcID = atoi(strNpcID.c_str()); m_npcName[npcID] = strName; } } }
void CCAnimationCache::parseVersion1(CCDictionary* animations) { CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); CCDictElement* pElement = NULL; CCDICT_FOREACH(animations, pElement) { CCDictionary* animationDict = (CCDictionary*)pElement->getObject(); CCArray* frameNames = (CCArray*)animationDict->objectForKey("frames"); float delay = animationDict->valueForKey("delay")->floatValue(); CCAnimation* animation = NULL; if ( frameNames == NULL ) { CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", pElement->getStrKey()); continue; } CCArray* frames = CCArray::createWithCapacity(frameNames->count()); frames->retain(); CCObject* pObj = NULL; CCARRAY_FOREACH(frameNames, pObj) { const char* frameName = ((CCString*)pObj)->getCString(); CCSpriteFrame* spriteFrame = frameCache->spriteFrameByName(frameName); if ( ! spriteFrame ) { CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", pElement->getStrKey(), frameName); continue; } CCAnimationFrame* animFrame = new CCAnimationFrame(); animFrame->initWithSpriteFrame(spriteFrame, 1, NULL); frames->addObject(animFrame); animFrame->release(); } if ( frames->count() == 0 ) { CCLOG("cocos2d: CCAnimationCache: None of the frames for animation '%s' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.", pElement->getStrKey()); continue; } else if ( frames->count() != frameNames->count() ) { CCLOG("cocos2d: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", pElement->getStrKey()); } animation = CCAnimation::create(frames, delay, 1); CCAnimationCache::sharedAnimationCache()->addAnimation(animation, pElement->getStrKey()); frames->release(); }
Json::Value jsonFromDictionary(CCDictionary * root) { if (root == NULL) return Json::Value::null; if (root->count() == 0) { Json::Value value; Json::Reader reader; reader.parse("{}", value); return value; } Json::Value jsonNode; CCDictElement * e = NULL; CCDICT_FOREACH(root, e) { if (dynamic_cast<CCArray *>(e->getObject()) != NULL) { Json::Value jsonChild = jsonFromArray((CCArray *)e->getObject()); jsonNode[e->getStrKey()] = jsonChild; } else if (dynamic_cast<CCDictionary *>(e->getObject()) != NULL) { Json::Value jsonChild = jsonFromDictionary((CCDictionary *)e->getObject()); jsonNode[e->getStrKey()] = jsonChild; } else if (dynamic_cast<CCString *>(e->getObject()) != NULL) { Json::Value jsonChild = Json::Value(((CCString *)e->getObject())->getCString()); jsonNode[e->getStrKey()] = jsonChild; } } return jsonNode; }
bool AmfUtil::isSame(cocos2d::CCObject *thisObj, cocos2d::CCObject *thatObj) { if (thisObj && !thatObj) return false; if (!thisObj && thatObj) return false; if (!thisObj && !thatObj) return true; if (dynamic_cast<CCBool *>(thisObj) && dynamic_cast<CCBool *>(thatObj)) { return dynamic_cast<CCBool *>(thisObj)->getValue() == dynamic_cast<CCBool *>(thatObj)->getValue(); } else if (dynamic_cast<CCInteger *>(thisObj) && dynamic_cast<CCInteger *>(thatObj)) { return dynamic_cast<CCInteger *>(thisObj)->getValue() == dynamic_cast<CCInteger *>(thatObj)->getValue(); } else if (dynamic_cast<CCFloat *>(thisObj) && dynamic_cast<CCFloat *>(thatObj)) { return dynamic_cast<CCFloat *>(thisObj)->getValue() == dynamic_cast<CCFloat *>(thatObj)->getValue(); } else if (dynamic_cast<CCDouble *>(thisObj) && dynamic_cast<CCDouble *>(thatObj)) { return dynamic_cast<CCDouble *>(thisObj)->getValue() == dynamic_cast<CCDouble *>(thatObj)->getValue(); } else if (dynamic_cast<CCString *>(thisObj) && dynamic_cast<CCString *>(thatObj)) { return strcmp(dynamic_cast<CCString *>(thisObj)->getCString(), dynamic_cast<CCString *>(thatObj)->getCString()) == 0; } else if (dynamic_cast<CCDate *>(thisObj) && dynamic_cast<CCDate *>(thatObj)) { return dynamic_cast<CCDate *>(thisObj)->isEqual(dynamic_cast<CCDate *>(thatObj)); } else if (dynamic_cast<AmfTraitsInfo *>(thisObj) && dynamic_cast<AmfTraitsInfo *>(thatObj)) { return dynamic_cast<AmfTraitsInfo *>(thisObj)->isEqual(dynamic_cast<AmfTraitsInfo *>(thatObj)); } else if (dynamic_cast<AmfObject *>(thisObj) && dynamic_cast<AmfObject *>(thatObj)) { return dynamic_cast<AmfObject *>(thisObj)->isEqual(dynamic_cast<AmfObject *>(thatObj)); } else if (dynamic_cast<AmfCoding *>(thisObj) && dynamic_cast<AmfCoding *>(thatObj)) { return dynamic_cast<AmfCoding *>(thisObj)->isEquals(thatObj); } else if (dynamic_cast<CCArray *>(thisObj) && dynamic_cast<CCArray *>(thatObj)) { CCArray *thisArray = dynamic_cast<CCArray *>(thisObj); CCArray *thatArray = dynamic_cast<CCArray *>(thatObj); int count = thisArray->count(); int capacity = thisArray->capacity(); if (count != thatArray->count() || (count == 0 && capacity != thatArray->capacity())) return false; for (int i = 0; i < count; i++) { if (!isSame(thisArray->objectAtIndex(i), thatArray->objectAtIndex(i))) return false; } return true; } else if (dynamic_cast<CCDictionary *>(thisObj) && dynamic_cast<CCDictionary *>(thatObj)) { CCDictionary *thisDict = dynamic_cast<CCDictionary *>(thisObj); CCDictionary *thatDict = dynamic_cast<CCDictionary *>(thatObj); int count = thisDict->count(); if (count != thatDict->count()) return false; CCDictElement *thisElement; CCDICT_FOREACH(thisDict, thisElement) { char const *thisKey = thisElement->getStrKey(); CCObject *thatValue = thatDict->objectForKey(thisKey); if (!thatValue) return false; if (!isSame(thisElement->getObject(), thatValue)) return false; }
void ArmatureDataManager::removeUnusedAnimations(){ if( m_pArmatureFileInfoDic ){ CCTextureCache * tc = CCTextureCache::sharedTextureCache(); CCSpriteFrameCache * sfc = CCSpriteFrameCache::sharedSpriteFrameCache(); std::vector<std::string> cleanlist; CCDictElement* pElement = NULL; CCDICT_FOREACH(m_pArmatureFileInfoDic, pElement){ const std::string file = pElement->getStrKey(); ArmatureFileInfo * _fileInfo = (ArmatureFileInfo*)pElement->getObject(); if (_fileInfo && _fileInfo->retainCount() == 1) { //清理 m_pAnimationDatas、m_pArmarureDatas、m_pTextureDatas 信息 if( m_pAnimationDatas ){ m_pAnimationDatas->removeObjectForKey(_fileInfo->configFilePath); } if( m_pArmarureDatas ){ m_pArmarureDatas->removeObjectForKey(_fileInfo->configFilePath); } if( m_pTextureDatas ){ m_pTextureDatas->removeObjectForKey(_fileInfo->configFilePath); } //清理精灵帧、纹理和标记需要清理的ArmatureFile for (std::vector<ImageInfo>::iterator it = _fileInfo->imageInfoVector.begin(); it != _fileInfo->imageInfoVector.end(); it++){ const std::string & plist = it->plistPath; const std::string & texture = it->imagePath; sfc->removeSpriteFramesFromFile(plist.c_str()); tc->removeTextureForKey(texture.c_str()); cleanlist.push_back(file); } } } int size = cleanlist.size(); for(int i = 0; i < size; i++) { m_pArmatureFileInfoDic->removeObjectForKey(cleanlist[i]); } cleanlist.clear(); } }
void ArmatureDataManager::addSpriteFrameFromFile(const char *_plistPath, const char *_imagePath){ //TODO:需要测试 #if USING_COCOS2D_2_1_PLUS std::string pszPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(_plistPath); #else std::string pszPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(_plistPath); #endif CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(pszPath.c_str()); CCDictionary *framesDict = (CCDictionary*)dict->objectForKey("frames"); CCDictElement* pElement = NULL; CCDICT_FOREACH(framesDict, pElement){ const std::string spriteFrameName = pElement->getStrKey(); m_Display2ImageMap[spriteFrameName] = _imagePath; } CC_SAFE_RELEASE_NULL(dict); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(_plistPath, _imagePath); }
ValueMap valueMapFromDictionary(CCDictionary * root) { assert(root != NULL); ValueMap map; CCDictElement * e = NULL; CCDICT_FOREACH(root, e) { CCObject * obj = e->getObject(); if (dynamic_cast<CCString *>(obj) != NULL) { CCString * str = (CCString *)obj; map[e->getStrKey()] = cocos2d::Value(str->getCString()); } else if (dynamic_cast<CCFloat *>(obj) != NULL) { CCFloat * val = (CCFloat *)obj; map[e->getStrKey()] = cocos2d::Value(val->getValue()); } else if (dynamic_cast<CCDouble *>(obj) != NULL) { CCDouble * val = (CCDouble *)obj; map[e->getStrKey()] = cocos2d::Value(val->getValue()); } else if (dynamic_cast<CCInteger *>(obj) != NULL) { CCInteger * val = (CCInteger *)obj; map[e->getStrKey()] = cocos2d::Value(val->getValue()); } else if (dynamic_cast<CCBool *>(obj) != NULL) { CCBool * val = (CCBool *)obj; map[e->getStrKey()] = cocos2d::Value(val->getValue()); } else if (dynamic_cast<CCDictionary *>(obj) != NULL) { CCDictionary * dict = (CCDictionary *)obj; map[e->getStrKey()] = cocos2d::Value(valueMapFromDictionary(dict)); } else if (dynamic_cast<CCArray *>(obj) != NULL) { CCArray * arr = (CCArray *)obj; map[e->getStrKey()] = cocos2d::Value(valueVectorFromArray(arr)); } }
JSBool jsval_to_std_map_string_string(JSContext *cx, jsval v, std::map<std::string,std::string> *ret) { cocos2d::CCDictionary* value; bool ok = jsval_to_ccdictionary(cx, v, &value); if (!ok) { return ok; } else { CCDictElement* pElement; CCDICT_FOREACH(value, pElement) { const char*key = pElement->getStrKey(); CCString *v = (CCString*) pElement->getObject(); ret->insert(std::make_pair(key, v->getCString())); } } return ok; }
void MovieClip::initFrame() { string plistName = this->mcName; plistName += ".plist"; //获取总帧数 string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(plistName.c_str()); CCDictionary* dictionary = CCDictionary::createWithContentsOfFileThreadSafe(fullPath.c_str()); CCDictionary* framesDict = (CCDictionary*)dictionary->objectForKey("frames"); CCDictElement* pElement = NULL; //ios平台下由于framesDict无法顺序读取,会造成动画错乱bug。增加平台判断排序keyList。 #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) { list<string> keyList; CCDICT_FOREACH(framesDict, pElement) { string spriteFrameName = pElement->getStrKey(); keyList.push_back(spriteFrameName); } keyList.sort(); for (list<string>::iterator it = keyList.begin(); it != keyList.end(); ++it) { string spriteFrameName = *it; string prefixStr = this->prefix; if (!prefixStr.empty()) { //提取key的子字符串 string subStr = spriteFrameName.substr(0, prefixStr.length()); //比较子字符串的参数 如果相同则放入帧数组 if (subStr.compare(prefixStr) == 0) this->frameList->addObject(CCString::create(spriteFrameName.c_str())); } else { this->frameList->addObject(CCString::create(spriteFrameName.c_str())); } } }
void BmVList::ShowContents() { clt->setString(g_chara->m_sName.c_str()); // <ÊôÐÔ CCDictElement* pCde = NULL; string t_name; CCLabelBMFont* t_clbm = NULL; int ti = 0; CCDICT_FOREACH(m_cdBmNum,pCde){ t_name = pCde->getStrKey(); t_clbm = (CCLabelBMFont*) pCde->getObject(); string tsMai = CCString::createWithFormat("%d",g_chara->getvalue(t_name))->getCString(); if(ti > 3 && ti < 14){ int ti = g_chara->getFixValue(t_name) - g_chara->getvalue(t_name); string tsMid; ti>0?tsMid="+":tsMid=""; string tsAto = CCString::createWithFormat("%d",ti)->getCString(); t_clbm->removeAllChildren(); t_clbm->setString((tsMai + tsMid + tsAto).c_str()); CCArray* pArray = t_clbm->getChildren(); CCLog(">[BmVList] %s - length:%d", tsMai.c_str(), tsMai.length()); for(int tfi = tsMai.length(); tfi < pArray->count(); ++tfi){ CCSprite* tcs = (CCSprite*) pArray->objectAtIndex(tfi); tcs->setColor(ccRED); } }else{ t_clbm->setString(tsMai.c_str()); } ++ti; }
void b2ShapeCache::addShapesWithFile(const std::string &plist, b2Vec2 vertexScale, float ptm) { CCDictionary *dict = CCDictionary::createWithContentsOfFile(plist.c_str()); CCAssert(dict != NULL, "Shape-file not found"); CCAssert(dict->count() != 0, "plist file empty or not existing"); CCDictionary *metadataDict = (CCDictionary *)dict->objectForKey("metadata"); int format = metadataDict->valueForKey("format")->intValue(); ptmRatio = metadataDict->valueForKey("ptm_ratio")->floatValue(); if (ptm <= 0) ptm = ptmRatio; CCLOG("ptmRatio = %f",ptmRatio); CCAssert(format == 1, "Format not supported"); CCDictionary *bodyDict = (CCDictionary *)dict->objectForKey("bodies"); b2Vec2 vertices[b2_maxPolygonVertices]; CCDictElement *dictElem; std::string bodyName; CCDictionary *bodyData; //iterate body list CCDICT_FOREACH(bodyDict,dictElem ) { bodyData = (CCDictionary*)dictElem->getObject(); bodyName = dictElem->getStrKey(); BodyDef *bodyDef = new BodyDef(); CCPoint a = CCPointFromString(bodyData->valueForKey("anchorpoint")->getCString()); float32 ax = (vertexScale.x >= 0) ? (float32)a.x : (float32)(1-a.x); float32 ay = (vertexScale.y >= 0) ? (float32)a.y : (float32)(1-a.y); bodyDef->anchorPoint = b2Vec2(ax, ay); CCArray *fixtureList = (CCArray*)(bodyData->objectForKey("fixtures")); FixtureDef **nextFixtureDef = &(bodyDef->fixtures); //iterate fixture list CCObject *arrayElem; CCARRAY_FOREACH(fixtureList, arrayElem) { b2FixtureDef basicData; CCDictionary* fixtureData = (CCDictionary*)arrayElem; basicData.filter.categoryBits = fixtureData->valueForKey("filter_categoryBits")->intValue(); basicData.filter.maskBits = fixtureData->valueForKey("filter_maskBits")->intValue(); basicData.filter.groupIndex = fixtureData->valueForKey("filter_groupIndex")->intValue(); basicData.friction = fixtureData->valueForKey("friction")->floatValue(); basicData.density = fixtureData->valueForKey("density")->floatValue(); basicData.restitution = fixtureData->valueForKey("restitution")->floatValue(); basicData.isSensor = fixtureData->valueForKey("isSensor")->intValue() != 0; int callbackData = fixtureData->valueForKey("userdataCbValue")->intValue(); const char* fixtureType = fixtureData->valueForKey("fixture_type")->getCString(); if (strcmp(fixtureType, "POLYGON")==0) { CCArray *polygonsArray = (CCArray *)(fixtureData->objectForKey("polygons")); CCObject *dicArrayElem; CCARRAY_FOREACH(polygonsArray, dicArrayElem) { FixtureDef *fix = new FixtureDef(); fix->fixture = basicData; // copy basic data fix->callbackData = callbackData; b2PolygonShape *polyshape = new b2PolygonShape(); int vindex = 0; CCArray *polygonArray = (CCArray*)dicArrayElem; assert(polygonArray->count() <= b2_maxPolygonVertices); CCObject *piter; CCARRAY_FOREACH(polygonArray, piter) { CCString *verStr = (CCString*)piter; CCPoint offset = CCPointFromString(verStr->getCString()); vertices[vindex] = b2Vec2((float32)(offset.x / ptmRatio) * vertexScale.x, (float32)(offset.y / ptmRatio) * vertexScale.y); vindex++; }
CCArray * GAFAsset::objectStatesFromConfigFrame(CCDictionary * configFrame) { if (!configFrame) { return NULL; } CCDictionary * stateNodes = (CCDictionary *) configFrame->objectForKey(kFrameStateKey); if (!stateNodes) { return NULL; } CCArray *states = CCArray::createWithCapacity(stateNodes->count()); CCDictElement* pElement = NULL; CCDICT_FOREACH(stateNodes, pElement) { CCDictionary * stateDictionary = (CCDictionary *)pElement->getObject(); GAFSubobjectState * state = GAFSubobjectState::createWithStateDictionary(stateDictionary, pElement->getStrKey()); if (state) { states->addObject(state); } else { CCLOGINFO("GAFSubobjectState cannot be created. Ignoring."); } }
bool CCPreLoad::cacheFramesForPlist(const char* plist, const char* textureFileName) { bool ret = false; do{ //private权限不好继承,直接挑出来改,Zwoptex.swf 1.0的version CCTexture2D *pobTexture = CCTextureCache::sharedTextureCache()->addImage(textureFileName); if(pobTexture == NULL) break; string pszPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(plist); CCDictionary *dictionary = CCDictionary::createWithContentsOfFileThreadSafe(pszPath.c_str()); CCDictionary *framesDict = (CCDictionary*)dictionary->objectForKey("frames"); int format = 0; CCDictElement* pElement = NULL; CCDICT_FOREACH(framesDict, pElement) { CCDictionary* frameDict = (CCDictionary*)pElement->getObject(); std::string spriteFrameName = pElement->getStrKey(); CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(spriteFrameName.c_str()); if (spriteFrame) { continue; } int format = 0;//就只挑这个 if(format == 0) { float x = frameDict->valueForKey("x")->floatValue(); float y = frameDict->valueForKey("y")->floatValue(); float w = frameDict->valueForKey("width")->floatValue(); float h = frameDict->valueForKey("height")->floatValue(); float ox = frameDict->valueForKey("offsetX")->floatValue(); float oy = frameDict->valueForKey("offsetY")->floatValue(); int ow = frameDict->valueForKey("originalWidth")->intValue(); int oh = frameDict->valueForKey("originalHeight")->intValue(); // check ow/oh if(!ow || !oh) { CCLOGWARN("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist"); } // abs ow/oh ow = abs(ow); oh = abs(oh); // create frame spriteFrame = new CCSpriteFrame(); spriteFrame->initWithTexture(pobTexture, CCRectMake(x, y, w, h), false, CCPointMake(ox, oy), CCSizeMake((float)ow, (float)oh) ); } // add sprite frame CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame(spriteFrame, spriteFrameName.c_str()); m_tmpFrames.insert(make_pair(spriteFrameName,spriteFrame)); spriteFrame->release(); } dictionary->release(); ret = true; }while(0);
void SpriteFrameCacheHelper::addSpriteFrameFromDict(CCDictionary* dictionary, CCTexture2D *pobTexture, const char *_imagePath) { /* Supported Zwoptex Formats: ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1 ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+ */ CCDictionary *metadataDict = (CCDictionary*)dictionary->objectForKey("metadata"); CCDictionary *framesDict = (CCDictionary*)dictionary->objectForKey("frames"); int format = 0; // get the format if(metadataDict != NULL) { format = metadataDict->valueForKey("format")->intValue(); } // check the format CCAssert(format >=0 && format <= 3, "format is not supported for CCSpriteFrameCache addSpriteFramesWithDictionary:textureFilename:"); CCDictElement* pElement = NULL; CCDICT_FOREACH(framesDict, pElement) { CCDictionary* frameDict = (CCDictionary*)pElement->getObject(); std::string spriteFrameName = pElement->getStrKey(); m_Display2ImageMap[spriteFrameName] = _imagePath; //CCLog("spriteFrameName : %s, imagePath : %s", spriteFrameName.c_str(), _imagePath); CCSpriteFrame* spriteFrame = (CCSpriteFrame*)CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(spriteFrameName.c_str()); if (spriteFrame) { continue; } if(format == 0) { float x = frameDict->valueForKey("x")->floatValue(); float y = frameDict->valueForKey("y")->floatValue(); float w = frameDict->valueForKey("width")->floatValue(); float h = frameDict->valueForKey("height")->floatValue(); float ox = frameDict->valueForKey("offsetX")->floatValue(); float oy = frameDict->valueForKey("offsetY")->floatValue(); int ow = frameDict->valueForKey("originalWidth")->intValue(); int oh = frameDict->valueForKey("originalHeight")->intValue(); // check ow/oh if(!ow || !oh) { CCLOG("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist"); } // abs ow/oh ow = abs(ow); oh = abs(oh); // create frame spriteFrame = new CCSpriteFrame(); spriteFrame->initWithTexture(pobTexture, CCRectMake(x, y, w, h), false, CCPointMake(ox, oy), CCSizeMake((float)ow, (float)oh) ); } else if(format == 1 || format == 2) { CCRect frame = CCRectFromString(frameDict->valueForKey("frame")->getCString()); bool rotated = false; // rotation if (format == 2) { rotated = frameDict->valueForKey("rotated")->boolValue(); } CCPoint offset = CCPointFromString(frameDict->valueForKey("offset")->getCString()); CCSize sourceSize = CCSizeFromString(frameDict->valueForKey("sourceSize")->getCString()); // create frame spriteFrame = new CCSpriteFrame(); spriteFrame->initWithTexture(pobTexture, frame, rotated, offset, sourceSize ); } else if (format == 3) { } // add sprite frame CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame(spriteFrame, spriteFrameName.c_str()); spriteFrame->release(); }
void GB2ShapeCache::addShapesWithFile(const std::string &plist) { const char *fullName = CCFileUtils::sharedFileUtils()->fullPathForFilename(plist.c_str()).c_str(); //const char *fullName = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(plist.c_str()); ObjectDict *dict = CCDictionary::createWithContentsOfFile(fullName); CCAssert(dict != NULL, "Shape-file not found"); // not triggered - cocos2dx delivers empty dict if non was found CCAssert(dict->count() != 0, "plist file empty or not existing"); ObjectDict *metadataDict = (ObjectDict *)dict->objectForKey("metadata"); int format = atoi(static_cast<CCString *>(metadataDict->objectForKey("format"))->getCString()); ptmRatio = atof(static_cast<CCString *>(metadataDict->objectForKey("ptm_ratio"))->getCString()); CCAssert(format == 1, "Format not supported"); ObjectDict *bodyDict = (ObjectDict *)dict->objectForKey("bodies"); CCLOG("%d", bodyDict->count()); b2Vec2 vertices[b2_maxPolygonVertices]; std::string bodyName; ObjectDict *bodyData; CCDictElement *pElement = NULL; CCDICT_FOREACH(bodyDict, pElement) { bodyName = pElement->getStrKey(); bodyData = (ObjectDict *)pElement->getObject(); CCLOG("%d", bodyData->count()); CCString *anchorPoint = static_cast<CCString *>(bodyData->objectForKey("anchorpoint")); BodyDef *bodyDef = new BodyDef(); bodyDef->anchorPoint = CCPointFromString(anchorPoint->getCString()); CCArray *fixtureList = (CCArray *)(bodyData->objectForKey("fixtures")); FixtureDef **nextFixtureDef = &(bodyDef->fixtures); CCObject *pElement = NULL; CCARRAY_FOREACH(fixtureList, pElement) { b2FixtureDef basicData; ObjectDict *fixtureData = (ObjectDict *)pElement; basicData.filter.categoryBits = atoi(static_cast<CCString *>(fixtureData->objectForKey("filter_categoryBits"))->getCString()); basicData.filter.maskBits = atoi(static_cast<CCString *>(fixtureData->objectForKey("filter_maskBits"))->getCString()); basicData.filter.groupIndex = atoi(static_cast<CCString *>(fixtureData->objectForKey("filter_groupIndex"))->getCString()); basicData.friction = atof(static_cast<CCString *>(fixtureData->objectForKey("friction"))->getCString()); basicData.density = atof(static_cast<CCString *>(fixtureData->objectForKey("density"))->getCString()); basicData.restitution = atof(static_cast<CCString *>(fixtureData->objectForKey("restitution"))->getCString()); basicData.isSensor = (bool)(atoi(static_cast<CCString *>(fixtureData->objectForKey("isSensor"))->getCString())); CCString *cb = static_cast<CCString *>(fixtureData->objectForKey("userdataCbValue")); int callbackData = 0; if (cb) callbackData = atoi(cb->getCString()); std::string fixtureType = static_cast<CCString *>(fixtureData->objectForKey("fixture_type"))->getCString(); if (fixtureType == "POLYGON") { CCArray *polygonsArray = (CCArray *)(fixtureData->objectForKey("polygons")); CCObject *pElement = NULL; CCARRAY_FOREACH(polygonsArray, pElement) { FixtureDef *fix = new FixtureDef(); fix->fixture = basicData; // copy basic data fix->callbackData = callbackData; b2PolygonShape *polyshape = new b2PolygonShape(); int vindex = 0; CCArray *polygonArray = (CCArray *)pElement; assert(polygonArray->count() <= b2_maxPolygonVertices); CCObject *pElement = NULL; CCARRAY_FOREACH(polygonArray, pElement) { CCString *str = (CCString *)pElement; CCPoint offset = CCPointFromString(str->getCString()); vertices[vindex].x = (offset.x / ptmRatio) ; vertices[vindex].y = (offset.y / ptmRatio) ; vindex++; }
bool startActivityJNI(const char* action, const char* pkgName, const char* clsName, CCDictionary* pParams) { if (action == NULL && (pkgName == NULL || clsName == NULL)) { CCLOGWARN("can't init Intent by action or package & class name"); return false; } JniMethodInfo t; jboolean ret(false); if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "startActivity", "(Landroid/content/Intent;)Z")) { fields_intent intent_fields; initIntent(t.env, &intent_fields); jobject objArg = objArg = t.env->NewObject(intent_fields.clazz, intent_fields.constructor); if (objArg == NULL) { CCLOGWARN("can't create a Intent object"); return false; } // create a jstring array to save all jstring local refs. // it contains action, package name, class name and all params(key & value) jstring* strArgs = new jstring[ACT_PKG_CLS + (pParams ? pParams->count() : 0) * 2]; int argsCount = 0; if (action) { strArgs[argsCount++] = t.env->NewStringUTF(action); parcelIntentAction(t.env, objArg, intent_fields.set_action, strArgs[argsCount - 1]); } if (pkgName && clsName) { strArgs[argsCount++] = t.env->NewStringUTF(pkgName); strArgs[argsCount++] = t.env->NewStringUTF(clsName); parcelIntentComponent(t.env, objArg, intent_fields.set_class, strArgs[argsCount - 2], strArgs[argsCount - 1]); } if (pParams) { CCDictElement* tmpElement = NULL; CCObject* tmpObject = NULL; CCDICT_FOREACH(pParams, tmpElement) { strArgs[argsCount++] = t.env->NewStringUTF(tmpElement->getStrKey()); tmpObject = tmpElement->getObject(); if (dynamic_cast<CCString*>(tmpObject)) { strArgs[argsCount++] = t.env->NewStringUTF( ((CCString*) tmpObject)->getCString()); parcelIntentExtras(t.env, objArg, intent_fields.put_string, strArgs[argsCount - 2], strArgs[argsCount - 1]); } else if (dynamic_cast<CCBool*>(tmpObject)) { parcelIntentExtras(t.env, objArg, intent_fields.put_bool, strArgs[argsCount - 1], ((CCBool*) tmpObject)->getValue()); } else if (dynamic_cast<CCInteger*>(tmpObject)) { parcelIntentExtras(t.env, objArg, intent_fields.put_int, strArgs[argsCount - 1], ((CCInteger*) tmpObject)->getValue()); } else if (dynamic_cast<CCFloat*>(tmpObject)) { parcelIntentExtras(t.env, objArg, intent_fields.put_float, strArgs[argsCount - 1], ((CCFloat*) tmpObject)->getValue()); } else { CCLOGWARN("can't support CCObject type: %s", typeid(tmpObject).name()); } } }
void GB2ShapeCache::addShapesWithFile(const std::string &plist) { CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(plist.c_str()); //dictionaryWithContentsOfFileThreadSafe(plist.c_str()); CCAssert(dict != NULL, "Shape-file not found"); // not triggered - cocos2dx delivers empty dict if non was found CCAssert(dict->count() != 0, "plist file empty or not existing"); CCDictionary *metadataDict = (CCDictionary *)dict->objectForKey("metadata"); int format = static_cast<CCString *>(metadataDict->objectForKey("format"))->intValue(); ptmRatio = static_cast<CCString *>(metadataDict->objectForKey("ptm_ratio"))->floatValue(); CCAssert(format == 1, "Format not supported"); CCDictionary *bodyDict = (CCDictionary *)dict->objectForKey("bodies"); b2Vec2 vertices[b2_maxPolygonVertices]; CCDictElement* pElement = NULL; CCDICT_FOREACH(bodyDict, pElement) { BodyDef *bodyDef = new BodyDef(); CCString *bodyName = ccs(pElement->getStrKey()); CCDictionary *bodyData = (CCDictionary *)pElement->getObject(); bodyDef->anchorPoint = CCPointFromString(static_cast<CCString *>(bodyData->objectForKey("anchorpoint"))->getCString()); CCArray *fixtureList = (CCArray *)bodyData->objectForKey("fixtures"); FixtureDef **nextFixtureDef = &(bodyDef->fixtures); CCObject *fixture = NULL; CCARRAY_FOREACH(fixtureList, fixture) { b2FixtureDef basicData; CCDictionary *fixtureData = (CCDictionary *)fixture; int callbackData = 0; basicData.filter.categoryBits = static_cast<CCString *>(fixtureData->objectForKey("filter_categoryBits"))->intValue(); basicData.filter.maskBits = static_cast<CCString *>(fixtureData->objectForKey("filter_maskBits"))->intValue(); basicData.filter.groupIndex = static_cast<CCString *>(fixtureData->objectForKey("filter_groupIndex"))->intValue(); basicData.friction = static_cast<CCString *>(fixtureData->objectForKey("friction"))->floatValue(); basicData.density = static_cast<CCString *>(fixtureData->objectForKey("density"))->floatValue(); basicData.restitution = static_cast<CCString *>(fixtureData->objectForKey("restitution"))->floatValue(); basicData.isSensor = (bool)static_cast<CCString *>(fixtureData->objectForKey("isSensor"))->intValue(); if(fixtureData->objectForKey("id")){ basicData.userData = static_cast<CCString *>(fixtureData->objectForKey("id")); callbackData = static_cast<CCString *>(fixtureData->objectForKey("id"))->intValue(); } std::string fixtureType = static_cast<CCString *>(fixtureData->objectForKey("fixture_type"))->getCString(); //CCString *fixtureType = static_cast<CCString *>(fixtureData->objectForKey("fixture_type"))->getCString(); if (fixtureType == "POLYGON") { //CCDictionary *polygons = (CCDictionary *)fixtureData->objectForKey("polygons"); CCArray *polygons = (CCArray *)fixtureData->objectForKey("polygons"); //CCDictElement *polygon = NULL; CCObject *polygon = NULL; //CCDICT_FOREACH(polygons, polygon) CCARRAY_FOREACH(polygons, polygon) { FixtureDef *fix = new FixtureDef(); fix->fixture = basicData; // copy basic data fix->callbackData = callbackData; b2PolygonShape *polyshape = new b2PolygonShape(); int vindex = 0; //CCDictionary *polygonData = (CCDictionary *)polygon->getObject(); CCArray *polygonData = (CCArray *)polygon; assert(polygonData->count() <= b2_maxPolygonVertices); //CCDictElement *offset = NULL; CCObject *offset = NULL; //CCDICT_FOREACH(polygonData, offset) CCARRAY_FOREACH(polygonData, offset) { CCString *pStr = (CCString *)offset; CCPoint p = CCPointFromString(pStr->getCString()); vertices[vindex].x = (p.x / ptmRatio) ; vertices[vindex].y = (p.y / ptmRatio) ; vindex++; }
void CCTextureWatcher::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data) { m_nCurrnetPage = data->nRow + 1; CCListViewCell *cell = CCListViewCell::node(); cell->setOpacity(0); cell->setContentSize(m_pList->getContentSize()); cell->setSelectionColor(ccc4(0, 0, 0, 0)); data->cell = cell; CCSize listItemSize = CCSize(m_pList->getContentSize().width / NUM_PER_PAGE, m_pList->getContentSize().height); CCSize size = CCSize(listItemSize.width * 0.9, listItemSize.height * 0.6); sprintf(m_pszString, "%d/%d", m_nCurrnetPage, m_nTotalPage); m_labelPage->setString(m_pszString); float offX = 0, offY = 0, offsetX = 0, offsetY = 0; CC_UNUSED_PARAM(offsetY); int nCount = 0; int nStart = (m_nCurrnetPage - 1) * NUM_PER_PAGE; int nEnd = nStart + NUM_PER_PAGE; CCDictElement* pElement = NULL; CCDICT_FOREACH(m_pTextures, pElement) { if (nCount >= nStart && nCount < nEnd) { string key = pElement->getStrKey(); CCTexture2D* textrue = (CCTexture2D*)pElement->getObject(); //textrue = m_pTextures->objectForKey(*it); if (textrue) { // reference count sprintf(m_pszString, "[%d]", textrue->retainCount() - 2); CCLabelTTF *labelCount = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); if (textrue->retainCount() - 2 > 0) { labelCount->setColor(ccc3(0, 255, 0)); } else { labelCount->setColor(ccc3(255, 0, 0)); } offX = offsetX + listItemSize.width * 0.5 - labelCount->getContentSize().width * 0.5; offY = (listItemSize.height - size.height) * 0.5 - labelCount->getContentSize().height; labelCount->setPosition(ccp(offX, offY)); labelCount->setAnchorPoint(ccp(0, 0)); cell->addChild(labelCount); // texture size sprintf(m_pszString, "%.0f*%.0f", textrue->getContentSize().width, textrue->getContentSize().height); CCLabelTTF *labelSize = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); offX = offsetX + listItemSize.width * 0.5; offY = (listItemSize.height - size.height) * 0.5 + size.height; labelSize->setPosition(ccp(offX, offY)); labelSize->setAnchorPoint(ccp(0.5, 0)); cell->addChild(labelSize); // texture name int len = key.length(); int pos = 0; pos = key.rfind('\\') + 1; int pos2 = key.rfind('/') + 1; pos = pos > pos2 ? pos : pos2; string name = key.substr(pos, len - pos); sprintf(m_pszString, "%s", name.c_str()); CCSize dimensions = CCSizeMake(listItemSize.width * 0.9, labelSize->getContentSize().height); CCLabelTTF *labelName = CCLabelTTF::labelWithString(m_pszString, dimensions, CCTextAlignmentCenter, "Arial", 16); offX = offsetX + listItemSize.width * 0.5; offY = offY + labelName->getContentSize().height; labelName->setPosition(ccp(offX, offY)); labelName->setAnchorPoint(ccp(0.5, 0)); cell->addChild(labelName); CCSprite *sprite = CCSprite::spriteWithTexture(textrue); sprite->setAnchorPoint(ccp(0, 0)); CCSize spriteSize = sprite->getContentSize(); float scale; if (spriteSize.width < size.width && spriteSize.height < size.height) { scale = 1; } else if (spriteSize.width * size.height >= spriteSize.height * size.width) { scale = size.width / spriteSize.width; } else { scale = size.height / spriteSize.height; } sprite->setScale(scale); spriteSize.width *= scale; spriteSize.height *= scale; offX = offsetX + (listItemSize.width - spriteSize.width) * 0.5; offY = (listItemSize.height - spriteSize.height) * 0.5; sprite->setPosition(ccp(offX, offY)); cell->addChild(sprite); offsetX += listItemSize.width; } } ++nCount; } }
bool WinPointsUseCommand::handleRecieve(cocos2d::CCDictionary *dict) { if (dict->valueForKey("cmd")->compare(WIN_POINTS_USE) != 0) return false; CCDictionary *params=_dict(dict->objectForKey("params")); if (!params) { return false; } const CCString *pStr = params->valueForKey("errorCode"); if (pStr->compare("")!=0) { CCCommonUtils::flyText((_lang(pStr->getCString()).c_str())); }else{ int itemId = params->valueForKey("itemId")->intValue(); if (params->objectForKey("remainPoints")) { long remainPoints = params->valueForKey("remainPoints")->doubleValue(); GlobalData::shared()->playerInfo.winPoint = remainPoints; } if(params && params->objectForKey("itemEffectObj")) { auto effectObj = _dict(params->objectForKey("itemEffectObj")); if (effectObj->objectForKey("oldStatus")) {//删除该状态的作用 int reStatusId = effectObj->valueForKey("oldStatus")->intValue(); if (GlobalData::shared()->statusMap.find(reStatusId) != GlobalData::shared()->statusMap.end()) { GlobalData::shared()->statusMap[reStatusId] = 0; } } if (effectObj->objectForKey("effectState")) { auto stateDict = _dict(effectObj->objectForKey("effectState")); CCDictElement* element; CCDICT_FOREACH(stateDict, element) { string key = element->getStrKey(); int effectId = atoi(key.c_str()); if(effectId>=PLAYER_PROTECTED_TIME1 && effectId<=PLAYER_PROTECTED_TIME5){ GlobalData::shared()->playerInfo.protectTimeStamp = stateDict->valueForKey(key)->doubleValue(); if(SceneController::getInstance()->currentSceneId == SCENE_ID_WORLD){ WorldMapView::instance()->m_map->updateDynamicMap(WorldController::getInstance()->selfPoint); } } double time = stateDict->valueForKey(key)->doubleValue()/1000; if (time>0) { time = GlobalData::shared()->changeTime(time); } if (key!="startTime") { GlobalData::shared()->statusMap[atoi(key.c_str())] = time; } auto info = ToolController::getInstance()->getToolInfoById(itemId); map<int, CCDictionary* >::iterator it = ToolController::getInstance()->m_statusItems.find(info.type2); CCObject* obj = element->getObject(); CCString* str = (CCString*)obj; if(info.type==4){ if(it!=ToolController::getInstance()->m_statusItems.end()){ auto dic = it->second; if(!dic->objectForKey("startTime")){ dic->setObject(CCString::create(CC_ITOA(WorldController::getInstance()->getTime())), "startTime"); }else if(key!="" && key!="startTime"){ dic->setObject(CCString::create(str->getCString()), "endTime"); }else if(key=="startTime"){ dic->setObject(CCString::create(str->getCString()), "startTime"); } ToolController::getInstance()->m_statusItems[info.type2] = dic; }else{ auto infoDic = CCDictionary::create(); infoDic->retain(); if(key!="" && key!="startTime"){ infoDic->setObject(CCString::create(str->getCString()), "endTime"); }else if(key=="startTime"){ infoDic->setObject(CCString::create(str->getCString()), "startTime"); } ToolController::getInstance()->m_statusItems[info.type2] = infoDic; } } if (effectObj->objectForKey("status")) { auto arr = dynamic_cast<CCArray*>(effectObj->objectForKey("status")); if (arr) { CCDictionary *item = NULL; for (int i=0; i<arr->count(); i++) { item = _dict(arr->objectAtIndex(i)); auto effState = stateEffect(); effState.effectId = item->valueForKey("effNum")->intValue(); effState.value = item->valueForKey("effVal")->intValue(); effState.stateId = item->valueForKey("stateId")->intValue(); if (GlobalData::shared()->effectStateMap.find(effState.effectId) != GlobalData::shared()->effectStateMap.end()) {//去除重复的stateId vector<stateEffect>::iterator it = GlobalData::shared()->effectStateMap[effState.effectId].begin(); for (; it != GlobalData::shared()->effectStateMap[effState.effectId].end(); it++) { if (effState.stateId == it->stateId) { GlobalData::shared()->effectStateMap[effState.effectId].erase(it); break; } } } GlobalData::shared()->effectStateMap[effState.effectId].push_back(effState); } } } } }
void setRequestDialogParamsJni(jobject obj, CCDictionary *params){ JniMethodInfo t; if(params == NULL){ return; } if(JniHelper::getMethodInfo(t, "java/util/TreeMap", "<init>", "()V")){ jobject map = t.env->NewObject(t.classID, t.methodID); if(map == NULL){ CCLog("Cannot create new TreeMap objeect in %S", __func__); return; } JniMethodInfo m; if(GreeJniHelper::getInstanceMethodInfo(m, map, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")){ CCDictElement* pElement = NULL; CCDICT_FOREACH(params, pElement){ const std::string str = pElement->getStrKey(); const char *pStr = str.c_str(); jstring jStr; if(!pStr){ jStr = t.env->NewStringUTF(""); }else{ jStr = t.env->NewStringUTF(pStr); } if(!strncmp(GD_REQUEST_DIALOG_PARAM_KEY_TITLE, pStr, sizeof(GD_REQUEST_DIALOG_PARAM_KEY_TITLE)) || !strncmp(GD_REQUEST_DIALOG_PARAM_KEY_BODY, pStr, sizeof(GD_REQUEST_DIALOG_PARAM_KEY_BODY)) || !strncmp(GD_REQUEST_DIALOG_PARAM_KEY_LISTTYPE, pStr, sizeof(GD_REQUEST_DIALOG_PARAM_KEY_LISTTYPE)) || !strncmp(GD_REQUEST_DIALOG_PARAM_KEY_EXPIRETIME, pStr, sizeof(GD_REQUEST_DIALOG_PARAM_KEY_EXPIRETIME))){ // title, body, list_type, expire_time CCString *val = ((CCString *)(pElement->getObject())); if(val == NULL){ return; } const char *pVal = val->getCString(); jstring jVal; if(!pVal){ jVal = t.env->NewStringUTF(""); }else{ jVal = t.env->NewStringUTF(pVal); } m.env->CallObjectMethod(map, m.methodID, jStr, jVal); m.env->DeleteLocalRef(jVal); }else if(!strncmp(GD_REQUEST_DIALOG_PARAM_KEY_TOUSERID, pStr, sizeof(GD_REQUEST_DIALOG_PARAM_KEY_TOUSERID))){ //touserid CCArray *array = ((CCArray *)(pElement->getObject())); if(array == NULL){ return; } jclass jcl = JniHelper::getClassID("java/lang/String"); if(jcl == NULL){ return; } jobjectArray jarry = t.env->NewObjectArray(array->count(), jcl, NULL); CCObject *it; int i = 0; CCARRAY_FOREACH(array, it){ CCString *val = dynamic_cast<CCString *>(it); const char *pVal = val->getCString(); jstring jVal; if(!pVal){ jVal = t.env->NewStringUTF(""); }else{ jVal = t.env->NewStringUTF(pVal); } t.env->SetObjectArrayElement(jarry, i, jVal); t.env->DeleteLocalRef(jVal); i++; } m.env->CallObjectMethod(map, m.methodID, jStr, jarry); t.env->DeleteLocalRef(jarry); }else if(!strncmp(GD_REQUEST_DIALOG_PARAM_KEY_ATTRS, pStr, sizeof(GD_REQUEST_DIALOG_PARAM_KEY_ATTRS))){