Ver Fonte

* started making creature info window
* callback for buttons/lists based on boost::function
* new file AdventureMapButton.cpp - update your project files

Michał W. Urbańczyk há 17 anos atrás
pai
commit
00929126d5

+ 262 - 0
AdventureMapButton.cpp

@@ -0,0 +1,262 @@
+#include "CAdvmapInterface.h"
+#include "SDL_Extensions.h"
+#include "hch\CDefHandler.h"
+#include "CGameInfo.h"
+#include "hch\CLodHandler.h"
+#include "hch\CPreGameTextHandler.h"
+#include "hch/CTownHandler.h"
+#include "CLua.h"
+#include "CCallback.h"
+AdventureMapButton::AdventureMapButton ()
+{
+	type=2;
+	abs=true;
+	active=false;
+	ourObj=NULL;
+	state=0;
+	actOnDown = false;
+}
+
+AdventureMapButton::AdventureMapButton
+( std::string Name, std::string HelpBox, boost::function<void()> Callback, int x, int y, std::string defName, bool activ,  std::vector<std::string> * add, bool playerColoredButton )
+{
+	callback = Callback;
+	actOnDown = false;
+	type=2;
+	abs=true;
+	active=false;
+	ourObj=NULL;
+	state=0;
+	name=Name;
+	helpBox=HelpBox;
+	colorChange = playerColoredButton;
+	int est = LOCPLINT->playerID;
+	CDefHandler * temp = CGI->spriteh->giveDef(defName); 
+	temp->notFreeImgs = true;
+	for (int i=0;i<temp->ourImages.size();i++)
+	{
+		imgs.resize(1);
+		imgs[0].push_back(temp->ourImages[i].bitmap);
+		if(playerColoredButton)
+			CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
+	}
+	delete temp;
+	if (add)
+	{
+		imgs.resize(imgs.size()+add->size());
+		for (int i=0; i<add->size();i++)
+		{
+			temp = CGI->spriteh->giveDef((*add)[i]);
+			temp->notFreeImgs = true;
+			for (int j=0;j<temp->ourImages.size();j++)
+			{
+				imgs[i+1].push_back(temp->ourImages[j].bitmap);
+				if(playerColoredButton)
+					CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
+			}
+			delete temp;
+		}
+		delete add;
+	}
+	pos.x=x;
+	pos.y=y;
+	pos.w = imgs[curimg][0]->w;
+	pos.h = imgs[curimg][0]->h  -1;
+	if (activ)
+		activate();
+}
+
+
+void AdventureMapButton::clickLeft (tribool down)
+{
+	if (down)
+	{
+		state=1;
+	}
+	else 
+	{
+		state=0;
+	}
+	show();
+	if (actOnDown && down)
+	{
+		pressedL=state;
+		callback();
+	}
+	else if (pressedL && (down==false))
+	{
+		pressedL=state;
+		callback();
+	}
+	else
+	{
+		pressedL=state;
+	}
+}
+
+void AdventureMapButton::clickRight (tribool down)
+{
+	if(helpBox.size()) //there is no point to show window with nothing inside...
+		LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
+}
+
+void AdventureMapButton::hover (bool on)
+{
+	Hoverable::hover(on);
+	if(name.size()) //if there is no name, there is nohing to display also
+	{
+		if (on)
+			LOCPLINT->statusbar->print(name);
+		else if (LOCPLINT->statusbar->getCurrent()==name)
+			LOCPLINT->statusbar->clear();
+	}
+}
+
+void AdventureMapButton::activate()
+{
+	if (active) return;
+	active=true;
+	ClickableL::activate();
+	ClickableR::activate();
+	Hoverable::activate();
+	KeyInterested::activate();
+}
+
+void AdventureMapButton::keyPressed (SDL_KeyboardEvent & key)
+{
+	//TODO: check if it's shortcut
+}
+
+void AdventureMapButton::deactivate()
+{
+	if (!active) return;
+	active=false;
+	ClickableL::deactivate();
+	ClickableR::deactivate();
+	Hoverable::deactivate();
+	KeyInterested::deactivate();
+}
+
+
+void CSlider::sliderClicked()
+{
+	if(!moving)
+	{
+		MotionInterested::activate();
+		moving = true;
+	}
+}
+
+void CSlider::mouseMoved (SDL_MouseMotionEvent & sEvent)
+{
+	float v = sEvent.x - pos.x - 24;
+	v/= (pos.w - 48);
+	v*=amount;
+	if(v!=value)
+	{
+		moveTo(v);
+		redrawSlider();
+	}
+}
+
+void CSlider::redrawSlider()
+{
+	slider.show();
+}
+
+void CSlider::moveLeft()
+{
+	moveTo(value-1);
+}
+
+void CSlider::moveRight()
+{
+	moveTo(value+1);
+}
+
+void CSlider::moveTo(int to)
+{
+	if(to<0)
+		to=0;
+	else if(to>amount)
+		to=amount;
+	value = to;
+	float part = (float)to/amount;
+	part*=(pos.w-48);
+	slider.pos.x = part + pos.x + 16;
+	moved(to);
+}
+
+void CSlider::activate() // makes button active
+{
+	left.activate();
+	right.activate();
+	slider.activate();
+	ClickableL::activate();
+}
+
+void CSlider::deactivate() // makes button inactive (but doesn't delete)
+{
+	left.deactivate();
+	right.deactivate();
+	slider.deactivate();
+	ClickableL::deactivate();
+}
+
+void CSlider::clickLeft (tribool down)
+{
+	if(down)
+	{
+		float pw = LOCPLINT->current->motion.x-pos.x-16;
+		float rw = pw / ((float)(pos.w-32));
+		if (rw>1) return;
+		if (rw<0) return;
+		moveTo(rw*amount);
+		return;
+	}
+	if(moving)
+	{
+		MotionInterested::deactivate();
+		moving = false;
+	}
+}
+
+void CSlider::show(SDL_Surface * to)
+{
+	left.show();
+	right.show();
+	slider.show();
+}
+
+CSlider::~CSlider()
+{
+	delete imgs;
+}
+
+CSlider::CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount, int Value, bool Horizontal)
+:capacity(Capacity),amount(Amount),value(Value),horizontal(Horizontal), moved(Moved)
+{
+	moving = false;
+	strongInterest = true;
+	imgs = CGI->spriteh->giveDefEss("IGPCRDIV.DEF");
+
+	left.pos.y = slider.pos.y = right.pos.y = pos.y = y;
+	left.pos.x = pos.x = x;
+	right.pos.x = x + totalw - 16;
+
+	//left.owner = right.owner = slider.owner = this;
+	//left.function = &CSlider::moveLeft;
+	//right.function = &CSlider::moveRight;
+	//slider.function = &CSlider::sliderClicked;
+	left.callback = boost::bind(&CSlider::moveLeft,this);
+	left.pos.w = left.pos.h = right.pos.w = right.pos.h = slider.pos.w = slider.pos.h = pos.h = 16;
+	pos.w = totalw;
+	left.imgs.resize(1); right.imgs.resize(1); slider.imgs.resize(1);
+	left.imgs[0].push_back(imgs->ourImages[0].bitmap); left.imgs[0].push_back(imgs->ourImages[1].bitmap);
+	right.imgs[0].push_back(imgs->ourImages[2].bitmap); right.imgs[0].push_back(imgs->ourImages[3].bitmap);
+	slider.imgs[0].push_back(imgs->ourImages[4].bitmap);
+	left.notFreeButton = right.notFreeButton = slider.notFreeButton = true;
+	slider.actOnDown = true;
+
+	moveTo(value);
+}

