#include "SectsInfomation.h" #include "WidgetMgr.h" #include "XButton.h" #include "XSroll.h" #include "Config.h" #include "XCommon.h" #include "XStatic.h" #include "XImage.h" #if(CC_TARGET_PLATFORM == CC_PLATFORM_IOS) #include "GameCenter.h" #include "AppExtra.h" #endif /******************************* *函数名称:CSectsInfomation *函数功能:构造函数 *函数参数:void *函数返回值:void *备注: *******************************/ CSectsInfomation::CSectsInfomation(void) { m_pBtnExit = NULL; m_pSta = NULL; m_PageNum = 1; m_FirstId = 1002; m_PageTotal = 0; CCLabelTTF *pLabel = NULL; memset(acPage,0,10); } CSectsInfomation::~CSectsInfomation(void) { } /******************************* *函数名称:init *函数功能:初始化函数 *函数参数:void *函数返回值:true--初始化成功;false--初始化失败 *备注: *******************************/ bool CSectsInfomation::init() { bool bRet = false; CWidgetMgr::getInstance()->loadWidget(this, _IDD_CSectsInfomation); CWidgetMgr::getInstance()->addWnd(this); for (deque<CXWindow*>::const_iterator it = this->getDequeWnd().begin(); it != this->getDequeWnd().end(); it++) { //给按钮添加响应函数 if (UI_BUTTON == (*it)->getUIType()) { (*it)->setClickListener(this, callfuncO_selector(CSectsInfomation::btnMsgCallback)); } //通过id中的第三位映射到相应的图片,每个按钮的id都加上200就是对应要显示的图片 int iNum = (*it)->getId(); iNum = (*it)->getId() / 100; iNum = iNum % 10; if (iNum >= 2) { (*it)->setVisible(false); m_vecImage.push_back(*it); } //显示第一页 iNum = (*it)->getId(); iNum = (*it)->getId() / 1000; if (iNum != 1) { (*it)->setVisible(false); } //保存最大页码 if (iNum > m_PageTotal) { m_PageTotal = iNum; } //第一张任务图片要显示 if ((*it)->getId() == 1202) { (*it)->setVisible(true); } } //显示页码 m_pSta = (CXStatic*)(this->getCtrl(1034)); char acTemp[10] = {0}; strcpy(acPage,"1/"); itoa(m_PageTotal,acTemp,10); strcat(acPage,acTemp); pLabel = CCLabelTTF::create(acPage,"Gautami",30); m_pSta->setLabel(pLabel); m_pSta->setPosition(420,20); m_pSta->setVisible(true); //选中框的图片 m_pImg = (CXImage*)(this->getCtrl(1004)); this->setVisible(false); return true; } /******************************* *函数名称:btnMsgCallback *函数功能:按钮的响应函数 *函数参数:CCObject* pSender--这里传进来的是this指针 *函数返回值:void *备注:这里处理四种情况: 1.上一页 2.下一页 3.返回 4.点击任务列表中某项的响应 这里不做页面循环,当到最后一页时取消下一页按钮的响应 当到了第一页时取消上一页按钮的响应 *******************************/ void CSectsInfomation::btnMsgCallback(CCObject* pSender) { int iAddNum = 0; CXImage *pImage = NULL; CXButton *pButton = (CXButton*)pSender; if (pButton->getId() == 1034) { this->setVisible(false); } else if (pButton->getId() == 1035) { m_PageNum = m_PageNum - 1; if (1 > m_PageNum) { m_PageNum = 1; } else { //上一页 for (deque<CXWindow*>::const_iterator it = this->getDequeWnd().begin(); it != this->getDequeWnd().end(); it++) { int iNum = 0; iNum = (*it)->getId() / 1000; if (iNum != m_PageNum) { (*it)->setVisible(true); } iNum = (*it)->getId() / 100; iNum = iNum % 10; if (iNum >= 2) { (*it)->setVisible(false); } if ((*it)->getId() == m_PageNum * 1000 + 2 ) { CCPoint point = (*it)->getPosition(); m_pImg->setPosition(point.x ,point.y); } int num = m_PageNum * 1000 + 2 + 200; if ((*it)->getId() == num) { (*it)->setVisible(true); } } memset(acPage,0,10); char acTotal[10] = {0}; char acTemp[10] = {0}; itoa(m_PageNum,acTemp,10); itoa(m_PageTotal,acTotal,10); strcpy(acPage,acTemp); strcat(acPage,"/"); strcat(acPage,acTotal); pLabel->setString(acPage); } } else if (pButton->getId() == 1036) { m_PageNum = m_PageNum + 1; if (m_PageTotal < m_PageNum) { m_PageNum = m_PageTotal; } else { //下一页 for (deque<CXWindow*>::const_iterator it = this->getDequeWnd().begin(); it != this->getDequeWnd().end(); it++) { int iNum = 0; iNum = (*it)->getId() / 1000; if (iNum != m_PageNum) { (*it)->setVisible(true); } iNum = (*it)->getId() / 100; iNum = iNum % 10; if (iNum >= 2) { (*it)->setVisible(false); } if ((*it)->getId() == m_PageNum * 1000 + 2 ) { CCPoint point = (*it)->getPosition(); m_pImg->setPosition(point.x ,point.y); } int num = m_PageNum * 1000 + 2 + 200; if ((*it)->getId() == num) { (*it)->setVisible(true); } } memset(acPage,0,10); char acTotal[10] = {0}; char acTemp[10] = {0}; itoa(m_PageNum,acTemp,10); itoa(m_PageTotal,acTotal,10); strcpy(acPage,acTemp); strcat(acPage,"/"); strcat(acPage,acTotal); pLabel->setString(acPage); } } else { //获取当前选中按钮所在的坐标,然后通过这个坐标,边框显示在相应位置 CCPoint point = pButton->getPosition(); m_pImg->setPosition(point.x ,point.y); SectsNotVisible(); //通过id获取图片控件的指针 pImage = (CXImage*)(this->getCtrl(pButton->getId() + 200)); pImage->setVisible(true); } } void CSectsInfomation::btnMsgSrollCallback(CCObject* pSender) { } /******************************* *函数名称:SectsNotVisible *函数功能:屏蔽所有任务图片控件 *函数参数:void *函数返回值:void *备注: *******************************/ void CSectsInfomation::SectsNotVisible() { for (deque<CXWindow*>::const_iterator it = m_vecImage.begin(); it != m_vecImage.end(); it++) { (*it)->setVisible(false); } }