码迷,mamicode.com
首页 > 其他好文 > 详细

分析Cocos2d-x横版ACT手游源代码 3、人物选择界面

时间:2014-11-26 16:33:01      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:style   io   ar   os   sp   for   文件   on   art   

。h文件
#ifndef _NF_ROLE_SELECT_SCENE_HEAD_
#define _NF_ROLE_SELECT_SCENE_HEAD_

#include "../publicdef/PublicDef.h"

/************************************************************************/
/*人物选择层															*/
/************************************************************************/
class CNFRoleSelectLayer : public CCLayer
{
protected:
	//标签
	enum 
	{
		enTagStudioMainUiLayer,
		enTagRole1,
		enTagRole2,
		enTagRole3,
	};

	int				m_nRoleID;			//角色ID	1.鸣人	2.小樱	3.佐助
	int				m_nRelaseRoleID;	//解锁角色ID	1.鸣人	2.小樱	3.佐助
public:
	static CNFRoleSelectLayer * CreateLayer();
	static CCScene * scene();

	void OnGameStartPage(CCObject *pSender, TouchEventType type);				//开始游戏

	void OnRoleSelect(CCObject *pSender, TouchEventType type);					//选择人物

	void OnFollowSelect(CCObject *pSender, TouchEventType type);				//选择随从

	void OnCancelFollowSelect(CCObject *pSender, TouchEventType type);			//取消随从

	void OnBack(CCObject *pSender, TouchEventType type);						//返回登录

	void OnShowReleaseDlg(CCObject *pSender, TouchEventType type);				//显示解锁对话框

	void OnHideReleaseDlg(CCObject *pSender, TouchEventType type);				//隐藏解锁对话框

	void OnBtnSureRelease(CCObject *pSender, TouchEventType type);				//确定解锁



protected:
	virtual bool init();     
};

#endif
.cpp文件
#include "NFRoleSelectLayer.h"
#include "NFTownScene.h"
#include "NFLoginScene.h"
#include "datamanager/NFServerDataManager.h"
/************************************************************************/
/*人物选择层<span style="white-space:pre">															</span>*/
/************************************************************************/


CCScene * CNFRoleSelectLayer::scene()
{
<span style="white-space:pre">	</span>do 
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>CCScene* pScene = CCScene::create();
<span style="white-space:pre">		</span>CC_BREAK_IF(pScene==NULL);


<span style="white-space:pre">		</span>CNFRoleSelectLayer* pLayer = CNFRoleSelectLayer::CreateLayer();
<span style="white-space:pre">		</span>CC_BREAK_IF(pLayer==NULL);


<span style="white-space:pre">		</span>pScene->addChild(pLayer);
<span style="white-space:pre">		</span>return pScene;


<span style="white-space:pre">	</span>} while (false);
<span style="white-space:pre">	</span>CCLog("Fun CNFRoleSelectLayer::scene Error!");
<span style="white-space:pre">	</span>return NULL;
}


CNFRoleSelectLayer * CNFRoleSelectLayer::CreateLayer()
{
<span style="white-space:pre">	</span>CNFRoleSelectLayer *pRet = new CNFRoleSelectLayer();
<span style="white-space:pre">	</span>if (pRet && pRet->init())
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>pRet->autorelease();
<span style="white-space:pre">		</span>return pRet;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>CCLog("Fun CNFRoleSelectLayer::CreateLayer Error!");
<span style="white-space:pre">	</span>delete pRet; 
<span style="white-space:pre">	</span>pRet = NULL; 
<span style="white-space:pre">	</span>return NULL;
}


bool CNFRoleSelectLayer::init()
{
<span style="white-space:pre">	</span>do 
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>//初始化父类
<span style="white-space:pre">		</span>CC_BREAK_IF(CCLayer::init()==false);


<span style="white-space:pre">		</span>m_nRoleID = 0;
<span style="white-space:pre">		</span>m_nRelaseRoleID = 0;
<span style="white-space:pre">		</span>//创建主场景UI层
<span style="white-space:pre">		</span>UILayer* pUiLayer = UILayer::create(); 
<span style="white-space:pre">		</span>CC_BREAK_IF(pUiLayer==NULL);


<span style="white-space:pre">		</span>//-------------------加入主场景UI----------------------------
<span style="white-space:pre">		</span>UILayout *pBg = dynamic_cast<UILayout*><span style="white-space:pre">	</span>(GUIReader::shareReader()->widgetFromJsonFile("Character_Select_Bg_NF.json"));
<span style="white-space:pre">		</span>CC_BREAK_IF(pBg==NULL);
<span style="white-space:pre">		</span>addChild(pBg,enZOrderBack);
<span style="white-space:pre">		</span>pBg->setSize(getContentSize());




<span style="white-space:pre">		</span>UILayout *pCharacter_Select = dynamic_cast<UILayout*><span style="white-space:pre">	</span>(GUIReader::shareReader()->widgetFromJsonFile("Character_Select_NF.json"));
<span style="white-space:pre">		</span>CC_BREAK_IF(pCharacter_Select==NULL);
<span style="white-space:pre">		</span>pUiLayer->addWidget(pCharacter_Select);
<span style="white-space:pre">		</span>pCharacter_Select->setName("Character_Select_Layer");
<span style="white-space:pre">		</span>pCharacter_Select->setSize(getContentSize());


<span style="white-space:pre">		</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/xiaoyin.ExportJson");
<span style="white-space:pre">		</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/NewProject.ExportJson");
<span style="white-space:pre">		</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/minren1.ExportJson");


<span style="white-space:pre">		</span>//设置开始游戏回调
<span style="white-space:pre">		</span>UIButton* pBtn_Start_Game = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName("Btn_Start_Game"));
<span style="white-space:pre">		</span>CC_BREAK_IF(pBtn_Start_Game==NULL);
<span style="white-space:pre">		</span>pBtn_Start_Game->addTouchEventListener(this,toucheventselector(CNFRoleSelectLayer::OnGameStartPage));




