// // 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 = iapshop::IAPCtlShop::createWith(); auto delegate = IAPDelegateImpl::createWith(); _iapShop->setDelegate(delegate); _iapShop->init(cfgFN); _iapShop->setCfg4Failure(failFN); // 第二个版位 // iapshop::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("点击显示商店按钮"); iapshop::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("点击失败时金币不够按钮"); // iapshop::ShopRequirement shopRequirement; // shopRequirement.coinsMin = 10000; // // _iapShop->showInNode(this, shopRequirement); std::vector 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(data.outNode); if(editBox){ std::string text = editBox->getText(); iapshop::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 == "点击添加一个活动版位"){ iapshop::IAPPlacement plInfo; plInfo.id = _placementIDs.size(); _placementIDs.push_back(plInfo.id); _iapShop->addAPlacement(plInfo); }else if(data.notify == "点击给活动版位添加卡片"){ auto editBox = dynamic_cast(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){ }