// on "init" you need to initialize your instance
bool StoreBScene::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !CCLayerColor::initWithColor(ccc4(255,255,255,255)))
	{
		return false;
	}

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

	CCLabelTTF* pLabelTitleTest = CCLabelTTF::create("Soomla Test Store", "GoodDog.otf", 34);
	pLabelTitleTest->setColor(ccc3(255,0,0));
	pLabelTitleTest->setPosition(ccp(pLabelTitleTest->boundingBox().size.width/2 + origin.x + 20, visibleSize.height - 30 + origin.y));
	this->addChild(pLabelTitleTest, 1);

	CCLabelTTF* pLabelTitle = CCLabelTTF::create("Virtual Currency Packs", "GoodDog.otf", 54);
	pLabelTitle->setColor(ccc3(0,0,0));
	pLabelTitle->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height - 100 + origin.y));
	this->addChild(pLabelTitle, 1);


	CCSprite* pSpriteMuffin = CCSprite::create("muffin.png");
	pSpriteMuffin->setScale(0.5f);
	pSpriteMuffin->setPosition(ccp(origin.x + visibleSize.width - 90, visibleSize.height + origin.y - 50));
	this->addChild(pSpriteMuffin, 0);

	pLabelBalance = CCLabelTTF::create("24", "GoodDog.otf", 34);
	pLabelBalance->setColor(ccc3(0,255,255));
	pLabelBalance->setPosition(ccp(origin.x + visibleSize.width - 40, visibleSize.height + origin.y - 50));
	this->addChild(pLabelBalance, 1);
	setCurrencyBalanceLabel();


	GameMenuItem* backItem = GameMenuItem::itemWithLabel(
		CCSprite::create("back.png"),
		this,
		menu_selector(StoreBScene::menuBackCallback));

	backItem->setPosition(ccp(origin.x + visibleSize.width/2 , 110));

	// In Game Menu
	CCMenu* menu = CCMenu::create(backItem, NULL);

	createListViewItem(origin, menu, visibleSize, 0, "no_ads.png");
	createListViewItem(origin, menu, visibleSize, 1, "muffins01.png");
	createListViewItem(origin, menu, visibleSize, 2, "muffins02.png");
	createListViewItem(origin, menu, visibleSize, 3, "muffins03.png");
	createListViewItem(origin, menu, visibleSize, 4, "muffins04.png");

	menu->setPosition(CCPointZero);
	this->addChild(menu);

	this->setKeypadEnabled(true);

	return true;
}
Beispiel #2
0
void StoreAScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img) {
	GameMenuItem *pChooseItem = GameMenuItem::itemWithLabel(
		CCSprite::create("button.png"),
					this,
					menu_selector(StoreAScene::menuChooseCallback));

	string itemId = itemIdFromTag(tag);
	
	// TODO: exception handling ..
    string nameS = cocos2dx_StoreInfo::getGoodName(itemId.c_str());
	string infoS = cocos2dx_StoreInfo::getGoodDescription(itemId.c_str());
	int price = cocos2dx_StoreInfo::getGoodPriceForCurrency(itemId.c_str(), "currency_muffin");
	int balance = 0;
	const char * name = nameS.c_str();
	const char * info = infoS.c_str();
	
	float yOffset = - 200;

	pChooseItem->setPosition(ccp(origin.x + visibleSize.width/2, yOffset + origin.y + visibleSize.height - 100 - (tag * pChooseItem->boundingBox().size.height)));
	pChooseItem->setTag(tag);


	CCSprite* pSpritePic = CCSprite::create(img);
	pSpritePic->setPosition(ccp(pSpritePic->boundingBox().size.width/2 + 20, pChooseItem->boundingBox().size.height/2));
	pChooseItem->addChild(pSpritePic, 0);


	CCLabelTTF* pLabelName = CCLabelTTF::create(name, "GoodDog.otf", 44);
	pLabelName->setColor(ccc3(0,0,0));
	pLabelName->setPosition(ccp(pSpritePic->getPositionX() + (pSpritePic->boundingBox().size.width / 2) + (pLabelName->boundingBox().size.width / 2) + 20 , pChooseItem->boundingBox().size.height/2));
	pChooseItem->addChild(pLabelName);


	CCLabelTTF* pLabelInfo = CCLabelTTF::create(info, "GoodDog.otf", 20);
	pLabelInfo->setColor(ccc3(50,50,50));
	pLabelInfo->setPosition(ccp(pSpritePic->getPositionX() + (pSpritePic->boundingBox().size.width / 2) + (pLabelInfo->boundingBox().size.width / 2) + 20 , -50 + (pChooseItem->boundingBox().size.height/2)));
	pChooseItem->addChild(pLabelInfo);


	CCLabelTTF* pLabelClickToBuy = CCLabelTTF::create("Click to Buy", "GoodDog.otf", 24);
	pLabelClickToBuy->setColor(ccc3(0,255,255));
	pLabelClickToBuy->setPosition(ccp(pChooseItem->boundingBox().size.width - (pLabelClickToBuy->boundingBox().size.width / 2) - 20 , 60 + pChooseItem->boundingBox().size.height/2));
	pChooseItem->addChild(pLabelClickToBuy);

	char buffer[512];

	snprintf(buffer, sizeof(buffer), "price: %d blanace: %d",  price, balance);

	goodsPriceBalanceLabels[tag] = CCLabelTTF::create(buffer, "GoodDog.otf", 24);
	goodsPriceBalanceLabels[tag]->setColor(ccc3(0,255,255));
	goodsPriceBalanceLabels[tag]->setPosition(ccp(pChooseItem->boundingBox().size.width - (goodsPriceBalanceLabels[tag]->boundingBox().size.width / 2) - 20 , 60));
	pChooseItem->addChild(goodsPriceBalanceLabels[tag]);

	menu->addChild(pChooseItem, 1);
	
	setPriceBalanceLabel(itemId.c_str());
}
Beispiel #3
0
/*
 * Control initialization
 */
