|
@@ -17,6 +17,10 @@
|
|
|
#include "IAPCtlShopItem.hpp"
|
|
|
#include "IAPDefine.hpp"
|
|
|
#include "IAPTestCard.hpp"
|
|
|
+
|
|
|
+#include "IAPCardView.hpp"
|
|
|
+#include "IAPTestCardViewDelegate.hpp"
|
|
|
+
|
|
|
#include <regex>
|
|
|
|
|
|
IAPCtlShopUI* IAPCtlShopUI::_instance = nullptr;
|
|
@@ -148,13 +152,6 @@ void IAPCtlShopUI::showPlacementsInNode(cocos2d::Node *pNode, const vector<std::
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- // 防止拉动的时候才创建
|
|
|
- _layer->scheduleOnce([=](float){
|
|
|
- for (int i=0; i<_allSizes.size(); i++) {
|
|
|
- _tableView->updateCellAtIndex(i);
|
|
|
- }
|
|
|
- }, 0.05, "SCH_Update_Cells");
|
|
|
-
|
|
|
|
|
|
_tableView = redutils::RUTableView::create(&_tableData, cocos2d::Size(size.width, size.height));
|
|
|
_tableView->setCascadeOpacityEnabled(true);
|
|
@@ -173,8 +170,8 @@ bool IAPCtlShopUI::addAPlacement(const iap::IAPPlacement &plInfo){
|
|
|
|
|
|
_placements[plInfo.id] = plInfo;
|
|
|
|
|
|
- std::vector<DrawNode*> drawNode;
|
|
|
- _indicators[plInfo.id] = drawNode;
|
|
|
+ std::vector<Node*> nodeVec;
|
|
|
+ _indicators[plInfo.id] = nodeVec;
|
|
|
|
|
|
return true;
|
|
|
}
|
|
@@ -446,70 +443,24 @@ void IAPCtlShopUI::constructShopItem(bool bShowAll) {
|
|
|
Node* IAPCtlShopUI::createPlacementUI(const iap::IAPPlacement& placement){
|
|
|
Node* node = Node::create();
|
|
|
|
|
|
- // 创建 PageView 用于分页滑动卡片
|
|
|
- auto pageView = ui::PageView::create();
|
|
|
- pageView->setContentSize(cocos2d::Size(584, 250));
|
|
|
+ IAPCardView::sDotCfg cfg;
|
|
|
+ cfg.hightSp = "内购版位_通用_图标_滑动点_已选中.png";
|
|
|
+ cfg.normalSp = "内购版位_通用_图标_滑动点_未选中.png";
|
|
|
+ cfg.sepWidth = 30.0f;
|
|
|
+ cfg.yStart = 0;
|
|
|
+ cocos2d::Size sz = cocos2d::Size(584, 250);
|
|
|
+ IAPCardView* cardView = IAPCardView::create(sz, cfg);
|
|
|
|
|
|
- // 创建指示点的父节点
|
|
|
- auto indicatorNode = Node::create();
|
|
|
- float spacing = 20.0f; // 每个指示点之间的间距
|
|
|
+ IAPTestCardViewDelegate* cardViewDelegate = new IAPTestCardViewDelegate();
|
|
|
+ cardView->setDelegate(cardViewDelegate);
|
|
|
|
|
|
// 遍历 placement 中的卡片,依次创建并添加到 PageView 中
|
|
|
for (int i = 0; i < placement.cards.size(); i++) {
|
|
|
- // 创建每张卡片的布局容器(PageView 只能添加 Layout 类型的子节点)
|
|
|
- auto layout = ui::Layout::create();
|
|
|
- layout->setContentSize(cocos2d::Size(584, 250));
|
|
|
-
|
|
|
- auto card = placement.cards[i]->create(); // 假设 card 有 create 方法
|
|
|
-
|
|
|
- // 设置卡片的居中位置
|
|
|
- card->setPosition(Vec2(layout->getContentSize().width / 2, layout->getContentSize().height / 2));
|
|
|
- layout->addChild(card);
|
|
|
-
|
|
|
- // 将布局容器添加到 PageView 中
|
|
|
- pageView->addPage(layout);
|
|
|
-
|
|
|
- // 创建指示点
|
|
|
- auto indicator = DrawNode::create();
|
|
|
- Vec2 center(i * spacing, 0); // 水平排列指示点
|
|
|
- _indicators[placement.id].push_back(indicator);
|
|
|
-
|
|
|
- // 画白色圆点
|
|
|
- indicator->drawDot(center, 5, Color4F(1, 1, 1, 1)); // 白色指示点
|
|
|
- indicatorNode->addChild(indicator);
|
|
|
+ cardView->addCard(placement.cards[i]->create());
|
|
|
}
|
|
|
-
|
|
|
- // 设置 PageView 的分页切换效果(滑动自动切换)
|
|
|
- pageView->setUsingCustomScrollThreshold(true); // 启用自定义滑动阈值
|
|
|
- pageView->setCustomScrollThreshold(50); // 设置触发翻页的滑动距离阈值
|
|
|
- pageView->setAutoScrollStopEpsilon(0.05f); // 提高自动滚动停止的精度
|
|
|
-
|
|
|
- // 设置指示点的位置,居中显示在卡片下方
|
|
|
- float indicatorNodeWidth = (placement.cards.size() - 1) * spacing;
|
|
|
- indicatorNode->setPosition(Vec2(pageView->getContentSize().width / 2 - indicatorNodeWidth / 2, 0)); // 调整y轴位置
|
|
|
- node->addChild(indicatorNode); // 将指示点容器添加到主节点中
|
|
|
-
|
|
|
- // 添加回调函数监听页面变化
|
|
|
- pageView->addEventListener([=](Ref* sender, ui::PageView::EventType type) {
|
|
|
- if (type == ui::PageView::EventType::TURNING) {
|
|
|
- log("滑动");
|
|
|
- auto pageView = dynamic_cast<ui::PageView*>(sender);
|
|
|
- int currentPageIndex = pageView->getCurrentPageIndex();
|
|
|
-
|
|
|
- // 更新指示点颜色,当前页的指示点变为红色,其他保持白色
|
|
|
- for (int i = 0; i < _indicators[placement.id].size(); i++) {
|
|
|
- _indicators[placement.id][i]->clear(); // 清除之前的绘制
|
|
|
- Color4F color = (i == currentPageIndex) ? Color4F(1, 0, 0, 1) : Color4F(1, 1, 1, 1); // 红色或白色
|
|
|
- _indicators[placement.id][i]->drawDot(Vec2(i * 20, 0), 5, color); // 更新指示点颜色
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 默认将第一页的指示点设为红色
|
|
|
- _indicators[placement.id][0]->drawDot(Vec2(0, 0), 5, Color4F(1, 0, 0, 1)); // 当前页红点
|
|
|
|
|
|
// 将 PageView 添加到父节点 node 中
|
|
|
- node->addChild(pageView);
|
|
|
+ node->addChild(cardView);
|
|
|
|
|
|
return node;
|
|
|
}
|