mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
Multiplayer menu improvements
This commit is contained in:
@@ -469,18 +469,26 @@ CMultiMode::CMultiMode(ESelectionScreen ScreenType)
|
|||||||
background = std::make_shared<CPicture>(ImagePath::builtin("MUPOPUP.bmp"));
|
background = std::make_shared<CPicture>(ImagePath::builtin("MUPOPUP.bmp"));
|
||||||
pos = background->center(); //center, window has size of bg graphic
|
pos = background->center(); //center, window has size of bg graphic
|
||||||
|
|
||||||
picture = std::make_shared<CPicture>(ImagePath::builtin("MUMAP.bmp"), 16, 77);
|
const auto& multiplayerConfig = CMainMenuConfig::get().getConfig()["multiplayer"];
|
||||||
|
if (multiplayerConfig.isVector() && !multiplayerConfig.Vector().empty())
|
||||||
|
picture = std::make_shared<CPicture>(ImagePath::fromJson(*RandomGeneratorUtil::nextItem(multiplayerConfig.Vector(), CRandomGenerator::getDefault())), 16, 77);
|
||||||
|
|
||||||
|
if (multiplayerConfig.isString())
|
||||||
|
picture = std::make_shared<CPicture>(ImagePath::fromJson(multiplayerConfig), 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);
|
||||||
|
|
||||||
statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(7, 465, 440, 18), 7, 465));
|
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 = std::make_shared<CTextInput>(Rect(19, 436, 334, 16), background->getSurface());
|
||||||
playerName->setText(getPlayersNames()[0]);
|
playerName->setText(getPlayersNames()[0]);
|
||||||
playerName->setCallback(std::bind(&CMultiMode::onNameChange, this, _1));
|
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);
|
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);
|
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);
|
||||||
|
|
||||||
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);
|
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);
|
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);
|
||||||
|
|
||||||
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"), CGI->generaltexth->zelp[288], [=](){ close();}, EShortcut::GLOBAL_CANCEL);
|
||||||
}
|
}
|
||||||
@@ -491,18 +499,18 @@ void CMultiMode::openLobby()
|
|||||||
CSH->getGlobalLobby().activateInterface();
|
CSH->getGlobalLobby().activateInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMultiMode::hostTCP()
|
void CMultiMode::hostTCP(EShortcut shortcut)
|
||||||
{
|
{
|
||||||
auto savedScreenType = screenType;
|
auto savedScreenType = screenType;
|
||||||
close();
|
close();
|
||||||
GH.windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, true, ELoadMode::MULTI);
|
GH.windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, true, ELoadMode::MULTI, shortcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMultiMode::joinTCP()
|
void CMultiMode::joinTCP(EShortcut shortcut)
|
||||||
{
|
{
|
||||||
auto savedScreenType = screenType;
|
auto savedScreenType = screenType;
|
||||||
close();
|
close();
|
||||||
GH.windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, false, ELoadMode::MULTI);
|
GH.windows().createAndPushWindow<CMultiPlayers>(getPlayersNames(), savedScreenType, false, ELoadMode::MULTI, shortcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> CMultiMode::getPlayersNames()
|
std::vector<std::string> CMultiMode::getPlayersNames()
|
||||||
@@ -532,16 +540,29 @@ void CMultiMode::onNameChange(std::string newText)
|
|||||||
name->String() = newText;
|
name->String() = newText;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMultiPlayers::CMultiPlayers(const std::vector<std::string> & playerNames, ESelectionScreen ScreenType, bool Host, ELoadMode LoadMode)
|
CMultiPlayers::CMultiPlayers(const std::vector<std::string>& playerNames, ESelectionScreen ScreenType, bool Host, ELoadMode LoadMode, EShortcut shortcut)
|
||||||
: loadMode(LoadMode), screenType(ScreenType), host(Host)
|
: loadMode(LoadMode), screenType(ScreenType), host(Host)
|
||||||
{
|
{
|
||||||
OBJECT_CONSTRUCTION;
|
OBJECT_CONSTRUCTION;
|
||||||
background = std::make_shared<CPicture>(ImagePath::builtin("MUHOTSEA.bmp"));
|
background = std::make_shared<CPicture>(ImagePath::builtin("MUHOTSEA.bmp"));
|
||||||
pos = background->center(); //center, window has size of bg graphic
|
pos = background->center(); //center, window has size of bg graphic
|
||||||
|
|
||||||
std::string text = CGI->generaltexth->allTexts[446];
|
std::string text;
|
||||||
boost::replace_all(text, "\t", "\n");
|
switch (shortcut)
|
||||||
textTitle = std::make_shared<CTextBox>(text, Rect(25, 10, 315, 60), 0, FONT_BIG, ETextAlignment::CENTER, Colors::WHITE); //HOTSEAT Please enter names
|
{
|
||||||
|
case EShortcut::MAIN_MENU_HOTSEAT:
|
||||||
|
text = CGI->generaltexth->allTexts[446];
|
||||||
|
boost::replace_all(text, "\t", "\n");
|
||||||
|
break;
|
||||||
|
case EShortcut::MAIN_MENU_HOST_GAME:
|
||||||
|
text = CGI->generaltexth->translate("vcmi.mainMenu.hostTCP");
|
||||||
|
break;
|
||||||
|
case EShortcut::MAIN_MENU_JOIN_GAME:
|
||||||
|
text = CGI->generaltexth->translate("vcmi.mainMenu.joinTCP");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
textTitle = std::make_shared<CTextBox>(text, Rect(25, 10, 315, 60), 0, FONT_BIG, ETextAlignment::CENTER, Colors::WHITE);
|
||||||
|
|
||||||
for(int i = 0; i < inputNames.size(); i++)
|
for(int i = 0; i < inputNames.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -604,7 +625,7 @@ CSimpleJoinScreen::CSimpleJoinScreen(bool host)
|
|||||||
background = std::make_shared<CPicture>(ImagePath::builtin("MUDIALOG.bmp")); // address background
|
background = std::make_shared<CPicture>(ImagePath::builtin("MUDIALOG.bmp")); // address background
|
||||||
pos = background->center(); //center, window has size of bg graphic (x,y = 396,278 w=232 h=212)
|
pos = background->center(); //center, window has size of bg graphic (x,y = 396,278 w=232 h=212)
|
||||||
|
|
||||||
textTitle = std::make_shared<CTextBox>("", Rect(20, 20, 205, 50), 0, FONT_BIG, ETextAlignment::CENTER, Colors::WHITE);
|
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());
|
inputAddress = std::make_shared<CTextInput>(Rect(25, 68, 175, 16), background->getSurface());
|
||||||
inputPort = std::make_shared<CTextInput>(Rect(25, 115, 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"), CGI->generaltexth->zelp[560], std::bind(&CSimpleJoinScreen::connectToServer, this), EShortcut::GLOBAL_ACCEPT);
|
||||||
|
@@ -83,6 +83,7 @@ public:
|
|||||||
ESelectionScreen screenType;
|
ESelectionScreen screenType;
|
||||||
std::shared_ptr<CPicture> background;
|
std::shared_ptr<CPicture> background;
|
||||||
std::shared_ptr<CPicture> picture;
|
std::shared_ptr<CPicture> picture;
|
||||||
|
std::shared_ptr<CTextBox> textTitle;
|
||||||
std::shared_ptr<CTextInput> playerName;
|
std::shared_ptr<CTextInput> playerName;
|
||||||
std::shared_ptr<CButton> buttonHotseat;
|
std::shared_ptr<CButton> buttonHotseat;
|
||||||
std::shared_ptr<CButton> buttonLobby;
|
std::shared_ptr<CButton> buttonLobby;
|
||||||
@@ -93,8 +94,8 @@ public:
|
|||||||
|
|
||||||
CMultiMode(ESelectionScreen ScreenType);
|
CMultiMode(ESelectionScreen ScreenType);
|
||||||
void openLobby();
|
void openLobby();
|
||||||
void hostTCP();
|
void hostTCP(EShortcut shortcut);
|
||||||
void joinTCP();
|
void joinTCP(EShortcut shortcut);
|
||||||
|
|
||||||
/// Get all configured player names. The first name would always be present and initialized to its default value.
|
/// Get all configured player names. The first name would always be present and initialized to its default value.
|
||||||
std::vector<std::string> getPlayersNames();
|
std::vector<std::string> getPlayersNames();
|
||||||
@@ -119,7 +120,7 @@ class CMultiPlayers : public WindowBase
|
|||||||
void enterSelectionScreen();
|
void enterSelectionScreen();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CMultiPlayers(const std::vector<std::string> & playerNames, ESelectionScreen ScreenType, bool Host, ELoadMode LoadMode);
|
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,...
|
/// Manages the configuration of pregame GUI elements like campaign screen, main menu, loading screen,...
|
||||||
|
Reference in New Issue
Block a user