// // BulldogGameOverIconAdLayer.cpp // BubbleShoot // // Created by 刘玉涛 on 17/9/1. // // #include "RUBulldogGameOverIconAdLayer.h" #include "RUBulldogGameOverIconAdCell.h" #include "BulldogTableViewAdController.h" #include "RedAdLayerController.h" #include "BulldogTool.h" NS_RU_BEGIN BulldogGameOverIconAdLayer * BulldogGameOverIconAdLayer::Layer(){ redream::NodeLoaderLibrary *lib = redream::NodeLoaderLibrary::newDefaultNodeLoaderLibrary(); lib->registerNodeLoader("BulldogGameOverIconAdLayer", BulldogGameOverIconAdLayerLoader::loader()); redream::REDReader *reader = new(std::nothrow) redream::REDReader(lib); reader->autorelease(); BulldogGameOverIconAdLayer * node = (BulldogGameOverIconAdLayer*)reader->readNodeGraphFromFile("BulldogGameOverIconAdLayer.redream"); return node; } bool BulldogGameOverIconAdLayer::onAssignREDMemberVariable(Ref* pTarget, const char* pMemberVariableName, Node* pNode){ RED_MEMBERVARIABLEASSIGNER_GLUE_WEAK(this, "nodeSlide", Node*, BulldogGameOverIconAdLayer::nodeSlide); return false; } SEL_MenuHandler BulldogGameOverIconAdLayer::onResolveREDCCMenuItemSelector(Ref * pTarget, const char* pSelectorName){return nullptr;} cocos2d::extension::Control::Handler BulldogGameOverIconAdLayer::onResolveREDCCControlSelector(cocos2d::Ref * pTarget, const char* pSelectorName){ RED_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onUrlClick", BulldogGameOverIconAdLayer::onUrlClick); return NULL; } void BulldogGameOverIconAdLayer::setAnimationManager(redream::REDAnimationManager* mgr){ CC_SAFE_RELEASE_NULL(this->amgr); this->amgr = mgr; amgr->setDelegate(this); CC_SAFE_RETAIN(this->amgr); } void BulldogGameOverIconAdLayer::setContent(){ mIconAdCellVector.clear(); BulldogAd* ad = BulldogTableViewAdController::getInstance()->getBulldog(); if(ad==nullptr){ return; } ad->updateIconCcbiPathArray(); vector iconPathDataVector = ad->getIconCcbiPathArray(); if(iconPathDataVector.size()==0){ setVisible(false); return; } setVisible(true); //初始化广告 for (int i=0; iaddSpriteFramesWithFile(iconPathData.plistPath); string path = iconPathData.ccbiPath; adCell->setContent(path); mIconAdCellVector.pushBack(adCell); } BulldogGameOverIconAdCell* cell = mIconAdCellVector.at(0); if(cell){ mCellSize = Size(cell->getContentSize()); } mMaxIconAdCellNum = mIconAdCellVector.size(); TableView* tableView = TableView::create(this, nodeSlide->getContentSize()); tableView->setDirection(ScrollView::Direction::HORIZONTAL); tableView->setDelegate(this); nodeSlide->addChild(tableView); tableView->reloadData(); int offsetW = mCellSize.width * mMaxIconAdCellNum; tableView->setContentOffset(Vec2(-offsetW,0)); float baseValue = 0.3f; float time = 0; for(int i=1;i<=mMaxIconAdCellNum;i++){ time += baseValue/i; } tableView->setContentOffsetInDuration(Vec2(0,0),time); } void BulldogGameOverIconAdLayer::completedAnimationSequenceNamed(const char *name, int seqId,int tag){ if(strcmp(name, "close") == 0){ removeFromParent(); } } void BulldogGameOverIconAdLayer::onNodeLoaded(Node * pNode, redream::NodeLoader * pNodeLoader){ setKeyboardEnabled(true); } void BulldogGameOverIconAdLayer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event) { switch(keyCode) { //监听返回键 case EventKeyboard::KeyCode::KEY_ESCAPE: event->stopPropagation(); break; //监听menu键 case EventKeyboard::KeyCode::KEY_MENU: break; } } void BulldogGameOverIconAdLayer::scrollViewDidScroll(cocos2d::extension::ScrollView* view) { } void BulldogGameOverIconAdLayer::scrollViewDidZoom(cocos2d::extension::ScrollView* view) { } void BulldogGameOverIconAdLayer::tableCellTouched(cocos2d::extension::TableView* table, cocos2d::extension::TableViewCell* cell){ RedAdLayerController::getInstance()->openTableViewAdLayer(cell->getIdx()); } cocos2d::Size BulldogGameOverIconAdLayer::tableCellSizeForIndex(cocos2d::extension::TableView *table, ssize_t idx){ return mCellSize; } TableViewCell* BulldogGameOverIconAdLayer::tableCellAtIndex(TableView *table, ssize_t idx){ TableViewCell *cell = table->dequeueCell(); cell = mIconAdCellVector.at(idx); return cell; } ssize_t BulldogGameOverIconAdLayer::numberOfCellsInTableView(cocos2d::extension::TableView *table){ return mMaxIconAdCellNum; } void BulldogGameOverIconAdLayer::onUrlClick(Ref * pSender,cocos2d::extension::Control::EventType pEvent){ BulldogTool::getInstance()->openBulldogCpiUrl(); } void BulldogGameOverIconAdLayer::onExit() { Layer::onExit(); amgr->setDelegate(NULL); } void BulldogGameOverIconAdLayer::onEnter(){ Layer::onEnter(); Ref* obj = this->getUserObject(); redream::REDAnimationManager * ret = dynamic_cast(obj); setAnimationManager(ret); setContent(); } BulldogGameOverIconAdLayer::~BulldogGameOverIconAdLayer(){ CC_SAFE_RELEASE_NULL(this->amgr); mIconAdCellVector.clear(); } BulldogGameOverIconAdLayer::BulldogGameOverIconAdLayer() :amgr(NULL) { amgr = NULL; } NS_RU_END