예제 #1
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

	CCRect rect1(133, 333, 42, 46);
	CCScale9Sprite* btnNormal = CCScale9Sprite::create("char_bluelight.png",rect1);  
	CCScale9Sprite* btnDown = CCScale9Sprite::create("char_bluelight.png",rect1);  
	CCControlButton* controlBtn = CCControlButton::create(btnNormal);  
	controlBtn->setBackgroundSpriteForState(btnDown, CCControlStateSelected);  
	controlBtn->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));  
	controlBtn->setPreferredSize(CCSize(60, 50));  
	controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDownAction), CCControlEventTouchDown);
	this->addChild(controlBtn);  
    
    return true;
}
예제 #2
0
CCControlButton* ButtonUtils::createButton(const char *normalFrame, const char *highLightFrame, const char *disableFrame, cocos2d::CCSize size, const char *label,float labelSize ,ccColor3B labelColor)
{
    CCScale9Sprite *normal = CCScale9Sprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(normalFrame));
    CCScale9Sprite *highLight = CCScale9Sprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(highLightFrame));
    CCScale9Sprite *disable = CCScale9Sprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(disableFrame));
    CCControlButton *btn = CCControlButton::create(label, "Arial", labelSize);
    btn->setPreferredSize(size);
    btn->setBackgroundSpriteForState(normal, CCControlStateNormal);
    btn->setBackgroundSpriteForState(highLight, CCControlStateHighlighted);
    btn->setBackgroundSpriteForState(disable, CCControlStateDisabled);
    btn->setTitleColorForState(labelColor, CCControlStateNormal);
    btn->setTitleColorForState(labelColor, CCControlStateHighlighted);
    btn->setTitleColorForState(labelColor, CCControlStateDisabled);
    btn->setTouchPriority(0);
    
    return btn;
}
예제 #3
0
bool TutorialLayer::init(){
    if (CCLayer::init()) {
        callback = NULL;
        target = NULL;
        
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        CCLayerColor *background = CCLayerColor::create(ccc4(0, 0, 0, 200), screenSize.width, screenSize.height);
        this->addChild(background);

        CCScale9Sprite *closeButtonSprite = Common::getCCScale9SpriteWithoutScale("CloseButton.png");
        CCControlButton *closeButton = CCControlButton::create(closeButtonSprite);
        closeButton->setPreferredSize(closeButtonSprite->getOriginalSize());
        closeButton->setContentSize(closeButtonSprite->getOriginalSize());
        closeButton->setPosition(ccp(screenSize.width*0.9, screenSize.height*0.9));
        closeButton->addTargetWithActionForControlEvents(this, cccontrol_selector(TutorialLayer::close), CCControlEventTouchUpInside);
        this->addChild(closeButton, CLOSE_BUTTON_Z);
        
        return true;
    }
    return false;
}
void QuestionLayer::displaySubViews()
{
    CCLOG("%f %f %f %f", this->getPositionX(), this->getPositionY(), this->getContentSize().width, this->getContentSize().height);

    CCArray* answer = questionObj->answerArray;

    int columns = 0;
    int rows = 0;
    float spaceX = 0;
    if (answer->count() <= 2) {
        //判断题2X1个
        columns = 2;
        rows = 1;
        spaceX = 80;
    } else if (answer->count() <= 3) {
        //3选1
        columns = 1;
        rows = 3;
        spaceX = 40;
    } else if (answer->count() <= 4) {
        //最多2x2个答案选项的
        columns = 2;
        rows = (answer->count()*1.0f/columns)>(answer->count()/columns)?(answer->count()/columns+1):(answer->count()/columns);
        spaceX = 60;
    } else if (answer->count() <= 9) {
        //最多3x3个答案选项
        columns = 3;
        rows = (answer->count()*1.0f/columns)>(answer->count()/columns)?(answer->count()/columns+1):(answer->count()/columns);
        spaceX = 40;
    } else if (answer->count() <= 16) {
        //最多4x4个答案选项
        columns = 4;
        rows = (answer->count()*1.0f/columns)>(answer->count()/columns)?(answer->count()/columns+1):(answer->count()/columns);
        spaceX = 20;
    }
    float spaceY = spaceX*(CCDirector::sharedDirector()->getWinSize().height/1334);

    //题目标题栏高度
    float topHeight = 190;
    CCLOG("%f %f", this->getContentSize().width, this->getContentSize().height);
    //
    float totalWidth = this->getContentSize().width;
    float cellWidth = (totalWidth-spaceX*(columns+1))/columns;
    float totalHeight = this->getContentSize().height-topHeight-50; //要减去答题头部区域
    float cellHeight = (totalHeight-spaceY*(rows+1))/rows;
    CCLOG("[%d %d]:%f %f", columns, rows, cellWidth, cellHeight);
    while (cellHeight > cellWidth) {
        spaceY += 10;
        cellHeight = (totalHeight-spaceY*(rows+1))/rows;
    }
    for (int i=0; i<answer->count(); i++) {
        //
        CCString* ans = (CCString *)(answer->objectAtIndex(i));
        CCLabelTTF* pLabel = CCLabelTTF::create(ans->getCString(), "Arial", 24, CCSizeMake(cellWidth, cellHeight), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
        CCControlButton* button = CCControlButton::create(pLabel, CCScale9Sprite::create("button_answer.png", CCRectMake(0, 0, 126, 70)));
        button->addTargetWithActionForControlEvents(this, cccontrol_selector(QuestionLayer::touchDownAction), CCControlEventTouchUpInside);
        button->setTag(i+1);
        button->setAnchorPoint(ccp(0.5f, 0.5f));
//        button->setPosition( ccp(-totalWidth/2+spaceX+(cellWidth+spaceX)*(i%columns)+cellWidth/2, -topHeight/2-totalHeight/2+spaceY+(cellHeight+spaceY)*(i/columns)+cellHeight/2) );
        button->setPosition( ccp(-totalWidth/2+spaceX+(cellWidth+spaceX)*(i%columns)+cellWidth/2, (totalHeight-topHeight)/2-spaceY-(cellHeight+spaceY)*(i/columns)-cellHeight/2) );
        CCLOG("button坐标:%f %f", button->getPositionX(), button->getPositionY());
        button->setPreferredSize(CCSize(cellWidth, cellHeight));
        this->addChild(button, 1);
    }
}
예제 #5
0
bool QimiAlipayView::init()
{
    UIMaskLayerView* mask = UIMaskLayerView::create();
    this->addChild(mask);
    
    m_pButtonList = CCArray::create();
    m_pButtonList->retain();
    
    CCSize m_size = CCDirector::sharedDirector()->getWinSize();
    
    CCNode* container = CCNode::create();
    container->setTag(100);
    this->addChild(container);
    container->setPosition(ccp(m_size.width/2, m_size.height/2-45));
    
    CCNode* topCCNode = CCNode::create();
    topCCNode->setPosition(ccp(m_size.width/2, m_size.height-45));
    this->addChild(topCCNode);
    
    
    CCSprite* bgTop = CCSprite::create("bg_top.png");
    topCCNode->addChild(bgTop);
    bgTop->setPosition(ccp(0, 0));
    
    
    CCControlButton* backBtn = CCControlButton::create(CCScale9Sprite::create("btn_fanhui.png"));
    backBtn->setPreferredSize(CCSizeMake(101, 51));
    backBtn->setTouchPriority(-1000);
    topCCNode->addChild(backBtn);
    backBtn->setPosition(ccp(-163, 0));
    backBtn->addTargetWithActionForControlEvents(this,
                                                 cccontrol_selector(QimiAlipayView::backOnClick),
                                                 CCControlEventTouchUpInside);
    
    
    CCControlButton* helpBtn = CCControlButton::create(CCScale9Sprite::create("btn_bangzhu.png"));
    helpBtn->setPreferredSize(CCSizeMake(93, 51));
    helpBtn->setTouchPriority(-1000);
    topCCNode->addChild(helpBtn);
    helpBtn->setPosition(ccp(163, 0));
    helpBtn->addTargetWithActionForControlEvents(this,
                                                 cccontrol_selector(QimiAlipayView::qimiHelp),
                                                 CCControlEventTouchUpInside);
    
    CCLabelTTF* topText = CCLabelTTF::create("奇米支付中心", "Helvetica", 28);
    topCCNode->addChild(topText);
    topText->setColor(ccc3(104, 67, 2));
    topText->setPosition(ccp(0, 0));
    
    
    
    CCSprite* bg = CCSprite::create("bg_dabeijing_480x800.png");
    bg->setPosition(ccp(0, 0));
    container->addChild(bg);
    
    
    ////////////公共部分结束
    
    
    CCRect form = CCRectMake(0, 0, 40, 40);
    CCRect capInset = CCRectMake(10, 10, 10, 10);
    CCScale9Sprite* scale9Sprite = CCScale9Sprite::create("bg_40x40.png", form, capInset);
    scale9Sprite->setContentSize(CCSizeMake(445, 560));
    scale9Sprite->setPosition(ccp(0, 12));
    container->addChild(scale9Sprite);
    
//    CCNode* containerCCNode = CCNode::create();
//    container->addChild(containerCCNode);
//    containerCCNode->setPosition(ccp(6, 418));

    CCLabelTTF* txtTitle = CCLabelTTF::create("请选择充值金额(1元=10元宝)", "Helvetica", 26);
    container->addChild(txtTitle);
    txtTitle->setColor(ccc3(0, 0, 0));
    txtTitle->setPosition(ccp(-204, 259));
    txtTitle->setAnchorPoint(ccp(0, 0.5));
    
    
    CCControlButton* m_pBtnCongzhi = CCControlButton::create(CCScale9Sprite::create("btn_querenchongzhi.png"));

    m_pBtnCongzhi->setPreferredSize(CCSizeMake(248, 74));
    m_pBtnCongzhi->setTouchPriority(-1000);
    container->addChild(m_pBtnCongzhi);
    m_pBtnCongzhi->setPosition(ccp(0, -167));
    m_pBtnCongzhi->addTargetWithActionForControlEvents(this,
                                                         cccontrol_selector(QimiAlipayView::rechargeOnClick),
                                                         CCControlEventTouchUpInside);

    CCLabelTTF* label10 = CCLabelTTF::create("10元", "Helvetica", 18);
    label10->setColor(ccc3(0, 0, 0));
    CCControlButton* m_pBtn10Select = CCControlButton::create(label10, CCScale9Sprite::create("bg_40x40.png"));
    m_pBtn10Select->setBackgroundSpriteForState(CCScale9Sprite::create("bg_seleceted.png"), CCControlStateDisabled);
    m_pBtn10Select->setPreferredSize(CCSizeMake(196, 47));
    m_pBtn10Select->setTouchPriority(-1000);
    container->addChild(m_pBtn10Select);
    m_pBtn10Select->setPosition(ccp(-104, 192));
    m_pBtn10Select->setTag(10);
    m_pBtn10Select->addTargetWithActionForControlEvents(this,
                                                    cccontrol_selector(QimiAlipayView::selected),
                                                    CCControlEventTouchUpInside);

   
    CCLabelTTF* label20 = CCLabelTTF::create("20元", "Helvetica", 18);
    label20->setColor(ccc3(0, 0, 0));
    CCControlButton* m_pBtn20Select = CCControlButton::create(label20, CCScale9Sprite::create("bg_40x40.png"));
    m_pBtn20Select->setBackgroundSpriteForState(CCScale9Sprite::create("bg_seleceted.png"), CCControlStateDisabled);
    m_pBtn20Select->setPreferredSize(CCSizeMake(196, 47));
    m_pBtn20Select->setTouchPriority(-1000);
    container->addChild(m_pBtn20Select);
    m_pBtn20Select->setPosition(ccp(107, 192));
    m_pBtn20Select->setTag(20);
    m_pBtn20Select->addTargetWithActionForControlEvents(this,
                                                        cccontrol_selector(QimiAlipayView::selected),
                                                        CCControlEventTouchUpInside);

    
    CCLabelTTF* label30 = CCLabelTTF::create("30元", "Helvetica", 18);
    label30->setColor(ccc3(0, 0, 0));
    CCControlButton* m_pBtn30Select = CCControlButton::create(label30,CCScale9Sprite::create("bg_40x40.png"));
    m_pBtn30Select->setBackgroundSpriteForState(CCScale9Sprite::create("bg_seleceted.png"), CCControlStateDisabled);
    m_pBtn30Select->setPreferredSize(CCSizeMake(196, 47));
    m_pBtn30Select->setTouchPriority(-1000);
    container->addChild(m_pBtn30Select);
    m_pBtn30Select->setPosition(ccp(-104, 136));
    m_pBtn30Select->setTag(30);
    m_pBtn30Select->addTargetWithActionForControlEvents(this,
                                                        cccontrol_selector(QimiAlipayView::selected),
                                                        CCControlEventTouchUpInside);
    
    
    CCLabelTTF* label50 = CCLabelTTF::create("50元", "Helvetica", 18);
    label50->setColor(ccc3(0, 0, 0));
    CCControlButton* m_pBtn50Select = CCControlButton::create(label50, CCScale9Sprite::create("bg_40x40.png"));
    m_pBtn50Select->setBackgroundSpriteForState(CCScale9Sprite::create("bg_seleceted.png"), CCControlStateDisabled);
    m_pBtn50Select->setPreferredSize(CCSizeMake(196, 47));
    m_pBtn50Select->setTouchPriority(-1000);
    container->addChild(m_pBtn50Select);
    m_pBtn50Select->setPosition(ccp(107, 136));
    m_pBtn50Select->setTag(50);
    m_pBtn50Select->addTargetWithActionForControlEvents(this,
                                                        cccontrol_selector(QimiAlipayView::selected),
                                                        CCControlEventTouchUpInside);
    
    CCLabelTTF* label100 = CCLabelTTF::create("100元", "Helvetica", 18);
    label100->setColor(ccc3(0, 0, 0));
    CCControlButton* m_pBtn100Select = CCControlButton::create(label100,CCScale9Sprite::create("bg_40x40.png"));
    m_pBtn100Select->setBackgroundSpriteForState(CCScale9Sprite::create("bg_seleceted.png"), CCControlStateDisabled);
    m_pBtn100Select->setPreferredSize(CCSizeMake(196, 47));
    m_pBtn100Select->setTouchPriority(-1000);
    container->addChild(m_pBtn100Select);
    m_pBtn100Select->setPosition(ccp(-104, 83));
    m_pBtn100Select->setTag(100);
    m_pBtn100Select->addTargetWithActionForControlEvents(this,
                                                        cccontrol_selector(QimiAlipayView::selected),
                                                        CCControlEventTouchUpInside);
    
    CCLabelTTF* label300 = CCLabelTTF::create("300元", "Helvetica", 18);
    label300->setColor(ccc3(0, 0, 0));
    CCControlButton* m_pBtn300Select = CCControlButton::create(label300, CCScale9Sprite::create("bg_40x40.png"));
    m_pBtn300Select->setBackgroundSpriteForState(CCScale9Sprite::create("bg_seleceted.png"), CCControlStateDisabled);
    m_pBtn300Select->setPreferredSize(CCSizeMake(196, 47));
    m_pBtn300Select->setTouchPriority(-1000);
    container->addChild(m_pBtn300Select);
    m_pBtn300Select->setPosition(ccp(107, 82));
    m_pBtn300Select->setTag(300);
    m_pBtn300Select->addTargetWithActionForControlEvents(this,
                                                         cccontrol_selector(QimiAlipayView::selected),
                                                         CCControlEventTouchUpInside);
    
    CCLabelTTF* label500 = CCLabelTTF::create("500元", "Helvetica", 18);
    label500->setColor(ccc3(0, 0, 0));
    
    CCControlButton* m_pBtn500Select = CCControlButton::create(label500, CCScale9Sprite::create("bg_40x40.png"));
    m_pBtn500Select->setBackgroundSpriteForState(CCScale9Sprite::create("bg_seleceted.png"), CCControlStateDisabled);
    m_pBtn500Select->setPreferredSize(CCSizeMake(196, 47));
    m_pBtn500Select->setTouchPriority(-1000);
    container->addChild(m_pBtn500Select);
    m_pBtn500Select->setPosition(ccp(-104, 26));
    m_pBtn500Select->setTag(500);
    m_pBtn500Select->addTargetWithActionForControlEvents(this,
                                                         cccontrol_selector(QimiAlipayView::selected),
                                                         CCControlEventTouchUpInside);
    
    
    m_pButtonList->addObject(m_pBtn10Select);
    m_pButtonList->addObject(m_pBtn20Select);
    m_pButtonList->addObject(m_pBtn30Select);
    m_pButtonList->addObject(m_pBtn50Select);
    m_pButtonList->addObject(m_pBtn100Select);
    m_pButtonList->addObject(m_pBtn300Select);
    m_pButtonList->addObject(m_pBtn500Select);
    
    
    cocos2d::extension::CCScale9Sprite* m_pInputTxtBg = CCScale9Sprite::create("loginbg.png");
    CCSize editBoxSize = CCSizeMake(200, 45);
    m_pInputTxtBg->removeFromParentAndCleanup(false);
    m_pEditName = CCEditBox::create(editBoxSize, m_pInputTxtBg);
    m_pEditName->setPosition(ccp(-112, -35));
    m_pEditName->setFontColor(ccc3(255, 0, 0));
    m_pEditName->setMaxLength(20);
    m_pEditName->setReturnType(kKeyboardReturnTypeDone);
    m_pEditName->setTouchPriority(-1000);
    m_pEditName->setText("10");
    m_pEditName->setDelegate(this);
    container->addChild(m_pEditName);
    
    
    CCLabelTTF* yuan = CCLabelTTF::create("元", "Helvetica", 20);
    container->addChild(yuan);
    yuan->setColor(ccc3(0, 0, 0));
    yuan->setPosition(ccp(0, -40));
    yuan->setAnchorPoint(ccp(0, 0.5));
    
    CCLabelTTF* label01 = CCLabelTTF::create("您将充值", "Helvetica", 20);
    container->addChild(label01);
    label01->setColor(ccc3(0, 0, 0));
    label01->setPosition(ccp(-199, -83));
    label01->setAnchorPoint(ccp(0, 0.5));
    
    m_pMcashNumTxt = CCLabelTTF::create("1", "Helvetica", 20);
    m_pMcashNumTxt->setColor(ccc3(196, 9, 9));
    m_pMcashNumTxt->setPosition(ccp(-116, -84));
    m_pMcashNumTxt->setAnchorPoint(ccp(0, 0.5));
    container->addChild(m_pMcashNumTxt);
    
    m_pMcashNumLastTxt = CCLabelTTF::create("元宝", "Helvetica", 20);
    container->addChild(m_pMcashNumLastTxt);
    m_pMcashNumLastTxt->setColor(ccc3(0, 0, 0));
    m_pMcashNumLastTxt->setPosition(ccp(-84, -84));
    m_pMcashNumLastTxt->setAnchorPoint(ccp(0, 0.5));
    return true;
}
예제 #6
0
bool HelloWorld::init()
{
    if ( !CCLayer::init())
    {
        return false;
    }
    //CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCNode* container = CCNode::create();
    this->addChild(container);
    container->setPosition(ccp(0, 80));
    
    QimiParamInfo* paramInfo = QimiParamInfo::create(21, 15, "7a92bba4670d479c5514720c1cf46aab", "pay");
    QimiPlatform::shareQimiPlatform()->setParamInfo(paramInfo);
    
    CCControlButton* backBtn0 = CCControlButton::create(CCLabelTTF::create("全屏WEBVIEW", "Helvetica", 20), CCScale9Sprite::create("buttonblue.png"));
    backBtn0->setPreferredSize(CCSizeMake(200, 50));
    container->addChild(backBtn0);
    backBtn0->setPosition(ccp(240, 590));
    backBtn0->addTargetWithActionForControlEvents(this,
                                                 cccontrol_selector(HelloWorld::openWebURLFull),
                                                 CCControlEventTouchUpInside);
    
    
    CCControlButton* backBtn = CCControlButton::create(CCLabelTTF::create("QIMI登录窗口", "Helvetica", 20), CCScale9Sprite::create("buttonblue.png"));
    backBtn->setPreferredSize(CCSizeMake(200, 50));
    container->addChild(backBtn);
    backBtn->setPosition(ccp(240, 520));
    backBtn->addTargetWithActionForControlEvents(this,
                                                 cccontrol_selector(HelloWorld::menuCloseCallback),
                                                 CCControlEventTouchUpInside);
    

    CCControlButton* backBtn3 = CCControlButton::create(CCLabelTTF::create("QIMI注册窗口", "Helvetica", 20), CCScale9Sprite::create("buttonblue.png"));
    backBtn3->setPreferredSize(CCSizeMake(200, 50));
    container->addChild(backBtn3);
    backBtn3->setPosition(ccp(240, 450));
    backBtn3->addTargetWithActionForControlEvents(this,
                                                  cccontrol_selector(HelloWorld::reg),
                                                  CCControlEventTouchUpInside);
    
    CCControlButton* backBtn2 = CCControlButton::create(CCLabelTTF::create("QIMI直接登录窗口", "Helvetica", 20), CCScale9Sprite::create("buttonblue.png"));
    backBtn2->setPreferredSize(CCSizeMake(200, 50));
    container->addChild(backBtn2);
    backBtn2->setPosition(ccp(240, 380));
    backBtn2->addTargetWithActionForControlEvents(this,
                                                  cccontrol_selector(HelloWorld::login),
                                                  CCControlEventTouchUpInside);
    
    
    CCControlButton* backBtn7 = CCControlButton::create(CCLabelTTF::create("QIMI充值中心", "Helvetica", 20), CCScale9Sprite::create("buttonblue.png"));
    backBtn7->setPreferredSize(CCSizeMake(200, 50));
    container->addChild(backBtn7);
    backBtn7->setPosition(ccp(240, 310));
    backBtn7->addTargetWithActionForControlEvents(this,
                                                  cccontrol_selector(HelloWorld::menuCloseCallback),
                                                  CCControlEventTouchUpInside);

    
    
    
    CCControlButton* backBtn4 = CCControlButton::create(CCLabelTTF::create("QIMI论坛", "Helvetica", 20), CCScale9Sprite::create("buttonblue.png"));
    backBtn4->setPreferredSize(CCSizeMake(200, 50));
    container->addChild(backBtn4);
    backBtn4->setPosition(ccp(240, 240));
    backBtn4->addTargetWithActionForControlEvents(this,
                                                  cccontrol_selector(HelloWorld::openWebURL),
                                                  CCControlEventTouchUpInside);
    
    CCControlButton* backBtn5 = CCControlButton::create(CCLabelTTF::create("忘记密码", "Helvetica", 20), CCScale9Sprite::create("buttonblue.png"));
    backBtn5->setPreferredSize(CCSizeMake(200, 50));
    container->addChild(backBtn5);
    backBtn5->setPosition(ccp(240, 160));
    backBtn5->addTargetWithActionForControlEvents(this,
                                                  cccontrol_selector(HelloWorld::forget),
                                                  CCControlEventTouchUpInside);
    
    
    CCControlButton* backBtn6 = CCControlButton::create(CCLabelTTF::create("退出QIMI", "Helvetica", 20), CCScale9Sprite::create("buttonblue.png"));
    backBtn6->setPreferredSize(CCSizeMake(200, 50));
    container->addChild(backBtn6);
    backBtn6->setPosition(ccp(240, 90));
    backBtn6->addTargetWithActionForControlEvents(this,
                                                  cccontrol_selector(HelloWorld::quit),
                                                  CCControlEventTouchUpInside);
    
    CCControlButton* backBtn9 = CCControlButton::create(CCLabelTTF::create("获取设备ID", "Helvetica", 20), CCScale9Sprite::create("buttonblue.png"));
    backBtn9->setPreferredSize(CCSizeMake(200, 50));
    container->addChild(backBtn9);
    backBtn9->setPosition(ccp(240, 20));
    backBtn9->addTargetWithActionForControlEvents(this,
                                                  cccontrol_selector(HelloWorld::getDivceId),
                                                  CCControlEventTouchUpInside);
    
    return true;
}
bool ControllerScene::init(){
    CCMenu *menu = CCMenu::create();
    menu->setPosition(CCPointZero);
    this->addChild(menu);
    
    CCLabelTTF *label = CCLabelTTF::create("CCTextFieldTTF", "Arial", 24);
    CCMenuItemLabel *item = CCMenuItemLabel::create(label, this, menu_selector(ControllerScene::menuItemClick1));
    item->setPosition(ccp(320, 1100));
    menu->addChild(item);
    
    label = CCLabelTTF::create("确定", "Arial", 24);
    m_btn = CCMenuItemLabel::create(label, this, menu_selector(ControllerScene::btnOk));
    m_btn->setPosition(ccp(400, 1050));
    menu->addChild(m_btn);
    
    m_texField = CCTextFieldTTF::textFieldWithPlaceHolder("input", CCSizeMake(200, 50), kCCTextAlignmentLeft, "Arial", 24);
    m_texField->setPosition(ccp(320, 1050));
    this->addChild(m_texField);
    m_texField->attachWithIME();
    
    m_name = CCLabelTTF::create("show info", "Arial", 24);
    m_name->setPosition(ccp(100, 1100));
    this->addChild(m_name);
    
    //CCControlButton label+s9
    label = CCLabelTTF::create("BUTTON", "Arial", 24);
    CCControlButton *btn = CCControlButton::create(label , CCScale9Sprite::create("start.png"));
    btn->setPreferredSize(CCSizeMake(228, 81));
    btn->setLabelAnchorPoint(ccp(0.5, 2));
    btn->setPosition(ccp(320, 1000));
    this->addChild(btn);
    btn->addTargetWithActionForControlEvents(this, cccontrol_selector(ControllerScene::btnClick), CCControlEventTouchDown);
    
    //CCControlButton s9
    CCScale9Sprite *s9 = CCScale9Sprite::create("start.png");
    btn = CCControlButton::create(s9);
    btn->setPosition(ccp(320, 900));
    btn->setPreferredSize(CCSizeMake(228, 81));
    this->addChild(btn);
    
    //CCControlButton title
    btn = CCControlButton::create("CCControlButton", "Arial", 24);
    btn->setPosition(ccp(320, 800));
    this->addChild(btn);
    
    //s9
//    s9 = CCScale9Sprite::create("home.png");
//    s9->setPosition(ccp(100, 800));
//    this->addChild(s9);
    
    //CCControlColourPicker not useful
    CCControlColourPicker *cp = CCControlColourPicker::create();
    cp->setPosition(ccp(320, 750));
    this->addChild(cp);
    
    //CCControlPotentiometer
    CCControlPotentiometer *pot = CCControlPotentiometer::create("potentiometerTrack.png", "potentiometerProgress.png", "potentiometerButton.png");
    pot->setPosition(ccp(100, 750));
    this->addChild(pot);
    pot->setValue(90);
    
    //CCControlSlider
    CCControlSlider *slider = CCControlSlider::create("sliderTrack.png", "sliderProgress.png", "sliderThumb.png");
    slider->setPosition(ccp(150, 600));
    slider->setMinimumValue(0);
    slider->setMaximumValue(100);
    this->addChild(slider);
    slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ControllerScene::valueChanged), CCControlEventValueChanged);
    
    //CCControlStepper
    CCControlStepper *ste = CCControlStepper::create(CCSprite::create("stepper-minus.png"), CCSprite::create("stepper-plus.png"));
    ste->setPosition(ccp(320, 600));
    this->addChild(ste);
    
    //CCControlSwitch
    CCControlSwitch *swi = CCControlSwitch::create(CCSprite::create("switch-mask.png"), CCSprite::create("switch-on.png"), CCSprite::create("switch-off.png"), CCSprite::create("switch-thumb.png"), CCLabelTTF::create("on", "Arial", 24), CCLabelTTF::create("off", "Arial", 24));
    swi->setPosition(ccp(500, 600));
    this->addChild(swi);

    //
    CCEditBox *edi = CCEditBox::create(CCSizeMake(200, 50), CCScale9Sprite::create("start.png"));
    edi->setPosition(ccp(150, 500));
    this->addChild(edi);
    
    return true;
}
예제 #8
0
bool MailWritePopUpView::initWithGift(int giftID,int propID) {
    if(!PopupBaseView::init()) {
        return false;
    }
    setIsHDPanel(true);
    mPropID = propID;
    mType = 1;
//    auto cf = CCLoadSprite::getSF("Mail_diban.png");
    auto cf = CCLoadSprite::getSF("Mail_BG1.png");
    if (cf==NULL) {
        CCLoadSprite::doResourceByCommonIndex(11, true);
        CCLoadSprite::doResourceByCommonIndex(6, true);
        setCleanFunction([]() {
            CCLoadSprite::doResourceByCommonIndex(11, false);
            CCLoadSprite::doResourceByCommonIndex(6, false);
        });
    }
    else {
        CCLoadSprite::doResourceByCommonIndex(11, true);
        setCleanFunction([]() {
            CCLoadSprite::doResourceByCommonIndex(11, false);
        });
    }

    auto bg = CCBLoadFile("NEWMailWriteView", this, this);
    if (CCCommonUtils::isIosAndroidPad()) {
        this->setContentSize(CCDirector::sharedDirector()->getWinSize());
    }
    else
        this->setContentSize(bg->getContentSize());
//    setTitleName(_lang("105513"));
    m_titleText->setString(_lang("105513"));
    if (CCCommonUtils::isIosAndroidPad()) {
        int extH = getExtendHeight();
        this->m_listNode->setContentSize(CCSize(m_listNode->getContentSize().width, m_listNode->getContentSize().height + extH));
        m_downNode->setPositionY(m_downNode->getPositionY() - extH);
        m_bgNode->setPositionY(m_bgNode->getPositionY() - extH);
//        m_nodeContent->setPositionY(m_nodeContent->getPositionY() - extH);
        auto tbg = CCLoadSprite::loadResource("Mail_diban.png");
        auto tBatchNode = CCSpriteBatchNode::createWithTexture(tbg->getTexture());
        auto picBg1 = CCLoadSprite::createSprite("Mail_diban.png");
        picBg1->setAnchorPoint(ccp(0, 0));
        picBg1->setPosition(ccp(0, 0));
        picBg1->setScaleX(2.4);
        tBatchNode->addChild(picBg1);
        int maxHeight = CCDirector::sharedDirector()->getWinSize().height;
        int curHeight = picBg1->getContentSize().height;
        while(curHeight < maxHeight)
        {
            auto picBg2 = CCLoadSprite::createSprite("Mail_diban.png");
            picBg2->setAnchorPoint(ccp(0, 0));
            picBg2->setPosition(ccp(0, curHeight));
            picBg2->setScaleX(2.4);
            tBatchNode->addChild(picBg2);
            curHeight += picBg2->getContentSize().height;
        }
        m_bgNode->addChild(tBatchNode);
    }
    else {
        int extH = getExtendHeight();
        this->m_listNode->setContentSize(CCSize(m_listNode->getContentSize().width, m_listNode->getContentSize().height + extH));
        m_downNode->setPositionY(m_downNode->getPositionY() - extH);
        m_bgNode->setPositionY(m_bgNode->getPositionY() - extH);
//        m_nodeContent->setPositionY(m_nodeContent->getPositionY() - extH);
        auto tbg = CCLoadSprite::loadResource("Mail_diban.png");
        auto tBatchNode = CCSpriteBatchNode::createWithTexture(tbg->getTexture());
        auto picBg1 = CCLoadSprite::createSprite("Mail_diban.png");
        picBg1->setAnchorPoint(ccp(0, 0));
        picBg1->setPosition(ccp(0, 0));
        tBatchNode->addChild(picBg1);
        int maxHeight = CCDirector::sharedDirector()->getWinSize().height;
        int curHeight = picBg1->getContentSize().height;
        while(curHeight < maxHeight)
        {
            auto picBg2 = CCLoadSprite::createSprite("Mail_diban.png");
            picBg2->setAnchorPoint(ccp(0, 0));
            picBg2->setPosition(ccp(0, curHeight));
            tBatchNode->addChild(picBg2);
            curHeight += picBg2->getContentSize().height;
        }
        m_bgNode->addChild(tBatchNode);
    }
//    CCSize wNodeSize = this->m_waitingNode->getContentSize();
//    m_waitingNode->setContentSize(CCSize(wNodeSize.width,wNodeSize.height + dh));
//    m_waitingNode->setPositionY(m_waitingNode->getPositionY() - dh*0.5);

//    this->m_nameText->setString(_lang("105505").c_str());
    //    this->m_titleText->setString(_lang("105503").c_str());
//    this->m_contentText->setString(_lang("105504").c_str());

    CCNode *searchnode = CCNode::create();
    auto spr1 = CCLoadSprite::createScale9Sprite("button_dark.png");
    CCControlButton *shareBtn = CCControlButton::create(spr1);
    searchnode->addChild(shareBtn);
    shareBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(MailWritePopUpView::onChooseName), CCControlEventTouchUpInside);
    CCSprite* sprIcon = CCLoadSprite::createSprite("search_icon.png");
    CCSize sprSize = sprIcon->getContentSize();
    searchnode->addChild(sprIcon);
    CCCommonUtils::setSpriteMaxSize(sprIcon, 40);
    shareBtn->setPreferredSize(CCSize(60, 60));
    this->m_nameContainer->addChild(searchnode);
    searchnode->setPosition(440, 0);

    CCScrollView *scrollView = CCScrollView::create(m_listNode->getContentSize());
    scrollView->setTouchPriority(Touch_Popup_Item);
    scrollView->setDirection(kCCScrollViewDirectionVertical);
    m_nodeContent->removeFromParentAndCleanup(false);
    scrollView->addChild(m_nodeContent);
    scrollView->setTag(10000);
    m_nameEditBox = InputFieldMultiLine::create(CCSizeMake(380,40),"Mail_write.png",24);
