1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-23 12:08:45 +02:00

All adventure map components now use shared_ptr

This commit is contained in:
Ivan Savenko 2023-02-10 16:26:32 +02:00
parent f8c1c46562
commit cc0c3e5bc9
6 changed files with 150 additions and 134 deletions

View File

@ -13,6 +13,10 @@
#include "adventureMap/CAdvMapInt.h" #include "adventureMap/CAdvMapInt.h"
#include "adventureMap/mapHandler.h" #include "adventureMap/mapHandler.h"
#include "adventureMap/CList.h"
#include "adventureMap/CTerrainRect.h"
#include "adventureMap/CInfoBar.h"
#include "adventureMap/CMinimap.h"
#include "battle/BattleInterface.h" #include "battle/BattleInterface.h"
#include "battle/BattleEffectsController.h" #include "battle/BattleEffectsController.h"
#include "battle/BattleFieldController.h" #include "battle/BattleFieldController.h"
@ -251,13 +255,13 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
return; return;
} }
adventureInt->minimap.updateTile(hero->convertToVisitablePos(details.start)); adventureInt->minimap->updateTile(hero->convertToVisitablePos(details.start));
adventureInt->minimap.updateTile(hero->convertToVisitablePos(details.end)); adventureInt->minimap->updateTile(hero->convertToVisitablePos(details.end));
bool directlyAttackingCreature = bool directlyAttackingCreature =
details.attackedFrom details.attackedFrom
&& adventureInt->terrain.currentPath //in case if movement has been canceled in the meantime and path was already erased && adventureInt->terrain->currentPath //in case if movement has been canceled in the meantime and path was already erased
&& adventureInt->terrain.currentPath->nodes.size() == 3;//FIXME should be 2 but works nevertheless... && adventureInt->terrain->currentPath->nodes.size() == 3;//FIXME should be 2 but works nevertheless...
if(makingTurn && hero->tempOwner == playerID) //we are moving our hero - we may need to update assigned path if(makingTurn && hero->tempOwner == playerID) //we are moving our hero - we may need to update assigned path
{ {
@ -267,10 +271,10 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
if(details.result == TryMoveHero::TELEPORTATION) if(details.result == TryMoveHero::TELEPORTATION)
{ {
if(adventureInt->terrain.currentPath) if(adventureInt->terrain->currentPath)
{ {
assert(adventureInt->terrain.currentPath->nodes.size() >= 2); assert(adventureInt->terrain->currentPath->nodes.size() >= 2);
std::vector<CGPathNode>::const_iterator nodesIt = adventureInt->terrain.currentPath->nodes.end() - 1; std::vector<CGPathNode>::const_iterator nodesIt = adventureInt->terrain->currentPath->nodes.end() - 1;
if((nodesIt)->coord == hero->convertToVisitablePos(details.start) if((nodesIt)->coord == hero->convertToVisitablePos(details.start)
&& (nodesIt - 1)->coord == hero->convertToVisitablePos(details.end)) && (nodesIt - 1)->coord == hero->convertToVisitablePos(details.end))
@ -286,8 +290,8 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
} }
} }
adventureInt->centerOn(hero, true); //actualizing screen pos adventureInt->centerOn(hero, true); //actualizing screen pos
adventureInt->minimap.redraw(); adventureInt->minimap->redraw();
adventureInt->heroList.update(hero); adventureInt->heroList->update(hero);
return; //teleport - no fancy moving animation return; //teleport - no fancy moving animation
//TODO: smooth disappear / appear effect //TODO: smooth disappear / appear effect
} }
@ -297,7 +301,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
{ {
eraseCurrentPathOf(hero, false); eraseCurrentPathOf(hero, false);
} }
else if(adventureInt->terrain.currentPath && hero->pos == details.end) //&& hero is moving else if(adventureInt->terrain->currentPath && hero->pos == details.end) //&& hero is moving
{ {
if(details.start != details.end) //so we don't touch path when revisiting with spacebar if(details.start != details.end) //so we don't touch path when revisiting with spacebar
removeLastNodeFromPath(hero); removeLastNodeFromPath(hero);
@ -309,7 +313,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
hero->isStanding = true; hero->isStanding = true;
stillMoveHero.setn(STOP_MOVE); stillMoveHero.setn(STOP_MOVE);
GH.totalRedraw(); GH.totalRedraw();
adventureInt->heroList.update(hero); adventureInt->heroList->update(hero);
return; return;
} }
@ -333,8 +337,8 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
} }
adventureInt->centerOn(hero); //actualizing screen pos adventureInt->centerOn(hero); //actualizing screen pos
adventureInt->minimap.redraw(); adventureInt->minimap->redraw();
adventureInt->heroList.redraw(); adventureInt->heroList->redraw();
initMovement(details, hero, hp); initMovement(details, hero, hp);
@ -370,8 +374,8 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
hero->isStanding = true; hero->isStanding = true;
//move finished //move finished
adventureInt->minimap.redraw(); adventureInt->minimap->redraw();
adventureInt->heroList.update(hero); adventureInt->heroList->update(hero);
//check if user cancelled movement //check if user cancelled movement
{ {
@ -434,7 +438,7 @@ void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
wanderingHeroes -= hero; wanderingHeroes -= hero;
adventureInt->heroList.update(hero); adventureInt->heroList->update(hero);
if (makingTurn && newSelection) if (makingTurn && newSelection)
adventureInt->select(newSelection, true); adventureInt->select(newSelection, true);
else if (adventureInt->selection == hero) else if (adventureInt->selection == hero)
@ -458,7 +462,7 @@ void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
wanderingHeroes.push_back(hero); wanderingHeroes.push_back(hero);
adventureInt->heroList.update(hero); adventureInt->heroList->update(hero);
} }
void CPlayerInterface::openTownWindow(const CGTownInstance * town) void CPlayerInterface::openTownWindow(const CGTownInstance * town)
{ {
@ -477,10 +481,10 @@ int3 CPlayerInterface::repairScreenPos(int3 pos)
pos.x = -CGI->mh->frameW; pos.x = -CGI->mh->frameW;
if (pos.y<-CGI->mh->frameH) if (pos.y<-CGI->mh->frameH)
pos.y = -CGI->mh->frameH; pos.y = -CGI->mh->frameH;
if (pos.x>CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW) if (pos.x>CGI->mh->sizes.x - adventureInt->terrain->tilesw + CGI->mh->frameW)
pos.x = CGI->mh->sizes.x - adventureInt->terrain.tilesw + CGI->mh->frameW; pos.x = CGI->mh->sizes.x - adventureInt->terrain->tilesw + CGI->mh->frameW;
if (pos.y>CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH) if (pos.y>CGI->mh->sizes.y - adventureInt->terrain->tilesh + CGI->mh->frameH)
pos.y = CGI->mh->sizes.y - adventureInt->terrain.tilesh + CGI->mh->frameH; pos.y = CGI->mh->sizes.y - adventureInt->terrain->tilesh + CGI->mh->frameH;
return pos; return pos;
} }
@ -488,7 +492,7 @@ void CPlayerInterface::activateForSpectator()
{ {
adventureInt->state = CAdvMapInt::INGAME; adventureInt->state = CAdvMapInt::INGAME;
adventureInt->activate(); adventureInt->activate();
adventureInt->minimap.activate(); adventureInt->minimap->activate();
} }
void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val) void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val)
@ -518,13 +522,13 @@ void CPlayerInterface::heroManaPointsChanged(const CGHeroInstance * hero)
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
updateInfo(hero); updateInfo(hero);
if (makingTurn && hero->tempOwner == playerID) if (makingTurn && hero->tempOwner == playerID)
adventureInt->heroList.update(hero); adventureInt->heroList->update(hero);
} }
void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero) void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
if (makingTurn && hero->tempOwner == playerID) if (makingTurn && hero->tempOwner == playerID)
adventureInt->heroList.update(hero); adventureInt->heroList->update(hero);
} }
void CPlayerInterface::receivedResource() void CPlayerInterface::receivedResource()
{ {
@ -575,7 +579,7 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
if (town->visitingHero->tempOwner == playerID && !vstd::contains(wanderingHeroes,town->visitingHero)) // our hero if (town->visitingHero->tempOwner == playerID && !vstd::contains(wanderingHeroes,town->visitingHero)) // our hero
wanderingHeroes.push_back(town->visitingHero); wanderingHeroes.push_back(town->visitingHero);
} }
adventureInt->heroList.update(); adventureInt->heroList->update();
adventureInt->updateNextHero(nullptr); adventureInt->updateNextHero(nullptr);
if(castleInt) if(castleInt)
@ -681,7 +685,7 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, BuildingID build
} }
} }
} }
adventureInt->townList.update(town); adventureInt->townList->update(town);
} }
void CPlayerInterface::battleStartBefore(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2) void CPlayerInterface::battleStartBefore(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2)
@ -1039,7 +1043,7 @@ void CPlayerInterface::showComp(const Component &comp, std::string message)
waitWhileDialog(); //Fix for mantis #98 waitWhileDialog(); //Fix for mantis #98
CCS->soundh->playSoundFromSet(CCS->soundh->pickupSounds); CCS->soundh->playSoundFromSet(CCS->soundh->pickupSounds);
adventureInt->infoBar.showComponent(comp, message); adventureInt->infoBar->showComponent(comp, message);
} }
void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<Component> & components, int soundID) void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector<Component> & components, int soundID)
@ -1197,7 +1201,7 @@ void CPlayerInterface::tileRevealed(const std::unordered_set<int3, ShashInt3> &p
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
//FIXME: wait for dialog? Magi hut/eye would benefit from this but may break other areas //FIXME: wait for dialog? Magi hut/eye would benefit from this but may break other areas
for (auto & po : pos) for (auto & po : pos)
adventureInt->minimap.updateTile(po); adventureInt->minimap->updateTile(po);
if (!pos.empty()) if (!pos.empty())
GH.totalRedraw(); GH.totalRedraw();
} }
@ -1206,7 +1210,7 @@ void CPlayerInterface::tileHidden(const std::unordered_set<int3, ShashInt3> &pos
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
for (auto & po : pos) for (auto & po : pos)
adventureInt->minimap.updateTile(po); adventureInt->minimap->updateTile(po);
if (!pos.empty()) if (!pos.empty())
GH.totalRedraw(); GH.totalRedraw();
} }
@ -1335,7 +1339,7 @@ void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHer
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
auto onEnd = [=](){ cb->selectionMade(0, queryID); }; auto onEnd = [=](){ cb->selectionMade(0, queryID); };
if (stillMoveHero.get() == DURING_MOVE && adventureInt->terrain.currentPath && adventureInt->terrain.currentPath->nodes.size() > 1) //to ignore calls on passing through garrisons if (stillMoveHero.get() == DURING_MOVE && adventureInt->terrain->currentPath && adventureInt->terrain->currentPath->nodes.size() > 1) //to ignore calls on passing through garrisons
{ {
onEnd(); onEnd();
return; return;
@ -1412,7 +1416,7 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
for(auto & po : pos) for(auto & po : pos)
{ {
if(cb->isVisible(po)) if(cb->isVisible(po))
adventureInt->minimap.updateTile(po); adventureInt->minimap->updateTile(po);
} }
if(obj->ID == Obj::TOWN) if(obj->ID == Obj::TOWN)
{ {
@ -1421,8 +1425,8 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
else else
towns -= obj; towns -= obj;
adventureInt->townList.update(); adventureInt->townList->update();
adventureInt->minimap.update(); adventureInt->minimap->update();
} }
assert(cb->getTownsInfo().size() == towns.size()); assert(cb->getTownsInfo().size() == towns.size());
} }
@ -1715,8 +1719,8 @@ void CPlayerInterface::movementPxStep( const TryMoveHero &details, int i, const
} }
} }
adventureInt->terrain.moveX = (32 - i) * (heroImageNewX - heroImageOldX) / 32; adventureInt->terrain->moveX = (32 - i) * (heroImageNewX - heroImageOldX) / 32;
adventureInt->terrain.moveY = (32 - i) * (heroImageNewY - heroImageOldY) / 32; adventureInt->terrain->moveY = (32 - i) * (heroImageNewY - heroImageOldY) / 32;
} }
void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &hp, const CGHeroInstance * ho ) void CPlayerInterface::finishMovement( const TryMoveHero &details, const int3 &hp, const CGHeroInstance * ho )
@ -1894,14 +1898,14 @@ void CPlayerInterface::eraseCurrentPathOf(const CGHeroInstance * ho, bool checkF
assert(ho == adventureInt->selection); assert(ho == adventureInt->selection);
paths.erase(ho); paths.erase(ho);
adventureInt->terrain.currentPath = nullptr; adventureInt->terrain->currentPath = nullptr;
adventureInt->updateMoveHero(ho, false); adventureInt->updateMoveHero(ho, false);
} }
void CPlayerInterface::removeLastNodeFromPath(const CGHeroInstance *ho) void CPlayerInterface::removeLastNodeFromPath(const CGHeroInstance *ho)
{ {
adventureInt->terrain.currentPath->nodes.erase(adventureInt->terrain.currentPath->nodes.end()-1); adventureInt->terrain->currentPath->nodes.erase(adventureInt->terrain->currentPath->nodes.end()-1);
if (adventureInt->terrain.currentPath->nodes.size() < 2) //if it was the last one, remove entire path and path with only one tile is not a real path if (adventureInt->terrain->currentPath->nodes.size() < 2) //if it was the last one, remove entire path and path with only one tile is not a real path
eraseCurrentPathOf(ho); eraseCurrentPathOf(ho);
} }
@ -1946,8 +1950,8 @@ void CPlayerInterface::acceptTurn()
adventureInt->startTurn(); adventureInt->startTurn();
} }
adventureInt->heroList.update(); adventureInt->heroList->update();
adventureInt->townList.update(); adventureInt->townList->update();
const CGHeroInstance * heroToSelect = nullptr; const CGHeroInstance * heroToSelect = nullptr;
@ -1972,7 +1976,7 @@ void CPlayerInterface::acceptTurn()
adventureInt->select(wanderingHeroes.front()); adventureInt->select(wanderingHeroes.front());
//show new day animation and sound on infobar //show new day animation and sound on infobar
adventureInt->infoBar.showDate(); adventureInt->infoBar->showDate();
adventureInt->updateNextHero(nullptr); adventureInt->updateNextHero(nullptr);
adventureInt->showAll(screen); adventureInt->showAll(screen);
@ -2052,7 +2056,7 @@ void CPlayerInterface::tryDiggging(const CGHeroInstance * h)
void CPlayerInterface::updateInfo(const CGObjectInstance * specific) void CPlayerInterface::updateInfo(const CGObjectInstance * specific)
{ {
adventureInt->infoBar.showSelection(); adventureInt->infoBar->showSelection();
} }
void CPlayerInterface::battleNewRoundFirst( int round ) void CPlayerInterface::battleNewRoundFirst( int round )
@ -2163,14 +2167,14 @@ void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
void CPlayerInterface::artifactPut(const ArtifactLocation &al) void CPlayerInterface::artifactPut(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->infoBar.showSelection(); adventureInt->infoBar->showSelection();
askToAssembleArtifact(al); askToAssembleArtifact(al);
} }
void CPlayerInterface::artifactRemoved(const ArtifactLocation &al) void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->infoBar.showSelection(); adventureInt->infoBar->showSelection();
for(auto isa : GH.listInt) for(auto isa : GH.listInt)
{ {
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get()); auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@ -2184,7 +2188,7 @@ void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst) void CPlayerInterface::artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->infoBar.showSelection(); adventureInt->infoBar->showSelection();
for(auto isa : GH.listInt) for(auto isa : GH.listInt)
{ {
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get()); auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@ -2205,7 +2209,7 @@ void CPlayerInterface::artifactPossibleAssembling(const ArtifactLocation & dst)
void CPlayerInterface::artifactAssembled(const ArtifactLocation &al) void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->infoBar.showSelection(); adventureInt->infoBar->showSelection();
for(auto isa : GH.listInt) for(auto isa : GH.listInt)
{ {
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get()); auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@ -2217,7 +2221,7 @@ void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al) void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
{ {
EVENT_HANDLER_CALLED_BY_CLIENT; EVENT_HANDLER_CALLED_BY_CLIENT;
adventureInt->infoBar.showSelection(); adventureInt->infoBar->showSelection();
for(auto isa : GH.listInt) for(auto isa : GH.listInt)
{ {
auto artWin = dynamic_cast<CArtifactHolder*>(isa.get()); auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@ -2236,7 +2240,7 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player)
} }
else else
{ {
adventureInt->infoBar.showSelection(); adventureInt->infoBar->showSelection();
while (GH.listInt.front() != adventureInt && !dynamic_cast<CInfoWindow*>(GH.listInt.front().get())) //don't remove dialogs that expect query answer while (GH.listInt.front() != adventureInt && !dynamic_cast<CInfoWindow*>(GH.listInt.front().get())) //don't remove dialogs that expect query answer
GH.popInts(1); GH.popInts(1);
} }

View File

@ -13,6 +13,11 @@
#include "CAdvMapPanel.h" #include "CAdvMapPanel.h"
#include "CAdventureOptions.h" #include "CAdventureOptions.h"
#include "CInGameConsole.h" #include "CInGameConsole.h"
#include "CMinimap.h"
#include "CResDataBar.h"
#include "CTerrainRect.h"
#include "CList.h"
#include "CInfoBar.h"
#include "mapHandler.h" #include "mapHandler.h"
#include "../windows/CKingdomInterface.h" #include "../windows/CKingdomInterface.h"
@ -76,11 +81,14 @@ static void setScrollingCursor(ui8 direction)
CAdvMapInt::CAdvMapInt(): CAdvMapInt::CAdvMapInt():
mode(EAdvMapMode::NORMAL), mode(EAdvMapMode::NORMAL),
worldViewScale(0.0f), //actual init later in changeMode worldViewScale(0.0f), //actual init later in changeMode
minimap(Rect(ADVOPT.minimapX, ADVOPT.minimapY, ADVOPT.minimapW, ADVOPT.minimapH)), minimap(new CMinimap(Rect(ADVOPT.minimapX, ADVOPT.minimapY, ADVOPT.minimapW, ADVOPT.minimapH))),
statusbar(CGStatusBar::create(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG)), statusbar(CGStatusBar::create(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG)),
heroList(ADVOPT.hlistSize, Point(ADVOPT.hlistX, ADVOPT.hlistY), ADVOPT.hlistAU, ADVOPT.hlistAD), heroList(new CHeroList(ADVOPT.hlistSize, Point(ADVOPT.hlistX, ADVOPT.hlistY), ADVOPT.hlistAU, ADVOPT.hlistAD)),
townList(ADVOPT.tlistSize, Point(ADVOPT.tlistX, ADVOPT.tlistY), ADVOPT.tlistAU, ADVOPT.tlistAD), townList(new CTownList(ADVOPT.tlistSize, Point(ADVOPT.tlistX, ADVOPT.tlistY), ADVOPT.tlistAU, ADVOPT.tlistAD)),
infoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192)), state(NA), infoBar(new CInfoBar(Rect(ADVOPT.infoboxX, ADVOPT.infoboxY, 192, 192))),
resdatabar(new CResDataBar),
terrain(new CTerrainRect),
state(NA),
spellBeingCasted(nullptr), position(int3(0, 0, 0)), selection(nullptr), spellBeingCasted(nullptr), position(int3(0, 0, 0)), selection(nullptr),
updateScreen(false), anim(0), animValHitCount(0), heroAnim(0), heroAnimValHitCount(0), updateScreen(false), anim(0), animValHitCount(0), heroAnim(0), heroAnimValHitCount(0),
activeMapPanel(nullptr), duringAITurn(false), scrollingDir(0), scrollingState(false), activeMapPanel(nullptr), duringAITurn(false), scrollingDir(0), scrollingState(false),
@ -91,7 +99,7 @@ CAdvMapInt::CAdvMapInt():
pos.w = GH.screenDimensions().x; pos.w = GH.screenDimensions().x;
pos.h = GH.screenDimensions().y; pos.h = GH.screenDimensions().y;
strongInterest = true; // handle all mouse move events to prevent dead mouse move space in fullscreen mode strongInterest = true; // handle all mouse move events to prevent dead mouse move space in fullscreen mode
townList.onSelect = std::bind(&CAdvMapInt::selectionChanged,this); townList->onSelect = std::bind(&CAdvMapInt::selectionChanged,this);
bg = IImage::createFromFile(ADVOPT.mainGraphic); bg = IImage::createFromFile(ADVOPT.mainGraphic);
if(!ADVOPT.worldViewGraphic.empty()) if(!ADVOPT.worldViewGraphic.empty())
{ {
@ -135,11 +143,11 @@ CAdvMapInt::CAdvMapInt():
nextHero = makeButton(301, std::bind(&CAdvMapInt::fnextHero,this), ADVOPT.nextHero, SDLK_h); nextHero = makeButton(301, std::bind(&CAdvMapInt::fnextHero,this), ADVOPT.nextHero, SDLK_h);
endTurn = makeButton(302, std::bind(&CAdvMapInt::fendTurn,this), ADVOPT.endTurn, SDLK_e); endTurn = makeButton(302, std::bind(&CAdvMapInt::fendTurn,this), ADVOPT.endTurn, SDLK_e);
int panelSpaceBottom = GH.screenDimensions().y - resdatabar.pos.h - 4; int panelSpaceBottom = GH.screenDimensions().y - resdatabar->pos.h - 4;
panelMain = std::make_shared<CAdvMapPanel>(nullptr, Point(0, 0)); panelMain = std::make_shared<CAdvMapPanel>(nullptr, Point(0, 0));
// TODO correct drawing position // TODO correct drawing position
panelWorldView = std::make_shared<CAdvMapWorldViewPanel>(worldViewIcons, bgWorldView, Point(heroList.pos.x - 2, 195), panelSpaceBottom, LOCPLINT->playerID); panelWorldView = std::make_shared<CAdvMapWorldViewPanel>(worldViewIcons, bgWorldView, Point(heroList->pos.x - 2, 195), panelSpaceBottom, LOCPLINT->playerID);
panelMain->addChildColorableButton(kingOverview); panelMain->addChildColorableButton(kingOverview);
panelMain->addChildColorableButton(underground); panelMain->addChildColorableButton(underground);
@ -207,7 +215,7 @@ CAdvMapInt::CAdvMapInt():
setPlayer(LOCPLINT->playerID); setPlayer(LOCPLINT->playerID);
int iconColorMultiplier = player.getNum() * 19; int iconColorMultiplier = player.getNum() * 19;
int wvLeft = heroList.pos.x - 2; // TODO correct drawing position int wvLeft = heroList->pos.x - 2; // TODO correct drawing position
//int wvTop = 195; //int wvTop = 195;
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i)
{ {
@ -285,10 +293,10 @@ void CAdvMapInt::fswitchLevel()
worldViewUnderground->redraw(); worldViewUnderground->redraw();
updateScreen = true; updateScreen = true;
minimap.setLevel(position.z); minimap->setLevel(position.z);
if (mode == EAdvMapMode::WORLD_VIEW) if (mode == EAdvMapMode::WORLD_VIEW)
terrain.redraw(); terrain->redraw();
} }
void CAdvMapInt::fshowQuestlog() void CAdvMapInt::fshowQuestlog()
{ {
@ -315,10 +323,10 @@ void CAdvMapInt::fsleepWake()
void CAdvMapInt::fmoveHero() void CAdvMapInt::fmoveHero()
{ {
const CGHeroInstance *h = curHero(); const CGHeroInstance *h = curHero();
if (!h || !terrain.currentPath || !CGI->mh->canStartHeroMovement()) if (!h || !terrain->currentPath || !CGI->mh->canStartHeroMovement())
return; return;
LOCPLINT->moveHero(h, *terrain.currentPath); LOCPLINT->moveHero(h, *terrain->currentPath);
} }
void CAdvMapInt::fshowSpellbok() void CAdvMapInt::fshowSpellbok()
@ -461,12 +469,12 @@ void CAdvMapInt::activate()
activeMapPanel->activate(); activeMapPanel->activate();
if (mode == EAdvMapMode::NORMAL) if (mode == EAdvMapMode::NORMAL)
{ {
heroList.activate(); heroList->activate();
townList.activate(); townList->activate();
infoBar.activate(); infoBar->activate();
} }
minimap.activate(); minimap->activate();
terrain.activate(); terrain->activate();
statusbar->activate(); statusbar->activate();
GH.fakeMouseMove(); //to restore the cursor GH.fakeMouseMove(); //to restore the cursor
@ -485,12 +493,12 @@ void CAdvMapInt::deactivate()
activeMapPanel->deactivate(); activeMapPanel->deactivate();
if (mode == EAdvMapMode::NORMAL) if (mode == EAdvMapMode::NORMAL)
{ {
heroList.deactivate(); heroList->deactivate();
townList.deactivate(); townList->deactivate();
infoBar.deactivate(); infoBar->deactivate();
} }
minimap.deactivate(); minimap->deactivate();
terrain.deactivate(); terrain->deactivate();
statusbar->deactivate(); statusbar->deactivate();
} }
} }
@ -506,23 +514,23 @@ void CAdvMapInt::showAll(SDL_Surface * to)
{ {
case EAdvMapMode::NORMAL: case EAdvMapMode::NORMAL:
heroList.showAll(to); heroList->showAll(to);
townList.showAll(to); townList->showAll(to);
infoBar.showAll(to); infoBar->showAll(to);
break; break;
case EAdvMapMode::WORLD_VIEW: case EAdvMapMode::WORLD_VIEW:
terrain.showAll(to); terrain->showAll(to);
break; break;
} }
activeMapPanel->showAll(to); activeMapPanel->showAll(to);
updateScreen = true; updateScreen = true;
minimap.showAll(to); minimap->showAll(to);
show(to); show(to);
resdatabar.showAll(to); resdatabar->showAll(to);
statusbar->show(to); statusbar->show(to);
@ -592,20 +600,20 @@ void CAdvMapInt::show(SDL_Surface * to)
position = betterPos; position = betterPos;
} }
terrain.show(to); terrain->show(to);
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
gems[i]->showAll(to); gems[i]->showAll(to);
updateScreen=false; updateScreen=false;
LOCPLINT->cingconsole->show(to); LOCPLINT->cingconsole->show(to);
} }
else if (terrain.needsAnimUpdate()) else if (terrain->needsAnimUpdate())
{ {
terrain.showAnim(to); terrain->showAnim(to);
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
gems[i]->showAll(to); gems[i]->showAll(to);
} }
infoBar.show(to); infoBar->show(to);
statusbar->showAll(to); statusbar->showAll(to);
} }
@ -633,9 +641,9 @@ void CAdvMapInt::handleMapScrollingUpdate()
setScrollingCursor(scrollingDir); setScrollingCursor(scrollingDir);
scrollingState = true; scrollingState = true;
updateScreen = true; updateScreen = true;
minimap.redraw(); minimap->redraw();
if(mode == EAdvMapMode::WORLD_VIEW) if(mode == EAdvMapMode::WORLD_VIEW)
terrain.redraw(); terrain->redraw();
} }
else if(scrollingState) else if(scrollingState)
{ {
@ -654,14 +662,14 @@ void CAdvMapInt::handleSwipeUpdate()
position.y = fixedPos.y; position.y = fixedPos.y;
CCS->curh->set(Cursor::Map::POINTER); CCS->curh->set(Cursor::Map::POINTER);
updateScreen = true; updateScreen = true;
minimap.redraw(); minimap->redraw();
swipeMovementRequested = false; swipeMovementRequested = false;
} }
} }
void CAdvMapInt::selectionChanged() void CAdvMapInt::selectionChanged()
{ {
const CGTownInstance *to = LOCPLINT->towns[townList.getSelectedIndex()]; const CGTownInstance *to = LOCPLINT->towns[townList->getSelectedIndex()];
if (selection != to) if (selection != to)
select(to); select(to);
} }
@ -672,7 +680,7 @@ void CAdvMapInt::centerOn(int3 on, bool fade)
if (fade) if (fade)
{ {
terrain.fadeFromCurrentView(); terrain->fadeFromCurrentView();
} }
switch (mode) switch (mode)
@ -698,11 +706,11 @@ void CAdvMapInt::centerOn(int3 on, bool fade)
worldViewUnderground->setIndex(on.z, true); worldViewUnderground->setIndex(on.z, true);
worldViewUnderground->redraw(); worldViewUnderground->redraw();
if (switchedLevels) if (switchedLevels)
minimap.setLevel(position.z); minimap->setLevel(position.z);
minimap.redraw(); minimap->redraw();
if (mode == EAdvMapMode::WORLD_VIEW) if (mode == EAdvMapMode::WORLD_VIEW)
terrain.redraw(); terrain->redraw();
} }
void CAdvMapInt::centerOn(const CGObjectInstance * obj, bool fade) void CAdvMapInt::centerOn(const CGObjectInstance * obj, bool fade)
@ -853,7 +861,7 @@ void CAdvMapInt::keyPressed(const SDL_Keycode & key)
} }
else if(isActive()) //no ctrl, advmapint is on the top => switch to town else if(isActive()) //no ctrl, advmapint is on the top => switch to town
{ {
townList.selectNext(); townList->selectNext();
} }
return; return;
} }
@ -888,11 +896,11 @@ void CAdvMapInt::keyPressed(const SDL_Keycode & key)
} }
CGPath &path = LOCPLINT->paths[h]; CGPath &path = LOCPLINT->paths[h];
terrain.currentPath = &path; terrain->currentPath = &path;
int3 dst = h->visitablePos() + int3(direction->x, direction->y, 0); int3 dst = h->visitablePos() + int3(direction->x, direction->y, 0);
if(dst != verifyPos(dst) || !LOCPLINT->cb->getPathsInfo(h)->getPath(path, dst)) if(dst != verifyPos(dst) || !LOCPLINT->cb->getPathsInfo(h)->getPath(path, dst))
{ {
terrain.currentPath = nullptr; terrain->currentPath = nullptr;
return; return;
} }
@ -960,14 +968,14 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView)
if(centerView) if(centerView)
centerOn(sel); centerOn(sel);
terrain.currentPath = nullptr; terrain->currentPath = nullptr;
if(sel->ID==Obj::TOWN) if(sel->ID==Obj::TOWN)
{ {
auto town = dynamic_cast<const CGTownInstance*>(sel); auto town = dynamic_cast<const CGTownInstance*>(sel);
infoBar.showTownSelection(town); infoBar->showTownSelection(town);
townList.select(town); townList->select(town);
heroList.select(nullptr); heroList->select(nullptr);
updateSleepWake(nullptr); updateSleepWake(nullptr);
updateMoveHero(nullptr); updateMoveHero(nullptr);
@ -977,18 +985,18 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView)
{ {
auto hero = dynamic_cast<const CGHeroInstance*>(sel); auto hero = dynamic_cast<const CGHeroInstance*>(sel);
infoBar.showHeroSelection(hero); infoBar->showHeroSelection(hero);
heroList.select(hero); heroList->select(hero);
townList.select(nullptr); townList->select(nullptr);
terrain.currentPath = LOCPLINT->getAndVerifyPath(hero); terrain->currentPath = LOCPLINT->getAndVerifyPath(hero);
updateSleepWake(hero); updateSleepWake(hero);
updateMoveHero(hero); updateMoveHero(hero);
updateSpellbook(hero); updateSpellbook(hero);
} }
townList.redraw(); townList->redraw();
heroList.redraw(); heroList->redraw();
} }
void CAdvMapInt::mouseMoved( const Point & cursorPosition ) void CAdvMapInt::mouseMoved( const Point & cursorPosition )
@ -1055,7 +1063,7 @@ void CAdvMapInt::setPlayer(PlayerColor Player)
panelMain->setPlayerColor(player); panelMain->setPlayerColor(player);
panelWorldView->setPlayerColor(player); panelWorldView->setPlayerColor(player);
panelWorldView->recolorIcons(player, player.getNum() * 19); panelWorldView->recolorIcons(player, player.getNum() * 19);
resdatabar.background->colorize(player); resdatabar->background->colorize(player);
} }
void CAdvMapInt::startTurn() void CAdvMapInt::startTurn()
@ -1065,7 +1073,7 @@ void CAdvMapInt::startTurn()
|| settings["session"]["spectate"].Bool()) || settings["session"]["spectate"].Bool())
{ {
adjustActiveness(false); adjustActiveness(false);
minimap.setAIRadar(false); minimap->setAIRadar(false);
} }
} }
@ -1130,7 +1138,7 @@ void CAdvMapInt::tileLClicked(const int3 &mapPos)
bool isHero = false; bool isHero = false;
if(selection->ID != Obj::HERO) //hero is not selected (presumably town) if(selection->ID != Obj::HERO) //hero is not selected (presumably town)
{ {
assert(!terrain.currentPath); //path can be active only when hero is selected assert(!terrain->currentPath); //path can be active only when hero is selected
if(selection == topBlocking) //selected town clicked if(selection == topBlocking) //selected town clicked
LOCPLINT->openTownWindow(static_cast<const CGTownInstance*>(topBlocking)); LOCPLINT->openTownWindow(static_cast<const CGTownInstance*>(topBlocking));
else if(canSelect) else if(canSelect)
@ -1153,10 +1161,10 @@ void CAdvMapInt::tileLClicked(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(terrain.currentPath && terrain.currentPath->endPos() == mapPos)//we'll be moving if(terrain->currentPath && terrain->currentPath->endPos() == mapPos)//we'll be moving
{ {
if(CGI->mh->canStartHeroMovement()) if(CGI->mh->canStartHeroMovement())
LOCPLINT->moveHero(currentHero, *terrain.currentPath); LOCPLINT->moveHero(currentHero, *terrain->currentPath);
return; return;
} }
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
@ -1168,7 +1176,7 @@ void CAdvMapInt::tileLClicked(const int3 &mapPos)
path = newpath; path = newpath;
if(path.nodes.size()) if(path.nodes.size())
terrain.currentPath = &path; terrain->currentPath = &path;
else else
LOCPLINT->eraseCurrentPathOf(currentHero); LOCPLINT->eraseCurrentPathOf(currentHero);
@ -1386,7 +1394,7 @@ void CAdvMapInt::enterCastingMode(const CSpell * sp)
spellBeingCasted = sp; spellBeingCasted = sp;
deactivate(); deactivate();
terrain.activate(); terrain->activate();
GH.fakeMouseMove(); GH.fakeMouseMove();
} }
@ -1395,7 +1403,7 @@ void CAdvMapInt::leaveCastingMode(bool cast, int3 dest)
assert(spellBeingCasted); assert(spellBeingCasted);
SpellID id = spellBeingCasted->id; SpellID id = spellBeingCasted->id;
spellBeingCasted = nullptr; spellBeingCasted = nullptr;
terrain.deactivate(); terrain->deactivate();
activate(); activate();
if(cast) if(cast)
@ -1439,9 +1447,9 @@ void CAdvMapInt::aiTurnStarted()
adjustActiveness(true); adjustActiveness(true);
CCS->musich->playMusicFromSet("enemy-turn", true, false); CCS->musich->playMusicFromSet("enemy-turn", true, false);
adventureInt->minimap.setAIRadar(true); adventureInt->minimap->setAIRadar(true);
adventureInt->infoBar.startEnemyTurn(LOCPLINT->cb->getCurrentPlayer()); adventureInt->infoBar->startEnemyTurn(LOCPLINT->cb->getCurrentPlayer());
adventureInt->infoBar.showAll(screen);//force refresh on inactive object adventureInt->infoBar->showAll(screen);//force refresh on inactive object
} }
void CAdvMapInt::adjustActiveness(bool aiTurnStart) void CAdvMapInt::adjustActiveness(bool aiTurnStart)
@ -1480,9 +1488,9 @@ void CAdvMapInt::changeMode(EAdvMapMode newMode, float newScale)
panelWorldView->deactivate(); panelWorldView->deactivate();
activeMapPanel = panelMain; activeMapPanel = panelMain;
townList.activate(); townList->activate();
heroList.activate(); heroList->activate();
infoBar.activate(); infoBar->activate();
worldViewOptions.clear(); worldViewOptions.clear();
@ -1493,10 +1501,10 @@ void CAdvMapInt::changeMode(EAdvMapMode newMode, float newScale)
activeMapPanel = panelWorldView; activeMapPanel = panelWorldView;
townList.deactivate(); townList->deactivate();
heroList.deactivate(); heroList->deactivate();
infoBar.showSelection(); // to prevent new day animation interfering world view mode infoBar->showSelection(); // to prevent new day animation interfering world view mode
infoBar.deactivate(); infoBar->deactivate();
break; break;
} }

