mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Full rework of pre-game interface and networking
New features for players: * Loading for multiplayer. Any save could be used for multiplayer. * Restart for multiplayer. All clients will restart together. * Loading from single save. * Hotseat mixed with network game. Multiple players per client. * Now connection to server could be cancelled. * Return to menu on disconnections instead of crashes. * Restoring of last selected map, save or campaign on next run. TLDR on important changes in engine code: * UI: work with server separated from UI * UI: all explitic blitting replaced with IntObject's * UI: all new code use smart pointers instead of DISPOSE * Gameplay always start through lobby controlled by server. * Threads receiving netpacks now shared for lobby and gameplay. * Campaigns: heroes for crossover now serialized as JsonNode.
This commit is contained in:
142
client/NetPacksLobbyClient.cpp
Normal file
142
client/NetPacksLobbyClient.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* NetPacksLobbyClient.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 "lobby/CSelectionBase.h"
|
||||
#include "lobby/CLobbyScreen.h"
|
||||
|
||||
#include "lobby/OptionsTab.h"
|
||||
#include "lobby/RandomMapTab.h"
|
||||
#include "lobby/SelectionTab.h"
|
||||
#include "lobby/CBonusSelection.h"
|
||||
|
||||
#include "CServerHandler.h"
|
||||
#include "CGameInfo.h"
|
||||
#include "gui/CGuiHandler.h"
|
||||
#include "widgets/Buttons.h"
|
||||
#include "widgets/TextControls.h"
|
||||
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "../lib/CGeneralTextHandler.h"
|
||||
#include "../lib/NetPacksLobby.h"
|
||||
#include "../lib/serializer/Connection.h"
|
||||
|
||||
bool LobbyClientConnected::applyOnLobbyHandler(CServerHandler * handler)
|
||||
{
|
||||
// Check if it's LobbyClientConnected for our client
|
||||
if(uuid == handler->c->uuid)
|
||||
{
|
||||
handler->c->connectionID = clientId;
|
||||
if(!settings["session"]["headless"].Bool())
|
||||
GH.pushInt(new CLobbyScreen(static_cast<ESelectionScreen>(handler->screenType)));
|
||||
handler->state = EClientState::LOBBY;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void LobbyClientConnected::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
|
||||
{
|
||||
if(uuid == handler->c->uuid)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
bool LobbyClientDisconnected::applyOnLobbyHandler(CServerHandler * handler)
|
||||
{
|
||||
if(clientId != c->connectionID)
|
||||
return false;
|
||||
|
||||
handler->stopServerConnection();
|
||||
return true;
|
||||
}
|
||||
|
||||
void LobbyClientDisconnected::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
|
||||
{
|
||||
GH.popIntTotally(lobby);
|
||||
}
|
||||
|
||||
void LobbyChatMessage::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
|
||||
{
|
||||
if(lobby)
|
||||
{
|
||||
lobby->card->chat->addNewMessage(playerName + ": " + message);
|
||||
lobby->card->setChat(true);
|
||||
if(lobby->buttonChat)
|
||||
lobby->buttonChat->addTextOverlay(CGI->generaltexth->allTexts[531], FONT_SMALL);
|
||||
}
|
||||
}
|
||||
|
||||
void LobbyGuiAction::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
|
||||
{
|
||||
if(!handler->isGuest())
|
||||
return;
|
||||
|
||||
switch(action)
|
||||
{
|
||||
case NO_TAB:
|
||||
lobby->toggleTab(lobby->curTab);
|
||||
break;
|
||||
case OPEN_OPTIONS:
|
||||
lobby->toggleTab(lobby->tabOpt);
|
||||
break;
|
||||
case OPEN_SCENARIO_LIST:
|
||||
lobby->toggleTab(lobby->tabSel);
|
||||
break;
|
||||
case OPEN_RANDOM_MAP_OPTIONS:
|
||||
lobby->toggleTab(lobby->tabRand);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool LobbyStartGame::applyOnLobbyHandler(CServerHandler * handler)
|
||||
{
|
||||
if(handler->state == EClientState::GAMEPLAY)
|
||||
{
|
||||
handler->endGameplay(false);
|
||||
}
|
||||
handler->state = EClientState::STARTING;
|
||||
if(handler->si->mode != StartInfo::LOAD_GAME)
|
||||
{
|
||||
handler->si = initializedStartInfo;
|
||||
}
|
||||
if(settings["session"]["headless"].Bool())
|
||||
handler->startGameplay();
|
||||
return true;
|
||||
}
|
||||
|
||||
void LobbyStartGame::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
|
||||
{
|
||||
CMM->showLoadingScreen(std::bind(&CServerHandler::startGameplay, handler));
|
||||
}
|
||||
|
||||
bool LobbyUpdateState::applyOnLobbyHandler(CServerHandler * handler)
|
||||
{
|
||||
hostChanged = state.hostClientId != handler->hostClientId;
|
||||
static_cast<LobbyState &>(*handler) = state;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LobbyUpdateState::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
|
||||
{
|
||||
if(!lobby->bonusSel && handler->si->campState && handler->state == EClientState::LOBBY_CAMPAIGN)
|
||||
{
|
||||
lobby->bonusSel = new CBonusSelection();
|
||||
GH.pushInt(lobby->bonusSel);
|
||||
}
|
||||
|
||||
if(lobby->bonusSel)
|
||||
lobby->bonusSel->updateAfterStateChange();
|
||||
else
|
||||
lobby->updateAfterStateChange();
|
||||
|
||||
if(hostChanged)
|
||||
lobby->toggleMode(handler->isHost());
|
||||
}
|
||||
Reference in New Issue
Block a user