瀏覽代碼

Wspólne zmiany (Common changes)
* fixed heroWindow
* started making garrisons

mateuszb 17 年之前
父節點
當前提交
8da051febf
共有 9 個文件被更改,包括 348 次插入48 次删除
  1. 20 0
      CCallback.cpp
  2. 2 0
      CCallback.h
  3. 17 11
      CCastleInterface.cpp
  4. 1 0
      CCastleInterface.h
  5. 3 0
      CConsoleHandler.cpp
  6. 14 35
      CHeroWindow.cpp
  7. 245 1
      CPlayerInterface.cpp
  8. 45 0
      CPlayerInterface.h
  9. 1 1
      SDL_Extensions.h

+ 20 - 0
CCallback.cpp

@@ -373,6 +373,26 @@ int CCallback::getHeroSerial(const CGHeroInstance * hero)
 	}
 	return -1;
 }
+
+int CCallback::swapCreatures(const CCreatureSet *s1, const CCreatureSet *s2, int p1, int p2)
+{
+	CCreatureSet *S1=const_cast<CCreatureSet *>(s1), *S2 = const_cast<CCreatureSet *>(s2);//todo - ugly
+	if (false)
+	{
+		//TODO: check if we are allowed to swap these creatures
+		return -1;
+	}
+	//if(S1->slots[p1].first)
+	{
+		//if(s2->slots[p2].first)
+		{
+			CCreature * pom = S2->slots[p2].first;
+			S2->slots[p2].first = S1->slots[p1].first;
+			S1->slots[p1].first = pom;
+		}
+	}
+	return -1;
+}
 int CCallback::getMySerial()
 {	
 	return gs->players[player].serial;

+ 2 - 0
CCallback.h

@@ -34,6 +34,7 @@ public:
 	virtual int getMyColor()=0;
 	virtual int getMySerial()=0;
 	virtual int getHeroSerial(const CGHeroInstance * hero)=0;
+	virtual int swapCreatures(const CCreatureSet *s1, const CCreatureSet *s2, int p1, int p2)=0;//swaps creatures between two posiibly different garrisons // TODO: AI-unsafe code - fix it!
 };
 
 struct HeroMoveDetails
@@ -78,6 +79,7 @@ public:
 	int getMyColor();
 	int getHeroSerial(const CGHeroInstance * hero);
 	int getMySerial();
+	int swapCreatures(const CCreatureSet *s1, const CCreatureSet *s2, int p1, int p2);
 
 //friends
 	friend int _tmain(int argc, _TCHAR* argv[]);

+ 17 - 11
CCastleInterface.cpp

@@ -155,7 +155,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
 	flag =  CGI->spriteh->giveDef("CREST58.DEF");
 	CSDL_Ext::blueToPlayersAdv(townInt,LOCPLINT->playerID);
 	exit = new AdventureMapButton<CCastleInterface>
-		(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,Activate);
+		(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,false);
 	exit->bitmapOffset = 4;
 
 	for (std::set<int>::const_iterator i=town->builtBuildings.begin();i!=town->builtBuildings.end();i++)
@@ -173,6 +173,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
 	}
 
 	std::sort(buildings.begin(),buildings.end(),srthlp);
