Sfoglia il codice sorgente

Improved tooltips.

Michał W. Urbańczyk 16 anni fa
parent
commit
24c2ce6a99
3 ha cambiato i file con 45 aggiunte e 14 eliminazioni
  1. 26 8
      hch/CObjectHandler.cpp
  2. 18 6
      hch/CObjectHandler.h
  3. 1 0
      lib/IGameCallback.cpp

+ 26 - 8
hch/CObjectHandler.cpp

@@ -48,6 +48,17 @@ void IObjectInterface::initObj()
 void IObjectInterface::setProperty( ui8 what, ui32 val )
 {}
 
+void CPlayersVisited::setPropertyDer( ui8 what, ui32 val )
+{
+	if(what == 10)
+		players.insert(val);
+}
+
+bool CPlayersVisited::hasVisited( ui8 player ) const
+{
+	return vstd::contains(players,player);
+}
+
 void CObjectHandler::loadObjects()
 {
 	tlog5 << "\t\tReading cregens \n";
@@ -1641,7 +1652,7 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const
 {
 	InfoWindow iw;
 	iw.player = h->getOwner();
-	if(!vstd::contains(playersVisited,h->tempOwner))
+	if(!hasVisited(h->tempOwner))
 		cb->setObjProperty(id,10,h->tempOwner);
 
 	if(h->getSecSkillLevel(ability)) //you alredy know this skill
@@ -1668,7 +1679,7 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const
 const std::string & CGWitchHut::getHoverText() const
 {
 	hoverName = VLC->generaltexth->names[ID];
-	if(vstd::contains(playersVisited,cb->getCurrentPlayer())) //TODO: use local player, not current
+	if(hasVisited(cb->getCurrentPlayer())) //TODO: use local player, not current
 	{
 		hoverName += "\n" + VLC->generaltexth->allTexts[356]; // + (learn %s)
 		boost::algorithm::replace_first(hoverName,"%s",VLC->generaltexth->skillName[ability]);
@@ -1678,11 +1689,6 @@ const std::string & CGWitchHut::getHoverText() const
 	return hoverName;
 }
 
-void CGWitchHut::setPropertyDer( ui8 what, ui32 val )
-{
-	if(what == 10)
-		playersVisited.insert(val);
-}
 
 void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
 {
@@ -1917,6 +1923,9 @@ void CGShrine::onHeroVisit( const CGHeroInstance * h ) const
 		return;
 	}
 
+	if(!hasVisited(h->tempOwner))
+		cb->setObjProperty(id,10,h->tempOwner);
+
 	InfoWindow iw;
 	iw.player = h->getOwner();
 	iw.text.addTxt(MetaString::ADVOB_TXT,127 + ID - 88);
@@ -1976,5 +1985,14 @@ void CGShrine::initObj()
 
 const std::string & CGShrine::getHoverText() const
 {
+	hoverName = VLC->generaltexth->names[ID];
+	if(hasVisited(cb->getCurrentPlayer())) //TODO: use local player, not current
+	{
+		hoverName += "\n" + VLC->generaltexth->allTexts[355]; // + (learn %s)
+		boost::algorithm::replace_first(hoverName,"%s",VLC->spellh->spells[spell].name);
+		const CGHeroInstance *h = cb->getSelectedHero(cb->getCurrentPlayer());
+		if(h && vstd::contains(h->spells,spell)) //hero knows that ability
+			hoverName += "\n\n" + VLC->generaltexth->allTexts[354]; // (Already learned)
+	}
 	return hoverName;
-}
+}

+ 18 - 6
hch/CObjectHandler.h

@@ -136,6 +136,20 @@ public:
 	}
 };
 
+class DLL_EXPORT CPlayersVisited: public CGObjectInstance
+{
+public:
+	std::set<ui8> players;
+
+	bool hasVisited(ui8 player) const;
+	void setPropertyDer(ui8 what, ui32 val);//synchr
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & players;
+	}
+};
+
 class  DLL_EXPORT CArmedInstance: public CGObjectInstance
 {
 public:
@@ -432,20 +446,18 @@ public:
 	}
 };
 
-class DLL_EXPORT CGWitchHut : public CGObjectInstance
+class DLL_EXPORT CGWitchHut : public CPlayersVisited
 {
 public:
 	std::vector<si32> allowedAbilities;
 	ui32 ability;
-	std::set<ui8> playersVisited; //players who know what skill is given here (used for hover texts)
 
-	void setPropertyDer(ui8 what, ui32 val);//synchr
 	const std::string & getHoverText() const;
 	void onHeroVisit(const CGHeroInstance * h) const;
 	void initObj();
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & static_cast<CGObjectInstance&>(*this);
+		h & static_cast<CGObjectInstance&>(*this) & static_cast<CPlayersVisited&>(*this);;
 		h & allowedAbilities & ability;
 	}
 };
@@ -532,7 +544,7 @@ public:
 	}
 };
 
-class DLL_EXPORT CGShrine : public CGObjectInstance
+class DLL_EXPORT CGShrine : public CPlayersVisited
 {
 public:
 	ui8 spell; //number of spell or 255 if random
@@ -542,7 +554,7 @@ public:
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & static_cast<CGObjectInstance&>(*this);
+		h & static_cast<CGObjectInstance&>(*this) & static_cast<CPlayersVisited&>(*this);;
 		h & spell;
 	}
 };

+ 1 - 0
lib/IGameCallback.cpp

@@ -104,5 +104,6 @@ bool IGameCallback::isAllowed( int type, int id )
 		return gs->map->allowedSpell[id];
 	default:
 		tlog1 << "Wrong call to IGameCallback::isAllowed!\n";
+		return false;
 	}
 }