2
0
Эх сурвалжийг харах

* improved borders
* minor changes

Michał W. Urbańczyk 18 жил өмнө
parent
commit
1f324c3b31

+ 43 - 23
CCastleInterface.cpp

@@ -56,17 +56,17 @@ bool CBuildingRect::operator<(const CBuildingRect & p2) const
 }
 void CBuildingRect::hover(bool on)
 {
-	if(area)
+	Hoverable::hover(on);
+	if(on)
 	{
-		if(CSDL_Ext::SDL_GetPixel(area,LOCPLINT->current->motion.x-pos.x,LOCPLINT->current->motion.y-pos.y) == 0)
-		{
-			Hoverable::hover(false);
-			return;
-		}
+		MotionInterested::activate();
+	}
+	else 
+	{
+		MotionInterested::deactivate();
+		if(LOCPLINT->castleInt->hBuild == this)
+			LOCPLINT->castleInt->hBuild = NULL;
 	}
-	Hoverable::hover(on);
-	if(border)
-		blitAt(border,pos.x,pos.y);
 }
 void CBuildingRect::clickLeft (tribool down)
 {
@@ -76,6 +76,35 @@ void CBuildingRect::clickRight (tribool down)
 {
 	//todo - handle
 }
+
+void CBuildingRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
+{
+	if(area)
+	{
+		if(CSDL_Ext::SDL_GetPixel(area,sEvent.x-pos.x,sEvent.y-pos.y) == 0) //najechany piksel jest poza polem
+		{
+			if(LOCPLINT->castleInt->hBuild == this)
+				LOCPLINT->castleInt->hBuild = NULL;
+		}
+		else //w polu
+		{
+			if(LOCPLINT->castleInt->hBuild) //jakis budynek jest zaznaczony
+			{
+				if((*LOCPLINT->castleInt->hBuild)<(*this)) //ustawiamy sie, jesli jestesmy na wierzchu
+				{
+					LOCPLINT->castleInt->hBuild = this;
+				}
+			}
+			else //nie ma budynku, wiec damy nasz
+			{
+				LOCPLINT->castleInt->hBuild = this;
+			}
+		}
+	}
+	//if(border)
+	//	blitAt(border,pos.x,pos.y);
+}
+
 std::string getBgName(int type) //TODO - co z tym zrobiæ?
 {
 	switch (type)
@@ -115,12 +144,7 @@ public:
 
 CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
 {
-	int t = 600;
-	while(t--)
-	{
-		CDefHandler* defik = CGI->spriteh->giveDef("ITMTL.DEF");
-		delete defik;
-	}
+	hBuild = NULL;
 	count=0;
 	town = Town;
 	townInt = CGI->bitmaph->loadBitmap("TOWNSCRN.bmp");
@@ -140,13 +164,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
 		{
 			if(CGI->townh->structures[town->subID].find(*i)!=CGI->townh->structures[town->subID].end())
 			{
-				//CDefHandler *b = CGI->spriteh->giveDef(CGI->townh->structures[town->subID][*i]->defName);
 				buildings.push_back(new CBuildingRect(CGI->townh->structures[town->subID][*i]));
-				//boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*> *t 
-				//	= new boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*>
-				//	(*i,b,CGI->townh->structures[town->subID][*i],NULL,NULL);
-				////TODO: obwódki i pola
-				//buildings.push_back(t);
 			}
 			else continue;
 		}
@@ -300,8 +318,10 @@ void CCastleInterface::show(SDL_Surface * to)
 		}
 		else 
 			blitAt(buildings[i]->def->ourImages[(animval)%(buildings[i]->def->ourImages.size())].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to);
-		if(buildings[i]->hovered && buildings[i]->border)
-			blitAt(buildings[i]->border,buildings[i]->pos.x,buildings[i]->pos.y);
+		//if(buildings[i]->hovered && buildings[i]->border)
+		//	blitAt(buildings[i]->border,buildings[i]->pos.x,buildings[i]->pos.y);
+		if(hBuild==buildings[i] && hBuild->border)
+			blitAt(hBuild->border,hBuild->pos,to);
 	}
 	//for(int i=0;i<buildings.size();i++)
 	//{

+ 3 - 1
CCastleInterface.h

@@ -7,7 +7,7 @@ class CGTownInstance;
 class CTownHandler;
 struct Structure;
 template <typename T> class AdventureMapButton;
-class CBuildingRect : public Hoverable, public ClickableL, public ClickableR//, public TimeInterested
+class CBuildingRect : public Hoverable, public MotionInterested, public ClickableL, public ClickableR//, public TimeInterested
 {
 public:
 	Structure* str;
@@ -22,11 +22,13 @@ public:
 	void hover(bool on);
 	void clickLeft (tribool down);
 	void clickRight (tribool down);
+	void mouseMoved (SDL_MouseMotionEvent & sEvent);
 };
 
 class CCastleInterface : public IShowable, public IActivable
 {
 public:
+	CBuildingRect * hBuild; //highlighted building
 	SDL_Surface * townInt;
 	SDL_Surface * cityBg;
 	const CGTownInstance * town;

+ 8 - 0
SDL_Extensions.cpp

@@ -43,6 +43,14 @@ void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst)
 	SDL_Rect pom = genRect(src->h,src->w,x,y);
 	SDL_BlitSurface(src,NULL,dst,&pom);
 }
+void blitAtWR(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst)
+{
+	blitAtWR(src,pos.x,pos.y,dst);
+}
+void blitAt(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst)
+{
+	blitAt(src,pos.x,pos.y,dst);
+}
 SDL_Color genRGB(int r, int g, int b, int a=0)
 {
 	SDL_Color ret;

+ 2 - 0
SDL_Extensions.h

@@ -9,6 +9,8 @@ extern SDL_Color tytulowy, tlo, zwykly ;
 extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
 void blitAtWR(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran);
 void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran);
+void blitAtWR(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=ekran);
+void blitAt(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=ekran);
 void updateRect (SDL_Rect * rect, SDL_Surface * scr = ekran);
 bool isItIn(const SDL_Rect * rect, int x, int y);
 SDL_Rect genRect(int hh, int ww, int xx, int yy);