+ 10 - 484
AdventureMapButton.h

@@ -1,13 +1,7 @@
 #pragma once
-#include "SDL_Extensions.h"
-#include "hch\CDefHandler.h"
-#include "CGameInfo.h"
-#include "hch\CLodHandler.h"
-#include "hch\CPreGameTextHandler.h"
-#include "hch/CTownHandler.h"
-#include "CLua.h"
 #include "CPlayerInterface.h"
-template <typename T=CAdvMapInt>
+#include <boost/function.hpp>
+#include <boost/bind.hpp>
 class AdventureMapButton 
 	: public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public CButtonBase
 {
@@ -15,8 +9,7 @@ public:
 	std::string name; //for status bar 
 	std::string helpBox; //for right-click help
 	char key; //key shortcut
-	T* owner;
-	void (T::*function)(); //function in CAdvMapInt called when this button is pressed, different for each button
+	boost::function<void()> callback;
 	bool colorChange,
 		actOnDown; //runs when mouse is pressed down over it, not when up
 
@@ -28,368 +21,24 @@ public:
 	void deactivate(); // makes button inactive (but doesn't delete)
 
 	AdventureMapButton(); //c-tor
-	AdventureMapButton( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ=false,  std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
+	AdventureMapButton( std::string Name, std::string HelpBox, boost::function<void()> Callback, int x, int y, std::string defName, bool activ=false,  std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
 };
 
-template <typename T>
-AdventureMapButton<T>::AdventureMapButton ()
-{
-	type=2;
-	abs=true;
-	active=false;
-	ourObj=NULL;
-	state=0;
-	actOnDown = false;
-}
-template <typename T>
-AdventureMapButton<T>::AdventureMapButton
-( std::string Name, std::string HelpBox, void(T::*Function)(), int x, int y, std::string defName, T* Owner, bool activ, std::vector<std::string> * add, bool playerColoredButton )
-{
-	actOnDown = false;
-	owner = Owner;
-	type=2;
-	abs=true;
-	active=false;
-	ourObj=NULL;
-	state=0;
-	name=Name;
-	helpBox=HelpBox;
-	colorChange = playerColoredButton;
-	int est = LOCPLINT->playerID;
-	CDefHandler * temp = CGI->spriteh->giveDef(defName); 
-	temp->notFreeImgs = true;
-	for (int i=0;i<temp->ourImages.size();i++)
-	{
-		imgs.resize(1);
-		imgs[0].push_back(temp->ourImages[i].bitmap);
-		if(playerColoredButton)
-			CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
-	}
-	delete temp;
-	if (add)
-	{
-		imgs.resize(imgs.size()+add->size());
-		for (int i=0; i<add->size();i++)
-		{
-			temp = CGI->spriteh->giveDef((*add)[i]);
-			temp->notFreeImgs = true;
-			for (int j=0;j<temp->ourImages.size();j++)
-			{
-				imgs[i+1].push_back(temp->ourImages[j].bitmap);
-				if(playerColoredButton)
-					CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
-			}
-			delete temp;
-		}
-		delete add;
-	}
-	function = Function;
-	pos.x=x;
-	pos.y=y;
-	pos.w = imgs[curimg][0]->w;
-	pos.h = imgs[curimg][0]->h  -1;
-	if (activ)
-		activate();
-}
-
-template <typename T>
-void AdventureMapButton<T>::clickLeft (tribool down)
-{
-	if (down)
-	{
-		state=1;
-	}
-	else 
-	{
-		state=0;
-	}
-	show();
-	if (actOnDown && down)
-	{
-		pressedL=state;
-		(owner->*function)();
-	}
-	else if (pressedL && (down==false))
-	{
-		pressedL=state;
-		(owner->*function)();
-	}
-	else
-	{
-		pressedL=state;
-	}
-}
-template <typename T>
-void AdventureMapButton<T>::clickRight (tribool down)
-{
-	if(helpBox.size()) //there is no point to show window with nothing inside...
-		LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
-}
-template <typename T>
-void AdventureMapButton<T>::hover (bool on)
-{
-	Hoverable::hover(on);
-	if(name.size()) //if there is no name, there is nohing to display also
-	{
-		if (on)
-			LOCPLINT->statusbar->print(name);
-		else if (LOCPLINT->statusbar->getCurrent()==name)
-			LOCPLINT->statusbar->clear();
-	}
-}
-template <typename T>
-void AdventureMapButton<T>::activate()
-{
-	if (active) return;
-	active=true;
-	ClickableL::activate();
-	ClickableR::activate();
-	Hoverable::activate();
-	KeyInterested::activate();
-}
-template <typename T>
-void AdventureMapButton<T>::keyPressed (SDL_KeyboardEvent & key)
-{
-	//TODO: check if it's shortcut
-}
-template <typename T>
-void AdventureMapButton<T>::deactivate()
-{
-	if (!active) return;
-	active=false;
-	ClickableL::deactivate();
-	ClickableR::deactivate();
-	Hoverable::deactivate();
-	KeyInterested::deactivate();
-}
-template <typename T>
-CTownList<T>::~CTownList()
-{
-	delete arrup;
-	delete arrdo;
-}
-template <typename T>
-CTownList<T>::CTownList(int Size, SDL_Rect * Pos, int arupx, int arupy, int ardox, int ardoy)
-:CList(Size)
-{
-	pos = *Pos;
-	arrup = CGI->spriteh->giveDef("IAM014.DEF");
-	arrdo = CGI->spriteh->giveDef("IAM015.DEF");
-
-	arrupp.x=arupx;
-	arrupp.y=arupy;
-	arrupp.w=arrup->ourImages[0].bitmap->w;
-	arrupp.h=arrup->ourImages[0].bitmap->h;
-	arrdop.x=ardox;
-	arrdop.y=ardoy;
-	arrdop.w=arrdo->ourImages[0].bitmap->w;
-	arrdop.h=arrdo->ourImages[0].bitmap->h;
-	posporx = arrdop.x;
-	pospory = arrupp.y + arrupp.h;
-
-	pressed = indeterminate;
-
-	from = 0;
-	
-}
-template<typename T>
-void CTownList<T>::genList()
-{
-	int howMany = LOCPLINT->cb->howManyTowns();
-	for (int i=0;i<howMany;i++)
-	{
-		items.push_back(LOCPLINT->cb->getTownInfo(i,0));
-	}
-}
-template<typename T>
-void CTownList<T>::select(int which)
-{
-	if (which>=items.size()) 
-		return;
-	selected = which;
-	if(owner)
-		(owner->*fun)();
-}
-template<typename T>
-void CTownList<T>::mouseMoved (SDL_MouseMotionEvent & sEvent)
-{
-	if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
-	{
-		if (from>0)
-			LOCPLINT->statusbar->print(CGI->preth->zelp[306].first);
-		else
-			LOCPLINT->statusbar->clear();
-		return;
-	}
-	else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
-	{
-		if ((items.size()-from)  >  SIZE)
-			LOCPLINT->statusbar->print(CGI->preth->zelp[307].first);
-		else
-			LOCPLINT->statusbar->clear();
-		return;
-	}
-	//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;
-	int ny = hy/32;
-	if ((ny>SIZE || ny<0) || (from+ny>=items.size()))
-	{
-		LOCPLINT->statusbar->clear();
-		return;
-	};
-	LOCPLINT->statusbar->print(items[from+ny]->state->hoverText(const_cast<CGTownInstance*>(items[from+ny])));
-}
-template<typename T>
-void CTownList<T>::clickLeft(tribool down)
-{
-	if (down)
-	{
-		/***************************ARROWS*****************************************/
-		if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
-		{
-			blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
-			pressed = true;
-			return;
-		}
-		else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>SIZE))
-		{
-			blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
-			pressed = false;
-			return;
-		}
-		/***************************TOWNS*****************************************/
-		int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
-		hx-=pos.x;
-		hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
-		int ny = hy/32;
-		if (ny>SIZE || ny<0)
-			return;
-		if (SIZE==5 && (ny+from)==selected && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
-			LOCPLINT->openTownWindow(items[selected]);//print town screen
-		else
-			select(ny+from);
-	}
-	else
-	{
-		if (indeterminate(pressed))
-			return;
-		if (pressed) //up
-		{
-			blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
-			pressed = indeterminate;
-			if (!down)
-			{
-				from--;
-				if (from<0)
-					from=0;
-				draw();
-			}
-		}
-		else if (!pressed) //down
-		{
-			blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
-			pressed = indeterminate;
-			if (!down)
-			{
-				from++;
-				//if (from<items.size()-5)
-				//	from=items.size()-5;
-				draw();
-			}
-		}
-		else
-			throw 0;
-
-	}
-}
-template<typename T>
-void CTownList<T>::clickRight(tribool down)
-{	
-	if (down)
-	{
-		/***************************ARROWS*****************************************/
-		if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
-		{
-			LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[306].second,down,this);
-		}
-		else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
-		{
-			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;
-		int ny = hy/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
-	{
-			LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[306].second,down,this);
-			LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[307].second,down,this);
-	}
-}
-template<typename T>
-void CTownList<T>::hover (bool on)
-{
-}
-template<typename T>
-void CTownList<T>::keyPressed (SDL_KeyboardEvent & key)
-{
-}
-template<typename T>
-void CTownList<T>::draw()
-{	
-	for (int iT=0+from;iT<SIZE+from;iT++)
-	{
-		int i = iT-from;
-		if (iT>=items.size())
-		{
-			blitAt(CGI->townh->getPic(-1),posporx,pospory+i*32);
-			continue;
-		}
-
-		blitAt(CGI->townh->getPic(items[iT]->subID,items[iT]->hasFort(),items[iT]->builded),posporx,pospory+i*32);
-
-		if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
-		{
-			blitAt(CGI->townh->getPic(-2),posporx,pospory+i*32);
-		}
-	}
-	if (from>0)
-		blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
-	else
-		blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
 
-	if (items.size()-from>SIZE)
-		blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
-	else
-		blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
-}
-
-
-template<typename T>
+//template<typename T>
 class CSlider : public IShowable, public MotionInterested, public ClickableL
 {
 public:
-	AdventureMapButton<CSlider> left, right, slider; //if vertical then left=up
+	AdventureMapButton left, right, slider; //if vertical then left=up
 	int capacity,//how many elements can be active at same time
 		amount, //how many elements
 		value; //first active element
 	bool horizontal, moving;
 	CDefEssential *imgs ;
 
-	T* owner;
-	void(T::*moved)(int to);
+	boost::function<void(int)> moved;
+	//void(T::*moved)(int to);
+	//T* owner;
 
 	void redrawSlider(); 
 
@@ -402,130 +51,7 @@ public:
 	void activate(); // makes button active
 	void deactivate(); // makes button inactive (but doesn't delete)
 	void show(SDL_Surface * to = NULL);
-	CSlider(int x, int y, int totalw, T*Owner,void(T::*Moved)(int to), int Capacity, int Amount, 
+	CSlider(int x, int y, int totalw, boost::function<void(int)> Moved, int Capacity, int Amount, 
 		int Value=0, bool Horizontal=true);
 	~CSlider();
 };	
-
-template<typename T>
-void CSlider<T>::sliderClicked()
-{
-	if(!moving)
-	{
-		MotionInterested::activate();
-		moving = true;
-	}
-}
-template<typename T>
-void CSlider<T>::mouseMoved (SDL_MouseMotionEvent & sEvent)
-{
-	float v = sEvent.x - pos.x - 24;
-	v/= (pos.w - 48);
-	v*=amount;
-	if(v!=value)
-	{
-		moveTo(v);
-		redrawSlider();
-	}
-}
-template<typename T>
-void CSlider<T>::redrawSlider()
-{
-	slider.show();
-}
-template<typename T>
-void CSlider<T>::moveLeft()
-{
-	moveTo(value-1);
-}
-template<typename T>
-void CSlider<T>::moveRight()
-{
-	moveTo(value+1);
-}
-template<typename T>
-void CSlider<T>::moveTo(int to)
-{
-	if(to<0)
-		to=0;
-	else if(to>amount)
-		to=amount;
-	value = to;
-	float part = (float)to/amount;
-	part*=(pos.w-48);
-	slider.pos.x = part + pos.x + 16;
-	(owner->*moved)(to);
-}
-template<typename T>
-void CSlider<T>::activate() // makes button active
-{
-	left.activate();
-	right.activate();
-	slider.activate();
-	ClickableL::activate();
-}
-template<typename T>
-void CSlider<T>::deactivate() // makes button inactive (but doesn't delete)
-{
-	left.deactivate();
-	right.deactivate();
-	slider.deactivate();
-	ClickableL::deactivate();
-}
-template<typename T>
-void CSlider<T>::clickLeft (tribool down)
-{
-	if(down)
-	{
-		float pw = LOCPLINT->current->motion.x-pos.x-16;
-		float rw = pw / ((float)(pos.w-32));
-		if (rw>1) return;
-		if (rw<0) return;
-		moveTo(rw*amount);
-		return;
-	}
-	if(moving)
-	{
-		MotionInterested::deactivate();
-		moving = false;
-	}
-}
-template<typename T>
-void CSlider<T>::show(SDL_Surface * to)
-{
-	left.show();
-	right.show();
-	slider.show();
-}
-template<typename T>
-CSlider<T>::CSlider(int x, int y, int totalw, T*Owner,void(T::*Moved)(int to), int Capacity, int Amount, int Value, bool Horizontal)
-:capacity(Capacity),amount(Amount),value(Value),horizontal(Horizontal), moved(Moved), owner(Owner)
-{
-	moving = false;
-	strongInterest = true;
-	imgs = CGI->spriteh->giveDefEss("IGPCRDIV.DEF");
-
-	left.pos.y = slider.pos.y = right.pos.y = pos.y = y;
-	left.pos.x = pos.x = x;
-	right.pos.x = x + totalw - 16;
-
-	left.owner = right.owner = slider.owner = this;
-	left.function = &CSlider::moveLeft;
-	right.function = &CSlider::moveRight;
-	slider.function = &CSlider::sliderClicked;
-	left.pos.w = left.pos.h = right.pos.w = right.pos.h = slider.pos.w = slider.pos.h = pos.h = 16;
-	pos.w = totalw;
-	left.imgs.resize(1); right.imgs.resize(1); slider.imgs.resize(1);
-	left.imgs[0].push_back(imgs->ourImages[0].bitmap); left.imgs[0].push_back(imgs->ourImages[1].bitmap);
-	right.imgs[0].push_back(imgs->ourImages[2].bitmap); right.imgs[0].push_back(imgs->ourImages[3].bitmap);
-	slider.imgs[0].push_back(imgs->ourImages[4].bitmap);
-	left.notFreeButton = right.notFreeButton = slider.notFreeButton = true;
-	slider.actOnDown = true;
-
-	moveTo(value);
-}
-template<typename T>
-CSlider<T>::~CSlider()
-{
-	delete imgs;
-}

+ 11 - 12
CAdvmapInterface.cpp

@@ -807,39 +807,38 @@ CAdvMapInt::CAdvMapInt(int Player)
 :player(Player),
 statusbar(7,556),
 kingOverview(CGI->preth->zelp[293].first,CGI->preth->zelp[293].second,
-			 &CAdvMapInt::fshowOverview, 679, 196, "IAM002.DEF", this,false,NULL,true),
+			 boost::bind(&CAdvMapInt::fshowOverview,this), 679, 196, "IAM002.DEF", false,NULL,true),
 
 underground(CGI->preth->zelp[294].first,CGI->preth->zelp[294].second,
-		   &CAdvMapInt::fswitchLevel, 711, 196, "IAM010.DEF", this, false, new std::vector<std::string>(1,std::string("IAM003.DEF")),true),
+			boost::bind(&CAdvMapInt::fswitchLevel,this), 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF")),true),
 
 questlog(CGI->preth->zelp[295].first,CGI->preth->zelp[295].second,
-		 &CAdvMapInt::fshowQuestlog, 679, 228, "IAM004.DEF", this,false,NULL,true),
+		 boost::bind(&CAdvMapInt::fshowQuestlog,this), 679, 228, "IAM004.DEF", false,NULL,true),
 
 sleepWake(CGI->preth->zelp[296].first,CGI->preth->zelp[296].second,
-		  &CAdvMapInt::fsleepWake, 711, 228, "IAM005.DEF", this,false,NULL,true),
+		  boost::bind(&CAdvMapInt::fsleepWake,this), 711, 228, "IAM005.DEF", false,NULL,true),
 
 moveHero(CGI->preth->zelp[297].first,CGI->preth->zelp[297].second,
-		  &CAdvMapInt::fmoveHero, 679, 260, "IAM006.DEF", this,false,NULL,true),
+		  boost::bind(&CAdvMapInt::fmoveHero,this), 679, 260, "IAM006.DEF", false,NULL,true),
 
 spellbook(CGI->preth->zelp[298].first,CGI->preth->zelp[298].second,
-		  &CAdvMapInt::fshowSpellbok, 711, 260, "IAM007.DEF", this,false,NULL,true),
+		  boost::bind(&CAdvMapInt::fshowSpellbok,this), 711, 260, "IAM007.DEF", false,NULL,true),
 
 advOptions(CGI->preth->zelp[299].first,CGI->preth->zelp[299].second,
-		  &CAdvMapInt::fadventureOPtions, 679, 292, "IAM008.DEF", this,false,NULL,true),
+		  boost::bind(&CAdvMapInt::fadventureOPtions,this), 679, 292, "IAM008.DEF", false,NULL,true),
 
 sysOptions(CGI->preth->zelp[300].first,CGI->preth->zelp[300].second,
-		  &CAdvMapInt::fsystemOptions, 711, 292, "IAM009.DEF", this,false,NULL,true),
+		  boost::bind(&CAdvMapInt::fsystemOptions,this), 711, 292, "IAM009.DEF", false,NULL,true),
 
 nextHero(CGI->preth->zelp[301].first,CGI->preth->zelp[301].second,
-		  &CAdvMapInt::fnextHero, 679, 324, "IAM000.DEF", this,false,NULL,true),
+		  boost::bind(&CAdvMapInt::fnextHero,this), 679, 324, "IAM000.DEF", false,NULL,true),
 
 endTurn(CGI->preth->zelp[302].first,CGI->preth->zelp[302].second,
-		  &CAdvMapInt::fendTurn, 679, 356, "IAM001.DEF", this,false,NULL,true),
+		  boost::bind(&CAdvMapInt::fendTurn,this), 679, 356, "IAM001.DEF", false,NULL,true),
 
 townList(5,&genRect(192,48,747,196),747,196,747,372)
 {
-	townList.owner = this;
-	townList.fun = &CAdvMapInt::selectionChanged;
+	townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
 	LOCPLINT->adventureInt=this;
 	bg = CGI->bitmaph->loadBitmap("ADVMAP.bmp");
 	blueToPlayersAdv(bg,player);

+ 2 - 2
CAdvmapInterface.h

@@ -121,7 +121,7 @@ public:
 
 
 	SDL_Surface * bg;
-	AdventureMapButton<> kingOverview,//- kingdom overview
+	AdventureMapButton kingOverview,//- kingdom overview
 		underground,//- underground switch
 		questlog,//- questlog
 		sleepWake, //- sleep/wake hero
@@ -139,7 +139,7 @@ public:
 	CResDataBar resdatabar;
 	
 	CHeroList heroList;
-	CTownList<CAdvMapInt> townList;	
+	CTownList townList;	
 	CInfoBar infoBar;
 
 	CHeroWindow * heroWindow;

+ 9 - 9
CBattleInterface.cpp

@@ -60,15 +60,15 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
 	CSDL_Ext::update();
 	
 	//preparing buttons and console
-	bOptions = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bOptionsf, 3, 561, "icm003.def", this, false, NULL, false);
-	bSurrender = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bSurrenderf, 54, 561, "icm001.def", this, false, NULL, false);
-	bFlee = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bFleef, 105, 561, "icm002.def", this, false, NULL, false);
-	bAutofight  = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bAutofightf, 157, 561, "icm004.def", this, false, NULL, false);
-	bSpell = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bSpellf, 645, 561, "icm005.def", this, false, NULL, false);
-	bWait = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bWaitf, 696, 561, "icm006.def", this, false, NULL, false);
-	bDefence = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bDefencef, 747, 561, "icm007.def", this, false, NULL, false);
-	bConsoleUp = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bConsoleUpf, 624, 561, "ComSlide.def", this, false, NULL, false);
-	bConsoleDown = new AdventureMapButton<CBattleInterface> (std::string(), std::string(), &CBattleInterface::bConsoleDownf, 624, 580, "ComSlide.def", this, false, NULL, false);
+	bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3, 561, "icm003.def", false, NULL, false);
+	bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54, 561, "icm001.def", false, NULL, false);
+	bFlee = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bFleef,this), 105, 561, "icm002.def", false, NULL, false);
+	bAutofight  = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bAutofightf,this), 157, 561, "icm004.def", false, NULL, false);
+	bSpell = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSpellf,this), 645, 561, "icm005.def", false, NULL, false);
+	bWait = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bWaitf,this), 696, 561, "icm006.def", false, NULL, false);
+	bDefence = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bDefencef,this), 747, 561, "icm007.def", false, NULL, false);
+	bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624, 561, "ComSlide.def", false, NULL, false);
+	bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624, 580, "ComSlide.def", false, NULL, false);
 	bConsoleDown->bitmapOffset = 2;
 	console = new CBattleConsole();
 	console->pos.x = 211;

