From 4b085691dfca49dde0dacd21b80b16d394fe09fe Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 29 Jan 2011 23:50:21 +0000 Subject: [PATCH] - added new LUA method togglePauseGame --- source/glest_game/game/game.cpp | 32 +++++++++++++++-------- source/glest_game/game/game.h | 2 ++ source/glest_game/game/script_manager.cpp | 13 +++++++++ source/glest_game/game/script_manager.h | 2 ++ source/glest_game/world/world.cpp | 4 +++ source/glest_game/world/world.h | 1 + 6 files changed, 43 insertions(+), 11 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 85298bbf..70a1a688 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1279,7 +1279,6 @@ void Game::keyDown(char key) { } Lang &lang= Lang::getInstance(); - bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGame(); //send key to the chat manager chatManager.keyDown(key); @@ -1352,16 +1351,8 @@ void Game::keyDown(char key) { } //pause else if(key == configKeys.getCharKey("PauseGame")) { - if(speedChangesAllowed){ - if(paused){ - console.addLine(lang.get("GameResumed")); - paused= false; - } - else{ - console.addLine(lang.get("GamePaused")); - paused= true; - } - } + //printf("Toggle pause paused = %d\n",paused); + setPaused(!paused); } //switch display color else if(key == configKeys.getCharKey("ChangeFontColor")) { @@ -1369,12 +1360,14 @@ void Game::keyDown(char key) { } //increment speed else if(key == configKeys.getCharKey("GameSpeedIncrease")) { + bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGame(); if(speedChangesAllowed){ incSpeed(); } } //decrement speed else if(key == configKeys.getCharKey("GameSpeedDecrease")) { + bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGame(); if(speedChangesAllowed){ decSpeed(); } @@ -1993,6 +1986,23 @@ void Game::decSpeed() { } } +void Game::setPaused(bool value) { + bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGame(); + //printf("Toggle pause value = %d, speedChangesAllowed = %d\n",value,speedChangesAllowed); + + if(speedChangesAllowed) { + Lang &lang= Lang::getInstance(); + if(value == false) { + console.addLine(lang.get("GameResumed")); + paused= false; + } + else { + console.addLine(lang.get("GamePaused")); + paused= true; + } + } +} + int Game::getUpdateLoops() { if(paused) { return 0; diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index d1a9cfd8..0c01aa58 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -133,6 +133,8 @@ public: World *getWorld() {return &world;} const World *getWorld() const {return &world;} + bool getPaused() const { return paused;} + void setPaused(bool value); const int getTotalRenderFps() const {return totalRenderFps;} //init virtual void load(LoadGameItem loadTypes); diff --git a/source/glest_game/game/script_manager.cpp b/source/glest_game/game/script_manager.cpp index 21536021..d2eb6d48 100644 --- a/source/glest_game/game/script_manager.cpp +++ b/source/glest_game/game/script_manager.cpp @@ -89,6 +89,7 @@ void ScriptManager::init(World* world, GameCamera *gameCamera){ luaScript.registerFunction(playStreamingSound, "playStreamingSound"); luaScript.registerFunction(stopStreamingSound, "stopStreamingSound"); luaScript.registerFunction(stopAllSound, "stopAllSound"); + luaScript.registerFunction(togglePauseGame, "togglePauseGame"); luaScript.registerFunction(giveResource, "giveResource"); luaScript.registerFunction(givePositionCommand, "givePositionCommand"); luaScript.registerFunction(giveProductionCommand, "giveProductionCommand"); @@ -456,6 +457,12 @@ void ScriptManager::stopAllSound() { world->stopAllSound(); } +void ScriptManager::togglePauseGame(int pauseStatus) { + SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] pauseStatus = %d\n",__FILE__,__FUNCTION__,__LINE__,pauseStatus); + ScriptManager_STREFLOP_Wrapper streflopWrapper; + world->togglePauseGame((pauseStatus != 0)); +} + void ScriptManager::morphToUnit(int unitId,const string &morphName, int ignoreRequirements) { SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] morphName [%s] forceUpgradesIfRequired = %d\n",__FILE__,__FUNCTION__,__LINE__,unitId,morphName.c_str(),ignoreRequirements); ScriptManager_STREFLOP_Wrapper streflopWrapper; @@ -909,6 +916,12 @@ int ScriptManager::stopAllSound(LuaHandle* luaHandle) { return luaArguments.getReturnCount(); } +int ScriptManager::togglePauseGame(LuaHandle* luaHandle) { + LuaArguments luaArguments(luaHandle); + SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] value = %d\n",__FILE__,__FUNCTION__,__LINE__,luaArguments.getInt(-1)); + thisScriptManager->togglePauseGame(luaArguments.getInt(-1)); + return luaArguments.getReturnCount(); +} int ScriptManager::giveResource(LuaHandle* luaHandle){ LuaArguments luaArguments(luaHandle); thisScriptManager->giveResource(luaArguments.getString(-3), luaArguments.getInt(-2), luaArguments.getInt(-1)); diff --git a/source/glest_game/game/script_manager.h b/source/glest_game/game/script_manager.h index f8fc9a73..0ba437f4 100644 --- a/source/glest_game/game/script_manager.h +++ b/source/glest_game/game/script_manager.h @@ -185,6 +185,7 @@ private: void playStreamingSound(const string &playSound); void stopStreamingSound(const string &playSound); void stopAllSound(); + void togglePauseGame(int pauseStatus); void giveResource(const string &resourceName, int factionIndex, int amount); void givePositionCommand(int unitId, const string &producedName, const Vec2i &pos); @@ -250,6 +251,7 @@ private: static int playStreamingSound(LuaHandle* luaHandle); static int stopStreamingSound(LuaHandle* luaHandle); static int stopAllSound(LuaHandle* luaHandle); + static int togglePauseGame(LuaHandle* luaHandle); static int giveResource(LuaHandle* luaHandle); static int givePositionCommand(LuaHandle* luaHandle); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 1e9030b9..6fd631ea 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -935,6 +935,10 @@ void World::moveToUnit(int unitId, int destUnitId) { } } +void World::togglePauseGame(bool pauseStatus) { + game->setPaused(pauseStatus); +} + void World::giveUpgradeCommand(int unitId, const string &upgradeName) { Unit *unit= findUnitById(unitId); if(unit != NULL) { diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 35b5a93e..911b0eea 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -202,6 +202,7 @@ public: void stopStreamingSound(const string &playSound); void stopAllSound(); void moveToUnit(int unitId, int destUnitId); + void togglePauseGame(bool pauseStatus); void giveResource(const string &resourceName, int factionIndex, int amount); int getResourceAmount(const string &resourceName, int factionIndex);