2023-12-28 21:27:21 +02:00
|
|
|
/*
|
|
|
|
* GlobalLobbyLoginWindow.cpp, 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "GlobalLobbyLoginWindow.h"
|
|
|
|
|
|
|
|
#include "GlobalLobbyClient.h"
|
|
|
|
#include "GlobalLobbyWindow.h"
|
|
|
|
|
2024-01-11 22:51:36 +02:00
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CServerHandler.h"
|
2023-12-28 21:27:21 +02:00
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../gui/WindowHandler.h"
|
|
|
|
#include "../widgets/Buttons.h"
|
2024-01-11 22:51:36 +02:00
|
|
|
#include "../widgets/Images.h"
|
2023-12-28 21:27:21 +02:00
|
|
|
#include "../widgets/MiscWidgets.h"
|
2024-01-11 22:51:36 +02:00
|
|
|
#include "../widgets/TextControls.h"
|
2023-12-28 21:27:21 +02:00
|
|
|
|
2024-01-11 22:51:36 +02:00
|
|
|
#include "../../lib/CConfigHandler.h"
|
2023-12-28 21:27:21 +02:00
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/MetaString.h"
|
|
|
|
|
|
|
|
GlobalLobbyLoginWindow::GlobalLobbyLoginWindow()
|
|
|
|
: CWindowObject(BORDERED)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
|
|
|
|
pos.w = 200;
|
|
|
|
pos.h = 200;
|
|
|
|
|
2024-02-02 02:36:57 +02:00
|
|
|
filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
|
2023-12-28 21:27:21 +02:00
|
|
|
labelTitle = std::make_shared<CLabel>( pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.login.title"));
|
|
|
|
labelUsername = std::make_shared<CLabel>( 10, 45, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->translate("vcmi.lobby.login.username"));
|
|
|
|
backgroundUsername = std::make_shared<TransparentFilledRectangle>(Rect(10, 70, 180, 20), ColorRGBA(0,0,0,128), ColorRGBA(64,64,64,64));
|
|
|
|
inputUsername = std::make_shared<CTextInput>(Rect(15, 73, 176, 16), FONT_SMALL, nullptr, ETextAlignment::TOPLEFT, true);
|
|
|
|
buttonLogin = std::make_shared<CButton>(Point(10, 160), AnimationPath::builtin("MuBchck"), CButton::tooltip(), [this](){ onLogin(); });
|
|
|
|
buttonClose = std::make_shared<CButton>(Point(126, 160), AnimationPath::builtin("MuBcanc"), CButton::tooltip(), [this](){ onClose(); });
|
2024-01-08 20:50:43 +02:00
|
|
|
labelStatus = std::make_shared<CTextBox>( "", Rect(15, 95, 175, 60), 1, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE);
|
2023-12-28 21:27:21 +02:00
|
|
|
|
2024-02-02 02:36:57 +02:00
|
|
|
filledBackground->playerColored(PlayerColor(1));
|
2024-01-08 20:50:43 +02:00
|
|
|
inputUsername->setText(settings["lobby"]["displayName"].String());
|
|
|
|
inputUsername->cb += [this](const std::string & text)
|
|
|
|
{
|
|
|
|
buttonLogin->block(text.empty());
|
|
|
|
};
|
2023-12-28 21:27:21 +02:00
|
|
|
|
|
|
|
center();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalLobbyLoginWindow::onClose()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
// TODO: abort ongoing connection attempt, if any
|
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalLobbyLoginWindow::onLogin()
|
|
|
|
{
|
2024-01-08 20:50:43 +02:00
|
|
|
Settings config = settings.write["lobby"]["displayName"];
|
|
|
|
config->String() = inputUsername->getText();
|
|
|
|
|
2023-12-28 21:27:21 +02:00
|
|
|
labelStatus->setText(CGI->generaltexth->translate("vcmi.lobby.login.connecting"));
|
2024-01-11 22:51:36 +02:00
|
|
|
if(!CSH->getGlobalLobby().isConnected())
|
2024-01-10 15:31:11 +02:00
|
|
|
CSH->getGlobalLobby().connect();
|
2024-01-08 20:50:43 +02:00
|
|
|
buttonClose->block(true);
|
2023-12-28 21:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalLobbyLoginWindow::onConnectionSuccess()
|
|
|
|
{
|
|
|
|
close();
|
2024-01-21 16:48:36 +02:00
|
|
|
CSH->getGlobalLobby().activateInterface();
|
2023-12-28 21:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalLobbyLoginWindow::onConnectionFailed(const std::string & reason)
|
|
|
|
{
|
|
|
|
MetaString formatter;
|
|
|
|
formatter.appendTextID("vcmi.lobby.login.error");
|
|
|
|
formatter.replaceRawString(reason);
|
|
|
|
|
|
|
|
labelStatus->setText(formatter.toString());
|
2024-01-08 20:50:43 +02:00
|
|
|
buttonClose->block(false);
|
2023-12-28 21:27:21 +02:00
|
|
|
}
|