//    m_nameEditBox->setTouchPriority(Touch_Default);
    m_nameEditBox->setMaxChars(30);
    m_nameEditBox->setPosition(ccp(0, -20));
    m_nameEditBox->setLineNumber(1);
    m_nameEditBox->setFontColor({63,44,27});

    this->m_nameContainer->addChild(m_nameEditBox);
    m_nameEditBox->m_enabled = (mPropID == ITEM_SEND_GIFTALLIANCE || mPropID == ITEM_SEND_GIFT || mPropID == ITEM_SEND_GIFTMORE)?false:true;

    m_contentEditBox = InputFieldMultiLine::create(m_contentContainer->getContentSize(),"Mail_write.png",24);
    m_contentEditBox->setTouchPriority(Touch_Default);
    m_contentEditBox->setMaxChars(300);
    m_contentEditBox->setLineNumber(5);
    m_contentEditBox->setPosition(ccp(0, 0));
    m_contentEditBox->setFontColor({63,44,27});
    this->m_contentContainer->addChild(m_contentEditBox);
    m_contentEditBox->setText(_lang("101383"));
    CCSize liseNodeSize = this->m_listNode->getContentSize() * m_listNode->getScale();
    MailGiftCell *mailGiftCell = MailGiftCell::create(CCSize(liseNodeSize.width, liseNodeSize.height - 110),mPropID,giftID);
    scrollView->addChild(mailGiftCell);
    mailGiftCell->setTag(10000);
    CCSize cellSize = mailGiftCell->getContentSize();
    int needH = ceil(cellSize.height + 400);
    int nowH = m_listNode->getContentSize().height;
    m_nodeContent->setPosition(ccp(300,cellSize.height + 100));
    mailGiftCell->setPosition(ccp(0,0));
    m_listNode->addChild(scrollView);
    scrollView->setContentSize(CCSize(600,400 + cellSize.height));
    scrollView->setContentOffset(ccp(0, nowH - needH));

    if(needH>nowH) {
        scrollView->setTouchEnabled(true);
    } else {
        scrollView->setTouchEnabled(false);
    }

    if(!m_toName.empty()) {
        m_nameEditBox->setText(m_toName.c_str());
        m_nameEditBox->setEnabled(false);
    }
    updateBtnStatus();

    return true;
}
bool CCLobbyView::init( CCNetworkLogic* network, const CCSize& mySize )
{
    if( CCLayer::init() )
    {
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
        const CCPoint& center = ccpMult( ccpFromSize( mySize ), 0.5f );
        CCPoint position = CCPointZero;
        CCSize size = CCSizeZero;
        int length = 0;
        int fontSize = 0;
        
        this->setNetwork( network );
        
        CCSprite* s = CCSprite::create("Images/r1.png");
        s->retain();
        CCRect rect = CCRectZero;
        rect.size = s->getContentSize();
        s->release();
        
        fontSize = 12;
        CCLabelTTF* label = CCLabelTTF::create( "Connect", "fonts/American Typewriter.ttf", fontSize );
        label->setColor( ccc3( 0, 0, 0 ) );
        CCScale9Sprite* sprite = CCScale9Sprite::create("Images/r1.png", rect, rect );
        sprite->setScaleX( 1.4f );
        sprite->setScaleY( 0.8f );
        CCControlButton* button = CCControlButton::create( label, sprite );
        button->addTargetWithActionForControlEvents( this, cccontrol_selector( CCLobbyView::connectButtonCallback ), CCControlEventTouchUpInside);
        button->setPreferredSize( rect.size );
        position = center;
        position.y -= 136;
        position.x -= 100;
        button->setPosition( position );
        this->setConnectButton( button );
        
        label = CCLabelTTF::create( "Create Room", "fonts/American Typewriter.ttf", fontSize );
        label->setColor( ccc3( 0, 0, 0 ) );
        sprite = CCScale9Sprite::create("Images/r1.png", rect, rect );
        sprite->setScaleX( 1.4f );
        sprite->setScaleY( 0.8f );
        button = CCControlButton::create( label, sprite );
        button->addTargetWithActionForControlEvents( this, cccontrol_selector( CCLobbyView::createGameButtonCallback ), CCControlEventTouchUpInside);
        button->setPreferredSize( rect.size );
        position = center;
        position.y -= 136;
        //position.x += 0;
        button->setPosition( position );
        this->setCreateGameButton( button );
        
        label = CCLabelTTF::create( "Random Room", "fonts/American Typewriter.ttf", fontSize );
        label->setColor( ccc3( 0, 0, 0 ) );
        sprite = CCScale9Sprite::create("Images/r1.png", rect, rect );
        sprite->setScaleX( 1.6f );
        sprite->setScaleY( 0.8f );
        button = CCControlButton::create( label, sprite );
        button->addTargetWithActionForControlEvents( this, cccontrol_selector( CCLobbyView::joinGameButtonCallback ), CCControlEventTouchUpInside);
        button->setPreferredSize( rect.size );
        position = center;
        position.y -= 136;
        position.x += 100;
        button->setPosition( position );
        this->setRandomGameButton( button );
        
        this->_lobbyViewDataSource = new CCLobbyViewDataSource( this );

        fontSize = 16;
        length = mySize.width;
        size = this->_lobbyViewDataSource->cellSizeForTable( NULL );
        size.height *= 3;
        CCTableView* table = CCTableView::create( this->_lobbyViewDataSource, size );
        table->setContentOffset( CCPointZero );
        table->setDirection(kCCScrollViewDirectionVertical);
        position = center;
        position.x -= size.width * 0.5f;
        position.y -= fontSize + ( size.height * 0.17f );
        table->setPosition( position );
        table->setDelegate( this );
        table->setVerticalFillOrder(kCCTableViewFillTopDown);
        this->setRoomTable( table );
        table->reloadData();
        
        fontSize = 16;
        label = CCLabelTTF::create("Running games:", "fonts/American Typewriter.ttf", fontSize,
                                                 winSize, kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
        position = center;
        position.x -= size.width * 0.4f;
        position.y += size.height - ( fontSize * 0.5f );
        label->setPosition( position );
        //label->setAnchorPoint( CCPointZero );
        this->setRoomTableLabel( label );
        
        fontSize = 16;
        CCLabelTTF* console = CCLabelTTF::create("disconnected", "fonts/American Typewriter.ttf", fontSize,
                                             winSize, kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter);
        
            
        console->setColor( ccc3(255, 255, 255) );
        console->setContentSize(winSize);
        position = center;
        position.y += 100;
        console->setPosition( position );
        this->setConsole( console );
        
        label = CCLabelTTF::create( "localhost:5055", "fonts/American Typewriter.ttf", fontSize );
        position.y += fontSize;
        label->setPosition( position );
        this->setDisplayAddress( label );
        
        // top
        fontSize = 24;
        length = 19;
        size = CCSize( length * fontSize * 0.7f, fontSize * 1.7f );
        CCEditBox* edit = CCEditBox::create( size, CCScale9Sprite::create( "extensions/green_edit.png" ) );
        edit->setPosition( center );
        edit->setFontColor(ccBLACK);
        edit->setPlaceHolder("ip:port");
        edit->setMaxLength( 19 );
        edit->setReturnType(kKeyboardReturnTypeDone);
        edit->setDelegate(this);
        position.y -= fontSize * 2;
        edit->setPosition( position );
        this->setEditAddress( edit );
        
        //CCChatRoom* chatroom = CCChatRoom::create(this->getNetwork());
        //this->setChatRoom( chatroom );
        
        this->scheduleUpdate();

        return true;
    }
    
    return false;
}