1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-27 21:49:10 +02:00

Merge pull request #1446 from dydzio0614/movement-points-show

Implement movement points info on ALT hold + tile mouse hover
This commit is contained in:
Ivan Savenko 2023-01-25 12:30:34 +02:00 committed by GitHub
commit 52ab0f9b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 12 deletions

View File

@ -1708,7 +1708,7 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
else
CCS->curh->set(Cursor::Map::POINTER);
}
else if(const CGHeroInstance * h = curHero())
else if(const CGHeroInstance * hero = curHero())
{
std::array<Cursor::Map, 4> cursorMove = { Cursor::Map::T1_MOVE, Cursor::Map::T2_MOVE, Cursor::Map::T3_MOVE, Cursor::Map::T4_MOVE, };
std::array<Cursor::Map, 4> cursorAttack = { Cursor::Map::T1_ATTACK, Cursor::Map::T2_ATTACK, Cursor::Map::T3_ATTACK, Cursor::Map::T4_ATTACK, };
@ -1718,16 +1718,21 @@ void CAdvMapInt::tileHovered(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> cursorSailVisit = { Cursor::Map::T1_SAIL_VISIT, Cursor::Map::T2_SAIL_VISIT, Cursor::Map::T3_SAIL_VISIT, Cursor::Map::T4_SAIL_VISIT, };
const CGPathNode * pnode = LOCPLINT->cb->getPathsInfo(h)->getPathInfo(mapPos);
assert(pnode);
const CGPathNode * pathNode = LOCPLINT->cb->getPathsInfo(hero)->getPathInfo(mapPos);
assert(pathNode);
int turns = pnode->turns;
if(LOCPLINT->altPressed() && pathNode->reachable()) //overwrite status bar text with movement info
{
ShowMoveDetailsInStatusbar(*hero, *pathNode);
}
int turns = pathNode->turns;
vstd::amin(turns, 3);
switch(pnode->action)
switch(pathNode->action)
{
case CGPathNode::NORMAL:
case CGPathNode::TELEPORT_NORMAL:
if(pnode->layer == EPathfindingLayer::LAND)
if(pathNode->layer == EPathfindingLayer::LAND)
CCS->curh->set(cursorMove[turns]);
else
CCS->curh->set(cursorSailVisit[turns]);
@ -1743,7 +1748,7 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
else
CCS->curh->set(cursorExchange[turns]);
}
else if(pnode->layer == EPathfindingLayer::LAND)
else if(pathNode->layer == EPathfindingLayer::LAND)
CCS->curh->set(cursorVisit[turns]);
else
CCS->curh->set(cursorSailVisit[turns]);
@ -1784,6 +1789,21 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
}
}
void CAdvMapInt::ShowMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode)
{
const int maxMovementPointsAtStartOfLastTurn = pathNode.turns > 0 ? hero.maxMovePoints(pathNode.layer == EPathfindingLayer::LAND) : hero.movement;
const int movementPointsLastTurnCost = maxMovementPointsAtStartOfLastTurn - pathNode.moveRemains;
const int remainingPointsAfterMove = pathNode.turns == 0 ? pathNode.moveRemains : 0;
std::string result = VLC->generaltexth->translate("vcmi.adventureMap", pathNode.turns > 0 ? "moveCostDetails" : "moveCostDetailsNoTurns");
boost::replace_first(result, "%TURNS", std::to_string(pathNode.turns));
boost::replace_first(result, "%POINTS", std::to_string(movementPointsLastTurnCost));
boost::replace_first(result, "%REMAINING", std::to_string(remainingPointsAfterMove));
statusbar->write(result);
}
void CAdvMapInt::tileRClicked(const int3 &mapPos)
{
if(mode != EAdvMapMode::NORMAL)

View File

@ -20,6 +20,7 @@
VCMI_LIB_NAMESPACE_BEGIN
struct CGPath;
struct CGPathNode;
class CGHeroInstance;
class CGTownInstance;
class CSpell;
@ -269,6 +270,8 @@ public:
void handleMapScrollingUpdate();
void handleSwipeUpdate();
private:
void ShowMoveDetailsInStatusbar(const CGHeroInstance & hero, const CGPathNode & pathNode);
};
extern std::shared_ptr<CAdvMapInt> adventureInt;

View File

@ -13,11 +13,13 @@
"vcmi.adventureMap.monsterThreat.levels.10" : "Deadly",
"vcmi.adventureMap.monsterThreat.levels.11" : "Impossible",
"vcmi.adventureMap.confirmRestartGame" : "Are you sure you want to restart game?",
"vcmi.adventureMap.noTownWithMarket" : "No available marketplace!",
"vcmi.adventureMap.noTownWithTavern" : "No available town with tavern!",
"vcmi.adventureMap.spellUnknownProblem" : "Unknown problem with this spell, no more information available.",
"vcmi.adventureMap.playerAttacked" : "Player has been attacked: %s",
"vcmi.adventureMap.confirmRestartGame" : "Are you sure you want to restart game?",
"vcmi.adventureMap.noTownWithMarket" : "No available marketplace!",
"vcmi.adventureMap.noTownWithTavern" : "No available town with tavern!",
"vcmi.adventureMap.spellUnknownProblem" : "Unknown problem with this spell, no more information available.",
"vcmi.adventureMap.playerAttacked" : "Player has been attacked: %s",
"vcmi.adventureMap.moveCostDetails" : "Movement points - Cost: %TURNS turns + %POINTS points, Remaining points: %REMAINING",
"vcmi.adventureMap.moveCostDetailsNoTurns" : "Movement points - Cost: %POINTS points, Remaining points: %REMAINING",
"vcmi.server.errors.existingProcess" : "Another vcmiserver process is running, please terminate it first",
"vcmi.server.errors.modsIncompatibility" : "Required mods to load game:",