Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
void GameLayer::initAnswerLayer(std::vector<std::string> &StrVector)
{
    CCArray *answerChildren = _answerLayer->getChildren();
    
    _canAnsImageSize = static_cast<UIButton *>(answerChildren->objectAtIndex(0))->getContentSize();
    
    CCObject *obj_butt;
    
    int countPerRow = 8;
    int row = 0,col = 0;
    int currCount = 0;
    
    CCARRAY_FOREACH(answerChildren, obj_butt)
    {
        row = currCount / countPerRow;
        col = currCount % countPerRow;
        
        UIButton *anButt = (UIButton *)(obj_butt);
        anButt->setTouchEnable(true);
        anButt->addTouchEventListener(this,toucheventselector(GameLayer::answerButt));
        
        CCPoint buttPoint = CCPointMake(CG_FISTANBUTT_POINT.x + (CG_ANSWER_BUTT_SPACE_SIZE.width)* col, CG_FISTANBUTT_POINT.y + (CG_ANSWER_BUTT_SPACE_SIZE.height) * row);
        
        anButt->setPosition(buttPoint);
        
        std::string butt_titlt_str = StrVector.at(currCount);
        
        if (!CGHelper::isChineseChar(butt_titlt_str.c_str())) {
            anButt->setTitleFontSize(20);
        }
        
        anButt->setText(butt_titlt_str.c_str());
        currCount++;
    }
Ejemplo n.º 3
0
void PlayScene::onBtnClothes(CCObject *target, TouchEventType e) {
  UIButton* btn = (UIButton *)ui_layer_->getWidgetByName(btn_name[sub_stage_id_]);
  if (btn) {
    if(e == TOUCH_EVENT_BEGAN) {
      btn_start_pos_ = btn->getPosition();
    } else if(e == TOUCH_EVENT_ENDED) {
      CCPoint pos = btn->getPosition();
      if(btn_start_pos_.fuzzyEquals(pos, 100.0f)) {
        btn->setPosition(btn_start_pos_);
      } else {
        if(!all_finish_) {
          btn->setEnabled(false);
          btn = (UIButton *)ui_layer_->getWidgetByName("BtnStartPlay");
          btn->setEnabled(true); 
        } else {
          btn->setEnabled(false);
          User::CurrentUser()->set_stageid(stageid_ + 1);
          User::CurrentUser()->Flush();
          PopWin::Instance().ShowPopScene(this, true, toucheventselector(PlayScene::onPopBack));
        }
      }
    }
  }
  CCLOG("%s\n", __FUNCTION__);
}
Ejemplo n.º 4
0
void PlayScene::onBtnMoveClothes(CCObject *target) {
  UIButton* btn = (UIButton *)ui_layer_->getWidgetByName(btn_name[sub_stage_id_]);
  if (btn) {
    CCPoint move_pos = btn->getTouchMovePos();
    btn->setPosition(move_pos);
  }
  CCLOG("%s\n", __FUNCTION__);
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
void GeneralGroupLogic::onEnter()
{
    CCNode::onEnter();

    // Create general buttons in game.
    for (UINT i = 0; i < m_generalData.size(); ++i)
    {
        UIButton* pButton = UIButton::create();
        pButton->setWidgetTag(static_cast<int>(i));
        pButton->setPosition(ccp(VisibleRect::right().x - 10, 30 * (1 + i) + 50));
        pButton->setTouchEnable(true);
        // Set relationship between these picture with generalType.
        EGeneralType type = m_generalData[i];
        pButton->setTextures(NormalPng[type], SelectedPng[type], DisablePng[type]);

        pButton->addReleaseEvent(this, coco_releaseselector(GeneralGroupLogic::GeneralBottonClicked));
        pButton->addPushDownEvent(this, coco_releaseselector(GeneralGroupLogic::GeneralBottonPushDown));

        pButton->setScale(0.5f);

        UiManager::Singleton().AddChildWidget(pButton);
    }
}
bool UIPanelTest_Color::init()
{
    if (UIScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();        
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("Panel color render");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f - alert->getRect().size.height * 2.925));
        m_pUiLayer->addWidget(alert);
        
        UIPanel *background = dynamic_cast<UIPanel*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the panel with color render
        UIPanel* panel = UIPanel::create();
        panel->setBackGroundColorType(PANEL_COLOR_SOLID);
        panel->setBackGroundColor(ccc3(128, 128, 128));
        panel->setClippingEnable(true);
        panel->setSize(CCSizeMake(280, 150));
        CCSize backgroundSize = background->getContentSize();
        panel->setPosition(ccp((screenSize.width - backgroundSize.width) / 2 +
                               (backgroundSize.width - panel->getRect().size.width) / 2,
                               (screenSize.height - backgroundSize.height) / 2 +
                               (backgroundSize.height - panel->getRect().size.height) / 2));
        m_pUiLayer->addWidget(panel);
        
        UIButton* button = UIButton::create();
        button->setTouchEnable(true);
        button->setTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        button->setPosition(ccp(button->getRect().size.width / 2, panel->getRect().size.height - button->getRect().size.height / 2));
        panel->addChild(button);
        
        UITextButton* textButton = UITextButton::create();
        textButton->setTouchEnable(true);
        textButton->setTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", "");
        textButton->setText("Text Button");
        textButton->setPosition(ccp(panel->getRect().size.width / 2, panel->getRect().size.height / 2));
        panel->addChild(textButton);
        
        UIZoomButton* zoomButton = UIZoomButton::create();
        zoomButton->setTouchEnable(true);
        zoomButton->setTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "cocosgui/button.png");
        zoomButton->setTitle("ControlButton", "ControlButton", "ControlButton");
        zoomButton->setNormalFontSize(16);
        zoomButton->setNormalFontName("Marker Felt");
        zoomButton->setPressedFontSize(16);
        zoomButton->setPressedFontName("Marker Felt");
        zoomButton->setDisabledFontSize(16);
        zoomButton->setDisabledFontName("Marker Felt");
        zoomButton->setPreferredSize(CCSizeMake(100, zoomButton->getContentSize().height * 2.0f));
        zoomButton->setPosition(ccp(panel->getRect().size.width - zoomButton->getRect().size.width / 2,
                                       zoomButton->getRect().size.height / 2));
        panel->addChild(zoomButton);
        
        return true;
    }
    return false;
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
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);
}
Ejemplo n.º 12
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;
}