+ 2 - 2
CBattleInterface.h

@@ -7,7 +7,7 @@ class CGHeroInstance;
 class CDefHandler;
 class CStack;
 class CCallback;
-template <typename T> class AdventureMapButton;
+class AdventureMapButton;
 
 class CBattleHero : public IShowable, public CIntObject
 {
@@ -68,7 +68,7 @@ class CBattleInterface : public IActivable, public IShowable
 {
 private:
 	SDL_Surface * background, * menu, * amountBasic, * amountNormal;
-	AdventureMapButton<CBattleInterface> * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
+	AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
 		* bWait, * bDefence, * bConsoleUp, * bConsoleDown;
 	CBattleConsole * console;
 	CBattleHero * attackingHero, * defendingHero;

+ 12 - 13
CCastleInterface.cpp

@@ -211,15 +211,14 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
 	//garrison
 	garr = new CGarrisonInt(305,387,4,32,townInt,243,13,town,town->visitingHero);
 
-	townlist = new CTownList<CCastleInterface>(3,&genRect(128,48,744,414),744,414,744,526);
-	exit = new AdventureMapButton<CCastleInterface>
-		(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,false,NULL,false);
-	split = new AdventureMapButton<CGarrisonInt>
-		(CGI->townh->tcommands[3],"",&CGarrisonInt::splitClick,744,382,"TSBTNS.DEF",garr,false,NULL,false);
+	townlist = new CTownList(3,&genRect(128,48,744,414),744,414,744,526);
+	exit = new AdventureMapButton
+		(CGI->townh->tcommands[8],"",boost::bind(&CCastleInterface::close,this),744,544,"TSBTNS.DEF",false,NULL,false);
+	split = new AdventureMapButton
+		(CGI->townh->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),744,382,"TSBTNS.DEF",false,NULL,false);
 	statusbar = new CStatusBar(8,555,"TSTATBAR.bmp",732);
 
-	townlist->owner = this;
-	townlist->fun = &CCastleInterface::townChange;
+	townlist->fun = boost::bind(&CCastleInterface::townChange,this);
 	townlist->genList();
 	townlist->selected = getIndexOf(townlist->items,Town);
 	if((townlist->selected+1) > townlist->SIZE)
@@ -716,8 +715,8 @@ CHallInterface::CHallInterface(CCastleInterface * owner)
 	CSDL_Ext::blueToPlayersAdv(bg,LOCPLINT->playerID);
 	bars = CGI->spriteh->giveDefEss("TPTHBAR.DEF");
 	status = CGI->spriteh->giveDefEss("TPTHCHK.DEF");
-	exit = new AdventureMapButton<CHallInterface>
-		(CGI->townh->tcommands[8],"",&CHallInterface::close,748,556,"TPMAGE1.DEF",this,false,NULL,false);
+	exit = new AdventureMapButton
+		(CGI->townh->tcommands[8],"",boost::bind(&CHallInterface::close,this),748,556,"TPMAGE1.DEF",false,NULL,false);
 
 	//preparing boxes with buildings//
 	boxes.resize(5);
@@ -989,10 +988,10 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod
 	}
 	if(!mode)
 	{
-		buy = new AdventureMapButton<CBuildWindow>
-			("","",&CBuildWindow::Buy,pos.x+45,pos.y+446,"IBUY30.DEF",this,false,NULL,false);
-		cancel = new AdventureMapButton<CBuildWindow>
-			("","",&CBuildWindow::close,pos.x+290,pos.y+445,"ICANCEL.DEF",this,false,NULL,false);
+		buy = new AdventureMapButton
+			("","",boost::bind(&CBuildWindow::Buy,this),pos.x+45,pos.y+446,"IBUY30.DEF",false,NULL,false);
+		cancel = new AdventureMapButton
+			("","",boost::bind(&CBuildWindow::close,this),pos.x+290,pos.y+445,"ICANCEL.DEF",false,NULL,false);
 		if(state!=7)
 			buy->state=2;
 	}

