mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-13 01:20:34 +02:00
Merge branch 'develop' into main_menu_1.7
This commit is contained in:
@ -21,7 +21,9 @@
|
||||
#include "../media/IVideoPlayer.h"
|
||||
#include "../gui/CursorHandler.h"
|
||||
#include "../windows/GUIClasses.h"
|
||||
#include "../gui/CGuiHandler.h"
|
||||
#include "../GameEngine.h"
|
||||
#include "../GameInstance.h"
|
||||
#include "../eventsSDL/InputHandler.h"
|
||||
#include "../gui/ShortcutHandler.h"
|
||||
#include "../gui/Shortcut.h"
|
||||
#include "../gui/WindowHandler.h"
|
||||
@ -38,9 +40,7 @@
|
||||
#include "../widgets/VideoWidget.h"
|
||||
#include "../windows/InfoWindows.h"
|
||||
#include "../CServerHandler.h"
|
||||
#include "../render/AssetGenerator.h"
|
||||
|
||||
#include "../CGameInfo.h"
|
||||
#include "../CPlayerInterface.h"
|
||||
#include "../Client.h"
|
||||
#include "../CMT.h"
|
||||
@ -59,13 +59,13 @@
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
#include "../../lib/GameConstants.h"
|
||||
#include "../../lib/CRandomGenerator.h"
|
||||
#include "../../lib/GameLibrary.h"
|
||||
|
||||
std::shared_ptr<CMainMenu> CMM;
|
||||
ISelectionScreenInfo * SEL = nullptr;
|
||||
|
||||
static void do_quit()
|
||||
{
|
||||
GH.dispatchMainThread([]()
|
||||
ENGINE->dispatchMainThread([]()
|
||||
{
|
||||
handleQuit(false);
|
||||
});
|
||||
@ -84,7 +84,7 @@ CMenuScreen::CMenuScreen(const JsonNode & configNode)
|
||||
background = std::make_shared<CPicture>(ImagePath::fromJson(bgConfig));
|
||||
|
||||
if(config["scalable"].Bool())
|
||||
background->scaleTo(GH.screenDimensions());
|
||||
background->scaleTo(ENGINE->screenDimensions());
|
||||
|
||||
pos = background->center();
|
||||
|
||||
@ -173,7 +173,7 @@ static std::function<void()> genCommand(CMenuScreen * menu, std::vector<std::str
|
||||
}
|
||||
case 1: //open campaign selection window
|
||||
{
|
||||
return std::bind(&CMainMenu::openCampaignScreen, CMM, commands.front());
|
||||
return std::bind(&CMainMenu::openCampaignScreen, GAME->mainmenu(), commands.front());
|
||||
break;
|
||||
}
|
||||
case 2: //start
|
||||
@ -183,7 +183,7 @@ static std::function<void()> genCommand(CMenuScreen * menu, std::vector<std::str
|
||||
case 0:
|
||||
return []() { CMainMenu::openLobby(ESelectionScreen::newGame, true, {}, ELoadMode::NONE); };
|
||||
case 1:
|
||||
return []() { GH.windows().createAndPushWindow<CMultiMode>(ESelectionScreen::newGame); };
|
||||
return []() { ENGINE->windows().createAndPushWindow<CMultiMode>(ESelectionScreen::newGame); };
|
||||
case 2:
|
||||
return []() { CMainMenu::openLobby(ESelectionScreen::campaignList, true, {}, ELoadMode::NONE); };
|
||||
case 3:
|
||||
@ -198,7 +198,7 @@ static std::function<void()> genCommand(CMenuScreen * menu, std::vector<std::str
|
||||
case 0:
|
||||
return []() { CMainMenu::openLobby(ESelectionScreen::loadGame, true, {}, ELoadMode::SINGLE); };
|
||||
case 1:
|
||||
return []() { GH.windows().createAndPushWindow<CMultiMode>(ESelectionScreen::loadGame); };
|
||||
return []() { ENGINE->windows().createAndPushWindow<CMultiMode>(ESelectionScreen::loadGame); };
|
||||
case 2:
|
||||
return []() { CMainMenu::openLobby(ESelectionScreen::loadGame, true, {}, ELoadMode::CAMPAIGN); };
|
||||
case 3:
|
||||
@ -209,7 +209,7 @@ static std::function<void()> genCommand(CMenuScreen * menu, std::vector<std::str
|
||||
break;
|
||||
case 4: //exit
|
||||
{
|
||||
return []() { CInfoWindow::showYesNoDialog(CGI->generaltexth->allTexts[69], std::vector<std::shared_ptr<CComponent>>(), do_quit, 0, PlayerColor(1)); };
|
||||
return []() { CInfoWindow::showYesNoDialog(LIBRARY->generaltexth->allTexts[69], std::vector<std::shared_ptr<CComponent>>(), do_quit, 0, PlayerColor(1)); };
|
||||
}
|
||||
break;
|
||||
case 5: //highscores
|
||||
@ -229,7 +229,7 @@ std::shared_ptr<CButton> CMenuEntry::createButton(CMenuScreen * parent, const Js
|
||||
|
||||
std::pair<std::string, std::string> help;
|
||||
if(!button["help"].isNull() && button["help"].Float() > 0)
|
||||
help = CGI->generaltexth->zelp[(size_t)button["help"].Float()];
|
||||
help = LIBRARY->generaltexth->zelp[(size_t)button["help"].Float()];
|
||||
|
||||
int posx = static_cast<int>(button["x"].Float());
|
||||
if(posx < 0)
|
||||
@ -239,7 +239,7 @@ std::shared_ptr<CButton> CMenuEntry::createButton(CMenuScreen * parent, const Js
|
||||
if(posy < 0)
|
||||
posy = pos.h + posy;
|
||||
|
||||
EShortcut shortcut = GH.shortcuts().findShortcut(button["shortcut"].String());
|
||||
EShortcut shortcut = ENGINE->shortcuts().findShortcut(button["shortcut"].String());
|
||||
|
||||
if (shortcut == EShortcut::NONE && !button["shortcut"].String().empty())
|
||||
logGlobal->warn("Unknown shortcut '%s' found when loading main menu config!", button["shortcut"].String());
|
||||
@ -332,25 +332,21 @@ const JsonNode & CMainMenuConfig::getCampaigns() const
|
||||
|
||||
CMainMenu::CMainMenu()
|
||||
{
|
||||
pos.w = GH.screenDimensions().x;
|
||||
pos.h = GH.screenDimensions().y;
|
||||
pos.w = ENGINE->screenDimensions().x;
|
||||
pos.h = ENGINE->screenDimensions().y;
|
||||
|
||||
menu = std::make_shared<CMenuScreen>(CMainMenuConfig::get().getConfig()["window"]);
|
||||
OBJECT_CONSTRUCTION;
|
||||
backgroundAroundMenu = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), pos);
|
||||
}
|
||||
|
||||
CMainMenu::~CMainMenu()
|
||||
{
|
||||
if(GH.curInt == this)
|
||||
GH.curInt = nullptr;
|
||||
}
|
||||
CMainMenu::~CMainMenu() = default;
|
||||
|
||||
void CMainMenu::playIntroVideos()
|
||||
{
|
||||
auto playVideo = [](std::string video, bool rim, float scaleFactor, std::function<void(bool)> cb){
|
||||
if(CCS->videoh->open(VideoPath::builtin(video), scaleFactor))
|
||||
GH.windows().createAndPushWindow<VideoWindow>(VideoPath::builtin(video), rim ? ImagePath::builtin("INTRORIM") : ImagePath::builtin(""), true, scaleFactor, [cb](bool skipped){ cb(skipped); });
|
||||
if(ENGINE->video().open(VideoPath::builtin(video), scaleFactor))
|
||||
ENGINE->windows().createAndPushWindow<VideoWindow>(VideoPath::builtin(video), rim ? ImagePath::builtin("INTRORIM") : ImagePath::builtin(""), true, scaleFactor, [cb](bool skipped){ cb(skipped); });
|
||||
else
|
||||
cb(true);
|
||||
};
|
||||
@ -372,13 +368,13 @@ void CMainMenu::playIntroVideos()
|
||||
|
||||
void CMainMenu::playMusic()
|
||||
{
|
||||
CCS->musich->playMusic(AudioPath::builtin("Music/MainMenu"), true, true);
|
||||
ENGINE->music().playMusic(AudioPath::builtin("Music/MainMenu"), true, true);
|
||||
}
|
||||
|
||||
void CMainMenu::activate()
|
||||
{
|
||||
// check if screen was resized while main menu was inactive - e.g. in gameplay mode
|
||||
if (pos.dimensions() != GH.screenDimensions())
|
||||
if (pos.dimensions() != ENGINE->screenDimensions())
|
||||
onScreenResize();
|
||||
|
||||
CIntObject::activate();
|
||||
@ -386,8 +382,8 @@ void CMainMenu::activate()
|
||||
|
||||
void CMainMenu::onScreenResize()
|
||||
{
|
||||
pos.w = GH.screenDimensions().x;
|
||||
pos.h = GH.screenDimensions().y;
|
||||
pos.w = ENGINE->screenDimensions().x;
|
||||
pos.h = ENGINE->screenDimensions().y;
|
||||
|
||||
menu = nullptr;
|
||||
menu = std::make_shared<CMenuScreen>(CMainMenuConfig::get().getConfig()["window"]);
|
||||
@ -395,29 +391,19 @@ void CMainMenu::onScreenResize()
|
||||
backgroundAroundMenu->pos = pos;
|
||||
}
|
||||
|
||||
void CMainMenu::update()
|
||||
void CMainMenu::makeActiveInterface()
|
||||
{
|
||||
if(CMM != this->shared_from_this()) //don't update if you are not a main interface
|
||||
return;
|
||||
|
||||
if(GH.windows().count() == 0)
|
||||
{
|
||||
GH.windows().pushWindow(CMM);
|
||||
GH.windows().pushWindow(menu);
|
||||
menu->switchToTab(menu->getActiveTab());
|
||||
}
|
||||
|
||||
// Handles mouse and key input
|
||||
GH.handleEvents();
|
||||
GH.windows().simpleRedraw();
|
||||
ENGINE->windows().pushWindow(GAME->mainmenu());
|
||||
ENGINE->windows().pushWindow(menu);
|
||||
menu->switchToTab(menu->getActiveTab());
|
||||
}
|
||||
|
||||
void CMainMenu::openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> & names, ELoadMode loadMode)
|
||||
{
|
||||
CSH->resetStateForLobby(screenType == ESelectionScreen::newGame ? EStartMode::NEW_GAME : EStartMode::LOAD_GAME, screenType, EServerMode::LOCAL, names);
|
||||
CSH->loadMode = loadMode;
|
||||
GAME->server().resetStateForLobby(screenType == ESelectionScreen::newGame ? EStartMode::NEW_GAME : EStartMode::LOAD_GAME, screenType, EServerMode::LOCAL, names);
|
||||
GAME->server().loadMode = loadMode;
|
||||
|
||||
GH.windows().createAndPushWindow<CSimpleJoinScreen>(host);
|
||||
ENGINE->windows().createAndPushWindow<CSimpleJoinScreen>(host);
|
||||
}
|
||||
|
||||
void CMainMenu::openCampaignLobby(const std::string & campaignFileName, std::string campaignSet)
|
||||
@ -429,18 +415,15 @@ void CMainMenu::openCampaignLobby(const std::string & campaignFileName, std::str
|
||||
|
||||
void CMainMenu::openCampaignLobby(std::shared_ptr<CampaignState> campaign)
|
||||
{
|
||||
CSH->resetStateForLobby(EStartMode::CAMPAIGN, ESelectionScreen::campaignList, EServerMode::LOCAL, {});
|
||||
CSH->campaignStateToSend = campaign;
|
||||
GH.windows().createAndPushWindow<CSimpleJoinScreen>();
|
||||
GAME->server().resetStateForLobby(EStartMode::CAMPAIGN, ESelectionScreen::campaignList, EServerMode::LOCAL, {});
|
||||
GAME->server().campaignStateToSend = campaign;
|
||||
ENGINE->windows().createAndPushWindow<CSimpleJoinScreen>();
|
||||
}
|
||||
|
||||
void CMainMenu::openCampaignScreen(std::string name)
|
||||
{
|
||||
auto const & config = CMainMenuConfig::get().getCampaigns();
|
||||
|
||||
AssetGenerator::createCampaignBackground();
|
||||
AssetGenerator::createChroniclesCampaignImages();
|
||||
|
||||
if(!vstd::contains(config.Struct(), name))
|
||||
{
|
||||
logGlobal->error("Unknown campaign set: %s", name);
|
||||
@ -459,11 +442,11 @@ void CMainMenu::openCampaignScreen(std::string name)
|
||||
|
||||
if (!campaignsFound)
|
||||
{
|
||||
CInfoWindow::showInfoDialog(CGI->generaltexth->translate("vcmi.client.errors.missingCampaigns"), std::vector<std::shared_ptr<CComponent>>(), PlayerColor(1));
|
||||
CInfoWindow::showInfoDialog(LIBRARY->generaltexth->translate("vcmi.client.errors.missingCampaigns"), std::vector<std::shared_ptr<CComponent>>(), PlayerColor(1));
|
||||
return;
|
||||
}
|
||||
|
||||
GH.windows().createAndPushWindow<CCampaignScreen>(config, name);
|
||||
ENGINE->windows().createAndPushWindow<CCampaignScreen>(config, name);
|
||||
}
|
||||
|
||||
void CMainMenu::startTutorial()
|
||||
@ -471,30 +454,22 @@ void CMainMenu::startTutorial()
|
||||
ResourcePath tutorialMap("Maps/Tutorial.tut", EResType::MAP);
|
||||
if(!CResourceHandler::get()->existsResource(tutorialMap))
|
||||
{
|
||||
CInfoWindow::showInfoDialog(CGI->generaltexth->translate("core.genrltxt.742"), std::vector<std::shared_ptr<CComponent>>(), PlayerColor(1));
|
||||
CInfoWindow::showInfoDialog(LIBRARY->generaltexth->translate("core.genrltxt.742"), std::vector<std::shared_ptr<CComponent>>(), PlayerColor(1));
|
||||
return;
|
||||
}
|
||||
|
||||
auto mapInfo = std::make_shared<CMapInfo>();
|
||||
mapInfo->mapInit(tutorialMap.getName());
|
||||
CMainMenu::openLobby(ESelectionScreen::newGame, true, {}, ELoadMode::NONE);
|
||||
CSH->startMapAfterConnection(mapInfo);
|
||||
GAME->server().startMapAfterConnection(mapInfo);
|
||||
}
|
||||
|
||||
void CMainMenu::openHighScoreScreen()
|
||||
{
|
||||
GH.windows().createAndPushWindow<CHighScoreScreen>(CHighScoreScreen::HighScorePage::SCENARIO);
|
||||
ENGINE->windows().createAndPushWindow<CHighScoreScreen>(CHighScoreScreen::HighScorePage::SCENARIO);
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<CMainMenu> CMainMenu::create()
|
||||
{
|
||||
if(!CMM)
|
||||
CMM = std::shared_ptr<CMainMenu>(new CMainMenu());
|
||||
|
||||
return CMM;
|
||||
}
|
||||
|
||||
std::shared_ptr<CPicture> CMainMenu::createPicture(const JsonNode & config)
|
||||
{
|
||||
return std::make_shared<CPicture>(ImagePath::fromJson(config["name"]), (int)config["x"].Float(), (int)config["y"].Float());
|
||||
@ -513,40 +488,40 @@ CMultiMode::CMultiMode(ESelectionScreen ScreenType)
|
||||
picture = std::make_shared<CPicture>(ImagePath::fromJson(*RandomGeneratorUtil::nextItem(multiplayerConfig.Vector(), CRandomGenerator::getDefault())), 16, 77);
|
||||
|
||||
textTitle = std::make_shared<CTextBox>("", Rect(7, 18, 440, 50), 0, FONT_BIG, ETextAlignment::CENTER, Colors::WHITE);
|
||||
textTitle->setText(CGI->generaltexth->zelp[263].second);
|
||||
textTitle->setText(LIBRARY->generaltexth->zelp[263].second);
|
||||
|
||||
statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(7, 465, 440, 18), 7, 465));
|
||||
playerName = std::make_shared<CTextInput>(Rect(19, 436, 334, 16), background->getSurface());
|
||||
playerName->setText(getPlayersNames()[0]);
|
||||
playerName->setCallback(std::bind(&CMultiMode::onNameChange, this, _1));
|
||||
|
||||
buttonHotseat = std::make_shared<CButton>(Point(373, 78 + 57 * 0), AnimationPath::builtin("MUBHOT.DEF"), CGI->generaltexth->zelp[266], std::bind(&CMultiMode::hostTCP, this, EShortcut::MAIN_MENU_HOTSEAT), EShortcut::MAIN_MENU_HOTSEAT);
|
||||
buttonLobby = std::make_shared<CButton>(Point(373, 78 + 57 * 1), AnimationPath::builtin("MUBONL.DEF"), CGI->generaltexth->zelp[265], std::bind(&CMultiMode::openLobby, this), EShortcut::MAIN_MENU_LOBBY);
|
||||
buttonHotseat = std::make_shared<CButton>(Point(373, 78 + 57 * 0), AnimationPath::builtin("MUBHOT.DEF"), LIBRARY->generaltexth->zelp[266], std::bind(&CMultiMode::hostTCP, this, EShortcut::MAIN_MENU_HOTSEAT), EShortcut::MAIN_MENU_HOTSEAT);
|
||||
buttonLobby = std::make_shared<CButton>(Point(373, 78 + 57 * 1), AnimationPath::builtin("MUBONL.DEF"), LIBRARY->generaltexth->zelp[265], std::bind(&CMultiMode::openLobby, this), EShortcut::MAIN_MENU_LOBBY);
|
||||
|
||||
buttonHost = std::make_shared<CButton>(Point(373, 78 + 57 * 3), AnimationPath::builtin("MUBHOST.DEF"), CButton::tooltip(CGI->generaltexth->translate("vcmi.mainMenu.hostTCP"), ""), std::bind(&CMultiMode::hostTCP, this, EShortcut::MAIN_MENU_HOST_GAME), EShortcut::MAIN_MENU_HOST_GAME);
|
||||
buttonJoin = std::make_shared<CButton>(Point(373, 78 + 57 * 4), AnimationPath::builtin("MUBJOIN.DEF"), CButton::tooltip(CGI->generaltexth->translate("vcmi.mainMenu.joinTCP"), ""), std::bind(&CMultiMode::joinTCP, this, EShortcut::MAIN_MENU_JOIN_GAME), EShortcut::MAIN_MENU_JOIN_GAME);
|
||||
buttonHost = std::make_shared<CButton>(Point(373, 78 + 57 * 3), AnimationPath::builtin("MUBHOST.DEF"), CButton::tooltip(LIBRARY->generaltexth->translate("vcmi.mainMenu.hostTCP"), ""), std::bind(&CMultiMode::hostTCP, this, EShortcut::MAIN_MENU_HOST_GAME), EShortcut::MAIN_MENU_HOST_GAME);
|
||||
buttonJoin = std::make_shared<CButton>(Point(373, 78 + 57 * 4), AnimationPath::builtin("MUBJOIN.DEF"), CButton::tooltip(LIBRARY->generaltexth->translate("vcmi.mainMenu.joinTCP"), ""), std::bind(&CMultiMode::joinTCP, this, EShortcut::MAIN_MENU_JOIN_GAME), EShortcut::MAIN_MENU_JOIN_GAME);
|
||||
|
||||
buttonCancel = std::make_shared<CButton>(Point(373, 424), AnimationPath::builtin("MUBCANC.DEF"), CGI->generaltexth->zelp[288], [=](){ close();}, EShortcut::GLOBAL_CANCEL);
|
||||
buttonCancel = std::make_shared<CButton>(Point(373, 424), AnimationPath::builtin("MUBCANC.DEF"), LIBRARY->generaltexth->zelp[288], [this](){ close();}, EShortcut::GLOBAL_CANCEL);
|
||||
}
|
||||
|
||||
void CMultiMode::openLobby()
|
||||
{
|
||||
close();
|
||||
CSH->getGlobalLobby().activateInterface();
|
||||
GAME->server().getGlobalLobby().activateInterface();
|
||||
}
|
||||
|
||||
void CMultiMode::hostTCP(EShortcut shortcut)
|
||||
{
|
||||
auto savedScreenType = screenType;
|
||||
close();
|
||||
GH.windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, true, ELoadMode::MULTI, shortcut);
|
||||
ENGINE->windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, true, ELoadMode::MULTI, shortcut);
|
||||
}
|
||||
|
||||
void CMultiMode::joinTCP(EShortcut shortcut)
|
||||
{
|
||||
auto savedScreenType = screenType;
|
||||
close();
|
||||
GH.windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, false, ELoadMode::MULTI, shortcut);
|
||||
ENGINE->windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, false, ELoadMode::MULTI, shortcut);
|
||||
}
|
||||
|
||||
std::vector<std::string> CMultiMode::getPlayersNames()
|
||||
@ -555,7 +530,7 @@ std::vector<std::string> CMultiMode::getPlayersNames()
|
||||
|
||||
std::string playerNameStr = settings["general"]["playerName"].String();
|
||||
if (playerNameStr == "Player")
|
||||
playerNameStr = CGI->generaltexth->translate("core.genrltxt.434");
|
||||
playerNameStr = LIBRARY->generaltexth->translate("core.genrltxt.434");
|
||||
playerNames.push_back(playerNameStr);
|
||||
|
||||
for (const auto & playerName : settings["general"]["multiPlayerNames"].Vector())
|
||||
@ -587,14 +562,14 @@ CMultiPlayers::CMultiPlayers(const std::vector<std::string>& playerNames, ESelec
|
||||
switch (shortcut)
|
||||
{
|
||||
case EShortcut::MAIN_MENU_HOTSEAT:
|
||||
text = CGI->generaltexth->allTexts[446];
|
||||
text = LIBRARY->generaltexth->allTexts[446];
|
||||
boost::replace_all(text, "\t", "\n");
|
||||
break;
|
||||
case EShortcut::MAIN_MENU_HOST_GAME:
|
||||
text = CGI->generaltexth->translate("vcmi.mainMenu.hostTCP");
|
||||
text = LIBRARY->generaltexth->translate("vcmi.mainMenu.hostTCP");
|
||||
break;
|
||||
case EShortcut::MAIN_MENU_JOIN_GAME:
|
||||
text = CGI->generaltexth->translate("vcmi.mainMenu.joinTCP");
|
||||
text = LIBRARY->generaltexth->translate("vcmi.mainMenu.joinTCP");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -606,8 +581,8 @@ CMultiPlayers::CMultiPlayers(const std::vector<std::string>& playerNames, ESelec
|
||||
inputNames[i]->setCallback(std::bind(&CMultiPlayers::onChange, this, _1));
|
||||
}
|
||||
|
||||
buttonOk = std::make_shared<CButton>(Point(95, 338), AnimationPath::builtin("MUBCHCK.DEF"), CGI->generaltexth->zelp[560], std::bind(&CMultiPlayers::enterSelectionScreen, this), EShortcut::GLOBAL_ACCEPT);
|
||||
buttonCancel = std::make_shared<CButton>(Point(205, 338), AnimationPath::builtin("MUBCANC.DEF"), CGI->generaltexth->zelp[561], [=](){ close();}, EShortcut::GLOBAL_CANCEL);
|
||||
buttonOk = std::make_shared<CButton>(Point(95, 338), AnimationPath::builtin("MUBCHCK.DEF"), LIBRARY->generaltexth->zelp[560], std::bind(&CMultiPlayers::enterSelectionScreen, this), EShortcut::GLOBAL_ACCEPT);
|
||||
buttonCancel = std::make_shared<CButton>(Point(205, 338), AnimationPath::builtin("MUBCANC.DEF"), LIBRARY->generaltexth->zelp[561], [this](){ close();}, EShortcut::GLOBAL_CANCEL);
|
||||
statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(7, 381, 348, 18), 7, 381));
|
||||
|
||||
for(int i = 0; i < playerNames.size(); i++)
|
||||
@ -664,42 +639,42 @@ CSimpleJoinScreen::CSimpleJoinScreen(bool host)
|
||||
textTitle = std::make_shared<CTextBox>("", Rect(20, 10, 205, 50), 0, FONT_BIG, ETextAlignment::CENTER, Colors::WHITE);
|
||||
inputAddress = std::make_shared<CTextInput>(Rect(25, 68, 175, 16), background->getSurface());
|
||||
inputPort = std::make_shared<CTextInput>(Rect(25, 115, 175, 16), background->getSurface());
|
||||
buttonOk = std::make_shared<CButton>(Point(26, 142), AnimationPath::builtin("MUBCHCK.DEF"), CGI->generaltexth->zelp[560], std::bind(&CSimpleJoinScreen::connectToServer, this), EShortcut::GLOBAL_ACCEPT);
|
||||
buttonOk = std::make_shared<CButton>(Point(26, 142), AnimationPath::builtin("MUBCHCK.DEF"), LIBRARY->generaltexth->zelp[560], std::bind(&CSimpleJoinScreen::connectToServer, this), EShortcut::GLOBAL_ACCEPT);
|
||||
if(host && !settings["session"]["donotstartserver"].Bool())
|
||||
{
|
||||
textTitle->setText(CGI->generaltexth->translate("vcmi.mainMenu.serverConnecting"));
|
||||
textTitle->setText(LIBRARY->generaltexth->translate("vcmi.mainMenu.serverConnecting"));
|
||||
buttonOk->block(true);
|
||||
startConnection();
|
||||
}
|
||||
else
|
||||
{
|
||||
textTitle->setText(CGI->generaltexth->translate("vcmi.mainMenu.serverAddressEnter"));
|
||||
textTitle->setText(LIBRARY->generaltexth->translate("vcmi.mainMenu.serverAddressEnter"));
|
||||
inputAddress->setCallback(std::bind(&CSimpleJoinScreen::onChange, this, _1));
|
||||
inputPort->setCallback(std::bind(&CSimpleJoinScreen::onChange, this, _1));
|
||||
inputPort->setFilterNumber(0, 65535);
|
||||
inputAddress->giveFocus();
|
||||
}
|
||||
inputAddress->setText(host ? CSH->getLocalHostname() : CSH->getRemoteHostname());
|
||||
inputPort->setText(std::to_string(host ? CSH->getLocalPort() : CSH->getRemotePort()));
|
||||
inputAddress->setText(host ? GAME->server().getLocalHostname() : GAME->server().getRemoteHostname());
|
||||
inputPort->setText(std::to_string(host ? GAME->server().getLocalPort() : GAME->server().getRemotePort()));
|
||||
buttonOk->block(inputAddress->getText().empty() || inputPort->getText().empty());
|
||||
|
||||
buttonCancel = std::make_shared<CButton>(Point(142, 142), AnimationPath::builtin("MUBCANC.DEF"), CGI->generaltexth->zelp[561], std::bind(&CSimpleJoinScreen::leaveScreen, this), EShortcut::GLOBAL_CANCEL);
|
||||
buttonCancel = std::make_shared<CButton>(Point(142, 142), AnimationPath::builtin("MUBCANC.DEF"), LIBRARY->generaltexth->zelp[561], std::bind(&CSimpleJoinScreen::leaveScreen, this), EShortcut::GLOBAL_CANCEL);
|
||||
statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(7, 186, 218, 18), 7, 186));
|
||||
}
|
||||
|
||||
void CSimpleJoinScreen::connectToServer()
|
||||
{
|
||||
textTitle->setText(CGI->generaltexth->translate("vcmi.mainMenu.serverConnecting"));
|
||||
textTitle->setText(LIBRARY->generaltexth->translate("vcmi.mainMenu.serverConnecting"));
|
||||
buttonOk->block(true);
|
||||
GH.stopTextInput();
|
||||
ENGINE->input().stopTextInput();
|
||||
|
||||
startConnection(inputAddress->getText(), boost::lexical_cast<ui16>(inputPort->getText()));
|
||||
}
|
||||
|
||||
void CSimpleJoinScreen::leaveScreen()
|
||||
{
|
||||
textTitle->setText(CGI->generaltexth->translate("vcmi.mainMenu.serverClosing"));
|
||||
CSH->setState(EClientState::CONNECTION_CANCELLED);
|
||||
textTitle->setText(LIBRARY->generaltexth->translate("vcmi.mainMenu.serverClosing"));
|
||||
GAME->server().setState(EClientState::CONNECTION_CANCELLED);
|
||||
}
|
||||
|
||||
void CSimpleJoinScreen::onChange(const std::string & newText)
|
||||
@ -710,9 +685,9 @@ void CSimpleJoinScreen::onChange(const std::string & newText)
|
||||
void CSimpleJoinScreen::startConnection(const std::string & addr, ui16 port)
|
||||
{
|
||||
if(addr.empty())
|
||||
CSH->startLocalServerAndConnect(false);
|
||||
GAME->server().startLocalServerAndConnect(false);
|
||||
else
|
||||
CSH->connectToServer(addr, port);
|
||||
GAME->server().connectToServer(addr, port);
|
||||
}
|
||||
|
||||
CLoadingScreen::CLoadingScreen()
|
||||
@ -727,7 +702,7 @@ CLoadingScreen::CLoadingScreen(ImagePath background)
|
||||
|
||||
addUsedEvents(TIME);
|
||||
|
||||
CCS->musich->stopMusic(5000);
|
||||
ENGINE->music().stopMusic(5000);
|
||||
|
||||
const auto& conf = CMainMenuConfig::get().getConfig()["loading"];
|
||||
|
||||
|
Reference in New Issue
Block a user