Browse Source

添加了一些测试代码

MoYuWang 9 months ago
parent
commit
0e664503cf

+ 5 - 11
Classes/IAP/IAPCtlShop.cpp

@@ -62,22 +62,12 @@ void IAPCtlShop::displayFailureCardIn(cocos2d::Node *node){
     
     PurchaseBannerView* view = PurchaseBannerView::create(sz, dot, true);
     std::vector<std::string> names;
-    if(_delegate)names = _delegate->getCardNameWhenFailed();
+    if(_delegate)names = _delegate->getCardsNameWhenFailed();
     for(const auto& name : names){
         PurchaseBannerCell* tmpNode = PurchaseBannerCell::create(name);
         view->addBanner(tmpNode);
     }
     
-//    // 测试暂用
-//    PurchaseBannerCell* tmpNode1 = PurchaseBannerCell::create("礼包1");
-//    view->addBanner(tmpNode1);
-//    PurchaseBannerCell* tmpNode2 = PurchaseBannerCell::create("tilefavor");
-//    view->addBanner(tmpNode2);
-//    PurchaseBannerCell* tmpNode3 = PurchaseBannerCell::create("tilepack");
-//    view->addBanner(tmpNode3);
-//    PurchaseBannerCell* tmpNode4 = PurchaseBannerCell::create("tilepass");
-//    view->addBanner(tmpNode4);
-    
     node->addChild(view);
 }
 
@@ -114,6 +104,10 @@ void IAPCtlShop::showInNode(cocos2d::Node *pParent, ShopRequirement &requirement
     IAPCtlShopUI::getInstance()->create(pParent, _conf, requirement);
 }
 
+void IAPCtlShop::showSlideCardsByCoinsIn(cocos2d::Node* pParent, int stillNeedCoins){
+    IAPCtlShopUI::getInstance()->showSlideCardsByCoinsIn(pParent, stillNeedCoins);
+}
+
 UserBuyType IAPCtlShop::getUserBuyType(){
     // 如果没有购买记录
     auto buyInfos = IAPUserData::getInstance()->getBuyInfos();

+ 5 - 0
Classes/IAP/IAPCtlShop.hpp

@@ -75,6 +75,11 @@ public:
     // requirement 对商店的要求,比如说最低金币数
     void showInNode(cocos2d::Node* pParent, ShopRequirement& requirement);
     
+    // 以滑动卡片的形式在某个节点中显示满足金币条件的所有商店卡片
+    // pParent 父节点
+    // stillNeedCoins 距离所需要的金币数还差多少金币
+    void showSlideCardsByCoinsIn(cocos2d::Node* pParent, int stillNeedCoins);
+    
     // 获取用户类型
     UserBuyType getUserBuyType();
     

+ 1 - 1
Classes/IAP/IAPDelegate.hpp

@@ -22,7 +22,7 @@ public:
 //    virtual int getStillNeedCoinsWhenFailed() = 0;
     
     // 获取失败时需要显示的卡片名称
-    virtual std::vector<std::string> getCardNameWhenFailed() = 0;
+    virtual std::vector<std::string> getCardsNameWhenFailed() = 0;
 };
 
 

+ 1 - 1
Classes/IAP/Shop/IAPCtlShopUI.cpp

@@ -99,7 +99,7 @@ bool IAPCtlShopUI::create(Node* pNode, IAPConf* cfg, iap::ShopRequirement& requi
     return true;
 }
 
-void IAPCtlShopUI::displayFailureCardIn(cocos2d::Node *pNode, int stillNeedCoins){
+void IAPCtlShopUI::showSlideCardsByCoinsIn(cocos2d::Node *pNode, int stillNeedCoins){
     clear();
     
     IAPCardView::sDotCfg cfg;

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

@@ -26,10 +26,10 @@ public:
     // 在指定节点内创建
     bool create(cocos2d::Node* pNode, IAPConf* cfg, iap::ShopRequirement& requirement,int placementId = 1);
     
-    // 以滑动卡片的形式在某个节点中显示某些版位(适用于失败时的场景)
+    // 以滑动卡片的形式在某个节点中显示满足金币条件的所有商店卡片
     // pParent 父节点
     // stillNeedCoins 距离所需要的金币数还差多少金币
-    void displayFailureCardIn(cocos2d::Node* pNode, int stillNeedCoins);
+    void showSlideCardsByCoinsIn(cocos2d::Node* pNode, int stillNeedCoins);
     
     // 添加一个商店版位
     // id 卡片id(添加版位时的id)

+ 32 - 0
Classes/IAPDelegateImpl.cpp

@@ -0,0 +1,32 @@
+//
+//  IAPDelegateImpl.cpp
+//  demo
+//
+//  Created by Red_mini on 2024/10/30.
+//
+
+#include "IAPDelegateImpl.hpp"
+
+
+IAPDelegateImpl* IAPDelegateImpl::createWith(){
+    IAPDelegateImpl* ret = new IAPDelegateImpl();
+    
+    return ret;
+}
+
+// 用户成功购买通知
+void IAPDelegateImpl::onUserBuySuccess(std::map<std::string, string> buyInfos){
+    for(const auto& buyInfo : buyInfos){
+        printf("道具名称: %s , 道具数量: %d\n", buyInfo.first.c_str(), stoi(buyInfo.second));
+    }
+}
+
+// 获取失败时需要显示的卡片名称
+std::vector<std::string> IAPDelegateImpl::getCardsNameWhenFailed(){
+    std::vector<std::string> names;
+//    names.push_back("礼包1");
+    names.push_back("tilefavor");
+    names.push_back("tilepack");
+    names.push_back("tilepass");
+    return names;
+}

+ 28 - 0
Classes/IAPDelegateImpl.hpp

@@ -0,0 +1,28 @@
+//
+//  IAPDelegateImpl.hpp
+//  demo
+//
+//  Created by Red_mini on 2024/10/30.
+//
+
+#ifndef IAPDelegateImpl_hpp
+#define IAPDelegateImpl_hpp
+
+#include <stdio.h>
+
+#include "IAPDelegate.hpp"
+
+// 该类用于测试
+class IAPDelegateImpl : public IAPDelegate{
+public:
+    static IAPDelegateImpl* createWith();
+    
+    // 用户成功购买通知
+    virtual void onUserBuySuccess(std::map<std::string, string> buyInfo) override;
+    
+    // 获取失败时需要显示的卡片名称
+    virtual std::vector<std::string> getCardsNameWhenFailed() override;
+    
+};
+
+#endif /* IAPDelegateImpl_hpp */

+ 4 - 0
Classes/TestScene.cpp

@@ -12,6 +12,7 @@
 #include "IAPDefine.hpp"
 
 #include "IAPTestCard.hpp"
+#include "IAPDelegateImpl.hpp"
 
 USING_NS_CC;
 
@@ -35,6 +36,9 @@ bool TestScene::init(){
     std::string failFN = "purchaseBannerConfig.csv";
     
     _iapShop = iap::IAPCtlShop::createWith();
+    auto delegate = IAPDelegateImpl::createWith();
+    _iapShop->setDelegate(delegate);
+    
     _iapShop->init(cfgFN);
     _iapShop->setCfg4Failure(failFN);
     

+ 8 - 0
proj.ios_mac/demo.xcodeproj/project.pbxproj

@@ -69,6 +69,8 @@
 		C19B68B22CD1E50600536ED4 /* PurchaseBannerView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C19B68AF2CD1E50600536ED4 /* PurchaseBannerView.cpp */; };
 		C19B68B52CD1E51300536ED4 /* RedreamLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C19B68B32CD1E51300536ED4 /* RedreamLoader.cpp */; };
 		C19B68B62CD1E51300536ED4 /* RedreamLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C19B68B32CD1E51300536ED4 /* RedreamLoader.cpp */; };