<span style="white-space:pre">		</span>//读取角色信息
<span style="white-space:pre">		</span>CNFServerRoleSelectInfoVec RoleSelectInfoVec;
<span style="white-space:pre">		</span>CNFServerDataManager::SharedData()->GetRoleSelectInfo(RoleSelectInfoVec);
<span style="white-space:pre">		</span>CNFServerRoleSelectInfoVec::iterator itRole=RoleSelectInfoVec.begin();


<span style="white-space:pre">		</span>char cName[3][256]={"minren1","xiaoyin","NewProject"};
<span style="white-space:pre">		</span>for (int i=0;itRole!=RoleSelectInfoVec.end();itRole++,i++)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>UIWidget* pChar=dynamic_cast<UIWidget*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString()));
<span style="white-space:pre">			</span>CC_BREAK_IF(pChar==NULL);




<span style="white-space:pre">			</span>UIButton* pBtn_Main_Role = dynamic_cast<UIButton*>(pChar->getChildByName("Btn_Main_Role"));
<span style="white-space:pre">			</span>CC_BREAK_IF(pBtn_Main_Role==NULL);
<span style="white-space:pre">			</span>pBtn_Main_Role->addTouchEventListener(this,toucheventselector(CNFRoleSelectLayer::OnRoleSelect));
<span style="white-space:pre">			</span>pBtn_Main_Role->setEnabled(false);


<span style="white-space:pre">			</span>UIButton* pBtnCancel_Follow = dynamic_cast<UIButton*>(pChar->getChildByName("Btn_Cancel_Follow"));
<span style="white-space:pre">			</span>CC_BREAK_IF(pBtnCancel_Follow==NULL);
<span style="white-space:pre">			</span>pBtnCancel_Follow->setEnabled(false);
<span style="white-space:pre">			</span>pBtnCancel_Follow->addTouchEventListener(this,toucheventselector(CNFRoleSelectLayer::OnCancelFollowSelect));


<span style="white-space:pre">			</span>UIButton* pBtnFollow = dynamic_cast<UIButton*>(pChar->getChildByName("Btn_Follow"));
<span style="white-space:pre">			</span>CC_BREAK_IF(pBtnFollow==NULL);
<span style="white-space:pre">			</span>pBtnFollow->setEnabled(false);
<span style="white-space:pre">			</span>pBtnFollow->addTouchEventListener(this,toucheventselector(CNFRoleSelectLayer::OnFollowSelect));


<span style="white-space:pre">			</span>CCArmature *pRole = CCArmature::create(cName[i]);
<span style="white-space:pre">			</span>CC_BREAK_IF(pRole==NULL);
<span style="white-space:pre">			</span>pRole->setPosition(ccp(pChar->getPositionX()+SCREEN_WIDTH/2,pChar->getPositionY()-100));
<span style="white-space:pre">			</span>pRole->setAnchorPoint(ccp(pRole->getAnchorPoint().x,0));
<span style="white-space:pre">			</span>pRole->setScale(1.5f);
<span style="white-space:pre">			</span>pRole->getAnimation()->play("hold",-1,-1,-1,10000);
<span style="white-space:pre">			</span>addChild(pRole,enZOrderFront,enTagRole1+i);


<span style="white-space:pre">			</span>UIButton* pBtn_Release_Lock = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString())->getChildByName("Btn_Release_Lock"));
<span style="white-space:pre">			</span>CC_BREAK_IF(pBtn_Release_Lock==NULL);
<span style="white-space:pre">			</span>pBtn_Release_Lock->addTouchEventListener(this,toucheventselector(CNFRoleSelectLayer::OnShowReleaseDlg));




