This commit is contained in:
natural-law 2010-10-12 03:52:11 +00:00
parent 3224f8b9c5
commit 31c069777d
5 changed files with 21 additions and 17 deletions

View File

@ -182,7 +182,7 @@ void UIImage::setResourceEntry(const AppResourceEntry* pResEntry)
} }
} }
void UIImage::setImageMap(const std::string keys[], const int values[], int nCount) void UIImage::setImageResInfo(const T_ImageResInfo ResInfo[], int nCount)
{ {
// first, clear the map before // first, clear the map before
if (!s_ImgMap.empty()) if (!s_ImgMap.empty())
@ -193,8 +193,9 @@ void UIImage::setImageMap(const std::string keys[], const int values[], int nCou
// second, insert the pairs // second, insert the pairs
for (int i = 0; i < nCount; ++i) for (int i = 0; i < nCount; ++i)
{ {
std::string key = CCFileUtils::fullPathFromRelativePath((keys[i]).c_str()); std::string name = (ResInfo[i]).ImgName;
int nResID = values[i]; std::string key = CCFileUtils::fullPathFromRelativePath(name.c_str());
int nResID = (ResInfo[i]).nResID;
s_ImgMap.insert(ResourceImageMap::value_type(key, nResID)); s_ImgMap.insert(ResourceImageMap::value_type(key, nResID));
} }

View File

@ -47,6 +47,12 @@ typedef struct
unsigned char *data; unsigned char *data;
} tImageInfo; } tImageInfo;
typedef struct
{
std::string ImgName;
int nResID;
} T_ImageResInfo;
class ResourceHandle class ResourceHandle
{ {
public: public:
@ -117,8 +123,8 @@ public:
/** set the Resource Entry */ /** set the Resource Entry */
static void setResourceEntry(const AppResourceEntry* pResEntry); static void setResourceEntry(const AppResourceEntry* pResEntry);
/** set the map between UIImage key and ResID */ /** set the images ResInfo(name and ResID) */
static void setImageMap(const std::string keys[], const int values[], int nCount); static void setImageResInfo(const T_ImageResInfo ResInfo[], int nCount);
private: private:
bool loadPng(const char* strFileName); bool loadPng(const char* strFileName);

View File

@ -30,8 +30,8 @@ bool AppDelegate::initCocos2d()
// set the ResourceEntry // set the ResourceEntry
UIImage::setResourceEntry(&cocosTemplateResourceEntry); UIImage::setResourceEntry(&cocosTemplateResourceEntry);
// set the map between names and ResIDs // set the Images ResInfo (name and ResID)
UIImage::setImageMap(ResourceNames, nResIDs, sizeof(nResIDs) / sizeof(Int32)); UIImage::setImageResInfo(ResInfo, sizeof(ResInfo) / sizeof(T_ImageResInfo));
// create a scene. it's an autorelease object // create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene(); CCScene *pScene = HelloWorld::scene();

View File

@ -34,8 +34,8 @@ bool HelloWorld::init()
// add a "close" icon to exit the progress. it's an autorelease object // add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage( CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
(ResourceNames[0]).c_str(), (ResInfo[0]).ImgName.c_str(),
(ResourceNames[1]).c_str(), (ResInfo[1]).ImgName.c_str(),
this, this,
menu_selector(HelloWorld::menuCloseCallback) ); menu_selector(HelloWorld::menuCloseCallback) );
pCloseItem->setPosition( ccp(CCDirector::getSharedDirector()->getWinSize().width - 20, 20) ); pCloseItem->setPosition( ccp(CCDirector::getSharedDirector()->getWinSize().width - 20, 20) );

View File

@ -2,17 +2,14 @@
#define _RESOURCE_H_ #define _RESOURCE_H_
#include "cocostemplate_res_def.h" #include "cocostemplate_res_def.h"
#include "cocos2d.h"
const std::string ResourceNames[] = using namespace cocos2d;
{
"CloseNormal",
"CloseSelected",
};
const Int32 nResIDs[] = const T_ImageResInfo ResInfo[] =
{ {
COCOST_ID_BITMAP_CloseNormal, { "CloseNormal", COCOST_ID_BITMAP_CloseNormal },
COCOST_ID_BITMAP_CloseSelected, { "CloseSelected", COCOST_ID_BITMAP_CloseSelected },
}; };
#endif #endif