Esempio n. 1
0
Node* TopRankScene::createRow(int rank, int score, std::string name){

	Node* row = Node::create();

	Size visibleSize = Director::getInstance()->getVisibleSize();

	char _rank[2];
	itoa(rank, _rank, 10);
	LabelTTF* labelRank = LabelTTF::create(_rank, "AppleGothic", 20);
	char _score[10];
	itoa(score, _score, 10);
	LabelTTF* labelScore = LabelTTF::create(_score, "AppleGothic", 20); 
	LabelTTF* labelName = LabelTTF::create(name, "AppleGothic", 20);


	labelRank->setAnchorPoint(Point(0, 0));
	labelRank->setPosition(visibleSize.width / 4 + 10, visibleSize.height / 20 * (5 - rank) + 10);
	labelScore->setAnchorPoint(Point(0, 0));
	labelScore->setPosition(visibleSize.width / 4 * 3 + 10, visibleSize.height / 20 * (5 - rank) + 10);
	labelName->setAnchorPoint(Point(0, 0));
	labelName->setPosition(visibleSize.width / 4 * 2 + 10, visibleSize.height / 20 * (5 - rank) + 10);

	row->addChild(labelName);
	row->addChild(labelRank);
	row->addChild(labelScore);

	row->setAnchorPoint(Point(0, 0));
	row->setPosition(0, visibleSize.height / 20 * (5 - rank));
	return row;
}
Esempio n. 2
0
Node* TopRankScene::createFirstRow(){
	Node* row = Node::create();

	Size visibleSize = Director::getInstance()->getVisibleSize();

	
	LabelTTF* labelRank = LabelTTF::create("排名", "AppleGothic", 20);
	LabelTTF* labelScore = LabelTTF::create("分数", "AppleGothic", 20);
	LabelTTF* labelName = LabelTTF::create("姓名", "AppleGothic", 20);


	labelRank->setAnchorPoint(Point(0, 0));
	labelRank->setPosition(visibleSize.width / 4, visibleSize.height / 20 * 5 + 10);
	labelScore->setAnchorPoint(Point(0, 0));
	labelScore->setPosition(visibleSize.width / 4 * 3 + 10, visibleSize.height / 20 * 5  + 10);
	labelName->setAnchorPoint(Point(0, 0));
	labelName->setPosition(visibleSize.width / 4 * 2 + 10, visibleSize.height / 20 * 5 + 10);

	row->addChild(labelName);
	row->addChild(labelRank);
	row->addChild(labelScore);

	row->setAnchorPoint(Point(0, 0));
	row->setPosition(0, visibleSize.height / 20 * 5+ 10);
	return row;
}
Esempio n. 3
0
void ChatLayer::setChatVector(std::vector<std::string> textVector ,
                   std::vector<std::string> senderNameVector,std::vector<int> senderId) {
    
    std::reverse(textVector.begin(), textVector.end());
    std::reverse(senderNameVector.begin(), senderNameVector.end());
    std::reverse(senderId.begin(), senderId.end());
    
    this->textVector = textVector;
    this->senderNameVector = senderNameVector;
    this->senderId = senderId;
    int i = 0;

    CCLOG("__________ Message __________");
    
    for (std::vector<std::string>::iterator it = this->textVector.begin() ; it != this->textVector.end(); ++it) {
        
        std::string message;
        LabelTTF* searchLabel = NULL;
        int count = 0;
        
        if (this->senderId.at(i) == UserDefault::getInstance()->getIntegerForKey("Player_ID")) {
            message = "Me: " + this->textVector.at(i);
            
            count = (message.length()/CHARACTER_IN_LINE)+1;
            searchLabel = LabelTTF::create(message.c_str(), "helvetica", 24,Size(275,LINE_HEIGHT*count), TextHAlignment::LEFT,TextVAlignment::TOP);
            searchLabel->setAnchorPoint(Point(0,1));
            searchLabel->setPosition(10,700 - (numberOfLines * LINE_HEIGHT) - (numberOfMessages * LINE_HEIGHT/2));
        }
        else {
            message = this->senderNameVector.at(i) + ": "+ this->textVector.at(i);
            
            count = (message.length()/CHARACTER_IN_LINE)+1;
            searchLabel = LabelTTF::create(message.c_str(), "helvetica", 24,Size(275,LINE_HEIGHT*count), TextHAlignment::LEFT,TextVAlignment::TOP);
            searchLabel->setAnchorPoint(Point(0,1));
            searchLabel->setPosition(10,700 - (numberOfLines * LINE_HEIGHT) - (numberOfMessages * LINE_HEIGHT/2));
        }
        
        searchLabel->setColor(Color3B(255, 0, 0));
        chatNode->addChild(searchLabel);
        
        numberOfLines = numberOfLines + count;
        numberOfMessages = numberOfMessages + 1;
        
        CCLOG("Count :: %d Message :: %s",count,message.c_str());

        i++;
    }
    
    stopWaitingAnim();
}
Esempio n. 4
0
TableViewCell* TableViewTestLayer::tableCellAtIndex(TableView *table, unsigned int idx)
{
    String *string = String::createWithFormat("%d", idx);
    TableViewCell *cell = table->dequeueCell();
    if (!cell) {
        cell = new CustomTableViewCell();
        cell->autorelease();
        Sprite *sprite = Sprite::create("Images/Icon.png");
        sprite->setAnchorPoint(Point::ZERO);
        sprite->setPosition(Point(0, 0));
        cell->addChild(sprite);

        LabelTTF *label = LabelTTF::create(string->getCString(), "Helvetica", 20.0);
        label->setPosition(Point::ZERO);
		label->setAnchorPoint(Point::ZERO);
        label->setTag(123);
        cell->addChild(label);
    }
    else
    {
        LabelTTF *label = (LabelTTF*)cell->getChildByTag(123);
        label->setString(string->getCString());
    }


    return cell;
}
Esempio n. 5
0
ControlButton* standardButtonWithTitle( const char * bgname, const char * bgseledname, const char * title){

	//Creates and return a button with a default background and title color.
//    Scale9Sprite *backgroundButton = Scale9Sprite::create(bgname);//按下前
//    Scale9Sprite *backgroundHighlightedButton = Scale9Sprite::create(bgseledname);//按下后
	

	ControlButton* btn = ControlButton::create();
	btn->setPreferredSize(Size(522, 88));

	Scale9Sprite*	normal = Scale9Sprite::create(bgname);
	Scale9Sprite*	select = Scale9Sprite::create(bgseledname);
	Scale9Sprite* hightlight = Scale9Sprite::create(bgseledname);
	Scale9Sprite* disable = Scale9Sprite::create(bgname);
	
	btn->setBackgroundSpriteForState(normal, Control::State::NORMAL);
	btn->setBackgroundSpriteForState(select, Control::State::SELECTED);
	btn->setBackgroundSpriteForState(hightlight, Control::State::HIGH_LIGHTED);
	btn->setBackgroundSpriteForState(disable, Control::State::DISABLED);
	
	
    LabelTTF *titleButton = LabelTTF::create(title, "AmericanTypewriter", 30);//添加文字
	titleButton->setAnchorPoint(Point(0.5f, 0.5f));
	titleButton->setPosition(Point(btn->getContentSize().width/2, btn->getContentSize().height/2));
	titleButton->setColor(Color3B::BLACK);//设置文字点击前的颜色
	titleButton->setTag(1000);
	btn->addChild(titleButton);

    return btn;
}
Esempio n. 6
0
void TestUseMutiplePicture::onEnter()
{
    ArmatureTestLayer::onEnter();
    setTouchEnabled(true);

    displayIndex = 0;

    armature = Armature::create("Knight_f/Knight");
    armature->getAnimation()->playByIndex(0);
    armature->setPosition(Point(VisibleRect::center().x, VisibleRect::left().y));
    armature->setScale(1.2f);
    addChild(armature);

    std::string weapon[] = {"weapon_f-sword.png", "weapon_f-sword2.png", "weapon_f-sword3.png", "weapon_f-sword4.png", "weapon_f-sword5.png", "weapon_f-knife.png", "weapon_f-hammer.png"};

    for (int i = 0; i < 7; i++)
    {
        Skin *skin = Skin::createWithSpriteFrameName(weapon[i].c_str());
        armature->getBone("weapon")->addDisplay(skin, i);
    }

    // 	CCSpriteDisplayData displayData;
    // 	for (int i = 0; i < 7; i++)
    // 	{
    // 		displayData.setParam(weapon[i].c_str());
    // 		armature->getBone("weapon")->addDisplay(&displayData, i);
    // 	}

    LabelTTF *l = LabelTTF::create("This is a weapon!", "Arial", 18);
    l->setAnchorPoint(Point(0.2f, 0.5f));
    armature->getBone("weapon")->addDisplay(l, 7);
}
Esempio n. 7
0
void Akuerdate::pintoPalabra(){
    
    LabelTTF *texto = CCLabelTTF::create(gProfesion->obtenerPalabraElemento(tagActual)->getCString(), "HVD_Comic_Serif_Pro.ttf",100,Size(panelPalabras->getContentSize().width-margenPanelPalabrasInterno,130), TextHAlignment::CENTER);
    texto->setColor(Color3B(228,70,106));
    texto->setVerticalAlignment(TextVAlignment::CENTER);
    texto->setAnchorPoint(Vec2(1,1));
    texto->setPosition(panelPalabras->getContentSize().width+margenPanelPalabrasInterno,panelPalabras->getContentSize().height-((panelPalabras->getChildrenCount()*(100+margenPanelPalabrasInterno))+(margenPanelPalabrasInterno*5)));
    //texto->setPosition(0,0);
    panelPalabras->addChild(texto);
    
}
Esempio n. 8
0
void LeaderBoardtNode::addItemToSlide(const int& iScore, const char* sName, const char* sFacebookId, const int& iRank, const int& iIndex)
{
    Node* pNodeItem = Node::create();

    Sprite* pLoadAvatar = Sprite::create("Target-End-Game/border_avatar.png");
    pLoadAvatar->setPosition(Point(50.0f, 95.0f));
    pNodeItem->addChild(pLoadAvatar);

    std::string urlAvatar = "https://graph.facebook.com/";
    urlAvatar.append(sFacebookId);
    urlAvatar.append("/picture");

    LoadingImagetNode* avatar = LoadingImagetNode::createLayout(urlAvatar.c_str());
    avatar->setPosition(Point(50.0f, 95.0f));
    pNodeItem->addChild(avatar);

    LabelBMFont *pLabelScore = LabelBMFont::create(formatNumber(iScore).getCString(), "fonts/font_small_alert.fnt");
    pLabelScore->setAnchorPoint(Point(0.0f, 0.5f));
    pLabelScore->setPosition(Point(57.0f, 8.0f));
    pLabelScore->setScale(0.8);
    pNodeItem->addChild(pLabelScore);

    LabelTTF *pLabelName = LabelTTF::create(sName, "Arial", 20.0f);
    pLabelName->setColor(ccc3(0.0f, 0.0f, 0.0f));
    //pLabelName->setScale(0.85f);
    pLabelName->setAnchorPoint(Point(0.0f, 0.5f));
    pLabelName->setPosition(Point(57.0f, 45.0f));
    pNodeItem->addChild(pLabelName);

    char sRank[10];
    sprintf(sRank, "%d", iRank);
    LabelBMFont *pLabelRank = LabelBMFont::create(sRank, "fonts/font-bechic.fnt");
    pLabelRank->setAnchorPoint(Point(0.0f, 0.5f));
    pLabelRank->setPosition(Point(25.0f, 23.0f));
    pNodeItem->addChild(pLabelRank);

    Sprite* pLineImage = Sprite::create("Target-End-Game/line.png");
    pLineImage->setPosition(Point(160.0f, 55.0f));
    pNodeItem->addChild(pLineImage);

    pNodeItem->setContentSize(Size(160.0f, 160.0f));
    pNodeItem->setPosition(Point(-320.0f + iIndex*160, -100.0f));
    pNodeItem->setTag(iIndex);
    m_pSlideShow->addChild(pNodeItem);

    Sprite* pIconAskLife = Sprite::create("Target-End-Game/btn_ask_life.png");
    ButtonNode* pButtonAskLife = ButtonNode::createButtonSprite(pIconAskLife, CC_CALLBACK_1(LeaderBoardtNode::clickAskLife, this));
    pButtonAskLife->setPosition(Point(-205.0f + iIndex*160, -5.0f));
    m_pButtonManagerNode->addButtonNode(pButtonAskLife);
}
Esempio n. 9
0
void ChatLayer::addMessageFromOpponent(std::string message) {
    std::string msg = "Parth: " + message;
    LabelTTF* searchLabel = NULL;
    
    int count = (msg.length()/CHARACTER_IN_LINE)+1;
    
    searchLabel = LabelTTF::create(msg.c_str(), "helvetica", 24,Size(275,LINE_HEIGHT*count), TextHAlignment::LEFT,TextVAlignment::TOP);
    searchLabel->setAnchorPoint(Point(0,1));
    searchLabel->setPosition(10,700 - (numberOfLines * LINE_HEIGHT) - (numberOfMessages * LINE_HEIGHT/2));
    
    searchLabel->setColor(Color3B(255, 0, 0));
    chatNode->addChild(searchLabel);
    
    numberOfLines = numberOfLines + count;
    numberOfMessages = numberOfMessages + 1;
}
Esempio n. 10
0
void LeaderBoardAdvanceModeNode::addItemToSlide(const int& iStage, const char* sName, const char* sFacebookId, const int& iRank)
{
    Node* pNodeItem = Node::create();

    Sprite* pLoadAvatar = Sprite::create("Target-End-Game/border_avatar.png");
    pLoadAvatar->setPosition(Point(55.0f, 65.0f));
    pNodeItem->addChild(pLoadAvatar);

    std::string urlAvatar = "https://graph.facebook.com/";
    urlAvatar.append(sFacebookId);
    urlAvatar.append("/picture");

    LoadingImagetNode* avatar = LoadingImagetNode::createLayout(urlAvatar.c_str());
    avatar->setPosition(Point(56.0f, 65.0f));
    pNodeItem->addChild(avatar);

    LabelTTF *pLabelName = LabelTTF::create(sName, "Arial", 20.0f);
    pLabelName->setColor(ccc3(0.0f, 0.0f, 0.0f));
    //pLabelName->setScale(0.80f);
    pLabelName->setAnchorPoint(Point(0.0f, 0.5f));
    pLabelName->setPosition(Point(26.0f, 17.0f));
    pNodeItem->addChild(pLabelName);

    char sStage[5];
    sprintf(sStage, "%d", iStage);
    LabelBMFont *pLabelNumberStage = LabelBMFont::create(sStage, "fonts/font-bechic.fnt");
    pLabelNumberStage->setAnchorPoint(Point(0.5f, 0.5f));
    pLabelNumberStage->setPosition(Point(130.0f, 85.0f));
    pLabelNumberStage->setScale(0.90);
    pNodeItem->addChild(pLabelNumberStage);

    LabelBMFont *pLabelStage = LabelBMFont::create("Stage", "fonts/font_small_alert.fnt");
    pLabelStage->setAnchorPoint(Point(0.5f, 0.5f));
    pLabelStage->setPosition(Point(130.0f, 50.0f));
    pLabelStage->setScale(0.8f);
    pNodeItem->addChild(pLabelStage);

    Sprite* pLineImage = Sprite::create("Target-End-Game/line.png");
    pLineImage->setPosition(Point(160.0f, 55.0f));
    pNodeItem->addChild(pLineImage);

    pNodeItem->setContentSize(Size(160.0f, 160.0f));
    pNodeItem->setPosition(Point(-320.0f + (iRank-1)*160, -100.0f));
    m_pSlideShow->addChild(pNodeItem);
}
TableViewCell* HelloWorld::tableCellAtIndex(cocos2d::extension::TableView *table, ssize_t idx){
    
    TableViewCell *cell = table->dequeueCell();
    LabelTTF *label;
    
    if(cell == NULL){
        cell = TableViewCell::create();
        label = LabelTTF::create();
        label->setTag(2);
        cell->addChild(label);
        label->setFontSize(30);
        label->setAnchorPoint(Point(0,0));
    }
    else {
        label = (LabelTTF*)cell->getChildByTag(2);
    }
    
    label->setString(StringUtils::format("Label %ld",idx));
    
    return cell;
};
Esempio n. 12
0
void PopUpBombLayer::setUpView(){
	Size winSize = Director::getInstance()->getWinSize();
    Point pCenter = Point(winSize.width / 2, winSize.height / 2);
	
	std::vector<std::string> imgs;
	imgs.push_back(std::string("play_dialog_bg.png"));//bg

	imgs.push_back(std::string("play_dialog_button_long.png")); //close b n
	imgs.push_back(std::string("play_dialog_button_long_selected.png")); //close b s
	
	bgLay = Layer::create();
	
	
	LabelTTF * tip = LabelTTF::create("提示", "AmericanTypewriter", 30);//添加文字
	tip->setAnchorPoint(Point(0.5f, 0.5f));
	tip->setColor(Color3B::YELLOW);
	tip->setPosition(Point(pCenter.x, pCenter.y + 40));
	bgLay->addChild(tip, 2);
	
	LabelTTF *label = LabelTTF::create("确认花费20枚金币,\n去掉一个错误答案么?", "AmericanTypewriter", 40);//添加文字
	label->setAnchorPoint(Point(0.5f, 0.5f));
	label->setColor(Color3B::WHITE);
	label->setPosition(Point(pCenter.x, pCenter.y - 60));
	bgLay->addChild(label, 2);
	

	Sprite* bg = Sprite::create( imgs.at(0));
	auto menuItem1 = MenuItemImage::create(
										   imgs.at(1),
										   imgs.at(2),
										   CC_CALLBACK_1(PopUpBombLayer::bombUse, this));
	auto menuItem2 = MenuItemImage::create(
										   imgs.at(1),
										   imgs.at(2),
										   CC_CALLBACK_1(PopUpBombLayer::bombNotUse, this));
	
	bg->setAnchorPoint(Point(0.5f, 0.5f));
	menuItem1->setAnchorPoint(Point(0.5f, 0.5f));
	menuItem2->setAnchorPoint(Point(0.5f, 0.5f));
	
	// create menu, it's an autorelease object
    auto menu = Menu::create(menuItem1, menuItem2, NULL);
    menu->setPosition(Point::ZERO);
	
	menuItem1->setPosition(Point(pCenter.x - 120,  pCenter.y - 180));
	menuItem2->setPosition(Point(pCenter.x + 120 ,  pCenter.y - 180));
	
	LabelTTF *label1 = LabelTTF::create("好的", "AmericanTypewriter", 30);//添加文字

	label1->setColor(Color3B::WHITE);
	label1->setPosition(menuItem1->getPosition());
	bgLay->addChild(label1, 2);
	
	LabelTTF *label2 = LabelTTF::create("忍着不用", "AmericanTypewriter", 30);//添加文字

	label2->setColor(Color3B::WHITE);
	label2->setPosition(menuItem2->getPosition());
	bgLay->addChild(label2,2);
	
	bg->setPosition(Point(pCenter.x, pCenter.y + 20));
	
	bgLay->setContentSize(winSize);
	bgLay->addChild(bg);
    bgLay->addChild(menu, 1);
	//	bgLay->addChild(title,2);
	
	this->addChild(bgLay);
}
Esempio n. 13
0
FailScene::FailScene(void)
{
	Vec2 points[] = {	Vec2(0, 0), 
						Vec2(0, 140),
						Vec2(400, 140),
						Vec2(400, 0) };
	DrawNode* draw = DrawNode::create();
	//±³¾°
	draw->drawPolygon(points, 4, ColorUtil::getColor4F(0x00 , 0xAD , 0xFF, 0xFF),
								0, ColorUtil::getColor4F(0x00, 0xDA, 0xFF, 0xFF));

	this->addChild(draw);
	draw->setAnchorPoint(Point(.5, .5));
	draw->setPositionX(ScreenUtil::getCenter().x - 200);
	draw->setPositionY(ScreenUtil::getCenter().y - 140);

	Vec2 points2[] = {	Vec2(0, 0), 
						Vec2(0, 150),
						Vec2(230, 150),
						Vec2(230, 0) };
	DrawNode* draw2 = DrawNode::create();
	//±³¾°
	draw2->drawPolygon(points2, 4, ColorUtil::getColor4F(0x00 , 0xAD , 0xFF, 0xFF),
								0, ColorUtil::getColor4F(0x00, 0xDA, 0xFF, 0xFF));

	this->addChild(draw2);
	draw2->setAnchorPoint(Point(.5, .5));
	draw2->setPositionX(ScreenUtil::getCenter().x - 115);
	draw2->setPositionY(ScreenUtil::getCenter().y + 40);

	LabelTTF* scoreTxt = LabelTTF::create("Score:", "Arial", 45);
	scoreTxt->setAnchorPoint(Point(0, .5));
	scoreTxt->setPosition(Point(draw2->getPositionX() + 10, 
								draw2->getPositionY() + 110));
	this->addChild(scoreTxt);

	LabelTTF* bestScoreTxt = LabelTTF::create("Best:", "Arial", 45);
	bestScoreTxt->setAnchorPoint(Point(0, .5));
	bestScoreTxt->setPosition(Point(scoreTxt->getPositionX(), 
									draw2->getPositionY() + 50));
	this->addChild(bestScoreTxt);

	LabelTTF* scoreValTxt = LabelTTF::create("0", "Arial", 45);
	scoreValTxt->setPositionX(scoreTxt->getPositionX() + scoreTxt->getContentSize().width + 25);
	scoreValTxt->setPositionY(scoreTxt->getPositionY());
	scoreValTxt->setTag(scoreValTxtTag);
	this->addChild(scoreValTxt);

	LabelTTF* bestScoreValTxt = LabelTTF::create("0", "Arial", 45);
	bestScoreValTxt->setPositionX(scoreValTxt->getPositionX());
	bestScoreValTxt->setPositionY(bestScoreTxt->getPositionY());
	bestScoreValTxt->setTag(bestScoreValTxtTag);
	this->addChild(bestScoreValTxt);

	LabelTTF* replayTxt = LabelTTF::create("Replay", "Arial", 45);
	MenuItemLabel* replayBtn = MenuItemLabel::create(replayTxt);
	replayBtn->setTag(replayBtnTag);

	LabelTTF* shareTxt = LabelTTF::create("Share", "Arial", 45);
	MenuItemLabel* shareBtn = MenuItemLabel::create(shareTxt);

	Menu* menu = Menu::create(replayBtn, shareBtn,  NULL);
	menu->setPositionX(ScreenUtil::getCenter().x);
	menu->setPositionY(ScreenUtil::getCenter().y - 70);
	menu->alignItemsHorizontallyWithPadding(50);
	menu->setTag(menuTag);
	this->addChild(menu);
}
bool ChatScene::init()
{
    if(!Layer::init())
    {
        return false;
    }
    Rect visibleRect = VisibleRect::getVisibleRect();
    m_tBeginPoint = Vec2(0, VisibleRect::top().y-50);
    auto backLabel = LabelTTF::create("Back", "Arial", 25);
    MenuItem* pBackMenuItem = MenuItemLabel::create(backLabel, std::bind(&ChatScene::backCallback, this, std::placeholders::_1));
    Menu* pBackMenu = Menu::create(pBackMenuItem, NULL);
    pBackMenu->setAnchorPoint(Point::ZERO);
    pBackMenu->setPosition(Vec2(VisibleRect::right().x+35, VisibleRect::top().y-20));
    this->addChild(pBackMenu, 10);
    
    auto pUserLabel = LabelTTF::create("Users", "Arial", 25);
    MenuItemLabel* pUserMenuItem = MenuItemLabel::create(pUserLabel, std::bind(&ChatScene::userCallback, this, std::placeholders::_1));
    Menu* pUserMenu = Menu::create(pUserMenuItem, NULL);
    pUserMenu->setAnchorPoint(Vec2::ZERO);
    pUserMenu->setPosition(Vec2(VisibleRect::right().x -40,VisibleRect::top().y -20));
    this->addChild(pUserMenu, 10);
    
    auto pSendLabel = LabelTTF::create("Send", "Arial", 25);
    MenuItemLabel* pSendMenuItem = MenuItemLabel::create(pSendLabel, std::bind(&ChatScene::sendCallback, this, std::placeholders::_1));
    Menu* pSendMenu = Menu::create(pSendMenuItem, NULL);
    pSendMenu->setAnchorPoint(Vec2::ZERO);
    pSendMenu->setPosition(Vec2(VisibleRect::right().x-45, 25));
    addChild(pSendMenu,10);
    
    this->m_pChannelText = LabelTTF::create(s_channel.c_str(), "Arial", 25);
    this->m_pChannelText->setPosition(Vec2(VisibleRect::center().x, VisibleRect::top().y - 20));
    addChild(this->m_pChannelText, 10);
    
    m_layer = Layer::create();
    
    for (int i = 0; i<visibleRect.size.height/LINE_SPACE; ++i) {
        LabelTTF* pLabel;
        if(i<TESTS_COUNT)
        {
            pLabel = LabelTTF::create(global_text[i].c_str(), "Arial", 23);
            pLabel->setDimensions(Size(visibleRect.size.width, 50));
        }
        else
        {
            pLabel = LabelTTF::create("", "Arial", 23);
            pLabel->setDimensions(Size(visibleRect.size.width, 50));
        }
        pLabel->setColor(Color3B(32, 32, 32));
        pLabel->setAnchorPoint(Vec2(0, 0));
        pLabel->setPosition(Vec2(VisibleRect::left().x+10, (m_tBeginPoint.y-(i+1)*LINE_SPACE)));
        m_layer->addChild(pLabel, 10, i);
    }
    
    m_layer->setContentSize(Size(Vec2(VisibleRect::getVisibleRect().size.width-30, (TESTS_COUNT+1)*(LINE_SPACE))));
    m_layer->setPosition(s_tCurPos);
    addChild(m_layer,2);
    
    LayerColor* pLayer1 = LayerColor::create(Color4B(255, 255, 255, 255), visibleRect.size.width, visibleRect.size.height);
    pLayer1->setCascadeColorEnabled(false);
    pLayer1->setPosition(Vec2(0,0));
    addChild(pLayer1,1);
    
    LayerColor* pLayer2 = LayerColor::create(Color4B(0, 0, 0, 255), visibleRect.size.width, 40);
    pLayer2->setCascadeColorEnabled(false);
    pLayer2->setPosition(Vec2(0, VisibleRect::top().y-40));
    addChild(pLayer2,8);
    
    LayerColor* pLayer3 = LayerColor::create(Color4B(72, 72, 72, 255), visibleRect.size.width, 50);
    pLayer3->setCascadeColorEnabled(false);
    pLayer3->setPosition(Vec2(0, 0));
    addChild(pLayer3,8);
    
    m_pTextField = TextFieldTTF::textFieldWithPlaceHolder("", FONT_NAME, FONT_SIZE);
    m_pTextField->setAnchorPoint(Vec2::ZERO);
    m_pTextField->setPosition(VisibleRect::left().x+10,5);
    //m_pTextField->setColorSpaceHolder(Color3B(255,0,0));
    m_pTextField->setString("1111111111111111111111111111111111111111111111111111111111");
    addChild(m_pTextField,12);
    
    m_pTextField->setDelegate(this);
    
    return true;
}
Esempio n. 15
0
void Dialog::updateLayout()
{
    Size content_size = this->getContentSize();

    Menu* menu = Menu::create();
    menu->setPosition(15.0f, 10.0f);
    menu->setContentSize(Size(240.0f, 27.0f));

    float button_size = (240.0f - 1.0f * (m_list_button.size() - 1)) / m_list_button.size();
    int i = 0;

    for(auto it = m_list_button.begin(); it != m_list_button.end(); it++, i++) {
        if(it != m_list_button.begin()) {
            DrawObject* draw_line = DrawObject::create();
            draw_line->setPosition(button_size + 1.0f * (i - 1), 1.0f);
            draw_line->setContentSize(Size(1.0f, 25.0f));
            draw_line->setOnDraw([=] () {
                DrawPrimitives::setDrawColor4B(127, 127, 127, 255);
                DrawPrimitives::drawLine(Point(0.0f, 0.0f), Point(0.0f, draw_line->getContentSize().height));
            });
            draw_line->setAnchorPoint(Point(0.0f, 0.0f));

            menu->addChild(draw_line);
        }

        LabelTTF* label = LabelTTF::create(it->first, FourCard::DEFAULT_FONT, 20.0f, Size(button_size, 27.0f), TextHAlignment::CENTER, TextVAlignment::CENTER);
        label->setColor(Color3B(127, 127, 127));
        label->setAnchorPoint(Point(0.0f, 0.0f));

        MenuItemLabel* menuItem = MenuItemLabel::create(label, [=] (Object* pSender) {
            it->second();
        });
        menuItem->setAnchorPoint(Point(0.0f, 0.0f));
        menuItem->setPosition(button_size * i + 1.0f * i, 0.0f);

        menu->addChild(menuItem);
    }

    m_dialog->addChild(menu);

    DrawObject* draw_line_message = DrawObject::create();
    draw_line_message->setPosition(15.0f, 47.0f);
    draw_line_message->setContentSize(Size(240.0f, 1.0f));
    draw_line_message->setOnDraw([=] () {
        DrawPrimitives::setDrawColor4B(127, 127, 127, 255);
        DrawPrimitives::drawLine(Point(0.0f, 0.0f), Point(draw_line_message->getContentSize().width, 0.0f));
    });
    draw_line_message->setAnchorPoint(Point(0.0f, 0.0f));

    m_dialog->addChild(draw_line_message);

    if(m_layer != nullptr) {
        m_layer->setPosition(15.0f + (240.0f - m_layer->getContentSize().width) / 2, 48.0f);
        m_dialog->addChild(m_layer);
    }

    LabelTTF* label_message = LabelTTF::create(m_message, FourCard::DEFAULT_FONT, 15.0f, Size(240.0f, 0.0f), TextHAlignment::CENTER);
    label_message->setPosition(15.0f, 63.0f + ((m_layer != nullptr) ? m_layer->getContentSize().height : 0));
    label_message->setColor(Color3B(60, 60, 60));
    label_message->setAnchorPoint(Point(0.0f, 0.0f));

    m_dialog->addChild(label_message);

    DrawObject* draw_line_title = DrawObject::create();
    draw_line_title->setPosition(15.0f, 59.0f + ((m_layer != nullptr) ? m_layer->getContentSize().height : 0) + label_message->getContentSize().height + 15.0f);
    draw_line_title->setContentSize(Size(240.0f, 1.0f));
    draw_line_title->setOnDraw([=] () {
        DrawPrimitives::setDrawColor4B(127, 127, 127, 255);
        DrawPrimitives::drawLine(Point(0.0f, 0.0f), Point(draw_line_title->getContentSize().width, 0.0f));
    });
    draw_line_title->setAnchorPoint(Point(0.0f, 0.0f));

    m_dialog->addChild(draw_line_title);

    LabelTTF* label_title = LabelTTF::create(m_title, FourCard::DEFAULT_FONT, 20.0f, Size(240.0f, 27.0f), TextHAlignment::LEFT, TextVAlignment::CENTER);
    label_title->setPosition(15.0f, 74.0f + ((m_layer != nullptr) ? m_layer->getContentSize().height : 0) + label_message->getContentSize().height + 1.0f + 10.0f);
    label_title->setColor(Color3B(60, 60, 60));
    label_title->setAnchorPoint(Point(0.0f, 0.0f));

    m_dialog->addChild(label_title);

    m_dialog->setContentSize(Size(270.0f, 124.0f + ((m_layer != nullptr) ? m_layer->getContentSize().height : 0) + label_message->getContentSize().height));
    m_dialog->setPosition((content_size.width - m_dialog->getContentSize().width) / 2, (content_size.height - m_dialog->getContentSize().height) / 2);

    Scale9Sprite* sprite_background = Scale9Sprite::create(Rect(10, 10, 1, 1), "sprites/dialog/background.png");
    sprite_background->setContentSize(m_dialog->getContentSize());
    sprite_background->setAnchorPoint(Point(0.0f, 0.0f));

    m_dialog->addChild(sprite_background, -1);
}
Esempio n. 16
0
void AdvanceModePopularPackagesLayer::resultHttpRequestCompleted(cs::JsonDictionary* pJsonDict, std::string sKey)
{
	this->removeChildByTag(_TAG_ICON_LOADING_);

	String sTag = "GetPackagePopular";
	sTag.appendWithFormat("_%d", m_iConnectServer);
	
	if (sKey == sTag.getCString())
	{
		if (pJsonDict != NULL)
		{			
			cs::JsonDictionary* jsonData = pJsonDict->getSubDictionary("data");
			if(jsonData != NULL)
			{
				if (jsonData->getItemBoolvalue("result", false))
				{

					m_iTotalPackage = jsonData->getArrayItemCount("list");
					m_maxHeight = m_iTotalPackage*120.0f;
					for(int iIndex=0; iIndex < m_iTotalPackage; iIndex++)
					{

						cs::JsonDictionary* pJsonItem = jsonData->getSubItemFromArray("list", iIndex);
						CSPackageInfo csPackageInfo;
						csPackageInfo.sPackageName = pJsonItem->getItemStringValue("WordListName");
					

						csPackageInfo.sPackageCode = pJsonItem->getItemStringValue("PackageCode");
						csPackageInfo.sCreatedBy = pJsonItem->getItemStringValue("Author");


						csPackageInfo.iTotalWord = pJsonItem->getItemIntValue("TotalWords", 0);
						csPackageInfo.iTotalWordUnlock = 0;
					

						m_csPackageInfos.push_back(csPackageInfo);

						LabelBMFont *pLabelPackageName = LabelBMFont::create(csPackageInfo.sPackageName.c_str(), "fonts/font_small_alert.fnt", 310.0f);
						pLabelPackageName->setAnchorPoint(Point(0.0f, 0.5f));
						pLabelPackageName->setPosition(Point(0.0f, -iIndex*120 - 10));
						m_pSlideShow->addChild(pLabelPackageName);

						LabelTTF* pLabelTCreatedBy = LabelTTF::create(csPackageInfo.sCreatedBy.c_str(), "Arial", 28, Size(310.0f, 30.0f), TextHAlignment::LEFT, TextVAlignment::TOP);
						pLabelTCreatedBy->setColor(ccc3(255.0f, 255.0f, 255.0f));
						pLabelTCreatedBy->setAnchorPoint(Point(0.0f, 0.5f));
						pLabelTCreatedBy->setPosition(Point(0.0f, -iIndex*120 - 55));
						m_pSlideShow->addChild(pLabelTCreatedBy);


						LabelBMFont *pLabelPackageCode = LabelBMFont::create(csPackageInfo.sPackageCode.c_str(), "fonts/font_score.fnt");
						pLabelPackageCode->setAnchorPoint(Point(1.0f, 0.5f));
						pLabelPackageCode->setPosition(Point(440.0f, -iIndex*120 - 10));
						m_pSlideShow->addChild(pLabelPackageCode);

						char sTotalWord[20];
						sprintf(sTotalWord, "%d Words", csPackageInfo.iTotalWord);
						LabelTTF* pLabelTotalWord = LabelTTF::create(sTotalWord, "Arial", 28);
						pLabelTotalWord->setColor(ccc3(255.0f, 255.0f, 255.0f));
						pLabelTotalWord->setAnchorPoint(Point(1.0f, 0.5f));
						pLabelTotalWord->setPosition(Point(420.0f, -iIndex*120 - 55));
						m_pSlideShow->addChild(pLabelTotalWord);
					

						Sprite* pButtonPlayPackageImage = Sprite::create("AdvanceMode/download-icon.png");
						ButtonNode* pButtonPlayPackage = ButtonNode::createButtonSprite(pButtonPlayPackageImage, CC_CALLBACK_1(AdvanceModePopularPackagesLayer::clickDownloadPackage, this));
						pButtonPlayPackage->setTag(iIndex);
						pButtonPlayPackage->setPosition(Point(460.0f, -iIndex*120 - 35));
						m_pSlideShow->addButtonNode(pButtonPlayPackage);					

						Sprite* pLineImage = Sprite::create("AdvanceMode/line.png"); 
						pLineImage->setPosition(Point(245.0f, -iIndex*120 -90.0f));
						m_pSlideShow->addChild(pLineImage, 5);
					}
				}
			}
		}
	}
}