+	garr = new CGarrisonInt(305,387,4,32,townInt,241,13,&town->garrison,(town->garrisonHero)?(&town->garrisonHero->army):(NULL));
 
 	if(Activate)
 	{
@@ -281,23 +282,25 @@ void CCastleInterface::showAll(SDL_Surface * to)
 
 	//flag
 	blitAt(flag->ourImages[town->getOwner()].bitmap,241,387,to);
+
 	//print garrison
-	for(
-		std::map<int,std::pair<CCreature*,int> >::const_iterator i=town->garrison.slots.begin();
-		i!=town->garrison.slots.end();
-		i++
-			)
-	{
-		blitAt(CGI->creh->bigImgs[i->second.first->idNumber],305+(62*(i->first)),387,to);
-		itoa(i->second.second,temp,10);
-		CSDL_Ext::printTo(temp,305+(62*(i->first))+57,387+61,GEOR13,zwykly,to);
-	}
+	//for(
+	//	std::map<int,std::pair<CCreature*,int> >::const_iterator i=town->garrison.slots.begin();
+	//	i!=town->garrison.slots.end();
+	//	i++
+	//		)
+	//{
+	//	blitAt(CGI->creh->bigImgs[i->second.first->idNumber],305+(62*(i->first)),387,to);
+	//	itoa(i->second.second,temp,10);
+	//	CSDL_Ext::printTo(temp,305+(62*(i->first))+57,387+61,GEOR13,zwykly,to);
+	//}
 	show();
 }
 void CCastleInterface::show(SDL_Surface * to)
 {
 	if (!to)
 		to=ekran;
+	garr->show();
 	count++;
 	if(count==5)
 	{
@@ -333,12 +336,15 @@ void CCastleInterface::show(SDL_Surface * to)
 }
 void CCastleInterface::activate()
 {
+	garr->activate();
 	LOCPLINT->curint = this;
+	exit->activate();
 	for(int i=0;i<buildings.size();i++)
 		buildings[i]->activate();
 }
 void CCastleInterface::deactivate()
 {
+	garr->deactivate();
 	exit->deactivate();
 	for(int i=0;i<buildings.size();i++)
 		buildings[i]->deactivate();

+ 1 - 0
CCastleInterface.h

@@ -38,6 +38,7 @@ public:
 	CDefHandler *hall,*fort,
 		*bigTownPic, *flag;
 
+	CGarrisonInt * garr;
 	AdventureMapButton<CCastleInterface> * exit;
 
 	std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling

+ 3 - 0
CConsoleHandler.cpp

@@ -31,6 +31,9 @@ int internalFunc(void * callback)
 		int heronum;
 		int3 dest;
 
+		if(pom==std::string("die, fool"))
+			exit(0);
+
 		switch (*cn.c_str())
 		{
 		case 'P':

+ 14 - 35
CHeroWindow.cpp

@@ -118,7 +118,8 @@ void CHeroWindow::show(SDL_Surface *to)
 {
 	if(!to)
 		to=ekran;
-	blitAt(curBack,pos.x,pos.y,to);
+	if(curBack)
+		blitAt(curBack,pos.x,pos.y,to);
 	quitButton->show();
 	dismissButton->show();
 	questlogButton->show();
@@ -192,106 +193,87 @@ void CHeroWindow::setHero(const CGHeroInstance *hero)
 	artFeet->pos.x = 515;
 	artFeet->pos.y = 295;
 	artFeet->pos.h = artFeet->pos.w = 44;
-	artFeet->activate();
 	artHead = new CArtPlace(hero->artHead);
 	artHead->pos.x = 509;
 	artHead->pos.y = 30;
 	artHead->pos.h = artHead->pos.h = 44;
-	artHead->activate();
 	artLHand = new CArtPlace(hero->artLHand);
 	artLHand->pos.x = 564;
 	artLHand->pos.y = 183;
 	artLHand->pos.h = artLHand->pos.h = 44;
-	artLHand->activate();
 	artLRing = new CArtPlace(hero->artLRing);
 	artLRing->pos.x = 610;
 	artLRing->pos.y = 183;
 	artLRing->pos.h = artLRing->pos.h = 44;
-	artLRing->activate();
 	artMach1 = new CArtPlace(hero->artMach1);
 	artMach1->pos.x = 564;
 	artMach1->pos.y = 30;
 	artMach1->pos.h = artMach1->pos.h = 44;
-	artMach1->activate();
 	artMach2 = new CArtPlace(hero->artMach2);
 	artMach2->pos.x = 610;
 	artMach2->pos.y = 30;
 	artMach2->pos.h = artMach2->pos.h = 44;
-	artMach2->activate();
 	artMach3 = new CArtPlace(hero->artMach3);
 	artMach3->pos.x = 610;
 	artMach3->pos.y = 76;
 	artMach3->pos.h = artMach3->pos.h = 44;
-	artMach3->activate();
 	artMach4 = new CArtPlace(hero->artMach4);
 	artMach4->pos.x = 610;
 	artMach4->pos.y = 122;
 	artMach4->pos.h = artMach4->pos.h = 44;
-	artMach4->activate();
 	artMisc1 = new CArtPlace(hero->artMisc1);
 	artMisc1->pos.x = 383;
 	artMisc1->pos.y = 143;
 	artMisc1->pos.h = artMisc1->pos.h = 44;
-	artMisc1->activate();
 	artMisc2 = new CArtPlace(hero->artMisc2);
 	artMisc2->pos.x = 399;
 	artMisc2->pos.y = 194;
 	artMisc2->pos.h = artMisc2->pos.h = 44;
-	artMisc2->activate();
 	artMisc3 = new CArtPlace(hero->artMisc3);
 	artMisc3->pos.x = 415;
 	artMisc3->pos.y = 245;
 	artMisc3->pos.h = artMisc3->pos.h = 44;
-	artMisc3->activate();
 	artMisc4 = new CArtPlace(hero->artMisc4);
 	artMisc4->pos.x = 431;
 	artMisc4->pos.y = 296;
 	artMisc4->pos.h = artMisc4->pos.h = 44;
-	artMisc4->activate();
 	artMisc5 = new CArtPlace(hero->artMisc5);
 	artMisc5->pos.x = 381;
 	artMisc5->pos.y = 296;
 	artMisc5->pos.h = artMisc5->pos.h = 44;
-	artMisc5->activate();
 	artNeck = new CArtPlace(hero->artNeck);
 	artNeck->pos.x = 508;
 	artNeck->pos.y = 79;
 	artNeck->pos.h = artNeck->pos.h = 44;
-	artNeck->activate();
 	artRhand = new CArtPlace(hero->artRhand);
 	artRhand->pos.x = 383;
 	artRhand->pos.y = 68;
 	artRhand->pos.h = artRhand->pos.h = 44;
-	artRhand->activate();
 	artRRing = new CArtPlace(hero->artRRing);
 	artRRing->pos.x = 431;
 	artRRing->pos.y = 68;
 	artRRing->pos.h = artRRing->pos.h = 44;
-	artRRing->activate();
 	artShoulders = new CArtPlace(hero->artShoulders);
 	artShoulders->pos.x = 567;
 	artShoulders->pos.y = 240;
 	artShoulders->pos.h = artShoulders->pos.h = 44;
-	artShoulders->activate();
 	artSpellBook = new CArtPlace(hero->artSpellBook);
 	artSpellBook->pos.x = 610;
 	artSpellBook->pos.y = 310;
 	artSpellBook->pos.h = artSpellBook->pos.h = 44;
-	artSpellBook->activate();
 	artTorso = new CArtPlace(hero->artTorso);
 	artTorso->pos.x = 509;
 	artTorso->pos.y = 130;
 	artTorso->pos.h = artTorso->pos.h = 44;
-	artTorso->activate();
 	for(int s=0; s<5 && s<curHero->artifacts.size(); ++s)
 	{
 		CArtPlace * add = new CArtPlace(curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]);
 		add->pos.x = 403 + 46*s;
 		add->pos.y = 365;
 		add->pos.h = add->pos.h = 44;
-		add->activate();
 		backpack.push_back(add);
 	}
+	redrawCurBack();
 }
 
 void CHeroWindow::quit()
@@ -303,19 +285,7 @@ void CHeroWindow::quit()
 			LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+i);
 		}
 	}
