TestScene.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // TestScene.cpp
  3. // demo
  4. //
  5. // Created by Red_mini on 2024/10/11.
  6. //
  7. #include "TestScene.h"
  8. #include "RUPlatform.h"
  9. #include "IAPCtlShop.hpp"
  10. #include "IAPDefine.hpp"
  11. USING_NS_CC;
  12. Scene* TestScene::createScene(){
  13. // create the scene with physics enabled
  14. auto scene = Scene::create();
  15. auto layer = TestScene::create();
  16. scene->addChild(layer);
  17. return scene;
  18. }
  19. bool TestScene::init(){
  20. if (!Layer::init()) {
  21. return false;
  22. }
  23. std::string cfgFN = "shop_5.json";
  24. _iapShop = iap::IAPCtlShop::createWith();
  25. _iapShop->init(cfgFN);
  26. // iap::IAPPlacement plInfo;
  27. // plInfo.id = "1";
  28. // iap::IAPPlacement plInfo2;
  29. // plInfo2.id = "2";
  30. // _iapShop->addAPlacement(plInfo);
  31. // _iapShop->addAPlacement(plInfo2);
  32. // 在此处添加场景初始化的代码,比如创建背景、角色、UI等
  33. createBoard();
  34. schedule(CC_SCHEDULE_SELECTOR(TestScene::update), 1.0f);
  35. return true;
  36. }
  37. void TestScene::createBoard(){
  38. auto lyMap = redutils::RUReboltLayer::createReboltLayer("lyMap.redream");
  39. this->addChild(lyMap);
  40. // log(lyMap->getChildrenCount());
  41. lyMap->registerOnNotify([this](const redutils::ReboltNotifyData& data){
  42. onNotifyDevelopment(data);
  43. });
  44. lyMap->runBehaviacWhitFunName("初始化");
  45. }
  46. void TestScene::onNotifyDevelopment(const redutils::ReboltNotifyData& data){
  47. if(data.notify == "点击显示商店"){
  48. log("点击显示商店按钮");
  49. iap::ShopRequirement shopRequirement;
  50. shopRequirement.coinsMin = 0;
  51. _iapShop->showInNode(this, shopRequirement);
  52. }else if(data.notify == "点击设备1"){
  53. _iapShop->setDeviceLevel(1);
  54. log("设置为低等级设备");
  55. }else if(data.notify == "点击设备2"){
  56. _iapShop->setDeviceLevel(3);
  57. log("设置为高等级设备");
  58. }else if(data.notify == "点击失败"){
  59. log("点击失败时金币不够按钮");
  60. iap::ShopRequirement shopRequirement;
  61. shopRequirement.coinsMin = 10000;
  62. _iapShop->showInNode(this, shopRequirement);
  63. }else if(data.notify == "点击重置"){
  64. _iapShop->setDeviceLevel(1);
  65. _iapShop->clearUserBuyInfo();
  66. log("重置为低等级设备,且清除用户购买信息");
  67. }
  68. }
  69. void TestScene::update(float dt){
  70. }