123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- //
- // TestScene.cpp
- // demo
- //
- // Created by Red_mini on 2024/10/11.
- //
- #include "TestScene.h"
- #include "RUPlatform.h"
- #include "IAPCtlShop.hpp"
- #include "IAPDefine.hpp"
- #include "IAPTestCard.hpp"
- #include "IAPDelegateImpl.hpp"
- USING_NS_CC;
- Scene* TestScene::createScene(){
-
- // create the scene with physics enabled
- auto scene = Scene::create();
- auto layer = TestScene::create();
- scene->addChild(layer);
-
- return scene;
- }
- bool TestScene::init(){
- if (!Layer::init()) {
- return false;
- }
-
- std::string cfgFN = "shop_5.json";
- std::string failFN = "purchaseBannerConfig.csv";
-
- _iapShop = iap::IAPCtlShop::createWith();
- auto delegate = IAPDelegateImpl::createWith();
- _iapShop->setDelegate(delegate);
-
- _iapShop->init(cfgFN);
- _iapShop->setCfg4Failure(failFN);
-
-
-
- // 第二个版位
-
- // iap::IAPPlacement plInfo2;
- // plInfo2.id = "2";
- // IAPTestCard* testCard3 = new IAPTestCard();
- // IAPTestCard* testCard4 = new IAPTestCard();
- // plInfo2.cards.push_back(testCard3);
- // plInfo2.cards.push_back(testCard4);
- //
- // _iapShop->addAPlacement(plInfo2);
-
-
- // 在此处添加场景初始化的代码,比如创建背景、角色、UI等
- createBoard();
- schedule(CC_SCHEDULE_SELECTOR(TestScene::update), 1.0f);
-
- return true;
- }
- void TestScene::createBoard(){
- auto lyMap = redutils::RUReboltLayer::createReboltLayer("lyMap.redream");
- this->addChild(lyMap);
- // log(lyMap->getChildrenCount());
- lyMap->registerOnNotify([this](const redutils::ReboltNotifyData& data){
- onNotifyDevelopment(data);
- });
- lyMap->runBehaviacWhitFunName("初始化");
-
- }
- void TestScene::onNotifyDevelopment(const redutils::ReboltNotifyData& data){
- if(data.notify == "点击显示商店"){
- log("点击显示商店按钮");
-
- iap::ShopRequirement shopRequirement;
- shopRequirement.coinsMin = 0;
-
- _iapShop->showInNode(this, shopRequirement);
- }else if(data.notify == "点击设备1"){
- _iapShop->setDeviceLevel(1);
- log("设置为低等级设备");
- }else if(data.notify == "点击设备2"){
- _iapShop->setDeviceLevel(3);
- log("设置为高等级设备");
- }else if(data.notify == "点击失败"){
- log("点击失败时金币不够按钮");
-
- // iap::ShopRequirement shopRequirement;
- // shopRequirement.coinsMin = 10000;
- //
- // _iapShop->showInNode(this, shopRequirement);
- std::vector<std::string> names;
- // names.push_back("礼包1");
- names.push_back("tilefavor");
- names.push_back("tilepack");
- names.push_back("tilepass");
-
- _iapShop->displayFailureCardIn(this, names);
- }else if(data.notify == "点击失败时进入商店"){
- auto editBox = dynamic_cast<REDEditBox*>(data.outNode);
- if(editBox){
- std::string text = editBox->getText();
- iap::ShopRequirement req;
- req.coinsMin = 0;
- try {
- req.coinsMin = stoi(text);
- }
- catch (const std::invalid_argument&) {
- log("转化失败");
- }
- catch (const std::out_of_range&) {
- log("超过int值");
- }
- _iapShop->showInNode(this, req);
- log("点击失败时进入商店");
- }
- }else if(data.notify == "点击重置"){
-
- _iapShop->setDeviceLevel(1);
- _iapShop->clearUserBuyInfo();
- _iapShop->clearPlacement();
- _placementIDs.clear();
- log("重置为低等级设备,清除用户购买信息,清除活动版位");
- }else if(data.notify == "点击添加一个活动版位"){
- iap::IAPPlacement plInfo;
- plInfo.id = _placementIDs.size();
-
- _placementIDs.push_back(plInfo.id);
-
- _iapShop->addAPlacement(plInfo);
-
- }else if(data.notify == "点击给活动版位添加卡片"){
- auto editBox = dynamic_cast<REDEditBox*>(data.outNode);
- if(editBox){
- std::string text = editBox->getText();
- int index = 0;
- try {
- index = stoi(text);
- }
- catch (const std::invalid_argument&) {
- log("转化失败");
- }
- catch (const std::out_of_range&) {
- log("超过int值");
- }
- if(index < _placementIDs.size()){
- IAPTestCard* testCard = new IAPTestCard();
- _iapShop->addCardToPlacement(_placementIDs[index], testCard);
- }
- }
-
-
- }
- }
- void TestScene::update(float dt){
-
-
- }
|