Pārlūkot izejas kodu

- Almost finished kingdom overview window
- modified garrison to allow placing it in 2 rows
- some fixes to hero and exchange windows

Ivan Savenko 15 gadi atpakaļ
vecāks
revīzija
eefdd686de
5 mainītis faili ar 151 papildinājumiem un 61 dzēšanām
  1. 37 14
      client/CHeroWindow.cpp
  2. 2 1
      client/CHeroWindow.h
  3. 21 17
      client/CKingdomInterface.h
  4. 80 25
      client/GUIClasses.cpp
  5. 11 4
      client/GUIClasses.h

+ 37 - 14
client/CHeroWindow.cpp

@@ -51,6 +51,7 @@ CHeroWindow::CHeroWindow(int playerColor):
 	pos.w = background->w;
 	curBack = NULL;
 	curHero = NULL;
+	char bufor[400];
 
 	artifs = new CArtifactsOfHero(pos);
 	artifs->commonInfo = new CArtifactsOfHero::SCommonPart;
@@ -87,15 +88,23 @@ CHeroWindow::CHeroWindow(int playerColor):
 	portraitArea = new LRClickableAreaWText();
 	portraitArea->pos = genRect(64, 58, pos.x+83, pos.y  +  26);
 
-	for(int v=0; v<4; ++v)
+	for(int v=0; v<PRIMARY_SKILLS; ++v)
 	{
 		primSkillAreas.push_back(new LRClickableAreaWTextComp());
-		primSkillAreas[v]->pos = genRect(42, 42, pos.x+95 + 70*v, pos.y  +  111);
+		primSkillAreas[v]->pos = genRect(64, 42, pos.x+95 + 70*v, pos.y  +  117);
 		primSkillAreas[v]->text = CGI->generaltexth->arraytxt[2+v];
 		primSkillAreas[v]->type = v;
 		primSkillAreas[v]->bonus = -1; // to be initilized when hero is being set
-		primSkillAreas[v]->baseType = 0;
-	}
+		primSkillAreas[v]->baseType = 0;
+		sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), CGI->generaltexth->primarySkillNames[v].c_str());
+		primSkillAreas[v]->hoverText = std::string(bufor);
+
+	}
+
+	specArea = new LRClickableAreaWText();
+	specArea->pos = genRect(42, 136, pos.x+83, pos.y  +  188);
+	specArea->hoverText = CGI->generaltexth->heroscrn[27];
+
 	expArea = new LRClickableAreaWText();
 	expArea->pos = genRect(42, 136, pos.x+83, pos.y  +  236);
 	expArea->hoverText = CGI->generaltexth->heroscrn[9];
@@ -110,7 +119,7 @@ CHeroWindow::CHeroWindow(int playerColor):
 	spellPointsArea->pos = genRect(42, 136, pos.x+227, pos.y  +  236);
 	spellPointsArea->hoverText = CGI->generaltexth->heroscrn[22];
 
