CGarrisonInt.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #pragma once
  2. #include "../windows/CWindowObject.h"
  3. /*
  4. * CGarrisonInt.h, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  12. class CGarrisonInt;
  13. class CButton;
  14. class CArmedInstance;
  15. class CAnimImage;
  16. class CCreatureSet;
  17. class CGarrisonSlot;
  18. class CStackInstance;
  19. class CLabel;
  20. /// A single garrison slot which holds one creature of a specific amount
  21. class CGarrisonSlot : public CIntObject
  22. {
  23. SlotID ID; //for identification
  24. CGarrisonInt *owner;
  25. const CStackInstance *myStack; //nullptr if slot is empty
  26. const CCreature *creature;
  27. int upg; //0 - up garrison, 1 - down garrison
  28. CAnimImage * creatureImage;
  29. CAnimImage * selectionImage; // image for selection, not always visible
  30. CLabel * stackCount;
  31. void setHighlight(bool on);
  32. public:
  33. virtual void hover (bool on); //call-in
  34. const CArmedInstance * getObj() const;
  35. bool our() const;
  36. void clickRight(tribool down, bool previousState);
  37. void clickLeft(tribool down, bool previousState);
  38. void update();
  39. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, int Upg=0, const CStackInstance * Creature=nullptr);
  40. friend class CGarrisonInt;
  41. };
  42. /// Class which manages slots of upper and lower garrison, splitting of units
  43. class CGarrisonInt :public CIntObject
  44. {
  45. CGarrisonSlot *highlighted; //chosen slot. Should be changed only via selectSlot
  46. bool inSplittingMode;
  47. public:
  48. void selectSlot(CGarrisonSlot * slot); //null = deselect
  49. const CGarrisonSlot * getSelection();
  50. void setSplittingMode(bool on);
  51. bool getSplittingMode();
  52. int interx; //space between slots
  53. Point garOffset; //offset between garrisons (not used if only one hero)
  54. std::vector<CButton *> splitButtons; //may be empty if no buttons
  55. SlotID p2; //TODO: comment me
  56. int shiftPos;//1st slot of the second row, set shiftPoint for effect
  57. bool pb,
  58. smallIcons, //true - 32x32 imgs, false - 58x64
  59. removableUnits,//player can remove units from up
  60. twoRows,//slots will be placed in 2 rows
  61. owned[2];//player owns up or down army [0] upper, [1] lower
  62. // const CCreatureSet *set1; //top set of creatures
  63. // const CCreatureSet *set2; //bottom set of creatures
  64. std::vector<CGarrisonSlot*> slotsUp, slotsDown; //slots of upper and lower garrison
  65. const CArmedInstance *armedObjs[2]; //[0] is upper, [1] is down
  66. //const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
  67. void setArmy(const CArmedInstance *army, bool bottomGarrison);
  68. void addSplitBtn(CButton * button);
  69. void createSet(std::vector<CGarrisonSlot*> &ret, const CCreatureSet * set, int posX, int distance, int posY, int Upg );
  70. void createSlots();
  71. void recreateSlots();
  72. void splitClick(); //handles click on split button
  73. void splitStacks(int amountLeft, int amountRight); //TODO: comment me
  74. //x, y - position;
  75. //inx - distance between slots;
  76. //pomsur, SurOffset - UNUSED
  77. //s1, s2 - top and bottom armies;
  78. //removableUnits - you can take units from top;
  79. //smallImgs - units images size 64x58 or 32x32;
  80. //twoRows - display slots in 2 row (1st row = 4 slots, 2nd = 3 slots)
  81. CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *pomsur, const Point &SurOffset, const CArmedInstance *s1, const CArmedInstance *s2=nullptr, bool _removableUnits = true, bool smallImgs = false, bool _twoRows=false); //c-tor
  82. };
  83. class CGarrisonHolder
  84. {
  85. public:
  86. CGarrisonHolder();
  87. virtual void updateGarrisons()=0;
  88. };
  89. class CWindowWithGarrison : public virtual CGarrisonHolder
  90. {
  91. public:
  92. CGarrisonInt *garr;
  93. virtual void updateGarrisons();
  94. };
  95. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  96. class CGarrisonWindow : public CWindowObject, public CWindowWithGarrison
  97. {
  98. public:
  99. CButton * quit;
  100. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  101. };