// // IAPCtlShop.cpp // TileManor // // Created by 徐炼新 on 2024/9/30. // #include "IAPCtlShop.hpp" #include "cocos2d.h" #include "RUBaseConf.h" #include "RUUtils.h" #include "IAPConf.hpp" #include "IAPCtlShopUI.hpp" #include "IAPUserData.hpp" #include "IAPRunTimeData.hpp" #include "PBConfigData.hpp" #include "PurchaseBannerView.hpp" NS_IAPSHOP_BEGIN IAPCtlShop* IAPCtlShop::_instance = nullptr; IAPCtlShop* IAPCtlShop::createWith(){ if (_instance == nullptr) { _instance = new IAPCtlShop(); } return _instance; } void IAPCtlShop::init(std::string &cfgFN){ redutils::BaseConf* baseConf = new redutils::BaseConf(cfgFN.c_str()); _conf = IAPConf::getInstance(); _conf->initWith(baseConf); } void IAPCtlShop::setDelegate(IAPShopDelegate *delegate){ _delegate = delegate; } void IAPCtlShop::setCfg4Failure(std::string &cfgFN){ _pbConf = PBConfigData::getInstance(); _pbConf->initData(cfgFN); } void IAPCtlShop::displayFailureCardIn(cocos2d::Node *node, std::vector cardsName){ auto sDot = _pbConf->getViewDot(); PurchaseBannerView::sDotCfg dot; dot.highSp = sDot.highSp; dot.normalSp = sDot.normalSp; dot.sepWidth = sDot.sepWidth; dot.yStart = sDot.yStart; auto visibleSize = Director::getInstance()->getVisibleSize(); float width = visibleSize.width; cocos2d::Size sz = cocos2d::Size(width, 300); PurchaseBannerView* view = PurchaseBannerView::create(sz, dot, true); for(const auto& name : cardsName){ PurchaseBannerCell* tmpNode = PurchaseBannerCell::create(name); view->addBanner(tmpNode); } node->addChild(view); } void IAPCtlShop::setDeviceLevel(int level){ IAPRunTimeData::getInstance()->setDeviceLevel(level); } bool IAPCtlShop::addAPlacement(const IAPPlacement &plInfo){ bool ans =IAPCtlShopUI::getInstance()->addAPlacement(plInfo); return ans; } void IAPCtlShop::removePlacement(const std::string &id){ IAPCtlShopUI::getInstance()->removePlacement(id); } bool IAPCtlShop::addCardToPlacement(const std::string &id, IAPCard *card){ return IAPCtlShopUI::getInstance()->addCardToPlacement(id, card); } bool IAPCtlShop::removeCardToPlacement(const std::string &id, int cardIndex){ return IAPCtlShopUI::getInstance()->removeCardToPlacement(id, cardIndex); } void IAPCtlShop::clearPlacement(){ IAPCtlShopUI::getInstance()->clearPlacement(); } size_t IAPCtlShop::getPlacementCount(){ return IAPCtlShopUI::getInstance()->getPlacementCount(); } void IAPCtlShop::showInNode(cocos2d::Node *pParent, ShopRequirement &requirement){ IAPCtlShopUI::getInstance()->create(pParent, _conf, requirement); } void IAPCtlShop::showSlideCardsByCoinsIn(cocos2d::Node* pParent, int stillNeedCoins){ IAPCtlShopUI::getInstance()->showSlideCardsByCoinsIn(pParent, stillNeedCoins); } void IAPCtlShop::addUserBuyInfo(std::string commodityID){ iapshop::IAPUserData::getInstance()->addBuyInfo(commodityID); if(_delegate){ std::vector goodInfos; _conf->getAllGoods(goodInfos); for(const auto& goodInfo : goodInfos){ if(goodInfo.id == commodityID){ std::map buyInfo; for(const auto& area : goodInfo.areas){ for(const auto& info : area){ buyInfo[info.name] = info.count; } } // 发送礼包内含有的物品 _delegate->onUserBuySuccess(buyInfo); break; } } } } void IAPCtlShop::clearUserBuyInfo(){ iapshop::IAPUserData::getInstance()->clearBuyInfo(); } NS_IAPSHOP_END