View File

@ -14,12 +14,6 @@
#include "../../lib/int3.h" #include "../../lib/int3.h"
#include "../../lib/GameConstants.h" #include "../../lib/GameConstants.h"
#include "CTerrainRect.h"
#include "CResDataBar.h"
#include "CList.h"
#include "CInfoBar.h"
#include "CMinimap.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
class CGObjectInstance; class CGObjectInstance;
@ -39,6 +33,12 @@ class CGStatusBar;
class CAdvMapPanel; class CAdvMapPanel;
class CAdvMapWorldViewPanel; class CAdvMapWorldViewPanel;
class CAnimation; class CAnimation;
class CTerrainRect;
class CResDataBar;
class CHeroList;
class CTownList;
class CInfoBar;
class CMinimap;
struct MapDrawingInfo; struct MapDrawingInfo;
@ -100,7 +100,7 @@ public:
std::shared_ptr<IImage> bg; std::shared_ptr<IImage> bg;
std::shared_ptr<IImage> bgWorldView; std::shared_ptr<IImage> bgWorldView;
std::vector<std::shared_ptr<CAnimImage>> gems; std::vector<std::shared_ptr<CAnimImage>> gems;
CMinimap minimap; std::shared_ptr<CMinimap> minimap;
std::shared_ptr<CGStatusBar> statusbar; std::shared_ptr<CGStatusBar> statusbar;
std::shared_ptr<CButton> kingOverview; std::shared_ptr<CButton> kingOverview;
@ -116,11 +116,11 @@ public:
std::shared_ptr<CButton> worldViewUnderground; std::shared_ptr<CButton> worldViewUnderground;
CTerrainRect terrain; //visible terrain std::shared_ptr<CTerrainRect> terrain; //visible terrain
CResDataBar resdatabar; std::shared_ptr<CResDataBar> resdatabar;
CHeroList heroList; std::shared_ptr<CHeroList> heroList;
CTownList townList; std::shared_ptr<CTownList> townList;
CInfoBar infoBar; std::shared_ptr<CInfoBar> infoBar;
std::shared_ptr<CAdvMapPanel> panelMain; // panel that holds all right-side buttons in normal view std::shared_ptr<CAdvMapPanel> panelMain; // panel that holds all right-side buttons in normal view
std::shared_ptr<CAdvMapWorldViewPanel> panelWorldView; // panel that holds all buttons and other ui in world view std::shared_ptr<CAdvMapWorldViewPanel> panelWorldView; // panel that holds all buttons and other ui in world view

