⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 res.cpp

📁 3D游戏疯狂的鸡蛋
💻 CPP
字号:
#include "res.h"
#include "ResourceManager.h"

using namespace Sexy;

#pragma warning(disable:4311 4312)

static bool gNeedRecalcVariableToIdMap = false;

bool Sexy::ExtractResourcesByName(ResourceManager *theManager, const char *theName)
{
	if (strcmp(theName,"GUI")==0) return ExtractGUIResources(theManager);
	if (strcmp(theName,"Game")==0) return ExtractGameResources(theManager);
	if (strcmp(theName,"Init")==0) return ExtractInitResources(theManager);
	return false;
}

Sexy::ResourceId Sexy::GetIdByStringId(const char *theStringId)
{
	typedef std::map<std::string,int> MyMap;
	static MyMap aMap;
	if(aMap.empty())
	{
		for(int i=0; i<RESOURCE_ID_MAX; i++)
			aMap[GetStringIdById(i)] = i;
	}

	MyMap::iterator anItr = aMap.find(theStringId);
	if (anItr == aMap.end())
		return RESOURCE_ID_MAX;
	else
		return (ResourceId) anItr->second;
}

// GUI Resources
Image* Sexy::BOARD;
Image* Sexy::BRUNCH;
Image* Sexy::CHECK_BOX;
Image* Sexy::CURSOR_HIT_IMAGE;
Image* Sexy::CURSOR_NORMAL_IMAGE;
Image* Sexy::DIALOG_BTN;
Image* Sexy::DIALOG_SMALL;
Image* Sexy::EDIT_BOX;
Image* Sexy::EXIT_BTN_OFF;
Image* Sexy::EXIT_BTN_ON;
Image* Sexy::EXIT_BTN_PUSH;
Image* Sexy::GAME_OVER;
Image* Sexy::GAME_TIME_BAR;
Image* Sexy::GO;
Image* Sexy::HELP_BTN_OFF;
Image* Sexy::HELP_BTN_ON;
Image* Sexy::HELP_BTN_PUSH;
Image* Sexy::HELP_LINK_TYPE;
Image* Sexy::HIGHSCORE_BTN_OFF;
Image* Sexy::HIGHSCORE_BTN_ON;
Image* Sexy::HIGHSCORE_BTN_PUSH;
Image* Sexy::HIT_TIME_BAR;
Image* Sexy::INFO_PANNEL;
Image* Sexy::LEVEL_CLEAR;
Image* Sexy::MAIN_BACK;
Image* Sexy::OPTIONS_BTN_OFF;
Image* Sexy::OPTIONS_BTN_ON;
Image* Sexy::OPTIONS_BTN_PUSH;
Image* Sexy::PLAY_BTN_OFF;
Image* Sexy::PLAY_BTN_ON;
Image* Sexy::PLAY_BTN_PUSH;
Image* Sexy::READY;
Image* Sexy::SLIDER_THUMB;
Image* Sexy::SLIDER_TRACK;
Image* Sexy::STONE_BTN_OFF;
Image* Sexy::STONE_BTN_ON;
Image* Sexy::STONE_BTN_PUSH;
Image* Sexy::TIME_BACK;
Image* Sexy::TIME_SIGN;

