2011-12-14 00:23:17 +03:00
|
|
|
#pragma once
|
|
|
|
|
2013-07-28 17:49:50 +03:00
|
|
|
#include "../lib/filesystem/Filesystem.h"
|
2009-04-16 14:14:13 +03:00
|
|
|
#include <SDL.h>
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "../lib/StartInfo.h"
|
2011-03-15 16:35:36 +02:00
|
|
|
#include "GUIClasses.h"
|
2013-11-30 13:08:38 +03:00
|
|
|
#include "../lib/FunctionList.h"
|
2013-04-07 13:48:07 +03:00
|
|
|
#include "../lib/mapping/CMapInfo.h"
|
2013-04-15 20:18:04 +03:00
|
|
|
#include "../lib/rmg/CMapGenerator.h"
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CPreGame.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
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
|
|
|
|
2010-10-31 00:53:41 +03:00
|
|
|
class CMusicHandler;
|
2010-02-08 16:38:06 +02:00
|
|
|
class CMapHeader;
|
2010-02-13 18:26:47 +02:00
|
|
|
class CCampaignHeader;
|
2010-02-15 08:54:57 +02:00
|
|
|
class CTextInput;
|
2010-02-15 14:12:21 +02:00
|
|
|
class CCampaign;
|
2010-02-15 13:37:47 +02:00
|
|
|
class CGStatusBar;
|
2010-07-06 05:10:26 +03:00
|
|
|
class CTextBox;
|
2010-08-04 14:18:13 +03:00
|
|
|
class CCampaignState;
|
2010-09-03 21:42:54 +03:00
|
|
|
class CConnection;
|
2011-11-27 16:14:20 +03:00
|
|
|
class JsonNode;
|
2012-11-13 15:55:47 +03:00
|
|
|
class CMapGenOptions;
|
2013-05-21 22:08:06 +03:00
|
|
|
class CRandomMapTab;
|
2010-10-31 00:53:41 +03:00
|
|
|
struct CPackForSelectionScreen;
|
|
|
|
struct PlayerInfo;
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2010-10-24 14:35:14 +03:00
|
|
|
namespace boost{ class thread; class recursive_mutex;}
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2010-02-15 15:28:33 +02:00
|
|
|
enum ESortBy{_playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps}; //_numOfMaps is for campaigns
|
2010-02-08 16:38:06 +02:00
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Class which handles map sorting by different criteria
|
2010-02-08 16:38:06 +02:00
|
|
|
class mapSorter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ESortBy sortBy;
|
2010-02-13 18:26:47 +02:00
|
|
|
bool operator()(const CMapInfo *aaa, const CMapInfo *bbb);
|
2010-02-08 16:38:06 +02:00
|
|
|
mapSorter(ESortBy es):sortBy(es){};
|
|
|
|
};
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// The main menu screens listed in the EState enum
|
2009-08-17 11:50:31 +03:00
|
|
|
class CMenuScreen : public CIntObject
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2011-11-27 16:14:20 +03:00
|
|
|
const JsonNode& config;
|
|
|
|
|
|
|
|
CTabbedInt *tabs;
|
|
|
|
|
2012-05-20 14:03:21 +03:00
|
|
|
CPicture * background;
|
2011-11-27 16:14:20 +03:00
|
|
|
std::vector<CPicture*> images;
|
|
|
|
|
|
|
|
CIntObject *createTab(size_t index);
|
2009-04-16 14:14:13 +03:00
|
|
|
public:
|
2011-11-27 16:14:20 +03:00
|
|
|
std::vector<std::string> menuNameToEntry;
|
|
|
|
|
2010-02-13 18:26:47 +02:00
|
|
|
enum EState { //where are we?
|
2010-02-24 15:03:36 +02:00
|
|
|
mainMenu, newGame, loadGame, campaignMain, saveGame, scenarioInfo, campaignList
|
2010-02-13 18:26:47 +02:00
|
|
|
};
|
|
|
|
|
2010-09-03 21:42:54 +03:00
|
|
|
enum EMultiMode {
|
2010-10-24 14:35:14 +03:00
|
|
|
SINGLE_PLAYER = 0, MULTI_HOT_SEAT, MULTI_NETWORK_HOST, MULTI_NETWORK_GUEST
|
2010-09-03 21:42:54 +03:00
|
|
|
};
|
2011-11-27 16:14:20 +03:00
|
|
|
CMenuScreen(const JsonNode& configNode);
|
2010-09-03 21:42:54 +03:00
|
|
|
|
2012-05-18 20:35:46 +03:00
|
|
|
void showAll(SDL_Surface * to);
|
2009-08-17 11:50:31 +03:00
|
|
|
void show(SDL_Surface * to);
|
2011-11-27 16:14:20 +03:00
|
|
|
void activate();
|
|
|
|
void deactivate();
|
|
|
|
|
|
|
|
void switchToTab(size_t index);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CMenuEntry : public CIntObject
|
|
|
|
{
|
|
|
|
std::vector<CPicture*> images;
|
2011-12-22 16:05:19 +03:00
|
|
|
std::vector<CAdventureMapButton*> buttons;
|
2011-11-27 16:14:20 +03:00
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
CAdventureMapButton* createButton(CMenuScreen* parent, const JsonNode& button);
|
2011-11-27 16:14:20 +03:00
|
|
|
public:
|
|
|
|
CMenuEntry(CMenuScreen* parent, const JsonNode &config);
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
class CreditsScreen : public CIntObject
|
|
|
|
{
|
2013-08-29 19:41:14 +03:00
|
|
|
int positionCounter;
|
|
|
|
CMultiLineLabel* credits;
|
2011-11-27 16:14:20 +03:00
|
|
|
public:
|
|
|
|
CreditsScreen();
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
void show(SDL_Surface * to);
|
2011-11-27 16:14:20 +03:00
|
|
|
|
|
|
|
void clickLeft(tribool down, bool previousState);
|
|
|
|
void clickRight(tribool down, bool previousState);
|
|
|
|
};
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Implementation of the chat box
|
2010-09-03 21:42:54 +03:00
|
|
|
class CChatBox : public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTextBox *chatHistory;
|
|
|
|
CTextInput *inputBox;
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
CChatBox(const Rect &rect);
|
2010-10-24 14:35:14 +03:00
|
|
|
|
|
|
|
void keyPressed(const SDL_KeyboardEvent & key);
|
|
|
|
|
|
|
|
void addNewMessage(const std::string &text);
|
2010-09-03 21:42:54 +03:00
|
|
|
};
|
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
class InfoCard : public CIntObject
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2010-02-18 14:34:44 +02:00
|
|
|
public:
|
2011-11-27 16:14:20 +03:00
|
|
|
CPicture *bg;
|
2010-02-13 18:26:47 +02:00
|
|
|
CMenuScreen::EState type;
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2010-10-24 14:35:14 +03:00
|
|
|
bool network;
|
2010-09-03 21:42:54 +03:00
|
|
|
bool chatOn; //if chat is shown, then description is hidden
|
2010-07-06 05:10:26 +03:00
|
|
|
CTextBox *mapDescription;
|
2010-09-03 21:42:54 +03:00
|
|
|
CChatBox *chat;
|
2010-10-24 14:35:14 +03:00
|
|
|
CPicture *playerListBg;
|
2010-09-03 21:42:54 +03:00
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
CHighlightableButtonsGroup *difficulty;
|
2012-09-15 22:16:16 +03:00
|
|
|
CDefHandler *sizes, *sFlags;
|
2009-08-17 11:50:31 +03:00
|
|
|
|
|
|
|
void changeSelection(const CMapInfo *to);
|
|
|
|
void showAll(SDL_Surface * to);
|
2009-08-22 16:59:15 +03:00
|
|
|
void clickRight(tribool down, bool previousState);
|
|
|
|
void showTeamsPopup();
|
2010-09-03 21:42:54 +03:00
|
|
|
void toggleChat();
|
|
|
|
void setChat(bool activateChat);
|
2010-10-24 14:35:14 +03:00
|
|
|
InfoCard(bool Network = false);
|
2009-08-17 11:50:31 +03:00
|
|
|
~InfoCard();
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// The selection tab which is shown at the map selection screen
|
2009-08-17 11:50:31 +03:00
|
|
|
class SelectionTab : public CIntObject
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2010-02-13 18:26:47 +02:00
|
|
|
private:
|
|
|
|
CDefHandler *format; //map size
|
|
|
|
|
2013-07-28 17:49:50 +03:00
|
|
|
void parseMaps(const std::unordered_set<ResourceID> &files);
|
|
|
|
void parseGames(const std::unordered_set<ResourceID> &files, bool multi);
|
|
|
|
void parseCampaigns(const std::unordered_set<ResourceID> & files );
|
|
|
|
std::unordered_set<ResourceID> getFiles(std::string dirURI, int resType);
|
2011-11-27 16:14:20 +03:00
|
|
|
CMenuScreen::EState tabType;
|
2009-04-16 14:14:13 +03:00
|
|
|
public:
|
2009-08-17 11:50:31 +03:00
|
|
|
int positions; //how many entries (games/maps) can be shown
|
|
|
|
CPicture *bg; //general bg image
|
|
|
|
CSlider *slider;
|
|
|
|
std::vector<CMapInfo> allItems;
|
|
|
|
std::vector<CMapInfo*> curItems;
|
|
|
|
size_t selectionPos;
|
2013-06-26 14:18:27 +03:00
|
|
|
std::function<void(CMapInfo *)> onSelect;
|
2009-08-17 11:50:31 +03:00
|
|
|
|
|
|
|
ESortBy sortingBy;
|
|
|
|
bool ascending;
|
|
|
|
|
2009-08-27 11:04:32 +03:00
|
|
|
CTextInput *txt;
|
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
|
2009-08-27 11:04:32 +03:00
|
|
|
void filter(int size, bool selectFirst = false); //0 - all
|
2009-08-17 11:50:31 +03:00
|
|
|
void select(int position); //position: <0 - positions> position on the screen
|
2009-08-27 11:04:32 +03:00
|
|
|
void selectAbs(int position); //position: absolute position in curItems vector
|
2009-08-17 11:50:31 +03:00
|
|
|
int getPosition(int x, int y); //convert mouse coords to entry position; -1 means none
|
|
|
|
void sliderMove(int slidPos);
|
|
|
|
void sortBy(int criteria);
|
|
|
|
void sort();
|
|
|
|
void printMaps(SDL_Surface *to);
|
2009-08-27 11:04:32 +03:00
|
|
|
int getLine();
|
2012-08-01 15:02:54 +03:00
|
|
|
void selectFName(std::string fname);
|
2012-11-20 20:53:45 +03:00
|
|
|
const CMapInfo * getSelectedMapInfo() const;
|
2009-08-17 11:50:31 +03:00
|
|
|
|
|
|
|
void showAll(SDL_Surface * to);
|
|
|
|
void clickLeft(tribool down, bool previousState);
|
2009-08-23 21:01:08 +03:00
|
|
|
void keyPressed(const SDL_KeyboardEvent & key);
|
|
|
|
void onDoubleClick();
|
2013-06-26 14:18:27 +03:00
|
|
|
SelectionTab(CMenuScreen::EState Type, const std::function<void(CMapInfo *)> &OnSelect, CMenuScreen::EMultiMode MultiPlayer = CMenuScreen::SINGLE_PLAYER);
|
2012-11-11 15:23:31 +03:00
|
|
|
~SelectionTab();
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// The options tab which is shown at the map selection phase.
|
2009-08-17 11:50:31 +03:00
|
|
|
class OptionsTab : public CIntObject
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2010-02-18 14:34:44 +02:00
|
|
|
CPicture *bg;
|
2009-04-16 14:14:13 +03:00
|
|
|
public:
|
2009-08-17 11:50:31 +03:00
|
|
|
enum SelType {TOWN, HERO, BONUS};
|
2012-10-05 16:11:26 +03:00
|
|
|
|
2012-12-10 17:28:27 +03:00
|
|
|
struct CPlayerSettingsHelper
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2012-12-10 17:28:27 +03:00
|
|
|
const PlayerSettings & settings;
|
|
|
|
const SelType type;
|
|
|
|
|
|
|
|
CPlayerSettingsHelper(const PlayerSettings & settings, SelType type):
|
|
|
|
settings(settings),
|
|
|
|
type(type)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/// visible image settings
|
|
|
|
size_t getImageIndex();
|
|
|
|
std::string getImageName();
|
|
|
|
|
|
|
|
std::string getName(); /// name visible in options dialog
|
|
|
|
std::string getTitle(); /// title in popup box
|
|
|
|
std::string getSubtitle(); /// popup box subtitle
|
|
|
|
std::string getDescription();/// popup box description, not always present
|
|
|
|
};
|
|
|
|
|
|
|
|
class CPregameTooltipBox : public CWindowObject, public CPlayerSettingsHelper
|
|
|
|
{
|
|
|
|
void genHeader();
|
|
|
|
void genTownWindow();
|
|
|
|
void genHeroWindow();
|
|
|
|
void genBonusWindow();
|
|
|
|
public:
|
|
|
|
CPregameTooltipBox(CPlayerSettingsHelper & helper);
|
|
|
|
};
|
2009-08-22 16:59:15 +03:00
|
|
|
|
2012-12-10 17:28:27 +03:00
|
|
|
struct SelectedBox : public CIntObject, public CPlayerSettingsHelper //img with current town/hero/bonus
|
|
|
|
{
|
|
|
|
CAnimImage * image;
|
|
|
|
CLabel *subtitle;
|
2009-08-22 16:59:15 +03:00
|
|
|
|
2012-12-10 17:28:27 +03:00
|
|
|
SelectedBox(Point position, PlayerSettings & settings, SelType type);
|
2009-08-22 16:59:15 +03:00
|
|
|
void clickRight(tribool down, bool previousState);
|
2012-12-10 17:28:27 +03:00
|
|
|
|
|
|
|
void update();
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2009-08-17 11:50:31 +03:00
|
|
|
|
|
|
|
struct PlayerOptionsEntry : public CIntObject
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2010-10-24 14:35:14 +03:00
|
|
|
PlayerInfo π
|
2009-08-17 11:50:31 +03:00
|
|
|
PlayerSettings &s;
|
|
|
|
CPicture *bg;
|
2011-12-22 16:05:19 +03:00
|
|
|
CAdventureMapButton *btns[6]; //left and right for town, hero, bonus
|
|
|
|
CAdventureMapButton *flag;
|
2009-08-17 11:50:31 +03:00
|
|
|
SelectedBox *town;
|
|
|
|
SelectedBox *hero;
|
|
|
|
SelectedBox *bonus;
|
2010-03-08 00:56:51 +02:00
|
|
|
enum {HUMAN_OR_CPU, HUMAN, CPU} whoCanPlay;
|
2011-11-27 16:14:20 +03:00
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
PlayerOptionsEntry(OptionsTab *owner, PlayerSettings &S);
|
2011-08-25 18:24:37 +03:00
|
|
|
void selectButtons(); //hides unavailable buttons
|
2009-08-17 11:50:31 +03:00
|
|
|
void showAll(SDL_Surface * to);
|
2012-12-10 17:28:27 +03:00
|
|
|
void update();
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2010-10-24 14:35:14 +03:00
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
CSlider *turnDuration;
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
std::set<int> usedHeroes;
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2010-10-24 14:35:14 +03:00
|
|
|
struct PlayerToRestore
|
|
|
|
{
|
2013-03-03 20:06:03 +03:00
|
|
|
PlayerColor color;
|
|
|
|
int id;
|
|
|
|
void reset() { id = -1; color = PlayerColor::CANNOT_DETERMINE; }
|
2010-10-24 14:35:14 +03:00
|
|
|
PlayerToRestore(){ reset(); }
|
|
|
|
} playerToRestore;
|
|
|
|
|
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
std::map<PlayerColor, PlayerOptionsEntry *> entries; //indexed by color
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
void nextCastle(PlayerColor player, int dir); //dir == -1 or +1
|
|
|
|
void nextHero(PlayerColor player, int dir); //dir == -1 or +1
|
|
|
|
void nextBonus(PlayerColor player, int dir); //dir == -1 or +1
|
2009-08-17 11:50:31 +03:00
|
|
|
void setTurnLength(int npos);
|
2013-03-03 20:06:03 +03:00
|
|
|
void flagPressed(PlayerColor player);
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2010-10-24 14:35:14 +03:00
|
|
|
void recreate();
|
|
|
|
OptionsTab();
|
2009-08-17 11:50:31 +03:00
|
|
|
~OptionsTab();
|
|
|
|
void showAll(SDL_Surface * to);
|
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
int nextAllowedHero(PlayerColor player, int min, int max, int incl, int dir );
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
bool canUseThisHero(PlayerColor player, int ID );
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2013-05-21 22:08:06 +03:00
|
|
|
/// The random map tab shows options for generating a random map.
|
|
|
|
class CRandomMapTab : public CIntObject
|
2012-11-11 15:23:31 +03:00
|
|
|
{
|
|
|
|
public:
|
2013-05-21 22:08:06 +03:00
|
|
|
CRandomMapTab();
|
2012-11-11 15:23:31 +03:00
|
|
|
|
2013-05-21 22:08:06 +03:00
|
|
|
void showAll(SDL_Surface * to);
|
2012-11-20 20:53:45 +03:00
|
|
|
void updateMapInfo();
|
|
|
|
CFunctionList<void (const CMapInfo *)> & getMapInfoChanged();
|
2013-05-21 22:08:06 +03:00
|
|
|
const CMapInfo * getMapInfo() const;
|
2012-11-20 20:53:45 +03:00
|
|
|
const CMapGenOptions & getMapGenOptions() const;
|
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
private:
|
|
|
|
void addButtonsToGroup(CHighlightableButtonsGroup * group, const std::vector<std::string> & defs, int startIndex, int endIndex, int btnWidth, int helpStartIndex) const;
|
|
|
|
void addButtonsWithRandToGroup(CHighlightableButtonsGroup * group, const std::vector<std::string> & defs, int startIndex, int endIndex, int btnWidth, int helpStartIndex, int helpRandIndex) const;
|
|
|
|
void deactivateButtonsFrom(CHighlightableButtonsGroup * group, int startId);
|
|
|
|
void validatePlayersCnt(int playersCnt);
|
|
|
|
void validateCompOnlyPlayersCnt(int compOnlyPlayersCnt);
|
|
|
|
|
|
|
|
CPicture * bg;
|
2013-05-21 22:08:06 +03:00
|
|
|
CHighlightableButton * twoLevelsBtn;
|
|
|
|
CHighlightableButtonsGroup * mapSizeBtnGroup, * playersCntGroup, * teamsCntGroup, * compOnlyPlayersCntGroup,
|
|
|
|
* compOnlyTeamsCntGroup, * waterContentGroup, * monsterStrengthGroup;
|
2012-11-11 15:23:31 +03:00
|
|
|
CAdventureMapButton * showRandMaps;
|
2012-11-20 20:53:45 +03:00
|
|
|
CMapGenOptions mapGenOptions;
|
2013-05-21 22:08:06 +03:00
|
|
|
unique_ptr<CMapInfo> mapInfo;
|
2012-11-20 20:53:45 +03:00
|
|
|
CFunctionList<void(const CMapInfo *)> mapInfoChanged;
|
2012-11-11 15:23:31 +03:00
|
|
|
};
|
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Interface for selecting a map.
|
2010-10-24 14:35:14 +03:00
|
|
|
class ISelectionScreenInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CMenuScreen::EMultiMode multiPlayer;
|
|
|
|
CMenuScreen::EState screenType; //new/save/load#Game
|
|
|
|
const CMapInfo *current;
|
|
|
|
StartInfo sInfo;
|
2013-03-03 20:06:03 +03:00
|
|
|
std::map<ui8, std::string> playerNames; // id of player <-> player name; 0 is reserved as ID of AI "players"
|
2010-10-24 14:35:14 +03:00
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
ISelectionScreenInfo(const std::map<ui8, std::string> *Names = nullptr);
|
2010-10-24 14:35:14 +03:00
|
|
|
virtual ~ISelectionScreenInfo();
|
|
|
|
virtual void update(){};
|
|
|
|
virtual void propagateOptions() {};
|
|
|
|
virtual void postRequest(ui8 what, ui8 dir) {};
|
|
|
|
virtual void postChatMessage(const std::string &txt){};
|
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
void setPlayer(PlayerSettings &pset, ui8 player);
|
2010-10-24 14:35:14 +03:00
|
|
|
void updateStartInfo( std::string filename, StartInfo & sInfo, const CMapHeader * mapHeader );
|
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
ui8 getIdOfFirstUnallocatedPlayer(); //returns 0 if none
|
2010-10-24 14:35:14 +03:00
|
|
|
bool isGuest() const;
|
|
|
|
bool isHost() const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// The actual map selection screen which consists of the options and selection tab
|
2010-10-24 14:35:14 +03:00
|
|
|
class CSelectionScreen : public CIntObject, public ISelectionScreenInfo
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2012-05-18 20:35:46 +03:00
|
|
|
bool bordered;
|
2010-07-06 05:10:26 +03:00
|
|
|
public:
|
2009-08-17 11:50:31 +03:00
|
|
|
CPicture *bg; //general bg image
|
|
|
|
InfoCard *card;
|
|
|
|
OptionsTab *opt;
|
2013-05-21 22:08:06 +03:00
|
|
|
CRandomMapTab * randMapTab;
|
2011-12-22 16:05:19 +03:00
|
|
|
CAdventureMapButton *start, *back;
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2010-02-18 14:34:44 +02:00
|
|
|
SelectionTab *sel;
|
2009-08-17 11:50:31 +03:00
|
|
|
CIntObject *curTab;
|
2010-10-24 14:35:14 +03:00
|
|
|
|
|
|
|
boost::thread *serverHandlingThread;
|
|
|
|
boost::recursive_mutex *mx;
|
|
|
|
std::list<CPackForSelectionScreen *> upcomingPacks; //protected by mx
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2010-09-03 21:42:54 +03:00
|
|
|
CConnection *serv; //connection to server, used in MP mode
|
2010-10-24 14:35:14 +03:00
|
|
|
bool ongoingClosing;
|
|
|
|
ui8 myNameID; //used when networking - otherwise all player are "mine"
|
2010-09-03 21:42:54 +03:00
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer = CMenuScreen::SINGLE_PLAYER, const std::map<ui8, std::string> * Names = nullptr, const std::string & Address = "", const std::string & Port = "");
|
2009-08-17 11:50:31 +03:00
|
|
|
~CSelectionScreen();
|
|
|
|
void toggleTab(CIntObject *tab);
|
|
|
|
void changeSelection(const CMapInfo *to);
|
2010-02-15 14:12:21 +02:00
|
|
|
void startCampaign();
|
2012-12-17 21:01:17 +03:00
|
|
|
void startScenario();
|
2009-08-17 11:50:31 +03:00
|
|
|
void difficultyChange(int to);
|
2010-09-03 21:42:54 +03:00
|
|
|
|
|
|
|
void handleConnection();
|
2010-10-24 14:35:14 +03:00
|
|
|
|
|
|
|
void processPacks();
|
|
|
|
void setSInfo(const StartInfo &si);
|
2012-12-02 15:21:44 +03:00
|
|
|
void update() override;
|
|
|
|
void propagateOptions() override;
|
|
|
|
void postRequest(ui8 what, ui8 dir) override;
|
|
|
|
void postChatMessage(const std::string &txt) override;
|
2010-10-24 14:35:14 +03:00
|
|
|
void propagateNames();
|
2012-05-18 20:35:46 +03:00
|
|
|
void showAll(SDL_Surface *to);
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2009-08-17 11:50:31 +03:00
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Save game screen
|
2010-03-08 00:56:51 +02:00
|
|
|
class CSavingScreen : public CSelectionScreen
|
|
|
|
{
|
|
|
|
public:
|
2011-11-27 16:14:20 +03:00
|
|
|
const CMapInfo *ourGame;
|
2010-03-08 00:56:51 +02:00
|
|
|
|
|
|
|
|
2010-05-27 00:59:58 +03:00
|
|
|
CSavingScreen(bool hotseat = false);
|
2010-03-08 00:56:51 +02:00
|
|
|
~CSavingScreen();
|
|
|
|
};
|
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Scenario information screen shown during the game (thus not really a "pre-game" but fits here anyway)
|
2010-10-24 14:35:14 +03:00
|
|
|
class CScenarioInfo : public CIntObject, public ISelectionScreenInfo
|
2009-08-27 11:04:32 +03:00
|
|
|
{
|
|
|
|
public:
|
2011-12-22 16:05:19 +03:00
|
|
|
CAdventureMapButton *back;
|
2009-08-27 11:04:32 +03:00
|
|
|
InfoCard *card;
|
|
|
|
OptionsTab *opt;
|
|
|
|
|
2010-03-08 00:56:51 +02:00
|
|
|
CScenarioInfo(const CMapHeader *mapHeader, const StartInfo *startInfo);
|
2009-08-27 11:04:32 +03:00
|
|
|
~CScenarioInfo();
|
|
|
|
};
|
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Multiplayer mode
|
2010-02-15 08:54:57 +02:00
|
|
|
class CMultiMode : public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CPicture *bg;
|
|
|
|
CTextInput *txt;
|
2011-12-22 16:05:19 +03:00
|
|
|
CAdventureMapButton *btns[7]; //0 - hotseat, 6 - cancel
|
2010-02-15 13:37:47 +02:00
|
|
|
CGStatusBar *bar;
|
2010-02-15 08:54:57 +02:00
|
|
|
|
|
|
|
CMultiMode();
|
|
|
|
void openHotseat();
|
2010-09-03 21:42:54 +03:00
|
|
|
void hostTCP();
|
|
|
|
void joinTCP();
|
2010-02-15 08:54:57 +02:00
|
|
|
};
|
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Hot seat player window
|
2010-02-15 08:54:57 +02:00
|
|
|
class CHotSeatPlayers : public CIntObject
|
|
|
|
{
|
|
|
|
CPicture *bg;
|
2011-11-27 21:55:11 +03:00
|
|
|
CTextBox *title;
|
2011-12-14 00:23:17 +03:00
|
|
|
CTextInput* txt[8];
|
2011-12-22 16:05:19 +03:00
|
|
|
CAdventureMapButton *ok, *cancel;
|
2010-02-15 13:37:47 +02:00
|
|
|
CGStatusBar *bar;
|
2010-02-15 08:54:57 +02:00
|
|
|
|
2011-11-27 21:55:11 +03:00
|
|
|
void onChange(std::string newText);
|
2010-02-15 13:37:47 +02:00
|
|
|
void enterSelectionScreen();
|
2011-11-27 21:55:11 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
CHotSeatPlayers(const std::string &firstPlayer);
|
2010-02-15 08:54:57 +02:00
|
|
|
};
|
|
|
|
|
2013-02-19 23:39:09 +03:00
|
|
|
|
2013-08-29 19:41:14 +03:00
|
|
|
class CPrologEpilogVideo : public CWindowObject
|
2013-02-19 23:39:09 +03:00
|
|
|
{
|
|
|
|
CCampaignScenario::SScenarioPrologEpilog spe;
|
2013-08-29 19:41:14 +03:00
|
|
|
int positionCounter;
|
|
|
|
int voiceSoundHandle;
|
2013-02-21 00:01:18 +03:00
|
|
|
std::function<void()> exitCb;
|
2013-08-29 19:41:14 +03:00
|
|
|
|
|
|
|
CMultiLineLabel * text;
|
2013-02-19 23:39:09 +03:00
|
|
|
public:
|
2013-02-21 00:01:18 +03:00
|
|
|
CPrologEpilogVideo(CCampaignScenario::SScenarioPrologEpilog _spe, std::function<void()> callback);
|
2013-02-19 23:39:09 +03:00
|
|
|
|
|
|
|
void clickLeft(tribool down, bool previousState);
|
|
|
|
void show(SDL_Surface * to);
|
|
|
|
};
|
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Campaign screen where you can choose one out of three starting bonuses
|
2010-02-15 14:12:21 +02:00
|
|
|
class CBonusSelection : public CIntObject
|
|
|
|
{
|
2013-12-16 21:39:56 +03:00
|
|
|
public:
|
|
|
|
CBonusSelection(const std::string & campaignFName);
|
|
|
|
CBonusSelection(shared_ptr<CCampaignState> _ourCampaign);
|
|
|
|
~CBonusSelection();
|
2010-02-16 19:28:56 +02:00
|
|
|
|
2013-12-16 21:39:56 +03:00
|
|
|
void showAll(SDL_Surface * to) override;
|
|
|
|
void show(SDL_Surface * to) override;
|
2010-07-29 20:00:34 +03:00
|
|
|
|
2013-12-16 21:39:56 +03:00
|
|
|
private:
|
2010-02-16 19:28:56 +02:00
|
|
|
struct SCampPositions
|
|
|
|
{
|
|
|
|
std::string campPrefix;
|
|
|
|
int colorSuffixLength;
|
|
|
|
|
|
|
|
struct SRegionDesc
|
|
|
|
{
|
|
|
|
std::string infix;
|
|
|
|
int xpos, ypos;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<SRegionDesc> regions;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class CRegion : public CIntObject
|
|
|
|
{
|
|
|
|
CBonusSelection * owner;
|
2011-12-14 00:23:17 +03:00
|
|
|
SDL_Surface* graphics[3]; //[0] - not selected, [1] - selected, [2] - striped
|
2010-02-16 19:28:56 +02:00
|
|
|
bool accessible; //false if region should be striped
|
|
|
|
bool selectable; //true if region should be selectable
|
|
|
|
int myNumber; //number of region
|
2013-12-16 21:39:56 +03:00
|
|
|
|
2010-02-16 19:28:56 +02:00
|
|
|
public:
|
2010-02-18 14:34:44 +02:00
|
|
|
std::string rclickText;
|
2010-02-16 19:28:56 +02:00
|
|
|
CRegion(CBonusSelection * _owner, bool _accessible, bool _selectable, int _myNumber);
|
|
|
|
~CRegion();
|
|
|
|
|
|
|
|
void clickLeft(tribool down, bool previousState);
|
|
|
|
void clickRight(tribool down, bool previousState);
|
|
|
|
void show(SDL_Surface * to);
|
|
|
|
};
|
|
|
|
|
2013-12-16 21:39:56 +03:00
|
|
|
void init();
|
2010-02-16 19:28:56 +02:00
|
|
|
void loadPositionsOfGraphics();
|
2012-09-26 21:10:29 +03:00
|
|
|
void updateStartButtonState(int selected = -1); //-1 -- no bonus is selected
|
2010-02-23 17:39:31 +02:00
|
|
|
void updateBonusSelection();
|
2013-12-16 21:39:56 +03:00
|
|
|
void updateCampaignState();
|
2010-02-23 17:39:31 +02:00
|
|
|
|
2013-12-16 21:39:56 +03:00
|
|
|
// Event handlers
|
|
|
|
void goBack();
|
|
|
|
void startMap();
|
|
|
|
void restartMap();
|
|
|
|
void selectMap(int mapNr, bool initialSelect);
|
2010-07-31 16:55:05 +03:00
|
|
|
void selectBonus(int id);
|
2013-12-16 21:39:56 +03:00
|
|
|
void increaseDifficulty();
|
|
|
|
void decreaseDifficulty();
|
2010-02-18 14:34:44 +02:00
|
|
|
|
2013-12-16 21:39:56 +03:00
|
|
|
// GUI components
|
|
|
|
SDL_Surface * background;
|
|
|
|
CAdventureMapButton * startB, * restartB, * backB;
|
|
|
|
CTextBox * campaignDescription, * mapDescription;
|
|
|
|
std::vector<SCampPositions> campDescriptions;
|
|
|
|
std::vector<CRegion *> regions;
|
|
|
|
CRegion * highlightedRegion;
|
|
|
|
CHighlightableButtonsGroup * bonuses;
|
|
|
|
SDL_Surface * diffPics[5]; //pictures of difficulties, user-selectable (or not if campaign locks this)
|
|
|
|
CAdventureMapButton * diffLb, * diffRb; //buttons for changing difficulty
|
|
|
|
CDefHandler * sizes; //icons of map sizes
|
|
|
|
CDefHandler * sFlags;
|
2010-02-15 14:12:21 +02:00
|
|
|
|
2013-12-16 21:39:56 +03:00
|
|
|
// Data
|
|
|
|
shared_ptr<CCampaignState> ourCampaign;
|
|
|
|
int selectedMap;
|
|
|
|
boost::optional<int> selectedBonus;
|
|
|
|
StartInfo startInfo;
|
|
|
|
CMapHeader * ourHeader;
|
2010-02-15 14:12:21 +02:00
|
|
|
};
|
|
|
|
|
2011-03-15 16:35:36 +02:00
|
|
|
/// Campaign selection screen
|
|
|
|
class CCampaignScreen : public CIntObject
|
|
|
|
{
|
2011-11-27 16:14:20 +03:00
|
|
|
public:
|
|
|
|
enum CampaignStatus {DEFAULT = 0, ENABLED, DISABLED, COMPLETED}; // the status of the campaign
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// A button which plays a video when you move the mouse cursor over it
|
|
|
|
class CCampaignButton : public CIntObject
|
|
|
|
{
|
2011-03-15 16:35:36 +02:00
|
|
|
private:
|
2011-11-27 16:14:20 +03:00
|
|
|
CPicture *image;
|
|
|
|
CPicture *checkMark;
|
2011-03-15 16:35:36 +02:00
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
CLabel *hoverLabel;
|
|
|
|
CampaignStatus status;
|
2011-03-15 16:35:36 +02:00
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
std::string campFile; // the filename/resourcename of the campaign
|
|
|
|
std::string video; // the resource name of the video
|
|
|
|
std::string hoverText;
|
|
|
|
|
|
|
|
void clickLeft(tribool down, bool previousState);
|
|
|
|
void hover(bool on);
|
|
|
|
|
|
|
|
public:
|
|
|
|
CCampaignButton(const JsonNode &config );
|
2011-12-22 16:05:19 +03:00
|
|
|
void show(SDL_Surface * to);
|
2011-11-27 16:14:20 +03:00
|
|
|
};
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
CAdventureMapButton *back;
|
2011-11-27 16:14:20 +03:00
|
|
|
std::vector<CCampaignButton*> campButtons;
|
|
|
|
std::vector<CPicture*> images;
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
CAdventureMapButton* createExitButton(const JsonNode& button);
|
2012-09-26 21:10:29 +03:00
|
|
|
|
2011-03-15 16:35:36 +02:00
|
|
|
public:
|
2011-03-19 16:27:51 +02:00
|
|
|
enum CampaignSet {ROE, AB, SOD, WOG};
|
2011-03-15 16:35:36 +02:00
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
CCampaignScreen(const JsonNode &config);
|
2012-05-18 20:35:46 +03:00
|
|
|
void showAll(SDL_Surface *to);
|
2011-03-15 16:35:36 +02:00
|
|
|
};
|
|
|
|
|
2013-12-17 15:12:25 +03:00
|
|
|
/// Manages the configuration of pregame GUI elements like campaign screen, main menu, loading screen,...
|
|
|
|
class CGPreGameConfig
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static CGPreGameConfig & get();
|
|
|
|
const JsonNode & getConfig() const;
|
2014-02-15 01:46:06 +03:00
|
|
|
const JsonNode & getCampaigns() const;
|
2013-12-17 15:12:25 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
CGPreGameConfig();
|
|
|
|
|
2014-02-15 01:46:06 +03:00
|
|
|
const JsonNode campaignSets;
|
2013-12-17 15:12:25 +03:00
|
|
|
const JsonNode config;
|
|
|
|
};
|
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Handles background screen, loads graphics for victory/loss condition and random town or hero selection
|
2009-12-28 06:08:24 +02:00
|
|
|
class CGPreGame : public CIntObject, public IUpdateable
|
2009-04-16 14:14:13 +03:00
|
|
|
{
|
2012-05-18 20:35:46 +03:00
|
|
|
void loadGraphics();
|
|
|
|
void disposeGraphics();
|
|
|
|
|
|
|
|
CGPreGame(); //Use createIfNotPresent
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
public:
|
2013-12-17 15:12:25 +03:00
|
|
|
CMenuScreen * menu;
|
2009-08-17 11:50:31 +03:00
|
|
|
|
|
|
|
CDefHandler *victory, *loss;
|
|
|
|
|
|
|
|
~CGPreGame();
|
2009-12-28 06:08:24 +02:00
|
|
|
void update();
|
2010-09-03 21:42:54 +03:00
|
|
|
void openSel(CMenuScreen::EState type, CMenuScreen::EMultiMode multi = CMenuScreen::SINGLE_PLAYER);
|
2010-08-20 16:34:39 +03:00
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
void openCampaignScreen(std::string name);
|
2012-03-11 19:29:01 +03:00
|
|
|
|
2012-05-18 20:35:46 +03:00
|
|
|
static CGPreGame * create();
|
2012-05-26 20:59:00 +03:00
|
|
|
void removeFromGui();
|
2013-06-26 14:18:27 +03:00
|
|
|
static void showLoadingScreen(std::function<void()> loader);
|
2012-12-17 21:01:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class CLoadingScreen : public CWindowObject
|
|
|
|
{
|
|
|
|
boost::thread loadingThread;
|
|
|
|
|
|
|
|
std::string getBackground();
|
|
|
|
public:
|
2013-06-26 14:18:27 +03:00
|
|
|
CLoadingScreen(std::function<void()> loader);
|
2012-12-18 13:32:11 +03:00
|
|
|
~CLoadingScreen();
|
2012-12-17 21:01:17 +03:00
|
|
|
|
|
|
|
void showAll(SDL_Surface *to);
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
|
|
|
|
2013-06-02 22:53:13 +03:00
|
|
|
/// Simple window to enter the server's address.
|
|
|
|
class CSimpleJoinScreen : public CIntObject
|
|
|
|
{
|
|
|
|
CPicture * bg;
|
|
|
|
CTextBox * title;
|
|
|
|
CAdventureMapButton * ok, * cancel;
|
|
|
|
CGStatusBar * bar;
|
|
|
|
CTextInput * address;
|
|
|
|
CTextInput * port;
|
|
|
|
|
|
|
|
void enterSelectionScreen();
|
|
|
|
void onChange(const std::string & newText);
|
|
|
|
public:
|
|
|
|
CSimpleJoinScreen();
|
|
|
|
};
|
|
|
|
|
2012-01-03 04:55:26 +03:00
|
|
|
extern ISelectionScreenInfo *SEL;
|
2009-08-17 11:50:31 +03:00
|
|
|
extern CGPreGame *CGP;
|