diff --git a/src/screens/gm/gameMasterScreen.cpp b/src/screens/gm/gameMasterScreen.cpp index 889d2768f5..8a7e11a5b0 100644 --- a/src/screens/gm/gameMasterScreen.cpp +++ b/src/screens/gm/gameMasterScreen.cpp @@ -174,18 +174,35 @@ GameMasterScreen::GameMasterScreen(RenderLayer* render_layer) box_selection_overlay->layout.fill_width = false; box_selection_overlay->hide(); - pause_button = new GuiToggleButton(this, "PAUSE_BUTTON", tr("button", "Pause"), [](bool value) { - if (!value) + pause_button = new GuiToggleButton(this, "PAUSE_BUTTON", tr("button", "Pause"), [this](bool value) { + if (!value) { engine->setGameSpeed(1.0f); + slow_button->setValue(false); + } else + { engine->setGameSpeed(0.0f); + slow_button->setValue(false); + } }); pause_button->setValue(engine->getGameSpeed() == 0.0f)->setPosition(20, 20, sp::Alignment::TopLeft)->setSize(250, 50); + slow_button = new GuiToggleButton(this, "SLOW_BUTTON", tr("button", "Slow"), [this](bool value) { + if (!value) { + engine->setGameSpeed(1.0f); + pause_button->setValue(false); + } + else + { + engine->setGameSpeed(0.1f); + pause_button->setValue(false); + } + }); + slow_button->setValue(false)->setPosition(300, 20, sp::Alignment::TopLeft)->setSize(250, 50); intercept_comms_button = new GuiToggleButton(this, "INTERCEPT_COMMS_BUTTON", tr("button", "Intercept all comms"), [](bool value) { gameGlobalInfo->intercept_all_comms_to_gm = value; }); - intercept_comms_button->setValue(gameGlobalInfo->intercept_all_comms_to_gm)->setTextSize(20)->setPosition(300, 20, sp::Alignment::TopLeft)->setSize(200, 25); + intercept_comms_button->setValue(gameGlobalInfo->intercept_all_comms_to_gm)->setTextSize(20)->setPosition(580, 20, sp::Alignment::TopLeft)->setSize(200, 25); faction_selector = new GuiSelector(this, "FACTION_SELECTOR", [this](int index, string value) { for (auto obj : targets.getTargets()) @@ -478,6 +495,10 @@ void GameMasterScreen::update(float delta) // Track selection indices to determine "*mixed*" state. std::unordered_map selection_info_index; + // Update pause button + slow_button->setValue(engine->getGameSpeed() == 0.1f); + pause_button->setValue(engine->getGameSpeed() == 0.0f); + // List position if only one entity is selected. if (targets.getTargets().size() == 1) { diff --git a/src/screens/gm/gameMasterScreen.h b/src/screens/gm/gameMasterScreen.h index d2da1f1ab8..998e82e667 100644 --- a/src/screens/gm/gameMasterScreen.h +++ b/src/screens/gm/gameMasterScreen.h @@ -53,6 +53,7 @@ class GameMasterScreen : public GuiCanvas, public Updatable GuiButton* player_comms_hail; GuiButton* global_message_button; GuiToggleButton* pause_button; + GuiToggleButton* slow_button; GuiToggleButton* intercept_comms_button; GuiButton* tweak_button; GuiRadarZoomSlider* zoom_slider; diff --git a/src/script.cpp b/src/script.cpp index 67b8a6fa60..e062a30a53 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -702,6 +702,21 @@ static bool luaIsGamePaused() return engine->getGameSpeed() == 0.0f; } +static void luaSlowGame() +{ + engine->setGameSpeed(0.1f); +} + +static void luaUnslowGame() +{ + engine->setGameSpeed(1.0f); +} + +static bool luaIsGameSlowed() +{ + return engine->getGameSpeed() == 0.1f; +} + static void luaPlaySoundFile(string filename) { int n = filename.rfind("."); @@ -1405,6 +1420,18 @@ bool setupScriptEnvironment(sp::script::Environment& env) /// Returns true if the game is paused. /// Example: local is_paused = isGamePaused() env.setGlobal("isGamePaused", &luaIsGamePaused); + /// void slowGame() + /// Slows down the game to 10% game speed. + /// Example: slowGame() + env.setGlobal("slowGame", &luaSlowGame); + /// void unslowGame() + /// Restores the normal game speed. + /// Example: unslowGame() + env.setGlobal("unslowGame", &luaUnslowGame); + /// bool isGameSlowed() + /// Returns true if the game was slowed down by slowGame. + /// Example: local is_slowed = isGameSlowed() + env.setGlobal("isGameSlowed", &luaIsGameSlowed); /// void playSoundFile(string filename) /// Plays the given audio file on the server. /// Paths are relative to the resources/ directory.