#include "HelpScene.h" #include "GlobalJosn.h" #include "PopScene.h" #include "Utility.h" #include "Platform.h" #include "editor-support/cocostudio/CCComExtensionData.h" #include "WN_CMD_Sparrow.h" using namespace cocostudio; HelpScene::HelpScene() { #if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) m_layerLoading = nullptr; m_sprLoading = nullptr; _webView = nullptr; #endif } HelpScene::~HelpScene() { } bool HelpScene::init() { if (!Node::init()) { return false; }; auto rootPanel = CSLoader::createNode("Platform/HelpScene.csb"); CC_ASSERT(rootPanel != nullptr); this->addChild(rootPanel); m_ImageView = (ImageView*)rootPanel->getChildByName("Imagebg"); CC_ASSERT(nullptr != m_ImageView); // 创建节点; for (int i = 0; i < MAX_GAME_COUNT; i++) { std::string strItemKey = __String::createWithFormat("chb_Item_%d", i)->getCString(); CheckBox* GameItem = (CheckBox*)m_ImageView->getChildByName(strItemKey); ASSERT(GameItem != nullptr); if (GameItem == nullptr) continue; m_RadioGroupMenu.AddCheckBox(GameItem); GameItem->addClickEventListener([this](Ref* ref){ if (ref == nullptr) return; CheckBox* chbSelect = (CheckBox*)ref; auto pData = (ComExtensionData*)chbSelect->getComponent("ComExtensionData"); std::string strUserData = pData->getCustomProperty(); int wKindID = atoi(strUserData.c_str()); // 显示内容; std::string strTextUrl = StringUtils::format("%s/rule/%d_rule.html", WEB_SERVER_ADDRESS, wKindID); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) if (m_lblShowUrl) { m_lblShowUrl->setString(strTextUrl); } #else if (_webView) { _webView->loadURL(strTextUrl); } #endif }); } m_RadioGroupMenu.setDelauftSelect(0, true); // 顶部; m_ImageTop = (ImageView*)rootPanel->getChildByName("top"); CC_ASSERT(nullptr != m_ImageTop); //获取关闭按钮 auto btnClose = (Button*)m_ImageTop->getChildByName("btnClose"); CC_ASSERT(btnClose != nullptr); //注册关闭按钮事件 btnClose->addClickEventListener(CC_CALLBACK_1(HelpScene::onClickClose, this)); //对手机返回键的监听 auto keyListener = EventListenerKeyboard::create(); //和回调函数绑定 keyListener->onKeyReleased = CC_CALLBACK_2(HelpScene::onKeyReleased, this); //添加到事件分发器中 _eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this); return true; } void HelpScene::onEnter() { Node::onEnter(); } void HelpScene::onEnterTransitionDidFinish() { Node::onEnterTransitionDidFinish(); } void HelpScene::onExit() { Node::onExit(); } void HelpScene::initRule() { cocos2d::log("HelpScene::initRule()..."); auto webInfo = (Layout*)m_ImageView->getChildByName("panelGameRule"); CC_ASSERT(webInfo != nullptr); const Size& size = webInfo->getContentSize(); // 显示内容; std::string strTextUrl = StringUtils::format("%s/rule/%d_rule.html", WEB_SERVER_ADDRESS, WNMJ_SPACE::KIND_ID); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) //auto label = Label::createWithSystemFont(strTextUrl, "", 26); //label->setColor(Color3B(0, 0, 0)); //label->setPosition(size / 2); //webInfo->addChild(label); m_lblShowUrl = Label::createWithSystemFont(strTextUrl, "", 26); m_lblShowUrl->setColor(Color3B(0, 0, 0)); m_lblShowUrl->setPosition(size / 2); webInfo->addChild(m_lblShowUrl); #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(HelpScene::onWebViewShouldStartLoading, this)); //_webView->setOnDidFinishLoading(CC_CALLBACK_2(HelpScene::onWebViewDidFinishLoading, this)); //_webView->setOnDidFailLoading(CC_CALLBACK_2(HelpScene::onWebViewDidFailLoading, this)); webInfo->addChild(_webView); ////Loading层 //m_layerLoading = LayerColor::create(Color4B(0, 0, 0, 50), size.width, size.height); //m_layerLoading->setPosition(Vec2(0, 0)); //webInfo->addChild(m_layerLoading); ////加入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 HelpScene::pushScene() { float height = Director::getInstance()->getWinSize().height; if (m_ImageTop) { float top_h = m_ImageTop->getContentSize().height; m_ImageTop->setPositionY(height + top_h/2); m_ImageTop->runAction(MoveBy::create(0.2f, Vec2(0, 0 - top_h))); } if (m_ImageView) { float b_h = m_ImageView->getContentSize().height; m_ImageView->setPositionY(0); m_ImageView->setOpacity(0); auto act = MoveBy::create(0.2f, Vec2(0, b_h / 2)); auto spawn = Spawn::create(FadeIn::create(0.2f), act, nullptr); m_ImageView->runAction(Sequence::create(spawn, CallFunc::create([&]() { this->initRule(); }), nullptr)); } } void HelpScene::popScene() { float height = Director::getInstance()->getWinSize().height; if (m_ImageTop) { float top_h = m_ImageTop->getContentSize().height; m_ImageTop->runAction(MoveBy::create(0.2f, Vec2(0, top_h))); } if (m_ImageView) { float b_h = m_ImageView->getContentSize().height; auto act = MoveBy::create(0.2f, Vec2(0, 0 - b_h/2)); auto spawn = Spawn::create(FadeOut::create(0.2f), act, nullptr); m_ImageView->runAction(Sequence::create(spawn, CallFunc::create([&]() { this->removeFromParent(); }), nullptr)); } } // 关闭弹窗; void HelpScene::onClickClose(Ref*) { YSAudioEngine::Instance().playBtnClickEffect(); this->popScene(); } //按键处理 void HelpScene::onKeyReleased(EventKeyboard::KeyCode keyCode, Event * pEvent) { //返回值处理 if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE) { pEvent->stopPropagation(); onClickClose(nullptr); } } #if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32) bool HelpScene::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 HelpScene::onWebViewDidFinishLoading(experimental::ui::WebView *sender, const std::string &url) { CCLOG("onWebViewDidFinishLoading, url is %s", url.c_str()); hideLoadingLayer(); } void HelpScene::onWebViewDidFailLoading(experimental::ui::WebView *sender, const std::string &url) { CCLOG("onWebViewDidFailLoading, url is %s", url.c_str()); hideLoadingLayer(); } void HelpScene::hideLoadingLayer() { if (m_layerLoading != nullptr) { if (m_sprLoading != nullptr) { m_sprLoading->stopAllActions(); } m_layerLoading->removeFromParent(); m_layerLoading = nullptr; } } #endif