diff options
author | Dennis Friis <peavey@placid.dk> | 2008-04-28 16:31:32 +0000 |
---|---|---|
committer | Dennis Friis <peavey@placid.dk> | 2008-04-28 16:31:32 +0000 |
commit | 7fcc51177970a398742b65aac5817f0bdc62aea9 (patch) | |
tree | 821c26d72e0b5ffbf7cb46a2294ba1d05aab76e2 /src | |
parent | 86d441913287287baa56d6d262be9ee519840e96 (diff) | |
download | mana-7fcc51177970a398742b65aac5817f0bdc62aea9.tar.gz mana-7fcc51177970a398742b65aac5817f0bdc62aea9.tar.bz2 mana-7fcc51177970a398742b65aac5817f0bdc62aea9.tar.xz mana-7fcc51177970a398742b65aac5817f0bdc62aea9.zip |
Tweak keyboard input handling a bit. This fixes using emoticons triggering shortcut items to be used.
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 283 |
1 files changed, 143 insertions, 140 deletions
diff --git a/src/game.cpp b/src/game.cpp index 7834b42f..f94fd305 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -461,82 +461,154 @@ void Game::handleInput() keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE); return; } - switch (event.key.keysym.sym) + // Keys pressed together with Alt/Meta + // Emotions and some internal gui windows + #ifndef __APPLE__ + if (event.key.keysym.mod & KMOD_ALT) + #else + if (event.key.keysym.mod & KMOD_LMETA) + #endif { - case SDLK_F1: - // In-game Help - if (helpWindow->isVisible()) - { - helpWindow->setVisible(false); - } - else - { - helpWindow->loadHelp("index"); - helpWindow->requestMoveToTop(); - } - used = true; - break; - - case SDLK_F2: requestedWindow = statusWindow; break; - case SDLK_F3: requestedWindow = inventoryWindow; break; - case SDLK_F4: requestedWindow = equipmentWindow; break; - case SDLK_F5: requestedWindow = skillDialog; break; - case SDLK_F6: requestedWindow = minimap; break; - case SDLK_F7: requestedWindow = chatWindow; break; - //case SDLK_F8: requestedWindow = buddyWindow; break; - case SDLK_F9: requestedWindow = setupWindow; break; - case SDLK_F10: requestedWindow = debugWindow; break; - //case SDLK_F11: requestedWindow = newSkillWindow; break; - - case SDLK_RETURN: - // Input chat window - if (chatWindow->isFocused() || - deathNotice != NULL || - weightNotice != NULL) - { + switch (event.key.keysym.sym) + { + 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); + } + used = true; break; - } - // Quit by pressing Enter if the exit confirm is there - if (exitConfirm) - { - done = true; - } - // Close the Browser if opened - else if (helpWindow->isVisible()) - { - helpWindow->setVisible(false); - } - // Close the config window, cancelling changes if opened - else if (setupWindow->isVisible()) - { - setupWindow->action(gcn::ActionEvent(NULL, "cancel")); - } - // Else, open the chat edit box - else - { - chatWindow->requestChatFocus(); + default: + break; + + case SDLK_f: + // Find path to mouse (debug purpose) + viewport->toggleDebugPath(); used = true; - } - break; - // Quitting confirmation dialog - case SDLK_ESCAPE: - if (!exitConfirm) { - exitConfirm = new ConfirmDialog( - "Quit", "Are you sure you want to quit?"); - exitConfirm->addActionListener(&exitListener); - exitConfirm->requestMoveToTop(); - } - else - { - exitConfirm->action(gcn::ActionEvent(NULL, "no")); - } - break; + break; - default: - break; - } + case SDLK_t: + // Toggle accepting of incoming trade requests + { + TradeHandler *th = static_cast<TradeHandler*>( + mTradeHandler.get()); + th->setAcceptTradeRequests( + !th->acceptTradeRequests()); + } + used = true; + break; + } + // Emotions + Uint8 emotion; + switch (event.key.keysym.sym) + { + case SDLK_1: emotion = 1; break; + case SDLK_2: emotion = 2; break; + case SDLK_3: emotion = 3; break; + case SDLK_4: emotion = 4; break; + case SDLK_5: emotion = 5; break; + case SDLK_6: emotion = 6; break; + case SDLK_7: emotion = 7; break; + case SDLK_8: emotion = 8; break; + case SDLK_9: emotion = 9; break; + case SDLK_0: emotion = 10; break; + case SDLK_MINUS: emotion = 11; break; + case SDLK_EQUALS: emotion = 12; break; + default: emotion = 0; break; + } + + if (emotion) + { + player_node->emote(emotion); + used = true; + } + } + if (event.key.keysym.mod == KMOD_NONE) + { + switch (event.key.keysym.sym) + { + case SDLK_F1: + // In-game Help + if (helpWindow->isVisible()) + { + helpWindow->setVisible(false); + } + else + { + helpWindow->loadHelp("index"); + helpWindow->requestMoveToTop(); + } + used = true; + break; + + case SDLK_F2: requestedWindow = statusWindow; break; + case SDLK_F3: requestedWindow = inventoryWindow; break; + case SDLK_F4: requestedWindow = equipmentWindow; break; + case SDLK_F5: requestedWindow = skillDialog; break; + case SDLK_F6: requestedWindow = minimap; break; + case SDLK_F7: requestedWindow = chatWindow; break; + //case SDLK_F8: requestedWindow = buddyWindow; break; + case SDLK_F9: requestedWindow = setupWindow; break; + case SDLK_F10: requestedWindow = debugWindow; break; + //case SDLK_F11: requestedWindow = newSkillWindow; break; + + case SDLK_RETURN: + // Input chat window + if (chatWindow->isFocused() || + deathNotice != NULL || + weightNotice != NULL) + { + break; + } + + // Quit by pressing Enter if the exit confirm is there + if (exitConfirm) + { + done = true; + } + // Close the Browser if opened + else if (helpWindow->isVisible()) + { + helpWindow->setVisible(false); + } + // Close the config window, cancelling changes if opened + else if (setupWindow->isVisible()) + { + setupWindow->action(gcn::ActionEvent(NULL, "cancel")); + } + // Else, open the chat edit box + else + { + chatWindow->requestChatFocus(); + used = true; + } + break; + // Quitting confirmation dialog + case SDLK_ESCAPE: + if (!exitConfirm) { + exitConfirm = new ConfirmDialog( + "Quit", "Are you sure you want to quit?"); + exitConfirm->addActionListener(&exitListener); + exitConfirm->requestMoveToTop(); + } + else + { + exitConfirm->action(gcn::ActionEvent(NULL, "no")); + } + break; + + default: + break; + } + } + if (keyboard.isEnabled() && !chatWindow->isFocused()) { const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); @@ -545,7 +617,7 @@ void Game::handleInput() i <= KeyboardConfig::KEY_SHORTCUT_9; i++) { - if (tKey == i) { + if (tKey == i && !used) { itemShortcut->useItem( i - KeyboardConfig::KEY_SHORTCUT_0); break; @@ -611,75 +683,6 @@ void Game::handleInput() used = true; } - // Keys pressed together with Alt/Meta - // Emotions and some internal gui windows - #ifndef __APPLE__ - if (event.key.keysym.mod & KMOD_ALT) - #else - if (event.key.keysym.mod & KMOD_LMETA) - #endif - { - switch (event.key.keysym.sym) - { - 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); - } - used = true; - break; - - default: - break; - - case SDLK_f: - // Find path to mouse (debug purpose) - viewport->toggleDebugPath(); - used = true; - break; - - case SDLK_t: - // Toggle accepting of incoming trade requests - { - TradeHandler *th = static_cast<TradeHandler*>( - mTradeHandler.get()); - th->setAcceptTradeRequests( - !th->acceptTradeRequests()); - } - used = true; - break; - } - - // Emotions - Uint8 emotion; - switch (event.key.keysym.sym) - { - case SDLK_1: emotion = 1; break; - case SDLK_2: emotion = 2; break; - case SDLK_3: emotion = 3; break; - case SDLK_4: emotion = 4; break; - case SDLK_5: emotion = 5; break; - case SDLK_6: emotion = 6; break; - case SDLK_7: emotion = 7; break; - case SDLK_8: emotion = 8; break; - case SDLK_9: emotion = 9; break; - case SDLK_0: emotion = 10; break; - case SDLK_MINUS: emotion = 11; break; - case SDLK_EQUALS: emotion = 12; break; - default: emotion = 0; break; - } - - if (emotion) - { - player_node->emote(emotion); - used = true; - } - } } // Quit event |