+ 6 - 6
CCastleInterface.h

@@ -7,7 +7,7 @@ class CGTownInstance;
 class CTownHandler;
 class CHallInterface;
 struct Structure;
-template <typename T> class AdventureMapButton;
+class AdventureMapButton;
 class CBuildingRect : public Hoverable, public MotionInterested, public ClickableL, public ClickableR//, public TimeInterested
 {
 public:
@@ -41,11 +41,11 @@ public:
 
 	CDefHandler *hall,*fort, *flag;
 	CDefEssential* bicons; //150x70 buildings imgs
-	CTownList<CCastleInterface> * townlist;
+	CTownList * townlist;
 
 	CGarrisonInt * garr;
-	AdventureMapButton<CCastleInterface> * exit;
-	AdventureMapButton<CGarrisonInt>*split;
+	AdventureMapButton *exit;
+	AdventureMapButton *split;
 
 	std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling
 
@@ -101,7 +101,7 @@ public:
 		int tid, bid, state; //town id, building id, state
 		bool mode; // 0 - normal (with buttons), 1 - r-click popup
 		SDL_Surface * bitmap; //main window bitmap, with blitted res/text, without buttons/subtitle in "statusbar"
-		AdventureMapButton<CBuildWindow> *buy, *cancel;
+		AdventureMapButton *buy, *cancel;
 
 		void activate();
 		void deactivate();
@@ -118,7 +118,7 @@ public:
 		*status; //0 - already, 1 - can't, 2 - lack of resources
 	std::vector< std::vector<CBuildingBox*> >boxes;
 
-	AdventureMapButton<CHallInterface> * exit;
+	AdventureMapButton *exit;
 
 	SDL_Surface * bg;
 

+ 11 - 1
CGameInterface.h

@@ -1,7 +1,7 @@
 #ifndef CGAMEINTERFACE_H
 #define CGAMEINTERFACE_H
 #include "global.h"
-//#include "CCallback.h"
+#include <set>
 #include <vector>
 BOOST_TRIBOOL_THIRD_STATE(outOfRange)
 
@@ -32,6 +32,16 @@ struct BattleAction
 	int destinationTile; 
 	int additionalInfo; // e.g. spell number if type is 1 || 10
 };
