Files
wnmj/Classes/Scenes/GongHuiScene.cpp

222 lines
5.5 KiB
C++
Raw Normal View History

2026-02-13 14:34:15 +08:00
#include "GongHuiScene.h"
#include "GlobalJosn.h"
#include "GlobalUserInfo.h"
#include "PopScene.h"
#include "Utility.h"
GongHuiScene::GongHuiScene()
{
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
m_layerLoading = nullptr;
m_sprLoading = nullptr;
#endif
}
GongHuiScene::~GongHuiScene()
{
}
bool GongHuiScene::init()
{
if (!Node::init())
{
return false;
};
auto rootPanel = CSLoader::createNode("Platform/GongHuiScene.csb");
CC_ASSERT(rootPanel != nullptr);
this->addChild(rootPanel);
m_ImageView = (ImageView*)rootPanel->getChildByName("Imagebg");
CC_ASSERT(nullptr != m_ImageView);
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(GongHuiScene::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(GongHuiScene::onKeyReleased, this);
//<2F><><EFBFBD>ӵ<EFBFBD><D3B5>¼<EFBFBD><C2BC>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>;
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);
return true;
}
void GongHuiScene::onEnter()
{
Node::onEnter();
}
void GongHuiScene::onEnterTransitionDidFinish()
{
Node::onEnterTransitionDidFinish();
}
void GongHuiScene::onExit()
{
Node::onExit();
}
void GongHuiScene::initRule()
{
cocos2d::log("GongHuiScene::initRule()...");
auto webInfo = (Layout*)m_ImageView->getChildByName("info");
CC_ASSERT(webInfo != nullptr);
const Size& size = webInfo->getContentSize();
CGlobalUserInfo * pGlobalUserInfo = CGlobalUserInfo::GetInstance();
tagGlobalUserData * pGlobalUserData = pGlobalUserInfo->GetGlobalUserData();
std::string strCode = utility::getIdentifyingCode(pGlobalUserInfo->getGameID());
std::string strTextUrl = GlobalJosn::getInstance()->m_strGongHuiUrl + 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);
webInfo->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(GongHuiScene::onWebViewShouldStartLoading, this));
_webView->setOnDidFinishLoading(CC_CALLBACK_2(GongHuiScene::onWebViewDidFinishLoading, this));
_webView->setOnDidFailLoading(CC_CALLBACK_2(GongHuiScene::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 GongHuiScene::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 - 20;
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 GongHuiScene::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 - 20;
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 GongHuiScene::onClickClose(Ref*)
{
YSAudioEngine::Instance().playBtnClickEffect();
this->popScene();
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void GongHuiScene::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 GongHuiScene::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 GongHuiScene::onWebViewDidFinishLoading(experimental::ui::WebView *sender, const std::string &url)
{
CCLOG("onWebViewDidFinishLoading, url is %s", url.c_str());
hideLoadingLayer();
}
void GongHuiScene::onWebViewDidFailLoading(experimental::ui::WebView *sender, const std::string &url)
{
CCLOG("onWebViewDidFailLoading, url is %s", url.c_str());
hideLoadingLayer();
}
void GongHuiScene::hideLoadingLayer()
{
if (m_layerLoading != nullptr)
{
if (m_sprLoading != nullptr)
{
m_sprLoading->stopAllActions();
}
m_layerLoading->removeFromParent();
}
}
#endif