<span style="white-space:pre">			</span>if (itRole->nState==0)//空闲
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>pBtn_Release_Lock->setEnabled(false);
<span style="white-space:pre">				</span>pBtn_Main_Role->setEnabled(true);
<span style="white-space:pre">				</span>pBtn_Main_Role->setVisible(true);
<span style="white-space:pre">				</span>pBtnFollow->setEnabled(true);
<span style="white-space:pre">				</span>pBtnFollow->setVisible(true);
<span style="white-space:pre">			</span>}


<span style="white-space:pre">			</span>if (itRole->nState==1)//出战
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>pBtn_Release_Lock->setEnabled(false);
<span style="white-space:pre">				</span>pBtn_Main_Role->setEnabled(false);
<span style="white-space:pre">				</span>pBtn_Main_Role->setVisible(false);


<span style="white-space:pre">				</span>//获取按下图
<span style="white-space:pre">				</span>UIImageView* pBtn_Select_Img=dynamic_cast<UIImageView*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName("Select_Main_Role_Img"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn_Select_Img==NULL);


<span style="white-space:pre">				</span>pBtn_Select_Img->setVisible(true);
<span style="white-space:pre">				</span>pBtn_Select_Img->setPosition(pChar->getPosition());
<span style="white-space:pre">				</span>pBtn_Start_Game->setVisible(true);


<span style="white-space:pre">				</span>m_nRoleID=itRole->nRoleID;
<span style="white-space:pre">			</span>}


<span style="white-space:pre">			</span>if (itRole->nState==2)//助战
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>pBtn_Release_Lock->setEnabled(false);
<span style="white-space:pre">				</span>pBtn_Main_Role->setEnabled(true);
<span style="white-space:pre">				</span>pBtn_Main_Role->setVisible(true);
<span style="white-space:pre">				</span>pBtnCancel_Follow->setEnabled(true);
<span style="white-space:pre">				</span>pBtnCancel_Follow->setVisible(true);


<span style="white-space:pre">				</span>//获取按下图
<span style="white-space:pre">				</span>UIImageView* pBtn_Select_Img=dynamic_cast<UIImageView*>(pChar->getChildByName("Select_Follow_Img"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn_Select_Img==NULL);


<span style="white-space:pre">				</span>pBtn_Select_Img->setVisible(true);
<span style="white-space:pre">			</span>}


<span style="white-space:pre">		</span>}










<span style="white-space:pre">		</span>//设置返回开始界面回调
<span style="white-space:pre">		</span>UIButton* pBtn_Return = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName("Btn_Return"));
<span style="white-space:pre">		</span>CC_BREAK_IF(pBtn_Return==NULL);
<span style="white-space:pre">		</span>pBtn_Return->addTouchEventListener(this,toucheventselector(CNFRoleSelectLayer::OnBack));




<span style="white-space:pre">		</span>//隐藏解锁对话框
<span style="white-space:pre">		</span>UIImageView *pReleaseDlg = dynamic_cast<UIImageView*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName("ReleaseDlg"));
<span style="white-space:pre">		</span>CC_BREAK_IF(pReleaseDlg==NULL);
<span style="white-space:pre">		</span>pReleaseDlg->setEnabled(false);
<span style="white-space:pre">		</span>pReleaseDlg->setVisible(false);


<span style="white-space:pre">		</span>UIButton *pCloseDlg=dynamic_cast<UIButton*>(pReleaseDlg->getChildByName("Btn_Close"));
<span style="white-space:pre">		</span>CC_BREAK_IF(pCloseDlg==NULL);
<span style="white-space:pre">		</span>pCloseDlg->addTouchEventListener(this,toucheventselector(CNFRoleSelectLayer::OnHideReleaseDlg));




<span style="white-space:pre">		</span>UIButton *pBtn_Sure=dynamic_cast<UIButton*>(pReleaseDlg->getChildByName("Btn_Sure"));
<span style="white-space:pre">		</span>CC_BREAK_IF(pBtn_Sure==NULL);
<span style="white-space:pre">		</span>pBtn_Sure->addTouchEventListener(this,toucheventselector(CNFRoleSelectLayer::OnBtnSureRelease));


<span style="white-space:pre">		</span>addChild(pUiLayer,enZOrderFront,enTagStudioMainUiLayer);










<span style="white-space:pre">		</span>return true;
<span style="white-space:pre">	</span>} while (false);
<span style="white-space:pre">	</span>CCLog("Fun CNFRoleSelectLayer::init Error!");
<span style="white-space:pre">	</span>return false;
}


