From 31c069777dc248e8e8f88c4452f02fa6cc486dbd Mon Sep 17 00:00:00 2001 From: natural-law Date: Tue, 12 Oct 2010 03:52:11 +0000 Subject: [PATCH] issue #182 --- cocos2dx/platform/uphone/CCXUIImage_uphone.cpp | 7 ++++--- cocos2dx/platform/uphone/CCXUIImage_uphone.h | 10 ++++++++-- template/AppDelegate.cpp | 4 ++-- template/HelloWorldScene.cpp | 4 ++-- template/Resource.h | 13 +++++-------- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/cocos2dx/platform/uphone/CCXUIImage_uphone.cpp b/cocos2dx/platform/uphone/CCXUIImage_uphone.cpp index 1485ee115d..e46f83a1b2 100644 --- a/cocos2dx/platform/uphone/CCXUIImage_uphone.cpp +++ b/cocos2dx/platform/uphone/CCXUIImage_uphone.cpp @@ -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)); } diff --git a/cocos2dx/platform/uphone/CCXUIImage_uphone.h b/cocos2dx/platform/uphone/CCXUIImage_uphone.h index c178286f4e..a4a06d0b1c 100644 --- a/cocos2dx/platform/uphone/CCXUIImage_uphone.h +++ b/cocos2dx/platform/uphone/CCXUIImage_uphone.h @@ -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); diff --git a/template/AppDelegate.cpp b/template/AppDelegate.cpp index 49075310e3..95a017795b 100644 --- a/template/AppDelegate.cpp +++ b/template/AppDelegate.cpp @@ -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(); diff --git a/template/HelloWorldScene.cpp b/template/HelloWorldScene.cpp index 79cd8f1592..4510ae61f2 100644 --- a/template/HelloWorldScene.cpp +++ b/template/HelloWorldScene.cpp @@ -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) ); diff --git a/template/Resource.h b/template/Resource.h index 73a88a9de2..7022e519ed 100644 --- a/template/Resource.h +++ b/template/Resource.h @@ -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