コード例 #1
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    if ( !LayerColor::initWithColor(Constants::BACKGROUND_COLOR) )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    auto learnBtn = ui::Button::create("BtnNormal", "BtnPressed", "", ui::Widget::TextureResType::PLIST);
    learnBtn->setScale9Enabled(true);
    learnBtn->setCapInsets(Rect(12, 12, 12, 12));
    learnBtn->setSize(Size(177, 58));
    learnBtn->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2 + 39));
    learnBtn->getTitleRenderer()->setBMFontFilePath(Constants::FONT_BOLD30);
    learnBtn->setTitleText("Learn");
    learnBtn->addTouchEventListener(CC_CALLBACK_2(HelloWorld::touchEvent, this));
    this->addChild(learnBtn, 1, 1);
    
    auto testBtn = ui::Button::create("BtnBlueNormal", "BtnBluePressed", "", ui::Widget::TextureResType::PLIST);
    testBtn->setScale9Enabled(true);
    testBtn->setCapInsets(Rect(12, 12, 12, 12));
    testBtn->setSize(Size(177, 58));
    testBtn->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2 - 39));
    testBtn->getTitleRenderer()->setBMFontFilePath(Constants::FONT_BOLD30);
    testBtn->setTitleText("Test");
    testBtn->addTouchEventListener(CC_CALLBACK_2(HelloWorld::touchEvent, this));
    this->addChild(testBtn, 2, 2);
    
    auto rateBtn = ui::Button::create("RateBtn", "", "", ui::Widget::TextureResType::PLIST);
    rateBtn->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + 30));
    rateBtn->addTouchEventListener(CC_CALLBACK_2(HelloWorld::touchEvent, this));
    this->addChild(rateBtn, 3, 3);

    return true;
}
コード例 #2
0
ファイル: knaccountdetailbox.cpp プロジェクト: AnkyoChu/Mu
KNAccountDetailBox::KNAccountDetailBox(QWidget *parent) :
    KNMessageBox(parent),
    m_username(new QLabel(this)),
    m_nickName(generateLineEdit()),
    m_emailAddress(generateLineEdit())
{
    //Set property.
    setTitleText("Preference");
    setCancelButtonVisible(true);
    //Configure the user name.
    m_username->setFixedHeight(m_nickName->height());

    //Initial the container.
    QWidget *container=new QWidget(this);
    //Initial the label palette.
    QPalette pal=palette();
    pal.setColor(QPalette::WindowText, QColor(157, 157, 157));
    //Initial the label.
    for(int i=0; i<EditRowCount; ++i)
    {
        //Initial the label.
        m_title[i]=new QLabel(container);
        //Set the palette.
        m_title[i]->setPalette(pal);
    }

    //Initial the layout.
    QFormLayout *containerLayout=new QFormLayout(container);
    //Configure layout.
    containerLayout->setVerticalSpacing(10);
    containerLayout->setContentsMargins(20, 15, 20, 10);
    containerLayout->setLabelAlignment(Qt::AlignRight | Qt::AlignTop);
    //Set the container.
    container->setLayout(containerLayout);
    //Add rows.
    containerLayout->addRow(m_title[UserNameRow],
                            m_username);
    containerLayout->addRow(m_title[NickNameRow],
                            m_nickName);
    containerLayout->addRow(m_title[EmailAddressRow],
                            m_emailAddress);

    //Set the container to be the conent widget.
    setContentWidget(container);

    //Link translator.
    knI18n->link(this, &KNAccountDetailBox::retranslate);
    retranslate();
}
コード例 #3
0
ファイル: McdLayer.cpp プロジェクト: dgkae/cube3d
ui::Button* McdLayer::decorateButtonEx(const Btn_info& btnInfo, BTN_CALLBACK callback){
    auto button = ui::Button::create(btnInfo.img, btnInfo.img_p);
    button->setPressedActionEnabled(true);
    button->setPosition(genPos(btnInfo.pos));
    auto mytag = _tagAI++;
    button->setTag(mytag);
    button->addTouchEventListener(CC_CALLBACK_2(McdLayer::touchEvent, this));
    button->setScale(btnInfo.scale);
    button->setTitleText(btnInfo.text);
    button->setTitleFontName(uic::font_zh);
    button->setTitleFontSize(20);
    this->addChild(button, 1);
    _cbMap[mytag] = callback;
    return button;
}
コード例 #4
0
ファイル: McdLayer.cpp プロジェクト: dgkae/cube3d
ui::Button* McdLayer::decorateButton(const Btn_info& btnInfo , int tag)
{
    auto button = ui::Button::create(btnInfo.img, btnInfo.img_p);
    button->setPressedActionEnabled(true);
    //    button->setAnchorPoint({0,0});
    button->setPosition(genPos(btnInfo.pos));
    button->setTag(tag);
    button->addTouchEventListener(CC_CALLBACK_2(McdLayer::touchEvent, this));
    button->setScale(btnInfo.scale);
    button->setTitleText(btnInfo.text);
    button->setTitleFontName(uic::font_zh);
    button->setTitleFontSize(30);
    this->addChild(button, 1);
    return button;
}
コード例 #5
0
ファイル: UIButton.cpp プロジェクト: hugohuang1111/Bird
void Button::copySpecialProperties(Widget *widget)
{
    Button* button = dynamic_cast<Button*>(widget);
    if (button)
    {
        _prevIgnoreSize = button->_prevIgnoreSize;
        setScale9Enabled(button->_scale9Enabled);

        // clone the inner sprite: https://github.com/cocos2d/cocos2d-x/issues/16924
        button->_buttonNormalRenderer->copyTo(_buttonNormalRenderer);
        _normalFileName = button->_normalFileName;
        _normalTextureSize = button->_normalTextureSize;
        _normalTexType = button->_normalTexType;
        _normalTextureLoaded = button->_normalTextureLoaded;
        setupNormalTexture(!_normalFileName.empty());

        button->_buttonClickedRenderer->copyTo(_buttonClickedRenderer);
        _clickedFileName = button->_clickedFileName;
        _pressedTextureSize = button->_pressedTextureSize;
        _pressedTexType = button->_pressedTexType;
        _pressedTextureLoaded = button->_pressedTextureLoaded;
        setupPressedTexture(!_clickedFileName.empty());

        button->_buttonDisabledRenderer->copyTo(_buttonDisabledRenderer);
        _disabledFileName = button->_disabledFileName;
        _disabledTextureSize = button->_disabledTextureSize;
        _disabledTexType = button->_disabledTexType;
        _disabledTextureLoaded = button->_disabledTextureLoaded;
        setupDisabledTexture(!_disabledFileName.empty());

        setCapInsetsNormalRenderer(button->_capInsetsNormal);
        setCapInsetsPressedRenderer(button->_capInsetsPressed);
        setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
        if(nullptr != button->getTitleRenderer())
        {
            setTitleText(button->getTitleText());
            setTitleFontName(button->getTitleFontName());
            setTitleFontSize(button->getTitleFontSize());
            setTitleColor(button->getTitleColor());
        }
        setPressedActionEnabled(button->_pressedActionEnabled);
        setZoomScale(button->_zoomScale);
    }

}
コード例 #6
0
ファイル: UIFocusTest.cpp プロジェクト: jiaozicat/cocos2d-x
bool UIFocusTestVertical::init()
{
    if (UIFocusTestBase::init()) {
        
        Size winSize = Director::getInstance()->getVisibleSize();
        
        _verticalLayout = VBox::create();
        _verticalLayout->setPosition(Vec2(winSize.width/2 - 100, winSize.height - 70));
        _uiLayer->addChild(_verticalLayout);
        _verticalLayout->setTag(100);
        _verticalLayout->setScale(0.5);
        
        _verticalLayout->setFocused(true);
        _verticalLayout->setLoopFocus(true);
        _firstFocusedWidget = _verticalLayout;
        
        int count = 3;
        for (int i=0; i<count; ++i) {
            ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
            w->setTouchEnabled(true);
            w->setTag(i);
            w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestVertical::onImageViewClicked, this));
            _verticalLayout->addChild(w);
            if (i == 2) {
                w->requestFocus();
            }
        }
        
        _loopText = Text::create("loop enabled", "Airal", 20);
        _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
        _loopText->setColor(Color3B::GREEN);
        this->addChild(_loopText);
        
        auto btn = Button::create("cocosui/switch-mask.png");
        btn->setTitleText("Toggle Loop");
        btn->setPosition(Vec2(60, winSize.height - 50));
        btn->setTitleColor(Color3B::RED);
        btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestVertical::toggleFocusLoop, this));
        this->addChild(btn);
        
        
        return true;
    }
    return false;
}
コード例 #7
0
bool PurchaseLayer::init()
{  
    bool bRet = false;  
    do
    {  
        CC_BREAK_IF(!Layer::init());  

        Size winSize = Director::getInstance()->getWinSize();

		// load csb
		auto rootNode = CSLoader::createNode("PurchaseLayer.csb");
		this->addChild(rootNode);

        m_pLayout = dynamic_cast<Layout*>(rootNode->getChildByName("Panel_Purchase"));
        m_pListView = dynamic_cast<ListView*>(m_pLayout->getChildByName("ListView_Products"));
        
        // get botton
        auto buttonClose = dynamic_cast<Button*>(m_pLayout->getChildByName("Button_Close"));
        buttonClose->addClickEventListener(CC_CALLBACK_1(PurchaseLayer::menuCallback_Close, this));
        
		// set all text
		buttonClose->setTitleText(GameMediator::getInstance()->getGameText()->at("ID_COMMON_CLOSE"));

        // run animation
        m_pLayout->setPosition(Point(winSize.width/2, winSize.height+ m_pLayout->getContentSize().height));
        m_pLayout->runAction(MoveTo::create(0.2f, Point(winSize.width/2, winSize.height/2)));
        
        // swallow all touches
        auto touchListener = EventListenerTouchOneByOne::create();
        touchListener->setSwallowTouches(true);
        touchListener->onTouchBegan = [=](Touch *, Event *){return true;};
        _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
        
		// request IAP
#if IAPTEST_FLAG == 1
		CSCClass::CSC_IOSHelper::getInstance()->IAP_requestAllPurchasedProductsWithCallback(true, CC_CALLBACK_0(PurchaseLayer::showListItems, this));
#else
	    CSCClass::CSC_IOSHelper::getInstance()->IAP_requestAllPurchasedProductsWithCallback(false, CC_CALLBACK_0(PurchaseLayer::showListItems, this));
#endif
		
        bRet = true;
    } while (0);  
  
    return bRet;  
}
コード例 #8
0
ファイル: imt_mrgui.cpp プロジェクト: IMTtugraz/AGILE
void IMT_MRGui::startauto(QStringList filepath, QStringList filename)
{
  _dicom=true;

//  qDebug()<<"\n filepath->size(): "<<filepath.size();
  if(!filepath.empty())
  {
    _cycleread_thread->cycle_stop();
    //qDebug()<<"\n filepath: "<<filepath;
    _filenames_to_archive = filename;

    _outfilename = filename.first()+"-"+QString::number(filename.size());   //set filename for outputfile
    setTitleText(_outfilename);

    get_dcmrawdata(filepath);
    createstartcalcthread();
  }
}
コード例 #9
0
ファイル: UIButton.cpp プロジェクト: 6520874/pipiGame
void Button::copySpecialProperties(Widget *widget)
{
    Button* button = dynamic_cast<Button*>(widget);
    if (button)
    {   
        _prevIgnoreSize = button->_prevIgnoreSize;
        setScale9Enabled(button->_scale9Enabled);
        loadTextureNormal(button->_normalFileName.c_str(), button->_normalTexType);
        loadTexturePressed(button->_clickedFileName.c_str(), button->_pressedTexType);
        loadTextureDisabled(button->_disabledFileName.c_str(), button->_disabledTexType);
        setCapInsetsNormalRenderer(button->_capInsetsNormal);
        setCapInsetsPressedRenderer(button->_capInsetsPressed);
        setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
        setTitleText(button->getTitleText());
        setTitleFontName(button->getTitleFontName());
        setTitleFontSize(button->getTitleFontSize());
        setTitleColor(button->getTitleColor());
        setPressedActionEnabled(button->_pressedActionEnabled);
    }
}
コード例 #10
0
void ConnectFriendWizard::setGpgId(const RsPgpId &gpgId, const RsPeerId &sslId, bool friendRequest)
{
	if (!rsPeers->getGPGDetails(gpgId, peerDetails)) {
		setField("errorMessage", tr("Cannot get peer details of PGP key %1").arg(QString::fromStdString(gpgId.toStdString())));
		setStartId(Page_ErrorMessage);
		return;
	}

	/* Set ssl id when available */
	peerDetails.id = sslId;

    //setStartId(friendRequest ? Page_FriendRequest : Page_Conclusion);
    setStartId(Page_Conclusion);
    if (friendRequest){
    ui->fr_label->show();
    ui->requestinfolabel->show();
    setTitleText(ui->ConclusionPage,tr("Friend request"));
    ui->ConclusionPage->setSubTitle(tr("Details about the request"));
    }
}
コード例 #11
0
ファイル: MainScene.cpp プロジェクト: JiangySky/CocosManual
bool MainScene::init()
{
    Size sizeWin = DIRECTOR->getWinSize();
    float listWidth = sizeWin.width - sizeWin.height;
    
    // background layout
    auto layerColor = LayerColor::create(Color4B::WHITE, sizeWin.width, sizeWin.height);
    auto drawNodeV = DrawNode::create();
    drawNodeV->drawSegment(Point(listWidth, 0), Point(listWidth, sizeWin.height), 2, Color4F::GRAY);
    layerColor->addChild(drawNodeV);
    auto drawNodeH = DrawNode::create();
    drawNodeH->drawSegment(Point(listWidth, sizeWin.height / 3), Point(sizeWin.width, sizeWin.height / 3), 2, Color4F::GRAY);
    layerColor->addChild(drawNodeH);
    addChild(layerColor);
    
    // title
    auto btnTitle = Button::create();
    btnTitle->setTouchEnabled(true);
    btnTitle->ignoreContentAdaptWithSize(false);
    btnTitle->setTitleFontName("Marker Felt");
    btnTitle->setTitleText("Cocos2d Manual");
    btnTitle->setTitleColor(Color3B::GREEN);
    btnTitle->setTitleFontSize(30);
    btnTitle->setSize(Size(listWidth, 40));
    btnTitle->setPosition(Point(listWidth / 2, sizeWin.height - 30));
    BIND_LISTENER_TOUCH(btnTitle, this, MainScene::onTouchTitle);
    addChild(btnTitle);
    
    // manual layer
    auto layerDisplay = ManualDisplay::create();
    auto layerCode = ManualCode::create();
    auto layerList = ManualList::create();
    layerCode->setDisplay(layerDisplay);
    layerCode->setTag(Tag::TAG_CODELAYER);
    layerList->setCode(layerCode);
    addChild(layerDisplay);
    addChild(layerCode);
    addChild(layerList);
    
    return Layer::init();
}
コード例 #12
0
ファイル: hist.cpp プロジェクト: Frenzie/crengine
CRBookmark::CRBookmark (ldomXPointer ptr )
: _startpos(lString16::empty_str)
, _endpos(lString16::empty_str)
, _percent(0)
, _type(0)
, _shortcut(0)
, _postext(lString16::empty_str)
, _titletext(lString16::empty_str)
, _commenttext(lString16::empty_str)
, _timestamp(time_t(0))
, _page(0)
{
    //
    if ( ptr.isNull() )
        return;

    //CRLog::trace("CRBookmark::CRBookmark() started");
    lString16 path;

    //CRLog::trace("CRBookmark::CRBookmark() calling ptr.toPoint");
    lvPoint pt = ptr.toPoint();
    //CRLog::trace("CRBookmark::CRBookmark() calculating percent");
    ldomDocument * doc = ptr.getNode()->getDocument();
    int h = doc->getFullHeight();
    if ( pt.y > 0 && h > 0 ) {
        if ( pt.y < h ) {
            _percent = (int)((lInt64)pt.y * 10000 / h);
        } else {
            _percent = 10000;
        }
    }
    //CRLog::trace("CRBookmark::CRBookmark() calling getChaptername");
	setTitleText( CRBookmark::getChapterName( ptr ) );
    _startpos = ptr.toString();
    _timestamp = (time_t)time(0);
    lvPoint endpt = pt;
    endpt.y += 100;
    //CRLog::trace("CRBookmark::CRBookmark() creating xpointer for endp");
    ldomXPointer endptr = doc->createXPointer( endpt );
    //CRLog::trace("CRBookmark::CRBookmark() finished");
}
コード例 #13
0
ファイル: introcode.cpp プロジェクト: JuanPotato/tdesktop
CodeWidget::CodeWidget(QWidget *parent, Widget::Data *data) : Step(parent, data)
, _noTelegramCode(this, lang(lng_code_no_telegram), st::introLink)
, _code(this, st::introCode, langFactory(lng_code_ph))
, _callTimer(this)
, _callStatus(getData()->callStatus)
, _callTimeout(getData()->callTimeout)
, _callLabel(this, st::introDescription)
, _checkRequest(this) {
	subscribe(Lang::Current().updated(), [this] { refreshLang(); });

	connect(_code, SIGNAL(changed()), this, SLOT(onInputChange()));
	connect(_callTimer, SIGNAL(timeout()), this, SLOT(onSendCall()));
	connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
	connect(_noTelegramCode, SIGNAL(clicked()), this, SLOT(onNoTelegramCode()));

	_code->setDigitsCountMax(getData()->codeLength);
	setErrorBelowLink(true);

	setTitleText([text = App::formatPhone(getData()->phone)] { return text; });
	updateDescText();
}
コード例 #14
0
ファイル: UI.cpp プロジェクト: baokuanze/UIdemo
//按钮
void UI:: initButton(){
    auto visibleSize=Director::getInstance()->getVisibleSize();
    auto ub=Button::create();
    ub->loadTextureNormal("0.png");
    ub->loadTexturePressed("2.png");
    ub->loadTextureDisabled("2.png");
    ub->setScale9Enabled(true);
    ub->setContentSize(cocos2d::Size(128,128));
    ub->setPressedActionEnabled(true);
    ub->setZoomScale(2);
    ub->setTitleFontName("fonts/Marker Felt.ttf");
    ub->setTitleFontSize(30);
    ub->setTitleColor(cocos2d::Color3B::YELLOW);
    ub->setTitleText("HHLLO Button");
   // ub->addClickEventListener(CC_CALLBACK_1(UI::buttonClick, this));
    //添加触摸事件
    ub->addTouchEventListener (this,toucheventselector(UI::buttonClick));
    ub->setPosition(visibleSize/2);
    addChild(ub);
    
}
コード例 #15
0
KNMusicLyricsDownloadDialog::KNMusicLyricsDownloadDialog(QWidget *parent) :
    KNMusicLyricsDownloadDialogBase(knGlobal->mainWindow()),
    m_downloadWidget(new KNMusicLyricsDownloadWidget(this))
{
    Q_UNUSED(parent)
    //Set properties.
    setContentWidget(m_downloadWidget);
    setTitleText("Lyrics");
    setShowCancelButton(true);
    setShowOkayButton(false);

    //Configure the download widget.
    connect(m_downloadWidget, &KNMusicLyricsDownloadWidget::requireExpand,
            this, &KNMusicLyricsDownloadDialog::onActionExpand);
    connect(m_downloadWidget,
            &KNMusicLyricsDownloadWidget::requireShowOkayButton,
            [=]{setButtonVisible(true, true);});
    connect(m_downloadWidget,
            &KNMusicLyricsDownloadWidget::requireHideOkayButton,
            [=]{setButtonVisible(true, false);});
}
コード例 #16
0
ファイル: MenuScene.cpp プロジェクト: kupilas/cpp_playground
void MenuScene::initHttpButton(){
    auto button = ui::Button::create("CloseNormal.png", "CloseSelected.png", "CloseNormal.png");
    
    button->setTitleText("http request");
    
    button->addTouchEventListener([&](Ref* sender, cocos2d::ui::Widget::TouchEventType type){
        switch (type)
        {
            case ui::Widget::TouchEventType::BEGAN:
                break;
            case ui::Widget::TouchEventType::ENDED:
                //                Director::getInstance()->replaceScene(TestingSceneOne::createScene());
                CCLOG("btn lick");
                this->makeHttpRequest();
                break;
            default:
                break;
        }
    });
    button->cocos2d::Node::setPosition(300, 300);
    this->addChild(button);
}
コード例 #17
0
OutputConsole::OutputConsole():
	View()
{
    setTitleText( "Console" );

    QAction* close = new QAction( 0 );
             close->setIcon( ActionIconProvider().getIconForAction("close") );

    setTitleCloseButton( close, this, SLOT(close()) );

	QFont	font;
			font.setFamily	( "Monospace" );
			font.setPointSize	( 8 );

    QTextCharFormat textCharFormat;
                    textCharFormat.setFont( font );

    textCharFormat.setForeground        ( QBrush(Qt::gray)      );
    _infoOutput.setReadOnly             ( true                  );
    _infoOutput.setCurrentCharFormat    ( textCharFormat        );
    _infoOutput.setPalette              ( QPalette(Qt::darkGray));

    textCharFormat.setForeground        ( QBrush(Qt::darkBlue)  );
    _warningOutput.setReadOnly          ( true                  );
    _warningOutput.setCurrentCharFormat ( textCharFormat        );

    textCharFormat.setForeground        ( QBrush(Qt::darkRed)   );
    _errorOutput.setReadOnly            ( true                  );
    _errorOutput.setCurrentCharFormat   ( textCharFormat        );

    _tabWidget = new QTabWidget();
    _tabWidget->setTabPosition( QTabWidget::West       );
    _tabWidget->setTabShape   ( QTabWidget::Triangular );
    _tabWidget->addTab( &_infoOutput,    c_outputTabText    );
    _tabWidget->addTab( &_warningOutput, c_warningsTabText  );
    _tabWidget->addTab( &_errorOutput,   c_errorsTabText    );
                
	setContentWidget( _tabWidget );
}
コード例 #18
0
ファイル: MenuScene.cpp プロジェクト: kupilas/cpp_playground
void MenuScene::initNewSceneButton(){
    auto button2 = ui::Button::create("CloseNormal.png", "CloseSelected.png", "CloseNormal.png");
    
    button2->setTitleText("next scene");
    
    button2->addTouchEventListener([&](Ref* sender, cocos2d::ui::Widget::TouchEventType type){
        switch (type)
        {
            case ui::Widget::TouchEventType::BEGAN:
                break;
            case ui::Widget::TouchEventType::ENDED:
                CCLOG("btn click");
                Director::getInstance()->replaceScene(PhysicsSene::createScene());
                
                break;
            default:
                break;
        }
    });
    button2->cocos2d::Node::setPosition(600, 300);
    this->addChild(button2);
}
コード例 #19
0
ファイル: GameLayer.cpp プロジェクト: tankorsmash/Runner
cocos2d::ui::Button* GameLayer::create_button(std::string text, cocos2d::ccMenuCallback cb)
{
    auto param = ui::LinearLayoutParameter::create();
    param->setGravity(ui::LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);
    param->setMargin(ui::Margin(0, menu_fontsize/2, 0, 0));

    auto btn = ui::Button::create();
    btn->setTitleFontName(menu_font);
    btn->setTitleFontSize(menu_fontsize);
    btn->setTitleColor(Color3B::GREEN);
    btn->setLayoutParameter(param);
    btn->setTouchEnabled(true);
    btn->setPressedActionEnabled(true);

    btn->addTouchEventListener([this,cb](Ref* ref, ui::Widget::TouchEventType event)
            {
            if (event == ui::Widget::TouchEventType::ENDED){ cb(NULL); }
            });
    btn->setTitleText(text);

    return btn;

};
コード例 #20
0
ファイル: PauseScene.cpp プロジェクト: DerekDick/Photon
bool Pause::init() {
    if (!Setting::init()) {
        return false;
    }

    auto resumeButton = ui::Button::create("Pics/button/OptionNormal.png", "Pics/button/OptionSelected.png");
    resumeButton->setTitleFontName("Fonts/Amplify.ttf");
    resumeButton->setTitleFontSize(36);    
    resumeButton->setTitleText("RESUME");
    resumeButton->setTitleColor(Color3B(53, 54, 165));
    resumeButton->addTouchEventListener([](Ref* pSender, ui::Widget::TouchEventType type) {
        if (type == ui::Widget::TouchEventType::ENDED) {
            Director::getInstance()->popScene();
            if (UserDefault::getInstance()->getBoolForKey(SOUND_KEY)) {
                SimpleAudioEngine::getInstance()->playEffect(FILE_SOUND_1);
            }
        }
    });
    resumeButton->setPosition(Vec2(480, 200));

    this->addChild(resumeButton);
    return true;
}
コード例 #21
0
ファイル: UIButton.cpp プロジェクト: DominicD/Hyperdrive
void Button::copySpecialProperties(Widget *widget)
{
    Button* button = dynamic_cast<Button*>(widget);
    if (button)
    {
        _prevIgnoreSize = button->_prevIgnoreSize;
        setScale9Enabled(button->_scale9Enabled);
        auto normalSprite = button->_buttonNormalRenderer->getSprite();
        if (nullptr != normalSprite)
        {
            loadTextureNormal(normalSprite->getSpriteFrame());
        }
        auto clickedSprite = button->_buttonClickedRenderer->getSprite();
        if (nullptr != clickedSprite)
        {
            loadTexturePressed(clickedSprite->getSpriteFrame());
        }
        auto disabledSprite = button->_buttonDisableRenderer->getSprite();
        if (nullptr != disabledSprite)
        {
            loadTextureDisabled(disabledSprite->getSpriteFrame());
        }
        setCapInsetsNormalRenderer(button->_capInsetsNormal);
        setCapInsetsPressedRenderer(button->_capInsetsPressed);
        setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
        if(nullptr != button->getTitleRenderer())
        {
            setTitleText(button->getTitleText());
            setTitleFontName(button->getTitleFontName());
            setTitleFontSize(button->getTitleFontSize());
            setTitleColor(button->getTitleColor());
        }
        setPressedActionEnabled(button->_pressedActionEnabled);
        setZoomScale(button->_zoomScale);
    }

}
コード例 #22
0
ファイル: imt_mrgui.cpp プロジェクト: IMTtugraz/AGILE
void IMT_MRGui::on_actionOpen_matlab_bin_triggered()
{

  QString path( QFileDialog::getOpenFileName( this, tr("Open File"),
                                             _pathsetting->get_matlabpath(),
                                             tr("*.bin") ) );
  QFileInfo pathinfo;
  QString filename;

  if ( ! path.isNull() ) {
    pathinfo.setFile(path);
    filename = pathinfo.fileName();

    _pathsetting->set_matlabpath(pathinfo.absolutePath());

    _outfilename = pathinfo.baseName();   //set filename for outputfile

    setTitleText(_outfilename);
    gui_readMatlab(path);
  }

  _dicom=false;

}
コード例 #23
0
ファイル: UIFocusTest.cpp プロジェクト: jiaozicat/cocos2d-x
bool UIFocusTestNestedLayout3::init()
{
    if (UIFocusTestBase::init()) {
        
        Size winSize = Director::getInstance()->getVisibleSize();
        
        _verticalLayout = VBox::create();
        _verticalLayout->setPosition(Vec2(40, winSize.height - 70));
        _uiLayer->addChild(_verticalLayout);
        _verticalLayout->setScale(0.8);
        
        _verticalLayout->setFocused(true);
        _verticalLayout->setLoopFocus(true);
        _verticalLayout->setTag(-1000);
        _firstFocusedWidget = _verticalLayout;
        
        
        HBox *upperHBox = HBox::create();
        upperHBox->setTag(-200);
        _verticalLayout->addChild(upperHBox);
        
        LinearLayoutParameter *params = LinearLayoutParameter::create();
        params->setMargin(Margin(0,0,50,0));
        
        LinearLayoutParameter *vparams = LinearLayoutParameter::create();
        vparams->setMargin(Margin(10, 0, 0, 140));
        upperHBox->setLayoutParameter(vparams);
        
        int count = 3;
        for (int i=0; i<count; ++i) {
            VBox *firstVbox = VBox::create();
            firstVbox->setScale(0.5);
            firstVbox->setLayoutParameter(params);
            firstVbox->setTag((i+1) * 100);
            
            int count1 = 3;
            for (int j=0; j<count1; ++j) {
                ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
                w->setTouchEnabled(true);
                w->setTag(j+firstVbox->getTag()+1);
                w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this));
                firstVbox->addChild(w);
            }
            
            upperHBox->addChild(firstVbox);

        }
        
        HBox *bottomHBox = HBox::create();
        bottomHBox->setScale(0.5);
        bottomHBox->setTag(600);
        
        bottomHBox->setLayoutParameter(vparams);
        count = 3;
        LinearLayoutParameter *bottomParams = LinearLayoutParameter::create();
        bottomParams->setMargin(Margin(0, 0, 8, 0));
        for (int i=0; i < count; ++i) {
            ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
            w->setLayoutParameter(bottomParams);
            w->setTouchEnabled(true);
            w->setTag(i+601);
            w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this));
            bottomHBox->addChild(w);
        }
        _verticalLayout->addChild(bottomHBox);
        
     
        
        _loopText = Text::create("loop enabled", "Airal", 20);
        _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
        _loopText->setColor(Color3B::GREEN);
        this->addChild(_loopText);
        
        auto btn = Button::create("cocosui/switch-mask.png");
        btn->setTitleText("Toggle Loop");
        btn->setPosition(Vec2(60, winSize.height - 50));
        btn->setTitleColor(Color3B::RED);
        btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout3::toggleFocusLoop, this));
        this->addChild(btn);
        
        
        return true;
    }
    return false;
}
コード例 #24
0
ファイル: TableModel.cpp プロジェクト: KDE/kdiagram
bool TableModel::loadFromCSV( const QString& filename )
{
    QFile file( filename );
    if ( !file.exists() || !file.open ( QIODevice::ReadOnly ) ) {
        qDebug() << "TableModel::loadFromCSV: file" << filename
                 << "does not exist or could not be opened";
        return false;
    }

    QStringList lines;
    while ( !file.atEnd() ) {
        lines.append( QString::fromUtf8( file.readLine() ) );
    }

    setTitleText( QString() );
    m_rows.clear();
    m_rows.resize( qMax( 0, lines.size() - ( m_dataHasHorizontalHeaders ? 1 : 0 ) ) );

    for ( int row = 0; row < lines.size(); ++row ) {
        QStringList cells = splitLine( lines.at( row ) );

        QVector<QVariant> values( qMax( 0, cells.size() - ( m_dataHasVerticalHeaders ? 1 : 0 ) ) );

        for ( int column = 0; column < cells.size(); ++column ) {
            QString cell = cells.at( column );

            if ( row == 0 && m_dataHasHorizontalHeaders ) {
                // interpret the first row as column headers:
                // the first one is an exception: interpret that as title
                if ( column == 0 && m_dataHasVerticalHeaders ) {
                    setTitleText( cell );
                } else {
                    m_horizontalHeaderData.append( cell );
                }
            } else {
                if ( column == 0 && m_dataHasVerticalHeaders ) {
                    // interpret first column as row headers:
                    m_verticalHeaderData.append( cell );
                } else {
                    // try to interpret cell values as floating point
                    bool convertedOk = false;
                    qreal numeric = cell.toDouble( &convertedOk );
                    const int destColumn = column - ( m_dataHasVerticalHeaders ? 1 : 0 );
                    values[ destColumn ] = convertedOk ? numeric : ( cell.isEmpty() ? QVariant() : cell );
                }
            }
        }
        const int destRow = row - ( m_dataHasHorizontalHeaders ? 1 : 0 );
        if ( destRow >= 0 ) {
            m_rows[ destRow ] = values;
        }
    }

    beginResetModel();
    endResetModel();

    if ( m_rows.isEmpty() ) {
        qDebug() << "TableModel::loadFromCSV: table loaded, but no "
                 "model data found.";
    }
    return true;
}
コード例 #25
0
ファイル: EquipLayer.cpp プロジェクト: 37947538/Young3_7
bool EquipLayer::init()
{
    if (!PopBase::init()){
        return false;
    }
    //选择背包的ID
    currSelectBackpackID=-1;
    //选择穿戴ID
    currSelectWearpackID=-1;
    //当前选择英雄ID
    currSelectHeroID=1;
    
    equiplocalBll=EquipmentLocalBLL::create();
    equiplocalBll->retain();
    
    m_RootNode = static_cast<Layout*>(CSLoader::createNode("EquipLayer.csb"));
    this->addChild(m_RootNode);
    
    if (kIsPayTest) {
        APTools::PrintUIWidgetChildrenInfo(m_RootNode);
    }
    
    auto Button_Close=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_Close"));
    if (Button_Close) {
        Button_Close->addTouchEventListener(CC_CALLBACK_2(EquipLayer::Button_Exit_BtnOnTouch, this));
    }
    auto Button_xiezai=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_xiezai"));
    if (Button_xiezai) {
        Button_xiezai->addTouchEventListener(CC_CALLBACK_2(EquipLayer::Button_xiezai_BtnOnTouch, this));
    }
    auto Button_chushou=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_chushou"));
    if (Button_chushou) {
        Button_chushou->addTouchEventListener(CC_CALLBACK_2(EquipLayer::Button_chushou_BtnOnTouch, this));
    }
    auto Button_shiyong=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_shiyong"));
    if (Button_shiyong) {
        Button_shiyong->addTouchEventListener(CC_CALLBACK_2(EquipLayer::Button_shiyong_BtnOnTouch, this));
    }
    
    sv_backpack=dynamic_cast<ui::ScrollView*>(Helper::seekWidgetByName(m_RootNode, "ScrollView_wupinlan"));
    m_EquipPanel=dynamic_cast<Layout*>(Helper::seekWidgetByName(m_RootNode, "Panel_zhuangbeilan"));
    m_WearPanel=dynamic_cast<Layout*>(Helper::seekWidgetByName(m_RootNode, "Panel_zhuangbei"));
    m_BackPanel=dynamic_cast<Layout*>(Helper::seekWidgetByName(m_RootNode, "Panel_wupin"));
    //选择英雄
    sv_Menu = dynamic_cast<ui::ScrollView*>(Helper::seekWidgetByName(m_RootNode, "ScrollView_menu"));
    auto sv_MenuSize=sv_Menu->getInnerContainerSize();
    
    auto pb=PlayerBLL::create();
    
    int iRow=0;
    HeroModelBLL *hmb=HeroModelBLL::create(kModelWritablePath);
    for (int i=0; i<HeroModel_MaxData; i++) {
        if (pb->getIsBuyHero(i)) {
            HeroModel *hm=&(hmb->modelData[i]);
            auto btn=Button::create();
            btn->setTag(i+1);
            btn->loadTextureNormal("imgs/tb_qiehuan_2.png");
            btn->loadTextureDisabled("imgs/tb_qiehuan_1.png");
            btn->addTouchEventListener(CC_CALLBACK_2(EquipLayer::heroButton_OnTouch, this));
            btn->setPosition(Vec2(sv_MenuSize.width/2, sv_MenuSize.height-((iRow * 100)+60)));
            btn->setTitleText(hm->HeroName);
            sv_Menu->addChild(btn);
            
            m_HeroItemButtons.pushBack(btn);
            iRow++;
        }
    }
    m_HeroItemButtons.at(0)->setTouchEnabled(false);
    m_HeroItemButtons.at(0)->setBright(false);
    
    m_Panel=dynamic_cast<Layout*>(Helper::seekWidgetByName(m_RootNode, "Panel_juese"));
    //角色基本属性
    t_lv=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "t_LV"));
    t_currExp=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "t_currExp"));
    t_power=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "t_strength"));
    t_currHP=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "t_currHP"));
    t_attack=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_Attack"));
    t_def=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_Def"));
    t_critical=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_critical"));
    //金币数量
    t_gold=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_jinbishu"));
    //增加的属性
    t_addcurrHP=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "t_currHP_add"));
    t_addattack=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_Attack_add"));
    t_adddef=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_Def_add"));
    t_addcritical=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "T_critical_add"));
    //佩戴物品说明
    t_wearpackDes=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_zhuangbeixinxi"));
    t_backpackDes=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_shuxing"));
    //佩戴物品名
    t_wearitemname=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_wupinmingcheng_1"));
    //包裹物品名
    t_backitemname=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_wupinmingcheng_2"));
    //选中物品边框
    s_wearborder = Sprite::create("imgs/k_xuanzhong.png");
    m_RootNode->addChild(s_wearborder);
    
    //英雄
    HeroBase *hero=GameObjectFactory::getHero(currSelectHeroID-1);
    //刷新数据
    updateInfo(hero->getHeroModel());
    
    showWearpack();
    showBackpack();
    
    setWearpackDataView(false);
    setBackpackDataView(false);
    
    return true;
}
コード例 #26
0
cocos2d::ui::Button* GameLayer::create_button(std::string text, BoolFuncNoArgs cb, bool start_disabled, ButtonState* btn_state)
{
    auto param = ui::LinearLayoutParameter::create();
    param->setGravity(ui::LinearLayoutParameter::LinearGravity::CENTER_HORIZONTAL);

    auto disable_button = [](ui::Button* button)
    {
        button->setTitleColor(Color3B::GRAY);
        button->setTouchEnabled(false);
        button->setPressedActionEnabled(false);
    };

    auto btn = ui::Button::create("main_UI_export_10_x4.png", "", "", ui::TextureResType::PLIST);

    btn->setTitleFontName(menu_font);
    btn->setTitleFontSize(menu_fontsize);
    btn->setTitleColor(Color3B::BLACK);
    btn->getTitleRenderer()->getTexture()->setAliasTexParameters();

    btn->setColor(Color3B(114, 160, 72));

    btn->getVirtualRenderer()->setScale(sx(1.0f));
    btn->setScaleX(sx(1.0f));
    btn->setScaleY(sy(1.0f));

    param->setMargin(ui::Margin(0, sy(15.0f)*btn->getScaleY(), 0, sy(15.0f)*btn->getScaleY()));

    btn->setLayoutParameter(param);
    btn->setTouchEnabled(true);
    btn->setPressedActionEnabled(true);

    if (start_disabled) 
    {
        disable_button(btn);
    };

    btn->setTitleText(text);
    if (btn_state)
    {
        //update the text
        btn_state->swap_state(btn, btn_state->current);
    };

    btn->addTouchEventListener(
        [btn_state, cb, btn, disable_button](Ref* ref, ui::Widget::TouchEventType event)
            {
                if (event == ui::Widget::TouchEventType::ENDED)
                {
                    if (!cb())
                    {
                        disable_button(btn);
                    };
                    if (btn_state)
                    {
                        btn_state->current = !btn_state->current;
                        btn_state->swap_state(btn, btn_state->current);
                    };
                }
            }
    );

    return btn;

};
コード例 #27
0
ファイル: LearnScene.cpp プロジェクト: atapie/gre-hit-parade
// on "init" you need to initialize your instance
bool LearnScene::init()
{
    if ( !LayerColor::initWithColor(Constants::BACKGROUND_COLOR) )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    // Home btn
    auto btn = ui::Button::create("HomeBtn", "HomeBtn", "", ui::Widget::TextureResType::PLIST);
    btn->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT);
    btn->setPosition(Vec2(origin.x + visibleSize.width, origin.y + visibleSize.height));
    btn->addTouchEventListener(CC_CALLBACK_2(LearnScene::touchEvent, this));
    this->addChild(btn, 1, 1);
    
    // Learn progress txt
    float retainedPercent = round(Constants::getRetainedWordCount() * 100 / Constants::getTotalWordCount());
    std::stringstream stm;
    stm << "Learning progress: " << retainedPercent << "%";
    auto label = Label::createWithBMFont(Constants::FONT_BOLD12, stm.str());
    label->setColor(Color3B::BLACK);
    label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
    label->setPosition(origin.x + 14, origin.y + visibleSize.height - 28);
    this->addChild(label, 2, 2);
    
    // Learn progress bar
    auto sprite9 = ui::Scale9Sprite::createWithSpriteFrameName("PbBg", Rect(2, 2, 2, 2));
    sprite9->setContentSize(Size(visibleSize.width - 28, 18));
    sprite9->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - 60));
    this->addChild(sprite9, 3, 3);
    
    auto pb = ui::Scale9Sprite::createWithSpriteFrameName("PbProgress", Rect(2, 2, 2, 2));
    Size pbSize = sprite9->getContentSize();
    pbSize.width *= retainedPercent / 100;
    if(pbSize.width < 6) pbSize.width = 6;
    pb->setContentSize(pbSize);
    pb->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
    sprite9->addChild(pb, 1, 1);
    
    // Text area
    sprite9 = ui::Scale9Sprite::createWithSpriteFrameName("TextArea", Rect(12, 12, 12, 12));
    sprite9->setContentSize(Size(visibleSize.width-28, visibleSize.height - 264));
    sprite9->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - 86 - sprite9->getContentSize().height / 2));
    this->addChild(sprite9, 4, 4);
    
    // choices
    btn = ui::Button::create("ChoiceBg", "ChoiceSelectedBg", "", ui::Widget::TextureResType::PLIST);
    btn->setScale9Enabled(true);
    btn->setCapInsets(Rect(5, 5, 5, 5));
    btn->setSize(Size(visibleSize.width-28, 30));
    btn->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + 148));
    btn->getTitleRenderer()->setBMFontFilePath(Constants::FONT_REGULAR12);
    btn->getTitleRenderer()->setColor(Color3B::BLACK);
    btn->setTitleText("I know this word.");
    btn->addTouchEventListener(CC_CALLBACK_2(LearnScene::touchEvent, this));
    this->addChild(btn, 5, 5);
    btn = ui::Button::create("ChoiceBg", "ChoiceSelectedBg", "", ui::Widget::TextureResType::PLIST);
    btn->setScale9Enabled(true);
    btn->setCapInsets(Rect(5, 5, 5, 5));
    btn->setSize(Size(visibleSize.width-28, 30));
    btn->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + 103));
    btn->getTitleRenderer()->setBMFontFilePath(Constants::FONT_REGULAR12);
    btn->getTitleRenderer()->setColor(Color3B::BLACK);
    btn->setTitleText("Not yet!");
    btn->addTouchEventListener(CC_CALLBACK_2(LearnScene::touchEvent, this));
    this->addChild(btn, 6, 6);
    
    // check btn
    btn = ui::Button::create("BtnNormal", "BtnPressed", "BtnDisabled", ui::Widget::TextureResType::PLIST);
    btn->setScale9Enabled(true);
    btn->setCapInsets(Rect(12, 12, 12, 12));
    btn->setSize(Size(visibleSize.width-28, 58));
    btn->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + 45));
    btn->getTitleRenderer()->setBMFontFilePath(Constants::FONT_BOLD30);
    btn->setTitleText("Check");
    btn->addTouchEventListener(CC_CALLBACK_2(LearnScene::touchEvent, this));
    this->addChild(btn, 7, 7);
    btn->setEnabled(false);
    btn->setBright(false);
    
    // term
    std::string nextWord = Constants::getNextWordToLearn();
    label = Label::createWithBMFont(Constants::FONT_BOLD30, nextWord);
    label->setColor(Color3B::BLACK);
    label->setPosition(sprite9->getContentSize().width/2, sprite9->getContentSize().height/2);
    sprite9->addChild(label, 1, 1);
    
    // definition
    const ValueMap& wInfo = Configuration::getInstance()->getValue("words").asValueMap().at(nextWord).asValueMap();
    auto it = wInfo.find("ldef");
    std::string ldef = it != wInfo.end() ? it->second.asString() : "Missing definition";
    label = Label::createWithBMFont(Constants::FONT_REGULAR14, ldef);
    label->setColor(Color3B::BLACK);
    label->setWidth(sprite9->getContentSize().width - 28);
    label->setAlignment(TextHAlignment::LEFT);
    label->setPosition(sprite9->getContentSize().width/2, sprite9->getContentSize().height/2);
    sprite9->addChild(label, 2, 2);
    label->setOpacity(0);
    label->setVisible(false);
    
    // play sound
    Constants::playText(nextWord);
    
    // init vars
    this->startTime = time(0);
    this->showNext = false;
    this->answerChoice = -1;
    
    return true;
}
コード例 #28
0
ファイル: MenuScene.cpp プロジェクト: Nordsoft91/MagicWars
    bool MainMenu::init()
    {
        if(!cocos2d::Scene::init())
            return false;
        
        auto sz = cocos2d::Director::getInstance()->getVisibleSize();
        auto origin = cocos2d::Director::getInstance()->getVisibleOrigin();
        
#ifdef RESET_GAMEPLAY
        cocos2d::UserDefault::getInstance()->setIntegerForKey("WizardWay_level",0); //USERDATA
#endif
#ifdef ALL_AVAILABLE
        cocos2d::UserDefault::getInstance()->setIntegerForKey("WizardWay_level",10); //USERDATA
#endif
        loadSpriteSheetFromXml("uipack_rpg_sheet.png", "uipack_rpg_sheet.xml");
        
		auto* backgroundImage = cocos2d::Sprite::create(RES("menu","Sphash.jpg"));
		float scaleFactorH = sz.height / backgroundImage->getContentSize().height;
        float scaleFactorW = sz.width / backgroundImage->getContentSize().width;
        
        auto* layout = cocos2d::ui::Layout::create();
        layout->setBackGroundImage(RES("menu","Sphash.jpg"));
        layout->cocos2d::Node::setPosition(sz.width/2+origin.x, sz.height/2+origin.y);
        layout->setScale(scaleFactorW, scaleFactorH);
        
        auto* box = cocos2d::ui::RelativeBox::create({220,180});
        box->setAnchorPoint({0.5, 0.5});
        box->setBackGroundImage("panel_brown.png", cocos2d::ui::TextureResType::PLIST);
        box->setBackGroundImageScale9Enabled(true);
        layout->addChild(box);
        
        auto buttonNewGame = cocos2d::ui::Button::create("buttonLong_beige.png", "buttonLong_beige_pressed.png", "buttonLong_blue.png", cocos2d::ui::TextureResType::PLIST);
        buttonNewGame->setTitleText("Play MagicWars");
        buttonNewGame->addTouchEventListener([&](Ref* sender, cocos2d::ui::Widget::TouchEventType type){
            if(type==cocos2d::ui::Widget::TouchEventType::ENDED)
            {
                auto scene = CampaignSelect::create();
                cocos2d::Director::getInstance()->replaceScene(cocos2d::TransitionFade::create(1.5, scene));
            }
        });
        buttonNewGame->setPosition({0,50});
        layout->addChild(buttonNewGame);
        
        auto buttonSandbox = cocos2d::ui::Button::create("buttonLong_beige.png", "buttonLong_beige_pressed.png", "buttonLong_blue.png", cocos2d::ui::TextureResType::PLIST);
        buttonSandbox->setTitleText("Sandbox");
        buttonSandbox->addTouchEventListener([&](Ref* sender, cocos2d::ui::Widget::TouchEventType type){
            if(type==cocos2d::ui::Widget::TouchEventType::ENDED)
            {
                CampaignReader::Mission mission{"Песочница", "map_L_frument.txt", "map_sandbox_triggers.txt", "mapRule_frument.txt", "", "", {}, 0, 0};
                auto scene = HelloWorld::createScene(mission);
                cocos2d::Director::getInstance()->replaceScene(cocos2d::TransitionFade::create(1, scene));
            }
        });
#ifndef SANDBOX
        buttonSandbox->setEnabled(false);
#endif
        buttonSandbox->setPosition({0,0});
        layout->addChild(buttonSandbox);
        
        addChild(layout);
        
        return true;
    }
