1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/client/windows/CHeroOverview.cpp

237 lines
13 KiB
C++
Raw Normal View History

2023-09-17 00:32:10 +02:00
/*
* CHeroOverview.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 "CHeroOverview.h"
#include "../CGameInfo.h"
#include "../gui/CGuiHandler.h"
2023-09-17 02:14:03 +02:00
#include "../render/Canvas.h"
2023-09-17 00:32:10 +02:00
#include "../render/Colors.h"
2023-09-17 02:14:03 +02:00
#include "../render/IImage.h"
#include "../renderSDL/RenderHandler.h"
2023-09-17 00:32:10 +02:00
#include "../widgets/CComponent.h"
#include "../widgets/Images.h"
#include "../widgets/TextControls.h"
#include "../widgets/GraphicalPrimitiveCanvas.h"
2023-09-17 00:32:10 +02:00
2023-09-17 23:01:18 +02:00
#include "../../lib/GameSettings.h"
#include "../../lib/texts/CGeneralTextHandler.h"
2023-09-17 13:22:39 +02:00
#include "../../lib/CCreatureHandler.h"
2023-09-17 00:32:10 +02:00
#include "../../lib/CHeroHandler.h"
2023-09-17 15:28:05 +02:00
#include "../../lib/CSkillHandler.h"
#include "../../lib/spells/CSpellHandler.h"
2023-09-17 00:32:10 +02:00
CHeroOverview::CHeroOverview(const HeroTypeID & h)
2023-09-17 13:22:39 +02:00
: CWindowObject(BORDERED | RCLICK_POPUP), hero { h }
2023-09-17 00:32:10 +02:00
{
OBJECT_CONSTRUCTION;
2023-09-17 00:32:10 +02:00
2023-09-17 21:41:55 +02:00
heroIdx = hero.getNum();
2023-09-17 13:22:39 +02:00
2023-09-17 16:55:26 +02:00
pos = Rect(0, 0, 600, 485);
2023-09-17 16:15:17 +02:00
2023-09-17 16:55:26 +02:00
genBackground();
genControls();
2023-09-17 00:32:10 +02:00
center();
}
2023-09-17 16:55:26 +02:00
void CHeroOverview::genBackground()
2023-09-17 00:32:10 +02:00
{
backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), pos);
updateShadow();
2023-09-17 16:55:26 +02:00
}
2023-09-17 02:14:03 +02:00
2023-09-17 16:55:26 +02:00
void CHeroOverview::genControls()
{
2023-09-17 21:41:55 +02:00
Rect r = Rect();
2023-09-17 00:32:10 +02:00
labelTitle = std::make_shared<CLabel>(pos.w / 2 + 8, 21, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[77]);
2023-09-17 02:14:03 +02:00
2023-09-17 03:21:29 +02:00
// hero image
2023-09-17 21:41:55 +02:00
r = Rect(borderOffset, borderOffset + yOffset, 58, 64);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
imageHero = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), (*CGI->heroh)[heroIdx]->imageIndex, 0, r.x, r.y);
2023-09-17 02:14:03 +02:00
2023-09-17 03:21:29 +02:00
// hero name
2023-09-17 21:41:55 +02:00
r = Rect(64 + borderOffset, borderOffset + yOffset, 220, 64);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
labelHeroName = std::make_shared<CLabel>(r.x + 110, r.y + 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, (*CGI->heroh)[heroIdx]->getNameTranslated());
labelHeroClass = std::make_shared<CLabel>(r.x + 110, r.y + 45, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, (*CGI->heroh)[heroIdx]->heroClass->getNameTranslated());
2023-09-17 03:21:29 +02:00
2023-09-17 21:41:55 +02:00
// vertical line
backgroundLines.push_back(std::make_shared<SimpleLine>(Point(295, borderOffset + yOffset - 1), Point(295, borderOffset + yOffset - 2 + 439), borderColor));
2023-09-17 04:10:08 +02:00
// skills header
2023-09-17 21:41:55 +02:00
r = Rect(borderOffset, 2 * borderOffset + yOffset + 64, 284, 20);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
2023-09-17 04:10:08 +02:00
for(int i = 0; i < 4; i++)
2023-09-17 21:41:55 +02:00
labelSkillHeader.push_back(std::make_shared<CLabel>((r.w / 4) * i + 42, r.y + 10, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->jktexts[1 + i]));
2023-09-17 04:10:08 +02:00
// skill
2023-09-17 16:15:17 +02:00
const int tmp[] = {0, 1, 2, 5};
2023-09-17 04:10:08 +02:00
for(int i = 0; i < 4; i++)
2023-09-17 21:41:55 +02:00
{
r = Rect((284 / 4) * i + 21, 3 * borderOffset + yOffset + 85, 42, 42);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
imageSkill.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("PSKIL42"), tmp[i], 0, r.x, r.y));
}
2023-09-17 04:10:08 +02:00
// skills footer
2023-09-17 21:41:55 +02:00
r = Rect(borderOffset, 4 * borderOffset + yOffset + 128, 284, 20);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
2023-09-17 04:10:08 +02:00
for(int i = 0; i < 4; i++)
2023-09-17 21:41:55 +02:00
{
r = Rect((284 / 4) * i + 42, r.y, r.w, r.h);
labelSkillFooter.push_back(std::make_shared<CLabel>(r.x, r.y + 10, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, std::to_string((*CGI->heroh)[heroIdx]->heroClass->primarySkillInitial[i])));
}
2023-09-17 04:10:08 +02:00
2023-09-17 03:21:29 +02:00
// hero biography
2023-09-17 21:41:55 +02:00
r = Rect(borderOffset, 5 * borderOffset + yOffset + 148, 284, 130);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
labelHeroBiography = std::make_shared<CMultiLineLabel>(r.resize(-borderOffset), FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, (*CGI->heroh)[heroIdx]->getBiographyTranslated());
2023-09-17 03:21:29 +02:00
// speciality name
2023-09-17 21:41:55 +02:00
r = Rect(2 * borderOffset + 44, 6 * borderOffset + yOffset + 278, 235, 44);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
labelHeroSpeciality = std::make_shared<CLabel>(r.x + borderOffset, r.y + borderOffset, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[78]);
labelSpecialityName = std::make_shared<CLabel>(r.x + borderOffset, r.y + borderOffset + 20, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, (*CGI->heroh)[heroIdx]->getSpecialtyNameTranslated());
2023-09-17 03:21:29 +02:00
// speciality image
2023-09-17 21:41:55 +02:00
r = Rect(borderOffset, 6 * borderOffset + yOffset + 278, 44, 44);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
imageSpeciality = std::make_shared<CAnimImage>(AnimationPath::builtin("UN44"), (*CGI->heroh)[heroIdx]->imageIndex, 0, r.x, r.y);
2023-09-17 03:21:29 +02:00
// speciality description
2023-09-17 21:41:55 +02:00
r = Rect(borderOffset, 7 * borderOffset + yOffset + 322, 284, 85);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
labelSpecialityDescription = std::make_shared<CMultiLineLabel>(r.resize(-borderOffset), FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, (*CGI->heroh)[heroIdx]->getSpecialtyDescriptionTranslated());
2023-09-17 13:22:39 +02:00
// army title
2023-09-17 21:41:55 +02:00
r = Rect(302, borderOffset + yOffset, 292, 30);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
labelArmyTitle = std::make_shared<CLabel>(r.x + borderOffset, r.y + borderOffset + 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->translate("vcmi.heroOverview.startingArmy"));
// army numbers
2023-09-17 23:01:18 +02:00
r = Rect(302, 3 * borderOffset + yOffset + 62, 292, 32);
2023-09-17 21:41:55 +02:00
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
2023-09-17 13:22:39 +02:00
auto stacksCountChances = CGI->settings()->getVector(EGameSettings::HEROES_STARTING_STACKS_CHANCES);
2023-09-17 23:01:18 +02:00
2023-09-17 13:22:39 +02:00
// army
2023-09-17 21:55:35 +02:00
int space = (260 - 7 * 32) / 6;
for(int i = 0; i < 7; i++)
2023-09-17 21:41:55 +02:00
{
r = Rect(318 + i * (32 + space), 2 * borderOffset + yOffset + 30, 32, 32);
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
}
2023-09-17 13:22:39 +02:00
int i = 0;
2023-09-17 23:01:18 +02:00
int iStack = 0;
2023-09-17 21:41:55 +02:00
for(auto & army : (*CGI->heroh)[heroIdx]->initialArmy)
2023-09-17 13:22:39 +02:00
{
if((*CGI->creh)[army.creature]->warMachine == ArtifactID::NONE)
{
2023-09-17 14:31:07 +02:00
imageArmy.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("CPRSMALL"), (*CGI->creh)[army.creature]->getIconIndex(), 0, 302 + i * (32 + space) + 16, 2 * borderOffset + yOffset + 30));
2023-09-17 16:55:26 +02:00
labelArmyCount.push_back(std::make_shared<CLabel>(302 + i * (32 + space) + 32, 3 * borderOffset + yOffset + 72, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, (army.minAmount == army.maxAmount) ? std::to_string(army.minAmount) : std::to_string(army.minAmount) + "-" + std::to_string(army.maxAmount)));
2023-09-17 23:01:18 +02:00
if(iStack<stacksCountChances.size())
labelArmyCount.push_back(std::make_shared<CLabel>(302 + i * (32 + space) + 32, 3 * borderOffset + yOffset + 86, FONT_SMALL, ETextAlignment::CENTER, grayedColor, std::to_string(stacksCountChances[iStack]) + "%"));
2023-09-17 13:22:39 +02:00
i++;
}
2023-09-17 23:01:18 +02:00
iStack++;
2023-09-17 13:22:39 +02:00
}
// war machine title
2023-09-17 23:01:18 +02:00
r = Rect(302, 4 * borderOffset + yOffset + 94, 292, 30);
2023-09-17 21:41:55 +02:00
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
labelWarMachineTitle = std::make_shared<CLabel>(r.x + borderOffset, r.y + borderOffset + 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->translate("vcmi.heroOverview.warMachine"));
2023-09-17 13:22:39 +02:00
// war machine
2023-09-17 21:55:35 +02:00
space = (260 - 4 * 32) / 3;
for(int i = 0; i < 4; i++)
2023-09-17 21:41:55 +02:00
{
2023-09-17 23:01:18 +02:00
r = Rect(318 + i * (32 + space), 5 * borderOffset + yOffset + 124, 32, 32);
2023-09-17 21:41:55 +02:00
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
}
2023-09-17 13:22:39 +02:00
i = 0;
2023-09-17 23:01:18 +02:00
iStack = 0;
2023-09-17 21:41:55 +02:00
for(auto & army : (*CGI->heroh)[heroIdx]->initialArmy)
2023-09-17 13:22:39 +02:00
{
2023-09-17 14:31:07 +02:00
if(i == 0)
{
2023-09-17 23:01:18 +02:00
imageWarMachine.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("CPRSMALL"), (*CGI->creh)[army.creature.CATAPULT]->getIconIndex(), 0, 302 + i * (32 + space) + 16, 5 * borderOffset + yOffset + 124));
labelArmyCount.push_back(std::make_shared<CLabel>(302 + i * (32 + space) + 51, 5 * borderOffset + yOffset + 144, FONT_SMALL, ETextAlignment::TOPLEFT, grayedColor, "100%"));
2023-09-17 14:31:07 +02:00
i++;
}
2023-09-17 13:22:39 +02:00
if((*CGI->creh)[army.creature]->warMachine != ArtifactID::NONE)
{
2023-09-17 23:01:18 +02:00
imageWarMachine.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("CPRSMALL"), (*CGI->creh)[army.creature]->getIconIndex(), 0, 302 + i * (32 + space) + 16, 5 * borderOffset + yOffset + 124));
if(iStack<stacksCountChances.size())
labelArmyCount.push_back(std::make_shared<CLabel>(302 + i * (32 + space) + 51, 5 * borderOffset + yOffset + 144, FONT_SMALL, ETextAlignment::TOPLEFT, grayedColor, std::to_string(stacksCountChances[iStack]) + "%"));
2023-09-17 13:22:39 +02:00
i++;
}
2023-09-17 23:01:18 +02:00
iStack++;
2023-09-17 13:22:39 +02:00
}
2023-09-17 14:31:07 +02:00
2023-09-17 15:28:05 +02:00
// secskill title
2023-09-17 23:01:18 +02:00
r = Rect(302, 6 * borderOffset + yOffset + 156, (292 / 2) - 2 * borderOffset, 30);
2023-09-17 21:41:55 +02:00
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
labelSecSkillTitle = std::make_shared<CLabel>(r.x + borderOffset, r.y + borderOffset + 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->translate("vcmi.heroOverview.secondarySkills"));
// vertical line
2023-09-17 23:01:18 +02:00
backgroundLines.push_back(std::make_shared<SimpleLine>(Point(302 + (292 / 2), 6 * borderOffset + yOffset + 156 - 1), Point(302 + (292 / 2), 6 * borderOffset + yOffset + 156 - 2 + 254), borderColor));
2023-09-17 14:31:07 +02:00
2023-09-17 15:28:05 +02:00
// spell title
2023-09-17 23:01:18 +02:00
r = Rect(302 + (292 / 2) + 2 * borderOffset, 6 * borderOffset + yOffset + 156, (292 / 2) - 2 * borderOffset, 30);
2023-09-17 21:41:55 +02:00
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
labelSpellTitle = std::make_shared<CLabel>(r.x + borderOffset, r.y + borderOffset + 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->translate("vcmi.heroOverview.spells"));
2023-09-17 14:31:07 +02:00
2023-09-17 15:28:05 +02:00
// secskill
2023-09-17 21:41:55 +02:00
for(int i = 0; i < 6; i++)
{
2023-09-17 23:01:18 +02:00
r = Rect(302, 7 * borderOffset + yOffset + 186 + i * (32 + borderOffset), 32, 32);
2023-09-17 21:41:55 +02:00
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
2023-09-17 21:55:35 +02:00
r = Rect(r.x + 32 + borderOffset, r.y, (292 / 2) - 32 - 3 * borderOffset, r.h);
2023-09-17 21:41:55 +02:00
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
}
2023-09-17 15:28:05 +02:00
i = 0;
2023-09-17 21:41:55 +02:00
for(auto & skill : (*CGI->heroh)[heroIdx]->secSkillsInit)
2023-09-17 15:28:05 +02:00
{
2023-09-17 23:01:18 +02:00
imageSecSkills.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("SECSK32"), (*CGI->skillh)[skill.first]->getIconIndex() * 3 + skill.second + 2, 0, 302, 7 * borderOffset + yOffset + 186 + i * (32 + borderOffset)));
labelSecSkillsNames.push_back(std::make_shared<CLabel>(334 + 2 * borderOffset, 8 * borderOffset + yOffset + 186 + i * (32 + borderOffset) - 5, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->levels[skill.second - 1]));
labelSecSkillsNames.push_back(std::make_shared<CLabel>(334 + 2 * borderOffset, 8 * borderOffset + yOffset + 186 + i * (32 + borderOffset) + 10, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, (*CGI->skillh)[skill.first]->getNameTranslated()));
2023-09-17 15:28:05 +02:00
i++;
}
// spell
2023-09-17 21:41:55 +02:00
for(int i = 0; i < 6; i++)
{
2023-09-17 23:01:18 +02:00
r = Rect(302 + (292 / 2) + 2 * borderOffset, 7 * borderOffset + yOffset + 186 + i * (32 + borderOffset), 32, 32);
2023-09-17 21:41:55 +02:00
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
2023-09-17 21:55:35 +02:00
r = Rect(r.x + 32 + borderOffset, r.y, (292 / 2) - 32 - 3 * borderOffset, r.h);
2023-09-17 21:41:55 +02:00
backgroundRectangles.push_back(std::make_shared<TransparentFilledRectangle>(r.resize(1), rectangleColor, borderColor));
}
2023-09-17 15:28:05 +02:00
i = 0;
2023-09-17 21:41:55 +02:00
for(auto & spell : (*CGI->heroh)[heroIdx]->spells)
2023-09-17 15:28:05 +02:00
{
2023-09-17 16:15:17 +02:00
if(i == 0)
{
2023-09-17 21:41:55 +02:00
if((*CGI->heroh)[heroIdx]->haveSpellBook)
2023-09-17 16:15:17 +02:00
{
imageSpells.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("ARTIFACT"), 0, Rect(302 + (292 / 2) + 2 * borderOffset, 7 * borderOffset + yOffset + 186 + i * (32 + borderOffset), 32, 32), 0));
2023-09-17 16:15:17 +02:00
}
i++;
}
imageSpells.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("SPELLBON"), (*CGI->spellh)[spell]->getIconIndex(), Rect(302 + (292 / 2) + 2 * borderOffset, 7 * borderOffset + yOffset + 186 + i * (32 + borderOffset), 32, 32), 0));
2023-09-17 23:01:18 +02:00
labelSpellsNames.push_back(std::make_shared<CLabel>(302 + (292 / 2) + 3 * borderOffset + 32 + borderOffset, 8 * borderOffset + yOffset + 186 + i * (32 + borderOffset) + 3, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, (*CGI->spellh)[spell]->getNameTranslated()));
2023-09-17 15:28:05 +02:00
i++;
}
}