瀏覽代碼

heroWindow is now show/hideable ;]

mateuszb 18 年之前
父節點
當前提交
2ce033aba9
共有 6 個文件被更改,包括 46 次插入9 次删除
  1. 3 0
      AdventureMapButton.h
  2. 2 1
      CAdvmapInterface.cpp
  3. 1 1
      CAdvmapInterface.h
  4. 29 4
      CHeroWindow.cpp
  5. 7 1
      CHeroWindow.h
  6. 4 2
      CPlayerInterface.cpp

+ 3 - 0
AdventureMapButton.h

@@ -1,5 +1,8 @@
 #pragma once
 #include "SDL_Extensions.h"
+#include "hch\CDefHandler.h"
+#include "CGameInfo.h"
+#include "hch\CLodHandler.h"
 template <typename T>
 AdventureMapButton<T>::AdventureMapButton ()
 {

+ 2 - 1
CAdvmapInterface.cpp

@@ -25,6 +25,7 @@ using namespace CSDL_Ext;
 CAdvMapInt::~CAdvMapInt()
 {
 	SDL_FreeSurface(bg);
+	delete heroWindow;
 }
 void CList::activate()
 {
@@ -1277,7 +1278,7 @@ endTurn(CGI->preth->advEndTurn.first,CGI->preth->advEndTurn.second,
 	//townList.init();
 	townList.genList();
 
-	heroWindow = CHeroWindow();
+	heroWindow = new CHeroWindow(this->player);
 	
 	gems.push_back(CGI->spriteh->giveDef("agemLL.def"));
 	gems.push_back(CGI->spriteh->giveDef("agemLR.def"));

+ 1 - 1
CAdvmapInterface.h

@@ -237,7 +237,7 @@ public:
 	CTownList townList;	
 	CInfoBar infoBar;
 
-	CHeroWindow heroWindow;
+	CHeroWindow * heroWindow;
 	
 	struct CurrentSelection
 	{

+ 29 - 4
CHeroWindow.cpp

@@ -2,21 +2,27 @@
 #include "CHeroWindow.h"
 #include "SDL.h"
 #include "SDL_Extensions.h"
+#include "CAdvmapInterface.h"
+#include "AdventureMapButton.h"
 
 extern SDL_Surface * ekran;
 
-CHeroWindow::CHeroWindow()
+CHeroWindow::CHeroWindow(int playerColor)
 {
 	background = SDL_LoadBMP("Data\\HEROSCR4.bmp");
-	pos.x = 0;
-	pos.y = 0;
+	CSDL_Ext::blueToPlayersAdv(background, playerColor);
+	pos.x = 65;
+	pos.y = 8;
 	pos.h = background->h;
 	pos.w = background->w;
+
+	quitButton = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::quit, 674, 524, "hsbtns.def", this);
 }
 
 CHeroWindow::~CHeroWindow()
 {
 	SDL_FreeSurface(background);
+	delete quitButton;
 }
 
 void CHeroWindow::show(SDL_Surface *to)
@@ -24,9 +30,28 @@ void CHeroWindow::show(SDL_Surface *to)
 	if(!to)
 		to=ekran;
 	blitAt(background,pos.x,pos.y,to);
+	quitButton->show();
 }
 
 void CHeroWindow::setHero(const CGHeroInstance *hero)
 {
 	curHero = hero;
-}
+}
+
+void CHeroWindow::quit()
+{
+	for(int i=0; i<LOCPLINT->objsToBlit.size(); ++i)
+	{
+		if( dynamic_cast<CHeroWindow*>( LOCPLINT->objsToBlit[i] ) )
+		{
+			LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+i);
+		}
+	}
+	quitButton->deactivate();
+	LOCPLINT->adventureInt->show();
+}
+
+void CHeroWindow::activate()
+{
+	quitButton->activate();
+}

+ 7 - 1
CHeroWindow.h

@@ -1,6 +1,7 @@
 #pragma once
 #include "CPlayerInterface.h"
 
+template <typename T> class AdventureMapButton;
 class SDL_Surface;
 class CGHeroInstance;
 
@@ -8,9 +9,14 @@ class CHeroWindow: public IShowable, public virtual CIntObject
 {
 	SDL_Surface * background;
 	const CGHeroInstance * curHero;
+
+	//buttons
+	AdventureMapButton<CHeroWindow> * quitButton;
 public:
-	CHeroWindow(); //c-tor
+	CHeroWindow(int playerColor); //c-tor
 	~CHeroWindow(); //d-tor
 	void setHero(const CGHeroInstance * hero); //sets main displayed hero
+	void activate(); //activates hero window;
 	virtual void show(SDL_Surface * to = NULL); //shows hero window
+	void quit(); //stops displaying hero window
 };

+ 4 - 2
CPlayerInterface.cpp

@@ -1569,6 +1569,8 @@ void CPlayerInterface::tileHidden(int3 pos)
 }
 void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
 {
-	adventureInt->heroWindow.setHero(hero);
-	adventureInt->heroWindow.show();
+	adventureInt->heroWindow->setHero(hero);
+	this->objsToBlit.push_back(adventureInt->heroWindow);
+	adventureInt->heroWindow->activate();
+	adventureInt->hide();
 }