CreaturePurhaseCard.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * CreaturePurhaseCard.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 "CreaturePurhaseCard.h"
  12. #include "CAdvmapInterface.h"
  13. #include "CHeroWindow.h"
  14. #include "../widgets/Buttons.h"
  15. #include "../../CCallback.h"
  16. #include "../CreatureCostBox.h"
  17. #include "QuickRecruitmentWindow.h"
  18. void CreaturePurhaseCard::initButtons()
  19. {
  20. initMaxButton();
  21. initMinButton();
  22. }
  23. void CreaturePurhaseCard::initMaxButton()
  24. {
  25. maxButton = std::make_shared<CButton>(Point(pos.x + 52, pos.y + 178), "iam014.def", CButton::tooltip(), std::bind(&CSlider::moveToMax,slider), SDLK_m);
  26. }
  27. void CreaturePurhaseCard::initMinButton()
  28. {
  29. minButton = std::make_shared<CButton>(Point(pos.x, pos.y + 178), "iam015.def", CButton::tooltip(), std::bind(&CSlider::moveToMin,slider), SDLK_m);
  30. }
  31. void CreaturePurhaseCard::initAmountInfo()
  32. {
  33. availableAmount = std::make_shared<CLabel>(pos.x + 27, pos.y + 146, FONT_SMALL, CENTER, Colors::YELLOW);
  34. purhaseAmount = std::make_shared<CLabel>(pos.x + 77, pos.y + 146, FONT_SMALL, CENTER, Colors::WHITE);
  35. updateAmountInfo(0);
  36. }
  37. void CreaturePurhaseCard::updateAmountInfo(int value)
  38. {
  39. availableAmount->setText(boost::lexical_cast<std::string>(maxAmount-value));
  40. purhaseAmount->setText(boost::lexical_cast<std::string>(value));
  41. }
  42. void CreaturePurhaseCard::initSlider()
  43. {
  44. slider = std::make_shared<CSlider>(Point(pos.x, pos.y + 158), 102, std::bind(&CreaturePurhaseCard::sliderMoved, this , _1), 0, maxAmount, 0);
  45. }
  46. void CreaturePurhaseCard::initCostBox()
  47. {
  48. cost = std::make_shared<CreatureCostBox>(Rect(pos.x, pos.y + 194, 97, 74), "");
  49. cost->createItems(creatureOnTheCard->cost);
  50. }
  51. void CreaturePurhaseCard::sliderMoved(int to)
  52. {
  53. updateAmountInfo(to);
  54. cost->set(creatureOnTheCard->cost * to);
  55. parent->updateAllSliders();
  56. }
  57. CreaturePurhaseCard::CreaturePurhaseCard(const CCreature * creature, Point position, int creaturesMaxAmount, QuickRecruitmentWindow * parents) : creatureOnTheCard(creature), parent(parents), maxAmount(creaturesMaxAmount)
  58. {
  59. moveTo(Point(position.x, position.y));
  60. initView();
  61. }
  62. void CreaturePurhaseCard::initView()
  63. {
  64. picture = std::make_shared<CCreaturePic>(pos.x, pos.y, creatureOnTheCard);
  65. initAmountInfo();
  66. initSlider();
  67. initButtons();
  68. initCostBox();
  69. }