void COptionsOrganizerDlg::OnButtonMoveUp() { const int selected = getSelectedIndex(); if(selected > 0) { if(m_nameList.move(selected, true)) { updateListCtrl(); setSelectedIndex(m_nameListCtrl, selected-1); } } }
void LLRadioGroup::setIndexEnabled(S32 index, BOOL enabled) { S32 count = 0; for (button_list_t::iterator iter = mRadioButtons.begin(); iter != mRadioButtons.end(); ++iter) { LLRadioCtrl* child = *iter; if (count == index) { child->setEnabled(enabled); if (index == mSelectedIndex && enabled == FALSE) { setSelectedIndex(-1); } break; } count++; } count = 0; if (mSelectedIndex < 0) { // Set to highest enabled value < index, // or lowest value above index if none lower are enabled // or 0 if none are enabled for (button_list_t::iterator iter = mRadioButtons.begin(); iter != mRadioButtons.end(); ++iter) { LLRadioCtrl* child = *iter; if (count >= index && mSelectedIndex >= 0) { break; } if (child->getEnabled()) { setSelectedIndex(count); } count++; } if (mSelectedIndex < 0) { setSelectedIndex(0); } } }
void AutocompletePopupMenuClient::setSuggestions(const WebVector<WebString>& suggestions) { m_suggestions.clear(); for (size_t i = 0; i < suggestions.size(); ++i) m_suggestions.append(suggestions[i]); // Try to preserve selection if possible. if (getSelectedIndex() >= static_cast<int>(suggestions.size())) setSelectedIndex(-1); }
void COptionsOrganizerDlg::OnOK() { int errorLine; if(!m_nameList.validate(errorLine)) { setSelectedIndex(m_nameListCtrl, errorLine); return; } if(m_nameList.save()) { __super::OnOK(); } }
void COptionsOrganizerDlg::OnButtonDelete() { const int selected = getSelectedIndex(); if(selected >= 0) { const bool wasLast = selected == getListSize()-1; m_nameList.remove(selected); updateListCtrl(); if(wasLast && (selected > 0)) { setSelectedIndex(m_nameListCtrl, selected-1); } } }
void ItemContainer::selectNone() { setSelectedIndex(-1); mSelectionStatus = SEL_NONE; if (outfitWindow) outfitWindow->setItemSelected(-1); if (shopWindow) shopWindow->setItemSelected(-1); // if (skillDialog) // skillDialog->setItemSelected(-1); }
void SelectElement::typeAheadFind(SelectElementData& data, Element* element, KeyboardEvent* event) { if (event->timeStamp() < data.lastCharTime()) return; DOMTimeStamp delta = event->timeStamp() - data.lastCharTime(); data.setLastCharTime(event->timeStamp()); UChar c = event->charCode(); String prefix; int searchStartOffset = 1; if (delta > typeAheadTimeout) { prefix = String(&c, 1); data.setTypedString(prefix); data.setRepeatingChar(c); } else { data.typedString().append(c); if (c == data.repeatingChar()) // The user is likely trying to cycle through all the items starting with this character, so just search on the character prefix = String(&c, 1); else { data.setRepeatingChar(0); prefix = data.typedString(); searchStartOffset = 0; } } const Vector<Element*>& items = data.listItems(element); int itemCount = items.size(); if (itemCount < 1) return; int selected = selectedIndex(data, element); int index = (optionToListIndex(data, element, selected >= 0 ? selected : 0) + searchStartOffset) % itemCount; ASSERT(index >= 0); for (int i = 0; i < itemCount; ++i, index = (index + 1) % itemCount) { OptionElement* optionElement = toOptionElement(items[index]); if (!optionElement || items[index]->disabled()) continue; String text = optionElement->textIndentedToRespectGroupLabel(); if (stripLeadingWhiteSpace(text).startsWith(prefix, false)) { setSelectedIndex(data, element, listToOptionIndex(data, element, index)); if (!data.usesMenuList()) listBoxOnChange(data, element); element->setNeedsStyleRecalc(); return; } } }
Menu::Menu() : gcn::Container() , gcn::KeyListener() , items() , selectionListeners() , enableSelectionWrap(true) , selectedIndex(0) { setFocusable(true); setSelectedIndex(0); addKeyListener(this); }
BOOL COptionsOrganizerDlg::OnInitDialog() { __super::OnInitDialog(); m_nameListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT); m_nameListCtrl.InsertColumn( 0,EMPTYSTRING,LVCFMT_LEFT, 200); updateListCtrl(); GetDlgItem(IDC_LISTOPTIONNAMES)->SetFocus(); setSelectedIndex(m_nameListCtrl, 0); ajourButtons(); return FALSE; }
Menu::Menu(const std::vector<std::shared_ptr<MenuItem>> & items) : gcn::Container() , gcn::KeyListener() , items(items) , selectionListeners() , enableSelectionWrap(true) , selectedIndex(0) { setFocusable(true); setSelectedIndex(0); addKeyListener(this); }
void TabPanel::removeTab(const UInt32 TabIndex) { if(TabIndex == getMFTabs()->size()-1 && TabIndex == getSelectedIndex()) { setSelectedIndex(TabIndex-1); } removeObjFromChildren(getTabs(TabIndex)); removeObjFromChildren(getTabContents(TabIndex)); editMFTabs()->erase(editMFTabs()->find(getTabs(TabIndex))); editMFTabContents()->erase(editMFTabContents()->find(getTabContents(TabIndex))); }
void Menu::removeItem(const std::shared_ptr<MenuItem> & item) { if(item) { items.erase( std::remove( std::begin(items), std::end(items), item ), std::end(items) ); remove(item.get()); setSelectedIndex(getSelectedIndex()); } }
void ListBox::setItemText(int index, const TCHAR *str) { int si = getSelectedIndex(); int top = getTopIndex(); LRESULT lresult = SendMessage(m_hwnd, LB_GETTOPINDEX, NULL, NULL); UINT topIndex = (UINT)lresult; _ASSERT(topIndex == lresult); LPARAM data = getItemData(index); removeString(index); insertString(index, str, data); if (si == index) { setSelectedIndex(si); } setTopIndex(top); }
void ItemContainer::mousePressed(gcn::MouseEvent &event) { if (!mInventory) return; const int button = event.getButton(); mClicks = event.getClickCount(); if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT) { const int index = getSlotIndex(event.getX(), event.getY()); if (index == Inventory::NO_SLOT_INDEX) return; Item *item = mInventory->getItem(index); // put item name into chat window if (item && mDescItems && chatWindow) chatWindow->addItemText(item->getInfo().getName()); if (mSelectedIndex == index && mClicks != 2) { mSelectionStatus = SEL_DESELECTING; } else if (item && item->getId()) { setSelectedIndex(index); mSelectionStatus = SEL_SELECTING; int num = itemShortcutWindow->getTabIndex(); if (num >= 0 && num < SHORTCUT_TABS) { if (itemShortcut[num]) itemShortcut[num]->setItemSelected(item); } if (dropShortcut) dropShortcut->setItemSelected(item); if (item->isEquipment() && outfitWindow) outfitWindow->setItemSelected(item); if (shopWindow) shopWindow->setItemSelected(item->getId()); } else { selectNone(); } } }
void AutoFillPopupMenuClient::setSuggestions(const WebVector<WebString>& names, const WebVector<WebString>& labels) { ASSERT(names.size() == labels.size()); m_names.clear(); m_labels.clear(); for (size_t i = 0; i < names.size(); ++i) { m_names.append(names[i]); m_labels.append(labels[i]); } // Try to preserve selection if possible. if (getSelectedIndex() >= static_cast<int>(names.size())) setSelectedIndex(-1); }
BOOL LLRadioGroup::setSelectedByValue(const LLSD& value, BOOL selected) { S32 idx = 0; for (button_list_t::const_iterator iter = mRadioButtons.begin(); iter != mRadioButtons.end(); ++iter) { if((*iter)->getPayload().asString() == value.asString()) { setSelectedIndex(idx); return TRUE; } idx++; } return FALSE; }
void Menu::selectPreviousItem() { if(getItemCount() > 1) { int startingPoint = getSelectedIndex(); int previousIndex = getPreviousIndex(startingPoint); while(previousIndex != startingPoint) { if(items.at(previousIndex)->isEnabled()) { setSelectedIndex(previousIndex); break; } previousIndex = getPreviousIndex(previousIndex); } } // Don't do anything if there is only 1 or 0 items }
void ComboBox::keyDown(int keyCode, char character) { if ((this != Control::getFocus()) || (!_pnlOptions.isVisible())) { return; } int change = 0; switch (keyCode) { case VK_RETURN: case VK_SPACE: setSelectedIndex(_listIndex); return; case VK_DOWN: change = 1; break; case VK_UP: change = -1; break; default: return; } vector<Control*> controls; _pnlOptions.getAllControls(&controls); controls[_listIndex]->setBackground(getBackground()); controls[_listIndex]->setForeground(getForeground()); if ((change == -1) && (_listIndex == 0)) { _listIndex = controls.size() - 1; } else { _listIndex = (_listIndex + change) % controls.size(); } controls[_listIndex]->setBackground(getForeground()); controls[_listIndex]->setForeground(getBackground()); }
BOOL LLRadioGroup::setSelectedByValue(LLSD value, BOOL selected) { S32 idx = 0; std::string value_string = value.asString(); for (button_list_t::const_iterator iter = mRadioButtons.begin(); iter != mRadioButtons.end(); ++iter) { if((*iter)->getName() == value_string) { setSelectedIndex(idx); return TRUE; } idx++; } return FALSE; }
void TabPanel::handleTabFocusGained(FocusEventDetails* const e) { ComponentRefPtr Tab = dynamic_cast<Component*>(e->getSource()); Int32 index(-1); for (UInt32 i = 0; i < getMFTabs()->size(); ++i) { if(editMFTabs()->find(Tab) == editMFTabs()->find(getTabs(i))) { index = i; } } if (index != -1) { setSelectedIndex(index); } }
void TopMenu::initView() { Size visibleSize = Director::getInstance()->getVisibleSize(); ///暂停按钮 MenuItemImage* btnPause = MenuItemImage::create("images/pause.png","images/pause_s.png",CC_CALLBACK_0(TopMenu::pauseGame,this)); Menu* menuPause = Menu::create(btnPause,NULL); menuPause->alignItemsVertically(); menuPause->setPosition(60.0f,visibleSize.height - 50.0f); this->addChild(menuPause,1,100); this->m_menuBtnPause = menuPause; ///声音 //音乐 auto musicOnMenuItem =MenuItemImage::create("images/ico_audio_on.png","images/ico_audio_on.png"); auto musicOffMenuItem =MenuItemImage::create("images/ico_audio_off.png","images/ico_audio_off.png"); auto musicToggleMenuItem = MenuItemToggle::createWithCallback(CC_CALLBACK_1(TopMenu::menuMusicToggleCallback,this),musicOnMenuItem,musicOffMenuItem,NULL ); auto menuMusic = Menu::create(musicToggleMenuItem, nullptr ); menuMusic->setPosition(visibleSize.width - 70.0f,visibleSize.height - 50.0f); this->addChild(menuMusic); musicToggleMenuItem->setSelectedIndex((Audio::getInstance()->getbIsOpenMusic() ? 0 : 1)); ///技能0,刷子 ///技能1,重新排列 ///技能2,炸弹 #if 0 MenuItemImage* btnSkill0 = MenuItemImage::create("images/Props_Paint.png","images/Props_Paint_s.png",CC_CALLBACK_0(TopMenu::pauseGame,this)); MenuItemImage* btnSkill1 = MenuItemImage::create("images/Props_Rainbow.png","images/Props_Rainbow_s.png",CC_CALLBACK_0(TopMenu::pauseGame,this)); MenuItemImage* btnSkill2 = MenuItemImage::create("images/Props_Bomb.png","images/Props_Bomb_s.png",CC_CALLBACK_0(TopMenu::pauseGame,this)); Menu* menuSkill= Menu::create(btnSkill0,btnSkill1,btnSkill2,NULL); menuSkill->alignItemsHorizontallyWithPadding(40.0f); menuSkill->setPosition(visibleSize.width - 220.0f,visibleSize.height - 200.0f); this->addChild(menuSkill); #endif this->initScore(); }
void CMakeAviDlg::OnEditDeleteSelected() { int index = getSelectedIndex(); if(index >= 0) { m_nameArray.removeIndex(index); m_nameList.DeleteItem(index); if(m_nameArray.size() > 0) { index = min(index, (int)m_nameArray.size()-1); loadPicture(m_nameArray[index]); if(m_currentPicture.isLoaded()) { setSelectedIndex(m_nameList, index); } } else { unloadPicture(); } updateWindowState(); updatePreview(); } }
void QvisColorGridWidget::keyPressEvent(QKeyEvent *e) { QColor temp; int column = activeIndex() % numColumns; int row = activeIndex() / numColumns; // Handle the key strokes. switch(e->key()) { case Qt::Key_Escape: // emit an empty color. emit selectedColor(temp); break; case Qt::Key_Return: case Qt::Key_Enter: setSelectedIndex(activeIndex()); break; case Qt::Key_Left: if(column == 0) setActiveIndex(getIndex(row, numColumns - 1)); else setActiveIndex(getIndex(row, column - 1)); break; case Qt::Key_Right: if(column == numColumns - 1) setActiveIndex(getIndex(row, 0)); else setActiveIndex(getIndex(row, column + 1)); break; case Qt::Key_Up: if(row == 0) setActiveIndex(getIndex(numRows - 1, column)); else setActiveIndex(getIndex(row - 1, column)); break; case Qt::Key_Down: if(row == numRows - 1) setActiveIndex(getIndex(0, column)); else setActiveIndex(getIndex(row + 1, column)); break; } }
void QvisColorGridWidget::setSelectedColor(const QColor &color) { // Figure out the index of the color. If it is not in the palette, we'll // end up unselecting the currently selected color. int index = -1; bool notFound = true; for(int i = 0; i < numGridSquares && notFound; ++i) { if(color == paletteColors[i]) { index = i; notFound = false; } } // Set the selected color. setSelectedIndex(index); }
void SelectElement::accessKeySetSelectedIndex(SelectElementData& data, Element* element, int index) { // first bring into focus the list box if (!element->focused()) element->accessKeyAction(false); // if this index is already selected, unselect. otherwise update the selected index const Vector<Element*>& items = data.listItems(element); int listIndex = optionToListIndex(data, element, index); if (OptionElement* optionElement = (listIndex >= 0 ? toOptionElement(items[listIndex]) : 0)) { if (optionElement->selected()) optionElement->setSelectedState(false); else setSelectedIndex(data, element, index, false, true); } listBoxOnChange(data, element); scrollToSelection(data, element); }
bool HTMLSelectElement::platformHandleKeydownEvent(KeyboardEvent* event) { // Allow (Shift) F4 and (Ctrl/Shift) Alt/AltGr + Up/Down arrow to pop the menu, matching Firefox. bool eventShowsMenu = (!event->altKey() && !event->ctrlKey() && event->keyIdentifier() == "F4") || ((event->altGraphKey() || event->altKey()) && (event->keyIdentifier() == "Down" || event->keyIdentifier() == "Up")); if (!eventShowsMenu) return false; // Save the selection so it can be compared to the new selection when dispatching change events during setSelectedIndex, // which gets called from RenderMenuList::valueChanged, which gets called after the user makes a selection from the menu. saveLastSelection(); if (RenderMenuList* menuList = toRenderMenuList(renderer())) menuList->showPopup(); int index = selectedIndex(); ASSERT(index >= 0); ASSERT_WITH_SECURITY_IMPLICATION(index < static_cast<int>(listItems().size())); setSelectedIndex(index); event->setDefaultHandled(); return true; }
void QvisColorGridWidget::mousePressEvent(QMouseEvent *e) { if(e->button() == Qt::RightButton) { int index = getIndexFromXY(e->x(), e->y()); // If a valid color index was returned, select the color. if(index != -1) { // Set the selected color. setSelectedIndex(index); // Emit a signal that allows us to activate a menu. int row, column; QPoint center(e->x(), e->y()); getRowColumnFromIndex(currentSelectedItem, row, column); emit activateMenu(selectedColor(), row, column, mapToGlobal(center)); } } }
void ItemContainer::mousePressed(gcn::MouseEvent &event) { const int button = event.getButton(); if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT) { const int index = getSlotIndex(event.getX(), event.getY()); if (index == Inventory::NO_SLOT_INDEX) return; Item *item = mInventory->getItem(index); // put item name into chat window if (mDescItems) { chatWindow->addItemText(item->getInfo().getName()); } if (mSelectedIndex == index) { mSelectionStatus = SEL_DESELECTING; } else if (item && item->getId()) { setSelectedIndex(index); mSelectionStatus = SEL_SELECTING; itemShortcut->setItemSelected(item->getId()); if (item->isEquipment()) outfitWindow->setItemSelected(item->getId()); } else { selectNone(); } } }
bool MainMenu::init() { if(!LayerColor::initWithColor(MENU_BACKGROUND_COLOR)) { return false; } auto titleFinalPosition = Point(VisibleRect::top().x, 1920 - 202); auto titleSprite = sprite("Title", Point(titleFinalPosition.x, titleFinalPosition.y + 300)); addChild(titleSprite); titleSprite->runAction(EaseSineOut::create(MoveTo::create(DEFAULT_ANIMATION_TIME, titleFinalPosition))); auto menuBackground = sprite("MenuBackground", Point(VisibleRect::center().x, 1920 - 966)); menuBackground->setScale(1.0f, 0.1); menuBackground->runAction(ScaleTo::create(DEFAULT_ANIMATION_TIME, 1.0f)); addChild(menuBackground); auto arcadeButtonFinalPosition = Point(335, 1288); auto arcadeButton = MenuItemSprite::create(sprite("ArcadeButtonNormal"), sprite("ArcadeButtonPressed"), [=] (Ref* sender) { auto userDefault = UserDefault::getInstance(); userDefault->setIntegerForKey("mode", GameMode::ARCADE); onPlayPress(sender); }); arcadeButton->setPosition(arcadeButtonFinalPosition.x, arcadeButtonFinalPosition.y + 2000); arcadeButton->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME), EaseBounceOut::create(MoveTo::create(DEFAULT_ANIMATION_TIME, arcadeButtonFinalPosition)), CallFunc::create([=](){ arcadeButton->runAction(RepeatForever::create(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 4), RotateTo::create(DEFAULT_ANIMATION_TIME / 2, TILE_ROTATION_DEGREE), RotateTo::create(DEFAULT_ANIMATION_TIME, -TILE_ROTATION_DEGREE),RotateTo::create(DEFAULT_ANIMATION_TIME / 2, 0.0f),NULL))); }), NULL) ); auto timeAttackButtonFinalPosition = Point(788, 1920 - 932); auto timeAttackButton = MenuItemSprite::create(sprite("TimeAttackButtonNormal"), sprite("TimeAttackButtonPressed"), [=] (Ref* sender) { auto userDefault = UserDefault::getInstance(); userDefault->setIntegerForKey("mode", GameMode::TIME_ATTACK); onPlayPress(sender); }); timeAttackButton->setPosition(timeAttackButtonFinalPosition.x, timeAttackButtonFinalPosition.y + 2000); timeAttackButton->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 2), EaseBounceOut::create(MoveTo::create(DEFAULT_ANIMATION_TIME, timeAttackButtonFinalPosition)), CallFunc::create([=](){ timeAttackButton->runAction(RepeatForever::create(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 4), RotateTo::create(DEFAULT_ANIMATION_TIME / 2, TILE_ROTATION_DEGREE), RotateTo::create(DEFAULT_ANIMATION_TIME, -TILE_ROTATION_DEGREE),RotateTo::create(DEFAULT_ANIMATION_TIME / 2, 0.0f),NULL))); }), NULL) ); auto zenButtonFinalPosition = Point(335, 1920 - 1251); auto zenButton = MenuItemSprite::create(sprite("ZenButtonNormal"), sprite("ZenButtonPressed"), [=] (Ref* sender) { auto userDefault = UserDefault::getInstance(); userDefault->setIntegerForKey("mode", GameMode::ZEN); onPlayPress(sender); }); zenButton->setPosition(zenButtonFinalPosition.x, zenButtonFinalPosition.y + 2000); zenButton->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 3), EaseBounceOut::create(MoveTo::create(DEFAULT_ANIMATION_TIME, zenButtonFinalPosition)), CallFunc::create([=](){ zenButton->runAction(RepeatForever::create(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 4), RotateTo::create(DEFAULT_ANIMATION_TIME / 2, TILE_ROTATION_DEGREE), RotateTo::create(DEFAULT_ANIMATION_TIME, -TILE_ROTATION_DEGREE),RotateTo::create(DEFAULT_ANIMATION_TIME / 2, 0.0f),NULL))); }), NULL) ); auto arcadeLabel = label("ARCADE")->size(MENU_FONT_SIZE)->position(Point(timeAttackButtonFinalPosition.x, arcadeButtonFinalPosition.y))->color(ARCADE_TEXT_COLOR)->addTo(this); arcadeLabel->setVisible(false); arcadeLabel->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 3), Show::create(), NULL)); auto timeAttackLabel = label(" TIME\nATTACK")->size(MENU_FONT_SIZE)->position(Point(arcadeButtonFinalPosition.x, timeAttackButtonFinalPosition.y))->color(TIME_ATTACK_TEXT_COLOR)->addTo(this); timeAttackLabel->setVisible(false); timeAttackLabel->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 4), Show::create(), NULL)); auto zenLabel = label("ZEN")->size(MENU_FONT_SIZE)->position(Point(timeAttackButtonFinalPosition.x, zenButtonFinalPosition.y))->color(ZEN_TEXT_COLOR)->addTo(this); zenLabel->setVisible(false); zenLabel->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 5), Show::create(), NULL)); auto soundManager = SoundManager::sharedSoundManager(); auto soundButtonOn = MenuItemSprite::create(sprite("SoundButtonOn"), nullptr); auto soundButton = MenuItemToggle::createWithCallback([=](Ref* sender) { auto button = (MenuItemToggle*) sender; if(button->getSelectedItem() == soundButtonOn) { soundManager->unmuteSound(); } else { soundManager->muteSound(); } playSoundEffect("Click"); }, soundButtonOn, MenuItemSprite::create(sprite("SoundButtonOff"), nullptr), NULL); if(soundManager->isSoundEnabled()) { soundButton->setSelectedIndex(0); } else { soundButton->setSelectedIndex(1); } soundButton->setPosition(Point(291, 1920 - 1710)); #if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) auto leaderBoardButton = MenuItemSprite::create(sprite("LeaderboardButtonNormal"), sprite("LeaderboardButtonPressed"), [=] (Ref* sender) { playSoundEffect("Click"); NativeUtils::showLeaderboards(); }); leaderBoardButton->setPosition(Point(796, 1920 - 1710)); auto menu = Menu::create(arcadeButton, timeAttackButton, zenButton, soundButton, leaderBoardButton, NULL); menu->setPosition(Point::ZERO); addChild(menu); #else auto menu = Menu::create(arcadeButton, timeAttackButton, zenButton, soundButton, NULL); menu->setPosition(Point::ZERO); addChild(menu); #endif runAction(RepeatForever::create(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 12), CallFunc::create([=] () { playSoundEffect("Giggle"); }) , NULL))); return true; }
bool GameMenu::init() { if (!Layer::init()) { return false; } //加载音效 Tools::preloadMusic(); if (DataModel::isMusic) { if (!CocosDenshion::SimpleAudioEngine::getInstance()->isBackgroundMusicPlaying()) { CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("music_menu.mp3",true); } } auto winSize = Director::getInstance()->getWinSize(); auto pSprite = Sprite::create("menu_bg.png"); pSprite->setPosition(Vec2(winSize.width/2,winSize.height/2)); this->addChild(pSprite); //主菜单 //--普通模式 auto newgameNormal = Sprite::create("menu_newgame.png"); auto newgamePressed = Sprite::create("menu_newgame.png"); newgamePressed->setScale(1.2f); auto pNewGameItem = MenuItemSprite::create( newgameNormal, newgamePressed, nullptr, CC_CALLBACK_1(GameMenu::menuNewGame,this)); pNewGameItem->setPosition(Vec2(winSize.width-250,winSize.height/2)); pNewGameItem->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); //--专家模式 auto expertNormal = Sprite::create("menu_expert.png"); auto expertPressed = Sprite::create("menu_expert.png"); expertPressed->setScale(1.2f); auto pExpertItem = MenuItemSprite::create( expertNormal, expertPressed, nullptr, CC_CALLBACK_1(GameMenu::menuExpertGame,this)); pExpertItem->setPosition(Vec2(winSize.width-250,winSize.height/2 - 75)); pExpertItem->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); //--商店 auto pStoreNormal = Sprite::create("menu_store.png"); auto pStorePressed = Sprite::create("menu_store.png"); pStorePressed->setScale(1.2f); auto pStoreItem = MenuItemSprite::create( pStoreNormal, pStorePressed, nullptr, CC_CALLBACK_1(GameMenu::menuStore,this)); pStoreItem->setPosition(Vec2(winSize.width-250,winSize.height/2 -75*2)); pStoreItem->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT); //--其他 auto pOtherNormal = Sprite::create("menu_setting.png"); auto pOtherPressed = Sprite::create("menu_setting.png"); pOtherPressed->setScale(1.2f); auto pOtherItem = MenuItemSprite::create( pOtherNormal, pOtherPressed, nullptr, CC_CALLBACK_1(GameMenu::menuSystem,this)); pOtherItem->setPosition(Vec2(80,winSize.height-10)); pOtherItem->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT); pMenu = Menu::create(pNewGameItem,pExpertItem,pStoreItem,pOtherItem,nullptr); pMenu->setPosition(Vec2::ZERO); this->addChild(pMenu,1); //--系统 systemBg = Sprite::create("system_bg.png"); systemBg->setPosition(Vec2( pOtherItem->getPositionX()-pOtherItem->getContentSize().width/2, pOtherItem->getPositionY()-pOtherItem->getContentSize().height)); systemBg->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP); this->addChild(systemBg); //先隐藏起来 isShowSystem = false; systemBg->setScale(0); //--声音选项 auto soundOff = Sprite::create("sound.png"); auto ban = Sprite::create("ban.png"); ban->setPosition(Vec2(soundOff->getContentSize().width/2,soundOff->getContentSize().height/2)); soundOff->addChild(ban); auto pSubSoundOffItem = MenuItemSprite::create(soundOff,nullptr); auto pSubSoundOpenItem = MenuItemSprite::create(Sprite::create("sound.png"),nullptr); auto pSoundItem = MenuItemToggle::createWithCallback(CC_CALLBACK_0(GameMenu::menuSetSound,this),pSubSoundOffItem,pSubSoundOpenItem,nullptr); pSoundItem->setSelectedIndex(DataModel::isSound); //--音乐开关子选项 auto musicOff = Sprite::create("music.png"); auto musicban = Sprite::create("ban.png"); musicban->setPosition(Vec2(musicOff->getContentSize().width/2,musicOff->getContentSize().height/2)); musicOff->addChild(musicban); auto pSubMusicOffItem = MenuItemSprite::create(musicOff,nullptr); auto pSubMusicOpenItem = MenuItemSprite::create(Sprite::create("music.png"),nullptr); auto pMusicItem = MenuItemToggle::createWithCallback(CC_CALLBACK_0(GameMenu::menuSetMusic,this),pSubMusicOffItem,pSubMusicOpenItem,nullptr); pMusicItem->setSelectedIndex(DataModel::isMusic); //--帮助 auto helpNormalSprite = Sprite::create("menu_help.png"); auto helpPressedSprite = Sprite::create("menu_help.png"); helpPressedSprite->setScale(1.2f); auto pHelpItem = MenuItemSprite::create(helpNormalSprite,helpPressedSprite,CC_CALLBACK_0(GameMenu::menuHelp,this)); //--关于 auto aboutNormal = Sprite::create("menu_about.png"); auto aboutPressed = Sprite::create("menu_about.png"); aboutPressed->setScale(1.2f); auto pAboutItem = MenuItemSprite::create(aboutNormal,aboutPressed,CC_CALLBACK_0(GameMenu::menuAbout,this)); auto pSettingMenu = Menu::create(pSoundItem,pMusicItem,pHelpItem,pAboutItem,nullptr); //排列菜单项 pSettingMenu->alignItemsVerticallyWithPadding(10); pSettingMenu->setPosition(Vec2( systemBg->getContentSize().width/2, systemBg->getContentSize().height/2)); systemBg->addChild(pSettingMenu); return true; }