Преглед на файлове

* new interface coloring (many thanks to GrayFace ;])
* fixed bug in object flag's coloring
* a bit of water animation (next thanks to GrayFace, even if it does not work good ATM)

mateuszb преди 17 години
родител
ревизия
8b5a50f619
променени са 9 файла, в които са добавени 72 реда и са изтрити 86 реда
  1. 6 3
      AdventureMapButton.h
  2. 2 1
      CAdvmapInterface.h
  3. 2 2
      CCastleInterface.cpp
  4. 9 9
      CHeroWindow.cpp
  5. 15 0
      CMT.cpp
  6. 29 2
      CPlayerInterface.cpp
  7. 6 67
      SDL_Extensions.cpp
  8. 0 1
      SDL_Extensions.h
  9. 3 1
      mapHandler.cpp

+ 6 - 3
AdventureMapButton.h

@@ -17,7 +17,7 @@ AdventureMapButton<T>::AdventureMapButton ()
 }
 template <typename T>
 AdventureMapButton<T>::AdventureMapButton
-( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ, std::vector<std::string> * add )
+( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ, std::vector<std::string> * add, bool playerColoredButton )
 {
 	owner = Owner;
 	type=2;
@@ -27,6 +27,7 @@ AdventureMapButton<T>::AdventureMapButton
 	state=0;
 	name=Name;
 	helpBox=HelpBox;
+	colorChange = playerColoredButton;
 	int est = LOCPLINT->playerID;
 	CDefHandler * temp = CGI->spriteh->giveDef(defName); 
 	temp->notFreeImgs = true;
@@ -34,7 +35,8 @@ AdventureMapButton<T>::AdventureMapButton
 	{
 		imgs.resize(1);
 		imgs[0].push_back(temp->ourImages[i].bitmap);
-		CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
+		if(playerColoredButton)
+			CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
 	}
 	delete temp;
 	if (add)
@@ -47,7 +49,8 @@ AdventureMapButton<T>::AdventureMapButton
 			for (int j=0;j<temp->ourImages.size();j++)
 			{
 				imgs[i+1].push_back(temp->ourImages[j].bitmap);
-				CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
+				if(playerColoredButton)
+					CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
 			}
 			delete temp;
 		}

+ 2 - 1
CAdvmapInterface.h

@@ -22,6 +22,7 @@ public:
 	char key; //key shortcut
 	T* owner;
 	void (T::*function)(); //function in CAdvMapInt called when this button is pressed, different for each button
+	bool colorChange;
 
 	void clickRight (tribool down);
 	void clickLeft (tribool down);
@@ -31,7 +32,7 @@ public:
 	void deactivate(); // makes button inactive (but doesn't delete)
 
 	AdventureMapButton(); //c-tor
-	AdventureMapButton( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ=false,  std::vector<std::string> * add = NULL );//c-tor
+	AdventureMapButton( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ=false,  std::vector<std::string> * add = NULL, bool playerColoredButton = true );//c-tor
 };
 /*****************************/
 class CMinimap

+ 2 - 2
CCastleInterface.cpp

@@ -163,9 +163,9 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
 	flag =  CGI->spriteh->giveDef("CREST58.DEF");
 	townlist = new CTownList<CCastleInterface>(3,&genRect(128,48,744,414),744,414,744,526);
 	exit = new AdventureMapButton<CCastleInterface>
-		(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,false);
+		(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,false,NULL,false);
 	split = new AdventureMapButton<CCastleInterface>
-		(CGI->townh->tcommands[3],"",&CCastleInterface::splitF,744,382,"TSBTNS.DEF",this,false);
+		(CGI->townh->tcommands[3],"",&CCastleInterface::splitF,744,382,"TSBTNS.DEF",this,false,NULL,false);
 	statusbar = new CStatusBar(8,555,"TSTATBAR.bmp",732);
 
 	townlist->owner = this;

+ 9 - 9
CHeroWindow.cpp

@@ -31,17 +31,17 @@ CHeroWindow::CHeroWindow(int playerColor):
 	garInt = NULL;
 	ourBar = new CStatusBar(72, 567, "ADROLLVR.bmp", 660);
 