-	quitButton->deactivate();
-	dismissButton->deactivate();
-	questlogButton->deactivate();
-	gar1button->deactivate();
-	gar2button->deactivate();
-	gar3button->deactivate();
-	gar4button->deactivate();
-	leftArtRoll->deactivate();
-	rightArtRoll->deactivate();
-	for(int g=0; g<heroListMi.size(); ++g)
-	{
-		heroListMi[g]->deactivate();
-	}
+	deactivate();
 
 	LOCPLINT->adventureInt->show();
 
@@ -326,7 +296,6 @@ void CHeroWindow::quit()
 		if(dynamic_cast<CArtPlace*>(LOCPLINT->lclickable[v]))
 			LOCPLINT->lclickable.erase(LOCPLINT->lclickable.begin()+v);
 	}*/
-	portraitArea->deactivate();
 
 	delete artFeet;
 	artFeet = 0;
@@ -435,6 +404,10 @@ void CHeroWindow::activate()
 		if(backpack[f])
 			backpack[f]->activate();
 	}
+	for(int e=0; e<heroListMi.size(); ++e)
+	{
+		heroListMi[e]->activate();
+	}
 
 	//LOCPLINT->lclickable.push_back(artFeet);
 }
@@ -499,6 +472,10 @@ void CHeroWindow::deactivate()
 		if(backpack[f])
 			backpack[f]->deactivate();
 	}
+	for(int e=0; e<heroListMi.size(); ++e)
+	{
+		heroListMi[e]->deactivate();
+	}
 }
 
 void CHeroWindow::dismissCurrent()
@@ -784,8 +761,10 @@ void LClickableAreaHero::clickLeft(boost::logic::tribool down)
 {
 	if(!down)
 	{
+		owner->deactivate();
 		const CGHeroInstance * buf = LOCPLINT->cb->getHeroInfo(owner->player, id, false);
 		owner->setHero(buf);
 		owner->redrawCurBack();
+		owner->activate();
 	}
 }

+ 245 - 1
CPlayerInterface.cpp

@@ -28,6 +28,250 @@ public:
 		return (*a.first)<(*b.first);
 	}
 } ocmptwo_cgin ;
