コード例 #1
0
bool GameOverLayer::init()
{
	if ( CCLayerColor::initWithColor( ccc4(255,255,255,255) ) )
	{
		// Get window size and place the label upper. 
		CCSize size = CCDirector::sharedDirector()->getWinSize();

		// 3. Add add a splash screen, show the cocos2d splash image.
		CCSprite* pSprite = CCSprite::create("IntroScene.png");
		if(!pSprite)
			return false;

		// Place the sprite on the center of the screen
		pSprite->setPosition(ccp(size.width/2, size.height/2));

		// Add the sprite to HelloWorld layer as a child layer.
		this->addChild(pSprite, 0);

		//Add the menu choice
		CCMenuItemFont::setFontSize( 100 );
		CCMenuItemFont::setFontName("Courier New");
		CCLabelBMFont* labelNew = CCLabelBMFont::create("Restart Game!", "bitmapFontTest3.fnt");
		CCMenuItemLabel* itemNew = CCMenuItemLabel::create(labelNew, this, menu_selector(GameOverLayer::menuRestartCallback));

		CCLabelBMFont* labelQuit = CCLabelBMFont::create("Quit", "bitmapFontTest3.fnt");
		CCMenuItemLabel* itemQuit = CCMenuItemLabel::create(labelQuit, this, menu_selector(GameOverLayer::menuCloseCallback));

		CCMenu* menu = CCMenu::create( itemNew, itemQuit, NULL);
		menu->alignItemsVerticallyWithPadding(50);

		int i=0;
		CCNode* child;
		CCArray * pArray = menu->getChildren();
		CCObject* pObject = NULL;
		CCARRAY_FOREACH(pArray, pObject)
		{
			if(pObject == NULL)
				break;

			child = (CCNode*)pObject;

			CCPoint dstPoint = child->getPosition();
			int offset = (int) (size.width/2 + 50);
			if( i % 2 == 0)
				offset = -offset;

			child->setPosition( ccp( dstPoint.x + offset, dstPoint.y) );
			child->runAction( 
				CCEaseElasticOut::create(CCMoveBy::create(2, ccp(dstPoint.x - offset,0)), 0.35f) 
				);
			i++;
		}

		addChild(menu);
		menu->setPosition(ccp(size.width/2, size.height/2));

		EntityManager::GetInstance()->SetGameOver(false);

		return true;
	}
コード例 #2
0
ファイル: CCRichLabelTTF.cpp プロジェクト: ourgames/dc208
void CCRichLabelTTF::setLinkTargetForAll(CCCallFunc* func) {
	// if not found, do nothing
    CCMenu* menu = (CCMenu*)getChildByTag(TAG_MENU);
    if(!menu)
        return;
	
	CCObject* obj;
    auto& children = menu->getChildren();
    for (auto child : children)
    {
        CCMenuItemColor* item = (CCMenuItemColor*)child;
        obj = (CCObject*)item->getUserData();
        if(obj) {
            CC_SAFE_RELEASE(obj);
        }
        item->setUserData(func);
        CC_SAFE_RETAIN(func);
    }
//	CCARRAY_FOREACH(menu->getChildren(), obj) {
//		CCMenuItemColor* item = (CCMenuItemColor*)obj;
//		obj = (CCObject*)item->getUserData();
//		if(obj) {
//			CC_SAFE_RELEASE(obj);
//		}
//		item->setUserData(func);
//		CC_SAFE_RETAIN(func);
//	}
}
コード例 #3
0
ファイル: CCRichLabelTTF.cpp プロジェクト: ourgames/dc208
CCRichLabelTTF::~CCRichLabelTTF()
{
    CC_SAFE_DELETE(m_pFontName);
	
	// release callfunc
	CCMenu* menu = (CCMenu*)getChildByTag(TAG_MENU);
	if(menu) {
		CCObject* obj;
        const auto& children = menu->getChildren();
        for (const auto& child : children)
        {
            CCNode* item = (CCNode*)child;
            CCObject* data = (CCObject*)item->getUserData();
            CC_SAFE_RELEASE(data);
        }
//		CCARRAY_FOREACH(menu->getChildren(), obj) {
//			CCNode* item = (CCNode*)obj;
//			CCObject* data = (CCObject*)item->getUserData();
//			CC_SAFE_RELEASE(data);
//		}
	}
	
	// release other
	m_stateListener->release();
}
コード例 #4
0
ファイル: UIScrollLayer.cpp プロジェクト: niuzb/hellopet
	void UIScrollLayer::checkChildrenPos()
	{
		//CCArray* array = m_PageLayer->getChildren();
		CCObject* obj;
		CCARRAY_FOREACH(m_PageLayer,obj)
		{		
			CCLayer* layer = dynamic_cast<CCLayer*>(obj);
			if(layer)
			{
				CCArray* itemArray = layer->getChildren();
				CCObject* itemObj;
				CCARRAY_FOREACH(itemArray,itemObj)
				{
					CCNode* iconButton = dynamic_cast<CCNode*>(itemObj);
					if(iconButton)
					{
						CCArray* menuArray = iconButton->getChildren();
						CCObject* menuObj;
						CCARRAY_FOREACH(menuArray,menuObj)
						{
							CCMenu* menu = dynamic_cast<CCMenu*>(menuObj);
							if(menu)
							{
								CCArray* menuItemArray = menu->getChildren();
								CCObject* menuItmeObj;
								bool claim = false;
								CCARRAY_FOREACH(menuItemArray,menuItmeObj)
								{
									CCMenuItem* item = dynamic_cast<CCMenuItem*>(menuItmeObj);
									if(item)
									{
										CCPoint pt = layer->convertToWorldSpace(menu->getPosition());
										claim = touchIsInContent(pt);
										if(claim)
										{
											break;
										}
									}
								}
								menu->setEnabled(claim);
							}
						}
					}
コード例 #5
0
CCTableViewCell* RequestList::tableCellAtIndex(CCTableView *table, unsigned int idx)
{
    int index = idx;    
    EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(index);
    EziFacebookFriend* sender       = fbRequest->getSender();
    
    const char* senderName = sender->getName();
    
    // Create the fancy test.
    EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType();
    std::string messageToDisplay = "";
    
    switch (requestType)
    {
        case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE:
            messageToDisplay.append(senderName).append(" has sent invitation to you.");
            break;

        case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT:
            messageToDisplay.append(senderName).append(" has sent gift to you.");
            break;

        case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE:
            messageToDisplay.append(senderName).append(" has challenged to you.");
            break;
            
        default:
            messageToDisplay.append("Unknown message");
            break;
    }
    
    // Means users have already used this request.
    bool requestConsumed = fbRequest->isConsumed();
    
    CCSprite* profilePic            = NULL;
    ccColor4B bgColor = ccc4(20, 0, 40, 255);
    
    if (requestConsumed == false)
    {
        bgColor = ccc4(50, 50, 20, 255);
    }

    
    // Build the table cell.
    CCTableViewCell *cell = table->dequeueCell();
    
    if (cell == NULL)
    {
        cell = new CCTableViewCell();
        cell->autorelease();

                
        // Create the back layer of the cell.
        CCLayerColor* colorLayer = CCLayerColor::create(bgColor, SCREEN_WIDTH, CELL_HEIGHT);
        colorLayer->setTag(BACKGROUND_TAG);
        
        cell->addChild(colorLayer);
        
        // Get the sender profile picture path. Create it if path is available.
        if (sender != NULL && strcmp(sender->getPhotoPath(), "") != 0)
        {
            const char*  picPath = sender->getPhotoPath();
            profilePic = CCSprite::create(picPath);
        }
        else
        {
            profilePic = CCSprite::create(FB_DEFAULT_PHOTO);
        }

        // Add the profile pic to the cell row.
        profilePic->setAnchorPoint(ccp(0, 0.5));
        profilePic->setPosition(ccp(20, CELL_HEIGHT/2));
        cell->addChild(profilePic);
        profilePic->setTag(FRIEND_PHOTO_TAG);
        
        // Set the message.
        CCLabelTTF *messageLabel = CCLabelTTF::create(messageToDisplay.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE);
        messageLabel->setAnchorPoint(ccp(0, 0.5));
        messageLabel->setPosition(ccp(20 + 20 + profilePic->getContentSize().width, CELL_HEIGHT/2));
        messageLabel->setTag(REQUEST_MESSAGE_LABEL_TAG);
        messageLabel->setDimensions(CCSizeMake(SCREEN_WIDTH - (profilePic->getContentSize().width * 2) - 60, CELL_HEIGHT-5));
        messageLabel->setHorizontalAlignment(kCCTextAlignmentLeft);
        cell->addChild(messageLabel);

        CCMenuItemImage* constumeItemButton = NULL;
        constumeItemButton = CCMenuItemImage::create("use.png", "use_pressed.png");
        

        constumeItemButton->setTag(idx);
        constumeItemButton->setTarget(this, menu_selector(RequestList::useItem));
        constumeItemButton->setScale(SCALE_FACTOR * 0.8);
        constumeItemButton->setTag(FRIEND_CONSUME_BUTTON_TAG);
        
        CCMenu* consumeMenu = CCMenu::create(constumeItemButton, NULL);
        consumeMenu->setTag(FRIEND_CONSUME_MENU_TAG);
        consumeMenu->setPosition(ccp(SCREEN_WIDTH - (constumeItemButton->getContentSize().width*SCALE_FACTOR*0.4),
                                       (CELL_HEIGHT - (constumeItemButton->getContentSize().height)*SCALE_FACTOR*0.4)));
        
        
        cell->addChild(consumeMenu);
        
        
    }
    else
    {
        // Refresh the cell data based upon idx.
        
        // 1. Refresh the profile picture.
        CCSprite* cellProfilePic = (CCSprite*)cell->getChildByTag(FRIEND_PHOTO_TAG);
        
        if (strcmp("", sender->getPhotoPath()) != 0 )
        {
            const char*  picPath = sender->getPhotoPath();
            profilePic = CCSprite::create(picPath);
            
        }
        else
        {
            profilePic = CCSprite::create(FB_DEFAULT_PHOTO);
        }
        
        cellProfilePic->setTexture(profilePic->getTexture());
        
        // Update the message Label.
        CCLabelTTF *messageLabel = (CCLabelTTF*)cell->getChildByTag(REQUEST_MESSAGE_LABEL_TAG);
        messageLabel->setString(messageToDisplay.c_str());
        
        CCMenu* consumeMenu = (CCMenu*)cell->getChildByTag(FRIEND_CONSUME_MENU_TAG);
        
        CCArray* children = consumeMenu->getChildren();
        
        if (children)
        {
            CCMenuItemImage* consumenButton = (CCMenuItemImage*)children->objectAtIndex(0);
            
            if (consumenButton)
            {
                consumenButton->setTag(index);
            }
            else
            {
                CCLOG("No Consume Button");
            }
            
        }
        
        CCLayerColor* bgLayer = (CCLayerColor*)cell->getChildByTag(BACKGROUND_TAG);
        bgLayer->setColor(ccc3(bgColor.r, bgColor.g, bgColor.b));
    }
    
    return cell;
    
}
コード例 #6
0
ファイル: MenuTest.cpp プロジェクト: charlesa101/cocos2d-x
//------------------------------------------------------------------
//
// MenuLayer1
//
//------------------------------------------------------------------
MenuLayer1::MenuLayer1()
{
	CCMenuItemFont::setFontSize( 30 );
	CCMenuItemFont::setFontName("Courier New");

	// Font Item
	
	CCSprite* spriteNormal = CCSprite::spriteWithFile(s_MenuItem, CGRectMake(0,23*2,115,23));
	CCSprite* spriteSelected = CCSprite::spriteWithFile(s_MenuItem, CGRectMake(0,23*1,115,23));
	CCSprite* spriteDisabled = CCSprite::spriteWithFile(s_MenuItem, CGRectMake(0,23*0,115,23));
	//dynamic_cast<CCNode*>(mgr)->addChild(spriteNormal);
	//dynamic_cast<CCNode*>(mgr)->addChild(spriteSelected);
	//dynamic_cast<CCNode*>(mgr)->addChild(spriteDisabled);

	CCMenuItemSprite* item1 = CCMenuItemSprite::itemFromNormalSprite(spriteNormal, spriteSelected, spriteDisabled, this, menu_selector(MenuLayer1::menuCallback) );
	
	// Image Item
	CCMenuItem* item2 = CCMenuItemImage::itemFromNormalImage(s_SendScore, s_PressSendScore, this, menu_selector(MenuLayer1::menuCallback2) );

	// Label Item (LabelAtlas)
	CCLabelAtlas* labelAtlas = CCLabelAtlas::labelAtlasWithString("0123456789", "fonts/fps_images.png", 16, 24, '.');
	CCMenuItemLabel* item3 = CCMenuItemLabel::itemWithLabel(labelAtlas, this, menu_selector(MenuLayer1::menuCallbackDisabled) );
	item3->setDisabledColor( ccc3(32,32,64) );
	item3->setColor( ccc3(200,200,255) );
	
	// Font Item
	CCMenuItem *item4 = CCMenuItemFont::itemFromString("I toggle enable items", this, menu_selector(MenuLayer1::menuCallbackEnable) );
	
	// Label Item (BitmapFontAtlas)
	CCBitmapFontAtlas* label = CCBitmapFontAtlas::bitmapFontAtlasWithString("configuration", "fonts/bitmapFontTest3.fnt");
	CCMenuItemLabel* item5 = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(MenuLayer1::menuCallbackConfig));

	// Testing issue #500
	item5->setScale( 0.8f );

	// Font Item
	CCMenuItemFont* item6 = CCMenuItemFont::itemFromString("Quit", this, menu_selector(MenuLayer1::onQuit));
	
	CCIntervalAction* color_action = CCTintBy::actionWithDuration(0.5f, 0, -255, -255);
	CCIntervalAction* color_back = color_action->reverse();
	CCFiniteTimeAction* seq = CCSequence::actions(color_action, color_back, NULL);
	item6->runAction(CCRepeatForever::actionWithAction((CCIntervalAction*)seq));

	CCMenu* menu = CCMenu::menuWithItems( item1, item2, item3, item4, item5, item6, NULL);
	menu->alignItemsVertically();
	
	
	// elastic effect
	CGSize s = CCDirector::sharedDirector()->getWinSize();
	
	int i=0;
	CCNode* child;
	NSMutableArray<CCNode*> * pArray = menu->getChildren();
    NSMutableArray<CCNode*>::NSMutableArrayIterator it;

	for(it = pArray->begin(); it != pArray->end(); it++)
	{
		if(*it == NULL)
			break;

		child = (CCNode*)(*it);

		CGPoint dstPoint = child->getPosition();
		int offset = (int) (s.width/2 + 50);
		if( i % 2 == 0)
			offset = -offset;
		
		child->setPosition( CGPointMake( dstPoint.x + offset, dstPoint.y) );
		child->runAction( 
							CCEaseElasticOut::actionWithAction(
																CCMoveBy::actionWithDuration(2, CGPointMake(dstPoint.x - offset,0)), 0.35f
															) 
						);
		i++;
	}

	m_disabledItem = item3; item3->retain();
	m_disabledItem->setIsEnabled( false );

	addChild(menu);

}
コード例 #7
0
ファイル: MenuTest.cpp プロジェクト: DangoXJ/TuJinZhi
//------------------------------------------------------------------
//
// MenuLayerMainMenu
//
//------------------------------------------------------------------
MenuLayerMainMenu::MenuLayerMainMenu()
{
    CCMenuItemFont::setFontSize( 30 );
    CCMenuItemFont::setFontName("Courier New");

    setTouchEnabled(true);
    // Font Item
    
    CCSprite* spriteNormal = CCSprite::create(s_MenuItem, CCRectMake(0,23*2,115,23));
    CCSprite* spriteSelected = CCSprite::create(s_MenuItem, CCRectMake(0,23*1,115,23));
    CCSprite* spriteDisabled = CCSprite::create(s_MenuItem, CCRectMake(0,23*0,115,23));
    //dynamic_cast<CCNode*>(mgr)->addChild(spriteNormal);
    //dynamic_cast<CCNode*>(mgr)->addChild(spriteSelected);
    //dynamic_cast<CCNode*>(mgr)->addChild(spriteDisabled);

    CCMenuItemSprite* item1 = CCMenuItemSprite::create(spriteNormal, spriteSelected, spriteDisabled, this, menu_selector(MenuLayerMainMenu::menuCallback) );
    
    // Image Item
    CCMenuItem* item2 = CCMenuItemImage::create(s_SendScore, s_PressSendScore, this, menu_selector(MenuLayerMainMenu::menuCallback2) );

    // Label Item (LabelAtlas)
    CCLabelAtlas* labelAtlas = CCLabelAtlas::create("0123456789", "fonts/labelatlas.png", 16, 24, '.');
    CCMenuItemLabel* item3 = CCMenuItemLabel::create(labelAtlas, this, menu_selector(MenuLayerMainMenu::menuCallbackDisabled) );
    item3->setDisabledColor( ccc3(32,32,64) );
    item3->setColor( ccc3(200,200,255) );
    
    // Font Item
    CCMenuItemFont *item4 = CCMenuItemFont::create("I toggle enable items", this, menu_selector(MenuLayerMainMenu::menuCallbackEnable) );

    item4->setFontSizeObj(20);
    item4->setFontName("Marker Felt");
    
    // Label Item (CCLabelBMFont)
    CCLabelBMFont* label = CCLabelBMFont::create("configuration", "fonts/bitmapFontTest3.fnt");
    CCMenuItemLabel* item5 = CCMenuItemLabel::create(label, this, menu_selector(MenuLayerMainMenu::menuCallbackConfig));

    // Testing issue #500
    item5->setScale( 0.8f );

    // Events
    CCMenuItemFont::setFontName("Marker Felt");
    CCMenuItemFont *item6 = CCMenuItemFont::create("Priority Test", this, menu_selector(MenuLayerMainMenu::menuCallbackPriorityTest));

    // Font Item
    CCMenuItemFont* item7 = CCMenuItemFont::create("Quit", this, menu_selector(MenuLayerMainMenu::onQuit));
    
    CCActionInterval* color_action = CCTintBy::create(0.5f, 0, -255, -255);
    CCActionInterval* color_back = color_action->reverse();
    CCFiniteTimeAction* seq = CCSequence::create(color_action, color_back, NULL);
    item7->runAction(CCRepeatForever::create((CCActionInterval*)seq));

    CCMenu* menu = CCMenu::create( item1, item2, item3, item4, item5, item6, item7, NULL);
    menu->alignItemsVertically();
    
    
    // elastic effect
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    int i=0;
    CCNode* child;
    CCArray * pArray = menu->getChildren();
    CCObject* pObject = NULL;
    CCARRAY_FOREACH(pArray, pObject)
    {
        if(pObject == NULL)
            break;

        child = (CCNode*)pObject;

        CCPoint dstPoint = child->getPosition();
        int offset = (int) (s.width/2 + 50);
        if( i % 2 == 0)
            offset = -offset;
        
        child->setPosition( CCPointMake( dstPoint.x + offset, dstPoint.y) );
        child->runAction( 
                            CCEaseElasticOut::create(
                                                                CCMoveBy::create(2, CCPointMake(dstPoint.x - offset,0)), 0.35f
                                                            ) 
                        );
        i++;
    }

    m_disabledItem = item3; item3->retain();
    m_disabledItem->setEnabled( false );

    addChild(menu);
    menu->setPosition(ccp(s.width/2, s.height/2));
}
コード例 #8
0
MenuLayerMainMenu::MenuLayerMainMenu(void){
		setTouchEnabled(true);
		setTouchMode(kCCTouchesOneByOne);
		setTouchPriority(kCCMenuHandlerPriority+1);

		CCSprite* itemNor = CCSprite::create(s_MenuItem,CCRectMake(0,23*2,115,23));
		CCSprite* itemSelected = CCSprite::create(s_MenuItem,CCRectMake(0,23*1,115,23));
		CCSprite* itemDisAbled = CCSprite::create(s_MenuItem,CCRectMake(0,23*0,115,23));

		CCMenuItemSprite* menuItem1 = CCMenuItemSprite::create(itemNor,itemSelected,
			itemDisAbled,this,menu_selector(MenuLayerMainMenu::menuChangeUiEditCallBack));
		CCMenuItemImage* menuItem2 = CCMenuItemImage::create("SendScoreButton.png","SendScoreButtonPressed.png",
			this,menu_selector(MenuLayerMainMenu::menuCloseCallback));
		CCMenuItemImage* item3 = CCMenuItemImage::create(
			"CloseNormal.png",
			"CloseSelected.png",
			this,
			menu_selector(MenuLayerMainMenu::menuCloseCallback));
		
		// Font Item
		CCMenuItemFont *item4 = CCMenuItemFont::create("Start Game", this, menu_selector(MenuLayerMainMenu::menuStartGame) );

		item4->setFontSizeObj(30);
		item4->setFontName("Marker Felt");

		CCMenuItemFont *item5 = CCMenuItemFont::create("Quite Game", this, menu_selector(MenuLayerMainMenu::menuCloseCallback) );

		item5->setFontSizeObj(30);
		item5->setFontName("Marker Felt");

		CCMenuItemFont *item6 = CCMenuItemFont::create("Start Shot Plan Game", this, menu_selector(MenuLayerMainMenu::menuStartAirGame) );

		item6->setFontSizeObj(30);
		item6->setFontName("Marker Felt");

		CCSize size = CCDirector::sharedDirector()->getWinSize();

		CCMenu* menu = CCMenu::create(item5,menuItem1,menuItem2,item3,item6,item4,NULL);

		int i=0;
		CCNode* child;
		CCArray * pArray = menu->getChildren();
		CCObject* pObject = NULL;
		CCARRAY_FOREACH(pArray, pObject)
		{
			if(pObject == NULL)
				break;

			child = (CCNode*)pObject;

			CCPoint dstPoint = child->getPosition();
			int offset = (int) (size.width/2 + 50);
			if( i % 2 == 0)
				offset = -offset;

			child->setPosition( ccp( dstPoint.x + offset, i*40 - 40) );
			child->runAction( 
				CCEaseElasticOut::create(CCMoveBy::create(2, ccp(dstPoint.x - offset,0)), 0.35f) 
				);
			i++;
		}


		addChild(menu);
		menu->setPosition(ccp(size.width/2, size.height/2));
}