-	quitButton = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[17], std::string(), &CHeroWindow::quit, 674, 524, "hsbtns.def", this);
-	dismissButton = new AdventureMapButton<CHeroWindow>(std::string(), CGI->generaltexth->heroscrn[28], &CHeroWindow::dismissCurrent, 519, 437, "hsbtns2.def", this);
-	questlogButton = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[0], std::string(), &CHeroWindow::questlog, 379, 437, "hsbtns4.def", this);
+	quitButton = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[17], std::string(), &CHeroWindow::quit, 674, 524, "hsbtns.def", this, false, NULL, false);
+	dismissButton = new AdventureMapButton<CHeroWindow>(std::string(), CGI->generaltexth->heroscrn[28], &CHeroWindow::dismissCurrent, 519, 437, "hsbtns2.def", this, false, NULL, false);
+	questlogButton = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[0], std::string(), &CHeroWindow::questlog, 379, 437, "hsbtns4.def", this, false, NULL, false);
 
-	gar1button = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[23], CGI->generaltexth->heroscrn[29], &CHeroWindow::gar1, 546, 491, "hsbtns6.def", this);
-	gar2button = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::gar2, 604, 491, "hsbtns8.def", this);
-	gar3button = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[24], CGI->generaltexth->heroscrn[30], &CHeroWindow::gar3, 546, 527, "hsbtns7.def", this);
-	gar4button = new AdventureMapButton<CHeroWindow>(std::string(), CGI->generaltexth->heroscrn[32], &CHeroWindow::gar4, 604, 527, "hsbtns9.def", this);
+	gar1button = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[23], CGI->generaltexth->heroscrn[29], &CHeroWindow::gar1, 546, 491, "hsbtns6.def", this, false, NULL, false);
+	gar2button = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::gar2, 604, 491, "hsbtns8.def", this, false, NULL, false);
+	gar3button = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[24], CGI->generaltexth->heroscrn[30], &CHeroWindow::gar3, 546, 527, "hsbtns7.def", this, false, NULL, false);
+	gar4button = new AdventureMapButton<CHeroWindow>(std::string(), CGI->generaltexth->heroscrn[32], &CHeroWindow::gar4, 604, 527, "hsbtns9.def", this, false, NULL, false);
 
