Files
wnmj/Classes/Scenes/HelpScene.cpp

267 lines
6.5 KiB
C++
Raw Normal View History

2026-02-13 14:34:15 +08:00
#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);
// <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>;
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());
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>;
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);
// <20><><EFBFBD><EFBFBD>;
m_ImageTop = (ImageView*)rootPanel->getChildByName("top");
CC_ASSERT(nullptr != m_ImageTop);
//<2F><>ȡ<EFBFBD>رհ<D8B1>ť
auto btnClose = (Button*)m_ImageTop->getChildByName("btnClose");
CC_ASSERT(btnClose != nullptr);
//ע<><D7A2><EFBFBD>رհ<D8B1>ť<EFBFBD>¼<EFBFBD>
btnClose->addClickEventListener(CC_CALLBACK_1(HelpScene::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(HelpScene::onKeyReleased, this);
//<2F><><EFBFBD>ӵ<EFBFBD><D3B5>¼<EFBFBD><C2BC>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
_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();
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>;
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<6E><67>
//m_layerLoading = LayerColor::create(Color4B(0, 0, 0, 50), size.width, size.height);
//m_layerLoading->setPosition(Vec2(0, 0));
//webInfo->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 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));
}
}
// <20>رյ<D8B1><D5B5><EFBFBD>;
void HelpScene::onClickClose(Ref*)
{
YSAudioEngine::Instance().playBtnClickEffect();
this->popScene();
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void HelpScene::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 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