void MailListScene::callbackSwitch(CCObject* pSender){ CCMenuItemToggle* pSwitch = (CCMenuItemToggle*)pSender; int *idx = (int *)pSwitch->getUserData(); if (idx==NULL) { if (pSwitch->getSelectedIndex()==0) { for(int i=0;i<mArrayList->count();i++) { vUserData[i]=0; } } else { for(int i=0;i<mArrayList->count();i++) { vUserData[i]=1; } } mTableViewMail->refreshData(); } else { if (pSwitch->getSelectedIndex()==0) { *idx = 0; } else { *idx = 1; } } }
void IOSStoreLayer::clickToggleCallBack(CCObject* pObj) { CCLog("menutoggle call back"); CCMenuItemToggle* pToggle = (CCMenuItemToggle*)pObj; int iTag = pToggle->getTag(); int index = pToggle->getSelectedIndex(); switch (iTag) { case kaibaoxiang_toggle_tag: { m_iCurShowNodeIndex = kaibaoxiang_node_index; if (m_enumComeFrom == from_GameInSuperTool) { this->setComefrom(m_enumComeFrom); } else if (m_enumComeFrom == from_SeasonSelector) { this->setComefrom(m_enumComeFrom); } else if (m_enumComeFrom == from_MarketStore) { this->setComefrom(m_enumComeFrom); } else if (m_enumComeFrom == from_GameInHelpMap) { this->setTipBgVisible(true); } this->setLeftTopTipStrVisible(true); this->setADVisible(false); } break; case buystar_toggle_tag: { m_iCurShowNodeIndex = buystar_node_index; this->setLeftTopTipStrVisible(false); this->setTipBgVisible(false); this->setADVisible(true); } break; default: break; } this->setToggleStateByNodeIndex(m_iCurShowNodeIndex); if (index == 1) { if (m_iCurShowNodeIndex == buystar_node_index) { this->replaceLayer(m_pKaibaoxiangNode, m_pBuyStarNode, this, SEL_CallFuncN(&IOSStoreLayer::setTableViewVisble)); } else { this->replaceLayer(m_pBuyStarNode, m_pKaibaoxiangNode, this, SEL_CallFuncN(&IOSStoreLayer::setTableViewVisble)); } } }
void NotificationCenterTest::connectToSwitch(CCObject *sender) { CCMenuItemToggle* item = (CCMenuItemToggle*)sender; bool bConnected = item->getSelectedIndex() == 0 ? false : true; Light* pLight = (Light*)this->getChildByTag(item->getTag()-kTagConnect+kTagLight); pLight->setIsConnectToSwitch(bConnected); }
void MyBuildingCard::toggleDetail(cocos2d::CCNode *pSender) { CCMenuItemToggle* toggle = ((CCMenuItemToggle*)pSender); if(toggle->getSelectedIndex() == 1) { displayDetail(pSender); } else { cancelDetail(pSender); } }
NotificationCenterTest::NotificationCenterTest() : m_bShowImage(false) { CCSize s = CCDirector::sharedDirector()->getWinSize(); CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", this, menu_selector(NotificationCenterTest::toExtensionsMainLayer)); pBackItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); CCMenu* pBackMenu = CCMenu::create(pBackItem, NULL); pBackMenu->setPosition( CCPointZero ); addChild(pBackMenu); CCLabelTTF *label1 = CCLabelTTF::create("switch off", "Marker Felt", 26); CCLabelTTF *label2 = CCLabelTTF::create("switch on", "Marker Felt", 26); CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1); CCMenuItemLabel *item2 = CCMenuItemLabel::create(label2); CCMenuItemToggle *item = CCMenuItemToggle::createWithTarget(this, menu_selector(NotificationCenterTest::toggleSwitch), item1, item2, NULL); // turn on item->setSelectedIndex(1); CCMenu *menu = CCMenu::create(item, NULL); menu->setPosition(ccp(s.width/2+100, s.height/2)); addChild(menu); CCMenu *menuConnect = CCMenu::create(); menuConnect->setPosition(CCPointZero); addChild(menuConnect); for (int i = 1; i <= 3; i++) { Light* light = Light::lightWithFile("Images/Pea.png"); light->setTag(kTagLight+i); light->setPosition(ccp(100, s.height/4*i)); addChild(light); CCLabelTTF *label1 = CCLabelTTF::create("not connected", "Marker Felt", 26); CCLabelTTF *label2 = CCLabelTTF::create("connected", "Marker Felt", 26); CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1); CCMenuItemLabel *item2 = CCMenuItemLabel::create(label2); CCMenuItemToggle *item = CCMenuItemToggle::createWithTarget(this, menu_selector(NotificationCenterTest::connectToSwitch), item1, item2, NULL); item->setTag(kTagConnect+i); item->setPosition(ccp(light->getPosition().x, light->getPosition().y+50)); menuConnect->addChild(item, 0); if (i == 2) { item->setSelectedIndex(1); } bool bConnected = item->getSelectedIndex() == 1 ? true : false; light->setIsConnectToSwitch(bConnected); } CCNotificationCenter::sharedNotificationCenter()->postNotification(MSG_SWITCH_STATE, (CCObject*)(intptr_t)item->getSelectedIndex()); /* for testing removeAllObservers */ CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(NotificationCenterTest::doNothing), "random-observer1", NULL); CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(NotificationCenterTest::doNothing), "random-observer2", NULL); CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(NotificationCenterTest::doNothing), "random-observer3", NULL); }
void ConfigMenu::musicMenuCallback( CCObject* sender ) { CCMenuItemToggle* target = (CCMenuItemToggle*) sender; int item = target->getSelectedIndex();//item为0时,当前背景音乐是关闭的; if(item==0){ GameManager::getInstance()->playerBackgroundMusic(); }else{ GameManager::getInstance()->stopBackgroundMusic(); } }
void ChatLayer::callbackSwitch(CCObject* pSender){ CCMenuItemToggle* pSwitch = (CCMenuItemToggle*)pSender; if (pSwitch->getSelectedIndex()==0) { m_blnRememberMe = false; } else { m_blnRememberMe = true; } }
void MenuLayer::getMusicState(CCObject* pSender){ if (signIn->isVisible() || !canStartGame || signInPrize->isVisible()){ return; } Audio::getInstance()->playSound("Music/paddle_hit.wav"); CCMenuItemToggle* temp = (CCMenuItemToggle*)pSender; if (temp->getSelectedIndex() == 1) { CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); GAMEDATA::getInstance()->setMusicState(false); } if (temp->getSelectedIndex() == 0) { CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); GAMEDATA::getInstance()->setMusicState(true); } }
NotificationCenterTest::NotificationCenterTest() : m_bShowImage(false) { CCSize s = CCDirector::sharedDirector()->getWinSize(); CCMenuItemFont* pBackItem = CCMenuItemFont::itemFromString("Back", this, menu_selector(NotificationCenterTest::toExtensionsMainLayer)); pBackItem->setPosition(ccp(s.width - 50, 25)); CCMenu* pBackMenu = CCMenu::menuWithItems(pBackItem, NULL); pBackMenu->setPosition( CCPointZero ); addChild(pBackMenu); CCLabelTTF *label1 = CCLabelTTF::labelWithString("switch off", "Marker Felt", 26); CCLabelTTF *label2 = CCLabelTTF::labelWithString("switch on", "Marker Felt", 26); CCMenuItemLabel *item1 = CCMenuItemLabel::itemWithLabel(label1); CCMenuItemLabel *item2 = CCMenuItemLabel::itemWithLabel(label2); CCMenuItemToggle *item = CCMenuItemToggle::itemWithTarget(this, menu_selector(NotificationCenterTest::toggleSwitch), item1, item2, NULL); // turn on item->setSelectedIndex(1); CCMenu *menu = CCMenu::menuWithItems(item, NULL); menu->setPosition(ccp(s.width/2+100, s.height/2)); addChild(menu); CCMenu *menuConnect = CCMenu::menuWithItems(NULL); menuConnect->setPosition(CCPointZero); addChild(menuConnect); for (int i = 1; i <= 3; i++) { Light* light = Light::lightWithFile("Images/Pea.png"); light->setTag(kTagLight+i); light->setPosition(ccp(100, s.height/4*i)); addChild(light); CCLabelTTF *label1 = CCLabelTTF::labelWithString("not connected", "Marker Felt", 26); CCLabelTTF *label2 = CCLabelTTF::labelWithString("connected", "Marker Felt", 26); CCMenuItemLabel *item1 = CCMenuItemLabel::itemWithLabel(label1); CCMenuItemLabel *item2 = CCMenuItemLabel::itemWithLabel(label2); CCMenuItemToggle *item = CCMenuItemToggle::itemWithTarget(this, menu_selector(NotificationCenterTest::connectToSwitch), item1, item2, NULL); item->setTag(kTagConnect+i); item->setPosition(ccp(light->getPosition().x, light->getPosition().y+50)); menuConnect->addChild(item, 0); if (i == 2) { item->setSelectedIndex(1); } bool bConnected = item->getSelectedIndex() == 1 ? true : false; light->setIsConnectToSwitch(bConnected); } CCNotificationCenter::sharedNotifCenter()->postNotification(MSG_SWITCH_STATE, (CCObject*)item->getSelectedIndex()); }
// UILabelBMFontTest_Editor void UILabelBMFontTest_Editor::switchLoadMethod(cocos2d::CCObject *pSender) { CCMenuItemToggle *item = (CCMenuItemToggle*)pSender; if (item->getSelectedIndex() == 0){ _layout->removeFromParentAndCleanup(true); _layout = static_cast<Layout*>(GUIReader::getInstance()->widgetFromJsonFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.json")); _touchGroup->addWidget(_layout); this->configureGUIScene(); }else{ _layout->removeFromParentAndCleanup(true); _layout = static_cast<Layout*>(GUIReader::getInstance()->widgetFromBinaryFile("cocosui/UIEditorTest/UILabelBMFont_Editor/ui_labelbmfont_editor_1.csb")); _touchGroup->addWidget(_layout); this->configureGUIScene(); } }
KDvoid OptionsMenu::difficultyToggle ( CCObject* pSender ) { CCMenuItemToggle* pItem = (CCMenuItemToggle*) pSender; m_pMessage->setString ( ccszf ( "Selected Difficulty Index:%d", pItem->getSelectedIndex ( ) ) ); }
void NotificationCenterTest::toggleSwitch(CCObject *sender) { CCMenuItemToggle* item = (CCMenuItemToggle*)sender; int index = item->getSelectedIndex(); CCNotificationCenter::sharedNotificationCenter()->postNotification(MSG_SWITCH_STATE, (CCObject*)(intptr_t)index); }