Browse Source

use CLabel in SpellArea

AlexVinS 9 years ago
parent
commit
345dd913f6
2 changed files with 43 additions and 36 deletions
  1. 41 31
      client/windows/CSpellWindow.cpp
  2. 2 5
      client/windows/CSpellWindow.h

+ 41 - 31
client/windows/CSpellWindow.cpp

@@ -509,8 +509,13 @@ CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
 	schoolBorder = nullptr;
 
 	OBJ_CONSTRUCTION_CAPTURING_ALL;
+
 	image = new CAnimImage(owner->spells, 0, 0);
 	image->visible = false;
+
+	name  = new CLabel(39, 70, FONT_TINY, CENTER);
+	level = new CLabel(39, 82, FONT_TINY, CENTER);
+	cost  = new CLabel(39, 94, FONT_TINY, CENTER);
 }
 
 CSpellWindow::SpellArea::~SpellArea()
@@ -777,39 +782,9 @@ void CSpellWindow::SpellArea::showAll(SDL_Surface * to)
 	if(!mySpell)
 		return;
 
+	//printing border (indicates level of magic school)
 	schoolBorder->draw(to, pos.x, pos.y);
 	CIntObject::showAll(to);
-
-//	blitAt(owner->schoolBorders[owner->selectedTab >= 4 ? whichSchool : owner->selectedTab]->ourImages[schoolLevel].bitmap, pos.x, pos.y, to); //printing border (indicates level of magic school)
-
-	SDL_Color firstLineColor, secondLineColor;
-	if(spellCost > owner->myHero->mana) //hero cannot cast this spell
-	{
-		static const SDL_Color unavailableSpell = {239, 189, 33, 0};
-		firstLineColor = Colors::WHITE;
-		secondLineColor = unavailableSpell;
-	}
-	else
-	{
-		firstLineColor = Colors::YELLOW;
-		secondLineColor = Colors::WHITE;
-	}
-	//printing spell's name
-	printAtMiddleLoc(mySpell->name, 39, 70, FONT_TINY, firstLineColor, to);
-	//printing lvl
-	if(schoolLevel > 0)
-	{
-		boost::format fmt("%s/%s");
-		fmt % CGI->generaltexth->allTexts[171 + mySpell->level];
-		fmt % CGI->generaltexth->levels.at(3+(schoolLevel-1));//lines 4-6
-		printAtMiddleLoc(fmt.str(), 39, 82, FONT_TINY, secondLineColor, to);
-	}
-	else
-		printAtMiddleLoc(CGI->generaltexth->allTexts[171 + mySpell->level], 39, 82, FONT_TINY, secondLineColor, to);
-	//printing  cost
-	std::ostringstream ss;
-	ss << CGI->generaltexth->allTexts[387] << ": " << spellCost;
-	printAtMiddleLoc(ss.str(), 39, 94, FONT_TINY, secondLineColor, to);
 }
 
 void CSpellWindow::SpellArea::setSpell(const CSpell * spell)
@@ -817,6 +792,9 @@ void CSpellWindow::SpellArea::setSpell(const CSpell * spell)
 	if(schoolBorder)
 		schoolBorder->decreaseRef();
 	image->visible = false;
+	name->setText("");
+	level->setText("");
+	cost->setText("");
 	mySpell = spell;
 	if(mySpell)
 	{
@@ -826,5 +804,37 @@ void CSpellWindow::SpellArea::setSpell(const CSpell * spell)
 		image->setFrame(mySpell->id);
 		image->visible = true;
 		schoolBorder = owner->schoolBorders[owner->selectedTab >= 4 ? whichSchool : owner->selectedTab]->getImage(schoolLevel,0);
+
+		SDL_Color firstLineColor, secondLineColor;
+		if(spellCost > owner->myHero->mana) //hero cannot cast this spell
+		{
+			static const SDL_Color unavailableSpell = {239, 189, 33, 0};
+			firstLineColor = Colors::WHITE;
+			secondLineColor = unavailableSpell;
+		}
+		else
+		{
+			firstLineColor = Colors::YELLOW;
+			secondLineColor = Colors::WHITE;
+		}
+
+		name->color = firstLineColor;
+		name->setText(mySpell->name);
+
+		level->color = secondLineColor;
+		if(schoolLevel > 0)
+		{
+			boost::format fmt("%s/%s");
+			fmt % CGI->generaltexth->allTexts[171 + mySpell->level];
+			fmt % CGI->generaltexth->levels.at(3+(schoolLevel-1));//lines 4-6
+			level->setText(fmt.str());
+		}
+		else
+			level->setText(CGI->generaltexth->allTexts[171 + mySpell->level]);
+
+		cost->color = secondLineColor;
+		boost::format costfmt("%s: %d");
+		costfmt % CGI->generaltexth->allTexts[387] % spellCost;
+		cost->setText(costfmt.str());
 	}
 }

+ 2 - 5
client/windows/CSpellWindow.h

@@ -27,10 +27,8 @@ class CSpell;
 /// The spell window
 class CSpellWindow : public CWindowObject
 {
-private:
 	class SpellArea : public CIntObject
 	{
-	public:
 		const CSpell * mySpell;
 		int schoolLevel; //range: 0 none, 3 - expert
 		int whichSchool; //0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic,
@@ -38,7 +36,8 @@ private:
 		CSpellWindow * owner;
 		CAnimImage * image;
 		IImage * schoolBorder;
-
+		CLabel * name, * level, * cost;
+	public:
 		SpellArea(SDL_Rect pos, CSpellWindow * owner);
 		~SpellArea();
 		void setSpell(const CSpell * spell);
@@ -51,7 +50,6 @@ private:
 
 	class InteractiveArea : public CIntObject
 	{
-	private:
 		std::function<void()> onLeft;
 		CSpellWindow * owner;
 
@@ -95,7 +93,6 @@ private:
 	void turnPageRight();
 
 public:
-
 	CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells = true); //c-tor
 	~CSpellWindow(); //d-tor