コード例 #29
0
ファイル: BattleUI.cpp プロジェクト: cxfshelter/TokenGame
void BattleUI::InitHeroUI()
{
    ArmatureDataManager::getInstance()->addArmatureFileInfo("Texiao.ExportJson");
    
    auto layout_Bottom = m_RootWidget->getChildByName<Layout*>("Layout_Bottom");
    
    auto text_HeroText = layout_Bottom->getChildByName<Text*>("Text_HeroText");
    
    auto langId = (int)LanguageIdEnum::SelfLangId;
    auto langText = MultiLanguage::getInstance()->GetText(langId);
    text_HeroText->setString(langText);
    
    auto lbar_HeroHp = layout_Bottom->getChildByName<LoadingBar*>("LBar_HeroHp");
    lbar_HeroHp->setPercent(100);
    
    
    //自动或手动控制战斗
    auto btn_Auto = layout_Bottom->getChildByName<Button*>("Btn_Auto");
    auto btn_UnAuto = layout_Bottom->getChildByName<Button*>("Btn_UnAuto");
    if (BattleData::getInstance()->m_HeroAutoAttack)
    {
        btn_Auto->setVisible(true); btn_UnAuto->setVisible(false);
        
    }else
    {
        btn_Auto->setVisible(false); btn_UnAuto->setVisible(true);
    }
    
    langId = (int)LanguageIdEnum::AutoAttackLangId;
    langText = MultiLanguage::getInstance()->GetText(langId);
    btn_Auto->setTitleText(langText); btn_UnAuto->setTitleText(langText);
    btn_Auto->addClickEventListener([=](Ref* sender)
     {
         btn_Auto->setVisible(false);
         btn_UnAuto->setVisible(true);
         BattleData::getInstance()->m_HeroAutoAttack = false;
         UserData::getInstance()->Update_Value(UserDataEnum::AutoAttack, Value(0));
     });
    
    btn_UnAuto->addClickEventListener([=](Ref* sender)
    {
        btn_Auto->setVisible(true);
        btn_UnAuto->setVisible(false);
        for (auto pb : *m_VecProgressBar) pb->Resume();
        BattleData::getInstance()->m_HeroAutoAttack = true;
        UserData::getInstance()->Update_Value(UserDataEnum::AutoAttack, Value(1) );
    });
    
    auto btn_Bread = layout_Bottom->getChildByName<Button*>("Btn_Bread");
    auto text_BreadName = btn_Bread->getChildByName<Text*>("Text_BreadNAME");
    langId = (int)LanguageIdEnum::BreadLangId;
    langText = MultiLanguage::getInstance()->GetText(langId);
    text_BreadName->setString(langText);
    
    auto text_Bread = btn_Bread->getChildByName<Text*>("Text_Bread");
    
    
    auto bread_Num = 0;
    auto breadData = UserData::getInstance()->Get_MVI_Value(UserDataEnum::BackPack, (int)CfgIdEnum::BreadId);
    if(breadData != Value::Null) bread_Num = breadData.asInt();
    
    text_Bread->setString(StringUtils::format("%d", bread_Num));
    
    auto lbar_Bread = btn_Bread->getChildByName<LoadingBar*>("LBar_Bread");
    
    string pbName = "BreadHpSchedule";
    auto progressBar = new ProgressBar();
    progressBar->SetTotalTime(3); //3秒吃一个面包
    progressBar->SetScheduleName(pbName);
    progressBar->SetLoadingBar(lbar_Bread);
    
    m_VecProgressBar->push_back(progressBar);
    
    progressBar->SetCallBack([this, progressBar]()
     {
         progressBar->Restart();
         progressBar->GetLoadingBar()->setPercent(0);
         m_RootWidget->unschedule(progressBar->GetScheduleName());
     });
    
    
    btn_Bread->addClickEventListener([=](Ref* sender)
     {

         auto bread_Num = 0;
         auto breadData = UserData::getInstance()->Get_MVI_Value(UserDataEnum::BackPack, (int)CfgIdEnum::BreadId);
         if(breadData != Value::Null) bread_Num = breadData.asInt();

         if (bread_Num == 0)
         {
             auto langId = (int)LanguageIdEnum::BreadNotEnoughId;
             auto langText = MultiLanguage::getInstance()->GetText(langId);
             MoveText::getInstance()->AddDefaultTextData(m_RootWidget, langText);
         }else
         {
             if(progressBar->GetRemainTime() == progressBar->GetTotalTime())
             {
                 auto bread_Num = UserData::getInstance()->Update_VMI_Fun(
                                  UserDataEnum::BackPack, (int)CfgIdEnum::BreadId, -1);
                 if (bread_Num >= 0)
                 {
                     text_Bread->setString(StringUtils::format("%d", bread_Num));
                     //回血
                     BattleData::getInstance()->BreadRevertHp();
                     
                     m_RootWidget->schedule([this, progressBar](float f)
                        {
                            progressBar->Update(f);
                        }, progressBar->GetScheduleName());
                 }
             }
             AchievementSystem::getInstance()->CheckAchievement(UserEventType::BattleEatBread, 1);
         }
     });
    
    vector<pair<int, int> >heroVec;
    BattlePubUI::getInstance()->GetBackPackHero(&heroVec);
    auto idx = 0; //创建英雄技能
    for (auto heroData : heroVec)
    {
        auto heroId = heroData.first;
        auto heroNum = heroData.second;
        for (auto i = 0; i < heroNum ; i++)
        {
            CreateHeroEvent(heroId, idx);  idx++;
        }
    }

    auto talentTeamTotalHp = BattleData::getInstance()->m_TalentTeamTotalHp;
    auto text_HeroHp = layout_Bottom->getChildByName<Text*>("Text_HeroHp");
    text_HeroHp->setString(StringUtils::format("%d/%d", talentTeamTotalHp, talentTeamTotalHp));
    
    BattleData::getInstance()->m_HeroHpLBar = lbar_HeroHp;
    BattleData::getInstance()->m_TextHeroHp = text_HeroHp;

}
コード例 #30
0
ファイル: UIFocusTest.cpp プロジェクト: jiaozicat/cocos2d-x
bool UIFocusTestListView::init()
{
    if (UIFocusTestBase::init()) {
        
        Size winSize = Director::getInstance()->getVisibleSize();
        
        _listView = ListView::create();
        _listView->setDirection(ui::ScrollView::Direction::VERTICAL);
        _listView->setBounceEnabled(true);
        _listView->setBackGroundImage("cocosui/green_edit.png");
        _listView->setBackGroundImageScale9Enabled(true);
        _listView->setContentSize(Size(240, 130));
        
        _listView->setPosition(Vec2(40, 70));
        _uiLayer->addChild(_listView);
        _listView->setScale(0.8);
        
        _listView->setFocused(true);
        _listView->setLoopFocus(true);
        _listView->setTag(-1000);
        _firstFocusedWidget = _listView;
        
        // create model
        Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
        default_button->setName("Title Button");
        
        
        // set model
        _listView->setItemModel(default_button);
        
        // add default item
        ssize_t count = 20;
        for (int i = 0; i < count / 4; ++i)
        {
            _listView->pushBackDefaultItem();
        }
        // insert default item
        for (int i = 0; i < count / 4; ++i)
        {
            _listView->insertDefaultItem(0);
        }
        
        
        
        _loopText = Text::create("loop enabled", "Airal", 20);
        _loopText->setPosition(Vec2(winSize.width/2, winSize.height - 50));
        _loopText->setColor(Color3B::GREEN);
        this->addChild(_loopText);
        
        auto btn = Button::create("cocosui/switch-mask.png");
        btn->setTitleText("Toggle Loop");
        btn->setPosition(Vec2(60, winSize.height - 50));
        btn->setTitleColor(Color3B::RED);
        btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestListView::toggleFocusLoop, this));
        this->addChild(btn);
        
        
        return true;
    }
    return false;
}