Files
wnmj-normal/Classes/Scenes/SelectShareScene.cpp
2026-03-03 13:56:44 +08:00

196 lines
4.6 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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
// ɾ<><C9BE><EFBFBD>ļ<EFBFBD>;
FileUtils::getInstance()->removeFile(name);
#endif
}
};
//// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>SD<53><44>·<EFBFBD><C2B7>;
//std::string strScreenShot = JniFun::getInnerSDCardPath() + "screenshot.jpg";
//cocos2d::utils::captureScreen(afterCaptured, strScreenShot);
cocos2d::utils::captureScreen(afterCaptured, "screenshot.png");
this->removeFromParent();
});
m_btnWinxin->runAction(Sequence::create(DelayTime::create(0.2f), tmpBack, nullptr));
}
else
{
MissionWeiXin::Instance().shareUrlWeiXin(m_ShareItem.strkUrl, m_ShareItem.strkTitle, m_ShareItem.strkDesc);
this->removeFromParent();
}
}
});
ASSERT(m_btnXL != nullptr);
m_btnXL->addClickEventListener([this](Ref*){
YSAudioEngine::Instance().playBtnClickEffect();
if (m_pRootNode != nullptr)
{
// ֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD>;
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
// ɾ<><C9BE><EFBFBD>ļ<EFBFBD>;
FileUtils::getInstance()->removeFile(name);
#endif
}
};
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>SD<53><44>·<EFBFBD><C2B7>;
//std::string strScreenShot = JniFun::getInnerSDCardPath() + "screenshot.jpg";
//cocos2d::utils::captureScreen(afterCaptured, strScreenShot);
cocos2d::utils::captureScreen(afterCaptured, "screenshot.png");
this->removeFromParent();
});
m_btnXL->runAction(Sequence::create(DelayTime::create(0.2f), tmpBack, nullptr));
}
else
{
MissionWeiXin::Instance().shareUrlXL(m_ShareItem.strkUrl, m_ShareItem.strkTitle, 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;
//<2F><><EFBFBD>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EBB3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뵱ǰ<EBB5B1><C7B0><EFBFBD>г<EFBFBD><D0B3><EFBFBD>
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;
//<2F><><EFBFBD>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EBB3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뵱ǰ<EBB5B1><C7B0><EFBFBD>г<EFBFBD><D0B3><EFBFBD>
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);
}