void CNFRoleSelectLayer::OnGameStartPage( CCObject *pSender, TouchEventType type )
{
<span style="white-space:pre">	</span>do 
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>switch (type)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">		</span>case TOUCH_EVENT_ENDED:
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>//跳转到城镇
<span style="white-space:pre">				</span>CCScene * pScene = CNFTownScene::CreateTownScene(1,m_nRoleID);
<span style="white-space:pre">				</span>CC_BREAK_IF(pScene==NULL);
<span style="white-space:pre">				</span>CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1.f,pScene));
<span style="white-space:pre">				</span>
<span style="white-space:pre">			</span>}break;
<span style="white-space:pre">		</span>default:
<span style="white-space:pre">			</span>break;
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>return;
<span style="white-space:pre">	</span>} while (false);
<span style="white-space:pre">	</span>CCLog("CNFRoleSelectLayer::OnGameStartPage Error");
}


void CNFRoleSelectLayer::OnRoleSelect( CCObject *pSender, TouchEventType type )
{
<span style="white-space:pre">	</span>do 
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>switch (type)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">		</span>case TOUCH_EVENT_ENDED:
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>UILayer* pMainUiLayer = dynamic_cast<UILayer*>(getChildByTag(enTagStudioMainUiLayer));
<span style="white-space:pre">				</span>CC_BREAK_IF(pMainUiLayer==NULL);


<span style="white-space:pre">				</span>UILayout *pCharacter_Select = dynamic_cast<UILayout*><span style="white-space:pre">	</span>(pMainUiLayer->getWidgetByName("Character_Select_Layer"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pCharacter_Select==NULL);


<span style="white-space:pre">				</span>for (int i=0;i<3;i++)
<span style="white-space:pre">				</span>{


<span style="white-space:pre">					</span>UIButton* pBtn_Release_Lock = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString())->getChildByName("Btn_Release_Lock"));
<span style="white-space:pre">					</span>CC_BREAK_IF(pBtn_Release_Lock==NULL);
<span style="white-space:pre">					</span>if(pBtn_Release_Lock->isEnabled())continue;


<span style="white-space:pre">					</span>UIButton* pBtnSelect = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString())->getChildByName("Btn_Main_Role"));
<span style="white-space:pre">					</span>CC_BREAK_IF(pBtnSelect==NULL);
<span style="white-space:pre">					</span>pBtnSelect->setVisible(true);
<span style="white-space:pre">					</span>pBtnSelect->setEnabled(true);


<span style="white-space:pre">					</span>UIButton* pBtnFollow = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString())->getChildByName("Btn_Follow"));
<span style="white-space:pre">					</span>CC_BREAK_IF(pBtnFollow==NULL);
<span style="white-space:pre">					</span>pBtnFollow->setVisible(true);
<span style="white-space:pre">					</span>pBtnFollow->setEnabled(true);


<span style="white-space:pre">					</span>UIButton* pBtnCancel_Follow = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString())->getChildByName("Btn_Cancel_Follow"));
<span style="white-space:pre">					</span>CC_BREAK_IF(pBtnCancel_Follow==NULL);
<span style="white-space:pre">					</span>pBtnCancel_Follow->setEnabled(false);
<span style="white-space:pre">					</span>pBtnCancel_Follow->setVisible(false);


<span style="white-space:pre">					</span>//获取按下图
<span style="white-space:pre">					</span>UIImageView* pBtn_Select_Img=dynamic_cast<UIImageView*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString())->getChildByName("Select_Follow_Img"));
<span style="white-space:pre">					</span>CC_BREAK_IF(pBtn_Select_Img==NULL);
<span style="white-space:pre">					</span>pBtn_Select_Img->setVisible(false);


<span style="white-space:pre">				</span>}






<span style="white-space:pre">				</span>UIButton* pBtn = dynamic_cast<UIButton*>(pSender);
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn==NULL);
<span style="white-space:pre">				</span>pBtn->setVisible(false);
<span style="white-space:pre">			</span>


<span style="white-space:pre">				</span>UIWidget* pUiLayer = dynamic_cast<UIWidget*>(pBtn->getParent()->getParent());
<span style="white-space:pre">				</span>CC_BREAK_IF(pUiLayer==NULL);


<span style="white-space:pre">				</span>UIWidget* pChar = dynamic_cast<UIWidget*>(pBtn->getParent());
<span style="white-space:pre">				</span>CC_BREAK_IF(pChar==NULL);




<span style="white-space:pre">				</span>//判断选择的那个角色
<span style="white-space:pre">				</span>if (strcmp("Char_1",pChar->getName())==0)<span style="white-space:pre">	</span>m_nRoleID = 1;<span style="white-space:pre">	</span>//鸣人
<span style="white-space:pre">				</span>else if (strcmp("Char_2",pChar->getName())==0)<span style="white-space:pre">	</span>m_nRoleID = 2;<span style="white-space:pre">	</span>//小樱
<span style="white-space:pre">				</span>else if (strcmp("Char_3",pChar->getName())==0)<span style="white-space:pre">	</span>m_nRoleID = 3;<span style="white-space:pre">	</span>//佐助
<span style="white-space:pre">				</span>//CCLog("%d",m_nRoleID);


