void MainLayerZhuangBeiBody::selectAtIndex(unsigned int index)
{
	// 0 是第一个  所有装备
	CCTableViewCell* currentCell = tableView->cellAtIndex(index);
	CCTableViewCell* lastCell = tableView->cellAtIndex(selectedIndex);

	//if (selectedIndex != index)
	{
		if (lastCell!=NULL)
		{
			CCMenuItemImage* itemImage = (CCMenuItemImage*)lastCell->getChildByTag(TAG_MENU)->getChildByTag(lastCell->getIdx());
			int idx = itemImage->getTag();
			itemImage->initWithNormalImage(
				itemFiles[idx].c_str()
				,itemFiles_select[idx].c_str()
				,NULL, this, menu_selector(MainLayerZhuangBeiBody::menuItemClicked));
		}

		if (currentCell!=NULL)
		{
			CCMenuItemImage* itemImage = (CCMenuItemImage*)currentCell->getChildByTag(TAG_MENU)->getChildByTag(currentCell->getIdx());
			int idx = itemImage->getTag();
			itemImage->initWithNormalImage(
				itemFiles_select[idx].c_str()
				,itemFiles[idx].c_str()
				,NULL, this, menu_selector(MainLayerZhuangBeiBody::menuItemClicked));
		}

		selectedIndex = index;

		BaseLayer* content = createContentAtIndex(index);

		if (selectedContaint)
		{
			selectedContaint->removeFromParent();
		}
		if (content)
		{
			container->addChild(content);
			content->setPosition(ccp(0,0));
		}
		selectedContaint = content;
	}
}
예제 #2
0
CCMenuItemImage * CCMenuItemImage::create(const char *normalImage, const char *selectedImage, const char *disabledImage)
{
    CCMenuItemImage *pRet = new CCMenuItemImage();
    if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, NULL, NULL))
    {
        pRet->autorelease();
        return pRet;
    }
    CC_SAFE_DELETE(pRet);
    return NULL;
}
예제 #3
0
CCMenuItemImage * CCMenuItemImage::create(const char *normalImage, const char *selectedImage, const char *disabledImage, CCObject* target, SEL_MenuHandler selector)
{
    CCMenuItemImage *pRet = new CCMenuItemImage();
    if (pRet && pRet->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector))
    {
        pRet->autorelease();
        return pRet;
    }
    CC_SAFE_DELETE(pRet);
    return NULL;
}
예제 #4
0
bool HelpLayer::init()
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(!CCLayer::init());

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

		// 1.黑色半透明背景
		ccColor4B color = ccc4(0, 0, 0, 190);
		setColorLayer(CCLayerColor::create(color));
		m_pColorLayer->setPosition(0, 0);
		m_pColorLayer->setContentSize(size);
		this->addChild(m_pColorLayer, 1);


		// 2.主框架
		setFrame(CCSprite::create());
		m_pFrame->initWithFile(I18N_FILE("StageBase_help_frame.png"));
		m_pFrame->setPosition(ccp(size.width / 2, m_pFrame->boundingBox().size.height / 2 + size.height));
		this->addChild(m_pFrame, 2);

		// 3.退出键
		setMenu(MyMenu::create());
		m_pMenu->setPosition(CCPointZero);	
		m_pFrame->addChild(m_pMenu, 1);
				

		CCMenuItemImage *pBack = new CCMenuItemImage();		
		pBack->initWithNormalImage(
			I18N_FILE("StageBase_help_back_normal.png"),
			I18N_FILE("StageBase_help_back_pressed.png"),
			I18N_FILE("StageBase_help_back_normal.png"),
			this,
			menu_selector(HelpLayer::backCallback));	

		pBack->setPosition(ccp(385, 58));	
		m_pMenu->addChild(pBack);

		// 禁止后层的按键,不写的话得手动remove from dispatcher,否则本类不会被析构
		this->setTouchEnabled(true);

		bRet = true;
	}while(0);

	return bRet;
}
예제 #5
0
void MainLayerStoreFrame::menuItemClicked(CCObject* sender)
{
	CCMenuItemImage* sbItem = (CCMenuItemImage*)mMenu->getChildByTag(TAG_ITEM_ShenBing);
//	CCMenuItemImage* djItem = (CCMenuItemImage*)mMenu->getChildByTag(TAG_ITEM_DAOJU);
	CCMenuItemImage* lbItem = (CCMenuItemImage*)mMenu->getChildByTag(TAG_ITEM_LiBao);
	CCMenuItemImage* czItem = (CCMenuItemImage*)mMenu->getChildByTag(TAG_ITEM_CHONGZHI);

	//初始化所有按钮的图片
	{
		sbItem->initWithNormalImage(
			"shangdian_shenbin_dengdai.png",
			"shangdian_shenbin_anxia.png",
			"shangdian_shenbin_select.png",
			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
// 		djItem->initWithNormalImage(
// 			"shangdian_daoju_dengdai.png",
// 			"shangdian_daoju_anxia.png",
// 			"shangdian_daoju_select.png",
// 			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
		lbItem->initWithNormalImage(
			"shangdian_libao_dengdai.png",
			"shangdian_libao_anxia.png",
			"shangdian_libao_select.png", 
			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
		czItem->initWithNormalImage(
			"shangdian_chongzhi_dengdai.png",
			"shangdian_chongzhi_anxia.png",
			"shangdian_chongzhi_select.png", 
			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
	}

	if(mContentLayer != NULL)
	{
		mContentLayer->removeFromParent();
		mContentLayer = NULL;
	}
	//
	CCSize contentSize = CCSize(mWinSize.width, mBg->getContentSize().height-195-15);
	CCMenuItemImage* item = (CCMenuItemImage*)(sender);
	int tag = item->getTag();
	if (tag == TAG_ITEM_ShenBing)
	{
		ShenBingShangDian *layer = new ShenBingShangDian(mFooterLayer, contentSize);
		mContentLayer = layer;
		addChild(mContentLayer, 1);
		layer->release();
		mContentLayer->setPosition(0, 0);

		//调换图片
		item->initWithNormalImage(
			"shangdian_shenbin_select.png",
			"shangdian_shenbin_anxia.png",
			NULL,
			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
	}
	else if (tag == TAG_ITEM_DAOJU)
	{
		MainLayerStoreDaoju* layer = new MainLayerStoreDaoju(mFooterLayer, contentSize);
		mContentLayer = layer;
		addChild(mContentLayer, 1);
		layer->release();
		mContentLayer->setPosition(0, 0);
		
		//调换图片
		item->initWithNormalImage(
			"shangdian_daoju_select.png",
			"shangdian_daoju_anxia.png",
			NULL,
			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
	}
	else if (tag == TAG_ITEM_LiBao)
	{
		LibaoLayer* layer = new LibaoLayer(mFooterLayer, contentSize);
		mContentLayer = layer;
		addChild(mContentLayer, 1);
		layer->release();
		mContentLayer->setPosition(0, 0);

		//调换图片
		item->initWithNormalImage(
			"shangdian_libao_select.png",
			"shangdian_libao_anxia.png",
			NULL,
			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
	}
	else if (tag == TAG_ITEM_CHONGZHI)
	{
		ChongZhiLayer *layer = new ChongZhiLayer(mFooterLayer, contentSize);
		mContentLayer = layer;
		addChild(mContentLayer, 1);
		layer->release();
		mContentLayer->setPosition(ccp(0,0));

		//调换图片
		item->initWithNormalImage(
			"shangdian_chongzhi_select.png",
			"shangdian_chongzhi_anxia.png",
			NULL,
			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
	}
	
}
예제 #6
0
bool DialogLayer::init()
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(!CCLayer::init());

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

		// 黑色半透明背景
		ccColor4B color = ccc4(0, 0, 0, 190);
		setColorLayer(CCLayerColor::create(color));
		m_pColorLayer->setPosition(0, 0);
		m_pColorLayer->setContentSize(size);
		this->addChild(m_pColorLayer, 1);


		// 主框架
		setFrame(CCSprite::create());
		m_pFrame->initWithFile("Dialog_frame.png");
		m_pFrame->setPosition(ccp(size.width / 2, size.height / 2));
		this->addChild(m_pFrame, 2);

		// 退出键
		setMenu(MyMenu::create());
		m_pMenu->setPosition(CCPointZero);	
		m_pFrame->addChild(m_pMenu, 1);


		CCMenuItemImage *pBack = new CCMenuItemImage();		
		pBack->initWithNormalImage(
			"Dialog_ok_normal.png",
			"Dialog_ok_pressed.png",
			"Dialog_ok_pressed.png",
			this,
			menu_selector(DialogLayer::okCallback));	

		pBack->setPosition(ccp(388, 62));	
		m_pMenu->addChild(pBack);

		// 内容
		setContentLabel(CCLabelTTF::create(" ", FONT_8BITOPERATOR_JVE, 35));	
		ccColor3B ccMyOrange={255, 104, 0};
		CCSize frameSize = m_pFrame->boundingBox().size;
		m_pContentLabel->setPosition(ccp(frameSize.width / 2 - 5, 158));
		m_pContentLabel->setDimensions(CCSizeMake(391, 128));
		m_pContentLabel->setHorizontalAlignment(kCCTextAlignmentCenter);
		m_pContentLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter);
		m_pContentLabel->setColor(ccMyOrange);
		m_pFrame->addChild(m_pContentLabel);

		// 禁止后层的按键,不写的话得手动remove from dispatcher,否则本类不会被析构
		this->setTouchEnabled(true);

		this->setVisible(false);

		bRet = true;
	}while(0);

	return bRet;
}
BaseSprite* MainLayerHerosBaseBody::getItemContentByIndex(unsigned int index)
{

	BaseSprite* bg = BaseSprite::create("duiwu_yingxiong_bg.png");
	bg->setPosition(ccp(bg->getContentSize().width/2,bg->getContentSize().height/2));

	//图片
	{
		ImageData data = ImageManager::getManager()->getImageData_ProfessionHead((Profession)mHerosVec[index]->getActorType());

		CCLOG("----------------->%s",data.getCurrentImageFile().c_str());
		BaseSprite *sprite = BaseSprite::create( data.getCurrentImageFile());
		BaseSprite *sprite2 = BaseSprite::create( data.getCurrentImageFile());
		BaseSprite *sprite3 = BaseSprite::create( data.getCurrentImageFile());
		CCMenuItemSprite* heroItem = CCMenuItemSprite::create(sprite, sprite2, sprite3, this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_heroImg));
		CCMenu* menu = CCMenu::create(heroItem, NULL);
		bg->addChild(menu, 0, TAG_BaseBody_TABLE_HERO_IMG);
		heroItem->setPosition(ccp(74, bg->getContentSize().height/2));
		menu->setPosition(CCPointZero);

		BaseSprite *biankuang = BaseSprite::create("renxing_renwu_touxiang_select.png");
		bg->addChild(biankuang, 1);
		biankuang->setPosition(heroItem->getPosition());
		BaseSprite *item = NULL;
		Profession iType = (Profession)mHerosVec[index]->getActorType();
		if (iType == Profession_Yemanren)
		{
			item = BaseSprite::create("touxiang_jiaobiao_3.png");
		}
		else if (iType == Profession_Chike)
		{
			item = BaseSprite::create("touxiang_jiaobiao_2.png");
		}
		else if (iType == Profession_Fashi)
		{
			item = BaseSprite::create("touxiang_jiaobiao_1.png");
		}
		else if (iType == Profession_Qishi)
		{
			item = BaseSprite::create("touxiang_jiaobiao_3.png");
		}
		else if (iType == Profession_ShenJianShou)
		{
			item = BaseSprite::create("touxiang_jiaobiao_4.png");
		}
		else if (iType == Profession_MiShu)
		{
			item = BaseSprite::create("touxiang_jiaobiao_1.png");
		}
		else if (iType == Profession_WuSeng)
		{
			item = BaseSprite::create("touxiang_jiaobiao_5.png");
		}
		else if (iType == Profession_YouXia)
		{
			item = BaseSprite::create("touxiang_jiaobiao_2.png");
		}
		else if (iType == Profession_LieShou)
		{
			item = BaseSprite::create("touxiang_jiaobiao_4.png");
		}
		else if (iType == Profession_WuShi)
		{
			item = BaseSprite::create("touxiang_jiaobiao_6.png");
		}

		if (item)
		{
			item->setAnchorPoint(ccp(1, 0));
			biankuang->addChild(item);
			item->setPosition(ccp(biankuang->getContentSize().width, 0));
		}		
	}

	//name
	HeroFixedPro info = BaseActorPropertyParser::getParser()->getExtraProerty((Profession)mHerosVec[index]->getActorType());
	LF::lable(bg, info.nameInChinese,ccp(140, 106),22,fontStr_kaiti)->setTag(TAG_BaseBody_LABLE_NAME);

	// 英雄介绍
	{
		Profession profId = mHerosVec[index]->getActorType();
		CCLabelTTF *directionLabel = CCLabelTTF::create(getHeroDirectionByProfessionId(profId).c_str(), fontStr_kaiti, 20, CCSize(380, 0), kCCTextAlignmentLeft);
		bg->addChild(directionLabel, 1, Tag_Label_HeroDirection);
		directionLabel->setColor(ccc3(165, 125, 76));
		directionLabel->setAnchorPoint(ccp(0, 1));
		directionLabel->setPosition(ccp(140, 94));
	}

	if (mFlag == 1)
	{
		CCMenuItemImage* chose = CCMenuItemImage::create(
			"duiwu_yingxiong_weixuanzhong.png"
			, "duiwu_yingxiong_weixuanzhong.png"
			, this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_choseHero));
		chose->setPosition(558, 83);
		CCMenu* menu = CCMenu::create(chose, NULL);
		menu->setPosition(CCPointZero);
		bg->addChild(menu, 0, TAG_Menu);

		CCSprite* unlock = CCSprite::create("duiwu_yingxiong_unlock.png", CCRect(0, 0, 610, 129));
		bg->addChild(unlock, 0, TAG_Unlock);
		unlock->setOpacity(200);
		unlock->setPosition(bg->getPosition());

		int state = mChoseHeroState.at(index);
		if(state>=1 && state<=4) //已选中的
		{
			chose->initWithNormalImage(
				"duiwu_yingxiong_xuanzhong.png"
				, "duiwu_yingxiong_xuanzhong.png"
				, "duiwu_yingxiong_xuanzhong.png"
				, this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_choseHero));
			unlock->setVisible(false);
		}
		else if(state == 0 && mChoseNum<3) //未选中 可选的
		{
			chose->initWithNormalImage(
				"duiwu_yingxiong_daixuan.png"
				, "duiwu_yingxiong_daixuan.png"
				, "duiwu_yingxiong_daixuan.png"
				, this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_choseHero));
			unlock->setVisible(false);
		}

		else						//选满了、不能选的
		{
			bg->initWithFile("duiwu_yingxiong_bg_suoding.png");
		}

	}
	else if (mFlag == 2)
	{
		if (mHerosVec.at(index)->canUnlock())
		{
			//可解锁
			CCMenuItemImage* kjsItem = CCMenuItemImage::create(
				"duiwu_yingxiong_jiesuo.png"
				, "duiwu_yingxiong_jiesuo.png"
				, this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_jiesuoHero));
			kjsItem->setPosition(558, 83);
			kjsItem->setTag(index);
			CCMenu* menu = CCMenu::create(kjsItem, NULL);
			menu->setPosition(CCPointZero);
			bg->addChild(menu, 0, TAG_Menu);
		}
		else //还不能解锁
		{
			//不能解锁
			CCMenuItemImage* kjsItem = CCMenuItemImage::create(
				"duiwu_yingxiong_suoding.png"
				, "duiwu_yingxiong_suoding.png"
				, this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_jiesuoHero));
			kjsItem->setPosition(558, 83);
			kjsItem->setTag(index);
			CCMenu* menu = CCMenu::create(kjsItem, NULL);
			menu->setPosition(CCPointZero);
			bg->addChild(menu, 0, TAG_Menu);

			CCSprite* unlock = CCSprite::create("duiwu_yingxiong_unlock.png", CCRect(0, 0, 610, 129));
			bg->addChild(unlock, 0, TAG_Unlock);
			unlock->setOpacity(200);
			unlock->setPosition(bg->getPosition());
		}

	}
	

	return bg;
}
예제 #8
0
void MainFooterLayer::selectAtIndex(enum_MainLayerIndex index,bool reSelect /* = false */)
{
	//sound
	Music::sharedMusicPlayer()->buttonClicked();

	selectedIndex = index;

	CCMenuItemImage *itemMaoxian = (CCMenuItemImage*)mMenu->getChildByTag(TAG_MENU_MAOXIAN);
	CCMenuItemImage *itemJingji = (CCMenuItemImage*)mMenu->getChildByTag(TAG_MENU_JINGJI);
	CCMenuItemImage *itemZhuye = (CCMenuItemImage*)mMenu->getChildByTag(TAG_MENU_HOME);
	CCMenuItemImage *itemHuodong = (CCMenuItemImage*)mMenu->getChildByTag(TAG_MENU_HUODONG);
	CCMenuItemImage *itemShangdian = (CCMenuItemImage*)mMenu->getChildByTag(TAG_MENU_STORE);
	//初始化所有按钮的图片
	{
		itemZhuye->initWithNormalImage(
			"zhuye_anniu_zhuye.png",
			"zhuye_anniu_zhuye_select.png",
			NULL,
			this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked));

		itemMaoxian->initWithNormalImage(
			"zhuye_anniu_maoxian.png",
			"zhuye_anniu_maoxian_select.png",
			NULL,
			this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked));

		itemJingji->initWithNormalImage(
			"zhuye_anniu_jingji.png",
			"zhuye_anniu_jingji_select.png",
			NULL,
			this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked));

		itemHuodong->initWithNormalImage(
			"zhuye_anniu_huodong.png",
			"zhuye_anniu_huodong_select.png",
			NULL,
			this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked));

		itemShangdian->initWithNormalImage(
			"zhuye_anniu_shangdian.png",
			"zhuye_anniu_shangdian_select.png",
			NULL,
			this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked));
	}

	if(index == mainlayer_MaoXian)
	{
		itemMaoxian->initWithNormalImage(
			"zhuye_anniu_maoxian_select.png",
			"zhuye_anniu_maoxian.png",
			NULL,
			this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked));
	}
	else if(index == mainlayer_JingJiChang_challenge || index == mainlayer_JingJiChang_random)
	{
		itemJingji->initWithNormalImage(
			"zhuye_anniu_jingji_select.png",
			"zhuye_anniu_jingji.png",
			NULL,
			this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked));
	}
	else if(index == mainlayer_HuoDong)
	{
		itemHuodong->initWithNormalImage(
			"zhuye_anniu_huodong_select.png",
			"zhuye_anniu_huodong.png",
			NULL,
			this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked));
	}
	else if(index == mainlayer_ShangDian || index == mainlayer_ChongZhi)
	{
		itemShangdian->initWithNormalImage(
			"zhuye_anniu_shangdian_select.png",
			"zhuye_anniu_shangdian.png",
			NULL,
			this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked));
	}
	else 
	{
		itemZhuye->initWithNormalImage(
			"zhuye_anniu_zhuye_select.png",
			"zhuye_anniu_zhuye.png",
			NULL,
			this,SEL_MenuHandler(&MainFooterLayer::menuItemClicked));
	}

	mCallback->footerItemSelected(index);
}