+
+struct StackState
+{
+	int attackBonus, defenseBonus, healthBonus, speedBonus;
+	int currentHealth;
+	int shotsLeft;
+	std::set<int> effects; 
+	int morale, luck;
+};
+
 class CGameInterface
 {
 public:

+ 10 - 10
CHeroWindow.cpp

@@ -34,17 +34,17 @@ CHeroWindow::CHeroWindow(int playerColor):
 	garInt = NULL;
 	ourBar = new CStatusBar(72, 567, "ADROLLVR.bmp", 660);
 
-	quitButton = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[17], std::string(), &CHeroWindow::quit, 674, 524, "hsbtns.def", this, false, NULL, false);
-	dismissButton = new AdventureMapButton<CHeroWindow>(std::string(), CGI->generaltexth->heroscrn[28], &CHeroWindow::dismissCurrent, 519, 437, "hsbtns2.def", this, false, NULL, false);
-	questlogButton = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[0], std::string(), &CHeroWindow::questlog, 379, 437, "hsbtns4.def", this, false, NULL, false);
+	quitButton = new AdventureMapButton(CGI->generaltexth->heroscrn[17], std::string(), boost::bind(&CHeroWindow::quit,this), 674, 524, "hsbtns.def", false, NULL, false);
+	dismissButton = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[28], boost::bind(&CHeroWindow::dismissCurrent,this), 519, 437, "hsbtns2.def", false, NULL, false);
+	questlogButton = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CHeroWindow::questlog,this), 379, 437, "hsbtns4.def", false, NULL, false);
 
