2018-01-05 19:21:07 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
2024-02-11 23:09:01 +02:00
|
|
|
#include "../../lib/json/JsonNode.h"
|
2023-08-21 03:06:58 +02:00
|
|
|
#include "../../lib/LoadProgress.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-06-25 20:16:03 +02:00
|
|
|
class CampaignState;
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
class CTextInput;
|
|
|
|
class CGStatusBar;
|
|
|
|
class CTextBox;
|
|
|
|
class CTabbedInt;
|
2023-08-22 14:00:14 +02:00
|
|
|
class CAnimImage;
|
2018-01-05 19:21:07 +02:00
|
|
|
class CAnimation;
|
|
|
|
class CButton;
|
|
|
|
class CFilledTexture;
|
2023-08-21 16:56:01 +02:00
|
|
|
class CLabel;
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
// TODO: Find new location for these enums
|
2024-01-21 16:48:36 +02:00
|
|
|
enum class ESelectionScreen : ui8 {
|
2018-01-05 19:21:07 +02:00
|
|
|
unknown = 0, newGame, loadGame, saveGame, scenarioInfo, campaignList
|
|
|
|
};
|
|
|
|
|
2024-01-21 16:48:36 +02:00
|
|
|
enum class ELoadMode : ui8
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-09 13:29:48 +02:00
|
|
|
NONE = 0, SINGLE, MULTI, CAMPAIGN, TUTORIAL
|
2018-01-05 19:21:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// 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::vector<std::shared_ptr<CPicture>> images;
|
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> createTab(size_t index);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
std::vector<std::string> menuNameToEntry;
|
|
|
|
|
|
|
|
CMenuScreen(const JsonNode & configNode);
|
|
|
|
|
2023-06-02 15:42:18 +02:00
|
|
|
void show(Canvas & to) override;
|
2018-01-05 19:21:07 +02:00
|
|
|
void activate() override;
|
|
|
|
void deactivate() override;
|
|
|
|
|
|
|
|
void switchToTab(size_t index);
|
2018-04-07 13:42:11 +02:00
|
|
|
void switchToTab(std::string name);
|
2021-01-17 18:16:34 +02:00
|
|
|
size_t getActiveTab() const;
|
2018-01-05 19:21:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2018-07-25 00:36:48 +02:00
|
|
|
class CMultiMode : public WindowBase
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ESelectionScreen screenType;
|
|
|
|
std::shared_ptr<CPicture> background;
|
2022-12-11 23:43:43 +02:00
|
|
|
std::shared_ptr<CPicture> picture;
|
2018-01-05 19:21:07 +02:00
|
|
|
std::shared_ptr<CTextInput> playerName;
|
|
|
|
std::shared_ptr<CButton> buttonHotseat;
|
2023-11-11 16:43:58 +02:00
|
|
|
std::shared_ptr<CButton> buttonLobby;
|
2018-01-05 19:21:07 +02:00
|
|
|
std::shared_ptr<CButton> buttonHost;
|
|
|
|
std::shared_ptr<CButton> buttonJoin;
|
|
|
|
std::shared_ptr<CButton> buttonCancel;
|
|
|
|
std::shared_ptr<CGStatusBar> statusBar;
|
|
|
|
|
|
|
|
CMultiMode(ESelectionScreen ScreenType);
|
2023-11-11 16:43:58 +02:00
|
|
|
void openLobby();
|
2018-01-05 19:21:07 +02:00
|
|
|
void hostTCP();
|
|
|
|
void joinTCP();
|
2023-05-28 17:29:11 +02:00
|
|
|
std::string getPlayerName();
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
void onNameChange(std::string newText);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Hot seat player window
|
2018-07-25 00:36:48 +02:00
|
|
|
class CMultiPlayers : public WindowBase
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
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::string & firstPlayer, ESelectionScreen ScreenType, bool Host, ELoadMode LoadMode);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Manages the configuration of pregame GUI elements like campaign screen, main menu, loading screen,...
|
|
|
|
class CMainMenuConfig
|
|
|
|
{
|
|
|
|
public:
|
2024-02-12 13:22:54 +02:00
|
|
|
static const CMainMenuConfig & get();
|
2018-01-05 19:21:07 +02:00
|
|
|
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
|
2018-07-25 00:36:48 +02:00
|
|
|
class CMainMenu : public CIntObject, public IUpdateable, public std::enable_shared_from_this<CMainMenu>
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
std::shared_ptr<CFilledTexture> backgroundAroundMenu;
|
|
|
|
|
|
|
|
CMainMenu(); //Use CMainMenu::create
|
|
|
|
|
|
|
|
public:
|
2018-07-25 00:36:48 +02:00
|
|
|
std::shared_ptr<CMenuScreen> menu;
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
~CMainMenu();
|
2023-05-07 23:59:48 +02:00
|
|
|
void activate() override;
|
|
|
|
void onScreenResize() override;
|
2018-01-05 19:21:07 +02:00
|
|
|
void update() override;
|
2024-01-21 16:48:36 +02:00
|
|
|
static void openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> & names, ELoadMode loadMode);
|
2023-09-20 03:13:54 +02:00
|
|
|
static void openCampaignLobby(const std::string & campaignFileName, std::string campaignSet = "");
|
2023-09-20 21:18:13 +02:00
|
|
|
static void openCampaignLobby(std::shared_ptr<CampaignState> campaign);
|
2023-08-09 01:54:09 +02:00
|
|
|
static void startTutorial();
|
2023-09-22 01:39:35 +02:00
|
|
|
static void openHighScoreScreen();
|
2018-01-05 19:21:07 +02:00
|
|
|
void openCampaignScreen(std::string name);
|
|
|
|
|
2018-07-25 00:36:48 +02:00
|
|
|
static std::shared_ptr<CMainMenu> create();
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
static std::shared_ptr<CPicture> createPicture(const JsonNode & config);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Simple window to enter the server's address.
|
2018-07-25 00:36:48 +02:00
|
|
|
class CSimpleJoinScreen : public WindowBase
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
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);
|
2023-11-18 16:34:18 +02:00
|
|
|
void startConnection(const std::string & addr = {}, ui16 port = 0);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
CSimpleJoinScreen(bool host = true);
|
|
|
|
};
|
|
|
|
|
2023-08-21 03:06:58 +02:00
|
|
|
class CLoadingScreen : virtual public CWindowObject, virtual public Load::Progress
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-21 16:56:01 +02:00
|
|
|
std::vector<std::shared_ptr<CAnimImage>> progressBlocks;
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
ImagePath getBackground();
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-08-21 03:06:58 +02:00
|
|
|
public:
|
|
|
|
CLoadingScreen();
|
2018-01-05 19:21:07 +02:00
|
|
|
~CLoadingScreen();
|
|
|
|
|
2023-08-22 14:00:14 +02:00
|
|
|
void tick(uint32_t msPassed) override;
|
2018-01-05 19:21:07 +02:00
|
|
|
};
|
|
|
|
|
2018-07-25 00:36:48 +02:00
|
|
|
extern std::shared_ptr<CMainMenu> CMM;
|