OptionsTab.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. FactionID initialFaction;
  93. HeroTypeID initialHero;
  94. int initialBonus;
  95. FactionID selectedFaction;
  96. HeroTypeID selectedHero;
  97. int selectedBonus;
  98. std::set<FactionID> allowedFactions;
  99. std::set<HeroTypeID> allowedHeroes;
  100. std::vector<int> allowedBonus;
  101. void genContentGrid(int lines);
  102. void genContentFactions();
  103. void genContentHeroes();
  104. void genContentBonus();
  105. void drawOutlinedText(int x, int y, ColorRGBA color, std::string text);
  106. int calcLines(FactionID faction);
  107. void apply();
  108. void recreate();
  109. void setSelection();
  110. int getElement(const Point & cursorPosition);
  111. void setElement(int element, bool doApply);
  112. bool receiveEvent(const Point & position, int eventType) const override;
  113. void clickReleased(const Point & cursorPosition) override;
  114. void showPopupWindow(const Point & cursorPosition) override;
  115. public:
  116. SelectionWindow(PlayerColor _color, SelType _type);
  117. };
  118. /// Image with current town/hero/bonus
  119. struct SelectedBox : public Scrollable, public CPlayerSettingsHelper
  120. {
  121. std::shared_ptr<CAnimImage> image;
  122. std::shared_ptr<CLabel> subtitle;
  123. SelectedBox(Point position, PlayerSettings & settings, SelType type);
  124. void showPopupWindow(const Point & cursorPosition) override;
  125. void clickReleased(const Point & cursorPosition) override;
  126. void scrollBy(int distance) override;
  127. void update();
  128. };
  129. struct PlayerOptionsEntry : public CIntObject
  130. {
  131. std::unique_ptr<PlayerInfo> pi;
  132. std::unique_ptr<PlayerSettings> s;
  133. std::shared_ptr<CLabel> labelPlayerName;
  134. std::shared_ptr<CMultiLineLabel> labelWhoCanPlay;
  135. std::shared_ptr<CPicture> background;
  136. std::shared_ptr<CButton> buttonTownLeft;
  137. std::shared_ptr<CButton> buttonTownRight;
  138. std::shared_ptr<CButton> buttonHeroLeft;
  139. std::shared_ptr<CButton> buttonHeroRight;
  140. std::shared_ptr<CButton> buttonBonusLeft;
  141. std::shared_ptr<CButton> buttonBonusRight;
  142. std::shared_ptr<CButton> flag;
  143. std::shared_ptr<SelectedBox> town;
  144. std::shared_ptr<SelectedBox> hero;
  145. std::shared_ptr<SelectedBox> bonus;
  146. enum {HUMAN_OR_CPU, HUMAN, CPU} whoCanPlay;
  147. PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parentTab);
  148. void hideUnavailableButtons();
  149. private:
  150. const OptionsTab & parentTab;
  151. };
  152. };