void OptionsLayer::initControls()
{
	int xPos = 100;
	int fontSize = 35;

	CCSize visibleSize = CCEGLView::sharedOpenGLView()->getVisibleSize();
    
	//Labels
	CCLabelTTF* lblName = sgl_ControlFactory.createTTFLabel("Name:", ccp(xPos, 500));
    this->addChild(lblName);

	CCLabelTTF* lblGoal = sgl_ControlFactory.createTTFLabel("Goals:", ccp(xPos, 400));
	this->addChild(lblGoal);

	CCLabelTTF* lblColor = sgl_ControlFactory.createTTFLabel("Time:", ccp(xPos, 300));
	this->addChild(lblColor);

	//Controls
	int controlLimit = xPos + lblGoal->boundingBox().size.width + 20;

    std::string userName = CCUserDefault::sharedUserDefault()->getStringForKey(USER_DATA_NAME);
    if (userName.empty())
    {
        userName = "******";
    }
    
	CCSize editBoxSize = CCSizeMake(visibleSize.width * 0.2f, 50);
	CCScale9Sprite* sp = CCScale9Sprite::create("textbg.png");
	
	_txtName = CCEditBox::create(editBoxSize, sp);
    _txtName->setPosition(ccp(controlLimit+10, 480));
	_txtName->setFontName(S_F_TYPE.c_str());
	_txtName->setFontSize(fontSize);
    _txtName->setFontColor(ccRED);
	_txtName->setPlaceHolder(userName.c_str());
    _txtName->setPlaceholderFontColor(ccWHITE);
    _txtName->setMaxLength(15);
    _txtName->setReturnType(kKeyboardReturnTypeDone);
    _txtName->setDelegate(this);
	_txtName->setZOrder(1);
    _txtName->setAnchorPoint(ccp(0,0));
	
	addChild(_txtName);

	int goals = CCUserDefault::sharedUserDefault()->getIntegerForKey(GOALS_DATA_NAME);
	if (goals < 1) goals = 10;

	_goalNoSlider = CCControlSlider::create("sliderTrack.png", "sliderProgress.png", "sliderThumb.png");
    
    _goalNoSlider->setTouchEnabled(true);
    _goalNoSlider->setMinimumValue(1.0f); // Sets the min value of range
    _goalNoSlider->setMaximumValue(goals); // Sets the max value of range
    _goalNoSlider->setPosition(ccp(controlLimit+100, 400));
	_goalNoSlider->setAnchorPoint(ccp(0,0));
	_goalNoSlider->addTargetWithActionForControlEvents(this, cccontrol_selector(OptionsLayer::sliderEvent), CCControlEventValueChanged);
	_goalNoSlider->setTag(goalTag);

	_lblGoalSelection = sgl_ControlFactory.createTTFLabel("", ccp(controlLimit+_goalNoSlider->boundingBox().size.width+100, 400));
    this->addChild(_lblGoalSelection);

	_timeSlider = CCControlSlider::create("sliderTrack.png", "sliderProgress.png", "sliderThumb.png");
    
    _timeSlider->setTouchEnabled(true);
    _timeSlider->setPosition(ccp(controlLimit+100, 300));
	_timeSlider->setAnchorPoint(ccp(0,0));
	_timeSlider->addTargetWithActionForControlEvents(this, cccontrol_selector(OptionsLayer::sliderEvent), CCControlEventValueChanged);
	_timeSlider->setTag(timerTag);

    addChild(_goalNoSlider);
	addChild(_timeSlider);
}
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;
    }
}
CCMenuItemImage* Objects2dFactory::textButton(CCNode* scene, CCMenu* menu, string value, string normalImagePath, string selectedImagePath, string disabledImagePath, 
	float positionX, float positionY, float width, float height, SEL_MenuHandler selector, void* selectorArg, AlignX alignX, AlignY alignY, ccColor3B textColor, int zOrder)
{
	// Check arguments validity
	if(scene == NULL ||menu == NULL || !selector)
		return NULL;

	// Create a button menu item
    CCMenuItemImage *button = CCMenuItemImage::create(
        normalImagePath.c_str(),
        selectedImagePath.c_str(),
		disabledImagePath.c_str(),
        scene,
        selector);
    if(!button)
		return NULL;

	if (selectorArg != NULL)
	{
		button->setUserData(selectorArg);
	}

    // Place the menu item in the given position
    button->setPosition(ccp(positionX, positionY));

	// Set menu item anchor
	button->setAnchorPoint(ccp(Constants::getAnchorValue(alignX), Constants::getAnchorValue(alignY)));
	
	// Set menu item height
	float buttonHeight = button->boundingBox().size.height;
	float buttonPosScaleHeight = buttonHeight;
	if (height > 0) // if height is defined, it is setted
	{
		button->setScaleY(height / buttonHeight);
		buttonPosScaleHeight = height;
	}
	
    // Create a label and initialize with the given string
	CCLabelTTF* pLabel = CCLabelTTF::create(value.c_str(), "Arial"/*string(Constants::getResourcesPath() + "SOResources/Fonts/AlphaFridgeMagnetsAllCap.ttf").c_str()*/, 
		buttonPosScaleHeight * 0.6f);
    if(!pLabel)
		return NULL;
	
    // Set color
    pLabel->setColor(textColor);
	
	// Set menu item width
	float buttonWidth = button->boundingBox().size.width;
	float buttonPosScaleWidth = buttonWidth;
	if (width > 0) // if width is defined, it is setted
	{
		button->setScaleX(width / buttonWidth);
		buttonPosScaleWidth = width;
	}
	else // otherwise, we will compare the text width with the button width
	{
		float textWidth = pLabel->boundingBox().size.width;
		if (textWidth * 1.25 > buttonWidth) // if the width adapted to the text is bigger than the button width, adapted width must be setted, otherwise, button width must stay as it was
		{
			button->setScaleX(textWidth * 1.25f / buttonWidth);
			buttonPosScaleWidth = textWidth * 1.25f;
		}
	}
	
    // Place the label; must be in the center of the button
	pLabel->setPosition(ccp(buttonPosScaleWidth * 0.5f * 1/button->getScaleX(), buttonPosScaleHeight * 0.5f * 1/button->getScaleY()));
	
	// Set label centered anchor
	pLabel->setAnchorPoint(ccp(Constants::getAnchorValue(Centered), Constants::getAnchorValue(Middle)));
	
	// Add label to button
	button->addChild(pLabel);

	// Set label scale; the inverse of button scale, so label can be as it would be if it was a child of scene
	pLabel->setScaleY(1/button->getScaleY());
	pLabel->setScaleX(1/button->getScaleX());

	// If label is larger than button
	if (pLabel->boundingBox().size.width * button->getScaleX() > button->boundingBox().size.width)
	{
		// Label must be rescaled
		float newScale = button->boundingBox().size.width / (pLabel->boundingBox().size.width * button->getScaleX());
		pLabel->setScaleX(pLabel->getScaleX() * newScale);
	}

	// Add button to the menu
	menu->addChild(button, zOrder);
	
	return button;
}
Beispiel #6
0
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;
        }
    }
}
void StoreBScene::createListViewItem(CCPoint& origin, CCMenu* menu, CCSize& visibleSize, int tag, const char* img) {
	GameMenuItem *pChooseItem = GameMenuItem::itemWithLabel(
		CCSprite::create("button.png"),
					this,
					menu_selector(StoreBScene::menuChooseCallback));

	string itemId = itemIdFromTag(tag);

	char name[512];
	char info[512];
	double price = 0;
	int balance = 0;
	if (itemId == "ERROR") {
		snprintf(name, sizeof(name), "Remove Ads!");
		snprintf(info, sizeof(info), "Test purchase of MANAGED item.");
		price = 5.99f;
	}
	else {
		// TODO: exception handling ..
	    string nameS = cocos2dx_StoreInfo::getItemName(itemId.c_str());
		string infoS = cocos2dx_StoreInfo::getItemDescription(itemId.c_str());
		price = cocos2dx_StoreInfo::getItemPrice(itemId.c_str());

		snprintf(name, sizeof(name), nameS.c_str());
		snprintf(info, sizeof(info), infoS.c_str());
	}

	float yOffset = - 200;

	pChooseItem->setPosition(ccp(origin.x + visibleSize.width/2, yOffset + origin.y + visibleSize.height - 100 - (tag * pChooseItem->boundingBox().size.height)));
	pChooseItem->setTag(tag);


	CCSprite* pSpritePic = CCSprite::create(img);
	pSpritePic->setPosition(ccp(pSpritePic->boundingBox().size.width/2 + 20, pChooseItem->boundingBox().size.height/2));
	pChooseItem->addChild(pSpritePic, 0);


	CCLabelTTF* pLabelName = CCLabelTTF::create(name, "GoodDog.otf", 44);
	pLabelName->setColor(ccc3(0,0,0));
	pLabelName->setPosition(ccp(pSpritePic->getPositionX() + (pSpritePic->boundingBox().size.width / 2) + (pLabelName->boundingBox().size.width / 2) + 20 , pChooseItem->boundingBox().size.height/2));
	pChooseItem->addChild(pLabelName);


	CCLabelTTF* pLabelInfo = CCLabelTTF::create(info, "GoodDog.otf", 20);
	pLabelInfo->setColor(ccc3(50,50,50));
	pLabelInfo->setPosition(ccp(pSpritePic->getPositionX() + (pSpritePic->boundingBox().size.width / 2) + (pLabelInfo->boundingBox().size.width / 2) + 20 , -50 + (pChooseItem->boundingBox().size.height/2)));
	pChooseItem->addChild(pLabelInfo);


	CCLabelTTF* pLabelClickToBuy = CCLabelTTF::create("Click to Buy", "GoodDog.otf", 24);
	pLabelClickToBuy->setColor(ccc3(0,255,255));
	pLabelClickToBuy->setPosition(ccp(pChooseItem->boundingBox().size.width - (pLabelClickToBuy->boundingBox().size.width / 2) - 20 , 60 + pChooseItem->boundingBox().size.height/2));
	pChooseItem->addChild(pLabelClickToBuy);

	char buffer[512];

	snprintf(buffer, sizeof(buffer), "price: $%.2f",  price);

	CCLabelTTF* pLabelPriceBalance = CCLabelTTF::create(buffer, "GoodDog.otf", 24);
	pLabelPriceBalance->setColor(ccc3(0,255,255));
	pLabelPriceBalance->setPosition(ccp(pChooseItem->boundingBox().size.width - (pLabelPriceBalance->boundingBox().size.width / 2) - 20 , 60));
	pChooseItem->addChild(pLabelPriceBalance);

	menu->addChild(pChooseItem, 1);
}
Beispiel #8
0
// on "init" you need to initialize your instance
bool StoreAScene::init()
{
	cocos2dx_StoreController::storeOpening();
		
	//////////////////////////////
	// 1. super init first
	if ( !CCLayerColor::initWithColor(ccc4(255,255,255,255)))
	{
		return false;
	}

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

	CCLabelTTF* pLabelTitleTest = CCLabelTTF::create("Soomla Test Store", "GoodDog.otf", 34);
	pLabelTitleTest->setColor(ccc3(255,0,0));
	pLabelTitleTest->setPosition(ccp(pLabelTitleTest->boundingBox().size.width/2 + origin.x + 20, visibleSize.height - 30 + origin.y));
	this->addChild(pLabelTitleTest, 1);

	CCLabelTTF* pLabelTitle = CCLabelTTF::create("Virtual Goods", "GoodDog.otf", 54);
	pLabelTitle->setColor(ccc3(0,0,0));
	pLabelTitle->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height - 100 + origin.y));
	this->addChild(pLabelTitle, 1);


	CCSprite* pSpriteMuffin = CCSprite::create("muffin.png");
	pSpriteMuffin->setScale(0.5f);
	pSpriteMuffin->setPosition(ccp(origin.x + visibleSize.width - 90, visibleSize.height + origin.y - 50));
	this->addChild(pSpriteMuffin, 0);
	
	pLabelBalance = CCLabelTTF::create("0", "GoodDog.otf", 34);
	pLabelBalance->setColor(ccc3(0,255,255));
	pLabelBalance->setPosition(ccp(origin.x + visibleSize.width - 40, visibleSize.height + origin.y - 50));
	this->addChild(pLabelBalance, 1);
	setCurrencyBalanceLabel();

	GameMenuItem* getMoreItem = GameMenuItem::itemWithLabel(
		CCSprite::create("get_more.png"),
		this,
		menu_selector(StoreAScene::menuGetMoreCallback));

	getMoreItem->setPosition(ccp(origin.x + visibleSize.width/2 + (getMoreItem->boundingBox().size.width /2) + 10, 110));


	GameMenuItem* backItem = GameMenuItem::itemWithLabel(
		CCSprite::create("back.png"),
		this,
		menu_selector(StoreAScene::menuBackCallback));

	backItem->setPosition(ccp(origin.x + visibleSize.width/2 - (backItem->boundingBox().size.width /2) - 10 , 110));

	// In Game Menu
	CCMenu* menu = CCMenu::create(getMoreItem, backItem, NULL);

	createListViewItem(origin, menu, visibleSize, 0, "fruit_cake.png");
	createListViewItem(origin, menu, visibleSize, 1, "pavlova.png");
	createListViewItem(origin, menu, visibleSize, 2, "cream_cup.png");
	createListViewItem(origin, menu, visibleSize, 3, "chocolate_cake.png");
	
	menu->setPosition(CCPointZero);
	this->addChild(menu);

	this->setKeypadEnabled(true);

	return true;
}