Handle game ending in Atlas a bit more gracefully, it now continues until the user stops the simulation test. Fixes #641.

This was SVN commit r11575.
This commit is contained in:
historic_bruno 2012-04-20 01:41:54 +00:00
parent 7d47407c70
commit c8745ee41f
4 changed files with 43 additions and 7 deletions

View File

@ -77,6 +77,10 @@ function init(initData, hotloadData)
getGUIObjectByName("civIcon").sprite = "stretched:"+g_CivData[g_Players[Engine.GetPlayerID()].civ].Emblem; getGUIObjectByName("civIcon").sprite = "stretched:"+g_CivData[g_Players[Engine.GetPlayerID()].civ].Emblem;
initMenuPosition(); // set initial position initMenuPosition(); // set initial position
// If in Atlas editor, disable the exit button
if (Engine.IsAtlasRunning())
getGUIObjectByName("menuExitButton").enabled = false;
if (hotloadData) if (hotloadData)
{ {
g_Selection.selected = hotloadData.selection; g_Selection.selected = hotloadData.selection;
@ -230,9 +234,20 @@ function checkPlayerState()
closeMenu(); closeMenu();
closeOpenDialogs(); closeOpenDialogs();
var btCaptions = ["Yes", "No"]; if (Engine.IsAtlasRunning())
var btCode = [leaveGame, null]; {
messageBox(400, 200, "Do you want to quit?", "DEFEATED!", 0, btCaptions, btCode); // 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") else if (playerState.state == "won")
{ {
@ -245,9 +260,20 @@ function checkPlayerState()
if (!getGUIObjectByName("devCommandsRevealMap").checked) if (!getGUIObjectByName("devCommandsRevealMap").checked)
getGUIObjectByName("devCommandsRevealMap").checked = true; getGUIObjectByName("devCommandsRevealMap").checked = true;
var btCaptions = ["Yes", "No"]; if (Engine.IsAtlasRunning())
var btCode = [leaveGame, null]; {
messageBox(400, 200, "Do you want to quit?", "VICTORIOUS!", 0, btCaptions, btCode); // 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);
} }
} }
} }

View File

@ -43,6 +43,7 @@
#include "ps/UserReport.h" #include "ps/UserReport.h"
#include "ps/GameSetup/Atlas.h" #include "ps/GameSetup/Atlas.h"
#include "ps/GameSetup/Config.h" #include "ps/GameSetup/Config.h"
#include "tools/atlas/GameInterface/GameLoop.h"
#include "simulation2/Simulation2.h" #include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpAIManager.h" #include "simulation2/components/ICmpAIManager.h"
@ -370,6 +371,11 @@ bool AtlasIsAvailable(void* UNUSED(cbdata))
return ATLAS_IsAvailable(); return ATLAS_IsAvailable();
} }
bool IsAtlasRunning(void* UNUSED(cbdata))
{
return (g_AtlasGameLoop && g_AtlasGameLoop->running);
}
CScriptVal LoadMapSettings(void* cbdata, VfsPath pathname) CScriptVal LoadMapSettings(void* cbdata, VfsPath pathname)
{ {
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata); CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
@ -613,6 +619,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction<void, std::string, &OpenURL>("OpenURL"); scriptInterface.RegisterFunction<void, std::string, &OpenURL>("OpenURL");
scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas"); scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas");
scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable"); scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable");
scriptInterface.RegisterFunction<bool, &IsAtlasRunning>("IsAtlasRunning");
scriptInterface.RegisterFunction<CScriptVal, VfsPath, &LoadMapSettings>("LoadMapSettings"); scriptInterface.RegisterFunction<CScriptVal, VfsPath, &LoadMapSettings>("LoadMapSettings");
scriptInterface.RegisterFunction<CScriptVal, &GetMapSettings>("GetMapSettings"); scriptInterface.RegisterFunction<CScriptVal, &GetMapSettings>("GetMapSettings");
scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollow>("CameraFollow"); scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollow>("CameraFollow");

View File

@ -309,6 +309,7 @@ bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll)
Atlas_SetConfigDirectory(paths.Config().string().c_str()); Atlas_SetConfigDirectory(paths.Config().string().c_str());
// Run the engine loop in a new thread // Run the engine loop in a new thread
g_AtlasGameLoop->running = true;
pthread_t engineThread; pthread_t engineThread;
pthread_create(&engineThread, NULL, RunEngine, reinterpret_cast<void*>(const_cast<CmdLineArgs*>(&args))); pthread_create(&engineThread, NULL, RunEngine, reinterpret_cast<void*>(const_cast<CmdLineArgs*>(&args)));

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games. /* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -26,6 +26,8 @@ class AtlasView;
struct GameLoopState struct GameLoopState
{ {
GameLoopState() : running(false) {};
CmdLineArgs args; CmdLineArgs args;
bool running; // whether the Atlas game loop is still running bool running; // whether the Atlas game loop is still running