bool Sexy::ExtractGUIResources(ResourceManager *theManager)
{
	gNeedRecalcVariableToIdMap = true;

	ResourceManager &aMgr = *theManager;
	try
	{
		BOARD = aMgr.GetImageThrow("BOARD");
		BRUNCH = aMgr.GetImageThrow("BRUNCH");
		CHECK_BOX = aMgr.GetImageThrow("CHECK_BOX");
		CURSOR_HIT_IMAGE = aMgr.GetImageThrow("CURSOR_HIT_IMAGE");
		CURSOR_NORMAL_IMAGE = aMgr.GetImageThrow("CURSOR_NORMAL_IMAGE");
		DIALOG_BTN = aMgr.GetImageThrow("DIALOG_BTN");
		DIALOG_SMALL = aMgr.GetImageThrow("DIALOG_SMALL");
		EDIT_BOX = aMgr.GetImageThrow("EDIT_BOX");
		EXIT_BTN_OFF = aMgr.GetImageThrow("EXIT_BTN_OFF");
		EXIT_BTN_ON = aMgr.GetImageThrow("EXIT_BTN_ON");
		EXIT_BTN_PUSH = aMgr.GetImageThrow("EXIT_BTN_PUSH");
		GAME_OVER = aMgr.GetImageThrow("GAME_OVER");
		GAME_TIME_BAR = aMgr.GetImageThrow("GAME_TIME_BAR");
		GO = aMgr.GetImageThrow("GO");
		HELP_BTN_OFF = aMgr.GetImageThrow("HELP_BTN_OFF");
		HELP_BTN_ON = aMgr.GetImageThrow("HELP_BTN_ON");
		HELP_BTN_PUSH = aMgr.GetImageThrow("HELP_BTN_PUSH");
		HELP_LINK_TYPE = aMgr.GetImageThrow("HELP_LINK_TYPE");
		HIGHSCORE_BTN_OFF = aMgr.GetImageThrow("HIGHSCORE_BTN_OFF");
		HIGHSCORE_BTN_ON = aMgr.GetImageThrow("HIGHSCORE_BTN_ON");
		HIGHSCORE_BTN_PUSH = aMgr.GetImageThrow("HIGHSCORE_BTN_PUSH");
		HIT_TIME_BAR = aMgr.GetImageThrow("HIT_TIME_BAR");
		INFO_PANNEL = aMgr.GetImageThrow("INFO_PANNEL");
		LEVEL_CLEAR = aMgr.GetImageThrow("LEVEL_CLEAR");
		MAIN_BACK = aMgr.GetImageThrow("MAIN_BACK");
		OPTIONS_BTN_OFF = aMgr.GetImageThrow("OPTIONS_BTN_OFF");
		OPTIONS_BTN_ON = aMgr.GetImageThrow("OPTIONS_BTN_ON");
		OPTIONS_BTN_PUSH = aMgr.GetImageThrow("OPTIONS_BTN_PUSH");
		PLAY_BTN_OFF = aMgr.GetImageThrow("PLAY_BTN_OFF");
		PLAY_BTN_ON = aMgr.GetImageThrow("PLAY_BTN_ON");
		PLAY_BTN_PUSH = aMgr.GetImageThrow("PLAY_BTN_PUSH");
		READY = aMgr.GetImageThrow("READY");
		SLIDER_THUMB = aMgr.GetImageThrow("SLIDER_THUMB");
		SLIDER_TRACK = aMgr.GetImageThrow("SLIDER_TRACK");
		STONE_BTN_OFF = aMgr.GetImageThrow("STONE_BTN_OFF");
		STONE_BTN_ON = aMgr.GetImageThrow("STONE_BTN_ON");
		STONE_BTN_PUSH = aMgr.GetImageThrow("STONE_BTN_PUSH");
		TIME_BACK = aMgr.GetImageThrow("TIME_BACK");
		TIME_SIGN = aMgr.GetImageThrow("TIME_SIGN");
	}
	catch(ResourceManagerException&)
	{
		return false;
	}
	return true;
}

// Game Resources
Image* Sexy::CLOUD;
Image* Sexy::CLOUD1;
Image* Sexy::CLOUD2;
Image* Sexy::CLOUD3;
Image* Sexy::CLOUD4;
Image* Sexy::DRAGON_ANGRY;
Image* Sexy::DRAGON_BREATH;
Image* Sexy::DRAGON_LAUGH;
Image* Sexy::DRAGON_SAD;
Image* Sexy::EGGS;
Image* Sexy::FLOAT_ISLAND;
Image* Sexy::HINT_HAND;
Image* Sexy::LIGHTNING;
Image* Sexy::LIGHTNING_VER;
Image* Sexy::LOCK;
Image* Sexy::SHOOT_FIRE;
Image* Sexy::SKY;
int Sexy::SND_EXPLOSION;
int Sexy::SND_GAME_BACK;
int Sexy::SND_GAME_OVER;
int Sexy::SND_LEVEL_CLEAR;
int Sexy::SND_MAIN;
int Sexy::SND_TIMEOUT;
Image* Sexy::UNKNOWN_EGG;

