CHeroOverview.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * CHeroOverview.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CHeroOverview.h"
  12. #include "../CGameInfo.h"
  13. #include "../gui/CGuiHandler.h"
  14. #include "../render/Canvas.h"
  15. #include "../render/Colors.h"
  16. #include "../render/Graphics.h"
  17. #include "../render/IImage.h"
  18. #include "../renderSDL/RenderHandler.h"
  19. #include "../widgets/CComponent.h"
  20. #include "../widgets/Images.h"
  21. #include "../widgets/TextControls.h"
  22. #include "../../lib/CGeneralTextHandler.h"
  23. #include "../../lib/CHeroHandler.h"
  24. CHeroOverview::CHeroOverview(const HeroTypeID & h)
  25. : CWindowObject(BORDERED | RCLICK_POPUP), /*hero { h },*/ heroIndex { h.getNum() }
  26. {
  27. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  28. genHeroWindow();
  29. center();
  30. }
  31. void CHeroOverview::genHeader()
  32. {
  33. backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), pos);
  34. updateShadow();
  35. int yOffset = 35;
  36. int borderOffset = 5;
  37. int alpha = 75;
  38. ColorRGBA borderColor = ColorRGBA(128, 100, 75);
  39. Canvas canvas = Canvas(Point(pos.w, pos.h));
  40. // hero image
  41. canvas.drawBorder(Rect(borderOffset - 1, borderOffset + yOffset - 1, 58 + 2, 64 + 2), borderColor);
  42. // hero name
  43. canvas.drawColorBlended(Rect(64 + borderOffset, borderOffset + yOffset, 220, 64), ColorRGBA(0, 0, 0, alpha));
  44. canvas.drawBorder(Rect(64 + borderOffset - 1, borderOffset + yOffset - 1, 220 + 2, 64 + 2), borderColor);
  45. // vertical line
  46. canvas.drawLine(Point(295, borderOffset + yOffset - 1), Point(295, 445), borderColor, borderColor);
  47. // skill header
  48. canvas.drawColorBlended(Rect(borderOffset, 2 * borderOffset + yOffset + 64, 284, 20), ColorRGBA(0, 0, 0, alpha));
  49. canvas.drawBorder(Rect(borderOffset - 1, 2 * borderOffset + yOffset + 64 - 1, 284 + 2, 20 + 2), borderColor);
  50. // skill
  51. for(int i = 0; i < 4; i++)
  52. canvas.drawBorder(Rect((284 / 4) * i + 21 - 1, 3 * borderOffset + yOffset + 64 + 20 + 1 - 1, 42 + 2, 42 + 2), borderColor);
  53. // skill footer
  54. canvas.drawColorBlended(Rect(borderOffset, 4 * borderOffset + yOffset + 64 + 20 + 44, 284, 20), ColorRGBA(0, 0, 0, alpha));
  55. canvas.drawBorder(Rect(borderOffset - 1, 4 * borderOffset + yOffset + 64 + 20 + 44 - 1, 284 + 2, 20 + 2), borderColor);
  56. // hero biography
  57. canvas.drawColorBlended(Rect(borderOffset, 5 * borderOffset + yOffset + 64 + 20 + 44 + 20, 284, 130), ColorRGBA(0, 0, 0, alpha));
  58. canvas.drawBorder(Rect(borderOffset - 1, 5 * borderOffset + yOffset + 64 + 20 + 44 + 20 - 1, 284 + 2, 130 + 2), borderColor);
  59. // speciality name
  60. canvas.drawColorBlended(Rect(2 * borderOffset + 44, 6 * borderOffset + yOffset + 64 + 20 + 44 + 20 + 130, 235, 44), ColorRGBA(0, 0, 0, alpha));
  61. canvas.drawBorder(Rect(2 * borderOffset + 44 - 1, 6 * borderOffset + yOffset + 64 + 20 + 44 + 20 + 130 - 1, 235 + 2, 44 + 2), borderColor);
  62. // speciality image
  63. canvas.drawBorder(Rect(borderOffset - 1, 6 * borderOffset + yOffset + 64 + 20 + 44 + 20 + 130 - 1, 44 + 2, 44 + 2), borderColor);
  64. // speciality description
  65. canvas.drawColorBlended(Rect(borderOffset, 7 * borderOffset + yOffset + 64 + 20 + 44 + 20 + 130 + 44, 284, 85), ColorRGBA(0, 0, 0, alpha));
  66. canvas.drawBorder(Rect(borderOffset - 1, 7 * borderOffset + yOffset + 64 + 20 + 44 + 20 + 130 + 44 - 1, 284 + 2, 85 + 2), borderColor);
  67. std::shared_ptr<IImage> backgroundShapesImg = GH.renderHandler().createImage(canvas.getInternalSurface());
  68. backgroundShapes = std::make_shared<CPicture>(backgroundShapesImg, pos);
  69. labelTitle = std::make_shared<CLabel>(pos.w / 2 + 8, 21, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[77]);
  70. // hero image
  71. image = std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), (*CGI->heroh)[heroIndex]->imageIndex, 0, borderOffset, borderOffset + yOffset);
  72. // hero name
  73. labelHeroName = std::make_shared<CLabel>(64 + borderOffset + 110, borderOffset + yOffset + 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, (*CGI->heroh)[heroIndex]->getNameTranslated());
  74. labelHeroClass = std::make_shared<CLabel>(64 + borderOffset + 110, borderOffset + yOffset + 45, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, (*CGI->heroh)[heroIndex]->heroClass->getNameTranslated());
  75. // skills header
  76. for(int i = 0; i < 4; i++)
  77. labelSkillHeader.push_back(std::make_shared<CLabel>((284 / 4) * i + 42, 2 * borderOffset + yOffset + 64 + 10, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->jktexts[1 + i]));
  78. // skill
  79. for(int i = 0; i < 4; i++)
  80. imageSkill.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("PSKIL42"), (const int[]){0, 1, 2, 5}[i], 0, (284 / 4) * i + 21, 3 * borderOffset + yOffset + 64 + 20 + 1));
  81. // skills footer
  82. for(int i = 0; i < 4; i++)
  83. labelSkillFooter.push_back(std::make_shared<CLabel>((284 / 4) * i + 42, 4 * borderOffset + yOffset + 64 + 20 + 44 + 10, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, std::to_string((*CGI->heroh)[heroIndex]->heroClass->primarySkillInitial[i])));
  84. // hero biography
  85. labelHeroBiography = std::make_shared<CMultiLineLabel>(Rect(2 * borderOffset, 5 * borderOffset + borderOffset + yOffset + 64 + 20 + 44 + 20, 284 - 2 * borderOffset, 130 - 2 * borderOffset), FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, (*CGI->heroh)[heroIndex]->getBiographyTranslated());
  86. // speciality name
  87. labelHeroSpeciality = std::make_shared<CLabel>(3 * borderOffset + 44, 7 * borderOffset + yOffset + 64 + 20 + 44 + 20 + 130, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[78]);
  88. labelSpecialityName = std::make_shared<CLabel>(3 * borderOffset + 44, 7 * borderOffset + yOffset + 64 + 20 + 44 + 20 + 130 + 20, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, (*CGI->heroh)[heroIndex]->getSpecialtyNameTranslated());
  89. // speciality image
  90. imageSpeciality = std::make_shared<CAnimImage>(AnimationPath::builtin("UN44"), (*CGI->heroh)[heroIndex]->imageIndex, 0, borderOffset, 6 * borderOffset + yOffset + 64 + 20 + 44 + 20 + 130);
  91. // speciality description
  92. labelSpecialityDescription = std::make_shared<CMultiLineLabel>(Rect(2 * borderOffset, 8 * borderOffset + yOffset + 64 + 20 + 44 + 20 + 130 + 44 - 1, 284 - borderOffset, 85 - borderOffset), FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, (*CGI->heroh)[heroIndex]->getSpecialtyDescriptionTranslated());
  93. }
  94. void CHeroOverview::genHeroWindow()
  95. {
  96. pos = Rect(0, 0, 450, 450 + 35);
  97. genHeader();
  98. }