Bläddra i källkod

Display object description only on right-click

Ivan Savenko 2 år sedan
förälder
incheckning
e0f6b582f5

+ 2 - 2
client/windows/InfoWindows.cpp

@@ -365,9 +365,9 @@ void CRClickPopup::createAndPush(const CGObjectInstance * obj, const Point & p,
 			guiComponents.push_back(std::make_shared<CComponent>(component));
 
 		if(LOCPLINT->localState->getCurrentHero())
-			CRClickPopup::createAndPush(obj->getHoverText(LOCPLINT->localState->getCurrentHero()), guiComponents);
+			CRClickPopup::createAndPush(obj->getPopupText(LOCPLINT->localState->getCurrentHero()), guiComponents);
 		else
-			CRClickPopup::createAndPush(obj->getHoverText(LOCPLINT->playerID), guiComponents);
+			CRClickPopup::createAndPush(obj->getPopupText(LOCPLINT->playerID), guiComponents);
 	}
 }
 

+ 9 - 0
lib/mapObjects/CGObjectInstance.cpp

@@ -271,6 +271,15 @@ std::string CGObjectInstance::getHoverText(const CGHeroInstance * hero) const
 	return getHoverText(hero->tempOwner);
 }
 
+std::string CGObjectInstance::getPopupText(PlayerColor player) const
+{
+	return getHoverText(player);
+}
+std::string CGObjectInstance::getPopupText(const CGHeroInstance * hero) const
+{
+	return getHoverText(hero);
+}
+
 std::vector<Component> CGObjectInstance::getPopupComponents(PlayerColor player) const
 {
 	return {};

+ 3 - 0
lib/mapObjects/CGObjectInstance.h

@@ -112,6 +112,9 @@ public:
 	/// Returns hero-specific hover name, including visited/not visited info. Default = player-specific name
 	virtual std::string getHoverText(const CGHeroInstance * hero) const;
 
+	virtual std::string getPopupText(PlayerColor player) const;
+	virtual std::string getPopupText(const CGHeroInstance * hero) const;
+
 	virtual std::vector<Component> getPopupComponents(PlayerColor player) const;
 	virtual std::vector<Component> getPopupComponents(const CGHeroInstance * hero) const;
 

+ 44 - 45
lib/mapObjects/CRewardableObject.cpp

@@ -244,55 +244,59 @@ bool CRewardableObject::wasVisited(const CGHeroInstance * h) const
 	}
 }
 
-std::string CRewardableObject::getHoverText(PlayerColor player) const
+std::string CRewardableObject::getDisplayTextImpl(PlayerColor player, const CGHeroInstance * hero, bool includeDescription) const
 {
 	std::string result = getObjectName();
 
-	if (!getDescriptionMessage(player).empty())
-		result += "\n" + getDescriptionMessage(player);
+	if (includeDescription && !getDescriptionMessage(player, hero).empty())
+		result += "\n" + getDescriptionMessage(player, hero);
 
-	if(configuration.visitMode == Rewardable::VISIT_PLAYER || configuration.visitMode == Rewardable::VISIT_ONCE)
+	if (hero)
 	{
-		if (wasVisited(player))
-			result += "\n\n" + configuration.visitedTooltip.toString();
-		else
-			result += "\n\n" + configuration.notVisitedTooltip.toString();
+		if(configuration.visitMode != Rewardable::VISIT_UNLIMITED)
+		{
+			if (wasVisited(hero))
+				result += "\n" + configuration.visitedTooltip.toString();
+			else
+				result += "\n " + configuration.notVisitedTooltip.toString();
+		}
+	}
+	else
+	{
+		if(configuration.visitMode == Rewardable::VISIT_PLAYER || configuration.visitMode == Rewardable::VISIT_ONCE)
+		{
+			if (wasVisited(player))
+				result += "\n" + configuration.visitedTooltip.toString();
+			else
+				result += "\n" + configuration.notVisitedTooltip.toString();
+		}
 	}
 	return result;
 }
 
-std::string CRewardableObject::getHoverText(const CGHeroInstance * hero) const
+std::string CRewardableObject::getHoverText(PlayerColor player) const
 {
-	std::string result = getObjectName();
-
-	if (!getDescriptionMessage(hero).empty())
-		result += "\n" + getDescriptionMessage(hero);
-
-	if(configuration.visitMode != Rewardable::VISIT_UNLIMITED)
-	{
-		if (wasVisited(hero))
-			result += "\n\n" + configuration.visitedTooltip.toString();
-		else
-			result += "\n\n" + configuration.notVisitedTooltip.toString();
-	}
-	return result;
+	return getDisplayTextImpl(player, nullptr, false);
 }
 
