void OptionLayer::addOption() { this->setDJ(DiscJockey::getInstance()); Node *optionNode = CSLoader::createNode("optionNode.csb");//传入Studio2.x的资源路径 optionNode->setPosition(Point(originPoint.x + visibleSize.width / 2, (originPoint.y + visibleSize.height / 2))); this->addChild(optionNode); optionNode->setName("optionNode"); this->setAnchorPoint(Point(0.5, 0.5)); this->ignoreAnchorPointForPosition(false); this->setPosition(Point(originPoint.x + visibleSize.width / 2, -(originPoint.y + visibleSize.height / 2))); auto eventListener = EventListenerTouchOneByOne::create(); eventListener->setSwallowTouches(true); eventListener->onTouchBegan = CC_CALLBACK_2(OptionLayer::onTouchBegan, this); eventListener->onTouchCancelled = CC_CALLBACK_2(OptionLayer::onTouchCancelled, this); eventListener->onTouchEnded = CC_CALLBACK_2(OptionLayer::onTouchEnded, this); Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(eventListener, this); auto cancelButton = dynamic_cast<ui::Button*> (optionNode->getChildByName("cancelButton")); if (cancelButton) { cancelButton->addClickEventListener(CC_CALLBACK_1(OptionLayer::cancel, this)); } //set font name again due to the cocos studio 2.0 bugs (Text load ttf error) for (auto node : optionNode->getChildren()) { auto textNode = dynamic_cast<ui::Text*>(node); if (textNode) { textNode->enableOutline(Color4B(25, 26, 25, 155), 2); } } auto musicBox = dynamic_cast<ui::CheckBox*>(optionNode->getChildByName("soundCheck")); musicBox->addEventListenerCheckBox(this, checkboxselectedeventselector(OptionLayer::musicCheckBoxCallback)); auto effectBox = dynamic_cast<ui::CheckBox*>(optionNode->getChildByName("effectCheck")); effectBox->addEventListenerCheckBox(this, checkboxselectedeventselector(OptionLayer::effectCheckBoxCallback)); musicBox->setSelectedState(getDJ()->isMusicOn()); effectBox->setSelectedState(getDJ()->isEffectOn()); int curSpeed = CommandCenter::getInstance()->getSpeedLevel(); auto textNode = dynamic_cast<ui::Text*>(optionNode->getChildByName("textCurSpeed")); textNode->setText(String::createWithFormat("%d", curSpeed)->getCString()); auto speedSlider = dynamic_cast<ui::Slider*>(optionNode->getChildByName("speedSlider")); speedSlider->addEventListenerSlider(this, sliderpercentchangedselector(OptionLayer::speedSliderCallback)); speedSlider->setPercent(curSpeed * 10); }
bool UICheckBoxTest::init() { if (UIScene::init()) { Size widgetSize = _widget->getSize();; // Add a label in which the checkbox events will be displayed _displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32); _displayValueLabel->setAnchorPoint(Point(0.5f, -1)); _displayValueLabel->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); _uiLayer->addChild(_displayValueLabel); // Add the alert Text* alert = Text::create("CheckBox","fonts/Marker Felt.ttf",30 ); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the checkbox CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png", "cocosui/check_box_normal_press.png", "cocosui/check_box_active.png", "cocosui/check_box_normal_disable.png", "cocosui/check_box_active_disable.png"); checkBox->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); checkBox->addEventListenerCheckBox(this, checkboxselectedeventselector(UICheckBoxTest::selectedEvent)); _uiLayer->addChild(checkBox); return true; } return false; }
bool CFightPause::onInit() { do { Button* BtnBack = (Button*)Helper::seekWidgetByName(m_pWidget,"Back"); Button* BtnLeave = (Button*)Helper::seekWidgetByName(m_pWidget,"Leave"); CheckBox* MusicSet = (CheckBox*)Helper::seekWidgetByName(m_pWidget,"MusicSet"); CheckBox* EffectSet = (CheckBox*)Helper::seekWidgetByName(m_pWidget,"EffectSet"); BREAK_IF( !(BtnBack&&BtnLeave&&MusicSet&&EffectSet) ); BtnBack->addTouchEventListener(this,toucheventselector(CFightPause::ClickBack)); BtnLeave->addTouchEventListener(this,toucheventselector(CFightPause::ClickLeave)); MusicSet->addEventListenerCheckBox(this,checkboxselectedeventselector(CFightPause::ClickMusic)); EffectSet->addEventListenerCheckBox(this,checkboxselectedeventselector(CFightPause::ClickEffect)); MusicSet->setSelectedState(true); EffectSet->setSelectedState(true); return true; } while (0); return false; }
bool SettingMenuLayer::init(bool musicVolumeClosed, bool musicEffectClosed,int musicVolume, int musicEffect) { if(UILayer::init()) { this->setTouchEnabled(true); this->setTouchMode(kCCTouchesOneByOne); SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); CCDirector::sharedDirector()->pause(); Widget * myWidget = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("UI/SettingMenu/SettingMenu_1.json")); this->addWidget(myWidget); musicVolumeSlider = dynamic_cast<UISlider*>(this->getWidgetByName("volume_bar")); musicEffectSlider = dynamic_cast<UISlider*>(this->getWidgetByName("effect_bar")); musicVolumeCheckBox = dynamic_cast<UICheckBox*>(this->getWidgetByName("volume_CheckBox")); musicEffectCheckBox = dynamic_cast<UICheckBox*>(this->getWidgetByName("effect_CheckBox")); UIButton* resumeBtn = dynamic_cast<UIButton*>(this->getWidgetByName("resume")); UIButton* quitBtn = dynamic_cast<UIButton*>(this->getWidgetByName("quit")); musicVolumeCheckBox->addEventListenerCheckBox(this,checkboxselectedeventselector(SettingMenuLayer::musicVolumeCheckBoxCallFunc)); musicEffectCheckBox->addEventListenerCheckBox(this,checkboxselectedeventselector(SettingMenuLayer::musicEffectCheckBoxCallFunc)); musicVolumeSlider->addEventListenerSlider(this, sliderpercentchangedselector(SettingMenuLayer::musicVolumeSliderCallFunc)); musicEffectSlider->addEventListenerSlider(this, sliderpercentchangedselector(SettingMenuLayer::musicEffectSliderCallFunc)); resumeBtn->addTouchEventListener(this, toucheventselector(SettingMenuLayer::resumeGame)); quitBtn->addTouchEventListener(this, toucheventselector(SettingMenuLayer::quitGame)); musicVolumeCheckBox->setSelectedState(musicVolumeClosed); musicEffectCheckBox->setSelectedState(musicEffectClosed); musicVolumeSlider->setPercent(musicVolume); musicEffectSlider->setPercent(musicEffect); return true; } return false; }
void TouchLayer::getAndSetButtons() { Point originPoint = Director::getInstance()->getVisibleOrigin(); Size visibleSize = Director::getInstance()->getVisibleSize(); Node *rootNode = CSLoader::createNode("buttonNode.csb"); rootNode->setPosition(Point(originPoint.x + visibleSize.width / 2, originPoint.y + visibleSize.height / 2)); this->addChild(rootNode); rootNode->setName("rootNode"); auto buttonRoot = dynamic_cast<Node*>(rootNode->getChildByName("buttonRoot")); auto buttonNode = dynamic_cast<Node*>(buttonRoot->getChildByName("buttonNode")); auto leftButton = dynamic_cast<ui::Button*> (buttonNode->getChildByName("leftButton")); if (leftButton) { leftButton->addTouchEventListener(CC_CALLBACK_2(TouchLayer::onLongLeftClick, this)); leftButton->addClickEventListener(CC_CALLBACK_1(TouchLayer::onLeft, this)); } auto rightButton = dynamic_cast<ui::Button*> (buttonNode->getChildByName("rightButton")); if (rightButton) { rightButton->addTouchEventListener(CC_CALLBACK_2(TouchLayer::onLongRightClick, this)); rightButton->addClickEventListener(CC_CALLBACK_1(TouchLayer::onRight, this)); } auto downButton = dynamic_cast<ui::Button*> (buttonNode->getChildByName("downButton")); if (downButton) { downButton->addTouchEventListener(CC_CALLBACK_2(TouchLayer::onLongDownClick, this)); downButton->addClickEventListener(CC_CALLBACK_1(TouchLayer::onDown, this)); } auto hardButton = dynamic_cast<ui::Button*> (buttonNode->getChildByName("hardButton")); if (hardButton) { hardButton->addClickEventListener(CC_CALLBACK_1(TouchLayer::onHardDrop, this)); } auto rotateButton = dynamic_cast<ui::Button*> (buttonRoot->getChildByName("rotateButton")); if (rotateButton) { rotateButton->addTouchEventListener(CC_CALLBACK_2(TouchLayer::onLongRotateClick, this)); rotateButton->addClickEventListener(CC_CALLBACK_1(TouchLayer::onRotation, this)); } auto holdButton = dynamic_cast<ui::Button*>(buttonRoot->getChildByName("holdButton")); if (holdButton) { holdButton->addClickEventListener(CC_CALLBACK_1(TouchLayer::onHold, this)); } auto pauseBox = dynamic_cast<ui::CheckBox*>(buttonRoot->getChildByName("pauseCheck")); if (pauseBox) { pauseBox->addEventListenerCheckBox(this, checkboxselectedeventselector(TouchLayer::pauseCheckBoxCallback)); } }
bool MainScene::init(CCScene* pScene) { iBGIndex = 1; m_scene = pScene; if (CCLayer::init()) { m_rootNode = (NodeReader::getInstance()->createNode("R/MainScene_1.json")); addChild(m_rootNode); Layout *root = static_cast<Layout*>(m_rootNode->getChildren()->objectAtIndex(0)); m_root = root; btnImport = initButton(BUTTON_IMPORT, root, this, toucheventselector(MainScene::touchEvent)); btnImport->setTitleText(xStr("start")); initButton(BUTTON_PRV, root, this, toucheventselector(MainScene::touchEvent)); initButton(BUTTON_NEXT, root, this, toucheventselector(MainScene::touchEvent)); initButton(BUTTON_PREVIEW, root, this, toucheventselector(MainScene::touchEvent)); initButton(BUTTON_REMOVE, root, this, toucheventselector(MainScene::touchEvent)); initButton(BUTTON_CLEAN, root, this, toucheventselector(MainScene::touchEvent)); initButton(BUTTON_SAVE, root, this, toucheventselector(MainScene::touchEvent)); initButton(BUTTON_PREVIEW_ALL, root, this, toucheventselector(MainScene::touchEvent)); initButton(CHANGE_BG, root, this, toucheventselector(MainScene::touchEvent)); initButton(MOTION_PREVIEW, root, this, toucheventselector(MainScene::touchEvent)); Button * btn = initButton(APPLY_TO_ALL, root, this, toucheventselector(MainScene::touchEvent)); btn->setScale(0.5f); btn2x = initButton(BUTTON_2X, root, this, toucheventselector(MainScene::touchEvent)); btn2x->setScale(0.3f, 0.5f); btnAddMotion = initButton(BUTTON_ADD_MOTION, root, this, toucheventselector(MainScene::touchEvent)); btnAddMotion->setEnabled(false); btnDelMotion = initButton(BUTTON_DEL_MOTION, root, this, toucheventselector(MainScene::touchEvent)); btnPre5 = initButton(BUTTON_PRV_5, root, this, toucheventselector(MainScene::touchEvent)); btnNext5 = initButton(BUTTON_NEXT_5, root, this, toucheventselector(MainScene::touchEvent)); //输入区 m_ebAnchor[0] = InputBox::create(ANCHOR_X, root, this, m_rootNode); m_ebAnchor[1] = InputBox::create(ANCHOR_Y, root, this, m_rootNode); m_ebPosition[0] = InputBox::create(POSITION_X, root, this, m_rootNode); m_ebPosition[1] = InputBox::create(POSITION_Y, root, this, m_rootNode); m_ebRotate = InputBox::create(ROTATE, root, this, m_rootNode); m_ebScale = InputBox::create(SCALE, root, this, m_rootNode); m_ebDelay = InputBox::create(DELAY, root, this, m_rootNode); m_ebName = InputBox::create(SKILL_PART_NAME, root, this, m_rootNode); m_ebDegree = InputBox::create(DEGREE, root, this, m_rootNode); m_ebSpeed = InputBox::create(SPEED, root, this, m_rootNode); m_ebAttackDuration = InputBox::create(ATTACK_DURATION, root, this, m_rootNode); m_ebAttackInterval = InputBox::create(ATTACK_INTERVAL, root, this, m_rootNode); m_ebBulletType = InputBox::create(BULLET_TYPE, root, this, m_rootNode); m_ebBulletType->setText("0"); m_pHolder = static_cast<CCSprite*>(m_rootNode->getChildByTag(SPRITE_HOLDER)); m_pHolder->initWithFile("R/cross.png"); m_iFrameBG = (ImageView*)UIHelper::seekWidgetByTag(root, FRAME_BG); m_iFrameBG->addTouchEventListener(this, toucheventselector(MainScene::touchEvent)); m_iPreviewBG = (ImageView*)UIHelper::seekWidgetByTag(root, PREVIEW_BG); m_iPreviewBG->loadTexture("R/bg_1.jpg"); m_iPreviewBG->setPosition(ccp(m_iPreviewBG->getPositionX() - 240, m_iPreviewBG->getPositionY())); m_iPreviewBG1 = ImageView::create(); m_iPreviewBG1->loadTexture("R/bg_1.jpg"); m_iPreviewBG1->setPosition(ccp(1440, 0)); m_iPreviewBG->addChild(m_iPreviewBG1); m_lFrameCount = (Label*)UIHelper::seekWidgetByTag(root, LABEL_FRAME_COUNT); m_preview = static_cast<CCSprite*>(m_rootNode->getChildByTag(PREVIEW)); m_preview->initWithFile("R/cross.png"); m_preview->setVisible(false); xSkill->init(m_pHolder->getPosition(), m_preview->getPosition(), m_rootNode); //checkbox m_cbFlags[0] = initCheckBox(177, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent)); m_cbFlags[1] = initCheckBox(179, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent)); m_cbFlags[2] = initCheckBox(183, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent)); m_cbFlags[3] = initCheckBox(185, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent)); m_cbFlags[4] = initCheckBox(187, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent)); m_cbFlags[5] = initCheckBox(ISOLATE, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent)); m_cbFlags[6] = NULL; //FI_BULLET_TYPE m_cbFlags[7] = initCheckBox(HIGH_LIGHT, root, this, checkboxselectedeventselector(MainScene::selectedStateEvent)); m_cbNormal = initCheckBox(NORMAL_ATTACK, root, this, checkboxselectedeventselector(MainScene::selectedNormal)); CCUserDefault::sharedUserDefault()->setBoolForKey(NORMAL, false); m_cbAttack = initCheckBox(ATTACK_FRAME, root, this, checkboxselectedeventselector(MainScene::selectedAttackFrame)); m_lError = (Label*)(UIHelper::seekWidgetByTag(root, LABEL_ERROR)); m_lError->setVisible(false); //列表 listView = (UIListView*)UIHelper::seekWidgetByTag(root, PARTS_LIST); CCNode *node = (NodeReader::getInstance()->createNode("R/FolderBrowser_2.ExportJson")); listroot = static_cast<Layout*>(node->getChildren()->objectAtIndex(0)); Layout* defaultItem = (Layout*)UIHelper::seekWidgetByTag(listroot, 32); //还有转一层, 一来至少加2个Panel listView->setItemModel(defaultItem); _listAudio = (UIListView*)UIHelper::seekWidgetByTag(root, T_LIST_AUDIO); _listAudio->setItemModel(defaultItem); initButton(T_AUDIO_BACK, root, this, toucheventselector(MainScene::touchEvent)); motionlist = (UIListView*)UIHelper::seekWidgetByTag(root, MOTION_LIST); motionlist->setItemModel(defaultItem); _layoutAudio = (Layout*)UIHelper::seekWidgetByTag(root, T_SELECT_AUDIO); _layoutAudio->setVisible(false); _btnAddAudio = initButton(T_ADD_AUDIO, root, this, toucheventselector(MainScene::touchEvent)); xNotify->addObserver(this, callfuncO_selector(MainScene::updateProperty), UPDATE_PROPERTY, NULL); xNotify->addObserver(this, callfuncO_selector(MainScene::updateList), UPDATE_EFFECT_LIST, NULL); xNotify->addObserver(this, callfuncO_selector(MainScene::updateMotionList), UPDATE_MOTION_LIST, NULL); xNotify->addObserver(this, callfuncO_selector(MainScene::setFrameCount), UPDATE_ALL_INDEX, NULL); xNotify->addObserver(this, callfuncO_selector(MainScene::error), UPDATE_ERROR, NULL); setTouchEnabled(true); return true; } return true; }