예제 #1
0
void CGroupInfoScene::CreateGroupGameRoom()
{
	// 最后一个为新加的,draw it
	vector<CGameRoomInfo> &rooms = CGameManager::Instance().GetGameRoomInfo();

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	float w = visibleSize.width/ 2;
	float h = visibleSize.height - 120;

	CCMenuItemImage *pAddItem = CCMenuItemImage::create(
		PATCH_RES_DIR("group_room.png"),
		PATCH_RES_DIR("group_room.png"),
		this,
		menu_selector(CGroupInfoScene::menuEnterGroupGameRoomCallback) );

	h -= (rooms.size()-1) * (pAddItem->getContentSize().height + 5);

	pAddItem->setAnchorPoint( ccp(0, 0) );
	pAddItem->setPosition( ccp(w, h) );
	pAddItem->setUserData( &rooms[rooms.size()-1] );

	CCMenu *pMenu = CCMenu::create( pAddItem, NULL );
	pMenu->setPosition( CCPointZero );
	addChild( pMenu, 1 );
}
예제 #2
0
CCMenuItemImage* Objects2dFactory::imageButton(CCNode* scene, CCMenu* menu, string normalImagePath, string selectedImagePath, string disabledImagePath, 
	float positionX, float positionY, float width, float height, SEL_MenuHandler selector, void* selectorArg, AlignX alignX, AlignY alignY, 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 anchor
	button->setAnchorPoint(ccp(Constants::getAnchorValue(alignX), Constants::getAnchorValue(alignY)));
	
	// Set menu item width
	float buttonWidth = button->boundingBox().size.width;
	if (width > 0) // if width is defined, it is setted
	{
		button->setScaleX(width / buttonWidth);
	}

	// Set menu item height
	float buttonHeight = button->boundingBox().size.height;
	if (height > 0) // if height is defined, it is setted
	{
		button->setScaleY(height / buttonHeight);
	}

	// Add button to the menu
	menu->addChild(button, zOrder);

	return button;
}
예제 #3
0
CCMenuItemImage* Objects2dFactory::clickableRectangle(CCNode* scene, CCMenu* menu, ccColor3B color, float positionX, float positionY, float width, float height, 
	SEL_MenuHandler selector, void* selectorArg, AlignX alignX, AlignY alignY, GLubyte opacity, int zOrder)
{
	// Check arguments validity
	if(scene == NULL || menu == NULL || !selector)
		return NULL;

	// Create a button menu item
    CCMenuItemImage *button = CCMenuItemImage::create("TopQXResources/white.png", "TopQXResources/white.png", "TopQXResources/white.png", scene, selector);
    if(!button)
		return NULL;

	// Set argument
	if (selectorArg != NULL)
	{
		button->setUserData(selectorArg);
	}
	
	// Set color
	button->setColor(color);

	// Set opacity
	button->setOpacity(opacity);

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

	// Set anchor
	button->setAnchorPoint(ccp(Constants::getAnchorValue(alignX), Constants::getAnchorValue(alignY)));
	
	// Set menu item width
	float buttonWidth = button->boundingBox().size.width;
    button->setScaleX(width / buttonWidth);

	// Set menu item height
	float buttonHeight = button->boundingBox().size.height;
	button->setScaleY(height / buttonHeight);
    
	// Add button to the menu
	menu->addChild(button, zOrder);
	
	return button;
}
예제 #4
0
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;
}
bool ChuanqiduanzaoItem::initItem(BaseActor* info)
{
	bool bret = false;

	//初始化背景
	if (CCSprite::initWithFile("shangdian_chuanqi_bg.png"))
	{
		bret = true;
	}

	if (bret)
	{
		m_Profession_id = info->getCurrentProperty().profession;
		//顶部文字显示
		CCLabelTTF* pTopTip = CCLabelTTF::create(LFStrings::getValue("ShenBingDuanZao_ShuoMingTiShi").c_str(), fontStr_kaiti, 18);
		pTopTip->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height-70));
		pTopTip->setColor(fonColor_FaGuang);
		this->addChild(pTopTip);

		//头像
		CCSprite* pIcon = CCSprite::create(this->getIconFileNameByType(info->getActorType()).c_str());
		this->addChild(pIcon);
		pIcon->setPosition(ccp(this->getContentSize().width/2, 400));

		//美术字(英雄类型)
		CCSprite* pHeroType = CCSprite::create(this->getHeroTypeFileNameByType(info->getActorType()).c_str());
		this->addChild(pHeroType);
		pHeroType->setPosition(ccp(this->getContentSize().width/2, 
			pIcon->getPositionY()-pIcon->getContentSize().height/2-pHeroType->getContentSize().height+2));


		//套装名字
		string zhuangBeiStr = ChuanqiPool::getPool()->getChuanQiSuitName(info->getActorType());
		CCLabelTTF* pName = CCLabelTTF::create(zhuangBeiStr.c_str(), fontStr_kaiti, 20);
		pName->setPosition(ccp(this->getContentSize().width/2, 280));
		this->addChild(pName);

		CCMenu* pMenu = CCMenu::create();
		this->addChild(pMenu);
		pMenu->setPosition(CCPointZero);
		//锻造一次
		CCMenuItemImage *yici = CCMenuItemImage::create(
			"shangdian_shenbin_anniu_duanzaoyici.png",
			"shangdian_shenbin_anniu_duanzaoyici_select.png",
			this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_DuanZao));
		pMenu->addChild(yici, 0, Tag_MenuItem_Yici);
		yici->setPosition(ccp(this->getContentSize().width/2-yici->getContentSize().width/2, 185));
		yici->setUserData((void*)info->getActorType());

		//锻造十次
		CCMenuItemImage *shici = CCMenuItemImage::create(
			"shangdian_shenbin_anniu_duanzaoshici.png",
			"shangdian_shenbin_anniu_duanzaoshici_select.png",
			this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_DuanZao));
		pMenu->addChild(shici, 0, Tag_MenuItem_Shici);
		shici->setPosition(ccp(this->getContentSize().width/2+yici->getContentSize().width/2, yici->getPositionY()));
		shici->setUserData((void*)info->getActorType());

		char buf[20];
		//锻造一次需要金币
		BaseSprite *goldIcon1 = BaseSprite::create("jinbi_tubiao.png");
		this->addChild(goldIcon1);
		goldIcon1->setScale(0.5f);
		goldIcon1->setPosition(ccp(yici->getPositionX()-goldIcon1->getContentSize().width/2, yici->getPositionY()+yici->getContentSize().height/2+goldIcon1->getContentSize().height/2));
		sprintf(buf, "%d", 400);
		CCLabelTTF *yiciLabel = CCLabelTTF::create(buf, fontStr_BookAntiqua, 20);
		this->addChild(yiciLabel);
		yiciLabel->setPosition(ccp(goldIcon1->getPositionX()+goldIcon1->getContentSize().width/2*goldIcon1->getScaleX()+yiciLabel->getContentSize().width/2
			, goldIcon1->getPositionY()));
		//锻造十次需要金币
		BaseSprite *goldIcon10 = BaseSprite::create("jinbi_tubiao.png");
		this->addChild(goldIcon10);
		goldIcon10->setScale(0.5f);
		goldIcon10->setPosition(ccp(shici->getPositionX()-goldIcon10->getContentSize().width/2, shici->getPositionY()+shici->getContentSize().height/2+goldIcon10->getContentSize().height/2));
		sprintf(buf, "%d", 400*10);
		CCLabelTTF *yiciLabel0 = CCLabelTTF::create(buf, fontStr_BookAntiqua, 20);
		this->addChild(yiciLabel0);
		yiciLabel0->setPosition(ccp(goldIcon10->getPositionX()+goldIcon10->getContentSize().width/2*goldIcon10->getScaleX()+yiciLabel0->getContentSize().width/2
			, goldIcon10->getPositionY()));

		CCMenuItemImage* pXiaoguo = CCMenuItemImage::create(
			"shandian_anniu_taozhuangxiaoguo.png",
			"shandian_anniu_taozhuangxiaoguo_select.png",
			this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_Xiaoguo)
			);
		pMenu->addChild(pXiaoguo);
		pXiaoguo->setPosition(ccp(this->getContentSize().width/2, pXiaoguo->getContentSize().height/2));
	}

	return bret;
}