CCTableViewCell* RequestList::tableCellAtIndex(CCTableView *table, unsigned int idx) { int index = idx; EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(index); EziFacebookFriend* sender = fbRequest->getSender(); const char* senderName = sender->getName(); // Create the fancy test. EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType(); std::string messageToDisplay = ""; switch (requestType) { case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE: messageToDisplay.append(senderName).append(" has sent invitation to you."); break; case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT: messageToDisplay.append(senderName).append(" has sent gift to you."); break; case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE: messageToDisplay.append(senderName).append(" has challenged to you."); break; default: messageToDisplay.append("Unknown message"); break; } // Means users have already used this request. bool requestConsumed = fbRequest->isConsumed(); CCSprite* profilePic = NULL; ccColor4B bgColor = ccc4(20, 0, 40, 255); if (requestConsumed == false) { bgColor = ccc4(50, 50, 20, 255); } // Build the table cell. CCTableViewCell *cell = table->dequeueCell(); if (cell == NULL) { cell = new CCTableViewCell(); cell->autorelease(); // Create the back layer of the cell. CCLayerColor* colorLayer = CCLayerColor::create(bgColor, SCREEN_WIDTH, CELL_HEIGHT); colorLayer->setTag(BACKGROUND_TAG); cell->addChild(colorLayer); // Get the sender profile picture path. Create it if path is available. if (sender != NULL && strcmp(sender->getPhotoPath(), "") != 0) { const char* picPath = sender->getPhotoPath(); profilePic = CCSprite::create(picPath); } else { profilePic = CCSprite::create(FB_DEFAULT_PHOTO); } // Add the profile pic to the cell row. profilePic->setAnchorPoint(ccp(0, 0.5)); profilePic->setPosition(ccp(20, CELL_HEIGHT/2)); cell->addChild(profilePic); profilePic->setTag(FRIEND_PHOTO_TAG); // Set the message. CCLabelTTF *messageLabel = CCLabelTTF::create(messageToDisplay.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE); messageLabel->setAnchorPoint(ccp(0, 0.5)); messageLabel->setPosition(ccp(20 + 20 + profilePic->getContentSize().width, CELL_HEIGHT/2)); messageLabel->setTag(REQUEST_MESSAGE_LABEL_TAG); messageLabel->setDimensions(CCSizeMake(SCREEN_WIDTH - (profilePic->getContentSize().width * 2) - 60, CELL_HEIGHT-5)); messageLabel->setHorizontalAlignment(kCCTextAlignmentLeft); cell->addChild(messageLabel); CCMenuItemImage* constumeItemButton = NULL; constumeItemButton = CCMenuItemImage::create("use.png", "use_pressed.png"); constumeItemButton->setTag(idx); constumeItemButton->setTarget(this, menu_selector(RequestList::useItem)); constumeItemButton->setScale(SCALE_FACTOR * 0.8); constumeItemButton->setTag(FRIEND_CONSUME_BUTTON_TAG); CCMenu* consumeMenu = CCMenu::create(constumeItemButton, NULL); consumeMenu->setTag(FRIEND_CONSUME_MENU_TAG); consumeMenu->setPosition(ccp(SCREEN_WIDTH - (constumeItemButton->getContentSize().width*SCALE_FACTOR*0.4), (CELL_HEIGHT - (constumeItemButton->getContentSize().height)*SCALE_FACTOR*0.4))); cell->addChild(consumeMenu); } else { // Refresh the cell data based upon idx. // 1. Refresh the profile picture. CCSprite* cellProfilePic = (CCSprite*)cell->getChildByTag(FRIEND_PHOTO_TAG); if (strcmp("", sender->getPhotoPath()) != 0 ) { const char* picPath = sender->getPhotoPath(); profilePic = CCSprite::create(picPath); } else { profilePic = CCSprite::create(FB_DEFAULT_PHOTO); } cellProfilePic->setTexture(profilePic->getTexture()); // Update the message Label. CCLabelTTF *messageLabel = (CCLabelTTF*)cell->getChildByTag(REQUEST_MESSAGE_LABEL_TAG); messageLabel->setString(messageToDisplay.c_str()); CCMenu* consumeMenu = (CCMenu*)cell->getChildByTag(FRIEND_CONSUME_MENU_TAG); CCArray* children = consumeMenu->getChildren(); if (children) { CCMenuItemImage* consumenButton = (CCMenuItemImage*)children->objectAtIndex(0); if (consumenButton) { consumenButton->setTag(index); } else { CCLOG("No Consume Button"); } } CCLayerColor* bgLayer = (CCLayerColor*)cell->getChildByTag(BACKGROUND_TAG); bgLayer->setColor(ccc3(bgColor.r, bgColor.g, bgColor.b)); } return cell; }
CCTableViewCell* FriendList::tableCellAtIndex(CCTableView *table, unsigned int idx) { EziFacebookFriend* friendDetails = (EziFacebookFriend*)mFriendList->objectAtIndex(idx); std::string friendID = friendDetails->getFBID(); std::string friendName = friendDetails->getName(); std::string installed = ""; std::string score = ""; CCSprite* profilePic = NULL; // Set the score. long mylong = friendDetails->getScore(); std::stringstream mystream; mystream << mylong; score = mystream.str(); // Set the install status if (friendDetails->isInstalled()) { installed = "Installed"; } else { installed = "Not Installed"; } CCTableViewCell *cell = table->dequeueCell(); if (!cell) // Creation of Cell. { cell = new CCTableViewCell(); cell->autorelease(); CCLayerColor* colorLayer = CCLayerColor::create(ccc4(20, 0, 40, 255), SCREEN_WIDTH, CELL_HEIGHT); cell->addChild(colorLayer); CCSprite *sprite = NULL; if (strcmp(friendDetails->getPhotoPath(), "") != 0) { const char* picPath = friendDetails->getPhotoPath(); sprite = CCSprite::create(picPath); } else { sprite = CCSprite::create(FB_DEFAULT_PHOTO); } if (sprite == NULL) { CCLOG("Sprite is NULL"); } sprite->setAnchorPoint(ccp(0, 0.5)); sprite->setPosition(ccp(20, CELL_HEIGHT/2)); cell->addChild(sprite); //sprite->setScale(0.9); sprite->setTag(FRIEND_PHOTO_TAG); // Friend Facebook ID CCLabelTTF *friendIDLabel = CCLabelTTF::create(friendID.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE); float gapY = (CELL_HEIGHT - (friendIDLabel->getContentSize().height * 2)) / 3; if (sprite) { friendIDLabel->setPosition(ccp(sprite->getPositionX() + sprite->getContentSize().width + 20, CELL_HEIGHT - gapY)); } friendIDLabel->setAnchorPoint(ccp(0, 1)); friendIDLabel->setTag(FRIEND_ID_LABEL_TAG); cell->addChild(friendIDLabel); // Friend Facebook Name CCLabelTTF *friendNameLabel = CCLabelTTF::create(friendName.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE); friendNameLabel->setPosition(ccp(friendIDLabel->getPositionX(), friendIDLabel->getPositionY() - friendIDLabel->getContentSize().height - gapY)); friendNameLabel->setAnchorPoint(ccp(0, 1)); friendNameLabel->setTag(FRIEND_NAME_LABEL_TAG); cell->addChild(friendNameLabel); // High Score CCLabelTTF *scoreLabel = CCLabelTTF::create(score.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE); scoreLabel->setPosition(ccp(SCREEN_WIDTH - 20, friendIDLabel->getPositionY())); scoreLabel->setAnchorPoint(ccp(1, 1)); scoreLabel->setTag(FRIEND_SCORE_LABEL_TAG); cell->addChild(scoreLabel); // Installed String CCLabelTTF *installedLabel = CCLabelTTF::create(installed.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE); installedLabel->setPosition(ccp(SCREEN_WIDTH - 20, friendNameLabel->getPositionY())); installedLabel->setAnchorPoint(ccp(1, 1)); installedLabel->setTag(FRIEND_INSTALLED_LABEL_TAG); cell->addChild(installedLabel); } else { // Set the Friend ID CCLabelTTF *friendIDLabel = (CCLabelTTF*)cell->getChildByTag(FRIEND_ID_LABEL_TAG); friendIDLabel->setString(friendID.c_str()); // Set the Friend Name CCLabelTTF *friendNameLabel = (CCLabelTTF*)cell->getChildByTag(FRIEND_NAME_LABEL_TAG); friendNameLabel->setString(friendName.c_str()); CCLabelTTF *highScoreLabel = (CCLabelTTF*)cell->getChildByTag(FRIEND_SCORE_LABEL_TAG); if (highScoreLabel != NULL) { highScoreLabel->setString(score.c_str()); } highScoreLabel->setVisible(mEnableHighScoreDisplay); CCLabelTTF *installedLabel = (CCLabelTTF*)cell->getChildByTag(FRIEND_INSTALLED_LABEL_TAG); if (installedLabel != NULL) { installedLabel->setString(installed.c_str()); } installedLabel->setVisible(mEnableInstalledDisplay); CCSprite* cellProfilePic = (CCSprite*)cell->getChildByTag(FRIEND_PHOTO_TAG); if (strcmp("", friendDetails->getPhotoPath()) != 0 ) { const char* picPath = friendDetails->getPhotoPath(); profilePic = CCSprite::create(picPath); } else { profilePic = CCSprite::create(FB_DEFAULT_PHOTO); } cellProfilePic->setTexture(profilePic->getTexture()); } return cell; }