CResDataBar.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * CAdvmapInterface.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 "CAdvmapInterface.h"
  12. #include "CCastleInterface.h"
  13. #include "CHeroWindow.h"
  14. #include "CKingdomInterface.h"
  15. #include "CSpellWindow.h"
  16. #include "CTradeWindow.h"
  17. #include "GUIClasses.h"
  18. #include "InfoWindows.h"
  19. #include "../CBitmapHandler.h"
  20. #include "../CGameInfo.h"
  21. #include "../CMessage.h"
  22. #include "../CMusicHandler.h"
  23. #include "../CPlayerInterface.h"
  24. #include "../mainmenu/CMainMenu.h"
  25. #include "../lobby/CSelectionBase.h"
  26. #include "../lobby/CCampaignInfoScreen.h"
  27. #include "../lobby/CSavingScreen.h"
  28. #include "../lobby/CScenarioInfoScreen.h"
  29. #include "../Graphics.h"
  30. #include "../mapHandler.h"
  31. #include "../gui/CAnimation.h"
  32. #include "../gui/CursorHandler.h"
  33. #include "../gui/CGuiHandler.h"
  34. #include "../gui/SDL_Extensions.h"
  35. #include "../widgets/MiscWidgets.h"
  36. #include "../../CCallback.h"
  37. #include "../../lib/CConfigHandler.h"
  38. #include "../../lib/CGameState.h"
  39. #include "../../lib/CGeneralTextHandler.h"
  40. #include "../../lib/CHeroHandler.h"
  41. #include "../../lib/CSoundBase.h"
  42. #include "../../lib/spells/CSpellHandler.h"
  43. #include "../../lib/CTownHandler.h"
  44. #include "../../lib/JsonNode.h"
  45. #include "../../lib/mapObjects/CGHeroInstance.h"
  46. #include "../../lib/mapping/CMap.h"
  47. #include "../../lib/UnlockGuard.h"
  48. #include "../../lib/VCMI_Lib.h"
  49. #include "../../lib/StartInfo.h"
  50. #include "../../lib/mapping/CMapInfo.h"
  51. #include "../../lib/TerrainHandler.h"
  52. #include <SDL_surface.h>
  53. #include <SDL_events.h>
  54. #define ADVOPT (conf.go()->ac)
  55. using namespace CSDL_Ext;
  56. std::shared_ptr<CAdvMapInt> adventureInt;
  57. static void setScrollingCursor(ui8 direction)
  58. {
  59. if(direction & CAdvMapInt::RIGHT)
  60. {
  61. if(direction & CAdvMapInt::UP)
  62. CCS->curh->set(Cursor::Map::SCROLL_NORTHEAST);
  63. else if(direction & CAdvMapInt::DOWN)
  64. CCS->curh->set(Cursor::Map::SCROLL_SOUTHEAST);
  65. else
  66. CCS->curh->set(Cursor::Map::SCROLL_EAST);
  67. }
  68. else if(direction & CAdvMapInt::LEFT)
  69. {
  70. if(direction & CAdvMapInt::UP)
  71. CCS->curh->set(Cursor::Map::SCROLL_NORTHWEST);
  72. else if(direction & CAdvMapInt::DOWN)
  73. CCS->curh->set(Cursor::Map::SCROLL_SOUTHWEST);
  74. else
  75. CCS->curh->set(Cursor::Map::SCROLL_WEST);
  76. }
  77. else if(direction & CAdvMapInt::UP)
  78. CCS->curh->set(Cursor::Map::SCROLL_NORTH);
  79. else if(direction & CAdvMapInt::DOWN)
  80. CCS->curh->set(Cursor::Map::SCROLL_SOUTH);
  81. }
  82. void CResDataBar::clickRight(tribool down, bool previousState)
  83. {
  84. }
  85. CResDataBar::CResDataBar(const std::string & defname, int x, int y, int offx, int offy, int resdist, int datedist)
  86. {
  87. pos.x += x;
  88. pos.y += y;
  89. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  90. background = std::make_shared<CPicture>(defname, 0, 0);
  91. background->colorize(LOCPLINT->playerID);
  92. pos.w = background->pos.w;
  93. pos.h = background->pos.h;
  94. txtpos.resize(8);
  95. for (int i = 0; i < 8 ; i++)
  96. {
  97. txtpos[i].first = pos.x + offx + resdist*i;
  98. txtpos[i].second = pos.y + offy;
  99. }
  100. txtpos[7].first = txtpos[6].first + datedist;
  101. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  102. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  103. addUsedEvents(RCLICK);
  104. }
  105. CResDataBar::CResDataBar()
  106. {
  107. pos.x += ADVOPT.resdatabarX;
  108. pos.y += ADVOPT.resdatabarY;
  109. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  110. background = std::make_shared<CPicture>(ADVOPT.resdatabarG, 0, 0);
  111. background->colorize(LOCPLINT->playerID);
  112. pos.w = background->pos.w;
  113. pos.h = background->pos.h;
  114. txtpos.resize(8);
  115. for (int i = 0; i < 8 ; i++)
  116. {
  117. txtpos[i].first = pos.x + ADVOPT.resOffsetX + ADVOPT.resDist*i;
  118. txtpos[i].second = pos.y + ADVOPT.resOffsetY;
  119. }
  120. txtpos[7].first = txtpos[6].first + ADVOPT.resDateDist;
  121. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  122. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  123. }
  124. CResDataBar::~CResDataBar() = default;
  125. void CResDataBar::draw(SDL_Surface * to)
  126. {
  127. //TODO: all this should be labels, but they require proper text update on change
  128. for (auto i=Res::WOOD; i<=Res::GOLD; vstd::advance(i, 1))
  129. {
  130. std::string text = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(i));
  131. graphics->fonts[FONT_SMALL]->renderTextLeft(to, text, Colors::WHITE, Point(txtpos[i].first,txtpos[i].second));
  132. }
  133. std::vector<std::string> temp;
  134. temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::MONTH)));
  135. temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::WEEK)));
  136. temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::DAY_OF_WEEK)));
  137. graphics->fonts[FONT_SMALL]->renderTextLeft(to, processStr(datetext,temp), Colors::WHITE, Point(txtpos[7].first,txtpos[7].second));
  138. }
  139. void CResDataBar::show(SDL_Surface * to)
  140. {
  141. }
  142. void CResDataBar::showAll(SDL_Surface * to)
  143. {
  144. CIntObject::showAll(to);
  145. draw(to);
  146. }