Przeglądaj źródła

* code reorganization
* minor stuff for resource <-> infoBar interaction

Michał W. Urbańczyk 18 lat temu
rodzic
commit
e427974875
7 zmienionych plików z 371 dodań i 350 usunięć
  1. 184 212
      CAdvmapInterface.cpp
  2. 2 0
      CAdvmapInterface.h
  3. 7 0
      CCallback.cpp
  4. 1 0
      CCallback.h
  5. 6 0
      CLua.cpp
  6. 163 137
      CPlayerInterface.cpp
  7. 8 1
      CPlayerInterface.h

+ 184 - 212
CAdvmapInterface.cpp

@@ -663,30 +663,6 @@ void CMinimap::draw()
 			}
 		}
 	}
-
-	//draw FoW
-	//for (int i=0; i<mw; i++)
-	//{
-	//	for (int j=0; j<mh; j++)
-	//	{
-	//		int3 pp((((float)i/mw)*CGI->mh->sizes.x), (((float)j/mh)*CGI->mh->sizes.y), LOCPLINT->adventureInt->position.z);
-	//		/*pp.x = (((float)i/mw)*CGI->mh->sizes.x);
-	//		pp.y = (((float)j/mh)*CGI->mh->sizes.y);
-	//		pp.z = LOCPLINT->adventureInt->position.z;*/
-	//		if ( !LOCPLINT->cb->isVisible(pp) )
-	//		{
-	//			for (int ii=0; ii<wo; ii++)
-	//			{
-	//				for (int jj=0; jj<ho; jj++)
-	//				{
-	//					if ((i+ii<pos.w-1) && (j+jj<pos.h-1))
-	//						SDL_PutPixelWithoutRefresh(temps,i+ii,j+jj,0,0,0);
-	//				}
-	//			}
-	//		}
-	//	}
-	//}
-	//update(temps);
 	blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps);
 	
 	//draw radar
@@ -864,14 +840,6 @@ void CTerrainRect::clickLeft(tribool down)
 	//bufpos.x-=1;
 	if (mres)
 		currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
-
-	//if (LOCPLINT->objsToBlit.size()==0)
-	//{
-	//	CSimpleWindow * temp = CMessage::genWindow(" Tutaj dlugi dlugo test Tutaj dlugi dlugi dlugo test Tutaj dlugi dlugi dlugo test Tutaj dlugi dlugi dlugo test {Tutaj tytul} Tutaj dlugi dlugi dlugo test",0);
-	//	temp->pos.x=temp->pos.y=0;temp->ID=3;
-	//	LOCPLINT->objsToBlit.push_back(temp);
-	//}
-	//SDL_Delay(5000);
 }
 void CTerrainRect::clickRight(tribool down)
 {
@@ -900,213 +868,217 @@ void CTerrainRect::hover(bool on)
 	if (!on)
 		LOCPLINT->adventureInt->statusbar.clear();
 }
