CCMenuItemSprite * CCMenuItemDynamic::dynamicItemWithText(const char* text,  const char* font, const CCSize &minSize,  const char*normalImage, const char *selectedImage, CCObject* target, SEL_MenuHandler selector, const CCRect& centerRegion, GLubyte opacity) {
	  //Create the label
	  CCLabelBMFont *label = CCLabelBMFont ::labelWithString(text ,font);
	  label ->setOpacity(opacity);

	  //Calculate the Dynamic Button size
	  float minWidth = label->getContentSize().width>minSize.width?label->getContentSize().width:minSize.width;
	  float minHeight = label->getContentSize().height>minSize.height?label->getContentSize().height:minSize.height;

	  CCSize size(minWidth+30,minHeight+24);

	  label->setPosition(ccp(size.width*0.5f, size.height*0.5f));

	  //Sprite normal
	  CCScale9Sprite *normalSprite = CCScale9Sprite::scale9SpriteWithFile(normalImage, centerRegion);	
	  normalSprite ->setContentSize(size);
	  normalSprite ->setOpacity(opacity);
	  //Sprite selected
	  CCScale9Sprite *selectedSprite = NULL;
	  if(selectedImage){
		  selectedSprite = CCScale9Sprite::scale9SpriteWithFile(selectedImage, centerRegion);	
		  selectedSprite ->setContentSize(size);
		  selectedSprite->setOpacity(opacity);
	  }

	  //Create the CCMenuItemSprite
	  CCMenuItemSprite* returnItem = CCMenuItemSprite::itemFromNormalSprite(normalSprite,selectedSprite,target, selector);
	  returnItem->addChild(label);
	  return returnItem;

}
Example #2
0
bool ToTextLayer::DerSelMenu(Script* ts){
	do{
		CC_BREAK_IF(!ts);
		//CCDictionary* attrs = ts->attributes;
		CCArray* scrs = ts->scriptnodes;
		int n = ts->m_snum;
		int maxleng = 0;	/* <最大字长 */

		CCArray* tm = CCArray::createWithCapacity(n);
		for(int i=0;i<n;i++){
			Script* tmp = (Script*) scrs->objectAtIndex(i);		//set more here if you want more.

			float sf = 1;
			CCSprite* spriteNormal; 
			CCSprite* spriteSelected;
			CCSprite* spriteDisabled;

			spriteNormal = CCSprite::create("Images/menuitemsprite2.png", CCRectMake(0,23*2/sf,70/sf,23/sf));
			spriteSelected = CCSprite::create("Images/menuitemsprite2.png", CCRectMake(0,23*1/sf,70/sf,23/sf));
			spriteDisabled = CCSprite::create("Images/menuitemsprite2.png", CCRectMake(0,23*0,70/sf,23/sf));

			SpriteTextMenuItem* item2 = new SpriteTextMenuItem();
			item2->autorelease();
			item2->initWithNormalSprite(spriteNormal, spriteSelected, spriteDisabled,this, menu_selector(ToTextLayer::menucallback) );
			item2->settext(tmp->getstring("content"), FNT_CHN, 24);
			item2->setSData(tmp->getint("jump"));
			item2->setTag(100+i);

			maxleng = max(maxleng, strlen(tmp->getstring("content")));

			tm->insertObject(item2,i);
		}
		sel_menu = MouseMenu::createWithArray(tm);	

		sel_menu->setTouchEnabled(false);
		sel_menu->alignItemsVertically();
		sel_menu->setTag(MENUTAG);
		sel_menu->setPosition(ccp(s.width/2, s.height/2));
		sel_menu->f_setaligntype(1);
		addChild(sel_menu);

		float t_width,t_height;

		t_width = maxleng * 30;
		t_height = n * 30;

		CCScale9Sprite* nback = CCScale9Sprite::create("Images/popup_back.png"); 
		nback->setContentSize(CCSize(t_width+ 23,t_height+ 22));
		nback->setAnchorPoint(ccp(0.5,0.5));
		nback->setPosition(s.width/2, s.height/2 - t_height/2 +30 );
		nback->setOpacity(200);
		nback->setTag(MENUTAG+1);
		addChild(nback,-1);

		e_layerstate = 1;

		return true;
	}while(0);
	return false;
}
Example #3
0
LFToast::LFToast(string msg,float during)
{
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCScale9Sprite* base = CCScale9Sprite::create("toast.png");
	CCLabelTTF* lable = CCLabelTTF::create(
		msg.c_str(),
		fontStr_kaiti,
		30,
		CCSize(base->getContentSize().width - 10,0), 
		kCCTextAlignmentLeft);
	lable->setAnchorPoint(ccp(0,0.5f));
	addChild(base);
	base->setContentSize(CCSizeMake(base->getContentSize().width,lable->getContentSize().height + 20));
	base->setOpacity(0);
	base->addChild(lable);
	lable->setPosition(ccp(10,base->getContentSize().height/2));
	base->setPosition(ccp(visibleSize.width/2,base->getContentSize().height + 20));
	base->runAction(CCSequence::create(
		CCFadeTo::create(0.2f,255),
		CCDelayTime::create(during),
		CCFadeTo::create(0.1f,0),
		CCCallFuncN::create(this,SEL_CallFuncN(&LFToast::removeToast)),
		NULL
		));
}
Example #4
0
void CAIndicator::setOpacity(GLubyte opacity)
{
    CCScale9Sprite* indicator = dynamic_cast<CCScale9Sprite*>(m_pIndicator);
    if (indicator)
    {
        indicator->setOpacity(opacity);
        indicator->setColor(ccc3(opacity, opacity, opacity));
    }
}
Example #5
0
LayerChanToast::LayerChanToast(string message){
	vector<string> lstRegex;
	for( int i = 1; i <= 16; i++ ){
		lstRegex.push_back( CCString::createWithFormat("(%d)", i)->getCString() );
	}

	this->setAnchorPoint(ccp(0, 0));
	// text
	cocos2d::ui::RichText* label = cocos2d::ui::RichText::create();
	label->setAnchorPoint(ccp(0, 0));
	label->setPosition(ccp(0, HEIGHT_DESIGN / 3.5));

	vector<string> lstContents = mUtils::splitStringByListRegex(message, lstRegex);
	int wLabel = 0, hLabel = 0;
	for( int i = 0; i < lstContents.size(); i++ ){
		bool check = false;
		int j = 0;
		for( j = 0; j < lstRegex.size(); j++ )
			if( lstRegex.at(j) == lstContents.at(i) ){
				check = true;
				break;
			}
			if( check ){
				CCArmature *armature = CCArmature::create(CCString::createWithFormat("onion%d", 1)->getCString());
				armature->getAnimation()->playByIndex(j);
				cocos2d::ui::RichElementCustomNode* recustom = cocos2d::ui::RichElementCustomNode::create(1, ccWHITE, 255, armature);
				label->pushBackElement(recustom);
				wLabel += 50;
				hLabel = 55;
			}else{
				CCLabelTTF *l = CCLabelTTF::create(lstContents.at(i).c_str(), "Arial", 16);
				l->setColor(ccc3(204, 16, 85));
				cocos2d::ui::RichElementText* re1 = cocos2d::ui::RichElementText::create(1, ccWHITE, 255, lstContents.at(i).c_str(), "Arial", 16);
				label->pushBackElement(re1);
				wLabel += l->getContentSize().width;
				hLabel = hLabel > 50 ? 55 : l->getContentSize().height;
			}
	}
	this->addChild(label, 1, 0);

	CCSize sizeDesign = CCSize(169, 30);
	CCSpriteBatchNode *batchNode = CCSpriteBatchNode::create("chats/framechat_a.png");
	CCScale9Sprite *blocks = CCScale9Sprite::create();
	blocks ->updateWithBatchNode(batchNode , CCRect(0, 0, sizeDesign.width, sizeDesign.height), false, CCRect(10, 10, sizeDesign.width - 20, sizeDesign.height - 20));

	CCSize size = CCSizeMake(wLabel + 10, hLabel + 5);
	blocks ->setContentSize(size);
	blocks->setAnchorPoint(ccp(0.5, 0.5));
	blocks->setPosition(ccp(label->getPositionX() + wLabel / 2, label->getPositionY() + hLabel / 2));

	blocks->setColor(ccc3(84, 81, 69));
	blocks->setOpacity(200);
	this->setPosition(ccp((WIDTH_DESIGN - size.width) / 2, 100));
	// add
	this->addChild(blocks);
}
void BroadGameRankButton::init( Layer* parentLayer, PokerPlayerRankInfo* ptrFriendInfo, int index, bool isShowFriend )
{
	initWithNormalSprite(m_ptrNormal, m_ptrSelected, NULL, parentLayer, NULL);
	
	PokerPlayerRankInfo friendInfo;
	if(ptrFriendInfo->account_id == GameUtils::s_myInfo.getAccountID())
	{
		friendInfo = *ptrFriendInfo;
		friendInfo.onlineType = OFF_LINE;
		ptrFriendInfo = &friendInfo;
	}

	if (ptrFriendInfo->account_id == GameUtils::s_myInfo.getAccountID())
	{
		CCScale9Sprite* ptrCellBgCover = GameUtils::createScale9("light_blue_bg.png",
			CCRectMake(0,0,88,88),CCRectMake(30,30,25,25));
		ptrCellBgCover->setContentSize(CCSizeMake(434,128));
		ptrCellBgCover->setOpacity(0.5 * 255);
		addChild(ptrCellBgCover);
		LayoutUtil::layoutParentCenter(ptrCellBgCover);
	}

	// Rank
	if(index <= 2 && index >= 0 && ptrFriendInfo->winCount > 0)
	{
		char buf[40] ;
		sprintf(buf,"rank_%d.png",index + 1);
		CCSprite* ptrCupSprite = CREATE_SPRITE(this,buf,true);
		addChild(ptrCupSprite);
		LayoutUtil::layoutParentCenter(ptrCupSprite, -123);
	}
	else if(index <= -1 || ptrFriendInfo->winCount == 0)
	{
		CCLabelTTF* ptrLbRank = CCLabelTTF::create("---",FontConstant::TTF_IMPACT,30);
		addChild(ptrLbRank);
		LayoutUtil::layoutParentCenter(ptrLbRank, -123);
	}
	else
	{
		char buf[10];
		sprintf(buf, "%d", index + 1);
		CCLabelTTF* ptrLbRank = CCLabelTTF::create(buf,FontConstant::TTF_IMPACT,30);
		addChild(ptrLbRank);
		LayoutUtil::layoutParentCenter(ptrLbRank, -123);
	}

	// Head Portrait
	string photoPath;
	GameUtils::getPhotoPath(photoPath,ptrFriendInfo->account_id,ptrFriendInfo->photo);
	CCSprite* ptrHeadSprite = CREATE_SPRITE(this,photoPath.c_str(),true);
	Icon* ptrIcon = Icon::create(86.0f);
	addChild(ptrIcon);
	ptrIcon->setContent(ptrHeadSprite);
	ptrIcon->setStencil(CREATE_SPRITE(this,"photo_mask_clip.png",true));
	LayoutUtil::layoutParentLeft(ptrIcon, 72);
	ptrIcon->setCover(CREATE_SPRITE(this,"photo_mask.png",true));

	// Name
	string name = ptrFriendInfo->account_id == GameUtils::s_myInfo.getAccountID() 
		? GameUtils::s_myInfo.getNickName() : ptrFriendInfo->nickName;
	name = GameUtils::cutName(name,12);
	CCLabelTTF* ptrLbName = CCLabelTTF::create(name.c_str(), FontConstant::TTF_IMPACT, 22);
	ptrLbName->setDimensions(CCSizeMake(145,ptrLbName->getContentSize().height));
	ptrLbName->setHorizontalAlignment(kCCTextAlignmentLeft);
	addChild(ptrLbName);
	LayoutUtil::layoutParentLeftTop(ptrLbName, 172, -10);

	if(!isShowFriend)
	{
		// Win
		CCLabelTTF* ptrLbWin = CCLabelTTF::create(LOCALIZED_STRING("win_label"),
			FontConstant::TTF_IMPACT,24);
		ptrLbWin->setColor(ccc3(255,234,0));
		addChild(ptrLbWin);
		LayoutUtil::layoutParentLeftTop(ptrLbWin, 172, -43);

		// Win Count
		CCLabelTTF* ptrLbWinCount = CCLabelTTF::create(
			Utils::num2strF(ptrFriendInfo->winCount,8,",",false).c_str(), 
			FontConstant::TTF_IMPACT, 22);
		ptrLbWinCount->setColor(ccc3(0,255,255));
		addChild(ptrLbWinCount);
		LayoutUtil::layoutRight(ptrLbWinCount, ptrLbWin);
	}
	else
	{
		if(ptrFriendInfo->onlineType == ON_LINE_NORMAL)
		{
			// Icon
			CCSprite* ptrGreenIcon = CREATE_SPRITE(this, "ico_green.png", true);
			addChild(ptrGreenIcon);
			LayoutUtil::layoutParentLeftTop(ptrGreenIcon, 166, -43);
		}
		else
		{
			CCLabelTTF* ptrLbWin = CCLabelTTF::create(LOCALIZED_STRING("win_label"),
				FontConstant::TTF_IMPACT,24);
			ptrLbWin->setColor(ccc3(255,234,0));
			addChild(ptrLbWin);
			LayoutUtil::layoutParentLeftTop(ptrLbWin, 172, -43);

			CCLabelTTF* ptrLbWinCount = CCLabelTTF::create(
				Utils::num2strF(ptrFriendInfo->winCount,8,",",false).c_str(), 
				FontConstant::TTF_IMPACT,22);
			ptrLbWinCount->setColor(ccc3(0,255,255));
			addChild(ptrLbWinCount);
			LayoutUtil::layoutRight(ptrLbWinCount, ptrLbWin);

			if (ptrFriendInfo->onlineType > ON_LINE_NORMAL)
			{
				CCSprite* ptrStatusBg = CREATE_SPRITE(this,"status_bg.png",false);
				addChild(ptrStatusBg);
				LayoutUtil::layoutBottom(ptrStatusBg,ptrIcon,0,24);

				string path = "in_sng.png";
				if (ptrFriendInfo->onlineType == ON_LINE_SO)
				{
					path = "in_shootout.png";
				}
				CCSprite* ptrOnlineStatus = CREATE_SPRITE(this,path.c_str(),false);	
				ptrStatusBg->addChild(ptrOnlineStatus);
				LayoutUtil::layoutParentCenter(ptrOnlineStatus);
			}
		}
	}

	//line
	CCSprite* ptrBottomLine = CREATE_SPRITE(this,"Images/separator_line_thin.png",true);
	ptrBottomLine->setScaleX(0.328f);
	addChild(ptrBottomLine);
	LayoutUtil::layoutParentBottom(ptrBottomLine,0,-17);
}
Example #7
0
void CAIndicator::setIndicator(const CCSize& parentSize, const CCRect& childrenFrame)
{
    CCScale9Sprite* indicator = dynamic_cast<CCScale9Sprite*>(m_pIndicator);
    
    int x = (int)indicator->getCenterOrigin().x * 10;
    int y = (int)indicator->getCenterOrigin().y * 10;
    
    
    if (m_eType == CAIndicatorTypeHorizontal)
    {
        float size_scale_x = parentSize.width / childrenFrame.size.width;
        size_scale_x = MIN(size_scale_x, 1.0f);
        
        float lenght_scale_x = parentSize.width / 2 - childrenFrame.origin.x;
        lenght_scale_x /= childrenFrame.size.width;
        
        CCSize size = m_obContentSize;
        size.width *= size_scale_x;
        
        if (lenght_scale_x < size_scale_x / 2)
        {
            size.width *= lenght_scale_x / (size_scale_x / 2);
        }
        if (1 - lenght_scale_x < size_scale_x / 2)
        {
            size.width *= (1 - lenght_scale_x) / (size_scale_x / 2);
        }
        size.width = MAX(size.height, size.width);
        indicator->setPreferredSize(size);
        
        CCPoint point = m_obContentSize;
        point.y *= 0.5f;
        point.x *= lenght_scale_x;
        point.x = MAX(point.x, size.width/2);
        point.x = MIN(point.x, m_obContentSize.width - size.width/2);
        indicator->setCenterOrigin(point);
    }
    else if (m_eType == CAIndicatorTypeVertical)
    {
        float size_scale_y = parentSize.height / childrenFrame.size.height;
        size_scale_y = MIN(size_scale_y, 1.0f);
        
        float lenght_scale_y = parentSize.height / 2 - childrenFrame.origin.y;
        lenght_scale_y /= childrenFrame.size.height;
        
        CCSize size = m_obContentSize;
        size.height *= size_scale_y;
        
        if (lenght_scale_y < size_scale_y / 2)
        {
            size.height *= lenght_scale_y / (size_scale_y / 2);
        }
        if (1 - lenght_scale_y < size_scale_y / 2)
        {
            size.height *= (1 - lenght_scale_y) / (size_scale_y / 2);
        }
        size.height = MAX(size.height, size.width);
		indicator->setPreferredSize(size);
        
        
        CCPoint point = m_obContentSize;
        point.x *= 0.5f;
        point.y *= lenght_scale_y;
        point.y = MAX(point.y, size.height/2);
        point.y = MIN(point.y, m_obContentSize.height - size.height/2);
        
        indicator->setCenterOrigin(point);
    }
    
    do
    {
        if (x == (int)indicator->getCenterOrigin().x * 10 && y == (int)indicator->getCenterOrigin().y * 10)
        {
            CC_BREAK_IF(indicator->getActionByTag(0xfff));
            
            CC_BREAK_IF(indicator->getOpacity() < 255);
            
            CCDelayTime* delayTime = CCDelayTime::create(0.2f);
            CCFadeOut* fadeOut = CCFadeOut::create(0.3f);
            CCEaseSineOut* easeSineOut = CCEaseSineOut::create(fadeOut);
            CCSequence* actions = CCSequence::create(delayTime, easeSineOut, NULL);
            actions->setTag(0xfff);
            indicator->runAction(actions);
        }
        else
        {
            CC_BREAK_IF(indicator->getOpacity() == 255);
            
            indicator->stopAllActions();
            indicator->setOpacity(255);
        }
    }
    while (0);
}