瀏覽代碼

All adventure map components now use shared_ptr

Ivan Savenko 2 年之前
父節點
當前提交
cc0c3e5bc9

+ 52 - 48
client/CPlayerInterface.cpp

@@ -13,6 +13,10 @@
 
 #include "adventureMap/CAdvMapInt.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/BattleEffectsController.h"
 #include "battle/BattleFieldController.h"
@@ -251,13 +255,13 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
 			return;
 	}
 
-	adventureInt->minimap.updateTile(hero->convertToVisitablePos(details.start));
-	adventureInt->minimap.updateTile(hero->convertToVisitablePos(details.end));
+	adventureInt->minimap->updateTile(hero->convertToVisitablePos(details.start));
+	adventureInt->minimap->updateTile(hero->convertToVisitablePos(details.end));
 
 	bool directlyAttackingCreature =
 		details.attackedFrom
-		&& 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					//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...
 
 	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(adventureInt->terrain.currentPath)
+			if(adventureInt->terrain->currentPath)
 			{
-				assert(adventureInt->terrain.currentPath->nodes.size() >= 2);
-				std::vector<CGPathNode>::const_iterator nodesIt = adventureInt->terrain.currentPath->nodes.end() - 1;
+				assert(adventureInt->terrain->currentPath->nodes.size() >= 2);
+				std::vector<CGPathNode>::const_iterator nodesIt = adventureInt->terrain->currentPath->nodes.end() - 1;
 
 				if((nodesIt)->coord == hero->convertToVisitablePos(details.start)
 					&& (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->minimap.redraw();
-			adventureInt->heroList.update(hero);
+			adventureInt->minimap->redraw();
+			adventureInt->heroList->update(hero);
 			return;	//teleport - no fancy moving animation
 					//TODO: smooth disappear / appear effect
 		}
@@ -297,7 +301,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
 		{
 			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
 				removeLastNodeFromPath(hero);
@@ -309,7 +313,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
 		hero->isStanding = true;
 		stillMoveHero.setn(STOP_MOVE);
 		GH.totalRedraw();
-		adventureInt->heroList.update(hero);
+		adventureInt->heroList->update(hero);
 		return;
 	}
 
@@ -333,8 +337,8 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
 	}
 
 	adventureInt->centerOn(hero); //actualizing screen pos
-	adventureInt->minimap.redraw();
-	adventureInt->heroList.redraw();
+	adventureInt->minimap->redraw();
+	adventureInt->heroList->redraw();
 
 	initMovement(details, hero, hp);
 
@@ -370,8 +374,8 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
 	hero->isStanding = true;
 
 	//move finished
-	adventureInt->minimap.redraw();
-	adventureInt->heroList.update(hero);
+	adventureInt->minimap->redraw();
+	adventureInt->heroList->update(hero);
 
 	//check if user cancelled movement
 	{
@@ -434,7 +438,7 @@ void CPlayerInterface::heroKilled(const CGHeroInstance* hero)
 
 	wanderingHeroes -= hero;
 
-	adventureInt->heroList.update(hero);
+	adventureInt->heroList->update(hero);
 	if (makingTurn && newSelection)
 		adventureInt->select(newSelection, true);
 	else if (adventureInt->selection == hero)
@@ -458,7 +462,7 @@ void CPlayerInterface::heroCreated(const CGHeroInstance * hero)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	wanderingHeroes.push_back(hero);
-	adventureInt->heroList.update(hero);
+	adventureInt->heroList->update(hero);
 }
 void CPlayerInterface::openTownWindow(const CGTownInstance * town)
 {
@@ -477,10 +481,10 @@ int3 CPlayerInterface::repairScreenPos(int3 pos)
 		pos.x = -CGI->mh->frameW;
 	if (pos.y<-CGI->mh->frameH)
 		pos.y = -CGI->mh->frameH;
-	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;
-	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;
+	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;
+	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;
 	return pos;
 }
 
@@ -488,7 +492,7 @@ void CPlayerInterface::activateForSpectator()
 {
 	adventureInt->state = CAdvMapInt::INGAME;
 	adventureInt->activate();
-	adventureInt->minimap.activate();
+	adventureInt->minimap->activate();
 }
 
 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;
 	updateInfo(hero);
 	if (makingTurn && hero->tempOwner == playerID)
-		adventureInt->heroList.update(hero);
+		adventureInt->heroList->update(hero);
 }
 void CPlayerInterface::heroMovePointsChanged(const CGHeroInstance * hero)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	if (makingTurn && hero->tempOwner == playerID)