-	leftArtRoll = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::leftArtRoller, 379, 364, "hsbtns3.def", this);
-	rightArtRoll = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::rightArtRoller, 632, 364, "hsbtns5.def", this);
+	leftArtRoll = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::leftArtRoller, 379, 364, "hsbtns3.def", this, false, NULL, false);
+	rightArtRoll = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::rightArtRoller, 632, 364, "hsbtns5.def", this, false, NULL, false);
 
 	for(int g=0; g<8; ++g)
 	{

+ 15 - 0
CMT.cpp

@@ -64,6 +64,8 @@ CGameInfo* CGI;
 #define CHUNK 16384
 const char * NAME = "VCMI 0.53c \"Tirion\" Techdemo";
 
+SDL_Color playerColorPalette[256]; //palette to make interface colors good
+
 SDL_Surface * ekran, * screen, * screen2;
 extern SDL_Surface * CSDL_Ext::std32bppSurface;
 TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
@@ -417,6 +419,19 @@ int _tmain(int argc, _TCHAR* argv[])
 		p.r = 0x84; p.g = 0x84; p.b = 0x84;//gray
 		cgi->neutralColor = p;//gray
 		//colors initialized
+		//palette initialization
+		std::string pals = cgi->bitmaph->getTextFile("PLAYERS.PAL");
+		int startPoint = 24; //beginning byte; used to read
+		for(int i=0; i<256; ++i)
+		{
+			SDL_Color col;
+			col.r = pals[startPoint++];
+			col.g = pals[startPoint++];
+			col.b = pals[startPoint++];
+			col.unused = pals[startPoint++];
+			playerColorPalette[i] = col;
+		}
+		//palette initialized
 		THC std::cout<<"Preparing players' colours: "<<tmh.getDif()<<std::endl;
 		CMessage::init();
 		cgi->townh = new CTownHandler;

+ 29 - 2
CPlayerInterface.cpp

@@ -801,6 +801,33 @@ void CPlayerInterface::yourTurn()
 	th.getDif();
 	for(;makingTurn;) // main loop
 	{
+		//updating water tiles
+		int wnumber = -1;
+		for(int s=0; s<CGI->mh->reader->defs.size(); ++s)
+		{
+			if(CGI->mh->reader->defs[s]->defName==std::string("WATRTL.DEF"))
+			{
+				wnumber = s;
+				break;
+			}
+		}
+		if(wnumber>=0)
+		{
+			for(int g=0; g<CGI->mh->reader->defs[wnumber]->ourImages.size(); ++g)
+			{
+				SDL_Color tab[32];
+				for(int i=0; i<32; ++i)
+				{
+					tab[i] = CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[224 + (i+1)%32];
+				}
+				for(int i=0; i<32; ++i)
+				{
+					CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[224 + i] = tab[i];
+				}
+				CSDL_Ext::update(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap);
+			}
+		}
+		//water tiles updated
 		CGI->screenh->updateScreen();
 		int tv = th.getDif();
 		for (int i=0;i<timeinterested.size();i++)
@@ -1391,9 +1418,9 @@ SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL
 SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
 {
 	char * buf = new char[10];
+	blueToPlayersAdv(hInfo,playerID,1);
 	SDL_Surface * ret = SDL_DisplayFormat(hInfo);
 	SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
-	blueToPlayersAdv(ret,playerID,1);
 	printAt(curh->name,75,15,GEOR13,zwykly,ret);
 	drawPrimarySkill(curh, ret);
 	for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->army.slots.begin(); i!=curh->army.slots.end();i++)
@@ -1415,9 +1442,9 @@ SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
 SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh)
 {
 	char * buf = new char[10];
+	blueToPlayersAdv(tInfo,playerID,1);
 	SDL_Surface * ret = SDL_DisplayFormat(tInfo);
 	SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
-	blueToPlayersAdv(ret,playerID,1);
 	printAt(curh->name,75,15,GEOR13,zwykly,ret);
 
 	int pom = curh->fortLevel() - 1; if(pom<0) pom = 3;

+ 6 - 67
SDL_Extensions.cpp

@@ -8,6 +8,9 @@
 #include "CMessage.h"
 #include <boost/algorithm/string.hpp>
 #include "hch\CDefHandler.h"
+
+extern SDL_Color playerColorPalette[256];
+
 SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given
 {
 	return SDL_CreateRGBSurface(mod->flags,w,h,mod->format->BitsPerPixel,mod->format->Rmask,mod->format->Gmask,mod->format->Bmask,mod->format->Amask);
@@ -676,53 +679,12 @@ void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player, int mode, void* a
 		return;
 	if(sur->format->BitsPerPixel == 8)
 	{
-		for(int i=0; i<sur->format->palette->ncolors; ++i) //message, button, avmap, resbar
+		for(int i=0; i<32; ++i)
 		{
-			SDL_Color * cc = sur->format->palette->colors+i;
-			if(
-				((mode==0) && (cc->b>cc->g) && (cc->b>cc->r)) ||
-				((mode==1) && (cc->r<45) && (cc->b>80) && (cc->g<70) && ((cc->b-cc->r)>40)) ||
-				((mode==2) && (cc->r<110) && (cc->b>63) && (cc->g<122) && ((cc->b-cc->r)>44) && ((cc->b-cc->g)>32))
-			  )
-			{
-				if ((mode==2) && additionalInfo)
-				{
-					for (int vi=0; vi<((std::vector<SDL_Color>*)additionalInfo)->size(); vi++)
-					{
-						if 
-						  (
-							((*((std::vector<SDL_Color>*)additionalInfo))[vi].r==cc->r) &&
-							((*((std::vector<SDL_Color>*)additionalInfo))[vi].g==cc->g) &&
-							((*((std::vector<SDL_Color>*)additionalInfo))[vi].b==cc->b)
-						  )	
-							goto main8bitloopend;
-					}
-				}
-				std::vector<long long int> sort1;
-				sort1.push_back(cc->r);
-				sort1.push_back(cc->g);
-				sort1.push_back(cc->b);
-				std::vector< std::pair<long long int, Uint8*> > sort2;
-				sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].r, &(cc->r)));
-				sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].g, &(cc->g)));
-				sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].b, &(cc->b)));
-				std::sort(sort1.begin(), sort1.end());
-				if(sort2[0].first>sort2[1].first)
-					std::swap(sort2[0], sort2[1]);
-				if(sort2[1].first>sort2[2].first)
-					std::swap(sort2[1], sort2[2]);
-				if(sort2[0].first>sort2[1].first)
-					std::swap(sort2[0], sort2[1]);
-				for(int hh=0; hh<3; ++hh)
-				{
-					(*sort2[hh].second) = (sort1[hh]*0.8 + sort2[hh].first)/2;
-				}
-			}
-main8bitloopend:
-			;
+			sur->format->palette->colors[224+i] = playerColorPalette[32*player+i];
 		}
 	}
