123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- //
- // 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<IconCcbiPathData> iconPathDataVector = ad->getIconCcbiPathArray();
-
- if(iconPathDataVector.size()==0){
- setVisible(false);
- return;
- }
- setVisible(true);
-
- //初始化广告
- for (int i=0; i<iconPathDataVector.size(); i++) {
- BulldogGameOverIconAdCell* adCell = BulldogGameOverIconAdCell::Layer();
- IconCcbiPathData iconPathData = iconPathDataVector.at(i);
- SpriteFrameCache::getInstance()->addSpriteFramesWithFile(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<redream::REDAnimationManager*>(obj);
- setAnimationManager(ret);
-
- setContent();
-
- }
- BulldogGameOverIconAdLayer::~BulldogGameOverIconAdLayer(){
- CC_SAFE_RELEASE_NULL(this->amgr);
- mIconAdCellVector.clear();
-
- }
- BulldogGameOverIconAdLayer::BulldogGameOverIconAdLayer()
- :amgr(NULL)
- {
- amgr = NULL;
- }
- NS_RU_END
|