فهرست منبع

Hover text for heroes.

Michał W. Urbańczyk 17 سال پیش
والد
کامیت
dc82232e70
4فایلهای تغییر یافته به همراه12 افزوده شده و 11 حذف شده
  1. 5 9
      CLua.cpp
  2. 1 1
      CPlayerInterface.cpp
  3. 4 0
      client/Client.cpp
  4. 2 1
      lib/NetPacks.h

+ 5 - 9
CLua.cpp

@@ -634,6 +634,11 @@ std::vector<int> CTownScript::yourObjects() //returns IDs of objects which are h
 void CHeroScript::newObject(int objid)
 {
 	cb->setBlockVis(objid,true);
+	MetaString ms;
+	ms << std::pair<ui8,ui32>(1,15);
+	ms.replacements.push_back(cb->getHero(objid)->name);
+	ms.replacements.push_back(cb->getHero(objid)->type->heroClass->name);
+	cb->setHoverName(objid,&ms);
 }
 
 void CHeroScript::onHeroVisit(int objid, int heroID)
@@ -661,15 +666,6 @@ std::vector<int> CHeroScript::yourObjects() //returns IDs of objects which are h
 	ret.push_back(34); //hero
 	return ret;
 }
-//std::string CHeroScript::hoverText(int objid)
-//{
-//	//CGHeroInstance* h = static_cast<CGHeroInstance*>(os);
-//	//std::string ret = VLC->generaltexth->allTexts[15];
-//	//boost::algorithm::replace_first(ret,"%s",h->name);
-//	//boost::algorithm::replace_first(ret,"%s",h->type->heroClass->name);
-//	//return ret;
-//	return "";
-//}
 void CMonsterS::newObject(int objid)
 {
 	//os->blockVisit = true;

+ 1 - 1
CPlayerInterface.cpp

@@ -568,7 +568,7 @@ SComponent::SComponent(const Component &c)
 	switch(c.id)
 	{
 	case resource:
-		if(c.when==1)
+		if(c.when == -1)
 			subtitle += CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2);
 		break;
 	}

+ 4 - 0
client/Client.cpp

@@ -81,6 +81,10 @@ std::string toString(MetaString &ms)
 			}
 		}
 	}
+	for(int i=0;i<ms.replacements.size();i++)
+	{
+		ret.replace(ret.find("%s"),2,ms.replacements[i]);
+	}
 	return ret;
 }
 

+ 2 - 1
lib/NetPacks.h

@@ -145,10 +145,11 @@ struct MetaString : public CPack<MetaString> //2001 helper for object scrips
 	std::vector<std::string> strings;
 	std::vector<std::pair<ui8,ui32> > texts; //pairs<text handler type, text number>; types: 1 - generaltexthandler->all; 2 - objh->xtrainfo; 3 - objh->names; 4 - objh->restypes; 5 - arth->artifacts[id].name; 6 - generaltexth->arraytxt; 7 - creh->creatures[os->subID].namePl; 8 - objh->creGens; 9 - objh->mines[ID].first; 10 - objh->mines[ID].second; 11 - objh->advobtxt
 	std::vector<si32> message;
+	std::vector<std::string> replacements;
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & strings & texts & message;
+		h & strings & texts & message & replacements;
 	}
 
 	MetaString& operator<<(const std::pair<ui8,ui32> &txt)