<span style="white-space:pre">				</span>for (int i=0;i<3;i++)
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>CCArmature *pRole = dynamic_cast<CCArmature*>(getChildByTag(i+enTagRole1));
<span style="white-space:pre">					</span>CC_BREAK_IF(pRole==NULL);


<span style="white-space:pre">					</span>if (pRole->getPositionX()-SCREEN_WIDTH/2==pChar->getPositionX())
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>
<span style="white-space:pre">						</span>
<span style="white-space:pre">						</span>if (strcmp("Char_1",pChar->getName())==0)<span style="white-space:pre">	</span>pRole->getAnimation()->play("skill_2",-1,-1,-1,10000);<span style="white-space:pre">	</span>//鸣人
<span style="white-space:pre">						</span>else if (strcmp("Char_2",pChar->getName())==0)<span style="white-space:pre">	</span>pRole->getAnimation()->play("skill_3",-1,-1,-1,10000);<span style="white-space:pre">	</span>//小樱
<span style="white-space:pre">						</span>else if (strcmp("Char_3",pChar->getName())==0)<span style="white-space:pre">	</span>pRole->getAnimation()->play("skill_5",-1,-1,-1,10000);<span style="white-space:pre">	</span>//佐助
<span style="white-space:pre">					</span>}
<span style="white-space:pre">					</span>else
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>pRole->getAnimation()->play("hold",-1,-1,-1,10000);
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>}




<span style="white-space:pre">				</span>UIButton* pBtnFollowSelect = dynamic_cast<UIButton*>(pChar->getChildByName("Btn_Follow"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtnFollowSelect==NULL);
<span style="white-space:pre">				</span>pBtnFollowSelect->setEnabled(false);
<span style="white-space:pre">				</span>pBtnFollowSelect->setVisible(false);


<span style="white-space:pre">				</span>//获取按下图
<span style="white-space:pre">				</span>UIImageView* pBtn_Select_Img=dynamic_cast<UIImageView*>(pUiLayer->getChildByName("Select_Main_Role_Img"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn_Select_Img==NULL);


<span style="white-space:pre">				</span>pBtn_Select_Img->setVisible(true);
<span style="white-space:pre">				</span>pBtn_Select_Img->setPosition(pChar->getPosition());




<span style="white-space:pre">				</span>//设置开始游戏回调
<span style="white-space:pre">				</span>UIButton* pBtn_Start_Game = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName("Btn_Start_Game"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn_Start_Game==NULL);
<span style="white-space:pre">				</span>pBtn_Start_Game->setVisible(true);


<span style="white-space:pre">			</span>}break;
<span style="white-space:pre">		</span>default:
<span style="white-space:pre">			</span>break;
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>return;
<span style="white-space:pre">	</span>} while (false);
<span style="white-space:pre">	</span>CCLog("CNFRoleSelectLayer::OnRoleSelect Error");
}


void CNFRoleSelectLayer::OnBack( CCObject *pSender, TouchEventType type )
{
<span style="white-space:pre">	</span>do 
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>switch (type)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">		</span>case TOUCH_EVENT_ENDED:
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>//跳转到服务器选择界面
<span style="white-space:pre">				</span>CCScene * pScene = CNFLoginScene::scene();
<span style="white-space:pre">				</span>CC_BREAK_IF(pScene==NULL);
<span style="white-space:pre">				</span>CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1.f,pScene));
<span style="white-space:pre">			</span>}break;
<span style="white-space:pre">		</span>default:
<span style="white-space:pre">			</span>break;
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>return;
<span style="white-space:pre">	</span>} while (false);
<span style="white-space:pre">	</span>CCLog("CNFRoleSelectLayer::OnBack Error");
}


void CNFRoleSelectLayer::OnFollowSelect( CCObject *pSender, TouchEventType type )
{
<span style="white-space:pre">	</span>do 
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>switch (type)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">		</span>case TOUCH_EVENT_ENDED:
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>//UILayer* pMainUiLayer = dynamic_cast<UILayer*>(getChildByTag(enTagStudioMainUiLayer));
<span style="white-space:pre">				</span>//CC_BREAK_IF(pMainUiLayer==NULL);


<span style="white-space:pre">				</span>//UILayout *pCharacter_Select = dynamic_cast<UILayout*><span style="white-space:pre">	</span>(pMainUiLayer->getWidgetByName("Character_Select_Layer"));
<span style="white-space:pre">				</span>//CC_BREAK_IF(pCharacter_Select==NULL);


<span style="white-space:pre">				</span>//for (int i=0;i<3;i++)
<span style="white-space:pre">				</span>//{


<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>UIButton* pBtnSelect = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString())->getChildByName("Btn_Main_Role"));
<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>CC_BREAK_IF(pBtnSelect==NULL);
<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>pBtnSelect->setVisible(true);


