UIHelper.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * UIHelper.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 "UIHelper.h"
  12. #include "widgets/CComponent.h"
  13. #include "../lib/CArtHandler.h"
  14. #include "../lib/CArtifactInstance.h"
  15. #include "../lib/mapObjects/CGHeroInstance.h"
  16. #include "../lib/networkPacks/ArtifactLocation.h"
  17. #include "../lib/CRandomGenerator.h"
  18. #include "../lib/CCreatureSet.h"
  19. std::vector<Component> UIHelper::getArtifactsComponents(const CArtifactSet & artSet, const std::vector<MoveArtifactInfo> & movedPack)
  20. {
  21. std::vector<Component> components;
  22. for(const auto & artMoveInfo : movedPack)
  23. {
  24. const auto art = artSet.getArt(artMoveInfo.dstPos);
  25. assert(art);
  26. if(art->isScroll())
  27. components.emplace_back(ComponentType::SPELL_SCROLL, art->getScrollSpellID());
  28. else
  29. components.emplace_back(ComponentType::ARTIFACT, art->getTypeId());
  30. }
  31. return components;
  32. }
  33. std::vector<Component> UIHelper::getSpellsComponents(const std::set<SpellID> & spells)
  34. {
  35. std::vector<Component> components;
  36. for(const auto & spell : spells)
  37. components.emplace_back(ComponentType::SPELL, spell);
  38. return components;
  39. }
  40. soundBase::soundID UIHelper::getNecromancyInfoWindowSound()
  41. {
  42. return soundBase::soundID(soundBase::pickup01 + CRandomGenerator::getDefault().nextInt(6));
  43. }
  44. std::string UIHelper::getNecromancyInfoWindowText(const CStackBasicDescriptor & stack)
  45. {
  46. MetaString text;
  47. if(stack.count > 1) // Practicing the dark arts of necromancy, ... (plural)
  48. {
  49. text.appendLocalString(EMetaText::GENERAL_TXT, 145);
  50. text.replaceNumber(stack.count);
  51. }
  52. else // Practicing the dark arts of necromancy, ... (singular)
  53. {
  54. text.appendLocalString(EMetaText::GENERAL_TXT, 146);
  55. }
  56. text.replaceName(stack);
  57. return text.toString();
  58. }
  59. std::string UIHelper::getArtifactsInfoWindowText()
  60. {
  61. MetaString text;
  62. text.appendLocalString(EMetaText::GENERAL_TXT, 30);
  63. return text.toString();
  64. }
  65. std::string UIHelper::getEagleEyeInfoWindowText(const CGHeroInstance & hero, const std::set<SpellID> & spells)
  66. {
  67. MetaString text;
  68. text.appendLocalString(EMetaText::GENERAL_TXT, 221); // Through eagle-eyed observation, %s is able to learn %s
  69. text.replaceRawString(hero.getNameTranslated());
  70. auto curSpell = spells.begin();
  71. text.replaceName(*curSpell++);
  72. for(int i = 1; i < spells.size(); i++, curSpell++)
  73. {
  74. if(i + 1 == spells.size())
  75. text.appendLocalString(EMetaText::GENERAL_TXT, 141); // " and "
  76. else
  77. text.appendRawString(", ");
  78. text.appendName(*curSpell);
  79. }
  80. text.appendRawString(".");
  81. return text.toString();
  82. }