OptionsTab.h 6.0 KB

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