小伙伴们今天晚上我要给大家讲讲cocos2dx之关卡开发,这里自己先看代码我里面写的很清楚了不懂的可以留言问我 我后续还有说明时间紧迫我暂时就不多写了,下次我在重点讲解
#ifndef __MISSIONUI_header__#define __MISSIONUI_header__#include <typedef.hpp>#include <cocos-base.h>#include <cocos-Widget.h>#include <ScreenUtil.hpp>#include <CMisc.hpp>#include <Facade.hpp>#include <Language.hpp>#include <Textbutton.hpp>#include <MissionDialogUi.hpp>CLIENT_NS_BEGIN;USING_NS_CC;using namespace cocos2d::cocosWidget;//关卡UIenum MissionUiBtn{ tagTurnBack,Tagstagenormal,TagstageElite,TagstageTeam,tagTurn@R_419_6823@,tagTurnRight,TagshowDialog};//button tag//todostruct MissionData{ int ID; int star; int result;};// enum MissionType// {// MISSION_TYPE_norMAL,// MISSION_TYPE_HARD,// MISSION_TYPE_GUILD,// // MISSION_TYPE_MAX// };//关卡类型枚举class CustomsPassUi : public CSceneExtension {public: CREATE_SCENE_FUNC(CustomsPassUi) CustomsPassUi(); virtual ~CustomsPassUi(); virtual voID onLoadResources(); virtual voID onLoadResourcesCompleted(); virtual voID onLoadScene(); virtual voID onEnterScene(); virtual voID onExitScene(); voID onLoadChild(); voID caseClick(); voID arrowClick(int i_arrowType);protected:private: CC_SYNTHESIZE(int,n_xMissionType,MissionType); //pageIndex int curtIndex; // PageVIEw Contener CWidgetWindow* m_pWindow; //ScollVIEw background 's textrue Texture2D *scollTexture; CC_SYNTHESIZE_Readonly(cocosWidget::CPageVIEw*,m_pMissionScrVIEw,MissionPage); //关卡SollVIEw背景图 CC_SYNTHESIZE_Readonly(CCSprite*,m_pScollVIEwBg,ScollVIEwBg); //返回 CC_SYNTHESIZE_Readonly(cocosWidget::Cbutton*,m_pMissionBackBtn,MissionBack); // 精英 CC_SYNTHESIZE_Readonly(Textbutton*,m_pEliteBtn,MissionElite); //普通 CC_SYNTHESIZE_Readonly(Textbutton*,m_pnormalBtn,Missionnormal); //Teambutton CC_SYNTHESIZE_Readonly(Textbutton*,m_pMissionTeam,MissionTeam); //Turn@R_419_6823@ CC_SYNTHESIZE_Readonly(cocosWidget::Cbutton*,m_pTurn@R_419_6823@,Mission@R_419_6823@); //Turn Right CC_SYNTHESIZE_Readonly(cocosWidget::Cbutton*,m_pTurnRight,MissionRight); private: Ref* pagevIEwDataSource(Ref* pConvertCell,unsigned int nPageIDx); voID onPageChanged(Ref* pObject,unsigned int nPageIndx); voID showDialogBack(CCObject* pSender);};APP_NS_END#endif __MISSIONUI_header__
#include "MissionUi.hpp"#include <MissionMediator.hpp>#include <Scale9Sprite.h>CLIENT_NS_BEGINCustomsPassUi::CustomsPassUi() : m_pScollVIEwBg(nullptr),m_pMissionScrVIEw(nullptr),m_pMissionBackBtn(nullptr),m_pEliteBtn(nullptr),m_pnormalBtn(nullptr),n_xMissionType(1),curtIndex(0){ setCachable(true); setautoRemoveUnusedTexture(true);}CustomsPassUi::~CustomsPassUi(){}voID CustomsPassUi::onLoadResources(){ addImageAsync("Common/bg.jpg"); addImageAsync("MissionUi/stage-map-elite-frame.jpg"); addImageAsync("MissionUi/stage-map-elite-frame_Alpha_mask.png"); addImageAsync("MissionUi/stage-map-frame.jpg"); addImageAsync("MissionUi/stage-map-frame_Alpha_mask.png"); addImageAsync("MissionUi/stageselect_map_bg_1.jpg"); addImageAsync("MissionUi/stageselect_map_bg_2.jpg"); addImageAsync("MissionUi/stageselect_map_bg_3.jpg"); addImageAsync("MissionUi/stageselect_map_bg_4.jpg"); addImageAsync("MissionUi/stageselect_map_bg_5.jpg"); addImageAsync("MissionUi/stageselect_map_bg_6.jpg"); addImageAsync("MissionUi/stageselect_map_bg_7.jpg"); addImageAsync("MissionUi/stageselect_map_bg_8.jpg"); addImageAsync("MissionUi/stageselect_map_bg_9.jpg"); addImageAsync("MissionUi/back_normal.png"); addImageAsync("MissionUi/back_seleted.png"); addImageAsync("MissionUi/button_normal.png"); addImageAsync("MissionUi/button_selected.png"); addImageAsync("MissionUi/nextbtn.jpg"); addImageAsync("MissionUi/nextbtn_Alpha_mask.png");}voID CustomsPassUi::onLoadResourcesCompleted(){}voID CustomsPassUi::onLoadScene(){ this->removeAllChildrenWithCleanup(true); onLoadChild();}voID CustomsPassUi::caseClick(){ //scollVIEw的背景图 switch (n_xMissionType) { case 1: { // normal Textrue scollTexture = getNewTexture("MissionUi/stage-map-frame.jpg","MissionUi/stage-map-frame_Alpha_mask.png"); } break; case 2: { // elite Textrue scollTexture = getNewTexture("MissionUi/stage-map-elite-frame.jpg","MissionUi/stage-map-elite-frame_Alpha_mask.png"); } break; case 3: { // Team Textrue } break; default: break; }}voID CustomsPassUi::onLoadChild(){ caseClick(); //背景图 CCSprite *bg = CCSprite::create("Common/bg.jpg"); bg->setposition(ScreenUtil::getCenter()); addChild(bg); if (scollTexture!=nullptr) { m_pScollVIEwBg = Sprite::createWithTexture(scollTexture); m_pScollVIEwBg->setAnchorPoint(Vec2(0.5,0)); m_pScollVIEwBg->setposition(Vec2(480,20)); addChild(m_pScollVIEwBg); } //返回按钮 m_pMissionBackBtn = cocosWidget::Cbutton::create("MissionUi/back_normal.png","MissionUi/back_seleted.png"); getMissionBack()->setAnchorPoint(ccp(0,0)); //getBagBack()->setScale(0.8f); getMissionBack()->setposition(ccp(60,570)); getMissionBack()->setTag(tagTurnBack); this->addChild(getMissionBack()); //普通按钮 m_pnormalBtn = Textbutton::create(LANGUAGE_VALUE("Mission_normal"),"MissionUi/button_normal.png","MissionUi/button_selected.png"); getMissionnormal()->setposition(Vec2(480 - 100,550)); getMissionnormal()->setTag(Tagstagenormal); addChild(getMissionnormal()); //精英按钮 m_pEliteBtn = Textbutton::create(LANGUAGE_VALUE("Mission_Elit"),"MissionUi/button_selected.png"); getMissionElite()->setposition(Vec2(480 + 130,550)); getMissionElite()->setTag(TagstageElite); addChild(getMissionElite()); //Teambutton m_pMissionTeam = Textbutton::create(LANGUAGE_VALUE("Mission_Team"),"MissionUi/button_selected.png"); getMissionTeam()->setposition(Vec2(480 + 390,550)); getMissionTeam()->setTag(TagstageTeam); addChild(getMissionTeam()); //Turn @R_419_6823@ m_pTurn@R_419_6823@ = cocosWidget::Cbutton::create("MissionUi/nextbtn.jpg","MissionUi/nextbtn_Alpha_mask.png"); getMission@R_419_6823@()->setposition(Vec2(20,320)); getMission@R_419_6823@()->setTag(tagTurn@R_419_6823@); addChild(getMission@R_419_6823@(),1); //Turn Right m_pTurnRight = cocosWidget::Cbutton::create("MissionUi/nextbtn.jpg","MissionUi/nextbtn_Alpha_mask.png"); getMissionRight()->setposition(Vec2(960 - 30,320)); getMissionRight()->setTag(tagTurnRight); addChild(getMissionRight(),1); m_pWindow = CWidgetWindow::create(); m_pWindow->setMultitouchEnabled(true); m_pWindow->setAnchorPoint(ccp(0,0)); m_pWindow->setposition(Vec2(10,30)); addChild(m_pWindow,1); //ScollVIEw m_pMissionScrVIEw = CPageVIEw::create( Size(910,470),9,this,ccw_datasource_adapter_selector(CustomsPassUi::pagevIEwDataSource)); m_pMissionScrVIEw->setonPageChangedListener(this,ccw_pagechanged_selector(CustomsPassUi::onPageChanged)); m_pMissionScrVIEw->setAnchorPoint(ccp(0,0)); m_pMissionScrVIEw->setposition(Vec2(20,30)); m_pMissionScrVIEw->setEnabled(true); m_pMissionScrVIEw->setDirection(eScrollVIEwDirectionHorizontal); m_pWindow->addChild(m_pMissionScrVIEw); m_pMissionScrVIEw->reloadData();}voID CustomsPassUi::onEnterScene(){ g_facade.sendNotification(FRAME_MESSAGE_ENTER_MISSION_UI);}voID CustomsPassUi::onExitScene(){// g_facade.sendNotification(FRAME_MESSAGE_EXIT_MISSION_UI);}Ref* CustomsPassUi::pagevIEwDataSource(Ref* pConvertCell,unsigned int nPageIDx){ CPageVIEwCell* pPageCell = (CPageVIEwCell*)pConvertCell; char pictruename[40]; sprintf(pictruename,"MissionUi/stageselect_map_bg_%d.jpg",nPageIDx + 1); Cbutton* m_pShowDialog = nullptr; Sprite* pageVIEwBg = nullptr; if (!pPageCell) { pPageCell = new CPageVIEwCell(); pPageCell->autorelease(); m_pShowDialog = Cbutton::create("MissionUi/nextbtn.jpg","MissionUi/nextbtn_Alpha_mask.png"); m_pShowDialog->setonClickListener(this,ccw_click_selector(MissionMediator::onClickBtn)); m_pShowDialog->setposition(200,250); m_pShowDialog->setTag(TagshowDialog); pPageCell->addChild(m_pShowDialog); pageVIEwBg = Sprite::create(); pageVIEwBg->setposition(Vec2(455,235)); pageVIEwBg->setTag(100001); pPageCell->addChild(pageVIEwBg); } else { m_pShowDialog = (Cbutton*)pPageCell->getChildByTag(TagshowDialog); pageVIEwBg = (Sprite*)pPageCell->getChildByTag(100001); } pageVIEwBg->setTexture(pictruename); return pPageCell;}voID CustomsPassUi::onPageChanged(Ref* pObject,unsigned int nPageIndx){ //pageIndex = nPageIndx;}voID CustomsPassUi::arrowClick(int i_arrowType){ cclog("=============click @R_419_6823@======="); if (i_arrowType == 1) { //向左 if (curtIndex == 0) { this->removeChildByTag(tagTurn@R_419_6823@); } else { curtIndex -= 1; m_pTurnRight = cocosWidget::Cbutton::create("MissionUi/nextbtn.jpg","MissionUi/nextbtn_Alpha_mask.png"); getMissionRight()->setposition(Vec2(960 - 30,320)); getMissionRight()->setTag(tagTurnRight); addChild(getMissionRight(),1); m_pMissionScrVIEw->setContentOffsetEaseIn(Vec2(curtIndex * 910,0),0.05,0.5); } } else if (i_arrowType == 2) { //向右 cclog("=============Click right======"); if (curtIndex == 8) { this->removeChildByTag(tagTurnRight); } else { curtIndex += 1; m_pTurn@R_419_6823@ = cocosWidget::Cbutton::create("MissionUi/nextbtn.jpg","MissionUi/nextbtn_Alpha_mask.png"); getMission@R_419_6823@()->setposition(Vec2(20,320)); getMission@R_419_6823@()->setTag(tagTurn@R_419_6823@); addChild(getMission@R_419_6823@(),1); getMissionPage()->setContentOffsetEaseIn(Vec2(-(curtIndex * 910),0.5); } }}APP_NS_END
#include <ScreenUtil.hpp>#include <Language.hpp>#include <CMisc.hpp>#include <Facade.hpp>USING_NS_CC;CLIENT_NS_BEGINusing namespace cocosWidget;enum DialogBtn{ TagstageBack,Tagstagefight};@H_404_666@ class CustomsPassDialogUi : public CSceneExtension { public: CREATE_SCENE_FUNC(CustomsPassDialogUi); CustomsPassDialogUi(); ~CustomsPassDialogUi(); virtual voID onLoadResources(); virtual voID onLoadResourcesCompleted(); virtual voID onLoadScene(); virtual voID onEnterScene(); virtual voID onExitScene(); private: voID initDialog(); private: CC_SYNTHESIZE_Readonly(int,n_pMissionID,MissionID); //调用的关卡ID CC_SYNTHESIZE_Readonly(int,n_pMissionType,MissionDialogType);//调用关卡类型 CC_SYNTHESIZE_Readonly(Sprite*,m_pBackPictrue,BackPictrue); //地图图片 CC_SYNTHESIZE_Readonly(Texture2D*,m_pFrameTextrue,FrameTexture); //d窗背景Texture CC_SYNTHESIZE_Readonly(Sprite*,m_pBg,Bg); //d框背景 CC_SYNTHESIZE_Readonly(Sprite*,m_pStar,Star); //星星 CC_SYNTHESIZE_Readonly(cocosWidget::Cbutton*,m_pBack,CallBackBtn); //返回按钮 CC_SYNTHESIZE_Readonly(cocosWidget::Cbutton*,m_pfightBtn,GofightBtn); //战斗按钮 CC_SYNTHESIZE_Readonly(cocosWidget::CLabel*,m_pTitle,LabelTitle); //该关卡名字 CC_SYNTHESIZE_Readonly(cocosWidget::CLabel*,m_pDes,LabelDes); //描述该关卡 CC_SYNTHESIZE_Readonly(cocosWidget::CLabel*,m_pConsume,LabelConsume);//体力消耗数值 // todo 敌方阵容....可能获得...图片显示 }; APP_NS_END #endif
#include "MissionDialogUi.hpp"#include <XmlConfig.hpp>CLIENT_NS_BEGINCustomsPassDialogUi::CustomsPassDialogUi(){ setCachable(true); //setautoRemoveUnusedTexture(true);}CustomsPassDialogUi::~CustomsPassDialogUi(){}voID CustomsPassDialogUi::onLoadResources(){ addImageAsync("MissionUi/stage-map-frame.jpg"); addImageAsync("MissionUi/stage-map-frame_Alpha_mask.png"); addImageAsync("MissionUi/star-Disabled.jpg"); addImageAsync("MissionUi/star-Disabled_Alpha_mask.png"); addImageAsync("MissionUi/star.jpg"); addImageAsync("MissionUi/star_Alpha_mask.png"); addImageAsync("MissionUi/back_normal.png"); addImageAsync("MissionUi/back_seleted.png"); addImageAsync("MissionUi/resume_battle.jpg"); addImageAsync("MissionUi/resume_battle_Alpha_mask.png"); addImageAsync("MissionUi/resume_battle_press.jpg"); addImageAsync("MissionUi/resume_battle_press_Alpha_mask.png");}voID CustomsPassDialogUi::onLoadResourcesCompleted(){}voID CustomsPassDialogUi::onLoadScene(){ initDialog();}// @param关卡ID,类型voID CustomsPassDialogUi::initDialog(){ m_pBackPictrue = Sprite::create("MissionUi/stageselect_map_bg_1.jpg"); m_pBackPictrue->setAnchorPoint(ccp(0,0)); m_pBackPictrue->setposition(ccp(20,20)); m_pBackPictrue->setopacity(40); addChild(m_pBackPictrue); m_pFrameTextrue = getNewTexture("MissionUi/stage-map-frame.jpg","MissionUi/stage-map-frame_Alpha_mask.png"); m_pBg = Sprite::createWithTexture(m_pFrameTextrue); m_pBg->setAnchorPoint(ccp(0,0)); /* m_pBg->setopacity(100);*/ m_pBg->setposition(ccp(20,20)); addChild(m_pBg); //关卡名字 m_pTitle = CLabel::create(); getLabelTitle()->setString(""); getLabelTitle()->setcolor(color3B(227,207,87)); getLabelTitle()->setposition(ccp(300,480)); addChild(getLabelTitle()); //关卡描述 m_pDes = CLabel::create(); getLabelDes()->setString(""); getLabelDes()->setcolor(color3B(255,255,255)); getLabelDes()->setposition(100,450); addChild(getLabelDes()); //星星 auto disStarTexture = getNewTexture("MissionUi/star-Disabled.jpg","MissionUi/star-Disabled_Alpha_mask.png"); auto starTexture = getNewTexture("MissionUi/star.jpg","MissionUi/star_Alpha_mask.png"); for (int i = 0; i < 3; i++) { m_pStar = Sprite::createWithTexture(disStarTexture); getStar()->setAnchorPoint(ccp(0.5,0)); getStar()->setposition(ccp(450 + i * 100,500)); addChild(getStar()); } //体力消耗 auto strengDes = CLabel::create(); strengDes->setString(LANGUAGE_VALUE("MissionDialog_cosstr")); strengDes->setcolor(color3B(255,277,132)); strengDes->setposition(ccp(100,350)); addChild(strengDes); //体力消耗数值 m_pConsume = CLabel::create(); getLabelConsume()->setString(""); getLabelConsume()->setcolor(color3B(227,87)); getLabelConsume()->setposition(ccp(130,350)); addChild(getLabelConsume()); //体力图片 //敌方阵容 auto enmeyLable = CLabel::create(); enmeyLable->setString(LANGUAGE_VALUE("MissionDialog_EnemyArr")); enmeyLable->setcolor(color3B(255,132)); enmeyLable->setposition(ccp(130,320)); addChild(enmeyLable); //可能获得 auto gainLable = CLabel::create(); gainLable->setString(LANGUAGE_VALUE("MissionDialog_gain")); gainLable->setcolor(color3B(255,132)); gainLable->setposition(ccp(130,300)); addChild(gainLable); //返回按钮 m_pBack = Cbutton::create("MissionUi/back_normal.png","MissionUi/back_seleted.png"); m_pBack->setposition(ccp(100,540)); getCallBackBtn()->setTag(TagstageBack); addChild(m_pBack); //去战斗按钮 auto normalTextrue = getNewTexture("MissionUi/resume_battle.jpg","MissionUi/resume_battle_Alpha_mask.png"); auto secletTextrue = getNewTexture("MissionUi/resume_battle_press.jpg","MissionUi/resume_battle_press_Alpha_mask.png"); m_pfightBtn = Cbutton::create(); m_pfightBtn->setnormalTexture(normalTextrue); m_pfightBtn->setSelectedTexture(secletTextrue); m_pfightBtn->setposition(620,100); getGofightBtn()->setTag(Tagstagefight); addChild(m_pfightBtn);}voID CustomsPassDialogUi::onEnterScene(){ g_facade.sendNotification(FRAME_MESSAGE_ENTER_MISSIONDIALOG_UI);}voID CustomsPassDialogUi::onExitScene(){}APP_NS_END
#ifndef __MISSION_MEDIATOR_header__#define __MISSION_MEDIATOR_header__#include <typedef.hpp>#include <Mediator.hpp>#include "MissionUi.hpp"CLIENT_NS_BEGINUSING_NS_CC;struct MissionInfomation : public Ref{ int MissionInfoID; int MissionInfoType; int MissionInfoStar; MissionInfomation() { this->autorelease(); }};class CustomsPassMediator : public Mediator {public: CustomsPassMediator(); virtual ~CustomsPassMediator(); virtual voID onRegisterNotification(); virtual voID handleNotification(Notification* pNotification); virtual voID update(); virtual std::string getMediatorname(){ return "MissionMediator"; } frIEnd class MissionUi;private: CC_SYNTHESIZE_Readonly(MissionUi*,m_pMissionUi,MissionUi); CC_SYNTHESIZE(int,n_CurMissionID,CurMissionID); CC_SYNTHESIZE(int,n_CurMissionType,CurMissionType); CC_SYNTHESIZE(int,n_CurMissionStar,CurMissionStar); voID onClickBtn(CCObject* pObject);};APP_NS_END#endif
include "MissionMediator.hpp"#include <Facade.hpp>CLIENT_NS_BEGINCustomsPassMediator::CustomsPassMediator() :m_pMissionUi(nullptr){ REGISTER_SCENE_FUNC(MissionUi);}CustomsPassMediator::~CustomsPassMediator(){}voID CustomsPassMediator::onRegisterNotification(){ m_xFrameMessageVec.push_back(FRAME_MESSAGE_SHOW_MISSION_UI); m_xFrameMessageVec.push_back(FRAME_MESSAGE_ENTER_MISSION_UI); m_xFrameMessageVec.push_back(FRAME_MESSAGE_EXIT_MISSION_UI);}voID CustomsPassMediator::handleNotification(Notification* pNotification){ if (NulL == pNotification) { return; } switch (pNotification->m_xMessage) { case FRAME_MESSAGE_SHOW_MISSION_UI: { m_pMissionUi = (MissionUi*)LoadScene("MissionUi"); CSceneManager::getInstance()->replaceScene(m_pMissionUi); } break; case FRAME_MESSAGE_ENTER_MISSION_UI: { //返回按钮 getMissionUi()->getMissionBack()->setonClickListener(this,ccw_click_selector(CustomsPassMediator::onClickBtn)); //普通按钮 getMissionUi()->getMissionnormal()->setonClickListener(this,ccw_click_selector(CustomsPassMediator::onClickBtn)); //精英按钮 getMissionUi()->getMissionElite()->setonClickListener(this,ccw_click_selector(CustomsPassMediator::onClickBtn)); //团队按钮 getMissionUi()->getMissionTeam()->setonClickListener(this,ccw_click_selector(CustomsPassMediator::onClickBtn)); //向左按钮 getMissionUi()->getMission@R_419_6823@()->setonClickListener(this,ccw_click_selector(CustomsPassMediator::onClickBtn)); //向右按钮 getMissionUi()->getMissionRight()->setonClickListener(this,ccw_click_selector(CustomsPassMediator::onClickBtn)); } break; case FRAME_MESSAGE_EXIT_MISSION_UI: { g_facade.sendNotification(FRAME_MESSAGE_SHOW_MAIN_UI); /*CSceneManager::getInstance()->popScene(m_pMissionUi);*/ } break; }}voID CustomsPassMediator::update(){}voID CustomsPassMediator::onClickBtn(CCObject* pObject){ MissionInfomation* pMissionInfomation = nullptr; auto pbutton = (Cbutton*)pObject; switch (pbutton->getTag()) { case tagTurnBack: { cclog("tag Mission back"); g_facade.sendNotification(FRAME_MESSAGE_EXIT_MISSION_UI); //g_facade.sendNotification(FRAME_MESSAGE_SHOW_MAIN_UI); } break; case Tagstagenormal: { cclog("tag Mission normal"); getMissionUi()->setMissionType(1); setCurMissionType(1); getMissionUi()->onLoadChild(); } break; case TagstageElite: { cclog("tag Mission Elite"); getMissionUi()->setMissionType(2); setCurMissionType(2); getMissionUi()->onLoadChild(); } break; case TagstageTeam: { cclog("tag Mission Team"); getMissionUi()->setMissionType(3); setCurMissionType(3); getMissionUi()->onLoadChild(); } break; case tagTurn@R_419_6823@: { cclog("tag Turn @R_419_6823@"); getMissionUi()->arrowClick(1); } break; case tagTurnRight: { cclog("tag Turn @R_419_6823@"); getMissionUi()->arrowClick(2); } break; case TagshowDialog: { cclog("show Mission Dialog "); /* test,sendNotification to Dialog,pack this strcut,this ID should get from the MissionUI,this is a test. */ setCurMissionID(600001); pMissionInfomation = new MissionInfomation(); pMissionInfomation->MissionInfoID = getCurMissionID(); pMissionInfomation->MissionInfoType = 1; g_facade.sendNotification(FRAME_MESSAGE_SHOW_MISSIONDIALOG_UI); } break; }}APP_NS_END
#ifndef __MISSIONDIALOG_MEDIATOR_header__#define __MISSIONDIALOG_MEDIATOR_header__#include <typedef.hpp>#include <Mediator.hpp>#include "MissionDialogUi.hpp"#include <MissionProxy.hpp>CLIENT_NS_BEGINUSING_NS_CC;struct Data{ int dataID; int dataType;};class CustomsPassDialogMediator : public Mediator{public: CustomsPassDialogMediator(); virtual ~CustomsPassDialogMediator(); virtual voID onRegisterNotification(); virtual voID handleNotification(Notification* pNotification); virtual voID update(); virtual std::string getMediatorname(){ return "MissionDialogMediator"; } frIEnd class CustomsPassUi;private: CC_SYNTHESIZE_Readonly(MissionDialogUi*,m_pMissionDialogUi,MissionDialogUi); voID onClickBtn(CCObject* pObject); MissionProxy *pMissionProxy;};APP_NS_END#endif
#include "MissionDialogMediator.hpp"#include "MissionMediator.hpp"CLIENT_NS_BEGINCustomsPassDialogMediator::CustomsPassDialogMediator(){ REGISTER_SCENE_FUNC(MissionDialogUi); pMissionProxy = (MissionProxy*)g_facade.retrIEveProxy("MissionProxy");}CustomsPassDialogMediator::~CustomsPassDialogMediator(){}voID CustomsPassDialogMediator::onRegisterNotification(){ m_xFrameMessageVec.push_back(FRAME_MESSAGE_SHOW_MISSIONDIALOG_UI); m_xFrameMessageVec.push_back(FRAME_MESSAGE_ENTER_MISSIONDIALOG_UI); m_xFrameMessageVec.push_back(FRAME_MESSAGE_EXIT_MISSIONDIALOG_UI);}voID CustomsPassDialogMediator::handleNotification(Notification* pNotification){ if (NulL == pNotification) { return; } switch (pNotification->m_xMessage) { case FRAME_MESSAGE_SHOW_MISSIONDIALOG_UI: { //int ID = ((MissionInfomation*)pNotification->m_pBody)->MissionInfoID; m_pMissionDialogUi = (MissionDialogUi*)LoadScene("MissionDialogUi"); CSceneManager::getInstance()->pushScene(m_pMissionDialogUi); } break; case FRAME_MESSAGE_ENTER_MISSIONDIALOG_UI: { if (pMissionProxy == nullptr) { return; } else { //test information MissionTrunkVo *_CurMAPInfo = pMissionProxy->getMAPInfo(41010101); std::string s = _CurMAPInfo->getMapname(); getMissionDialogUi()->getLabelDes()->setString(s); } getMissionDialogUi()->getCallBackBtn()->setonClickListener(this,ccw_click_selector(CustomsPassDialogMediator::onClickBtn)); getMissionDialogUi()->getGofightBtn()->setonClickListener(this,ccw_click_selector(CustomsPassDialogMediator::onClickBtn)); } break; case FRAME_MESSAGE_EXIT_MISSIONDIALOG_UI: { CSceneManager::getInstance()->popScene(m_pMissionDialogUi); } break; }}voID CustomsPassDialogMediator::update(){}voID CustomsPassDialogMediator::onClickBtn(CCObject* pObject){ int nTag = ((cocosWidget::Cbutton*)pObject)->getTag(); switch (nTag) { case TagstageBack: { cclog(" tag MissionDialog Back"); g_facade.sendNotification(FRAME_MESSAGE_EXIT_MISSIONDIALOG_UI); } break; case Tagstagefight: { cclog("tag MissionDialog fight"); if (nullptr == pMissionProxy) { return; } pMissionProxy->onMission(201110243,2,1); } break; }}APP_NS_END
接下来这部分就是客户端向服务端发送消息,意思就是当我通过关卡以后我要去告诉服务端那边玩家是否打过 打过了该怎么怎么样,没打过该怎么这么样
#ifndef __MISSION_PROXY_header__#define __MISSION_PROXY_header__#include <typedef.hpp>#include <Proxy.hpp>#include <MissionVo.hpp>#include <Character.hpp>CLIENT_NS_BEGINUSING_NS_CC;class CustomsPassproxy : public Proxy{public: CustomsPassproxy(); ~CustomsPassproxy(); virtual voID onInitilize(); virtual voID onRegisterMessage(); virtual std::string getProxyname(){ return "MissionProxy"; } voID onMission(int ID,int mission_type,int star); voID handleMissionAgentTokenAck(Message::Ptr& pMessage); // Get this mAPId's information MissionTrunkVo* getMAPInfo(int mAPId); //get this node's information MissionBranchVo* getNodeInfo(int nodeID); //get this NodeID ' enmey information MissionArrayVo* getCurEnemyInfo(int nodeID);private: voID loadTrunkInfo(); voID loadBranchInfo(); voID loadArrayInfo();private: CC_SYNTHESIZE(CCDictionary*,m_pTrunkInfo,TrunkInfo); CC_SYNTHESIZE(CCDictionary*,m_pBranchInfo,BranchInfo); CC_SYNTHESIZE(CCDictionary*,m_pEnmeyArrInfo,EnmeyArrInfo);};APP_NS_END#endif
#include <MissionProxy.hpp>#include <tinyxml2/tinyxml2.h>#include <AgentServer/Mission.hpp>#include <Alert.hpp>#include <Facade.hpp>#include <NetDelegate.hpp>CLIENT_NS_BEGINCustomsPassproxy::CustomsPassproxy(){ m_pTrunkInfo = CCDictionary::create(); m_pTrunkInfo->retain(); m_pBranchInfo = CCDictionary::create(); m_pBranchInfo->retain(); m_pEnmeyArrInfo = CCDictionary::create(); m_pEnmeyArrInfo->retain();}CustomsPassproxy::~CustomsPassproxy(){}voID CustomsPassproxy::onInitilize(){ loadTrunkInfo(); loadBranchInfo(); loadArrayInfo();}voID CustomsPassproxy::onRegisterMessage(){ DEFREG_MESSAGE(ID_GS2C_EnterMissionAck,CustomsPassproxy,handleMissionAgentTokenAck)}voID CustomsPassproxy::handleMissionAgentTokenAck(Message::Ptr & pMessage){ GS2C_EnterMissionAck missionAgentTokenAck; pMessage->unpack(missionAgentTokenAck); if (missionAgentTokenAck.Result == 1 ) { MissionInfoVec xMissionInfoVec; StageInfoVec::iterator iter = missionAgentTokenAck.StageInfo.begin(); StageInfoVec::iterator end = missionAgentTokenAck.StageInfo.end(); for (; iter != end;++iter) { MissionInfo xMissionInfo; xMissionInfo.MissionID = iter->MissionsqlID; xMissionInfo.MissionType = iter->MissionsqlType; xMissionInfo.MissionStar = iter->MissionsqlStar; xMissionInfo.MissionCount = iter->MissionsqlCount; xMissionInfo.MissionresetCount = iter->MissionsqlresetCount; xMissionInfo.MissionDilayChallenge = iter->MissionsqlDilayChallenge; xMissionInfoVec.push_back(xMissionInfo); } g_character.setMissionInfoVec(xMissionInfoVec); } else { return; }}voID CustomsPassproxy::onMission(int ID,int mission_type,int star){ Message::Ptr sendMsg(new Message()); C2GS_MissionReq missionAgentTokenReq; missionAgentTokenReq.MissionToID = ID; missionAgentTokenReq.MissionToType = mission_type; missionAgentTokenReq.MissionToStar = star; missionAgentTokenReq.MissionToCount = 2; missionAgentTokenReq.MissionToresetCount = 1; missionAgentTokenReq.MissionToDilayChallenge = 3; sendMsg->pack(missionAgentTokenReq); g_netDelegate.send(sendMsg);}//地图读取voID CustomsPassproxy::loadTrunkInfo(){ ssize_t bufferSize = 0; unsigned char* pBuffer = CCfileUtils::sharedfileUtils()->getfileData("MissionData.xml","r",&bufferSize); if (NulL == pBuffer) { return; } tinyxml2::XMLdocument* pXml = new tinyxml2::XMLdocument(); pXml->Parse((const char*)pBuffer); tinyxml2::XMLElement* pNode = pXml->RootElement()->FirstChildElement(); MissionTrunkVo* pMissionTrunkVo = nullptr; while (pNode) { pMissionTrunkVo = new MissionTrunkVo(); pMissionTrunkVo->setMAPId(pNode->IntAttribute("MAPId")); // 地图ID pMissionTrunkVo->setMapname(pNode->Attribute("Mapname")); //地图名字 pMissionTrunkVo->setMapResource(pNode->Attribute("MapResource")); //地图资源 pMissionTrunkVo->setMapType(pNode->IntAttribute("MapType")); //地图类型 pMissionTrunkVo->setlimitLevel(pNode->IntAttribute("limitLevel")); //等级限制 pMissionTrunkVo->setlimitTime(pNode->IntAttribute("limitTime")); //时间限制 pMissionTrunkVo->setlimitType(pNode->IntAttribute("limitType")); //限制条件 pMissionTrunkVo->setlimitCon(pNode->IntAttribute("limitCon")); //限制条件参数 pMissionTrunkVo->setLastID(pNode->IntAttribute("LastID")); //前置要求 pMissionTrunkVo->autorelease(); m_pTrunkInfo->setobject(pMissionTrunkVo,pMissionTrunkVo->getMAPId()); pNode = pNode->NextSiblingElement(); }}//节点读取voID CustomsPassproxy::loadBranchInfo(){ ssize_t bufferSize = 0; unsigned char* pBuffer = CCfileUtils::sharedfileUtils()->getfileData("NodeData.xml",&bufferSize); if (NulL == pBuffer) { return; } tinyxml2::XMLdocument* pXml = new tinyxml2::XMLdocument(); pXml->Parse((const char*)pBuffer); tinyxml2::XMLElement* pNode = pXml->RootElement()->FirstChildElement(); MissionBranchVo* pMissionBranchVo = nullptr; while (pNode) { pMissionBranchVo = new MissionBranchVo(); pMissionBranchVo->setBranchID(pNode->IntAttribute("NodeID")); // 节点ID pMissionBranchVo->setNodename(pNode->Attribute("Nodename")); //节点名字 pMissionBranchVo->setNodeResource(pNode->Attribute("NodeResource")); //图片资源 pMissionBranchVo->setNodeMap(pNode->Attribute("NodeMap")); //所属地图 pMissionBranchVo->setNodeImage(pNode->Attribute("NodeImage")); //背景地图 pMissionBranchVo->setFrontID(pNode->IntAttribute("FrontID")); //前置节点 pMissionBranchVo->setNodeLevel(pNode->IntAttribute("NodeLevel")); //需要等级 pMissionBranchVo->setNeedStr(pNode->IntAttribute("NeedStr")); //体力消耗 pMissionBranchVo->setlimitCou(pNode->IntAttribute("limitCou")); //次数限制 pMissionBranchVo->setNodeCion(pNode->IntAttribute("NodeCion")); //金币产出 pMissionBranchVo->setNodeExp(pNode->IntAttribute("NodeExp")); //角色经验产出 pMissionBranchVo->setNodeHeroExp(pNode->IntAttribute("NodeHeroExp")); //英雄经验产出 pMissionBranchVo->setDropType(pNode->IntAttribute("DropType")); //掉落类型 pMissionBranchVo->setDropID(pNode->IntAttribute("DropID")); //掉落ID pMissionBranchVo->setDropNum(pNode->IntAttribute("DropNum")); //掉落数量 pMissionBranchVo->setNodeDec(pNode->Attribute("NodeDec")); //节点描述 pMissionBranchVo->setNodeOrderID(pNode->IntAttribute("NodeOrderID")); //节点阵容ID pMissionBranchVo->setTeamDiff1(pNode->IntAttribute("TeamDiff1")); //阵容难度1 pMissionBranchVo->setTeamDiff2(pNode->IntAttribute("TeamDiff2")); //阵容难度2 pMissionBranchVo->setTeamDiff3(pNode->IntAttribute("TeamDiff3")); //阵容难度3 pMissionBranchVo->setTeamDiff4(pNode->IntAttribute("TeamDiff4")); //阵容难度4 pMissionBranchVo->setTeamDiff5(pNode->IntAttribute("TeamDiff15")); //阵容难度5 pMissionBranchVo->setcopyDrop1(pNode->IntAttribute("copyDrop1")); //副本掉落1 pMissionBranchVo->setcopyPro1(pNode->IntAttribute("copyPro1")); //概率1 pMissionBranchVo->setcopyDrop2(pNode->IntAttribute("copyDrop2")); //副本掉落2 pMissionBranchVo->setcopyPro2(pNode->IntAttribute("copyPro2")); //概率2 pMissionBranchVo->setcopyDrop3(pNode->IntAttribute("copyDrop3")); //副本掉落3 pMissionBranchVo->setcopyPro3(pNode->IntAttribute("copyPro3")); //概率3 pMissionBranchVo->setcopyDrop4(pNode->IntAttribute("copyDrop4")); //副本掉落4 pMissionBranchVo->setcopyPro4(pNode->IntAttribute("copyPro4")); //概率4 pMissionBranchVo->setcopyDrop5(pNode->IntAttribute("copyDrop5")); //副本掉落5 pMissionBranchVo->setcopyPro5(pNode->IntAttribute("copyPro5")); //概率5 pMissionBranchVo->setWipeDrop1(pNode->IntAttribute("WipeDrop1")); //扫荡掉落1 pMissionBranchVo->setWipeNum1(pNode->IntAttribute("WipeNum1")); //扫荡掉落数量1 pMissionBranchVo->setWipeDrop2(pNode->IntAttribute("WipeDrop2")); //扫荡掉落2 pMissionBranchVo->setWipeNum2(pNode->IntAttribute("WipeNum2")); //扫荡掉落数量2 pMissionBranchVo->setAdjustRatio(pNode->IntAttribute("AdjustRatio")); //调整系数 pMissionBranchVo->autorelease(); m_pBranchInfo->setobject(pMissionBranchVo,pMissionBranchVo->getBranchID()); pNode = pNode->NextSiblingElement(); }}//阵容读取voID CustomsPassproxy::loadArrayInfo(){ ssize_t bufferSize = 0; unsigned char* pBuffer = CCfileUtils::sharedfileUtils()->getfileData("MissionEnemy.xml",&bufferSize); if (NulL == pBuffer) { return; } tinyxml2::XMLdocument* pXml = new tinyxml2::XMLdocument(); pXml->Parse((const char*)pBuffer); tinyxml2::XMLElement* pNode = pXml->RootElement()->FirstChildElement(); MissionArrayVo* pMissionArrayVo = nullptr; while (pNode) { pMissionArrayVo = new MissionArrayVo(); pMissionArrayVo->setEnemyArrID(pNode->IntAttribute("EnemyArrID")); // 阵容ID pMissionArrayVo->setEnemyOrder(pNode->IntAttribute("EnemyOrder")); // 阵容序号 pMissionArrayVo->setEnemyRatio(pNode->DoubleAttribute("EnemyRatio")); // 阵容系数 pMissionArrayVo->setEnmey1(pNode->IntAttribute("Enmey1")); // 出战角色1 pMissionArrayVo->setLevel1(pNode->IntAttribute("Level1")); // 等级1 pMissionArrayVo->setEnmey2(pNode->IntAttribute("Enmey2")); // 出战角色2 pMissionArrayVo->setLevel2(pNode->IntAttribute("Level2")); // 等级2 pMissionArrayVo->setEnmey3(pNode->IntAttribute("Enmey3")); // 出战角色3 pMissionArrayVo->setLevel3(pNode->IntAttribute("Level3")); // 等级3 pMissionArrayVo->setEnmey4(pNode->IntAttribute("Enmey4")); // 出战角色4 pMissionArrayVo->setLevel4(pNode->IntAttribute("Level4")); // 等级4 pMissionArrayVo->setEnmey5(pNode->IntAttribute("Enmey5")); // 出战角色5 pMissionArrayVo->setLevel5(pNode->IntAttribute("Level5")); // 等级5 pMissionArrayVo->autorelease(); m_pEnmeyArrInfo->setobject(pMissionArrayVo,pMissionArrayVo->getEnemyArrID()); pNode = pNode->NextSiblingElement(); }}//根据关卡ID获取此关卡ID的信息MissionTrunkVo* CustomsPassproxy::getMAPInfo(int mAPId){ DictElement* pElement = NulL; CCDICT_FOREACH(m_pTrunkInfo,pElement) { auto KeyMAPId = pElement->getIntKey(); if (KeyMAPId == mAPId) { MissionTrunkVo* MAPInfo = (MissionTrunkVo*)pElement->getobject(); return MAPInfo; } }}//根据节点ID去获取此节点ID中的数据MissionBranchVo* CustomsPassproxy::getNodeInfo(int nodeID){ DictElement* pElement = NulL; CCDICT_FOREACH(m_pBranchInfo,pElement) { auto KeyNodeID = pElement->getIntKey(); if (KeyNodeID == nodeID) { MissionBranchVo* NodeInfo = (MissionBranchVo*)pElement->getobject(); return NodeInfo; } }}//根据节点ID去获取阵容表中的数据MissionArrayVo* CustomsPassproxy::getCurEnemyInfo(int nodeID){ MissionBranchVo* Node = getNodeInfo(nodeID); int _ArrID = Node->getNodeOrderID(); DictElement* pElement = NulL; CCDICT_FOREACH(m_pEnmeyArrInfo,pElement) { auto KeyEnemyID = pElement->getIntKey(); if (KeyEnemyID == _ArrID) { MissionArrayVo* _EnemyArrInfo = (MissionArrayVo*)pElement->getobject(); return _EnemyArrInfo; } }}APP_NS_END总结
以上是内存溢出为你收集整理的cocos2dx游戏只关卡开发全部内容,希望文章能够帮你解决cocos2dx游戏只关卡开发所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)