-	gar1button = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[23], CGI->generaltexth->heroscrn[29], &CHeroWindow::gar1, 546, 491, "hsbtns6.def", this, false, NULL, false);
-	gar2button = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::gar2, 604, 491, "hsbtns8.def", this, false, NULL, false);
-	gar3button = new AdventureMapButton<CHeroWindow>(CGI->generaltexth->heroscrn[24], CGI->generaltexth->heroscrn[30], &CHeroWindow::gar3, 546, 527, "hsbtns7.def", this, false, NULL, false);
-	gar4button = new AdventureMapButton<CGarrisonInt>(std::string(), CGI->generaltexth->heroscrn[32], &CGarrisonInt::splitClick, 604, 527, "hsbtns9.def", garInt, false, NULL, false);
+	gar1button = new AdventureMapButton(CGI->generaltexth->heroscrn[23], CGI->generaltexth->heroscrn[29], boost::bind(&CHeroWindow::gar1,this), 546, 491, "hsbtns6.def", false, NULL, false);
+	gar2button = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::gar2,this), 604, 491, "hsbtns8.def", false, NULL, false);
+	gar3button = new AdventureMapButton(CGI->generaltexth->heroscrn[24], CGI->generaltexth->heroscrn[30], boost::bind(&CHeroWindow::gar3,this), 546, 527, "hsbtns7.def", false, NULL, false);
+	gar4button = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[32], boost::bind(&CGarrisonInt::splitClick,garInt), 604, 527, "hsbtns9.def", false, NULL, false);
 
-	leftArtRoll = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::leftArtRoller, 379, 364, "hsbtns3.def", this, false, NULL, false);
-	rightArtRoll = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::rightArtRoller, 632, 364, "hsbtns5.def", this, false, NULL, false);
+	leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::leftArtRoller,this), 379, 364, "hsbtns3.def", false, NULL, false);
+	rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::rightArtRoller,this), 632, 364, "hsbtns5.def", false, NULL, false);
 
 	for(int g=0; g<8; ++g)
 	{
@@ -202,7 +202,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero)
 	portraitArea->text = hero->biography;
 
 	delete garInt;
-	gar4button->owner = garInt = new CGarrisonInt(80, 493, 8, 0, curBack, 13, 482, curHero);
+	/*gar4button->owner = */garInt = new CGarrisonInt(80, 493, 8, 0, curBack, 13, 482, curHero);
 	garInt->update = false;
 	for(int g=0; g<primSkillAreas.size(); ++g)
 	{

+ 3 - 3
CHeroWindow.h

@@ -1,7 +1,7 @@
 #pragma once
 #include "CPlayerInterface.h"
 
-template <typename T> class AdventureMapButton;
+class AdventureMapButton;
 struct SDL_Surface;
 class CGHeroInstance;
 class CDefHandler;
@@ -91,10 +91,10 @@ class CHeroWindow: public IActivable, public IShowable, public virtual CIntObjec
 	CDefHandler * skillpics, *flags;
 
 	//buttons
-	AdventureMapButton<CHeroWindow> * quitButton, * dismissButton, * questlogButton, //general
+	AdventureMapButton * quitButton, * dismissButton, * questlogButton, //general
 		* gar1button, * gar2button, * gar3button, //garrison / formation handling
 		* leftArtRoll, * rightArtRoll;
-	AdventureMapButton<CGarrisonInt> * gar4button; //splitting
+	AdventureMapButton * gar4button; //splitting
 	//std::vector< AdventureMapButton<CHeroWindow> * > heroList; //list of heroes
 	std::vector<LClickableAreaHero *> heroListMi; //new better list of heroes
 

+ 319 - 11
CPlayerInterface.cpp

@@ -23,6 +23,7 @@
 #include <boost/algorithm/string/replace.hpp>
 #include "hch\CPreGameTextHandler.h"
 #include "CBattleInterface.h"
+#include "CLua.h"
 using namespace CSDL_Ext;
 
 extern TTF_Font * GEOR16;
@@ -103,6 +104,8 @@ void CGarrisonSlot::hover (bool on)
 }
 void CGarrisonSlot::clickRight (tribool down)
 {
+	//if(down && creature)
+		//(new CCreInfoWindow(creature->idNumber,0))->activate();
 }
 void CGarrisonSlot::clickLeft(tribool down)
 {
@@ -113,13 +116,15 @@ void CGarrisonSlot::clickLeft(tribool down)
 	}
 	if(down)
 	{
+		bool refr = false;
 		if(owner->highlighted)
 		{
-			if(owner->highlighted == this)
+			if(owner->highlighted == this) //view info
 			{
 				//TODO: view creature info
 				owner->highlighted = NULL;
 				show();
+				refr = true;
 			}
 			else if( !creature && owner->splitting)//split
 			{
@@ -129,6 +134,7 @@ void CGarrisonSlot::clickLeft(tribool down)
 				LOCPLINT->curint->deactivate();
 				CSplitWindow * spw = new CSplitWindow(owner->highlighted->creature->idNumber,owner->highlighted->count, owner);
 				spw->activate();
+				refr = true;
 			}
 			else if(creature != owner->highlighted->creature) //swap
 			{
@@ -137,7 +143,7 @@ void CGarrisonSlot::clickLeft(tribool down)
 					(!owner->highlighted->upg)?(owner->oup):(owner->odown),
 					ID,owner->highlighted->ID);
 			}
-			else
+			else //merge
 			{
 				LOCPLINT->cb->mergeStacks(
 					(!owner->highlighted->upg)?(owner->oup):(owner->odown),
@@ -145,12 +151,14 @@ void CGarrisonSlot::clickLeft(tribool down)
 					owner->highlighted->ID,ID);
 			}
 		}
-		else
+		else //highlight
 		{
 			if(creature)
 				owner->highlighted = this;
 			show();
+			refr = true;
 		}
+		if(refr) {hover(false);	hover(true); } //to refresh statusbar
 	}
 }
 void CGarrisonSlot::activate()
@@ -2401,6 +2409,223 @@ void CHeroList::draw()
 	else
 		blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
 }
