CMainMenu.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. };
  46. class CMenuEntry : public CIntObject
  47. {
  48. std::vector<std::shared_ptr<CPicture>> images;
  49. std::vector<std::shared_ptr<CButton>> buttons;
  50. std::shared_ptr<CButton> createButton(CMenuScreen * parent, const JsonNode & button);
  51. public:
  52. CMenuEntry(CMenuScreen * parent, const JsonNode & config);
  53. };
  54. /// Multiplayer mode
  55. class CMultiMode : public WindowBase
  56. {
  57. public:
  58. ESelectionScreen screenType;
  59. std::shared_ptr<CPicture> background;
  60. std::shared_ptr<CTextInput> playerName;
  61. std::shared_ptr<CButton> buttonHotseat;
  62. std::shared_ptr<CButton> buttonHost;
  63. std::shared_ptr<CButton> buttonJoin;
  64. std::shared_ptr<CButton> buttonCancel;
  65. std::shared_ptr<CGStatusBar> statusBar;
  66. CMultiMode(ESelectionScreen ScreenType);
  67. void hostTCP();
  68. void joinTCP();
  69. void onNameChange(std::string newText);
  70. };
  71. /// Hot seat player window
  72. class CMultiPlayers : public WindowBase
  73. {
  74. bool host;
  75. ELoadMode loadMode;
  76. ESelectionScreen screenType;
  77. std::shared_ptr<CPicture> background;
  78. std::shared_ptr<CTextBox> textTitle;
  79. std::array<std::shared_ptr<CTextInput>, 8> inputNames;
  80. std::shared_ptr<CButton> buttonOk;
  81. std::shared_ptr<CButton> buttonCancel;
  82. std::shared_ptr<CGStatusBar> statusBar;
  83. void onChange(std::string newText);
  84. void enterSelectionScreen();
  85. public:
  86. CMultiPlayers(const std::string & firstPlayer, ESelectionScreen ScreenType, bool Host, ELoadMode LoadMode);
  87. };
  88. /// Manages the configuration of pregame GUI elements like campaign screen, main menu, loading screen,...
  89. class CMainMenuConfig
  90. {
  91. public:
  92. static CMainMenuConfig & get();
  93. const JsonNode & getConfig() const;
  94. const JsonNode & getCampaigns() const;
  95. private:
  96. CMainMenuConfig();
  97. const JsonNode campaignSets;
  98. const JsonNode config;
  99. };
  100. /// Handles background screen, loads graphics for victory/loss condition and random town or hero selection
  101. class CMainMenu : public CIntObject, public IUpdateable, public std::enable_shared_from_this<CMainMenu>
  102. {
  103. std::shared_ptr<CFilledTexture> backgroundAroundMenu;
  104. CMainMenu(); //Use CMainMenu::create
  105. public:
  106. std::shared_ptr<CMenuScreen> menu;
  107. ~CMainMenu();
  108. void update() override;
  109. static void openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> * names, ELoadMode loadMode);
  110. static void openCampaignLobby(const std::string & campaignFileName);
  111. static void openCampaignLobby(std::shared_ptr<CCampaignState> campaign);
  112. void openCampaignScreen(std::string name);
  113. static std::shared_ptr<CMainMenu> create();
  114. static std::shared_ptr<CPicture> createPicture(const JsonNode & config);
  115. };
  116. /// Simple window to enter the server's address.
  117. class CSimpleJoinScreen : public WindowBase
  118. {
  119. std::shared_ptr<CPicture> background;
  120. std::shared_ptr<CTextBox> textTitle;
  121. std::shared_ptr<CButton> buttonOk;
  122. std::shared_ptr<CButton> buttonCancel;
  123. std::shared_ptr<CGStatusBar> statusBar;
  124. std::shared_ptr<CTextInput> inputAddress;
  125. std::shared_ptr<CTextInput> inputPort;
  126. void connectToServer();
  127. void leaveScreen();
  128. void onChange(const std::string & newText);
  129. void connectThread(const std::string addr = "", const ui16 inputPort = 0);
  130. public:
  131. CSimpleJoinScreen(bool host = true);
  132. };
  133. class CLoadingScreen : public CWindowObject
  134. {
  135. boost::thread loadingThread;
  136. std::string getBackground();
  137. public:
  138. CLoadingScreen(std::function<void()> loader);
  139. ~CLoadingScreen();
  140. void showAll(SDL_Surface * to) override;
  141. };
  142. extern std::shared_ptr<CMainMenu> CMM;