1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-06 23:26:26 +02:00

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
This commit is contained in:
Andrii Danylchenko 2022-09-22 18:21:45 +03:00 committed by GitHub
commit 43a1a8b76d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 61 additions and 39 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,6 +13,7 @@
#include "CAdvmapInterface.h" #include "CAdvmapInterface.h"
#include "CHeroWindow.h" #include "CHeroWindow.h"
#include "CTradeWindow.h" #include "CTradeWindow.h"
#include "InfoWindows.h"
#include "GUIClasses.h" #include "GUIClasses.h"
#include "QuickRecruitmentWindow.h" #include "QuickRecruitmentWindow.h"
@ -24,7 +25,6 @@
#include "../Graphics.h" #include "../Graphics.h"
#include "../gui/CGuiHandler.h" #include "../gui/CGuiHandler.h"
#include "../gui/SDL_Extensions.h" #include "../gui/SDL_Extensions.h"
#include "../windows/InfoWindows.h"
#include "../widgets/MiscWidgets.h" #include "../widgets/MiscWidgets.h"
#include "../widgets/CComponent.h" #include "../widgets/CComponent.h"
@ -842,7 +842,16 @@ void CCastleBuildings::enterDwelling(int level)
void CCastleBuildings::enterToTheQuickRecruitmentWindow() 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) 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); hall = std::make_shared<CTownInfo>(80, 413, town, true);
fort = std::make_shared<CTownInfo>(122, 413, town, false); fort = std::make_shared<CTownInfo>(122, 413, town, false);
fastArmyPurhase = std::make_shared<CButton>(Point(122, 413), "itmcl.def", CButton::tooltip(), [&](){builds->enterToTheQuickRecruitmentWindow();}); fastArmyPurchase = 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); fastArmyPurchase->setImageOrder(town->fortLevel() - 1, town->fortLevel() - 1, town->fortLevel() - 1, town->fortLevel() - 1);
fastArmyPurhase->setAnimateLonelyFrame(true); fastArmyPurchase->setAnimateLonelyFrame(true);
creainfo.clear(); creainfo.clear();

View File

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

View File

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

View File

@ -562,7 +562,7 @@ void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
if(!texts.empty()) if(!texts.empty())
owner->myInt->showInfoDialog(texts.front()); owner->myInt->showInfoDialog(texts.front());
else 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 else //adventure spell

View File

@ -10,6 +10,8 @@
#include "StdInc.h" #include "StdInc.h"
#include "CWindowObject.h" #include "CWindowObject.h"
#include "CAdvmapInterface.h"
#include "../widgets/MiscWidgets.h" #include "../widgets/MiscWidgets.h"
#include "../gui/SDL_Pixels.h" #include "../gui/SDL_Pixels.h"
@ -26,7 +28,6 @@
#include "../CPlayerInterface.h" #include "../CPlayerInterface.h"
#include "../CMessage.h" #include "../CMessage.h"
#include "../CMusicHandler.h" #include "../CMusicHandler.h"
#include "../windows/CAdvmapInterface.h"
#include "../../CCallback.h" #include "../../CCallback.h"

View File

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

View File

@ -43,7 +43,7 @@ private:
void initCostBox(); void initCostBox();
std::shared_ptr<CButton> maxButton, minButton, creatureSwitcher; 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<CCreaturePic> picture;
std::shared_ptr<CreatureCostBox> cost; std::shared_ptr<CreatureCostBox> cost;
std::vector<CreatureID> upgradesID; std::vector<CreatureID> upgradesID;

View File

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

View File

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

View File

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

View File

@ -35,7 +35,7 @@ void QuickRecruitmentWindow::setCancelButton()
void QuickRecruitmentWindow::setBuyButton() 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); cancelButton->assignedKeys.insert(SDLK_ESCAPE);
buyButton->setImageOrder(0, 1, 2, 3); buyButton->setImageOrder(0, 1, 2, 3);
} }
@ -46,7 +46,7 @@ void QuickRecruitmentWindow::setMaxButton()
maxButton->setImageOrder(0, 1, 2, 3); maxButton->setImageOrder(0, 1, 2, 3);
} }
void QuickRecruitmentWindow::setCreaturePurhaseCards() void QuickRecruitmentWindow::setCreaturePurchaseCards()
{ {
int availableAmount = getAvailableCreatures(); int availableAmount = getAvailableCreatures();
Point position = Point((pos.w - 100*availableAmount - 8*(availableAmount-1))/2,64); 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) for(auto selected : cards)
{ {
@ -154,6 +154,6 @@ QuickRecruitmentWindow::QuickRecruitmentWindow(const CGTownInstance * townd, Rec
initWindow(startupPosition); initWindow(startupPosition);
setButtons(); setButtons();
setCreaturePurhaseCards(); setCreaturePurchaseCards();
maxAllCards(cards); maxAllCards(cards);
} }

View File

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

View File

@ -21,6 +21,10 @@
"Impossible" "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" "playerAttacked" : "Player has been attacked: %s"
}, },
"systemOptions" : "systemOptions" :
@ -44,6 +48,7 @@
"townHall" : "townHall" :
{ {
"missingBase" : "Base building %s must be built first", "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.", "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).", "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).", "greetingSpellPower" : "The %s teaches you new ways to focus your magical powers (+1 Power).",

View File

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