+
+
+
+CTownList::~CTownList()
+{
+	delete arrup;
+	delete arrdo;
+}
+
+CTownList::CTownList(int Size, SDL_Rect * Pos, int arupx, int arupy, int ardox, int ardoy)
+:CList(Size)
+{
+	pos = *Pos;
+	arrup = CGI->spriteh->giveDef("IAM014.DEF");
+	arrdo = CGI->spriteh->giveDef("IAM015.DEF");
+
+	arrupp.x=arupx;
+	arrupp.y=arupy;
+	arrupp.w=arrup->ourImages[0].bitmap->w;
+	arrupp.h=arrup->ourImages[0].bitmap->h;
+	arrdop.x=ardox;
+	arrdop.y=ardoy;
+	arrdop.w=arrdo->ourImages[0].bitmap->w;
+	arrdop.h=arrdo->ourImages[0].bitmap->h;
+	posporx = arrdop.x;
+	pospory = arrupp.y + arrupp.h;
+
+	pressed = indeterminate;
+
+	from = 0;
+	
+}
+
+void CTownList::genList()
+{
+	int howMany = LOCPLINT->cb->howManyTowns();
+	for (int i=0;i<howMany;i++)
+	{
+		items.push_back(LOCPLINT->cb->getTownInfo(i,0));
+	}
+}
+
+void CTownList::select(int which)
+{
+	if (which>=items.size()) 
+		return;
+	selected = which;
+	if(!fun.empty())
+		fun();
+}
+
+void CTownList::mouseMoved (SDL_MouseMotionEvent & sEvent)
+{
+	if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
+	{
+		if (from>0)
+			LOCPLINT->statusbar->print(CGI->preth->zelp[306].first);
+		else
+			LOCPLINT->statusbar->clear();
+		return;
+	}
+	else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
+	{
+		if ((items.size()-from)  >  SIZE)
+			LOCPLINT->statusbar->print(CGI->preth->zelp[307].first);
+		else
+			LOCPLINT->statusbar->clear();
+		return;
+	}
+	//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;
+	int ny = hy/32;
+	if ((ny>SIZE || ny<0) || (from+ny>=items.size()))
+	{
+		LOCPLINT->statusbar->clear();
+		return;
+	};
+	LOCPLINT->statusbar->print(items[from+ny]->state->hoverText(const_cast<CGTownInstance*>(items[from+ny])));
+}
+
+void CTownList::clickLeft(tribool down)
+{
+	if (down)
+	{
+		/***************************ARROWS*****************************************/
+		if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
+		{
+			blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
+			pressed = true;
+			return;
+		}
+		else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>SIZE))
+		{
+			blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
+			pressed = false;
+			return;
+		}
+		/***************************TOWNS*****************************************/
+		int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
+		hx-=pos.x;
+		hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
+		int ny = hy/32;
+		if (ny>SIZE || ny<0)
+			return;
+		if (SIZE==5 && (ny+from)==selected && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
+			LOCPLINT->openTownWindow(items[selected]);//print town screen
+		else
+			select(ny+from);
+	}
+	else
+	{
+		if (indeterminate(pressed))
+			return;
+		if (pressed) //up
+		{
+			blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
+			pressed = indeterminate;
+			if (!down)
+			{
+				from--;
+				if (from<0)
+					from=0;
+				draw();
+			}
+		}
+		else if (!pressed) //down
+		{
+			blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
+			pressed = indeterminate;
+			if (!down)
+			{
+				from++;
+				//if (from<items.size()-5)
+				//	from=items.size()-5;
+				draw();
+			}
+		}
+		else
+			throw 0;
+
+	}
+}
+
+void CTownList::clickRight(tribool down)
+{	
+	if (down)
+	{
+		/***************************ARROWS*****************************************/
+		if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
+		{
+			LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[306].second,down,this);
+		}
+		else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
+		{
+			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;
+		int ny = hy/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
+	{
+			LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[306].second,down,this);
+			LOCPLINT->adventureInt->handleRightClick(CGI->preth->zelp[307].second,down,this);
+	}
+}
+
+void CTownList::hover (bool on)
+{
+}
+
+void CTownList::keyPressed (SDL_KeyboardEvent & key)
+{
+}
+
+void CTownList::draw()
+{	
+	for (int iT=0+from;iT<SIZE+from;iT++)
+	{
+		int i = iT-from;
+		if (iT>=items.size())
+		{
+			blitAt(CGI->townh->getPic(-1),posporx,pospory+i*32);
+			continue;
+		}
+
+		blitAt(CGI->townh->getPic(items[iT]->subID,items[iT]->hasFort(),items[iT]->builded),posporx,pospory+i*32);
+
+		if ((selected == iT) && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE))
+		{
+			blitAt(CGI->townh->getPic(-2),posporx,pospory+i*32);
+		}
+	}
+	if (from>0)
+		blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
+	else
+		blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
+
+	if (items.size()-from>SIZE)
+		blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
+	else
+		blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
+}
+
+
 void CRecrutationWindow::close()
 {
 	deactivate();
@@ -2503,7 +2728,7 @@ void CRecrutationWindow::show(SDL_Surface * to)
 	{
 		blitAt(CGI->creh->backgrounds[CGI->creh->creatures[creatures[i].ID].faction],curx-50,pos.y+130-65);
 		SDL_Rect dst = genRect(130,100,curx-50,pos.y+130-65);
-		creatures[i].anim->nextFrameMiddle(screen,curx+20,pos.y+110,true,!(c%2),&dst);
+		creatures[i].anim->nextFrameMiddle(screen,curx+20,pos.y+110,true,!(c%2),false,&dst);
 		curx += 120;
 	}
 	c++;
@@ -2533,7 +2758,7 @@ CRecrutationWindow::CRecrutationWindow(std::vector<std::pair<int,int> > &Creatur
 	pos.y = screen->h/2 - bitmap->h/2;
 	pos.w = bitmap->w;
 	pos.h = bitmap->h;
-	slider = new CSlider<CRecrutationWindow>(pos.x+176,pos.y+279,135,this,&CRecrutationWindow::sliderMoved,1,std::min(amounts[0],creatures[0].amount),0,true);
+	slider = new CSlider(pos.x+176,pos.y+279,135,boost::bind(&CRecrutationWindow::sliderMoved,this, _1),1,std::min(amounts[0],creatures[0].amount),0,true);
 	std::string pom;
 	printAtMiddle(CGI->generaltexth->allTexts[346],113,231,GEOR13,zwykly,bitmap); //cost per troop t
 	printAtMiddle(CGI->generaltexth->allTexts[465],205,231,GEOR13,zwykly,bitmap); //available t
@@ -2562,9 +2787,9 @@ CRecrutationWindow::CRecrutationWindow(std::vector<std::pair<int,int> > &Creatur
 		curx += 120;
 	}
 
-	max = new AdventureMapButton<CRecrutationWindow>("","",&CRecrutationWindow::Max,pos.x+134,pos.y+313,"IRCBTNS.DEF",this);
-	buy = new AdventureMapButton<CRecrutationWindow>("","",&CRecrutationWindow::Buy,pos.x+212,pos.y+313,"IBY6432.DEF",this);
-	cancel = new AdventureMapButton<CRecrutationWindow>("","",&CRecrutationWindow::Cancel,pos.x+290,pos.y+313,"ICN6432.DEF",this);
+	max = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Max,this),pos.x+134,pos.y+313,"IRCBTNS.DEF");
+	buy = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Buy,this),pos.x+212,pos.y+313,"IBY6432.DEF");
+	cancel = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Cancel,this),pos.x+290,pos.y+313,"ICN6432.DEF");
 	LOCPLINT->curint->deactivate();
 	//AdventureMapButton( std::string Name, std::string HelpBox, void(T::*Function)(), 
 	//int x, int y, std::string defName, T* Owner, bool activ=false,  std::vector<std::string> * add = NULL, bool playerColoredButton = true );//c-tor
@@ -2586,9 +2811,9 @@ CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner)
 	pos.y = screen->h/2 - bitmap->h/2;
 	pos.w = bitmap->w;
 	pos.h = bitmap->h;
