Files
wnmj/Classes/AppDelegate.cpp

211 lines
5.5 KiB
C++
Raw Normal View History

2026-02-13 14:34:15 +08:00
#include "AppDelegate.h"
2026-02-13 14:09:12 +08:00
#include "MainScene.h"
#include "GameFrameBase.h"
#include "LogoScene.h"
#include "LogonScene.h"
#include "GlobalJosn.h"
#include "ChatScene.h"
#include "GameCreator.h"
//#include "WN_CreateScene.h"
#include "WN_GameScene.h"
#include "DDZ_GameScene.h"
#include "NN_GameScene.h"
#include "DZ_GameScene.h"
#include "13S_GameScene.h"
#include "ZJH_GameScene.h"
#include "PDK_GameScene.h"
USING_NS_CC;
2026-02-13 14:34:15 +08:00
/*******************************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ****************************************/
2026-02-13 14:09:12 +08:00
2026-02-13 14:34:15 +08:00
// <20><>Ϸѡ<CFB7><D1A1>
2026-02-13 14:09:12 +08:00
struct tagGameItem
{
WORD wKindID;
GAME_CREATE_SELECTOR create;
GAME_CREATE_NODE createNode;
};
static tagGameItem s_GameList[] =
{
2026-02-13 14:34:15 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
2026-02-13 14:09:12 +08:00
{ DDZ_KIND_ID, GAME_CREATE_SELECTOR(DDZ_SPACE::DDZGameScene::create), GAME_CREATE_NODE(nullptr) },
2026-02-13 14:34:15 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>齫;
2026-02-13 14:09:12 +08:00
{ WNMJ_SPACE::KIND_ID, GAME_CREATE_SELECTOR(WNMJ_SPACE::WN_GameScene::create), GAME_CREATE_NODE(nullptr) },
2026-02-13 14:34:15 +08:00
// ţţ;
2026-02-13 14:09:12 +08:00
{ NN_KIND_ID, GAME_CREATE_SELECTOR(NiuNiu_SPACE::NNGameScene::create), GAME_CREATE_NODE(nullptr) },
2026-02-13 14:34:15 +08:00
// <20><>ը;
2026-02-13 14:09:12 +08:00
{ DZ_KIND_ID, GAME_CREATE_SELECTOR(DZ_SPACE::DZGameScene::create), GAME_CREATE_NODE(nullptr) },
2026-02-13 14:34:15 +08:00
// ʮ<><CAAE><EFBFBD><EFBFBD>;
2026-02-13 14:09:12 +08:00
{ SSS_KIND_ID, GAME_CREATE_SELECTOR(SSS_SPACE::SSSGameScene::create), GAME_CREATE_NODE(nullptr) },
2026-02-13 14:34:15 +08:00
// ը<><D5A8><EFBFBD><EFBFBD>;
2026-02-13 14:09:12 +08:00
{ ZJH_KIND_ID, GAME_CREATE_SELECTOR(ZJH_SPACE::ZJHGameScene::create), GAME_CREATE_NODE(nullptr) },
2026-02-13 14:34:15 +08:00
// <20>ܵÿ<DCB5>;
2026-02-13 14:09:12 +08:00
{ PDK_KIND_ID, GAME_CREATE_SELECTOR(PDK_SPACE::PDKGameScene::create), GAME_CREATE_NODE(nullptr) },
};
/******************************************************************************/
AppDelegate::AppDelegate()
{
m_dispathMsgNode = NULL;
}
AppDelegate::~AppDelegate()
{
2026-02-13 14:34:15 +08:00
//// <20>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>;
2026-02-13 14:09:12 +08:00
//YvVoiceManager::GetInstance()->Cleanup();
if (m_dispathMsgNode != NULL)
{
m_dispathMsgNode->stopDispatch();
m_dispathMsgNode->release();
m_dispathMsgNode = NULL;
}
}
//if you want a different context,just modify the value of glContextAttrs
//it will takes effect on all platforms
void AppDelegate::initGLContextAttrs()
{
//set OpenGL context attributions,now can only set six attributions:
//red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
GLView::setGLContextAttrs(glContextAttrs);
}
// If you want to use packages manager to install more packages,
// don't modify or remove this function
static int register_all_packages()
{
return 0; //flag for packages manager
}
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
glview = GLViewImpl::createWithRect("GameClient", Rect(0, 0, TARGET_WIDTH, TARGET_HEIGHT));
#else
glview = GLViewImpl::create("GameClient");
#endif
director->setOpenGLView(glview);
}
// turn on display FPS
director->setDisplayStats(false);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0f / 60);
2026-02-13 14:34:15 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
2026-02-13 14:09:12 +08:00
//FileUtils::getInstance()->addSearchPath("UI/");
//FileUtils::getInstance()->addSearchPath("NCMJ/");
register_all_packages();
initGameConfig();
GlobalJosn::getInstance()->loadConfig();
2026-02-13 14:34:15 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2026-02-13 14:09:12 +08:00
Device::setKeepScreenOn(true);
// create a scene. it's an autorelease object
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32||CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
Scene *pScene = LogonScene::create();
srand(time(0));
// run
director->runWithScene(pScene);
#else
Scene *pScene = LogoScene::create();
if (pScene == nullptr)
{
pScene = LogonScene::create();
}
srand(time(0));
// run
director->runWithScene(pScene);
#endif
glview->setDesignResolutionSize(TARGET_WIDTH, TARGET_HEIGHT, ResolutionPolicy::EXACT_FIT);
if (m_dispathMsgNode == NULL)
{
m_dispathMsgNode = DispatchMsgNode::create();
m_dispathMsgNode->retain();
m_dispathMsgNode->startDispatch();
}
YvVoiceManager::GetInstance()->Init();
return true;
}
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
#if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32
Director::getInstance()->stopAnimation();
Scene* pScene = Director::getInstance()->getRunningScene();
if(pScene!=nullptr && pScene->getTag()==SCENE_TAG_GAME)
{
//applicationDidEnterBackground();
}
#endif
// if you use SimpleAudioEngine, it must be pause
// SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
Director::getInstance()->startAnimation();
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
2026-02-13 14:34:15 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2026-02-13 14:09:12 +08:00
Device::setKeepScreenOn(true);
Scene* pScene = Director::getInstance()->getRunningScene();
if (pScene != nullptr)
{
int nTag = pScene->getTag();
if ( nTag == SCENE_TAG_GAME )
{
GameFrameBase* pMJScene = (GameFrameBase*)pScene;
pMJScene->ReconnectServer();
}
else if ( nTag == SCENE_TAG_MAIN )
{
MainScene* pMainScene = (MainScene*)pScene;
pMainScene->appWillEnterForeground();
}
}
#endif
// if you use SimpleAudioEngine, it must resume here
// SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}
void AppDelegate::initGameConfig()
{
2026-02-13 14:34:15 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ
2026-02-13 14:09:12 +08:00
int gameCount = sizeof(s_GameList) / sizeof(tagGameItem);
for (int i = 0; i < gameCount; i++)
{
CGameCreator::getInstance()->addGame(s_GameList[i].wKindID, CGameCreator::PRIVATE, s_GameList[i].create, s_GameList[i].createNode);
}
2026-02-13 14:34:15 +08:00
}