CGarrisonInt.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. bool ally() const;
  37. void clickRight(tribool down, bool previousState);
  38. void clickLeft(tribool down, bool previousState);
  39. void update();
  40. CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, int Upg=0, const CStackInstance * Creature=nullptr);
  41. friend class CGarrisonInt;
  42. };
  43. /// Class which manages slots of upper and lower garrison, splitting of units
  44. class CGarrisonInt :public CIntObject
  45. {
  46. CGarrisonSlot *highlighted; //chosen slot. Should be changed only via selectSlot
  47. bool inSplittingMode;
  48. public:
  49. void selectSlot(CGarrisonSlot * slot); //null = deselect
  50. const CGarrisonSlot * getSelection();
  51. void setSplittingMode(bool on);
  52. bool getSplittingMode();
  53. int interx; //space between slots
  54. Point garOffset; //offset between garrisons (not used if only one hero)
  55. std::vector<CButton *> splitButtons; //may be empty if no buttons
  56. SlotID p2; //TODO: comment me
  57. int shiftPos;//1st slot of the second row, set shiftPoint for effect
  58. bool pb,
  59. smallIcons, //true - 32x32 imgs, false - 58x64
  60. removableUnits,//player can remove units from up
  61. twoRows,//slots will be placed in 2 rows
  62. owned[2];//player owns up or down army [0] upper, [1] lower
  63. // const CCreatureSet *set1; //top set of creatures
  64. // const CCreatureSet *set2; //bottom set of creatures
  65. std::vector<CGarrisonSlot*> slotsUp, slotsDown; //slots of upper and lower garrison
  66. const CArmedInstance *armedObjs[2]; //[0] is upper, [1] is down
  67. //const CArmedInstance *oup, *odown; //upper and lower garrisons (heroes or towns)
  68. void setArmy(const CArmedInstance *army, bool bottomGarrison);
  69. void addSplitBtn(CButton * button);
  70. void createSet(std::vector<CGarrisonSlot*> &ret, const CCreatureSet * set, int posX, int distance, int posY, int Upg );
  71. void createSlots();
  72. void recreateSlots();
  73. void splitClick(); //handles click on split button
  74. void splitStacks(int amountLeft, int amountRight); //TODO: comment me
  75. //x, y - position;
  76. //inx - distance between slots;
  77. //pomsur, SurOffset - UNUSED
  78. //s1, s2 - top and bottom armies;
  79. //removableUnits - you can take units from top;
  80. //smallImgs - units images size 64x58 or 32x32;
  81. //twoRows - display slots in 2 row (1st row = 4 slots, 2nd = 3 slots)
  82. 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
  83. };
  84. class CGarrisonHolder
  85. {
  86. public:
  87. CGarrisonHolder();
  88. virtual void updateGarrisons()=0;
  89. };
  90. class CWindowWithGarrison : public virtual CGarrisonHolder
  91. {
  92. public:
  93. CGarrisonInt *garr;
  94. virtual void updateGarrisons();
  95. };
  96. /// Garrison window where you can take creatures out of the hero to place it on the garrison
  97. class CGarrisonWindow : public CWindowObject, public CWindowWithGarrison
  98. {
  99. public:
  100. CButton * quit;
  101. CGarrisonWindow(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits); //c-tor
  102. };