浏览代码

vcmi: allow showing simple rewardables in infobox

Konstantin 2 年之前
父节点
当前提交
c759400767

+ 2 - 0
lib/mapObjects/CRewardableConstructor.cpp

@@ -231,6 +231,8 @@ void CRandomRewardObjectInfo::configureObject(CRewardableObject * object, CRando
 
 	object->canRefuse = parameters["canRefuse"].Bool();
 	
+	object->showInInfobox = parameters["showInInfobox"].Bool();
+	
 	auto visitMode = parameters["visitMode"].String();
 	for(int i = 0; i < Rewardable::VisitModeString.size(); ++i)
 	{

+ 4 - 2
lib/mapObjects/CRewardableObject.cpp

@@ -134,13 +134,15 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
 	{
 		auto vi = info[index];
 		logGlobal->debug("Granting reward %d. Message says: %s", index, vi.message.toString());
-		// show message only if it is not empty
-		if (!vi.message.toString().empty())
+		if (showInInfobox || !vi.message.toString().empty()) // show message only if it is not empty or in infobox
 		{
 			InfoWindow iw;
 			iw.player = h->tempOwner;
 			iw.text = vi.message;
 			vi.reward.loadComponents(iw.components, h);
+			iw.type = EInfoWindowMode::AUTO;
+			if(showInInfobox)
+				iw.type = EInfoWindowMode::INFO;
 			cb->showInfoDialog(&iw);
 		}
 		// grant reward afterwards. Note that it may remove object

+ 4 - 0
lib/mapObjects/CRewardableObject.h

@@ -306,6 +306,9 @@ protected:
 	/// if true - player can refuse visiting an object (e.g. Tomb)
 	bool canRefuse;
 
+	/// if true - object info will shown in infobox (like resource pickup)
+	bool showInInfobox;
+
 	/// return true if this object was "cleared" before and no longer has rewards applicable to selected hero
 	/// unlike wasVisited, this method uses information not available to player owner, for example, if object was cleared by another player before
 	bool wasVisitedBefore(const CGHeroInstance * contextHero) const;
@@ -345,6 +348,7 @@ public:
 		h & static_cast<CArmedInstance&>(*this);
 		h & info;
 		h & canRefuse;
+		h & showInInfobox;
 		h & resetParameters;
 		h & onSelect;
 		h & visitMode;