CMainMenu.h 4.6 KB

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