<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>UIButton* pBtnFollow = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString())->getChildByName("Btn_Follow"));
<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>CC_BREAK_IF(pBtnFollow==NULL);
<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>pBtnFollow->setVisible(true);


<span style="white-space:pre">				</span>//}






<span style="white-space:pre">				</span>UIButton* pBtn = dynamic_cast<UIButton*>(pSender);
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn==NULL);
<span style="white-space:pre">				</span>pBtn->setVisible(false);
<span style="white-space:pre">				</span>pBtn->setEnabled(false);


<span style="white-space:pre">				</span>UIWidget* pChar = dynamic_cast<UIWidget*>(pBtn->getParent());
<span style="white-space:pre">				</span>CC_BREAK_IF(pChar==NULL);


<span style="white-space:pre">				</span>UIButton* pBtn_Cancel_Follow = dynamic_cast<UIButton*>(pChar->getChildByName("Btn_Cancel_Follow"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn_Cancel_Follow==NULL);


<span style="white-space:pre">				</span>pBtn_Cancel_Follow->setVisible(true);
<span style="white-space:pre">				</span>pBtn_Cancel_Follow->setEnabled(true);
<span style="white-space:pre">				</span>//获取按下图
<span style="white-space:pre">				</span>UIImageView* pBtn_Select_Img=dynamic_cast<UIImageView*>(pChar->getChildByName("Select_Follow_Img"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn_Select_Img==NULL);


<span style="white-space:pre">				</span>pBtn_Select_Img->setVisible(true);








<span style="white-space:pre">			</span>}break;
<span style="white-space:pre">		</span>default:
<span style="white-space:pre">			</span>break;
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>return;
<span style="white-space:pre">	</span>} while (false);
<span style="white-space:pre">	</span>CCLog("CNFRoleSelectLayer::OnFollowSelect Error");
}


void CNFRoleSelectLayer::OnCancelFollowSelect( CCObject *pSender, TouchEventType type )
{
<span style="white-space:pre">	</span>do 
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>switch (type)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">		</span>case TOUCH_EVENT_ENDED:
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>//UILayer* pMainUiLayer = dynamic_cast<UILayer*>(getChildByTag(enTagStudioMainUiLayer));
<span style="white-space:pre">				</span>//CC_BREAK_IF(pMainUiLayer==NULL);


<span style="white-space:pre">				</span>//UILayout *pCharacter_Select = dynamic_cast<UILayout*><span style="white-space:pre">	</span>(pMainUiLayer->getWidgetByName("Character_Select_Layer"));
<span style="white-space:pre">				</span>//CC_BREAK_IF(pCharacter_Select==NULL);


<span style="white-space:pre">				</span>//for (int i=0;i<3;i++)
<span style="white-space:pre">				</span>//{


<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>UIButton* pBtnSelect = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString())->getChildByName("Btn_Main_Role"));
<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>CC_BREAK_IF(pBtnSelect==NULL);
<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>pBtnSelect->setVisible(true);


<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>UIButton* pBtnFollow = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",i+1)->getCString())->getChildByName("Btn_Follow"));
<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>CC_BREAK_IF(pBtnFollow==NULL);
<span style="white-space:pre">				</span>//<span style="white-space:pre">	</span>pBtnFollow->setVisible(true);


<span style="white-space:pre">				</span>//}






<span style="white-space:pre">				</span>UIButton* pBtn = dynamic_cast<UIButton*>(pSender);
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn==NULL);
<span style="white-space:pre">				</span>pBtn->setVisible(false);
<span style="white-space:pre">				</span>pBtn->setEnabled(false);


<span style="white-space:pre">				</span>UIWidget* pChar = dynamic_cast<UIWidget*>(pBtn->getParent());
<span style="white-space:pre">				</span>CC_BREAK_IF(pChar==NULL);


<span style="white-space:pre">				</span>UIButton* pBtn_Follow = dynamic_cast<UIButton*>(pChar->getChildByName("Btn_Follow"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn_Follow==NULL);


<span style="white-space:pre">				</span>pBtn_Follow->setVisible(true);
<span style="white-space:pre">				</span>pBtn_Follow->setEnabled(true);
<span style="white-space:pre">				</span>//获取按下图
<span style="white-space:pre">				</span>UIImageView* pBtn_Select_Img=dynamic_cast<UIImageView*>(pChar->getChildByName("Select_Follow_Img"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn_Select_Img==NULL);


<span style="white-space:pre">				</span>pBtn_Select_Img->setVisible(false);








<span style="white-space:pre">			</span>}break;
<span style="white-space:pre">		</span>default:
<span style="white-space:pre">			</span>break;
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>return;
<span style="white-space:pre">	</span>} while (false);
<span style="white-space:pre">	</span>CCLog("CNFRoleSelectLayer::OnCancelFollowSelect Error");
}


