OptionsTab.h 5.0 KB

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