diff options
author | Paramat <paramat@users.noreply.github.com> | 2018-11-24 10:41:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-24 10:41:11 +0000 |
commit | 2e37ee956530b7cd310e0d6cfb8ce3cd8f6973e6 (patch) | |
tree | 4f607e1f226fa169c2bd98de531b62cba4de3260 /src/game.cpp | |
parent | a969635322576218312be3e32e5b4fcb0359ac05 (diff) | |
download | minetest-2e37ee956530b7cd310e0d6cfb8ce3cd8f6973e6.tar.gz minetest-2e37ee956530b7cd310e0d6cfb8ce3cd8f6973e6.tar.bz2 minetest-2e37ee956530b7cd310e0d6cfb8ce3cd8f6973e6.zip |
CSM: Don't create the client script environment if CSM is disabled (#7874)
Use the CSM death formspec when CSM is enabled and use the engine death formspec when CSM is disabled.
Move the CSM death formspec code to a dedicated file.
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/src/game.cpp b/src/game.cpp index 1cb9a1650..6cf6723e9 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -177,8 +177,13 @@ struct LocalFormspecHandler : public TextDest } } - // Don't disable this part when modding is disabled, it's used in builtin - if (m_client && m_client->getScript()) + if (m_formname == "MT_DEATH_SCREEN") { + assert(m_client != 0); + m_client->sendRespawn(); + return; + } + + if (m_client && m_client->moddingEnabled()) m_client->getScript()->on_formspec_input(m_formname, fields); } @@ -775,6 +780,7 @@ private: bool disable_camera_update = false; }; + void showDeathFormspec(); void showPauseMenu(); // ClientEvent handlers @@ -1496,8 +1502,6 @@ bool Game::connectToServer(const std::string &playername, fps_control.last_time = RenderingEngine::get_timer_time(); - client->loadBuiltin(); - while (RenderingEngine::run()) { limitFps(&fps_control, &dtime); @@ -1882,7 +1886,10 @@ void Game::processKeyInput() } else if (wasKeyDown(KeyType::CMD)) { openConsole(0.2, L"/"); } else if (wasKeyDown(KeyType::CMD_LOCAL)) { - openConsole(0.2, L"."); + if (client->moddingEnabled()) + openConsole(0.2, L"."); + else + m_game_ui->showStatusText(wgettext("CSM is disabled")); } else if (wasKeyDown(KeyType::CONSOLE)) { openConsole(core::clamp(g_settings->getFloat("console_height"), 0.1f, 1.0f)); } else if (wasKeyDown(KeyType::FREEMOVE)) { @@ -2532,12 +2539,15 @@ void Game::handleClientEvent_PlayerForceMove(ClientEvent *event, CameraOrientati void Game::handleClientEvent_Deathscreen(ClientEvent *event, CameraOrientation *cam) { - // This should be enabled for death formspec in builtin - client->getScript()->on_death(); - - LocalPlayer *player = client->getEnv().getLocalPlayer(); + // If CSM enabled, deathscreen is handled by CSM code in + // builtin/client/init.lua + if (client->moddingEnabled()) + client->getScript()->on_death(); + else + showDeathFormspec(); /* Handle visualization */ + LocalPlayer *player = client->getEnv().getLocalPlayer(); runData.damage_flash = 0; player->hurt_tilt_timer = 0; player->hurt_tilt_strength = 0; @@ -4006,6 +4016,27 @@ void Game::extendedResourceCleanup() << " (note: irrlicht doesn't support removing renderers)" << std::endl; } +void Game::showDeathFormspec() +{ + static std::string formspec = + std::string(FORMSPEC_VERSION_STRING) + + SIZE_TAG + "bgcolor[#320000b4;true]" + "label[4.85,1.35;" + gettext("You died") + "]" + "button_exit[4,3;3,0.5;btn_respawn;" + gettext("Respawn") + "]" + ; + + /* Create menu */ + /* Note: FormspecFormSource and LocalFormspecHandler * + * are deleted by guiFormSpecMenu */ + FormspecFormSource *fs_src = new FormspecFormSource(formspec); + LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_DEATH_SCREEN", client); + + GUIFormSpecMenu::create(current_formspec, client, &input->joystick, fs_src, + txt_dst, client->getFormspecPrepend()); + current_formspec->setFocus("btn_respawn"); +} + #define GET_KEY_NAME(KEY) gettext(getKeySetting(#KEY).name()) void Game::showPauseMenu() { |