mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
Fix checks for tile visibility in tile click/hover handlers
This commit is contained in:
@@ -501,12 +501,12 @@ const CGObjectInstance* AdventureMapInterface::getActiveObject(const int3 &mapPo
|
|||||||
return *boost::range::max_element(bobjs, &CMapHandler::compareObjectBlitOrder);
|
return *boost::range::max_element(bobjs, &CMapHandler::compareObjectBlitOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdventureMapInterface::onTileLeftClicked(const int3 &mapPos)
|
void AdventureMapInterface::onTileLeftClicked(const int3 &targetPosition)
|
||||||
{
|
{
|
||||||
if(!shortcuts->optionMapViewActive())
|
if(!shortcuts->optionMapViewActive())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!LOCPLINT->cb->isVisible(mapPos))
|
if(!LOCPLINT->cb->isVisible(targetPosition))
|
||||||
{
|
{
|
||||||
if(!spellBeingCasted || spellBeingCasted->id != SpellID::DIMENSION_DOOR)
|
if(!spellBeingCasted || spellBeingCasted->id != SpellID::DIMENSION_DOOR)
|
||||||
return;
|
return;
|
||||||
@@ -514,14 +514,14 @@ void AdventureMapInterface::onTileLeftClicked(const int3 &mapPos)
|
|||||||
if(!LOCPLINT->makingTurn)
|
if(!LOCPLINT->makingTurn)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const CGObjectInstance *topBlocking = getActiveObject(mapPos);
|
const CGObjectInstance *topBlocking = LOCPLINT->cb->isVisible(targetPosition) ? getActiveObject(targetPosition) : nullptr;
|
||||||
|
|
||||||
int3 selPos = LOCPLINT->localState->getCurrentArmy()->getSightCenter();
|
int3 selPos = LOCPLINT->localState->getCurrentArmy()->getSightCenter();
|
||||||
if(spellBeingCasted)
|
if(spellBeingCasted)
|
||||||
{
|
{
|
||||||
assert(shortcuts->optionSpellcasting());
|
assert(shortcuts->optionSpellcasting());
|
||||||
|
|
||||||
if (!isInScreenRange(selPos, mapPos))
|
if (!isInScreenRange(selPos, targetPosition))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const TerrainTile *heroTile = LOCPLINT->cb->getTile(selPos);
|
const TerrainTile *heroTile = LOCPLINT->cb->getTile(selPos);
|
||||||
@@ -530,12 +530,12 @@ void AdventureMapInterface::onTileLeftClicked(const int3 &mapPos)
|
|||||||
{
|
{
|
||||||
case SpellID::SCUTTLE_BOAT: //Scuttle Boat
|
case SpellID::SCUTTLE_BOAT: //Scuttle Boat
|
||||||
if(topBlocking && topBlocking->ID == Obj::BOAT)
|
if(topBlocking && topBlocking->ID == Obj::BOAT)
|
||||||
performSpellcasting(mapPos);
|
performSpellcasting(targetPosition);
|
||||||
break;
|
break;
|
||||||
case SpellID::DIMENSION_DOOR:
|
case SpellID::DIMENSION_DOOR:
|
||||||
const TerrainTile *targetTile = LOCPLINT->cb->getTileForDimensionDoor(mapPos, LOCPLINT->localState->getCurrentHero());
|
const TerrainTile *targetTile = LOCPLINT->cb->getTileForDimensionDoor(targetPosition, LOCPLINT->localState->getCurrentHero());
|
||||||
if(targetTile && targetTile->isClear(heroTile))
|
if(targetTile && targetTile->isClear(heroTile))
|
||||||
performSpellcasting(mapPos);
|
performSpellcasting(targetPosition);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -556,7 +556,7 @@ void AdventureMapInterface::onTileLeftClicked(const int3 &mapPos)
|
|||||||
{
|
{
|
||||||
isHero = true;
|
isHero = true;
|
||||||
|
|
||||||
const CGPathNode *pn = LOCPLINT->cb->getPathsInfo(currentHero)->getPathInfo(mapPos);
|
const CGPathNode *pn = LOCPLINT->cb->getPathsInfo(currentHero)->getPathInfo(targetPosition);
|
||||||
if(currentHero == topBlocking) //clicked selected hero
|
if(currentHero == topBlocking) //clicked selected hero
|
||||||
{
|
{
|
||||||
LOCPLINT->openHeroWindow(currentHero);
|
LOCPLINT->openHeroWindow(currentHero);
|
||||||
@@ -570,7 +570,7 @@ void AdventureMapInterface::onTileLeftClicked(const int3 &mapPos)
|
|||||||
else //still here? we need to move hero if we clicked end of already selected path or calculate a new path otherwise
|
else //still here? we need to move hero if we clicked end of already selected path or calculate a new path otherwise
|
||||||
{
|
{
|
||||||
if(LOCPLINT->localState->hasPath(currentHero) &&
|
if(LOCPLINT->localState->hasPath(currentHero) &&
|
||||||
LOCPLINT->localState->getPath(currentHero).endPos() == mapPos)//we'll be moving
|
LOCPLINT->localState->getPath(currentHero).endPos() == targetPosition)//we'll be moving
|
||||||
{
|
{
|
||||||
assert(!CGI->mh->hasOngoingAnimations());
|
assert(!CGI->mh->hasOngoingAnimations());
|
||||||
if(!CGI->mh->hasOngoingAnimations() && LOCPLINT->localState->getPath(currentHero).nextNode().turns == 0)
|
if(!CGI->mh->hasOngoingAnimations() && LOCPLINT->localState->getPath(currentHero).nextNode().turns == 0)
|
||||||
@@ -586,7 +586,7 @@ void AdventureMapInterface::onTileLeftClicked(const int3 &mapPos)
|
|||||||
}
|
}
|
||||||
else //remove old path and find a new one if we clicked on accessible tile
|
else //remove old path and find a new one if we clicked on accessible tile
|
||||||
{
|
{
|
||||||
LOCPLINT->localState->setPath(currentHero, mapPos);
|
LOCPLINT->localState->setPath(currentHero, targetPosition);
|
||||||
onHeroChanged(currentHero);
|
onHeroChanged(currentHero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -604,7 +604,7 @@ void AdventureMapInterface::onTileLeftClicked(const int3 &mapPos)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdventureMapInterface::onTileHovered(const int3 &mapPos)
|
void AdventureMapInterface::onTileHovered(const int3 &targetPosition)
|
||||||
{
|
{
|
||||||
if(!shortcuts->optionMapViewActive())
|
if(!shortcuts->optionMapViewActive())
|
||||||
return;
|
return;
|
||||||
@@ -613,7 +613,9 @@ void AdventureMapInterface::onTileHovered(const int3 &mapPos)
|
|||||||
if(!LOCPLINT->localState->getCurrentArmy())
|
if(!LOCPLINT->localState->getCurrentArmy())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(!LOCPLINT->cb->isVisible(mapPos))
|
bool isTargetPositionVisible = LOCPLINT->cb->isVisible(targetPosition);
|
||||||
|
|
||||||
|
if(!isTargetPositionVisible)
|
||||||
{
|
{
|
||||||
GH.statusbar()->clear();
|
GH.statusbar()->clear();
|
||||||
|
|
||||||
@@ -626,7 +628,7 @@ void AdventureMapInterface::onTileHovered(const int3 &mapPos)
|
|||||||
|
|
||||||
auto objRelations = PlayerRelations::ALLIES;
|
auto objRelations = PlayerRelations::ALLIES;
|
||||||
|
|
||||||
const CGObjectInstance *objAtTile = LOCPLINT->cb->isVisible(mapPos) ? getActiveObject(mapPos) : nullptr;
|
const CGObjectInstance *objAtTile = isTargetPositionVisible ? getActiveObject(targetPosition) : nullptr;
|
||||||
if(objAtTile)
|
if(objAtTile)
|
||||||
{
|
{
|
||||||
objRelations = LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, objAtTile->tempOwner);
|
objRelations = LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, objAtTile->tempOwner);
|
||||||
@@ -634,10 +636,10 @@ void AdventureMapInterface::onTileHovered(const int3 &mapPos)
|
|||||||
boost::replace_all(text,"\n"," ");
|
boost::replace_all(text,"\n"," ");
|
||||||
GH.statusbar()->write(text);
|
GH.statusbar()->write(text);
|
||||||
}
|
}
|
||||||
else
|
else if(isTargetPositionVisible)
|
||||||
{
|
{
|
||||||
std::string hlp = CGI->mh->getTerrainDescr(mapPos, false); //TODO: possible to get info about invisible tiles
|
std::string tileTooltipText = CGI->mh->getTerrainDescr(targetPosition, false);
|
||||||
GH.statusbar()->write(hlp);
|
GH.statusbar()->write(tileTooltipText);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(spellBeingCasted)
|
if(spellBeingCasted)
|
||||||
@@ -646,9 +648,9 @@ void AdventureMapInterface::onTileHovered(const int3 &mapPos)
|
|||||||
{
|
{
|
||||||
case SpellID::SCUTTLE_BOAT:
|
case SpellID::SCUTTLE_BOAT:
|
||||||
{
|
{
|
||||||
int3 hpos = LOCPLINT->localState->getCurrentArmy()->getSightCenter();
|
int3 heroPosition = LOCPLINT->localState->getCurrentArmy()->getSightCenter();
|
||||||
|
|
||||||
if(objAtTile && objAtTile->ID == Obj::BOAT && isInScreenRange(hpos, mapPos))
|
if(objAtTile && objAtTile->ID == Obj::BOAT && isInScreenRange(heroPosition, targetPosition))
|
||||||
CCS->curh->set(Cursor::Map::SCUTTLE_BOAT);
|
CCS->curh->set(Cursor::Map::SCUTTLE_BOAT);
|
||||||
else
|
else
|
||||||
CCS->curh->set(Cursor::Map::POINTER);
|
CCS->curh->set(Cursor::Map::POINTER);
|
||||||
@@ -656,7 +658,7 @@ void AdventureMapInterface::onTileHovered(const int3 &mapPos)
|
|||||||
}
|
}
|
||||||
case SpellID::DIMENSION_DOOR:
|
case SpellID::DIMENSION_DOOR:
|
||||||
{
|
{
|
||||||
const TerrainTile * t = LOCPLINT->cb->getTileForDimensionDoor(mapPos, LOCPLINT->localState->getCurrentHero());
|
const TerrainTile * t = LOCPLINT->cb->getTileForDimensionDoor(targetPosition, LOCPLINT->localState->getCurrentHero());
|
||||||
int3 heroPosition = LOCPLINT->localState->getCurrentArmy()->getSightCenter();
|
int3 heroPosition = LOCPLINT->localState->getCurrentArmy()->getSightCenter();
|
||||||
if(t && t->isClear(LOCPLINT->cb->getTile(heroPosition))/* && isInScreenRange(hpos, mapPos)*/)
|
if(t && t->isClear(LOCPLINT->cb->getTile(heroPosition))/* && isInScreenRange(hpos, mapPos)*/)
|
||||||
CCS->curh->set(Cursor::Map::TELEPORT); //TODO: something wrong with beyond east spell range border cursor on arrogance after TP-ing near underground portal on previous day
|
CCS->curh->set(Cursor::Map::TELEPORT); //TODO: something wrong with beyond east spell range border cursor on arrogance after TP-ing near underground portal on previous day
|
||||||
@@ -691,7 +693,7 @@ void AdventureMapInterface::onTileHovered(const int3 &mapPos)
|
|||||||
std::array<Cursor::Map, 4> cursorVisit = { Cursor::Map::T1_VISIT, Cursor::Map::T2_VISIT, Cursor::Map::T3_VISIT, Cursor::Map::T4_VISIT, };
|
std::array<Cursor::Map, 4> cursorVisit = { Cursor::Map::T1_VISIT, Cursor::Map::T2_VISIT, Cursor::Map::T3_VISIT, Cursor::Map::T4_VISIT, };
|
||||||
std::array<Cursor::Map, 4> cursorSailVisit = { Cursor::Map::T1_SAIL_VISIT, Cursor::Map::T2_SAIL_VISIT, Cursor::Map::T3_SAIL_VISIT, Cursor::Map::T4_SAIL_VISIT, };
|
std::array<Cursor::Map, 4> cursorSailVisit = { Cursor::Map::T1_SAIL_VISIT, Cursor::Map::T2_SAIL_VISIT, Cursor::Map::T3_SAIL_VISIT, Cursor::Map::T4_SAIL_VISIT, };
|
||||||
|
|
||||||
const CGPathNode * pathNode = LOCPLINT->cb->getPathsInfo(hero)->getPathInfo(mapPos);
|
const CGPathNode * pathNode = LOCPLINT->cb->getPathsInfo(hero)->getPathInfo(targetPosition);
|
||||||
assert(pathNode);
|
assert(pathNode);
|
||||||
|
|
||||||
if((GH.isKeyboardAltDown() || settings["gameTweaks"]["forceMovementInfo"].Bool()) && pathNode->reachable()) //overwrite status bar text with movement info
|
if((GH.isKeyboardAltDown() || settings["gameTweaks"]["forceMovementInfo"].Bool()) && pathNode->reachable()) //overwrite status bar text with movement info
|
||||||
|
@@ -170,10 +170,10 @@ public:
|
|||||||
void onMapViewMoved(const Rect & visibleArea, int mapLevel);
|
void onMapViewMoved(const Rect & visibleArea, int mapLevel);
|
||||||
|
|
||||||
/// called by MapView whenever tile is clicked
|
/// called by MapView whenever tile is clicked
|
||||||
void onTileLeftClicked(const int3 & mapPos);
|
void onTileLeftClicked(const int3 & targetPosition);
|
||||||
|
|
||||||
/// called by MapView whenever tile is hovered
|
/// called by MapView whenever tile is hovered
|
||||||
void onTileHovered(const int3 & mapPos);
|
void onTileHovered(const int3 & targetPosition);
|
||||||
|
|
||||||
/// called by MapView whenever tile is clicked
|
/// called by MapView whenever tile is clicked
|
||||||
void onTileRightClicked(const int3 & mapPos);
|
void onTileRightClicked(const int3 & mapPos);
|
||||||
|
@@ -64,7 +64,7 @@ public:
|
|||||||
void removeMapObserver(IMapObjectObserver * observer);
|
void removeMapObserver(IMapObjectObserver * observer);
|
||||||
|
|
||||||
/// returns string description for terrain interaction
|
/// returns string description for terrain interaction
|
||||||
std::string getTerrainDescr(const int3 & pos, bool rightClick) const;
|
std::string getTerrainDescr(const int3 & pos, bool rightClick) const; //TODO: possible to get info about invisible tiles from client without serverside validation
|
||||||
|
|
||||||
/// determines if the map is ready to handle new hero movement (not available during fading animations)
|
/// determines if the map is ready to handle new hero movement (not available during fading animations)
|
||||||
bool hasOngoingAnimations();
|
bool hasOngoingAnimations();
|
||||||
|
@@ -440,7 +440,7 @@ bool CGameInfoCallback::isVisible(const CGObjectInstance *obj) const
|
|||||||
// return armi;
|
// return armi;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
std::vector < const CGObjectInstance * > CGameInfoCallback::getBlockingObjs( int3 pos ) const
|
std::vector <const CGObjectInstance *> CGameInfoCallback::getBlockingObjs( int3 pos ) const
|
||||||
{
|
{
|
||||||
std::vector<const CGObjectInstance *> ret;
|
std::vector<const CGObjectInstance *> ret;
|
||||||
const TerrainTile *t = getTile(pos);
|
const TerrainTile *t = getTile(pos);
|
||||||
@@ -451,7 +451,7 @@ std::vector < const CGObjectInstance * > CGameInfoCallback::getBlockingObjs( int
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector <const CGObjectInstance * > CGameInfoCallback::getVisitableObjs(int3 pos, bool verbose) const
|
std::vector <const CGObjectInstance *> CGameInfoCallback::getVisitableObjs(int3 pos, bool verbose) const
|
||||||
{
|
{
|
||||||
std::vector<const CGObjectInstance *> ret;
|
std::vector<const CGObjectInstance *> ret;
|
||||||
const TerrainTile *t = getTile(pos, verbose);
|
const TerrainTile *t = getTile(pos, verbose);
|
||||||
@@ -470,7 +470,7 @@ const CGObjectInstance * CGameInfoCallback::getTopObj (int3 pos) const
|
|||||||
return vstd::backOrNull(getVisitableObjs(pos));
|
return vstd::backOrNull(getVisitableObjs(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector < const CGObjectInstance * > CGameInfoCallback::getFlaggableObjects(int3 pos) const
|
std::vector <const CGObjectInstance *> CGameInfoCallback::getFlaggableObjects(int3 pos) const
|
||||||
{
|
{
|
||||||
std::vector<const CGObjectInstance *> ret;
|
std::vector<const CGObjectInstance *> ret;
|
||||||
const TerrainTile *t = getTile(pos);
|
const TerrainTile *t = getTile(pos);
|
||||||
|
Reference in New Issue
Block a user