- added new LUA method togglePauseGame

This commit is contained in:
Mark Vejvoda 2011-01-29 23:50:21 +00:00
parent 82e31d670b
commit 4b085691df
6 changed files with 43 additions and 11 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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));

View File

@ -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);

View File

@ -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) {

View File

@ -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);