OptionsTab.h 5.6 KB

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