示例#1
0
void RWLViewDBSource::ReadLgCell(std::string asHead, LogicCell* algc)
{
	if(0 == algc->miType){
		CCLabelTTF* tlt = CCLabelTTF::create((asHead+algc->msText).c_str(), FNT_UI_LABEL, 24,CCSize(rw,0), kCCTextAlignmentLeft);
		tlt->retain();
		m_plength.push_back(tlt->getContentSize().height);
		CCLog("+++++++%f", tlt->getContentSize().height);
		m_height += tlt->getContentSize().height;
		data->addObject(tlt);		

		asHead += " ";
		return;
	}


	for(std::vector<LogicCell*>::iterator it = algc->mvChilds.begin(); it != algc->mvChilds.end(); ++it){
		if((*it)->miType == 0){
			asHead += " ";
			break;
		}
	}

	for(std::vector<LogicCell*>::iterator it = algc->mvChilds.begin(); it != algc->mvChilds.end(); ++it){
		ReadLgCell(asHead.c_str(), *it);
	}

}
示例#2
0
void ObjectiveHandler::playObjective(bool showNotification)
{
    //CCLog("new objective received!");
    //CCLog("number of objectives: %d", objectives->count());
    if(objectives->count() <= 0)
    {
        return;
    }
    
    for(int i = 0; i < GameHUD::getThis()->objectiveDescriptions->count(); i++)
    {
        CCLabelTTF* tempLabel = (CCLabelTTF*) GameHUD::getThis()->objectiveDescriptions->objectAtIndex(i);
        GameHUD::getThis()->objectiveMenu->removeChild(tempLabel, true);
    }
    
    if(nextID == 0)
    {
        obj = (Objective*) objectives->objectAtIndex(0);
    }
    else
    {
        obj = NULL;
        for(int i = 0; i < objectives->count(); i++)
        {
            Objective* temp = (Objective*) objectives->objectAtIndex(i);
            if(temp->oid == nextID)
            {
                obj = temp;
            }
        }
    }
    
    if(obj == NULL)
    {
        nextID = currID;
        if(UserProfile::getThis()->gameLevel == 1)
        {
            NotificationPopup::getThis()->showScenario1Congratulations();
        }
        else if(UserProfile::getThis()->gameLevel == 2)
        {
            NotificationPopup::getThis()->showScenario2Congratulations();
        }
        if(UserProfile::getThis()->gameLevel == 4)
        {
            NotificationPopup::getThis()->showScenario4Congratulations();
        }
        else if(UserProfile::getThis()->gameLevel == 5)
        {
            NotificationPopup::getThis()->showScenario5Congratulations();
        }
        else if(UserProfile::getThis()->gameLevel == 6)
        {
            NotificationPopup::getThis()->showScenario6Congratulations();
        }
        return;
    }
    
    stringstream ss;
    stringstream ss1;
    stringstream ss2;
    
    if(obj->oType == GoldGoal)
    {
        ss << "Cumulate Gold";
        ss1 << "Collect gold of " << obj->value << "!";
        ss2 << "(" << GameHUD::getThis()->money << "/" << obj->value << ")";
        progressNumber = GameHUD::getThis()->money;
    }
    else if(obj->oType == FoodGoal)
    {
        ss << "Cumulate Food";
        ss1 << "Collect food of " << obj->value << "!";
        ss2 << "(" << GameHUD::getThis()->foodLabel->getString() << "/" << obj->value << ")";
        progressNumber = ::atoi(GameHUD::getThis()->foodLabel->getString());
    }
    else if(obj->oType == PopulationGoal)
    {
        ss << "Sustain Population";
        ss1 << "Raise your population to " << obj->value << "!";
        CCArray* spritesOnMap = SpriteHandler::getThis()->spritesOnMap;
        int num = 0;
        for (int i = 0; i < spritesOnMap->count(); i++)
        {
            GameSprite* gs = (GameSprite*) spritesOnMap->objectAtIndex(i);
            if(gs->villagerClass != V_CLASS_END && gs->villagerClass != V_BANDIT && gs->getHome() != NULL)
            {
                num++;
            }
        }
        ss2 << "(" << num << "/" << obj->value << ")";
        progressNumber = num;
    }
    else if(obj->oType == RaisePopulationGoal)
    {
        ss << "Raise Population";
        ss1 << "Raise your population by " << obj->value << "!";
        CCArray* spritesOnMap = SpriteHandler::getThis()->spritesOnMap;
        int num = 0;
        for (int i = 0; i < spritesOnMap->count(); i++)
        {
            GameSprite* gs = (GameSprite*) spritesOnMap->objectAtIndex(i);
            if(gs->villagerClass != V_CLASS_END && gs->villagerClass != V_BANDIT)
            {
                num++;
            }
        }
        startPopulation = num;
        targetPopulation = startPopulation + obj->value;
        int currentPopulation = obj->value - (targetPopulation - startPopulation);
        if(currentPopulation < 0)
        {
            currentPopulation = 0;
        }
        else if(currentPopulation > obj->value)
        {
            currentPopulation = obj->value;
        }
        
        ss2 << "(" << obj->value - (targetPopulation - startPopulation) << "/" << obj->value << ")";
        progressNumber = obj->value - (targetPopulation - startPopulation);
    }
    else if(obj->oType == ArmyGoal)
    {
        ss << "Build Army";
        ss1 << "Build 5 guard towers and man them.";
        
        int numberOfMannedTowers = 0;
        CCArray* guardTowers = BuildingHandler::getThis()->militaryOnMap;
        for(int i = 0; i < guardTowers->count(); i++)
        {
            Building* bui = (Building*)guardTowers->objectAtIndex(i);
            if(bui->memberSpriteList->count() > 0)
            {
                numberOfMannedTowers += 1;
            }
        }
        
        ss2 << "(" << numberOfMannedTowers << "/" << obj->value << ")";
        progressNumber = numberOfMannedTowers;
    }
    else if(obj->oType == ReputationGoal)
    {
        ss << "Achieve Reputation";
        ss1 << "Raise your reputation to " << obj->value << "!";
        ss2 << "(" << GameHUD::getThis()->reputation << "/" << obj->value << ")";
        progressNumber = GameHUD::getThis()->reputation;
    }
    else if(obj->oType == BuildBuilding)
    {
        ss << "Build a Building";
        ss1 << "Build a Building: " << obj->strValue << "!";
        ss2 << "(Build: Incomplete)";
        progressNumber = 0;
    }
    else if(obj->oType == DisplayGoal)
    {
        ss << obj->title;
        ss1 << obj->content;
        ss2 << obj->progress;
    }
    else
    {
        ss << "OBJECTIVE";
        ss1 << "There is no objectives currently!";
        ss2 << "";
        progressNumber = -1;
    }
    
    GameHUD::getThis()->objectiveTitle->setString(ss.str().c_str());
    GameHUD::getThis()->objectiveProgress->setString(ss2.str().c_str());
    
    string objectiveDescription = ss1.str();
    vector<string> objectiveDescriptionTokens = GlobalHelper::split(objectiveDescription, ' ');
    
    CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
    ccColor3B colorWhite = ccc3(255, 255, 255);
    
    float startX = screenSize.width * 0.11f;
    float startY = screenSize.height - 510;
    float offX = 0;
    float offY = 0;
    float limit = 700;
    
    
    string tempString = "";
    string previousString = "";
    for (int i = 0; i < objectiveDescriptionTokens.size(); i++)
    {
        previousString = tempString;
        string temp = objectiveDescriptionTokens.at(i);
        if (i > 0)
        {
            tempString = tempString + " ";
        }
        tempString = tempString + temp;
        CCLabelTTF* tempLabel = CCLabelTTF::create(tempString.c_str(), "Shojumaru-Regular", 28);
        tempLabel->retain();
        if(startX + tempLabel->boundingBox().size.width > limit)
        {
            CCLabelTTF* theLabel = CCLabelTTF::create(previousString.c_str(), "Shojumaru-Regular", 28);
            theLabel->setAnchorPoint(ccp(0, 1));
            theLabel->setPosition(ccp(startX + offX, startY + offY));
            theLabel->setColor(colorWhite);
            GameHUD::getThis()->objectiveDescriptions->addObject(theLabel);
            GameHUD::getThis()->objectiveMenu->addChild(theLabel);
            tempString = temp;
            offY -= 25;
        }
        CC_SAFE_RELEASE(tempLabel);
    }
    
    CCLabelTTF* tempLabel = CCLabelTTF::create(tempString.c_str(), "Shojumaru-Regular", 28);
    tempLabel->setAnchorPoint(ccp(0, 1));
    tempLabel->setPosition(ccp(startX + offX, startY + offY));
    tempLabel->setColor(colorWhite);
    GameHUD::getThis()->objectiveDescriptions->addObject(tempLabel);
    GameHUD::getThis()->objectiveMenu->addChild(tempLabel);
    
    currID = obj->oid;
    nextID = obj->nid;
    
    if(obj->timeLimit > 0)
    {
        ss.str(std::string());
        if(obj->timeLimit < 10)
        {
            ss << "0";
        }
        ss << obj->timeLimit << ":" << "00";
        
        GameHUD::getThis()->objectiveTime->setString(ss.str().c_str());
        GameHUD::getThis()->objectiveTime->setVisible(true);
        GameHUD::getThis()->targetTime = obj->timeLimit * 60.0f;
        GameHUD::getThis()->currentTime = 0;
        GameHUD::getThis()->hasTimer = true;
    }
    else
    {
        GameHUD::getThis()->objectiveTime->setVisible(false);
    }
    
    stringstream sss;
    sss << "You receive a new objective!";
    GameHUD::getThis()->addNewNotification(sss.str());
    
    if(showNotification)
    {
        GameHUD::getThis()->scheduleShowNewObjectiveNotification();
    }
    
    if(obj->scheduleScenario)
    {
        GameHUD::getThis()->hasScenario = true;
        GameHUD::getThis()->scenarioTime = obj->scenarioTime;
    }
}
示例#3
0
文件: Senario.cpp 项目: keyor/Nanhua
void Senario::displayTexts(std::string str, float startX, float startY, string font, float fontSize, ccColor3B color, float limitX)
{
    vector<std::string> tokens = GlobalHelper::split(str, ' ');
    float offX = 0;
    float offY = 0;
    float flashTimeGap = 0.05f;
    int flashGapCount = 0;
    
    for (int i = 0; i < tokens.size(); i++)
    {
        std::string tokenStr = tokens.at(i);
        
        bool hasChinese = false;
        for (int j = 0; j < tokenStr.length(); j++)
        {
            if(tokenStr.at(j) == '^')
            {
                hasChinese = true;
                break;
            }
        }
        
        if (hasChinese)
        {
            int startIndex = 0;
            for (int j = 0; j < tokenStr.length(); j++)
            {
                if(tokenStr.at(j) == '^')
                {
                    string str = tokenStr.substr(startIndex, j - startIndex);
                    
                    CCLabelTTF* tempLabel = CCLabelTTF::create(str.c_str(), font.c_str(), fontSize);
                    tempLabel->retain();
                    
                    if (startX + offX + tempLabel->boundingBox().size.width > limitX)
                    {
                        offY = offY + 35.0f;
                        offX = 0;
                    }
                    
                    CC_SAFE_RELEASE(tempLabel);
                    
                    AnimatedString* as = AnimatedString::create(str, flashTimeGap * flashGapCount, font, fontSize, 80.0f);
                    as->getLabel()->setColor(color);
                    as->getLabel()->setAnchorPoint(ccp(0, 1));
                    
                    as->getLabel()->setPosition(ccp(startX + offX, startY - offY));
                    offX += as->label->boundingBox().size.width;
                    
                    this->addChild(as->getLabel(), 20);
                    animatedStringList->addObject(as);
                    
                    flashGapCount += 1;
                    
                    startIndex = j + 1;
                }
            }
            
            string str = tokenStr.substr(startIndex, tokenStr.length() - startIndex);
            AnimatedString* as = AnimatedString::create(str, flashTimeGap * flashGapCount, font, fontSize, 80.0f);
            as->getLabel()->setColor(color);
            as->getLabel()->setAnchorPoint(ccp(0, 1));
            
            as->getLabel()->setPosition(ccp(startX + offX, startY - offY));
            offX += as->label->boundingBox().size.width;
            
            this->addChild(as->getLabel(), 20);
            animatedStringList->addObject(as);
            
            flashGapCount += 1;
            
            offX += 10;
        }
        else
        {
            CCLabelTTF* tempLabel = CCLabelTTF::create(tokenStr.c_str(), font.c_str(), fontSize);
            tempLabel->retain();
            
            if (startX + offX + tempLabel->boundingBox().size.width > limitX)
            {
                offY = offY + 35.0f;
                offX = 0;
            }
            
            CC_SAFE_RELEASE(tempLabel);
            
            for (int j = 0; j < tokenStr.length(); j++)
            {
                string tempStr = tokenStr.substr(j, 1);
                AnimatedString* as = AnimatedString::create(tempStr, flashTimeGap * (j + flashGapCount), font, fontSize, 80.0f);
                as->getLabel()->setColor(color);
                as->getLabel()->setAnchorPoint(ccp(0, 1));
                
                as->getLabel()->setPosition(ccp(startX + offX, startY - offY));
                offX += as->label->boundingBox().size.width;
                
                this->addChild(as->getLabel(), 20);
                animatedStringList->addObject(as);
            }
            
            flashGapCount += tokenStr.size();
            offX += 10;
        }
    }
}