// // BulldogMapIconAdLayer.cpp // BubbleShoot // // Created by 刘玉涛 on 17/9/1. // // #include "RUBulldogMapIconAdLayer.h" #include "BulldogIconAdController.h" #include "RedAdLayerController.h" #include "BulldogIconLayer.h" NS_RU_BEGIN BulldogMapIconAdLayer * BulldogMapIconAdLayer::Layer(){ redream::NodeLoaderLibrary *lib = redream::NodeLoaderLibrary::newDefaultNodeLoaderLibrary(); lib->registerNodeLoader("BulldogMapIconAdLayer", BulldogMapIconAdLayerLoader::loader()); redream::REDReader *reader = new(std::nothrow) redream::REDReader(lib); reader->autorelease(); BulldogMapIconAdLayer * node = (BulldogMapIconAdLayer*)reader->readNodeGraphFromFile("BulldogMapIconAdLayer.redream"); return node; } bool BulldogMapIconAdLayer::onAssignREDMemberVariable(Ref* pTarget, const char* pMemberVariableName, Node* pNode){ // RED_MEMBERVARIABLEASSIGNER_GLUE_WEAK(this, "btnClose", ControlButton*, BulldogMapIconAdLayer::btnClose); RED_MEMBERVARIABLEASSIGNER_GLUE_WEAK(this, "btnOpen", ControlButton*, BulldogMapIconAdLayer::btnOpen); RED_MEMBERVARIABLEASSIGNER_GLUE_WEAK(this, "nodeIconAd", cocos2d::Node*, BulldogMapIconAdLayer::nodeIconAd); return false; } SEL_MenuHandler BulldogMapIconAdLayer::onResolveREDCCMenuItemSelector(Ref * pTarget, const char* pSelectorName){return nullptr;} cocos2d::extension::Control::Handler BulldogMapIconAdLayer::onResolveREDCCControlSelector(cocos2d::Ref * pTarget, const char* pSelectorName){ RED_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onOpenClick", BulldogMapIconAdLayer::onOpenClick); // RED_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCloseClick", BulldogMapIconAdLayer::onCloseClick); return NULL; } void BulldogMapIconAdLayer::setAnimationManager(redream::REDAnimationManager* mgr){ CC_SAFE_RELEASE_NULL(this->amgr); this->amgr = mgr; amgr->setDelegate(this); CC_SAFE_RETAIN(this->amgr); } void BulldogMapIconAdLayer::setContent(){ } void BulldogMapIconAdLayer::completedAnimationSequenceNamed(const char *name, int seqId,int tag){ // if(strcmp(name, "close") == 0){ // // removeFromParent(); // // } } void BulldogMapIconAdLayer::onNodeLoaded(Node * pNode, redream::NodeLoader * pNodeLoader){ // PFCloseTouch(this); // if(layerWrapper){ // CoreFunc::SmartScaleHeightNoContentSize(layerWrapper); // } // setLocalZOrder(999999); // setGlobalZOrder(999999); // removeFromParentAndCleanup(false); // Director::getInstance()->getRunningScene()->addChild(this, 999999); // EventListenerTouchOneByOne* listen = EventListenerTouchOneByOne::create(); // listen->setSwallowTouches(true); // listen->onTouchBegan = CC_CALLBACK_2(BrickGameLayer::onTouchBegan, this); // listen->onTouchMoved = CC_CALLBACK_2(BrickGameLayer::onTouchMoved, this); // listen->onTouchEnded = CC_CALLBACK_2(BrickGameLayer::onTouchEnded, this); // _bulldogAdsMaplisten = EventListenerTouchOneByOne::create(); // auto callback = [this](Touch * touch,Event *) // { // //// CCLOG("MapIconAd_touch:%f,%f",touch->getLocation().x,touch->getLocation().y); // Vec2 point = convertTouchToNodeSpace(touch); //// CCLOG("MapIconAd_point:%f,%f",point.x,point.y); // if(point.x<0 || point.y<0 || point.x>getContentSize().width || point.y>getContentSize().height){ // return false; // } // // RedAdLayerController::getInstance()->openIconAdLayer(); // // return true; // }; // _bulldogAdsMaplisten->onTouchBegan = callback; // _bulldogAdsMaplisten->setSwallowTouches(true); //// Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listen, this); // Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_bulldogAdsMaplisten, -999999); } void BulldogMapIconAdLayer::onOpenClick(Ref * pSender,cocos2d::extension::Control::EventType pEvent){ // BulldogAd* ad = BulldogIconAdController::getInstance()->getBulldogAd(); // int index = BulldogIconAdController::getInstance()->getCurShowAdIndex(); RedAdLayerController::getInstance()->openIconAdLayer(); } //void BulldogMapIconAdLayer::onCloseClick(Ref * pSender,cocos2d::extension::Control::EventType pEvent){ //// btnClose->setEnabled(false); //// amgr->runAnimationsForSequenceNamed("close"); //// //// RedAdLayerController::getInstance()->closeInterstitial(); //// Sound::Shared()->resumeBackgroundMusic(); // // //} void BulldogMapIconAdLayer::onExit() { Layer::onExit(); amgr->setDelegate(NULL); } void BulldogMapIconAdLayer::onEnter(){ Layer::onEnter(); Ref* obj = this->getUserObject(); redream::REDAnimationManager * ret = dynamic_cast(obj); setAnimationManager(ret); setContent(); IconCcbiPathData iconData = BulldogIconAdController::getInstance()->getNextIconPath(); if(iconData.plistPath==""){ setVisible(false); return; } SpriteFrameCache::getInstance()->addSpriteFramesWithFile(iconData.plistPath); BulldogIconLayer* bulldogIconLayer = BulldogIconLayer::Layer(iconData.ccbiPath); if(bulldogIconLayer==nullptr){ setVisible(false); return; } nodeIconAd->removeAllChildren(); bulldogIconLayer->toParentLayer(nodeIconAd); setVisible(true); } BulldogMapIconAdLayer::~BulldogMapIconAdLayer() { // Director::getInstance()->getEventDispatcher()->removeEventListener(_bulldogAdsMaplisten); CC_SAFE_RELEASE_NULL(this->amgr); } BulldogMapIconAdLayer::BulldogMapIconAdLayer() { amgr = NULL; _bulldogAdsMaplisten = nullptr; } NS_RU_END