UIHelper.cpp 2.7 KB

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