Преглед на файлове

Merge pull request #928 from kambala-decapitator/quick-recruit-no-creatures

show message instead of the Quick Recruit dialog when there're no creatures in town
Andrii Danylchenko преди 3 години
родител
ревизия
43a1a8b76d

+ 3 - 2
client/gui/CAnimation.cpp

@@ -10,10 +10,11 @@
 #include "StdInc.h"
 #include "CAnimation.h"
 
+#include "SDL_Extensions.h"
+#include "SDL_Pixels.h"
+
 #include "../CBitmapHandler.h"
 #include "../Graphics.h"
-#include "../gui/SDL_Extensions.h"
-#include "../gui/SDL_Pixels.h"
 
 #include "../lib/filesystem/Filesystem.h"
 #include "../lib/filesystem/ISimpleResourceLoader.h"

+ 2 - 1
client/mainmenu/CCampaignScreen.cpp

@@ -9,9 +9,10 @@
  */
 
 #include "StdInc.h"
-#include "../mainmenu/CMainMenu.h"
 #include "CCampaignScreen.h"
 
+#include "CMainMenu.h"
+
 #include "../CGameInfo.h"
 #include "../CMessage.h"
 #include "../CBitmapHandler.h"

+ 2 - 0
client/mainmenu/CCampaignScreen.h

@@ -9,6 +9,8 @@
  */
 #pragma once
 
+#include "../windows/CWindowObject.h"
+
 class CLabel;
 class CPicture;
 class CButton;

+ 3 - 2
client/mainmenu/CreditsScreen.cpp

@@ -9,9 +9,10 @@
  */
 
 #include "StdInc.h"
-
 #include "CreditsScreen.h"
-#include "../mainmenu/CMainMenu.h"
+
+#include "CMainMenu.h"
+
 #include "../gui/CGuiHandler.h"
 #include "../widgets/TextControls.h"
 #include "../widgets/ObjectLists.h"

+ 1 - 2
client/widgets/AdventureMapClasses.cpp

@@ -14,6 +14,7 @@
 
 #include "MiscWidgets.h"
 #include "CComponent.h"
+#include "Images.h"
 
 #include "../CGameInfo.h"
 #include "../CMusicHandler.h"
@@ -26,8 +27,6 @@
 #include "../gui/SDL_Pixels.h"
 #include "../gui/SDL_Compat.h"
 
-#include "../widgets/Images.h"
-
 #include "../windows/InfoWindows.h"
 #include "../windows/CAdvmapInterface.h"
 #include "../windows/GUIClasses.h"

+ 3 - 2
client/widgets/CComponent.cpp

@@ -10,6 +10,9 @@
 #include "StdInc.h"
 #include "CComponent.h"
 
+#include "CArtifactHolder.h"
+#include "Images.h"
+
 #include <vcmi/spells/Service.h>
 #include <vcmi/spells/Spell.h>
 
@@ -18,8 +21,6 @@
 
 #include "../CMessage.h"
 #include "../CGameInfo.h"
-#include "../widgets/Images.h"
-#include "../widgets/CArtifactHolder.h"
 #include "../windows/CAdvmapInterface.h"
 
 #include "../../lib/CArtHandler.h"

+ 3 - 2
client/widgets/CGarrisonInt.cpp

@@ -10,12 +10,13 @@
 #include "StdInc.h"
 #include "CGarrisonInt.h"
 
+#include "Buttons.h"
+#include "TextControls.h"
+
 #include "../gui/CGuiHandler.h"
 
 #include "../CGameInfo.h"
 #include "../CPlayerInterface.h"
-#include "../widgets/Buttons.h"
-#include "../widgets/TextControls.h"
 #include "../windows/CCreatureWindow.h"
 #include "../windows/GUIClasses.h"
 

+ 5 - 5
client/windows/CAdvmapInterface.cpp

@@ -14,8 +14,9 @@
 #include "CHeroWindow.h"
 #include "CKingdomInterface.h"
 #include "CSpellWindow.h"
-#include "GUIClasses.h"
 #include "CTradeWindow.h"
+#include "GUIClasses.h"
+#include "InfoWindows.h"
 
 #include "../CBitmapHandler.h"
 #include "../CGameInfo.h"
@@ -35,7 +36,6 @@
 #include "../gui/CGuiHandler.h"
 #include "../gui/SDL_Extensions.h"
 #include "../widgets/MiscWidgets.h"
-#include "../windows/InfoWindows.h"
 
 #include "../../CCallback.h"
 
@@ -1217,7 +1217,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 			if(itr != LOCPLINT->towns.end())
 				LOCPLINT->showThievesGuildWindow(*itr);
 			else
