Jelajahi Sumber

* partially done spell window

mateuszb 17 tahun lalu
induk
melakukan
11cef89810
3 mengubah file dengan 165 tambahan dan 0 penghapusan
  1. 9 0
      CAdvmapInterface.cpp
  2. 113 0
      client/CSpellWindow.cpp
  3. 43 0
      client/CSpellWindow.h

+ 9 - 0
CAdvmapInterface.cpp

@@ -25,6 +25,7 @@
 #include "hch/CObjectHandler.h"
 #include <boost/thread.hpp>
 #include "map.h"
+#include "client/CSpellWindow.h"
 #pragma warning (disable : 4355) 
 extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
 
@@ -1001,6 +1002,14 @@ void CAdvMapInt::fmoveHero()
 }
 void CAdvMapInt::fshowSpellbok()
 {
+	if (selection->ID!=HEROI_TYPE) //checking necessary values
+		return;
+
+	LOCPLINT->curint->deactivate();
+
+	CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, 90, 2), ((const CGHeroInstance*)LOCPLINT->adventureInt->selection));
+	spellWindow->activate();
+	LOCPLINT->objsToBlit.push_back(spellWindow);
 }
 void CAdvMapInt::fadventureOPtions()
 {

+ 113 - 0
client/CSpellWindow.cpp

@@ -0,0 +1,113 @@
+#include "CSpellWindow.h"
+#include "client/Graphics.h"
+#include "hch/CDefHandler.h"
+#include "hch/CObjectHandler.h"
+#include "SDL_Extensions.h"
+#include <boost/bind.hpp>
+#include <sstream>
+
+extern SDL_Surface * screen;
+extern SDL_Color tytulowy, zwykly ;
+extern TTF_Font *GEOR16;
+
+ClickableArea::ClickableArea(SDL_Rect &myRect, boost::function<void()> func)
+{
+	pos = myRect;
+	myFunc = func;
+}
+
+void ClickableArea::clickLeft(boost::logic::tribool down)
+{
+	if(!down)
+	{
+		myFunc();
+	}
+}
+
+void ClickableArea::activate()
+{
+	ClickableL::activate();
+}
+void ClickableArea::deactivate()
+{
+	ClickableL::deactivate();
+}
+
+CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero): selectedTab(4)
+{
+	pos = myRect;
+	background = BitmapHandler::loadBitmap("SpelBack.bmp");
+	graphics->blueToPlayersAdv(background, myHero->tempOwner);
+
+	std::stringstream mana;
+	mana<<myHero->mana;
+	CSDL_Ext::printAtMiddle(mana.str(), 434, 425, GEOR16, tytulowy, background);
+
+	leftCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp");
+	rightCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp");
+	spells = CDefHandler::giveDef("Spells.def");
+	spellTab = CDefHandler::giveDef("SpelTab.def");
+	schools = CDefHandler::giveDef("Schools.def");
+	schoolW = CDefHandler::giveDef("SplevW.def");
+	schoolE = CDefHandler::giveDef("SplevE.def");
+	schoolF = CDefHandler::giveDef("SplevF.def");
+	schoolA = CDefHandler::giveDef("SplevA.def");
+
+	exitBtn = new ClickableArea(genRect(45, 35, 569, 407), boost::bind(&CSpellWindow::fexitb, this));
+	statusBar = new CStatusBar(97, 571, "Spelroll.bmp");
+}
+
+CSpellWindow::~CSpellWindow()
+{
+	SDL_FreeSurface(background);
+	SDL_FreeSurface(leftCorner);
+	SDL_FreeSurface(rightCorner);
+	delete spells;
+	delete spellTab;
+	delete schools;
+	delete schoolW;
+	delete schoolE;
+	delete schoolF;
+	delete schoolA;
+
+	delete exitBtn;
+	delete statusBar;
+}
+
+void CSpellWindow::fexitb()
+{
+	deactivate();
+
+	for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
+	{
+		if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
+		{
+			LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
+			break;
+		}
+	}
+
+	delete this;
+	LOCPLINT->curint->activate();
+}
+
+void CSpellWindow::show(SDL_Surface *to)
+{
+	if(to == NULL)  //evaluating to
+		to = screen;
+
+	SDL_BlitSurface(background, NULL, to, &pos);
+	blitAt(spellTab->ourImages[selectedTab].bitmap, 614, 96, to);
+	
+	statusBar->show();
+}
+
+void CSpellWindow::activate()
+{
+	exitBtn->activate();
+}
+
+void CSpellWindow::deactivate()
+{
+	exitBtn->deactivate();
+}

+ 43 - 0
client/CSpellWindow.h

@@ -0,0 +1,43 @@
+#pragma once
+#include "global.h"
+#include "CPlayerInterface.h"
+
+struct SDL_Surface;
+class CDefHandler;
+struct SDL_Rect;
+class CGHeroInstance;
+
+class ClickableArea : public ClickableL
+{
+private:
+	boost::function<void()> myFunc;
+public:
+	void clickLeft(boost::logic::tribool down);
+	void activate();
+	void deactivate();
+
+	ClickableArea(SDL_Rect & myRect, boost::function<void()> func);//c-tor
+};
+
+class CSpellWindow : public IShowActivable, public CIntObject
+{
+private:
+	SDL_Surface * background, * leftCorner, * rightCorner;
+	CDefHandler * spells, //pictures of spells
+		* spellTab, //school select
+		* schools, //schools' pictures
+		* schoolW, * schoolE, * schoolF, * schoolA; //schools' 'borders'
+
+	ClickableArea * exitBtn;
+	CStatusBar * statusBar;
+public:
+	Uint8 selectedTab;
+	CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero); //c-tor
+	~CSpellWindow(); //d-tor
+
+	void fexitb();
+
+	void activate();
+	void deactivate();
+	void show(SDL_Surface * to = NULL);
+};