bool Sexy::ExtractGameResources(ResourceManager *theManager)
{
	gNeedRecalcVariableToIdMap = true;

	ResourceManager &aMgr = *theManager;
	try
	{
		CLOUD = aMgr.GetImageThrow("CLOUD");
		CLOUD1 = aMgr.GetImageThrow("CLOUD1");
		CLOUD2 = aMgr.GetImageThrow("CLOUD2");
		CLOUD3 = aMgr.GetImageThrow("CLOUD3");
		CLOUD4 = aMgr.GetImageThrow("CLOUD4");
		DRAGON_ANGRY = aMgr.GetImageThrow("DRAGON_ANGRY");
		DRAGON_BREATH = aMgr.GetImageThrow("DRAGON_BREATH");
		DRAGON_LAUGH = aMgr.GetImageThrow("DRAGON_LAUGH");
		DRAGON_SAD = aMgr.GetImageThrow("DRAGON_SAD");
		EGGS = aMgr.GetImageThrow("EGGS");
		FLOAT_ISLAND = aMgr.GetImageThrow("FLOAT_ISLAND");
		HINT_HAND = aMgr.GetImageThrow("HINT_HAND");
		LIGHTNING = aMgr.GetImageThrow("LIGHTNING");
		LIGHTNING_VER = aMgr.GetImageThrow("LIGHTNING_VER");
		LOCK = aMgr.GetImageThrow("LOCK");
		SHOOT_FIRE = aMgr.GetImageThrow("SHOOT_FIRE");
		SKY = aMgr.GetImageThrow("SKY");
		SND_EXPLOSION = aMgr.GetSoundThrow("SND_EXPLOSION");
		SND_GAME_BACK = aMgr.GetSoundThrow("SND_GAME_BACK");
		SND_GAME_OVER = aMgr.GetSoundThrow("SND_GAME_OVER");
		SND_LEVEL_CLEAR = aMgr.GetSoundThrow("SND_LEVEL_CLEAR");
		SND_MAIN = aMgr.GetSoundThrow("SND_MAIN");
		SND_TIMEOUT = aMgr.GetSoundThrow("SND_TIMEOUT");
		UNKNOWN_EGG = aMgr.GetImageThrow("UNKNOWN_EGG");
	}
	catch(ResourceManagerException&)
	{
		return false;
	}
	return true;
}

// Init Resources
Image* Sexy::LOGO;
Font* Sexy::NORMAL_FONT;

bool Sexy::ExtractInitResources(ResourceManager *theManager)
{
	gNeedRecalcVariableToIdMap = true;

	ResourceManager &aMgr = *theManager;
	try
	{
		LOGO = aMgr.GetImageThrow("LOGO");
		NORMAL_FONT = aMgr.GetFontThrow("NORMAL_FONT");
	}
	catch(ResourceManagerException&)
	{
		return false;
	}
	return true;
}