+
+void CGarrisonSlot::hover (bool on)
+{
+}
+void CGarrisonSlot::clickRight (tribool down)
+{
+}
+void CGarrisonSlot::clickLeft(tribool down)
+{
+	if(owner->ignoreEvent)
+	{
+		owner->ignoreEvent = false;
+		return;
+	}
+	if(down)
+	{
+		if(owner->highlighted)
+		{
+			LOCPLINT->cb->swapCreatures(
+				(!upg)?(owner->set1):(owner->set2),
+				(!owner->highlighted->upg)?(owner->set1):(owner->set2),
+				ID,owner->highlighted->ID);
+			owner->highlighted = NULL;
+			owner->recreateSlots();
+		}
+		else
+		{
+			owner->highlighted = this;
+		}
+	}
+}
+void CGarrisonSlot::activate()
+{
+	ClickableL::activate();
+	ClickableR::activate();
+	Hoverable::activate();
+}
+void CGarrisonSlot::deactivate()
+{
+	ClickableL::deactivate();
+	ClickableR::deactivate();
+	Hoverable::deactivate();
+}
+CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, const CCreature * Creature, int Count)
+{
+	upg = 0;
+	count = Count;
+	ID = IID;
+	creature = Creature;
+	pos.x = x;
+	pos.y = y;
+	pos.w = 58;
+	pos.h = 64;
+	owner = Owner;
+}
+void CGarrisonSlot::show()
+{
+	if(creature)
+	{
+		blitAtWR(CGI->creh->bigImgs[creature->idNumber],pos);
+	}
+	else
+	{
+		SDL_Rect jakis1 = genRect(pos.w,pos.h,owner->offx+ID*(pos.w+owner->interx),owner->offy+upg*(pos.h+owner->intery)), jakis2 = pos;
+		SDL_BlitSurface(owner->sur,&jakis1,ekran,&jakis2);
+		SDL_UpdateRect(ekran,pos.x,pos.y,pos.w,pos.h);
+	}
+}
+CGarrisonInt::~CGarrisonInt()
+{
+	if(sup)
+	{
+		for(int i=0;i<sup->size();i++)
+			delete (*sup)[i];
+		delete sup;
+	}
+	if(sdown)
+	{
+		for(int i=0;i<sdown->size();i++)
+			delete (*sdown)[i];
+		delete sdown;
+	}
+}
+
+void CGarrisonInt::show()
+{
+	if(sup)
+	{
+		for(int i = 0; i<sup->size(); i++)
+			if((*sup)[i])
+				(*sup)[i]->show();
+	}
+	if(sdown)
+	{
+		for(int i = 0; i<sdown->size(); i++)
+			if((*sdown)[i])
+				(*sdown)[i]->show();
+	}
+	if(highlighted)
+	{
+		blitAt(CGI->creh->bigImgs[-1],highlighted->pos);
+	}
+}
+void CGarrisonInt::deactiveteSlots()
+{
+	if(sup)
+	{
+		for(int i = 0; i<sup->size(); i++)
+		{
+			if((*sup)[i])
+			{
+				(*sup)[i]->deactivate();
+			}
+		}
+	}
+	if(sdown)
+	{
+		for(int i = 0; i<sdown->size(); i++)
+		{
+			if((*sdown)[i])
+			{
+				(*sdown)[i]->deactivate();
+			}
+		}
+	}
+}
+void CGarrisonInt::activeteSlots()
+{
+	if(sup)
+	{
+		for(int i = 0; i<sup->size(); i++)
+		{
+			if((*sup)[i])
+			{
+				(*sup)[i]->activate();
+			}
+		}
+	}
+	if(sdown)
+	{
+		for(int i = 0; i<sdown->size(); i++)
+		{
+			if((*sdown)[i])
+			{
+				(*sdown)[i]->activate();
+			}
+		}
+	}
+}
+void CGarrisonInt::createSlots()
+{
+	if(set1)
+	{
+		sup = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
+		for
+			(std::map<int,std::pair<CCreature*,int> >::const_iterator i=set1->slots.begin();
+			i!=set1->slots.end(); i++)
+		{
+			(*sup)[i->first] = 
+				new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y,i->first, i->second.first,i->second.second);
+		}
+		for(int i=0; i<sup->size(); i++)
+			if((*sup)[i] == NULL)
+				(*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y,i, NULL, 0);
+	}
+	if(set2)
+	{	
+		sdown = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
+		for
+			(std::map<int,std::pair<CCreature*,int> >::const_iterator i=set2->slots.begin();
+			i!=set2->slots.end(); i++)
+		{
+			(*sdown)[i->first] = 
+				new CGarrisonSlot(this, pos.x + (i->first*(58+interx)), pos.y + 64 + intery,i->first, i->second.first,i->second.second);
+		}
+		for(int i=0; i<sup->size(); i++)
+			if((*sdown)[i] == NULL)
+				(*sdown)[i] = new CGarrisonSlot(this, pos.x + (i*(58+interx)), pos.y,i, NULL, 0);
+	}
+}
+void CGarrisonInt::deleteSlots()
+{
+	if(sup)
+	{
+		for(int i = 0; i<sup->size(); i++)
+		{
+			if((*sup)[i])
+			{
+				delete (*sup)[i];
+			}
+		}
+	}
+	if(sdown)
+	{
+		for(int i = 0; i<sdown->size(); i++)
+		{
+			if((*sdown)[i])
+			{
+				delete (*sdown)[i];
+			}
+		}
+	}
+}
+void CGarrisonInt::recreateSlots()
+{
+	deactiveteSlots();
+	deleteSlots();
+	createSlots();
+	activeteSlots();
+	show();
+}
+CGarrisonInt::CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CCreatureSet * s1, const CCreatureSet *s2)
+	:interx(inx),intery(iny),sur(pomsur),highlighted(NULL),sup(NULL),sdown(NULL),set1(s1),set2(s2),
+	offx(OX),offy(OY)
+{
+	
+	ignoreEvent = false;
+	pos.x=(x);
+	pos.y=(y);
+	pos.w=(58);
+	pos.h=(64);
+	createSlots();
+}
+
+void CGarrisonInt::activate()
+{
+	if(sup)
+	{
+		for(int i = 0; i<sup->size(); i++)
+			if((*sup)[i])
+				(*sup)[i]->activate();
+	}
+	if(sdown)
+	{
+		for(int i = 0; i<sdown->size(); i++)
+			if((*sdown)[i])
+				(*sdown)[i]->activate();
+	}
+}
+void CGarrisonInt::deactivate()
+{
+	deactiveteSlots();
+}
+
 CInfoWindow::CInfoWindow()
 :okb(NMessage::ok,NULL,&CInfoWindow::okClicked)
 {
@@ -1582,6 +1826,6 @@ void CPlayerInterface::openHeroWindow(const CGHeroInstance *hero)
 {
 	adventureInt->heroWindow->setHero(hero);
 	this->objsToBlit.push_back(adventureInt->heroWindow);
-	adventureInt->heroWindow->activate();
 	adventureInt->hide();
+	adventureInt->heroWindow->activate();
 }

+ 45 - 0
CPlayerInterface.h

@@ -178,6 +178,51 @@ public:
 	void select(bool on);
 	SDL_Surface * getImg();
 };