-	for(int i=0; i<8; ++i)
+	for(int i=0; i<SKILL_PER_HERO; ++i)
 	{
 		secSkillAreas.push_back(new LRClickableAreaWTextComp());
 		secSkillAreas[i]->pos = genRect(42, 136, pos.x  +  ((i%2==0) ? (83) : (227)), pos.y  +  (284 + 48 * (i/2)));
@@ -153,7 +162,8 @@ CHeroWindow::~CHeroWindow()
 	delete portraitArea;
 	delete expArea;
 	delete luck;
-	delete morale;
+	delete morale;
+	delete specArea;
 	delete spellPointsArea;
 	for(size_t v=0; v<primSkillAreas.size(); ++v)
 	{
@@ -195,6 +205,8 @@ void CHeroWindow::setHero(const CGHeroInstance *hero)
 	//pos temporarily switched, restored later
 	pos.x -= 65;
 	pos.y -= 8;
+
+	specArea->text = CGI->generaltexth->hTxts[hero->subID].longBonus;
 
 	gar2button->callback.clear();
 	gar2button->callback2.clear();
@@ -242,7 +254,7 @@ void CHeroWindow::setHero(const CGHeroInstance *hero)
 	boost::replace_first(expArea->text, "%d", boost::lexical_cast<std::string>(hero->exp));
 
 	//printing spell points
-	sprintf(bufor, CGI->generaltexth->allTexts[205].c_str(), hero->name.c_str(), hero->mana, hero->manaLimit());
+	sprintf(bufor, CGI->generaltexth->allTexts[205].c_str(), hero->name.c_str(), hero->mana, hero->manaLimit());
 	spellPointsArea->text = std::string(bufor);
 
 	artifs->setHero(hero);
@@ -271,8 +283,12 @@ void CHeroWindow::setHero(const CGHeroInstance *hero)
 	morale->bonus = mrlv;
 	morale->text = CGI->generaltexth->arraytxt[88];
 	boost::algorithm::replace_first(morale->text,"%s",CGI->generaltexth->arraytxt[86-mrlt]);
-	for(int it=0; it < mrl.size(); it++)
-		morale->text += mrl[it].second;
+	if (!mrl.size())
+		morale->text += CGI->generaltexth->arraytxt[108];
+	else
+		for(int it=0; it < mrl.size(); it++)
+			morale->text += mrl[it].second;
+
 
 	//setting luck
 	mrl = hero->getCurrentLuckModifiers();
@@ -283,8 +299,11 @@ void CHeroWindow::setHero(const CGHeroInstance *hero)
 	luck->bonus = mrlv;
 	luck->text = CGI->generaltexth->arraytxt[62];
 	boost::algorithm::replace_first(luck->text,"%s",CGI->generaltexth->arraytxt[60-mrlt]);
-	for(int it=0; it < mrl.size(); it++)
-		luck->text += mrl[it].second;
+	if (!mrl.size())
+		luck->text += CGI->generaltexth->arraytxt[77];
+	else
+		for(int it=0; it < mrl.size(); it++)
+			luck->text += mrl[it].second;
 
 	//restoring pos
 	pos.x += 65;
@@ -307,7 +326,8 @@ void CHeroWindow::activate()
 	gar2button->activate();
 	formations->activate();
 	//gar4button->activate();
-	portraitArea->activate();
+	portraitArea->activate();
+	specArea->activate();
 	expArea->activate();
 	spellPointsArea->activate();
 	morale->activate();
@@ -340,7 +360,8 @@ void CHeroWindow::deactivate()
 	dismissButton->deactivate();
 	questlogButton->deactivate();
 	gar2button->deactivate();
-	formations->deactivate();
+	formations->deactivate();
+	specArea->deactivate();
 	//gar4button->deactivate();
 	portraitArea->deactivate();
 	expArea->deactivate();
@@ -487,7 +508,9 @@ void CHeroWindow::redrawCurBack()
 	}
 
 	//printing special ability
-	blitAt(graphics->un44->ourImages[curHero->subID].bitmap, 18, 180, curBack);
+	blitAt(graphics->un44->ourImages[curHero->subID].bitmap, 18, 180, curBack);
+	CSDL_Ext::printAt(CGI->generaltexth->jktexts[5].substr(1, CGI->generaltexth->jktexts[5].size()-2), 69, 183, GEOR13, tytulowy, curBack);
+	CSDL_Ext::printAt(CGI->generaltexth->hTxts[curHero->subID].bonusName, 69, 199, GEOR16, zwykly, curBack);
 
 	//printing necessery texts
 	CSDL_Ext::printAt(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 231, GEOR13, tytulowy, curBack);

+ 2 - 1
client/CHeroWindow.h

@@ -46,7 +46,8 @@ class CHeroWindow: public CWindowWithGarrison
 	std::vector<LRClickableAreaWTextComp *> primSkillAreas;
 	LRClickableAreaWText * expArea;
 	LRClickableAreaWText * spellPointsArea;
-	LRClickableAreaWTextComp * luck;
+	LRClickableAreaWTextComp * luck;
+	LRClickableAreaWText * specArea;//speciality
 	LRClickableAreaWTextComp * morale;
 	std::vector<LRClickableAreaWTextComp *> secSkillAreas;
 public:

+ 21 - 17
client/CKingdomInterface.h

@@ -29,25 +29,28 @@ class LRClickableAreaWTextComp*/
  */
 
 class CKingdomInterface : public CIntObject
-{
-	class CResIncomePic : public CIntObject
-	{
-	public:
-		int resID,value;//resource ID
-		std::string hoverText;
-		CResIncomePic(int RID, CDefEssential * Mines, CKingdomInterface * Owner);//c-tor
-		~CResIncomePic();//d-tor
-		void hover(bool on);
-		void show(SDL_Surface * to);
-		CDefEssential * mines;//pointer to mines pictures;
-	};
-	class CTownItem : public CIntObject
+{
+	class CTownItem : public CWindowWithGarrison
 	{
-	private:
-		const CGTownInstance * town;
+		class CCreaPlace: public LRClickableAreaWTextComp
+		{
+		public:
+			const CGTownInstance * town;
+			CCreaPlace(); //c-tor
+			void clickLeft(tribool down, bool previousState);
+			void clickRight(tribool down, bool previousState);
+			void activate();
+			void deactivate();
+		};
 	public:
+		const CGTownInstance * town;
 		CKingdomInterface * owner;
 		int numb;//position on screen (1..size)
+		HoverableArea *hallArea, *fortArea, *incomeArea;//hoverable text for town hall, fort, income
+		HoverableArea * garrHero, *visitHero;//portraits of heroes
+		HoverableArea * townImage;//town image
+		std::vector < HoverableArea * > creaGrowth;
+		std::vector < CCreaPlace * > creaCount;
 		void setTown(const CGTownInstance * newTown);//change town and update info
 		void showAll(SDL_Surface * to);
 		void activate();
@@ -122,8 +125,9 @@ public:
 	AdventureMapButton* ObjUp, *ObjDown, *ObjTop, *ObjBottom;//buttons for dwellings list
 
 	//income pics
-	std::vector<CResIncomePic *> incomes;//mines + incomes
-	CDefEssential * mines;//picture of mines
+	std::vector<HoverableArea*> incomes;//mines + incomes
+	std::vector<int> incomesVal;//values to print
+	CDefEssential * mines;
 
 	CKingdomInterface(); //c-tor
 	~CKingdomInterface(); //d-tor

+ 80 - 25
client/GUIClasses.cpp

@@ -495,6 +495,12 @@ void CGarrisonInt::createSlots()
 		for(int i=0; i<sup->size(); i++)
 			if((*sup)[i] == NULL)
 				(*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(w+interx)), pos.y,i,0,NULL, 0);
+		if (shiftPos)
+			for (int i=shiftPos; i<sup->size(); i++)
+			{
+				(*sup)[i]->pos.x += shiftPoint.x;
+				(*sup)[i]->pos.y += shiftPoint.y;
+			};
 	}
 	if(set2)
 	{
@@ -510,6 +516,12 @@ void CGarrisonInt::createSlots()
 		for(int i=0; i<sdown->size(); i++)
 			if((*sdown)[i] == NULL)
 				(*sdown)[i] = new CGarrisonSlot(this, pos.x + (i*(w+interx)) + garOffset.x,	pos.y + garOffset.y,i,1, NULL, 0);
+		if (shiftPos)
+			for (int i=shiftPos; i<sup->size(); i++)
+			{
+				(*sdown)[i]->pos.x += shiftPoint.x;
+				(*sdown)[i]->pos.y += shiftPoint.y;
+			};
 	}
 }
 void CGarrisonInt::deleteSlots()
@@ -578,9 +590,9 @@ void CGarrisonInt::splitStacks(int am2)
 
 }
 CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *&pomsur, const Point& SurOffset, 
