Esempio n. 1
0
void FacebookInviteView::onSearchClick(CCObject *pSender, CCControlEvent event){
    m_selectAll = true;
    std::string sName = m_inputName->getText();
    int num = m_srcData->count();
    m_data->removeAllObjects();
    std::transform(sName.begin(),sName.end(),sName.begin(),::toupper);
    for (int i=0; i<num; i++) {
        auto dic = _dict(m_srcData->objectAtIndex(i));
        if (dic!=NULL) {
            string name = dic->valueForKey("name")->getCString();
            std::transform(name.begin(),name.end(),name.begin(),::toupper);
            if (name.find(sName) < name.length() && m_data->count()<50) {
                dic->setObject(CCString::create("1"), "flag");
                m_data->addObject(dic);
            }
        }
    }
    refreshData(0.0);
}
Esempio n. 2
0
void GameBackgroundView::playerHpBy(float percentageChange) {	// 进度变化值
	// 
	if (SpriteManager::getSpriteManager()->playerSprite->Attack_O_FPS_ == 0)
	{
		if (SpriteManager::getSpriteManager()->playerSprite->OX == false)
		{
			stopTimeS->setTexture("st.png");
			SpriteManager::getSpriteManager()->playerSprite->OX = true;
		}
	}
	else {
		if (SpriteManager::getSpriteManager()->playerSprite->OX == true) {
			stopTimeS->setTexture("st2.png");
			SpriteManager::getSpriteManager()->playerSprite->OX = false;
		}
	}


	// HP
	float hp_Change = SpriteManager::getSpriteManager()->playerSprite->HP_Change;
	if (hp_Change != 0.0f)
	{
		float hp = SpriteManager::getSpriteManager()->playerSprite->HP;
		float maxHp = SpriteManager::getSpriteManager()->playerSprite->MAXHP;
		if (hp_Change >= maxHp)
		{
			// 超过生命值上限
			hp_Change = maxHp;
		}
		else if (hp_Change <= 0)
		{
			// 死亡
			hp_Change = 0.0f;
			// 改变信息栏数据
			// 调用角色死亡方法
			auto prTo = ProgressFromTo::create(0.0f, hp / maxHp * 100, 0);
			loadBar->runAction(prTo);
			// 释放所有弹幕池
			SpriteManager::removeBarrage();

			map<string, ccMenuCallback> map;
			//auto dic = Dictionary::createWithContentsOfFile("qiandai.xml");
			auto dic2 = Dictionary::createWithContentsOfFile("Text_CN2.xml");
			map.insert(pair<string, ccMenuCallback>(
				dic2->valueForKey("chongxin")->getCString(), CC_CALLBACK_1(GameBackgroundView::chongxin, this)));
			map.insert(pair<string, ccMenuCallback>(
				dic2->valueForKey("fanhui")->getCString(), CC_CALLBACK_1(GameBackgroundView::fanhui, this)));
			GameMessage2::newGameMessage(this, ((String *)dic2->objectForKey("title"))->getCString(),
				((String *)dic2->objectForKey("message"))->getCString(),
				map,
				"duihuakuang.png"
				);
		}
		float toPercentage = hp_Change / maxHp * 100;
		// 血量变化时头像的变化
		int nIn = (int)toPercentage / 10;
		nIn = ((nIn == 0) && toPercentage != 0) ? 1 : nIn;
		playerHeadPortrait->setTexture(SpriteManager::getSpriteManager()->playerSprite->HeadImage[nIn]);
		// 执行动作
		auto prTo = ProgressFromTo::create(0.0f, hp / maxHp * 100, toPercentage);
		loadBar->runAction(prTo);
		SpriteManager::getSpriteManager()->playerSprite->HP = hp_Change;
		SpriteManager::getSpriteManager()->playerSprite->HP_Change = 0.0f;
		// 更新标签值
		auto st = String::createWithFormat("%.0f", hp_Change);
		rwHP->setString(st->getCString());
	}
}
uint32_t WebPreferencesStore::getUInt32ValueForKey(const String& key) const
{
    return valueForKey(m_uint32Values, key);
}
String WebPreferencesStore::getStringValueForKey(const String& key) const
{
    return valueForKey(m_stringValues, key);
}
Esempio n. 5
0
void AllianceInfo::updateAllianceInfo(CCDictionary* dict){
    if(dict==NULL) return;
    if(createTime==0){
         createTime = GlobalData::shared()->getTimeStamp();
    }
    if(dict==NULL) return ;
    if(dict->objectForKey("alliancename")){
        name = dict->valueForKey("alliancename")->getCString();
    }
    if(dict->objectForKey("fightpower")){
        fightpower = (long)dict->valueForKey("fightpower")->doubleValue();
    }
    if(dict->objectForKey("giftexp1")){
        giftexp1 = dict->valueForKey("giftexp1")->intValue();
    }
    if(dict->objectForKey("giftexp2")){
        giftexp2 = dict->valueForKey("giftexp2")->intValue();
    }
    if(dict->objectForKey("giftexp3")){
        giftexp3 = dict->valueForKey("giftexp3")->intValue();
    }
    if(dict->objectForKey("giftexp4")){
        giftexp4 = dict->valueForKey("giftexp4")->intValue();
    }
    if(dict->objectForKey("giftexp5")){
        giftexp5 = dict->valueForKey("giftexp5")->intValue();
    }
    if(dict->objectForKey("giftexp6")){
        giftexp6 = dict->valueForKey("giftexp6")->intValue();
    }
    if(dict->objectForKey("uid")){
        uid = dict->valueForKey("uid")->getCString();
    }
    if(dict->objectForKey("abbr")){
        shortName = dict->valueForKey("abbr")->getCString();
    }
    if(dict->objectForKey("language")){
        language = dict->valueForKey("language")->getCString();
    }
    if(dict->objectForKey("curMember")){
        currentNum = dict->valueForKey("curMember")->intValue();
    }
    if(dict->objectForKey("icon")){
        icon = dict->valueForKey("icon")->getCString();
    }
    if(dict->objectForKey("applied")){
        isApplied = dict->valueForKey("applied")->intValue();
    }
    if(dict->objectForKey("learderName")){
        leader = dict->valueForKey("learderName")->getCString();
    }
    if(dict->objectForKey("learderUid")){
        leaderUid = dict->valueForKey("learderUid")->getCString();
    }
    if(dict->objectForKey("country")){
        country = dict->valueForKey("country")->getCString();
    }
    if(dict->objectForKey("recruit")){
        recruit = dict->valueForKey("recruit")->intValue();
    }
    
    rallyPoint = 0;
    if(dict->objectForKey("rallyPoint")){
        rallyPoint = dict->valueForKey("rallyPoint")->intValue();
    }
    if(dict->objectForKey("leaderPoint")){
        leaderPoint = dict->valueForKey("leaderPoint")->intValue();
    }
    
    if(dict->objectForKey("rank")){
        rank = dict->valueForKey("rank")->intValue();
    }
    
    if(dict->objectForKey("giftlevel")){
        giftlevel = dict->valueForKey("giftlevel")->intValue();
    }
    if(dict->objectForKey("giftlevel")){
        currentGiftExp = dict->valueForKey("giftlevel")->intValue();
    }
    if(dict->objectForKey("currentlevel")){
        currentGiftLevel = dict->valueForKey("currentlevel")->intValue();
    }
    if(dict->objectForKey("nextlevel")){
        giftNextExp = dict->valueForKey("nextlevel")->intValue();
    }
    if(dict->objectForKey("intro")){
        intro = dict->valueForKey("intro")->getCString();
    }
    if(dict->objectForKey("point")){
        point = dict->valueForKey("point")->intValue();
    }
    if(dict->objectForKey("accPoint")){
        accPoint = dict->valueForKey("accPoint")->intValue();
    }
    if(dict->objectForKey("donateAvailable")){
        donateAvailable = dict->valueForKey("donateAvailable")->intValue();
    }
    if(dict->objectForKey("donateCDTime")){
        int tmpT = dict->valueForKey("donateCDTime")->doubleValue()/1000;
        if (tmpT>0) {
            donateCDTime = GlobalData::shared()->changeTime(tmpT);
        }
        else {
            donateCDTime = 0;
        }
    }
    if(dict->objectForKey("jointime")){
        int tmpT = dict->valueForKey("jointime")->doubleValue()/1000;
        if (tmpT>0) {
            joinTime = GlobalData::shared()->changeTime(tmpT);
        }
        else {
            joinTime = 0;
        }
    }
    if(dict->objectForKey("alliancepoint")){
        alliancepoint = dict->valueForKey("alliancepoint")->intValue();
    }
    if(dict->objectForKey("announce")){
        announce = dict->valueForKey("announce")->getCString();
    }
    if(dict->objectForKey("fightpower")){
        totalForce = (unsigned long)dict->valueForKey("fightpower")->doubleValue();
    }
    if(dict->objectForKey("maxMember")){
        maxNum = dict->valueForKey("maxMember")->intValue();
    }
    if(dict->objectForKey("abbrRename")){
        abbrRename = dict->valueForKey("abbrRename")->intValue();
    }
    if(dict->objectForKey("helpcount")){
        helpcount = dict->valueForKey("helpcount")->intValue();
    }
    if(dict->objectForKey("reicon")){
        reicon = dict->valueForKey("reicon")->intValue();
    }
    if(dict->objectForKey("rankone")){
        strRank1 = dict->valueForKey("rankone")->getCString();
    }
    if(dict->objectForKey("ranktwo")){
        strRank2 = dict->valueForKey("ranktwo")->getCString();
    }
    if(dict->objectForKey("rankthree")){
        strRank3 = dict->valueForKey("rankthree")->getCString();
    }
    if(dict->objectForKey("rankfour")){
        strRank4 = dict->valueForKey("rankfour")->getCString();
    }
    if(dict->objectForKey("rankfive")){
        strRank5 = dict->valueForKey("rankfive")->getCString();
    }
    if(dict->objectForKey("territory")) {
        CCArray* tNameArr = dynamic_cast<CCArray*>(dict->objectForKey("territory"));
        if (tNameArr) {
            int num = tNameArr->count();
            for (int i = 0; i<num; i++) {
                auto dic = _dict(tNameArr->objectAtIndex(i));
                if (dic->objectForKey("uid")) {
                    std::string tuid = dic->valueForKey("uid")->getCString();
                    std::string tname = dic->valueForKey("name")->getCString();
                    int index = dic->valueForKey("count")->intValue();
                    if (tname == "") {
                        tname = _lang_1("115312", CC_ITOA(index));
                    }
                    territoryNameMap[index] = make_pair(tuid, tname);
                }
            }
        }
    }
    if(dict->objectForKey("militaryNum")){
        militaryNum = dict->valueForKey("militaryNum")->intValue();
    }
    if(dict->objectForKey("applyCount")){
        applyNum = dict->valueForKey("applyCount")->intValue();
    }
    if(dict->objectForKey("allianceScience") && uid == GlobalData::shared()->playerInfo.allianceInfo.uid){
        CCArray* arr = dynamic_cast<CCArray*>(dict->objectForKey("allianceScience"));
        ScienceController::getInstance()->initAllianceScienceData(arr);
    }
    if (dict->objectForKey("serverId")) {
        serverId = dict->valueForKey("serverId")->intValue();
    }
    if (dict->objectForKey("powerRestriction")) {
        powerRestriction = dict->valueForKey("powerRestriction")->intValue();
    }
    if (dict->objectForKey("castleRestriction")) {
        castleRestriction = dict->valueForKey("castleRestriction")->intValue();
    }
    if (dict->objectForKey("permission")) {
        CCDictionary * configDic = _dict(dict->objectForKey("permission"));
        AllianceManager::getInstance()->initRankStateInfo(configDic);
    }
    
}
Esempio n. 6
0
int64_t BencodeObject::intValueForKey(const char* key, int64_t def) {
	BencodeObject* obj = valueForKey(key);

	return (obj ? obj->intValue(def) : def);
}
Esempio n. 7
0
const void* BencodeObject::byteStringValueForKey(const char* key, size_t* len) {
	BencodeObject* obj = valueForKey(key);

	return (obj ? obj->byteStringValue(len) : NULL);
}
Esempio n. 8
0
//-----------------------------------------------------------------
//
//
void CCXMLLayer::LoadPlist( const char *pList )
{
	string strPath = GetGameLevelPath();
	strPath = strPath + pList;

	std::string fullpath(CCFileUtils::fullPathFromRelativePath(strPath.c_str())); 
    
	CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(fullpath.c_str());

	CCDictionary<std::string, CCObject*> *imagesDict = (CCDictionary<std::string, CCObject*>*)dict->objectForKey(std::string("images"));

	m_vNodeObject.clear();

	imagesDict->begin();
	std::string key = "";
	CCDictionary<std::string, CCObject*> *imageDict = NULL;
	while( (imageDict = (CCDictionary<std::string, CCObject*>*)imagesDict->next(&key)) )
	{
		float x = (float)atof(valueForKey("x", imageDict));
		float y = (float)atof(valueForKey("y", imageDict));
		float w = (float)atof(valueForKey("width", imageDict));
		float h = (float)atof(valueForKey("height", imageDict));
//        #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
//        if( CCDirector::sharedDirector()->getWinSize().width == 1024 || 2 == CC_CONTENT_SCALE_FACTOR() )
//        {
//            
//        }
//        else
//        {
//            x = x / 2;
//            y = y / 2;
//            w = w / 2;
//            h = h / 2;
//        }
//        #endif    
        
		float layer = (float)atof(valueForKey("layer", imageDict));
		bool flipX = (bool)atoi(valueForKey("FlipX", imageDict));
		bool flipY = (bool)atoi(valueForKey("FlipY", imageDict));
		TurnitorqueWorldToCoco2d( x, y, layer );

		if( strstr( key.c_str(), "t2dSceneObject_") )
		{
			CCNode *pNode = CCNode::node();
			//pNode->setPositionInPixels( ccp( x, y ) );
			pNode->setPosition( ccp( x / CC_CONTENT_SCALE_FACTOR(), y / CC_CONTENT_SCALE_FACTOR() ) );
			CCSize size( w / CC_CONTENT_SCALE_FACTOR(), h / CC_CONTENT_SCALE_FACTOR() );
			pNode->setContentSize( size );
			
			string *pNameKey = new string( key );
			pNode->setUserData( pNameKey );

			addChild( pNode, (int)layer );
			m_vNodeObject.push_back( pNode );
		}
		else if( strstr( key.c_str(), "t2dAnimatedSprite_") )
		{
			AdvanceSprite *m_pAnimation = new AdvanceSprite();
			
			string plist = (valueForKey("plist", imageDict));
			m_pAnimation->addFramesFromiT2D( plist.c_str() );
            m_pAnimation->autorelease();
			//m_pAnimation->setPositionInPixels( ccp( x, y ) );
			m_pAnimation->setPosition( ccp( x / CC_CONTENT_SCALE_FACTOR(), y / CC_CONTENT_SCALE_FACTOR() ) );
			m_pAnimation->setScaleX( ( w / CC_CONTENT_SCALE_FACTOR() ) / m_pAnimation->getContentSize().width );
			m_pAnimation->setScaleY( ( h / CC_CONTENT_SCALE_FACTOR() ) / m_pAnimation->getContentSize().height );
			m_pAnimation->setFlipX( flipX );
			m_pAnimation->setFlipY( flipY );
		    string *pNameKey = new string( key );
			m_pAnimation->setUserData( pNameKey );
			

			int startFrameIndex = (int)atoi(valueForKey("startframe", imageDict));
			int endFrameIndex   = (int)atoi(valueForKey("endframe", imageDict));
			float time = (float)atof(valueForKey("animationtime", imageDict));

			m_pAnimation->startAnimation( startFrameIndex, endFrameIndex, -1, NULL, this, (float)( ( endFrameIndex - startFrameIndex + 1 ) / time ), false, false  );
			addChild( m_pAnimation, (int)layer );

			m_vNodeObject.push_back( m_pAnimation );
		}
		else
		{
			const char *image = valueForKey("image", imageDict);

			string ImagePath = GetGameImagesPath();
			ImagePath = ImagePath + image;

			CCSprite *pSprite = CCSprite::spriteWithFile( ImagePath.c_str() );
			//pSprite->setPositionInPixels( ccp( x, y ) );
			pSprite->setPosition( ccp( x / CC_CONTENT_SCALE_FACTOR(), y / CC_CONTENT_SCALE_FACTOR() ) );
			pSprite->setScaleX( ( w / CC_CONTENT_SCALE_FACTOR() ) / pSprite->getTextureRect().size.width );
			pSprite->setScaleY( ( h / CC_CONTENT_SCALE_FACTOR() ) / pSprite->getTextureRect().size.height );
			pSprite->setFlipX( flipX );
			pSprite->setFlipY( flipY );
		    string *pNameKey = new string( key );
			pSprite->setUserData( pNameKey );
			addChild( pSprite, (int)layer );

			m_vNodeObject.push_back( pSprite );
		}
	}
}
void wyAngelCodeTXTFontLoader::load(wyBitmapFont* font, const char* data, size_t length, float resScale) {
	char line[256];
	char value[32];
	char* buf = (char*)data;
	while(length > 0) {
		// read one line
		int readLen = wyUtils::readLine(&buf, line);
		length -= readLen;

		// check start token
		if(wyUtils::startsWith(line, "common")) {
			valueForKey(line, "lineHeight", value);
			float height = atof(value) * resScale;
			font->setLineHeight(height);
		} else if(wyUtils::startsWith(line, "page")) {
			valueForKey(line, "file", value);

			// cut extension
			char* dot = strrchr(value, '.');
			if(dot != NULL)
				*dot = 0;

		    // create texture
		    const char* path = font->getPath();
		    if(path) {
		        char* fullPngPath = (char*) wyMalloc((strlen(path) + strlen(value) + 4) * sizeof(char));
		        if(fullPngPath) {
		        	// cut fnt file name
		            memcpy(fullPngPath, path, (strlen(path) + 1) * sizeof(char));
		            char* lastSolidus = fullPngPath;
		            char* temp = fullPngPath;
		            while(temp != NULL) {
		                temp = strstr(temp, "/");
		                if(temp) {
		                    lastSolidus = ++temp;
		                }
		            }

		            // append png file name
		            sprintf(lastSolidus, "%s.png", value);
		            if(font->isFile()) {
		            	font->addTexture(wyTexture2D::makeFile(fullPngPath,
		            			0,
		            			wyTextureManager::getInstance()->getTexturePixelFormat(),
		            			wyDevice::density / resScale));
		            } else {
		            	font->addTexture(wyTexture2D::make(fullPngPath,
		            			0,
		            			wyTextureManager::getInstance()->getTexturePixelFormat(),
		            			wyDevice::density / resScale));
		            }
		            wyFree(fullPngPath);
		        }
		    } else {
		    	font->addTexture(wyTexture2D::make(wyUtils::getResId(value, "drawable", NULL)));
		    }
		} else if(wyUtils::startsWith(line, "char")) {
			// create char info
			wyCharInfo* ci = WYNEW wyCharInfo();

			// x
			valueForKey(line, "x", value);
			ci->texRect.x = atof(value) * resScale;

			// y
			valueForKey(line, "y", value);
			ci->texRect.y = atof(value) * resScale;

			// width
			valueForKey(line, "width", value);
			ci->texRect.width = atof(value) * resScale;

			// height
			valueForKey(line, "height", value);
			ci->texRect.height = atof(value) * resScale;

			// xoffset map to left
			valueForKey(line, "xoffset", value);
			ci->left = atof(value) * resScale;

			// yoffset map to top
			valueForKey(line, "yoffset", value);
			ci->top = atof(value) * resScale;

			// xadvance - xoffset - width ==> right
			valueForKey(line, "xadvance", value);
			ci->right = atof(value) * resScale - ci->texRect.width - ci->left;

			// page
			valueForKey(line, "page", value);
			ci->page = atoi(value);

			// id is unicode, transform it to utf-8
			valueForKey(line, "id", value);
			char32_t c = atoi(value);
			if(c != ' ') {
				c = wyUtils::utf32toutf8(c);
				ci->word = c;
			}

			// add char info
			if(ci->word == 0)
				wyFree(ci);
			else
				font->addCharInfo(ci);
		}
	}
}
Esempio n. 10
0
float WebPreferencesStore::getFloatValueForKey(const String& key) const
{
    return valueForKey(m_floatValues, key);
}
Esempio n. 11
0
const char* GxxDictionary::stringValueForKey( const char* key )
{
	return valueForKey(key)->stringValue();
}
Esempio n. 12
0
bool UserUpgradeView::init()
{
    if (!PopupBaseView::init()) {
        return false;
    }
    setIsHDPanel(true);
//    m_cellArr = CCArray::create();
//    m_cellArr->retain();
    CCLoadSprite::doResourceByCommonIndex(505, true);
    CCLoadSprite::doResourceByCommonIndex(11, true);
    setCleanFunction([](){
        CCLoadSprite::doResourceByCommonIndex(505, false);
        CCLoadSprite::doResourceByCommonIndex(11, false);
    });
    auto tmpCCB = CCBLoadFile("NewUserUpgradeView",this,this);
    CCSize size=CCDirector::sharedDirector()->getWinSize();
    setContentSize(size);
    this->setModelLayerTouchCallback([&](cocos2d::CCTouch *pTouch){
        // detect touch inside panel
        if (isTouchInside(this, pTouch)) {
            this->onRewardBtnClick(NULL, Control::EventType::TOUCH_DOWN);
        }
    });
    vector_node.clear();
    vector_node.push_back(m_node1);
    vector_node.push_back(m_node2);
    vector_node.push_back(m_node3);
    vector_node.push_back(m_node4);
    vector_node.push_back(m_node5);
    vector_node.push_back(m_node6);
    vector_num.clear();
    vector_num.push_back(m_num1);
    vector_num.push_back(m_num2);
    vector_num.push_back(m_num3);
    vector_num.push_back(m_num4);
    vector_num.push_back(m_num5);
    vector_num.push_back(m_num6);
    vector_name.clear();
    vector_name.push_back(m_name1);
    vector_name.push_back(m_name2);
    vector_name.push_back(m_name3);
    vector_name.push_back(m_name4);
    vector_name.push_back(m_name5);
    vector_name.push_back(m_name6);
    vector_picNode.clear();
    vector_picNode.push_back(m_picNode1);
    vector_picNode.push_back(m_picNode2);
    vector_picNode.push_back(m_picNode3);
    vector_picNode.push_back(m_picNode4);
    vector_picNode.push_back(m_picNode5);
    vector_picNode.push_back(m_picNode6);
//    m_hatAnimNode->setPositionY(m_hatAnimNode->getPositionY()+40);
    m_titleLabel->setString(_lang("113184"));
    m_titleLabel->setColor({67,39,7});
    int userLv = GlobalData::shared()->lordInfo.levelUp+1;
    string lvInfo = CC_ITOA(userLv);
    if(userLv>=GlobalData::shared()->MaxPlayerLv) {
//        lvInfo += _lang("102183");
    }
    m_lvLabel->setString(lvInfo.c_str());
    
    int lastEndowment = 0;
    int lastPower = 0;
    
    int key = 100100 + userLv-1;
    auto dict = LocalController::shared()->DBXMLManager()->getObjectByKey(CC_ITOA(key));
    int curEndowment = dict->valueForKey("endowment")->intValue();
    int curPower = dict->valueForKey("power")->intValue();
    if (userLv>2) {
        int lastkey = 100100 + (userLv-2);
        auto lastdict = LocalController::shared()->DBXMLManager()->getObjectByKey(CC_ITOA(lastkey));
        lastEndowment = lastdict->valueForKey("endowment")->intValue();
        lastPower = lastdict->valueForKey("power")->intValue();
    }
    
    m_powLabel->setFntFile("Arial_Bold_Regular.fnt");
    m_powNumLabel->setFntFile("Arial_Bold_Regular.fnt");
    m_skillLabel->setFntFile("Arial_Bold_Regular.fnt");
    m_skillNumLabel->setFntFile("Arial_Bold_Regular.fnt");
    m_powLabel->setString(_lang("105034"));
    string powerInfo = "";
    powerInfo.append(" +");
    powerInfo.append(CC_ITOA(curPower-lastPower));
    m_powNumLabel->setString(powerInfo);
    
    m_skillLabel->setString(_lang("105035"));
    string skillInfo = "";
    skillInfo.append(" +");
    skillInfo.append(CC_ITOA(curEndowment-lastEndowment));
    m_skillNumLabel->setString(skillInfo);
    
    float px=m_skillLabel->getPositionX() + m_skillLabel->getContentSize().width+20;
    
    //get reward item
    m_fbTxt->setString(_lang("107098").c_str());
    string item =  dict->valueForKey("level_item")->getCString();   CCLOG("///i///%s",item.c_str());
    int offY = 150;
    if(item==""){
        return true;
    }
    CCCommonUtils::splitString(item, "|", vector_item);             CCLOG("///n///%s",vector_item[0].c_str());
    item =  dict->valueForKey("level_num")->getCString();          CCLOG("///n///%s",item.c_str());
    CCCommonUtils::splitString(item, "|", vector_number);
    
//    m_tabView = CCMultiColTableView::create(this, m_rewardlist->getContentSize());
//    m_tabView->setDirection(kCCScrollViewDirectionVertical);
//    m_tabView->setVerticalFillOrder(kCCTableViewFillTopDown);
//    m_tabView->setMultiColTableViewDelegate(this);
//    m_tabView->setTouchPriority(Touch_Default);
//    m_rewardlist->addChild(m_tabView);
//    m_tabView->setTouchEnabled(false);
//    m_tabView->reloadData();
    
    std:: map<string, CCDictionary*>::iterator it = GlobalData::shared()->shareFbmap.find("level_up");
    bool flag = false;
    if (it!=GlobalData::shared()->shareFbmap.end()) {
        CCDictionary* dict = it->second;
        if (dict) {
            int on = dict->valueForKey("ON")->intValue();
            if (on==1) {
                flag = true;
            }
        }
    }
    if(GlobalData::shared()->analyticID == "cn1" || GlobalData::shared()->analyticID.find("cn_")<GlobalData::shared()->analyticID.length()){//平台是国内的,不显示facebook 的share btn 按钮
        flag = false;
    }
    if(GlobalData::shared()->playerInfo.level>3 && flag){
//        m_likeNode->setPositionY(m_likeNode->getPositionY() - offY);
        m_likeNode->setVisible(true);
    }
    m_waitInterFace = NULL;
    if(GlobalData::shared()->playerInfo.level==6){
        CCPoint locPos = ccp(40, 70);
//        CCPoint pos = m_buildBG->convertToWorldSpace(locPos);
//        int len = (1-(pos.y/CCDirector::sharedDirector()->getWinSize().height))*100;
        GlobalData::shared()->isBind = true;
//#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
//        //pos = CCDirector::sharedDirector()->convertToUI(pos);
//        pos.y = len;
//        FBUtilies::fbLike(pos);
//#else
//        string localCus = CCUserDefault::sharedUserDefault()->getStringForKey(FB_USERID,"");
//        pos = ccp(pos.x, pos.y + 18);
//        FBUtilies::fbLike(pos);
//#endif
    }
    
    refreshView();
    return true;
}
Esempio n. 13
0
void MailInfo::parse(cocos2d::CCDictionary *dic){
    isThanks=false;
    saveDict=NULL;
    isShare=false;
    contents = "";
    detecterName = "";
    ckfContents = "";
    pic = "";
    allianceLang = "";
    msReport = 0;
    picVer = 0;
    ckf = 0;
    serverType = 0;
    mbLevel = 0;
    isWorldBossKillRewardMail = false;
    if(dic->objectForKey("pic")){
        pic = dic->valueForKey("pic")->getCString();
    }
    
    if (dic->objectForKey("picVer"))
    {
        picVer = dic->valueForKey("picVer")->intValue();
    }
    type = dic->valueForKey("type")->intValue();
    //define tabType
    if(type==MAIL_BATTLE_REPORT||type==MAIL_DETECT||type==MAIL_DETECT_REPORT||type==MAIL_ENCAMP||type==MAIL_WORLD_BOSS){
        tabType = 4;
    }else if(type==ALL_SERVICE){
        tabType = 3;
    }else if(type== MAIL_FRESHER||type==MAIL_SYSNOTICE||type==MAIL_SYSUPDATE){
        tabType = 2;
        
    }else if(type <=MAIL_USER||type==MAIL_Alliance_ALL||type==CHAT_ROOM){
        tabType = 0;
    }else if(type == MAIL_MOD_SEND || type == MAIL_MOD_PERSONAL){
        if(GlobalData::shared()->playerInfo.gmFlag == 2 || GlobalData::shared()->playerInfo.gmFlag == 5){
            tabType = 5;
        }else{
            tabType = 0;
        }
    }else{
        tabType = 1;
    }
    if(dic->objectForKey("uid"))
        uid = dic->valueForKey("uid")->getCString();
    else
        uid="";
    createTime =  dic->valueForKey("createTime")->doubleValue() / 1000;
    CCLOGFUNCF("createTime: %ld",createTime);
    if(dic->objectForKey("mbLevel"))
    {
        mbLevel=dic->valueForKey("mbLevel")->intValue();
    }
    rewardId = dic->valueForKey("rewardId")->getCString();
    int status1 = dic->valueForKey("status")->intValue();
    if(status1>0){
        if(status1==2){
            isThanks=true;
        }
        status = READ;
    }else{
        status = UNREAD;
    }
    fromName = dic->valueForKey("oldName")->getCString();
    nowName = dic->valueForKey("fromName")->getCString();
    modLanguage = dic->valueForKey("modLanguage")->getCString();
    if(fromName.empty() && !nowName.empty()){
        fromName = nowName;
    }
    if(dic->objectForKey("fromUid")){
        fromUid = dic->valueForKey("fromUid")->getCString();
    }
    else if(dic->objectForKey("fromUser"))
    {
        fromUid = dic->valueForKey("fromUser")->getCString();
    }
    else{
        fromUid = "";
    }
    if(dic->objectForKey("share")){
        isShare = dic->valueForKey("share")->boolValue();
    }
    if (dic->objectForKey("donate")) {
        goToDonate = dic->valueForKey("donate")->intValue();
    }
    reply = dic->valueForKey("reply")->intValue();
    alliance = dic->valueForKey("alliance")->getCString();
    version = dic->valueForKey("version")->getCString();
    rewardStatus = dic->valueForKey("rewardStatus")->intValue();
    battleType = dic->valueForKey("battleType")->intValue();
    title = dic->valueForKey("title")->getCString();
    itemIdFlag = dic->valueForKey("itemIdFlag")->intValue();
    unreadDialogNum = dic->valueForKey("unread")->intValue();
    dialogNum = dic->valueForKey("totalNum")->intValue();
    userKill = dic->valueForKey("userKill")->intValue();
    allKill = dic->valueForKey("allKill")->intValue();
    msReport = dic->valueForKey("msReport")->intValue();
    failTimes = dic->valueForKey("failTimes")->intValue();
    winPercent = dic->valueForKey("winPercent")->intValue();
    killRound = dic->valueForKey("killRound")->intValue();
    userScore = dic->valueForKey("userScore")->intValue();
    monsterLevel = dic->valueForKey("monsterLevel")->intValue();
    like = dic->valueForKey("like")->intValue();
    if(dic->objectForKey("serverType")){
        serverType = dic->valueForKey("serverType")->intValue();
    }
    if(dic->objectForKey("contents")){
        showContent = dic->valueForKey("contents")->getCString();
    }
    if(type <= MAIL_USER || type == MAIL_MOD_SEND || type == MAIL_MOD_PERSONAL || type == CHAT_ROOM){
        
    }else if(type == MAIL_RESOURCE_HELP){
        fromName = _lang("114121");
    }else if(type == MAIL_RESOURCE){
        fromName = _lang("105516");
        if(title == ""){
            title = "1,1";
        }
        vector<std::string> vector;
        CCCommonUtils::splitString(title, ",", vector);
        int level = 0;
        int type = 0;
        if(vector.size()>=2){
            level = atoi(vector[0].c_str());
            type = atoi(vector[1].c_str());
        }
        title = string("Lv.") + CC_ITOA(level) + " " + CCCommonUtils::getResourceProductByType(type);
        showContent = _lang_1("105517", title.c_str());
    }else if(type == MAIL_DETECT){
        if(itemIdFlag == 1){
            std::string contentId = dic->valueForKey("contents")->getCString();
            if(!contentId.empty() && contentId.length()>6){
                contentId = contentId.substr(6);
                if(contentId=="105554"){
                    fromName = _lang("105523");
                    title = showContent;
                }
            }
        }else{
            std::string contentId = dic->valueForKey("contents")->getCString();
    //        if(contentId=="105554"){
    //            fromName = _lang("105523");
    //            title = _lang("105554");
    //        }else{
    //            fromName = _lang("105522");
           // }
            fromName = _lang("105522");
            if(title.compare("1") == 0){
                title = _lang("105523");
            }else{
                title = _lang("105567");
            }
        }
    }
    else if(type == MAIL_DETECT_REPORT){
        std::string contentId = dic->valueForKey("contents")->getCString();
        if(contentId.compare("114005") == 0){
            pointType = MAIL_DETECT_REPORT_PROTECT;
            fromName = _lang("105522");
            title = _lang("114102");
            showContent = _lang("114005");
        }else{
            fromName = _lang("105522");
            //title = _lang("105523");
            showContent = "";
            switch (pointType) {
                case Throne:{ //王座
                    showContent = _lang("105708");
                    break;
                }
                case Trebuchet:{//投石机
                    showContent = _lang("105709");
                    break;
                }
                default:{
                    showContent = _lang("105527");
                    break;
                }
            }
        }
    }else if(type == MAIL_ENCAMP){
        fromName = _lang("105536");
        switch (pointType) {
            case Throne:{
                title = _lang("105710");
                break;
            }
            case Trebuchet:{
                title = _lang("105711");
                break;
            }
            default:{
                if(this->isTreasureMap){
                    fromName = _lang("111504");
                    title = _lang("111504");
                }else{
                    title = _lang("105537");
                }
                break;
            }
        }
    }else if(type == MAIL_WOUNDED){
        fromName = _lang("105305");
        title = _lang("105550");
    }else if(type == MAIL_BATTLE_REPORT){
        if(dic->objectForKey("contents")){
            auto tempDic = _dict(dic->objectForKey("contents"));
            if(tempDic!=NULL){
                int pos = tempDic->valueForKey("warPoint")->intValue();
                CCPoint pt = WorldController::getPointByIndex(pos);
                if (serverType>=SERVER_BATTLE_FIELD) {
                    pt = WorldController::getPointByMapTypeAndIndex(pos,(MapType)serverType);
                }
                //fromName = _lang_2("105518",CC_ITOA(pt.x),CC_ITOA(pt.y));
                std::string npcId = "";
                if( tempDic->objectForKey("npcId"))
                    npcId= tempDic->valueForKey("npcId")->getCString();
                std::string defName ="";
                if(npcId!=""){
                    defName = CCCommonUtils::getNameById(tempDic->valueForKey("npcId")->getCString());
                }else{
                    if (tempDic->objectForKey("defName")) {
                        defName = tempDic->valueForKey("defName")->getCString();
                    }
                }
                std::string attName = tempDic->valueForKey("atkName")->getCString();
                
                if(GlobalData::shared()->playerInfo.name==attName){
                    title = _lang_2("105547",_lang("102187").c_str(),defName.c_str());
                }else{
                    title = _lang_2("105547",attName.c_str(),_lang("108678").c_str());
                }
                
                int win = tempDic->valueForKey("win")->intValue();
                std::string result = "";
                if(win==0){
                    result = _lang("105117");
                }else if(win==1){
                    result = _lang("105118");
                }else{
                    result = _lang("105549");
                }
                showContent = _lang_1("105548", result.c_str());
                fromName = result;
            }
        }
    }else if(type == MAIL_DIGONG || type == WORLD_NEW_EXPLORE){
        title = _lang("108675");
    }else if(type == MAIL_ATTACKMONSTER){
        fromName = _lang("103715");
    }else if(type==MAIL_Alliance_ALL || type == MAIL_GIFT){
    
    }else if(type == MAIL_DONATE){
        fromName = _lang("105305");
        std::string contentId = dic->valueForKey("contents")->getCString();
        vector<string> mVStr;
        CCCommonUtils::splitString(contentId, "|", mVStr);
        if(mVStr.size()>4){
            std::string userName = mVStr.at(1);
            if (!mVStr.at(2).empty()) {
                userName = "******" + mVStr.at(2) +")" + userName;
            }
            title = _lang_1("101007",userName.c_str());
            contents = _lang_3(mVStr.at(0), userName.c_str(), mVStr.at(3).c_str(), mVStr.at(4).c_str());
            showContent = contents;
        }
        itemIdFlag = 0;
    }else{
        fromName = _lang("105305");
    }
    
    prepareToDelete = false;
    save = dic->valueForKey("save")->intValue();
    isRead = false;
    if(itemIdFlag == 1){
        //杀死世界boss领奖邮件
        if (title=="137460") {
            type=MAIL_WORLD_BOSS;
            isWorldBossKillRewardMail = true;
        }
        title = _lang(title);
        
        string fromdl = dic->valueForKey("fromName")->getCString();
        if(fromdl != ""){
            string fromNL = _lang(fromdl);
            if(fromNL!=""){
                fromName = fromNL;
            }
        }
        if(showContent != ""){
            showContent = _lang(showContent);
        }
    }
    if(type == MAIL_FRESHER){
        fromName = _lang("3000001");
    }
//    std::string contentId = dic->valueForKey("contents")->getCString();
//    if(contentId=="114005"){
//        fromName = _lang("114102");
//        title = _lang("114005");
//    }else if(contentId!=""&&contentId.length()>6){
//        contentId = contentId.substr(6);
//        if(contentId=="105554"){
//            fromName = _lang("105523");
//            title = showContent;
//        }
//    }
    if(tabType==0 || type == MAIL_MOD_PERSONAL || type == MAIL_MOD_SEND || type==CHAT_ROOM){
        if(dialogs==NULL)
        {
            dialogs=CCArray::create();
            dialogs->retain();
        }
        contents = showContent;
        title = contents;
        if(dic->objectForKey("chats")){
            CCArray *arr = dynamic_cast<CCArray*>(dic->objectForKey("chats"));
            CCObject* obj;
            int count = arr->count();
            int i = 0;
            CCARRAY_FOREACH(arr, obj){
                CCDictionary* dictDialog = dynamic_cast<CCDictionary*>(obj);
                MailDialogInfo* dialogInfo = MailDialogInfo::create();
                dialogInfo->parse(dictDialog);
                this->dialogs->addObject(dialogInfo);
                if(i==count-1){
                    title = dialogInfo->contents;
                }
                i++;
            }
        }
Esempio n. 14
0
void ActivityTipView::initReward(){
    if(m_info->getReward()==NULL || m_info->getReward()->count()<=0) return ;
    
    
    int TOOL_BG[] = {PURPLE, ORANGE, BLUE, BLUE};
    
    string name = "";
    string icon = "";
    CCDictionary* reward = NULL;
    if(m_info->getReward()->count()>0){
        reward = dynamic_cast<CCDictionary*>(m_info->getReward()->objectAtIndex(0));
        if(reward){
            int type = reward->valueForKey("type")->intValue();
            int value = reward->valueForKey("value")->intValue();
            if(type==R_GOODS){
                auto valueObj = _dict(reward->objectForKey("value"));
                int id = valueObj->valueForKey("id")->intValue();
                name = RewardController::getInstance()->getNameByType(type,id);
                icon = RewardController::getInstance()->getPicByType(type,id);
                value = valueObj->valueForKey("num")->intValue();
            }else{
                name = RewardController::getInstance()->getNameByType(type,value);
                icon = RewardController::getInstance()->getPicByType(type,value);
            }
            m_numTxt1->setString(CC_ITOA(value));
            m_rewardTxt1->setString(name);
            CCSprite* spr = CCLoadSprite::createSprite(CCCommonUtils::getToolBgByColor(TOOL_BG[0]).c_str());
            CCCommonUtils::setSpriteMaxSize(spr,  80);
            m_rewardIcon1->addChild(spr);
            spr = CCLoadSprite::createSprite(icon.c_str());
            CCCommonUtils::setSpriteMaxSize(spr,  84,true);
            m_rewardIcon1->addChild(spr);
        }
    }
    
    if(m_info->getReward()->count()>1){
        reward = dynamic_cast<CCDictionary*>(m_info->getReward()->objectAtIndex(1));
        if(reward){
            int type = reward->valueForKey("type")->intValue();
            int value = reward->valueForKey("value")->intValue();
            if(type==R_GOODS){
                auto valueObj = _dict(reward->objectForKey("value"));
                int id = valueObj->valueForKey("id")->intValue();
                name = RewardController::getInstance()->getNameByType(type,id);
                icon = RewardController::getInstance()->getPicByType(type,id);
                value = valueObj->valueForKey("num")->intValue();
            }else{
                name = RewardController::getInstance()->getNameByType(type,value);
                icon = RewardController::getInstance()->getPicByType(type,value);
            }
            m_rewardTxt2->setString(name);
            m_numTxt2->setString(CC_ITOA(value));
            CCSprite* spr = CCLoadSprite::createSprite(CCCommonUtils::getToolBgByColor(TOOL_BG[1]).c_str());
            CCCommonUtils::setSpriteMaxSize(spr,  80);
            m_rewardIcon2->addChild(spr);
            spr = CCLoadSprite::createSprite(icon.c_str());
            CCCommonUtils::setSpriteMaxSize(spr,  84,true);
            m_rewardIcon2->addChild(spr);
        }
    }
    
    if(m_info->getReward()->count()>2){
        reward = dynamic_cast<CCDictionary*>(m_info->getReward()->objectAtIndex(2));
        if(reward){
            int type = reward->valueForKey("type")->intValue();
            int value = reward->valueForKey("value")->intValue();
            if(type==R_GOODS){
                auto valueObj = _dict(reward->objectForKey("value"));
                int id = valueObj->valueForKey("id")->intValue();
                name = RewardController::getInstance()->getNameByType(type,id);
                icon = RewardController::getInstance()->getPicByType(type,id);
                value = valueObj->valueForKey("num")->intValue();
            }else{
                name = RewardController::getInstance()->getNameByType(type,value);
                icon = RewardController::getInstance()->getPicByType(type,value);
            }
            m_rewardTxt3->setString(name);
            m_numTxt3->setString(CC_ITOA(value));
            CCSprite* spr = CCLoadSprite::createSprite(CCCommonUtils::getToolBgByColor(TOOL_BG[2]).c_str());
            CCCommonUtils::setSpriteMaxSize(spr,  80);
            m_rewardIcon3->addChild(spr);
            spr = CCLoadSprite::createSprite(icon.c_str());
            CCCommonUtils::setSpriteMaxSize(spr,  84,true);
            m_rewardIcon3->addChild(spr);
        }
    }
    
    CCSprite* spr = CCLoadSprite::createSprite(CCCommonUtils::getToolBgByColor(TOOL_BG[3]).c_str());
    CCCommonUtils::setSpriteMaxSize(spr,  80);
    m_rewardIcon4->addChild(spr);
    spr = CCLoadSprite::createSprite("MonsterAttack_3.png");
    CCCommonUtils::setSpriteMaxSize(spr,  84);
    m_rewardIcon4->addChild(spr);
    m_rewardTxt4->setString(_lang("105849"));
}
Esempio n. 15
0
// loads info about all tiles,sets self.contentSize & screenLoadRectExtension
// creates & adds tiles for dynamic usage if batchNode
void CCBigImage::prepareTilesWithFileExtensionZ(string plistFile, string extension, int tilesZ)
{
	// load plist with image & tiles info
    CCDictionary *dict = CCDictionary::createWithContentsOfFile(plistFile.c_str());
    if ( !dict )
    {
        CCLOGERROR("CCBigImage#prepareTilesWithFile:extension:z: can not load dictionary from file: %s", plistFile.c_str());
        return;
    }
	
	// load image size
    CCDictionary *sourceDict = (CCDictionary*)dict->objectForKey(std::string("Source"));
    CCSize size = CCSizeFromString(valueForKey("Size", sourceDict));
    
    this->setContentSize(size);
	
	// load tiles
    CCArray* array = (CCArray*)dict->objectForKey(std::string("Tiles"));
	
	_dynamicChildren = CCArray::createWithCapacity(array->count());
    _dynamicChildren->retain();
    
	// set screenLoadRectExtension = size of first tile
	if (array->count())
	{
        CCDictionary *dict_ = (CCDictionary*)array->objectAtIndex(0);
        _screenLoadRectExtension = CCRectFromString(valueForKey("Rect", dict_)).size;
	}
	
	//read data and create nodes and add them
    for (int i=0; i<array->count(); i++)
    {
        CCDictionary* tileDict = (CCDictionary*)array->objectAtIndex(i);

        // All properties of Dictionary
        const char *spriteName = valueForKey("Name", tileDict);
		
		CCRect tileRect = CCRectFromString(valueForKey("Rect", tileDict));
        
		// convert rect origin from top-left to bottom-left
		tileRect.origin.y = this->getContentSize().height - tileRect.origin.y - tileRect.size.height;
		
		// Use forced tile extension or original if tilesExtension isn't set
		if (!extension.empty())
		{
			// Change extension
            string filename = string(spriteName);
            int index = filename.find('.');
            string name = filename.substr(0, index);
			spriteName = (name+"."+extension).c_str();
		}

		// Create & Add Tile (Dynamic Sprite Mode)
		UnloadableSpriteNode* tile = UnloadableSpriteNode::nodeWithImageForRect(spriteName, tileRect);
		this->addChild(tile, tilesZ);
		_dynamicChildren->addObject(tile);
		
    } //< for dict in arr
    
    dict->release();
	
}
Esempio n. 16
0
void AllianceTerritoryInfo::parseInfo(CCDictionary* dict){
    if(dict->objectForKey("uid")){
        m_territoryId = dict->valueForKey("uid")->getCString();
    }
    if(dict->objectForKey("allianceAbbr")){
        m_allianceAbbr = dict->valueForKey("allianceAbbr")->getCString();
    }
    if(dict->objectForKey("allianceName")){
        m_allianceName = dict->valueForKey("allianceName")->getCString();
    }
    if(dict->objectForKey("pic")){
        m_territoryPic = dict->valueForKey("pic")->getCString();
    }
    if(dict->objectForKey("stat")){
        m_territoryState = dict->valueForKey("stat")->intValue();
    }
    if(dict->objectForKey("type")){
        m_territoryType = (WorldCityType)dict->valueForKey("type")->intValue();
    }
    if(dict->objectForKey("resType")){
        m_territoryResourceType = (WorldResourceType)dict->valueForKey("resType")->intValue();
    }
    if(dict->objectForKey("name")){
        m_territoryName = dict->valueForKey("name")->getCString();
        if (dict->objectForKey("count")) {
            m_territoryCount = dict->valueForKey("count")->intValue();
        }
        if (m_territoryType == Tile_allianceArea) {
            GlobalData::shared()->playerInfo.allianceInfo.territoryNameMap[m_territoryCount] = make_pair(m_territoryId, m_territoryName);
        }
    }
    if(!dict->objectForKey("name")){
        if (m_territoryType == Tile_allianceArea) {
            if (dict->objectForKey("count")) {
                m_territoryCount = dict->valueForKey("count")->intValue();
                m_territoryName = _lang_1("115312", CC_ITOA(m_territoryCount));
            }
            else
                m_territoryName = _lang_1("115312", "1");
            GlobalData::shared()->playerInfo.allianceInfo.territoryNameMap[m_territoryCount] = make_pair(m_territoryId, m_territoryName);
        }
        else if (m_territoryType == tile_superMine) {
            switch (m_territoryResourceType) {
                case Food:
                    m_territoryName = _lang("115376");
                    break;
                case Wood:
                    m_territoryName = _lang("115377");
                    break;
                case Iron:
                    m_territoryName = _lang("115378");
                    break;
                case Stone:
                    m_territoryName = _lang("115379");
                    break;
                default:
                    break;
            }
        }
        else if (m_territoryType == tile_tower) {
            if (dict->objectForKey("count")) {
                m_territoryCount = dict->valueForKey("count")->intValue();
                m_territoryName = _lang_1("115406", CC_ITOA(m_territoryCount));
            }
            else
                m_territoryName = _lang_1("115406", "1");
        }
        else if (m_territoryType == tile_wareHouse) {
            m_territoryName = _lang("115364");
        }
    }
    if(dict->objectForKey("level")){
        m_territoryLv = dict->valueForKey("level")->intValue();
    }
    if(dict->objectForKey("curDef")){
        m_territoryDef = dict->valueForKey("curDef")->intValue();
    }
    if(dict->objectForKey("tq")){
        m_territoryRes = dict->valueForKey("tq")->intValue();
    }
    if(dict->objectForKey("pointId")){
        m_territoryPtIndex = dict->valueForKey("pointId")->intValue();
    }
    if (!dict->objectForKey("pointId")) {
        m_territoryPtIndex = 0;
    }
    if(dict->objectForKey("owner")){
        m_ownerFlag = true;
    }
    if(!dict->objectForKey("owner")){
        m_ownerFlag = false;
    }
    
    m_territoryActive = 1;
    
    m_totalResStorage = 0;
    if (dict->objectForKey("resourceList")) {
        CCArray* array = (CCArray*)dict->objectForKey("resourceList");
        if(array){
            int count = array->count();
            for(int i=0;i<count;i++){
                auto item = _dict(array->objectAtIndex(i));
                if (item->objectForKey("uid")) {
                    if (item->objectForKey("wood")) {
                        m_totalResStorage += item->valueForKey("wood")->longValue() * GlobalData::shared()->resources_weight_1;
                    }
                    if (item->objectForKey("food")) {
                        m_totalResStorage += item->valueForKey("food")->longValue() * GlobalData::shared()->resources_weight_4;
                    }
                    if (item->objectForKey("stone")) {
                        m_totalResStorage += item->valueForKey("stone")->longValue() * GlobalData::shared()->resources_weight_2;
                    }
                    if (item->objectForKey("iron")) {
                        m_totalResStorage += item->valueForKey("iron")->longValue() * GlobalData::shared()->resources_weight_3;
                    }
                }
            }
        }
    }
    
    m_banner = "";
    if (dict->objectForKey("banner")) {
        m_banner = dict->valueForKey("banner")->getCString();
    }
}
Esempio n. 17
0
bool MailBatchRewardCommand::handleRecieve(cocos2d::CCDictionary *dict){
    if (dict->valueForKey("cmd")->compare(MAIL_REWARD_BATCH_COMMAND) != 0)
        return false;

    CCDictionary* params = _dict(dict->objectForKey("params"));
    const CCString *pStr = params->valueForKey("errorCode");
    if (pStr->compare("")!=0) {
        CCCommonUtils::flyText((_lang(pStr->getCString()).c_str()));
 
        return true;
    }
    
    if (params->valueForKey("success")->intValue() == 1 ) {
    #if(CC_TARGET_PLATFORM==CC_PLATFORM_IOS)
        if (ChatServiceCocos2dx::Mail_OC_Native_Enable){
            ChatServiceCocos2dx::setMailRewardStatusForBatchToReadWithMailIDs(m_uids,1);
        }
    #endif
    }
    if(params->objectForKey("honor")){
        int honor = params->valueForKey("honor")->intValue();
        GlobalData::shared()->playerInfo.allianceInfo.accPoint = honor;
    }
    if(params->objectForKey("alliancepoint")){
        int alliancepoint = params->valueForKey("alliancepoint")->intValue();
        GlobalData::shared()->playerInfo.allianceInfo.point = alliancepoint;
    }
    string rewardStr = "{\"flyToolReward\":[";
    if(params->objectForKey("goods")){
        CCArray* arr = dynamic_cast<CCArray*>(params->objectForKey("goods"));
        
        CCLOGFUNC("111");
        
#if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
        
        if(MailController::getInstance()->getIsNewMailListEnable())
        {
//            MailController::getInstance()->m_mutiFlyToolRewardArray->removeAllObjects();
//            MailController::getInstance()->m_mutiFlyToolRewardArray->addObjectsFromArray(arr);
//            if (ChatServiceCocos2dx::isChatShowing) {
//                ChatServiceCocos2dx::exitChatActivityFrom2dx(false);
//            }
            
            CCObject* obj;
            
            string rewardToolBody = "";
            CCARRAY_FOREACH(arr, obj) {
                auto tdic = _dict(obj);
                if(tdic)
                {
                    string itemId ="";
                    if (tdic->objectForKey("itemId")) {
                        itemId = tdic->valueForKey("itemId")->getCString();
                        if (itemId!="") {
                            auto &item = ToolController::getInstance()->getToolInfoById(atoi(itemId.c_str()));
                            int num = 0;
                            if (tdic->objectForKey("rewardAdd")) {
                                num = tdic->valueForKey("rewardAdd")->intValue();
                            } else if (tdic->objectForKey("count")){
                                num = tdic->valueForKey("count")->intValue() - item.getCNT();
                            }
                            if(rewardToolBody!="")
                                rewardToolBody.append(",");
                            rewardToolBody.append("{\"itemPic\":").append("\"").append(CCCommonUtils::getIcon(itemId.c_str())).append("\"").append(",\"itemNum\":").append(CC_ITOA(num)).append("}");
                        }
                    }
                }
            }
Esempio n. 18
0
/**
   @brief Returns category name
 
   @return A string representing the category
 */
string Category::getName()
{
    return valueForKey(KEY_CAT_NAME);
}
Esempio n. 19
0
const char* BencodeObject::stringValueForKey(const char* key, const char* def) {
	BencodeObject* obj = valueForKey(key);

	return (obj ? obj->_terminatedStringValue(def, _mode != BencodeModeNondestructive) : def);
}
void TerritoryResourceDetailView::onDetailCallback(cocos2d::CCObject *obj) {
    removeLoadingAni();
    m_isInUpdate = false;
    if(SceneController::getInstance()->currentSceneId != SCENE_ID_WORLD){
        return;
    }
    if(!WorldController::getInstance()->isInWorld){
        return;
    }
    auto ret = dynamic_cast<NetResult*>(obj);
    if (!ret || ret->getErrorCode() != Error_OK) {
        // todo : parse error
        return;
    }
    auto info = dynamic_cast<CCDictionary*>(ret->getData());
    if (!info) {
        return;
    }
    if(!this->getParent()){
        return;
    }
    
    if (info->objectForKey("stat")) {
        m_cityInfo.m_superMineInfo.trstat = (AAreaState)info->valueForKey("stat")->intValue();
    }
    
    if (info->objectForKey("maxSoldier")) {
        soldierMax = info->valueForKey("maxSoldier")->intValue();
    }
    else
        soldierMax = 0;
    
    if (info->objectForKey("alreadySoldier")) {
        soldierAlready = info->valueForKey("alreadySoldier")->intValue();
    }
    else
        soldierAlready = 0;
    
    if (!info->objectForKey("owner")) {
        m_cityInfo.m_allianceAreaOwnerInfo.ownerId = "";
        m_cityInfo.m_allianceAreaOwnerInfo.ownerName = "";
        m_cityInfo.m_allianceAreaOwnerInfo.allianceId = "";
        m_cityInfo.m_allianceAreaOwnerInfo.allianceAbbr = "";
        m_cityInfo.m_allianceAreaOwnerInfo.ownerPic = "";
        m_cityInfo.m_allianceAreaOwnerInfo.team = false;
    }
    if (info->objectForKey("owner")) {
        CCDictionary* owner = _dict(info->objectForKey("owner"));
        if (owner->objectForKey("uid")) {
            m_cityInfo.m_allianceAreaOwnerInfo.ownerId = owner->valueForKey("uid")->getCString();
        }
        if (owner->objectForKey("name")) {
            m_cityInfo.m_allianceAreaOwnerInfo.ownerName = owner->valueForKey("name")->getCString();
        }
        if (owner->objectForKey("allianceId")) {
            m_cityInfo.m_allianceAreaOwnerInfo.allianceId = owner->valueForKey("allianceId")->getCString();
        }
        if (owner->objectForKey("abbr")) {
            m_cityInfo.m_allianceAreaOwnerInfo.allianceAbbr = owner->valueForKey("abbr")->getCString();
        }
        if (owner->objectForKey("team")) {
            m_cityInfo.m_allianceAreaOwnerInfo.team = owner->valueForKey("team")->boolValue();
        }
        if (owner->objectForKey("pic")) {
            m_cityInfo.m_allianceAreaOwnerInfo.ownerPic = owner->valueForKey("pic")->getCString();
        }
    }
    
    if (info->objectForKey("curDef")) {
        m_cityInfo.m_superMineInfo.trdef = info->valueForKey("curDef")->intValue();
    }
    if (info->objectForKey("maxDef")) {
        m_cityInfo.m_superMineInfo.trdefmax = info->valueForKey("maxDef")->intValue();
    }
    if (info->objectForKey("updateTime")) {
        m_cityInfo.m_superMineInfo.trutime = info->valueForKey("updateTime")->doubleValue() / 1000;
    }
    if (info->objectForKey("startTime")) {
        if (m_cityInfo.m_superMineInfo.trstat == 0 || m_cityInfo.m_superMineInfo.trstat == 1) {
            m_cityInfo.m_superMineInfo.trstime = info->valueForKey("startTime")->doubleValue() / 1000;
        }
        else if (m_cityInfo.m_superMineInfo.trstat == 6 || m_cityInfo.m_superMineInfo.trstat == 3 || m_cityInfo.m_superMineInfo.trstat == 4) {
            m_cityInfo.m_superMineInfo.digStartTime = info->valueForKey("startTime")->doubleValue() / 1000;
        }
    }
    if (info->objectForKey("buildingSpd")) {
        if (m_cityInfo.m_superMineInfo.trstat == 0 || m_cityInfo.m_superMineInfo.trstat == 1) {
            m_cityInfo.m_superMineInfo.buildSpeed = info->valueForKey("buildingSpd")->doubleValue() * 1000;
        }
        else if (m_cityInfo.m_superMineInfo.trstat == 6 || m_cityInfo.m_superMineInfo.trstat == 3 || m_cityInfo.m_superMineInfo.trstat == 4) {
            m_cityInfo.m_superMineInfo.digSpeed = info->valueForKey("buildingSpd")->doubleValue() * 1000;
        }
    }
    if (info->objectForKey("name")) {
        m_cityInfo.m_aArea_nickname = info->valueForKey("name")->getCString();
    }
    if (!info->objectForKey("name")) {
        switch (m_cityInfo.m_superMineInfo.type) {
            case Food:
                m_cityInfo.m_aArea_nickname = _lang("115376");
                break;
            case Wood:
                m_cityInfo.m_aArea_nickname = _lang("115377");
                break;
            case Iron:
                m_cityInfo.m_aArea_nickname = _lang("115378");
                break;
            case Stone:
                m_cityInfo.m_aArea_nickname = _lang("115379");
                break;
            default:
                break;
        }
    }
    if (info->objectForKey("allianceAbbr")) {
        m_cityInfo.m_aArea_simpleName = info->valueForKey("allianceAbbr")->getCString();
    }
    if (info->objectForKey("allianceId")) {
        std::string allianceId = info->valueForKey("allianceId")->getCString();
        if (allianceId.compare(GlobalData::shared()->playerInfo.allianceInfo.uid)==0) {
            m_ownerFlag = true;
        }
        else
            m_ownerFlag = false;
    }
    
    m_data->removeAllObjects();
    m_territoryFlag = true;
    bool tempFlag = true;
    if (info->objectForKey("army")) {
        CCArray* array = (CCArray*)info->objectForKey("army");
        if(array){
            int count = array->count();
            for(int i=0;i<count;i++){
                auto item = _dict(array->objectAtIndex(i));
                YuanJunInfo* info = new YuanJunInfo();
                info->parseInfo(item);
                m_data->addObject(info);
                if (info->getUid()==GlobalData::shared()->playerInfo.uid) {
                    tempFlag = false;
                    m_marchId = info->getUuid();
                    if(WorldController::getInstance()->m_marchInfo.find(m_marchId) != WorldController::getInstance()->m_marchInfo.end()){
                        auto &marchInfo = WorldController::getInstance()->m_marchInfo[m_marchId];
                        m_digStartTime = marchInfo.digStartTime / 1000;
                        m_digStartNum = marchInfo.digStartNum;
                        m_digSpeed = marchInfo.digSpeed;
                        m_troopMax = marchInfo.troopMax;
                        m_changeCollectSpdTime = marchInfo.changeCollectSpdTime / 1000;
                    }
                }
                CC_SAFE_RELEASE(info);
            }
        }
    }
    
    if (tempFlag) {
        m_digStartTime = 0;
        m_digStartNum = 0;
        m_digSpeed = 0;
        m_troopMax = 0;
        m_changeCollectSpdTime = 0;
    }
    
    if (m_cityInfo.m_superMineInfo.trstat == 1 || m_cityInfo.m_superMineInfo.trstat == 0) {
        int num = (GlobalData::shared()->world_alliance_war_k2 +CCCommonUtils::getEffectValueByNum(ALLIANCE_TEAM_MEMBER_MAX));
        int gapNum = num - m_data->count();
        gapNum = MAX(gapNum,0);
        YuanJunInfo* info = NULL;
        for (int i=0; i<gapNum; i++) {
            YuanJunInfo* info = new YuanJunInfo();
            CCArray* array = CCArray::create();
            info->setSoldiers(array);
            info->setCanUse(tempFlag);
            if (soldierAlready >= soldierMax && soldierMax != 0) {
                info->setIndex(4);
            }
            else
                info->setIndex(2);
            m_data->addObject(info);
            CC_SAFE_RELEASE(info);
        }
        info = new YuanJunInfo();
        CCArray* array = CCArray::create();
        info->setSoldiers(array);
        info->setIndex(3);
        m_data->addObject(info);
        CC_SAFE_RELEASE(info);
    }
    else if (m_cityInfo.m_superMineInfo.trstat == 3 || m_cityInfo.m_superMineInfo.trstat == 4) {
        if (m_data->count() == 0) {
            YuanJunInfo* info = new YuanJunInfo();
            CCArray* array = CCArray::create();
            info->setSoldiers(array);
            info->setCanUse(true);
            info->setIndex(2);
            m_data->addObject(info);
            CC_SAFE_RELEASE(info);

        }
    }

    refreshView();
}
Esempio n. 21
0
void FacebookInviteView::onSendClick(CCObject *pSender, CCControlEvent event){
    CCArray* arr = CCArray::create();
    for (int i=0; i<m_data->count(); i++) {
        auto dic = _dict(m_data->objectAtIndex(i));
        string flag = dic->valueForKey("flag")->getCString();
        if (arr->count()>50) {
            break;
        }
        if (flag=="1") {
            string id = dic->valueForKey("id")->getCString();;
            arr->addObject(CCString::create(id));
        }
    }
    m_inviteNum = arr->count();
    GlobalData::shared()->isBind = true;
    
    
    string msg = _lang("107087");
    FBUtilies::postFBSelectedFriendList(arr,msg,m_ftype);
    FBUtilies::appEventShareLog(CC_ITOA(GlobalData::shared()->playerInfo.selfServerId), GlobalData::shared()->playerInfo.level, FunBuildController::getInstance()->getMainCityLv(), "107087");
    if (FBUtilies::fbIsLogin() && m_ftype=="2") {
        double lastTime = 0.0;
        string timeStr = CCUserDefault::sharedUserDefault()->getStringForKey("facebookCallForHelpTime","");
        if (timeStr!="") {
            lastTime = atof(timeStr.c_str());
        }
        std:: map<string, CCDictionary*>::iterator it = GlobalData::shared()->shareFbmap.find("call_for_help");
        double ctime = GlobalData::shared()->getWorldTime();
        if (it!=GlobalData::shared()->shareFbmap.end()) {
            CCDictionary* dict = it->second;
            if (dict) {
                int on = dict->valueForKey("ON")->intValue();
                double limit = dict->valueForKey("Limit")->doubleValue();
                string permission = dict->valueForKey("permissions")->getCString();
                if (lastTime > 0) {
                    lastTime = lastTime + limit;
                }
                bool flag = FBUtilies::fbHasGranted(permission);
                if (on==1 && ctime >= lastTime && flag) {
                    CCUserDefault::sharedUserDefault()->setStringForKey("facebookCallForHelpTime", CC_ITOA(ctime));
                    CCUserDefault::sharedUserDefault()->flush();
                    string fbName = CCUserDefault::sharedUserDefault()->getStringForKey(FB_USERNAME, "");
                    string name = _lang_1(dict->valueForKey("name")->getCString(),fbName.c_str());
                    string caption = _lang_1(dict->valueForKey("caption")->getCString(),fbName.c_str());
                    string linkDescription = _lang_1(dict->valueForKey("linkDescription")->getCString(),fbName.c_str());
                    string pictureUrl = dict->valueForKey("pictureUrl")->getCString();
                    string link = dict->valueForKey("link")->getCString();
                    string ref = dict->valueForKey("ref")->getCString();
                    FBUtilies::fbPublishFeedDialog(name,caption,linkDescription,link,pictureUrl,1,ref);
                    CCLog("fb ask for help push ");
                }else{
                    CCLog("fb time or on key error on=%d limit=%f permission=%s flag=%d lastTime=%f ctime=%f",on,limit,permission.c_str(),flag,lastTime,ctime);
                }
            }else{
                CCLog("fb dict null");
            }
        }else{
            CCLog("fb have not call_for_help object");
        }
    }else{
        CCLog("fb facebook not login");
    }

}
Esempio n. 22
0
void UserDataUpdatePush::handleResponse(cocos2d::CCDictionary *dict)
{
    if (!dict)
        return;
    
    CCDictionary *params=_dict(dict->objectForKey("params"));
    if (!params)
        return;
    
    const CCString *pStr = params->valueForKey("level");
    auto &general = GlobalData::shared()->generals.begin()->second;
    
    if(GlobalData::shared()->playerInfo.level != pStr->intValue())
    {
        auto tmp = CCDictionary::create();
        if (params->objectForKey("gift_AP")) {
            int actionPoint = params->valueForKey("gift_AP")->intValue();
            auto &lordInfo = GlobalData::shared()->lordInfo;
            lordInfo.energy += actionPoint;
            if (lordInfo.energy > lordInfo.physical_k1) {
                lordInfo.energy = lordInfo.physical_k1;
            }
            
            if (params->objectForKey("has_gift")) {
                // hold Energy update animation for delay play
//                UIComponent::getInstance()->removeEnergyUpdate();
            }
            
            tmp->setObject(CCInteger::create(actionPoint), "gift2");
        }
        if (params->objectForKey("has_gift")) {
            tmp->setObject(CCBool::create(true), "has_gift");
        }
        GlobalData::shared()->playerInfo.level = pStr->intValue();
        general.level = GlobalData::shared()->playerInfo.level;

        pStr = params->valueForKey("att");
        general.attack = pStr->intValue();
        pStr = params->valueForKey("defence");
        general.defense = pStr->intValue();

        // client user level save
        CCUserDefault::sharedUserDefault()->setIntegerForKey(ACCOUNT_USER_LEVEL, pStr->intValue());
        if(GlobalData::shared()->playerInfo.level>1){
            int userLv = GlobalData::shared()->playerInfo.level;
            //if(userLv<GlobalData::shared()->playerInfo.level){
                int key = 100100 + userLv-1;
                auto dict = LocalController::shared()->DBXMLManager()->getObjectByKey(CC_ITOA(key));
                string item =  dict->valueForKey("level_item")->getCString();
                if(item!=""){
                    CCSafeNotificationCenter::sharedNotificationCenter()->postNotification(MSG_PLAYER_LEVELUP,tmp);
                }else{
                    GlobalData::shared()->lordInfo.levelUp+=1;
                }
            //}
            
        }
        
    } else {
        GlobalData::shared()->playerInfo.level = pStr->intValue();
    }
    pStr = params->valueForKey("exp");
    GlobalData::shared()->playerInfo.exp = pStr->intValue();
    pStr = params->valueForKey("maxExp");
    GlobalData::shared()->playerInfo.maxExp = pStr->intValue();
    UIComponent::getInstance()->setUserData();
    
    general.currExp = GlobalData::shared()->playerInfo.exp;
    general.maxExp = GlobalData::shared()->playerInfo.maxExp;
    
    CCArray *generalArr = dynamic_cast<CCArray*>(params->objectForKey("userGenerals"));
    if(generalArr){
        map<string,GeneralInfo> *generals = &(GlobalData::shared()->generals);

        CCObject *generalItem;
        const CCString *pStrGeneral;
        CCARRAY_FOREACH(generalArr,generalItem){
            pStrGeneral = _dict(generalItem)->valueForKey("generalId");
            if(pStrGeneral->compare("")!=0){
                auto it = generals->find(pStrGeneral->getCString());
                it->second.updateGeneralData(_dict(generalItem),false);
            }
        }
    }
Esempio n. 23
0
bool CCParticleSystem::initWithDictionary(NSDictionary<std::string, NSObject*> *dictionary)
{
	bool bRet = false;
	unsigned char *buffer = NULL;
	unsigned char *deflated = NULL;
	UIImage *image = NULL;
	do 
	{
		int maxParticles = atoi(valueForKey("maxParticles", dictionary));
		// self, not super
		if(this->initWithTotalParticles(maxParticles))
		{
			// angle
			m_fAngle = (float)atof(valueForKey("angle", dictionary));
			m_fAngleVar = (float)atof(valueForKey("angleVariance", dictionary));

			// duration
			m_fDuration = (float)atof(valueForKey("duration", dictionary));

			// blend function 
			m_tBlendFunc.src = atoi(valueForKey("blendFuncSource", dictionary));
			m_tBlendFunc.dst = atoi(valueForKey("blendFuncDestination", dictionary));

			// color
			m_tStartColor.r = (float)atof(valueForKey("startColorRed", dictionary));
			m_tStartColor.g = (float)atof(valueForKey("startColorGreen", dictionary));
			m_tStartColor.b = (float)atof(valueForKey("startColorBlue", dictionary));
			m_tStartColor.a = (float)atof(valueForKey("startColorAlpha", dictionary));

			m_tStartColorVar.r = (float)atof(valueForKey("startColorVarianceRed", dictionary));
			m_tStartColorVar.g = (float)atof(valueForKey("startColorVarianceGreen", dictionary));
			m_tStartColorVar.b = (float)atof(valueForKey("startColorVarianceBlue", dictionary));
			m_tStartColorVar.a = (float)atof(valueForKey("startColorVarianceAlpha", dictionary));

			m_tEndColor.r = (float)atof(valueForKey("finishColorRed", dictionary));
			m_tEndColor.g = (float)atof(valueForKey("finishColorGreen", dictionary));
			m_tEndColor.b = (float)atof(valueForKey("finishColorBlue", dictionary));
			m_tEndColor.a = (float)atof(valueForKey("finishColorAlpha", dictionary));

			m_tEndColorVar.r = (float)atof(valueForKey("finishColorVarianceRed", dictionary));
			m_tEndColorVar.g = (float)atof(valueForKey("finishColorVarianceGreen", dictionary));
			m_tEndColorVar.b = (float)atof(valueForKey("finishColorVarianceBlue", dictionary));
			m_tEndColorVar.a = (float)atof(valueForKey("finishColorVarianceAlpha", dictionary));

			// particle size
			m_fStartSize = (float)atof(valueForKey("startParticleSize", dictionary));
			m_fStartSizeVar = (float)atof(valueForKey("startParticleSizeVariance", dictionary));
			m_fEndSize = (float)atof(valueForKey("finishParticleSize", dictionary));
			m_fEndSizeVar = (float)atof(valueForKey("finishParticleSizeVariance", dictionary));

			// position
			m_tPosition.x = (float)atof(valueForKey("sourcePositionx", dictionary));
			m_tPosition.y = (float)atof(valueForKey("sourcePositiony", dictionary));
			m_tPosVar.x = (float)atof(valueForKey("sourcePositionVariancex", dictionary));
			m_tPosVar.y = (float)atof(valueForKey("sourcePositionVariancey", dictionary));

			m_nEmitterMode = atoi(valueForKey("emitterType", dictionary));

			// Mode A: Gravity + tangential accel + radial accel
			if( m_nEmitterMode == kCCParticleModeGravity ) 
			{
				// gravity
				modeA.gravity.x = (float)atof(valueForKey("gravityx", dictionary));
				modeA.gravity.y = (float)atof(valueForKey("gravityy", dictionary));

				// speed
				modeA.speed = (float)atof(valueForKey("speed", dictionary));
				modeA.speedVar = (float)atof(valueForKey("speedVariance", dictionary));

                const char * pszTmp = NULL;
				// radial acceleration
                pszTmp = valueForKey("radialAcceleration", dictionary);
                modeA.radialAccel = (pszTmp) ? (float)atof(pszTmp) : 0;

                pszTmp = valueForKey("radialAccelVariance", dictionary);
				modeA.radialAccelVar = (pszTmp) ? (float)atof(pszTmp) : 0;

				// tangential acceleration
                pszTmp = valueForKey("tangentialAcceleration", dictionary);
				modeA.tangentialAccel = (pszTmp) ? (float)atof(pszTmp) : 0;

                pszTmp = valueForKey("tangentialAccelVariance", dictionary);
				modeA.tangentialAccelVar = (pszTmp) ? (float)atof(pszTmp) : 0;
			}

			// or Mode B: radius movement
			else if( m_nEmitterMode == kCCParticleModeRadius ) 
			{
				modeB.startRadius = (float)atof(valueForKey("maxRadius", dictionary));
				modeB.startRadiusVar = (float)atof(valueForKey("maxRadiusVariance", dictionary));
				modeB.endRadius = (float)atof(valueForKey("minRadius", dictionary));
				modeB.endRadiusVar = 0;
				modeB.rotatePerSecond = (float)atof(valueForKey("rotatePerSecond", dictionary));
				modeB.rotatePerSecondVar = (float)atof(valueForKey("rotatePerSecondVariance", dictionary));

			} else {
				NSAssert( false, "Invalid emitterType in config file");
				CCX_BREAK_IF(true);
			}

			// life span
			m_fLife = (float)atof(valueForKey("particleLifespan", dictionary));
			m_fLifeVar = (float)atof(valueForKey("particleLifespanVariance", dictionary));

			// emission Rate
			m_fEmissionRate = m_nTotalParticles / m_fLife;

			// texture		
			// Try to get the texture from the cache
			char *textureName = (char *)valueForKey("textureFileName", dictionary);
            std::string fullpath = CCFileUtils::fullPathFromRelativeFile(textureName, m_sPlistFile.c_str());

            if (strlen(textureName) > 0)
            {
                // set not pop-up message box when load image failed
                bool bNotify = UIImage::getIsPopupNotify();
                UIImage::setIsPopupNotify(false);
                this->m_pTexture = CCTextureCache::sharedTextureCache()->addImage(fullpath.c_str());

                // reset the value of UIImage notify
                UIImage::setIsPopupNotify(bNotify);
            }

			// if it fails, try to get it from the base64-gzipped data			
            char *textureData = NULL;
			if ( ! m_pTexture && 
                (textureData = (char *)valueForKey("textureImageData", dictionary)))
			{
				int dataLen = strlen(textureData);
				if(dataLen != 0)
				{
					int decodeLen = base64Decode((unsigned char*)textureData, dataLen, &buffer);
					NSAssert( buffer != NULL, "CCParticleSystem: error decoding textureImageData");
					CCX_BREAK_IF(!buffer);

						int deflatedLen = ZipUtils::ccInflateMemory(buffer, decodeLen, &deflated);
						NSAssert( deflated != NULL, "CCParticleSystem: error ungzipping textureImageData");
						CCX_BREAK_IF(!deflated);
						
						image = new UIImage();
						bool isOK = image->initWithData(deflated, deflatedLen);
						NSAssert(isOK, "CCParticleSystem: error init image with Data");
						CCX_BREAK_IF(!isOK);
						
						m_pTexture = CCTextureCache::sharedTextureCache()->addUIImage(image, fullpath.c_str());
				}
			}
			NSAssert( this->m_pTexture != NULL, "CCParticleSystem: error loading the texture");
			
			CCX_BREAK_IF(!m_pTexture);
			this->m_pTexture->retain();
			bRet = true;
		}
	} while (0);
	CCX_SAFE_DELETE_ARRAY(buffer);
    CCX_SAFE_DELETE_ARRAY(deflated);
	CCX_SAFE_DELETE(image);
	return bRet;
}
Esempio n. 24
0
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);
                            }
                        }
                    }
                }
            }