-				LOCPLINT->showInfoDialog("No available town with tavern!");
+				LOCPLINT->showInfoDialog(CGI->generaltexth->localizedTexts["adventureMap"]["noTownWithTavern"].String());
 		}
 		return;
 	case SDLK_i:
@@ -1249,7 +1249,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 	case SDLK_r:
 		if(isActive() && LOCPLINT->ctrlPressed())
 		{
-			LOCPLINT->showYesNoDialog("Are you sure you want to restart game?",
+			LOCPLINT->showYesNoDialog(CGI->generaltexth->localizedTexts["adventureMap"]["confirmRestartGame"].String(),
 				[](){ LOCPLINT->sendCustomEvent(EUserEvent::RESTART_GAME); }, nullptr);
 		}
 		return;
@@ -1308,7 +1308,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 				if(townWithMarket) //if any town has marketplace, open window
 					GH.pushIntT<CMarketplaceWindow>(townWithMarket);
 				else //if not - complain
-					LOCPLINT->showInfoDialog("No available marketplace!");
+					LOCPLINT->showInfoDialog(CGI->generaltexth->localizedTexts["adventureMap"]["noTownWithMarket"].String());
 			}
 			else if(isActive()) //no ctrl, advmapint is on the top => switch to town
 			{

+ 14 - 5
client/windows/CCastleInterface.cpp

@@ -13,6 +13,7 @@
 #include "CAdvmapInterface.h"
 #include "CHeroWindow.h"
 #include "CTradeWindow.h"
+#include "InfoWindows.h"
 #include "GUIClasses.h"
 #include "QuickRecruitmentWindow.h"
 
@@ -24,7 +25,6 @@
 #include "../Graphics.h"
 #include "../gui/CGuiHandler.h"
 #include "../gui/SDL_Extensions.h"
-#include "../windows/InfoWindows.h"
 #include "../widgets/MiscWidgets.h"
 #include "../widgets/CComponent.h"
 
@@ -842,7 +842,16 @@ void CCastleBuildings::enterDwelling(int level)
 
 void CCastleBuildings::enterToTheQuickRecruitmentWindow()
 {
-	GH.pushIntT<QuickRecruitmentWindow>(town, pos);
+	const auto beginIt = town->creatures.cbegin();
+	const auto afterLastIt = town->creatures.size() > GameConstants::CREATURES_PER_TOWN
+		? std::next(beginIt, GameConstants::CREATURES_PER_TOWN)
+		: town->creatures.cend();
+	const auto hasSomeoneToRecruit = std::any_of(beginIt, afterLastIt,
+		[](const auto & creatureInfo) { return creatureInfo.first > 0; });
+	if(hasSomeoneToRecruit)
+		GH.pushIntT<QuickRecruitmentWindow>(town, pos);
+	else
+		CInfoWindow::showInfoDialog(CGI->generaltexth->localizedTexts["townHall"]["noCreaturesToRecruit"].String(), {});
 }
 
 void CCastleBuildings::enterFountain(const BuildingID & building, BuildingSubID::EBuildingSubID subID, BuildingID::EBuildingID upgrades)
@@ -1235,9 +1244,9 @@ void CCastleInterface::recreateIcons()
 	hall = std::make_shared<CTownInfo>(80, 413, town, true);
 	fort = std::make_shared<CTownInfo>(122, 413, town, false);
 
-	fastArmyPurhase = std::make_shared<CButton>(Point(122, 413), "itmcl.def", CButton::tooltip(), [&](){builds->enterToTheQuickRecruitmentWindow();});
-	fastArmyPurhase->setImageOrder(town->fortLevel()-1, town->fortLevel()-1, town->fortLevel()-1, town->fortLevel()-1);
-	fastArmyPurhase->setAnimateLonelyFrame(true);
+	fastArmyPurchase = std::make_shared<CButton>(Point(122, 413), "itmcl.def", CButton::tooltip(), [&](){ builds->enterToTheQuickRecruitmentWindow(); });
+	fastArmyPurchase->setImageOrder(town->fortLevel() - 1, town->fortLevel() - 1, town->fortLevel() - 1, town->fortLevel() - 1);
+	fastArmyPurchase->setAnimateLonelyFrame(true);
 
 	creainfo.clear();
 

+ 1 - 1
client/windows/CCastleInterface.h

@@ -209,7 +209,7 @@ class CCastleInterface : public CStatusbarWindow, public CGarrisonHolder
 
 	std::shared_ptr<CButton> exit;
 	std::shared_ptr<CButton> split;
-	std::shared_ptr<CButton> fastArmyPurhase;
+	std::shared_ptr<CButton> fastArmyPurchase;
 
 	std::vector<std::shared_ptr<CCreaInfo>> creainfo;//small icons of creatures (bottom-left corner);
 

+ 1 - 1
client/windows/CKingdomInterface.cpp

@@ -12,6 +12,7 @@
 
 #include "CAdvmapInterface.h"
 #include "CCastleInterface.h"
+#include "InfoWindows.h"
 
 #include "../CGameInfo.h"
 #include "../CMT.h"
@@ -19,7 +20,6 @@
 #include "../gui/CGuiHandler.h"
 #include "../widgets/CComponent.h"
 #include "../widgets/MiscWidgets.h"
-#include "../windows/InfoWindows.h"
 
 #include "../../CCallback.h"
 

+ 1 - 1
client/windows/CSpellWindow.cpp

@@ -562,7 +562,7 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
 				if(!texts.empty())
 					owner->myInt->showInfoDialog(texts.front());
 				else
-					owner->myInt->showInfoDialog("Unknown problem with this spell, no more information available.");
+					owner->myInt->showInfoDialog(CGI->generaltexth->localizedTexts["adventureMap"]["spellUnknownProblem"].String());
 			}
 		}
 		else //adventure spell