-						   const CArmedInstance *s1, const CArmedInstance *s2, bool _removableUnits, bool smallImgs)
+						   const CArmedInstance *s1, const CArmedInstance *s2, bool _removableUnits, bool smallImgs, int _shiftPos, const Point &_shiftPoint)
 	 :interx(inx),garOffset(garsOffset),highlighted(NULL),sur(pomsur),surOffset(SurOffset),sup(NULL),
-	 sdown(NULL),oup(s1),odown(s2), removableUnits(_removableUnits), smallIcons(smallImgs)
+	 sdown(NULL),oup(s1),odown(s2), removableUnits(_removableUnits), smallIcons(smallImgs), shiftPos(_shiftPos), shiftPoint(_shiftPoint)
 {
 	active = false;
 	splitting = false;
@@ -4165,26 +4177,30 @@ void CExchangeWindow::activate()
 	}
 
 	for(int b=0; b<primSkillAreas.size(); ++b)
-	{
 		primSkillAreas[b]->activate();
-	}
 
 	LOCPLINT->statusbar = ourBar;
 
 	for(int g=0; g<ARRAY_COUNT(questlogButton); g++)
-	{
 		questlogButton[g]->activate();
-	}
 
 	for(int g=0; g<ARRAY_COUNT(morale); g++)
