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
if (!s_ImgMap.empty())
@ -193,8 +193,9 @@ void UIImage::setImageMap(const std::string keys[], const int values[], int nCou
// second, insert the pairs
for (int i = 0; i < nCount; ++i)
{
std::string key = CCFileUtils::fullPathFromRelativePath((keys[i]).c_str());
int nResID = values[i];
std::string name = (ResInfo[i]).ImgName;
std::string key = CCFileUtils::fullPathFromRelativePath(name.c_str());
int nResID = (ResInfo[i]).nResID;
s_ImgMap.insert(ResourceImageMap::value_type(key, nResID));
}

View File

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

View File

@ -30,8 +30,8 @@ bool AppDelegate::initCocos2d()
// set the ResourceEntry
UIImage::setResourceEntry(&cocosTemplateResourceEntry);
// set the map between names and ResIDs
UIImage::setImageMap(ResourceNames, nResIDs, sizeof(nResIDs) / sizeof(Int32));
// set the Images ResInfo (name and ResID)
UIImage::setImageResInfo(ResInfo, sizeof(ResInfo) / sizeof(T_ImageResInfo));
// create a scene. it's an autorelease object
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
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
(ResourceNames[0]).c_str(),
(ResourceNames[1]).c_str(),
(ResInfo[0]).ImgName.c_str(),
(ResInfo[1]).ImgName.c_str(),
this,
menu_selector(HelloWorld::menuCloseCallback) );
pCloseItem->setPosition( ccp(CCDirector::getSharedDirector()->getWinSize().width - 20, 20) );

View File

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