Переглянути джерело

a bit of hero window

help needed - make something to prevent changing surface stored in CHeroWindow::background. I do not overwrite it, but it changes dramatically with every call of CHeroWindow method!

And besides - is there anything to make my window displayed easily, without calling show() every frame when it should be displayed? any machanism?
mateuszb 18 роки тому
батько
коміт
e62cfed95f

+ 1 - 0
AdventureMapButton.h

@@ -1,3 +1,4 @@
+#pragma once
 #include "SDL_Extensions.h"
 template <typename T>
 AdventureMapButton<T>::AdventureMapButton ()

+ 4 - 0
CAdvmapInterface.cpp

@@ -121,6 +121,8 @@ void CHeroList::clickLeft(tribool down)
 		float ny = (float)hy/(float)32;
 		if (ny>5 || ny<0)
 			return;
+		if (((int)(ny+from))==selected)
+			LOCPLINT->openHeroWindow(items[selected].first);//print hero screen
 		select(ny+from);
 	}
 	else
@@ -1274,6 +1276,8 @@ endTurn(CGI->preth->advEndTurn.first,CGI->preth->advEndTurn.second,
 	heroList.genList();
 	//townList.init();
 	townList.genList();
+
+	heroWindow = CHeroWindow();
 	
 	gems.push_back(CGI->spriteh->giveDef("agemLL.def"));
 	gems.push_back(CGI->spriteh->giveDef("agemLR.def"));

+ 3 - 0
CAdvmapInterface.h

@@ -5,6 +5,7 @@
 #include "SDL.h"
 #include "CPlayerInterface.h"
 #include <map>
+#include "CHeroWindow.h"
 class CDefHandler;
 class CCallback;
 class CTownInstance;
@@ -235,6 +236,8 @@ public:
 	CHeroList heroList;
 	CTownList townList;	
 	CInfoBar infoBar;
+
+	CHeroWindow heroWindow;
 	
 	struct CurrentSelection
 	{

+ 1 - 0
CCastleInterface.h

@@ -1,3 +1,4 @@
+#pragma once
 #include "global.h"
 #include "SDL.h"
 #include "CPlayerInterface.h"

+ 32 - 0
CHeroWindow.cpp

@@ -0,0 +1,32 @@
+#include "stdafx.h"
+#include "CHeroWindow.h"
+#include "SDL.h"
+#include "SDL_Extensions.h"
+
+extern SDL_Surface * ekran;
+
+CHeroWindow::CHeroWindow()
+{
+	background = SDL_LoadBMP("Data\\HEROSCR4.bmp");
+	pos.x = 0;
+	pos.y = 0;
+	pos.h = background->h;
+	pos.w = background->w;
+}
+
+CHeroWindow::~CHeroWindow()
+{
+	SDL_FreeSurface(background);
+}
+
+void CHeroWindow::show(SDL_Surface *to)
+{
+	if(!to)
+		to=ekran;
+	blitAt(background,pos.x,pos.y,to);
+}
+
+void CHeroWindow::setHero(const CGHeroInstance *hero)
+{
+	curHero = hero;
+}

+ 16 - 0
CHeroWindow.h

@@ -0,0 +1,16 @@
+#pragma once
+#include "CPlayerInterface.h"
+
+class SDL_Surface;
+class CGHeroInstance;
+
+class CHeroWindow: public IShowable, public virtual CIntObject
+{
+	SDL_Surface * background;
+	const CGHeroInstance * curHero;
+public:
+	CHeroWindow(); //c-tor
+	~CHeroWindow(); //d-tor
+	void setHero(const CGHeroInstance * hero); //sets main displayed hero
+	virtual void show(SDL_Surface * to = NULL); //shows hero window
+};

+ 5 - 0
CPlayerInterface.cpp

@@ -1567,3 +1567,8 @@ void CPlayerInterface::tileHidden(int3 pos)
 {
 	adventureInt->minimap.hideTile(pos);
 }
+void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
+{
+	adventureInt->heroWindow.setHero(hero);
+	adventureInt->heroWindow.show();
+}

+ 2 - 1
CPlayerInterface.h

@@ -219,7 +219,8 @@ public:
 
 	void showComp(SComponent comp);
 
-	void openTownWindow(const CGTownInstance * town);
+	void openTownWindow(const CGTownInstance * town); //shows townscreen
+	void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
 	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);

+ 3 - 3
hch/CAmbarCendamo.cpp

@@ -1639,7 +1639,7 @@ void CAmbarCendamo::deh3m()
 									{
 										std::cout<<"Hej, sprawdz co to za budynek w miescie " <<nt<<std::endl;
 									}
-								}//bs==3 - nie wiadomo co to, 4 w 2. bajcie
+								}//bs==3 - not known what it is, 4 in 2. byte
 								else
 								{
 									if(spec->buildingSettings[ir] & (1<<bs))
@@ -1662,7 +1662,7 @@ void CAmbarCendamo::deh3m()
 								{
 									if(spec->buildingSettings[ir] & (1<<bs))
 									{
-										nt->builtBuildings.insert(26); //graal
+										nt->builtBuildings.insert(26); //grail
 									}
 								}
 								else if(bs==2)
@@ -1683,7 +1683,7 @@ void CAmbarCendamo::deh3m()
 								{
 									if(spec->buildingSettings[ir] & (1<<bs))
 									{
-										nt->builtBuildings.insert(21); //stajnia
+										nt->builtBuildings.insert(21); //stables
 									}
 								}
 								else if(bs==5)