TestScene.cpp 2.4 KB

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