-std::string CRewardableObject::getDescriptionMessage(PlayerColor player) const
+std::string CRewardableObject::getHoverText(const CGHeroInstance * hero) const
 {
-	if (!wasScouted(player) || configuration.info.empty())
-		return configuration.description.toString();
+	return getDisplayTextImpl(hero->getOwner(), hero, false);
+}
 
-	auto rewardIndices = getAvailableRewards(nullptr, Rewardable::EEventType::EVENT_FIRST_VISIT);
-	if (rewardIndices.empty())
-		return configuration.info[0].description.toString();
+std::string CRewardableObject::getPopupText(PlayerColor player) const
+{
+	return getDisplayTextImpl(player, nullptr, true);
+}
 
-	return configuration.info[rewardIndices.front()].description.toString();
+std::string CRewardableObject::getPopupText(const CGHeroInstance * hero) const
+{
+	return getDisplayTextImpl(hero->getOwner(), hero, true);
 }
 
-std::string CRewardableObject::getDescriptionMessage(const CGHeroInstance * hero) const
+std::string CRewardableObject::getDescriptionMessage(PlayerColor player, const CGHeroInstance * hero) const
 {
-	if (!wasScouted(hero->getOwner()) || configuration.info.empty())
+	if (!wasScouted(player) || configuration.info.empty())
 		return configuration.description.toString();
 
 	auto rewardIndices = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT);
@@ -302,34 +306,29 @@ std::string CRewardableObject::getDescriptionMessage(const CGHeroInstance * hero
 	return configuration.info[rewardIndices.front()].description.toString();
 }
 
-std::vector<Component> CRewardableObject::getPopupComponents(PlayerColor player) const
+std::vector<Component> CRewardableObject::getPopupComponentsImpl(PlayerColor player, const CGHeroInstance * hero) const
 {
 	if (!wasScouted(player))
 		return {};
 
-	auto rewardIndices = getAvailableRewards(nullptr, Rewardable::EEventType::EVENT_FIRST_VISIT);
+	auto rewardIndices = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT);
 	if (rewardIndices.empty() && !configuration.info.empty())
 		rewardIndices.push_back(0);
 
 	if (rewardIndices.empty())
 		return {};
 
-	return loadComponents(nullptr, rewardIndices);
+	return loadComponents(hero, rewardIndices);
 }
 
-std::vector<Component> CRewardableObject::getPopupComponents(const CGHeroInstance * hero) const
+std::vector<Component> CRewardableObject::getPopupComponents(PlayerColor player) const
 {
-	if (!wasScouted(hero->getOwner()))
-		return {};
-
-	auto rewardIndices = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT);
-	if (rewardIndices.empty() && !configuration.info.empty())
-		rewardIndices.push_back(0);
-
-	if (rewardIndices.empty())
-		return {};
+	return getPopupComponentsImpl(player, nullptr);
+}
 
-	return loadComponents(nullptr, rewardIndices);
+std::vector<Component> CRewardableObject::getPopupComponents(const CGHeroInstance * hero) const
+{
+	return getPopupComponentsImpl(hero->getOwner(), hero);
 }
 
 void CRewardableObject::setPropertyDer(ui8 what, ui32 val)

+ 6 - 2
lib/mapObjects/CRewardableObject.h

@@ -39,6 +39,10 @@ protected:
 
 	std::vector<Component> loadComponents(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices) const;
 
+	std::string getDisplayTextImpl(PlayerColor player, const CGHeroInstance * hero, bool includeDescription) const;
+	std::string getDescriptionMessage(PlayerColor player, const CGHeroInstance * hero) const;
+	std::vector<Component> getPopupComponentsImpl(PlayerColor player, const CGHeroInstance * hero) const;
+
 public:
 	/// Visitability checks. Note that hero check includes check for hero owner (returns true if object was visited by player)
 	bool wasVisited(PlayerColor player) const override;
@@ -68,8 +72,8 @@ public:
 	std::string getHoverText(PlayerColor player) const override;
 	std::string getHoverText(const CGHeroInstance * hero) const override;
 
-	std::string getDescriptionMessage(PlayerColor player) const;
-	std::string getDescriptionMessage(const CGHeroInstance * hero) const;
+	std::string getPopupText(PlayerColor player) const override;
+	std::string getPopupText(const CGHeroInstance * hero) const override;
 
 	std::vector<Component> getPopupComponents(PlayerColor player) const override;
 	std::vector<Component> getPopupComponents(const CGHeroInstance * hero) const override;