void CNFRoleSelectLayer::OnShowReleaseDlg( CCObject *pSender, TouchEventType type )
{
<span style="white-space:pre">	</span>do 
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>switch (type)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">		</span>case TOUCH_EVENT_ENDED:
<span style="white-space:pre">			</span>{


<span style="white-space:pre">				</span>UILayer* pMainUiLayer = dynamic_cast<UILayer*>(getChildByTag(enTagStudioMainUiLayer));
<span style="white-space:pre">				</span>CC_BREAK_IF(pMainUiLayer==NULL);


<span style="white-space:pre">				</span>UILayout *pCharacter_Select = dynamic_cast<UILayout*><span style="white-space:pre">	</span>(pMainUiLayer->getWidgetByName("Character_Select_Layer"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pCharacter_Select==NULL);






<span style="white-space:pre">				</span>UIButton* pBtn = dynamic_cast<UIButton*>(pSender);
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn==NULL);




<span style="white-space:pre">				</span>UIWidget* pChar = dynamic_cast<UIWidget*>(pBtn->getParent());
<span style="white-space:pre">				</span>CC_BREAK_IF(pChar==NULL);




<span style="white-space:pre">				</span>//隐藏解锁对话框
<span style="white-space:pre">				</span>UIImageView *pReleaseDlg = dynamic_cast<UIImageView*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName("ReleaseDlg"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pReleaseDlg==NULL);
<span style="white-space:pre">				</span>pReleaseDlg->setEnabled(true);
<span style="white-space:pre">				</span>pReleaseDlg->setVisible(true);


<span style="white-space:pre">				</span>UILabel* pCharName = dynamic_cast<UILabel*>(pChar->getChildByName("Char_Info")->getChildByName("Name_Lable"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pCharName==NULL);




<span style="white-space:pre">				</span>UILabel *pName_Lable = dynamic_cast<UILabel*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName("ReleaseDlg")->getChildByName("Name_Lable"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pName_Lable==NULL);
<span style="white-space:pre">				</span>pName_Lable->setText(pCharName->getStringValue());
<span style="white-space:pre">		</span>


<span style="white-space:pre">				</span>//判断选择的那个角色
<span style="white-space:pre">				</span>if (strcmp("Char_1",pChar->getName())==0)<span style="white-space:pre">		</span>//鸣人
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>m_nRelaseRoleID=1;
<span style="white-space:pre">				</span>}
<span style="white-space:pre">				</span>else if (strcmp("Char_2",pChar->getName())==0)<span style="white-space:pre">	</span>//小樱
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>m_nRelaseRoleID=2;
<span style="white-space:pre">				</span>}
<span style="white-space:pre">				</span>else if (strcmp("Char_3",pChar->getName())==0)<span style="white-space:pre">	</span>//佐助
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>m_nRelaseRoleID=3;
<span style="white-space:pre">				</span>}






<span style="white-space:pre">			</span>}break;
<span style="white-space:pre">		</span>default:
<span style="white-space:pre">			</span>break;
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>return;
<span style="white-space:pre">	</span>} while (false);
<span style="white-space:pre">	</span>CCLog("CNFRoleSelectLayer::OnShowReleaseDlg Error");
}


