1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-15 20:03:15 +02:00

Extract method and make customizable movement points string

This commit is contained in:
Dydzio
2023-01-21 15:30:32 +01:00
parent c886a2a02b
commit 192a97bc05
3 changed files with 34 additions and 21 deletions

View File

@@ -1708,7 +1708,7 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
else else
CCS->curh->set(Cursor::Map::POINTER); 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> 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, }; std::array<Cursor::Map, 4> cursorAttack = { Cursor::Map::T1_ATTACK, Cursor::Map::T2_ATTACK, Cursor::Map::T3_ATTACK, Cursor::Map::T4_ATTACK, };
@@ -1718,28 +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> 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 * pnode = LOCPLINT->cb->getPathsInfo(h)->getPathInfo(mapPos); const CGPathNode * pathNode = LOCPLINT->cb->getPathsInfo(hero)->getPathInfo(mapPos);
assert(pnode); assert(pathNode);
if(LOCPLINT->altPressed() && pnode->reachable()) //overwrite status bar text with movement info if(LOCPLINT->altPressed() && pathNode->reachable()) //overwrite status bar text with movement info
{ {
const int maxMovementPointsForDestinationLastTurn = pnode->turns > 0 ? h->maxMovePoints(pnode->layer == EPathfindingLayer::LAND) : h->movement; ShowMoveDetailsInStatusbar(*hero, *pathNode);
const int movementPointsLastTurnCost = maxMovementPointsForDestinationLastTurn - pnode->moveRemains;
const int remainingPointsAfterMove = pnode->turns == 0 ? pnode->moveRemains : 0;
const std::string costWord = VLC->generaltexth->allTexts[346];
const std::string leftWord = VLC->generaltexth->allTexts[200];
const std::string turnsCount = pnode->turns > 0 ? std::to_string(pnode->turns) + "T + " : "";
statusbar->write(costWord + ": " + turnsCount + std::to_string(movementPointsLastTurnCost) + ", " + leftWord + ": " + std::to_string(remainingPointsAfterMove));
} }
int turns = pnode->turns; int turns = pathNode->turns;
vstd::amin(turns, 3); vstd::amin(turns, 3);
switch(pnode->action) switch(pathNode->action)
{ {
case CGPathNode::NORMAL: case CGPathNode::NORMAL:
case CGPathNode::TELEPORT_NORMAL: case CGPathNode::TELEPORT_NORMAL:
if(pnode->layer == EPathfindingLayer::LAND) if(pathNode->layer == EPathfindingLayer::LAND)
CCS->curh->set(cursorMove[turns]); CCS->curh->set(cursorMove[turns]);
else else
CCS->curh->set(cursorSailVisit[turns]); CCS->curh->set(cursorSailVisit[turns]);
@@ -1755,7 +1748,7 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
else else
CCS->curh->set(cursorExchange[turns]); CCS->curh->set(cursorExchange[turns]);
} }
else if(pnode->layer == EPathfindingLayer::LAND) else if(pathNode->layer == EPathfindingLayer::LAND)
CCS->curh->set(cursorVisit[turns]); CCS->curh->set(cursorVisit[turns]);
else else
CCS->curh->set(cursorSailVisit[turns]); CCS->curh->set(cursorSailVisit[turns]);
@@ -1796,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) void CAdvMapInt::tileRClicked(const int3 &mapPos)
{ {
if(mode != EAdvMapMode::NORMAL) if(mode != EAdvMapMode::NORMAL)

View File

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

View File

@@ -18,6 +18,8 @@
"vcmi.adventureMap.noTownWithTavern" : "No available town with tavern!", "vcmi.adventureMap.noTownWithTavern" : "No available town with tavern!",
"vcmi.adventureMap.spellUnknownProblem" : "Unknown problem with this spell, no more information available.", "vcmi.adventureMap.spellUnknownProblem" : "Unknown problem with this spell, no more information available.",
"vcmi.adventureMap.playerAttacked" : "Player has been attacked: %s", "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.existingProcess" : "Another vcmiserver process is running, please terminate it first",
"vcmi.server.errors.modsIncompatibility" : "Required mods to load game:", "vcmi.server.errors.modsIncompatibility" : "Required mods to load game:",