选项卡的实现有两个特点
1. 被点击的按钮不能再进行点击
setEnabled(false);
2. 其余选项卡应处于可以没被点击的状态(复原),并且可以点击。
setSelectedIndex(0);
setEnabled(true);
e.g.
CCSprite* spButtonN1 = CCSprite::createWithSpriteFrameName("parentsButtonNormal.png");
CCSprite* spButtonS1 = CCSprite::createWithSpriteFrameName("parentsButtonSelected.png");
CCMenuItemSprite* spItemTheGameN = CCMenuItemSprite::create(spButtonN1, NULL);
CCMenuItemSprite* spItemTheGameS = CCMenuItemSprite::create(spButtonS1, NULL);
CCMenuItemToggle* toggleItem1 = CCMenuItemToggle::createWithTarget(this, menu_selector(Parents::menuSelectCallback), spItemTheGameN,spItemTheGameS,NULL);
toggleItem1->setPosition(ccp(frame->getContentSize().width/3.7, frame->getContentSize().height*0.82));
CCSprite* spButtonN2 = CCSprite::createWithSpriteFrameName("parentsButtonNormal.png");
CCSprite* spButtonS2 = CCSprite::createWithSpriteFrameName("parentsButtonSelected.png");
CCMenuItemSprite* spItemAboutUsN = CCMenuItemSprite::create(spButtonN2, NULL);
CCMenuItemSprite* spItemAboutUsS = CCMenuItemSprite::create(spButtonS2, NULL);
CCMenuItemToggle* toggleItem2 = CCMenuItemToggle::createWithTarget(this, menu_selector(Parents::menuSelectCallback), spItemAboutUsN,spItemAboutUsS,NULL);
toggleItem2->setPosition(ccp(frame->getContentSize().width/2.38, frame->getContentSize().height*0.82));
CCSprite* spButtonN3 = CCSprite::createWithSpriteFrameName("parentsButtonNormal.png");
CCSprite* spButtonS3 = CCSprite::createWithSpriteFrameName("parentsButtonSelected.png");
CCMenuItemSprite* spItemLikeTheAppN = CCMenuItemSprite::create(spButtonN3, NULL);
CCMenuItemSprite* spItemLikeTheAppS = CCMenuItemSprite::create(spButtonS3, NULL);
CCMenuItemToggle* toggleItem3 = CCMenuItemToggle::createWithTarget(this, menu_selector(Parents::menuSelectCallback), spItemLikeTheAppN,spItemLikeTheAppS,NULL);
toggleItem3->setPosition(ccp(frame->getContentSize().width/1.76, frame->getContentSize().height*0.82));
m_menu = CCMenu::create();
m_menu->addChild(toggleItem1,1,tagTheGame);
m_menu->addChild(toggleItem2,1,tagAboutUs);
m_menu->addChild(toggleItem3,1,tagLiketheApp);
m_menu->setPosition(CCPointZero);
frame->addChild(m_menu);
void Parents::menuSelectCallback(CCObject* pSender)
{
CCLOG("Touched!");
CCMenuItemToggle* pMenuItemToggle = (CCMenuItemToggle*)pSender;
switch (pMenuItemToggle->getTag())
{
case tagTheGame:
{
pMenuItemToggle->setEnabled(false);
CCMenuItemToggle* tmp = (CCMenuItemToggle*)m_menu->getChildByTag(tagAboutUs);
tmp->setSelectedIndex(0);
tmp->setEnabled(true);
tmp = (CCMenuItemToggle*)m_menu->getChildByTag(tagLiketheApp);
tmp->setSelectedIndex(0);
tmp->setEnabled(true);
}
break;
case tagAboutUs:
{
pMenuItemToggle->setEnabled(false);
CCMenuItemToggle* tmp = (CCMenuItemToggle*)m_menu->getChildByTag(tagTheGame);
tmp->setSelectedIndex(0);
tmp->setEnabled(true);
tmp = (CCMenuItemToggle*)m_menu->getChildByTag(tagLiketheApp);
tmp->setSelectedIndex(0);
tmp->setEnabled(true);
}
break;
case tagLiketheApp:
{
pMenuItemToggle->setEnabled(false);
CCMenuItemToggle* tmp = (CCMenuItemToggle*)m_menu->getChildByTag(tagAboutUs);
tmp->setSelectedIndex(0);
tmp->setEnabled(true);
tmp = (CCMenuItemToggle*)m_menu->getChildByTag(tagTheGame);
tmp->setSelectedIndex(0);
tmp->setEnabled(true);
}
break;
default:
break;
}
}