IAPCtlShopUI.cpp 23 KB

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