void FriendListScene::fbFriendsCallback(int responseCode, const char *responseMessage, std::vector<EziFacebookFriend*> friends) { MessageBox(responseMessage, "Friends Callback"); // Empty the current friend list & dictionary. _friendList.clear(); _friendDictionary.clear(); _friendList.swap(friends); int totalFriends = _friendList.size()-1; _downloadCount = 0; for (int i=totalFriends; i >= 0; i--) { EziFacebookFriend* myFriend = (EziFacebookFriend*)_friendList.at(i); CCLOG("%d. %s", i+1, myFriend->getProfileID().c_str()); //_friendDictionary.insert("ABC", "ABC"); _friendDictionary.insert(myFriend->getProfileID(), myFriend); myFriend->getPhoto(CC_CALLBACK_2(FriendListScene::applyPhoto, this), false, SCALED_VALUE(85.0f), SCALED_VALUE(85.0f)); //EziSocialObject::sharedObject()->getProfilePicForID(this, myFriend->getProfileID().c_str(), SCALED_VALUE(85.0f), SCALED_VALUE(85.0f), false); } _tableView->reloadData(); }
TableViewCell* FriendListScene::tableCellAtIndex(TableView *table, ssize_t idx) { int index = idx; EziFacebookFriend* myFriend = (EziFacebookFriend*)_friendList.at(index); std::string friendName = myFriend->getName(); //const char* photoPath = myFriend->getPhotoPath().c_str(); bool toRequestForPhoto = false; if (myFriend->getPhoto() == nullptr) { toRequestForPhoto = true; //EziSocialObject::sharedObject()->getProfilePicForID(this, myFriend->getFBID(), SCALED_VALUE(85.0f), SCALED_VALUE(85.0f), false); } // Build the table cell. TableViewCell *cell = table->cellAtIndex(idx); if (cell == NULL) { cell = new TableViewCell(); cell->autorelease(); LayerColor* colorLayer = LayerColor::create(Color4B(100, 100, 100, 200), AppDelegate::SCREEN_WIDTH - SCALED_VALUE(20.0f), SCALED_VALUE(124.0f)); //cell->addChild(colorLayer); LayerColor* photoLayer = LayerColor::create(Color4B(255, 255, 255, 255), SCALED_VALUE(100.0f), SCALED_VALUE(100.0f)); photoLayer->setPosition(SCALED_VALUE(40.0f), SCALED_VALUE(12.0f)); cell->addChild(photoLayer); Sprite* userPhotoSprite = NULL; if (toRequestForPhoto) { userPhotoSprite = Sprite::create(); userPhotoSprite->setContentSize(Size(SCALED_VALUE(85.0f), SCALED_VALUE(85.0f))); } else { userPhotoSprite = myFriend->getPhoto(CC_CALLBACK_2(FriendListScene::applyPhoto, this), false, SCALED_VALUE(85.0f), SCALED_VALUE(85.0f)); if (userPhotoSprite == nullptr) { userPhotoSprite = Sprite::create(); } } cell->addChild(userPhotoSprite); userPhotoSprite->setAnchorPoint(Point(0.0f, 0.0)); userPhotoSprite->cocos2d::CCNode::setPosition(SCALED_VALUE(47.0f), SCALED_VALUE(18.0f)); userPhotoSprite->setTag(TAG_PHOTO); auto message = LabelTTF::create(friendName.c_str(), "Arial", SCALED_VALUE(30.0f)); message->setAnchorPoint(Point(0, 0.5)); message->setPosition(Point(photoLayer->getContentSize().width + photoLayer->getPositionX() + SCALED_VALUE(20.0f), colorLayer->getContentSize().height/2)); cell->addChild(message); message->setTag(TAG_MESSAGE); /* Sprite* consumedIcon = Sprite::createWithSpriteFrameName("green_tick"); consumedIcon->setAnchorPoint(Point(1.0, 0.5)); cell->addChild(consumedIcon); consumedIcon->setPosition(Point(colorLayer->getContentSize().width - SCALED_VALUE(20.0f), colorLayer->getContentSize().height/2)); message->setTag(TAG_CONSUMED_ICON); MenuItemImage* useButton = MenuItemImage::create(); useButton->setSelectedSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_use_prd")); useButton->setNormalSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("btn_use_nrl")); useButton->setAnchorPoint(Point(1.0, 0.5)); useButton->setTarget(this, menu_selector(FriendListScene::useRequest)); Menu* useMenu = Menu::create(useButton, NULL); cell->addChild(useMenu); useMenu->setPosition(Point(colorLayer->getContentSize().width - SCALED_VALUE(20.0f), colorLayer->getContentSize().height/2)); useButton->setTag(index); useMenu->setTag(TAG_USE_MENU); */ } else { Sprite* cellProfilePic = (Sprite*)cell->getChildByTag(TAG_PHOTO); if (toRequestForPhoto == false) { //cellProfilePic->setTexture(Sprite::create(myFriend->getPhotoPath())->getTexture()); Sprite* tempSprite = myFriend->getPhoto(); if (myFriend->getPhoto() != nullptr) { cellProfilePic->setTexture(tempSprite->getTexture()); } else { myFriend->getPhoto(CC_CALLBACK_2(FriendListScene::applyPhoto, this), false, SCALED_VALUE(85.0f), SCALED_VALUE(85.0f)); } } // Update the message Label. auto messageLabel = (LabelTTF*)cell->getChildByTag(TAG_MESSAGE); CCLOG("Friend Name = %s", friendName.c_str()); if (messageLabel) { messageLabel->setString(friendName.c_str()); } } return cell; }