Browse Source

Fixed remaining regressions

Ivan Savenko 2 years ago
parent
commit
80b37a3019

+ 3 - 1
client/CPlayerInterface.cpp

@@ -313,6 +313,7 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
 		hero->convertToVisitablePos(details.end)
 	};
 	adventureInt->onMapTilesChanged(changedTiles);
+	adventureInt->onHeroMovementStarted(hero);
 
 	bool directlyAttackingCreature = details.attackedFrom && localState->hasPath(hero) && localState->getPath(hero).endPos() == *details.attackedFrom;
 
@@ -510,7 +511,8 @@ void CPlayerInterface::heroInGarrisonChange(const CGTownInstance *town)
 
 	if(town->garrisonHero) //wandering hero moved to the garrison
 	{
-		if(town->garrisonHero->tempOwner == playerID)
+		// This method also gets called on hero recruitment -> garrisoned hero is already in garrison
+		if(town->garrisonHero->tempOwner == playerID && !vstd::contains(localState->getWanderingHeroes(), town->visitingHero))
 			localState->removeWanderingHero(town->garrisonHero);
 	}
 

+ 2 - 2
client/ClientCommandManager.cpp

@@ -415,7 +415,7 @@ void ClientCommandManager::handleTellCommand(std::istringstream& singleWordBuffe
 
 void ClientCommandManager::handleMpCommand()
 {
-	if(const CGHeroInstance* h = adventureInt->getCurrentHero())
+	if(const CGHeroInstance* h = LOCPLINT->localState->getCurrentHero())
 		printCommandMessage(std::to_string(h->movement) + "; max: " + std::to_string(h->maxMovePoints(true)) + "/" + std::to_string(h->maxMovePoints(false)) + "\n");
 }
 
@@ -601,7 +601,7 @@ void ClientCommandManager::processCommand(const std::string & message, bool call
 	else if(commandName == "tell")
 		handleTellCommand(singleWordBuffer);
 
-	else if(commandName == "mp" && adventureInt)
+	else if(commandName == "mp" && LOCPLINT)
 		handleMpCommand();
 
 	else if (commandName == "set")

+ 30 - 17
client/adventureMap/CAdventureMapInterface.cpp

@@ -397,11 +397,17 @@ void CAdventureMapInterface::updateButtons()
 	}
 }
 
+void CAdventureMapInterface::onHeroMovementStarted(const CGHeroInstance * hero)
+{
+	infoBar->popAll();
+	infoBar->showSelection();
+}
+
 void CAdventureMapInterface::onHeroChanged(const CGHeroInstance *h)
 {
 	heroList->update(h);
 
-	if (h == LOCPLINT->localState->getCurrentHero())
+	if (h && h == LOCPLINT->localState->getCurrentHero() && !infoBar->showingComponents())
 		infoBar->showSelection();
 
 	updateButtons();
@@ -410,7 +416,9 @@ void CAdventureMapInterface::onHeroChanged(const CGHeroInstance *h)
 void CAdventureMapInterface::onTownChanged(const CGTownInstance * town)
 {
 	townList->update(town);
-	infoBar->showSelection();
+
+	if (town && town == LOCPLINT->localState->getCurrentTown() && !infoBar->showingComponents())
+		infoBar->showSelection();
 }
 
 void CAdventureMapInterface::showInfoBoxMessage(const std::vector<Component> & components, std::string message, int timer)
@@ -432,8 +440,8 @@ void CAdventureMapInterface::activate()
 		LOCPLINT->cingconsole->activate();
 		LOCPLINT->cingconsole->pos = this->pos;
 	}
