Exemple #1
0
void Home::setup()
{
  /*
   * This function switches between the two major components of the homepage,
   * depending on the internal path:
   * /src -> source viewer
   * /... -> homepage
   *
   * FIXME: we should take into account language /cn/src ...
   */
  std::string base = internalPathNextPart("/");

  if (base == SRC_INTERNAL_PATH) {
    if (!sourceViewer_) {
      delete homePage_;
      homePage_ = 0;

      root()->clear();

      sourceViewer_ = sourceViewer("/" + SRC_INTERNAL_PATH + "/");
      WVBoxLayout *layout = new WVBoxLayout();
      layout->setContentsMargins(0, 0, 0, 0);
      layout->addWidget(sourceViewer_);
      root()->setLayout(layout);
    }
  } else {
    if (!homePage_) {
      delete sourceViewer_;
      sourceViewer_ = 0;

      root()->clear();

      createHome();
      root()->addWidget(homePage_);

      setLanguageFromPath();
    }
  }
}
bool TollgateMapLayer::init() {
    bool bRet = false;

    do {
        CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();

        /* 读取关卡配置 */
        loadConfig();

		/* 加载怪物队列数量 */
		CCString* sMonsterListPath = CCString::createWithFormat("%slevel_%d_others.plist",CCFileUtils::sharedFileUtils()->getWritablePath().c_str(), m_iCurLevel);
	
		if(!CCFileUtils::sharedFileUtils()->isFileExist(sMonsterListPath->getCString()))
		{
			sMonsterListPath = CCString::createWithFormat("tollgate/level_%d_others.plist", m_iCurLevel);
		}
		tinyxml2::XMLDocument * xmlDoc = new tinyxml2::XMLDocument();
		unsigned char* pBuffer = NULL;
		unsigned long bufferSize = 0;

		pBuffer = CCFileUtils::sharedFileUtils()->getFileData(sMonsterListPath->getCString(), "r", &bufferSize);

		if (pBuffer)
		{
			xmlDoc->Parse((const char*)pBuffer);
			CCString* nums = CCString::create(xmlDoc->RootElement()->FirstChildElement()->FirstChildElement()->GetText());
			m_monsterListNum = nums->intValue();
		}
		delete xmlDoc;

		
		/* 创建怪物管理器 */
		m_monsterMgrList = CCArray::createWithCapacity(m_monsterListNum);
		CC_SAFE_RETAIN(m_monsterMgrList);
		for(int i = 0; i < m_monsterListNum; i++){
			m_monsterMgrList->insertObject(MonsterManager::createWithLevel(m_iCurLevel, i), i);
			this->addChild((MonsterManager*)m_monsterMgrList->objectAtIndex(i), MONSTER_LAYER_LVL);
		}
		
		/* 创建英雄管理器 */
		m_heroMgr = HeroManager::createWithLevel(m_iCurLevel);
		this->addChild(m_heroMgr, HERO_LAYER_LVL);

        /* 创建起始点 */
        createStartPoint();

        /* 创建堡垒 */
        createHome();
		
        /* 初始化塔魂、怪物和魔力数量 */
        CCDictionary* dict = CCDictionary::create();

        dict->setObject(CCInteger::create(5), enMsgDataKey_TowerSoulNum);
        NOTIFY->postNotification("TowerSoulChange", dict);

        dict->removeAllObjects();
		CCObject* it = NULL;
		int NotShowMonster = 0;
		CCARRAY_FOREACH(m_monsterMgrList, it){
			MonsterManager* m_monsterMgr = dynamic_cast<MonsterManager*>(it);
			NotShowMonster += m_monsterMgr->getNotShowMonsterCount();
		}
		dict->setObject(CCInteger::create(NotShowMonster), enMsgDataKey_MonsterNum);
        //dict->setObject(CCInteger::create(m_monsterMgr->getNotShowMonsterCount()), enMsgDataKey_MonsterNum);
        NOTIFY->postNotification("MonsterNumChange", dict);

        dict->removeAllObjects();
        dict->setObject(CCInteger::create(100), enMsgDataKey_MagicNum);
        NOTIFY->postNotification("MagicChange", dict);

		dict->removeAllObjects();
        dict->setObject(CCInteger::create(3), enMsgDataKey_MagicNum);
		NOTIFY->postNotification("MonsterListNumChange", dict);

		NOTIFY->addObserver(this, 
			callfuncO_selector(TollgateMapLayer::removeMonsterList), 
			"AllMonsterDead", 
		NULL);

        bRet = true;

    } while (0);