RUBulldogGameOverIconAdLayer.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //
  2. // BulldogGameOverIconAdLayer.cpp
  3. // BubbleShoot
  4. //
  5. // Created by 刘玉涛 on 17/9/1.
  6. //
  7. //
  8. #include "RUBulldogGameOverIconAdLayer.h"
  9. #include "RUBulldogGameOverIconAdCell.h"
  10. #include "BulldogTableViewAdController.h"
  11. #include "RedAdLayerController.h"
  12. #include "BulldogTool.h"
  13. NS_RU_BEGIN
  14. BulldogGameOverIconAdLayer * BulldogGameOverIconAdLayer::Layer(){
  15. redream::NodeLoaderLibrary *lib = redream::NodeLoaderLibrary::newDefaultNodeLoaderLibrary();
  16. lib->registerNodeLoader("BulldogGameOverIconAdLayer", BulldogGameOverIconAdLayerLoader::loader());
  17. redream::REDReader *reader = new(std::nothrow) redream::REDReader(lib);
  18. reader->autorelease();
  19. BulldogGameOverIconAdLayer * node = (BulldogGameOverIconAdLayer*)reader->readNodeGraphFromFile("BulldogGameOverIconAdLayer.redream");
  20. return node;
  21. }
  22. bool BulldogGameOverIconAdLayer::onAssignREDMemberVariable(Ref* pTarget, const char* pMemberVariableName, Node* pNode){
  23. RED_MEMBERVARIABLEASSIGNER_GLUE_WEAK(this, "nodeSlide", Node*, BulldogGameOverIconAdLayer::nodeSlide);
  24. return false;
  25. }
  26. SEL_MenuHandler BulldogGameOverIconAdLayer::onResolveREDCCMenuItemSelector(Ref * pTarget, const char* pSelectorName){return nullptr;}
  27. cocos2d::extension::Control::Handler BulldogGameOverIconAdLayer::onResolveREDCCControlSelector(cocos2d::Ref * pTarget, const char* pSelectorName){
  28. RED_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onUrlClick", BulldogGameOverIconAdLayer::onUrlClick);
  29. return NULL;
  30. }
  31. void BulldogGameOverIconAdLayer::setAnimationManager(redream::REDAnimationManager* mgr){
  32. CC_SAFE_RELEASE_NULL(this->amgr);
  33. this->amgr = mgr;
  34. amgr->setDelegate(this);
  35. CC_SAFE_RETAIN(this->amgr);
  36. }
  37. void BulldogGameOverIconAdLayer::setContent(){
  38. mIconAdCellVector.clear();
  39. BulldogAd* ad = BulldogTableViewAdController::getInstance()->getBulldog();
  40. if(ad==nullptr){
  41. return;
  42. }
  43. ad->updateIconCcbiPathArray();
  44. vector<IconCcbiPathData> iconPathDataVector = ad->getIconCcbiPathArray();
  45. if(iconPathDataVector.size()==0){
  46. setVisible(false);
  47. return;
  48. }
  49. setVisible(true);
  50. //初始化广告
  51. for (int i=0; i<iconPathDataVector.size(); i++) {
  52. BulldogGameOverIconAdCell* adCell = BulldogGameOverIconAdCell::Layer();
  53. IconCcbiPathData iconPathData = iconPathDataVector.at(i);
  54. SpriteFrameCache::getInstance()->addSpriteFramesWithFile(iconPathData.plistPath);
  55. string path = iconPathData.ccbiPath;
  56. adCell->setContent(path);
  57. mIconAdCellVector.pushBack(adCell);
  58. }
  59. BulldogGameOverIconAdCell* cell = mIconAdCellVector.at(0);
  60. if(cell){
  61. mCellSize = Size(cell->getContentSize());
  62. }
  63. mMaxIconAdCellNum = mIconAdCellVector.size();
  64. TableView* tableView = TableView::create(this, nodeSlide->getContentSize());
  65. tableView->setDirection(ScrollView::Direction::HORIZONTAL);
  66. tableView->setDelegate(this);
  67. nodeSlide->addChild(tableView);
  68. tableView->reloadData();
  69. int offsetW = mCellSize.width * mMaxIconAdCellNum;
  70. tableView->setContentOffset(Vec2(-offsetW,0));
  71. float baseValue = 0.3f;
  72. float time = 0;
  73. for(int i=1;i<=mMaxIconAdCellNum;i++){
  74. time += baseValue/i;
  75. }
  76. tableView->setContentOffsetInDuration(Vec2(0,0),time);
  77. }
  78. void BulldogGameOverIconAdLayer::completedAnimationSequenceNamed(const char *name, int seqId,int tag){
  79. if(strcmp(name, "close") == 0){
  80. removeFromParent();
  81. }
  82. }
  83. void BulldogGameOverIconAdLayer::onNodeLoaded(Node * pNode, redream::NodeLoader * pNodeLoader){
  84. setKeyboardEnabled(true);
  85. }
  86. void BulldogGameOverIconAdLayer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
  87. {
  88. switch(keyCode)
  89. {
  90. //监听返回键
  91. case EventKeyboard::KeyCode::KEY_ESCAPE:
  92. event->stopPropagation();
  93. break;
  94. //监听menu键
  95. case EventKeyboard::KeyCode::KEY_MENU:
  96. break;
  97. }
  98. }
  99. void BulldogGameOverIconAdLayer::scrollViewDidScroll(cocos2d::extension::ScrollView* view)
  100. {
  101. }
  102. void BulldogGameOverIconAdLayer::scrollViewDidZoom(cocos2d::extension::ScrollView* view) {
  103. }
  104. void BulldogGameOverIconAdLayer::tableCellTouched(cocos2d::extension::TableView* table, cocos2d::extension::TableViewCell* cell){
  105. RedAdLayerController::getInstance()->openTableViewAdLayer(cell->getIdx());
  106. }
  107. cocos2d::Size BulldogGameOverIconAdLayer::tableCellSizeForIndex(cocos2d::extension::TableView *table, ssize_t idx){
  108. return mCellSize;
  109. }
  110. TableViewCell* BulldogGameOverIconAdLayer::tableCellAtIndex(TableView *table, ssize_t idx){
  111. TableViewCell *cell = table->dequeueCell();
  112. cell = mIconAdCellVector.at(idx);
  113. return cell;
  114. }
  115. ssize_t BulldogGameOverIconAdLayer::numberOfCellsInTableView(cocos2d::extension::TableView *table){
  116. return mMaxIconAdCellNum;
  117. }
  118. void BulldogGameOverIconAdLayer::onUrlClick(Ref * pSender,cocos2d::extension::Control::EventType pEvent){
  119. BulldogTool::getInstance()->openBulldogCpiUrl();
  120. }
  121. void BulldogGameOverIconAdLayer::onExit() {
  122. Layer::onExit();
  123. amgr->setDelegate(NULL);
  124. }
  125. void BulldogGameOverIconAdLayer::onEnter(){
  126. Layer::onEnter();
  127. Ref* obj = this->getUserObject();
  128. redream::REDAnimationManager * ret = dynamic_cast<redream::REDAnimationManager*>(obj);
  129. setAnimationManager(ret);
  130. setContent();
  131. }
  132. BulldogGameOverIconAdLayer::~BulldogGameOverIconAdLayer(){
  133. CC_SAFE_RELEASE_NULL(this->amgr);
  134. mIconAdCellVector.clear();
  135. }
  136. BulldogGameOverIconAdLayer::BulldogGameOverIconAdLayer()
  137. :amgr(NULL)
  138. {
  139. amgr = NULL;
  140. }
  141. NS_RU_END