View File

@ -12,6 +12,7 @@
#include "CMinimap.h" #include "CMinimap.h"
#include "CAdvMapInt.h" #include "CAdvMapInt.h"
#include "CTerrainRect.h"
#include "../widgets/Images.h" #include "../widgets/Images.h"
#include "../CGameInfo.h" #include "../CGameInfo.h"
@ -167,7 +168,7 @@ void CMinimap::showAll(SDL_Surface * to)
Canvas target(to); Canvas target(to);
int3 mapSizes = LOCPLINT->cb->getMapSize(); int3 mapSizes = LOCPLINT->cb->getMapSize();
int3 tileCountOnScreen = adventureInt->terrain.tileCountOnScreen(); int3 tileCountOnScreen = adventureInt->terrain->tileCountOnScreen();
//draw radar //draw radar
Rect radar = Rect radar =

View File

@ -28,6 +28,8 @@
#include "../render/IImage.h" #include "../render/IImage.h"
#include "../render/ColorFilter.h" #include "../render/ColorFilter.h"
#include "../adventureMap/CAdvMapInt.h" #include "../adventureMap/CAdvMapInt.h"
#include "../adventureMap/CList.h"
#include "../adventureMap/CResDataBar.h"
#include "../../CCallback.h" #include "../../CCallback.h"
#include "../../lib/CArtHandler.h" #include "../../lib/CArtHandler.h"

