Node* LHGameChat::waitView(){ Size vs = Director::getInstance()->getVisibleSize(); Vec2 vo = Director::getInstance()->getVisibleOrigin(); auto lo = ui::Layout::create(); Size sz = Size(vs.width/2,vs.height/4); lo->setSize(sz); lo->setPosition(Vec2(vs.width/2 - sz.width/2, vs.height/2 - sz.height/2)); lo->setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID); lo->setBackGroundColor(Color3B::GRAY); lo->setBackGroundColorOpacity(200); auto load = ui::Text::create("Loading...", Common_Font, 30); load->setColor(Color3B::GREEN); load->setPosition(Vec2(sz.width/2, lo->getSize().height/2)); auto cancel = ui::Button::create("close.png"); cancel->setPosition(Vec2(sz.width/2, lo->getSize().height/2 - load->getContentSize().height - 20)); cancel->addTouchEventListener([](Ref *ps,ui::Widget::TouchEventType type){ if (type == ui::Widget::TouchEventType::ENDED) { if (_chatManager) { _chatManager->disconnect(); delete _chatManager; _chatManager = nullptr; LHDialog::disMissDialog(); } } }); lo->addChild(load); lo->addChild(cancel); return lo; }
bool LHDialog::init(){ Size vs = Director::getInstance()->getVisibleSize(); Vec2 vo = Director::getInstance()->getVisibleOrigin(); setPosition(vo); setSize(vs); auto rs = Director::getInstance()->getRunningScene(); rs->addChild(this); setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID); setBackGroundColor(Color3B::BLACK); setBackGroundColorOpacity(200); return true; }
void UILayout::copySpecialProperties(UIWidget *widget) { UILayout* layout = dynamic_cast<UILayout*>(widget); if (layout) { setBackGroundImageScale9Enabled(layout->m_bBackGroundScale9Enabled); setBackGroundImage(layout->m_strBackGroundImageFileName.c_str(),layout->m_eBGImageTexType); setBackGroundImageCapInsets(layout->m_backGroundImageCapInsets); setBackGroundColorType(layout->m_colorType); setBackGroundColor(layout->m_cColor); setBackGroundColor(layout->m_gStartColor, layout->m_gEndColor); setBackGroundColorOpacity(layout->m_nCOpacity); setBackGroundColorVector(layout->m_AlongVector); setLayoutType(layout->m_eLayoutType); setClippingEnabled(layout->m_bClippingEnabled); } }
void Layout::copySpecialProperties(Widget *widget) { Layout* layout = dynamic_cast<Layout*>(widget); if (layout) { setBackGroundImageScale9Enabled(layout->_backGroundScale9Enabled); setBackGroundImage(layout->_backGroundImageFileName,layout->_bgImageTexType); setBackGroundImageCapInsets(layout->_backGroundImageCapInsets); setBackGroundColorType(layout->_colorType); setBackGroundColor(layout->_cColor); setBackGroundColor(layout->_gStartColor, layout->_gEndColor); setBackGroundColorOpacity(layout->_cOpacity); setBackGroundColorVector(layout->_alongVector); setLayoutType(layout->_layoutType); setClippingEnabled(layout->_clippingEnabled); setClippingType(layout->_clippingType); _loopFocus = layout->_loopFocus; _passFocusToChild = layout->_passFocusToChild; _isInterceptTouch = layout->_isInterceptTouch; } }
Layout * Mx::createDialog(Node* child, Node * parent, Size innerSize, DialogBtn buttonStyle, string background){ auto layout = Layout::create(); auto size = parent->getContentSize(); auto dialogSize = Size(innerSize.width + 30, innerSize.height + 30); parent->addChild(layout, 999); layout->setContentSize(size); layout->setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID); layout->setBackGroundColor(Color3B::BLACK); layout->setBackGroundColorOpacity(150); layout->setTouchEnabled(true); auto diaLayout = Layout::create(); layout->addChild(diaLayout); diaLayout->setContentSize(innerSize); diaLayout->setClippingEnabled(false); diaLayout->setAnchorPoint(Vec2::ANCHOR_MIDDLE); diaLayout->setPosition(Vec2(dialogSize.width/2, dialogSize.height/2)); diaLayout->setScale(0); diaLayout->setBackGroundImageScale9Enabled(true); if (background == "") { diaLayout->setBackGroundImage("sys_toast_b.png"); }else{ diaLayout->setBackGroundImage(background); } diaLayout->setPosition(size/2); if (child != nullptr) { diaLayout->addChild(child); } // set button; { if (buttonStyle.buttonNum != 0) { if (buttonStyle.closeText == "") { buttonStyle.closeText = this->getStrValue("close"); } auto buttonConfirm = this->createDialogButton(buttonStyle, buttonStyle.confirmText); auto buttonClose = this->createDialogButton(buttonStyle, buttonStyle.closeText); if (buttonStyle.buttonNum == 1) { buttonConfirm->setPosition(Vec2((dialogSize/2).width, 0)); diaLayout->addChild(buttonConfirm); }else{ Size size = buttonConfirm->getContentSize()/2; Size center = dialogSize/2; buttonConfirm->setPosition(Vec2(center.width - size.width, 0)); buttonClose->setPosition(Vec2(center.width + size.width, 0)); diaLayout->addChild(buttonConfirm); diaLayout->addChild(buttonClose); } } if (buttonStyle.isVisibleClose) { auto buttonClose = this->createDialogCloseButton(buttonStyle, buttonStyle.closeText, layout, diaLayout); diaLayout->addChild(buttonClose); buttonClose->setPosition(diaLayout->getContentSize() - buttonClose->getContentSize()/2 + Size(25, 25)); } } auto action = EaseBackOut::create(ScaleTo::create(.3, 1)); diaLayout->runAction(action); return layout; }
// on "init" you need to initialize your instance bool PageTest::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } scheduleUpdate(); percent = 0; Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto loadingBar = ui::LoadingBar::create("sliderProgress.png"); loadingBar->setTag(0); loadingBar->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2)); loadingBar->setPercent(percent); this->addChild(loadingBar); auto checkBox = ui::CheckBox::create("check_box_normal.png", "check_box_normal_press.png", "check_box_active.png", "check_box_normal_disable.png", "check_box_active_disable.png"); checkBox->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height - 100)); checkBox->addEventListener(CC_CALLBACK_2(PageTest::selectedEvent, this)); this->addChild(checkBox); auto slider = ui::Slider::create(); slider->loadBarTexture("sliderTrack.png"); slider->loadSlidBallTextures("sliderThumb.png", "sliderThumb.png", ""); slider->loadProgressBarTexture("sliderProgress.png"); slider->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height - 200)); slider->addEventListener(CC_CALLBACK_2(PageTest::sliderEvent, this)); this->addChild(slider); // auto recustom = ui::RichElementCustomNode::create(1, Color3B::WHITE, 255, pAr); // richText->pushBackElement(recustom); // androidだとバックグランドが緑がデフォ? // androidだと盤面全体が背景白になる // http://discuss.cocos2d-x.org/t/ui-pageview-bug-with-v3-rc1-green-background-on-android/12897 // auto layout = ui::Layout::create(); layout->setSize(Size(visibleSize.width, 200.0f)); layout->setPosition(Vec2::ZERO); layout->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID); layout->setBackGroundColor(Color3B::BLUE); this->addChild(layout); auto pageView = ui::PageView::create(); /* pageView->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID); pageView->setBackGroundColor(Color3B::RED); */ pageView->setSize(Size(visibleSize.width, 130.0f)); pageView->setPosition(Vec2::ZERO); pageView->setContentSize(Size(visibleSize.width, 130.0f)); for (int i = 0; i < 3; ++i) { auto layout = ui::Layout::create(); layout->setBackGroundImage(""); layout->setBackGroundColor(Color3B::YELLOW); layout->setBackGroundColorType(ui::Layout::BackGroundColorType::SOLID); layout->setSize(Size(240.0f, 130.0f)); // layout->addTouchEventListener(<#ccWidgetTouchCallback callback#>) auto imageView = ui::ImageView::create("HelloWorld.png"); imageView->setScale9Enabled(true); imageView->setSize(Size(240, 130)); imageView->setPosition(Vec2(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(imageView); auto label = ui::Text::create(StringUtils::format("page %d",(i+1)), "Arial", 30); label->setColor(Color3B(192, 192, 192)); label->setPosition(Vec2(layout->getSize().width / 2.0f, layout->getSize().height / 2.0f)); layout->addChild(label); auto btn = ui::Button::create(""); btn->setTitleText(""); btn->setTitleFontSize(12); btn->setTitleFontName(""); pageView->addPage(layout); } // pageView->scrollToPage(2); // うまくいかない。handleReleaseLogicのboundaryのためだと思われる pageView->addEventListener(CC_CALLBACK_2(PageTest::pageViewEvent, this)); layout->addChild(pageView); auto richText = ui::RichText::create(); richText->ignoreContentAdaptWithSize(false); richText->setSize(Size(100, 100)); richText->setPosition(Vec2(visibleSize.width / 2.0f, visibleSize.height - 300)); this->addChild(richText); auto re1 = ui::RichElementText::create(1, Color3B::WHITE, 255, "This color is white. ", "Arial", 10); richText->pushBackElement(re1); auto re2 = ui::RichElementText::create(2, Color3B::YELLOW, 255, "This color is yellow. ", "Arial", 24); richText->insertElement(re2, 1); auto reimg = ui::RichElementImage::create(6, Color3B::WHITE, 255, "sliderballnormal.png"); richText->pushBackElement(reimg); return true; }