OptionsTab.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * OptionsTab.h, 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. #pragma once
  11. #include "../windows/CWindowObject.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. struct PlayerSettings;
  14. struct PlayerInfo;
  15. VCMI_LIB_NAMESPACE_END
  16. #include "../widgets/Scrollable.h"
  17. class CSlider;
  18. class CLabel;
  19. class CMultiLineLabel;
  20. class CFilledTexture;
  21. class CAnimImage;
  22. class CComponentBox;
  23. class CTextBox;
  24. class CButton;
  25. class FilledTexturePlayerColored;
  26. /// The options tab which is shown at the map selection phase.
  27. class OptionsTab : public CIntObject
  28. {
  29. std::shared_ptr<CPicture> background;
  30. std::shared_ptr<CLabel> labelTitle;
  31. std::shared_ptr<CMultiLineLabel> labelSubTitle;
  32. std::shared_ptr<CMultiLineLabel> labelPlayerNameAndHandicap;
  33. std::shared_ptr<CMultiLineLabel> labelStartingTown;
  34. std::shared_ptr<CMultiLineLabel> labelStartingHero;
  35. std::shared_ptr<CMultiLineLabel> labelStartingBonus;
  36. std::shared_ptr<CLabel> labelPlayerTurnDuration;
  37. std::shared_ptr<CLabel> labelTurnDurationValue;
  38. ui8 humanPlayers;
  39. public:
  40. enum SelType
  41. {
  42. TOWN,
  43. HERO,
  44. BONUS
  45. };
  46. struct CPlayerSettingsHelper
  47. {
  48. const PlayerSettings & settings;
  49. const SelType type;
  50. CPlayerSettingsHelper(const PlayerSettings & settings, SelType type)
  51. : settings(settings), type(type)
  52. {}
  53. /// visible image settings
  54. size_t getImageIndex(bool big = false);
  55. std::string getImageName(bool big = false);
  56. std::string getName(); /// name visible in options dialog
  57. std::string getTitle(); /// title in popup box
  58. std::string getSubtitle(); /// popup box subtitle
  59. std::string getDescription(); /// popup box description, not always present
  60. };
  61. class CPlayerOptionTooltipBox : public CWindowObject, public CPlayerSettingsHelper
  62. {
  63. std::shared_ptr<CFilledTexture> backgroundTexture;
  64. std::shared_ptr<CLabel> labelTitle;
  65. std::shared_ptr<CLabel> labelSubTitle;
  66. std::shared_ptr<CAnimImage> image;
  67. std::shared_ptr<CLabel> labelAssociatedCreatures;
  68. std::shared_ptr<CComponentBox> boxAssociatedCreatures;
  69. std::shared_ptr<CLabel> labelHeroSpeciality;
  70. std::shared_ptr<CAnimImage> imageSpeciality;
  71. std::shared_ptr<CLabel> labelSpecialityName;
  72. std::shared_ptr<CTextBox> textBonusDescription;
  73. void genHeader();
  74. void genTownWindow();
  75. void genHeroWindow();
  76. void genBonusWindow();
  77. public:
  78. CPlayerOptionTooltipBox(CPlayerSettingsHelper & helper);
  79. };
  80. class SelectionWindow : public CWindowObject
  81. {
  82. const int ICON_SMALL_WIDTH = 48;
  83. const int ICON_SMALL_HEIGHT = 32;
  84. const int ICON_BIG_WIDTH = 58;
  85. const int ICON_BIG_HEIGHT = 64;
  86. const int TEXT_POS_X = 29;
  87. const int TEXT_POS_Y = 56;
  88. int elementsPerLine;
  89. PlayerColor color;
  90. SelType type;
  91. std::shared_ptr<FilledTexturePlayerColored> backgroundTexture;
  92. std::vector<std::shared_ptr<CIntObject>> components;
  93. std::vector<FactionID> factions;
  94. std::vector<HeroTypeID> heroes;
  95. FactionID initialFaction;
  96. HeroTypeID initialHero;
  97. int initialBonus;
  98. FactionID selectedFaction;
  99. HeroTypeID selectedHero;
  100. int selectedBonus;
  101. std::set<FactionID> allowedFactions;
  102. std::set<HeroTypeID> allowedHeroes;
  103. std::vector<int> allowedBonus;
  104. void genContentGrid(int lines);
  105. void genContentFactions();
  106. void genContentHeroes();
  107. void genContentBonus();
  108. void drawOutlinedText(int x, int y, ColorRGBA color, std::string text);
  109. int calcLines(FactionID faction);
  110. void apply();
  111. void recreate();
  112. void setSelection();
  113. int getElement(const Point & cursorPosition);
  114. void setElement(int element, bool apply);
  115. void clickReleased(const Point & cursorPosition) override;
  116. void showPopupWindow(const Point & cursorPosition) override;
  117. public:
  118. SelectionWindow(PlayerColor _color, SelType _type);
  119. };
  120. /// Image with current town/hero/bonus
  121. struct SelectedBox : public Scrollable, public CPlayerSettingsHelper
  122. {
  123. std::shared_ptr<CAnimImage> image;
  124. std::shared_ptr<CLabel> subtitle;
  125. SelectedBox(Point position, PlayerSettings & settings, SelType type);
  126. void showPopupWindow(const Point & cursorPosition) override;
  127. void clickReleased(const Point & cursorPosition) override;
  128. void scrollBy(int distance) override;
  129. void update();
  130. };
  131. struct PlayerOptionsEntry : public CIntObject
  132. {
  133. std::unique_ptr<PlayerInfo> pi;
  134. std::unique_ptr<PlayerSettings> s;
  135. std::shared_ptr<CLabel> labelPlayerName;
  136. std::shared_ptr<CMultiLineLabel> labelWhoCanPlay;
  137. std::shared_ptr<CPicture> background;
  138. std::shared_ptr<CButton> buttonTownLeft;
  139. std::shared_ptr<CButton> buttonTownRight;
  140. std::shared_ptr<CButton> buttonHeroLeft;
  141. std::shared_ptr<CButton> buttonHeroRight;
  142. std::shared_ptr<CButton> buttonBonusLeft;
  143. std::shared_ptr<CButton> buttonBonusRight;
  144. std::shared_ptr<CButton> flag;
  145. std::shared_ptr<SelectedBox> town;
  146. std::shared_ptr<SelectedBox> hero;
  147. std::shared_ptr<SelectedBox> bonus;
  148. enum {HUMAN_OR_CPU, HUMAN, CPU} whoCanPlay;
  149. PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parentTab);
  150. void hideUnavailableButtons();
  151. private:
  152. const OptionsTab & parentTab;
  153. };
  154. std::shared_ptr<CSlider> sliderTurnDuration;
  155. std::map<PlayerColor, std::shared_ptr<PlayerOptionsEntry>> entries;
  156. OptionsTab();
  157. void recreate();
  158. void onSetPlayerClicked(const PlayerSettings & ps) const;
  159. };