Browse Source

优化暴露在.h文件中的内部文件

MoYuWang 9 months ago
parent
commit
494462b2e7

+ 11 - 3
Classes/IAP/IAPCtlShop.cpp

@@ -4,14 +4,18 @@
 //
 //  Created by 徐炼新 on 2024/9/30.
 //
-#include "cocos2d.h"
 
 #include "IAPCtlShop.hpp"
-#include "IAPCtlShopUI.hpp"
-#include "IAPConf.hpp"
+
+#include "cocos2d.h"
+
 #include "RUBaseConf.h"
 #include "RUUtils.h"
 
+#include "IAPConf.hpp"
+#include "IAPCtlShopUI.hpp"
+#include "IAPUserData.hpp"
+
 NS_IAP_BEGIN
 
 IAPCtlShop* IAPCtlShop::_instance = nullptr;
@@ -74,4 +78,8 @@ void IAPCtlShop::showPlacementsInNode(cocos2d::Node *pParent, const vector<std::
     
 }
 
+void IAPCtlShop::clearUserBuyInfo(){
+    iap::IAPUserData::getInstance()->clearBuyInfo();
+}
+
 NS_IAP_END

+ 6 - 2
Classes/IAP/IAPCtlShop.hpp

@@ -11,10 +11,11 @@
 #include <stdio.h>
 #include "cocos2d.h"
 #include "IAPDefine.hpp"
-#include "IAPCtlShopUI.hpp"
 #include "IAPDelegate.hpp"
 
-#include "IAPConf.hpp"
+
+class IAPConf;
+class IAPCtlShopUI;
 
 NS_IAP_BEGIN
 
@@ -59,6 +60,9 @@ public:
     // plIds 需要的版位id
     void showPlacementsInNode(cocos2d::Node* pParent, const vector<std::string>& plIds);
     
+    // 清除用户购买信息
+    void clearUserBuyInfo();
+    
 private:
     static IAPCtlShop* _instance;
     

+ 3 - 1
Classes/IAP/Shop/IAPCtlShopItem.cpp

@@ -6,14 +6,16 @@
 //
 
 #include "IAPCtlShopItem.hpp"
+
 #include "IAPCtlArea23.hpp"
 #include "IAPProcess.hpp"
-#include "IAPCtlShopUI.hpp"
 #include "IAPSucessProcess.hpp"
 #include "IAPDelegate.hpp"
 #include "RUUtils.h"
 
+#include "IAPConf.hpp"
 #include "IAPUserData.hpp"
