mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Display object description only on right-click
This commit is contained in:
parent
530c70c282
commit
e0f6b582f5
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {};
|
||||
|
@ -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;
|
||||
|
||||
|
@ -244,57 +244,61 @@ 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 (hero)
|
||||
{
|
||||
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\n" + configuration.visitedTooltip.toString();
|
||||
result += "\n" + configuration.visitedTooltip.toString();
|
||||
else
|
||||
result += "\n\n" + configuration.notVisitedTooltip.toString();
|
||||
result += "\n" + configuration.notVisitedTooltip.toString();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string CRewardableObject::getHoverText(PlayerColor player) const
|
||||
{
|
||||
return getDisplayTextImpl(player, nullptr, false);
|
||||
}
|
||||
|
||||
std::string CRewardableObject::getHoverText(const CGHeroInstance * hero) 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(hero->getOwner(), hero, false);
|
||||
}
|
||||
|
||||
std::string CRewardableObject::getDescriptionMessage(PlayerColor player) const
|
||||
std::string CRewardableObject::getPopupText(PlayerColor player) const
|
||||
{
|
||||
return getDisplayTextImpl(player, nullptr, true);
|
||||
}
|
||||
|
||||
std::string CRewardableObject::getPopupText(const CGHeroInstance * hero) const
|
||||
{
|
||||
return getDisplayTextImpl(hero->getOwner(), hero, true);
|
||||
}
|
||||
|
||||
std::string CRewardableObject::getDescriptionMessage(PlayerColor player, const CGHeroInstance * hero) const
|
||||
{
|
||||
if (!wasScouted(player) || configuration.info.empty())
|
||||
return configuration.description.toString();
|
||||
|
||||
auto rewardIndices = getAvailableRewards(nullptr, Rewardable::EEventType::EVENT_FIRST_VISIT);
|
||||
if (rewardIndices.empty())
|
||||
return configuration.info[0].description.toString();
|
||||
|
||||
return configuration.info[rewardIndices.front()].description.toString();
|
||||
}
|
||||
|
||||
std::string CRewardableObject::getDescriptionMessage(const CGHeroInstance * hero) const
|
||||
{
|
||||
if (!wasScouted(hero->getOwner()) || configuration.info.empty())
|
||||
return configuration.description.toString();
|
||||
|
||||
auto rewardIndices = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT);
|
||||
if (rewardIndices.empty())
|
||||
return configuration.info[0].description.toString();
|
||||
@ -302,26 +306,11 @@ 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);
|
||||
if (rewardIndices.empty() && !configuration.info.empty())
|
||||
rewardIndices.push_back(0);
|
||||
|
||||
if (rewardIndices.empty())
|
||||
return {};
|
||||
|
||||
return loadComponents(nullptr, rewardIndices);
|
||||
}
|
||||
|
||||
std::vector<Component> CRewardableObject::getPopupComponents(const CGHeroInstance * hero) 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);
|
||||
@ -329,7 +318,17 @@ std::vector<Component> CRewardableObject::getPopupComponents(const CGHeroInstanc
|
||||
if (rewardIndices.empty())
|
||||
return {};
|
||||
|
||||
return loadComponents(nullptr, rewardIndices);
|
||||
return loadComponents(hero, rewardIndices);
|
||||
}
|
||||
|
||||
std::vector<Component> CRewardableObject::getPopupComponents(PlayerColor player) const
|
||||
{
|
||||
return getPopupComponentsImpl(player, nullptr);
|
||||
}
|
||||
|
||||
std::vector<Component> CRewardableObject::getPopupComponents(const CGHeroInstance * hero) const
|
||||
{
|
||||
return getPopupComponentsImpl(hero->getOwner(), hero);
|
||||
}
|
||||
|
||||
void CRewardableObject::setPropertyDer(ui8 what, ui32 val)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user