コード例 #1
0
ファイル: StoreAScene.cpp プロジェクト: Obg1/cocos2dx-store
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());
}
コード例 #2
0
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);
}