Ejemplo n.º 1
0
void LeaderBoardAdvanceModeNode::resultHttpRequestCompleted(cs::JsonDictionary* pJsonDict, std::string sKey)
{
    this->removeChildByTag(_TAG_ICON_LOADING_);

    if (pJsonDict != NULL)
    {
        UserInfo userInfo = UserTable::getInstance()->getUserInfo();
        CSPackageInfo csPackageInfo = CSPackageTable::getCSPackageInfo(m_sPackageId);

        String sTag = "LeaderBoardAdvanceMode";
        sTag.appendWithFormat("_%d", m_iConnectServer);

        if (sKey == sTag.getCString())
        {
            cs::JsonDictionary* jsonData = pJsonDict->getSubDictionary("data");
            if (jsonData != NULL)
            {
                if (jsonData->getItemBoolvalue("result", false))
                {
                    cs::JsonDictionary* pJsonList = jsonData->getSubDictionary("list");
                    if (pJsonList != NULL)
                    {
                        int iStageMaxMe = csPackageInfo.iStage;
                        cs::JsonDictionary* pJsonMe = pJsonList->getSubDictionary("Me");
                        if (pJsonMe != NULL)
                        {
                            iStageMaxMe = pJsonMe->getItemIntValue("HighNumberStage", 0);
                            if (iStageMaxMe < csPackageInfo.iStage)
                            {
                                iStageMaxMe = csPackageInfo.iStage;
                            }
                        }

                        m_iLeaderBoardCount = pJsonList->getArrayItemCount("Friends");

                        // find index of me
                        int iRankMe = 1;
                        for(int iIndex=0; iIndex < m_iLeaderBoardCount; iIndex++)
                        {
                            cs::JsonDictionary* pJsonItem = pJsonList->getSubItemFromArray("Friends", iIndex);
                            int iStage = pJsonItem->getItemIntValue("HighNumberStage", 0);

                            if (iStage > iStageMaxMe)
                                iRankMe++;
                            else
                                break;
                        }

                        // Add me to slide
                        this->addItemToSlide(iStageMaxMe, "Me", userInfo.sFacebookId.c_str(), iRankMe);
                        m_pointMe.x = -(iRankMe-1)*160;

                        // Add friends to slide
                        int iCountRank = 0;
                        for (int iIndex=0; iIndex<m_iLeaderBoardCount; iIndex++)
                        {
                            iCountRank++;
                            if (iCountRank == iRankMe)
                                iCountRank++;

                            cs::JsonDictionary* pJsonItem = pJsonList->getSubItemFromArray("Friends", iIndex);
                            this->parseJsonToLeadeBoard(pJsonItem, iCountRank);
                        }

                        m_iLeaderBoardCount = m_iLeaderBoardCount + 1 + 1;
                        m_fMinPositionLeft = -((m_iLeaderBoardCount-4)*160.0f);

                        Node* pInviteFriendsNode = Node::create();
                        Sprite* pButtonInviteImage = Sprite::create("Target-End-Game/btn-add-friend-small.png");

                        LabelTTF* pLabelTCreatedBy = LabelTTF::create("Invite Friends", "Arial", 22);
                        pLabelTCreatedBy->setColor(ccc3(255.0f, 255.0f, 255.0f));
                        pLabelTCreatedBy->setPosition(Point(55.0f, -10.0f));
                        pButtonInviteImage->addChild(pLabelTCreatedBy);

                        ButtonNode* pButtonInvite = ButtonNode::createButtonSprite(pButtonInviteImage, CC_CALLBACK_1(LeaderBoardAdvanceModeNode::clickInviteFriends, this));
                        pButtonInvite->setPosition(Point(80.0f, 70.0f));

                        ButtonManagerNode* pButtonManager = ButtonManagerNode::create();
                        pButtonManager->addButtonNode(pButtonInvite);
                        pInviteFriendsNode->addChild(pButtonManager);

                        pInviteFriendsNode->setContentSize(Size(160.0f, 160.0f));
                        pInviteFriendsNode->setPosition(Point(-320.0f + (m_iLeaderBoardCount-1)*160, -100.0f));
                        m_pSlideShow->addChild(pInviteFriendsNode);
                    }
                }
                else
                {
                }
            }
        }
    }
}
Ejemplo n.º 2
0
bool EndGameCustomModeNode::init()
{
	if (!Node::init())
	{
		return false;
	}
	
	Sprite* pBackground = Sprite::create("AdvanceMode/background.png");
	pBackground->setPosition(Point(320.0f, 485.0f));
	this->addChild(pBackground);

	auto listener = EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE);
	listener->setSwallowTouches(true);
	listener->onTouchBegan = [this](Touch* touch, Event* event) { return true;  };
	EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, pBackground);

	Sprite* pBackgroundPopUp = Sprite::create("AdvanceMode/panel-AM-short.png");
	pBackgroundPopUp->setPosition(Point(320.0f, 595.0f));
	this->addChild(pBackgroundPopUp);

	LabelBMFont *pLabelTitle = LabelBMFont::create("ADVANCE MODE", "fonts/font-bechic.fnt");
	pLabelTitle->setAnchorPoint(Point(0.5f, 0.5f));
	pLabelTitle->setPosition(Point(320.0f, 872.0f));
	this->addChild(pLabelTitle);

	Sprite* pPanel = Sprite::create("AdvanceMode/panel-target-end-game.png");
	pPanel->setPosition(Point(320.0f, 550.0f));
	this->addChild(pPanel);

	/*
	Sprite* pIconEye1 = Sprite::create("AdvanceMode/eye-icon.png");
	pIconEye1->setPosition(Point(500.0f, 550.0f));
	this->addChild(pIconEye1);

	Sprite* pIconEye2 = Sprite::create("AdvanceMode/eye-icon.png");
	pIconEye2->setPosition(Point(500.0f, 480.0f));
	this->addChild(pIconEye2);
	*/

	m_csPackageInfo = CSPackageTable::getCSPackageInfo(m_sPackageId);

	if (m_csPackageInfo.iStage < m_iStage && m_iStage > 1)
	{
		Sprite* pNewRecord = Sprite::create("AdvanceMode/new-record.png");
		pNewRecord->setPosition(Point(548.0f, 668.0f));
		this->addChild(pNewRecord);
		m_csPackageInfo.iStage = m_iStage;
	}
	else if (m_csPackageInfo.iStage == 0)
	{
		m_csPackageInfo.iStage = m_iStage;
	}

	LabelBMFont *pLabelpackageName = LabelBMFont::create(m_csPackageInfo.sPackageName.c_str(), "fonts/font_title-popup.fnt");
	pLabelpackageName->setAnchorPoint(Point(0.5f, 0.5f));
	pLabelpackageName->setPosition(Point(320.0f, 780.0f));
	this->addChild(pLabelpackageName);

	LabelTTF* pLabelTCreatedBy = LabelTTF::create(m_csPackageInfo.sCreatedBy.c_str(), "Arial", 28);
	pLabelTCreatedBy->setColor(ccc3(255.0f, 255.0f, 255.0f));
	pLabelTCreatedBy->setPosition(Point(320.0f, 720.0f));
	this->addChild(pLabelTCreatedBy);

	char sStage[20];
	sprintf(sStage, "Stage %d", m_csPackageInfo.iStage);
	LabelBMFont *pLabelStage = LabelBMFont::create(sStage, "fonts/font_score.fnt", 310.0f);
	pLabelStage->setPosition(Point(320.0f, 630));
	pLabelStage->setScale(1.4);
	this->addChild(pLabelStage);

	LabelBMFont *pLabelTotalWord = LabelBMFont::create("Total Words", "fonts/font_small_alert.fnt", 310.0f);
	pLabelTotalWord->setAnchorPoint(Point(0.0f, 0.5f));
	pLabelTotalWord->setPosition(Point(122.0f, 550));
	this->addChild(pLabelTotalWord);

	char sTotalWord[20];
	sprintf(sTotalWord, "%d/%d", m_csPackageInfo.iTotalWordUnlock, m_csPackageInfo.iTotalWord);
	LabelBMFont *pLabelNumberTotalWord = LabelBMFont::create(sTotalWord, "fonts/font_score.fnt");
	pLabelNumberTotalWord->setAnchorPoint(Point(1.0f, 0.5f));
	pLabelNumberTotalWord->setPosition(Point(475.0f, 550));
	pLabelNumberTotalWord->setScale(1.2);
	this->addChild(pLabelNumberTotalWord);

	LabelBMFont *pLabelWordNew = LabelBMFont::create("New words", "fonts/font_small_alert.fnt", 310.0f);
	pLabelWordNew->setAnchorPoint(Point(0.0f, 0.5f));
	pLabelWordNew->setPosition(Point(122.0f, 480));
	this->addChild(pLabelWordNew);

	char sTotalWordNew[10];
	sprintf(sTotalWordNew, "%d", m_iWordNew);
	LabelBMFont *pLabelNumberWordNew = LabelBMFont::create(sTotalWordNew, "fonts/font_score.fnt");
	pLabelNumberWordNew->setAnchorPoint(Point(1.0f, 0.5f));
	pLabelNumberWordNew->setPosition(Point(475.0f, 480));
	pLabelNumberWordNew->setScale(1.2);
	this->addChild(pLabelNumberWordNew);

	ButtonManagerNode* pButtonManagerNode = ButtonManagerNode::create();
	this->addChild(pButtonManagerNode);

	Sprite* m_pButtonPlayImage = Sprite::create("AdvanceMode/btn_replay.png");
	ButtonNode* pButtonPlay = ButtonNode::createButtonSprite(m_pButtonPlayImage, CC_CALLBACK_1(EndGameCustomModeNode::clickRetry, this));
	pButtonPlay->setPosition(Point(320.0f, 345.0f));
	pButtonManagerNode->addButtonNode(pButtonPlay);

	Sprite* m_pButtonCloseImage = Sprite::create("AdvanceMode/btn_close.png");
	ButtonNode* pButtonClose = ButtonNode::createButtonSprite(m_pButtonCloseImage, CC_CALLBACK_1(EndGameCustomModeNode::clickClose, this));
	pButtonClose->setPosition(Point(580.0f, 898.0f));
	pButtonManagerNode->addButtonNode(pButtonClose);

	LeaderBoardAdvanceModeNode* pLeaderBoard = LeaderBoardAdvanceModeNode::createLayout(m_sPackageId);
	pLeaderBoard->setPosition(Point(320.0f, 114.0f));
	this->addChild(pLeaderBoard);

	return true;
}
Ejemplo n.º 3
0
bool EndGameNode::initWin()
{
	if (!Node::init())
	{
		return false;
	}

	LevelConfig* pLevelConfig = &GameConfigManager::getInstance()->GetLevelConfig(m_sChapterId, m_iCurrentLevel);
	m_iTotalBonusQuest = pLevelConfig->m_BonusQuestConfig.m_iBonusQuestCount;

	LayerColor* pBackground = LayerColor::create(ccc4(7, 25, 44, 150));
	pBackground->setContentSize(CCSizeMake(640.0f, 960.0f));
	auto listener = EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE);
	listener->setSwallowTouches(true);
	listener->onTouchBegan = [](Touch* touch, Event* event) { return true;  };
	EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, pBackground);
	this->addChild(pBackground);
	this->setContentSize(pBackground->getContentSize());

	//m_pSpriteBatchNode = SpriteBatchNode::create("Target-End-Game/TargetEndgame.pvr.ccz");
	//SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Target-End-Game/TargetEndgame.plist");
	//this->addChild(m_pSpriteBatchNode);

	Sprite* pBackgroundBoard = Sprite::create("Target-End-Game/panel-level_popup.png");
	pBackgroundBoard->setPosition(Point(320.0f, 610.0f));
	this->addChild(pBackgroundBoard);

	m_pStarAndBonusQuestNode = Node::create();
	this->addChild(m_pStarAndBonusQuestNode);
	this->generateLayoutStartAndBonusQuest();

	Sprite* pCompletedImage = Sprite::create("Target-End-Game/text_level_completed.png");
	pCompletedImage->setPosition(Point(320.0f, 654.0f));
	this->addChild(pCompletedImage);

	FlashCardNode* pFlashCard = FlashCardNode::createLayout(m_mainWord);
	pFlashCard->setPosition(70.0f, 200.0f);
	pFlashCard->setScale(0.52f);
	this->addChild(pFlashCard);

	char sLevel[20];
	int iCalLevel = GameConfigManager::getInstance()->CountLevelOfPreviousChapters(m_sChapterId);
	sprintf(sLevel, "Level %d", m_iCurrentLevel + iCalLevel);
	LabelBMFont *pLabelLevel = LabelBMFont::create(sLevel, "fonts/font-bechic.fnt");
	pLabelLevel->setAnchorPoint(Point(0.5f, 0.5f));
	pLabelLevel->setPosition(Point(320.0f, 870.0f));
	this->addChild(pLabelLevel);
	
	LabelBMFont *pLabelScore = LabelBMFont::create("SCORE:", "fonts/font_score.fnt");
	pLabelScore->setAnchorPoint(Point(0.5f, 0.5f));
	pLabelScore->setPosition(Point(474.0f, 525.0f));
	this->addChild(pLabelScore);

	LabelBMFont *pLabelNumScore = LabelBMFont::create(formatNumber(m_iScore).getCString(), "fonts/font_score.fnt");
	pLabelNumScore->setAnchorPoint(Point(0.5f, 0.5f));
	pLabelNumScore->setPosition(Point(474.0f, 480.0f));
	pLabelNumScore->setScale(1.4f);
	this->addChild(pLabelNumScore);

	Sprite* pButtonNextGameSprite = Sprite::create("Target-End-Game/btn_next.png");
	ButtonNode* buttonNextNode = ButtonNode::createButtonSprite(pButtonNextGameSprite, CC_CALLBACK_1(EndGameNode::menuNextLevelCallBack, this));
	buttonNextNode->setPosition(Point(425.0f, 279.0f));

	Sprite* pButtonReplayGameSprite = Sprite::create("Target-End-Game/btn_replay.png");
	ButtonNode* buttonReplayNode = ButtonNode::createButtonSprite(pButtonReplayGameSprite, CC_CALLBACK_1(EndGameNode::menuRetryLevelWinCallBack, this));
	buttonReplayNode->setPosition(Point(225.0f, 279.0f));

	Sprite* pButtonCloseSprite = Sprite::create("Target-End-Game/btn_close.png");
	ButtonNode* buttonCloseNode = ButtonNode::createButtonSprite(pButtonCloseSprite, CC_CALLBACK_1(EndGameNode::menuCloseWinCallBack, this));
	buttonCloseNode->setPosition(Point(572.0f, 894.0f));

	ButtonManagerNode* pButtonManagerNode = ButtonManagerNode::create();
	pButtonManagerNode->addButtonNode(buttonNextNode);
	pButtonManagerNode->addButtonNode(buttonCloseNode);
	pButtonManagerNode->addButtonNode(buttonReplayNode);
	this->addChild(pButtonManagerNode);

	m_levelInfo = LevelTable::getInstance()->getLevel(m_sChapterId, m_iCurrentLevel);
	m_chapterInfo = ChapterTable::getInstance()->getChapterInfo(m_sChapterId);

	if (m_levelInfo.bIsUnlock == false)
	{
		m_chapterInfo.iTotalLevelUnlock++;

		UserInfo userInfo = UserTable::getInstance()->getUserInfo();
		userInfo.sCurrentChapterId = m_levelInfo.sChapterId;
		userInfo.iCurrentLevel = m_levelInfo.iLevel + 1;

		// Unlock chapter
		WordlMapConfig worldMapConfig = GameConfigManager::getInstance()->GetWordlMapConfig();
		int iIndexCurrentChapter = worldMapConfig.m_WorlMapChapterConfigMap[m_levelInfo.sChapterId];
		WordlMapConfig::WordMapChapterConfig worldMapChapterConfig = worldMapConfig.m_WorlMapChapterConfigs[iIndexCurrentChapter];

		if (m_iCurrentLevel >= worldMapChapterConfig.m_iTotalevel)
		{
			//userInfo.iCurrentLevel = worldMapChapterConfig.m_iTotalevel;

			// Create data for new chapter
			std::string sNextChapterID;
			if ( GameConfigManager::getInstance()->GetNextChapterID(worldMapChapterConfig.m_sChapterId, sNextChapterID))
			{
				InitDatabase::getInstance()->createDataChapterAndLevel(sNextChapterID);

				userInfo.sCurrentChapterId = sNextChapterID;
				userInfo.iCurrentLevel = 1;
				UserDefault::getInstance()->setStringForKey("ChapterPlayGame", userInfo.sCurrentChapterId);
			}
			else // the last chapter is finished so game is end now!!!!
			{
				
			}
		}
		
		UserTable::getInstance()->updateUser(userInfo);
	}

	m_levelInfo.bIsUnlock = true;
	m_levelInfo.iTotalBonusQuest = m_iTotalBonusQuest;
	
	if (m_levelInfo.iScore < m_iScore)
	{
		m_levelInfo.iScore = m_iScore;
	}

	if(m_levelInfo.iBonusQuest < m_iBonusQuestCompleted)
	{
		m_levelInfo.iBonusQuest = m_iBonusQuestCompleted;	 
	}

	if(m_levelInfo.iStar < m_iYellowStar)
	{
		m_chapterInfo.iTotalStar += m_iYellowStar - m_levelInfo.iStar;
		m_levelInfo.iStar = m_iYellowStar;
	}

	// Update Word for chapter
	const std::string sWordId = GameWordManager::getInstance()->GetWordIdFromWord(m_mainWord);
	WordInfo wordInfo = WordTable::getInstance()->getWordInfoOnChapter(m_levelInfo.sChapterId, sWordId);
	wordInfo.iCountCollected++;

	LevelTable::getInstance()->updateLevel(m_levelInfo);
	WordTable::getInstance()->updateWord(wordInfo);
	ChapterTable::getInstance()->updateChapter(m_chapterInfo);
	
	m_iCountYellowStar = 0;
	m_iCountBonusQuest = 0;

	this->sequenceUpdateStar();

    LeaderBoardtNode* pLeaderBoard = LeaderBoardtNode::createLayout(m_iCurrentLevel, m_sChapterId);
	pLeaderBoard->setPosition(Point(320.0f, 114.0f));
	this->addChild(pLeaderBoard);

    auto actionupdateDatabaseAndSync = CallFunc::create(this, callfunc_selector(EndGameNode::updateDatabaseAndSync));
	this->runAction(Sequence::create(DelayTime::create(0.01f), actionupdateDatabaseAndSync, NULL));

	return true;
}
Ejemplo n.º 4
0
bool EndGameNode::initLose()
{
	if (!Node::init())
	{
		return false;
	}
	
	LayerColor* pBackground = LayerColor::create(ccc4(7, 25, 44, 150));
	pBackground->setContentSize(CCSizeMake(640.0f, 960.0f));
	auto listener = EventListenerTouch::create(Touch::DispatchMode::ONE_BY_ONE);
	listener->setSwallowTouches(true);
	listener->onTouchBegan = [](Touch* touch, Event* event) { return true;  };
	EventDispatcher::getInstance()->addEventListenerWithSceneGraphPriority(listener, pBackground);
	this->addChild(pBackground);
	this->setContentSize(pBackground->getContentSize());

	//m_pSpriteBatchNode = SpriteBatchNode::create("Target-End-Game/TargetEndgame.pvr.ccz");
	//SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Target-End-Game/TargetEndgame.plist");
	//this->addChild(m_pSpriteBatchNode);

	Sprite* pBackgroundBoard = Sprite::create("Target-End-Game/panel-level_popup.png");
	pBackgroundBoard->setPosition(Point(320.0f, 610.0f));
	this->addChild(pBackgroundBoard);

	Sprite* pLevelFailImage3 = Sprite::create("Target-End-Game/text_level_fail.png");
	pLevelFailImage3->setPosition(Point(320.0f, 750.0f));
	this->addChild(pLevelFailImage3);

	Sprite* pIconBoosterLock1 = Sprite::create("Target-End-Game/lock-icon-powerup.png");
	pIconBoosterLock1->setPosition(Point(220.0f, 415.0f));
	this->addChild(pIconBoosterLock1);

	Sprite* pIconBoosterLock2 = Sprite::create("Target-End-Game/lock-icon-powerup.png");
	pIconBoosterLock2->setPosition(Point(320.0f, 415.0f));
	this->addChild(pIconBoosterLock2);

	Sprite* pIconBoosterLock3 = Sprite::create("Target-End-Game/lock-icon-powerup.png");
	pIconBoosterLock3->setPosition(Point(420.0f, 415.0f));
	this->addChild(pIconBoosterLock3);

	FlashCardNode* pFlashCard = FlashCardNode::createLayout(m_mainWord);
	pFlashCard->setPosition(70.0f, 285.0f);
	pFlashCard->setScale(0.52f);
	this->addChild(pFlashCard);

	char sLevel[20];
	int iCalLevel = GameConfigManager::getInstance()->CountLevelOfPreviousChapters(m_sChapterId);
	sprintf(sLevel, "Level %d", m_iCurrentLevel + iCalLevel);
	LabelBMFont *pLabelLevel = LabelBMFont::create(sLevel, "fonts/font-bechic.fnt");
	pLabelLevel->setAnchorPoint(Point(0.5f, 0.5f));
	pLabelLevel->setPosition(Point(320.0f, 870.0f));
	this->addChild(pLabelLevel);
	
	LabelBMFont *pLabelScore = LabelBMFont::create("SCORE:", "fonts/font_score.fnt");
	pLabelScore->setAnchorPoint(Point(0.5f, 0.5f));
	pLabelScore->setPosition(Point(474.0f, 630.0f));
	this->addChild(pLabelScore);

	LabelBMFont *pLabelNumScore = LabelBMFont::create(formatNumber(m_iScore).getCString(), "fonts/font_score.fnt");
	pLabelNumScore->setAnchorPoint(Point(0.5f, 0.5f));
	pLabelNumScore->setPosition(Point(474.0f, 585.0f));
	pLabelNumScore->setScale(1.4f);
	this->addChild(pLabelNumScore);

	LeaderBoardtNode* pLeaderBoard = LeaderBoardtNode::createLayout(m_iCurrentLevel, m_sChapterId);
	pLeaderBoard->setPosition(Point(320.0f, 114.0f));
	this->addChild(pLeaderBoard);

	Sprite* pButtonPlayGameSprite = Sprite::create("Target-End-Game/btn_replay.png");
	ButtonNode* buttonPlayNode = ButtonNode::createButtonSprite(pButtonPlayGameSprite, CC_CALLBACK_1(EndGameNode::menuRetryLevelLoseCallBack, this));
	buttonPlayNode->setPosition(Point(320.0f, 279.0f));

	Sprite* pButtonCloseSprite = Sprite::create("Target-End-Game/btn_close.png");
	ButtonNode* buttonCloseNode = ButtonNode::createButtonSprite(pButtonCloseSprite, CC_CALLBACK_1(EndGameNode::menuCloseLoseCallBack, this));
	buttonCloseNode->setPosition(Point(572.0f, 894.0f));

	ButtonManagerNode* pButtonManagerNode = ButtonManagerNode::create();
	pButtonManagerNode->addButtonNode(buttonPlayNode);
	pButtonManagerNode->addButtonNode(buttonCloseNode);
	this->addChild(pButtonManagerNode);

	return true;
}
Ejemplo n.º 5
0
void LeaderBoardtNode::resultHttpRequestCompleted(cs::JsonDictionary* pJsonDict, std::string sKey)
{
    this->removeChildByTag(_TAG_ICON_LOADING_);

    if (pJsonDict != NULL)
    {
        LevelInfo levelInfo =  LevelTable::getInstance()->getLevel(m_sChapterId, m_iLevel);
        UserInfo userInfo = UserTable::getInstance()->getUserInfo();
        String sTag = "LeaderBoardLevel";
        sTag.appendWithFormat("_%d", m_iConnectServer);

        if (sKey == sTag.getCString())
        {
            cs::JsonDictionary* jsonData = pJsonDict->getSubDictionary("data");
            if (jsonData != NULL)
            {
                if (jsonData->getItemBoolvalue("result", false))
                {
                    m_iLeaderBoardCount = jsonData->getArrayItemCount("list");

                    if (levelInfo.bIsUnlock)
                    {
                        // find index of me
                        int iRank = 1;
                        for(int iIndex=0; iIndex < m_iLeaderBoardCount; iIndex++)
                        {
                            cs::JsonDictionary* pJsonItem = jsonData->getSubItemFromArray("list", iIndex);
                            int iScore = pJsonItem->getItemIntValue("Score", 0);

                            if (iScore > levelInfo.iScore)
                                iRank++;
                            else
                                break;
                        }

                        if (iRank == 1)
                        {
                            this->addItemToSlide(levelInfo.iScore, "Me", userInfo.sFacebookId.c_str(), iRank, 0);

                            if (m_iLeaderBoardCount > 5)
                                m_iLeaderBoardCount = 5;

                            for(int iIndex=0; iIndex < m_iLeaderBoardCount; iIndex++)
                            {
                                iRank++;
                                cs::JsonDictionary* pJsonItem = jsonData->getSubItemFromArray("list", iIndex);
                                this->parseJsonToLeadeBoard(pJsonItem, iRank, iIndex+1);
                            }
                        }
                        else
                        {
                            if (iRank > m_iLeaderBoardCount)
                            {
                                if (iRank >= 6)
                                {
                                    this->addItemToSlide(levelInfo.iScore, "Me", userInfo.sFacebookId.c_str(), iRank, 5);

                                    cs::JsonDictionary* pJsonItemLeft1 = jsonData->getSubItemFromArray("list", iRank-2);
                                    this->parseJsonToLeadeBoard(pJsonItemLeft1, iRank-1, 4);

                                    cs::JsonDictionary* pJsonItemLeft2 = jsonData->getSubItemFromArray("list", iRank-3);
                                    this->parseJsonToLeadeBoard(pJsonItemLeft2, iRank-2, 3);
                                }
                                else
                                {
                                    this->addItemToSlide(levelInfo.iScore, "Me", userInfo.sFacebookId.c_str(), iRank, iRank-1);

                                    cs::JsonDictionary* pJsonItemLeft1 = jsonData->getSubItemFromArray("list", iRank-2);
                                    this->parseJsonToLeadeBoard(pJsonItemLeft1, iRank-1, iRank-2);

                                    cs::JsonDictionary* pJsonItemLeft2 = jsonData->getSubItemFromArray("list", iRank-3);
                                    this->parseJsonToLeadeBoard(pJsonItemLeft2, iRank-2, iRank-3);
                                }
                            }
                            else
                            {
                                if (iRank >= 6)
                                {
                                    this->addItemToSlide(levelInfo.iScore, "Me", userInfo.sFacebookId.c_str(), iRank, 4);

                                    cs::JsonDictionary* pJsonItemRight = jsonData->getSubItemFromArray("list", iRank-1);
                                    this->parseJsonToLeadeBoard(pJsonItemRight, iRank+1, 5);

                                    cs::JsonDictionary* pJsonItemLeft = jsonData->getSubItemFromArray("list", iRank-2);
                                    this->parseJsonToLeadeBoard(pJsonItemLeft, iRank-1, 3);
                                }
                                else
                                {
                                    this->addItemToSlide(levelInfo.iScore, "Me", userInfo.sFacebookId.c_str(), iRank, iRank-1);

                                    cs::JsonDictionary* pJsonItemRight = jsonData->getSubItemFromArray("list", iRank-1);
                                    this->parseJsonToLeadeBoard(pJsonItemRight, iRank+1, iRank);

                                    cs::JsonDictionary* pJsonItemLeft = jsonData->getSubItemFromArray("list", iRank-2);
                                    this->parseJsonToLeadeBoard(pJsonItemLeft, iRank-1, iRank-2);
                                }
                            }

                            int iCount = 0;
                            for (int iIndex=0; iIndex<m_iLeaderBoardCount; iIndex++)
                            {
                                if(iCount > 2)
                                    break;

                                if (iIndex < iRank-2)
                                {
                                    iCount++;
                                    cs::JsonDictionary* pJsonItem = jsonData->getSubItemFromArray("list", iIndex);
                                    this->parseJsonToLeadeBoard(pJsonItem, iIndex+1, iIndex);
                                }
                                else if (iIndex > iRank-1)
                                {
                                    iCount++;
                                    cs::JsonDictionary* pJsonItem = jsonData->getSubItemFromArray("list", iIndex);
                                    this->parseJsonToLeadeBoard(pJsonItem, iIndex+2, iIndex+1);
                                }
                            }
                        }

                        m_iLeaderBoardCount = m_iLeaderBoardCount + 1;
                        if (m_iLeaderBoardCount > 6 )
                            m_iLeaderBoardCount = 6;
                    }
                    else
                    {
                        if (m_iLeaderBoardCount > 6)
                            m_iLeaderBoardCount = 6;

                        for(int iIndex=0; iIndex < m_iLeaderBoardCount; iIndex++)
                        {
                            cs::JsonDictionary* pJsonItem = jsonData->getSubItemFromArray("list", iIndex);
                            this->parseJsonToLeadeBoard(pJsonItem, iIndex+1, iIndex);
                        }
                    }

                    m_iLeaderBoardCount = m_iLeaderBoardCount + 1;
                    m_fMinPositionLeft = -((m_iLeaderBoardCount-4)*160.0f);

                    Node* pInviteFriendsNode = Node::create();
                    Sprite* pButtonInviteImage = Sprite::create("Target-End-Game/btn-add-friend-small.png");

                    LabelTTF* pLabelTCreatedBy = LabelTTF::create("Invite Friends", "Arial", 22);
                    pLabelTCreatedBy->setColor(ccc3(255.0f, 255.0f, 255.0f));
                    pLabelTCreatedBy->setPosition(Point(55.0f, -10.0f));
                    pButtonInviteImage->addChild(pLabelTCreatedBy);

                    ButtonNode* pButtonInvite = ButtonNode::createButtonSprite(pButtonInviteImage, CC_CALLBACK_1(LeaderBoardtNode::clickInviteFriends, this));
                    pButtonInvite->setPosition(Point(80.0f, 70.0f));

                    ButtonManagerNode* pButtonManager = ButtonManagerNode::create();
                    pButtonManager->addButtonNode(pButtonInvite);
                    pInviteFriendsNode->addChild(pButtonManager);

                    pInviteFriendsNode->setContentSize(Size(160.0f, 160.0f));
                    pInviteFriendsNode->setPosition(Point(-320.0f + (m_iLeaderBoardCount-1)*160, -100.0f));
                    m_pSlideShow->addChild(pInviteFriendsNode);
                }
                else
                {
                }
            }
        }
    }
}
Ejemplo n.º 6
0
bool AdvanceModePopularPackagesLayer::init()
{
	if(!Layer::init())
	{
		return false;
	}

	Sprite* pBackground = Sprite::create("AdvanceMode/background.png");
	pBackground->setPosition(Point(320.0f, 480.0f));
	this->addChild(pBackground);

	Sprite* pBackgroundPopUp = Sprite::create("AdvanceMode/panel-AM-long.png");
	pBackgroundPopUp->setPosition(Point(320.0f, 520.0f));
	this->addChild(pBackgroundPopUp);

	LabelTTF* pLabelMyPackage = LabelTTF::create("Popular Packages", "Arial", 35);
	pLabelMyPackage->setColor(ccc3(255.0f, 255.0f, 255.0f));
	pLabelMyPackage->setPosition(Point(200.0f, 630.0f));
	this->addChild(pLabelMyPackage);

	ButtonManagerNode* pButtonManagerNode = ButtonManagerNode::create();
	this->addChild(pButtonManagerNode);

	Sprite* m_pButtonAddMorePackageImage = Sprite::create("AdvanceMode/btn-add-small.png");
	ButtonNode* m_pButtonAddMorePackage = ButtonNode::createButtonSprite(m_pButtonAddMorePackageImage, CC_CALLBACK_1(AdvanceModePopularPackagesLayer::clickAddPackage, this));
	m_pButtonAddMorePackage->setPosition(Point(467.0f, 760.0f));
	pButtonManagerNode->addButtonNode(m_pButtonAddMorePackage);

	Sprite* m_pButtonPackageCodeImage = Sprite::create("AdvanceMode/text-box-small.png");
	//ButtonNode* m_pButtonPackageCode = ButtonNode::createButtonSprite(m_pButtonPackageCodeImage, CC_CALLBACK_1(AdvanceModePopularPackagesLayer::clickAddPackageCode, this));
	//m_pButtonPackageCode->setPosition(Point(213.0f, 760.0f));
	//pButtonManagerNode->addButtonNode(m_pButtonPackageCode);
	m_pButtonPackageCodeImage->setPosition(Point(213.0f, 760.0f));
	this->addChild(m_pButtonPackageCodeImage);


	m_pCodeEditBox = EditBox::create(Size(250.f, 50.f), Scale9Sprite::create("AdvanceMode/blank_edit.png"));
	m_pCodeEditBox->setFont("Arial", 30);
	m_pCodeEditBox->setFontColor(Color3B( 50, 50, 50));
    //m_pCodeEditBox->setPosition( Point(60.f, 260.f)); //Point(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/4));
	m_pCodeEditBox->setPosition(Point(215.0f, 760.0f));
    //m_pCodeEditBox->setAnchorPoint(Point(0, 0.5f));
    m_pCodeEditBox->setPlaceHolder("Input code");
	m_pCodeEditBox->setInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS);
	//m_pCodeEditBox->setInputMode(EditBox::InputMode::ANY);
    //editCode->setDelegate(this);
    addChild(m_pCodeEditBox);



	LabelTTF* pLabelDescription = LabelTTF::create("Build your own vocab from http://petzzlegame.com", "Arial", 20);
	pLabelDescription->setColor(ccc3(255.0f, 255.0f, 255.0f));
	pLabelDescription->setPosition(Point(320.0f, 700.0f));
	this->addChild(pLabelDescription);

	LabelBMFont *pLabelTitle = LabelBMFont::create("ADVANCE MODE", "fonts/font-bechic.fnt");
	pLabelTitle->setAnchorPoint(Point(0.5f, 0.5f));
	pLabelTitle->setPosition(Point(320.0f, 880.0f));
	this->addChild(pLabelTitle);

	m_pBackgroundSlideShow = Sprite::create("AdvanceMode/panel-vocab-list.png");
	m_pBackgroundSlideShow->setPosition(Point(315.0f, 375.0f));
	this->addChild(m_pBackgroundSlideShow);

	m_pFooterNode = FooterNode::create();
	m_pFooterNode->removeBackground();
	m_pFooterNode->removeButtonFlashcard();
	this->addChild(m_pFooterNode);

	m_pSlideShow = ButtonManagerNode::create();
	m_pSlideShow->AllowSwipingBackground(true);
	m_pSlideShow->setPosition(Point(0.0f, 295.0f));

	ClipMaskNode* pClipMaskNode = ClipMaskNode::create();
	pClipMaskNode->setPosition(Point(28.0f, 150.0f));
	pClipMaskNode->setContentSize(Size(544.0f, 448.0f));
	pClipMaskNode->addChild(m_pSlideShow);
	m_pBackgroundSlideShow->addChild(pClipMaskNode);

	this->setTouchEnabled(true);
	this->setTouchMode(Touch::DispatchMode::ONE_BY_ONE);

	Breadcrumb::getInstance()->addSceneMode(SceneMode::kPopularPackage);

	m_pScrollManager = new ScrollManager();

	m_iConnectServer = UserDefault::getInstance()->getIntegerForKey("NumberConnectServer", 0);
	m_iConnectServer++;
	UserDefault::getInstance()->setIntegerForKey("NumberConnectServer", m_iConnectServer);

	PackageService::getInstance()->setInterfaceServiceCallBack(this);
	PackageService::getInstance()->getPackagePopular(0, 20, m_iConnectServer);

	m_iTotalPackage = 0;
	m_maxHeight = 0;

	m_pCustomPackageDownloadManager = new CustomPackageDownloadManager();
	m_pCustomPackageDownloadManager->SetDownloadPackageCompleteCallback(std::bind( &AdvanceModePopularPackagesLayer::OnDownloadPackageComplete, this, std::placeholders::_1));

	IconLoadingNode* iconLoadingNode = IconLoadingNode::create();
	iconLoadingNode->setTag(_TAG_ICON_LOADING_);
	iconLoadingNode->setPosition(320.0f, 400.0f);
	this->addChild(iconLoadingNode, _TAG_ICON_LOADING_);

	return true;
}
Ejemplo n.º 7
0
bool FlashCardCollectionLayer::init()
{
	if(!Layer::init())
	{
		return false;
	}

	Sprite* pBackground = Sprite::create("FlashCard/background.png");
	pBackground->setPosition(Point(320.0f, 480.0f));
	this->addChild(pBackground);

	ButtonManagerNode* pButtonManagerNode = ButtonManagerNode::create();
	this->addChild(pButtonManagerNode);

	Sprite* pIconFlashCard = Sprite::create("FlashCard/flashcard_icon_btn.png");
	pIconFlashCard->setPosition(Point(-140.0f, 45.0f));

	Sprite* pButtonMiniGameSprite = Sprite::create("FlashCard/minigame-countdown.png");
	pButtonMiniGameSprite->addChild(pIconFlashCard);
	pButtonMiniGameSprite->setPosition(Point(154.0f, 0.0f));

	ButtonNode* pButtonMiniGame = ButtonNode::createButtonSprite(pButtonMiniGameSprite, CC_CALLBACK_1(FlashCardCollectionLayer::clickPlayMiniGame, this));
	pButtonMiniGame->setPosition(Point(320.0f, 810.0f));
	pButtonManagerNode->addButtonNode(pButtonMiniGame);


	m_iWordNew = WordTable::getInstance()->getNumberWordNew();
	m_iWordPlayMiniGame = WordTable::getInstance()->getNumberWordPlayMiniGame(getTimeLocalCurrent());

	m_pLabelMiniGame = LabelTTF::create("MINI GAME", "Arial", 30);
	m_pLabelMiniGame->setColor(ccc3(255.0f, 255.0f, 255.0f));
	m_pLabelMiniGame->setPosition(Point(148.0f, 47.0f));
	pButtonMiniGameSprite->addChild(m_pLabelMiniGame);

	m_iTimeCountDown = 0;
	if (m_iWordPlayMiniGame < 1 && m_iWordNew > 0)
	{
		unsigned long uMinTime = WordTable::getInstance()->getMinTimeNextPlayMiniGame();
		m_iTimeCountDown = uMinTime + _SECONDS_NEXT_PLAY_MINI_GAME_ - getTimeLocalCurrent();
		if (m_iTimeCountDown > 0)
		{
			m_pLabelMiniGame->setString(formatHMSToDisplay(m_iTimeCountDown).getCString());
			this->scheduleUpdate();
		}
		
	}

	if (m_iWordNew > 0)
	{
		Sprite* pIconNew = Sprite::create("FlashCard/noitify_msg.png");
		pIconNew->setPosition(Point(240.0f, 85.0f));
		pButtonMiniGameSprite->addChild(pIconNew);

		char sNumberNew[10];
		sprintf(sNumberNew, "%d", m_iWordNew);
		LabelTTF* pLabelNumber = LabelTTF::create(sNumberNew, "Arial", 25);
		pLabelNumber->setColor(ccc3(255.0f, 255.0f, 255.0f));
		pLabelNumber->setPosition(Point(22.0f, 20.0f));
		pIconNew->addChild(pLabelNumber);
	}

	Sprite* pBackgroundFlashcard = Sprite::create("FlashCard/panel-level_popup.png");
	pBackgroundFlashcard->setPosition(Point(320.0f, 415.0f));
	this->addChild(pBackgroundFlashcard);

	LabelBMFont *pLabelTitle = LabelBMFont::create("Flashcard Collection", "fonts/font-bechic.fnt");
	pLabelTitle->setAnchorPoint(Point(0.5f, 0.5f));
	pLabelTitle->setPosition(Point(320.0f, 673.0f));
	this->addChild(pLabelTitle);
	
	m_pFooterNode = FooterNode::create();
	m_pFooterNode->changeStatusButtonFlashcard(StatusButtonFlashcard::eNoClick);
	m_pFooterNode->removeBackground();
	this->addChild(m_pFooterNode);

	HeaderNode* pHeaderNode = HeaderNode::create();
	this->addChild(pHeaderNode);

	m_pSlideShow = ButtonManagerNode::create();
	m_pSlideShow->AllowSwipingBackground(true);
	m_pSlideShow->setPosition(Point(245.0f, 300.0f));

	ClipMaskNode* pClipMaskNode = ClipMaskNode::create();
	pClipMaskNode->setPosition(Point(75.0f, 155.0f));
	pClipMaskNode->setContentSize(Size(560.0f, 460.0f));
	pClipMaskNode->addChild(m_pSlideShow);
	pBackgroundFlashcard->addChild(pClipMaskNode);

	ChapterTable::getInstance()->refreshChapters();
	m_chapters = ChapterTable::getInstance()->getChaptersInfo();

	WordlMapConfig worlMapConfig = GameConfigManager::getInstance()->GetWordlMapConfig();
	
	int iCountIndex=0;
	for (int iIndex=0; iIndex<m_chapters.size(); iIndex++)
	{
		ChapterInfo chapterInfo = m_chapters[iIndex];
		if(chapterInfo.bIsUnlock)
		{
			int iTotalFlashcardUnlock = chapterInfo.iTotalFlashCardUnlock;
			if (iTotalFlashcardUnlock > 0)
			{
				Sprite* pBackgroundItem = Sprite::create("FlashCard/panel_flashcard_chapter.png");
				pBackgroundItem->setPosition(Point(0.0f, -iIndex*190));
				m_pSlideShow->addChild(pBackgroundItem);

				int iIndexChapter = worlMapConfig.m_WorlMapChapterConfigMap[chapterInfo.sChapterId];

				std::string sPath = worlMapConfig.m_WorlMapChapterConfigs[iIndexChapter].m_sPathData;
				sPath.append("/Flash-Card-icon.png");
				Sprite* pIconChapter = Sprite::create(sPath.c_str());

				ButtonNode* pButtonItem = ButtonNode::createButtonSprite(pIconChapter, CC_CALLBACK_1(FlashCardCollectionLayer::clickOpenFlashCard, this));
				pButtonItem->setTag(iIndex);
				pButtonItem->setPosition(Point(-140.0f, -15 -iIndex*190));
				m_pSlideShow->addButtonNode(pButtonItem);

				LabelBMFont* pLabelChapterName = LabelBMFont::create(worlMapConfig.m_WorlMapChapterConfigs[iIndexChapter].m_sChapterName.c_str(), "fonts/font_small_alert.fnt");
				pLabelChapterName->setPosition(Point(90.0f, 18 -iIndex*190));
				m_pSlideShow->addChild(pLabelChapterName);

				char sTotalFlashCard[10];
				sprintf(sTotalFlashCard, "(%d/%d)", iTotalFlashcardUnlock, chapterInfo.iTotalFlashCard);
				LabelTTF* pLabelTotalFlashCard = LabelTTF::create(sTotalFlashCard, "Arial", 25);
				pLabelTotalFlashCard->setColor(ccc3(0.0f, 0.0f, 0.0f));
				pLabelTotalFlashCard->setPosition(Point(90.0f, -18 -iIndex*190));
				m_pSlideShow->addChild(pLabelTotalFlashCard);

				if (iTotalFlashcardUnlock >= 0)
				{
					Sprite* pButtonPlayReviseGameImage = Sprite::create("AdvanceMode/btn-play-advance-mode.png");
					ButtonNode* pButtonPlayReviseGame = ButtonNode::createButtonSprite(pButtonPlayReviseGameImage, CC_CALLBACK_1(FlashCardCollectionLayer::clickPlayReviseGame, this));
					pButtonPlayReviseGame->setTag(iIndex);
					pButtonPlayReviseGame->setPosition(Point(235.0f, -iIndex*190));
					m_pSlideShow->addButtonNode(pButtonPlayReviseGame);
				}

				iCountIndex++;
				m_maxHeight = iCountIndex*190;
			}
		}
	}

	Breadcrumb::getInstance()->addSceneMode(SceneMode::kFlashCardCollection);

	this->setTouchEnabled(true);
	this->setTouchMode(Touch::DispatchMode::ONE_BY_ONE);

	m_pScrollManager = new ScrollManager();

	return true;
}