1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-05 13:04:54 +02:00

Merge pull request #1969 from Nordsoft91/spectator

Single player spectator
This commit is contained in:
Nordsoft91 2023-04-15 03:33:18 +04:00 committed by GitHub
commit 6b12ee044f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 9 deletions

View File

@ -401,18 +401,24 @@ void CClient::initPlayerEnvironments()
playerEnvironments.clear();
auto allPlayers = CSH->getAllClientPlayers(CSH->c->connectionID);
if(allPlayers.empty())
{
Settings session = settings.write["session"];
session["spectate"].Bool() = true;
}
bool hasHumanPlayer = false;
for(auto & color : allPlayers)
{
logNetwork->info("Preparing environment for player %s", color.getStr());
playerEnvironments[color] = std::make_shared<CPlayerEnvironment>(color, this, std::make_shared<CCallback>(gs, color, this));
if(!hasHumanPlayer && gs->players[color].isHuman())
hasHumanPlayer = true;
}
if(!hasHumanPlayer)
{
Settings session = settings.write["session"];
session["spectate"].Bool() = true;
session["spectate-skip-battle-result"].Bool() = true;
session["spectate-ignore-hero"].Bool() = true;
}
if(settings["session"]["spectate"].Bool())
{
playerEnvironments[PlayerColor::SPECTATOR] = std::make_shared<CPlayerEnvironment>(PlayerColor::SPECTATOR, this, std::make_shared<CCallback>(gs, boost::none, this));

View File

@ -69,14 +69,14 @@ CLobbyScreen::CLobbyScreen(ESelectionScreen screenType)
card->iconDifficulty->addCallback(std::bind(&IServerAPI::setDifficulty, CSH, _1));
buttonStart = std::make_shared<CButton>(Point(411, 535), "SCNRBEG.DEF", CGI->generaltexth->zelp[103], std::bind(&CLobbyScreen::startScenario, this, false), SDLK_b);
buttonStart = std::make_shared<CButton>(Point(411, 535), "SCNRBEG.DEF", CGI->generaltexth->zelp[103], std::bind(&CLobbyScreen::startScenario, this, true), SDLK_b);
initLobby();
break;
}
case ESelectionScreen::loadGame:
{
tabOpt = std::make_shared<OptionsTab>();
buttonStart = std::make_shared<CButton>(Point(411, 535), "SCNRLOD.DEF", CGI->generaltexth->zelp[103], std::bind(&CLobbyScreen::startScenario, this, false), SDLK_l);
buttonStart = std::make_shared<CButton>(Point(411, 535), "SCNRLOD.DEF", CGI->generaltexth->zelp[103], std::bind(&CLobbyScreen::startScenario, this, true), SDLK_l);
initLobby();
break;
}

View File

@ -514,7 +514,7 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
void OptionsTab::onSetPlayerClicked(const PlayerSettings & ps) const
{
if(ps.isControlledByAI() || humanPlayers > 1)
if(ps.isControlledByAI() || humanPlayers > 0)
CSH->setPlayer(ps.color);
}