View File

@ -22,6 +22,7 @@
#include "../battle/BattleInterface.h" #include "../battle/BattleInterface.h"
#include "../battle/BattleInterfaceClasses.h" #include "../battle/BattleInterfaceClasses.h"
#include "../adventureMap/CAdvMapInt.h" #include "../adventureMap/CAdvMapInt.h"
#include "../adventureMap/CTerrainRect.h"
#include "../windows/CMessage.h" #include "../windows/CMessage.h"
#include "../renderSDL/SDL_Extensions.h" #include "../renderSDL/SDL_Extensions.h"
#include "../gui/CursorHandler.h" #include "../gui/CursorHandler.h"
@ -364,8 +365,8 @@ CRClickPopupInt::~CRClickPopupInt()
Point CInfoBoxPopup::toScreen(Point p) Point CInfoBoxPopup::toScreen(Point p)
{ {
vstd::abetween(p.x, adventureInt->terrain.pos.x + 100, adventureInt->terrain.pos.x + adventureInt->terrain.pos.w - 100); vstd::abetween(p.x, adventureInt->terrain->pos.x + 100, adventureInt->terrain->pos.x + adventureInt->terrain->pos.w - 100);
vstd::abetween(p.y, adventureInt->terrain.pos.y + 100, adventureInt->terrain.pos.y + adventureInt->terrain.pos.h - 100); vstd::abetween(p.y, adventureInt->terrain->pos.y + 100, adventureInt->terrain->pos.y + adventureInt->terrain->pos.h - 100);
return p; return p;
} }