CMainMenu.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * CMainMenu.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. #include "../../lib/json/JsonNode.h"
  13. #include "../../lib/LoadProgress.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class CampaignState;
  16. VCMI_LIB_NAMESPACE_END
  17. class CTextInput;
  18. class CGStatusBar;
  19. class CTextBox;
  20. class CTabbedInt;
  21. class CAnimImage;
  22. class CButton;
  23. class CFilledTexture;
  24. class CLabel;
  25. class VideoWidget;
  26. // TODO: Find new location for these enums
  27. enum class ESelectionScreen : ui8 {
  28. unknown = 0, newGame, loadGame, saveGame, scenarioInfo, campaignList
  29. };
  30. enum class ELoadMode : ui8
  31. {
  32. NONE = 0, SINGLE, MULTI, CAMPAIGN, TUTORIAL
  33. };
  34. /// The main menu screens listed in the EState enum
  35. class CMenuScreen : public CWindowObject
  36. {
  37. const JsonNode & config;
  38. std::shared_ptr<CTabbedInt> tabs;
  39. std::shared_ptr<CPicture> background;
  40. std::shared_ptr<VideoWidget> videoPlayer;
  41. std::vector<std::shared_ptr<CPicture>> images;
  42. std::shared_ptr<CIntObject> createTab(size_t index);
  43. public:
  44. std::vector<std::string> menuNameToEntry;
  45. CMenuScreen(const JsonNode & configNode);
  46. void activate() override;
  47. void show(Canvas & to) override;
  48. void switchToTab(size_t index);
  49. void switchToTab(std::string name);
  50. size_t getActiveTab() const;
  51. };
  52. class CMenuEntry : public CIntObject
  53. {
  54. std::vector<std::shared_ptr<CPicture>> images;
  55. std::vector<std::shared_ptr<CButton>> buttons;
  56. std::shared_ptr<CButton> createButton(CMenuScreen * parent, const JsonNode & button);
  57. public:
  58. CMenuEntry(CMenuScreen * parent, const JsonNode & config);
  59. };
  60. /// Multiplayer mode
  61. class CMultiMode : public WindowBase
  62. {
  63. public:
  64. ESelectionScreen screenType;
  65. std::shared_ptr<CPicture> background;
  66. std::shared_ptr<CPicture> picture;
  67. std::shared_ptr<CTextInput> playerName;
  68. std::shared_ptr<CButton> buttonHotseat;
  69. std::shared_ptr<CButton> buttonLobby;
  70. std::shared_ptr<CButton> buttonHost;
  71. std::shared_ptr<CButton> buttonJoin;
  72. std::shared_ptr<CButton> buttonCancel;
  73. std::shared_ptr<CGStatusBar> statusBar;
  74. CMultiMode(ESelectionScreen ScreenType);
  75. void openLobby();
  76. void hostTCP();
  77. void joinTCP();
  78. /// Get all configured player names. The first name would always be present and initialized to its default value.
  79. std::vector<std::string> getPlayersNames();
  80. void onNameChange(std::string newText);
  81. };
  82. /// Hot seat player window
  83. class CMultiPlayers : public WindowBase
  84. {
  85. bool host;
  86. ELoadMode loadMode;
  87. ESelectionScreen screenType;
  88. std::shared_ptr<CPicture> background;
  89. std::shared_ptr<CTextBox> textTitle;
  90. std::array<std::shared_ptr<CTextInput>, 8> inputNames;
  91. std::shared_ptr<CButton> buttonOk;
  92. std::shared_ptr<CButton> buttonCancel;
  93. std::shared_ptr<CGStatusBar> statusBar;
  94. void onChange(std::string newText);
  95. void enterSelectionScreen();
  96. public:
  97. CMultiPlayers(const std::vector<std::string> & playerNames, ESelectionScreen ScreenType, bool Host, ELoadMode LoadMode);
  98. };
  99. /// Manages the configuration of pregame GUI elements like campaign screen, main menu, loading screen,...
  100. class CMainMenuConfig
  101. {
  102. public:
  103. static const CMainMenuConfig & get();
  104. const JsonNode & getConfig() const;
  105. const JsonNode & getCampaigns() const;
  106. private:
  107. CMainMenuConfig();
  108. const JsonNode campaignSets;
  109. const JsonNode config;
  110. };
  111. /// Handles background screen, loads graphics for victory/loss condition and random town or hero selection
  112. class CMainMenu : public CIntObject, public IUpdateable, public std::enable_shared_from_this<CMainMenu>
  113. {
  114. std::shared_ptr<CFilledTexture> backgroundAroundMenu;
  115. CMainMenu(); //Use CMainMenu::create
  116. public:
  117. std::shared_ptr<CMenuScreen> menu;
  118. ~CMainMenu();
  119. void activate() override;
  120. void onScreenResize() override;
  121. void update() override;
  122. static void openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> & names, ELoadMode loadMode);
  123. static void openCampaignLobby(const std::string & campaignFileName, std::string campaignSet = "");
  124. static void openCampaignLobby(std::shared_ptr<CampaignState> campaign);
  125. static void startTutorial();
  126. static void openHighScoreScreen();
  127. void openCampaignScreen(std::string name);
  128. static std::shared_ptr<CMainMenu> create();
  129. static std::shared_ptr<CPicture> createPicture(const JsonNode & config);
  130. };
  131. /// Simple window to enter the server's address.
  132. class CSimpleJoinScreen : public WindowBase
  133. {
  134. std::shared_ptr<CPicture> background;
  135. std::shared_ptr<CTextBox> textTitle;
  136. std::shared_ptr<CButton> buttonOk;
  137. std::shared_ptr<CButton> buttonCancel;
  138. std::shared_ptr<CGStatusBar> statusBar;
  139. std::shared_ptr<CTextInput> inputAddress;
  140. std::shared_ptr<CTextInput> inputPort;
  141. void connectToServer();
  142. void leaveScreen();
  143. void onChange(const std::string & newText);
  144. void startConnection(const std::string & addr = {}, ui16 port = 0);
  145. public:
  146. CSimpleJoinScreen(bool host = true);
  147. };
  148. class CLoadingScreen : virtual public CWindowObject, virtual public Load::Progress
  149. {
  150. std::vector<std::shared_ptr<CAnimImage>> progressBlocks;
  151. ImagePath getBackground();
  152. public:
  153. CLoadingScreen();
  154. ~CLoadingScreen();
  155. void tick(uint32_t msPassed) override;
  156. };
  157. extern std::shared_ptr<CMainMenu> CMM;