CMainMenu.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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<CTextBox> textTitle;
  68. std::shared_ptr<CTextInput> playerName;
  69. std::shared_ptr<CButton> buttonHotseat;
  70. std::shared_ptr<CButton> buttonLobby;
  71. std::shared_ptr<CButton> buttonHost;
  72. std::shared_ptr<CButton> buttonJoin;
  73. std::shared_ptr<CButton> buttonCancel;
  74. std::shared_ptr<CGStatusBar> statusBar;
  75. CMultiMode(ESelectionScreen ScreenType);
  76. void openLobby();
  77. void hostTCP(EShortcut shortcut);
  78. void joinTCP(EShortcut shortcut);
  79. /// Get all configured player names. The first name would always be present and initialized to its default value.
  80. std::vector<std::string> getPlayersNames();
  81. void onNameChange(std::string newText);
  82. };
  83. /// Hot seat player window
  84. class CMultiPlayers : public WindowBase
  85. {
  86. bool host;
  87. ELoadMode loadMode;
  88. ESelectionScreen screenType;
  89. std::shared_ptr<CPicture> background;
  90. std::shared_ptr<CTextBox> textTitle;
  91. std::array<std::shared_ptr<CTextInput>, 8> inputNames;
  92. std::shared_ptr<CButton> buttonOk;
  93. std::shared_ptr<CButton> buttonCancel;
  94. std::shared_ptr<CGStatusBar> statusBar;
  95. void onChange(std::string newText);
  96. void enterSelectionScreen();
  97. public:
  98. CMultiPlayers(const std::vector<std::string> & playerNames, ESelectionScreen ScreenType, bool Host, ELoadMode LoadMode, EShortcut shortcut);
  99. };
  100. /// Manages the configuration of pregame GUI elements like campaign screen, main menu, loading screen,...
  101. class CMainMenuConfig
  102. {
  103. public:
  104. static const CMainMenuConfig & get();
  105. const JsonNode & getConfig() const;
  106. const JsonNode & getCampaigns() const;
  107. private:
  108. CMainMenuConfig();
  109. const JsonNode campaignSets;
  110. const JsonNode config;
  111. };
  112. /// Handles background screen, loads graphics for victory/loss condition and random town or hero selection
  113. class CMainMenu final : public CIntObject, public std::enable_shared_from_this<CMainMenu>
  114. {
  115. std::shared_ptr<CFilledTexture> backgroundAroundMenu;
  116. std::vector<VideoPath> videoPlayList;
  117. public:
  118. CMainMenu();
  119. std::shared_ptr<CMenuScreen> menu;
  120. ~CMainMenu();
  121. void activate() override;
  122. void onScreenResize() override;
  123. void makeActiveInterface();
  124. static void openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> & names, ELoadMode loadMode);
  125. static void openCampaignLobby(const std::string & campaignFileName, std::string campaignSet = "");
  126. static void openCampaignLobby(std::shared_ptr<CampaignState> campaign);
  127. static void startTutorial();
  128. static void openHighScoreScreen();
  129. void openCampaignScreen(std::string name);
  130. static std::shared_ptr<CPicture> createPicture(const JsonNode & config);
  131. void playIntroVideos();
  132. void playMusic();
  133. };
  134. /// Simple window to enter the server's address.
  135. class CSimpleJoinScreen : public WindowBase
  136. {
  137. std::shared_ptr<CPicture> background;
  138. std::shared_ptr<CTextBox> textTitle;
  139. std::shared_ptr<CButton> buttonOk;
  140. std::shared_ptr<CButton> buttonCancel;
  141. std::shared_ptr<CGStatusBar> statusBar;
  142. std::shared_ptr<CTextInput> inputAddress;
  143. std::shared_ptr<CTextInput> inputPort;
  144. void connectToServer();
  145. void leaveScreen();
  146. void onChange(const std::string & newText);
  147. void startConnection(const std::string & addr = {}, ui16 port = 0);
  148. public:
  149. CSimpleJoinScreen(bool host = true);
  150. };
  151. class CLoadingScreen : virtual public CWindowObject, virtual public Load::Progress
  152. {
  153. std::shared_ptr<CPicture> backimg;
  154. std::vector<std::shared_ptr<CPicture>> images;
  155. std::shared_ptr<CPicture> loadFrame;
  156. std::vector<std::shared_ptr<CAnimImage>> progressBlocks;
  157. ImagePath getBackground();
  158. public:
  159. CLoadingScreen();
  160. CLoadingScreen(ImagePath background);
  161. ~CLoadingScreen();
  162. void tick(uint32_t msPassed) override;
  163. };