diff --git a/AdventureMapButton.h b/AdventureMapButton.h index 9ab30052a..a71620dbe 100644 --- a/AdventureMapButton.h +++ b/AdventureMapButton.h @@ -1,5 +1,8 @@ #pragma once #include "SDL_Extensions.h" +#include "hch\CDefHandler.h" +#include "CGameInfo.h" +#include "hch\CLodHandler.h" template AdventureMapButton::AdventureMapButton () { diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 2ae6092ed..f6803e951 100644 --- a/CAdvmapInterface.cpp +++ b/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")); diff --git a/CAdvmapInterface.h b/CAdvmapInterface.h index 83f113020..2a82be70d 100644 --- a/CAdvmapInterface.h +++ b/CAdvmapInterface.h @@ -237,7 +237,7 @@ public: CTownList townList; CInfoBar infoBar; - CHeroWindow heroWindow; + CHeroWindow * heroWindow; struct CurrentSelection { diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 5a05cf2b1..7b52f4ef5 100644 --- a/CHeroWindow.cpp +++ b/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(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; -} \ No newline at end of file +} + +void CHeroWindow::quit() +{ + for(int i=0; iobjsToBlit.size(); ++i) + { + if( dynamic_cast( LOCPLINT->objsToBlit[i] ) ) + { + LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+i); + } + } + quitButton->deactivate(); + LOCPLINT->adventureInt->show(); +} + +void CHeroWindow::activate() +{ + quitButton->activate(); +} diff --git a/CHeroWindow.h b/CHeroWindow.h index d99f46258..2da23a9e0 100644 --- a/CHeroWindow.h +++ b/CHeroWindow.h @@ -1,6 +1,7 @@ #pragma once #include "CPlayerInterface.h" +template 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 * 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 }; \ No newline at end of file diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 0745741b3..bb5ed7ae3 100644 --- a/CPlayerInterface.cpp +++ b/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(); } \ No newline at end of file