#ifndef __CONFIG_H__
#define __CONFIG_H__ #include "GameFrameHead.h" //图片信息
struct ImageInfo
{
int nId; //ID标识
string strKey; //key标识
string strFile; //文件路径
}; //资源信息
struct ResourceInfo
{ }; //ui
//控件信息
struct CtrlInfo
{
int nId;
CCPoint tPos; //坐标
CCPoint tAnchor; //锚点
CCRect rRect;
string strPic; //图片
string strText; //文本内容
string strFont; //文本字体
string strAudioFile;//声音文件
unsigned int nFontSize; //文本字体大小
unsigned int wLabelType; //文本类型
string strItem; //rollView条款
unsigned short wRollType;//roll控件类型
float fBounds; //拖动速率
string strWord; //
unsigned short wType;//控件类型
unsigned short wAlignment;//文本对齐方式
unsigned short btnState;//按钮状态
unsigned short btnType; //按钮类型
ccColor3B color3B; //文本颜色
unsigned short notType; //屏蔽消息框类型
int nPriority;//消息优先级
enum WTYPE
{
_IDC_IMG = , //图片
_IDC_STA = , //文本
_IDC_BTN = , //按钮
_IDC_SROLL = , //Sroll
_IDC_NOT = , //屏蔽消息框
_IDC_ROLL= , //滚动框
}; enum BTN_TYPE
{
_BT_Normal = , //正常
_BT_Select = , //选择
}; enum LabelType
{
_LableTTF = ,
_LabelBMFont = ,
_LabelAtlas = ,
}; }; //部件配置
struct WidgetInfo
{
int nId;
CCPoint tPos; //坐标
CCPoint tAnchor; //锚点
CCRect rRect;
string strPic; //图片
vector<CtrlInfo> m_vecCtrlInfo;
}; //场景配置
struct SceneInfo
{
int nId;
int nPosX;
int nPosY;
unsigned short wType; //条款(item)类型
unsigned short order; //层次
string strFile;
CCRect rRect;
enum WTYPE
{
_ITEM_IMG = , //图片
_ITEM_DLG = , //对话框
_ITEM_EFT = , //效果
_ITEM_STA = , //文本
_ITEM_BTN = , //按钮
};
}; //元素配置 struct PlistInfo
{
string strPlist;
string strImage;
};
struct ElementInfo
{
int nItem;
vector<PlistInfo> vecPlistInfo;
}; //动画配置
struct AnimationInfo
{
int nId; //物体ID(动画相关的物体)
int nBegan; //开始帧数
int nCount; //动画帧数
int nInterval;//帧之间的间隔
string strName; //动画名字
string plistpath; //plist路径
string texturePath;//静态贴图文件路径
string picPrefix; //资源目录--默认(或空)为物体的ID
}; //文字配置
struct WordInfo
{
string strKey;
string strLetter; //文字
}; //滚动项配置
//struct SrollInfo
//{
// int nId;
// int nPosX;
// int nPosY;
// CCRect rRect;
// string strPic;
//
// CtrlInfo ctrlInfo;
//
// unsigned short wType;//类型
//
// vector<SrollInfo> vecRollSub;
//};
//
//struct SrollViewInfo
//{
// string strKey;
// vector<SrollInfo> vecRollInfo;
//}; //滚动项配置
struct SrollInfo
{
string strKey;
vector<WidgetInfo> vecWidgetInfo;
}; //效果配置
struct EffectInfo
{
string strKey;
int nId;
int nPosX;
int nPosY;
CCRect rRect;
string strFile;
unsigned int wType;
vector<EffectInfo> vecEffectSub; enum WTYPE
{
_Particle = ,
_Action = ,
_Animation = ,
};
}; //动作配置
struct ActionInfo
{
string strKey;
int nAction;
string strDepict; //动作名字
string strParm; //参数
bool bReverse; //是否反动作
string strFile; //动作文件 enum ActionType
{
_Particle = ,
_Action = ,
_Animation = ,
}; ActionType eType; //动作类型
}; //音效配置
struct AudioInfo
{
string strKey;
unsigned int wType;
string strFile;
}; class GAMEFRAME_API CConfig
{
public:
CConfig();
~CConfig(); static CConfig* getInstance();
static void destroy();
void release(); bool loadConfig(); //读取配置文件
bool loadResourceInfo();//
bool loadImageInfo();//图片信息
bool loadAnimationInfo();//动画信息
bool loadSceneInfo();//场景信息
bool loadElementInfo();//元素 (plist)文件形式
bool loadWidgetInfo();// 控件信息
bool loadSrollInfo(); //滚动项信息
bool loadEffectInfo();//效果配置
bool loadAudioInfo();//声音配置
bool loadWordInfo();//文字配置
bool loadActionInfo();//动作配置
bool loadNumberInfo();//数字配置 bool readConfig(); //设置资源路径 一开始就要设定
void setResourcePath(const char* psPath);
string getResourcePath(); vector<ImageInfo>* getImageInfo();
ImageInfo* getImageInfoById(int nId);
ImageInfo* getImageInfoByKey(const char* psKey); vector<WidgetInfo>* getWidgetInfo();
WidgetInfo* getWidgetInfoById(int nId); vector<ElementInfo>* getElementInfo();
vector<PlistInfo>* getElementInfoByItem(int nId); map<int,vector<SceneInfo> >* getSceneInfo(); vector<AnimationInfo>* getAnimationInfo(); vector<EffectInfo>* getEffectInfo();
EffectInfo* getEffectInfoByKey(const char* psKey); vector<WidgetInfo>* getSrollInfoByKey(const char* psKey); AudioInfo* getAudioInfoByKey(const char* psKey); WordInfo& getWordInfoByKey(const char* psKey);
string getWordBykey(const char* psKey); ActionInfo* getActionInfoByKey(const char* psKey); float getNumberByKey(const char* psKey); private:
vector<string> m_vceConfigStr;
//资源路径
string m_strResourcePath;
static CConfig* g_pConfig; //图片资源配置标识
vector<ImageInfo> m_vecImageInfo; //场景配置标识
map<int, vector<SceneInfo> > m_mapSceneInfoVec; //元素(plist)配置标识
vector<ElementInfo> m_vecElement; //windget配置标识
vector<WidgetInfo> m_vecWidgetInfo; //动画配置标识
vector<AnimationInfo> m_vecAnimationInfo; //Sroll配置标识
vector<SrollInfo> m_vecSrollInfo; //效果配置
vector<EffectInfo> m_vecEffectInfo; //音效配置
vector<AudioInfo> m_vecAudioInfo; //文字配置
map<string, WordInfo> m_mapWordInfo; //动作配置
vector<ActionInfo> m_vecActionInfo; map<string, float> m_mapNumber;
}; #endif //__XCONFIG_H__
#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];
}
05-11 16:56