+class CGarrisonInt;
+class CGarrisonSlot : public ClickableL, public ClickableR, public Hoverable
+{
+public:
+	CGarrisonInt *owner;
+	const CCreature * creature;
+	int count;
+	int upg; //upper garrison
+	
+	virtual void hover (bool on);
+	void clickRight (tribool down);
+	void clickLeft(tribool down);
+	void activate();
+	void deactivate();
+	void show();
+	CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, const CCreature * Creature=NULL, int Count=0);
+};
+
+class CGarrisonInt :public CIntObject
+{
+public:
+	int interx, intery;
+	CGarrisonSlot *highlighted;
+
+	SDL_Surface *sur;
+	int offx, offy;
+	bool ignoreEvent;
+
+	const CCreatureSet *set1;
+	const CCreatureSet *set2;
+
+	std::vector<CGarrisonSlot*> *sup, *sdown;
+
+	void activate();
+	void deactivate();
+	void show();
+	void activeteSlots();
+	void deactiveteSlots();
+	void deleteSlots();
+	void createSlots();
+	void recreateSlots();
+
+	CGarrisonInt(int x, int y, int inx, int iny, SDL_Surface *pomsur, int OX, int OY, const CCreatureSet * s1, const CCreatureSet *s2=NULL);
+	~CGarrisonInt();
+};
 
 class CPlayerInterface : public CGameInterface
 {

+ 1 - 1
SDL_Extensions.h

@@ -29,7 +29,7 @@ namespace CSDL_Ext
 	SDL_Surface * secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha); //alpha is a surface we want to blit src to
 	void fullAlphaTransform(SDL_Surface *& src); //performs first and second alpha transform
 	Uint32 colorToUint32(const SDL_Color * color); //little endian only
-	void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2);
+	void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
 	void printAtMiddle(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
 	void printAtMiddleWB(std::string text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran);
 	void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest