172 lines
4.3 KiB
C++
172 lines
4.3 KiB
C++
|
|
#include "NoticeScene.h"
|
|||
|
|
#include "MissionWeiXin.h"
|
|||
|
|
#include "SimpleAudioEngine.h"
|
|||
|
|
#include "UserInfo.h"
|
|||
|
|
#include "GlobalJosn.h"
|
|||
|
|
|
|||
|
|
NoticeScene::NoticeScene()
|
|||
|
|
{
|
|||
|
|
m_rootPanel = nullptr;
|
|||
|
|
|
|||
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
|||
|
|
m_layerLoading = nullptr;
|
|||
|
|
m_sprLoading = nullptr;
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
NoticeScene::~NoticeScene()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool NoticeScene::init()
|
|||
|
|
{
|
|||
|
|
if (!Node::init())
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
auto rootPanel = CSLoader::createNode("Platform/NoticeScene.csb");
|
|||
|
|
CC_ASSERT(rootPanel != nullptr);
|
|||
|
|
this->addChild(rootPanel);
|
|||
|
|
|
|||
|
|
m_rootPanel = rootPanel->getChildByName("Image_bg");
|
|||
|
|
CC_ASSERT(m_rootPanel!=nullptr);
|
|||
|
|
|
|||
|
|
//<2F><>ȡ<EFBFBD>رհ<D8B1>ť
|
|||
|
|
auto btnClose = (Button*)m_rootPanel->getChildByName("btnClose");
|
|||
|
|
CC_ASSERT(btnClose != nullptr);
|
|||
|
|
|
|||
|
|
//ע<><D7A2><EFBFBD>رհ<D8B1>ť<EFBFBD>¼<EFBFBD>
|
|||
|
|
btnClose->addClickEventListener(CC_CALLBACK_1(NoticeScene::onClickClose, this));
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
|
auto keyListener = EventListenerKeyboard::create();
|
|||
|
|
//<2F>ͻص<CDBB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
keyListener->onKeyReleased = CC_CALLBACK_2(NoticeScene::onKeyReleased, this);
|
|||
|
|
//<2F><><EFBFBD>ӵ<EFBFBD><D3B5>¼<EFBFBD><C2BC>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NoticeScene::onEnter()
|
|||
|
|
{
|
|||
|
|
Node::onEnter();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NoticeScene::onEnterTransitionDidFinish()
|
|||
|
|
{
|
|||
|
|
Node::onEnterTransitionDidFinish();
|
|||
|
|
|
|||
|
|
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>;
|
|||
|
|
if (GlobalJosn::getInstance()->m_IsNotice)
|
|||
|
|
{
|
|||
|
|
auto noticeInfo = (Layout*)m_rootPanel->getChildByName("info");
|
|||
|
|
CC_ASSERT(noticeInfo != nullptr);
|
|||
|
|
const Size& size = noticeInfo->getContentSize();
|
|||
|
|
|
|||
|
|
CGlobalUserInfo * pGlobalUserInfo = CGlobalUserInfo::GetInstance();
|
|||
|
|
tagGlobalUserData * pGlobalUserData = pGlobalUserInfo->GetGlobalUserData();
|
|||
|
|
|
|||
|
|
std::string strCode = utility::getIdentifyingCode(pGlobalUserInfo->getGameID());
|
|||
|
|
|
|||
|
|
std::string strTextUrl = GlobalJosn::getInstance()->m_NoticeUrl + StringUtils::format("?gameid=%d&md5=%s", pGlobalUserData->dwGameID, strCode.c_str());
|
|||
|
|
|
|||
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|||
|
|
auto label = Label::createWithSystemFont(strTextUrl, "", 26);
|
|||
|
|
label->setColor(Color3B(0, 0, 0));
|
|||
|
|
label->setPosition(size / 2);
|
|||
|
|
noticeInfo->addChild(label);
|
|||
|
|
#else
|
|||
|
|
_webView = cocos2d::experimental::ui::WebView::create();
|
|||
|
|
_webView->setPosition(size / 2);
|
|||
|
|
_webView->setContentSize(size);
|
|||
|
|
_webView->loadURL(strTextUrl);
|
|||
|
|
_webView->setScalesPageToFit(true);
|
|||
|
|
|
|||
|
|
_webView->setOnShouldStartLoading(CC_CALLBACK_2(NoticeScene::onWebViewShouldStartLoading, this));
|
|||
|
|
_webView->setOnDidFinishLoading(CC_CALLBACK_2(NoticeScene::onWebViewDidFinishLoading, this));
|
|||
|
|
_webView->setOnDidFailLoading(CC_CALLBACK_2(NoticeScene::onWebViewDidFailLoading, this));
|
|||
|
|
|
|||
|
|
noticeInfo->addChild(_webView);
|
|||
|
|
|
|||
|
|
//Loading<6E><67>
|
|||
|
|
m_layerLoading = LayerColor::create(Color4B(0, 0, 0, 50), size.width, size.height);
|
|||
|
|
m_layerLoading->setPosition(Vec2(0, 0));
|
|||
|
|
noticeInfo->addChild(m_layerLoading);
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>loadingͼƬ
|
|||
|
|
m_sprLoading = Sprite::create("common/Img/ico_loding.png");
|
|||
|
|
m_sprLoading->setPosition(size / 2);
|
|||
|
|
m_layerLoading->addChild(m_sprLoading);
|
|||
|
|
|
|||
|
|
m_sprLoading->runAction(RepeatForever::create(RotateBy::create(1.6f, 360)));
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NoticeScene::onExit()
|
|||
|
|
{
|
|||
|
|
Node::onExit();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20>رյ<D8B1><D5B5><EFBFBD>;
|
|||
|
|
void NoticeScene::onClickClose(Ref*)
|
|||
|
|
{
|
|||
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|||
|
|
//this->removeFromParent();
|
|||
|
|
|
|||
|
|
CGlobalUserInfo * pGlobalUserInfo = CGlobalUserInfo::GetInstance();
|
|||
|
|
pGlobalUserInfo->SetShowNotice(false);
|
|||
|
|
|
|||
|
|
this->popScene();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void NoticeScene::onKeyReleased(EventKeyboard::KeyCode keyCode, Event * pEvent)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
|||
|
|
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
|
|||
|
|
{
|
|||
|
|
pEvent->stopPropagation();
|
|||
|
|
|
|||
|
|
onClickClose(nullptr);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
|||
|
|
bool NoticeScene::onWebViewShouldStartLoading(experimental::ui::WebView *sender, const std::string &url)
|
|||
|
|
{
|
|||
|
|
CCLOG("onWebViewShouldStartLoading, url is %s", url.c_str());
|
|||
|
|
//don't do any OpenGL operation here!! It's forbidden!
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NoticeScene::onWebViewDidFinishLoading(experimental::ui::WebView *sender, const std::string &url)
|
|||
|
|
{
|
|||
|
|
CCLOG("onWebViewDidFinishLoading, url is %s", url.c_str());
|
|||
|
|
|
|||
|
|
hideLoadingLayer();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NoticeScene::onWebViewDidFailLoading(experimental::ui::WebView *sender, const std::string &url)
|
|||
|
|
{
|
|||
|
|
CCLOG("onWebViewDidFailLoading, url is %s", url.c_str());
|
|||
|
|
|
|||
|
|
hideLoadingLayer();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void NoticeScene::hideLoadingLayer()
|
|||
|
|
{
|
|||
|
|
if (m_layerLoading!=nullptr)
|
|||
|
|
{
|
|||
|
|
if (m_sprLoading!=nullptr)
|
|||
|
|
{
|
|||
|
|
m_sprLoading->stopAllActions();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_layerLoading->removeFromParent();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif
|