IAPCtlShopUI.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. //
  2. // IAPCtlShopUI.cpp
  3. // TileManor
  4. //
  5. // Created by 徐炼新 on 2024/1/16.
  6. //
  7. #include "IAPCtlShop.hpp"
  8. #include "ui/UIPageView.h"
  9. #include "RUUtils.h"
  10. #include "RUPlatform.h"
  11. #include "IAPConf.hpp"
  12. #include "IAPCtlShopUI.hpp"
  13. #include "IAPCtlShopItem.hpp"
  14. #include "IAPDefine.hpp"
  15. #include "IAPTestCard.hpp"
  16. #include "IAPCardView.hpp"
  17. #include "IAPTestCardViewDelegate.hpp"
  18. #include "IAPRunTimeData.hpp"
  19. #include <regex>
  20. IAPCtlShopUI* IAPCtlShopUI::_instance = nullptr;
  21. IAPCtlShopUI* IAPCtlShopUI::getInstance() {
  22. if (_instance == nullptr) {
  23. _instance = new IAPCtlShopUI();
  24. _instance->autorelease();
  25. _instance->retain();
  26. }
  27. return _instance;
  28. }
  29. IAPCtlShopUI::IAPCtlShopUI() {
  30. }
  31. IAPCtlShopUI::~IAPCtlShopUI() {
  32. }
  33. bool IAPCtlShopUI::isShowing() {
  34. return _bUIShowing;
  35. }
  36. void IAPCtlShopUI::clear() {
  37. _goodsInfo.clear();
  38. for (auto& gi : _goodsItems) {
  39. gi->release();
  40. }
  41. _goodsItems.clear();
  42. _placementItems.clear();
  43. _failItems.clear();
  44. for(const auto& placement : _placements){
  45. _indicators[placement.first].clear();
  46. }
  47. _allSizes.clear();
  48. _cb = nullptr;
  49. }
  50. bool IAPCtlShopUI::create(Node* pNode, IAPConf* cfg, iap::ShopRequirement& requirement,int placementId) {
  51. redutils::Platform::getInstance()->reportLog("open iap");
  52. _cfg = cfg;
  53. _bUIShowing = true;
  54. _placementId = placementId;
  55. clear();
  56. _layer = redutils::RUReboltLayer::createReboltLayer("shop_interface.redream");
  57. pNode->addChild(_layer, 3);
  58. _layer->registerOnNotify([this](const redutils::ReboltNotifyData& data){
  59. _onNotifyDevelopment(data);
  60. });
  61. _layer->runBehaviacWhitFunName("初始化");
  62. // _igCoin->doOwnInit();
  63. if (_goodsInfo.size() == 0) {
  64. IAPConf::getInstance()->getAllGoods(_goodsInfo);
  65. }
  66. // 构建 list 区域
  67. constructShopItem(false, requirement);
  68. cocos2d::Size size = _ndScrollArea->getContentSize();
  69. _tableView = redutils::RUTableView::create(&_tableData, cocos2d::Size(size.width, size.height));
  70. _tableView->setCascadeOpacityEnabled(true);
  71. _tableView->setCascadeColorEnabled(true);
  72. _tableView->setDirection(ScrollViewSmooth::Direction::VERTICAL);
  73. _tableView->setVerticalFillOrder(TableViewSmooth::VerticalFillOrder::TOP_DOWN, false);
  74. _tableView->setDelegate(&_tableData);
  75. _tableView->setBounceable(true);
  76. // _tableView->setOutSightClean(false);
  77. _ndScrollArea->addChild(_tableView);
  78. return true;
  79. }
  80. void IAPCtlShopUI::displayFailureCardIn(cocos2d::Node *pNode){
  81. clear();
  82. IAPCardView::sDotCfg cfg;
  83. cfg.hightSp = "内购版位_通用_图标_滑动点_已选中.png";
  84. cfg.normalSp = "内购版位_通用_图标_滑动点_未选中.png";
  85. cfg.sepWidth = 30.0f;
  86. cfg.yStart = 0;
  87. IAPConf::getInstance()->getAllGoods(_goodsInfo);
  88. float h = 0.0;
  89. for(const auto& goodInfo : _goodsInfo){
  90. h = std::max(h, goodInfo.sz.height);
  91. }
  92. auto visibleSize = Director::getInstance()->getVisibleSize();
  93. float width = visibleSize.width;
  94. cocos2d::Size sz = cocos2d::Size(width, h + 20);
  95. IAPCardView* cardView = IAPCardView::create(sz, cfg);
  96. IAPTestCardViewDelegate* cardViewDelegate = new IAPTestCardViewDelegate();
  97. cardView->setDelegate(cardViewDelegate);
  98. for (const auto& goodInfo : _goodsInfo) {
  99. auto item = IAPCtlShopItem::create(goodInfo, 1);
  100. _failItems.push_back(item);
  101. cardView->addCard(item);
  102. }
  103. pNode->addChild(cardView);
  104. }
  105. bool IAPCtlShopUI::addAPlacement(const iap::IAPPlacement &plInfo){
  106. // 如果该活动ID存在,则添加失败
  107. if(_placements.count(plInfo.id) != 0)return false;
  108. _placements[plInfo.id] = plInfo;
  109. std::vector<Node*> nodeVec;
  110. _indicators[plInfo.id] = nodeVec;
  111. return true;
  112. }
  113. void IAPCtlShopUI::removePlacement(const std::string &id){
  114. _placements.erase(id);
  115. _indicators.erase(id);
  116. }
  117. bool IAPCtlShopUI::addCardToPlacement(const std::string &id, iap::IAPCard *card){
  118. if(_placements.count(id) == 0)return false;
  119. _placements[id].cards.push_back(card);
  120. return true;
  121. }
  122. bool IAPCtlShopUI::removeCardToPlacement(const std::string id, int cardIndex){
  123. if(_placements.count(id) == 0)return false;
  124. if(cardIndex < 0 || cardIndex >= _placements[id].cards.size()){
  125. return false;
  126. }
  127. _placements[id].cards.erase(_placements[id].cards.begin() + cardIndex);
  128. return true;
  129. }
  130. void IAPCtlShopUI::clearPlacement(){
  131. _placements.clear();
  132. _indicators.clear();
  133. }
  134. size_t IAPCtlShopUI::getPlacementCount(){
  135. return _placements.size();
  136. }
  137. void IAPCtlShopUI::_onNotifyDevelopment(const redutils::ReboltNotifyData& data) {
  138. if (data.notify == "绑定显示区域") {
  139. _ndScrollArea = data.outNode;
  140. } else if (data.notify == "绑定coin节点") {
  141. // _igCoin = new MapIGCoin(data.reboltRedManager);
  142. } else if (data.notify == "退出") {
  143. auto rm = RemoveSelf::create();
  144. auto cf = CallFunc::create([=]() {
  145. _layer->removeFromParent();
  146. _layer = nullptr;
  147. _bUIShowing = false;
  148. redutils::Platform::getInstance()->reportLog("iap closed");
  149. });
  150. _layer->runAction(Sequence::create(rm, cf, NULL));
  151. if (_cb) {
  152. _cb();
  153. }
  154. _cb = nullptr;
  155. }
  156. }
  157. void IAPCtlShopUI::constructShopItem(bool bShowAll, iap::ShopRequirement& requirement) {
  158. int index = 0;
  159. _tableData.setCascadeOpacity(true);
  160. _tableData.clear();
  161. cocos2d::Size size = _ndScrollArea->getContentSize();
  162. auto delayIdx = 0;
  163. cocos2d::Vec2 offset(size.width, 0);
  164. float dur = 0.4;
  165. int height = 0;
  166. // 加入一个表头
  167. {
  168. Node* nd = Node::create();
  169. _tableData.insertCell(index++, nd);
  170. int h = size.height*0.08;
  171. _allSizes.push_back(cocos2d::Size(size.width, h));
  172. height += h;
  173. }
  174. // 开始构建
  175. // 获取礼包信息
  176. IAPConf::getInstance()->getAllGoods(_goodsInfo);
  177. // 获取版位信息
  178. int bigPackCount,smallPackCount; // 需要显示的礼包
  179. auto iapCtlShop = iap::IAPCtlShop::createWith();
  180. auto userBuyType = iapCtlShop->getUserBuyType();
  181. int leval = IAPRunTimeData::getInstance()->getDeviceLevel(); //获取设备等级
  182. size_t placementCount = iapCtlShop->getPlacementCount(); // 获取活动礼包数量
  183. switch(leval){
  184. case 1:
  185. // 低等级
  186. bigPackCount = 2;
  187. smallPackCount = 1;
  188. break;
  189. case 2:
  190. // 中等级
  191. break;
  192. case 3:
  193. if(placementCount >= 2){
  194. bigPackCount = 3;
  195. smallPackCount = 0;
  196. }else{
  197. bigPackCount = 2;
  198. smallPackCount = 2;
  199. }
  200. // 高等级
  201. break;
  202. default:
  203. break;
  204. }
  205. // 展示活动礼包
  206. if(_placements.size() != 0){
  207. for(const auto& placement : _placements){
  208. bool isShow = false;
  209. if(bShowAll){
  210. isShow = true;
  211. }else{
  212. if(bigPackCount > 0){
  213. isShow = true;
  214. bigPackCount--;
  215. }
  216. }
  217. if(isShow){
  218. // 展示活动版位
  219. bool bNeedAnim = height <= size.height;
  220. Node* nd = Node::create();
  221. nd->setAnchorPoint(Vec2(0.5,0.5));
  222. nd->setContentSize(cocos2d::Size(584,250));
  223. nd->setCascadeOpacityEnabled(true);
  224. nd->setCascadeColorEnabled(true);
  225. auto si = createPlacementUI(placement.second);
  226. auto sz = cocos2d::Size(584,280);
  227. cocos2d::Vec2 pos(size.width/2.0, sz.height/2.0);
  228. nd->addChild(si);
  229. si->setPosition(bNeedAnim ? pos+offset : pos);
  230. _placementItems.push_back(nd);
  231. _tableData.insertCell(index++, nd);
  232. _allSizes.push_back(sz);
  233. height += sz.height;
  234. if (bNeedAnim) {
  235. // 加入动画
  236. auto d = DelayTime::create(delayIdx*dur/8.0);
  237. auto m = EaseBackOut::create(MoveBy::create(dur, cocos2d::Vec2(-offset.x, offset.y)));
  238. si->runAction(Sequence::create(d, m, NULL));
  239. delayIdx ++;
  240. }
  241. }
  242. }
  243. }
  244. // 根据用户类型进行礼包排序
  245. switch (userBuyType) {
  246. case iap::UserBuyType::NoShopping:
  247. sortGoods(true);
  248. break;
  249. case iap::UserBuyType::LittleShopping:
  250. sortGoods(true);
  251. break;
  252. case iap::UserBuyType::NormalShopping:
  253. sortGoods(true);
  254. break;
  255. case iap::UserBuyType::LotShopping:
  256. sortGoods(false);
  257. break;
  258. default:
  259. break;
  260. }
  261. // 判断是否展示全部
  262. if(!bShowAll){
  263. // 不展示全部,过滤掉不合格的礼包
  264. filterGoods(requirement);
  265. }
  266. // 判断是否为正常消费
  267. if(userBuyType == iap::UserBuyType::NormalShopping && !bShowAll){
  268. // (当前已按 大礼包 > 小礼包,金额小 > 金额大 的优先级排序)
  269. // 获取购买过的最大金额
  270. float maxn = iapCtlShop->getUserBuyMaxAmount();
  271. // 构建大礼包
  272. if(bigPackCount == 2){
  273. // 查找购买过的最高金额更高一级对应的常规礼包
  274. int nowAmount = INT_MAX;
  275. int nowIndex = -1;
  276. for(int i = 0; i < _goodsInfo.size(); i++){
  277. if(_goodsInfo[i].type != "panel")continue;
  278. if(_goodsInfo[i].getCostNumber() <= maxn)continue;
  279. if(nowAmount > _goodsInfo[i].getCostNumber()){
  280. nowAmount = _goodsInfo[i].getCostNumber();
  281. nowIndex = i;
  282. }
  283. }
  284. if(nowIndex != -1){
  285. bool bNeedAnim = height <= size.height;
  286. Node* nd = Node::create();
  287. nd->setCascadeOpacityEnabled(true);
  288. nd->setCascadeColorEnabled(true);
  289. auto si = IAPCtlShopItem::create(_goodsInfo[nowIndex], _placementId);
  290. auto sz = si->getSize();
  291. cocos2d::Vec2 pos(size.width/2.0, sz.height/2.0);
  292. nd->addChild(si);
  293. si->setPosition(bNeedAnim ? pos+offset : pos);
  294. _goodsItems.push_back(si);
  295. _tableData.insertCell(index++, nd);
  296. _allSizes.push_back(sz);
  297. height += sz.height;
  298. if (bNeedAnim) {
  299. // 加入动画
  300. auto d = DelayTime::create(delayIdx*dur/8.0);
  301. auto m = EaseBackOut::create(MoveBy::create(dur, cocos2d::Vec2(-offset.x, offset.y)));
  302. si->runAction(Sequence::create(d, m, NULL));
  303. delayIdx ++;
  304. }
  305. }
  306. bigPackCount--;
  307. }
  308. if(bigPackCount == 1){
  309. // 查找购买过最高金额所对应的常规礼包
  310. int nowAmount = INT_MIN;
  311. int nowIndex = -1;
  312. for(int i = 0; i < _goodsInfo.size(); i++){
  313. if(_goodsInfo[i].type != "panel")continue;
  314. if(_goodsInfo[i].getCostNumber() > maxn)continue;
  315. if(nowAmount <= _goodsInfo[i].getCostNumber()){
  316. nowAmount = _goodsInfo[i].getCostNumber();
  317. nowIndex = i;
  318. }
  319. }
  320. if(nowIndex != -1){
  321. bool bNeedAnim = height <= size.height;
  322. Node* nd = Node::create();
  323. nd->setCascadeOpacityEnabled(true);
  324. nd->setCascadeColorEnabled(true);
  325. auto si = IAPCtlShopItem::create(_goodsInfo[nowIndex], _placementId);
  326. auto sz = si->getSize();
  327. cocos2d::Vec2 pos(size.width/2.0, sz.height/2.0);
  328. nd->addChild(si);
  329. si->setPosition(bNeedAnim ? pos+offset : pos);
  330. _goodsItems.push_back(si);
  331. _tableData.insertCell(index++, nd);
  332. _allSizes.push_back(sz);
  333. height += sz.height;
  334. if (bNeedAnim) {
  335. // 加入动画
  336. auto d = DelayTime::create(delayIdx*dur/8.0);
  337. auto m = EaseBackOut::create(MoveBy::create(dur, cocos2d::Vec2(-offset.x, offset.y)));
  338. si->runAction(Sequence::create(d, m, NULL));
  339. delayIdx ++;
  340. }
  341. }
  342. bigPackCount--;
  343. }
  344. // 构建小礼包
  345. if(smallPackCount == 2){
  346. // 查找购买过的最高金额更高一级对应的金币礼包
  347. int nowAmount = INT_MAX;
  348. int nowIndex = -1;
  349. for(int i = 0; i < _goodsInfo.size(); i++){
  350. if(_goodsInfo[i].type != "bar")continue;
  351. if(_goodsInfo[i].getCostNumber() <= maxn)continue;
  352. if(nowAmount > _goodsInfo[i].getCostNumber()){
  353. nowAmount = _goodsInfo[i].getCostNumber();
  354. nowIndex = i;
  355. }
  356. }
  357. if(nowIndex != -1){
  358. bool bNeedAnim = height <= size.height;
  359. Node* nd = Node::create();
  360. nd->setCascadeOpacityEnabled(true);
  361. nd->setCascadeColorEnabled(true);
  362. auto si = IAPCtlShopItem::create(_goodsInfo[nowIndex], _placementId);
  363. auto sz = si->getSize();
  364. cocos2d::Vec2 pos(size.width/2.0, sz.height/2.0);
  365. nd->addChild(si);
  366. si->setPosition(bNeedAnim ? pos+offset : pos);
  367. _goodsItems.push_back(si);
  368. _tableData.insertCell(index++, nd);
  369. _allSizes.push_back(sz);
  370. height += sz.height;
  371. if (bNeedAnim) {
  372. // 加入动画
  373. auto d = DelayTime::create(delayIdx*dur/8.0);
  374. auto m = EaseBackOut::create(MoveBy::create(dur, cocos2d::Vec2(-offset.x, offset.y)));
  375. si->runAction(Sequence::create(d, m, NULL));
  376. delayIdx ++;
  377. }
  378. }
  379. smallPackCount--;
  380. }
  381. if(smallPackCount == 1){
  382. // 查找购买过最高金额所对应的金币礼包
  383. int nowAmount = INT_MIN;
  384. int nowIndex = -1;
  385. for(int i = 0; i < _goodsInfo.size(); i++){
  386. if(_goodsInfo[i].type != "bar")continue;
  387. if(_goodsInfo[i].getCostNumber() > maxn)continue;
  388. if(nowAmount <= _goodsInfo[i].getCostNumber()){
  389. nowAmount = _goodsInfo[i].getCostNumber();
  390. nowIndex = i;
  391. }
  392. }
  393. if(nowIndex != -1){
  394. bool bNeedAnim = height <= size.height;
  395. Node* nd = Node::create();
  396. nd->setCascadeOpacityEnabled(true);
  397. nd->setCascadeColorEnabled(true);
  398. auto si = IAPCtlShopItem::create(_goodsInfo[nowIndex], _placementId);
  399. auto sz = si->getSize();
  400. cocos2d::Vec2 pos(size.width/2.0, sz.height/2.0);
  401. nd->addChild(si);
  402. si->setPosition(bNeedAnim ? pos+offset : pos);
  403. _goodsItems.push_back(si);
  404. _tableData.insertCell(index++, nd);
  405. _allSizes.push_back(sz);
  406. height += sz.height;
  407. if (bNeedAnim) {
  408. // 加入动画
  409. auto d = DelayTime::create(delayIdx*dur/8.0);
  410. auto m = EaseBackOut::create(MoveBy::create(dur, cocos2d::Vec2(-offset.x, offset.y)));
  411. si->runAction(Sequence::create(d, m, NULL));
  412. delayIdx ++;
  413. }
  414. }
  415. smallPackCount--;
  416. }
  417. }else{
  418. // 判断是否还有版位
  419. if(bigPackCount != 0 || smallPackCount != 0 || bShowAll){
  420. // 显示常规商品
  421. for (const auto& gi : _goodsInfo) {
  422. // 判断是否显示
  423. bool isShow = false;
  424. if (bShowAll) {
  425. isShow = true;
  426. }else{
  427. if(gi.type == "panel" && bigPackCount > 0){
  428. isShow = true;
  429. bigPackCount--;
  430. }
  431. if(gi.type == "bar" && smallPackCount > 0){
  432. isShow = true;
  433. smallPackCount--;
  434. }
  435. }
  436. // 商品显示
  437. if (isShow) {
  438. bool bNeedAnim = height <= size.height;
  439. Node* nd = Node::create();
  440. nd->setCascadeOpacityEnabled(true);
  441. nd->setCascadeColorEnabled(true);
  442. auto si = IAPCtlShopItem::create(gi, _placementId);
  443. auto sz = si->getSize();
  444. cocos2d::Vec2 pos(size.width/2.0, sz.height/2.0);
  445. nd->addChild(si);
  446. si->setPosition(bNeedAnim ? pos+offset : pos);
  447. _goodsItems.push_back(si);
  448. _tableData.insertCell(index++, nd);
  449. _allSizes.push_back(sz);
  450. height += sz.height;
  451. if (bNeedAnim) {
  452. // 加入动画
  453. auto d = DelayTime::create(delayIdx*dur/8.0);
  454. auto m = EaseBackOut::create(MoveBy::create(dur, cocos2d::Vec2(-offset.x, offset.y)));
  455. si->runAction(Sequence::create(d, m, NULL));
  456. delayIdx ++;
  457. }
  458. }
  459. }
  460. }
  461. }
  462. // 添加展示所有按钮
  463. if (!bShowAll) {
  464. // 加入show All btn, 这个是一定会有动画的
  465. auto sz = cocos2d::Size(584, 130);
  466. Node* nd = Node::create();
  467. nd->setCascadeOpacityEnabled(true);
  468. nd->setCascadeColorEnabled(true);
  469. _btnShowAll = redutils::RUReboltLayer::createReboltLayer("shop_more_btn.redream");
  470. nd->addChild(_btnShowAll);
  471. _btnShowAll->setPosition(Vec2(size.width/2.0, sz.height/2.0) + offset);
  472. _tableData.insertCell(index++, nd);
  473. _btnShowAll->registerOnNotify([this](const redutils::ReboltNotifyData& data){
  474. if (data.notify == "点击") {
  475. auto rm = RemoveSelf::create();
  476. auto cf = CallFunc::create([=](){
  477. _btnShowAll = NULL;
  478. _tableData.clear();
  479. _goodsItems.clear();
  480. _placementItems.clear();
  481. for(const auto& placement : _placements){
  482. _indicators[placement.first].clear();
  483. }
  484. _allSizes.clear();
  485. iap::ShopRequirement req;
  486. req.coinsMin = 0;
  487. constructShopItem(true, req);
  488. _tableView->reloadData(true);
  489. });
  490. _btnShowAll->runAction(Sequence::create(rm, cf, NULL));
  491. }
  492. });
  493. redutils::iterateNode(nd, [](Node* nd){
  494. nd->setCascadeOpacityEnabled(true);
  495. nd->setCascadeColorEnabled(true);
  496. });
  497. _btnShowAll->runBehaviacWhitFunName("初始化");
  498. _allSizes.push_back(sz);
  499. // 加入动画
  500. auto d = DelayTime::create(delayIdx*dur/8.0);
  501. auto m = EaseBackOut::create(MoveBy::create(dur, cocos2d::Vec2(-offset.x, offset.y)));
  502. _btnShowAll->runAction(Sequence::create(d, m, NULL));
  503. delayIdx ++;
  504. } else {
  505. // 底部添加一个额外节点(一个是底部的广告,还有就是美观一些)
  506. _tableData.insertCell(index++, Node::create());
  507. _allSizes.push_back(cocos2d::Size(584, 150));
  508. }
  509. _tableData._numberOfCellsInTableView = [=](cocos2d::extension::TableViewSmooth*)->ssize_t{
  510. return _allSizes.size();
  511. };
  512. _tableData._tableCellSizeForIndex = [=](cocos2d::extension::TableViewSmooth*, ssize_t idx)->Size{
  513. if (idx < _allSizes.size()) {
  514. return _allSizes[idx];
  515. } else {
  516. return Size(0,0);
  517. }
  518. };
  519. // 防止拉动的时候才创建
  520. _layer->scheduleOnce([=](float){
  521. for (int i=0; i<_allSizes.size(); i++) {
  522. _tableView->updateCellAtIndex(i);
  523. }
  524. }, 0.05, "SCH_Update_Cells");
  525. }
  526. Node* IAPCtlShopUI::createPlacementUI(const iap::IAPPlacement& placement){
  527. Node* node = Node::create();
  528. IAPCardView::sDotCfg cfg;
  529. cfg.hightSp = "内购版位_通用_图标_滑动点_已选中.png";
  530. cfg.normalSp = "内购版位_通用_图标_滑动点_未选中.png";
  531. cfg.sepWidth = 30.0f;
  532. cfg.yStart = 0;
  533. cocos2d::Size sz = cocos2d::Size(584, 250);
  534. IAPCardView* cardView = IAPCardView::create(sz, cfg);
  535. IAPTestCardViewDelegate* cardViewDelegate = new IAPTestCardViewDelegate();
  536. cardView->setDelegate(cardViewDelegate);
  537. // 遍历 placement 中的卡片,依次创建并添加到 PageView 中
  538. for (int i = 0; i < placement.cards.size(); i++) {
  539. cardView->addCard(placement.cards[i]->create());
  540. }
  541. // 将 PageView 添加到父节点 node 中
  542. node->addChild(cardView);
  543. return node;
  544. }
  545. void IAPCtlShopUI::filterGoods(iap::ShopRequirement &requirement){
  546. std::map<int, bool> m;
  547. int cnt = 0;
  548. for(const auto& goodInfo : _goodsInfo){
  549. if(goodInfo.getCoinNumber() >= requirement.coinsMin){
  550. m[cnt] = true;
  551. }
  552. cnt++;
  553. }
  554. std::vector<GoodsInfo> newGoodsInfo;
  555. // 添加符合条件的礼包
  556. for(int i = 0;i < _goodsInfo.size(); i++){
  557. if(m[i]){
  558. newGoodsInfo.push_back(_goodsInfo[i]);
  559. }
  560. }
  561. // 添加不符合条件的礼包(不清楚是不是需要显示,暂放到列表末尾)
  562. // for(int i = 0;i < _goodsInfo.size(); i++){
  563. // if(!m[i]){
  564. // newGoodsInfo.push_back(_goodsInfo[i]);
  565. // }
  566. // }
  567. _goodsInfo = newGoodsInfo;
  568. }
  569. void IAPCtlShopUI::sortGoods(bool flag){
  570. sort(_goodsInfo.begin(), _goodsInfo.end(), [flag](GoodsInfo a, GoodsInfo b){
  571. if(a.getTypeValue() != b.getTypeValue())return a.getTypeValue() > b.getTypeValue();
  572. if(flag) return a.getCostNumber() < b.getCostNumber();
  573. else return a.getCostNumber() > b.getCostNumber();
  574. });
  575. }
  576. void IAPCtlShopUI::quit() {
  577. if (_layer) {
  578. _layer->runBehaviacWhitFunName("退出");
  579. }
  580. }