+#include "IAPCtlShopUI.hpp"
 
 IAPCtlShopItem* IAPCtlShopItem::create(const GoodsInfo& gi, int placementId) {
     IAPCtlShopItem* csi = new IAPCtlShopItem(gi);

+ 52 - 79
Classes/IAP/Shop/IAPCtlShopUI.cpp

@@ -5,13 +5,15 @@
 //  Created by 徐炼新 on 2024/1/16.
 //
 
-#include "IAPCtlShopUI.hpp"
-#include "IAPCtlShopItem.hpp"
+#include "IAPCtlShop.hpp"
+
 #include "RUUtils.h"
 #include "RUPlatform.h"
 
-#include "IAPCtlShop.hpp"
+#include "IAPConf.hpp"
 #include "IAPUserData.hpp"
+#include "IAPCtlShopUI.hpp"
+#include "IAPCtlShopItem.hpp"
 #include <regex>
 
 IAPCtlShopUI* IAPCtlShopUI::_instance = nullptr;
@@ -47,42 +49,6 @@ void IAPCtlShopUI::clear() {
     _cb = nullptr;
 }
 
-bool IAPCtlShopUI::create(Node* pNode, IAPConf* cfg, int placementId) {
-    redutils::Platform::getInstance()->reportLog("open iap");
-    _cfg = cfg;
-    _bUIShowing = true;
-    _placementId = placementId;
-    clear();
-    
-    _layer = redutils::RUReboltLayer::createReboltLayer("shop_interface.redream");
-    pNode->addChild(_layer, 3);
-    _layer->registerOnNotify([this](const redutils::ReboltNotifyData& data){
-        _onNotifyDevelopment(data);
-    });
-    _layer->runBehaviacWhitFunName("初始化");
-    
-//    _igCoin->doOwnInit();
-    
-    if (_goodsInfo.size() == 0) { 
-        IAPConf::getInstance()->getAllGoods(_goodsInfo);
-    }
-    
-    // 构建 list 区域
-    constructShopItem(false);
-    cocos2d::Size size = _ndScrollArea->getContentSize();
-    _tableView = redutils::RUTableView::create(&_tableData, cocos2d::Size(size.width, size.height));
-    _tableView->setCascadeOpacityEnabled(true);
-    _tableView->setCascadeColorEnabled(true);
-    _tableView->setDirection(ScrollViewSmooth::Direction::VERTICAL);
-    _tableView->setVerticalFillOrder(TableViewSmooth::VerticalFillOrder::TOP_DOWN, false);
-    _tableView->setDelegate(&_tableData);
-    _tableView->setBounceable(true);
-//    _tableView->setOutSightClean(false);
-    _ndScrollArea->addChild(_tableView);
-    
-    return true;
-}
-
 bool IAPCtlShopUI::create(Node* pNode, IAPConf* cfg, iap::ShopRequirement& requirement,int placementId) {
     redutils::Platform::getInstance()->reportLog("open iap");
     _cfg = cfg;
@@ -183,7 +149,7 @@ void IAPCtlShopUI::constructShopItem(bool bShowAll) {
             break;
     }
     // 当前有效的区域
-    int bigPackCount,SmallPackCount; // 需要显示的礼包
+    int bigPackCount,smallPackCount; // 需要显示的礼包
     auto iapCtlShop = iap::IAPCtlShop::createWith();
     int leval = iapCtlShop->getDeviceLevel();
     size_t placementCount = iapCtlShop->getPlacementCount();
@@ -191,7 +157,7 @@ void IAPCtlShopUI::constructShopItem(bool bShowAll) {
         case 1:
             // 低等级
             bigPackCount = 2;
-            SmallPackCount = 1;
+            smallPackCount = 1;
             break;
         case 2:
             // 中等级
@@ -199,10 +165,10 @@ void IAPCtlShopUI::constructShopItem(bool bShowAll) {
         case 3:
             if(placementCount >= 2){
                 bigPackCount = 3;
-                SmallPackCount = 0;
+                smallPackCount = 0;
             }else{
                 bigPackCount = 2;
-                SmallPackCount = 2;
+                smallPackCount = 2;
             }
             // 高等级
             break;
@@ -210,47 +176,54 @@ void IAPCtlShopUI::constructShopItem(bool bShowAll) {
             break;
     }
     
-    // 显示商品
-    for (const auto& gi : _goodsInfo) {
-        // 判断是否显示
-        bool isShow = false;
-        if (bShowAll) {
-            isShow = true;
-        }else{
-            if(gi.type == "panel" && bigPackCount > 0){
-                isShow = true;
-                bigPackCount--;
-            }
-            if(gi.type == "bar" && SmallPackCount > 0){
+    // 展示活动商品
+    
+    
+    // 判断是否还有版位
+    if(bigPackCount != 0 || smallPackCount != 0 || bShowAll){
+        // 显示常规商品
+        for (const auto& gi : _goodsInfo) {
+            // 判断是否显示
+            bool isShow = false;
+            if (bShowAll) {
                 isShow = true;
-                SmallPackCount--;
+            }else{
+                if(gi.type == "panel" && bigPackCount > 0){
+                    isShow = true;
+                    bigPackCount--;
+                }
+                if(gi.type == "bar" && smallPackCount > 0){
+                    isShow = true;
+                    smallPackCount--;
+                }
             }
-        }
-        // 商品显示
-        if (isShow) {
-            bool bNeedAnim = height <= size.height;
-            Node* nd = Node::create();
-            nd->setCascadeOpacityEnabled(true);
-            nd->setCascadeColorEnabled(true);
-            auto si = IAPCtlShopItem::create(gi, _placementId);
-            auto sz = si->getSize();
-            cocos2d::Vec2 pos(size.width/2.0, sz.height/2.0);
-            nd->addChild(si);
-            si->setPosition(bNeedAnim ? pos+offset : pos);
-            _goodsItems.push_back(si);
-            _tableData.insertCell(index++, nd);
-            _allSizes.push_back(sz);
-            height += sz.height;
-            
-            if (bNeedAnim) {
-                // 加入动画
-                auto d = DelayTime::create(delayIdx*dur/8.0);
-                auto m = EaseBackOut::create(MoveBy::create(dur, cocos2d::Vec2(-offset.x, offset.y)));
-                si->runAction(Sequence::create(d, m, NULL));
-                delayIdx ++;
+            // 商品显示
+            if (isShow) {
+                bool bNeedAnim = height <= size.height;
+                Node* nd = Node::create();
+                nd->setCascadeOpacityEnabled(true);
+                nd->setCascadeColorEnabled(true);
+                auto si = IAPCtlShopItem::create(gi, _placementId);
+                auto sz = si->getSize();
+                cocos2d::Vec2 pos(size.width/2.0, sz.height/2.0);
+                nd->addChild(si);
+                si->setPosition(bNeedAnim ? pos+offset : pos);
+                _goodsItems.push_back(si);
+                _tableData.insertCell(index++, nd);
+                _allSizes.push_back(sz);
+                height += sz.height;
+                
+                if (bNeedAnim) {
+                    // 加入动画
+                    auto d = DelayTime::create(delayIdx*dur/8.0);
+                    auto m = EaseBackOut::create(MoveBy::create(dur, cocos2d::Vec2(-offset.x, offset.y)));
+                    si->runAction(Sequence::create(d, m, NULL));
+                    delayIdx ++;
+                }
             }
         }
     }
+    
     // 添加展示所有按钮
     if (!bShowAll) {
         // 加入show All btn, 这个是一定会有动画的

+ 1 - 2
Classes/IAP/Shop/IAPCtlShopUI.hpp

@@ -12,11 +12,11 @@
 #include "cocos2d.h"
 #include "RUReboltLayer.h"
 #include "RUTableView.h"
-#include "IAPConf.hpp"
 #include "IAPDefine.hpp"
 
 class IAPCtlShopItem;
 class MapIGCoin;
+class IAPConf;
 
 class IAPCtlShopUI : public cocos2d::Ref
 {
@@ -24,7 +24,6 @@ public:
     static IAPCtlShopUI* getInstance();
     
     // 在指定节点内创建
-    bool create(cocos2d::Node* pParent, IAPConf* cfg, int placementId = 1);
     bool create(cocos2d::Node* pNode, IAPConf* cfg, iap::ShopRequirement& requirement,int placementId = 1);
     
     // 设置退出时的回调

+ 3 - 10
Classes/TestScene.cpp

@@ -8,12 +8,9 @@
 #include "TestScene.h"
 #include "RUPlatform.h"
 
-#include "IAPCtlShopUI.hpp"
 #include "IAPCtlShop.hpp"
 #include "IAPDefine.hpp"
 
-#include "IAPUserData.hpp"
-
 USING_NS_CC;
 
 Scene* TestScene::createScene(){
@@ -46,11 +43,6 @@ bool TestScene::init(){
 
 void TestScene::createBoard(){
 
-//    auto iapConf = IAPConf::getInstance();
-//    iapConf->initWith();
-//    auto iapCtlShopUi = IAPCtlShopUI::getInstance();
-//    iapCtlShopUi->create(this, iapConf);
-//
     auto lyMap = redutils::RUReboltLayer::createReboltLayer("lyMap.redream");
     this->addChild(lyMap);
 //    log(lyMap->getChildrenCount());
@@ -59,7 +51,6 @@ void TestScene::createBoard(){
     });
     lyMap->runBehaviacWhitFunName("初始化");
     
-//    _igCoin->doOwnInit();
 }
 
 
@@ -85,8 +76,10 @@ void TestScene::onNotifyDevelopment(const redutils::ReboltNotifyData& data){
         
         _iapShop->showInNode(this, shopRequirement);
     }else if(data.notify == "点击重置"){
+        
         _iapShop->setDeviceLevel(1);
-        iap::IAPUserData::getInstance()->clearBuyInfo();
+        _iapShop->clearUserBuyInfo();
+
         log("重置为低等级设备,且清除用户购买信息");
     }
 }