diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-12-14 20:28:24 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-12-14 20:28:24 +0100 |
commit | 46c30bb9939249c06d6994a660130a8e3c6f4dae (patch) | |
tree | b847dcd0015c091a2f37df95af96b8e3e7fc907a | |
parent | db7444ffba059e5ab92c12574dca3889e6b2f2c2 (diff) | |
download | Mana-46c30bb9939249c06d6994a660130a8e3c6f4dae.tar.gz Mana-46c30bb9939249c06d6994a660130a8e3c6f4dae.tar.bz2 Mana-46c30bb9939249c06d6994a660130a8e3c6f4dae.tar.xz Mana-46c30bb9939249c06d6994a660130a8e3c6f4dae.zip |
Code reformatting to conform to line length
-rw-r--r-- | src/game.cpp | 96 |
1 files changed, 57 insertions, 39 deletions
diff --git a/src/game.cpp b/src/game.cpp index 2cc68c0e..1875a7e4 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -344,10 +344,12 @@ Game::~Game() SDL_RemoveTimer(mSecondsCounterId); } -bool saveScreenshot(SDL_Surface *screenshot) +static bool saveScreenshot() { static unsigned int screenshotCount = 0; + SDL_Surface *screenshot = graphics->getScreenshot(); + // Search for an unused screenshot name std::stringstream filenameSuffix; std::stringstream filename; @@ -366,24 +368,28 @@ bool saveScreenshot(SDL_Surface *screenshot) #endif filenameSuffix << "TMW_Screenshot_" << screenshotCount << ".png"; filename << filenameSuffix.str(); - std::cerr << "Trying `" << filename.str() << "' from `" << filenameSuffix.str() << "'\n"; testExists.open(filename.str().c_str(), std::ios::in); found = !testExists.is_open(); testExists.close(); } while (!found); - if (ImageWriter::writePNG(screenshot, filename.str())) + const bool success = ImageWriter::writePNG(screenshot, filename.str()); + + if (success) { std::stringstream chatlogentry; chatlogentry << "Screenshot saved to ~/" << filenameSuffix.str().c_str(); chatWindow->chatLog(chatlogentry.str(), BY_SERVER); - return true; } else { chatWindow->chatLog("Saving screenshot failed!", BY_SERVER); - return false; + logger->log("Error: could not save screenshot."); } + + SDL_FreeSurface(screenshot); + + return success; } void Game::optionChanged(const std::string &name) @@ -453,9 +459,9 @@ void Game::logic() { if (!disconnectedDialog) { - disconnectedDialog = new - OkDialog("Network Error", - "The connection to the server was lost, the program will now quit"); + disconnectedDialog = new OkDialog("Network Error", + "The connection to the server was lost, " + "the program will now quit"); disconnectedDialog->addActionListener(&exitListener); disconnectedDialog->requestMoveToTop(); } @@ -465,10 +471,8 @@ void Game::logic() void Game::handleInput() { - if (joystick != NULL) - { + if (joystick) joystick->update(); - } // Events SDL_Event event; @@ -544,10 +548,12 @@ void Game::handleInput() { setupWindow->action(gcn::ActionEvent(NULL, "cancel")); } -/* else if (guildWindow->isVisible()) + /* + else if (guildWindow->isVisible()) { // TODO: Check if a dialog is open and close it if so - }*/ + } + */ // Else, open the chat edit box else { @@ -652,15 +658,34 @@ void Game::handleInput() guildWindow->setVisible(false); } break; - case KeyboardConfig::KEY_WINDOW_STATUS: requestedWindow = statusWindow; break; - case KeyboardConfig::KEY_WINDOW_INVENTORY: requestedWindow = inventoryWindow; break; - case KeyboardConfig::KEY_WINDOW_EQUIPMENT: requestedWindow = equipmentWindow; break; - case KeyboardConfig::KEY_WINDOW_SKILL: requestedWindow = skillDialog; break; - case KeyboardConfig::KEY_WINDOW_MINIMAP: requestedWindow = minimap; break; - case KeyboardConfig::KEY_WINDOW_CHAT: requestedWindow = chatWindow; break; - case KeyboardConfig::KEY_WINDOW_SHORTCUT: requestedWindow = itemShortcutWindow; break; - case KeyboardConfig::KEY_WINDOW_SETUP: requestedWindow = setupWindow; break; - case KeyboardConfig::KEY_WINDOW_DEBUG: requestedWindow = debugWindow; break; + + case KeyboardConfig::KEY_WINDOW_STATUS: + requestedWindow = statusWindow; + break; + case KeyboardConfig::KEY_WINDOW_INVENTORY: + requestedWindow = inventoryWindow; + break; + case KeyboardConfig::KEY_WINDOW_EQUIPMENT: + requestedWindow = equipmentWindow; + break; + case KeyboardConfig::KEY_WINDOW_SKILL: + requestedWindow = skillDialog; + break; + case KeyboardConfig::KEY_WINDOW_MINIMAP: + requestedWindow = minimap; + break; + case KeyboardConfig::KEY_WINDOW_CHAT: + requestedWindow = chatWindow; + break; + case KeyboardConfig::KEY_WINDOW_SHORTCUT: + requestedWindow = itemShortcutWindow; + break; + case KeyboardConfig::KEY_WINDOW_SETUP: + requestedWindow = setupWindow; + break; + case KeyboardConfig::KEY_WINDOW_DEBUG: + requestedWindow = debugWindow; + break; } } @@ -686,15 +711,7 @@ void Game::handleInput() { case SDLK_p: // Screenshot (picture, hence the p) - { - SDL_Surface *screenshot = graphics->getScreenshot(); - if (!saveScreenshot(screenshot)) - { - logger->log( - "Error: could not save Screenshot."); - } - SDL_FreeSurface(screenshot); - } + saveScreenshot(); used = true; break; @@ -767,11 +784,11 @@ void Game::handleInput() } } // End while + // If the user is configuring the keys then don't respond. if (!keyboard.isEnabled()) - { - return; - } + return; + // Moving player around if (player_node->mAction != Being::DEAD && !chatWindow->isInputFocused()) @@ -808,7 +825,8 @@ void Game::handleInput() direction |= Being::RIGHT; } - // First if player is pressing key for the direction he is already going + // First if player is pressing key for the direction he is already + // going if (direction == player_node->getWalkingDir()) { player_node->setWalkingDir(direction); @@ -830,8 +848,8 @@ void Game::handleInput() // Target the nearest player if 'q' is pressed if (keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER)) { - Being *target = - beingManager->findNearestLivingBeing(player_node, 20, Being::PLAYER); + Being *target = beingManager->findNearestLivingBeing( + player_node, 20, Being::PLAYER); if (target) { @@ -842,8 +860,8 @@ void Game::handleInput() // Target the nearest monster if 'a' pressed if (keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST)) { - Being *target = - beingManager->findNearestLivingBeing(x, y, 20, Being::MONSTER); + Being *target = beingManager->findNearestLivingBeing( + x, y, 20, Being::MONSTER); if (target) { |