浏览代码

#2903-morale-description-#1442

gamestales-com 1 年之前
父节点
当前提交
a574f18e69
共有 4 个文件被更改,包括 25 次插入16 次删除
  1. 7 2
      client/widgets/MiscWidgets.cpp
  2. 16 12
      lib/bonuses/Bonus.cpp
  3. 1 1
      lib/constants/EntityIdentifiers.h
  4. 1 1
      lib/mapObjects/CArmedInstance.cpp

+ 7 - 2
client/widgets/MiscWidgets.cpp

@@ -579,8 +579,13 @@ void MoraleLuckBox::set(const AFactionMember * node)
 		std::string addInfo = "";
 		for(auto & bonus : * modifierList)
 		{
-			if(bonus->val)
-				addInfo += "\n" + bonus->Description();
+			if(bonus->val) {
+				const std::string& description = bonus->Description();
+				//arraytxt already contains \n
+				if (description.size() && description[0] != '\n')
+					addInfo += '\n';
+				addInfo += description;
+			}
 		}
 		text = addInfo.empty() 
 			? text + CGI->generaltexth->arraytxt[noneTxtId] 

+ 16 - 12
lib/bonuses/Bonus.cpp

@@ -91,7 +91,7 @@ JsonNode CAddInfo::toJsonNode() const
 }
 std::string Bonus::Description(std::optional<si32> customValue) const
 {
-	std::ostringstream str;
+	std::string str;
 
 	if(description.empty())
 	{
@@ -100,38 +100,42 @@ std::string Bonus::Description(std::optional<si32> customValue) const
 			switch(source)
 			{
 			case BonusSource::ARTIFACT:
-				str << sid.as<ArtifactID>().toEntity(VLC)->getNameTranslated();
+				str = sid.as<ArtifactID>().toEntity(VLC)->getNameTranslated();
 				break;
 			case BonusSource::SPELL_EFFECT:
-				str << sid.as<SpellID>().toEntity(VLC)->getNameTranslated();
+				str = sid.as<SpellID>().toEntity(VLC)->getNameTranslated();
 				break;
 			case BonusSource::CREATURE_ABILITY:
-				str << sid.as<CreatureID>().toEntity(VLC)->getNamePluralTranslated();
+				str = sid.as<CreatureID>().toEntity(VLC)->getNamePluralTranslated();
 				break;
 			case BonusSource::SECONDARY_SKILL:
-				str << VLC->skills()->getById(sid.as<SecondarySkill>())->getNameTranslated();
+				str = VLC->skills()->getById(sid.as<SecondarySkill>())->getNameTranslated();
 				break;
 			case BonusSource::HERO_SPECIAL:
-				str << VLC->heroTypes()->getById(sid.as<HeroTypeID>())->getNameTranslated();
+				str = VLC->heroTypes()->getById(sid.as<HeroTypeID>())->getNameTranslated();
 				break;
 			default:
 				//todo: handle all possible sources
-				str << "Unknown";
+				str = "Unknown";
 				break;
 			}
 		}
 		else
-			str << stacking;
+			str = stacking;
 	}
 	else
 	{
-		str << description;
+		str = description;
 	}
 
-	if(auto value = customValue.value_or(val))
-		str << " " << std::showpos << value;
+	if(auto value = customValue.value_or(val)) {
+		//arraytxt already contains +-value
+		std::string valueString = boost::str(boost::format(" %+d") % value);
+		if(!boost::algorithm::ends_with(str, valueString))
+			str += valueString;
+	}
 
-	return str.str();
+	return str;
 }
 
 static JsonNode additionalInfoToJson(BonusType type, CAddInfo addInfo)

+ 1 - 1
lib/constants/EntityIdentifiers.h

@@ -760,7 +760,7 @@ public:
 		DIMENSION_DOOR = 8,
 		TOWN_PORTAL = 9,
 
-		// Combar spells
+		// Combat spells
 		QUICKSAND = 10,
 		LAND_MINE = 11,
 		FORCE_FIELD = 12,

+ 1 - 1
lib/mapObjects/CArmedInstance.cpp

@@ -111,7 +111,7 @@ void CArmedInstance::updateMoraleBonusFromArmy()
 	{
 		b->val = 2 - static_cast<si32>(factionsInArmy);
 		description = boost::str(boost::format(VLC->generaltexth->arraytxt[114]) % factionsInArmy % b->val); //Troops of %d alignments %d
-		description = b->description.substr(0, description.size()-2);//trim value
+		description = description.substr(0, description.size()-3);//trim value
 	}
 	
 	boost::algorithm::trim(description);