IAPCtlShopItem.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // IAPCtlShopItem.cpp
  3. // TileManor
  4. //
  5. // Created by 徐炼新 on 2024/1/17.
  6. //
  7. #include "IAPCtlShopItem.hpp"
  8. #include "IAPCtlArea23.hpp"
  9. #include "IAPProcess.hpp"
  10. #include "IAPSucessProcess.hpp"
  11. #include "IAPShopDelegate.hpp"
  12. #include "RUUtils.h"
  13. #include "IAPConf.hpp"
  14. #include "IAPUserData.hpp"
  15. #include "IAPCtlShopUI.hpp"
  16. IAPCtlShopItem* IAPCtlShopItem::create(const GoodsInfo& gi, int placementId) {
  17. IAPCtlShopItem* csi = new IAPCtlShopItem(gi);
  18. csi->_placementId = placementId;
  19. csi->autorelease();
  20. csi->retain();
  21. return csi;
  22. }
  23. IAPCtlShopItem::IAPCtlShopItem(const GoodsInfo& gi)
  24. : _gi(gi) {
  25. }
  26. IAPCtlShopItem::~IAPCtlShopItem() {
  27. if (_ctlArea23) {
  28. _ctlArea23->release();
  29. }
  30. }
  31. cocos2d::Size IAPCtlShopItem::getSize() {
  32. return _gi.sz;
  33. }
  34. void IAPCtlShopItem::onEnter() {
  35. Node::onEnter();
  36. if (_layer == nullptr) {
  37. initUI();
  38. setCascadeOpacityEnabled(true);
  39. setCascadeColorEnabled(true);
  40. redutils::iterateNode(this, [](Node* nd){
  41. nd->setCascadeOpacityEnabled(true);
  42. nd->setCascadeColorEnabled(true);
  43. });
  44. }
  45. }
  46. bool IAPCtlShopItem::initUI() {
  47. if (_gi.type == "bar") {
  48. _layer = redutils::RUReboltLayer::createReboltLayer("shop_panel_2.redream");
  49. } else {
  50. _layer = redutils::RUReboltLayer::createReboltLayer("shop_panel_1.redream");
  51. if (_gi.style == "normal") {
  52. _layer->setCoderDataVar("P-tStyle", "1");
  53. } else if (_gi.style == "mostValued") {
  54. _layer->setCoderDataVar("P-tStyle", "2");
  55. } else if (_gi.style == "special") {
  56. _layer->setCoderDataVar("P-tStyle", "3");
  57. }
  58. _layer->setCoderDataVar("P-tSlogon", _gi.slogon);
  59. _layer->setCoderDataVar("P-tHint", _gi.hint);
  60. }
  61. _layer->setCoderDataVar("P-tCost", _gi.cost);
  62. _layer->setCoderDataVar("P-tCoins", _gi.areas.front().front().count);
  63. std::string strCoins;
  64. // 从后往前遍历,每隔3个数增加一个空格
  65. for (int i=_gi.areas.front().front().count.size()-1; i>=0; i--) {
  66. if (strCoins.size() > 0 && (strCoins.size() == 3 || strCoins.size() == 7)) {
  67. strCoins = " " + strCoins;
  68. }
  69. strCoins = std::string(1, _gi.areas.front().front().count.at(i)) + strCoins;
  70. }
  71. _layer->setCoderDataVar("P-tLbCoins", strCoins);
  72. addChild(_layer);
  73. _layer->registerOnNotify([this](const redutils::ReboltNotifyData& data){
  74. onNotifyDevelopment(data);
  75. });
  76. _layer->runBehaviacWhitFunName("初始化");
  77. if (_ctlArea23) {
  78. _ctlArea23->doOwnInit();
  79. }
  80. return true;
  81. }
  82. void IAPCtlShopItem::onNotifyDevelopment(const redutils::ReboltNotifyData& data) {
  83. if (data.notify == "绑定展示区23") {
  84. _ctlArea23 = IAPCtlArea23::create(data.reboltRedManager, _gi);
  85. } else if (data.notify == "点击购买") {
  86. // 展示正在购买中的界面
  87. IAPProcess::getInstance()->buy(_gi,
  88. _placementId,
  89. [=](){
  90. accepted();
  91. },
  92. [=](){
  93. rejected();
  94. });
  95. }
  96. }
  97. void IAPCtlShopItem::accepted() {
  98. // 退出购买界面,展示成功界面
  99. IAPCtlShopUI::getInstance()->quit();
  100. }
  101. void IAPCtlShopItem::rejected() {
  102. }