diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index 8ecf776ad0..a32b36931d 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -77,6 +77,10 @@ function init(initData, hotloadData) getGUIObjectByName("civIcon").sprite = "stretched:"+g_CivData[g_Players[Engine.GetPlayerID()].civ].Emblem; initMenuPosition(); // set initial position + // If in Atlas editor, disable the exit button + if (Engine.IsAtlasRunning()) + getGUIObjectByName("menuExitButton").enabled = false; + if (hotloadData) { g_Selection.selected = hotloadData.selection; @@ -230,9 +234,20 @@ function checkPlayerState() closeMenu(); closeOpenDialogs(); - var btCaptions = ["Yes", "No"]; - var btCode = [leaveGame, null]; - messageBox(400, 200, "Do you want to quit?", "DEFEATED!", 0, btCaptions, btCode); + if (Engine.IsAtlasRunning()) + { + // If we're in Atlas, we can't leave the game + var btCaptions = ["OK"]; + var btCode = [null]; + var message = "Press OK to continue"; + } + else + { + var btCaptions = ["Yes", "No"]; + var btCode = [leaveGame, null]; + var message = "Do you want to quit?"; + } + messageBox(400, 200, message, "DEFEATED!", 0, btCaptions, btCode); } else if (playerState.state == "won") { @@ -245,9 +260,20 @@ function checkPlayerState() if (!getGUIObjectByName("devCommandsRevealMap").checked) getGUIObjectByName("devCommandsRevealMap").checked = true; - var btCaptions = ["Yes", "No"]; - var btCode = [leaveGame, null]; - messageBox(400, 200, "Do you want to quit?", "VICTORIOUS!", 0, btCaptions, btCode); + if (Engine.IsAtlasRunning()) + { + // If we're in Atlas, we can't leave the game + var btCaptions = ["OK"]; + var btCode = [null]; + var message = "Press OK to continue"; + } + else + { + var btCaptions = ["Yes", "No"]; + var btCode = [leaveGame, null]; + var message = "Do you want to quit?"; + } + messageBox(400, 200, message, "VICTORIOUS!", 0, btCaptions, btCode); } } } diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index f0be317d0b..711cd41648 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -43,6 +43,7 @@ #include "ps/UserReport.h" #include "ps/GameSetup/Atlas.h" #include "ps/GameSetup/Config.h" +#include "tools/atlas/GameInterface/GameLoop.h" #include "simulation2/Simulation2.h" #include "simulation2/components/ICmpAIManager.h" @@ -370,6 +371,11 @@ bool AtlasIsAvailable(void* UNUSED(cbdata)) return ATLAS_IsAvailable(); } +bool IsAtlasRunning(void* UNUSED(cbdata)) +{ + return (g_AtlasGameLoop && g_AtlasGameLoop->running); +} + CScriptVal LoadMapSettings(void* cbdata, VfsPath pathname) { CGUIManager* guiManager = static_cast (cbdata); @@ -613,6 +619,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface) scriptInterface.RegisterFunction("OpenURL"); scriptInterface.RegisterFunction("RestartInAtlas"); scriptInterface.RegisterFunction("AtlasIsAvailable"); + scriptInterface.RegisterFunction("IsAtlasRunning"); scriptInterface.RegisterFunction("LoadMapSettings"); scriptInterface.RegisterFunction("GetMapSettings"); scriptInterface.RegisterFunction("CameraFollow"); diff --git a/source/tools/atlas/GameInterface/GameLoop.cpp b/source/tools/atlas/GameInterface/GameLoop.cpp index 4a01a08373..dc07ca62fb 100644 --- a/source/tools/atlas/GameInterface/GameLoop.cpp +++ b/source/tools/atlas/GameInterface/GameLoop.cpp @@ -309,6 +309,7 @@ bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll) Atlas_SetConfigDirectory(paths.Config().string().c_str()); // Run the engine loop in a new thread + g_AtlasGameLoop->running = true; pthread_t engineThread; pthread_create(&engineThread, NULL, RunEngine, reinterpret_cast(const_cast(&args))); diff --git a/source/tools/atlas/GameInterface/GameLoop.h b/source/tools/atlas/GameInterface/GameLoop.h index 91d176ff9a..9dc702c231 100644 --- a/source/tools/atlas/GameInterface/GameLoop.h +++ b/source/tools/atlas/GameInterface/GameLoop.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009 Wildfire Games. +/* Copyright (C) 2012 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -26,6 +26,8 @@ class AtlasView; struct GameLoopState { + GameLoopState() : running(false) {}; + CmdLineArgs args; bool running; // whether the Atlas game loop is still running