CMainMenu.h 4.8 KB

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