static void* gResources[] =
{
	&NORMAL_FONT,
	&LOGO,
	&INFO_PANNEL,
	&STONE_BTN_ON,
	&STONE_BTN_OFF,
	&STONE_BTN_PUSH,
	&BOARD,
	&TIME_BACK,
	&HIT_TIME_BAR,
	&GAME_TIME_BAR,
	&TIME_SIGN,
	&GAME_OVER,
	&GO,
	&READY,
	&LEVEL_CLEAR,
	&DIALOG_SMALL,
	&DIALOG_BTN,
	&MAIN_BACK,
	&BRUNCH,
	&PLAY_BTN_ON,
	&PLAY_BTN_OFF,
	&PLAY_BTN_PUSH,
	&HIGHSCORE_BTN_ON,
	&HIGHSCORE_BTN_OFF,
	&HIGHSCORE_BTN_PUSH,
	&OPTIONS_BTN_ON,
	&OPTIONS_BTN_OFF,
	&OPTIONS_BTN_PUSH,
	&HELP_BTN_ON,
	&HELP_BTN_OFF,
	&HELP_BTN_PUSH,
	&EXIT_BTN_ON,
	&EXIT_BTN_OFF,
	&EXIT_BTN_PUSH,
	&HELP_LINK_TYPE,
	&CHECK_BOX,
	&SLIDER_THUMB,
	&SLIDER_TRACK,
	&EDIT_BOX,
	&CURSOR_NORMAL_IMAGE,
	&CURSOR_HIT_IMAGE,
	&SKY,
	&FLOAT_ISLAND,
	&EGGS,
	&UNKNOWN_EGG,
	&LOCK,
	&LIGHTNING,
	&LIGHTNING_VER,
	&CLOUD,
	&CLOUD1,
	&CLOUD2,
	&CLOUD3,
	&CLOUD4,
	&SHOOT_FIRE,
	&HINT_HAND,
	&SND_GAME_BACK,
	&SND_GAME_OVER,
	&SND_LEVEL_CLEAR,
	&SND_MAIN,
	&SND_EXPLOSION,
	&SND_TIMEOUT,
	&DRAGON_ANGRY,
	&DRAGON_BREATH,
	&DRAGON_LAUGH,
	&DRAGON_SAD,
	NULL
};

Image* Sexy::LoadImageById(ResourceManager *theManager, int theId)
{
	return (*((Image**)gResources[theId]) = theManager->LoadImage(GetStringIdById(theId)));
}

void Sexy::ReplaceImageById(ResourceManager *theManager, int theId, Image *theImage)
{
	theManager->ReplaceImage(GetStringIdById(theId),theImage);
	*(Image**)gResources[theId] = theImage;
}

Image* Sexy::GetImageById(int theId)
{
	return *(Image**)gResources[theId];
}

Font* Sexy::GetFontById(int theId)
{
	return *(Font**)gResources[theId];
}

int Sexy::GetSoundById(int theId)
{
	return *(int*)gResources[theId];
}

Image*& Sexy::GetImageRefById(int theId)
{
	return *(Image**)gResources[theId];
}

Font*& Sexy::GetFontRefById(int theId)
{
	return *(Font**)gResources[theId];
}

int& Sexy::GetSoundRefById(int theId)
{
	return *(int*)gResources[theId];
}

static Sexy::ResourceId GetIdByVariable(const void *theVariable)
{
	typedef std::map<int,int> MyMap;
	static MyMap aMap;
	if(gNeedRecalcVariableToIdMap)
	{
		gNeedRecalcVariableToIdMap = false;
		aMap.clear();
		for(int i=0; i<RESOURCE_ID_MAX; i++)
			aMap[*(int*)gResources[i]] = i;
	}

	MyMap::iterator anItr = aMap.find((int)theVariable);
	if (anItr == aMap.end())
		return RESOURCE_ID_MAX;
	else
		return (ResourceId) anItr->second;
}

Sexy::ResourceId Sexy::GetIdByImage(Image *theImage)
{
	return GetIdByVariable(theImage);
}

Sexy::ResourceId Sexy::GetIdByFont(Font *theFont)
{
	return GetIdByVariable(theFont);
}

Sexy::ResourceId Sexy::GetIdBySound(int theSound)
{
	return GetIdByVariable((void*)theSound);
}

