#include "Config.h"
#include "XXmlReader.h"
CConfig* CConfig::g_pConfig = NULL;
CConfig::CConfig()
{
m_strResourcePath.clear();
m_vecImageInfo.clear();
m_mapSceneInfoVec.clear();
m_vecElement.clear();
m_vecWidgetInfo.clear();
m_vecAnimationInfo.clear();
m_vecEffectInfo.clear();
}
CConfig::~CConfig()
{
}
CConfig* CConfig::getInstance()
{
if (!g_pConfig)
{
g_pConfig = new CConfig();
}
return g_pConfig;
}
void CConfig::destroy()
{
g_pConfig->release();
SAFE_DELETE(g_pConfig);
}
void CConfig::release()
{
m_strResourcePath.clear();
m_vecImageInfo.clear();
m_mapSceneInfoVec.clear();
m_vecElement.clear();
m_vecWidgetInfo.clear();
m_vecAnimationInfo.clear();
}
bool CConfig::loadConfig()
{
return false;
}
void CConfig::setResourcePath( const char* psPath )
{
m_strResourcePath = psPath;
}
string CConfig::getResourcePath()
{
return m_strResourcePath;
}
bool CConfig::readConfig()
{
return true;
}
bool CConfig::loadImageInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/image.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "images", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pCurNode = pRootNode->xmlChildrenNode;
while (NULL != pCurNode)
{
if ( != xmlStrcmp(pCurNode->name, BAD_CAST "image"))
{
pCurNode = pCurNode->next;
continue;
}
ImageInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "id");
info.strKey = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "key");
info.strFile = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "file");
m_vecImageInfo.push_back(info);
pCurNode = pCurNode->next;
}
xmlFreeDoc(pDoc);
return true;
} while ();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
vector<ImageInfo>* CConfig::getImageInfo()
{
return &m_vecImageInfo;
}
bool CConfig::loadSceneInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/scene.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "scenes", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pElement = pRootNode->xmlChildrenNode;
while (pElement)
{
if ( != xmlStrcmp(pElement->name, BAD_CAST "scene"))
{
pElement = pElement->next;
continue;
}
xmlNodePtr pItemNode = pElement->xmlChildrenNode;
vector<SceneInfo> vecSceneInfo;
while (pItemNode)
{
if ( != xmlStrcmp(pItemNode->name, BAD_CAST "item"))
{
pItemNode = pItemNode->next;
continue;
}
SceneInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pItemNode, "id");
info.wType = CCXmlReader::getXMLNodeAttribInt(&pItemNode, "type");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pItemNode, "pos");
int nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&info.nPosX,&info.nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
info.rRect.setRect(nRectX,nRectY,nRectW,nRectH);
info.order = CCXmlReader::getXMLNodeAttribInt(&pItemNode, "order");
info.strFile = CCXmlReader::getXMLNodeAttribStrs(&pItemNode, "file");
vecSceneInfo.push_back(info);
pItemNode = pItemNode->next;
}
int nKey = CCXmlReader::getXMLNodeAttribInt(&pElement, "id");
m_mapSceneInfoVec[nKey] = vecSceneInfo;
pElement = pElement->next;
}
xmlFreeDoc(pDoc);
return true;
} while ();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
bool CConfig::loadElementInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/element.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "elements", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pItemNode = pRootNode->xmlChildrenNode;
while (NULL != pItemNode)
{
if ( != xmlStrcmp(pItemNode->name, BAD_CAST "item"))
{
pItemNode = pItemNode->next;
continue;
}
ElementInfo elemInfo;
elemInfo.nItem = CCXmlReader::getXMLNodeAttribInt(&pItemNode, "id");
xmlNodePtr pElemNode = pItemNode->xmlChildrenNode;
while(pElemNode)
{
if ( != xmlStrcmp(pElemNode->name, BAD_CAST "element"))
{
pElemNode = pElemNode->next;
continue;
}
PlistInfo info;
info.strPlist = CCXmlReader::getXMLNodeAttribStrs(&pElemNode, "plist");
info.strImage = CCXmlReader::getXMLNodeAttribStrs(&pElemNode, "image");
elemInfo.vecPlistInfo.push_back(info);
pElemNode = pElemNode->next;
}
m_vecElement.push_back(elemInfo);
pItemNode = pItemNode->next;
}
xmlFreeDoc(pDoc);
return true;
} while ();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
bool CConfig::loadWidgetInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/widget.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "widgets", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pElement = pRootNode->xmlChildrenNode;
while (NULL != pElement)
{
if ( != xmlStrcmp(pElement->name, BAD_CAST "widget"))
{
pElement = pElement->next;
continue;
}
WidgetInfo widgetInfo;
widgetInfo.nId = CCXmlReader::getXMLNodeAttribInt(&pElement, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pElement,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
widgetInfo.tPos.setPoint(nPosX, nPosY);
widgetInfo.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pElement, "anchor");
float fAnchorX = , fAnchorY = ;
sscanf(strBuf.c_str(),"%f %f",&fAnchorX, &fAnchorY);
widgetInfo.tAnchor.setPoint(fAnchorX, fAnchorY);
widgetInfo.strPic = CCXmlReader::getXMLNodeAttribStrs(&pElement, "pic");
xmlNodePtr pCtrlNode = pElement->xmlChildrenNode;
while (pCtrlNode)
{
//图片控件
if ( == xmlStrcmp(pCtrlNode->name, BAD_CAST "img"))
{
CtrlInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
info.tPos.setPoint(nPosX, nPosY);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
info.strPic = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "pic");
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "anchor");
float fAnchorX = , fAnchorY = ;
sscanf(strBuf.c_str(),"%f %f",&fAnchorX, &fAnchorY);
info.tAnchor.setPoint(fAnchorX, fAnchorY);
info.wType = CtrlInfo::_IDC_IMG;
widgetInfo.m_vecCtrlInfo.push_back(info);
}
//按钮控件
if ( == xmlStrcmp(pCtrlNode->name, BAD_CAST "btn"))
{
CtrlInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
info.tPos.setPoint(nPosX, nPosY);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "anchor");
float fAnchorX = , fAnchorY = ;
sscanf(strBuf.c_str(),"%f %f",&fAnchorX, &fAnchorY);
info.wType = CtrlInfo::_IDC_BTN;
info.btnType = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "type");
info.btnState = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "state");
info.strPic = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "pic");
info.strAudioFile = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "audio");
widgetInfo.m_vecCtrlInfo.push_back(info);
}
//文本控件
if ( == xmlStrcmp(pCtrlNode->name, BAD_CAST "sta"))
{
CtrlInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
info.tPos.setPoint(nPosX, nPosY);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "anchor");
float fAnchorX = , fAnchorY = ;
sscanf(strBuf.c_str(),"%f %f",&fAnchorX, &fAnchorY);
info.tAnchor.setPoint(fAnchorX, fAnchorY);
info.wType = CtrlInfo::_IDC_STA;
info.wLabelType = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "type");
info.strText = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "text");
info.nFontSize = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "fontsize");
info.strFont = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "font");
info.wAlignment = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "aligning");
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "color");
int nR = , nG = , nB = ;
sscanf(strBuf.c_str(), "%d %d %d",&nR, &nG, &nB);
info.color3B.r = (char)nR;
info.color3B.g = (char)nG;
info.color3B.b = (char)nB;
widgetInfo.m_vecCtrlInfo.push_back(info);
}
//Sroll控件
if ( == xmlStrcmp(pCtrlNode->name, BAD_CAST "srl"))
{
CtrlInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
info.tPos.setPoint(nPosX, nPosY);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "anchor");
float fAnchorX = , fAnchorY = ;
sscanf(strBuf.c_str(),"%f %f",&fAnchorX, &fAnchorY);
info.tAnchor.setPoint(fAnchorX, fAnchorY);
info.strItem = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "item");
info.wRollType = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "type");
info.fBounds = CCXmlReader::getXMLNodeAttribfloat(&pCtrlNode, "bounds");
info.wType = CtrlInfo::_IDC_SROLL;
widgetInfo.m_vecCtrlInfo.push_back(info);
}
//禁用触摸控件
if ( == xmlStrcmp(pCtrlNode->name, BAD_CAST "not"))
{
CtrlInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "id");
info.notType = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "type");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
info.tPos.setPoint(nPosX, nPosY);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "anchor");
float fAnchorX = , fAnchorY = ;
sscanf(strBuf.c_str(),"%f %f",&fAnchorX, &fAnchorY);
info.tAnchor.setPoint(fAnchorX, fAnchorY);
info.nPriority = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "priority");
info.wType = CtrlInfo::_IDC_NOT;
widgetInfo.m_vecCtrlInfo.push_back(info);
}
pCtrlNode = pCtrlNode->next;
}
m_vecWidgetInfo.push_back(widgetInfo);
pElement = pElement->next;
}
xmlFreeDoc(pDoc);
return true;
} while ();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
vector<WidgetInfo>* CConfig::getWidgetInfo()
{
return& m_vecWidgetInfo;
}
vector<ElementInfo>* CConfig::getElementInfo()
{
return& m_vecElement;
}
map<int,vector<SceneInfo> >* CConfig::getSceneInfo()
{
return& m_mapSceneInfoVec;
}
bool CConfig::loadAnimationInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/animation.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "animations", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pCurNode = pRootNode->xmlChildrenNode;
while (NULL != pCurNode)
{
if ( != xmlStrcmp(pCurNode->name, BAD_CAST "animation"))
{
pCurNode = pCurNode->next;
continue;
}
AnimationInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "id");
info.nBegan = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "began");
info.nCount = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "count");
info.nInterval = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "interval");
info.strName = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "name");
m_vecAnimationInfo.push_back(info);
pCurNode = pCurNode->next;
}
xmlFreeDoc(pDoc);
return true;
} while ();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
vector<AnimationInfo>* CConfig::getAnimationInfo()
{
return &m_vecAnimationInfo;
}
ImageInfo* CConfig::getImageInfoById( int nId )
{
for (vector<ImageInfo>::iterator it = m_vecImageInfo.begin(); it != m_vecImageInfo.end(); it++)
{
if (it->nId == nId)
{
return &(*it);
}
}
CCLog("error: CConfig::getPlanInfoById");
return NULL;
}
WidgetInfo* CConfig::getWidgetInfoById( int nId )
{
for (vector<WidgetInfo>::iterator it = m_vecWidgetInfo.begin(); it != m_vecWidgetInfo.end(); it++)
{
if (it->nId == nId)
{
return &(*it);
}
}
CCLog("error: CConfig::getWidgetInfoById");
return NULL;
}
bool CConfig::loadSrollInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/sroll.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "srolls", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pElement = pRootNode->xmlChildrenNode;
while (NULL != pElement)
{
if ( == xmlStrcmp(pElement->name, BAD_CAST "item"))
{
SrollInfo srollInfo;
srollInfo.strKey = CCXmlReader::getXMLNodeAttribStrs(&pElement, "key");
xmlNodePtr pWidgetNode = pElement->xmlChildrenNode;
while(pWidgetNode)
{
if ( == xmlStrcmp(pWidgetNode->name, BAD_CAST "widget"))
{
WidgetInfo widgetInfo;
widgetInfo.nId = CCXmlReader::getXMLNodeAttribInt(&pWidgetNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pWidgetNode,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
widgetInfo.tPos.setPoint(nPosX, nPosY);
widgetInfo.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
widgetInfo.strPic = CCXmlReader::getXMLNodeAttribStrs(&pWidgetNode, "pic");
xmlNodePtr pCtrlNode = pWidgetNode->xmlChildrenNode;
while(pCtrlNode)
{
if ( == xmlStrcmp(pCtrlNode->name, BAD_CAST "btn"))
{
CtrlInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
info.tPos.setPoint(nPosX, nPosY);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "anchor");
float fAnchorX = , fAnchorY = ;
sscanf(strBuf.c_str(),"%f %f",&fAnchorX, &fAnchorY);
info.wType = CtrlInfo::_IDC_BTN;
info.btnType = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "type");
info.btnState = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "state");
info.strPic = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "pic");
info.strAudioFile = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "audio");
widgetInfo.m_vecCtrlInfo.push_back(info);
}
//图片控件
if ( == xmlStrcmp(pCtrlNode->name, BAD_CAST "img"))
{
CtrlInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
info.tPos.setPoint(nPosX, nPosY);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
info.strPic = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "pic");
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "anchor");
float fAnchorX = , fAnchorY = ;
sscanf(strBuf.c_str(),"%f %f",&fAnchorX, &fAnchorY);
info.tAnchor.setPoint(fAnchorX, fAnchorY);
info.wType = CtrlInfo::_IDC_IMG;
widgetInfo.m_vecCtrlInfo.push_back(info);
}
//文本控件
if ( == xmlStrcmp(pCtrlNode->name, BAD_CAST "sta"))
{
CtrlInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
info.tPos.setPoint(nPosX, nPosY);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "anchor");
float fAnchorX = , fAnchorY = ;
sscanf(strBuf.c_str(),"%f %f",&fAnchorX, &fAnchorY);
info.tAnchor.setPoint(fAnchorX, fAnchorY);
info.wType = CtrlInfo::_IDC_STA;
info.wLabelType = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "type");
info.strText = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "text");
info.nFontSize = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "fontsize");
info.strFont = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "font");
info.wAlignment = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "aligning");
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "color");
int nR = , nG = , nB = ;
sscanf(strBuf.c_str(), "%d %d %d",&nR, &nG, &nB);
info.color3B.r = (char)nR;
info.color3B.g = (char)nG;
info.color3B.b = (char)nB;
widgetInfo.m_vecCtrlInfo.push_back(info);
}
//禁用触摸控件
if ( == xmlStrcmp(pCtrlNode->name, BAD_CAST "not"))
{
CtrlInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode,"pos");
int nPosX = , nPosY = , nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(),"%d %d %d %d %d %d",&nPosX,&nPosY,&nRectX,&nRectY,&nRectW,&nRectH);
info.tPos.setPoint(nPosX, nPosY);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCtrlNode, "anchor");
float fAnchorX = , fAnchorY = ;
sscanf(strBuf.c_str(),"%f %f",&fAnchorX, &fAnchorY);
info.tAnchor.setPoint(fAnchorX, fAnchorY);
info.nPriority = CCXmlReader::getXMLNodeAttribInt(&pCtrlNode, "priority");
info.wType = CtrlInfo::_IDC_NOT;
widgetInfo.m_vecCtrlInfo.push_back(info);
}
pCtrlNode = pCtrlNode->next;
}
srollInfo.vecWidgetInfo.push_back(widgetInfo);
}
pWidgetNode = pWidgetNode->next;
}
m_vecSrollInfo.push_back(srollInfo);
}
pElement = pElement->next;
}
xmlFreeDoc(pDoc);
return true;
}while();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
bool CConfig::loadEffectInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/effect.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "effects", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pElement = pRootNode->xmlChildrenNode;
while (NULL != pElement)
{
if ( != xmlStrcmp(pElement->name, BAD_CAST "effect"))
{
pElement = pElement->next;
continue;
}
EffectInfo effectInfo;
effectInfo.strKey = CCXmlReader::getXMLNodeAttribStrs(&pElement, "key");
string strEffectPosBuf = CCXmlReader::getXMLNodeAttribStrs(&pElement, "pos");
int nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strEffectPosBuf.c_str(), "%d %d %d %d %d %d", &effectInfo.nPosX, &effectInfo.nPosY,
&nRectX, &nRectY, &nRectW, &nRectH);
effectInfo.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
xmlNodePtr pCurNode = pElement->xmlChildrenNode;
while (pCurNode)
{
if ( == xmlStrcmp(pCurNode->name, BAD_CAST "particle"))
{
EffectInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "pos");
int nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(), "%d %d %d %d %d %d", &info.nPosX, &info.nPosY,
&nRectX, &nRectY, &nRectW, &nRectH);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
info.wType = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "type");
info.strFile = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "file");
effectInfo.vecEffectSub.push_back(info);
}
if ( == xmlStrcmp(pCurNode->name, BAD_CAST "action"))
{
}
if ( == xmlStrcmp(pCurNode->name, BAD_CAST "Animate"))
{
EffectInfo info;
info.nId = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "id");
string strBuf = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "pos");
int nRectX = , nRectY = , nRectW = , nRectH = ;
sscanf(strBuf.c_str(), "%d %d %d %d %d %d", &info.nPosX, &info.nPosY,
&nRectX, &nRectY, &nRectW, &nRectH);
info.rRect.setRect(nRectX, nRectY, nRectW, nRectH);
info.wType = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "type");
info.strFile = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "file");
effectInfo.vecEffectSub.push_back(info);
}
pCurNode = pCurNode->next;
}
m_vecEffectInfo.push_back(effectInfo);
pElement = pElement->next;
}
xmlFreeDoc(pDoc);
return true;
} while ();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
EffectInfo* CConfig::getEffectInfoByKey(const char* psKey)
{
for (vector<EffectInfo>::iterator it = m_vecEffectInfo.begin(); it != m_vecEffectInfo.end(); it++)
{
if ( == strcmp(it->strKey.c_str(), psKey))
{
return &(*it);
}
}
CCLog("error: CConfig::getEffectInfoByKey");
return NULL;
}
vector<EffectInfo>* CConfig::getEffectInfo()
{
return &m_vecEffectInfo;
}
vector<WidgetInfo>* CConfig::getSrollInfoByKey( const char* psKey )
{
for (vector<SrollInfo>::iterator it = m_vecSrollInfo.begin(); it != m_vecSrollInfo.end(); it++)
{
if (it->strKey == psKey)
{
return & it->vecWidgetInfo;
}
}
CCLog("error: CConfig::getSrollInfoByKey");
return NULL;
}
bool CConfig::loadAudioInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/audio.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "audios", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pCurNode = pRootNode->xmlChildrenNode;
while (NULL != pCurNode)
{
if ( != xmlStrcmp(pCurNode->name, BAD_CAST "audio"))
{
pCurNode = pCurNode->next;
continue;
}
AudioInfo info;
info.strKey = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "key");
info.wType = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "type");
info.strFile = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "file");
m_vecAudioInfo.push_back(info);
pCurNode = pCurNode->next;
}
xmlFreeDoc(pDoc);
return true;
} while ();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
AudioInfo* CConfig::getAudioInfoByKey( const char* psKey )
{
for (vector<AudioInfo>::iterator it = m_vecAudioInfo.begin(); it != m_vecAudioInfo.end(); it++)
{
if ( == strcmp(it->strKey.c_str(), psKey))
{
return &(*it);
}
}
CCLog("error: CConfig::getAudioInfoByKey");
return NULL;
}
vector<PlistInfo>* CConfig::getElementInfoByItem( int nId )
{
for (vector<ElementInfo>::iterator it = m_vecElement.begin(); it != m_vecElement.end(); it++)
{
if (it->nItem == nId)
{
return &it->vecPlistInfo;
}
}
CCLog("error: CConfig::getElementInfoById");
return NULL;
}
ImageInfo* CConfig::getImageInfoByKey( const char* psKey )
{
for (vector<ImageInfo>::iterator it = m_vecImageInfo.begin(); it != m_vecImageInfo.end(); it++)
{
if ( it->strKey == psKey)
{
return &(*it);
}
}
CCLog("error: CConfig::getImageInfoByKey");
return NULL;
}
bool CConfig::loadWordInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/word.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "words", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pCurNode = pRootNode->xmlChildrenNode;
while (NULL != pCurNode)
{
if ( != xmlStrcmp(pCurNode->name, BAD_CAST "word"))
{
pCurNode = pCurNode->next;
continue;
}
WordInfo info;
info.strKey = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "key");
info.strLetter = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "letter");
m_mapWordInfo[info.strKey] = info;
pCurNode = pCurNode->next;
}
xmlFreeDoc(pDoc);
return true;
} while ();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
WordInfo& CConfig::getWordInfoByKey( const char* psKey )
{
return m_mapWordInfo[psKey];
}
string CConfig::getWordBykey( const char* psKey )
{
for (map<string, WordInfo>::iterator it = m_mapWordInfo.begin(); it != m_mapWordInfo.end(); it++)
{
if (it->first == psKey)
{
return it->second.strLetter;
}
}
CCLog("warning: CConfig::getWordByKey");
return "";
}
bool CConfig::loadActionInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/action.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "actions", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pCurNode = pRootNode->xmlChildrenNode;
while (NULL != pCurNode)
{
if ( == xmlStrcmp(pCurNode->name, BAD_CAST "action"))
{
ActionInfo info;
info.strKey = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "key");
info.nAction = CCXmlReader::getXMLNodeAttribInt(&pCurNode, "type");
info.strParm = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "parm");
info.eType = ActionInfo::_Action;
m_vecActionInfo.push_back(info);
}
if ( == xmlStrcmp(pCurNode->name, BAD_CAST "particle"))
{
ActionInfo info;
info.strKey = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "key");
info.strFile = CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "file");
info.eType = ActionInfo::_Particle;
m_vecActionInfo.push_back(info);
}
pCurNode = pCurNode->next;
}
xmlFreeDoc(pDoc);
return true;
} while ();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
ActionInfo* CConfig::getActionInfoByKey( const char* psKey )
{
for (vector<ActionInfo>::iterator it = m_vecActionInfo.begin(); it != m_vecActionInfo.end(); it++)
{
if (it->strKey == psKey)
{
return &(*it);
}
}
CCLog("error: CConfig::getActionInfoByKey");
return NULL;
}
bool CConfig::loadNumberInfo()
{
string strFile = m_strResourcePath;
strFile += "/config/number.xml";
//读取文档
xmlDocPtr pDoc = NULL;
LOAD_XML_DOC(strFile.c_str(), pDoc);
if (NULL == pDoc)
{
CCLog("can not read %s", strFile.c_str());
return false;
}
do
{
xmlNodePtr pRootNode = xmlDocGetRootElement(pDoc);
if (NULL == pRootNode)
{
break;
}
if( != xmlStrcmp(BAD_CAST "numbers", pRootNode->name))
{
break;
}
//读取节点
xmlNodePtr pCurNode = pRootNode->xmlChildrenNode;
while (NULL != pCurNode)
{
if ( == xmlStrcmp(pCurNode->name, BAD_CAST "number"))
{
m_mapNumber[CCXmlReader::getXMLNodeAttribStrs(&pCurNode, "key")]
= CCXmlReader::getXMLNodeAttribfloat(&pCurNode, "num");
}
pCurNode = pCurNode->next;
}
xmlFreeDoc(pDoc);
return true;
} while ();
xmlFreeDoc(pDoc);
CCLog("read xml error : %s", strFile.c_str());
return false;
}
float CConfig::getNumberByKey( const char* psKey )
{
return m_mapNumber[psKey];
}