OptionsTab.h 3.8 KB

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