const char* Sexy::GetStringIdById(int theId)
{
	switch(theId)
	{
		case NORMAL_FONT_ID: return "NORMAL_FONT";
		case LOGO_ID: return "LOGO";
		case INFO_PANNEL_ID: return "INFO_PANNEL";
		case STONE_BTN_ON_ID: return "STONE_BTN_ON";
		case STONE_BTN_OFF_ID: return "STONE_BTN_OFF";
		case STONE_BTN_PUSH_ID: return "STONE_BTN_PUSH";
		case BOARD_ID: return "BOARD";
		case TIME_BACK_ID: return "TIME_BACK";
		case HIT_TIME_BAR_ID: return "HIT_TIME_BAR";
		case GAME_TIME_BAR_ID: return "GAME_TIME_BAR";
		case TIME_SIGN_ID: return "TIME_SIGN";
		case GAME_OVER_ID: return "GAME_OVER";
		case GO_ID: return "GO";
		case READY_ID: return "READY";
		case LEVEL_CLEAR_ID: return "LEVEL_CLEAR";
		case DIALOG_SMALL_ID: return "DIALOG_SMALL";
		case DIALOG_BTN_ID: return "DIALOG_BTN";
		case MAIN_BACK_ID: return "MAIN_BACK";
		case BRUNCH_ID: return "BRUNCH";
		case PLAY_BTN_ON_ID: return "PLAY_BTN_ON";
		case PLAY_BTN_OFF_ID: return "PLAY_BTN_OFF";
		case PLAY_BTN_PUSH_ID: return "PLAY_BTN_PUSH";
		case HIGHSCORE_BTN_ON_ID: return "HIGHSCORE_BTN_ON";
		case HIGHSCORE_BTN_OFF_ID: return "HIGHSCORE_BTN_OFF";
		case HIGHSCORE_BTN_PUSH_ID: return "HIGHSCORE_BTN_PUSH";
		case OPTIONS_BTN_ON_ID: return "OPTIONS_BTN_ON";
		case OPTIONS_BTN_OFF_ID: return "OPTIONS_BTN_OFF";
		case OPTIONS_BTN_PUSH_ID: return "OPTIONS_BTN_PUSH";
		case HELP_BTN_ON_ID: return "HELP_BTN_ON";
		case HELP_BTN_OFF_ID: return "HELP_BTN_OFF";
		case HELP_BTN_PUSH_ID: return "HELP_BTN_PUSH";
		case EXIT_BTN_ON_ID: return "EXIT_BTN_ON";
		case EXIT_BTN_OFF_ID: return "EXIT_BTN_OFF";
		case EXIT_BTN_PUSH_ID: return "EXIT_BTN_PUSH";
		case HELP_LINK_TYPE_ID: return "HELP_LINK_TYPE";
		case CHECK_BOX_ID: return "CHECK_BOX";
		case SLIDER_THUMB_ID: return "SLIDER_THUMB";
		case SLIDER_TRACK_ID: return "SLIDER_TRACK";
		case EDIT_BOX_ID: return "EDIT_BOX";
		case CURSOR_NORMAL_IMAGE_ID: return "CURSOR_NORMAL_IMAGE";
		case CURSOR_HIT_IMAGE_ID: return "CURSOR_HIT_IMAGE";
		case SKY_ID: return "SKY";
		case FLOAT_ISLAND_ID: return "FLOAT_ISLAND";
		case EGGS_ID: return "EGGS";
		case UNKNOWN_EGG_ID: return "UNKNOWN_EGG";
		case LOCK_ID: return "LOCK";
		case LIGHTNING_ID: return "LIGHTNING";
		case LIGHTNING_VER_ID: return "LIGHTNING_VER";
		case CLOUD_ID: return "CLOUD";
		case CLOUD1_ID: return "CLOUD1";
		case CLOUD2_ID: return "CLOUD2";
		case CLOUD3_ID: return "CLOUD3";
		case CLOUD4_ID: return "CLOUD4";
		case SHOOT_FIRE_ID: return "SHOOT_FIRE";
		case HINT_HAND_ID: return "HINT_HAND";
		case SND_GAME_BACK_ID: return "SND_GAME_BACK";
		case SND_GAME_OVER_ID: return "SND_GAME_OVER";
		case SND_LEVEL_CLEAR_ID: return "SND_LEVEL_CLEAR";
		case SND_MAIN_ID: return "SND_MAIN";
		case SND_EXPLOSION_ID: return "SND_EXPLOSION";
		case SND_TIMEOUT_ID: return "SND_TIMEOUT";
		case DRAGON_ANGRY_ID: return "DRAGON_ANGRY";
		case DRAGON_BREATH_ID: return "DRAGON_BREATH";
		case DRAGON_LAUGH_ID: return "DRAGON_LAUGH";
		case DRAGON_SAD_ID: return "DRAGON_SAD";
		default: return "";
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -