Ver código fonte

* right click popups with infoboxes for heroes/towns lists
* separation activate/show functions in advmapint

Michał W. Urbańczyk 17 anos atrás
pai
commit
dbf3b8d08e
6 arquivos alterados com 107 adições e 23 exclusões
  1. 13 0
      AdventureMapButton.h
  2. 17 17
      CAdvmapInterface.cpp
  3. 2 2
      CCastleInterface.cpp
  4. 1 1
      CHeroWindow.cpp
  5. 58 2
      CPlayerInterface.cpp
  6. 16 1
      CPlayerInterface.h

+ 13 - 0
AdventureMapButton.h

@@ -283,6 +283,19 @@ void CTownList<T>::clickRight(tribool down)
 		{
 		{
 			LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[307].second,down,this);
 			LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[307].second,down,this);
 		}
 		}
+		//if not buttons then towns
+		int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
+		hx-=pos.x;
+		hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
+		float ny = (float)hy/(float)32;
+		if ((ny>5 || ny<0) || (from+ny>=items.size()))
+		{
+			return;
+		}
+
+		//show popup
+		CInfoPopup * ip = new CInfoPopup(LOCPLINT->townWins[items[from+ny]->identifier],LOCPLINT->current->motion.x-LOCPLINT->townWins[items[from+ny]->identifier]->w,LOCPLINT->current->motion.y-LOCPLINT->townWins[items[from+ny]->identifier]->h,false);
+		ip->activate();
 	}
 	}
 	else
 	else
 	{
 	{

+ 17 - 17
CAdvmapInterface.cpp

@@ -920,7 +920,23 @@ void CAdvMapInt::fendTurn()
 
 
 void CAdvMapInt::activate()
 void CAdvMapInt::activate()
 {
 {
-	//todo - docelowo wartoby rozdzielic czesc odpowiedzialna za wyswietlanie i aktywacje
+	LOCPLINT->curint = this;
+	LOCPLINT->statusbar = &statusbar;	
+	kingOverview.activate();
+	underground.activate();
+	questlog.activate();
+	sleepWake.activate();
+	moveHero.activate();
+	spellbook.activate();
+	sysOptions.activate();
+	advOptions.activate();
+	nextHero.activate();
+	endTurn.activate();
+
+	minimap.activate();
+	heroList.activate();
+	townList.activate();
+	terrain.activate();
 	show();
 	show();
 }
 }
 void CAdvMapInt::deactivate()
 void CAdvMapInt::deactivate()
@@ -929,38 +945,22 @@ void CAdvMapInt::deactivate()
 }
 }
 void CAdvMapInt::show()
 void CAdvMapInt::show()
 {
 {
-	LOCPLINT->curint = this;
-	LOCPLINT->statusbar = &statusbar;
 	blitAt(bg,0,0);
 	blitAt(bg,0,0);
 
 
 	kingOverview.show();
 	kingOverview.show();
-	kingOverview.activate();
 	underground.show();
 	underground.show();
-	underground.activate();
 	questlog.show();
 	questlog.show();
-	questlog.activate();
 	sleepWake.show();
 	sleepWake.show();
-	sleepWake.activate();
 	moveHero.show();
 	moveHero.show();
-	moveHero.activate();
 	spellbook.show();
 	spellbook.show();
-	spellbook.activate();
 	advOptions.show();
 	advOptions.show();
-	advOptions.activate();
 	sysOptions.show();
 	sysOptions.show();
-	sysOptions.activate();
 	nextHero.show();
 	nextHero.show();
-	nextHero.activate();
 	endTurn.show();
 	endTurn.show();
-	endTurn.activate();
 
 
-	minimap.activate();
 	minimap.draw();
 	minimap.draw();
-	heroList.activate();
 	heroList.draw();
 	heroList.draw();
-	townList.activate();
 	townList.draw();
 	townList.draw();
-	terrain.activate();
 	update();
 	update();
 
 
 	resdatabar.draw();
 	resdatabar.draw();

+ 2 - 2
CCastleInterface.cpp

@@ -276,7 +276,7 @@ void CCastleInterface::close()
 	LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
 	LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
 	deactivate();
 	deactivate();
 	LOCPLINT->castleInt = NULL;
 	LOCPLINT->castleInt = NULL;
-	LOCPLINT->adventureInt->show();
+	LOCPLINT->adventureInt->activate();
 	delete this;
 	delete this;
 }
 }
 void CCastleInterface::splitF()
 void CCastleInterface::splitF()
@@ -292,6 +292,7 @@ void CCastleInterface::showAll(SDL_Surface * to)
 	LOCPLINT->adventureInt->resdatabar.draw();
 	LOCPLINT->adventureInt->resdatabar.draw();
 	townlist->draw();
 	townlist->draw();
 
 
+	garr->show();
 	int pom;
 	int pom;
 
 
 	//draw fort icon
 	//draw fort icon
