CResDataBar.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. addUsedEvents(RCLICK);
  42. }
  43. CResDataBar::CResDataBar()
  44. {
  45. pos.x += ADVOPT.resdatabarX;
  46. pos.y += ADVOPT.resdatabarY;
  47. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  48. background = std::make_shared<CPicture>(ADVOPT.resdatabarG, 0, 0);
  49. background->colorize(LOCPLINT->playerID);
  50. pos.w = background->pos.w;
  51. pos.h = background->pos.h;
  52. txtpos.resize(8);
  53. for (int i = 0; i < 8 ; i++)
  54. {
  55. txtpos[i].first = pos.x + ADVOPT.resOffsetX + ADVOPT.resDist*i;
  56. txtpos[i].second = pos.y + ADVOPT.resOffsetY;
  57. }
  58. txtpos[7].first = txtpos[6].first + ADVOPT.resDateDist;
  59. }
  60. CResDataBar::~CResDataBar() = default;
  61. std::string CResDataBar::buildDateString()
  62. {
  63. std::string pattern = "%s: %d, %s: %d, %s: %d";
  64. auto formatted = boost::format(pattern)
  65. % CGI->generaltexth->allTexts[62] % LOCPLINT->cb->getDate(Date::MONTH)
  66. % CGI->generaltexth->allTexts[63] % LOCPLINT->cb->getDate(Date::WEEK)
  67. % CGI->generaltexth->allTexts[64] % LOCPLINT->cb->getDate(Date::DAY_OF_WEEK);
  68. return boost::str(formatted);
  69. }
  70. void CResDataBar::draw(SDL_Surface * to)
  71. {
  72. //TODO: all this should be labels, but they require proper text update on change
  73. for (auto i=Res::WOOD; i<=Res::GOLD; vstd::advance(i, 1))
  74. {
  75. std::string text = boost::lexical_cast<std::string>(LOCPLINT->cb->getResourceAmount(i));
  76. graphics->fonts[FONT_SMALL]->renderTextLeft(to, text, Colors::WHITE, Point(txtpos[i].first,txtpos[i].second));
  77. }
  78. graphics->fonts[FONT_SMALL]->renderTextLeft(to, buildDateString(), Colors::WHITE, Point(txtpos[7].first,txtpos[7].second));
  79. }
  80. void CResDataBar::show(SDL_Surface * to)
  81. {
  82. }
  83. void CResDataBar::showAll(SDL_Surface * to)
  84. {
  85. CIntObject::showAll(to);
  86. draw(to);
  87. }