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; }
void RequestList::useItem(CCObject* pSender) { if (pSender == NULL) { return; } CCMenuItemImage* sender = (CCMenuItemImage*)pSender; CCLOG("Call for useItem for tag = %d", sender->getTag()); if (sender->getTag() > _fbIncomingRequestList->count()) { return; } std::string messageToDisplay = ""; EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(sender->getTag()); if (fbRequest->isConsumed()) { CCMessageBox("This item is already consumed.", "Consume Item Status"); return; } EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType(); const char* senderName = fbRequest->getSender()->getName(); const char* requestTypeChar = ""; const char* message = ""; message = fbRequest->getMessage(); CCDictionary* giftDictionary = fbRequest->getDataDictionary(); switch (requestType) { case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE: requestTypeChar = "Invite"; break; case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT: requestTypeChar = "Gift"; break; case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE: requestTypeChar = "Challenge"; break; default: requestTypeChar = "Unknown"; break; } // Add the request Type messageToDisplay.append("Request Type = ").append(requestTypeChar).append("\n"); // Add the sender Name messageToDisplay.append("Sender = ").append(senderName).append("\n"); // Add the message. messageToDisplay.append("Message = ").append(message).append("\n"); if (giftDictionary && giftDictionary->count()>0) { CCArray* allKeys = giftDictionary->allKeys(); if (allKeys && allKeys->count() > 0) { messageToDisplay.append("Extra/Gift items sent:\n"); for (int i=0; i<allKeys->count(); i++) { CCString* key = (CCString*)allKeys->objectAtIndex(i); CCString* value = (CCString*)giftDictionary->objectForKey(key->getCString()); messageToDisplay.append(key->getCString()).append(": ").append(value->getCString()).append("\n"); } } } else { messageToDisplay.append("No Extra Items were sent by sender"); } CCMessageBox(messageToDisplay.c_str(), "Item Consumed!!! :)))"); EziFBIncomingRequestManager::sharedManager()->consumeItem(fbRequest); CCScene *pScene = CCScene::create(); RequestList *pLayer = RequestList::create(); pScene->addChild(pLayer); CCDirector::sharedDirector()->replaceScene(pScene); }
void RequestList::tableCellTouched(CCTableView *table, CCTableViewCell *cell) { CCLOG("cell touched at index: %i", cell->getIdx()); std::string messageToDisplay = ""; EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(cell->getIdx()); EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType(); const char* senderName = fbRequest->getSender()->getName(); const char* requestTypeChar = ""; const char* message = ""; message = fbRequest->getMessage(); CCDictionary* giftDictionary = fbRequest->getDataDictionary(); switch (requestType) { case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE: requestTypeChar = "Invite"; break; case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT: requestTypeChar = "Gift"; break; case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE: requestTypeChar = "Challenge"; break; default: requestTypeChar = "Unknown"; break; } // Add the request Type messageToDisplay.append("Request Type = ").append(requestTypeChar).append("\n"); // Add the sender Name messageToDisplay.append("Sender = ").append(senderName).append("\n"); // Add the message. messageToDisplay.append("Message = ").append(message).append("\n"); if (giftDictionary && giftDictionary->count()>0) { CCArray* allKeys = giftDictionary->allKeys(); if (allKeys && allKeys->count() > 0) { messageToDisplay.append("Extra/Gift items sent:\n"); for (int i=0; i<allKeys->count(); i++) { CCString* key = (CCString*)allKeys->objectAtIndex(i); CCString* value = (CCString*)giftDictionary->objectForKey(key->getCString()); messageToDisplay.append(key->getCString()).append(": ").append(value->getCString()).append("\n"); } } } else { messageToDisplay.append("No Extra Items were sent by sender"); } CCMessageBox(messageToDisplay.c_str(), "Request Details"); }