TestScene.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // 在此处添加场景初始化的代码,比如创建背景、角色、UI等
  27. createBoard();
  28. schedule(CC_SCHEDULE_SELECTOR(TestScene::update), 1.0f);
  29. return true;
  30. }
  31. void TestScene::createBoard(){
  32. auto lyMap = redutils::RUReboltLayer::createReboltLayer("lyMap.redream");
  33. this->addChild(lyMap);
  34. // log(lyMap->getChildrenCount());
  35. lyMap->registerOnNotify([this](const redutils::ReboltNotifyData& data){
  36. onNotifyDevelopment(data);
  37. });
  38. lyMap->runBehaviacWhitFunName("初始化");
  39. }
  40. void TestScene::onNotifyDevelopment(const redutils::ReboltNotifyData& data){
  41. if(data.notify == "点击显示商店"){
  42. log("点击显示商店按钮");
  43. iap::ShopRequirement shopRequirement;
  44. shopRequirement.coinsMin = 0;
  45. _iapShop->showInNode(this, shopRequirement);
  46. }else if(data.notify == "点击设备1"){
  47. _iapShop->setDeviceLevel(1);
  48. log("设置为低等级设备");
  49. }else if(data.notify == "点击设备2"){
  50. _iapShop->setDeviceLevel(3);
  51. log("设置为高等级设备");
  52. }else if(data.notify == "点击失败"){
  53. log("点击失败时金币不够按钮");
  54. iap::ShopRequirement shopRequirement;
  55. shopRequirement.coinsMin = 10000;
  56. _iapShop->showInNode(this, shopRequirement);
  57. }else if(data.notify == "点击重置"){
  58. _iapShop->setDeviceLevel(1);
  59. _iapShop->clearUserBuyInfo();
  60. log("重置为低等级设备,且清除用户购买信息");
  61. }
  62. }
  63. void TestScene::update(float dt){
  64. }