Files
wnmj/Classes/Scenes/SelectShareScene.cpp
2026-02-13 14:34:15 +08:00

196 lines
4.5 KiB
C++

#include "SelectShareScene.h"
#include "cocos2d.h"
#include "ui/CocosGUI.h"
#include "cocostudio/CocoStudio.h"
#include "types.h"
#include "YSAudioEngine.h"
#include "MissionWeiXin.h"
#include "JniFun.h"
SINGLETON_STORAGE(SelectShareScene);
SelectShareScene::SelectShareScene()
{
m_pRootNode = nullptr;
m_strShareType = "";
m_isShareImage = true;
init();
}
SelectShareScene::~SelectShareScene()
{
m_pRootNode = nullptr;
}
bool SelectShareScene::init()
{
auto rootPanel = CSLoader::createNode("Platform/SelectShareScene.csb");
CC_ASSERT(rootPanel != nullptr);
this->addChild(rootPanel);
m_pRootNode = (Layout*)rootPanel->getChildByName("Panelbg");
CC_ASSERT(m_pRootNode != nullptr);
m_pRootNode->addClickEventListener([this](Ref*){
YSAudioEngine::Instance().playBtnClickEffect();
this->removeFromParent();
});
ImageView* imgSharebg = (ImageView*)m_pRootNode->getChildByName("Imagebg");
ASSERT(imgSharebg != nullptr);
m_btnWinxin = (Button*)imgSharebg->getChildByName("btnWeiXin");
m_btnXL = (Button*)imgSharebg->getChildByName("btnXianLiao");
ASSERT(m_btnWinxin != nullptr);
m_btnWinxin->addClickEventListener([this](Ref*){
YSAudioEngine::Instance().playBtnClickEffect();
if (m_pRootNode != nullptr)
{
this->setVisible(false);
if (m_isShareImage)
{
CallFunc* tmpBack = CallFunc::create([this]{
std::function<void(bool, const std::string&)> afterCaptured = [this](bool bSucceed, std::string name)
{
if (bSucceed)
{
MissionWeiXin::Instance().shareScreenWeiXin(name);
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
// 删除文件;
FileUtils::getInstance()->removeFile(name);
#endif
}
};
//// 获取内置SD卡路径;
//std::string strScreenShot = JniFun::getInnerSDCardPath() + "screenshot.jpg";
//cocos2d::utils::captureScreen(afterCaptured, strScreenShot);
cocos2d::utils::captureScreen(afterCaptured, "screenshot.jpg");
this->removeFromParent();
});
m_btnWinxin->runAction(Sequence::create(DelayTime::create(0.2f), tmpBack, nullptr));
}
else
{
MissionWeiXin::Instance().shareUrlWeiXin(m_ShareItem.strkUrl, m_ShareItem.strkTitle, utility::a_u8(m_ShareItem.strkDesc));
this->removeFromParent();
}
}
});
ASSERT(m_btnXL != nullptr);
m_btnXL->addClickEventListener([this](Ref*){
YSAudioEngine::Instance().playBtnClickEffect();
if (m_pRootNode != nullptr)
{
// 通知分享;
m_pRootNode->setVisible(false);
if (m_isShareImage)
{
CallFunc* tmpBack = CallFunc::create([this]{
std::function<void(bool, const std::string&)> afterCaptured = [this](bool bSucceed, std::string name)
{
if (bSucceed)
{
MissionWeiXin::Instance().shareScreenXL(name);
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
// 删除文件;
FileUtils::getInstance()->removeFile(name);
#endif
}
};
// 获取内置SD卡路径;
//std::string strScreenShot = JniFun::getInnerSDCardPath() + "screenshot.jpg";
//cocos2d::utils::captureScreen(afterCaptured, strScreenShot);
cocos2d::utils::captureScreen(afterCaptured, "screenshot.jpg");
this->removeFromParent();
});
m_btnXL->runAction(Sequence::create(DelayTime::create(0.2f), tmpBack, nullptr));
}
else
{
MissionWeiXin::Instance().shareUrlXL(m_ShareItem.strkUrl, m_ShareItem.strkTitle, utility::a_u8(m_ShareItem.strkDesc));
this->removeFromParent();
}
}
});
return true;
}
void SelectShareScene::onEnter()
{
Node::onEnter();
}
void SelectShareScene::onEnterTransitionDidFinish()
{
Node::onEnterTransitionDidFinish();
}
void SelectShareScene::onExit()
{
Node::onExit();
}
void SelectShareScene::shareImage()
{
if (m_pRootNode == nullptr) return;
//如果没有被加入场景则加入当前运行场景
if (getParent() == nullptr)
{
Scene* pScene = Director::getInstance()->getRunningScene();
pScene->addChild(this, 999);
}
m_isShareImage = true;
m_pRootNode->setVisible(true);
this->setVisible(true);
}
void SelectShareScene::HideDlg()
{
if (m_pRootNode != nullptr)
{
m_pRootNode->setVisible(false);
}
}
void SelectShareScene::shareRoomInfo(std::string kUrl, std::string kTitle, std::string kDesc, int nShareType)
{
if (m_pRootNode == nullptr) return;
//如果没有被加入场景则加入当前运行场景
if (getParent() == nullptr)
{
Scene* pScene = Director::getInstance()->getRunningScene();
pScene->addChild(this, 999);
}
m_isShareImage = false;
m_ShareItem.strkUrl = kUrl;
m_ShareItem.strkTitle = kTitle;
m_ShareItem.strkDesc = kDesc;
m_ShareItem.nShareType = nShareType;
m_pRootNode->setVisible(true);
this->setVisible(true);
}