bool UILayoutTest_Color::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Layout color render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the layout with color render
        UILayout* layout = UILayout::create();
        layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
        layout->setBackGroundColor(ccc3(128, 128, 128));
        layout->setSize(CCSizeMake(280, 150));
        CCSize backgroundSize = background->getContentSize();
        layout->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                (backgroundSize.width - layout->getSize().width) / 2,
                                (widgetSize.height - backgroundSize.height) / 2 +
                                (backgroundSize.height - layout->getSize().height) / 2));
        m_pUiLayer->addWidget(layout);
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        button->setPosition(ccp(button->getSize().width / 2, layout->getSize().height - button->getSize().height / 2));
        layout->addChild(button);
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(ccp(layout->getSize().width / 2, layout->getSize().height / 2));
        layout->addChild(titleButton);
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
        button_scale9->setScale9Enabled(true);
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        button_scale9->setPosition(ccp(layout->getSize().width - button_scale9->getSize().width / 2, button_scale9->getSize().height / 2));
        layout->addChild(button_scale9);        
        
        return true;
    }
    return false;
}
bool UIButtonTest_Scale9::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the button events will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("No Event");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Button scale9 render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75));
        m_pUiLayer->addWidget(alert);
        
        // Create the button
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        // open scale9 render
        button->setScale9Enabled(true);
        button->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
        button->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
        button->setSize(CCSizeMake(150, button->getContentSize().height * 1.5f));
        button->addTouchEventListener(this, toucheventselector(UIButtonTest_Scale9::touchEvent));
        m_pUiLayer->addWidget(button);
        
        return true;
    }
    return false;
}
bool UIScrollViewTest_Vertical::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the scrollview alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by vertical direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView vertical");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the scrollview by vertical
        UIScrollView* scrollView = UIScrollView::create();
        scrollView->setTouchEnabled(true);
        scrollView->setBounceEnabled(true);
        scrollView->setSize(CCSizeMake(280, 150));        
        CCSize backgroundSize = background->getContentSize();
        scrollView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                               (backgroundSize.width - scrollView->getSize().width) / 2,
                               (widgetSize.height - backgroundSize.height) / 2 +
                               (backgroundSize.height - scrollView->getSize().height) / 2));
        scrollView->addEventListenerScrollView(this, scrollvieweventselector(UIScrollViewTest_Vertical::scrollEvent));
        m_pUiLayer->addWidget(scrollView);
        
        UIImageView* imageView = UIImageView::create();
        imageView->loadTexture("cocosgui/ccicon.png");
        
        float innerWidth = scrollView->getSize().width;
        float innerHeight = scrollView->getSize().height + imageView->getSize().height * 2;
        
        scrollView->setInnerContainerSize(CCSizeMake(innerWidth, innerHeight));
        
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        button->setPosition(ccp(innerWidth / 2, scrollView->getInnerContainerSize().height - button->getSize().height / 2));
        scrollView->addChild(button);
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(ccp(innerWidth / 2, button->getBottomInParent() - button->getSize().height));
        scrollView->addChild(titleButton);
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->setScale9Enabled(true);
        button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        button_scale9->setPosition(ccp(innerWidth / 2, titleButton->getBottomInParent() - titleButton->getSize().height));
        scrollView->addChild(button_scale9);
        
        imageView->setPosition(ccp(innerWidth / 2, imageView->getSize().height / 2));
        scrollView->addChild(imageView);
        
        
        
        