-	{
 		morale[g]->activate();
-	}
 
 	for(int g=0; g<ARRAY_COUNT(luck); g++)
-	{
 		luck[g]->activate();
-	}
+
+	for(int g=0; g<ARRAY_COUNT(portrait); g++)
+		portrait[g]->activate();
+
+	for(int g=0; g<ARRAY_COUNT(spellPoints); g++)
+		spellPoints[g]->activate();
+
+	for(int g=0; g<ARRAY_COUNT(experience); g++)
+		experience[g]->activate();
+
+	for(int g=0; g<ARRAY_COUNT(speciality); g++)
+		speciality[g]->activate();
 }
 
 void CExchangeWindow::deactivate()
@@ -4204,24 +4220,28 @@ void CExchangeWindow::deactivate()
 	}
 
 	for(int b=0; b<primSkillAreas.size(); ++b)
-	{
 		primSkillAreas[b]->deactivate();
-	}
 
 	for(int g=0; g<ARRAY_COUNT(questlogButton); g++)
-	{
 		questlogButton[g]->deactivate();
-	}
 
 	for(int g=0; g<ARRAY_COUNT(morale); g++)
-	{
 		morale[g]->deactivate();
-	}
 
 	for(int g=0; g<ARRAY_COUNT(luck); g++)
-	{
-		luck[g]->deactivate();
-	}
+		luck[g]->deactivate();
+
+	for(int g=0; g<ARRAY_COUNT(portrait); g++)
+		portrait[g]->deactivate();
+
+	for(int g=0; g<ARRAY_COUNT(spellPoints); g++)
+		spellPoints[g]->deactivate();
+
+	for(int g=0; g<ARRAY_COUNT(experience); g++)
+		experience[g]->deactivate();
+
+	for(int g=0; g<ARRAY_COUNT(speciality); g++)
+		speciality[g]->deactivate();
 }
 
 void CExchangeWindow::show(SDL_Surface * to)
@@ -4350,11 +4370,13 @@ CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) : bg(NULL)
 	{
 		//primary skill's clickable areas
 		primSkillAreas.push_back(new LRClickableAreaWTextComp());
-		primSkillAreas[g]->pos = genRect(32, 32, pos.x+385, pos.y + 19 + 36 * g);
+		primSkillAreas[g]->pos = genRect(32, 140, pos.x+329, pos.y + 19 + 36 * g);
 		primSkillAreas[g]->text = CGI->generaltexth->arraytxt[2+g];
 		primSkillAreas[g]->type = g;
 		primSkillAreas[g]->bonus = -1;
-		primSkillAreas[g]->baseType = 0;
+		primSkillAreas[g]->baseType = 0;
+		sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), CGI->generaltexth->primarySkillNames[g].c_str());
+		primSkillAreas[g]->hoverText = std::string(bufor);
 	}
 
 	//heroes related thing
@@ -4376,6 +4398,31 @@ CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) : bg(NULL)
 			sprintf(bufor, CGI->generaltexth->heroscrn[21].c_str(), CGI->generaltexth->levels[level - 1].c_str(), CGI->generaltexth->skillName[skill].c_str());
 			secSkillAreas[b][g]->hoverText = std::string(bufor);
 		}
