OptionsTab.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #include "../widgets/Scrollable.h"
  13. #include "../gui/InterfaceObjectConfigurable.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. struct PlayerSettings;
  16. struct PlayerInfo;
  17. VCMI_LIB_NAMESPACE_END
  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 InterfaceObjectConfigurable
  28. {
  29. struct PlayerOptionsEntry;
  30. ui8 humanPlayers;
  31. std::map<PlayerColor, std::shared_ptr<PlayerOptionsEntry>> entries;
  32. public:
  33. OptionsTab();
  34. void recreate();
  35. void onSetPlayerClicked(const PlayerSettings & ps) const;
  36. enum SelType
  37. {
  38. TOWN,
  39. HERO,
  40. BONUS
  41. };
  42. private:
  43. struct CPlayerSettingsHelper
  44. {
  45. const PlayerSettings & settings;
  46. const SelType type;
  47. CPlayerSettingsHelper(const PlayerSettings & settings, SelType type)
  48. : settings(settings), type(type)
  49. {}
  50. /// visible image settings
  51. size_t getImageIndex(bool big = false);
  52. std::string getImageName(bool big = false);
  53. std::string getName(); /// name visible in options dialog
  54. std::string getTitle(); /// title in popup box
  55. std::string getSubtitle(); /// popup box subtitle
  56. std::string getDescription(); /// popup box description, not always present
  57. };
  58. class CPlayerOptionTooltipBox : public CWindowObject, public CPlayerSettingsHelper
  59. {
  60. std::shared_ptr<CFilledTexture> backgroundTexture;
  61. std::shared_ptr<CLabel> labelTitle;
  62. std::shared_ptr<CLabel> labelSubTitle;
  63. std::shared_ptr<CAnimImage> image;
  64. std::shared_ptr<CLabel> labelAssociatedCreatures;
  65. std::shared_ptr<CComponentBox> boxAssociatedCreatures;
  66. std::shared_ptr<CLabel> labelHeroSpeciality;
  67. std::shared_ptr<CAnimImage> imageSpeciality;
  68. std::shared_ptr<CLabel> labelSpecialityName;
  69. std::shared_ptr<CTextBox> textBonusDescription;
  70. void genHeader();
  71. void genTownWindow();
  72. void genHeroWindow();
  73. void genBonusWindow();
  74. public:
  75. CPlayerOptionTooltipBox(CPlayerSettingsHelper & helper);
  76. };
  77. class SelectionWindow : public CWindowObject
  78. {
  79. //const int ICON_SMALL_WIDTH = 48;
  80. const int ICON_SMALL_HEIGHT = 32;
  81. const int ICON_BIG_WIDTH = 58;
  82. const int ICON_BIG_HEIGHT = 64;
  83. const int TEXT_POS_X = 29;
  84. const int TEXT_POS_Y = 56;
  85. int elementsPerLine;
  86. PlayerColor color;
  87. SelType type;
  88. std::shared_ptr<FilledTexturePlayerColored> backgroundTexture;
  89. std::vector<std::shared_ptr<CIntObject>> components;
  90. std::vector<FactionID> factions;
  91. std::vector<HeroTypeID> heroes;
  92. std::set<HeroTypeID> unusableHeroes;
  93. FactionID initialFaction;
  94. HeroTypeID initialHero;
  95. int initialBonus;
  96. FactionID selectedFaction;
  97. HeroTypeID selectedHero;
  98. int selectedBonus;
  99. std::set<FactionID> allowedFactions;
  100. std::set<HeroTypeID> allowedHeroes;
  101. std::vector<int> allowedBonus;
  102. void genContentGrid(int lines);
  103. void genContentFactions();
  104. void genContentHeroes();
  105. void genContentBonus();
  106. void drawOutlinedText(int x, int y, ColorRGBA color, std::string text);
  107. int calcLines(FactionID faction);
  108. void apply();
  109. void recreate();
  110. void setSelection();
  111. int getElement(const Point & cursorPosition);
  112. void setElement(int element, bool doApply);
  113. bool receiveEvent(const Point & position, int eventType) const override;
  114. void clickReleased(const Point & cursorPosition) override;
  115. void showPopupWindow(const Point & cursorPosition) override;
  116. public:
  117. void reopen();
  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. };