-	
-	if(state != EGameState::ENEMY_TURN)
+
+	if(state != EGameState::ENEMY_TURN && state != EGameState::HOTSEAT_WAIT)
 	{
 		assert(state == EGameState::MAKING_TURN);
 
@@ -456,7 +464,7 @@ void CAdventureMapInterface::deactivate()
 {
 	CIntObject::deactivate();
 
-	if(state != EGameState::ENEMY_TURN)
+	if(state != EGameState::ENEMY_TURN && state != EGameState::HOTSEAT_WAIT)
 	{
 		assert(state == EGameState::MAKING_TURN);
 
@@ -525,6 +533,9 @@ void CAdventureMapInterface::show(SDL_Surface * to)
 
 void CAdventureMapInterface::handleMapScrollingUpdate()
 {
+	/// Width of window border, in pixels, that triggers map scrolling
+	static constexpr uint32_t borderScrollWidth = 15;
+
 	uint32_t timePassed = GH.mainFPSmng->getElapsedMilliseconds();
 	uint32_t scrollSpeedPixels = settings["adventure"]["scrollSpeedPixels"].Float();
 	uint32_t scrollDistance = scrollSpeedPixels * timePassed / 1000;
@@ -534,16 +545,16 @@ void CAdventureMapInterface::handleMapScrollingUpdate()
 	Point cursorPosition = GH.getCursorPosition();
 	Point scrollDirection;
 
-	if (cursorPosition.x < 15)
+	if (cursorPosition.x < borderScrollWidth)
 		scrollDirection.x = -1;
 
-	if (cursorPosition.x > GH.screenDimensions().x - 15)
+	if (cursorPosition.x > GH.screenDimensions().x - borderScrollWidth)
 		scrollDirection.x = +1;
 
-	if (cursorPosition.y < 15)
+	if (cursorPosition.y < borderScrollWidth)
 		scrollDirection.y = -1;
 
-	if (cursorPosition.y > GH.screenDimensions().y - 15)
+	if (cursorPosition.y > GH.screenDimensions().y - borderScrollWidth)
 		scrollDirection.y = +1;
 
 	Point scrollDelta = scrollDirection * scrollDistance;
@@ -1251,7 +1262,7 @@ void CAdventureMapInterface::onTileRightClicked(const int3 &mapPos)
 
 void CAdventureMapInterface::enterCastingMode(const CSpell * sp)
 {
-	assert(sp->id == SpellID::SCUTTLE_BOAT  ||  sp->id == SpellID::DIMENSION_DOOR);
+	assert(sp->id == SpellID::SCUTTLE_BOAT || sp->id == SpellID::DIMENSION_DOOR);
 	spellBeingCasted = sp;
 
 	deactivate();
@@ -1259,7 +1270,7 @@ void CAdventureMapInterface::enterCastingMode(const CSpell * sp)
 	GH.fakeMouseMove();
 }
 
-void CAdventureMapInterface::abortCastingMode()
+void CAdventureMapInterface::exitCastingMode()
 {
 	assert(spellBeingCasted);
 	spellBeingCasted = nullptr;
@@ -1267,15 +1278,17 @@ void CAdventureMapInterface::abortCastingMode()
 	activate();
 }
 
+void CAdventureMapInterface::abortCastingMode()
+{
+	exitCastingMode();
+	LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[731]); //Spell cancelled
+}
+
 void CAdventureMapInterface::leaveCastingMode(const int3 & dest)
 {
 	SpellID id = spellBeingCasted->id;
-
-	abortCastingMode();
-//	if(cast)
-		LOCPLINT->cb->castSpell(LOCPLINT->localState->getCurrentHero(), id, dest);
-//	else
-//		LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[731]); //Spell cancelled
+	exitCastingMode();
+	LOCPLINT->cb->castSpell(LOCPLINT->localState->getCurrentHero(), id, dest);
 }
 
 Rect CAdventureMapInterface::terrainAreaPixels() const

+ 5 - 1
client/adventureMap/CAdventureMapInterface.h

@@ -136,6 +136,7 @@ private:
 
 	/// exits currently opened world view mode and returns to normal map
 	void exitWorldView();
+	void exitCastingMode();
 	void leaveCastingMode(const int3 & castTarget);
 	void abortCastingMode();
 
@@ -166,7 +167,10 @@ public:
 	void onCurrentPlayerChanged(PlayerColor playerID);
 
 	/// Called by PlayerInterface when specific map tile changed and must be updated on minimap
-	void onMapTilesChanged( boost::optional<std::unordered_set<int3> > positions);
+	void onMapTilesChanged(boost::optional<std::unordered_set<int3>> positions);
+
+	/// Called by PlayerInterface when hero starts movement
+	void onHeroMovementStarted(const CGHeroInstance * hero);
 
 	/// Called by PlayerInterface when hero state changed and hero list must be updated
 	void onHeroChanged(const CGHeroInstance * hero);

+ 3 - 1
client/adventureMap/CMinimap.cpp

@@ -18,7 +18,7 @@
 #include "../CPlayerInterface.h"
 #include "../gui/CGuiHandler.h"
 #include "../render/Colors.h"
-#include "../renderSDL/SDL_PixelAccess.h"
+#include "../renderSDL/SDL_Extensions.h"
 #include "../render/Canvas.h"
 #include "../windows/InfoWindows.h"
 
@@ -28,6 +28,8 @@
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapping/CMapDefines.h"
 
+#include <SDL_pixels.h>
+
 ColorRGBA CMinimapInstance::getTileColor(const int3 & pos) const
 {
 	const TerrainTile * tile = LOCPLINT->cb->getTile(pos, false);