#include "ShowScene.h" #include "MissionWeiXin.h" #include "SimpleAudioEngine.h" #include "UserInfo.h" #include "GlobalJosn.h" ShowScene::ShowScene() { m_rootPanel = nullptr; } ShowScene::~ShowScene() { } bool ShowScene::init() { if (!Node::init()) { return false; }; auto rootPanel = CSLoader::createNode("Platform/ShowScene.csb"); CC_ASSERT(rootPanel != nullptr); this->addChild(rootPanel); m_rootPanel = (ImageView*)rootPanel->getChildByName("Imagebg"); CC_ASSERT(m_rootPanel != nullptr); //获取关闭按钮 auto btnClose = (Button*)m_rootPanel->getChildByName("btnClose"); CC_ASSERT(btnClose != nullptr); //注册关闭按钮事件 btnClose->addClickEventListener([this](Ref*){ YSAudioEngine::Instance().playBtnClickEffect(); //this->removeFromParent(); this->popScene(); }); // 微信 auto btnWeiXin = (Button*)m_rootPanel->getChildByName("btnWeiXin"); CC_ASSERT(btnWeiXin != nullptr); //注册关闭按钮事件 btnWeiXin->addClickEventListener([this](Ref*){ YSAudioEngine::Instance().playBtnClickEffect(); std::string strUrl = GlobalJosn::getInstance()->getShareInfoByKind(SH_KIND_WEIXIN_URL); std::string strTitle = GlobalJosn::getInstance()->getShareInfoByKind(SH_KIND_WEIXIN_TITLE); std::string strComment = GlobalJosn::getInstance()->getShareInfoByKind(SH_KIND_WEIXIN_COMMET); MissionWeiXin::Instance().shareUrlWeiXin(strUrl, strTitle, strComment); this->removeFromParent(); }); // 朋友圈 auto btnMoments = (Button*)m_rootPanel->getChildByName("btnMoments"); CC_ASSERT(btnMoments != nullptr); //注册关闭按钮事件 btnMoments->addClickEventListener([this](Ref*){ YSAudioEngine::Instance().playBtnClickEffect(); std::string strUrl = GlobalJosn::getInstance()->getShareInfoByKind(SH_KIND_FRIEND_RUL); std::string strTitle = GlobalJosn::getInstance()->getShareInfoByKind(SH_KIND_FRIEND_TITLE); std::string strComment = GlobalJosn::getInstance()->getShareInfoByKind(SH_KIND_FRIEND_COMMET); MissionWeiXin::Instance().shareUrlWeiXin(strUrl, strTitle, strTitle, 1); #if (CC_TARGET_PLATFORM==CC_PLATFORM_WIN32) auto dispatcher = Director::getInstance()->getEventDispatcher(); EventCustom event(WXSHARE_FRIENDS_SUCCESS); //派发创建游戏事件至ShowScene dispatcher->dispatchEvent(&event); #endif this->removeFromParent(); }); // txtTip; auto txtTip = (Text*)m_rootPanel->getChildByName("txtTip"); ASSERT(txtTip != nullptr); txtTip->setString(GlobalJosn::getInstance()->m_strShareTip); return true; } void ShowScene::onEnter() { Node::onEnter(); } void ShowScene::onEnterTransitionDidFinish() { Node::onEnterTransitionDidFinish(); } void ShowScene::onExit() { Node::onExit(); } void ShowScene::pushScene() { if (m_rootPanel) { this->setVisible(true); m_rootPanel->setScale(0.8f); m_rootPanel->runAction(Sequence::create(Show::create(), ScaleTo::create(0.2f, 1.2f), ScaleTo::create(0.1f, 1.f), CallFunc::create([&]() { }), nullptr)); } } void ShowScene::popScene() { if (m_rootPanel) { m_rootPanel->runAction(Sequence::create(Hide::create(), ScaleTo::create(0.1f, 0.1f), CallFunc::create([&]() { this->setVisible(false); }), nullptr)); } }