@@ -381,7 +382,6 @@ void CCastleInterface::show(SDL_Surface * to)
 {
 {
 	if (!to)
 	if (!to)
 		to=ekran;
 		to=ekran;
-	garr->show();
 	count++;
 	count++;
 	if(count==4)
 	if(count==4)
 	{
 	{

+ 1 - 1
CHeroWindow.cpp

@@ -523,7 +523,7 @@ void CHeroWindow::quit()
 	}
 	}
 	deactivate();
 	deactivate();
 
 
-	LOCPLINT->adventureInt->show();
+	LOCPLINT->adventureInt->activate();
 
 
 	SDL_FreeSurface(curBack);
 	SDL_FreeSurface(curBack);
 	curBack = NULL;
 	curBack = NULL;

+ 58 - 2
CPlayerInterface.cpp

@@ -119,6 +119,7 @@ void CGarrisonSlot::clickLeft(tribool down)
 		{
 		{
 			if(creature)
 			if(creature)
 				owner->highlighted = this;
 				owner->highlighted = this;
+			show();
 		}
 		}
 	}
 	}
 }
 }
@@ -375,6 +376,46 @@ void CInfoWindow::close()
 CInfoWindow::~CInfoWindow()
 CInfoWindow::~CInfoWindow()
 {
 {
 }
 }
+
+CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free)
+:bitmap(Bitmap),free(Free)
+{
+	pos.x = x;
+	pos.y = y;
+	pos.h = bitmap->h;
+	pos.w = bitmap->w;
+}
+void CInfoPopup::clickRight (tribool down)
+{
+	//if(!down)
+		close();
+}
+void CInfoPopup::activate()
+{
+	ClickableR::activate();
+	LOCPLINT->objsToBlit.push_back(this);
+}
+void CInfoPopup::deactivate()
+{
+	ClickableR::deactivate();
+	LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
+}
+void CInfoPopup::close()
+{
+	deactivate();
+	if(free)
+		SDL_FreeSurface(bitmap);
+	delete this;
+	if(LOCPLINT->curint == LOCPLINT->adventureInt)
+		LOCPLINT->adventureInt->show();
+	else if(LOCPLINT->curint == LOCPLINT->castleInt)
+		LOCPLINT->castleInt->showAll();
+}
+void CInfoPopup::show(SDL_Surface * to)
+{
+	blitAt(bitmap,pos.x,pos.y,(to)?(to):(ekran));
+}
+
 SComponent::SComponent(Etype Type, int Subtype, int Val)
 SComponent::SComponent(Etype Type, int Subtype, int Val)
 {
 {
 	std::ostringstream oss;
 	std::ostringstream oss;
@@ -788,7 +829,7 @@ void CPlayerInterface::yourTurn()
 	unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
 	unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
 	unsigned char & heroAnimVal = LOCPLINT->adventureInt->heroAnim;
 	unsigned char & heroAnimVal = LOCPLINT->adventureInt->heroAnim;
 	adventureInt->infoBar.newDay(cb->getDate(1));
 	adventureInt->infoBar.newDay(cb->getDate(1));
-	adventureInt->show();
+	adventureInt->activate();
 	//show rest of things
 	//show rest of things
 
 
 	//initializing framerate keeper
 	//initializing framerate keeper
@@ -820,11 +861,13 @@ void CPlayerInterface::yourTurn()
 				{
 				{
 					tab[i] = CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[224 + (i+1)%32];
 					tab[i] = CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[224 + (i+1)%32];
 				}
 				}
+				//SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t1.bmp");
 				for(int i=0; i<32; ++i)
 				for(int i=0; i<32; ++i)
 				{
 				{
 					CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[224 + i] = tab[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);
+				//SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t2.bmp");
+				CSDL_Ext::update(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap); 
 			}
 			}
 		}
 		}
 		//water tiles updated
 		//water tiles updated
@@ -2077,6 +2120,19 @@ void CHeroList::clickRight(tribool down)
 		{
 		{
 			LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[304].second,down,this);
 			LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[304].second,down,this);
 		}
 		}
+		//if not buttons then heroes
+		int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
+		hx-=pos.x;
+		hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
+		float ny = (float)hy/(float)32;
+		if ((ny>5 || ny<0) || (from+ny>=items.size()))
+		{
+			return;
+		}
+
+		//show popup
+		CInfoPopup * ip = new CInfoPopup(LOCPLINT->heroWins[items[from+ny].first->subID],LOCPLINT->current->motion.x-LOCPLINT->heroWins[items[from+ny].first->subID]->w,LOCPLINT->current->motion.y-LOCPLINT->heroWins[items[from+ny].first->subID]->h,false);
+		ip->activate();
 	}
 	}
 	else
 	else
 	{
 	{

+ 16 - 1
CPlayerInterface.h

@@ -151,10 +151,25 @@ public:
 
 
 class CRClickPopup : public IShowable, public ClickableR
 class CRClickPopup : public IShowable, public ClickableR
 {
 {
+public:
 	virtual void activate()=0;
 	virtual void activate()=0;
 	virtual void deactivate()=0;
 	virtual void deactivate()=0;
 	virtual void close()=0;
 	virtual void close()=0;
-	virtual void show()=0;
+	virtual ~CRClickPopup(){};
+};
+
+class CInfoPopup : public CRClickPopup
+{
+public:
+	bool free;
+	SDL_Surface * bitmap;
+	CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free=false);
+	void clickRight (tribool down);
+	void activate();
+	void deactivate();
+	void close();
+	void show(SDL_Surface * to = NULL);
+	~CInfoPopup(){};
 };
 };
 
 
 class SComponent : public ClickableR
 class SComponent : public ClickableR