CMainMenu.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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/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 CAnimation;
  23. class CButton;
  24. class CFilledTexture;
  25. class CLabel;
  26. // TODO: Find new location for these enums
  27. enum ESelectionScreen : ui8 {
  28. unknown = 0, newGame, loadGame, saveGame, scenarioInfo, campaignList
  29. };
  30. enum 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::vector<std::shared_ptr<CPicture>> images;
  41. std::shared_ptr<CIntObject> createTab(size_t index);
  42. public:
  43. std::vector<std::string> menuNameToEntry;
  44. CMenuScreen(const JsonNode & configNode);
  45. void show(Canvas & to) override;
  46. void activate() override;
  47. void deactivate() 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> buttonHost;
  70. std::shared_ptr<CButton> buttonJoin;
  71. std::shared_ptr<CButton> buttonCancel;
  72. std::shared_ptr<CGStatusBar> statusBar;
  73. CMultiMode(ESelectionScreen ScreenType);
  74. void hostTCP();
  75. void joinTCP();
  76. std::string getPlayerName();
  77. void onNameChange(std::string newText);
  78. };
  79. /// Hot seat player window
  80. class CMultiPlayers : public WindowBase
  81. {
  82. bool host;
  83. ELoadMode loadMode;
  84. ESelectionScreen screenType;
  85. std::shared_ptr<CPicture> background;
  86. std::shared_ptr<CTextBox> textTitle;
  87. std::array<std::shared_ptr<CTextInput>, 8> inputNames;
  88. std::shared_ptr<CButton> buttonOk;
  89. std::shared_ptr<CButton> buttonCancel;
  90. std::shared_ptr<CGStatusBar> statusBar;
  91. void onChange(std::string newText);
  92. void enterSelectionScreen();
  93. public:
  94. CMultiPlayers(const std::string & firstPlayer, ESelectionScreen ScreenType, bool Host, ELoadMode LoadMode);
  95. };
  96. /// Manages the configuration of pregame GUI elements like campaign screen, main menu, loading screen,...
  97. class CMainMenuConfig
  98. {
  99. public:
  100. static CMainMenuConfig & get();
  101. const JsonNode & getConfig() const;
  102. const JsonNode & getCampaigns() const;
  103. private:
  104. CMainMenuConfig();
  105. const JsonNode campaignSets;
  106. const JsonNode config;
  107. };
  108. /// Handles background screen, loads graphics for victory/loss condition and random town or hero selection
  109. class CMainMenu : public CIntObject, public IUpdateable, public std::enable_shared_from_this<CMainMenu>
  110. {
  111. std::shared_ptr<CFilledTexture> backgroundAroundMenu;
  112. CMainMenu(); //Use CMainMenu::create
  113. public:
  114. std::shared_ptr<CMenuScreen> menu;
  115. ~CMainMenu();
  116. void activate() override;
  117. void onScreenResize() override;
  118. void update() override;
  119. static void openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> * names, ELoadMode loadMode);
  120. static void openCampaignLobby(const std::string & campaignFileName, std::string campaignSet = "");
  121. static void openCampaignLobby(std::shared_ptr<CampaignState> campaign);
  122. static void startTutorial();
  123. static void openHighScoreScreen();
  124. void openCampaignScreen(std::string name);
  125. static std::shared_ptr<CMainMenu> create();
  126. static std::shared_ptr<CPicture> createPicture(const JsonNode & config);
  127. };
  128. /// Simple window to enter the server's address.
  129. class CSimpleJoinScreen : public WindowBase
  130. {
  131. std::shared_ptr<CPicture> background;
  132. std::shared_ptr<CTextBox> textTitle;
  133. std::shared_ptr<CButton> buttonOk;
  134. std::shared_ptr<CButton> buttonCancel;
  135. std::shared_ptr<CGStatusBar> statusBar;
  136. std::shared_ptr<CTextInput> inputAddress;
  137. std::shared_ptr<CTextInput> inputPort;
  138. void connectToServer();
  139. void leaveScreen();
  140. void onChange(const std::string & newText);
  141. void startConnectThread(const std::string & addr = {}, ui16 port = 0);
  142. void connectThread(const std::string & addr, ui16 port);
  143. public:
  144. CSimpleJoinScreen(bool host = true);
  145. };
  146. class CLoadingScreen : virtual public CWindowObject, virtual public Load::Progress
  147. {
  148. std::vector<std::shared_ptr<CAnimImage>> progressBlocks;
  149. ImagePath getBackground();
  150. public:
  151. CLoadingScreen();
  152. ~CLoadingScreen();
  153. void tick(uint32_t msPassed) override;
  154. };
  155. extern std::shared_ptr<CMainMenu> CMM;