//        UIButton* button_1 = UIButton::create();
//        button_1->setTouchEnabled(true);
//        button_1->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
//        button_1->addTouchEventListener(this, toucheventselector(UIScrollViewTest_Vertical::touchEvent));
//        
//        Layout* layout = Layout::create();
//        layout->setSize(button_1->getSize());
//        layout->setBackGroundImage("cocosgui/green_edit.png");
//        layout->setBackGroundImageScale9Enabled(true);
////        layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
////        layout->setBackGroundColor(ccc3(0, 255, 0));
//        layout->setPosition(ccp(imageView->getPosition().x, layout->getSize().height * 2));
//        
//        button_1->setPosition(ccp(button_1->getSize().width / 2, button_1->getSize().height / 2));
//        
//        layout->addChild(button_1);
//        scrollView->addChild(layout);
        
        return true;
    }
    
    return false;
}
bool UIScrollViewTest_Horizontal::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the scrollview alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by horizontal direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);            
        
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView horizontal");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the scrollview by horizontal
        UIScrollView* scrollView = UIScrollView::create();        
        scrollView->setDirection(SCROLLVIEW_DIR_HORIZONTAL);
        scrollView->setBounceEnabled(true);
        scrollView->setTouchEnabled(true);
        scrollView->setSize(CCSizeMake(280, 150));
        scrollView->setInnerContainerSize(scrollView->getSize());
        CCSize backgroundSize = background->getContentSize();
        scrollView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                    (backgroundSize.width - scrollView->getSize().width) / 2,
                                    (widgetSize.height - backgroundSize.height) / 2 +
                                    (backgroundSize.height - scrollView->getSize().height) / 2));
        m_pUiLayer->addWidget(scrollView);
        
        UIImageView* imageView = UIImageView::create();
        imageView->loadTexture("cocosgui/ccicon.png");
        
        float innerWidth = scrollView->getSize().width + imageView->getSize().width * 2;
        float innerHeight = scrollView->getSize().height;
        
        scrollView->setInnerContainerSize(CCSizeMake(innerWidth, innerHeight));
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        button->setPosition(ccp(button->getSize().width / 2,
                                scrollView->getInnerContainerSize().height - button->getSize().height / 2));
        scrollView->addChild(button);
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(ccp(button->getRightInParent() + button->getSize().width / 2,
                                    button->getBottomInParent() - button->getSize().height / 2));
        scrollView->addChild(titleButton);
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->setScale9Enabled(true);
        button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        button_scale9->setPosition(ccp(titleButton->getRightInParent() + titleButton->getSize().width / 2,
                                       titleButton->getBottomInParent() - titleButton->getSize().height / 2));
        scrollView->addChild(button_scale9);                
                
        imageView->setPosition(ccp(innerWidth - imageView->getSize().width / 2,
                                   button_scale9->getBottomInParent() - button_scale9->getSize().height / 2));
        scrollView->addChild(imageView);                
        
        return true;
    }
    
    return false;
}
Beispiel #5
0
// on "init" you need to initialize your instance
bool LayerChatWindow::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !CCLayer::init() )
	{
		return false;
	}
	lstStringMessage.clear();
	lstStringMessage.push_back("Nhanh lên nào (14)!");
	lstStringMessage.push_back("Mạng lag quá (9)!");
	lstStringMessage.push_back("Bài xấu quá (3)!");
	lstStringMessage.push_back("Hehe, lên nóc nhà\nmà bắt con gà (6)");
	lstStringMessage.push_back("Nhất rồi, haha (1)");
	lstStringMessage.push_back("Đánh gà thế (11)!");
	lstStringMessage.push_back("Đỏ vãi lúa (13)!");
	lstStringMessage.push_back("Nhọ như chó mực (5)!");

	//return true;

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
	_count = 100;
	layerButton = UILayer::create();
	layerButton->addWidget(GUIReader::shareReader()->widgetFromJsonFile("LayerChatWindow_1.ExportJson"));
	this->addChild(layerButton);
	layerButton->setTouchPriority(-128);
	this->setTouchEnabled(true);

	//Get all chat button
	for( int i = 1; i <= 8; i++ ){
		UIButton* btnChat = dynamic_cast<UIButton*>(layerButton->getWidgetByName( CCString::createWithFormat("btnChat%d", i)->getCString() ));
		btnChat->setTitleText( lstStringMessage.at(i-1).c_str() );
		btnChat->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::onButtonChats);
	}
	UIButton* btnClose = dynamic_cast<UIButton*>(layerButton->getWidgetByName("btnClose"));
	btnClose->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::onButtonClose);
	//
	UIButton* btnSend = dynamic_cast<UIButton*>(layerButton->getWidgetByName("btnSend"));
	btnSend->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::onButtonSend);

	txtChat = dynamic_cast<UITextField*>(layerButton->getWidgetByName("txtChat"));
	txtChat->setText("");
	txtChat->setPlaceHolder("Noi dung");
	txtChat->setTextHorizontalAlignment(kCCTextAlignmentCenter);
	txtChat->setTextVerticalAlignment(kCCVerticalTextAlignmentCenter);
	txtChat->addEventListenerTextField(this, textfieldeventselector(LayerChatWindow::textFieldEvent));

	UIPanel* pEmo = dynamic_cast<UIPanel*>(layerButton->getWidgetByName("pEmo"));
	UIImageView* pImg = dynamic_cast<UIImageView*>(layerButton->getWidgetByName("Image_25_0"));
	//Add all emo to this
	int i = 1;
