CResDataBar.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * CResDataBar.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 "CResDataBar.h"
  12. #include "../CGameInfo.h"
  13. #include "../CPlayerInterface.h"
  14. #include "../render/Colors.h"
  15. #include "../renderSDL/SDL_Extensions.h"
  16. #include "../gui/CGuiHandler.h"
  17. #include "../widgets/Images.h"
  18. #include "../../CCallback.h"
  19. #include "../../lib/CConfigHandler.h"
  20. #include "../../lib/CGeneralTextHandler.h"
  21. #define ADVOPT (conf.go()->ac)
  22. void CResDataBar::clickRight(tribool down, bool previousState)
  23. {
  24. }
  25. CResDataBar::CResDataBar(const std::string & defname, int x, int y, int offx, int offy, int resdist, int datedist)
  26. {
  27. pos.x += x;
  28. pos.y += y;
  29. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  30. background = std::make_shared<CPicture>(defname, 0, 0);
  31. background->colorize(LOCPLINT->playerID);
  32. pos.w = background->pos.w;
  33. pos.h = background->pos.h;
  34. txtpos.resize(8);
  35. for (int i = 0; i < 8 ; i++)
  36. {
  37. txtpos[i].first = pos.x + offx + resdist*i;
  38. txtpos[i].second = pos.y + offy;
  39. }
  40. txtpos[7].first = txtpos[6].first + datedist;
  41. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  42. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  43. addUsedEvents(RCLICK);
  44. }
  45. CResDataBar::CResDataBar()
  46. {
  47. pos.x += ADVOPT.resdatabarX;
  48. pos.y += ADVOPT.resdatabarY;
  49. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  50. background = std::make_shared<CPicture>(ADVOPT.resdatabarG, 0, 0);
  51. background->colorize(LOCPLINT->playerID);
  52. pos.w = background->pos.w;
  53. pos.h = background->pos.h;
  54. txtpos.resize(8);
  55. for (int i = 0; i < 8 ; i++)
  56. {
  57. txtpos[i].first = pos.x + ADVOPT.resOffsetX + ADVOPT.resDist*i;
  58. txtpos[i].second = pos.y + ADVOPT.resOffsetY;
  59. }
  60. txtpos[7].first = txtpos[6].first + ADVOPT.resDateDist;
  61. datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63]
  62. + ": %s, " + CGI->generaltexth->allTexts[64] + ": %s";
  63. }
  64. CResDataBar::~CResDataBar() = default;
  65. void CResDataBar::draw(SDL_Surface * to)
  66. {
  67. //TODO: all this should be labels, but they require proper text update on change
  68. for (auto i=Res::WOOD; i<=Res::GOLD; vstd::advance(i, 1))
  69. {
  70. std::string text = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(i));
  71. graphics->fonts[FONT_SMALL]->renderTextLeft(to, text, Colors::WHITE, Point(txtpos[i].first,txtpos[i].second));
  72. }
  73. std::vector<std::string> temp;
  74. temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::MONTH)));
  75. temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::WEEK)));
  76. temp.push_back(boost::lexical_cast<std::string>(LOCPLINT->cb->getDate(Date::DAY_OF_WEEK)));
  77. graphics->fonts[FONT_SMALL]->renderTextLeft(to, CSDL_Ext::processStr(datetext,temp), Colors::WHITE, Point(txtpos[7].first,txtpos[7].second));
  78. }
  79. void CResDataBar::show(SDL_Surface * to)
  80. {
  81. }
  82. void CResDataBar::showAll(SDL_Surface * to)
  83. {
  84. CIntObject::showAll(to);
  85. draw(to);
  86. }