2
0

CQuestLog.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include "StdInc.h"
  2. #include "CQuestLog.h"
  3. #include "CAdvmapInterface.h"
  4. #include "../CBitmapHandler.h"
  5. #include "../CDefHandler.h"
  6. #include "../CGameInfo.h"
  7. #include "../CPlayerInterface.h"
  8. #include "../Graphics.h"
  9. #include "../gui/CGuiHandler.h"
  10. #include "../gui/SDL_Extensions.h"
  11. #include "../../CCallback.h"
  12. #include "../../lib/CArtHandler.h"
  13. #include "../../lib/CConfigHandler.h"
  14. #include "../../lib/CGameState.h"
  15. #include "../../lib/CGeneralTextHandler.h"
  16. #include "../../lib/NetPacksBase.h"
  17. /*
  18. * CQuestLog.cpp, part of VCMI engine
  19. *
  20. * Authors: listed in file AUTHORS in main folder
  21. *
  22. * License: GNU General Public License v2.0 or later
  23. * Full text of license available in license.txt file, in main folder
  24. *
  25. */
  26. struct QuestInfo;
  27. class CAdvmapInterface;
  28. void CQuestLabel::clickLeft(tribool down, bool previousState)
  29. {
  30. if (down)
  31. callback();
  32. }
  33. void CQuestLabel::showAll(SDL_Surface * to)
  34. {
  35. if (active)
  36. CMultiLineLabel::showAll (to);
  37. }
  38. CQuestIcon::CQuestIcon (const std::string &defname, int index, int x, int y) :
  39. CAnimImage(defname, index, 0, x, y)
  40. {
  41. addUsedEvents(LCLICK);
  42. }
  43. void CQuestIcon::clickLeft(tribool down, bool previousState)
  44. {
  45. if (down)
  46. callback();
  47. }
  48. void CQuestIcon::showAll(SDL_Surface * to)
  49. {
  50. CSDL_Ext::CClipRectGuard guard(to, parent->pos);
  51. CAnimImage::showAll(to);
  52. }
  53. CQuestMinimap::CQuestMinimap (const Rect & position) :
  54. CMinimap (position),
  55. currentQuest (nullptr)
  56. {
  57. }
  58. void CQuestMinimap::addQuestMarks (const QuestInfo * q)
  59. {
  60. OBJ_CONSTRUCTION_CAPTURING_ALL;
  61. icons.clear();
  62. int3 tile;
  63. if (q->obj)
  64. {
  65. tile = q->obj->pos;
  66. }
  67. else
  68. {
  69. tile = q->tile;
  70. }
  71. int x,y;
  72. minimap->tileToPixels (tile, x, y);
  73. CQuestIcon * pic = new CQuestIcon ("VwSymbol.def", 3, x, y);
  74. pic->moveBy (Point ( -pic->pos.w/2, -pic->pos.h/2));
  75. pic->callback = boost::bind (&CQuestMinimap::iconClicked, this);
  76. icons.push_back(pic);
  77. }
  78. void CQuestMinimap::update()
  79. {
  80. CMinimap::update();
  81. if (currentQuest)
  82. addQuestMarks (currentQuest);
  83. }
  84. void CQuestMinimap::iconClicked()
  85. {
  86. if (currentQuest->obj)
  87. adventureInt->centerOn (currentQuest->obj->pos);
  88. moveAdvMapSelection();
  89. }
  90. void CQuestMinimap::showAll(SDL_Surface * to)
  91. {
  92. CIntObject::showAll(to); // blitting IntObject directly to hide radar
  93. for (auto pic : icons)
  94. pic->showAll(to);
  95. }
  96. CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
  97. CWindowObject(PLAYER_COLORED, "QuestLog.pcx"),
  98. questIndex(0),
  99. currentQuest(nullptr),
  100. quests (Quests),
  101. slider(nullptr)
  102. {
  103. OBJ_CONSTRUCTION_CAPTURING_ALL;
  104. init();
  105. }
  106. void CQuestLog::init()
  107. {
  108. minimap = new CQuestMinimap (Rect (47, 33, 144, 144));
  109. description = new CTextBox ("", Rect(245, 33, 350, 355), 1, FONT_MEDIUM, TOPLEFT, Colors::WHITE);
  110. ok = new CButton(Point(547, 401), "IOKAY.DEF", CGI->generaltexth->zelp[445], boost::bind(&CQuestLog::close,this), SDLK_RETURN);
  111. if (quests.size() > QUEST_COUNT)
  112. slider = new CSlider(203, 199, 230, boost::bind (&CQuestLog::sliderMoved, this, _1), QUEST_COUNT, quests.size(), false, 0);
  113. for (int i = 0; i < quests.size(); ++i)
  114. {
  115. MetaString text;
  116. quests[i].quest->getRolloverText (text, false);
  117. if (quests[i].obj)
  118. text.addReplacement (quests[i].obj->getObjectName()); //get name of the object
  119. CQuestLabel * label = new CQuestLabel (Rect(28, 199 + i * 24, 172,30), FONT_SMALL, TOPLEFT, Colors::WHITE, text.toString());
  120. label->callback = boost::bind(&CQuestLog::selectQuest, this, i);
  121. labels.push_back(label);
  122. }
  123. recreateQuestList (0);
  124. }
  125. void CQuestLog::showAll(SDL_Surface * to)
  126. {
  127. CIntObject::showAll (to);
  128. for (auto label : labels)
  129. {
  130. label->show(to); //shows only if active
  131. }
  132. if (labels.size() && labels[questIndex]->active)
  133. {
  134. CSDL_Ext::drawBorder(to, Rect::around(labels[questIndex]->pos), int3(Colors::METALLIC_GOLD.r, Colors::METALLIC_GOLD.g, Colors::METALLIC_GOLD.b));
  135. }
  136. description->show(to);
  137. minimap->update();
  138. minimap->show(to);
  139. }
  140. void CQuestLog::recreateQuestList (int newpos)
  141. {
  142. for (int i = 0; i < labels.size(); ++i)
  143. {
  144. labels[i]->pos = Rect (pos.x + 28, pos.y + 207 + (i-newpos) * 25, 173, 23);
  145. if (i >= newpos && i < newpos + QUEST_COUNT)
  146. {
  147. labels[i]->activate();
  148. }
  149. else
  150. {
  151. labels[i]->deactivate();
  152. }
  153. }
  154. }
  155. void CQuestLog::selectQuest (int which)
  156. {
  157. questIndex = which;
  158. currentQuest = &quests[which];
  159. minimap->currentQuest = currentQuest;
  160. MetaString text;
  161. std::vector<Component> components; //TODO: display them
  162. currentQuest->quest->getVisitText (text, components , currentQuest->quest->isCustomFirst, true);
  163. description->setText (text.toString()); //TODO: use special log entry text
  164. redraw();
  165. }
  166. void CQuestLog::sliderMoved (int newpos)
  167. {
  168. recreateQuestList (newpos); //move components
  169. redraw();
  170. }