1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

Fixed #1820, better detection of object below cursor that uses same logic as renderer

This commit is contained in:
Ivan Savenko
2014-07-01 17:19:08 +03:00
parent bae9f2083f
commit c956b3f02a
5 changed files with 21 additions and 10 deletions

View File

@@ -1127,17 +1127,19 @@ void CAdvMapInt::endingTurn()
LOCPLINT->cb->endTurn(); 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 std::vector < const CGObjectInstance * > bobjs = LOCPLINT->cb->getBlockingObjs(mapPos); //blocking objects at tile
if (bobjs.empty()) if (bobjs.empty())
return nullptr; return nullptr;
return *boost::range::max_element(bobjs, &CMapHandler::compareObjectBlitOrder);
/*
if (bobjs.back()->ID == Obj::HERO) if (bobjs.back()->ID == Obj::HERO)
return bobjs.back(); return bobjs.back();
else else
return bobjs.front(); return bobjs.front();*/
} }
void CAdvMapInt::tileLClicked(const int3 &mapPos) void CAdvMapInt::tileLClicked(const int3 &mapPos)
@@ -1147,7 +1149,7 @@ void CAdvMapInt::tileLClicked(const int3 &mapPos)
const TerrainTile *tile = LOCPLINT->cb->getTile(mapPos); const TerrainTile *tile = LOCPLINT->cb->getTile(mapPos);
const CGObjectInstance *topBlocking = getBlockingObject(mapPos); const CGObjectInstance *topBlocking = getActiveObject(mapPos);
int3 selPos = selection->getSightCenter(); int3 selPos = selection->getSightCenter();
if(spellBeingCasted && isInScreenRange(selPos, mapPos)) if(spellBeingCasted && isInScreenRange(selPos, mapPos))
@@ -1232,7 +1234,7 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
statusbar.clear(); statusbar.clear();
return; return;
} }
const CGObjectInstance *objAtTile = getBlockingObject(mapPos); const CGObjectInstance *objAtTile = getActiveObject(mapPos);
if (objAtTile) if (objAtTile)
{ {
@@ -1432,7 +1434,7 @@ void CAdvMapInt::tileRClicked(const int3 &mapPos)
return; return;
} }
const CGObjectInstance * obj = getBlockingObject(mapPos); const CGObjectInstance * obj = getActiveObject(mapPos);
if(!obj) if(!obj)
{ {
// Bare or undiscovered terrain // Bare or undiscovered terrain

View File

@@ -85,8 +85,8 @@ public:
/// can get to the towns and heroes. /// can get to the towns and heroes.
class CAdvMapInt : public CIntObject class CAdvMapInt : public CIntObject
{ {
//get top selectable object at tile //Return object that must be active at this tile (=clickable)
const CGObjectInstance *getBlockingObject(const int3 &tile); const CGObjectInstance *getActiveObject(const int3 &tile);
public: public:
CAdvMapInt(); CAdvMapInt();

View File

@@ -6181,7 +6181,12 @@ void CRClickPopup::createAndPush(const CGObjectInstance *obj, const Point &p, EA
if(iWin) if(iWin)
GH.pushInt(iWin); GH.pushInt(iWin);
else 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() CRClickPopup::CRClickPopup()

View File

@@ -308,6 +308,7 @@ bool CRewardableObject::wasVisited (PlayerColor player) const
switch (visitMode) switch (visitMode)
{ {
case VISIT_UNLIMITED: case VISIT_UNLIMITED:
case VISIT_BONUS:
return false; return false;
case VISIT_ONCE: // FIXME: hide this info deeper and return same as player? case VISIT_ONCE: // FIXME: hide this info deeper and return same as player?
for (auto & visit : info) for (auto & visit : info)
@@ -329,6 +330,8 @@ bool CRewardableObject::wasVisited (const CGHeroInstance * h) const
switch (visitMode) switch (visitMode)
{ {
case VISIT_UNLIMITED: case VISIT_UNLIMITED:
return false;
case VISIT_BONUS:
return h->hasBonusFrom(Bonus::OBJECT, ID); return h->hasBonusFrom(Bonus::OBJECT, ID);
case VISIT_HERO: case VISIT_HERO:
return h->visitedObjects.count(ObjectInstanceID(id)); return h->visitedObjects.count(ObjectInstanceID(id));
@@ -389,7 +392,7 @@ static std::string & visitedTxt(const bool visited)
std::string CRewardableObject::getHoverText(PlayerColor player) const 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() + " " + visitedTxt(wasVisited(player));
return getObjectName(); return getObjectName();
} }
@@ -611,7 +614,7 @@ void CGPickable::initObj()
CGBonusingObject::CGBonusingObject() CGBonusingObject::CGBonusingObject()
{ {
visitMode = VISIT_UNLIMITED; visitMode = VISIT_BONUS;
selectMode = SELECT_FIRST; selectMode = SELECT_FIRST;
} }

View File

@@ -177,6 +177,7 @@ protected:
VISIT_UNLIMITED, // any number of times. Side effect - object hover text won't contain visited/not visited text 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_ONCE, // only once, first to visit get all the rewards
VISIT_HERO, // every hero can visit object once 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 VISIT_PLAYER // every player can visit object once
}; };