HeroInfoWindow.cpp 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * HeroInfoWindow.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 "HeroInfoWindow.h"
  12. #include "../widgets/Images.h"
  13. #include "../widgets/TextControls.h"
  14. #include "../../lib/GameLibrary.h"
  15. #include "../../lib/gameState/InfoAboutArmy.h"
  16. #include "../../lib/texts/CGeneralTextHandler.h"
  17. HeroInfoBasicPanel::HeroInfoBasicPanel(const InfoAboutHero & hero, const Point * position, bool initializeBackground)
  18. : CIntObject(0)
  19. {
  20. OBJECT_CONSTRUCTION;
  21. if(position != nullptr)
  22. moveTo(*position);
  23. if(initializeBackground)
  24. {
  25. background = std::make_shared<CPicture>(ImagePath::builtin("CHRPOP"));
  26. background->setPlayerColor(hero.owner);
  27. }
  28. initializeData(hero);
  29. }
  30. void HeroInfoBasicPanel::initializeData(const InfoAboutHero & hero)
  31. {
  32. OBJECT_CONSTRUCTION;
  33. auto attack = hero.details->primskills[0];
  34. auto defense = hero.details->primskills[1];
  35. auto power = hero.details->primskills[2];
  36. auto knowledge = hero.details->primskills[3];
  37. auto morale = hero.details->morale;
  38. auto luck = hero.details->luck;
  39. auto currentSpellPoints = hero.details->mana;
  40. auto maxSpellPoints = hero.details->manaLimit;
  41. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("PortraitsLarge"), hero.getIconIndex(), 0, 10, 6));
  42. //primary stats
  43. labels.push_back(std::make_shared<CLabel>(9, 75, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, LIBRARY->generaltexth->allTexts[380] + ":"));
  44. labels.push_back(std::make_shared<CLabel>(9, 87, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, LIBRARY->generaltexth->allTexts[381] + ":"));
  45. labels.push_back(std::make_shared<CLabel>(9, 99, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, LIBRARY->generaltexth->allTexts[382] + ":"));
  46. labels.push_back(std::make_shared<CLabel>(9, 111, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, LIBRARY->generaltexth->allTexts[383] + ":"));
  47. labels.push_back(std::make_shared<CLabel>(69, 87, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(attack)));
  48. labels.push_back(std::make_shared<CLabel>(69, 99, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(defense)));
  49. labels.push_back(std::make_shared<CLabel>(69, 111, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(power)));
  50. labels.push_back(std::make_shared<CLabel>(69, 123, EFonts::FONT_TINY, ETextAlignment::BOTTOMRIGHT, Colors::WHITE, std::to_string(knowledge)));
  51. //morale+luck
  52. labels.push_back(std::make_shared<CLabel>(9, 131, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, LIBRARY->generaltexth->allTexts[384] + ":"));
  53. labels.push_back(std::make_shared<CLabel>(9, 143, EFonts::FONT_TINY, ETextAlignment::TOPLEFT, Colors::WHITE, LIBRARY->generaltexth->allTexts[385] + ":"));
  54. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("IMRL22"), std::clamp(morale + 3, 0, 6), 0, 47, 131));
  55. icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("ILCK22"), std::clamp(luck + 3, 0, 6), 0, 47, 143));
  56. //spell points
  57. labels.push_back(std::make_shared<CLabel>(39, 174, EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, LIBRARY->generaltexth->allTexts[387]));
  58. labels.push_back(std::make_shared<CLabel>(39, 186, EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, std::to_string(currentSpellPoints) + "/" + std::to_string(maxSpellPoints)));
  59. }
  60. void HeroInfoBasicPanel::update(const InfoAboutHero & updatedInfo)
  61. {
  62. icons.clear();
  63. labels.clear();
  64. initializeData(updatedInfo);
  65. }
  66. void HeroInfoBasicPanel::show(Canvas & to)
  67. {
  68. showAll(to);
  69. CIntObject::show(to);
  70. }
  71. HeroInfoWindow::HeroInfoWindow(const InfoAboutHero & hero, const Point * position)
  72. : CWindowObject(RCLICK_POPUP | SHADOW_DISABLED, ImagePath::builtin("CHRPOP"))
  73. {
  74. OBJECT_CONSTRUCTION;
  75. if(position != nullptr)
  76. moveTo(*position);
  77. background->setPlayerColor(hero.owner); //maybe add this functionality to base class?
  78. content = std::make_shared<HeroInfoBasicPanel>(hero, nullptr, false);
  79. }