+ 3 - 2
client/windows/CWindowObject.cpp

@@ -10,6 +10,8 @@
 #include "StdInc.h"
 #include "CWindowObject.h"
 
+#include "CAdvmapInterface.h"
+
 #include "../widgets/MiscWidgets.h"
 
 #include "../gui/SDL_Pixels.h"
@@ -26,7 +28,6 @@
 #include "../CPlayerInterface.h"
 #include "../CMessage.h"
 #include "../CMusicHandler.h"
-#include "../windows/CAdvmapInterface.h"
 
 #include "../../CCallback.h"
 
@@ -251,4 +252,4 @@ void CStatusbarWindow::activate()
 {
 	CIntObject::activate();
 	GH.statusbar = statusbar;
-}
+}

+ 2 - 2
client/windows/CreaturePurchaseCard.cpp

@@ -54,14 +54,14 @@ void CreaturePurchaseCard::switchCreatureLevel()
 void CreaturePurchaseCard::initAmountInfo()
 {
 	availableAmount = std::make_shared<CLabel>(pos.x + 25, pos.y + 146, FONT_SMALL, CENTER, Colors::YELLOW);
-	purhaseAmount = std::make_shared<CLabel>(pos.x + 76, pos.y + 146, FONT_SMALL, CENTER, Colors::WHITE);
+	purchaseAmount = std::make_shared<CLabel>(pos.x + 76, pos.y + 146, FONT_SMALL, CENTER, Colors::WHITE);
 	updateAmountInfo(0);
 }
 
 void CreaturePurchaseCard::updateAmountInfo(int value)
 {
 	availableAmount->setText(boost::lexical_cast<std::string>(maxAmount-value));
-	purhaseAmount->setText(boost::lexical_cast<std::string>(value));
+	purchaseAmount->setText(boost::lexical_cast<std::string>(value));
 }
 
 void CreaturePurchaseCard::initSlider()

+ 1 - 1
client/windows/CreaturePurchaseCard.h

@@ -43,7 +43,7 @@ private:
 	void initCostBox();
 
 	std::shared_ptr<CButton> maxButton, minButton, creatureSwitcher;
-	std::shared_ptr<CLabel> availableAmount,  purhaseAmount;
+	std::shared_ptr<CLabel> availableAmount, purchaseAmount;
 	std::shared_ptr<CCreaturePic> picture;
 	std::shared_ptr<CreatureCostBox> cost;
 	std::vector<CreatureID> upgradesID;

+ 1 - 1
client/windows/GUIClasses.cpp

@@ -15,6 +15,7 @@
 #include "CCreatureWindow.h"
 #include "CHeroWindow.h"
 #include "CreatureCostBox.h"
+#include "InfoWindows.h"
 
 #include "../CBitmapHandler.h"
 #include "../CGameInfo.h"
@@ -36,7 +37,6 @@
 
 #include "../widgets/CComponent.h"
 #include "../widgets/MiscWidgets.h"
-#include "../windows/InfoWindows.h"
 
 #include "../lobby/CSavingScreen.h"
 

+ 1 - 1
client/windows/GUIClasses.h

@@ -9,13 +9,13 @@
  */
 #pragma once
 
+#include "CWindowObject.h"
 #include "../lib/GameConstants.h"
 #include "../lib/ResourceSet.h"
 #include "../lib/CConfigHandler.h"
 #include "../widgets/CArtifactHolder.h"
 #include "../widgets/CGarrisonInt.h"
 #include "../widgets/Images.h"
