CResDataBar.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 "../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. CResDataBar::CResDataBar(const std::string & defname, int x, int y, int offx, int offy, int resdist, int datedist)
  22. {
  23. pos.x += x;
  24. pos.y += y;
  25. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  26. background = std::make_shared<CPicture>(defname, 0, 0);
  27. background->colorize(LOCPLINT->playerID);
  28. pos.w = background->pos.w;
  29. pos.h = background->pos.h;
  30. txtpos.resize(8);
  31. for (int i = 0; i < 8 ; i++)
  32. {
  33. txtpos[i].first = pos.x + offx + resdist*i;
  34. txtpos[i].second = pos.y + offy;
  35. }
  36. txtpos[7].first = txtpos[6].first + datedist;
  37. addUsedEvents(RCLICK);
  38. }
  39. CResDataBar::CResDataBar()
  40. {
  41. pos.x += ADVOPT.resdatabarX;
  42. pos.y += ADVOPT.resdatabarY;
  43. OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
  44. background = std::make_shared<CPicture>(ADVOPT.resdatabarG, 0, 0);
  45. background->colorize(LOCPLINT->playerID);
  46. pos.w = background->pos.w;
  47. pos.h = background->pos.h;
  48. txtpos.resize(8);
  49. for (int i = 0; i < 8 ; i++)
  50. {
  51. txtpos[i].first = pos.x + ADVOPT.resOffsetX + ADVOPT.resDist*i;
  52. txtpos[i].second = pos.y + ADVOPT.resOffsetY;
  53. }
  54. txtpos[7].first = txtpos[6].first + ADVOPT.resDateDist;
  55. }
  56. std::string CResDataBar::buildDateString()
  57. {
  58. std::string pattern = "%s: %d, %s: %d, %s: %d";
  59. auto formatted = boost::format(pattern)
  60. % CGI->generaltexth->translate("core.genrltxt.62") % LOCPLINT->cb->getDate(Date::MONTH)
  61. % CGI->generaltexth->translate("core.genrltxt.63") % LOCPLINT->cb->getDate(Date::WEEK)
  62. % CGI->generaltexth->translate("core.genrltxt.64") % LOCPLINT->cb->getDate(Date::DAY_OF_WEEK);
  63. return boost::str(formatted);
  64. }
  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=GameResID(EGameResID::WOOD); i <= GameResID(EGameResID::GOLD); vstd::advance(i, 1))
  69. {
  70. std::string text = std::to_string(LOCPLINT->cb->getResourceAmount(i));
  71. graphics->fonts[FONT_SMALL]->renderTextLeft(to, text, Colors::WHITE, Point(txtpos[i].first, txtpos[i].second));
  72. }
  73. graphics->fonts[FONT_SMALL]->renderTextLeft(to, buildDateString(), Colors::WHITE, Point(txtpos[7].first, txtpos[7].second));
  74. }
  75. void CResDataBar::showAll(SDL_Surface * to)
  76. {
  77. CIntObject::showAll(to);
  78. draw(to);
  79. }
  80. void CResDataBar::colorize(PlayerColor player)
  81. {
  82. background->colorize(player);
  83. }