+		C19B68BF2CD222A400536ED4 /* IAPDelegateImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C19B68BD2CD222A400536ED4 /* IAPDelegateImpl.cpp */; };
+		C19B68C02CD222A400536ED4 /* IAPDelegateImpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C19B68BD2CD222A400536ED4 /* IAPDelegateImpl.cpp */; };
 		D44C620C132DFF330009C878 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D44C620B132DFF330009C878 /* OpenAL.framework */; };
 		D44C620E132DFF430009C878 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D44C620D132DFF430009C878 /* AVFoundation.framework */; };
 		D44C6210132DFF4E0009C878 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D44C620F132DFF4E0009C878 /* AudioToolbox.framework */; };
@@ -227,6 +229,8 @@
 		C19B68B32CD1E51300536ED4 /* RedreamLoader.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RedreamLoader.cpp; sourceTree = "<group>"; };
 		C19B68B42CD1E51300536ED4 /* RedreamLoader.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = RedreamLoader.hpp; sourceTree = "<group>"; };
 		C19B68B72CD2007B00536ED4 /* rapidcsv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = rapidcsv.h; sourceTree = "<group>"; };
+		C19B68BD2CD222A400536ED4 /* IAPDelegateImpl.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = IAPDelegateImpl.cpp; sourceTree = "<group>"; };
+		C19B68BE2CD222A400536ED4 /* IAPDelegateImpl.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = IAPDelegateImpl.hpp; sourceTree = "<group>"; };
 		D44C620B132DFF330009C878 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; };
 		D44C620D132DFF430009C878 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
 		D44C620F132DFF4E0009C878 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
@@ -484,6 +488,8 @@
 				46880B8519C43A87006E1F66 /* AppDelegate.h */,
 				C17ACCC52CB904460072A711 /* TestScene.h */,
 				C17ACCBB2CB903BA0072A711 /* TestScene.cpp */,
+				C19B68BE2CD222A400536ED4 /* IAPDelegateImpl.hpp */,
+				C19B68BD2CD222A400536ED4 /* IAPDelegateImpl.cpp */,
 			);
 			name = Classes;
 			path = ../Classes;
@@ -789,6 +795,7 @@
 				C19B68A42CD1E4C800536ED4 /* PBConfigData.cpp in Sources */,
 				C17946172CC7502600779B63 /* IAPTestCard.cpp in Sources */,
 				E4D223422BD667D4006F1F8D /* AdUtilsVideo.cpp in Sources */,
+				C19B68BF2CD222A400536ED4 /* IAPDelegateImpl.cpp in Sources */,
 				2F15E2402CB52B0F00082BF8 /* IAPProductInfo.cpp in Sources */,
 				E4D223482BD667E8006F1F8D /* AdUtils.cpp in Sources */,
 				C19B68B52CD1E51300536ED4 /* RedreamLoader.cpp in Sources */,
@@ -829,6 +836,7 @@
 				C19B68B62CD1E51300536ED4 /* RedreamLoader.cpp in Sources */,
 				2F15E2432CB52B0F00082BF8 /* IAPUtils.cpp in Sources */,
 				2F15C5F82CB8F65A0057855D /* IAPUserData.cpp in Sources */,
+				C19B68C02CD222A400536ED4 /* IAPDelegateImpl.cpp in Sources */,
 				C17ACCBD2CB903BA0072A711 /* TestScene.cpp in Sources */,
 				2F15C5F52CB8F65A0057855D /* IAPCtlArea23.cpp in Sources */,
 				C18082342CCB71D3009DE140 /* IAPTestCardViewDelegate.cpp in Sources */,