-#include "../windows/CWindowObject.h"
 
 class CGDwelling;
 class CreatureCostBox;

+ 2 - 1
client/windows/InfoWindows.cpp

@@ -10,6 +10,8 @@
 #include "StdInc.h"
 #include "InfoWindows.h"
 
+#include "CAdvmapInterface.h"
+
 #include "../CBitmapHandler.h"
 #include "../Graphics.h"
 #include "../CGameInfo.h"
@@ -17,7 +19,6 @@
 #include "../CMessage.h"
 #include "../CMusicHandler.h"
 
-#include "../windows/CAdvmapInterface.h"
 #include "../widgets/CComponent.h"
 #include "../widgets/MiscWidgets.h"
 

+ 4 - 4
client/windows/QuickRecruitmentWindow.cpp

@@ -35,7 +35,7 @@ void QuickRecruitmentWindow::setCancelButton()
 
 void QuickRecruitmentWindow::setBuyButton()
 {
-	buyButton = std::make_shared<CButton>(Point((pos.w/2)-32, 418), "IBY6432.DEF", CButton::tooltip(), [&](){ purhaseUnits(); }, SDLK_RETURN);
+	buyButton = std::make_shared<CButton>(Point((pos.w / 2) - 32, 418), "IBY6432.DEF", CButton::tooltip(), [&](){ purchaseUnits(); }, SDLK_RETURN);
 	cancelButton->assignedKeys.insert(SDLK_ESCAPE);
 	buyButton->setImageOrder(0, 1, 2, 3);
 }
@@ -46,7 +46,7 @@ void QuickRecruitmentWindow::setMaxButton()
 	maxButton->setImageOrder(0, 1, 2, 3);
 }
 
-void QuickRecruitmentWindow::setCreaturePurhaseCards()
+void QuickRecruitmentWindow::setCreaturePurchaseCards()
 {
 	int availableAmount = getAvailableCreatures();
 	Point position = Point((pos.w - 100*availableAmount - 8*(availableAmount-1))/2,64);
@@ -99,7 +99,7 @@ void QuickRecruitmentWindow::maxAllCards(std::vector<std::shared_ptr<CreaturePur
 }
 
 
-void QuickRecruitmentWindow::purhaseUnits()
+void QuickRecruitmentWindow::purchaseUnits()
 {
 	for(auto selected : cards)
 	{
@@ -154,6 +154,6 @@ QuickRecruitmentWindow::QuickRecruitmentWindow(const CGTownInstance * townd, Rec
 
 	initWindow(startupPosition);
 	setButtons();
-	setCreaturePurhaseCards();
+	setCreaturePurchaseCards();
 	maxAllCards(cards);
 }

+ 2 - 2
client/windows/QuickRecruitmentWindow.h

@@ -31,11 +31,11 @@ private:
 	void setBuyButton();
 	void setMaxButton();
 
-	void setCreaturePurhaseCards();
+	void setCreaturePurchaseCards();
 
 	void maxAllCards(std::vector<std::shared_ptr<CreaturePurchaseCard>> cards);
 	void maxAllSlidersAmount(std::vector<std::shared_ptr<CreaturePurchaseCard>> cards);
-	void purhaseUnits();
+	void purchaseUnits();
 
 	const CGTownInstance * town;
 	std::shared_ptr<CButton> maxButton, buyButton, cancelButton;

+ 5 - 0
config/translate.json

@@ -21,6 +21,10 @@
 				"Impossible"
 			]
 		},
+		"confirmRestartGame" : "Are you sure you want to restart game?",
+		"noTownWithMarket": "No available marketplace!",
+		"noTownWithTavern": "No available town with tavern!",
+		"spellUnknownProblem": "Unknown problem with this spell, no more information available.",
 		"playerAttacked" : "Player has been attacked: %s"
 	},
 	"systemOptions" :
@@ -44,6 +48,7 @@
 	"townHall" :
 	{
 		"missingBase" : "Base building %s must be built first",
+		"noCreaturesToRecruit" : "There are no creatures to recruit!",
 		"greetingManaVortex" : "As you near the %s your body is filled with new energy. You have doubled your normal spell points.",
 		"greetingKnowledge" : "You study the glyphs on the %s and gain insight into the workings of various magics (+1 Knowledge).",
 		"greetingSpellPower" : "The %s teaches you new ways to focus your magical powers (+1 Power).",

+ 1 - 1
lib/filesystem/Filesystem.cpp

@@ -156,7 +156,7 @@ ISimpleResourceLoader * CResourceHandler::createInitial()
 
 void CResourceHandler::initialize()
 {
-	// Create tree-loke structure that looks like this:
+	// Create tree-like structure that looks like this:
 	// root
 	// |
 	// |- initial