-		adventureInt->heroList.update(hero);
+		adventureInt->heroList->update(hero);
 }
 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
 			wanderingHeroes.push_back(town->visitingHero);
 	}
-	adventureInt->heroList.update();
+	adventureInt->heroList->update();
 	adventureInt->updateNextHero(nullptr);
 
 	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)
@@ -1039,7 +1043,7 @@ void CPlayerInterface::showComp(const Component &comp, std::string message)
 	waitWhileDialog(); //Fix for mantis #98
 
 	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)
@@ -1197,7 +1201,7 @@ void CPlayerInterface::tileRevealed(const std::unordered_set<int3, ShashInt3> &p
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	//FIXME: wait for dialog? Magi hut/eye would benefit from this but may break other areas
 	for (auto & po : pos)
-		adventureInt->minimap.updateTile(po);
+		adventureInt->minimap->updateTile(po);
 	if (!pos.empty())
 		GH.totalRedraw();
 }
@@ -1206,7 +1210,7 @@ void CPlayerInterface::tileHidden(const std::unordered_set<int3, ShashInt3> &pos
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	for (auto & po : pos)
-		adventureInt->minimap.updateTile(po);
+		adventureInt->minimap->updateTile(po);
 	if (!pos.empty())
 		GH.totalRedraw();
 }
@@ -1335,7 +1339,7 @@ void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHer
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	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();
 		return;
@@ -1412,7 +1416,7 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
 		for(auto & po : pos)
 		{
 			if(cb->isVisible(po))
-				adventureInt->minimap.updateTile(po);
+				adventureInt->minimap->updateTile(po);
 		}
 		if(obj->ID == Obj::TOWN)
 		{
@@ -1421,8 +1425,8 @@ void CPlayerInterface::objectPropertyChanged(const SetObjectProperty * sop)
 			else
 				towns -= obj;
 
-			adventureInt->townList.update();
-			adventureInt->minimap.update();
+			adventureInt->townList->update();
+			adventureInt->minimap->update();
 		}
 		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.moveY = (32 - i) * (heroImageNewY - heroImageOldY) / 32;
+	adventureInt->terrain->moveX = (32 - i) * (heroImageNewX - heroImageOldX) / 32;
+	adventureInt->terrain->moveY = (32 - i) * (heroImageNewY - heroImageOldY) / 32;
 }
 
 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);
 
 	paths.erase(ho);
-	adventureInt->terrain.currentPath = nullptr;
+	adventureInt->terrain->currentPath = nullptr;
 	adventureInt->updateMoveHero(ho, false);
 }
 
 void CPlayerInterface::removeLastNodeFromPath(const CGHeroInstance *ho)
 {
-	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
+	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
 		eraseCurrentPathOf(ho);
 }
 
@@ -1946,8 +1950,8 @@ void CPlayerInterface::acceptTurn()
 		adventureInt->startTurn();
 	}
 
-	adventureInt->heroList.update();
-	adventureInt->townList.update();
+	adventureInt->heroList->update();
+	adventureInt->townList->update();
 
 	const CGHeroInstance * heroToSelect = nullptr;
 
@@ -1972,7 +1976,7 @@ void CPlayerInterface::acceptTurn()
 		adventureInt->select(wanderingHeroes.front());
 
 	//show new day animation and sound on infobar
-	adventureInt->infoBar.showDate();
+	adventureInt->infoBar->showDate();
 
 	adventureInt->updateNextHero(nullptr);
 	adventureInt->showAll(screen);
@@ -2052,7 +2056,7 @@ void CPlayerInterface::tryDiggging(const CGHeroInstance * h)
 
 void CPlayerInterface::updateInfo(const CGObjectInstance * specific)
 {
-	adventureInt->infoBar.showSelection();
+	adventureInt->infoBar->showSelection();
 }
 
 void CPlayerInterface::battleNewRoundFirst( int round )
@@ -2163,14 +2167,14 @@ void CPlayerInterface::askToAssembleArtifact(const ArtifactLocation &al)
 void CPlayerInterface::artifactPut(const ArtifactLocation &al)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	adventureInt->infoBar.showSelection();