-	ok = new AdventureMapButton<CSplitWindow>("","",&CSplitWindow::split,pos.x+20,pos.y+263,"IOK6432.DEF",this);
-	cancel = new AdventureMapButton<CSplitWindow>("","",&CSplitWindow::close,pos.x+214,pos.y+263,"ICN6432.DEF",this);
-	slider = new CSlider<CSplitWindow>(pos.x+21,pos.y+194,257,this,&CSplitWindow::sliderMoved,1,max,0,true);
+	ok = new AdventureMapButton("","",boost::bind(&CSplitWindow::split,this),pos.x+20,pos.y+263,"IOK6432.DEF");
+	cancel = new AdventureMapButton("","",boost::bind(&CSplitWindow::close,this),pos.x+214,pos.y+263,"ICN6432.DEF");
+	slider = new CSlider(pos.x+21,pos.y+194,257,boost::bind(&CSplitWindow::sliderMoved,this,_1),1,max,0,true);
 	a1 = max;
 	a2 = 0;
 	anim = new CCreatureAnimation(CGI->creh->creatures[cid].animDefName);
@@ -2661,3 +2886,86 @@ void CSplitWindow::keyPressed (SDL_KeyboardEvent & key)
 {
 	//TODO: zeby sie dalo recznie wpisywac
 }
+
+
+
+void CCreInfoWindow::show(SDL_Surface * to)
+{
+	char pom[15];
+	blitAt(bitmap,pos.x,pos.y,screen);
+	blitAt(CGI->creh->backgrounds[c->faction],pos.x+21,pos.y+48,screen);
+	anim->nextFrameMiddle(screen,pos.x+90,pos.y+95,true,false,false);
+}
+
+CCreInfoWindow::CCreInfoWindow(int Cid, int Type, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm)
+:ok(0),dismiss(0),upgrade(0),type(Type)
+{
+	c = &CGI->creh->creatures[Cid];
+	bitmap = CGI->bitmaph->loadBitmap("CRSTKPU.bmp");
+	pos.x = screen->w/2 - bitmap->w/2;
+	pos.y = screen->h/2 - bitmap->h/2;
+	pos.w = bitmap->w;
+	pos.h = bitmap->h;
+	SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
+	anim = new CCreatureAnimation(c->animDefName);
+	anim->setType(1);
+
+	printAtMiddle(c->namePl,149,30,GEOR13,zwykly,bitmap);
+
+	printAt(CGI->preth->zelp[435].first,155,48,GEOR13,zwykly,bitmap);
+	printAt(CGI->preth->zelp[436].first,155,67,GEOR13,zwykly,bitmap);
+	if(c->shots)
+		printAt(CGI->preth->zelp[437].first,155,86,GEOR13,zwykly,bitmap);
+	printAt(CGI->generaltexth->allTexts[199],155,105,GEOR13,zwykly,bitmap);
+	printAt(CGI->preth->zelp[439].first,155,124,GEOR13,zwykly,bitmap);
+	//printAt(CGI->preth->zelp[440].first,155,143,GEOR13,zwykly,bitmap);
+	printAt(CGI->preth->zelp[441].first,155,162,GEOR13,zwykly,bitmap);
+}
+CCreInfoWindow::~CCreInfoWindow()
+{
+	SDL_FreeSurface(bitmap);
+	delete anim;
+}
+void CCreInfoWindow::activate()
+{
+	ClickableR::activate();
+	LOCPLINT->objsToBlit.push_back(this);
+	if(ok)
+		ok->activate();
+	if(dismiss)
+		dismiss->activate();
+	if(upgrade)
+		upgrade->activate();
+}
+void CCreInfoWindow::close()
+{
+	deactivate();
+	delete this;
+
+	if(type)
+	{
+		LOCPLINT->curint->activate();
+		CCastleInterface *c = dynamic_cast<CCastleInterface*>(LOCPLINT->curint);
+		if(c) c->showAll();
+	}
+}
+void CCreInfoWindow::clickRight(boost::logic::tribool down)
+{
+	if(down)
+		return;
+	close();
+}
+void CCreInfoWindow::keyPressed (SDL_KeyboardEvent & key)
+{
+}
+void CCreInfoWindow::deactivate()
+{
+	ClickableR::deactivate(); 
+	LOCPLINT->objsToBlit.erase(std::find(LOCPLINT->objsToBlit.begin(),LOCPLINT->objsToBlit.end(),this));
+	if(ok)
+		ok->deactivate();
+	if(dismiss)
+		dismiss->deactivate();
+	if(upgrade)
+		upgrade->deactivate();
+}

+ 29 - 9
CPlayerInterface.h

@@ -4,9 +4,10 @@
 #include "CGameInterface.h"
 #include "SDL_framerate.h"
 #include <map>
+#include <boost/function.hpp>
 
 class CDefEssential;
-template <typename T> class AdventureMapButton;
+class AdventureMapButton;
 class CDefHandler;
 struct HeroMoveDetails;
 class CDefEssential;
@@ -22,7 +23,7 @@ class CCreatureAnimation;
 class CSelectableComponent;
 class CCreatureSet;
 class CGObjectInstance;
-template<typename T>class CSlider;
+class CSlider;
 
 class IShowable
 {
@@ -424,13 +425,12 @@ public:
 	void draw();
 	void init();
 };
-template<typename T>
+
 class CTownList 
 	: public CList
 {
 public: 
-	T* owner;
-	void(T::*fun)();
+	boost::function<void()> fun;
 	std::vector<const CGTownInstance*> items;
 	int posporx,pospory;
 
@@ -465,8 +465,8 @@ public:
 	std::vector<int> amounts; //how many creatures we can afford
 	std::vector<creinfo> creatures;
 	IRecruit *rec;
-	CSlider<CRecrutationWindow> *slider;
-	AdventureMapButton<CRecrutationWindow> *max, *buy, *cancel;
+	CSlider *slider;
+	AdventureMapButton *max, *buy, *cancel;
 	SDL_Surface *bitmap;
 	int which; //which creature is active
 
@@ -487,9 +487,9 @@ class CSplitWindow : public IShowable, public KeyInterested
 {
 public:
 	CGarrisonInt *gar;
-	CSlider<CSplitWindow> *slider;
+	CSlider *slider;
 	CCreatureAnimation *anim;
-	AdventureMapButton<CSplitWindow> *ok, *cancel;
+	AdventureMapButton *ok, *cancel;
 	SDL_Surface *bitmap;
 	int a1, a2, c;
 	bool which;
@@ -505,4 +505,24 @@ public:
 	void sliderMoved(int to);
 };
 
+class CCreInfoWindow : public IShowable, public KeyInterested, public ClickableR
+{
+public:
+	int type;//0 - rclick popup; 1 - normal window
+	SDL_Surface *bitmap;
+
+	CCreatureAnimation *anim;
+	CCreature *c;
+
+	AdventureMapButton *dismiss, *upgrade, *ok;
+	CCreInfoWindow(int Cid, int Type, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm);
+	~CCreInfoWindow();
+	void activate(); 
+	void close();
+	void clickRight(boost::logic::tribool down);
+	void keyPressed (SDL_KeyboardEvent & key);
+	void deactivate();
+	void show(SDL_Surface * to = NULL);
+};
+
 #endif //CPLAYERINTERFACE_H