RUBulldogMapIconAdLayer.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // BulldogMapIconAdLayer.cpp
  3. // BubbleShoot
  4. //
  5. // Created by 刘玉涛 on 17/9/1.
  6. //
  7. //
  8. #include "RUBulldogMapIconAdLayer.h"
  9. #include "BulldogIconAdController.h"
  10. #include "RedAdLayerController.h"
  11. #include "BulldogIconLayer.h"
  12. NS_RU_BEGIN
  13. BulldogMapIconAdLayer * BulldogMapIconAdLayer::Layer(){
  14. redream::NodeLoaderLibrary *lib = redream::NodeLoaderLibrary::newDefaultNodeLoaderLibrary();
  15. lib->registerNodeLoader("BulldogMapIconAdLayer", BulldogMapIconAdLayerLoader::loader());
  16. redream::REDReader *reader = new(std::nothrow) redream::REDReader(lib);
  17. reader->autorelease();
  18. BulldogMapIconAdLayer * node = (BulldogMapIconAdLayer*)reader->readNodeGraphFromFile("BulldogMapIconAdLayer.redream");
  19. return node;
  20. }
  21. bool BulldogMapIconAdLayer::onAssignREDMemberVariable(Ref* pTarget, const char* pMemberVariableName, Node* pNode){
  22. // RED_MEMBERVARIABLEASSIGNER_GLUE_WEAK(this, "btnClose", ControlButton*, BulldogMapIconAdLayer::btnClose);
  23. RED_MEMBERVARIABLEASSIGNER_GLUE_WEAK(this, "btnOpen", ControlButton*, BulldogMapIconAdLayer::btnOpen);
  24. RED_MEMBERVARIABLEASSIGNER_GLUE_WEAK(this, "nodeIconAd", cocos2d::Node*, BulldogMapIconAdLayer::nodeIconAd);
  25. return false;
  26. }
  27. SEL_MenuHandler BulldogMapIconAdLayer::onResolveREDCCMenuItemSelector(Ref * pTarget, const char* pSelectorName){return nullptr;}
  28. cocos2d::extension::Control::Handler BulldogMapIconAdLayer::onResolveREDCCControlSelector(cocos2d::Ref * pTarget, const char* pSelectorName){
  29. RED_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onOpenClick", BulldogMapIconAdLayer::onOpenClick);
  30. // RED_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCloseClick", BulldogMapIconAdLayer::onCloseClick);
  31. return NULL;
  32. }
  33. void BulldogMapIconAdLayer::setAnimationManager(redream::REDAnimationManager* mgr){
  34. CC_SAFE_RELEASE_NULL(this->amgr);
  35. this->amgr = mgr;
  36. amgr->setDelegate(this);
  37. CC_SAFE_RETAIN(this->amgr);
  38. }
  39. void BulldogMapIconAdLayer::setContent(){
  40. }
  41. void BulldogMapIconAdLayer::completedAnimationSequenceNamed(const char *name, int seqId,int tag){
  42. // if(strcmp(name, "close") == 0){
  43. //
  44. // removeFromParent();
  45. //
  46. // }
  47. }
  48. void BulldogMapIconAdLayer::onNodeLoaded(Node * pNode, redream::NodeLoader * pNodeLoader){
  49. // PFCloseTouch(this);
  50. // if(layerWrapper){
  51. // CoreFunc::SmartScaleHeightNoContentSize(layerWrapper);
  52. // }
  53. // setLocalZOrder(999999);
  54. // setGlobalZOrder(999999);
  55. // removeFromParentAndCleanup(false);
  56. // Director::getInstance()->getRunningScene()->addChild(this, 999999);
  57. // EventListenerTouchOneByOne* listen = EventListenerTouchOneByOne::create();
  58. // listen->setSwallowTouches(true);
  59. // listen->onTouchBegan = CC_CALLBACK_2(BrickGameLayer::onTouchBegan, this);
  60. // listen->onTouchMoved = CC_CALLBACK_2(BrickGameLayer::onTouchMoved, this);
  61. // listen->onTouchEnded = CC_CALLBACK_2(BrickGameLayer::onTouchEnded, this);
  62. // _bulldogAdsMaplisten = EventListenerTouchOneByOne::create();
  63. // auto callback = [this](Touch * touch,Event *)
  64. // {
  65. //
  66. //// CCLOG("MapIconAd_touch:%f,%f",touch->getLocation().x,touch->getLocation().y);
  67. // Vec2 point = convertTouchToNodeSpace(touch);
  68. //// CCLOG("MapIconAd_point:%f,%f",point.x,point.y);
  69. // if(point.x<0 || point.y<0 || point.x>getContentSize().width || point.y>getContentSize().height){
  70. // return false;
  71. // }
  72. //
  73. // RedAdLayerController::getInstance()->openIconAdLayer();
  74. //
  75. // return true;
  76. // };
  77. // _bulldogAdsMaplisten->onTouchBegan = callback;
  78. // _bulldogAdsMaplisten->setSwallowTouches(true);
  79. //// Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listen, this);
  80. // Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_bulldogAdsMaplisten, -999999);
  81. }
  82. void BulldogMapIconAdLayer::onOpenClick(Ref * pSender,cocos2d::extension::Control::EventType pEvent){
  83. // BulldogAd* ad = BulldogIconAdController::getInstance()->getBulldogAd();
  84. // int index = BulldogIconAdController::getInstance()->getCurShowAdIndex();
  85. RedAdLayerController::getInstance()->openIconAdLayer();
  86. }
  87. //void BulldogMapIconAdLayer::onCloseClick(Ref * pSender,cocos2d::extension::Control::EventType pEvent){
  88. //// btnClose->setEnabled(false);
  89. //// amgr->runAnimationsForSequenceNamed("close");
  90. ////
  91. //// RedAdLayerController::getInstance()->closeInterstitial();
  92. //// Sound::Shared()->resumeBackgroundMusic();
  93. //
  94. //
  95. //}
  96. void BulldogMapIconAdLayer::onExit() {
  97. Layer::onExit();
  98. amgr->setDelegate(NULL);
  99. }
  100. void BulldogMapIconAdLayer::onEnter(){
  101. Layer::onEnter();
  102. Ref* obj = this->getUserObject();
  103. redream::REDAnimationManager * ret = dynamic_cast<redream::REDAnimationManager*>(obj);
  104. setAnimationManager(ret);
  105. setContent();
  106. IconCcbiPathData iconData = BulldogIconAdController::getInstance()->getNextIconPath();
  107. if(iconData.plistPath==""){
  108. setVisible(false);
  109. return;
  110. }
  111. SpriteFrameCache::getInstance()->addSpriteFramesWithFile(iconData.plistPath);
  112. BulldogIconLayer* bulldogIconLayer = BulldogIconLayer::Layer(iconData.ccbiPath);
  113. if(bulldogIconLayer==nullptr){
  114. setVisible(false);
  115. return;
  116. }
  117. nodeIconAd->removeAllChildren();
  118. bulldogIconLayer->toParentLayer(nodeIconAd);
  119. setVisible(true);
  120. }
  121. BulldogMapIconAdLayer::~BulldogMapIconAdLayer()
  122. {
  123. // Director::getInstance()->getEventDispatcher()->removeEventListener(_bulldogAdsMaplisten);
  124. CC_SAFE_RELEASE_NULL(this->amgr);
  125. }
  126. BulldogMapIconAdLayer::BulldogMapIconAdLayer()
  127. {
  128. amgr = NULL;
  129. _bulldogAdsMaplisten = nullptr;
  130. }
  131. NS_RU_END