OptionsTab.h 5.4 KB

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