Esempio n. 25
0
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string, CCObject*> *dictionary, CCTexture2D *pobTexture)
{
	/*
	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<std::string, CCObject*> *metadataDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("metadata"));
	CCDictionary<std::string, CCObject*> *framesDict = (CCDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("frames"));
	int format = 0;

	// get the format
	if(metadataDict != NULL) 
	{
		format = atoi(valueForKey("format", metadataDict));
	}

	// check the format
	CCAssert(format >=0 && format <= 3, "");

	framesDict->begin();
	std::string key = "";
	CCDictionary<std::string, CCObject*> *frameDict = NULL;
	while( (frameDict = (CCDictionary<std::string, CCObject*>*)framesDict->next(&key)) )
	{
		CCSpriteFrame *spriteFrame = m_pSpriteFrames->objectForKey(key);
		if (spriteFrame)
		{
			continue;
		}
		
		if(format == 0) 
		{
			float x = (float)atof(valueForKey("x", frameDict));
			float y = (float)atof(valueForKey("y", frameDict));
			float w = (float)atof(valueForKey("width", frameDict));
			float h = (float)atof(valueForKey("height", frameDict));
			float ox = (float)atof(valueForKey("offsetX", frameDict));
			float oy = (float)atof(valueForKey("offsetY", frameDict));
			int ow = atoi(valueForKey("originalWidth", frameDict));
			int oh = atoi(valueForKey("originalHeight", frameDict));
			// 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(valueForKey("frame", frameDict));
			bool rotated = false;

			// rotation
			if (format == 2)
			{
				rotated = atoi(valueForKey("rotated", frameDict)) == 0 ? false : true;
			}

			CCPoint offset = CCPointFromString(valueForKey("offset", frameDict));
			CCSize sourceSize = CCSizeFromString(valueForKey("sourceSize", frameDict));

			// create frame
			spriteFrame = new CCSpriteFrame();
			spriteFrame->initWithTexture(pobTexture, 
				frame,
				rotated,
				offset,
				sourceSize
				);
		} else
		if (format == 3)
		{
			// get values
			CCSize spriteSize = CCSizeFromString(valueForKey("spriteSize", frameDict));
			CCPoint spriteOffset = CCPointFromString(valueForKey("spriteOffset", frameDict));
			CCSize spriteSourceSize = CCSizeFromString(valueForKey("spriteSourceSize", frameDict));
			CCRect textureRect = CCRectFromString(valueForKey("textureRect", frameDict));
            bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0 ? false : true;

			// get aliases
			CCMutableArray<CCString*> *aliases = (CCMutableArray<CCString*> *) (frameDict->objectForKey(std::string("aliases")));
            CCMutableArray<CCString*>::CCMutableArrayIterator iter;

            CCString * frameKey = new CCString(key.c_str());
            for (iter = aliases->begin(); iter != aliases->end(); ++iter)
            {
                std::string oneAlias = ((CCString*) (*iter))->m_sString;
                if (m_pSpriteFramesAliases->objectForKey(oneAlias))
                {
                    CCLOG("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
                }

                m_pSpriteFramesAliases->setObject(frameKey, oneAlias);
            }
            frameKey->release();
            // create frame
            spriteFrame = new CCSpriteFrame();
            spriteFrame->initWithTexture(pobTexture,
                            CCRectMake(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
                            textureRotated,
                            spriteOffset,
                            spriteSourceSize);
		}

		// add sprite frame
		m_pSpriteFrames->setObject(spriteFrame, key);
		spriteFrame->release();
	}
}
Esempio n. 26
0
void CCSpriteFrameCache::addSpriteFramesWithDictionary(NSDictionary<std::string, NSObject*> *dictionary, CCTexture2D *pobTexture)
{
	/*
	Supported Zwoptex Formats:
		enum {
			ZWTCoordinatesListXMLFormat_Legacy = 0
			ZWTCoordinatesListXMLFormat_v1_0,
		};
	*/

	NSDictionary<std::string, NSObject*> *metadataDict = (NSDictionary<std::string, NSObject*>*)dictionary->objectForKey(std::string("metadata"));
	NSDictionary<std::string, NSObject*> *framesDict = (NSDictionary<std::string, NSObject*>*)dictionary->objectForKey(std::string("frames"));
	int format = 0;

	// get the format
	if(metadataDict != NULL) 
	{
		format = atoi(valueForKey("format", metadataDict));
	}

	// check the format
	if(format < 0 || format > 1) 
	{
		NSAssert(0, "cocos2d: WARNING: format is not supported for CCSpriteFrameCache addSpriteFramesWithDictionary:texture:");
		return;
	}

	framesDict->begin();
	std::string key = "";
	NSDictionary<std::string, NSObject*> *frameDict = NULL;
	while( frameDict = (NSDictionary<std::string, NSObject*>*)framesDict->next(&key) )
	{
		CCSpriteFrame *spriteFrame = m_pSpriteFrames->objectForKey(key);
		if (spriteFrame)
		{
			continue;
		}
		
		if(format == 0) 
		{
			float x = (float)atof(valueForKey("x", frameDict));
			float y = (float)atof(valueForKey("y", frameDict));
			float w = (float)atof(valueForKey("width", frameDict));
			float h = (float)atof(valueForKey("height", frameDict));
			float ox = (float)atof(valueForKey("offsetX", frameDict));
			float oy = (float)atof(valueForKey("offsetY", frameDict));
			int ow = atoi(valueForKey("originalWidth", frameDict));
			int oh = atoi(valueForKey("originalHeight", frameDict));
			// 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 = CCSpriteFrame::frameWithTexture(pobTexture, CGRectMake(x, y, w, h), CGPointMake(ox, oy), CGSizeMake((float)ow, (float)oh));
		} 
		else if(format == 1) 
		{
			/** @todo
			CGRect frame = CGRectFromString([frameDict objectForKey:@"frame"]);
			CGPoint offset = CGPointFromString([frameDict objectForKey:@"offset"]);
			CGSize sourceSize = CGSizeFromString([frameDict objectForKey:@"sourceSize"]);
			
			// create frame
			spriteFrame = [CCSpriteFrame frameWithTexture:texture rect:frame offset:offset originalSize:sourceSize];
			*/
		}
		else
		{
			CCLOG("cocos2d: Unsupported Zwoptex version. Update cocos2d.");
		}
		// add sprite frame
		m_pSpriteFrames->setObject(spriteFrame, key);
	}
}
Esempio n. 27
0
bool WebPreferencesStore::getBoolValueForKey(const String& key) const
{
    return valueForKey(m_boolValues, key);
}
Esempio n. 28
0
GxxValue* GxxDictionary::operator[](const char* key)
{
	return valueForKey(key);
}
Esempio n. 29
0
double WebPreferencesStore::getDoubleValueForKey(const String& key) const
{
    return valueForKey(m_doubleValues, key);
}
Esempio n. 30
0
static URL processAndCreateYouTubeURL(const URL& url, bool& isYouTubeShortenedURL)
{
    if (!url.protocolIs("http") && !url.protocolIs("https"))
        return URL();
    
    // Bail out early if we aren't even on www.youtube.com or youtube.com.
    if (!isYouTubeURL(url))
        return URL();
    
    const String& hostName = url.host().lower();
    
    bool isYouTubeMobileWebAppURL = hostName == "m.youtube.com";
    isYouTubeShortenedURL = hostName == "youtu.be";
    
    // Short URL of the form: http://youtu.be/v1d301D
    if (isYouTubeShortenedURL) {
        const String& videoID = url.lastPathComponent();
        if (videoID.isEmpty() || videoID == "/")
            return URL();
        
        return createYouTubeURL(videoID, emptyString());
    }
    
    String path = url.path();
    String query = url.query();
    String fragment = url.fragmentIdentifier();
    
    // On the YouTube mobile web app, the path and query string are put into the
    // fragment so that one web page is only ever loaded (see <rdar://problem/9550639>).
    if (isYouTubeMobileWebAppURL) {
        size_t location = fragment.find('?');
        if (location == notFound) {
            path = fragment;
            query = emptyString();
        } else {
            path = fragment.substring(0, location);
            query = fragment.substring(location + 1);
        }
        fragment = emptyString();
    }
    
    if (path.lower() == "/watch") {
        if (!query.isEmpty()) {
            const auto& queryDictionary = queryKeysAndValues(query);
            String videoID = valueForKey(queryDictionary, "v");
            
            if (!videoID.isEmpty()) {
                const auto& fragmentDictionary = queryKeysAndValues(url.fragmentIdentifier());
                String timeID = valueForKey(fragmentDictionary, "t");
                return createYouTubeURL(videoID, timeID);
            }
        }
        
        // May be a new-style link (see <rdar://problem/7733692>).
        if (fragment.startsWith('!')) {
            query = fragment.substring(1);
            
            if (!query.isEmpty()) {
                const auto& queryDictionary = queryKeysAndValues(query);
                String videoID = valueForKey(queryDictionary, "v");
                
                if (!videoID.isEmpty()) {
                    String timeID = valueForKey(queryDictionary, "t");
                    return createYouTubeURL(videoID, timeID);
                }
            }
        }
    } else if (hasCaseInsensitivePrefix(path, "/v/") || hasCaseInsensitivePrefix(path, "/e/")) {
        String videoID = url.lastPathComponent();
        
        // These URLs are funny - they don't have a ? for the first query parameter.
        // Strip all characters after and including '&' to remove extraneous parameters after the video ID.
        size_t ampersand = videoID.find('&');
        if (ampersand != notFound)
            videoID = videoID.substring(0, ampersand);
        
        if (!videoID.isEmpty())
            return createYouTubeURL(videoID, emptyString());
    }
    
    return URL();
}