2018-01-05 19:21:07 +02:00
|
|
|
/*
|
|
|
|
* CBonusSelection.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "CBonusSelection.h"
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
|
|
|
|
#include <vcmi/spells/Spell.h>
|
|
|
|
#include <vcmi/spells/Service.h>
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "CSelectionBase.h"
|
2024-02-07 22:40:56 +02:00
|
|
|
#include "ExtraOptionsTab.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
#include "../CServerHandler.h"
|
|
|
|
#include "../mainmenu/CMainMenu.h"
|
|
|
|
#include "../mainmenu/CPrologEpilogVideo.h"
|
2024-05-02 14:55:20 +02:00
|
|
|
#include "../media/IMusicPlayer.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/CComponent.h"
|
|
|
|
#include "../widgets/Buttons.h"
|
|
|
|
#include "../widgets/MiscWidgets.h"
|
|
|
|
#include "../widgets/ObjectLists.h"
|
|
|
|
#include "../widgets/TextControls.h"
|
2024-08-31 17:16:42 +02:00
|
|
|
#include "../widgets/VideoWidget.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../windows/GUIClasses.h"
|
|
|
|
#include "../windows/InfoWindows.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../render/IImage.h"
|
2023-09-04 17:01:44 +02:00
|
|
|
#include "../render/IRenderHandler.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../render/CAnimation.h"
|
2023-07-31 18:50:55 +02:00
|
|
|
#include "../render/Graphics.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-04-27 19:21:06 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
2023-05-16 14:10:26 +02:00
|
|
|
#include "../gui/WindowHandler.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2024-05-02 14:55:20 +02:00
|
|
|
#include "../../lib/CConfigHandler.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../../lib/CCreatureHandler.h"
|
2024-07-21 12:49:40 +02:00
|
|
|
#include "../../lib/CSkillHandler.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../../lib/StartInfo.h"
|
2024-07-21 12:49:40 +02:00
|
|
|
#include "../../lib/entities/building/CBuilding.h"
|
|
|
|
#include "../../lib/entities/building/CBuildingHandler.h"
|
|
|
|
#include "../../lib/entities/faction/CFaction.h"
|
|
|
|
#include "../../lib/entities/faction/CTown.h"
|
|
|
|
#include "../../lib/entities/faction/CTownHandler.h"
|
2024-10-11 18:30:16 +02:00
|
|
|
#include "../../lib/entities/hero/CHeroHandler.h"
|
2024-07-21 12:49:40 +02:00
|
|
|
#include "../../lib/filesystem/Filesystem.h"
|
|
|
|
#include "../../lib/texts/CGeneralTextHandler.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-06-25 21:28:24 +02:00
|
|
|
#include "../../lib/campaign/CampaignState.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../../lib/mapping/CMapService.h"
|
|
|
|
#include "../../lib/mapping/CMapInfo.h"
|
2024-09-24 21:41:37 +02:00
|
|
|
#include "../../lib/mapping/CMapHeader.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
|
|
|
|
2023-06-25 20:16:03 +02:00
|
|
|
std::shared_ptr<CampaignState> CBonusSelection::getCampaign()
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
return CSH->si->campState;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBonusSelection::CBonusSelection()
|
|
|
|
: CWindowObject(BORDERED)
|
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2023-04-08 22:16:11 +02:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
setBackground(getCampaign()->getRegions().getBackgroundName());
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
panelBackground = std::make_shared<CPicture>(ImagePath::builtin("CAMPBRF.BMP"), 456, 6);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2024-05-18 21:59:28 +02:00
|
|
|
const auto & playVideo = [this]()
|
|
|
|
{
|
|
|
|
GH.windows().createAndPushWindow<CPrologEpilogVideo>(
|
|
|
|
getCampaign()->scenario(CSH->campaignMap).prolog,
|
|
|
|
[this]() { redraw(); } );
|
|
|
|
};
|
|
|
|
|
|
|
|
buttonStart = std::make_shared<CButton>(
|
|
|
|
Point(475, 536), AnimationPath::builtin("CBBEGIB.DEF"), CButton::tooltip(), std::bind(&CBonusSelection::startMap, this), EShortcut::GLOBAL_ACCEPT
|
|
|
|
);
|
2023-08-23 14:07:50 +02:00
|
|
|
buttonRestart = std::make_shared<CButton>(Point(475, 536), AnimationPath::builtin("CBRESTB.DEF"), CButton::tooltip(), std::bind(&CBonusSelection::restartMap, this), EShortcut::GLOBAL_ACCEPT);
|
2024-05-18 21:59:28 +02:00
|
|
|
buttonVideo = std::make_shared<CButton>(Point(705, 214), AnimationPath::builtin("CBVIDEB.DEF"), CButton::tooltip(), playVideo, EShortcut::LOBBY_REPLAY_VIDEO);
|
2023-08-23 14:07:50 +02:00
|
|
|
buttonBack = std::make_shared<CButton>(Point(624, 536), AnimationPath::builtin("CBCANCB.DEF"), CButton::tooltip(), std::bind(&CBonusSelection::goBack, this), EShortcut::GLOBAL_CANCEL);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2024-08-21 21:43:54 +02:00
|
|
|
campaignName = std::make_shared<CLabel>(481, 28, FONT_BIG, ETextAlignment::TOPLEFT, Colors::YELLOW, CSH->si->getCampaignName(), 250);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
iconsMapSizes = std::make_shared<CAnimImage>(AnimationPath::builtin("SCNRMPSZ"), 4, 0, 735, 26);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
labelCampaignDescription = std::make_shared<CLabel>(481, 63, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[38]);
|
2023-09-27 22:53:13 +02:00
|
|
|
campaignDescription = std::make_shared<CTextBox>(getCampaign()->getDescriptionTranslated(), Rect(480, 86, 286, 117), 1);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2024-09-01 12:23:10 +02:00
|
|
|
bool videoButtonActive = CSH->getState() == EClientState::GAMEPLAY;
|
|
|
|
int availableSpace = videoButtonActive ? 225 : 285;
|
|
|
|
mapName = std::make_shared<CLabel>(481, 219, FONT_BIG, ETextAlignment::TOPLEFT, Colors::YELLOW, CSH->mi->getNameTranslated(), availableSpace );
|
2022-11-26 23:12:20 +02:00
|
|
|
labelMapDescription = std::make_shared<CLabel>(481, 253, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[496]);
|
2023-06-27 18:32:27 +02:00
|
|
|
mapDescription = std::make_shared<CTextBox>("", Rect(480, 278, 292, 108), 1);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2024-02-07 23:04:50 +02:00
|
|
|
labelChooseBonus = std::make_shared<CLabel>(475, 432, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[71]);
|
2018-01-05 19:21:07 +02:00
|
|
|
groupBonuses = std::make_shared<CToggleGroup>(std::bind(&IServerAPI::setCampaignBonus, CSH, _1));
|
|
|
|
|
|
|
|
flagbox = std::make_shared<CFlagBox>(Rect(486, 407, 335, 23));
|
|
|
|
|
|
|
|
std::vector<std::string> difficulty;
|
2023-01-01 22:26:07 +02:00
|
|
|
std::string difficultyString = CGI->generaltexth->allTexts[492];
|
|
|
|
boost::split(difficulty, difficultyString, boost::is_any_of(" "));
|
2024-02-07 23:04:50 +02:00
|
|
|
labelDifficulty = std::make_shared<CLabel>(724, settings["general"]["enableUiEnhancements"].Bool() ? 457 : 432, FONT_MEDIUM, ETextAlignment::TOPCENTER, Colors::WHITE, difficulty.back());
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
for(size_t b = 0; b < difficultyIcons.size(); ++b)
|
|
|
|
{
|
2024-02-07 23:04:50 +02:00
|
|
|
difficultyIcons[b] = std::make_shared<CAnimImage>(AnimationPath::builtinTODO("GSPBUT" + std::to_string(b + 3) + ".DEF"), 0, 0, 709, settings["general"]["enableUiEnhancements"].Bool() ? 480 : 455);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-06-26 00:07:55 +02:00
|
|
|
if(getCampaign()->playerSelectedDifficulty())
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2024-05-18 21:59:28 +02:00
|
|
|
Point posLeft = settings["general"]["enableUiEnhancements"].Bool() ? Point(693, 495) : Point(694, 508);
|
|
|
|
Point posRight = settings["general"]["enableUiEnhancements"].Bool() ? Point(739, 495) : Point(738, 508);
|
|
|
|
|
|
|
|
buttonDifficultyLeft = std::make_shared<CButton>(posLeft, AnimationPath::builtin("SCNRBLF.DEF"), CButton::tooltip(), std::bind(&CBonusSelection::decreaseDifficulty, this), EShortcut::MOVE_LEFT);
|
|
|
|
buttonDifficultyRight = std::make_shared<CButton>(posRight, AnimationPath::builtin("SCNRBRT.DEF"), CButton::tooltip(), std::bind(&CBonusSelection::increaseDifficulty, this), EShortcut::MOVE_RIGHT);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-06-25 23:01:25 +02:00
|
|
|
for(auto scenarioID : getCampaign()->allScenarios())
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-06-25 23:01:25 +02:00
|
|
|
if(getCampaign()->isAvailable(scenarioID))
|
2024-09-24 11:23:10 +02:00
|
|
|
regions.push_back(std::make_shared<CRegion>(scenarioID, true, true, false, getCampaign()->getRegions()));
|
2023-06-25 23:01:25 +02:00
|
|
|
else if(getCampaign()->isConquered(scenarioID)) //display as striped
|
2024-09-24 11:23:10 +02:00
|
|
|
regions.push_back(std::make_shared<CRegion>(scenarioID, false, false, false, getCampaign()->getRegions()));
|
|
|
|
else
|
|
|
|
regions.push_back(std::make_shared<CRegion>(scenarioID, false, false, true, getCampaign()->getRegions()));
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-06-27 19:09:11 +02:00
|
|
|
|
|
|
|
if (!getCampaign()->getMusic().empty())
|
2023-09-04 12:03:15 +02:00
|
|
|
CCS->musich->playMusic( getCampaign()->getMusic(), true, false);
|
2024-02-07 22:40:56 +02:00
|
|
|
|
2024-04-05 18:48:38 +02:00
|
|
|
if(CSH->getState() != EClientState::GAMEPLAY && settings["general"]["enableUiEnhancements"].Bool())
|
2024-02-07 22:40:56 +02:00
|
|
|
{
|
|
|
|
tabExtraOptions = std::make_shared<ExtraOptionsTab>();
|
|
|
|
tabExtraOptions->recActions = UPDATE | SHOWALL | LCLICK | RCLICK_POPUP;
|
|
|
|
tabExtraOptions->recreate(true);
|
|
|
|
tabExtraOptions->setEnabled(false);
|
2024-05-18 21:59:28 +02:00
|
|
|
buttonExtraOptions = std::make_shared<CButton>(Point(643, 431), AnimationPath::builtin("GSPBUT2.DEF"), CGI->generaltexth->zelp[46], [this]{ tabExtraOptions->setEnabled(!tabExtraOptions->isActive()); GH.windows().totalRedraw(); }, EShortcut::LOBBY_EXTRA_OPTIONS);
|
2024-02-27 22:19:09 +02:00
|
|
|
buttonExtraOptions->setTextOverlay(CGI->generaltexth->translate("vcmi.optionsTab.extraOptions.hover"), FONT_SMALL, Colors::WHITE);
|
2024-02-07 22:40:56 +02:00
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBonusSelection::createBonusesIcons()
|
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2023-06-25 23:01:25 +02:00
|
|
|
const CampaignScenario & scenario = getCampaign()->scenario(CSH->campaignMap);
|
2023-06-25 20:16:03 +02:00
|
|
|
const std::vector<CampaignBonus> & bonDescs = scenario.travelOptions.bonusesToChoose;
|
2018-01-05 19:21:07 +02:00
|
|
|
groupBonuses = std::make_shared<CToggleGroup>(std::bind(&IServerAPI::setCampaignBonus, CSH, _1));
|
|
|
|
|
2024-02-12 13:22:54 +02:00
|
|
|
constexpr std::array bonusPics =
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
"SPELLBON.DEF", // Spell
|
|
|
|
"TWCRPORT.DEF", // Monster
|
|
|
|
"", // Building - BO*.BMP
|
|
|
|
"ARTIFBON.DEF", // Artifact
|
|
|
|
"SPELLBON.DEF", // Spell scroll
|
|
|
|
"PSKILBON.DEF", // Primary skill
|
|
|
|
"SSKILBON.DEF", // Secondary skill
|
|
|
|
"BORES.DEF", // Resource
|
|
|
|
"PORTRAITSLARGE", // Hero HPL*.BMP
|
|
|
|
"PORTRAITSLARGE"
|
|
|
|
// Player - CREST58.DEF
|
|
|
|
};
|
|
|
|
|
|
|
|
for(int i = 0; i < bonDescs.size(); i++)
|
|
|
|
{
|
2023-06-25 20:16:03 +02:00
|
|
|
int bonusType = static_cast<size_t>(bonDescs[i].type);
|
|
|
|
std::string picName = bonusPics[bonusType];
|
2018-01-05 19:21:07 +02:00
|
|
|
size_t picNumber = bonDescs[i].info2;
|
|
|
|
|
2023-09-27 22:53:13 +02:00
|
|
|
MetaString desc;
|
2018-01-05 19:21:07 +02:00
|
|
|
switch(bonDescs[i].type)
|
|
|
|
{
|
2023-06-25 20:16:03 +02:00
|
|
|
case CampaignBonusType::SPELL:
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.appendLocalString(EMetaText::GENERAL_TXT, 715);
|
2023-11-02 22:01:49 +02:00
|
|
|
desc.replaceName(SpellID(bonDescs[i].info2));
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
2023-06-25 20:16:03 +02:00
|
|
|
case CampaignBonusType::MONSTER:
|
2018-01-05 19:21:07 +02:00
|
|
|
picNumber = bonDescs[i].info2 + 2;
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.appendLocalString(EMetaText::GENERAL_TXT, 717);
|
|
|
|
desc.replaceNumber(bonDescs[i].info3);
|
2023-11-02 22:01:49 +02:00
|
|
|
desc.replaceNamePlural(bonDescs[i].info2);
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
2023-06-25 20:16:03 +02:00
|
|
|
case CampaignBonusType::BUILDING:
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-11-02 17:48:48 +02:00
|
|
|
FactionID faction;
|
2018-01-05 19:21:07 +02:00
|
|
|
for(auto & elem : CSH->si->playerInfos)
|
|
|
|
{
|
|
|
|
if(elem.second.isControlledByHuman())
|
|
|
|
{
|
|
|
|
faction = elem.second.castle;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
assert(faction != -1);
|
|
|
|
|
2023-04-09 02:53:06 +02:00
|
|
|
BuildingID buildID;
|
2023-06-26 00:07:55 +02:00
|
|
|
if(getCampaign()->formatVCMI())
|
2023-04-09 02:53:06 +02:00
|
|
|
buildID = BuildingID(bonDescs[i].info1);
|
|
|
|
else
|
|
|
|
buildID = CBuildingHandler::campToERMU(bonDescs[i].info1, faction, std::set<BuildingID>());
|
2018-01-05 19:21:07 +02:00
|
|
|
picName = graphics->ERMUtoPicture[faction][buildID];
|
|
|
|
picNumber = -1;
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(vstd::contains((*CGI->townh)[faction]->town->buildings, buildID))
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.appendTextID((*CGI->townh)[faction]->town->buildings.find(buildID)->second->getNameTextID());
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-06-25 20:16:03 +02:00
|
|
|
case CampaignBonusType::ARTIFACT:
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.appendLocalString(EMetaText::GENERAL_TXT, 715);
|
2023-11-02 22:01:49 +02:00
|
|
|
desc.replaceName(ArtifactID(bonDescs[i].info2));
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
2023-06-25 20:16:03 +02:00
|
|
|
case CampaignBonusType::SPELL_SCROLL:
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.appendLocalString(EMetaText::GENERAL_TXT, 716);
|
2024-06-26 17:47:44 +02:00
|
|
|
desc.replaceName(SpellID(bonDescs[i].info2));
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
2023-06-25 20:16:03 +02:00
|
|
|
case CampaignBonusType::PRIMARY_SKILL:
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
int leadingSkill = -1;
|
|
|
|
std::vector<std::pair<int, int>> toPrint; //primary skills to be listed <num, val>
|
|
|
|
const ui8 * ptr = reinterpret_cast<const ui8 *>(&bonDescs[i].info2);
|
|
|
|
for(int g = 0; g < GameConstants::PRIMARY_SKILLS; ++g)
|
|
|
|
{
|
|
|
|
if(leadingSkill == -1 || ptr[g] > ptr[leadingSkill])
|
|
|
|
{
|
|
|
|
leadingSkill = g;
|
|
|
|
}
|
|
|
|
if(ptr[g] != 0)
|
|
|
|
{
|
|
|
|
toPrint.push_back(std::make_pair(g, ptr[g]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
picNumber = leadingSkill;
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.appendLocalString(EMetaText::GENERAL_TXT, 715);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
std::string substitute; //text to be printed instead of %s
|
|
|
|
for(int v = 0; v < toPrint.size(); ++v)
|
|
|
|
{
|
2023-03-09 15:36:46 +02:00
|
|
|
substitute += std::to_string(toPrint[v].second);
|
2018-01-05 19:21:07 +02:00
|
|
|
substitute += " " + CGI->generaltexth->primarySkillNames[toPrint[v].first];
|
|
|
|
if(v != toPrint.size() - 1)
|
|
|
|
{
|
|
|
|
substitute += ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.replaceRawString(substitute);
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-06-25 20:16:03 +02:00
|
|
|
case CampaignBonusType::SECONDARY_SKILL:
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.appendLocalString(EMetaText::GENERAL_TXT, 718);
|
2024-04-22 15:51:08 +02:00
|
|
|
desc.replaceTextID(TextIdentifier("core", "skilllev", bonDescs[i].info3 - 1).get());
|
2023-11-02 22:01:49 +02:00
|
|
|
desc.replaceName(SecondarySkill(bonDescs[i].info2));
|
2018-01-05 19:21:07 +02:00
|
|
|
picNumber = bonDescs[i].info2 * 3 + bonDescs[i].info3 - 1;
|
|
|
|
|
|
|
|
break;
|
2023-06-25 20:16:03 +02:00
|
|
|
case CampaignBonusType::RESOURCE:
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-11-08 16:13:08 +02:00
|
|
|
desc.appendLocalString(EMetaText::GENERAL_TXT, 717);
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
switch(bonDescs[i].info1)
|
|
|
|
{
|
2023-11-08 16:13:08 +02:00
|
|
|
case 0xFD: //wood + ore
|
|
|
|
{
|
|
|
|
desc.replaceLocalString(EMetaText::GENERAL_TXT, 721);
|
|
|
|
picNumber = 7;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 0xFE: //wood + ore
|
|
|
|
{
|
|
|
|
desc.replaceLocalString(EMetaText::GENERAL_TXT, 722);
|
|
|
|
picNumber = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
desc.replaceName(GameResID(bonDescs[i].info1));
|
|
|
|
picNumber = bonDescs[i].info1;
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.replaceNumber(bonDescs[i].info2);
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-06-25 20:16:03 +02:00
|
|
|
case CampaignBonusType::HEROES_FROM_PREVIOUS_SCENARIO:
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-06-25 23:01:25 +02:00
|
|
|
auto superhero = getCampaign()->strongestHero(static_cast<CampaignScenarioID>(bonDescs[i].info2), PlayerColor(bonDescs[i].info1));
|
2018-01-05 19:21:07 +02:00
|
|
|
if(!superhero)
|
|
|
|
logGlobal->warn("No superhero! How could it be transferred?");
|
2023-09-28 18:43:04 +02:00
|
|
|
picNumber = superhero ? superhero->getIconIndex() : 0;
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.appendLocalString(EMetaText::GENERAL_TXT, 719);
|
|
|
|
desc.replaceRawString(getCampaign()->scenario(static_cast<CampaignScenarioID>(bonDescs[i].info2)).scenarioName.toString());
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-06-25 20:16:03 +02:00
|
|
|
case CampaignBonusType::HERO:
|
2018-01-05 19:21:07 +02:00
|
|
|
if(bonDescs[i].info2 == 0xFFFF)
|
|
|
|
{
|
2023-12-23 18:13:31 +02:00
|
|
|
desc.appendLocalString(EMetaText::GENERAL_TXT, 720); // Start with random hero
|
2018-01-05 19:21:07 +02:00
|
|
|
picNumber = -1;
|
|
|
|
picName = "CBONN1A3.BMP";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-12-23 18:13:31 +02:00
|
|
|
desc.appendLocalString(EMetaText::GENERAL_TXT, 715); // Start with %s
|
2023-09-27 22:53:13 +02:00
|
|
|
desc.replaceTextID(CGI->heroh->objects[bonDescs[i].info2]->getNameTextID());
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-09-06 00:08:18 +02:00
|
|
|
std::shared_ptr<CToggleButton> bonusButton = std::make_shared<CToggleButton>(Point(475 + i * 68, 455), AnimationPath::builtin("campaignBonusSelection"), CButton::tooltip(desc.toString(), desc.toString()), nullptr, EShortcut::NONE, false, [this](){
|
|
|
|
if(buttonStart->isActive() && !buttonStart->isBlocked())
|
|
|
|
CBonusSelection::startMap();
|
|
|
|
});
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
if(picNumber != -1)
|
2024-02-29 15:52:11 +02:00
|
|
|
bonusButton->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin(picName), picNumber));
|
|
|
|
else
|
|
|
|
bonusButton->setOverlay(std::make_shared<CPicture>(ImagePath::builtin(picName)));
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
if(CSH->campaignBonus == i)
|
|
|
|
bonusButton->setBorderColor(Colors::BRIGHT_YELLOW);
|
|
|
|
groupBonuses->addToggle(i, bonusButton);
|
|
|
|
}
|
|
|
|
|
2023-06-25 23:01:25 +02:00
|
|
|
if(getCampaign()->getBonusID(CSH->campaignMap))
|
|
|
|
groupBonuses->setSelected(*getCampaign()->getBonusID(CSH->campaignMap));
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBonusSelection::updateAfterStateChange()
|
|
|
|
{
|
2024-02-04 19:56:04 +02:00
|
|
|
if(CSH->getState() != EClientState::GAMEPLAY)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
buttonRestart->disable();
|
2024-01-24 00:45:31 +02:00
|
|
|
buttonVideo->disable();
|
2018-01-05 19:21:07 +02:00
|
|
|
buttonStart->enable();
|
2024-02-04 19:56:04 +02:00
|
|
|
buttonBack->block(!getCampaign()->conqueredScenarios().empty());
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buttonStart->disable();
|
|
|
|
buttonRestart->enable();
|
2024-01-24 00:45:31 +02:00
|
|
|
buttonVideo->enable();
|
2018-01-05 19:21:07 +02:00
|
|
|
buttonBack->block(false);
|
2022-07-27 11:30:54 +02:00
|
|
|
if(buttonDifficultyLeft)
|
|
|
|
buttonDifficultyLeft->disable();
|
|
|
|
if(buttonDifficultyRight)
|
|
|
|
buttonDifficultyRight->disable();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
if(CSH->campaignBonus == -1)
|
|
|
|
{
|
2023-06-25 23:01:25 +02:00
|
|
|
buttonStart->block(getCampaign()->scenario(CSH->campaignMap).travelOptions.bonusesToChoose.size());
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-09-11 18:39:32 +02:00
|
|
|
else
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
buttonStart->block(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto region : regions)
|
|
|
|
region->updateState();
|
|
|
|
|
|
|
|
if(!CSH->mi)
|
|
|
|
return;
|
|
|
|
iconsMapSizes->setFrame(CSH->mi->getMapSizeIconId());
|
2023-09-27 22:53:13 +02:00
|
|
|
mapName->setText(CSH->mi->getNameTranslated());
|
|
|
|
mapDescription->setText(CSH->mi->getDescriptionTranslated());
|
2018-01-05 19:21:07 +02:00
|
|
|
for(size_t i = 0; i < difficultyIcons.size(); i++)
|
|
|
|
{
|
|
|
|
if(i == CSH->si->difficulty)
|
|
|
|
difficultyIcons[i]->enable();
|
|
|
|
else
|
|
|
|
difficultyIcons[i]->disable();
|
|
|
|
}
|
|
|
|
flagbox->recreate();
|
|
|
|
createBonusesIcons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBonusSelection::goBack()
|
|
|
|
{
|
2024-02-04 19:56:04 +02:00
|
|
|
if(CSH->getState() != EClientState::GAMEPLAY)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().popWindows(2);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
close();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
// TODO: we can actually only pop bonus selection interface for custom campaigns
|
|
|
|
// Though this would require clearing CLobbyScreen::bonusSel pointer when poping this interface
|
|
|
|
/*
|
|
|
|
else
|
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
close();
|
2018-01-05 19:21:07 +02:00
|
|
|
CSH->state = EClientState::LOBBY;
|
|
|
|
}
|
|
|
|
*/
|
2024-09-24 21:41:37 +02:00
|
|
|
CMM->playMusic();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBonusSelection::startMap()
|
|
|
|
{
|
2023-09-11 18:39:32 +02:00
|
|
|
if (!CSH->validateGameStart())
|
|
|
|
return;
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
auto showPrologVideo = [=]()
|
|
|
|
{
|
|
|
|
auto exitCb = [=]()
|
|
|
|
{
|
2023-06-25 20:16:03 +02:00
|
|
|
logGlobal->info("Starting scenario %d", static_cast<int>(CSH->campaignMap));
|
2018-01-05 19:21:07 +02:00
|
|
|
CSH->sendStartGame();
|
|
|
|
};
|
|
|
|
|
2023-06-25 23:01:25 +02:00
|
|
|
const CampaignScenario & scenario = getCampaign()->scenario(CSH->campaignMap);
|
2018-01-05 19:21:07 +02:00
|
|
|
if(scenario.prolog.hasPrologEpilog)
|
|
|
|
{
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<CPrologEpilogVideo>(scenario.prolog, exitCb);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
exitCb();
|
|
|
|
}
|
|
|
|
};
|
2022-11-25 12:36:17 +02:00
|
|
|
|
|
|
|
//block buttons immediately
|
|
|
|
buttonStart->block(true);
|
|
|
|
buttonRestart->block(true);
|
2024-01-24 00:45:31 +02:00
|
|
|
buttonVideo->block(true);
|
2022-11-25 12:36:17 +02:00
|
|
|
buttonBack->block(true);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
if(LOCPLINT) // we're currently ingame, so ask for starting new map and end game
|
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
close();
|
2018-01-05 19:21:07 +02:00
|
|
|
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [=]()
|
|
|
|
{
|
|
|
|
showPrologVideo();
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
showPrologVideo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBonusSelection::restartMap()
|
|
|
|
{
|
2018-07-25 00:36:48 +02:00
|
|
|
close();
|
2023-06-26 20:51:10 +02:00
|
|
|
LOCPLINT->showYesNoDialog(
|
|
|
|
CGI->generaltexth->allTexts[67],
|
|
|
|
[=]()
|
|
|
|
{
|
|
|
|
GH.dispatchMainThread(
|
|
|
|
[]()
|
|
|
|
{
|
|
|
|
CSH->sendRestartGame();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
0
|
|
|
|
);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBonusSelection::increaseDifficulty()
|
|
|
|
{
|
|
|
|
CSH->setDifficulty(CSH->si->difficulty + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBonusSelection::decreaseDifficulty()
|
|
|
|
{
|
2021-07-25 12:09:00 +02:00
|
|
|
// avoid negative overflow (0 - 1 = 255)
|
|
|
|
if (CSH->si->difficulty > 0)
|
|
|
|
CSH->setDifficulty(CSH->si->difficulty - 1);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2024-09-24 11:23:10 +02:00
|
|
|
CBonusSelection::CRegion::CRegion(CampaignScenarioID id, bool accessible, bool selectable, bool labelOnly, const CampaignRegions & campDsc)
|
|
|
|
: CIntObject(LCLICK | SHOW_POPUP), idOfMapAndRegion(id), accessible(accessible), selectable(selectable), labelOnly(labelOnly)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-06-26 00:42:53 +02:00
|
|
|
pos += campDsc.getPosition(id);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-06-26 00:42:53 +02:00
|
|
|
auto color = CSH->si->campState->scenario(idOfMapAndRegion).regionColor;
|
|
|
|
|
|
|
|
graphicsNotSelected = std::make_shared<CPicture>(campDsc.getAvailableName(id, color));
|
2018-01-05 19:21:07 +02:00
|
|
|
graphicsNotSelected->disable();
|
2023-06-26 00:42:53 +02:00
|
|
|
graphicsSelected = std::make_shared<CPicture>(campDsc.getSelectedName(id, color));
|
2018-01-05 19:21:07 +02:00
|
|
|
graphicsSelected->disable();
|
2023-06-26 00:42:53 +02:00
|
|
|
graphicsStriped = std::make_shared<CPicture>(campDsc.getConqueredName(id, color));
|
2018-01-05 19:21:07 +02:00
|
|
|
graphicsStriped->disable();
|
2023-01-30 13:58:13 +02:00
|
|
|
pos.w = graphicsNotSelected->pos.w;
|
|
|
|
pos.h = graphicsNotSelected->pos.h;
|
2024-09-24 11:23:10 +02:00
|
|
|
|
|
|
|
auto labelPos = campDsc.getLabelPosition(id);
|
|
|
|
if(labelPos)
|
2024-09-24 21:41:37 +02:00
|
|
|
{
|
|
|
|
auto mapHeader = CSH->si->campState->getMapHeader(idOfMapAndRegion);
|
|
|
|
label = std::make_shared<CLabel>((*labelPos).x, (*labelPos).y, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, mapHeader->name.toString());
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBonusSelection::CRegion::updateState()
|
|
|
|
{
|
2024-09-24 11:23:10 +02:00
|
|
|
if(labelOnly)
|
|
|
|
return;
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
if(!accessible)
|
|
|
|
{
|
|
|
|
graphicsNotSelected->disable();
|
|
|
|
graphicsSelected->disable();
|
|
|
|
graphicsStriped->enable();
|
|
|
|
}
|
|
|
|
else if(CSH->campaignMap == idOfMapAndRegion)
|
|
|
|
{
|
|
|
|
graphicsNotSelected->disable();
|
|
|
|
graphicsSelected->enable();
|
|
|
|
graphicsStriped->disable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
graphicsNotSelected->enable();
|
|
|
|
graphicsSelected->disable();
|
|
|
|
graphicsStriped->disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void CBonusSelection::CRegion::clickReleased(const Point & cursorPosition)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2024-09-24 11:23:10 +02:00
|
|
|
if(!labelOnly && selectable && !graphicsNotSelected->getSurface()->isTransparent(cursorPosition - pos.topLeft()))
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
CSH->setCampaignMap(idOfMapAndRegion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void CBonusSelection::CRegion::showPopupWindow(const Point & cursorPosition)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
// FIXME: For some reason "down" is only ever contain indeterminate_value
|
2023-09-28 00:10:28 +02:00
|
|
|
auto & text = CSH->si->campState->scenario(idOfMapAndRegion).regionText;
|
2024-09-24 11:23:10 +02:00
|
|
|
if(!labelOnly && !graphicsNotSelected->getSurface()->isTransparent(cursorPosition - pos.topLeft()) && !text.empty())
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-28 00:10:28 +02:00
|
|
|
CRClickPopup::createAndPush(text.toString());
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|