From c956b3f02a3754a2e45fc0558d6e81c95270a404 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 1 Jul 2014 17:19:08 +0300 Subject: [PATCH] Fixed #1820, better detection of object below cursor that uses same logic as renderer --- client/CAdvmapInterface.cpp | 12 +++++++----- client/CAdvmapInterface.h | 4 ++-- client/GUIClasses.cpp | 7 ++++++- lib/mapObjects/CRewardableObject.cpp | 7 +++++-- lib/mapObjects/CRewardableObject.h | 1 + 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index ea075bcf7..d98364a3d 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -1127,17 +1127,19 @@ void CAdvMapInt::endingTurn() LOCPLINT->cb->endTurn(); } -const CGObjectInstance* CAdvMapInt::getBlockingObject(const int3 &mapPos) +const CGObjectInstance* CAdvMapInt::getActiveObject(const int3 &mapPos) { std::vector < const CGObjectInstance * > bobjs = LOCPLINT->cb->getBlockingObjs(mapPos); //blocking objects at tile if (bobjs.empty()) return nullptr; + return *boost::range::max_element(bobjs, &CMapHandler::compareObjectBlitOrder); +/* if (bobjs.back()->ID == Obj::HERO) return bobjs.back(); else - return bobjs.front(); + return bobjs.front();*/ } void CAdvMapInt::tileLClicked(const int3 &mapPos) @@ -1147,7 +1149,7 @@ void CAdvMapInt::tileLClicked(const int3 &mapPos) const TerrainTile *tile = LOCPLINT->cb->getTile(mapPos); - const CGObjectInstance *topBlocking = getBlockingObject(mapPos); + const CGObjectInstance *topBlocking = getActiveObject(mapPos); int3 selPos = selection->getSightCenter(); if(spellBeingCasted && isInScreenRange(selPos, mapPos)) @@ -1232,7 +1234,7 @@ void CAdvMapInt::tileHovered(const int3 &mapPos) statusbar.clear(); return; } - const CGObjectInstance *objAtTile = getBlockingObject(mapPos); + const CGObjectInstance *objAtTile = getActiveObject(mapPos); if (objAtTile) { @@ -1432,7 +1434,7 @@ void CAdvMapInt::tileRClicked(const int3 &mapPos) return; } - const CGObjectInstance * obj = getBlockingObject(mapPos); + const CGObjectInstance * obj = getActiveObject(mapPos); if(!obj) { // Bare or undiscovered terrain diff --git a/client/CAdvmapInterface.h b/client/CAdvmapInterface.h index 793c393ff..cf7f785a9 100644 --- a/client/CAdvmapInterface.h +++ b/client/CAdvmapInterface.h @@ -85,8 +85,8 @@ public: /// can get to the towns and heroes. class CAdvMapInt : public CIntObject { - //get top selectable object at tile - const CGObjectInstance *getBlockingObject(const int3 &tile); + //Return object that must be active at this tile (=clickable) + const CGObjectInstance *getActiveObject(const int3 &tile); public: CAdvMapInt(); diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index b2d824fb6..c17ff1466 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -6181,7 +6181,12 @@ void CRClickPopup::createAndPush(const CGObjectInstance *obj, const Point &p, EA if(iWin) GH.pushInt(iWin); else - CRClickPopup::createAndPush(obj->getHoverText(LOCPLINT->playerID)); + { + if (adventureInt->curHero()) + CRClickPopup::createAndPush(obj->getHoverText(adventureInt->curHero())); + else + CRClickPopup::createAndPush(obj->getHoverText(LOCPLINT->playerID)); + } } CRClickPopup::CRClickPopup() diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index 6a4786ced..55a8d6fcb 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -308,6 +308,7 @@ bool CRewardableObject::wasVisited (PlayerColor player) const switch (visitMode) { case VISIT_UNLIMITED: + case VISIT_BONUS: return false; case VISIT_ONCE: // FIXME: hide this info deeper and return same as player? for (auto & visit : info) @@ -329,6 +330,8 @@ bool CRewardableObject::wasVisited (const CGHeroInstance * h) const switch (visitMode) { case VISIT_UNLIMITED: + return false; + case VISIT_BONUS: return h->hasBonusFrom(Bonus::OBJECT, ID); case VISIT_HERO: return h->visitedObjects.count(ObjectInstanceID(id)); @@ -389,7 +392,7 @@ static std::string & visitedTxt(const bool visited) std::string CRewardableObject::getHoverText(PlayerColor player) const { - if(visitMode != VISIT_UNLIMITED) + if(visitMode == VISIT_PLAYER || visitMode == VISIT_ONCE) return getObjectName() + " " + visitedTxt(wasVisited(player)); return getObjectName(); } @@ -611,7 +614,7 @@ void CGPickable::initObj() CGBonusingObject::CGBonusingObject() { - visitMode = VISIT_UNLIMITED; + visitMode = VISIT_BONUS; selectMode = SELECT_FIRST; } diff --git a/lib/mapObjects/CRewardableObject.h b/lib/mapObjects/CRewardableObject.h index b6924d470..163890e6a 100644 --- a/lib/mapObjects/CRewardableObject.h +++ b/lib/mapObjects/CRewardableObject.h @@ -177,6 +177,7 @@ protected: VISIT_UNLIMITED, // any number of times. Side effect - object hover text won't contain visited/not visited text VISIT_ONCE, // only once, first to visit get all the rewards VISIT_HERO, // every hero can visit object once + VISIT_BONUS, // can be visited by any hero that don't have bonus from this object VISIT_PLAYER // every player can visit object once };