CResDataBar.cpp 3.1 KB

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