File: UIHelper.cpp

package info (click to toggle)
vcmi 1.7.2%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: sid
  • size: 43,732 kB
  • sloc: cpp: 275,851; ansic: 734; sh: 235; xml: 163; objc: 61; makefile: 50; python: 41
file content (90 lines) | stat: -rw-r--r-- 2,586 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * UIHelper.cpp, part of VCMI engine
 *
 * Authors: listed in file AUTHORS in main folder
 *
 * License: GNU General Public License v2.0 or later
 * Full text of license available in license.txt file, in main folder
 *
 */

#include "StdInc.h"
#include "UIHelper.h"

#include "widgets/CComponent.h"

#include "../lib/mapObjects/CGHeroInstance.h"
#include "../lib/networkPacks/ArtifactLocation.h"
#include "../lib/CRandomGenerator.h"

std::vector<Component> UIHelper::getArtifactsComponents(const CArtifactSet & artSet, const std::vector<MoveArtifactInfo> & movedPack)
{
	std::vector<Component> components;
	for(const auto & artMoveInfo : movedPack)
	{
		const auto art = artSet.getArt(artMoveInfo.dstPos);
		assert(art);

		if(art->isScroll())
			components.emplace_back(ComponentType::SPELL_SCROLL, art->getScrollSpellID());
		else
			components.emplace_back(ComponentType::ARTIFACT, art->getTypeId());
	}
	return components;
}

std::vector<Component> UIHelper::getSpellsComponents(const std::set<SpellID> & spells)
{
	std::vector<Component> components;
	for(const auto & spell : spells)
		components.emplace_back(ComponentType::SPELL, spell);
	return components;
}

soundBase::soundID UIHelper::getNecromancyInfoWindowSound()
{
	return soundBase::soundID(soundBase::pickup01 + CRandomGenerator::getDefault().nextInt(6));
}

std::string UIHelper::getNecromancyInfoWindowText(const CStackBasicDescriptor & stack)
{
	MetaString text;
	if(stack.getCount() > 1) // Practicing the dark arts of necromancy, ... (plural)
	{
		text.appendLocalString(EMetaText::GENERAL_TXT, 145);
		text.replaceNumber(stack.getCount());
	}
	else // Practicing the dark arts of necromancy, ... (singular)
	{
		text.appendLocalString(EMetaText::GENERAL_TXT, 146);
	}
	text.replaceName(stack);
	return text.toString();
}

std::string UIHelper::getArtifactsInfoWindowText()
{
	MetaString text;
	text.appendLocalString(EMetaText::GENERAL_TXT, 30);
	return text.toString();
}

std::string UIHelper::getEagleEyeInfoWindowText(const CGHeroInstance & hero, const std::set<SpellID> & spells)
{
	MetaString text;
	text.appendLocalString(EMetaText::GENERAL_TXT, 221); // Through eagle-eyed observation, %s is able to learn %s
	text.replaceRawString(hero.getNameTranslated());

	auto curSpell = spells.begin();
	text.replaceName(*curSpell++);
	for(int i = 1; i < spells.size(); i++, curSpell++)
	{
		if(i + 1 == spells.size())
			text.appendLocalString(EMetaText::GENERAL_TXT, 141); // " and "
		else
			text.appendRawString(", ");
		text.appendName(*curSpell);
	}
	text.appendRawString(".");
	return text.toString();
}