1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/*
* CMainMenu.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "../windows/CWindowObject.h"
#include "../../lib/json/JsonNode.h"
#include "../../lib/LoadProgress.h"
VCMI_LIB_NAMESPACE_BEGIN
class CampaignState;
VCMI_LIB_NAMESPACE_END
class CTextInput;
class CGStatusBar;
class CTextBox;
class CTabbedInt;
class CAnimImage;
class CButton;
class CFilledTexture;
class CLabel;
class VideoWidget;
// TODO: Find new location for these enums
enum class ESelectionScreen : ui8 {
unknown = 0, newGame, loadGame, saveGame, scenarioInfo, campaignList
};
enum class ELoadMode : ui8
{
NONE = 0, SINGLE, MULTI, CAMPAIGN, TUTORIAL
};
/// The main menu screens listed in the EState enum
class CMenuScreen : public CWindowObject
{
const JsonNode & config;
std::shared_ptr<CTabbedInt> tabs;
std::shared_ptr<CPicture> background;
std::shared_ptr<VideoWidget> videoPlayer;
std::vector<std::shared_ptr<CPicture>> images;
std::shared_ptr<CIntObject> createTab(size_t index);
public:
std::vector<std::string> menuNameToEntry;
CMenuScreen(const JsonNode & configNode);
void activate() override;
void show(Canvas & to) override;
void switchToTab(size_t index);
void switchToTab(std::string name);
size_t getActiveTab() const;
};
class CMenuEntry : public CIntObject
{
std::vector<std::shared_ptr<CPicture>> images;
std::vector<std::shared_ptr<CButton>> buttons;
std::shared_ptr<CButton> createButton(CMenuScreen * parent, const JsonNode & button);
public:
CMenuEntry(CMenuScreen * parent, const JsonNode & config);
};
/// Multiplayer mode
class CMultiMode : public WindowBase
{
public:
ESelectionScreen screenType;
std::shared_ptr<CPicture> background;
std::shared_ptr<CPicture> picture;
std::shared_ptr<CTextBox> textTitle;
std::shared_ptr<CTextInput> playerName;
std::shared_ptr<CButton> buttonHotseat;
std::shared_ptr<CButton> buttonLobby;
std::shared_ptr<CButton> buttonHost;
std::shared_ptr<CButton> buttonJoin;
std::shared_ptr<CButton> buttonCancel;
std::shared_ptr<CGStatusBar> statusBar;
CMultiMode(ESelectionScreen ScreenType);
void openLobby();
void hostTCP(EShortcut shortcut);
void joinTCP(EShortcut shortcut);
/// Get all configured player names. The first name would always be present and initialized to its default value.
std::vector<std::string> getPlayersNames();
void onNameChange(std::string newText);
};
/// Hot seat player window
class CMultiPlayers : public WindowBase
{
bool host;
ELoadMode loadMode;
ESelectionScreen screenType;
std::shared_ptr<CPicture> background;
std::shared_ptr<CTextBox> textTitle;
std::array<std::shared_ptr<CTextInput>, 8> inputNames;
std::shared_ptr<CButton> buttonOk;
std::shared_ptr<CButton> buttonCancel;
std::shared_ptr<CGStatusBar> statusBar;
void onChange(std::string newText);
void enterSelectionScreen();
public:
CMultiPlayers(const std::vector<std::string> & playerNames, ESelectionScreen ScreenType, bool Host, ELoadMode LoadMode, EShortcut shortcut);
};
/// Manages the configuration of pregame GUI elements like campaign screen, main menu, loading screen,...
class CMainMenuConfig
{
public:
static const CMainMenuConfig & get();
const JsonNode & getConfig() const;
const JsonNode & getCampaigns() const;
private:
CMainMenuConfig();
const JsonNode campaignSets;
const JsonNode config;
};
/// Handles background screen, loads graphics for victory/loss condition and random town or hero selection
class CMainMenu : public CIntObject, public IUpdateable, public std::enable_shared_from_this<CMainMenu>
{
std::shared_ptr<CFilledTexture> backgroundAroundMenu;
std::vector<VideoPath> videoPlayList;
CMainMenu(); //Use CMainMenu::create
public:
std::shared_ptr<CMenuScreen> menu;
~CMainMenu();
void activate() override;
void onScreenResize() override;
void update() override;
static void openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> & names, ELoadMode loadMode);
static void openCampaignLobby(const std::string & campaignFileName, std::string campaignSet = "");
static void openCampaignLobby(std::shared_ptr<CampaignState> campaign);
static void startTutorial();
static void openHighScoreScreen();
void openCampaignScreen(std::string name);
static std::shared_ptr<CMainMenu> create();
static std::shared_ptr<CPicture> createPicture(const JsonNode & config);
void playIntroVideos();
void playMusic();
};
/// Simple window to enter the server's address.
class CSimpleJoinScreen : public WindowBase
{
std::shared_ptr<CPicture> background;
std::shared_ptr<CTextBox> textTitle;
std::shared_ptr<CButton> buttonOk;
std::shared_ptr<CButton> buttonCancel;
std::shared_ptr<CGStatusBar> statusBar;
std::shared_ptr<CTextInput> inputAddress;
std::shared_ptr<CTextInput> inputPort;
void connectToServer();
void leaveScreen();
void onChange(const std::string & newText);
void startConnection(const std::string & addr = {}, ui16 port = 0);
public:
CSimpleJoinScreen(bool host = true);
};
class CLoadingScreen : virtual public CWindowObject, virtual public Load::Progress
{
std::vector<std::shared_ptr<CAnimImage>> progressBlocks;
ImagePath getBackground();
public:
CLoadingScreen();
CLoadingScreen(ImagePath background);
~CLoadingScreen();
void tick(uint32_t msPassed) override;
};
extern std::shared_ptr<CMainMenu> CMM;
|