CQuestLog.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. for (auto icon : icons)
  62. delete icon;
  63. icons.clear();
  64. int3 tile;
  65. if (q->obj)
  66. {
  67. tile = q->obj->pos;
  68. }
  69. else
  70. {
  71. tile = q->tile;
  72. }
  73. int x,y;
  74. minimap->tileToPixels (tile, x, y);
  75. CQuestIcon * pic = new CQuestIcon ("VwSymbol.def", 3, x, y);
  76. pic->moveBy (Point ( -pic->pos.w/2, -pic->pos.h/2));
  77. pic->callback = std::bind (&CQuestMinimap::iconClicked, this);
  78. icons.push_back(pic);
  79. }
  80. void CQuestMinimap::update()
  81. {
  82. CMinimap::update();
  83. if (currentQuest)
  84. addQuestMarks (currentQuest);
  85. }
  86. void CQuestMinimap::iconClicked()
  87. {
  88. if (currentQuest->obj)
  89. adventureInt->centerOn (currentQuest->obj->pos);
  90. //moveAdvMapSelection();
  91. }
  92. void CQuestMinimap::showAll(SDL_Surface * to)
  93. {
  94. CIntObject::showAll(to); // blitting IntObject directly to hide radar
  95. for (auto pic : icons)
  96. pic->showAll(to);
  97. }
  98. CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
  99. CWindowObject(PLAYER_COLORED | BORDERED, "questDialog.pcx"),
  100. questIndex(0),
  101. currentQuest(nullptr),
  102. quests (Quests),
  103. slider(nullptr)
  104. {
  105. OBJ_CONSTRUCTION_CAPTURING_ALL;
  106. init();
  107. }
  108. void CQuestLog::init()
  109. {
  110. minimap = new CQuestMinimap (Rect (33, 18, 144, 144));
  111. description = new CTextBox ("", Rect(221, 18, 350, 355), 1, FONT_MEDIUM, TOPLEFT, Colors::WHITE);
  112. ok = new CButton(Point(533, 386), "IOKAY.DEF", CGI->generaltexth->zelp[445], boost::bind(&CQuestLog::close,this), SDLK_RETURN);
  113. if (quests.size() > QUEST_COUNT)
  114. slider = new CSlider(Point(189, 184), 230, std::bind (&CQuestLog::sliderMoved, this, _1), QUEST_COUNT, quests.size(), false, CSlider::BROWN);
  115. for (int i = 0; i < quests.size(); ++i)
  116. {
  117. MetaString text;
  118. quests[i].quest->getRolloverText (text, false);
  119. if (quests[i].obj)
  120. text.addReplacement (quests[i].obj->getObjectName()); //get name of the object
  121. CQuestLabel * label = new CQuestLabel (Rect(14, 184 + i * 24, 172,30), FONT_SMALL, TOPLEFT, Colors::WHITE, text.toString());
  122. label->callback = boost::bind(&CQuestLog::selectQuest, this, i);
  123. labels.push_back(label);
  124. }
  125. recreateQuestList (0);
  126. }
  127. void CQuestLog::showAll(SDL_Surface * to)
  128. {
  129. CWindowObject::showAll (to);
  130. for (auto label : labels)
  131. {
  132. label->show(to); //shows only if active
  133. }
  134. if (labels.size() && labels[questIndex]->active)
  135. {
  136. CSDL_Ext::drawBorder(to, Rect::around(labels[questIndex]->pos), int3(Colors::METALLIC_GOLD.r, Colors::METALLIC_GOLD.g, Colors::METALLIC_GOLD.b));
  137. }
  138. description->show(to);
  139. minimap->show(to);
  140. }
  141. void CQuestLog::recreateQuestList (int newpos)
  142. {
  143. for (int i = 0; i < labels.size(); ++i)
  144. {
  145. labels[i]->pos = Rect (pos.x + 14, pos.y + 192 + (i-newpos) * 25, 173, 23);
  146. if (i >= newpos && i < newpos + QUEST_COUNT)
  147. {
  148. labels[i]->activate();
  149. }
  150. else
  151. {
  152. labels[i]->deactivate();
  153. }
  154. }
  155. minimap->update();
  156. }
  157. void CQuestLog::selectQuest (int which)
  158. {
  159. questIndex = which;
  160. currentQuest = &quests[which];
  161. minimap->currentQuest = currentQuest;
  162. MetaString text;
  163. std::vector<Component> components; //TODO: display them
  164. currentQuest->quest->getVisitText (text, components , currentQuest->quest->isCustomFirst, true);
  165. description->setText (text.toString()); //TODO: use special log entry text
  166. minimap->update();
  167. redraw();
  168. }
  169. void CQuestLog::sliderMoved (int newpos)
  170. {
  171. recreateQuestList (newpos); //move components
  172. redraw();
  173. }