-	else if(sur->format->BitsPerPixel == 24)
+	else if(sur->format->BitsPerPixel == 24) //should never happen in general
 	{
 		for(int y=0; y<sur->h; ++y)
 		{
@@ -787,29 +749,6 @@ main8bitloopend:
 	}
 }
 
-void CSDL_Ext::blueToPlayersNice(SDL_Surface * sur, int player) //incomplete, TODO: finish
-{
-	if(sur->format->BitsPerPixel==8)
-	{
-		for(int a=0; a<sur->format->palette->ncolors; ++a)
-		{
-			for(int s=0; s<CGI->playerColorInfo[0]->ourImages[1].bitmap->format->palette->ncolors; ++s)
-			{
-				if(abs((sur->format->palette->colors+a)->b - (CGI->playerColorInfo[0]->ourImages[1].bitmap->format->palette->colors+s)->b) < 5
-					&& abs((sur->format->palette->colors+a)->g - (CGI->playerColorInfo[0]->ourImages[1].bitmap->format->palette->colors+s)->g) < 5
-					&& abs((sur->format->palette->colors+a)->r - (CGI->playerColorInfo[0]->ourImages[1].bitmap->format->palette->colors+s)->r) < 5
-					)
-				{
-					(sur->format->palette->colors+a)->b = (CGI->playerColorInfo[0]->ourImages[player].bitmap->format->palette->colors+s)->b;
-					(sur->format->palette->colors+a)->r = (CGI->playerColorInfo[0]->ourImages[player].bitmap->format->palette->colors+s)->g;
-					(sur->format->palette->colors+a)->g = (CGI->playerColorInfo[0]->ourImages[player].bitmap->format->palette->colors+s)->r;
-					break;
-				}
-			}
-		}
-	}
-}
-
 void CSDL_Ext::setPlayerColor(SDL_Surface * sur, unsigned char player)
 {
 	if(player==254)

+ 0 - 1
SDL_Extensions.h

@@ -47,7 +47,6 @@ namespace CSDL_Ext
 	void blueToPlayersAdv(SDL_Surface * sur, int player, int mode=0, void* additionalInfo=NULL); //substitute blue color by another one, makes it nicer keeping nuances
 																							//mode 1 is calibrated for hero infobox
 																							//mode 2 is calibrated for resbar and gets in additionalInfo a pointer to the set of (SDL_Color) which shouldn't be replaced
-	void blueToPlayersNice(SDL_Surface * sur, int player); //uses interface gems to substitute colours
 	void setPlayerColor(SDL_Surface * sur, unsigned char player); //sets correct color of flags; -1 for neutral
 	std::string processStr(std::string str, std::vector<std::string> & tor); //replaces %s in string
 	SDL_Surface * newSurface(int w, int h, SDL_Surface * mod=ekran); //creates new surface, with flags/format same as in surface given

+ 3 - 1
mapHandler.cpp

@@ -541,6 +541,7 @@ void CMapHandler::borderAndTerrainBitmapInit()
 	//	terrainBitmap[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
 
 	CDefHandler * bord = CGameInfo::mainObj->spriteh->giveDef("EDG.DEF");
+	bord->notFreeImgs =  true;
 	for (int i=0-Woff; i<reader->map.width+Woff; i++) //jest po szerokoœci
 	{
 		for (int j=0-Hoff; j<reader->map.height+Hoff;j++) //po wysokoœci
@@ -650,6 +651,7 @@ void CMapHandler::borderAndTerrainBitmapInit()
 			}
 		}
 	}
+	delete bord;
 }
 void CMapHandler::initObjectRects()
 {
@@ -957,7 +959,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 					int imgVal = ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages.size();
 
 					//setting appropriate flag color
-					if((ttiles[x+bx][y+by][level].objects[h].first->tempOwner>=0 && ttiles[x+bx][y+by][level].objects[h].first->tempOwner<=8) || ttiles[x+bx][y+by][level].objects[h].first->tempOwner==255)
+					if((ttiles[x+bx][y+by][level].objects[h].first->tempOwner>=0 && ttiles[x+bx][y+by][level].objects[h].first->tempOwner<8) || ttiles[x+bx][y+by][level].objects[h].first->tempOwner==255)
 						CSDL_Ext::setPlayerColor(ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages[anim%imgVal].bitmap, ttiles[x+bx][y+by][level].objects[h].first->tempOwner);
 					
 					CSDL_Ext::blit8bppAlphaTo24bpp(ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages[anim%imgVal].bitmap,&pp,su,&sr);