// // IAPCtlShopItem.cpp // TileManor // // Created by 徐炼新 on 2024/1/17. // #include "IAPCtlShopItem.hpp" #include "IAPCtlArea23.hpp" #include "IAPProcess.hpp" #include "IAPSucessProcess.hpp" #include "IAPShopDelegate.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); csi->_placementId = placementId; csi->autorelease(); csi->retain(); return csi; } IAPCtlShopItem::IAPCtlShopItem(const GoodsInfo& gi) : _gi(gi) { } IAPCtlShopItem::~IAPCtlShopItem() { if (_ctlArea23) { _ctlArea23->release(); } } cocos2d::Size IAPCtlShopItem::getSize() { return _gi.sz; } void IAPCtlShopItem::onEnter() { Node::onEnter(); if (_layer == nullptr) { initUI(); setCascadeOpacityEnabled(true); setCascadeColorEnabled(true); redutils::iterateNode(this, [](Node* nd){ nd->setCascadeOpacityEnabled(true); nd->setCascadeColorEnabled(true); }); } } bool IAPCtlShopItem::initUI() { if (_gi.type == "bar") { _layer = redutils::RUReboltLayer::createReboltLayer("shop_panel_2.redream"); } else { _layer = redutils::RUReboltLayer::createReboltLayer("shop_panel_1.redream"); if (_gi.style == "normal") { _layer->setCoderDataVar("P-tStyle", "1"); } else if (_gi.style == "mostValued") { _layer->setCoderDataVar("P-tStyle", "2"); } else if (_gi.style == "special") { _layer->setCoderDataVar("P-tStyle", "3"); } _layer->setCoderDataVar("P-tSlogon", _gi.slogon); _layer->setCoderDataVar("P-tHint", _gi.hint); } _layer->setCoderDataVar("P-tCost", _gi.cost); _layer->setCoderDataVar("P-tCoins", _gi.areas.front().front().count); std::string strCoins; // 从后往前遍历,每隔3个数增加一个空格 for (int i=_gi.areas.front().front().count.size()-1; i>=0; i--) { if (strCoins.size() > 0 && (strCoins.size() == 3 || strCoins.size() == 7)) { strCoins = " " + strCoins; } strCoins = std::string(1, _gi.areas.front().front().count.at(i)) + strCoins; } _layer->setCoderDataVar("P-tLbCoins", strCoins); addChild(_layer); _layer->registerOnNotify([this](const redutils::ReboltNotifyData& data){ onNotifyDevelopment(data); }); _layer->runBehaviacWhitFunName("初始化"); if (_ctlArea23) { _ctlArea23->doOwnInit(); } return true; } void IAPCtlShopItem::onNotifyDevelopment(const redutils::ReboltNotifyData& data) { if (data.notify == "绑定展示区23") { _ctlArea23 = IAPCtlArea23::create(data.reboltRedManager, _gi); } else if (data.notify == "点击购买") { // 展示正在购买中的界面 IAPProcess::getInstance()->buy(_gi, _placementId, [=](){ accepted(); }, [=](){ rejected(); }); } } void IAPCtlShopItem::accepted() { // 退出购买界面,展示成功界面 IAPCtlShopUI::getInstance()->quit(); } void IAPCtlShopItem::rejected() { }