void GamePan::refreshWorldPad() { CCNode* pBaseNode = m_pCcbNode->getChildByTag(kTagGamePanWordPan); CCNode* tabNode = pBaseNode->getChildByTag(kTagGamePanWordPanTabBase); CCNode* itemNode = pBaseNode->getChildByTag(kTagGamePanWordPanItemBase); CCLabelTTF* itemTemp = dynamic_cast<CCLabelTTF*>(itemNode->getChildByTag(kTagGamePanWordPanItemTitle)); CCControlButton* tabItem = dynamic_cast<CCControlButton*>(tabNode->getChildByTag(kTagGamePanWordPanTabBaseItem)); float itemWidth = tabItem->getContentSize().width+ITEM_SPACE; float itemHeight = tabItem->getContentSize().height+ITEM_SPACE; for(int i =0;i<MAX_LINE;i++) { for(int j =0;j<MAX_ROW;j++) { CCControlButton* item = CCControlButton::create(); Utils::copyCCControlButton(item,tabItem); item->setPosition(ccp(tabItem->getPositionX()+j*itemWidth,tabItem->getPositionY()-i*itemHeight)); item->setTag(j+i*MAX_ROW); tabNode->addChild(item); CCLabelTTF* title = Utils::copyCCLabelTTF(itemTemp); title->setPosition(item->getPosition()); title->setTag(j+i*MAX_ROW); itemNode->addChild(title); CCString* str = (CCString*)_wordList->randomObject(); title->setString(str->getCString()); _wordList->removeObject(str); } } for(int i =0;i<MAX_LINE;i++) { for(int j =0;j<MAX_ROW;j++) { CCControlButton* item = dynamic_cast<CCControlButton*>(tabNode->getChildByTag(j+i*MAX_ROW)); XCheckBox* pCheckBox = XCheckBox::create(item); pCheckBox->setTag(item->getTag()); pCheckBox->setToggle(false); pCheckBox->setTarget(this, cccontrol_selector(GamePan::wordSelectCallbackCCControl)); tabNode->addChild(pCheckBox); item->removeFromParent(); } } itemTemp->removeFromParent(); tabItem->removeFromParent(); refreshLetter(); }
void QuestionLayer::displaySubViews() { CCLOG("%f %f %f %f", this->getPositionX(), this->getPositionY(), this->getContentSize().width, this->getContentSize().height); CCArray* answer = questionObj->answerArray; int columns = 0; int rows = 0; float spaceX = 0; if (answer->count() <= 2) { //判断题2X1个 columns = 2; rows = 1; spaceX = 80; } else if (answer->count() <= 3) { //3选1 columns = 1; rows = 3; spaceX = 40; } else if (answer->count() <= 4) { //最多2x2个答案选项的 columns = 2; rows = (answer->count()*1.0f/columns)>(answer->count()/columns)?(answer->count()/columns+1):(answer->count()/columns); spaceX = 60; } else if (answer->count() <= 9) { //最多3x3个答案选项 columns = 3; rows = (answer->count()*1.0f/columns)>(answer->count()/columns)?(answer->count()/columns+1):(answer->count()/columns); spaceX = 40; } else if (answer->count() <= 16) { //最多4x4个答案选项 columns = 4; rows = (answer->count()*1.0f/columns)>(answer->count()/columns)?(answer->count()/columns+1):(answer->count()/columns); spaceX = 20; } float spaceY = spaceX*(CCDirector::sharedDirector()->getWinSize().height/1334); //题目标题栏高度 float topHeight = 190; CCLOG("%f %f", this->getContentSize().width, this->getContentSize().height); // float totalWidth = this->getContentSize().width; float cellWidth = (totalWidth-spaceX*(columns+1))/columns; float totalHeight = this->getContentSize().height-topHeight-50; //要减去答题头部区域 float cellHeight = (totalHeight-spaceY*(rows+1))/rows; CCLOG("[%d %d]:%f %f", columns, rows, cellWidth, cellHeight); while (cellHeight > cellWidth) { spaceY += 10; cellHeight = (totalHeight-spaceY*(rows+1))/rows; } for (int i=0; i<answer->count(); i++) { // CCString* ans = (CCString *)(answer->objectAtIndex(i)); CCLabelTTF* pLabel = CCLabelTTF::create(ans->getCString(), "Arial", 24, CCSizeMake(cellWidth, cellHeight), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); CCControlButton* button = CCControlButton::create(pLabel, CCScale9Sprite::create("button_answer.png", CCRectMake(0, 0, 126, 70))); button->addTargetWithActionForControlEvents(this, cccontrol_selector(QuestionLayer::touchDownAction), CCControlEventTouchUpInside); button->setTag(i+1); button->setAnchorPoint(ccp(0.5f, 0.5f)); // button->setPosition( ccp(-totalWidth/2+spaceX+(cellWidth+spaceX)*(i%columns)+cellWidth/2, -topHeight/2-totalHeight/2+spaceY+(cellHeight+spaceY)*(i/columns)+cellHeight/2) ); button->setPosition( ccp(-totalWidth/2+spaceX+(cellWidth+spaceX)*(i%columns)+cellWidth/2, (totalHeight-topHeight)/2-spaceY-(cellHeight+spaceY)*(i/columns)-cellHeight/2) ); CCLOG("button坐标:%f %f", button->getPositionX(), button->getPositionY()); button->setPreferredSize(CCSize(cellWidth, cellHeight)); this->addChild(button, 1); } }