-void CTerrainRect::show()
+void CTerrainRect::showPath()
 {
-	SDL_Surface * teren = CGI->mh->terrainRect
-		(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
-		tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim, LOCPLINT->cb->getVisibilityMap());
-	SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),ekran,&genRect(547,594,7,6));
-	SDL_FreeSurface(teren);
-	if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
+	for (int i=0;i<currentPath->nodes.size()-1;i++)
 	{
-		for (int i=0;i<currentPath->nodes.size()-1;i++)
+		int pn=-1;//number of picture
+		if (i==0) //last tile
 		{
-			int pn=-1;//number of picture
-			if (i==0) //last tile
+			int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
+				y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
+			if (x<0 || y<0 || x>pos.w || y>pos.h)
+				continue;
+			pn=0;
+		}
+		else
+		{
+			std::vector<CPathNode> & cv = currentPath->nodes;
+			if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
+			{
+				if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
+				{
+					pn = 3;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
+				{
+					pn = 12;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
+				{
+					pn = 21;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
+				{
+					pn = 22;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
+				{
+					pn = 2;
+				}
+			}
+			else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
 			{
-				int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
-					y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
-				if (x<0 || y<0 || x>pos.w || y>pos.h)
-					continue;
-				pn=0;
+				if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
+				{
+					pn = 4;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
+				{
+					pn = 13;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
+				{
+					pn = 22;
+				}
 			}
-			else
+			else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
 			{
-				std::vector<CPathNode> & cv = currentPath->nodes;
-				if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y-1)
+				if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
 				{
-					if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
-					{
-						pn = 3;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 12;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 21;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 22;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 2;
-					}
+					pn = 5;
 				}
-				else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y-1)
+				else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
 				{
-					if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 4;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 13;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 22;
-					}
+					pn = 14;
 				}
-				else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y-1)
+				else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
 				{
-					if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 5;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 14;
-					}
-					else if(cv[i-1].coord.x+1 == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y)
-					{
-						pn = 23;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 24;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 4;
-					}
+					pn = 23;
 				}
-				else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
+				else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
 				{
-					if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 6;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
-					{
-						pn = 15;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 24;
-					}
+					pn = 24;
 				}
-				else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
+				else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
 				{
-					if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
-					{
-						pn = 7;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 16;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 17;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 6;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 18;
-					}
+					pn = 4;
 				}
-				else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
+			}
+			else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y)
+			{
+				if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
 				{
-					if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 8;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 9;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 18;
-					}
+					pn = 6;
 				}
-				else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
+				else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
 				{
-					if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 1;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 10;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
-					{
-						pn = 19;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 8;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 20;
-					}
+					pn = 15;
 				}
-				else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
+				else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
 				{
-					if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
-					{
-						pn = 2;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
-					{
-						pn = 11;
-					}
-					else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
-					{
-						pn = 20;
-					}
+					pn = 24;
 				}
-
 			}
-			if (  ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->movement)
-				pn+=25;
-			if (pn>=0)
-			{			
-				int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
-					y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
-				if (x<0 || y<0 || x>pos.w || y>pos.h)
-					continue;
-				int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
-					hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
-				if (hvx<0 && hvy<0)
-					blitAt(arrows->ourImages[pn].bitmap,x,y);
-				else if(hvx<0)
-					SDL_BlitSurface
-						(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
-						ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
-				else if (hvy<0)
+			else if (cv[i+1].coord.x == cv[i].coord.x+1 && cv[i+1].coord.y == cv[i].coord.y+1)
+			{
+				if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y)
+				{
+					pn = 7;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
 				{
-					SDL_BlitSurface
-						(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
-						ekran,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
+					pn = 16;
 				}
-				else
-					SDL_BlitSurface
-						(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
-						ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
+				else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
+				{
+					pn = 17;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y+1)
+				{
+					pn = 6;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
+				{
+					pn = 18;
+				}
+			}
+			else if (cv[i+1].coord.x == cv[i].coord.x && cv[i+1].coord.y == cv[i].coord.y+1)
+			{
+				if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
+				{
+					pn = 8;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
+				{
+					pn = 9;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
+				{
+					pn = 18;
+				}
+			}
+			else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y+1)
+			{
+				if(cv[i-1].coord.x == cv[i].coord.x && cv[i-1].coord.y == cv[i].coord.y-1)
+				{
+					pn = 1;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
+				{
+					pn = 10;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
+				{
+					pn = 19;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x-1 && cv[i-1].coord.y == cv[i].coord.y-1)
+				{
+					pn = 8;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
+				{
+					pn = 20;
+				}
+			}
+			else if (cv[i+1].coord.x == cv[i].coord.x-1 && cv[i+1].coord.y == cv[i].coord.y)
+			{
+				if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y-1)
+				{
+					pn = 2;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y)
+				{
+					pn = 11;
+				}
+				else if(cv[i-1].coord.x == cv[i].coord.x+1 && cv[i-1].coord.y == cv[i].coord.y+1)
+				{
+					pn = 20;
+				}
+			}
 
+		}
+		if (  ((currentPath->nodes[i].dist)-(*(currentPath->nodes.end()-1)).dist) > ((const CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->movement)
+			pn+=25;
+		if (pn>=0)
+		{
+			int x = 32*(currentPath->nodes[i].coord.x-LOCPLINT->adventureInt->position.x)+7,
+				y = 32*(currentPath->nodes[i].coord.y-LOCPLINT->adventureInt->position.y)+6;
+			if (x<0 || y<0 || x>pos.w || y>pos.h)
+				continue;
+			int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
+				hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
+			if (hvx<0 && hvy<0)
+				blitAt(arrows->ourImages[pn].bitmap,x,y);
+			else if(hvx<0)
+				SDL_BlitSurface
+				(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
+				ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
+			else if (hvy<0)
+			{
+				SDL_BlitSurface
+					(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
+					ekran,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
 			}
-		} //for (int i=0;i<currentPath->nodes.size()-1;i++)
-	} // if (currentPath)
+			else
+				SDL_BlitSurface
+				(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
+				ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
+
+		}
+	} //for (int i=0;i<currentPath->nodes.size()-1;i++)
+}
+void CTerrainRect::show()
+{
+	SDL_Surface * teren = CGI->mh->terrainRect
+		(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
+		tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim, LOCPLINT->cb->getVisibilityMap());
+	SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),ekran,&genRect(547,594,7,6));
+	SDL_FreeSurface(teren);
+	if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path
+	{
+		showPath();
+	}
 }
 
 int3 CTerrainRect::whichTileIsIt(int x, int y)

+ 2 - 0
CAdvmapInterface.h

@@ -166,6 +166,7 @@ public:
 	void mouseMoved (SDL_MouseMotionEvent & sEvent);
 	void keyPressed (SDL_KeyboardEvent & key);
 	void show();
+	void showPath();
 	int3 whichTileIsIt(int x, int y); //x,y are cursor position 
 	int3 whichTileIsIt(); //uses current cursor pos
 };
@@ -190,6 +191,7 @@ class CInfoBar
 {
 public:
 	CDefHandler *day, *week1, *week2, *week3, *week4;
+	SComponent * current;
 	int mode;
 	int pom;
 

+ 7 - 0
CCallback.cpp

@@ -454,6 +454,13 @@ void CScriptCallback::giveResource(int player, int which, int val)
 	gs->players[player].resources[which]+=val;
 	CGI->playerint[gs->players[player].serial]->receivedResource(which,val);
 }
+void CScriptCallback::showCompInfo(int player, SComponent * comp)
+{
+	CPlayerInterface * i = dynamic_cast<CPlayerInterface*>(CGI->playerint[gs->players[player].serial]);
+	if(i)
+		i->showComp(*comp);
+}
+
 void CLuaCallback::registerFuncs(lua_State * L)
 {
 	lua_newtable(L);

+ 1 - 0
CCallback.h

@@ -94,6 +94,7 @@ public:
 	static void changePrimSkill(int ID, int which, int val);
 	void showInfoDialog(int player, std::string text, std::vector<SComponent*> * components);
 	void giveResource(int player, int which, int val);
+	void showCompInfo(int player, SComponent * comp);
 
 	//friends
 	friend void initGameState(CGameInfo * cgi);

+ 6 - 0
CLua.cpp

@@ -16,6 +16,8 @@
 #include "hch/CGeneralTextHandler.h"
 #include <sstream>
 #include "CPlayerInterface.h"
+#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/replace.hpp>
 #pragma warning (disable : 4311)
 bool getGlobalFunc(lua_State * L, std::string fname)
 {
@@ -470,7 +472,11 @@ void CPickable::onHeroVisit(CGObjectInstance *os, int heroID)
 				val = 3 + (rand()%3);
 				break;
 			}
+			SComponent ccc(SComponent::resource,os->subID,val);
+			ccc.description = CGI->objh->advobtxt[113];
+			boost::algorithm::replace_first(ccc.description,"%s",CGI->objh->restypes[os->subID]);
 			cb->giveResource(cb->getHeroOwner(heroID),os->subID,val);
+			cb->showCompInfo(cb->getHeroOwner(heroID),&ccc);
 			break;
 		}
 	}

+ 163 - 137
CPlayerInterface.cpp

@@ -1134,6 +1134,17 @@ void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
 		heroWins.insert(std::pair<int,SDL_Surface*>(hero->subID,infoWin(hero)));
 }
 
+SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from, int to)
+{
+	char * buf = new char[10];
+	for (int i=from;i<to;i++)
+	{
+		itoa(curh->primSkills[i],buf,10);
+		printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
+	}
+	delete buf;
+	return ret;
+}
 SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
 {
 	char * buf = new char[10];
@@ -1141,11 +1152,7 @@ SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
 	SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
 	blueToPlayersAdv(ret,playerID,1);
 	printAt(curh->name,75,15,GEOR13,zwykly,ret);
-	for (int i=0;i<PRIMARY_SKILLS;i++)
-	{
-		itoa(curh->primSkills[i],buf,10);
-		printAtMiddle(buf,84+28*i,68,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++)
 	{
 		blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
@@ -1183,174 +1190,187 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe
 	}
 	else
 	{
-		if (adventureInt->selection.type == HEROI_TYPE)
+		switch (adventureInt->selection.type)
 		{
-			const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
-			return drawHeroInfoWin(curh);
-		}
-		else if (adventureInt->selection.type == TOWNI_TYPE)
-		{
-			char * buf = new char[10];
-			SDL_Surface * ret = copySurface(hInfo);
-			return ret;
-		}
-		else
+		case HEROI_TYPE:
+			{
+				const CGHeroInstance * curh = (const CGHeroInstance *)adventureInt->selection.selected;
+				return drawHeroInfoWin(curh);
+			}
+		case TOWNI_TYPE:
+			{
+				return drawTownInfoWin((const CGTownInstance *)adventureInt->selection.selected);
+			}
+		default:
 			return NULL;
+		}
 	}
 	return NULL;
 }
 
-void CPlayerInterface::handleEvent(SDL_Event *sEvent)
+void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
 {
-	current = sEvent;
-
-	if(sEvent->type == SDL_MOUSEMOTION)
+	for (int i=0; i<hoverable.size();i++)
 	{
-		CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
+		if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
+		{
+			if (!hoverable[i]->hovered)
+				hoverable[i]->hover(true);
+		}
+		else if (hoverable[i]->hovered)
+		{
+			hoverable[i]->hover(false);
+		}
 	}
-
-	if(sEvent->type==SDL_QUIT) 
-		exit(0);
-	else if (sEvent->type==SDL_KEYDOWN)
+	for(int i=0; i<motioninterested.size();i++)
 	{
-		switch (sEvent->key.keysym.sym)
+		if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
 		{
-		case SDLK_LEFT:
-			{
-				LOCPLINT->adventureInt->scrollingLeft = true;
-				break;
-			}
-		case (SDLK_RIGHT):
-			{
-				LOCPLINT->adventureInt->scrollingRight = true;
-				break;
-			}
-		case (SDLK_UP):
-			{
-				LOCPLINT->adventureInt->scrollingUp = true;
-				break;
-			}
-		case (SDLK_DOWN):
-			{
-				LOCPLINT->adventureInt->scrollingDown = true;
-				break;
-			}
-		case (SDLK_q):
-			{
-				exit(0);
-				break;
-			}
-		case (SDLK_u):
-			{
-				adventureInt->underground.clickLeft(true);
-				break;
-			}
-		case (SDLK_m):
-			{
-				adventureInt->moveHero.clickLeft(true);
-				break;
-			}
-		case (SDLK_e):
-			{
-				adventureInt->endTurn.clickLeft(true);
-				break;
-			}
+			motioninterested[i]->mouseMoved(sEvent->motion);
 		}
-	} //keydown end
-	else if(sEvent->type==SDL_KEYUP) 
+	}
+	if(sEvent->motion.x<15)
+	{
+		LOCPLINT->adventureInt->scrollingLeft = true;
+	}
+	else
+	{
+		LOCPLINT->adventureInt->scrollingLeft = false;
+	}
+	if(sEvent->motion.x>ekran->w-15)
 	{
-		switch (sEvent->key.keysym.sym)
+		LOCPLINT->adventureInt->scrollingRight = true;
+	}
+	else
+	{
+		LOCPLINT->adventureInt->scrollingRight = false;
+	}
+	if(sEvent->motion.y<15)
+	{
+		LOCPLINT->adventureInt->scrollingUp = true;
+	}
+	else
+	{
+		LOCPLINT->adventureInt->scrollingUp = false;
+	}
+	if(sEvent->motion.y>ekran->h-15)
+	{
+		LOCPLINT->adventureInt->scrollingDown = true;
+	}
+	else
+	{
+		LOCPLINT->adventureInt->scrollingDown = false;
+	}
+}
+void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
+{
+	switch (sEvent->key.keysym.sym)
+	{
+	case SDLK_LEFT:
 		{
-		case SDLK_LEFT:
-			{
-				LOCPLINT->adventureInt->scrollingLeft = false;
-				break;
-			}
-		case (SDLK_RIGHT):
-			{
-				LOCPLINT->adventureInt->scrollingRight = false;
-				break;
-			}
-		case (SDLK_UP):
-			{
-				LOCPLINT->adventureInt->scrollingUp = false;
-				break;
-			}
-		case (SDLK_DOWN):
-			{
-				LOCPLINT->adventureInt->scrollingDown = false;
-				break;
-			}
-		case (SDLK_u):
-			{
-				adventureInt->underground.clickLeft(false);
-				break;
-			}
-		case (SDLK_m):
-			{
-				adventureInt->moveHero.clickLeft(false);
-				break;
-			}
-		case (SDLK_e):
-			{
-				adventureInt->endTurn.clickLeft(false);
-				break;
-			}
+			LOCPLINT->adventureInt->scrollingLeft = false;
+			break;
 		}
-	}//keyup end
-	else if(sEvent->type==SDL_MOUSEMOTION)
-	{
-		for (int i=0; i<hoverable.size();i++)
+	case (SDLK_RIGHT):
 		{
-			if (isItIn(&hoverable[i]->pos,sEvent->motion.x,sEvent->motion.y))
-			{
-				if (!hoverable[i]->hovered)
-					hoverable[i]->hover(true);
-			}
-			else if (hoverable[i]->hovered)
-			{
-				hoverable[i]->hover(false);
-			}
+			LOCPLINT->adventureInt->scrollingRight = false;
+			break;
 		}
-		for(int i=0; i<motioninterested.size();i++)
+	case (SDLK_UP):
 		{
-			if (isItIn(&motioninterested[i]->pos,sEvent->motion.x,sEvent->motion.y))
-			{
-				motioninterested[i]->mouseMoved(sEvent->motion);
-			}
+			LOCPLINT->adventureInt->scrollingUp = false;
+			break;
 		}
-		if(sEvent->motion.x<15)
+	case (SDLK_DOWN):
 		{
-			LOCPLINT->adventureInt->scrollingLeft = true;
+			LOCPLINT->adventureInt->scrollingDown = false;
+			break;
 		}
-		else
+	case (SDLK_u):
 		{
-			LOCPLINT->adventureInt->scrollingLeft = false;
+			adventureInt->underground.clickLeft(false);
+			break;
 		}
-		if(sEvent->motion.x>ekran->w-15)
+	case (SDLK_m):
 		{
-			LOCPLINT->adventureInt->scrollingRight = true;
+			adventureInt->moveHero.clickLeft(false);
+			break;
 		}
-		else
+	case (SDLK_e):
 		{
-			LOCPLINT->adventureInt->scrollingRight = false;
+			adventureInt->endTurn.clickLeft(false);
+			break;
 		}
-		if(sEvent->motion.y<15)
+	}
+}
+void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
+{
+	switch (sEvent->key.keysym.sym)
+	{
+	case SDLK_LEFT:
 		{
-			LOCPLINT->adventureInt->scrollingUp = true;
+			LOCPLINT->adventureInt->scrollingLeft = true;
+			break;
 		}
-		else
+	case (SDLK_RIGHT):
 		{
-			LOCPLINT->adventureInt->scrollingUp = false;
+			LOCPLINT->adventureInt->scrollingRight = true;
+			break;
 		}
-		if(sEvent->motion.y>ekran->h-15)
+	case (SDLK_UP):
+		{
+			LOCPLINT->adventureInt->scrollingUp = true;
+			break;
+		}
+	case (SDLK_DOWN):
 		{
 			LOCPLINT->adventureInt->scrollingDown = true;
+			break;
 		}
-		else
+	case (SDLK_q):
 		{
-			LOCPLINT->adventureInt->scrollingDown = false;
+			exit(0);
+			break;
 		}
+	case (SDLK_u):
+		{
+			adventureInt->underground.clickLeft(true);
+			break;
+		}
+	case (SDLK_m):
+		{
+			adventureInt->moveHero.clickLeft(true);
+			break;
+		}
+	case (SDLK_e):
+		{
+			adventureInt->endTurn.clickLeft(true);
+			break;
+		}
+	}
+}
+void CPlayerInterface::handleEvent(SDL_Event *sEvent)
+{
+	current = sEvent;
+
+	if(sEvent->type == SDL_MOUSEMOTION)
+	{
+		CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
+	}
+
+	if(sEvent->type==SDL_QUIT) 
+		exit(0);
+	else if (sEvent->type==SDL_KEYDOWN)
+	{
+		handleKeyDown(sEvent);
+	} //keydown end
+	else if(sEvent->type==SDL_KEYUP) 
+	{
+		handleKeyUp(sEvent);
+	}//keyup end
+	else if(sEvent->type==SDL_MOUSEMOTION)
+	{
+		handleMouseMotion(sEvent);
 	} //mousemotion end
 
 	else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
@@ -1427,6 +1447,12 @@ void CPlayerInterface::receivedResource(int type, int val)
 {
 	adventureInt->resdatabar.draw();
 }
+
+void CPlayerInterface::showComp(SComponent comp)
+{
+
+}
+
 void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
 {
 	adventureInt->hide(); //dezaktywacja starego interfejsu

+ 8 - 1
CPlayerInterface.h

@@ -205,14 +205,21 @@ public:
 	void heroCreated(const CGHeroInstance* hero);
 	void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
 	void receivedResource(int type, int val);
-	
+
+	void showComp(SComponent comp);
+
 	SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void*
 	void handleEvent(SDL_Event * sEvent);
+	void handleKeyDown(SDL_Event *sEvent);
+	void handleKeyUp(SDL_Event *sEvent);
+	void handleMouseMotion(SDL_Event *sEvent);
 	void init(ICallback * CB);
 	int3 repairScreenPos(int3 pos);
 	void showInfoDialog(std::string text, std::vector<SComponent*> & components);
 	void removeObjToBlit(IShowable* obj);
 	SDL_Surface * drawHeroInfoWin(const CGHeroInstance * curh);
+	SDL_Surface * drawPrimarySkill(const CGHeroInstance *curh, SDL_Surface *ret, int from=0, int to=PRIMARY_SKILLS);
+
 	SDL_Surface * drawTownInfoWin(const CGTownInstance * curh);
 
 	CPlayerInterface(int Player, int serial);