+	adventureInt->infoBar->showSelection();
 	askToAssembleArtifact(al);
 }
 
 void CPlayerInterface::artifactRemoved(const ArtifactLocation &al)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	adventureInt->infoBar.showSelection();
+	adventureInt->infoBar->showSelection();
 	for(auto isa : GH.listInt)
 	{
 		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)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	adventureInt->infoBar.showSelection();
+	adventureInt->infoBar->showSelection();
 	for(auto isa : GH.listInt)
 	{
 		auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@@ -2205,7 +2209,7 @@ void CPlayerInterface::artifactPossibleAssembling(const ArtifactLocation & dst)
 void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	adventureInt->infoBar.showSelection();
+	adventureInt->infoBar->showSelection();
 	for(auto isa : GH.listInt)
 	{
 		auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@@ -2217,7 +2221,7 @@ void CPlayerInterface::artifactAssembled(const ArtifactLocation &al)
 void CPlayerInterface::artifactDisassembled(const ArtifactLocation &al)
 {
 	EVENT_HANDLER_CALLED_BY_CLIENT;
-	adventureInt->infoBar.showSelection();
+	adventureInt->infoBar->showSelection();
 	for(auto isa : GH.listInt)
 	{
 		auto artWin = dynamic_cast<CArtifactHolder*>(isa.get());
@@ -2236,7 +2240,7 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player)
 	}
 	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
 			GH.popInts(1);
 	}

+ 79 - 71
client/adventureMap/CAdvMapInt.cpp

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

+ 12 - 12
client/adventureMap/CAdvMapInt.h

@@ -14,12 +14,6 @@
 #include "../../lib/int3.h"
 #include "../../lib/GameConstants.h"
 
-#include "CTerrainRect.h"
-#include "CResDataBar.h"
-#include "CList.h"
-#include "CInfoBar.h"
-#include "CMinimap.h"
-
 VCMI_LIB_NAMESPACE_BEGIN
 
 class CGObjectInstance;
@@ -39,6 +33,12 @@ class CGStatusBar;
 class CAdvMapPanel;
 class CAdvMapWorldViewPanel;
 class CAnimation;
+class CTerrainRect;
+class CResDataBar;
+class CHeroList;
+class CTownList;
+class CInfoBar;
+class CMinimap;
 
 struct MapDrawingInfo;
 
@@ -100,7 +100,7 @@ public:
 	std::shared_ptr<IImage> bg;
 	std::shared_ptr<IImage> bgWorldView;
 	std::vector<std::shared_ptr<CAnimImage>> gems;
-	CMinimap minimap;
+	std::shared_ptr<CMinimap> minimap;
 	std::shared_ptr<CGStatusBar> statusbar;
 
 	std::shared_ptr<CButton> kingOverview;
@@ -116,11 +116,11 @@ public:
 
 	std::shared_ptr<CButton> worldViewUnderground;
 
-	CTerrainRect terrain; //visible terrain
-	CResDataBar resdatabar;
-	CHeroList heroList;
-	CTownList townList;
-	CInfoBar infoBar;
+	std::shared_ptr<CTerrainRect> terrain; //visible terrain
+	std::shared_ptr<CResDataBar> resdatabar;
+	std::shared_ptr<CHeroList> heroList;
+	std::shared_ptr<CTownList> townList;
+	std::shared_ptr<CInfoBar> infoBar;
 
 	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

+ 2 - 1
client/adventureMap/CMinimap.cpp

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

+ 2 - 0
client/windows/CCastleInterface.cpp

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

+ 3 - 2
client/windows/InfoWindows.cpp

@@ -22,6 +22,7 @@
 #include "../battle/BattleInterface.h"
 #include "../battle/BattleInterfaceClasses.h"
 #include "../adventureMap/CAdvMapInt.h"
+#include "../adventureMap/CTerrainRect.h"
 #include "../windows/CMessage.h"
 #include "../renderSDL/SDL_Extensions.h"
 #include "../gui/CursorHandler.h"
@@ -364,8 +365,8 @@ CRClickPopupInt::~CRClickPopupInt()
 
 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.y, adventureInt->terrain.pos.y + 100, adventureInt->terrain.pos.y + adventureInt->terrain.pos.h - 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);
 
 	return p;
 }