void CNFRoleSelectLayer::OnBtnSureRelease( CCObject *pSender, TouchEventType type )
{
<span style="white-space:pre">	</span>do 
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>switch (type)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">		</span>case TOUCH_EVENT_ENDED:
<span style="white-space:pre">			</span>{
<span style="white-space:pre">				</span>if(m_nRelaseRoleID==0)return;




<span style="white-space:pre">				</span>UILayer* pMainUiLayer = dynamic_cast<UILayer*>(getChildByTag(enTagStudioMainUiLayer));
<span style="white-space:pre">				</span>CC_BREAK_IF(pMainUiLayer==NULL);


<span style="white-space:pre">				</span>UILayout *pCharacter_Select = dynamic_cast<UILayout*><span style="white-space:pre">	</span>(pMainUiLayer->getWidgetByName("Character_Select_Layer"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pCharacter_Select==NULL);




<span style="white-space:pre">				</span>//隐藏解锁对话框
<span style="white-space:pre">				</span>UIImageView *pReleaseDlg = dynamic_cast<UIImageView*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName("ReleaseDlg"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pReleaseDlg==NULL);
<span style="white-space:pre">				</span>pReleaseDlg->setEnabled(false);
<span style="white-space:pre">				</span>pReleaseDlg->setVisible(false);




<span style="white-space:pre">				</span>//读取角色信息
<span style="white-space:pre">				</span>CNFServerRoleSelectInfoVec RoleSelectInfoVec;
<span style="white-space:pre">				</span>CNFServerDataManager::SharedData()->GetRoleSelectInfo(RoleSelectInfoVec);
<span style="white-space:pre">				</span>CNFServerRoleSelectInfoVec::iterator itRole=RoleSelectInfoVec.begin();


<span style="white-space:pre">				</span>for (;itRole!=RoleSelectInfoVec.end();itRole++)
<span style="white-space:pre">				</span>{
<span style="white-space:pre">					</span>if (itRole->nRoleID==m_nRelaseRoleID)
<span style="white-space:pre">					</span>{
<span style="white-space:pre">						</span>itRole->nState=0;
<span style="white-space:pre">					</span>}
<span style="white-space:pre">				</span>}


<span style="white-space:pre">				</span>CNFServerDataManager::SharedData()->SetRoleSelectInfo(RoleSelectInfoVec);








<span style="white-space:pre">				</span>UIButton* pBtn_Release_Lock = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",m_nRelaseRoleID)->getCString())->getChildByName("Btn_Release_Lock"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn_Release_Lock==NULL);
<span style="white-space:pre">				</span>pBtn_Release_Lock->setEnabled(false);
<span style="white-space:pre">				</span>pBtn_Release_Lock->setVisible(false);


<span style="white-space:pre">				</span>UIButton* pBtnSelect = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",m_nRelaseRoleID)->getCString())->getChildByName("Btn_Main_Role"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtnSelect==NULL);
<span style="white-space:pre">				</span>pBtnSelect->setVisible(true);
<span style="white-space:pre">				</span>pBtnSelect->setEnabled(true);


<span style="white-space:pre">				</span>UIButton* pBtnFollow = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",m_nRelaseRoleID)->getCString())->getChildByName("Btn_Follow"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtnFollow==NULL);
<span style="white-space:pre">				</span>pBtnFollow->setVisible(true);
<span style="white-space:pre">				</span>pBtnFollow->setEnabled(true);


<span style="white-space:pre">				</span>UIButton* pBtnCancel_Follow = dynamic_cast<UIButton*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",m_nRelaseRoleID)->getCString())->getChildByName("Btn_Cancel_Follow"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtnCancel_Follow==NULL);
<span style="white-space:pre">				</span>pBtnCancel_Follow->setEnabled(false);
<span style="white-space:pre">				</span>pBtnCancel_Follow->setVisible(false);


<span style="white-space:pre">				</span>//获取按下图
<span style="white-space:pre">				</span>UIImageView* pBtn_Select_Img=dynamic_cast<UIImageView*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName(CCString::createWithFormat("Char_%d",m_nRelaseRoleID)->getCString())->getChildByName("Select_Follow_Img"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pBtn_Select_Img==NULL);
<span style="white-space:pre">				</span>pBtn_Select_Img->setVisible(false);


<span style="white-space:pre">				</span>




<span style="white-space:pre">			</span>}break;
<span style="white-space:pre">		</span>default:
<span style="white-space:pre">			</span>break;
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>return;
<span style="white-space:pre">	</span>} while (false);
<span style="white-space:pre">	</span>CCLog("CNFRoleSelectLayer::OnHideReleaseDlg Error");
}


void CNFRoleSelectLayer::OnHideReleaseDlg( CCObject *pSender, TouchEventType type )
{
<span style="white-space:pre">	</span>do 
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>switch (type)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">		</span>case TOUCH_EVENT_ENDED:
<span style="white-space:pre">			</span>{


<span style="white-space:pre">				</span>UILayer* pMainUiLayer = dynamic_cast<UILayer*>(getChildByTag(enTagStudioMainUiLayer));
<span style="white-space:pre">				</span>CC_BREAK_IF(pMainUiLayer==NULL);


<span style="white-space:pre">				</span>UILayout *pCharacter_Select = dynamic_cast<UILayout*><span style="white-space:pre">	</span>(pMainUiLayer->getWidgetByName("Character_Select_Layer"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pCharacter_Select==NULL);




<span style="white-space:pre">				</span>//隐藏解锁对话框
<span style="white-space:pre">				</span>UIImageView *pReleaseDlg = dynamic_cast<UIImageView*>(pCharacter_Select->getChildByName("Main_Ui")->getChildByName("ReleaseDlg"));
<span style="white-space:pre">				</span>CC_BREAK_IF(pReleaseDlg==NULL);
<span style="white-space:pre">				</span>pReleaseDlg->setEnabled(false);










<span style="white-space:pre">			</span>}break;
<span style="white-space:pre">		</span>default:
<span style="white-space:pre">			</span>break;
<span style="white-space:pre">		</span>}


<span style="white-space:pre">		</span>return;
<span style="white-space:pre">	</span>} while (false);
<span style="white-space:pre">	</span>CCLog("CNFRoleSelectLayer::OnHideReleaseDlg Error");
}

个人博客 www.sundaboke.com

分析Cocos2d-x横版ACT手游源代码 3、人物选择界面

标签:style   io   ar   os   sp   for   文件   on   art   

原文地址:http://blog.csdn.net/sundaboke/article/details/41516949

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!