// 	CCArmatureDataManager::sharedArmatureDataManager()->removeArmatureFileInfo(CCString::createWithFormat("onion%d.ExportJson", 1)->getCString());
// 	CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo(CCString::createWithFormat("onion%d.ExportJson", 1)->getCString());
	int row=-1, col = 1;
	int widthOfPage = 580;
	int numOfCols = 9;
	int space = 10;
	int widthOfImage = 50;
	int startPosX = widthOfPage/2 - (widthOfImage+space)*numOfCols/2 - 300;
	int startPosY = space - 100;
	lstEmo.clear();
	for( int i = 1; i<=16; i++ ){
		CCArmature *armature = CCArmature::create(CCString::createWithFormat("onion%d", 1)->getCString());
		armature->getAnimation()->playByIndex(i-1);
		RichElementCustomNode* recustom = RichElementCustomNode::create(1, ccWHITE, 255, armature);
		RichText* _richText = RichText::create();
		_richText->setContentSize( armature->getContentSize() );
		_richText->pushBackElement(recustom); 
		if( col> numOfCols ){
			row++;
			col = 1;
		}
		_richText->setAnchorPoint(ccp(0, 1));
		_richText->setPosition(ccp( startPosX + 60*(col-1)
			, -1*row*50 - startPosY - (row+1)*space ));
		_richText->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::OnEmoClick);

		lstEmo.push_back( armature );

		UIButton* b = UIButton::create();
		b->setPosition(ccp( startPosX + 60*(col-1)
			, -1*row*50 - startPosY - (row+1)*space ));
		b->setAnchorPoint(ccp(0, 1));
		b->setContentSize( armature->getContentSize() );
		b->addTouchEventListener(this,(SEL_TouchEvent)&LayerChatWindow::OnEmoClick);
		b->loadTextures("emo_blank.png", "", "");
		b->setTag(i);

		pImg->addChild( _richText );
		pImg->addChild( b );
		//CCLOG("button w: %lf h: %lf", b->getContentSize().width, b->getContentSize().height);
		col++;
	}
	return true;
}
void ZhuangBeiListLayer::setData(HeroType hero,int type,ZhuangBeiType zhuangtype)
{
    UILayer*m_pUiLayer=UILayer::create();
    addChild(m_pUiLayer,0);
    CCSize winSize =CCDirector::sharedDirector()->getWinSize();
    UIImageView * imagebg=UIImageView::create();
    setTouchEnabled(true);
    imagebg->setTexture("herobg.png");
    imagebg->setPosition(ccp(winSize.width/2, winSize.height/2));
    m_pUiLayer->addWidget(imagebg);
    

    
    UIScrollView*scrollView = UIScrollView::create();
    scrollView->setTouchEnable(true);
    scrollView->setBounceEnabled(true);
    scrollView->setSize(CCSize(winSize.width,600));

    scrollView->setPosition(ccp(0,winSize.height/2-360));
    m_pUiLayer->addWidget(scrollView);
    

    vector<ZhuangBeiType> zhuangBeis=GameData::shareGameData()->getZhuangbei();
    int j=0;
    for(int i=0;i<zhuangBeis.size();i++)
    {
        ZhuangBeiType zhuang=zhuangBeis[i];
         int t=(type+3)*100;
        printf("zhuangtype==%d,%d,%d",zhuang.type,t,m_type);
       
        if((zhuang.type>=t&&zhuang.type<(t+100))||type==-1)
        {
            j++;
            UIImageView* imageView = UIImageView::create();
            imageView->setTexture("cellbg.png");
            int imageHeight=imageView->getRect().size.height;
            float innerWidth = scrollView->getRect().size.width;
            float innerHeight = scrollView->getRect().size.height +imageHeight*zhuangBeis.size();
            scrollView->setInnerContainerSize(CCSizeMake(innerWidth, innerHeight));
            
            
            imageView->setPosition(ccp(innerWidth / 2,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/2));
            scrollView->addChild(imageView);
            
            UIImageView* imagebg= UIImageView::create();
            imagebg->setTexture("addbutton.png");
            imagebg->setPosition(ccp(120,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/2));
            scrollView->addChild(imagebg);
            
            UIImageView* imageHead = UIImageView::create();
            imageHead->setTexture(zhuang.textureName.c_str());
            imageHead->setPosition(ccp(120,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/2));
            scrollView->addChild(imageHead);
            
            UILabel *label=UILabel::create();
            char strlevel[32];
            sprintf(strlevel,"Lv:%d",zhuang.level);
            label->setFontSize(24);
            label->setText(strlevel);
            label->setColor(ccBLUE);
            label->setPosition(ccp(winSize.width/2-100,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight-60));
            scrollView->addChild(label);
            
            UILabel *namelabel=UILabel::create();
            namelabel->setFontSize(24);
            namelabel->setText(zhuang.name.c_str());
            namelabel->setColor(ccBLUE);
            namelabel->setPosition(ccp(winSize.width/2,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight-60));
            scrollView->addChild(namelabel);
            
            if(zhuang.hp>0)
            {
                UIImageView* imageattack = UIImageView::create();
                imageattack->setTexture("heart.png");
                imageattack->setPosition(ccp(winSize.width/2-100,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/3));
                scrollView->addChild(imageattack);
                UILabel *label=UILabel::create();
                label->setPosition(ccp(winSize.width/2-40,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/3));
                scrollView->addChild(label);
                char str[32];
                int hp=zhuang.hp+(40+10*zhuang.star)*zhuang.level;
                sprintf(str,"%d",hp);
                label->setFontSize(24);
                label->setColor(ccBLACK);
                label->setText(str);
            }
            if(zhuang.ap>0)
            {
            UIImageView* imageattack = UIImageView::create();
            imageattack->setTexture("swordicon.png");
            imageattack->setPosition(ccp(winSize.width/2+40,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/3));
            scrollView->addChild(imageattack);
            UILabel *label=UILabel::create();
            label->setPosition(ccp(winSize.width/2+100,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/3));
            scrollView->addChild(label);
            char str[32];
            int ap=zhuang.ap+(10+2*zhuang.star)*zhuang.level;
            sprintf(str,"%d",ap);
            label->setColor(ccBLACK);
            label->setFontSize(24);
            label->setText(str);
                
            }

            if(zhuang.defender>0)
            {
                UIImageView* imageattack = UIImageView::create();
                imageattack->setTexture("fang.png");
                imageattack->setPosition(ccp(winSize.width/2-100,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/3));
                scrollView->addChild(imageattack);
                UILabel *label=UILabel::create();
                label->setPosition(ccp(winSize.width/2-40,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/3));
                scrollView->addChild(label);
                char str[32];
                int defender=zhuang.defender+(6+1*zhuang.star)*zhuang.level;
                sprintf(str,"%d",defender);
                label->setColor(ccBLACK);
                label->setFontSize(24);
                label->setText(str);
            }
            if(zhuang.magicdefender>0)
            {
                UIImageView* imageattack = UIImageView::create();
                imageattack->setTexture("mofang.png");
                imageattack->setPosition(ccp(winSize.width/2+40,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/3));
                scrollView->addChild(imageattack);
                UILabel *label=UILabel::create();
                label->setPosition(ccp(winSize.width/2+100,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/3));
                scrollView->addChild(label);
                char str[32];
                int magicdefender=zhuang.magicdefender+(6+1*zhuang.star)*zhuang.level;
                sprintf(str,"%d",magicdefender);
                label->setFontSize(24);
                label->setColor(ccBLACK);
                label->setText(str);
            }
            for(int i=0;i<zhuang.star;i++)
            {
                UIImageView* imageattack = UIImageView::create();
                imageattack->setTexture("star.png");
                imageattack->setPosition(ccp(winSize.width/2+i*20+100,scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight-60));
                scrollView->addChild(imageattack);
            }

            UIButton* button = UIButton::create();
            button->setTouchEnable(true);
            button->setTag(zhuang.index);
            //string texturename=zhuang.textureName;
            if(type==-1)
            {
            button->loadTextures("heroup1.png", "heroup2.png", "");
            button->addReleaseEvent(this, coco_releaseselector(ZhuangBeiListLayer::Shengji));
            }
            else
            {
                button->loadTextures("zhuangbei1.png", "zhuangbei2.png", "");
                button->addReleaseEvent(this, coco_releaseselector(ZhuangBeiListLayer::menuPauseCallback));
            }
            
            button->setPosition(ccp(winSize.width-120, scrollView->getInnerContainerSize().height-imageHeight*j+imageHeight/3));
            scrollView->addChild(button);
        }
    }
    UIButton * btn= UIButton::create();
    btn->setTouchEnable(true);
    btn->addReleaseEvent(this, coco_releaseselector(ZhuangBeiListLayer::close));
    btn->setTextures("close1.png","close2.png","close2.png");
    btn->setPosition(ccp(winSize.width-60, winSize.height/2+300));
    m_pUiLayer->addWidget(btn);
}
bool UILayoutTest_Layout_Relative_Align_Parent::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Layout Relative Align Parent");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
        m_pUiLayer->addWidget(alert);
        
        Layout* background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the layout
        Layout* layout = Layout::create();
        layout->setLayoutType(LAYOUT_RELATIVE);
        layout->setSize(CCSizeMake(280, 150));
        layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
        layout->setBackGroundColor(ccGREEN);
        CCSize backgroundSize = background->getSize();
        layout->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                (backgroundSize.width - layout->getSize().width) / 2,
                                (widgetSize.height - backgroundSize.height) / 2 +
                                (backgroundSize.height - layout->getSize().height) / 2));
        m_pUiLayer->addWidget(layout);
        
        // top left
        UIButton* button_TopLeft = UIButton::create();
        button_TopLeft->setTouchEnabled(true);
        button_TopLeft->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_TopLeft);
        
        UIRelativeLayoutParameter* rp_TopLeft = UIRelativeLayoutParameter::create();
        rp_TopLeft->setAlign(RELATIVE_ALIGN_PARENT_TOP_LEFT);
        button_TopLeft->setLayoutParameter(rp_TopLeft);
        
        
        // top center horizontal
        UIButton* button_TopCenter = UIButton::create();
        button_TopCenter->setTouchEnabled(true);
        button_TopCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_TopCenter);
        
        UIRelativeLayoutParameter* rp_TopCenter = UIRelativeLayoutParameter::create();
        rp_TopCenter->setAlign(RELATIVE_ALIGN_PARENT_TOP_CENTER_HORIZONTAL);
        button_TopCenter->setLayoutParameter(rp_TopCenter);
        
        
        // top right
        UIButton* button_TopRight = UIButton::create();
        button_TopRight->setTouchEnabled(true);
        button_TopRight->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_TopRight);
        
        UIRelativeLayoutParameter* rp_TopRight = UIRelativeLayoutParameter::create();
        rp_TopRight->setAlign(RELATIVE_ALIGN_PARENT_TOP_RIGHT);
        button_TopRight->setLayoutParameter(rp_TopRight);
        
        
        // left center
        UIButton* button_LeftCenter = UIButton::create();
        button_LeftCenter->setTouchEnabled(true);
        button_LeftCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_LeftCenter);
        
        UIRelativeLayoutParameter* rp_LeftCenter = UIRelativeLayoutParameter::create();
        rp_LeftCenter->setAlign(RELATIVE_ALIGN_PARENT_LEFT_CENTER_VERTICAL);
        button_LeftCenter->setLayoutParameter(rp_LeftCenter);
        
        
        // center
        UIButton* buttonCenter = UIButton::create();
        buttonCenter->setTouchEnabled(true);
        buttonCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(buttonCenter);
        
        UIRelativeLayoutParameter* rpCenter = UIRelativeLayoutParameter::create();
        rpCenter->setAlign(RELATIVE_CENTER_IN_PARENT);
        buttonCenter->setLayoutParameter(rpCenter);
        
        
        // right center
        UIButton* button_RightCenter = UIButton::create();
        button_RightCenter->setTouchEnabled(true);
        button_RightCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_RightCenter);
        
        UIRelativeLayoutParameter* rp_RightCenter = UIRelativeLayoutParameter::create();
        rp_RightCenter->setAlign(RELATIVE_ALIGN_PARENT_RIGHT_CENTER_VERTICAL);
        button_RightCenter->setLayoutParameter(rp_RightCenter);
        
        
        // left bottom
        UIButton* button_LeftBottom = UIButton::create();
        button_LeftBottom->setTouchEnabled(true);
        button_LeftBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_LeftBottom);
        
        UIRelativeLayoutParameter* rp_LeftBottom = UIRelativeLayoutParameter::create();
        rp_LeftBottom->setAlign(RELATIVE_ALIGN_PARENT_LEFT_BOTTOM);
        button_LeftBottom->setLayoutParameter(rp_LeftBottom);
        
        
        // bottom center
        UIButton* button_BottomCenter = UIButton::create();
        button_BottomCenter->setTouchEnabled(true);
        button_BottomCenter->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_BottomCenter);
        
        UIRelativeLayoutParameter* rp_BottomCenter = UIRelativeLayoutParameter::create();
        rp_BottomCenter->setAlign(RELATIVE_ALIGN_PARENT_BOTTOM_CENTER_HORIZONTAL);
        button_BottomCenter->setLayoutParameter(rp_BottomCenter);
        
        
        // right bottom
        UIButton* button_RightBottom = UIButton::create();
        button_RightBottom->setTouchEnabled(true);
        button_RightBottom->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button_RightBottom);
        
        UIRelativeLayoutParameter* rp_RightBottom = UIRelativeLayoutParameter::create();
        rp_RightBottom->setAlign(RELATIVE_ALIGN_PARENT_RIGHT_BOTTOM);
        button_RightBottom->setLayoutParameter(rp_RightBottom);
        
        return true;
    }
    
    return false;
}
bool UILayoutTest_Layout_Linear_Horizontal::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add the alert
        UILabel* alert = UILabel::create();
        alert->setText("Layout Layout Linear Horizontal");
        alert->setFontName("Marker Felt");
        alert->setFontSize(20);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 4.5));
        m_pUiLayer->addWidget(alert);
        
        Layout* background = dynamic_cast<Layout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the layout
        Layout* layout = Layout::create();
        layout->setLayoutType(LAYOUT_LINEAR_HORIZONTAL);
        layout->setClippingEnabled(true);
        layout->setSize(CCSizeMake(280, 150));
        CCSize backgroundSize = background->getSize();
        layout->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                                (backgroundSize.width - layout->getSize().width) / 2,
                                (widgetSize.height - backgroundSize.height) / 2 +
                                (backgroundSize.height - layout->getSize().height) / 2));
        m_pUiLayer->addWidget(layout);
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png", "");
        layout->addChild(button);
        
        UILinearLayoutParameter* lp1 = UILinearLayoutParameter::create();
        button->setLayoutParameter(lp1);
        lp1->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL);
        lp1->setMargin(UIMargin(0, 10, 0, 10));
        
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        layout->addChild(titleButton);
        
        UILinearLayoutParameter* lp2 = UILinearLayoutParameter::create();
        titleButton->setLayoutParameter(lp2);
        lp2->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL);
        lp2->setMargin(UIMargin(0, 10, 0, 10));
        
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->loadTextures("cocosui/button.png", "cocosui/buttonHighlighted.png", "");
        button_scale9->setScale9Enabled(true);
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        layout->addChild(button_scale9);
        
        UILinearLayoutParameter* lp3 = UILinearLayoutParameter::create();
        button_scale9->setLayoutParameter(lp3);
        lp3->setGravity(LINEAR_GRAVITY_CENTER_VERTICAL);
        lp3->setMargin(UIMargin(0, 10, 0, 10));
        
        return true;
    }
    
    return false;
}
Beispiel #9
0
bool JiangLiLayer::init()
{
    if(!CCLayer::init()){
        return false;
    }
    int mlevel=GameData::shareGameData()->mlevel;
    CCSize winSize =CCDirector::sharedDirector()->getWinSize();
    UILayer *m_pUiLayer=UILayer::create();
    addChild(m_pUiLayer,1);
    
    UIImageView* imagehead= UIImageView::create();
    imagehead->setTexture("menubg.png");
    imagehead->setPosition(ccp(winSize.width/2,winSize.height/2));
    m_pUiLayer->addWidget(imagehead);
    
    
    UIScrollView* scrollView = UIScrollView::create();
    scrollView->setTouchEnable(true);
    scrollView->setBounceEnabled(true);
    scrollView->setSize(CCSize(winSize.width,600));
    
    scrollView->setPosition(ccp(0,winSize.height/2-360));
    m_pUiLayer->addWidget(scrollView);
    
    UIButton * btn= UIButton::create();
    btn->setTouchEnable(true);
    btn->addReleaseEvent(this, coco_releaseselector(JiangLiLayer::close));
    btn->setTextures("close1.png","close2.png","close2.png");
    btn->setPosition(ccp(winSize.width-60, winSize.height/2+300));
    m_pUiLayer->addWidget(btn);
    
    mlevel=GameData::shareGameData()->mlevel;
    bool support=CCUserDefault::sharedUserDefault()->getBoolForKey("support",false);
    bool level[9];
    for(int i=0;i<9;i++)
    {
        char str[64];
        sprintf(str,"level%d",i);
        level[i]=CCUserDefault::sharedUserDefault()->getBoolForKey(str,false);
    }
    CCUserDefault::sharedUserDefault()->flush();
    
    int number=10;
    if(support)
        number=9;
    for(int i=0;i<number;i++)
    {
        UIImageView* imageView = UIImageView::create();
        imageView->setTexture("cellbg.png");
        float innerWidth = scrollView->getRect().size.width;
        float innerHeight =(imageView->getRect().size.height)*number;
        
        scrollView->setInnerContainerSize(CCSizeMake(innerWidth, innerHeight));
        
        int imageHeight=imageView->getRect().size.height;
        imageView->setPosition(ccp(winSize.width/2,scrollView->getInnerContainerSize().height-imageHeight*i-imageHeight/2));
        scrollView->addChild(imageView);
        
        
        UIImageView* imagehead= UIImageView::create();
        imagehead->setTexture("yuanbao.png");
        imagehead->setPosition(ccp(winSize.width/2-140,scrollView->getInnerContainerSize().height-imageHeight*i-imageHeight/2));
        scrollView->addChild(imagehead);
        
        char str[64];
        if(i<9)
        {
                sprintf(str,"%d",(i+1)*20000);
        }
        else
        {
                sprintf(str,"%d",50000);
        }
        
        UILabel *moneyLabel=UILabel::create();
        moneyLabel->setText(str);
        moneyLabel->setColor(ccBLACK);
        moneyLabel->setFontSize(32);
        moneyLabel->setPosition(ccp(winSize.width/2+100,scrollView->getInnerContainerSize().height-imageHeight*i-imageHeight/2));
        scrollView->addChild(moneyLabel);
        
       if(i<9)
       {
        sprintf(str,"%d级\n礼包",10*(i+1));
       }
       else
        {
            sprintf(str,"5星评论");
        }
        UILabel *label=UILabel::create();
        label->setFontSize(32);
        label->setText(str);
        label->setColor(ccBLUE);
        scrollView->addChild(label);
        label->setPosition(ccp(100,scrollView->getInnerContainerSize().height-imageHeight*i-imageHeight/2));
        
//        UIImageView* imagecoin= UIImageView::create();
//        imagecoin->setTexture("dollar.png");
//        imagecoin->setPosition(ccp(350,scrollView->getInnerContainerSize().height-imageHeight*i-imageHeight/2));
//        scrollView->addChild(imagecoin);
        
        if(i<9)
        {
            sprintf(str,"%d",(i+1)*100);
        }
        else
        {
            sprintf(str,"%d",500);
        }
        
        UILabel *coinLabel=UILabel::create();
        coinLabel->setText(str);
        coinLabel->setFontSize(32);
        coinLabel->setColor(ccBLACK);
        coinLabel->setPosition(ccp(winSize.width/2-70,scrollView->getInnerContainerSize().height-imageHeight*i-imageHeight/2));
        scrollView->addChild(coinLabel);
        
        UIButton* button = UIButton::create();
//        if(level[i])//已经领取
//        {
//            button->setTouchEnable(false);
//            button->loadTextures("fight1.png", "fight1.png", "");
//            button->addReleaseEvent(this, coco_releaseselector(JiangLiLayer::menuCallback));
//        }
       if(mlevel>=10*(i+1))//等级满足
        {
            button->setTouchEnable(true);
            button->loadTextures("getmoney2.png", "getmoney1.png", "");
            button->addReleaseEvent(this, coco_releaseselector(JiangLiLayer::menuPauseCallback));
        }
        else//等级不满足
        {
            button->setTouchEnable(false);
            button->loadTextures("getmoney1.png", "getmoney2.png", "");
            button->addReleaseEvent(this, coco_releaseselector(JiangLiLayer::menuCallback));
        }
        if(i==9)//等级满足
        {
            button->setTouchEnable(true);
            button->loadTextures("getmoney2.png", "getmoney1.png", "");
            button->addReleaseEvent(this, coco_releaseselector(JiangLiLayer::menuPauseCallback));
        }
        button->setPosition(ccp(winSize.width-100, scrollView->getInnerContainerSize().height-imageHeight*i-imageHeight/2));
        button->setTag(i);
        scrollView->addChild(button);
        }
    return true;
}