UIHelper.cpp 2.7 KB

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