+
+		portrait[b] = new LRClickableAreaWText();
+		portrait[b]->pos = genRect(64, 58, pos.x + 257 + 228*b, pos.y + 13);
+		portrait[b]->text = heroInst[b]->getBiography();
+		sprintf(bufor, CGI->generaltexth->allTexts[15].c_str(), heroInst[b]->name.c_str(), heroInst[b]->type->heroClass->name.c_str());
+		portrait[b]->hoverText = std::string(bufor);
+
+		speciality[b] = new LRClickableAreaWText();
+		speciality[b]->pos = genRect(32, 32, pos.x + 69 + 490*b, pos.y + 45);
+		speciality[b]->hoverText = CGI->generaltexth->heroscrn[27];
+		speciality[b]->text = CGI->generaltexth->hTxts[heroInst[b]->subID].longBonus;
+
+		experience[b] = new LRClickableAreaWText();
+		experience[b]->pos = genRect(32, 32, pos.x + 105 + 490*b, pos.y + 45);
+		experience[b]->hoverText = CGI->generaltexth->heroscrn[9];
+		experience[b]->text = CGI->generaltexth->allTexts[2].c_str();
+		boost::replace_first(experience[b]->text, "%d", boost::lexical_cast<std::string>(heroInst[b]->level));
+		boost::replace_first(experience[b]->text, "%d", boost::lexical_cast<std::string>(CGI->heroh->reqExp(heroInst[b]->level+1)));
+		boost::replace_first(experience[b]->text, "%d", boost::lexical_cast<std::string>(heroInst[b]->exp));
+
+		spellPoints[b] = new LRClickableAreaWText();
+		spellPoints[b]->pos = genRect(32, 32, pos.x + 141 + 490*b, pos.y + 45);
+		spellPoints[b]->hoverText = CGI->generaltexth->heroscrn[22];
+		sprintf(bufor, CGI->generaltexth->allTexts[205].c_str(), heroInst[b]->name.c_str(), heroInst[b]->mana, heroInst[b]->manaLimit());
+		spellPoints[b]->text = std::string(bufor);
 
 		//setting morale
 		morale[b] = new LRClickableAreaWTextComp();
@@ -4460,14 +4507,22 @@ CExchangeWindow::~CExchangeWindow() //d-tor
 	}
 
 	for(int g=0; g<ARRAY_COUNT(morale); g++)
-	{
 		delete morale[g];
-	}
 
 	for(int g=0; g<ARRAY_COUNT(luck); g++)
-	{
 		delete luck[g];
-	}
+
+	for(int g=0; g<ARRAY_COUNT(portrait); g++)
+		delete portrait[g];
+
+	for(int g=0; g<ARRAY_COUNT(spellPoints); g++)
+		delete spellPoints[g];
+
+	for(int g=0; g<ARRAY_COUNT(experience); g++)
+		delete experience[g];
+
+	for(int g=0; g<ARRAY_COUNT(speciality); g++)
+		delete speciality[g];
 }
 
 void CShipyardWindow::activate()

+ 11 - 4
client/GUIClasses.h

@@ -207,12 +207,14 @@ class CGarrisonInt :public CIntObject
 public:
 	int interx; //space between slots
 	Point garOffset, //offset between garrisons (not used if only one hero)
-		surOffset; //offset between garrison position on the bg surface and position on the screen
+		surOffset, //offset between garrison position on the bg surface and position on the screen
+		shiftPoint;//how last slots will be shifted (for second row, set shiftPoint for effect)
 	CGarrisonSlot *highlighted; //chosen slot
 	std::vector<AdventureMapButton *> splitButtons; //may be empty if no buttons
 
 	SDL_Surface *&sur; //bg surface
-	int p2; //TODO: comment me
+	int p2, //TODO: comment me
+	    shiftPos;//1st slot of the second row, set shiftPoint for effect
 	bool ignoreEvent, update, active, splitting, pb, 
 		smallIcons; //true - 32x32 imgs, false - 58x64
 	bool removableUnits;
@@ -235,7 +237,7 @@ public:
 	void splitClick(); //handles click on split button
 	void splitStacks(int am2); //TODO: comment me
 
-	CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *&pomsur, const Point &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=NULL, bool _removableUnits = true, bool smallImgs = false); //c-tor
+	CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *&pomsur, const Point &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=NULL, bool _removableUnits = true, bool smallImgs = false, int _shiftPos = 0, const Point &_shiftPoint =Point()); //c-tor
 	~CGarrisonInt(); //d-tor
 };
 
@@ -733,7 +735,12 @@ class CExchangeWindow : public CWindowWithGarrison
 
 	std::vector<LRClickableAreaWTextComp *> secSkillAreas[2], primSkillAreas;
 
-	LRClickableAreaWTextComp *morale[2], *luck[2];
+	LRClickableAreaWTextComp *morale[2], *luck[2];
+
+	LRClickableAreaWText *speciality[2];
+	LRClickableAreaWText *experience[2];
+	LRClickableAreaWText *spellPoints[2];
+	LRClickableAreaWText *portrait[2];
 
 public: