OptionsTab.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. class CSlider;
  18. class CLabel;
  19. class CMultiLineLabel;
  20. class CFilledTexture;
  21. class CAnimImage;
  22. class CComponentBox;
  23. class CTextBox;
  24. class CButton;
  25. /// The options tab which is shown at the map selection phase.
  26. class OptionsTab : public CIntObject
  27. {
  28. std::shared_ptr<CPicture> background;
  29. std::shared_ptr<CLabel> labelTitle;
  30. std::shared_ptr<CMultiLineLabel> labelSubTitle;
  31. std::shared_ptr<CMultiLineLabel> labelPlayerNameAndHandicap;
  32. std::shared_ptr<CMultiLineLabel> labelStartingTown;
  33. std::shared_ptr<CMultiLineLabel> labelStartingHero;
  34. std::shared_ptr<CMultiLineLabel> labelStartingBonus;
  35. std::shared_ptr<CLabel> labelPlayerTurnDuration;
  36. std::shared_ptr<CLabel> labelTurnDurationValue;
  37. ui8 humanPlayers;
  38. public:
  39. enum SelType
  40. {
  41. TOWN,
  42. HERO,
  43. BONUS
  44. };
  45. struct CPlayerSettingsHelper
  46. {
  47. const PlayerSettings & settings;
  48. const SelType type;
  49. CPlayerSettingsHelper(const PlayerSettings & settings, SelType type)
  50. : settings(settings), type(type)
  51. {}
  52. /// visible image settings
  53. size_t getImageIndex();
  54. std::string getImageName();
  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. /// Image with current town/hero/bonus
  80. struct SelectedBox : public Scrollable, public CPlayerSettingsHelper
  81. {
  82. std::shared_ptr<CAnimImage> image;
  83. std::shared_ptr<CLabel> subtitle;
  84. SelectedBox(Point position, PlayerSettings & settings, SelType type);
  85. void showPopupWindow(const Point & cursorPosition) override;
  86. void scrollBy(int distance) override;
  87. void update();
  88. };
  89. struct PlayerOptionsEntry : public CIntObject
  90. {
  91. std::unique_ptr<PlayerInfo> pi;
  92. std::unique_ptr<PlayerSettings> s;
  93. std::shared_ptr<CLabel> labelPlayerName;
  94. std::shared_ptr<CMultiLineLabel> labelWhoCanPlay;
  95. std::shared_ptr<CPicture> background;
  96. std::shared_ptr<CButton> buttonTownLeft;
  97. std::shared_ptr<CButton> buttonTownRight;
  98. std::shared_ptr<CButton> buttonHeroLeft;
  99. std::shared_ptr<CButton> buttonHeroRight;
  100. std::shared_ptr<CButton> buttonBonusLeft;
  101. std::shared_ptr<CButton> buttonBonusRight;
  102. std::shared_ptr<CButton> flag;
  103. std::shared_ptr<SelectedBox> town;
  104. std::shared_ptr<SelectedBox> hero;
  105. std::shared_ptr<SelectedBox> bonus;
  106. enum {HUMAN_OR_CPU, HUMAN, CPU} whoCanPlay;
  107. PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parentTab);
  108. void hideUnavailableButtons();
  109. private:
  110. const OptionsTab & parentTab;
  111. };
  112. std::shared_ptr<CSlider> sliderTurnDuration;
  113. std::map<PlayerColor, std::shared_ptr<PlayerOptionsEntry>> entries;
  114. OptionsTab();
  115. void recreate();
  116. void onSetPlayerClicked(const PlayerSettings & ps) const;
  117. };