コード例 #1
0
ファイル: CCMenuItem.cpp プロジェクト: saranpol/cocos2d-x
bool CCMenuItemImage::initWithNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, CCObject* target, SEL_MenuHandler selector)
{
    CCNode *normalSprite = NULL;
    CCNode *selectedSprite = NULL;
    CCNode *disabledSprite = NULL;

    if (normalImage)
    {
        normalSprite = CCSprite::create(normalImage);
    }

    if (selectedImage)
    {
        selectedSprite = CCSprite::create(selectedImage);
    }
    
    if(disabledImage)
    {
        disabledSprite = CCSprite::create(disabledImage);
    }
    return initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
}
コード例 #2
0
bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback)
{
    Node *normalSprite = nullptr;
    Node *selectedSprite = nullptr;
    Node *disabledSprite = nullptr;

    if (normalImage.size() >0)
    {
        normalSprite = Sprite::create(normalImage);
    }

    if (selectedImage.size() >0)
    {
        selectedSprite = Sprite::create(selectedImage);
    }

    if(disabledImage.size() >0)
    {
        disabledSprite = Sprite::create(disabledImage);
    }
    return initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, callback);
}
コード例 #3
0
ファイル: CCMenuItem.cpp プロジェクト: Ratel13/WarriorQuest
// XXX deprecated
bool MenuItemSprite::initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Ref* target, SEL_MenuHandler selector)
{
	_target = target;
	CC_SAFE_RETAIN(_target);
	return initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, std::bind(selector,target, std::placeholders::_1) );
}
コード例 #4
0
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);
}
コード例 #5
0
bool CCMenuItemImageBMF::init()
{
	return initWithNormalSprite(NULL, NULL, NULL, NULL, NULL);
}