CQuestLog.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include "StdInc.h"
  2. #include "CQuestLog.h"
  3. #include "CGameInfo.h"
  4. #include "../lib/CGeneralTextHandler.h"
  5. #include "../CCallback.h"
  6. #include <SDL.h>
  7. #include "UIFramework/SDL_Extensions.h"
  8. #include "CBitmapHandler.h"
  9. #include "CDefHandler.h"
  10. #include "Graphics.h"
  11. #include "CPlayerInterface.h"
  12. #include "CConfigHandler.h"
  13. #include "../lib/CGameState.h"
  14. #include "../lib/CArtHandler.h"
  15. #include "../lib/NetPacks.h"
  16. #include "../lib/CObjectHandler.h"
  17. #include "UIFramework/CGuiHandler.h"
  18. #include "UIFramework/CIntObjectClasses.h"
  19. /*
  20. * CQuestLog.cpp, part of VCMI engine
  21. *
  22. * Authors: listed in file AUTHORS in main folder
  23. *
  24. * License: GNU General Public License v2.0 or later
  25. * Full text of license available in license.txt file, in main folder
  26. *
  27. */
  28. struct QuestInfo;
  29. class CAdvmapInterface;
  30. void CQuestLabel::clickLeft(tribool down, bool previousState)
  31. {
  32. if (down)
  33. callback();
  34. }
  35. void CQuestLabel::showAll(SDL_Surface * to)
  36. {
  37. if (active)
  38. CBoundedLabel::showAll (to);
  39. }
  40. void CQuestMinimap::clickLeft(tribool down, bool previousState)
  41. {
  42. if (down)
  43. {
  44. moveAdvMapSelection();
  45. update();
  46. }
  47. }
  48. void CQuestMinimap::update()
  49. {
  50. CMinimap::update();
  51. if (currentQuest)
  52. addQuestMarks (currentQuest);
  53. }
  54. CQuestLog::CQuestLog (const std::vector<QuestInfo> & Quests) :
  55. CWindowObject(PLAYER_COLORED, "QuestLog.pcx"),
  56. quests (Quests), slider (NULL),
  57. questIndex(0), currentQuest(NULL)
  58. {
  59. OBJ_CONSTRUCTION_CAPTURING_ALL;
  60. init();
  61. }
  62. void CQuestLog::init()
  63. {
  64. minimap = new CQuestMinimap (Rect (47, 33, 144, 144));
  65. description = new CTextBox ("", Rect(245, 33, 350, 355), 1, FONT_MEDIUM, TOPLEFT, Colors::Cornsilk);
  66. ok = new CAdventureMapButton("",CGI->generaltexth->zelp[445].second, boost::bind(&CQuestLog::close,this), 547, 401, "IOKAY.DEF", SDLK_RETURN);
  67. if (quests.size() > QUEST_COUNT)
  68. slider = new CSlider(203, 199, 230, boost::bind (&CQuestLog::sliderMoved, this, _1), QUEST_COUNT, quests.size(), false, 0);
  69. auto map = LOCPLINT->cb->getVisibilityMap(); //TODO: another function to get all tiles?
  70. for (int g = 0; g < map.size(); ++g)
  71. for (int h = 0; h < map[g].size(); ++h)
  72. for (int y = 0; y < map[g][h].size(); ++y)
  73. minimap->showTile (int3 (g, h, y));
  74. for (int i = 0; i < quests.size(); ++i)
  75. {
  76. MetaString text;
  77. quests[i].quest->getRolloverText (text, false);
  78. if (quests[i].obj)
  79. text.addReplacement (quests[i].obj->getHoverText()); //get name of the object
  80. CQuestLabel * label = new CQuestLabel (28, 199 + i * 24, FONT_SMALL, TOPLEFT, Colors::Cornsilk, text.toString());
  81. label->callback = boost::bind(&CQuestLog::selectQuest, this, i);
  82. label->setBounds (172, 30);
  83. labels.push_back(label);
  84. }
  85. recreateQuestList (0);
  86. showAll (screen2);
  87. }
  88. void CQuestLog::showAll(SDL_Surface * to)
  89. {
  90. CIntObject::showAll (to);
  91. BOOST_FOREACH (auto label, labels)
  92. {
  93. label->show(to); //shows only if active
  94. }
  95. if (labels.size() && labels[questIndex]->active)
  96. {
  97. CSDL_Ext::drawBorder(to, Rect::around(labels[questIndex]->pos), int3(Colors::MetallicGold.r, Colors::MetallicGold.g, Colors::MetallicGold.b));
  98. }
  99. description->show(to);
  100. minimap->update();
  101. }
  102. void CQuestLog::recreateQuestList (int newpos)
  103. {
  104. for (int i = 0; i < labels.size(); ++i)
  105. {
  106. labels[i]->pos = Rect (pos.x + 28, pos.y + 207 + (i-newpos) * 25, 173, 23);
  107. if (i >= newpos && i < newpos + QUEST_COUNT)
  108. {
  109. labels[i]->activate();
  110. }
  111. else
  112. {
  113. labels[i]->deactivate();
  114. }
  115. }
  116. }
  117. void CQuestLog::selectQuest (int which)
  118. {
  119. questIndex = which;
  120. currentQuest = &quests[which];
  121. minimap->currentQuest = currentQuest;
  122. if (currentQuest->obj)
  123. {
  124. adventureInt->centerOn (currentQuest->obj->pos);
  125. }
  126. MetaString text;
  127. std::vector<Component> components; //TODO: display them
  128. currentQuest->quest->getVisitText (text, components , currentQuest->quest->isCustomFirst, true);
  129. description->setTxt (text.toString()); //TODO: use special log entry text
  130. redraw();
  131. }
  132. void CQuestLog::sliderMoved (int newpos)
  133. {
  134. recreateQuestList (newpos); //move components
  135. redraw();
  136. }