OptionsTab.h 6.2 KB

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