123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- //
- // PurchaseBannerCtrl.cpp
- // merge6
- //
- // Created by Black Homles on 2024/9/24.
- //
- #include "PurchaseBannerCtrl.hpp"
- #include "PBConfigData.hpp"
- PurchaseBannerCtrl* PurchaseBannerCtrl::tempPBCtrlInst = nullptr;
- PurchaseBannerCtrl::PurchaseBannerCtrl() {
- }
- PurchaseBannerCtrl::~PurchaseBannerCtrl() {
- }
- PurchaseBannerCtrl* PurchaseBannerCtrl::getInstance() {
- if (tempPBCtrlInst == nullptr || !tempPBCtrlInst) {
- tempPBCtrlInst = new (std::nothrow) PurchaseBannerCtrl();
- }
- return tempPBCtrlInst;
- }
- void PurchaseBannerCtrl::init(PurchaseBannerDelegate* pDelegate) {
- _pBannerDelegate = pDelegate;
- PBConfigData::getInstance()->initData();
- SpriteFrameCache::getInstance()->addSpriteFramesWithFile("内购版位_UI.plist");
- }
- void PurchaseBannerCtrl::showBanner(Node* outerNode,vector<string> bNameList,float autoTime) {
- if (outerNode == nullptr || bNameList.size() <= 0) {
- return;
- }
- _parentNode = outerNode;
- //640,340
- Size tmpsize = Size(640,340);
- auto vDotCfg = PBConfigData::getInstance()->getViewDot();
- _gDotCfg.sepWidth = vDotCfg.sepWidth;
- _gDotCfg.yStart = vDotCfg.yStart;
- _gDotCfg.highSp = vDotCfg.highSp;
- _gDotCfg.normalSp = vDotCfg.normalSp;
- _pviewNode = PurchaseBannerView::create(tmpsize,_gDotCfg,true);
- _pviewNode->setDelegate(this);
- _parentNode->addChild(_pviewNode);
- _pviewNode->setAnchorPoint(Vec2(.5,.5));
- _pviewNode->setIgnoreAnchorPointForPosition(false);
- _pviewCellNameMap.clear();
- for (int lopp = 0; lopp < bNameList.size(); lopp++) {
- string tmpbName = bNameList[lopp];
- auto tmppbcell = PurchaseBannerCell::create(tmpbName);
- _pviewNode->addBanner(tmppbcell);
- tmppbcell->setBtnClickCallBack(std::bind(&PurchaseBannerCtrl::pageViewBtnClick,this,std::placeholders::_1,std::placeholders::_2));
- tmppbcell->setBannerNO(lopp);
- _pviewCellNameMap[lopp] = tmppbcell;
- }
- this->startShowNextPage(autoTime);
- }
- void PurchaseBannerCtrl::pageViewBtnClick(int bNO,string bName) {
- if (bName == "noTime") {
- this->showTimeOutTip();
- return;
- }
- auto bannerinfo = PBConfigData::getInstance()->getBannerInfo(bName);
- if (_pBannerDelegate == nullptr) {
- return;
- }
- auto thisobj = this;
- if (bannerinfo.bannerType == "礼包") {
- _pBannerDelegate->onPurchaseClick(bannerinfo.bannerPID,[=](bool isok){
- thisobj->purchaseOverCallBack(bNO,bName,isok);
- });
- } else if (bannerinfo.bannerType == "计时") {
- _pBannerDelegate->onPurchaseClick(bannerinfo.bannerPID,[=](bool isok){
- thisobj->purchaseOverCallBack(bNO,bName,isok);
- });
- } else if (bannerinfo.bannerType == "活动") {
- _pBannerDelegate->onActBtnClick(bannerinfo.bannerName);
- }
- }
- void PurchaseBannerCtrl::purchaseOverCallBack(int bNO,string bName,bool isok) {
- if (isok) {
- if (_pviewCellNameMap.find(bNO) != _pviewCellNameMap.end()) {
- _pviewCellNameMap[bNO]->setCellStatus();
- }
- }
- }
- void PurchaseBannerCtrl::showTimeOutTip() {
- auto tmpTipLayer = RedreamLoader::Layer("内购版位_浮层_提示文本.redream");
- auto pNode = Director::getInstance()->getRunningScene();
- pNode->addChild(tmpTipLayer);
- float dtt = tmpTipLayer->playAnim("优惠已过期");
- tmpTipLayer->scheduleOnce([=](float dt){
- tmpTipLayer->removeFromParent();
- },dtt,"PurchaseBannerCtrl::showTimeOutTip");
- }
- void PurchaseBannerCtrl::startShowNextPage(float dtt) {
- if (dtt <= 0 || _pviewNode == nullptr) {
- return;
- }
- if (_pviewNode->getPageCount() <= 1) {
- return;
- }
- auto thisNode = this;
- _moveNextTime = 0;
- string schname = "PurchaseBannerCtrl::startShowNextPage";
- _pviewNode->unschedule(schname);
- _pviewNode->schedule([=](float dt){
- if (thisNode->_moveNextTime >= dtt) {
- int curridx = thisNode->_pviewNode->getCurrentPageIdx();
- int pagecount = thisNode->_pviewNode->getPageCount();
- if (curridx >= pagecount - 1) {
- thisNode->_pviewNode->moveToFirstPage();
- } else {
- thisNode->_pviewNode->moveToNextPage();
- }
- thisNode->_moveNextTime = 0;
- } else {
- thisNode->_moveNextTime++;
- }
- },1,schname);
- }
- PurchaseBannerCell* PurchaseBannerCtrl::pageCellAtIndex(PurchaseBannerView* pageView, int index) {
- return nullptr;
- }
- void PurchaseBannerCtrl::pageCellTouched(Touch* touch, PurchaseBannerCell* page) {
- }
- void PurchaseBannerCtrl::onPageChanged(int currentPageIndex, bool manualSet) {
- }
- void PurchaseBannerCtrl::onPageTouchBegan(Touch* touch) {
- _moveNextTime = 0;
- }
|